* Accessing symbol table to find function given address
@ 2007-05-26 20:37 Paulo J. Matos
2007-05-26 21:00 ` David Daney
2007-05-26 21:17 ` Brian Dessent
0 siblings, 2 replies; 4+ messages in thread
From: Paulo J. Matos @ 2007-05-26 20:37 UTC (permalink / raw)
To: gcc-help
Hello all,
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)?
Cheers,
--
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Accessing symbol table to find function given address
2007-05-26 20:37 Accessing symbol table to find function given address Paulo J. Matos
@ 2007-05-26 21:00 ` David Daney
2007-05-26 21:17 ` Brian Dessent
1 sibling, 0 replies; 4+ messages in thread
From: David Daney @ 2007-05-26 21:00 UTC (permalink / raw)
To: Paulo J. Matos; +Cc: gcc-help
Paulo J. Matos wrote:
> Hello all,
>
> 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)?
If you are using glibc, you could try the dladdr() function. Otherwise
you can try addr2line as you suggested.
David Daney.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Accessing symbol table to find function given address
2007-05-26 20:37 Accessing symbol table to find function given address Paulo J. Matos
2007-05-26 21:00 ` David Daney
@ 2007-05-26 21:17 ` Brian Dessent
2007-05-27 18:05 ` Paulo J. Matos
1 sibling, 1 reply; 4+ messages in thread
From: Brian Dessent @ 2007-05-26 21:17 UTC (permalink / raw)
To: Paulo J. Matos; +Cc: gcc-help
"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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Accessing symbol table to find function given address
2007-05-26 21:17 ` Brian Dessent
@ 2007-05-27 18:05 ` Paulo J. Matos
0 siblings, 0 replies; 4+ messages in thread
From: Paulo J. Matos @ 2007-05-27 18:05 UTC (permalink / raw)
To: gcc-help
Great, thank you Brian and David. I'll go with the dladdr function. :-)
--
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-05-27 15:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-26 20:37 Accessing symbol table to find function given address Paulo J. Matos
2007-05-26 21:00 ` David Daney
2007-05-26 21:17 ` Brian Dessent
2007-05-27 18:05 ` Paulo J. Matos
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).