Debugging with GDB Manual (5900-1473; WDB 6.2; January 2011)

Table Of Contents
Contents
Summary of GDB.....................................................................................................................14
Free Software.........................................................................................................14
Contributors to GDB...............................................................................................14
1 A Sample GDB Session..........................................................................................................18
1.1 Loading the Executable......................................................................................19
1.2 Setting Display width.........................................................................................19
1.3 Setting Breakpoints............................................................................................19
1.4 Running the executable under GDB.....................................................................19
1.5 Stepping to the next line in the source program.....................................................20
1.6 Stepping into a subroutine.................................................................................20
1.7 Examining the Stack..........................................................................................20
1.8 Printing Variable Values.....................................................................................21
1.9 Listing Source Code...........................................................................................21
1.10 Setting Variable Values During a Session............................................................21
2 Getting In and Out of GDB.....................................................................................................23
2.1 Invoking GDB...................................................................................................23
2.1.1 Choosing files............................................................................................24
2.1.2 Choosing modes........................................................................................25
2.1.3 Redirecting HP WDB input and output to a file...............................................28
2.2 Quitting GDB...................................................................................................28
2.3 Shell commands...............................................................................................29
3 GDB Commands...................................................................................................................30
3.1 Command syntax..............................................................................................30
3.2 Command completion.......................................................................................30
3.3 Getting help....................................................................................................32
4 Running Programs Under GDB................................................................................................35
4.1 Compiling for debugging...................................................................................35
4.2 Starting your program.......................................................................................35
4.3 Arguments To Your Program...............................................................................36
4.4 Program Environment........................................................................................37
4.5 Working directory............................................................................................38
4.6 Program Input and Output.................................................................................38
4.7 Debugging a Running Process............................................................................39
4.8 Killing the child process.....................................................................................40
4.9 Debugging programs with multiple threads..........................................................41
Contents 3