1、刚工作时做Linux 流控;后来做安全操作系统;再后来做操作系统加固;现在做TCP 加速。唉!没离开过类Unix!!!但是水平有限。。
全部博文(353)
分类: LINUX
2011-10-26 14:57:53
It is a section in an ELF file containing
It is used as a pointer to a file with separate debug info and can be created with
objcopy --add-gnu-debuglink=command (more on creation subject in the next post).
For example, let's find out where libc debug info resides on x86 Ubuntu 9.04:
1. Locate libc itself by using ldd on a random binary:
2. Dump contents of its .gnu_debuglink section:
So name of the file with debug info is libc-2.9.so; the rest must be checksum. We'll leave that for debugger to verify.
Debug info files are usually stored under /usr/lib/debug plus dirname of their "parent" library; in our case it is
Debug packages do not get installed automatically. Let's install one for libc:
Package with debug info is usually (always?) named like
After installation, libc-2.9.so appears in the location we predicted:
It has DWARF debug info as can be seen by doing
Debug info is not enough - one needs source code to debug. The source code is again distributed separately and can be downloaded with apt-get source command:
This will create /export/home/maxim/work/glibc-2.9/ directory and populate it with glibc source code.
Brute-force attempt gives us nothig:
Obviously, dbx was able to read .gnu_debuglink as it knows where the source code for __gethostname() is. It may even be enough if all you need is correct parameter name/values in stack trace:
But since we already downloaded the source code, let's point dbx to it:
pathmap command is described in `help pathmap' topic; here's an excerpt:
Establish a new mapping from
The result is immediately visible:
We have source code of a libc function - gethostname().
A tale about Linux system wouldn't be complete without a story about gdb. Gdb also supports .gnu_debuglink (obviously), but has a different command for source code path mapping.
Here's how to step into gethostname() using gdb (in the same environment, e.g. debug info and source code are present):
NB: you have to set substitute-path before starting debug session; when I tried to set it at the same time as in dbx - after stepping into gethostname() - I got nothing. Besides, with gdb you have to figure out "from" part of substitute-path by yourself somehow as it doesn't give you a hint like dbx; here's what gdb prints without proper substitute-path set: