简体   繁体   中英

Where the variable stored (data segment or heap or BSS) according to the variable's address?

A little similar with Where are static variables stored (data segment or heap or BSS)? ,but not the same one.

Now I get a other process's variable's address like:0x10fb90,where is this variable stored(data segment or heap or BSS), could i get the location just from the process's pid and the variable's address?

I am working on osx using obj-c and c.

You have 2 options.

1. Use objdump

Something like

objdump -x a.out | grep YOUR_VARIABLE_ADDRESS

2. Use gcc's map option to generate a map file

Compile something like this in gcc

$ gcc -o foo.exe -Wl,-Map,foo.map foo.c

and now

$ grep YOUR_VARIABLE_ADDRESS foo.map

Both these methods will show your variable's location, if at all the address you supplied exits.

PS : The link I've added for the map file shows an example map file generated by Visual Studio linkers, but the format is typically similar in most of the map file formats generated by various linkers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM