问题
I have libc6
& libc6-dbg
installed.
(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
However, gdb refuse to get me any info about ifaddrs.c, although it knows it is on line 840
What happened here?
回答1:
The debugging information in the libc6-dbg
package includes the names of the source files for the C library, and a mapping from assembly instructions to specific lines within those source files, but it does not include the source files themselves. So gdb
can tell you that your breakpoint is associated with line 840 of a file named sysdeps/unix/sysv/linux/ifaddrs.c
, but it can't show you what's actually on that line. (The leading ../
is an artifact of glibc's terrifyingly complicated build system.)
If you know where to find the Git repository for 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, but others do), and it doesn't get you access to the code inside gdb.
To get the code visible inside gdb, you would need to download the source package that matches the C library on your system. Based on the package name libc6-dbg
I am guessing you are using a Linux distribution in the Debian family; if that's right, the command
apt-get source glibc
will do the job. Then you can use the GDB command directory to tell GDB where to look for the source files. It will probably take a bit of fiddling to get everything working just so.
来源:https://stackoverflow.com/questions/48308171/why-gdb-cannot-find-sysdeps-unix-sysv-linux-ifaddrs-c