Re: Accessing symbol table to find function given address

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Paulo J. Matos" wrote:

> Is there a way to access the symbol table during runtime to know which
> function belongs to a given address. The problem is to print the
> function name if I am instrumenting functions. I get the address, can
> I during runtime print the function name? (or the solution is get it
> through addr2line after program as run)?

Gcc provides the standard symbols __func__ and __FUNCTION__ as well as
the extension __PRETTY_FUNCTION__.  See
<http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html#index-g_t_0040code_007b_005f_005fPRETTY_005fFUNCTION_005f_005f_007d-identifier-2118>. 
To use them you'd have to arrange to pass them to your instrumentation
routine from a call within the function though, they can't be used to
just map a memory address to a function name.  To do that will be
extremely target-specific and seeing as how gcc supports something like
3 dozen various targets, there's no way to answer that without more
details.  If you're using a glibc platform, you can use dladdr(); see
dlopen(3).  But realize this is nonportable, it is a glibc extension.

Brian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux