linux - 如何使用调试版的 libc

简短的问题: 如何让 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".

https://stackoverflow.com/questions/10000335/

相关文章:

python - 以 Unix 时间戳格式获取当前 GMT 时间的最简单方法是什么?

linux - 使用 Wget 发布请求?

linux - 在 Linux 中模拟/模拟 iOS

python - 如何使用 Python 写入 Excel 电子表格?

python - Python中最有效的字符串连接方法是什么?

python - 比较两个 DataFrame 并并排输出它们的差异

linux - 在 Linux 中注册文件扩展名/mime 类型

python - Django 内容类型究竟是如何工作的?

linux - ubuntu "No space left on device"但是有很多空间

linux - epoll() 是否在 O(1) 中完成工作?