[Dwarf-Discuss] question about variable locations from dwarf debugging information

Michael Eager eager at eagercon.com
Thu Jun 18 11:19:08 PDT 2009

Fengwei Zhang wrote:
> Dear all,
> I am working on a project which needs to get the variable location from 
> executable application. I could use readelf and dwarfdump to output the 
> text debugging information, including the variable locations. However, 
> the debugging information is very complex. For example, variable 
> location will be "DW_OP_fbreg: -32". It means some offset from stack 
> base frame. In other words, I need to compute where the variable is 
> based on the debugging information.
> I am wondering: Is there any other tool which help me get the memory 
> address of variables? Like "print variable_name" command in gdb, then I 
> could get 0xff73d305.

It's not clear what you are trying to do.

What is your environment?  Is it a hosted environment like Linux
or an embedded environment without memory protection?

What do you want to do once you have the address of the variable?

Do you want to find the variable address in an executable file or
while you are executing the application?

Assuming you are working in a hosted environment and running an
application, if you want to look at the variable from a different
process, you need more than just the address of the variable, you
need a way to access the memory space for the application using ptrace.
That amounts to implementing a debugger like gdb.  This is somewhat
easier to do in an embedded environment.

Are you looking for a specific variable rather than wanting to look
at an arbitrary variable?  Can you modify the program?

If so, the simplest way may be to just use printf to print the address
of the variable

Michael Eager	 eager at eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077

More information about the Dwarf-Discuss mailing list