Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Resolving a Mach-O symbol address into a variable address at runtime



Nevermind. I'm a retard. Got my pointers confused. Everything's working; thanks for the help! :)
--


Damien Sorresso
Macintosh Developer
Computer Infrastructure Support Services
Illinois State University
email@hidden

On 11 Jul, 2006, at 11:35 AM, Damien Sorresso wrote:
dlsym(...) gives me the information I already have: the symbol address in the Mach-O file. I need the address of the variable the symbol corresponds to at runtime. Or am I doing something wrong here? This is what I'm doing.

void *mainHandle = dlopen(NULL, RTLD_LAZY);
if( !mainHandle ) {
	printf("dlopen() failed.\n");
}

int *debug_addr = (int *)dlsym(mainHandle, "__debug_level");
printf("debug_addr = 0x%x->0x%x\n", debug_addr, *debug_addr);	
dlclose(mainHandle);

--

Damien Sorresso
Macintosh Developer
Computer Infrastructure Support Services
Illinois State University
email@hidden


On 11 Jul, 2006, at 10:52 AM, Peter O'Gorman wrote:
On Tue, 2006-07-11 at 10:34 -0500, Damien Sorresso wrote:
I've got a loadable bundle in a Cocoa application, and I'd like this
bundle to grab the value of a global symbol from the main application
after it's been loaded, specifically a global debugging level.


Now, I can grab the symbol's address using nlist(...), but I want to
in turn take this address and find the location of the variable in
memory at runtime. I've already tried CFBundleGetDataPointerForName
(...); it doesn't work. Don't ask me why. I've been pouring over the
Mach-O documentation, and I'm thinking that the best way to go about
it would be to grab the `vmaddr' member of the `segment_command'
structure to determine the VM address of the __DATA segment and then
work from there, but I'm not sure how to specifically go about doing
this.

Use dlopen/dlsym, see the manpages.

Peter

_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden

References: 
 >Resolving a Mach-O symbol address into a variable address at runtime (From: Damien Sorresso <email@hidden>)
 >Re: Resolving a Mach-O symbol address into a variable address at runtime (From: "Peter O'Gorman" <email@hidden>)
 >Re: Resolving a Mach-O symbol address into a variable address at runtime (From: Damien Sorresso <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.