extract debug symbol info from elf binary

Viewed 8282

Let's have a look to this basic c program:

#include <stdio.h>

int myadd(int a, int b);

int myadd(int a, int b)
{
    return a+b;
}

int main(int argc, char *argv[])
{
    int res = myadd(argc,3);
    printf("%d\n",res);
    return 0;
}

What i want is to understand how debug symbol files work.

If i compile this way:

gcc test.c 

I can see debug symbols in gdb:

gdb ./a.out
(gdb) disassemble myadd
Dump of assembler code for function myadd:
   0x00000000000006b0 <+0>: push   %rbp

That's fine !

Now, if i run:

gcc -s test.c 

Here what i get in gdb:

(gdb) disassemble myadd
No symbol table is loaded.  Use the "file" command.

That's fine too, because i have stripped symbols with -s gcc option.

Now, i want to "split" my elf executable in 2 files: - A stripped elf executable - an external debug symbol files.

Here what i read in some tutorials:

gcc test.c
objcopy --only-keep-debug a.out a.dbg
strip ./a.out 

But, now, if i want to run gdb, i say to gdb to look inside ./a.dbg for debug symbols

gdb -s ./a.dbg a.out

And gdb cannot resolve myadd function:

(gdb) disassemble myadd
No symbol table is loaded.  Use the "file" command.

And this is what i do not understand: Why gdb does not resolv myadd function?

Thanks

1 Answers
Related