Where is the variable (data segment or heap or BSS) stored according to the address of the variable?

A bit like Where static variables are stored (data segment or heap or BSS)? but not the same thing.

Now I get another address of the process variable, for example: 0x10fb90, where this variable is stored (data segment or heap or BSS), can I get the location only from the pid of the process and the address of the variable?

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

+3
source share
1 answer

You have 2 options.

1. Use objdump

Sort of

objdump -x a.out | grep YOUR_VARIABLE_ADDRESS

2. Use the gcc map option to create 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

, , , .

PS: , map file, , Visual Studio, ,

+2

All Articles