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

Paul Pluzhnikov ppluzhnikov at google.com
Thu Jun 18 10:57:46 PDT 2009


On Thu, Jun 18, 2009 at 10:48 AM, Fengwei Zhang<fz2135 at columbia.edu> wrote:

> I am working on a project which needs to get the variable location from
> executable application.

Only global (and static) variables have fixed addresses.

Automatic (aka stack) variables exist only at program runtime, and may
have different address at different points in execution.

Are you interested in the addresses of globals, automatics, or both?

> 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.

These are automatic variables, and to compute their address you need debug
info *and* runtime info (the value of frame register in that frame).

For globals and static variables you just need to read the symbol table
(try 'nm a.out'), which is much simpler to read and interpret.

> 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.
>
> If there is no such tool,  It would be great if some could tell me how to
> compute the variable locations from dwarf debugging information, or some
> links I could read helping me to do that.

You could always read the DWARF standard and GDB sources :=)


-- 
Paul Pluzhnikov



More information about the Dwarf-Discuss mailing list