Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

linux

gdb

libc

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?

like image 844
colinfang Avatar asked Jan 17 '18 18:01

colinfang


1 Answers

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.

like image 161
zwol Avatar answered Nov 07 '22 08:11

zwol