Using the GNU Debugger (GDB) Pranav Peshwe
Techzemplary Pvt.Ltd February 24th 2008
Some background about GDB... ●
Started by RMS in 1986
●
Ported to all major OSes thereafter
●
Has support for almost all popular architectures
●
Supports symbolic debugging
●
Primarily used for debugging C/C++
●
Supports remote debugging
●
Work being done on bringing in 'Reversible debugging'
Getting ready... ●
Compiling with debug information
●
Side effects of debug information
●
Readying multi-file projects for debugging
●
Nifty utililies – file, nm, objdump, strip etc
A typical debug workflow ●
Run
●
Backtrace
●
Break
●
Step
●
Inspect
●
Change
●
Continue
Preliminary usage ●
The GDB executable - /usr/bin/gdb
●
To start – gdb [program-name]
●
To quit – quit
●
Select a program to run – file <prog-name>
●
Run a program in gdb - run
●
Kill a prog in gdb – kill <prog-name>
●
Getting help – GDB manual and online help
Zeroing on the function ●
Backtracing bt
●
Moving between frames – up, down and frame
●
Viewing arguments' addresses – info args
●
Other information about the frame – info frame
Looking at the source ●
Specifying the source file(s) – directory
●
Listing the source – the many variants of list
●
Searching the source – search
Breaking into the code ●
Breakpoint on a function – b func_name, continue
●
Breakpoint on a source line – b [filename:]line_no
●
Listing current breakpoints – info b
●
Break only the first time – tbreak
●
Ignore, disable and delete breakpoints
●
Watchpoints
Moving ahead...one step at a time ●
Single stepping – step, next
●
'finish'ing a function
●
Forcing a return
Inspecting data ●
Global variables – info variables
●
Local variables – info locals
●
Examining values of variables – print
●
Viewing arrays
●
Automatic display
Inspecting data contd... ●
Examining memory - x
●
Viewing registers – info registers
●
Listing functions
●
Listing variables in scope of a function
Onsite debugging ?? ●
Get the pid of the process
●
Attach to a running process – attach
●
Loading symbol table from an external file
●
Detach from a running process – detach
Miscellaneous stuff ●
Getting runtime information
●
Redirecting output
●
Logging
●
Shell commands
●
Graphical front-ends to GDB
●
Delta debugging B)
END OF PART I Questions welcome...