This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: using bfd and shared libraries


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]