This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Mapping Addresses for Shared Library Routines to Code
- From: John Reiser <jreiser at bitwagon dot com>
- To: binutils at sourceware dot org
- Date: Thu, 04 Feb 2010 16:25:36 -0800
- Subject: Re: Mapping Addresses for Shared Library Routines to Code
- References: <4B6B4E57.1010100@oarcorp.com>
My question is: How can I figure out what
dynamically loaded routine corresponds to
those addresses in the trace? Is there some
utility to "preload" and give me a symbol
table?
It depends on when you want to do the mapping: at run time, or later?
The result of dlopen() is really a struct link_map * [see <link.h>]
and the link_map struct is a member of a doubly-linked list which
describes all the modules that are present in memory.
The .l_addr is the relocation constant for that module. Add this
value to every address that is given in Elf32_.* structs in the file,
in order to get the corresponding address in memory. If prelinking
has not been done, then the relocation constant equals the base address.
The base address of a loaded module can be found by inspecting
the output from "cat /proc/PID/maps" where PID is the decimal
process ID. The base address for modules that were present
when a "core" file was generated, is given by
readelf --segments core
and perhaps by
(gdb) info memory
(gdb) info shared
In standard cases, the relocation constant for a module
equals (base_address - Elf32_Phdr[0].p_vaddr) which is different
from base_address if prelinking has been done.
In some cases you must tell gdb about loaded modules that gdb
does not realize are there:
(gdb) add-symbol-file FILE ADDR
where ADDR is the memory address of the base of .text:
objdump --section-headers FILE | grep '\.text'
and then add the base address of the module.
--