3

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.

trincot
  • 317,000
  • 35
  • 244
  • 286
timestee
  • 1,086
  • 12
  • 36

1 Answers1

2

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

Community
  • 1
  • 1
Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125