Gdb Internals a Guide to the Internals of the GNU Debugger
Total Page:16
File Type:pdf, Size:1020Kb
gdb Internals A guide to the internals of the GNU debugger John Gilmore Cygnus Solutions Second Edition: Stan Shebs Cygnus Solutions Cygnus Solutions Revision TEXinfo 2004-02-19.09 Copyright c 1990,1991,1992,1993,1994,1996,1998,1999,2000,2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 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 no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”. i Table of Contents Scope of this Document ....................... 1 1 Requirements.............................. 1 2 Overall Structure .......................... 1 2.1 The Symbol Side ............................................ 2 2.2 The Target Side ............................................. 2 2.3 Configurations .............................................. 2 3 Algorithms ................................ 2 3.1 Frames ..................................................... 2 3.2 Prologue Analysis ........................................... 3 3.3 Breakpoint Handling ........................................ 5 3.4 Single Stepping ............................................. 6 3.5 Signal Handling ............................................. 6 3.6 Thread Handling ............................................ 6 3.7 Inferior Function Calls ....................................... 6 3.8 Longjmp Support ........................................... 7 3.9 Watchpoints ................................................ 7 3.9.1 x86 Watchpoints ........................................ 9 3.10 Checkpoints .............................................. 11 3.11 Observing changes in gdb internals ......................... 12 4 User Interface ............................ 12 4.1 Command Interpreter ...................................... 12 4.2 UI-Independent Output—the ui_out Functions............... 13 4.2.1 Overview and Terminology ............................. 13 4.2.2 General Conventions ................................... 14 4.2.3 Table, Tuple and List Functions ........................ 14 4.2.4 Item Output Functions ................................. 16 4.2.5 Utility Output Functions ............................... 17 4.2.6 Examples of Use of ui_out functions .................... 18 4.3 Console Printing ........................................... 21 4.4 TUI ....................................................... 21 5 libgdb.................................... 21 5.1 libgdb 1.0.................................................. 21 5.2 libgdb 2.0.................................................. 22 5.3 The libgdb Model ......................................... 22 5.4 CLI support ............................................... 22 5.5 libgdb components ........................................ 23 ii 6 Symbol Handling ......................... 23 6.1 Symbol Reading............................................ 23 6.2 Partial Symbol Tables ...................................... 24 6.3 Types ..................................................... 26 Fundamental Types (e.g., FT_VOID, FT_BOOLEAN). ............... 26 Type Codes (e.g., TYPE_CODE_PTR, TYPE_CODE_ARRAY). .......... 26 Builtin Types (e.g., builtin_type_void, builtin_type_char)... 26 6.4 Object File Formats ........................................ 26 6.4.1 a.out ................................................. 26 6.4.2 COFF ................................................ 26 6.4.3 ECOFF ............................................... 27 6.4.4 XCOFF ............................................... 27 6.4.5 PE ................................................... 27 6.4.6 ELF .................................................. 27 6.4.7 SOM ................................................. 27 6.4.8 Other File Formats .................................... 27 6.5 Debugging File Formats .................................... 27 6.5.1 stabs ................................................. 27 6.5.2 COFF ................................................ 28 6.5.3 Mips debug (Third Eye)................................ 28 6.5.4 DWARF 1 ............................................ 28 6.5.5 DWARF 2 ............................................ 28 6.5.6 SOM ................................................. 28 6.6 Adding a New Symbol Reader to gdb ....................... 28 6.7 Memory Management for Symbol Files....................... 28 7 Language Support ........................ 29 7.1 Adding a Source Language to gdb........................... 29 8 Host Definition ........................... 31 8.1 Adding a New Host ........................................ 31 8.2 Host Conditionals .......................................... 32 9 Target Architecture Definition............. 34 9.1 Operating System ABI Variant Handling ..................... 34 9.2 Registers and Memory ...................................... 36 9.3 Pointers Are Not Always Addresses .......................... 36 9.4 Address Classes ............................................ 38 9.5 Raw and Virtual Register Representations.................... 39 9.6 Using Different Register and Memory Data Representations ... 40 9.7 Frame Interpretation ....................................... 41 9.8 Inferior Call Setup ......................................... 42 9.9 Compiler Characteristics .................................... 42 9.10 Target Conditionals ....................................... 42 9.11 Adding a New Target...................................... 57 9.12 Converting an existing Target Architecture to Multi-arch ..... 58 9.12.1 Preparation .......................................... 58 iii 9.12.2 Add the multi-arch initialization code .................. 58 9.12.3 Update multi-arch incompatible mechanisms ............ 59 9.12.4 Prepare for multi-arch level to one ..................... 59 9.12.5 Set multi-arch level one ............................... 59 9.12.6 Convert remaining macros ............................. 59 9.12.7 Set multi-arch level to two............................. 60 9.12.8 Delete the TM file .................................... 60 10 Target Vector Definition ................. 60 10.1 File Targets............................................... 60 10.2 Standard Protocol and Remote Stubs ....................... 60 10.3 ROM Monitor Interface.................................... 60 10.4 Custom Protocols ......................................... 61 10.5 Transport Layer........................................... 61 10.6 Builtin Simulator.......................................... 61 11 Native Debugging ....................... 61 11.1 Native core file Support.................................... 62 11.2 ptrace .................................................... 62 11.3 /proc..................................................... 63 11.4 win32 .................................................... 63 11.5 shared libraries............................................ 63 11.6 Native Conditionals ....................................... 63 12 Support Libraries........................ 65 12.1 BFD ..................................................... 65 12.2 opcodes .................................................. 65 12.3 readline .................................................. 65 12.4 mmalloc .................................................. 65 12.5 libiberty .................................................. 66 12.5.1 obstacks in gdb ..................................... 66 12.6 gnu-regex ................................................. 66 12.7 include ................................................... 67 13 Coding.................................. 67 13.1 Cleanups ................................................. 67 13.2 Per-architecture module data............................... 68 13.3 Wrapping Output Lines.................................... 70 13.4 gdb Coding Standards .................................... 70 13.4.1 ISO C ............................................... 70 13.4.2 Memory Management ................................. 70 13.4.3 Compiler Warnings ................................... 71 13.4.4 Formatting ........................................... 72 13.4.5 Comments ........................................... 72 13.4.6 C Usage ............................................. 73 13.4.7 Function Prototypes .................................. 73 13.4.8 Internal Error Recovery ............................... 73 iv 13.4.9 File Names ........................................... 74 13.4.10 Include Files ........................................ 74 13.4.11 Clean Design and Portable Implementation ............ 74 14 Porting gdb ............................. 76 15 Versions and Branches ................... 77 15.1 Versions .................................................. 77 15.2 Release Branches .......................................... 78 15.3 Vendor Branches .......................................... 78 15.4 Experimental Branches .................................... 79 15.4.1 Guidelines ........................................... 79 15.4.2 Tags ................................................. 79 16 Start of New Year Procedure ............. 80 17 Releasing gdb ........................... 80 17.1 Branch Commit Policy .................................... 80 17.2 Obsoleting code ........................................... 81 17.3 Before the Branch ......................................... 81 17.3.1