Re: How does one get static procedure names?

2009-10-29 Thread Andreas Schwab
Bruce Korb  writes:

> Sorry.   When you do a "bt" using gdb, you see the function
> names, whether they be "static" or have global (external)
> linkage.  The function backtrace_symbols(), on the other
> hand, doe *not* print static scope function names.

backtrace_symbols can only deal with dynamic symbols, which are the only
ones available at runtime.  If you want to resolve normal symbols you
need to read them from the (unstripped) binary, like addr2line does.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Re: How does one get static procedure names?

2009-10-29 Thread Bruce Korb
On Tue, Oct 27, 2009 at 12:37 PM, Daniel Jacobowitz  wrote:
> On Tue, Oct 27, 2009 at 12:33:39PM -0700, Bruce Korb wrote:
>> Exactly.  I know it'd be some work.  I think I need to
>> call:  dlopen(NULL, RTLD_NOW)
>
> No.  You need to open the file and have your own ELF and symbol table
> reader.  They are not in the area mapped by dlopen.

OK.  Still not terribly hard:

{
static char const exe_fmt[] =
"/proc/%d/exe";
char bf[sizeof (exe_fmt) + 12];
sprintf(bf, exe_fmt, getpid());
path_len = readlink(bf, exe_path, sizeof (exe_path) - 1);
}

(This is for Linux only...)

> GDB is almost certainly not where you want to get this code from.  We
> just use BFD...

Ah!  There we go.  That's what I was looking for.  Thank you!




Re: How does one get static procedure names?

2009-10-29 Thread Daniel Jacobowitz
On Tue, Oct 27, 2009 at 12:33:39PM -0700, Bruce Korb wrote:
> Exactly.  I know it'd be some work.  I think I need to
> call:  dlopen(NULL, RTLD_NOW)

No.  You need to open the file and have your own ELF and symbol table
reader.  They are not in the area mapped by dlopen.

> and then copy & fiddle code out of GDB.  yes?  :)

GDB is almost certainly not where you want to get this code from.  We
just use BFD...

-- 
Daniel Jacobowitz
CodeSourcery




Re: How does one get static procedure names?

2009-10-29 Thread Bruce Korb
On Tue, Oct 27, 2009 at 12:27 PM, Daniel Jacobowitz  wrote:
> On Tue, Oct 27, 2009 at 11:56:46AM -0700, Bruce Korb wrote:
>> Sorry.   When you do a "bt" using gdb, you see the function
>> names, whether they be "static" or have global (external)
>> linkage.  The function backtrace_symbols(), on the other
>> hand, doe *not* print static scope function names.  Even if
>> it takes some work, I'd like to "fix" the constraint.  However,
>> I wasn't able to decipher the gdb source well enough to figure
>> out how it accomplished this feat.  So, is there some place
>> in the GDB source where I ought to be looking?
>
> You can't readily do so.  backtrace_symbols is using the dynamic
> symbol table, which is loaded into memory.  Local symbols are not
> added to the dynamic symbol table.
>
> GDB reads both the local symbol table and the DWARF/stabs debug
> information.
>
> You'd need an additional symbol table reader which read them off disk
> instead of out of RAM.

Exactly.  I know it'd be some work.  I think I need to
call:  dlopen(NULL, RTLD_NOW)

and then copy & fiddle code out of GDB.  yes?  :)
Or, do I have to figure out the actual file name and replace
NULL with that file name?  Either waynow what?
Just point me to some code & I ought to be okay.




Re: How does one get static procedure names?

2009-10-29 Thread Daniel Jacobowitz
On Tue, Oct 27, 2009 at 11:56:46AM -0700, Bruce Korb wrote:
> Sorry.   When you do a "bt" using gdb, you see the function
> names, whether they be "static" or have global (external)
> linkage.  The function backtrace_symbols(), on the other
> hand, doe *not* print static scope function names.  Even if
> it takes some work, I'd like to "fix" the constraint.  However,
> I wasn't able to decipher the gdb source well enough to figure
> out how it accomplished this feat.  So, is there some place
> in the GDB source where I ought to be looking?

You can't readily do so.  backtrace_symbols is using the dynamic
symbol table, which is loaded into memory.  Local symbols are not
added to the dynamic symbol table.

GDB reads both the local symbol table and the DWARF/stabs debug
information.

You'd need an additional symbol table reader which read them off disk
instead of out of RAM.

-- 
Daniel Jacobowitz
CodeSourcery




Re: How does one get static procedure names?

2009-10-29 Thread Bruce Korb
On Tue, Oct 27, 2009 at 11:40 AM, Paul Pluzhnikov
 wrote:
> On Tue, Oct 27, 2009 at 11:32 AM, Bruce Korb  wrote:
>
>> I know GDB has some way to do it, but I couldn't locate
>> the code that does it.  A pointer on where to look would
>> be really helpful and greatly appreciated!
>
> Your question is rather unclear :-(

Sorry.   When you do a "bt" using gdb, you see the function
names, whether they be "static" or have global (external)
linkage.  The function backtrace_symbols(), on the other
hand, doe *not* print static scope function names.  Even if
it takes some work, I'd like to "fix" the constraint.  However,
I wasn't able to decipher the gdb source well enough to figure
out how it accomplished this feat.  So, is there some place
in the GDB source where I ought to be looking?

Thank you!

Regards, Bruce




Re: How does one get static procedure names?

2009-10-29 Thread Paul Pluzhnikov
On Tue, Oct 27, 2009 at 11:32 AM, Bruce Korb  wrote:

> I know GDB has some way to do it, but I couldn't locate
> the code that does it.  A pointer on where to look would
> be really helpful and greatly appreciated!

Your question is rather unclear :-(

Are you looking for
A) how to set a breakpoint in a static procedure in GDB, or
B) how to find an address of a given static function in a given executable, or
C) a list of all static functions in a given executable, or
D) something else (if so, what exactly?)

Cheers,
-- 
Paul Pluzhnikov