Debugging with GDB the Gnu Source-Level Debugger
Total Page:16
File Type:pdf, Size:1020Kb
Debugging with GDB The gnu Source-Level Debugger Eighth Edition, for GDB version 5.0 March 2000 Richard Stallman, Roland Pesch, Stan Shebs, et al. (Send bugs and comments on GDB to [email protected].) Debugging with GDB TEXinfo 1999-09-25.10 Copyright c 1988-2000 Free Software Foundation, Inc. Published by the Free Software Foundation 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA ISBN 1-882114-77-9 Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided also that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another lan- guage, under the above conditions for modified versions. i Table of Contents Summary of GDB............................. 1 Free software ................................................ 1 Contributors to GDB......................................... 1 1 A Sample GDB Session .................... 5 2 Getting In and Out of GDB ................ 9 2.1 Invoking GDB .......................................... 9 2.1.1 Choosing files ................................. 10 2.1.2 Choosing modes ............................... 11 2.2 Quitting GDB ......................................... 13 2.3 Shell commands ........................................ 13 3 GDB Commands ......................... 15 3.1 Command syntax ...................................... 15 3.2 Command completion .................................. 15 3.3 Getting help ........................................... 17 4 Running Programs Under GDB ........... 21 4.1 Compiling for debugging ................................ 21 4.2 Starting your program .................................. 21 4.3 Your program's arguments .............................. 22 4.4 Your program's environment ............................ 23 4.5 Your program's working directory ....................... 24 4.6 Your program's input and output........................ 24 4.7 Debugging an already-running process ................... 25 4.8 Killing the child process ................................ 26 4.9 Debugging programs with multiple threads ............... 26 4.10 Debugging programs with multiple processes ............ 28 5 Stopping and Continuing .................. 31 5.1 Breakpoints, watchpoints, and catchpoints ............... 31 5.1.1 Setting breakpoints ............................ 32 5.1.2 Setting watchpoints ............................ 35 5.1.3 Setting catchpoints ............................ 37 5.1.4 Deleting breakpoints ........................... 38 5.1.5 Disabling breakpoints .......................... 39 5.1.6 Break conditions............................... 40 5.1.7 Breakpoint command lists ...................... 41 5.1.8 Breakpoint menus ............................. 42 5.1.9 \Cannot insert breakpoints" .................... 43 ii Debugging with GDB 5.2 Continuing and stepping ................................ 44 5.3 Signals ................................................ 46 5.4 Stopping and starting multi-thread programs ............. 48 6 Examining the Stack ...................... 51 6.1 Stack frames ........................................... 51 6.2 Backtraces............................................. 52 6.3 Selecting a frame ....................................... 53 6.4 Information about a frame .............................. 54 7 Examining Source Files ................... 55 7.1 Printing source lines .................................... 55 7.2 Searching source files ................................... 56 7.3 Specifying source directories ............................ 57 7.4 Source and machine code ............................... 57 8 Examining Data .......................... 61 8.1 Expressions ............................................ 61 8.2 Program variables ...................................... 62 8.3 Artificial arrays ........................................ 63 8.4 Output formats ........................................ 64 8.5 Examining memory..................................... 65 8.6 Automatic display...................................... 66 8.7 Print settings .......................................... 68 8.8 Value history .......................................... 73 8.9 Convenience variables .................................. 74 8.10 Registers ............................................. 75 8.11 Floating point hardware ............................... 76 9 Using GDB with Different Languages ...... 77 9.1 Switching between source languages ..................... 77 9.1.1 List of filename extensions and languages ........ 77 9.1.2 Setting the working language ................... 78 9.1.3 Having GDB infer the source language .......... 78 9.2 Displaying the language ................................ 78 9.3 Type and range checking................................ 79 9.3.1 An overview of type checking ................... 79 9.3.2 An overview of range checking .................. 80 9.4 Supported languages ................................... 81 9.4.1 C and C++ .................................... 81 9.4.1.1 C and C++ operators .................. 82 9.4.1.2 C and C++ constants .................. 83 9.4.1.3 C++ expressions ....................... 84 9.4.1.4 C and C++ defaults ................... 85 9.4.1.5 C and C++ type and range checks ...... 85 9.4.1.6 GDB and C .......................... 86 9.4.1.7 GDB features for C++ ................. 86 iii 9.4.2 Modula-2 ..................................... 87 9.4.2.1 Operators ............................ 87 9.4.2.2 Built-in functions and procedures ...... 89 9.4.2.3 Constants ............................ 90 9.4.2.4 Modula-2 defaults ..................... 90 9.4.2.5 Deviations from standard Modula-2 .... 90 9.4.2.6 Modula-2 type and range checks........ 91 9.4.2.7 The scope operators :: and . .......... 91 9.4.2.8 GDB and Modula-2 ................... 91 9.4.3 Chill.......................................... 92 9.4.3.1 How modes are displayed .............. 92 9.4.3.2 Locations and their accesses ........... 94 9.4.3.3 Values and their Operations ........... 94 9.4.3.4 Chill type and range checks ............ 96 9.4.3.5 Chill defaults ......................... 97 10 Examining the Symbol Table ............. 99 11 Altering Execution ..................... 103 11.1 Assignment to variables .............................. 103 11.2 Continuing at a different address ...................... 104 11.3 Giving your program a signal ......................... 105 11.4 Returning from a function ............................ 105 11.5 Calling program functions ............................ 106 11.6 Patching programs ................................... 106 12 GDB Files ............................. 107 12.1 Commands to specify files ............................ 107 12.2 Errors reading symbol files ............................ 111 13 Specifying a Debugging Target .......... 113 13.1 Active targets........................................ 113 13.2 Commands for managing targets ...................... 113 13.3 Choosing target byte order............................ 115 13.4 Remote debugging ................................... 115 13.4.1 The GDB remote serial protocol .............. 116 13.4.1.1 What the stub can do for you ........ 117 13.4.1.2 What you must do for the stub ...... 117 13.4.1.3 Putting it all together ............... 119 13.4.1.4 Communication protocol ............ 120 13.4.1.5 Using the gdbserver program ....... 132 13.4.1.6 Using the gdbserve.nlm program .... 133 13.5 Kernel Object Display ................................ 134 iv Debugging with GDB 14 Configuration-Specific Information....... 135 14.1 Native .............................................. 135 14.1.1 HP-UX ..................................... 135 14.1.2 SVR4 process information .................... 135 14.2 Embedded Operating Systems......................... 136 14.2.1 Using GDB with VxWorks ................... 136 14.2.1.1 Connecting to VxWorks ............. 136 14.2.1.2 VxWorks download ................. 137 14.2.1.3 Running tasks ...................... 137 14.3 Embedded Processors ................................ 138 14.3.1 AMD A29K Embedded ...................... 138 14.3.1.1 A29K UDI ......................... 138 14.3.1.2 EBMON protocol for AMD29K ...... 138 14.3.1.3 Communications setup .............. 138 14.3.1.4 EB29K cross-debugging ............. 140 14.3.1.5 Remote log ......................... 140 14.3.2 ARM ....................................... 140 14.3.3 Hitachi H8/300.............................. 141 14.3.3.1 Connecting to Hitachi boards ........ 141 14.3.3.2 Using the E7000 in-circuit emulator .. 143 14.3.3.3 Special GDB commands for Hitachi micros ........................................ 143 14.3.4 H8/500 ..................................... 143 14.3.5 Intel i960 ................................... 143 14.3.5.1 Startup with Nindy ................. 144 14.3.5.2 Options for Nindy .................. 144 14.3.5.3 Nindy reset command ............... 145 14.3.6 Mitsubishi M32R/D ......................... 145 14.3.7 M68k ....................................... 145 14.3.8 M88K ...................................... 145 14.3.9 MIPS Embedded ............................ 146 14.3.10 PowerPC .................................. 147 14.3.11 HP PA Embedded .......................... 148 14.3.12 Hitachi SH