Introspection via load_commands nlist + stabs
Introspection via load_commands nlist + stabs
- Subject: Introspection via load_commands nlist + stabs
- From: James Quick <email@hidden>
- Date: Mon, 7 Jul 2003 11:36:33 -0400
I'm not quite sure of the right list for this question. It is low
enough
level to for the darwin list, but since I am relying on some Macos X
only functionality I am not sure if it is off topic there.
I am writing a code testing/debugging framework for a Cocoa based
tool. Based on the results of tests performed either explicitly in the
code
or by the user via a gui tool, I need to provide feedback to the user
which refers back to the source code.
At startup I grab the in-memory copy of the mach-o header
(struct mach_header) <macho/loader.h> using _NXGetExecuteHeader()
I then walk the list load command structures to find LC_SYMTAB
and LC_DYSYMTAB entries. At this point I have structures purporting
to tell me the location of each of the segments containing nlist
structures.
For example in the symtab_command structure I get:
struct symtab_command {
unsigned long cmd; /* LC_SYMTAB */
unsigned long cmdsize; /* sizeof(struct symtab_command) */
unsigned long symoff; /* symbol table offset */
unsigned long nsyms; /* number of symbol table entries */
unsigned long stroff; /* string table offset */
unsigned long strsize; /* string table size in bytes */
};
I know that eventually I will also have to delve further to find symbol
stubs
entries but I want to start here initially.
Obviously I've missed something critical here, because for the life of
me,
I don't know what addresses to use as the base address for the string
and
symbol sections in the current vm address map. I know I could simply
open a file descriptor to the target in question and read the
structures from
disk, but apparently the loader has already done so, and prettied up
nlist string table offsets into usable addresses.
I cannot use code from gdb bfd subsystem to do this since it appears to
all be done externally rather than from inside the running image.
I am also unable to use GPL based code here, since I need it to
eventually be released under different open source licenses.
For instance a related extension to the objc_runtime will rely on this
introspection for the ability to set a conditional breakpoint on
a message invocation only if the sender was an object of a particular
type. That section, of course, has to be under APSL.
I'm sorry if this is a trivial question. But what address(es) do I add
to
stroff and symoff to get the string table base and nlist base
respectively.
I've tried adding the execute header base and the address immediately
following the LC_SYMTAB load command structure and I see zeroed
memory there.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.