linux - 如何使用调试版的 libc

标签 linux gdb libc debug-symbols ldd

简短的问题: 如何让 gdb 使用 libc 的调试符号?

加长版: 我正在用 gdb 调试一个程序,我想查看有关 libc 使用的 futex 的信息。但是,在调试过程中的某些时候,我会得到如下输出:

Catchpoint 2 (call to syscall futex), 0x00007ffff772b73e in ?? () from /lib/libc.so.6
(gdb) bt
#0  0x00007ffff772b73e in ?? () from /lib/libc.so.6
#1  0x00007ffff767fb90 in ?? () from /lib/libc.so.6
#2  0x00007ffff767a4c0 in vfprintf () from /lib/libc.so.6
#3  0x00007ffff768565a in printf () from /lib/libc.so.6
....

当我在 gdb 中的断点处运行 info sharedlibrary 时,我看到:

(gdb) info sharedlibrary
From                To                  Syms Read   Shared Object Library
0x00007ffff7dddaf0  0x00007ffff7df6704  Yes (*)     /lib64/ld-linux-x86-64.so.2
0x00007ffff7bc53e0  0x00007ffff7bd1388  Yes (*)     /lib/libpthread.so.0
0x00007ffff79ba190  0x00007ffff79bd7d8  Yes (*)     /lib/librt.so.1
0x00007ffff76538c0  0x00007ffff7766c60  Yes (*)     /lib/libc.so.6
0x00007ffff6c1fd80  0x00007ffff6c303c8  Yes (*)     /lib/libgcc_s.so.1
(*): Shared library is missing debugging information.

当我运行 ldd 我看到:

linux-vdso.so.1 =>  (0x00007ffff7fde000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007ffff7dbf000)
librt.so.1 => /lib/librt.so.1 (0x00007ffff7bb6000)
libc.so.6 => /lib/libc.so.6 (0x00007ffff7833000)
/lib64/ld-linux-x86-64.so.2 (0x00007ffff7fdf000)

我使用的是 Ubuntu 10.04,我认为带有调试符号的 libc 版本在 /usr/lib/debug/lib 中。我尝试将我的 LD_LIBRARY_PATH 变量设置在路径的前面,但这似乎没有什么不同。

我不完全清楚程序如何选择要加载的共享库,无论是在运行时还是编译时设置(我有点假设运行时,但现在我不确定)。因此,感谢您提供有关如何让 gdb 使用 libc 的调试版本的信息。

最佳答案

I think that the version of libc with debug symbols is in /usr/lib/debug/lib. I tried setting my LD_LIBRARY_PATH variable to have this at the front of the path but that did not seem to make a difference.

这些不是您正在寻找的机器人。

/usr/lib/debug 中的库不是真正的 库。相反,它们包含 only 调试信息,但不包含真正 libc.so.6 的 .text.data 部分。您可以阅读有关单独的调试信息文件 here .

/usr/lib/debug中的文件来自libc6-dbg包,GDB会自动加载,只要它们与您安装的 libc6 版本相匹配。如果您的 libc6libc6-dbg 不匹配,您应该会收到来自 GDB 的警告。

您可以通过设置 set verbose on 来观察 GDB 试图读取的文件。当 libc6libc6-dbg 匹配时,您应该看到以下内容:

(gdb) set verbose on
(gdb) run
thread_db_load_search returning 0
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/lib/ld-2.11.1.so...done.
thread_db_load_search returning 0
done.
thread_db_load_search returning 0
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from system-supplied DSO at 0x7ffff7ffb000...done.
WARNING: no debugging symbols found in system-supplied DSO at 0x7ffff7ffb000.
thread_db_load_search returning 0
Reading in symbols for dl-debug.c...done.
Reading in symbols for rtld.c...done.
Reading symbols from /lib/librt.so.1...Reading symbols from /usr/lib/debug/lib/librt-2.11.1.so...done.
thread_db_load_search returning 0
... etc ...

更新:

For instance I see
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done

这意味着您的 GDB 没有搜索 /usr/lib/debug。一种可能发生的情况是,如果您在 .gdbinit 中错误地设置了 debug-file-directory

这是默认设置:

(gdb) show debug-file-directory
The directory where separate debug symbols are searched for is "/usr/lib/debug".

关于linux - 如何使用调试版的 libc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10000335/

相关文章:

c++ - XFixesCursorImage 的结构

linux - 如何根据位置从PDF中提取文本?

c++ - gdb 在启动程序期间退出代码 127

android - 使用 bazel 编译 tensorflow android demo 时缺少输入文件@androidsdk//:build-tools/26. 0.1/aapt

c - 在 GDB 中运行程序给出的结果与从命令行运行程序的结果不同

c - uClibc/glibc 是否提供任何将错误重定向到系统日志的功能?

ubuntu - 无法在 gdb 中打印 errno,提示缺少共享库,但它存在

c - gcc:降低 libc 所需的版本

linux - 如何在 Linux 上 OOM liller 被杀或内存不足之前得到通知?

linux - 套接字 FD 存储在哪里?