Subject: inserting symbols for gdb
To: None <netbsd-users@netbsd.org>
From: Emmanuel Dreyfus <manu@netbsd.org>
List: netbsd-users
Date: 12/21/2005 00:48:03
Hello

A tricky gdb question: I'm working on a stripped binary, and I would
like gdb to display the current function for breakpoints and backtraces.
Of course I don't have the binary sources.

I know where the functions are, the problem is to tell gdb about it. I
tried a few ways:

1) I dumped the ld link script (cc -Wl,--verbose), and I now give it
to ld (cc -Wl,-Tldscript) with symbols defined in it:
SECTIONS {
  .text  :  
    {
    foo = -40000;
    }

NB: the symbol is negative because I mmap the binary from a program in C, 
so the symbol is outside of .text.

If I do that, I can tell gdb to break on foo, but gdb will not display the
function name when breaking in foo (it displays ?? instead).

2) I tried to dump all the assembly code, add .func directives, rebuild it.
The problem is that the code is not relocatable, so I have to load it
at a fixed address. I do that using cc -Wl,-Ttext -Wl,0xa48e78, but the
link failed with this error: "not enough room for program headers (allocated 3, need 4)"

Any idea?

-- 
Emmanuel Dreyfus
manu@netbsd.org