[Dwarf-Discuss] how to find local variable stored in register

Jim Blandy jimb@red-bean.com
Wed Feb 6 07:14:58 GMT 2008

On Feb 5, 2008 8:57 PM, Neeraj kushwaha <kushneeraj at gmail.com> wrote:
> How GDB finds the value of variable which are stored in register for
> each function stack frame?
> As GDB uses dwarf debug info internally and is capable of finding them.

It depends.  For native Linux debugging, GDB uses the 'ptrace' system
call to read and write a process's registers.  See
i386_linux_fetch_inferior_registers.  Other debuggers probably do
something similar.

DWARF only shows the relationship between a particular pile of machine
code and the source code from which it was generated.  So while DWARF
does tell GDB which register a variable lives in, or how to calculate
the variable's address, DWARF doesn't tell GDB how to actually read
that register or access that memory.

GDB could be debugging a program running on a simulator; it could be
using the remote protocol (see Appendix D of the GDB manual); it could
be doing something else.  In each of these cases, the way GDB actually
reads the register that DWARF has directed it to would be entirely

More information about the Dwarf-discuss mailing list