Linux 如何使用调试版的 libc

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10000335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:35:47  来源:igfitidea点击:

How to use debug version of libc

linuxgdblibcldd

提问by Gabriel Southern

Short version of question:How can I get gdb to use the debugging symbols for libc?

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

Longer version:I am debugging a program with gdb and I want to see information about a futex used by libc. However, at some point during debugging I get output such as:

更长的版本:我正在用 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
....

When I run info sharedlibraryin gdb at the breakpoint I see:

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

(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.

And when I run lddI see:

当我跑步时,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)

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

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

I'm not completely clear on how the program chooses which shared libraries to load, whether this is set at runtime or compile time (I sort of assumed runtime but now I'm not sure). So information on how to get gdb to use the debug version of libc is appreciated.

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

采纳答案by Employed Russian

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.

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

These are notthe droids you are looking for.

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

The libraries in /usr/lib/debug are not reallibraries. Rather, the contain onlydebug info, but do not contain .textnor .datasections of the real libc.so.6. You can read about the separate debuginfo files here.

/usr/lib/debug 中的库不是真正的库。相反,包含调试信息,但不包含.text也不.data现实的部分libc.so.6。您可以在此处阅读有关单独的 debuginfo 文件的信息

The files in /usr/lib/debugcome from libc6-dbgpackage, and GDB will load them automatically, so long as they match your installed libc6version. If your libc6and libc6-dbgdo not match, you should get a warning from GDB.

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

You can observe the files GDB is attempting to read by setting set verbose on. Here is what you should see when libc6and libc6-dbgdo match:

您可以通过设置来观察 GDB 尝试读取的文件set verbose on。以下是您应该在何时匹配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 ...

Update:

更新:

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

例如我看到
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done

That implies that your GDB is not searching /usr/lib/debug. One way that could happen is if you set debug-file-directoryin your .gdbinitincorrectly.

这意味着您的 GDB 没有搜索/usr/lib/debug. 可能发生的一种方法是,如果你设置debug-file-directory你的.gdbinit错误。

Here is the default setting:

这是默认设置:

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

回答by mtlynch

Make sure you've installed the debug symbols for libc:

确保你已经安装了 libc 的调试符号:

sudo apt-get install libc6-dbg

And if you're on an x64 system debugging x86 code:

如果您在 x64 系统上调试 x86 代码:

sudo apt-get install libc6:i386
sudo apt-get install libc6-dbg:i386