为什么GDB无法解析此符号,直到它击中`main`?为什么valgrind根本无法解决它?

时间:2015-12-22 01:49:35

标签: c memory linker gdb valgrind

我尝试track down issue,而Valgrind无法解析通过某些库的函数符号。我得到这样的输出:

    public class EmailDetails
    {
        public string EmailAddress { get; set; }
        public string EmailDisplayName { get; set; }
    }

    public List<EmailDetails> EmailInformation { get; set; } 

    [WebMethod]
    public static List<EmailDetails> GetEmails()
    {
        List<EmailDetails> emailAddresses = new List<EmailDetails>();

        //queries AD to pull all users
        var search = new DirectorySearcher();
        search.Filter = "(&(objectClass=user)(mail=*)(displayName=*))";
        search.PageSize = 1000;

        using (var results = search.FindAll())
        {
            foreach (SearchResult result in results)
            {
                emailAddresses.Add(new EmailDetails
                {
                    EmailAddress = result.Properties["mail"][0].ToString(),
                    EmailDisplayName = result.Properties["displayName"][0].ToString()
                });
            }
        }

        //sort email address list alphabetically and return sorted list
        List<EmailDetails> sortedEmailAddresses = emailAddresses.OrderBy(o => o.EmailDisplayName).ToList();
        return sortedEmailAddresses;

==83597== 920 bytes in 1 blocks are possibly lost in loss record 750 of 864 ==83597== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==83597== by 0x548EF93: myproject_malloc (mysourcefile.c:48) ==83597== by 0x4F13FD5: ??? (in /path/to/project/library-version.so) ==83597== by 0x54542FF: ??? (in /path/to/project/library-version.so) ==83597== by 0x4F536CA: ??? (in /path/to/project/library-version.so) ==83597== by 0x54542FF: ??? (in /path/to/project/library-version.so) 内的一个功能是library-version.sodo_init()已通过library-version.so加载。我发现当我在gdb下运行我的程序时,如果我在启动程序时尝试在LD_PRELOAD处设置断点,则会抱怨它无法找到符号,但如果我在do_init处设置一个断点并等到它达到那个断点,那么它就可以了。

例如:

main

所以这引出了两个问题:

  1. 似乎(gdb) break do_init Function "do_init" not defined. Make breakpoint pending on future shared library load? (y or [n]) n (gdb) break main Breakpoint 1 at 0x400b50: file runner.c, line 13. (gdb) run ... a bunch of output from the stuff in LD_PRELOAD ... Breakpoint 1, main (argc=1, argv=0x7fffffffe028) at myprogram.c:13 13 return do_some_stuff(); (gdb) break do_init Breakpoint 2 at 0x7ffff7658de0: file my/library/initializer.c, line 25. 被动态链接器吸引了。如何找出发生在初始化过程的哪一步?在这个项目中使用了许多库来定义do_init的函数,并且它们与链接器脚本粘合在一起。

  2. 为什么Valgrind看不到动态链接器加载的符号,比如GDB呢?我99%确定没有任何东西__attribute__((constructor))&#39; d,我认为无论如何,Valgrind仍然可以看到dlclose下的任何内容。

1 个答案:

答案 0 :(得分:0)

事实证明,由于碰巧同时存在大量奇怪的配置选项,包含library-version.so部分的.text的程序部分标头被标记为具有rwx权限而不是rx权限。 Valgrind认为.text部分不能在amd64机器上拥有rwx权限,因此在尝试加载调试符号时会忽略它们。

我认为这是Valgrind中的一个错误,因为具有rwx权限的.text部分根据相关标准完全有效;事实证明,报告已经filed here,我已经扩展了。