Ferramentas do usuário

Ferramentas do site


dev:debug:gdb_debugger

Essa é uma revisão anterior do documento!


GDB - Debugger

Type info variables to list “All global and static variable names”.

Type info locals to list “Local variables of current stack frame” (names and values), including static variables in that function.

Type info args to list “Arguments of the current stack frame” (names and values).

info frame to show the stack frame info

To read the memory at given addresses you should take a look at x

x/x $esp for hex x/d $esp for signed x/u $esp for unsigned etc. x uses the format syntax, you could also take a look at the current instruction via x/i $eip etc.

You need to use gdb's memory-display commands. The basic one is x, for examine. There's an example on the linked-to page that uses

gdb> x/4xw $sp

to print “four words (w ) of memory above the stack pointer (here, $sp) in hexadecimal (x)”. The quotation is slightly paraphrased.

Use: 1. bt - backtrace: show stack functions and args 2. info frame - show stack start/end/args/locals pointers 3. x/100x $sp - show stack memory Try using ddd. ddd manual

Ok. Maybe I elaborate a little. I use it like this.

compile my program with debug symbols:

gcc -g program.c -o program

run ddd:

ddd program

In gui you can do all sorts of things, view machine code, view memory, etc. . Look around. In manual there is also a section of examining stack. ddd provides good interface for you to examine C program

View stack: gdb> backtrace

View current stack frame: gdb> info frame

View arguments of current stack frame: gdb> info args

View local variable of current stack frame: gdb> info locals

Navigate to parent stack frame: gdb> frame 1