社区
Linux/Unix社区
帖子详情
GDB出现no debugging symbols found
blueboy82006
2011-10-27 03:57:43
看网上的错误原因都是因为没有加 -g 选项。
但我确定是加了 -g的。
GDB时还是出现:
Reading symbols from /home/XX/XX...(no debugging symbols found)...done.
的情况。
现在根本调试不了。
有这方面经验的朋友来交流下。
...全文
9153
15
打赏
收藏
GDB出现no debugging symbols found
看网上的错误原因都是因为没有加 -g 选项。 但我确定是加了 -g的。 GDB时还是出现: Reading symbols from /home/XX/XX...(no debugging symbols found)...done. 的情况。 现在根本调试不了。 有这方面经验的朋友来交流下。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
15 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
狮子林
2012-08-16
打赏
举报
回复
[Quote=引用 10 楼 的回复:]
我曾经遇到过这种问题。。。我是用.o文件gcc -g 生成一个可执行文件。但是可执行文件是不能够使用gdb的。。
只有使用.c通过gcc生成才能够进行调试的。。。。
gcc -g *.c -o * 这个是不能生成可gdb的文件的。。。
[/Quote]
正解!
zhengsiry
2012-08-10
打赏
举报
回复
这个很有用啊受教了
[Quote=引用 11 楼 的回复:]
gcc -c -g *.c
gcc -o exe *.o
[/Quote]
frogoscar
2012-01-02
打赏
举报
回复
[Quote=引用 10 楼 hrx1989 的回复:]
我曾经遇到过这种问题。。。我是用.o文件gcc -g 生成一个可执行文件。但是可执行文件是不能够使用gdb的。。
只有使用.c通过gcc生成才能够进行调试的。。。。
gcc -g *.c -o * 这个是不能生成可gdb的文件的。。。
[/Quote]
顶~~~~~~~~~~~~~
你在用gcc -c 时加 -g 选项
在gcc *.o -o * 时不用加 -g 选项
就好了
gohome520
2012-01-02
打赏
举报
回复
[Quote=引用 12 楼 frogoscar 的回复:]
引用 10 楼 hrx1989 的回复:
我曾经遇到过这种问题。。。我是用.o文件gcc -g 生成一个可执行文件。但是可执行文件是不能够使用gdb的。。
只有使用.c通过gcc生成才能够进行调试的。。。。
gcc -g *.c -o * 这个是不能生成可gdb的文件的。。。
顶~~~~~~~~~~~~~
你在用gcc -c 时加 -g 选项
在gcc *.o -o * 时……
[/Quote]
gcc *.o -o *,这个加不加-g选项无所谓。
主要是生成.o文件的时候,需要加-g。
hrx1989
2011-10-31
打赏
举报
回复
我曾经遇到过这种问题。。。我是用.o文件gcc -g 生成一个可执行文件。但是可执行文件是不能够使用gdb的。。
只有使用.c通过gcc生成才能够进行调试的。。。。
gcc -g *.c -o * 这个是不能生成可gdb的文件的。。。
yuchongjike
2011-10-31
打赏
举报
回复
gcc -c -g *.c
gcc -o exe *.o
Wenxy1
2011-10-28
打赏
举报
回复
1
Makefile,在文件开头加上:
CFLAGE += -g
xunxun
2011-10-27
打赏
举报
回复
加了后,你strip了没
或者gcc的调试信息 gdb不认识,比如gcc较新,gdb很老
查看gcc和gdb的版本
blueboy82006
2011-10-27
打赏
举报
回复
除了不加-g会出现这种情况,这我知道。
还有没有其他情况?
blueboy82006
2011-10-27
打赏
举报
回复
[Quote=引用 5 楼 lgxwqq111 的回复:]
加-g
[/Quote]
我确定加-g了,makefile只有一行,这个不会有错。
freetstar
2011-10-27
打赏
举报
回复
加-g
braveyly
2011-10-27
打赏
举报
回复
是不是哪里设置冲突了,把-g掩盖了。
建议自己写个简单点的makefile,测试-g和gdb
恨天低
2011-10-27
打赏
举报
回复
贴一下你的makefile文件,或者你gcc、g++时候是怎样搞的
qq120848369
2011-10-27
打赏
举报
回复
编译时候-g。
Linux-Torvalds
2011-10-27
打赏
举报
回复
[Quote=引用楼主 blueboy82006 的回复:]
看网上的错误原因都是因为没有加 -g 选项。
但我确定是加了 -g的。
GDB时还是出现:
Reading symbols from /home/XX/XX...(no debugging symbols found)...done.
的情况。
现在根本调试不了。
有这方面经验的朋友来交流下。
[/Quote]有没有对你的文件strip呢?
GDB
调试应用指南Guide.pdf
GDB
调试应用指南Guide
Debugging
with
GDB
--2007年
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
Debugging
with
GDB
--2003年6.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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4 Logging output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 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 5 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 . . . . . . . . . . . . . . . . . . . . . . 33 34 36 38 40 40 41 43 ii
Debugging
with
gdb
5.1.8 Breakpoint menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.9 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . 5.2 Continuing and stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4 Stopping and starting multi-thread programs . . . . . . . . . . . . . 6 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . 53 6.1 6.2 6.3 6.4 7 Stack frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Selecting a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Information about a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 60 61 61 61 62 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . 65 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 . . . . . . . . . . . . . . . . . . . . . . . 8.15 Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 53 54 55 56 Examining Source Files . . . . . . . . . . . . . . . . . . . 59 7.1 Printing source lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 Editing source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2.1 Choosing your editor . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.3 Searching source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.4 Specifying source directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5 Source and machine code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 44 44 45 48 50 65 66 67 68 69 70 72 76 77 78 79 80 80 81 81 81 81 81 82 C Preprocessor Macros . . . . . . . . . . . . . . . . . . . 87 iii 10 Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 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 . . 99 11.1 11.2 11.3 11.4 12 91 91 92 92 93 94 94 95 95 97 98 98 How Overlays Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Overlay Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Automatic Overlay
Debugging
. . . . . . . . . . . . . . . . . . . . . . . . 102 Overlay Sample Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Using
gdb
with Different Languages . . . . . 105 12.1 Switching between source languages . . . . . . . . . . . . . . . . . . . 105 12.1.1 List of filename extensions and languages . . . . . . 105 12.1.2 Setting the working language . . . . . . . . . . . . . . . . . 106 12.1.3 Having
gdb
infer the source language . . . . . . . . . 106 12.2 Displaying the language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 12.3 Type and range checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 12.3.1 An overview of type checking . . . . . . . . . . . . . . . . . 107 12.3.2 An overview of range checking . . . . . . . . . . . . . . . . 108 12.4 Supported languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 12.4.1 C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 12.4.1.1 C and C++ operators . . . . . . . . . . . . . . . . 110 12.4.1.2 C and C++ constants . . . . . . . . . . . . . . . . 111 12.4.1.3 C++ expressions . . . . . . . . . . . . . . . . . . . . . 112 12.4.1.4 C and C++ defaults . . . . . . . . . . . . . . . . . 113 12.4.1.5 C and C++ type and range checks . . . . 113 12.4.1.6
gdb
and C . . . . . . . . . . . . . . . . . . . . . . . . . 114 12.4.1.7
gdb
features for C++ . . . . . . . . . . . . . . . . 114 12.4.2 Objective-C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 12.4.2.1 Method Names in Commands . . . . . . . . 115 12.4.2.2 The Print Command With Objective-C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 12.4.3 Modula-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 12.4.3.1 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . 116 12.4.3.2 Built-in functions and procedures . . . . 118 12.4.3.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . 119 12.4.3.4 Modula-2 defaults . . . . . . . . . . . . . . . . . . . 119 iv
Debugging
with
gdb
12.4.3.5 Deviations from standard Modula-2 . . 12.4.3.6 Modula-2 type and range checks . . . . . 12.4.3.7 The scope operators :: and . . . . . . . . . 12.4.3.8
gdb
and Modula-2 . . . . . . . . . . . . . . . . . . 12.5 Unsupported languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 120 120 121 121 13 Examining the Symbol Table . . . . . . . . . . . . 123 14 Altering Execution . . . . . . . . . . . . . . . . . . . . . 129 14.1 14.2 14.3 14.4 14.5 14.6 15 Assignment to variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Continuing at a different address . . . . . . . . . . . . . . . . . . . . . . Giving your program a signal . . . . . . . . . . . . . . . . . . . . . . . . . Returning from a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . Calling program functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . Patching programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 130 131 131 132 132
gdb
Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 15.1 Commands to specify files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 15.2
Debugging
Information in Separate Files . . . . . . . . . . . . . . . 139 15.3 Errors reading symbol files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 16 Specifying a
Debugging
Target . . . . . . . . . . 145 16.1 16.2 16.3 16.4 16.5 17 Active targets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Commands for managing targets . . . . . . . . . . . . . . . . . . . . . . Choosing target byte order. . . . . . . . . . . . . . . . . . . . . . . . . . . . Remote
debugging
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Kernel Object Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 145 147 147 148
Debugging
remote programs . . . . . . . . . . . . 149 17.1 17.2 17.3 17.4 17.5 Connecting to a remote target . . . . . . . . . . . . . . . . . . . . . . . . Using the
gdb
server program. . . . . . . . . . . . . . . . . . . . . . . . . Using the
gdb
serve.nlm program . . . . . . . . . . . . . . . . . . . . . Remote configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Implementing a remote stub . . . . . . . . . . . . . . . . . . . . . . . . . . 17.5.1 What the stub can do for you . . . . . . . . . . . . . . . . 17.5.2 What you must do for the stub . . . . . . . . . . . . . . . 17.5.3 Putting it all together . . . . . . . . . . . . . . . . . . . . . . . 149 150 151 151 152 153 153 155 v 18 Configuration-Specific Information . . . . . . . 157 18.1 Native . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 18.1.1 HP-UX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 18.1.2 SVR4 process information . . . . . . . . . . . . . . . . . . . . 157 18.1.3 Features for
Debugging
djgpp Programs . . . . . . 157 18.1.4 Features for
Debugging
MS Windows PE executables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 18.1.4.1 Support for DLLs without
debugging
symbols
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 18.1.4.2 DLL name prefixes . . . . . . . . . . . . . . . . . . 160 18.1.4.3 Working with minimal
symbols
. . . . . . 161 18.2 Embedded Operating Systems. . . . . . . . . . . . . . . . . . . . . . . . . 162 18.2.1 Using
gdb
with VxWorks . . . . . . . . . . . . . . . . . . . . 162 18.2.1.1 Connecting to VxWorks . . . . . . . . . . . . . 163 18.2.1.2 VxWorks download . . . . . . . . . . . . . . . . . 163 18.2.1.3 Running tasks . . . . . . . . . . . . . . . . . . . . . . 164 18.3 Embedded Processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 18.3.1 ARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 18.3.2 Hitachi H8/300 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 18.3.2.1 Connecting to Hitachi boards . . . . . . . . 165 18.3.2.2 Using the E7000 in-circuit emulator . . 166 18.3.2.3 Special
gdb
commands for Hitachi micros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 18.3.3 H8/500 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 18.3.4 Mitsubishi M32R/D . . . . . . . . . . . . . . . . . . . . . . . . . 167 18.3.5 M68k . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 18.3.6 MIPS Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 18.3.7 OpenRISC 1000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 18.3.8 PowerPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 18.3.9 HP PA Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 18.3.10 Hitachi SH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 18.3.11 Tsqware Sparclet . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 18.3.11.1 Setting file to debug. . . . . . . . . . . . . . . . 172 18.3.11.2 Connecting to Sparclet . . . . . . . . . . . . . 172 18.3.11.3 Sparclet download . . . . . . . . . . . . . . . . . 173 18.3.11.4 Running and
debugging
. . . . . . . . . . . . 173 18.3.12 Fujitsu Sparclite . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 18.3.13 Tandem ST2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 18.3.14 Zilog Z8000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 18.4 Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 18.4.1 A29K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 18.4.2 Alpha . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 18.4.3 MIPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 vi 19
Debugging
with
gdb
Controlling
gdb
. . . . . . . . . . . . . . . . . . . . . . . . 177 19.1 19.2 19.3 19.4 19.5 19.6 19.7 19.8 20 Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Screen size. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Configuring the current ABI . . . . . . . . . . . . . . . . . . . . . . . . . . Optional warnings and messages . . . . . . . . . . . . . . . . . . . . . . Optional messages about internal happenings. . . . . . . . . . . 177 177 177 179 179 180 181 182 Canned Sequences of Commands . . . . . . . . 185 20.1 20.2 20.3 20.4 User-defined commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . User-defined command hooks . . . . . . . . . . . . . . . . . . . . . . . . . Command files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Commands for controlled output . . . . . . . . . . . . . . . . . . . . . . 185 186 187 188 21 Command Interpreters . . . . . . . . . . . . . . . . . . 191 22
gdb
Text User Interface . . . . . . . . . . . . . . . . . 193 22.1 22.2 22.3 22.4 22.5 TUI TUI TUI TUI TUI overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Single Key Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . specific commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . configuration variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 194 195 195 196 23 Using
gdb
under gnu Emacs . . . . . . . . . . . . 199 24 The
gdb
/mi Interface . . . . . . . . . . . . . . . . . . . 201 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 . . . . . . . . . . . . . . . . . . . 201 201 201 201 202 204 204 205 205 205 205 206 206 215 225 236 238 243 vii 24.11 24.12 24.13 24.14 25 Target Manipulation Commands . . . . . . . . . . . . . Thread Commands . . . . . . . . . . . . . . . . . . . . . . . . . . Tracepoint Commands. . . . . . . . . . . . . . . . . . . . . . . Variable Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 252 254 254
gdb
Annotations . . . . . . . . . . . . . . . . . . . . . . . 261 25.1 25.2 25.3 25.4 25.5 25.6 25.7 26
gdb
/mi
gdb
/mi
gdb
/mi
gdb
/mi What is an Annotation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Server Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Annotation for
gdb
Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Invalidation Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displaying Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 261 262 262 263 263 264 Reporting Bugs in
gdb
. . . . . . . . . . . . . . . . . . 265 26.1 Have you found a bug? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 26.2 How to report bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 27 Command Line Editing . . . . . . . . . . . . . . . . . 269 27.1 Introduction to Line Editing . . . . . . . . . . . . . . . . . . . . . . . . . . 27.2 Readline Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.2.1 Readline Bare Essentials . . . . . . . . . . . . . . . . . . . . . 27.2.2 Readline Movement Commands . . . . . . . . . . . . . . . 27.2.3 Readline Killing Commands . . . . . . . . . . . . . . . . . . 27.2.4 Readline Arguments . . . . . . . . . . . . . . . . . . . . . . . . . 27.2.5 Searching for Commands in the History . . . . . . . 27.3 Readline Init File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.3.1 Readline Init File Syntax. . . . . . . . . . . . . . . . . . . . . 27.3.2 Conditional Init Constructs . . . . . . . . . . . . . . . . . . 27.3.3 Sample Init File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.4 Bindable Readline Commands. . . . . . . . . . . . . . . . . . . . . . . . . 27.4.1 Commands For Moving . . . . . . . . . . . . . . . . . . . . . . 27.4.2 Commands For Manipulating The History . . . . . 27.4.3 Commands For Changing Text . . . . . . . . . . . . . . . 27.4.4 Killing And Yanking . . . . . . . . . . . . . . . . . . . . . . . . . 27.4.5 Specifying Numeric Arguments . . . . . . . . . . . . . . . 27.4.6 Letting Readline Type For You . . . . . . . . . . . . . . . 27.4.7 Keyboard Macros. . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.4.8 Some Miscellaneous Commands . . . . . . . . . . . . . . . 27.5 Readline vi Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 269 269 269 270 270 271 271 272 272 277 277 281 281 281 282 284 285 285 285 286 287 Using History Interactively. . . . . . . . . . . . . . 289 28.1 History 28.1.1 28.1.2 28.1.3 Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Designators . . . . . . . . . . . . . . . . . . . . . . . . . . . Word Designators . . . . . . . . . . . . . . . . . . . . . . . . . . . Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 289 289 290 viii
Debugging
with
gdb
Appendix A Formatting Documentation . . . . . 293 Appendix B Installing
gdb
. . . . . . . . . . . . . . . . . 295 B.1 Compiling
gdb
in another directory . . . . . . . . . . . . . . . . . . . . 296 B.2 Specifying names for hosts and targets . . . . . . . . . . . . . . . . . 297 B.3 configure options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 Appendix C Maintenance Commands . . . . . . . 299 Appendix D
gdb
Remote Serial Protocol . . . . 301 D.1 D.2 D.3 D.4 D.5 D.6 D.7 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stop Reply Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . General Query Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Register Packet Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . File-I/O remote protocol extension . . . . . . . . . . . . . . . . . . . . . D.7.1 File-I/O Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . D.7.2 Protocol basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.7.3 The F request packet . . . . . . . . . . . . . . . . . . . . . . . . . D.7.4 The F reply packet . . . . . . . . . . . . . . . . . . . . . . . . . . . D.7.5 Memory transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.7.6 The Ctrl-C message . . . . . . . . . . . . . . . . . . . . . . . . . . D.7.7 Console I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.7.8 The isatty(3) call . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.7.9 The system(3) call . . . . . . . . . . . . . . . . . . . . . . . . . . . D.7.10 List of supported calls . . . . . . . . . . . . . . . . . . . . . . . open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . read. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . lseek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . rename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . unlink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . stat/fstat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . gettimeofday . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . isatty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.7.11 Protocol specific representation of datatypes . . Integral datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pointer values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . struct stat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . struct timeval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.7.12 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Open flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . mode t values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Errno values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 302 308 309 312 312 312 312 313 314 314 315 315 315 316 316 316 316 317 318 318 319 319 320 320 321 321 321 322 322 322 322 323 323 323 324 324 ix Lseek flags. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324 Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324 D.7.13 File-I/O Examples . . . . . . . . . . . . . . . . . . . . . . . . . . 325 Appendix E The
GDB
Agent Expression Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 E.1 E.2 E.3 E.4 E.5 E.6 General Bytecode Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bytecode Descriptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Agent Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Varying Target Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . Tracing on Symmetrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Rationale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 329 333 333 334 336 Appendix F GNU GENERAL PUBLIC LICENSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION . . . . . . . . . . . . . . . 339 How to Apply These Terms to Your New Programs . . . . . . . . . . . 344 Appendix G GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 ADDENDUM: How to use this License for your documents . . . . 350 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
ctf-vagrant-64
无业游民的CTF盒子 附带的工具 安装VirtualBox 检查以获取有关在各自的操作系统上安装Virtualbox的信息。 安装无业游民 检查以获取有关安装vagrant的信息。 检查正确的安装 Pwndbg 在虚拟机中运行以下命令:
gdb
/bin/ls 预期产量: Loaded 53 commands. Type pwndbg for a list. Reading
symbols
from host-share/crackme...(no
debugging
symbols
found)...done. Only available when running pwn> 拉达雷 在虚拟机中运行以下命令: r2 /bin/ls 预期产量: [0x00404890]> aaa 宾柔 在虚拟机中运行以下命令: python >>> from pwn import * >>
Springer.The.Developer’s.Guide.to.
Debugging
.2008.pdf
1 You Write Software; You have Bugs . . . . . . . . . 1 2 A Systematic Approach to
Debugging
. . . . . . . 5 2.1 Why Follow a Structured Process? . . . . . . . 5 2.2 Making the Most of Your Opportunities . . . . . . 5 2.3 13 Golden Rules . . . . . . . . . . . . . 7 2.3.1 Understand the Requirements . . . . . . 8 2.3.2 Make it Fail . . . . . . . . . . . . 8 2.3.3 Simplify the Test Case . . . . . . . . . 9 2.3.4 Read the Right Error Message . . . . . . 9 2.3.5 Check the Plug . . . . . . . . . 9 2.3.6 Separate Facts from Interpretation . . . . . 10 2.3.7 Divide and Conquer . . . . . . . . 10 2.3.8 Match the Tool to the Bug . . . . . . . . . 12 2.3.9 One Change at a Time . . . . . . . . . 12 2.3.10 Keep an Audit Trail . . . . . . . . 12 2.3.11 Get a Fresh View . . . . . . . . . . . 13 2.3.12 If You Didn’t Fix it, it Ain’t Fixed . . . . . 13 2.3.13 Cover your Bugfix with a Regression Test . . . . . 13 2.4 Build a Good Toolkit . . . . . . . . . . . . 14 2.4.1 Your Workshop . . . . . . . . . 15 2.4.2 Running Tests Every Day Keeps the Bugs at Bay . . 15 2.5 Know Your Enemy – Meet the Bug Family . . . . . . 17 2.5.1 The Common Bug . . . . . . . . . . 17 2.5.2 Sporadic Bugs . . . . . . . . . . 18 2.5.3 Heisenbugs. . . . . . . . . . 18 2.5.4 Bugs Hiding Behind Bugs . . . . . . . . . 19 2.5.5 Secret Bugs –
Debugging
and Confidentiality . . . . . 20 2.5.6 Further Reading . . . . . . . . . 21 3 Getting to the Root – Source Code Debuggers . . . . . . 23 3.1 Visualizing Program Behavior . . . . . . . . 23 3.2 Prepare a Simple Predictable Example . . . . . . . 24 3.3 Get the Debugger to Run with Your Program . . . . . . . 24 3.4 Learn to do a Stack Trace on a Program Crash . . . . . . 27 3.5 Learn to Use Breakpoints . . . . . . . . . 28 3.6 Learn to Navigate Through the Program. . . . . . 28 3.7 Learn to Inspect Data: Variables and Expressions . . . . 29 3.8 A Debug Session on a Simple Example . . . . . . 30 4 Fixing Memory Problems . . . . . . . . . . . . 33 4.1 Memory Management in C/C++ – Powerful but Dangerous . . . . 33 4.1.1 Memory Leaks . . . . . . . . . 34 4.1.2 Incorrect Use of Memory Management . . . . 34 4.1.3 Buffer Overruns . . . . . . . . . . . 34 4.1.4 Uninitialized Memory Bugs . . . . . . . . 34 4.2 Memory Debuggers to the Rescue . . . . . . . . 35 4.3 Example 1: Detecting Memory Access Errors . . . . . . . 36 4.3.1 Detecting an Invalid Write Access . . . . . 36 4.3.2 Detecting Uninitialized Memory Reads . . . . 37 4.3.3 Detecting Memory Leaks . . . . . . . 38 4.4 Example 2: Broken Calls to Memory Allocation/Deallocation . . 38 4.5 Combining Memory and Source Code Debuggers . . . . . . 40 4.6 Cutting Down the Noise – Suppressing Errors . . . . . . . 40 4.7 When to Use a Memory Debugger . . . . . . . 41 4.8 Restrictions . . . . . . . . . . . . . . 42 4.8.1 Prepare Test Cases with Good Code Coverage . . . . 42 4.8.2 Provide Additional Computer Resources . . . . . . 42 4.8.3 Multi-Threading May Not be Supported . . . . . . 42 4.8.4 Support for Non-standard Memory Handlers . . . 42 5 Profiling Memory Use . . . . . . . . . . . . 45 5.1 Basic Strategy – The First Steps . . . . . . . . . 45 5.2 Example 1: Allocating Arrays . . . . . . . . 46 5.3 Step 1: Look for Leaks . . . . . . . . . . . 46 5.4 Step 2: Set Your Expectations . . . . . . . . 47 5.5 Step 3: Measure Memory Consumption . . . . . . 47 5.5.1 Use Multiple Inputs . . . . . . . . 48 5.5.2 Stopping the Program at Regular Intervals . . . . . 48 5.5.3 Measuring Memory Consumption with Simple Tools . . 49 5.5.4 Use top . . . . . . . . . . . . 49 5.5.5 Use the Windows Task Manager . . . . . . . 50 5.5.6 Select Relevant Input Values for testmalloc . . . 51 5.5.7 Determine how Memory is Deallocated on Your Machine . 51 5.5.8 Use a Memory Profiler . . . . . . . . . 53 5.6 Step 4: Identifying Greedy Data Structures . . . . . . 54 5.6.1 Instrumenting Data Structures . . . . . . 55 5.7 Putting it Together – The genindex Example. . . . . . 55 5.7.1 Check that There are No Major Leaks . . . . . 56 5.7.2 Estimate the Expected Memory Use . . . . . . . 56 5.7.3 Measure Memory Consumption . . . . . . . 57 5.7.4 Find the Data Structures that Consume Memory . . . 57 6 Solving Performance Problems . . . . . . . . . . 63 6.1 Finding Performance Bugs – A Step-by-Step Approach . . . . . 63 6.1.1 Do an Upfront Analysis . . . . . . . . 64 6.1.2 Use a Simple Method of Measuring Time . . . . . 64 6.1.3 Create a Test Case . . . . . . . . . . 65 6.1.4 Make the Test Case Reproducible . . . . . . 65 6.1.5 Check the Program for Correctness . . . . . . . 66 6.1.6 Make the Test Case Scalable . . . . . . . 66 6.1.7 Isolate the Test Case from Side Effects . . . . 67 6.1.8 Measurement with time can have Errors and Variations . 68 6.1.9 Select a Test Case that Exposes the Runtime Bottleneck . . 68 6.1.10 The Difference Between Algorithm and Implementation . . 70 6.2 Using Profiling Tools . . . . . . . . . . . . 72 6.2.1 Do Not Write Your Own Profiler . . . . . . . 72 6.2.2 How Profilers Work . . . . . . . . 73 6.2.3 Familiarize Yourself with gprof . . . . . . 74 6.2.4 Familiarize Yourself with Quantify . . . . . 79 6.2.5 Familiarize Yourself with Callgrind . . . . . . . 81 6.2.6 Familiarize Yourself with VTune . . . . . . 82 6.3 Analyzing I/O Performance . . . . . . . . . . 84 6.3.1 Do a Sanity Check of Your Measurements . . . . . 85 7
Debugging
Parallel Programs . . . . . . . . . 87 7.1 Writing Parallel Programs in C/C++ . . . . . . . . . 87 7.2
Debugging
Race Conditions . . . . . . . . . . 88 7.2.1 Using Basic Debugger Capabilities to Find Race Conditions . . . . . . . . . . 89 7.2.2 Using Log Files to Localize Race Conditions . . . . . 91 7.3
Debugging
Deadlocks . . . . . . . . . . . . 93 7.3.1 How to Determine What the Current Thread is Executing . 94 7.3.2 Analyzing the Threads of the Program . . . . . 95 7.4 Familiarize Yourself with Threading Analysis Tools . . . . . 96 7.5 Asynchronous Events and Interrupt Handlers . . . . . . . 98 8 Finding Environment and Compiler Problems . . . . . . 101 8.1 Environment Changes – Where Problems Begin . . . . . 101 8.1.1 Environment Variables . . . . . . . . . 101 8.1.2 Local Installation Dependencies . . . . . . . 102 8.1.3 Current Working Directory Dependency . . . . . . 102 8.1.4 Process ID Dependency . . . . . . . . 102 8.2 How else to See what a Program is Doing . . . . . . . 103 8.2.1 Viewing Processes with top . . . . . . . 103 8.2.2 Finding Multiple Processes of an Application with ps . . . 103 8.2.3 Using /proc/
to Access a Process . . . . 104 8.2.4 Use strace to Trace Calls to the OS . . . . . 104 8.3 Compilers and Debuggers have Bugs too . . . . . . . . 106 8.3.1 Compiler Bugs . . . . . . . . . 106 8.3.2 Debugger and Compiler Compatibility Problems . . 107 9 Dealing with Linking Problems . . . . . . . . . . 109 9.1 How a Linker Works . . . . . . . . . . 109 9.2 Building and Linking Objects . . . . . . . . 110 9.3 Resolving Undefined
Symbols
. . . . . . . . 111 9.3.1 Missing Linker Arguments . . . . . . . . 111 9.3.2 Searching for Missing
Symbols
. . . . . . . . 112 9.3.3 Linking Order Issues . . . . . . . . . . 113 9.3.4 C++
Symbols
and Name Mangling . . . . . 114 9.3.5 Demangling of
Symbols
. . . . . . . . 115 9.3.6 Linking C and C++ Code . . . . . . . 115 9.4
Symbols
with Multiple Definitions . . . . . . . 116 9.5 Symbol Clashes . . . . . . . . . . . 117 9.6 Identifying Compiler and Linker Version Mismatches . . . 118 9.6.1 Mismatching System Libraries . . . . . . . . 119 9.6.2 Mismatching Object Files . . . . . . . . . 119 9.6.3 Runtime Crashes . . . . . . . . . . . 120 9.6.4 Determining the Compiler Version . . . . . 120 9.7 Solving Dynamic Linking Issues . . . . . . . . . 122 9.7.1 Linking or Loading DLLs . . . . . . . . . 122 9.7.2 DLL Not Found . . . . . . . . . 124 9.7.3 Analyzing Loader Issues . . . . . . . 125 9.7.4 Setting Breakpoints in DLLs . . . . . . . 126 9.7.5 Provide Error Messages for DLL Issues . . . . 127 10 Advanced
Debugging
. . . . . . . . . . . . . 129 10.1 Setting Breakpoints in C++ Functions, Methods, and Operators . 129 10.2 Setting Breakpoints in Templatized Functions and C++ Classes . 131 10.3 Stepping in C++ Methods . . . . . . . . . 133 10.3.1 Stepping into Implicit Functions . . . . . . . 134 10.3.2 Skipping Implicit Functions with the Step-out Command . 135 10.3.3 Skipping Implicit Functions with a Temporary Breakpoint 136 10.3.4 Returning from Implicit Function Calls . . . . 136 10.4 Conditional Breakpoints and Breakpoint Commands . . . . 137 10.5
Debugging
Static Constructor/Destructor Problems . . . . . 140 10.5.1 Bugs Due to Order-Dependence of Static Initializers . . 140 10.5.2 Recognizing the Stack Trace of Static Initializers . . 141 10.5.3 Attaching the Debugger Before Static Initialization . . . 142 10.6 Using Watchpoints . . . . . . . . . . . 143 10.7 Catching Signals . . . . . . . . . . . . . 144 10.8 Catching Exceptions . . . . . . . . . . 147 10.9 Reading Stack Traces . . . . . . . . . . . . 148 10.9.1 Stack Trace of Source Code Compiled with Debug Information . . . . . . . . 148 10.9.2 Stack Trace of Source Code Compiled Without Debug Information . . . . . . . . 149 10.9.3 Frames Without Any Debug Information . . . . . . 149 10.9.4 Real-Life Stack Traces . . . . . . . . . 150 10.9.5 Mangled Function Names . . . . . . . . . 151 10.9.6 Broken Stack Traces . . . . . . . . 151 10.9.7 Core Dumps . . . . . . . . . . . . 152 10.10 Manipulating a Running Program . . . . . . . . 153 10.10.1 Changing a Variable . . . . . . . . 156 10.10.2 Calling Functions . . . . . . . . . . 156 10.10.3 Changing the Return Value of a Function . . . . . . 157 10.10.4 Aborting Function Calls . . . . . . . . 157 10.10.5 Skipping or Repeating Individual Statements . . . . . 158 10.10.6 Printing and Modifying Memory Content . . . . . 159 10.11
Debugging
Without Debug Information . . . . . . 161 10.11.1 Reading Function Arguments From the Stack . . . . . 163 10.11.2 Reading Local/Global Variables, User-Defined Data Types 165 10.11.3 Finding the Approximate Statement in the Source Code . . 165 10.11.4 Stepping Through Assembly Code . . . . . 166 11 Writing Debuggable Code . . . . . . . . . . . . 169 11.1 Why Comments Count . . . . . . . . . . . 169 11.1.1 Comments on Function Signatures . . . . . 170 11.1.2 Comments on Workarounds . . . . . . . . 171 11.1.3 Comments in Case of Doubt . . . . . . . 171 11.2 Adopting a Consistent Programming Style . . . . . . 171 11.2.1 Choose Names Carefully . . . . . . . 171 11.2.2 Avoid Insanely Clever Constructs . . . . . . 172 11.2.3 Spread Out Your Code . . . . . . . . . 172 11.2.4 Use Temporary Variables for Complex Expressions . . . 172 11.3 Avoiding Preprocessor Macros . . . . . . . . . . 173 11.3.1 Use Constants or Enums Instead of Macros . . . . 173 11.3.2 Use Functions Instead of Preprocessor Macros . . . . 175 11.3.3 Debug the Preprocessor Output . . . . . . . . 176 11.3.4 Consider Using More Powerful Preprocessors . . . . 177 11.4 Providing Additional
Debugging
Functions . . . . . . 179 11.4.1 Displaying User-Defined Data Types . . . . . . 179 11.4.2 Self-Checking Code . . . . . . . . 180 11.4.3 Debug Helpers for Operators . . . . . . . 181 11.5 Prepare for Post-Processing . . . . . . . . . . 181 11.5.1 Generate Log Files . . . . . . . . . 181 12 How Static Checking Can Help . . . . . . . . . . 183 12.1 Using Compilers as
Debugging
Tools . . . . . . . . 183 12.1.1 Do not Assume Warnings to be Harmless . . . . . 184 12.1.2 Use Multiple Compilers to Check the Code . . . . 186 12.2 Using lint . . . . . . . . . . . . . . 186 12.3 Using Static Analysis Tools . . . . . . . . . . 187 12.3.1 Familiarize Yourself with a Static Checker . . . . 187 12.3.2 Reduce Static Checker Errors to (Almost) Zero . . . 189 12.3.3 Rerun All Test Cases After a Code Cleanup . . . 190 12.4 Beyond Static Analysis . . . . . . . . . . . 190 13 Summary . . . . . . . . . . . . . . 191 A Debugger Commands . . . . . . . . . . . . . 193 B Access to Tools . . . . . . . . . . . . . 195 B.1 IDEs, Compilers, Build Tools . . . . . . . . 195 B.1.1 Microsoft Visual Studio . . . . . . . . 195 B.1.2 Eclipse . . . . . . . . . . . . . 196 B.1.3 GCC . . . . . . . . . . . . 196 B.1.4 GNU Make . . . . . . . . . . . . 196 B.2 Debuggers . . . . . . . . . . . . 196 B.2.1 dbx . . . . . . . . . . . . . 196 B.2.2 DDD . . . . . . . . . . . . 197 B.2.3
GDB
. . . . . . . . . . . . 197 B.2.4 ARM RealView . . . . . . . . . 197 B.2.5 TotalView Debugger . . . . . . . . 197 B.2.6 Lauterbach TRACE32 . . . . . . . . . 197 B.3 Environments . . . . . . . . . . . . . 198 B.3.1 Cygwin . . . . . . . . . . . . . 198 B.3.2 VMware . . . . . . . . . . . . 198 B.4 Memory Debuggers . . . . . . . . . . . 198 B.4.1 Purify . . . . . . . . . . . 198 B.4.2 Valgrind . . . . . . . . . . . . 199 B.4.3 KCachegrind . . . . . . . . . . . 199 B.4.4 Insure++ . . . . . . . . . . . . 199 B.4.5 BoundsChecker . . . . . . . . . 200 B.5 Profilers . . . . . . . . . . . . . . 200 B.5.1 gprof . . . . . . . . . . . . 200 B.5.2 Quantify . . . . . . . . . . . . 200 B.5.3 Intel VTune . . . . . . . . . . . . 200 B.5.4 AQtime . . . . . . . . . . . . . 201 B.5.5 mpatrol . . . . . . . . . . . . . 201 B.6 Static Checkers . . . . . . . . . . . 201 B.6.1 Coverity . . . . . . . . . . . . 201 B.6.2 Lint . . . . . . . . . . . . . 201 B.6.3 Splint . . . . . . . . . . . 202 B.6.4 /analyze option in Visual Studio Enterprise Versions . . 202 B.6.5 Klocwork . . . . . . . . . . . 202 B.6.6 Fortify . . . . . . . . . . . . . 202 B.6.7 PC-lint/FlexeLint . . . . . . . . . . 203 B.6.8 QA C++ . . . . . . . . . . . . 203 B.6.9 Codecheck . . . . . . . . . . 203 B.6.10 Axivion Bauhaus Suite . . . . . . . . . 203 B.6.11 C++ SoftBench CodeAdvisor . . . . . . 203 B.6.12 Parasoft C++test . . . . . . . . . . . 204 B.6.13 LDRA tool suite . . . . . . . . . . . 204 B.6.14 Understand C++ . . . . . . . . . . . 204 B.7 Tools for Parallel Programming . . . . . . . . . . 204 B.7.1 Posix Threads . . . . . . . . . . 204 B.7.2 OpenMP . . . . . . . . . . . . 204 B.7.3 Intel TBB . . . . . . . . . . . 205 B.7.4 MPI . . . . . . . . . . . . . 205 B.7.5 MapReduce . . . . . . . . . . . . 205 B.7.6 Intel Threading Analysis Tools . . . . . . . . 205 B.8 Miscellaneous Tools . . . . . . . . . . 206 B.8.1 GNU Binutils . . . . . . . . . . . 206 B.8.2 m4 . . . . . . . . . . . . . . 206 B.8.3 ps . . . . . . . . . . . . . . 206 B.8.4 strace / truss . . . . . . . . . . 207 B.8.5 top. . . . . . . . . . . . . 207 B.8.6 VNC . . . . . . . . . . . . 207 B.8.7 WebEx . . . . . . . . . . . . . 207 C Source Code . . . . . . . . . . . . . . . 209 C.1 testmalloc.c . . . . . . . . . . . . . . 209 C.2 genindex.c . . . . . . . . . . . . 210 C.3 isort.c . . . . . . . . . . . . . 214 C.4 filebug.c . . . . . . . . . . . . . . 216 References . . . . . . . . . . . . . . 217 Index . . . . . . . . . . . . . . . . 219
Linux/Unix社区
23,209
社区成员
74,537
社区内容
发帖
与我相关
我的任务
Linux/Unix社区
Linux/Unix社区 应用程序开发区
复制链接
扫一扫
分享
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章