GDB Hardware Debugging

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Choosing files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.2 Choosing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Quitting GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 Shell commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 GDB Commands . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.1 3.2 3.3 4 Command syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Command completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Getting help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Running Programs Under GDB . . . . . . . . . . . 23 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 5 11 12 13 15 15 Compiling for debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Starting your program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Your program’s arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Your program’s environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . Your program’s working directory . . . . . . . . . . . . . . . . . . . . . . . Your program’s input and output . . . . . . . . . . . . . . . . . . . . . . . . Debugging an already-running process . . . . . . . . . . . . . . . . . . . Killing the child process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debugging programs with multiple threads . . . . . . . . . . . . . . . Debugging programs with multiple processes . . . . . . . . . . . . 23 24 25 25 26 26 27 28 28 30 Stopping and Continuing . . . . . . . . . . . . . . . . . . 33 5.1 Breakpoints, watchpoints, and catchpoints . . . . . . . . . . . . . . . 5.1.1 Setting breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.2 Setting watchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3 Setting catchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.4 Deleting breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.5 Disabling breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.6 Break conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.7 Breakpoint command lists . . . . . . . . . . . . . . . . . . . . . . 5.1.8 Breakpoint menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 34 37 39 40 41 42 43 44 ii Debugging with GDB 5.2 5.3 5.4 6 Stack frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Selecting a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Information about a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Printing source lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Searching source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Specifying source directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . Source and machine code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 58 59 59 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . 63 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 8.11 8.12 8.13 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Program variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Artificial arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Output formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examining memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Automatic display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Print settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Value history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Convenience variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Floating point hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Vector Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Memory region attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.13.1 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.13.1.1 Memory Access Mode . . . . . . . . . . . . . . . . 8.13.1.2 Memory Access Size . . . . . . . . . . . . . . . . . . 8.13.1.3 Data Cache . . . . . . . . . . . . . . . . . . . . . . . . . . 8.14 Copy between memory and a file . . . . . . . . . . . . . . . . . . . . . . . 9 53 54 55 56 Examining Source Files . . . . . . . . . . . . . . . . . . . 57 7.1 7.2 7.3 7.4 8 45 45 48 50 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . 53 6.1 6.2 6.3 6.4 7 5.1.9 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . Continuing and stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stopping and starting multi-thread programs . . . . . . . . . . . . . 63 64 65 66 67 68 70 75 76 77 78 78 78 79 79 80 80 80 C Preprocessor Macros . . . . . . . . . . . . . . . . . . . 83 iii 10 Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 10.1 Commands to Set Tracepoints. . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.1 Create and Delete Tracepoints . . . . . . . . . . . . . . . . . 10.1.2 Enable and Disable Tracepoints. . . . . . . . . . . . . . . . 10.1.3 Tracepoint Passcounts . . . . . . . . . . . . . . . . . . . . . . . . 10.1.4 Tracepoint Action Lists . . . . . . . . . . . . . . . . . . . . . . . 10.1.5 Listing Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.6 Starting and Stopping Trace Experiment . . . . . . . 10.2 Using the collected data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2.1 tfind n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2.2 tdump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2.3 save-tracepoints filename . . . . . . . . . . . . . . . . . . . 10.3 Convenience Variables for Tracepoints . . . . . . . . . . . . . . . . . . 11 Debugging Programs That Use Overlays . . 97 11.1 11.2 11.3 11.4 12 87 87 88 88 89 90 91 91 91 93 94 94 How Overlays Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Overlay Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Automatic Overlay Debugging . . . . . . . . . . . . . . . . . . . . . . . . 100 Overlay Sample Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Using GDB with Different Languages . . . . 103 12.1 12.2 12.3 12.4 Switching between source languages . . . . . . . . . . . . . . . . . . . 12.1.1 List of filename extensions and languages . . . . . . 12.1.2 Setting the working language . . . . . . . . . . . . . . . . . 12.1.3 Having GDB infer the source language . . . . . . . . Displaying the language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Type and range checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.3.1 An overview of type checking . . . . . . . . . . . . . . . . . 12.3.2 An overview of range checking . . . . . . . . . . . . . . . . Supported languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1 C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1.1 C and C++ operators . . . . . . . . . . . . . . . . 12.4.1.2 C and C++ constants . . . . . . . . . . . . . . . . 12.4.1.3 C++ expressions . . . . . . . . . . . . . . . . . . . . . 12.4.1.4 C and C++ defaults . . . . . . . . . . . . . . . . . 12.4.1.5 C and C++ type and range checks . . . . 12.4.1.6 GDB and C . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1.7 GDB features for C++ . . . . . . . . . . . . . . . 12.4.2 Modula-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.2.1 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.2.2 Built-in functions and procedures . . . . 12.4.2.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.2.4 Modula-2 defaults . . . . . . . . . . . . . . . . . . . 12.4.2.5 Deviations from standard Modula-2 . . 12.4.2.6 Modula-2 type and range checks . . . . . 12.4.2.7 The scope operators :: and . . . . . . . . . 12.4.2.8 GDB and Modula-2 . . . . . . . . . . . . . . . . . 103 103 104 104 104 105 105 106 107 107 108 109 110 111 111 111 112 113 113 114 115 116 116 116 117 117 iv Debugging with GDB 13 Examining the Symbol Table . . . . . . . . . . . . 119 14 Altering Execution . . . . . . . . . . . . . . . . . . . . . 123 14.1 14.2 14.3 14.4 14.5 14.6 15 Active targets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Commands for managing targets . . . . . . . . . . . . . . . . . . . . . . Choosing target byte order. . . . . . . . . . . . . . . . . . . . . . . . . . . . Remote debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Kernel Object Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 135 137 137 138 Debugging remote programs . . . . . . . . . . . . 139 17.1 17.2 17.3 18 Commands to specify files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Errors reading symbol files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Specifying a Debugging Target . . . . . . . . . . 135 16.1 16.2 16.3 16.4 16.5 17 123 124 125 125 126 126 GDB Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 15.1 15.2 16 Assignment to variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Continuing at a different address . . . . . . . . . . . . . . . . . . . . . . Giving your program a signal . . . . . . . . . . . . . . . . . . . . . . . . . Returning from a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . Calling program functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . Patching programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the gdbserver program. . . . . . . . . . . . . . . . . . . . . . . . . Using the gdbserve.nlm program . . . . . . . . . . . . . . . . . . . . . Implementing a remote stub . . . . . . . . . . . . . . . . . . . . . . . . . . 17.3.1 What the stub can do for you . . . . . . . . . . . . . . . . 17.3.2 What you must do for the stub . . . . . . . . . . . . . . . 17.3.3 Putting it all together . . . . . . . . . . . . . . . . . . . . . . . 139 140 141 142 142 144 Configuration-Specific Information . . . . . . . 147 18.1 Native . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.1 HP-UX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.2 SVR4 process information . . . . . . . . . . . . . . . . . . . . 18.1.3 Features for Debugging djgpp Programs . . . . . . 18.1.4 Features for Debugging MS Windows PE executables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.2 Embedded Operating Systems. . . . . . . . . . . . . . . . . . . . . . . . . 18.2.1 Using GDB with VxWorks . . . . . . . . . . . . . . . . . . . 18.2.1.1 Connecting to VxWorks . . . . . . . . . . . . . 18.2.1.2 VxWorks download . . . . . . . . . . . . . . . . . 18.2.1.3 Running tasks . . . . . . . . . . . . . . . . . . . . . . 18.3 Embedded Processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.1 ARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.2 Hitachi H8/300 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.2.1 Connecting to Hitachi boards . . . . . . . . 18.3.2.2 Using the E7000 in-circuit emulator . . 147 147 147 147 149 150 150 151 151 152 152 152 152 153 154 v 18.4 19 Controlling GDB . . . . . . . . . . . . . . . . . . . . . . . 165 19.1 19.2 19.3 19.4 19.5 19.6 19.7 20 18.3.2.3 Special GDB commands for Hitachi micros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 18.3.3 H8/500 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 18.3.4 Intel i960 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 18.3.4.1 Startup with Nindy . . . . . . . . . . . . . . . . . 156 18.3.4.2 Options for Nindy . . . . . . . . . . . . . . . . . . 156 18.3.4.3 Nindy reset command . . . . . . . . . . . . . . . 156 18.3.5 Mitsubishi M32R/D . . . . . . . . . . . . . . . . . . . . . . . . . 156 18.3.6 M68k . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 18.3.7 MIPS Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 18.3.8 PowerPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 18.3.9 HP PA Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 18.3.10 Hitachi SH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 18.3.11 Tsqware Sparclet . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 18.3.11.1 Setting file to debug. . . . . . . . . . . . . . . . 160 18.3.11.2 Connecting to Sparclet . . . . . . . . . . . . . 160 18.3.11.3 Sparclet download . . . . . . . . . . . . . . . . . 161 18.3.11.4 Running and debugging . . . . . . . . . . . . 161 18.3.12 Fujitsu Sparclite . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 18.3.13 Tandem ST2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 18.3.14 Zilog Z8000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 18.4.1 A29K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 18.4.2 Alpha . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 18.4.3 MIPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Screen size. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Optional warnings and messages . . . . . . . . . . . . . . . . . . . . . . Optional messages about internal happenings. . . . . . . . . . . Canned Sequences of Commands . . . . . . . . 171 20.1 User-defined commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20.2 User-defined command hooks . . . . . . . . . . . . . . . . . . . . . . . . . 20.3 Command files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20.4 Commands for controlled output . . . . . . . . . . . . . . . . . . . . . . 21 165 165 165 167 167 168 169 171 172 173 174 GDB Text User Interface . . . . . . . . . . . . . . . 177 21.1 21.2 21.3 21.4 21.5 TUI TUI TUI TUI TUI overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Single Key Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . specific commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . configuration variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 178 179 179 180 vi Debugging with GDB 22 Using GDB under gnu Emacs . . . . . . . . . . . 183 23 GDB Annotations . . . . . . . . . . . . . . . . . . . . . . 185 23.1 23.2 23.3 23.4 23.5 23.6 23.7 23.8 23.9 23.10 23.11 23.12 24 What is an Annotation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Server Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Annotation for GDB Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Information on Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . Invalidation Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displaying Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Annotations We Might Want in the Future . . . . . . . . . . . . The gdb/mi Interface . . . . . . . . . . . . . . . . . . . 193 Function and Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Notation and Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.1 gdb/mi Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.1.1 gdb/mi Input Syntax . . . . . . . . . . . . . . . . . . . . . . . . 24.1.2 gdb/mi Output Syntax . . . . . . . . . . . . . . . . . . . . . . 24.1.3 Simple Examples of gdb/mi Interaction . . . . . . . 24.2 gdb/mi Compatibility with CLI . . . . . . . . . . . . . . . . . . . . . . . 24.3 gdb/mi Output Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.3.1 gdb/mi Result Records . . . . . . . . . . . . . . . . . . . . . . 24.3.2 gdb/mi Stream Records . . . . . . . . . . . . . . . . . . . . . 24.3.3 gdb/mi Out-of-band Records . . . . . . . . . . . . . . . . . 24.4 gdb/mi Command Description Format . . . . . . . . . . . . . . . . 24.5 gdb/mi Breakpoint table commands. . . . . . . . . . . . . . . . . . . 24.6 gdb/mi Data Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.7 gdb/mi Program control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.8 Miscellaneous GDB commands in gdb/mi. . . . . . . . . . . . . . 24.9 gdb/mi Stack Manipulation Commands . . . . . . . . . . . . . . . 24.10 gdb/mi Symbol Query Commands . . . . . . . . . . . . . . . . . . . 24.11 gdb/mi Target Manipulation Commands . . . . . . . . . . . . . 24.12 gdb/mi Thread Commands . . . . . . . . . . . . . . . . . . . . . . . . . . 24.13 gdb/mi Tracepoint Commands. . . . . . . . . . . . . . . . . . . . . . . 24.14 gdb/mi Variable Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 185 185 186 187 189 189 190 190 191 191 192 192 193 193 193 193 194 196 197 197 197 197 198 198 199 207 217 227 229 234 237 242 244 244 Reporting Bugs in GDB . . . . . . . . . . . . . . . . 249 25.1 25.2 Have you found a bug? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 How to report bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 vii 26 Command Line Editing . . . . . . . . . . . . . . . . . 253 26.1 26.2 26.3 26.4 26.5 27 Introduction to Line Editing . . . . . . . . . . . . . . . . . . . . . . . . . . Readline Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26.2.1 Readline Bare Essentials . . . . . . . . . . . . . . . . . . . . . 26.2.2 Readline Movement Commands . . . . . . . . . . . . . . . 26.2.3 Readline Killing Commands . . . . . . . . . . . . . . . . . . 26.2.4 Readline Arguments . . . . . . . . . . . . . . . . . . . . . . . . . 26.2.5 Searching for Commands in the History . . . . . . . Readline Init File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26.3.1 Readline Init File Syntax . . . . . . . . . . . . . . . . . . . . . 26.3.2 Conditional Init Constructs . . . . . . . . . . . . . . . . . . 26.3.3 Sample Init File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bindable Readline Commands . . . . . . . . . . . . . . . . . . . . . . . . . 26.4.1 Commands For Moving . . . . . . . . . . . . . . . . . . . . . . 26.4.2 Commands For Manipulating The History . . . . . 26.4.3 Commands For Changing Text . . . . . . . . . . . . . . . 26.4.4 Killing And Yanking . . . . . . . . . . . . . . . . . . . . . . . . . 26.4.5 Specifying Numeric Arguments . . . . . . . . . . . . . . . 26.4.6 Letting Readline Type For You . . . . . . . . . . . . . . . 26.4.7 Keyboard Macros. . . . . . . . . . . . . . . . . . . . . . . . . . . . 26.4.8 Some Miscellaneous Commands . . . . . . . . . . . . . . . Readline vi Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 253 253 254 254 255 255 256 256 260 261 264 264 264 265 266 267 268 268 269 270 Using History Interactively. . . . . . . . . . . . . . 271 27.1 History 27.1.1 27.1.2 27.1.3 Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Designators . . . . . . . . . . . . . . . . . . . . . . . . . . . Word Designators . . . . . . . . . . . . . . . . . . . . . . . . . . . Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 271 272 272 Appendix A Formatting Documentation . . . . 275 Appendix B Installing GDB . . . . . . . . . . . . . . . . 277 B.1 B.2 B.3 Compiling GDB in another directory . . . . . . . . . . . . . . . . . . . 278 Specifying names for hosts and targets . . . . . . . . . . . . . . . . . 279 configure options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 Appendix C Maintenance Commands . . . . . . . 281 Appendix D GDB Remote Serial Protocol . . 283 D.1 D.2 D.3 D.4 D.5 D.6 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stop Reply Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . General Query Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Register Packet Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 284 289 290 292 293 viii Debugging with GDB Appendix E GNU GENERAL PUBLIC LICENSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION . . . . . . . . . . . . . . . 296 How to Apply These Terms to Your New Programs . . . . . . . . . . . 300 Appendix F GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 ADDENDUM: How to use this License for your documents . . . . 308 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Table of Contents q q q q q Summary of GDB r Free software r Free Software Needs Free Documentation r Contributors to GDB A Sample GDB Session Getting In and Out of GDB r Invoking GDB s Choosing files s Choosing modes r Quitting GDB r Shell commands GDB Commands r Command syntax r Command completion r Getting help Running Programs Under GDB r Compiling for debugging r Starting your program r Your program's arguments r Your program's environment r Your program's working directory r Your program's input and output file:///C|/gdb.html (1 of 352)19. 1. 2004 20:32:03 Debugging with GDB Debugging an already-running process r Killing the child process r Debugging programs with multiple threads r Debugging programs with multiple processes Stopping and Continuing r Breakpoints, watchpoints, and catchpoints s Setting breakpoints s Setting watchpoints s Setting catchpoints s Deleting breakpoints s Disabling breakpoints s Break conditions s Breakpoint command lists s Breakpoint menus s "Cannot insert breakpoints" r Continuing and stepping r Signals r Stopping and starting multi-thread programs Examining the Stack r Stack frames r Backtraces r Selecting a frame r Information about a frame Examining Source Files r Printing source lines r Searching source files r Specifying source directories r Source and machine code Examining Data r Expressions r Program variables r Artificial arrays r Output formats r Examining memory r Automatic display r Print settings r Value history r Convenience variables r q q q q file:///C|/gdb.html (2 of 352)19. 1. 2004 20:32:03 Debugging with GDB Registers r Floating point hardware r Memory Region Attributes s Attributes s Memory Access Mode s Memory Access Size s Data Cache Tracepoints r Commands to Set Tracepoints s Create and Delete Tracepoints s Enable and Disable Tracepoints s Tracepoint Passcounts s Tracepoint Action Lists s Listing Tracepoints s Starting and Stopping Trace Experiment r Using the collected data s tfind n s tdump s save-tracepoints filename r Convenience Variables for Tracepoints Using GDB with Different Languages r Switching between source languages s List of filename extensions and languages s Setting the working language s Having GDB infer the source language r Displaying the language r Type and range checking s An overview of type checking s An overview of range checking r Supported languages s C and C++ s C and C++ operators s C and C++ constants s C++ expressions s C and C++ defaults s C and C++ type and range checks s GDB and C s GDB features for C++ r q q file:///C|/gdb.html (3 of 352)19. 1. 2004 20:32:03 Debugging with GDB Modula-2 s Operators s Built-in functions and procedures s Constants s Modula-2 defaults s Deviations from standard Modula-2 s Modula-2 type and range checks s The scope operators :: and . s GDB and Modula-2 s Chill s How modes are displayed s Locations and their accesses s Values and their Operations s Chill type and range checks s Chill defaults Examining the Symbol Table Altering Execution r Assignment to variables r Continuing at a different address r Giving your program a signal r Returning from a function r Calling program functions r Patching programs GDB Files r Commands to specify files r Errors reading symbol files Specifying a Debugging Target r Active targets r Commands for managing targets r Choosing target byte order r Remote debugging s The GDB remote serial protocol s What the stub can do for you s What you must do for the stub s Putting it all together s Communication protocol s Using the gdbserver program s Using the gdbserve.nlm program s q q q q file:///C|/gdb.html (4 of 352)19. 1. 2004 20:32:03 Debugging with GDB Kernel Object Display Configuration-Specific Information r Native s HP-UX s SVR4 process information s Features for Debugging DJGPP Programs r Embedded Operating Systems s Using GDB with VxWorks s Connecting to VxWorks s VxWorks download s Running tasks r Embedded Processors s AMD A29K Embedded s A29K UDI s EBMON protocol for AMD29K s Communications setup s EB29K cross-debugging s Remote log s ARM s Hitachi H8/300 s Connecting to Hitachi boards s Using the E7000 in-circuit emulator s Special GDB commands for Hitachi micros s H8/500 s Intel i960 s Startup with Nindy s Options for Nindy s Nindy reset command s Mitsubishi M32R/D s M68k s M88K s MIPS Embedded s PowerPC s HP PA Embedded s Hitachi SH s Tsqware Sparclet s Setting file to debug s Connecting to Sparclet r q file:///C|/gdb.html (5 of 352)19. 1. 2004 20:32:03 Debugging with GDB Sparclet download s Running and debugging s Fujitsu Sparclite s Tandem ST2000 s Zilog Z8000 r Architectures s A29K s Alpha s MIPS Controlling GDB r Prompt r Command editing r Command history r Screen size r Numbers r Optional warnings and messages r Optional messages about internal happenings Canned Sequences of Commands r User-defined commands r User-defined command hooks r Command files r Commands for controlled output GDB Text User Interface r TUI overview r TUI Key Bindings r TUI specific commands r TUI configuration variables Using GDB under GNU Emacs GDB Annotations r What is an Annotation? r The Server Prefix r Values r Frames r Displays r Annotation for GDB Input r Errors r Information on Breakpoints r Invalidation Notices s q q q q q file:///C|/gdb.html (6 of 352)19. 1. 2004 20:32:03 Debugging with GDB Running the Program r Displaying Source r Annotations We Might Want in the Future The GDB/MI Interface r Function and Purpose r Notation and Terminology r GDB/MI Command Syntax s GDB/MI Input Syntax s GDB/MI Output Syntax s Simple Examples of GDB/MI Interaction r GDB/MI Compatibility with CLI r GDB/MI Output Records s GDB/MI Result Records s GDB/MI Stream Records s GDB/MI Out-of-band Records r GDB/MI Command Description Format r GDB/MI Breakpoint table commands r GDB/MI Data Manipulation r GDB/MI Program control r Miscellaneous GDB commands in GDB/MI r GDB/MI Stack Manipulation Commands r GDB/MI Symbol Query Commands r GDB/MI Target Manipulation Commands r GDB/MI Thread Commands r GDB/MI Tracepoint Commands r GDB/MI Variable Objects Reporting Bugs in GDB r Have you found a bug? r How to report bugs Command Line Editing r Introduction to Line Editing r Readline Interaction s Readline Bare Essentials s Readline Movement Commands s Readline Killing Commands s Readline Arguments s Searching for Commands in the History r Readline Init File r q q q file:///C|/gdb.html (7 of 352)19. 1. 2004 20:32:03 Debugging with GDB Readline Init File Syntax s Conditional Init Constructs s Sample Init File r Bindable Readline Commands s Commands For Moving s Commands For Manipulating The History s Commands For Changing Text s Killing And Yanking s Specifying Numeric Arguments s Letting Readline Type For You s Keyboard Macros s Some Miscellaneous Commands r Readline vi Mode Using History Interactively r History Expansion s Event Designators s Word Designators s Modifiers Formatting Documentation Installing GDB r Compiling GDB in another directory r Specifying names for hosts and targets r configure options GNU Free Documentation License r ADDENDUM: How to use this License for your documents Index
Table of Contents Summary of GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Free software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Contributors to GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 A Sample GDB Session . . . . . . . . . . . . . . . . . . . . 5 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 2 Loading the Executable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Display width. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running the executable under GDB . . . . . . . . . . . . . . . . . . . . . . Stepping to the next line in the source program . . . . . . . . . . . . Stepping into a subroutine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examining the Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Printing Variable Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Listing Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Variable Values During a Session . . . . . . . . . . . . . . . . . Getting In and Out of GDB . . . . . . . . . . . . . . . 11 2.1 Invoking GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Choosing files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.2 Choosing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.3 Redirecting WDB input and output to a file . . . . . 2.2 Quitting GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 Shell commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 5 6 6 6 6 6 7 7 7 8 11 11 13 15 15 16 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 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 Compiling for debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Starting your program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arguments To Your Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . Program Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Working directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Program Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debugging a Running Process . . . . . . . . . . . . . . . . . . . . . . . . . . . Killing the child process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debugging programs with multiple threads . . . . . . . . . . . . . . . Debugging programs with multiple processes . . . . . . . . . . . . 23 23 24 25 26 26 27 28 28 31 ii 5 Debugging with GDB Stopping and Continuing . . . . . . . . . . . . . . . . . . 33 5.1 Breakpoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1 Setting breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.2 Setting catchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3 Deleting breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.4 Disabling breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.5 Break conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.6 Breakpoint command lists . . . . . . . . . . . . . . . . . . . . . . 5.1.7 Breakpoint menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.8 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . 5.2 Continuing and stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4 Stopping and starting multi-thread programs . . . . . . . . . . . . . 6 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . 51 6.1 6.2 6.3 6.4 6.5 6.6 7 Stack frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stacks Without frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Commands for Examining the Stack . . . . . . . . . . . . . . . . . . . . . Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Selecting a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Information about a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 51 52 52 53 54 Examining Source Files . . . . . . . . . . . . . . . . . . . 57 7.1 7.2 7.3 7.4 8 33 33 37 38 39 40 41 42 43 43 46 48 Printing source lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Searching source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Specifying source directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . Source and machine code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 58 59 59 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . 63 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 8.11 8.12 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Program variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Artificial arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Output formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examining memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Automatic display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Print settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Value history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Convenience variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Printing Floating Point Values . . . . . . . . . . . . . . . . . . . . . . . . . Floating point hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 64 65 66 67 68 70 74 75 76 78 78 iii 9 Using GDB with Different Languages . . . . . . 79 9.1 Switching between source languages . . . . . . . . . . . . . . . . . . . . . 9.1.1 List of filename extensions and languages . . . . . . . . 9.1.2 Setting the working language . . . . . . . . . . . . . . . . . . . 9.1.3 Having GDB infer the source language . . . . . . . . . . 9.2 Displaying the language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3 Type and range checking. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.1 An overview of type checking . . . . . . . . . . . . . . . . . . . 9.3.2 An overview of range checking . . . . . . . . . . . . . . . . . . 9.4 Supported languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.4.1 C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.4.1.1 C and C++ operators . . . . . . . . . . . . . . . . . . 9.4.1.2 C and C++ constants . . . . . . . . . . . . . . . . . . 9.4.1.3 C++ expressions . . . . . . . . . . . . . . . . . . . . . . . 9.4.1.4 C and C++ defaults . . . . . . . . . . . . . . . . . . . 9.4.1.5 C and C++ type and range checks . . . . . . 9.4.1.6 GDB and C . . . . . . . . . . . . . . . . . . . . . . . . . . 9.4.1.7 GDB features for C++ . . . . . . . . . . . . . . . . . 9.4.2 Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.4.2.1 Fortran types . . . . . . . . . . . . . . . . . . . . . . . . . 9.4.2.2 Fortran operators . . . . . . . . . . . . . . . . . . . . . 9.4.2.3 Fortran special issues . . . . . . . . . . . . . . . . . . 79 79 80 80 80 81 81 82 83 83 84 85 86 87 88 88 88 89 90 90 91 10 Examining the Symbol Table . . . . . . . . . . . . . 93 11 Altering Execution . . . . . . . . . . . . . . . . . . . . . . 97 11.1 11.2 11.3 11.4 11.5 11.6 12 Assignment to variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Continuing at a different address . . . . . . . . . . . . . . . . . . . . . . . 98 Giving your program a signal . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Returning from a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Calling program functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Patching programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 GDB Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 12.1 Commands to specify files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 12.2 Specifying shared library locations . . . . . . . . . . . . . . . . . . . . . 106 12.3 Errors reading symbol files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 13 Specifying a Debugging Target . . . . . . . . . . 109 13.1 Active targets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 13.2 Commands for managing targets . . . . . . . . . . . . . . . . . . . . . . 109 13.3 Choosing target byte order. . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 iv 14 Debugging with GDB HP-UX Configuration-Specific Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 14.1 Summary of HP Enhancements to GDB . . . . . . . . . . . . . . . 113 14.2 HP-UX dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 14.2.1 Linker Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . 115 14.2.2 Dependent Standard Library Routines for Run Time Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 14.3 Supported Platforms and Modes . . . . . . . . . . . . . . . . . . . . . . 117 14.4 HP-UX targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 14.5 Support for Alternate root . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 14.6 Specifying object file directories . . . . . . . . . . . . . . . . . . . . . . . 118 14.7 Fix and continue debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 14.7.1 Fix and Continue compiler dependencies . . . . . . 120 14.7.2 Fix and Continue restrictions . . . . . . . . . . . . . . . . . 121 14.7.3 Using Fix and Continue . . . . . . . . . . . . . . . . . . . . . . 121 14.7.4 Example Fix and Continue session . . . . . . . . . . . . 122 14.8 Inline Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 14.8.1 Inline Debugging in HP 9000 Systems . . . . . . . . . 124 14.8.2 Inline Debugging in Integrity Systems . . . . . . . . . 125 14.8.2.1 Debugging Inline Functions in Integrity Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 14.9 Debugging memory problems . . . . . . . . . . . . . . . . . . . . . . . . . 128 14.9.1 When to suspect a memory leak . . . . . . . . . . . . . . 128 14.9.2 Memory debugging restrictions . . . . . . . . . . . . . . . 128 14.9.3 Memory Debugging Methodologies . . . . . . . . . . . . 128 14.9.4 Debugging Memory in Interactive Mode . . . . . . . 129 14.9.4.1 Commands for interactive memory debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 14.9.4.2 Example for interactive debugging session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 14.9.5 Debugging Memory in Batch Mode . . . . . . . . . . . 133 14.9.5.1 Setting Configuration Options for Batch Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 14.9.5.2 Environment variable setting for Batch mode debugging . . . . . . . . . . . . . . . . . . . . . . . . . 134 14.9.5.3 Example for Batch Mode RTC . . . . . . . 135 14.9.6 Debugging Memory Interactively After Attaching to a Running Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 14.9.7 Configuring memory debugging settings . . . . . . . 137 14.9.7.1 Specifying the stack depth . . . . . . . . . . . 137 14.9.7.2 Specifying minimum leak size . . . . . . . . 138 14.9.7.3 Specifying minimum block size . . . . . . . 138 14.9.8 Scenarios in memory debugging . . . . . . . . . . . . . . . 138 14.9.8.1 Stop when freeing unallocated or deallocated blocks . . . . . . . . . . . . . . . . . . . . . . . 138 14.9.8.2 Stop when freeing a block if bad writes occurred outside block boundary . . . . . . . . . . 138 v 14.9.8.3 Stop when a specified block address is allocated or deallocated . . . . . . . . . . . . . . . . . . 139 14.9.8.4 Scramble previous memory contents at malloc/free calls . . . . . . . . . . . . . . . . . . . . . . . . . 139 14.9.9 Comparison of Memory Debugging Commands in Interactive Mode and Batch Mode . . . . . . . . . . . . . . . 140 14.9.10 Heap Profiling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 14.9.10.1 Commands for heap profiling . . . . . . . 142 14.9.10.2 info heap arena . . . . . . . . . . . . . . . . . . 143 14.9.10.3 info heap arena [0 |1|2|..] blocks stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 14.9.10.4 info module ADDRESS . . . . . . . . . . . . . . 143 14.9.10.5 info heap process . . . . . . . . . . . . . . . . 143 14.9.10.6 Example for heap profiling . . . . . . . . . . 143 14.9.11 Memory Checking Analysis for User Defined Memory Management Routines . . . . . . . . . . . . . . . . . . 144 14.9.12 Commands to track the change in data segment value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 14.10 Thread Debugging Support . . . . . . . . . . . . . . . . . . . . . . . . . . 145 14.10.1 Support for Enabling and Disabling Specific Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 14.10.2 Backtrace Support for Thread Debugging . . . . 146 14.10.3 Advanced Thread Debugging Support . . . . . . . . 146 14.10.3.1 Pre-requisites for Advanced Thread Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 14.10.3.2 Enabling and Disabling Advanced Thread Debugging Features. . . . . . . . . . . . . . . 148 14.10.3.3 Commands to view information on pthread primitives . . . . . . . . . . . . . . . . . . . . . . . 150 14.11 Debugging MPI Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 14.12 Debugging multiple processes ( programs with fork and vfork calls) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 14.12.1 Ask mode for set follow-fork-mode . . . . . . . . 151 14.12.2 serial mode for set follow-fork-mode . . . . . . . 151 14.12.3 Support for showing unwind info. . . . . . . . . . . . . 151 14.12.4 Printing CFM and PFS registers. . . . . . . . . . . . . 152 14.13 Debugging Core Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 14.13.1 Generating core files with packcore /unpackcore/getcore . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 14.13.2 Support for the dumpcore command . . . . . . . . . 153 14.13.2.1 Enhancements to the dumpcore command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 14.14 Invoking GDB Before a Program Aborts . . . . . . . . . . . . . . 154 14.15 Instruction Level Stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 14.16 Enhanced support for watchpoints and breakpoints . . . . 155 14.16.1 Deferred watchpoints . . . . . . . . . . . . . . . . . . . . . . . 155 14.16.2 Hardware watchpoints . . . . . . . . . . . . . . . . . . . . . . 155 14.16.3 Hardware breakpoints . . . . . . . . . . . . . . . . . . . . . . 155 vi Debugging with GDB 14.17 14.18 14.19 14.20 14.21 14.22 14.23 14.16.3.1 Setting breakpoints in unstripped shared library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 14.16.4 Support for procedural breakpoints . . . . . . . . . . 155 14.16.5 Support for template breakpoints . . . . . . . . . . . . 156 Debugging support for shared libraries . . . . . . . . . . . . . . . . 156 14.17.1 Using shared library as main program . . . . . . . . 157 14.17.2 Setting Deferred Breakpoints in Shared Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 14.17.3 Using catch load . . . . . . . . . . . . . . . . . . . . . . . . . . 158 14.17.4 Privately mapping shared libraries . . . . . . . . . . . 158 14.17.5 Selectively Mapping Shared Libraries As Private . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 14.17.6 Setting breakpoints in shared library . . . . . . . . . 159 Language support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 14.18.1 Enhanced Java Debugging Support . . . . . . . . . . 159 14.18.2 Commands for Examining Java Virtual Machine(JVM) internals . . . . . . . . . . . . . . . . . . . . . . . . . 159 14.18.2.1 Java subcommands . . . . . . . . . . . . . . . . 160 14.18.3 Support for stack traces in Java, C, and C++ programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 14.18.4 Support for 64-bit Java, C, aC++ stack unwinding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 14.18.5 Enhanced support for C++ templates . . . . . . . . . 161 14.18.6 Support for __fpreg data type on IPF . . . . . . . 162 14.18.7 Support for Complex variables in HP C . . . . . 162 14.18.8 Support for debugging namespaces . . . . . . . . . . . 163 14.18.9 Command for evaluating the address of an expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Viewing Wide Character Strings . . . . . . . . . . . . . . . . . . . . . 163 Support for output logging . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 14.20.1 Support for dumping array in an ASCII file . . 164 14.20.2 Support for Fortran array slices . . . . . . . . . . . . . . 165 14.20.3 Displaying enumerators . . . . . . . . . . . . . . . . . . . . . 165 14.20.4 Support for debugging typedefs . . . . . . . . . . . . . . 165 14.20.5 Support for steplast command for C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Getting information from a non-debug executable . . . . . 166 Debugging optimized code . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 14.22.1 Debugging Optimized Code at Various Optimization Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 14.22.1.1 +O0 and +O1 . . . . . . . . . . . . . . . . . . . . . . . 169 14.22.1.2 +O2 and +O3 . . . . . . . . . . . . . . . . . . . . . . . 169 14.22.1.3 +O4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Visual Interface for WDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 14.23.1 Starting and stopping Visual Interface for WDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 14.23.2 Navigating the Visual Interface for WDB display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 vii 14.23.3 Specifying foreground and background colors . . 172 14.23.4 Using the X-window graphical interface . . . . . . 173 14.23.5 Using the TUI mode . . . . . . . . . . . . . . . . . . . . . . . . 173 14.23.6 Changing the size of the source or debugger pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 14.23.7 Using commands to browse through source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 14.23.8 Loading source files . . . . . . . . . . . . . . . . . . . . . . . . . 175 14.23.9 Editing source files . . . . . . . . . . . . . . . . . . . . . . . . . 175 14.23.10 Editing the command line and command-line history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 14.23.11 Saving the contents of a debugging session to a file. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 14.24 Support for ddd. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 14.25 Support for XDB commands . . . . . . . . . . . . . . . . . . . . . . . . . 176 14.25.1 stop in/at dbx commands . . . . . . . . . . . . . . . . . . . 176 14.26 GNU GDB Logging Commands . . . . . . . . . . . . . . . . . . . . . . 176 14.27 Support for command line calls in a stripped executable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 14.27.1 Support for command line calls in a stripped executable on PA-RISC systems . . . . . . . . . . . . . . . . . 176 14.27.2 Additional support for command line calls in a stripped executable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 14.27.2.1 For 32-bit applications: . . . . . . . . . . . . . 177 14.27.2.2 For 64-bit applications . . . . . . . . . . . . . 177 14.27.3 Support for debugging stripped binaries . . . . . . 178 14.27.3.1 Printing of locals and globals in a stripped module . . . . . . . . . . . . . . . . . . . . . . . . . 178 14.27.3.2 Backtrace on stripped frames . . . . . . . 178 14.27.3.3 Command line calls to non-stripped library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 14.27.3.4 Setting breakpoints in unstripped shared library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 14.28 Displaying the current block scope information . . . . . . . . 178 14.29 Linux support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 15 The HP-UX Terminal User Interface. . . . . 181 15.1 Starting the TUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.2 Automatically running a program at startup . . . . . . . . . . . 15.3 Screen Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.3.1 Source pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.3.2 Disassembly pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.3.3 Source/Disassembly pane . . . . . . . . . . . . . . . . . . . . 15.3.4 Disassembly/Register pane . . . . . . . . . . . . . . . . . . . 15.3.5 Source/Register pane . . . . . . . . . . . . . . . . . . . . . . . . 15.4 Cycling through the panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.5 Changing pane focus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.6 Scrolling panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 182 183 183 183 184 185 186 187 187 190 viii Debugging with GDB 15.7 Changing the register display . . . . . . . . . . . . . . . . . . . . . . . . . 190 15.8 Changing the pane size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 15.9 Refreshing and updating the window . . . . . . . . . . . . . . . . . . 193 16 XDB to WDB Transition Guide . . . . . . . . . 195 16.1 By-function lists of XDB commands and HP WDB equivalents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 16.1.1 Invocation commands . . . . . . . . . . . . . . . . . . . . . . . . 196 16.1.2 Window mode commands . . . . . . . . . . . . . . . . . . . . 196 16.1.3 File viewing commands . . . . . . . . . . . . . . . . . . . . . . 197 16.1.4 Source directory mapping commands . . . . . . . . . . 198 16.1.5 Data Viewing and modification commands. . . . . 199 16.1.6 Stack viewing commands . . . . . . . . . . . . . . . . . . . . . 201 16.1.7 Status-viewing command . . . . . . . . . . . . . . . . . . . . . 201 16.1.8 Job control commands . . . . . . . . . . . . . . . . . . . . . . . 202 16.2 Overall breakpoint commands . . . . . . . . . . . . . . . . . . . . . . . . . 203 16.2.1 Auxiliary breakpoint commands . . . . . . . . . . . . . . 203 16.2.2 Breakpoint creation commands . . . . . . . . . . . . . . . 204 16.2.3 Breakpoint status commands . . . . . . . . . . . . . . . . . 205 16.2.4 All-procedures breakpoint commands . . . . . . . . . 206 16.2.5 Global breakpoint commands . . . . . . . . . . . . . . . . . 207 16.2.6 Assertion control commands . . . . . . . . . . . . . . . . . . 207 16.2.7 Record and playback commands . . . . . . . . . . . . . . 207 16.2.8 Macro facility commands . . . . . . . . . . . . . . . . . . . . . 208 16.2.9 Signal control commands . . . . . . . . . . . . . . . . . . . . . 208 16.2.10 Miscellaneous commands . . . . . . . . . . . . . . . . . . . . 209 16.3 XDB data formats and HP WDB equivalents . . . . . . . . . . . 210 16.4 XDB location syntax and HP WDB equivalents . . . . . . . . 212 16.5 XDB special language operators and HP WDB equivalents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 16.6 XDB special variables and HP WDB equivalents. . . . . . . . 213 16.7 XDB variable identifiers and HP WDB equivalents. . . . . . 215 16.8 Alphabetical lists of XDB commands and HP WDB equivalents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 16.8.1 A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 16.8.2 B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 16.8.3 C through D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 16.8.4 F through K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 16.8.5 L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 16.8.6 M through P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 16.8.7 Q through S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 16.8.8 T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 16.8.9 U through Z . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 16.8.10 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 ix 17 Controlling GDB . . . . . . . . . . . . . . . . . . . . . . . 231 17.1 17.2 17.3 17.4 17.5 17.6 17.7 18 Setting the GDB Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Command Editing Options in GDB . . . . . . . . . . . . Setting Command History Feature in GDB . . . . . . . . . . . . . Setting the GDB Screen Size . . . . . . . . . . . . . . . . . . . . . . . . . . Supported Number Formats. . . . . . . . . . . . . . . . . . . . . . . . . . . Optional warnings and messages . . . . . . . . . . . . . . . . . . . . . . Optional messages about internal happenings. . . . . . . . . . . 231 231 231 233 233 234 235 Canned Sequences of Commands . . . . . . . . 237 18.1 18.2 18.3 18.4 User-defined commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . User-defined command hooks . . . . . . . . . . . . . . . . . . . . . . . . . Command files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Commands for controlled output . . . . . . . . . . . . . . . . . . . . . . 237 238 239 239 19 Using GDB under gnu Emacs . . . . . . . . . . . 241 20 GDB Annotations . . . . . . . . . . . . . . . . . . . . . . 243 20.1 20.2 20.3 20.4 20.5 20.6 20.7 20.8 20.9 20.10 20.11 20.12 21 What is an annotation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The server prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Annotation for GDB input . . . . . . . . . . . . . . . . . . . . . . . . . . . . Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Information on breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . Invalidation notices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running the program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displaying source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Annotations We Might Want in the Future . . . . . . . . . . . . 243 243 244 245 246 247 247 248 248 249 249 250 The gdb/mi Interface . . . . . . . . . . . . . . . . . . . 251 Function and purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Notation and terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.1 gdb/mi Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.1.1 gdb/mi Input syntax . . . . . . . . . . . . . . . . . . . . . . . . 21.1.2 gdb/mi Output syntax . . . . . . . . . . . . . . . . . . . . . . 21.1.3 Simple examples of gdb/mi interaction . . . . . . . . 21.2 gdb/mi compatibility with CLI . . . . . . . . . . . . . . . . . . . . . . . 21.3 gdb/mi output records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3.1 gdb/mi result records . . . . . . . . . . . . . . . . . . . . . . . 21.3.2 gdb/mi stream records . . . . . . . . . . . . . . . . . . . . . . 21.3.3 gdb/mi out-of-band records . . . . . . . . . . . . . . . . . . 21.4 gdb/mi command description format . . . . . . . . . . . . . . . . . . 21.5 gdb/mi breakpoint table commands . . . . . . . . . . . . . . . . . . . 21.6 gdb/mi Data manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.7 gdb/mi program control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 251 251 251 252 254 254 255 255 255 255 256 257 265 275 x Debugging with GDB 21.8 21.9 21.10 21.11 21.12 21.13 21.14 22 Miscellaneous GDB commands in gdb/mi. . . . . . . . . . . . . . gdb/mi Stack Manipulation Commands . . . . . . . . . . . . . . . gdb/mi Symbol query commands . . . . . . . . . . . . . . . . . . . . gdb/mi Target Manipulation Commands . . . . . . . . . . . . . gdb/mi thread commands . . . . . . . . . . . . . . . . . . . . . . . . . . . gdb/mi tracepoint commands . . . . . . . . . . . . . . . . . . . . . . . . gdb/mi variable objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 288 293 296 301 303 303 Reporting Bugs in GDB . . . . . . . . . . . . . . . . 309 22.1 Have you found a bug? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 22.2 How to report bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 Appendix A Installing GDB . . . . . . . . . . . . . . . . 313 A.1 Compiling GDB in another directory . . . . . . . . . . . . . . . . . . . 314 A.2 Specifying names for hosts and targets . . . . . . . . . . . . . . . . . 315 A.3 configure options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值