logo资料库

GDB官方手册。绝对官方原版。.pdf

第1页 / 共632页
第2页 / 共632页
第3页 / 共632页
第4页 / 共632页
第5页 / 共632页
第6页 / 共632页
第7页 / 共632页
第8页 / 共632页
资料共632页,剩余部分请下载后查看
Summary of gdb
Free Software
Free Software Needs Free Documentation
Contributors to gdb
A Sample gdb Session
Getting In and Out of gdb
Invoking gdb
Choosing Files
Choosing Modes
What gdb Does During Startup
Quitting gdb
Shell Commands
Logging Output
gdb Commands
Command Syntax
Command Completion
Getting Help
Running Programs Under gdb
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 Multiple Inferiors and Programs
Debugging Programs with Multiple Threads
Debugging Forks
Setting a Bookmark to Return to Later
A Non-obvious Benefit of Using Checkpoints
Stopping and Continuing
Breakpoints, Watchpoints, and Catchpoints
Setting Breakpoints
Setting Watchpoints
Setting Catchpoints
Deleting Breakpoints
Disabling Breakpoints
Break Conditions
Breakpoint Command Lists
Dynamic Printf
How to save breakpoints to a file
Static Probe Points
``Cannot insert breakpoints''
``Breakpoint address adjusted...''
Continuing and Stepping
Skipping Over Functions and Files
Signals
Stopping and Starting Multi-thread Programs
All-Stop Mode
Non-Stop Mode
Background Execution
Thread-Specific Breakpoints
Interrupted System Calls
Observer Mode
Running programs backward
Recording Inferior's Execution and Replaying It
Examining the Stack
Stack Frames
Backtraces
Selecting a Frame
Information About a Frame
Examining Source Files
Printing Source Lines
Specifying a Location
Editing Source Files
Choosing your Editor
Searching Source Files
Specifying Source Directories
Source and Machine Code
Examining Data
Expressions
Ambiguous Expressions
Program Variables
Artificial Arrays
Output Formats
Examining Memory
Automatic Display
Print Settings
Pretty Printing
Pretty-Printer Introduction
Pretty-Printer Example
Pretty-Printer Commands
Value History
Convenience Variables
Registers
Floating Point Hardware
Vector Unit
Operating System Auxiliary Information
Memory Region Attributes
Attributes
Memory Access Mode
Memory Access Size
Data Cache
Memory Access Checking
Copy Between Memory and a File
How to Produce a Core File from Your Program
Character Sets
Caching Data of Remote Targets
Search Memory
Debugging Optimized Code
Inline Functions
Tail Call Frames
C Preprocessor Macros
Tracepoints
Commands to Set Tracepoints
Create and Delete Tracepoints
Enable and Disable Tracepoints
Tracepoint Passcounts
Tracepoint Conditions
Trace State Variables
Tracepoint Action Lists
Listing Tracepoints
Listing Static Tracepoint Markers
Starting and Stopping Trace Experiments
Tracepoint Restrictions
Using the Collected Data
tfind n
tdump
save tracepoints filename
Convenience Variables for Tracepoints
Using Trace Files
Debugging Programs That Use Overlays
How Overlays Work
Overlay Commands
Automatic Overlay Debugging
Overlay Sample Program
Using gdb with Different Languages
Switching Between Source Languages
List of Filename Extensions and Languages
Setting the Working Language
Having gdb Infer the Source Language
Displaying the Language
Type and Range Checking
An Overview of Type Checking
An Overview of Range Checking
Supported Languages
C and C++
C and C++ Operators
C and C++ Constants
C++ Expressions
C and C++ Defaults
C and C++ Type and Range Checks
gdb and C
gdb Features for C++
Decimal Floating Point format
D
Go
Objective-C
Method Names in Commands
The Print Command With Objective-C
OpenCL C
OpenCL C Datatypes
OpenCL C Expressions
OpenCL C Operators
Fortran
Fortran Operators and Expressions
Fortran Defaults
Special Fortran Commands
Pascal
Modula-2
Operators
Built-in Functions and Procedures
Constants
Modula-2 Types
Modula-2 Defaults
Deviations from Standard Modula-2
Modula-2 Type and Range Checks
The Scope Operators :: and .
gdb and Modula-2
Ada
Introduction
Omissions from Ada
Additions to Ada
Stopping at the Very Beginning
Extensions for Ada Tasks
Tasking Support when Debugging Core Files
Tasking Support when using the Ravenscar Profile
Known Peculiarities of Ada Mode
Unsupported Languages
Examining the Symbol Table
Altering Execution
Assignment to Variables
Continuing at a Different Address
Giving your Program a Signal
Returning from a Function
Calling Program Functions
Patching Programs
gdb Files
Commands to Specify Files
Debugging Information in Separate Files
Index Files Speed Up gdb
Errors Reading Symbol Files
GDB Data Files
Specifying a Debugging Target
Active Targets
Commands for Managing Targets
Choosing Target Byte Order
Debugging Remote Programs
Connecting to a Remote Target
Sending files to a remote system
Using the gdbserver Program
Running gdbserver
Attaching to a Running Program
Multi-Process Mode for gdbserver
TCP port allocation lifecycle of gdbserver
Other Command-Line Arguments for gdbserver
Connecting to gdbserver
Monitor Commands for gdbserver
Tracepoints support in gdbserver
Remote Configuration
Implementing a Remote Stub
What the Stub Can Do for You
What You Must Do for the Stub
Putting it All Together
Configuration-Specific Information
Native
HP-UX
BSD libkvm Interface
SVR4 Process Information
Features for Debugging djgpp Programs
Features for Debugging MS Windows PE Executables
Support for DLLs without Debugging Symbols
DLL Name Prefixes
Working with Minimal Symbols
Commands Specific to gnu Hurd Systems
QNX Neutrino
Darwin
Embedded Operating Systems
Using gdb with VxWorks
Connecting to VxWorks
VxWorks Download
Running Tasks
Embedded Processors
ARM
Renesas M32R/D and M32R/SDI
M68k
MicroBlaze
MIPS Embedded
OpenRISC 1000
PowerPC Embedded
HP PA Embedded
Tsqware Sparclet
Setting File to Debug
Connecting to Sparclet
Sparclet Download
Running and Debugging
Fujitsu Sparclite
Zilog Z8000
Atmel AVR
CRIS
Renesas Super-H
Architectures
x86 Architecture-specific Issues
Alpha
MIPS
HPPA
Cell Broadband Engine SPU architecture
PowerPC
Controlling gdb
Prompt
Command Editing
Command History
Screen Size
Numbers
Configuring the Current ABI
Automatically loading associated files
Automatically loading init file in the current directory
Automatically loading thread debugging library
The objfile-gdb.gdb file
Security restriction for auto-loading
Displaying files tried for auto-load
Optional Warnings and Messages
Optional Messages about Internal Happenings
Other Miscellaneous Settings
Extending gdb
Canned Sequences of Commands
User-defined Commands
User-defined Command Hooks
Command Files
Commands for Controlled Output
Scripting gdb using Python
Python Commands
Python API
Basic Python
Exception Handling
Values From Inferior
Types In Python
Pretty Printing API
Selecting Pretty-Printers
Writing a Pretty-Printer
Inferiors In Python
Events In Python
Threads In Python
Commands In Python
Parameters In Python
Writing new convenience functions
Program Spaces In Python
Objfiles In Python
Accessing inferior stack frames from Python.
Accessing frame blocks from Python.
Python representation of Symbols.
Symbol table representation in Python.
Manipulating breakpoints using Python
Finish Breakpoints
Python representation of lazy strings.
Python Auto-loading
The objfile-gdb.py file
The .debug_gdb_scripts section
Which flavor to choose?
Python modules
gdb.printing
gdb.types
gdb.prompt
Creating new spellings of existing commands
Command Interpreters
gdb Text User Interface
TUI Overview
TUI Key Bindings
TUI Single Key Mode
TUI-specific Commands
TUI Configuration Variables
Using gdb under gnu Emacs
The gdb/mi Interface
Function and Purpose
Notation and Terminology
gdb/mi General Design
Context management
Asynchronous command execution and non-stop mode
Thread groups
gdb/mi Command Syntax
gdb/mi Input Syntax
gdb/mi Output Syntax
gdb/mi Compatibility with CLI
gdb/mi Development and Front Ends
gdb/mi Output Records
gdb/mi Result Records
gdb/mi Stream Records
gdb/mi Async Records
gdb/mi Frame Information
gdb/mi Thread Information
gdb/mi Ada Exception Information
Simple Examples of gdb/mi Interaction
gdb/mi Command Description Format
gdb/mi Breakpoint Commands
gdb/mi Program Context
gdb/mi Thread Commands
gdb/mi Ada Tasking Commands
gdb/mi Program Execution
gdb/mi Stack Manipulation Commands
gdb/mi Variable Objects
gdb/mi Data Manipulation
gdb/mi Tracepoint Commands
gdb/mi Symbol Query Commands
gdb/mi File Commands
gdb/mi Target Manipulation Commands
gdb/mi File Transfer Commands
Miscellaneous gdb/mi Commands
gdb Annotations
What is an Annotation?
The Server Prefix
Annotation for gdb Input
Errors
Invalidation Notices
Running the Program
Displaying Source
JIT Compilation Interface
JIT Declarations
Registering Code
Unregistering Code
Custom Debug Info
Using JIT Debug Info Readers
Writing JIT Debug Info Readers
In-Process Agent
In-Process Agent Protocol
IPA Protocol Objects
IPA Protocol Commands
Reporting Bugs in gdb
Have You Found a Bug?
How to Report Bugs
Command Line Editing
Introduction to Line Editing
Readline Interaction
Readline Bare Essentials
Readline Movement Commands
Readline Killing Commands
Readline Arguments
Searching for Commands in the History
Readline Init File
Readline Init File Syntax
Conditional Init Constructs
Sample Init File
Bindable Readline Commands
Commands For Moving
Commands For Manipulating The History
Commands For Changing Text
Killing And Yanking
Specifying Numeric Arguments
Letting Readline Type For You
Keyboard Macros
Some Miscellaneous Commands
Readline vi Mode
Using History Interactively
History Expansion
Event Designators
Word Designators
Modifiers
In Memoriam
Formatting Documentation
Installing gdb
Requirements for Building gdb
Invoking the gdb configure Script
Compiling gdb in Another Directory
Specifying Names for Hosts and Targets
configure Options
System-wide configuration and settings
Maintenance Commands
gdb Remote Serial Protocol
Overview
Packets
Stop Reply Packets
General Query Packets
Architecture-Specific Protocol Details
ARM-specific Protocol Details
ARM Breakpoint Kinds
MIPS-specific Protocol Details
MIPS Register Packet Format
MIPS Breakpoint Kinds
Tracepoint Packets
Relocate instruction reply packet
Host I/O Packets
Interrupts
Notification Packets
Remote Protocol Support for Non-Stop Mode
Packet Acknowledgment
Examples
File-I/O Remote Protocol Extension
File-I/O Overview
Protocol Basics
The F Request Packet
The F Reply Packet
The Ctrl-C Message
Console I/O
List of Supported Calls
open
close
read
write
lseek
rename
unlink
stat/fstat
gettimeofday
isatty
system
Protocol-specific Representation of Datatypes
Integral Datatypes
Pointer Values
Memory Transfer
struct stat
struct timeval
Constants
Open Flags
mode_t Values
Errno Values
Lseek Flags
Limits
File-I/O Examples
Library List Format
Library List Format for SVR4 Targets
Memory Map Format
Thread List Format
Traceframe Info Format
The GDB Agent Expression Mechanism
General Bytecode Design
Bytecode Descriptions
Using Agent Expressions
Varying Target Capabilities
Rationale
Target Descriptions
Retrieving Descriptions
Target Description Format
Inclusion
Architecture
OS ABI
Compatible Architecture
Features
Types
Registers
Predefined Target Types
Standard Target Features
ARM Features
i386 Features
MIPS Features
M68K Features
PowerPC Features
TMS320C6x Features
Operating System Information
Process list
Trace File Format
.gdb_index section format
GNU GENERAL PUBLIC LICENSE
GNU Free Documentation License
Concept Index
Command, Variable, and Function Index
Debugging with gdb The gnu Source-Level Debugger Tenth Edition, for gdb version 7.5.1 (GDB) Richard Stallman, Roland Pesch, Stan Shebs, et al.
(Send bugs and comments on gdb to http://www.gnu.org/software/gdb/bugs/.) Debugging with gdb TEXinfo 2011-02-14.11 Published by the Free Software Foundation 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA ISBN 978-0-9831592-3-0 Copyright c 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 2011, 2012 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.3 or any later version published by the Free Software Foundation; with the Invariant Sections being “Free Software” and “Free Software Needs Free Documentation”, with the Front-Cover Texts being “A GNU Manual,” and with the Back-Cover Texts as in (a) below. (a) The FSF’s Back-Cover Text is: “You are free to copy and modify this GNU Man- ual. Buying copies from GNU Press supports the FSF in developing GNU and promoting software freedom.”
i Table of Contents Summary of gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Free Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Free Software Needs Free Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Contributors to gdb. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1 A Sample gdb Session . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.1 2 Getting In and Out of gdb . . . . . . . . . . . . . . . . . . . 11 Invoking gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.1.1 Choosing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.1.2 Choosing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.1.3 What gdb Does During Startup . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.2 Quitting gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.3 Shell Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.4 Logging Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3 gdb Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.1 Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.2 Command Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.3 Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 4 Running Programs Under gdb . . . . . . . . . . . . . . . 25 4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 4.2 Starting your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 4.3 Your Program’s Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.4 Your Program’s Environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 4.5 Your Program’s Working Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 4.6 Your Program’s Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 4.7 Debugging an Already-running Process . . . . . . . . . . . . . . . . . . . . . . . . 31 4.8 Killing the Child Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 4.9 Debugging Multiple Inferiors and Programs. . . . . . . . . . . . . . . . . . . . 32 4.10 Debugging Programs with Multiple Threads . . . . . . . . . . . . . . . . . . 35 4.11 Debugging Forks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 4.12 Setting a Bookmark to Return to Later. . . . . . . . . . . . . . . . . . . . . . . 40 4.12.1 A Non-obvious Benefit of Using Checkpoints . . . . . . . . . . . . . 42
ii Debugging with gdb 5 Stopping and Continuing . . . . . . . . . . . . . . . . . . . . . 43 5.1 Breakpoints, Watchpoints, and Catchpoints . . . . . . . . . . . . . . . . . . . 43 5.1.1 Setting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 5.1.2 Setting Watchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 5.1.3 Setting Catchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 5.1.4 Deleting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 5.1.5 Disabling Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 5.1.6 Break Conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 5.1.7 Breakpoint Command Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 5.1.8 Dynamic Printf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 5.1.9 How to save breakpoints to a file . . . . . . . . . . . . . . . . . . . . . . . . . 63 5.1.10 Static Probe Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 5.1.11 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 5.1.12 “Breakpoint address adjusted...” . . . . . . . . . . . . . . . . . . . . . . . . 64 5.2 Continuing and Stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 5.3 Skipping Over Functions and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 5.4 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 5.5 Stopping and Starting Multi-thread Programs . . . . . . . . . . . . . . . . . 71 5.5.1 All-Stop Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 5.5.2 Non-Stop Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 5.5.3 Background Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 5.5.4 Thread-Specific Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 5.5.5 Interrupted System Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 5.5.6 Observer Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 6 Running programs backward . . . . . . . . . . . . . . . . . 79 7 Recording Inferior’s Execution and Replaying It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 8 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . . . . . 85 8.1 Stack Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 8.2 Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 8.3 Selecting a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 8.4 Information About a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 9 Examining Source Files . . . . . . . . . . . . . . . . . . . . . . . 91 9.1 Printing Source Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 9.2 Specifying a Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 9.3 Editing Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 9.3.1 Choosing your Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 9.4 Searching Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 9.5 Specifying Source Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 9.6 Source and Machine Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
iii 10 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 10.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 10.2 Ambiguous Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 10.3 Program Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 10.4 Artificial Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 10.5 Output Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 10.6 Examining Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 10.7 Automatic Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 10.8 Print Settings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 10.9 Pretty Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 10.9.1 Pretty-Printer Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 10.9.2 Pretty-Printer Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 10.9.3 Pretty-Printer Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 10.10 Value History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 10.11 Convenience Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 10.12 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 10.13 Floating Point Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 10.14 Vector Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 10.15 Operating System Auxiliary Information . . . . . . . . . . . . . . . . . . . 128 10.16 Memory Region Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 10.16.1 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 10.16.1.1 Memory Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 10.16.1.2 Memory Access Size. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 10.16.1.3 Data Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 10.16.2 Memory Access Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 10.17 Copy Between Memory and a File . . . . . . . . . . . . . . . . . . . . . . . . . 132 10.18 How to Produce a Core File from Your Program . . . . . . . . . . . 133 10.19 Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 10.20 Caching Data of Remote Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 10.21 Search Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 11 Debugging Optimized Code . . . . . . . . . . . . . . . . 139 11.1 Inline Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 11.2 Tail Call Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 12 C Preprocessor Macros . . . . . . . . . . . . . . . . . . . . . 143 13 Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 13.1 Commands to Set Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 13.1.1 Create and Delete Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . 148 13.1.2 Enable and Disable Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . 150 13.1.3 Tracepoint Passcounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 13.1.4 Tracepoint Conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 13.1.5 Trace State Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 13.1.6 Tracepoint Action Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 13.1.7 Listing Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 13.1.8 Listing Static Tracepoint Markers . . . . . . . . . . . . . . . . . . . . . . 155
iv Debugging with gdb 13.1.9 Starting and Stopping Trace Experiments . . . . . . . . . . . . . . 155 13.1.10 Tracepoint Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 13.2 Using the Collected Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 13.2.1 tfind n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 13.2.2 tdump. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 13.2.3 save tracepoints filename . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 13.3 Convenience Variables for Tracepoints . . . . . . . . . . . . . . . . . . . . . . . 162 13.4 Using Trace Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 14 Debugging Programs That Use Overlays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 14.1 How Overlays Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 14.2 Overlay Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 14.3 Automatic Overlay Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 14.4 Overlay Sample Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 15 Using gdb with Different Languages . . . . . . 169 15.1 Switching Between Source Languages . . . . . . . . . . . . . . . . . . . . . . . 169 15.1.1 List of Filename Extensions and Languages . . . . . . . . . . . . . 169 15.1.2 Setting the Working Language . . . . . . . . . . . . . . . . . . . . . . . . . 170 15.1.3 Having gdb Infer the Source Language . . . . . . . . . . . . . . . . . 170 15.2 Displaying the Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 15.3 Type and Range Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 15.3.1 An Overview of Type Checking . . . . . . . . . . . . . . . . . . . . . . . . 171 15.3.2 An Overview of Range Checking . . . . . . . . . . . . . . . . . . . . . . . 172 15.4 Supported Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 15.4.1 C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 15.4.1.1 C and C++ Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 15.4.1.2 C and C++ Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 15.4.1.3 C++ Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 15.4.1.4 C and C++ Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 15.4.1.5 C and C++ Type and Range Checks . . . . . . . . . . . . . . . 177 15.4.1.6 gdb and C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 15.4.1.7 gdb Features for C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 15.4.1.8 Decimal Floating Point format . . . . . . . . . . . . . . . . . . . . 179 15.4.2 D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 15.4.3 Go. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 15.4.4 Objective-C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 15.4.4.1 Method Names in Commands . . . . . . . . . . . . . . . . . . . . . 180 15.4.4.2 The Print Command With Objective-C . . . . . . . . . . . . 181 15.4.5 OpenCL C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 15.4.5.1 OpenCL C Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 15.4.5.2 OpenCL C Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 15.4.5.3 OpenCL C Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 15.4.6 Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 15.4.6.1 Fortran Operators and Expressions . . . . . . . . . . . . . . . . 182 15.4.6.2 Fortran Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
v 15.4.6.3 Special Fortran Commands . . . . . . . . . . . . . . . . . . . . . . . . 182 15.4.7 Pascal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 15.4.8 Modula-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 15.4.8.1 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 15.4.8.2 Built-in Functions and Procedures . . . . . . . . . . . . . . . . . 184 15.4.8.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 15.4.8.4 Modula-2 Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 15.4.8.5 Modula-2 Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 15.4.8.6 Deviations from Standard Modula-2 . . . . . . . . . . . . . . . 187 15.4.8.7 Modula-2 Type and Range Checks. . . . . . . . . . . . . . . . . 188 15.4.8.8 The Scope Operators :: and . . . . . . . . . . . . . . . . . . . . . 188 15.4.8.9 gdb and Modula-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 15.4.9 Ada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 15.4.9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 15.4.9.2 Omissions from Ada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 15.4.9.3 Additions to Ada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 15.4.9.4 Stopping at the Very Beginning . . . . . . . . . . . . . . . . . . . 192 15.4.9.5 Extensions for Ada Tasks . . . . . . . . . . . . . . . . . . . . . . . . . 192 15.4.9.6 Tasking Support when Debugging Core Files . . . . . . 195 15.4.9.7 Tasking Support when using the Ravenscar Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 15.4.9.8 Known Peculiarities of Ada Mode . . . . . . . . . . . . . . . . . 196 15.5 Unsupported Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 16 Examining the Symbol Table . . . . . . . . . . . . . . 199 17 Altering Execution. . . . . . . . . . . . . . . . . . . . . . . . . . 205 17.1 Assignment to Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 17.2 Continuing at a Different Address . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 17.3 Giving your Program a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 17.4 Returning from a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 17.5 Calling Program Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 17.6 Patching Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 18 gdb Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 18.1 Commands to Specify Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 18.2 Debugging Information in Separate Files . . . . . . . . . . . . . . . . . . . . 219 Index Files Speed Up gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 18.3 18.4 Errors Reading Symbol Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 18.5 GDB Data Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 19 Specifying a Debugging Target . . . . . . . . . . . . 227 19.1 Active Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 19.2 Commands for Managing Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 19.3 Choosing Target Byte Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
vi Debugging with gdb 20 Debugging Remote Programs . . . . . . . . . . . . . . 231 20.1 Connecting to a Remote Target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 20.2 Sending files to a remote system . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 20.3 Using the gdbserver Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 20.3.1 Running gdbserver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 20.3.1.1 Attaching to a Running Program . . . . . . . . . . . . . . . . . . 234 20.3.1.2 Multi-Process Mode for gdbserver . . . . . . . . . . . . . . . . 234 20.3.1.3 TCP port allocation lifecycle of gdbserver . . . . . . . . 235 20.3.1.4 Other Command-Line Arguments for gdbserver . . . 235 20.3.2 Connecting to gdbserver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 20.3.3 Monitor Commands for gdbserver . . . . . . . . . . . . . . . . . . . . . 236 20.3.4 Tracepoints support in gdbserver . . . . . . . . . . . . . . . . . . . . . . 237 20.4 Remote Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 Implementing a Remote Stub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 20.5 20.5.1 What the Stub Can Do for You . . . . . . . . . . . . . . . . . . . . . . . . 244 20.5.2 What You Must Do for the Stub . . . . . . . . . . . . . . . . . . . . . . . 244 20.5.3 Putting it All Together. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 21 Configuration-Specific Information . . . . . . . . 247 21.1 Native . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 21.1.1 HP-UX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 21.1.2 BSD libkvm Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 21.1.3 SVR4 Process Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 21.1.4 Features for Debugging djgpp Programs . . . . . . . . . . . . . . . 249 21.1.5 Features for Debugging MS Windows PE Executables . . 251 21.1.5.1 Support for DLLs without Debugging Symbols. . . . . 252 21.1.5.2 DLL Name Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 21.1.5.3 Working with Minimal Symbols . . . . . . . . . . . . . . . . . . . 253 21.1.6 Commands Specific to gnu Hurd Systems . . . . . . . . . . . . . . 254 21.1.7 QNX Neutrino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 21.1.8 Darwin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 21.2 Embedded Operating Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 21.2.1 Using gdb with VxWorks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 21.2.1.1 Connecting to VxWorks . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 21.2.1.2 VxWorks Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 21.2.1.3 Running Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 21.3 Embedded Processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 21.3.1 ARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 21.3.2 Renesas M32R/D and M32R/SDI . . . . . . . . . . . . . . . . . . . . . . 261 21.3.3 M68k . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 21.3.4 MicroBlaze . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 21.3.5 MIPS Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 21.3.6 OpenRISC 1000. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 21.3.7 PowerPC Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 21.3.8 HP PA Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 21.3.9 Tsqware Sparclet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 21.3.9.1 Setting File to Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 21.3.9.2 Connecting to Sparclet . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
分享到:
收藏