Debugging with GDB The gnu Source-Level Debugger Ninth Edition, for GDB version 5.3 December 2001 Richard Stallman, Roland Pesch, Stan Shebs, et al. (Send bugs and comments on GDB to [email protected].) Debugging with GDB TEXinfo 2002-06-04.06 Copyright c 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002 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 copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the Invariant Sections being \Free Software" and \Free Software Needs Free Documentation", with the Front-Cover Texts being \A GNU Manual," and with the Back-Cover Texts as in (a) below. (a) The Free Software Foundation's Back-Cover Text is: \You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development." i Table of Contents Summary of GDB............................. 1 Free software ................................................ 1 Free Software Needs Free Documentation ...................... 1 Contributors to GDB......................................... 3 1 A Sample GDB Session .................... 7 2 Getting In and Out of GDB ............... 11 2.1 Invoking GDB ......................................... 11 2.1.1 Choosing files ................................. 12 2.1.2 Choosing modes ............................... 13 2.2 Quitting GDB ......................................... 15 2.3 Shell commands ........................................ 15 3 GDB Commands ......................... 17 3.1 Command syntax ...................................... 17 3.2 Command completion .................................. 17 3.3 Getting help ........................................... 19 4 Running Programs Under GDB ........... 23 4.1 Compiling for debugging ................................ 23 4.2 Starting your program .................................. 24 4.3 Your program's arguments .............................. 25 4.4 Your program's environment ............................ 25 4.5 Your program's working directory ....................... 26 4.6 Your program's input and output........................ 26 4.7 Debugging an already-running process ................... 27 4.8 Killing the child process ................................ 28 4.9 Debugging programs with multiple threads ............... 28 4.10 Debugging programs with multiple processes ............ 30 5 Stopping and Continuing .................. 33 5.1 Breakpoints, watchpoints, and catchpoints ............... 33 5.1.1 Setting breakpoints ............................ 34 5.1.2 Setting watchpoints ............................ 37 5.1.3 Setting catchpoints ............................ 39 5.1.4 Deleting breakpoints ........................... 40 5.1.5 Disabling breakpoints .......................... 41 5.1.6 Break conditions............................... 42 5.1.7 Breakpoint command lists ...................... 43 5.1.8 Breakpoint menus ............................. 44 ii Debugging with GDB 5.1.9 \Cannot insert breakpoints" .................... 45 5.2 Continuing and stepping ................................ 45 5.3 Signals ................................................ 48 5.4 Stopping and starting multi-thread programs ............. 50 6 Examining the Stack ...................... 53 6.1 Stack frames ........................................... 53 6.2 Backtraces............................................. 54 6.3 Selecting a frame ....................................... 55 6.4 Information about a frame .............................. 56 7 Examining Source Files ................... 57 7.1 Printing source lines .................................... 57 7.2 Searching source files ................................... 58 7.3 Specifying source directories ............................ 59 7.4 Source and machine code ............................... 59 8 Examining Data .......................... 63 8.1 Expressions ............................................ 63 8.2 Program variables ...................................... 64 8.3 Artificial arrays ........................................ 65 8.4 Output formats ........................................ 66 8.5 Examining memory..................................... 67 8.6 Automatic display...................................... 68 8.7 Print settings .......................................... 70 8.8 Value history .......................................... 75 8.9 Convenience variables .................................. 76 8.10 Registers ............................................. 77 8.11 Floating point hardware ............................... 78 8.12 Vector Unit ........................................... 78 8.13 Memory region attributes .............................. 78 8.13.1 Attributes ................................... 79 8.13.1.1 Memory Access Mode ................ 79 8.13.1.2 Memory Access Size.................. 80 8.13.1.3 Data Cache.......................... 80 8.14 Copy between memory and a file ....................... 80 9 C Preprocessor Macros ................... 83 iii 10 Tracepoints ............................. 87 10.1 Commands to Set Tracepoints.......................... 87 10.1.1 Create and Delete Tracepoints ................. 87 10.1.2 Enable and Disable Tracepoints................ 88 10.1.3 Tracepoint Passcounts ........................ 88 10.1.4 Tracepoint Action Lists ....................... 89 10.1.5 Listing Tracepoints ........................... 90 10.1.6 Starting and Stopping Trace Experiment ....... 91 10.2 Using the collected data ............................... 91 10.2.1 tfind n...................................... 91 10.2.2 tdump ....................................... 93 10.2.3 save-tracepoints filename ................... 94 10.3 Convenience Variables for Tracepoints .................. 94 11 Debugging Programs That Use Overlays .. 97 11.1 How Overlays Work ................................... 97 11.2 Overlay Commands ................................... 98 11.3 Automatic Overlay Debugging ........................ 100 11.4 Overlay Sample Program ............................. 101 12 Using GDB with Different Languages .... 103 12.1 Switching between source languages ................... 103 12.1.1 List of filename extensions and languages ...... 103 12.1.2 Setting the working language ................. 104 12.1.3 Having GDB infer the source language ........ 104 12.2 Displaying the language .............................. 104 12.3 Type and range checking ............................. 105 12.3.1 An overview of type checking ................. 105 12.3.2 An overview of range checking ................ 106 12.4 Supported languages ................................. 107 12.4.1 C and C++ .................................. 107 12.4.1.1 C and C++ operators ................ 108 12.4.1.2 C and C++ constants ................ 109 12.4.1.3 C++ expressions..................... 110 12.4.1.4 C and C++ defaults ................. 111 12.4.1.5 C and C++ type and range checks .... 111 12.4.1.6 GDB and C ........................ 111 12.4.1.7 GDB features for C++ ............... 112 12.4.2 Modula-2 ................................... 113 12.4.2.1 Operators .......................... 113 12.4.2.2 Built-in functions and procedures .... 114 12.4.2.3 Constants .......................... 115 12.4.2.4 Modula-2 defaults................... 116 12.4.2.5 Deviations from standard Modula-2 .. 116 12.4.2.6 Modula-2 type and range checks ..... 116 12.4.2.7 The scope operators :: and . ........ 117 12.4.2.8 GDB and Modula-2 ................. 117 iv Debugging with GDB 13 Examining the Symbol Table ............ 119 14 Altering Execution ..................... 123 14.1 Assignment to variables .............................. 123 14.2 Continuing at a different address ...................... 124 14.3 Giving your program a signal ......................... 125 14.4 Returning from a function ............................ 125 14.5 Calling program functions ............................ 126 14.6 Patching programs ................................... 126 15 GDB Files ............................. 127 15.1 Commands to specify files ............................ 127 15.2 Errors reading symbol files ............................ 132 16 Specifying a Debugging Target .......... 135 16.1 Active targets........................................ 135 16.2 Commands for managing targets ...................... 135 16.3 Choosing target byte order............................ 137 16.4 Remote debugging ................................... 137 16.5 Kernel Object Display ................................ 138 17 Debugging remote programs ............ 139 17.1 Using the gdbserver program......................... 139 17.2 Using the gdbserve.nlm program ..................... 140 17.3 Implementing a remote stub .......................... 141 17.3.1 What the stub can do for you ................ 142 17.3.2 What you must do for the stub ............... 142 17.3.3 Putting it all together ....................... 144 18 Configuration-Specific Information....... 147 18.1 Native .............................................. 147 18.1.1 HP-UX ..................................... 147 18.1.2 SVR4 process information .................... 147 18.1.3 Features for Debugging djgpp Programs ...... 147 18.1.4 Features for Debugging MS Windows PE executables ....................................
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages332 Page
-
File Size-