On Mon, 2013-08-05 at 15:33 +0400, Andrey Ponomarenko wrote:
What is the best way to read the file name from .gnu_debugaltlink
section?
I've tried objdump:
$> eu-objdump -s -j .gnu_debugaltlink
usr/lib/debug/usr/lib64/libTKLCAF.so.6.0.0.debug
Contents of section .gnu_debugaltlink:
0000 2e2e2f2e 2e2f2e64 777a2f4f 43452d30 ../../.dwz/OCE-0
0010 2e31322d 312e6663 31382e78 38365f36 .12-1.fc18.x86_6
0020 3400f971 c94aa7b5 33115f63 bbc3d3ed 4..q.J..3._c....
0030 88f7cdb6 ae09 ......
So the path to the alternate debug info file is
"../../.dwz/OCE-0.12-1.fc18.x86_64", but it's not so easy to parse it
from the output.
The easiest of course is to just parse the ELF file with libelf, the
section data just starts with the string, so something like:
GElf_Ehdr ehdr_mem;
GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
Elf_Scn *scn = NULL;
while ((scn = elf_nextscn (elf, scn)) != NULL)
{
const char *scnname = elf_strptr (elf, ehdr->e_shstrndx,
shdr->sh_name);
if (scnname != NULL
&& strcmp (scnname, ".gnu_debugaltlink") == 0)
{
Elf_Data *data = elf_getdata (scn, NULL);
if (data != NULL && data->d_size != 0)
const char *alt_name = data->d_buf;
The string is zero terminated.
So if you really insist on using existing command line tools you could
also do something like:
$ eu-readelf --strings=.gnu_debugaltlink ls.debug \
| grep ' 0]' | cut -c12-
Aka, the first (zero) string in the .gnu_debugaltlink (the second string
will be garbage because it really is the build-id).
Cheers,
Mark