Debugging with GDB Manual The GNU Source-Level Debugger (769148-001, March 2014)
Contents
HP secure development lifecycle....................................................................11
Summary of GDB........................................................................................12
Free Software.........................................................................................................................12
Contributors to GDB................................................................................................................12
1 A Sample GDB Session.............................................................................15
Loading the Executable...........................................................................................................15
Setting Display width..............................................................................................................16
Setting Breakpoints.................................................................................................................16
Running the executable under GDB...........................................................................................16
Stepping to the next line in the source program..........................................................................16
Stepping into a subroutine.......................................................................................................16
Examining the Stack................................................................................................................16
Printing Variable Values...........................................................................................................17
Listing Source Code................................................................................................................17
Setting Variable Values During a Session...................................................................................18
2 Getting In and Out of GDB........................................................................19
Invoking GDB........................................................................................................................19
Choosing files...................................................................................................................19
Choosing modes................................................................................................................20
Redirecting HP WDB input and output to a file.......................................................................22
Quitting GDB.........................................................................................................................23
Shell commands.....................................................................................................................23
3 GDB Commands......................................................................................24
Command syntax....................................................................................................................24
Command completion.............................................................................................................24
Getting help..........................................................................................................................25
4 Running Programs Under GDB...................................................................28
Compiling for debugging........................................................................................................28
Starting your program.............................................................................................................28
Arguments To Your Program.....................................................................................................29
Program Environment..............................................................................................................29
Working directory..................................................................................................................30
Program Input and Output.......................................................................................................30
Debugging a Running Process..................................................................................................31
Killing the child process...........................................................................................................32
Debugging programs with multiple threads................................................................................32
Debugging programs with multiple processes.............................................................................34
5 Stopping and Continuing..........................................................................36
Breakpoints............................................................................................................................36
Setting breakpoints............................................................................................................36
Setting catchpoints.............................................................................................................39
Deleting breakpoints..........................................................................................................40
Disabling breakpoints.........................................................................................................41
Break conditions................................................................................................................41
Breakpoint command lists...................................................................................................43
Breakpoint menus..............................................................................................................44
Cannot insert breakpoints...................................................................................................44
Continuing and stepping.........................................................................................................45
Contents 3