为什么 gdb 找不到 ../sysdeps/unix/sysv/linux/ifaddrs.c

Why gdb cannot find ../sysdeps/unix/sysv/linux/ifaddrs.c

我安装了 libc6 & libc6-dbg

(gdb) b
reak freeifaddrs
(gdb) run
Breakpoint 1, __freeifaddrs (ifa=0xa822e0) at ../sysdeps/unix/sysv/linux/ifaddrs.c:840
840 ../sysdeps/unix/sysv/linux/ifaddrs.c: No such file or directory.
(gdb) list
835 in ../sysdeps/unix/sysv/linux/ifaddrs.c
(gdb) disassemble
Dump of assembler code for function __freeifaddrs:
=> 0x00007ffff7912fd0 <+0>: jmpq   0x7ffff780f8a8
End of assembler dump.

(gdb) where
#0  __freeifaddrs (ifa=0xa822e0) at ../sysdeps/unix/sysv/linux/ifaddrs.c:840

然而,gdb 拒绝让我得到关于 ifaddrs.c 的任何信息,尽管它知道它在第 840 行

这里发生了什么?

libc6-dbg 包中的调试信息包括 C 库源文件的名称,以及从汇编指令到这些源中特定行的映射文件,但不包括源文件本身。因此 gdb 可以告诉您您的断点与名为 sysdeps/unix/sysv/linux/ifaddrs.c 的文件的第 840 行相关联,但它无法向您显示该行上的实际内容。 (前导 ../ 是 glibc 极其复杂的构建系统的产物。)

如果您知道在哪里可以找到 the source code for the GNU C Library, then you can look up that specific file and line by hand in a web browser. This is relatively quick and easy once you know how to do it, but probably won't show you the exact same version of the code that was used to build your copy of the library (this file in particular doesn't change very often 的 Git 存储库,但其他人知道),并且它不会让您访问代码 inside gdb.

要使代码在 gdb 中可见,您需要下载与您系统上的 C 库相匹配的源代码包。根据软件包名称 libc6-dbg,我猜您使用的是 Debian 家族的 Linux 发行版;如果正确,命令

apt-get source glibc

会完成这项工作。然后你可以使用 GDB 命令 directory 告诉 GDB 去哪里寻找源文件。可能需要一些操作才能使一切正常工作。