文件名称:GNUPro Debugging Tools
文件大小:2.4MB
文件格式:PDF
更新时间:2012-03-14 05:25:17
Debug linux
Debugging with GDB Summary of GDB, the GNU Debugger........................................................................5 GDB as Free Software..................................................................................................6 Requirements of GDB...................................................................................................7 Contributors to GDB.....................................................................................................7 Overall Structure of GDB...........................................................................................10 Configuring GDB........................................................................................................10 Symbol Handling for GDB.........................................................................................11 Symbol Reading.......................................................................................................11 Partial Symbol Tables..............................................................................................12 Types........................................................................................................................14 Object File Formats for GDB......................................................................................14 Debugging File Formats..........................................................................................15 Adding a New Symbol Reader to GDB...................................................................16 Installing GDB..............................................................................................................17 Locating Files for Installing GDB...............................................................................18 Compiling GDB in Another Directory........................................................................19 Specifying Names for Hosts and Targets................................................................20 configure Options with GDB....................................................................................20 Essentials of GDB.........................................................................................................23 Invoking GDB.............................................................................................................23 Choosing Files for GDB to Debug..............................................................................24 Choosing Modes.........................................................................................................26 Quitting GDB..............................................................................................................27 Shell Commands for GDB..........................................................................................27 GDB Commands...........................................................................................................29 Command Syntax........................................................................................................29 Command Completion................................................................................................30 Getting Help................................................................................................................32 Running Programs under GDB..................................................................................35 Compiling for Debugging...........................................................................................36 Starting a Program ......................................................................................................36 Your Program’s Arguments........................................................................................37 Your Program’s Environment.....................................................................................38 Your Program’s Working Directory...........................................................................39 Your Program’s Input and Output..............................................................................39 Debugging a Running Process....................................................................................40 Killing the Child Process............................................................................................41 Additional Process Information..................................................................................41 Debugging Programs with Multiple Threads..............................................................42 Debugging Programs with Multiple Processes...........................................................44 Stopping and Continuing.............................................................................................45 Breakpoints, Watchpoints, and Exceptions.................................................................46 Setting Breakpoints.....................................................................................................47 Setting Watchpoints....................................................................................................50 Setting Catchpoints.....................................................................................................51 Deleting Breakpoints...................................................................................................52 Disabling Breakpoints.................................................................................................53 Break Conditions.........................................................................................................54 Breakpoint Command Lists........................................................................................56 Breakpoint Menus.......................................................................................................57 Continuing and Stepping.............................................................................................58 Signals.........................................................................................................................60 Stopping and Starting Multiple Thread Programs......................................................62 Examining the Stack....................................................................................................65 Stack Frames...............................................................................................................66 Backtraces...................................................................................................................67 Selecting a Frame........................................................................................................67 Information about a Frame..........................................................................................69 Examining Source Files................................................................................................71 Printing Source Lines..................................................................................................71 Searching Source Files................................................................................................73 Specifying Source Directories.....................................................................................74 Source and Machine Code..........................................................................................75 Examining Data............................................................................................................77 Expressions.................................................................................................................78 Program Variables.......................................................................................................78 Artificial Arrays..........................................................................................................80 Output Formats............................................................................................................81 Examining Memory....................................................................................................82 Automatic Display......................................................................................................83 Print Settings...............................................................................................................85 Value History..............................................................................................................89 Convenience Variables................................................................................................90 Registers......................................................................................................................91 Floating Point Hardware.............................................................................................93 Using GDB with Different Languages........................................................................95 Switching between Source Languages........................................................................96 List of Filename Extensions and Languages...............................................................96 Setting GDB’s Working Language..........................................................................97 Having GDB Infer the Source Language.................................................................97 Displaying the Language.............................................................................................97 Type and Range Checking..........................................................................................98 An Overview of Type Checking.................................................................................99 An Overview of Range Checking.............................................................................100 Supported languages.................................................................................................101 C and C++..............................................................................................................101 C and C++ Operators.............................................................................................101 C and C++ Constants.............................................................................................103 C++ Expressions....................................................................................................104 C and C++ Defaults...............................................................................................105 C and C++ Type and Range Checks......................................................................105 GDB and C.............................................................................................................106 GDB Features for C++...........................................................................................106 Modula-2................................................................................................................107 Modula-2 Operators...............................................................................................107 Modula-2 Built-in Functions and Procedures........................................................109 Modula-2 Constants...............................................................................................110 Modula-2 Defaults.................................................................................................111 Deviations from Standard Modula-2.....................................................................111 Modula-2 Type and Range Checks........................................................................112 Modula-2 Scope Operator (.) and GDB Scope Operator (::)..............................112 GDB and Modula-2...............................................................................................112 Examining the Symbol Table....................................................................................115 Altering Execution......................................................................................................119 Assignment to Variables...........................................................................................119 Continuing at a Different Address............................................................................120 Giving a Program a Signal........................................................................................121 Returning from a Function........................................................................................122 Calling Program Functions.......................................................................................122 Patching Programs....................................................................................................122 GDB Files....................................................................................................................125 Commands to Specify Files......................................................................................125 Errors Reading Symbol Files....................................................................................129 Specifying a Debugging Target.................................................................................131 Active Targets...........................................................................................................131 Commands for Managing Targets.............................................................................132 Choosing Target Byte Order.....................................................................................134 Remote Debugging...................................................................................................135 The GDB Remote Serial Protocol.............................................................................135 What the Stub Can Do...........................................................................................137 What You Must Do for the Stub............................................................................137 Putting It All Together...........................................................................................139 Communication Protocol.......................................................................................140 gdbserver Program..................................................................................141 Using the gdbserve.nlm Program............................................................................143 Using the GDB with a Remote i960 (Nindy)............................................................................144 Startup with Nindy.................................................................................................144 Nindy Reset Command..........................................................................................144 Options for Nindy..................................................................................................144 The UDI Protocol for AMD29K...............................................................................145 The EBMON Protocol for AMD29K....................................................................145 GDB with a Tandem ST2000................................................................................148 GDB and VxWorks................................................................................................148 GDB and SPARClet...............................................................................................150 file to Debug...........................................................................................150 Setting Connecting to SPARClet.......................................................................................151 GDB and Hitachi Microprocessors...........................................................................152 Connecting to Hitachi Boards................................................................................152 Using the E7000 In-circuit Emulator.....................................................................152 GDB and Remote MIPS Boards............................................................................153 Controlling GDB.........................................................................................................157 Prompt.......................................................................................................................158 Command Editing.....................................................................................................158 Command History.....................................................................................................158 Screen Size................................................................................................................160 Numbers....................................................................................................................160 Optional Warnings and Messages.............................................................................161 Canned Sequences of Commands.............................................................................163 User-defined Commands...........................................................................................163 User-defined Command Hooks.................................................................................165 Command Files.........................................................................................................165 Commands for Controlled Output.............................................................................166 Insight, the GNUPro Debugger GUI Insight, GDB’s Alternative Interface.......................................................................171 Using the Source Window........................................................................................172 Using the Mouse in the Source Window...............................................................176 Source Window Menus and Display Features.......................................................179 Below the horizontal scroll bar of the Source Window.........................................179 Using the Stack Window...........................................................................................182 Using the Registers Window.....................................................................................183 Using the Memory Window......................................................................................184 Using the Watch Expressions Window.....................................................................186 Using the Local Variables Window..........................................................................188 Using the Breakpoints Window................................................................................191 Using the Console Window......................................................................................194 Using the Function Browser Window.......................................................................195 Using the Processes Window for Threads................................................................197 Using the Help Window............................................................................................198 Examples of Debugging with Insight........................................................................199 Selecting and Examining a Source File....................................................................200 Setting Breakpoints and Viewing Local Variables...................................................202 Setting Breakpoints on Multiple Threads.................................................................206 Appendixes Using GDB under GNU Emacs.................................................................................211 Emacs Considerations with GDB..............................................................................211 Keystroke Sequences for GDB with Emacs..............................................................212 Reporting Bugs in GDB.............................................................................................215 Have You Found a Bug?...........................................................................................215 How to Report Bugs..................................................................................................216 Command Line Editing..............................................................................................219 Readline Interaction..................................................................................................220 Readline Bare Essentials...........................................................................................220 Readline Movement Commands...............................................................................221 Readline Killing Commands.....................................................................................221 Readline Arguments..................................................................................................222 Searching for Commands in the History...................................................................222 init File....................................................................................................223 Readline init Syntax................................................................................................223 Readline Variable Settings for Readline..................................................................................224 Key Bindings for Readline....................................................................................225 init Constructs..................................................................................227 Conditional init File.......................................................................................................228 Sample Bindable Readline Commands..................................................................................230 Commands for Moving around in Readline..........................................................230 Commands for Manipulating History with Readline.............................................231 Commands for Changing Text in Readline...........................................................232 Killing and Yanking...............................................................................................233 Specifying Numeric Arguments............................................................................234 Letting Readline Type for You..............................................................................235 Keyboard Macros...................................................................................................235 Some Miscellaneous Readline Commands............................................................235 vi Mode.................................................................................................236 Readline in Using History Interactively........................................................................................237 Event Designators.....................................................................................................238 Word Designators .....................................................................................................238 Modifiers...................................................................................................................239 Formatting Documentation.......................................................................................241 Index ...............................................................................................................................243