This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: using bfd and shared libraries
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: Robert Schweikert <Robert dot Schweikert at abaqus dot com>
- Cc: gdb at sources dot redhat dot com, Robert Schweikert <rjschwei at abaqus dot com>
- Date: Mon, 23 Jun 2003 14:28:52 -0400
- Subject: Re: using bfd and shared libraries
- References: <1056390964.19234.33.camel@cheetah.hks.com>
On Mon, Jun 23, 2003 at 01:56:04PM -0400, Robert Schweikert wrote:
> Hi,
>
> I am trying to come up with some basic memory tracking tools and one
> thing I'd like to do is to write out the function/method in which memory
> was being allocated. So far what I have found is that I can use
> __builtin_return_address(0) to get the address of function on the stack
> that allocates the memory. Then using bfd I can figure out the
> function/method symbol. My problem now is that this works for monolithic
> executables but not for executables with shared libraries.
>
> Since gdb handles shared libraries just fine and also uses bfd I was
> hoping someone could provide some ideas on how to go about this, or
> point me to the code in the gdb source, or to some documentation where
> this issue is addressed.
You really don't want to do it the same way GDB does...
If you're working on GNU/Linux, dl_iterate_phdr should give you what
you need. Otherwise, investigate following the "struct link_map"
objects.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer