GDB调试,遭遇“cannot access memory at address”

jiankevin 2008-01-23 07:55:14
hi, 大家好!

本人系GCC小菜鸟,因最近工作需要,在WINDOWS上安装了MINGW32调试XviD代码。从网络上下载了代码后,修改了xvidcore-1.0.3/buid/generic/makefile文件,将源文件的如下内容:
CFLAGS = $(ARCHITECTURE) $(BUS) $(ENDIANNESS) $(FEATURES) $(SPECIFIC_CFLAGS)
修改为:
CFLAGS = -g $(ARCHITECTURE) $(BUS) $(ENDIANNESS) $(FEATURES) $(SPECIFIC_CFLAGS)
即添加GDB调试选项,然后configure-->make-->make install,最后在'usr/local'下生成了xvidcore.a,xvidcore.dll和xvidcore.dll.a。

下面的步骤用【1】【2】..列出。

【1】cd到examples文件夹下,使用如下命令:
$gcc -g -DARCH_IS_LITTLE_ENDIAN -DARCH_IS_GENERIC -DARCH_IS_32BIT -o xvid_decraw -I ../src xvid_decraw.c ../build/generic/=build/xvidcore.a
成功,生成xvid_decraw.exe。
【2】开始GDB。
$gdb xvid_decraw.exe
【3】list到指定的位置,xvid_decraw.c的699行,这一行代码为:
699: ret = xvid_decore(dec_handle, XVID_DEC_DECODE, &xvid_dec_frame, xvid_dec_stats);
【4】设置断点
$b 699
设置成功
【5】运行
$run -i test.mp4 -c rgb24 -f tga -d
上面的参数表示输入test.mp4文件,允许输出为RGB24位的TGA文件。
【6】停在断点处,此时输入‘s’,单步进入该函数,由于该函数在decoder.c中,已经被编译成library,即存在于前面的xvidcore.a中。
【7】 此时list可以看到decoder.i函数中的所有函数(如果不单步进入,list就看不到,不知道为什么?),在decoder_mbintra函数内部设置断点:
$list decoder_mbintra
$b 298
【8】continue到第二个断点处,出现如下提示:
(gdb)cannot access memory at address 0x80
【9】此时想打印该函数的局部变量stride,仍然提示
(gdb)cannot access memory at address 0x74

我在网络上搜索,有人说是library没有被load进来,我想如果没有被load进来,应该不可能单步进入这个文件,也不可能list出来,我将所有的断点disable,然后continue,可以完整的解码完整个序列,而且是正确的。

不知道有哪位大侠可以帮我看看这个问题,因为我需要进入到内部去调试,所以一定要能观察到程序运行时的变量值。

不知道有没有把这个问题说清楚,真诚希望有人帮助我,谢谢!
...全文
43037 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
paokuflying 2021-06-28
  • 打赏
  • 举报
回复

重新编译下试试,有可能是可执行文件给错了。

chen1255 2010-12-16
  • 打赏
  • 举报
回复
你看一下是不是你的引用指针没有分配内存,所以gcc debugger 会报这个错误。按你说的能单步调试,证明是已经加载了
threeleafzerg007 2009-06-20
  • 打赏
  • 举报
回复
这也我也碰到过 正常

给你个网址

http://www.cs.berkeley.edu/~smcpeak/memory-errors/

Now I restart the program and attempt to set a hardware watchpoint:

(gdb) break main
Breakpoint 1 at 0x8048b91: file tmalloc.c, line 81.
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y

Starting program: /home/scott/wrk/cplr/smbase/tmalloc

Breakpoint 1, main () at tmalloc.c:81
(gdb) watch *((int*)0x80508c6)
Cannot access memory at address 0x80508c6
(gdb)

Ok, the memory isn't mapped yet. Single-stepping through main a few times, I find a place where I can insert the watchpoint but the memory in question hasn't yet been trashed. When I then continue the program, the debugger next stops at the bug.

简而言之,这个线性地址 所在的区域 可能还没有映射到物理内存上
bxhsix 2009-06-20
  • 打赏
  • 举报
回复
有可能是你的程序或者你引用的库是32位,而你所使用的机器是64位的,如果是这样,那么你不能使用gdb,而应该使用gdb.32命令来进行调试。
zeloas 2008-01-24
  • 打赏
  • 举报
回复 1
可能是代码的有问题,也有可能是你运行不当。
问题可能是运行至此内存的地址不可访问,错误很早就犯下了,建议断点设的前一点。
kingwoo 2008-01-24
  • 打赏
  • 举报
回复
如果你没有lib的源码,理论上你是没法单步进入lib的。
你可以这样试试看
先用nm lib的名字查看xvid_decore的地址
然后
b *0x地址
或者地址偏移一些的位置
看会不会还出现cannot access
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 gdbserver program. . . . . . . . . . . . . . . . . . . . . . . . . Using the gdbserve.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
Table of Contents Summary of GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Free software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Free Software Needs Free Documentation . . . . . . . . . . . . . . . . . . . . . . 1 Contributors to GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1 A Sample GDB Session . . . . . . . . . . . . . . . . . . . . 7 2 Getting In and Out of GDB . . . . . . . . . . . . . . . 11 2.1 Invoking GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Choosing files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.2 Choosing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Quitting GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 Shell commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 GDB Commands . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.1 3.2 3.3 4 Command syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Command completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Getting help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Running Programs Under GDB . . . . . . . . . . . 23 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 5 11 12 13 15 15 Compiling for debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Starting your program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Your program’s arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Your program’s environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . Your program’s working directory . . . . . . . . . . . . . . . . . . . . . . . Your program’s input and output . . . . . . . . . . . . . . . . . . . . . . . . Debugging an already-running process . . . . . . . . . . . . . . . . . . . Killing the child process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debugging programs with multiple threads . . . . . . . . . . . . . . . Debugging programs with multiple processes . . . . . . . . . . . . 23 24 25 25 26 26 27 28 28 30 Stopping and Continuing . . . . . . . . . . . . . . . . . . 33 5.1 Breakpoints, watchpoints, and catchpoints . . . . . . . . . . . . . . . 5.1.1 Setting breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.2 Setting watchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3 Setting catchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.4 Deleting breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.5 Disabling breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.6 Break conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.7 Breakpoint command lists . . . . . . . . . . . . . . . . . . . . . . 5.1.8 Breakpoint menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 34 37 39 40 41 42 43 44 ii Debugging with GDB 5.2 5.3 5.4 6 Stack frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Selecting a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Information about a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Printing source lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Searching source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Specifying source directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . Source and machine code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 58 59 59 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . 63 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 8.11 8.12 8.13 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Program variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Artificial arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Output formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examining memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Automatic display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Print settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Value history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Convenience variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Floating point hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Vector Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Memory region attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.13.1 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.13.1.1 Memory Access Mode . . . . . . . . . . . . . . . . 8.13.1.2 Memory Access Size . . . . . . . . . . . . . . . . . . 8.13.1.3 Data Cache . . . . . . . . . . . . . . . . . . . . . . . . . . 8.14 Copy between memory and a file . . . . . . . . . . . . . . . . . . . . . . . 9 53 54 55 56 Examining Source Files . . . . . . . . . . . . . . . . . . . 57 7.1 7.2 7.3 7.4 8 45 45 48 50 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . 53 6.1 6.2 6.3 6.4 7 5.1.9 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . Continuing and stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stopping and starting multi-thread programs . . . . . . . . . . . . . 63 64 65 66 67 68 70 75 76 77 78 78 78 79 79 80 80 80 C Preprocessor Macros . . . . . . . . . . . . . . . . . . . 83 iii 10 Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 10.1 Commands to Set Tracepoints. . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.1 Create and Delete Tracepoints . . . . . . . . . . . . . . . . . 10.1.2 Enable and Disable Tracepoints. . . . . . . . . . . . . . . . 10.1.3 Tracepoint Passcounts . . . . . . . . . . . . . . . . . . . . . . . . 10.1.4 Tracepoint Action Lists . . . . . . . . . . . . . . . . . . . . . . . 10.1.5 Listing Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.6 Starting and Stopping Trace Experiment . . . . . . . 10.2 Using the collected data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2.1 tfind n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2.2 tdump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2.3 save-tracepoints filename . . . . . . . . . . . . . . . . . . . 10.3 Convenience Variables for Tracepoints . . . . . . . . . . . . . . . . . . 11 Debugging Programs That Use Overlays . . 97 11.1 11.2 11.3 11.4 12 87 87 88 88 89 90 91 91 91 93 94 94 How Overlays Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Overlay Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Automatic Overlay Debugging . . . . . . . . . . . . . . . . . . . . . . . . 100 Overlay Sample Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Using GDB with Different Languages . . . . 103 12.1 12.2 12.3 12.4 Switching between source languages . . . . . . . . . . . . . . . . . . . 12.1.1 List of filename extensions and languages . . . . . . 12.1.2 Setting the working language . . . . . . . . . . . . . . . . . 12.1.3 Having GDB infer the source language . . . . . . . . Displaying the language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Type and range checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.3.1 An overview of type checking . . . . . . . . . . . . . . . . . 12.3.2 An overview of range checking . . . . . . . . . . . . . . . . Supported languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1 C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1.1 C and C++ operators . . . . . . . . . . . . . . . . 12.4.1.2 C and C++ constants . . . . . . . . . . . . . . . . 12.4.1.3 C++ expressions . . . . . . . . . . . . . . . . . . . . . 12.4.1.4 C and C++ defaults . . . . . . . . . . . . . . . . . 12.4.1.5 C and C++ type and range checks . . . . 12.4.1.6 GDB and C . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1.7 GDB features for C++ . . . . . . . . . . . . . . . 12.4.2 Modula-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.2.1 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.2.2 Built-in functions and procedures . . . . 12.4.2.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.2.4 Modula-2 defaults . . . . . . . . . . . . . . . . . . . 12.4.2.5 Deviations from standard Modula-2 . . 12.4.2.6 Modula-2 type and range checks . . . . . 12.4.2.7 The scope operators :: and . . . . . . . . . 12.4.2.8 GDB and Modula-2 . . . . . . . . . . . . . . . . . 103 103 104 104 104 105 105 106 107 107 108 109 110 111 111 111 112 113 113 114 115 116 116 116 117 117 iv Debugging with GDB 13 Examining the Symbol Table . . . . . . . . . . . . 119 14 Altering Execution . . . . . . . . . . . . . . . . . . . . . 123 14.1 14.2 14.3 14.4 14.5 14.6 15 Active targets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Commands for managing targets . . . . . . . . . . . . . . . . . . . . . . Choosing target byte order. . . . . . . . . . . . . . . . . . . . . . . . . . . . Remote debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Kernel Object Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 135 137 137 138 Debugging remote programs . . . . . . . . . . . . 139 17.1 17.2 17.3 18 Commands to specify files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Errors reading symbol files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Specifying a Debugging Target . . . . . . . . . . 135 16.1 16.2 16.3 16.4 16.5 17 123 124 125 125 126 126 GDB Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 15.1 15.2 16 Assignment to variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Continuing at a different address . . . . . . . . . . . . . . . . . . . . . . Giving your program a signal . . . . . . . . . . . . . . . . . . . . . . . . . Returning from a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . Calling program functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . Patching programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the gdbserver program. . . . . . . . . . . . . . . . . . . . . . . . . Using the gdbserve.nlm program . . . . . . . . . . . . . . . . . . . . . Implementing a remote stub . . . . . . . . . . . . . . . . . . . . . . . . . . 17.3.1 What the stub can do for you . . . . . . . . . . . . . . . . 17.3.2 What you must do for the stub . . . . . . . . . . . . . . . 17.3.3 Putting it all together . . . . . . . . . . . . . . . . . . . . . . . 139 140 141 142 142 144 Configuration-Specific Information . . . . . . . 147 18.1 Native . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.1 HP-UX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.2 SVR4 process information . . . . . . . . . . . . . . . . . . . . 18.1.3 Features for Debugging djgpp Programs . . . . . . 18.1.4 Features for Debugging MS Windows PE executables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.2 Embedded Operating Systems. . . . . . . . . . . . . . . . . . . . . . . . . 18.2.1 Using GDB with VxWorks . . . . . . . . . . . . . . . . . . . 18.2.1.1 Connecting to VxWorks . . . . . . . . . . . . . 18.2.1.2 VxWorks download . . . . . . . . . . . . . . . . . 18.2.1.3 Running tasks . . . . . . . . . . . . . . . . . . . . . . 18.3 Embedded Processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.1 ARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.2 Hitachi H8/300 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.2.1 Connecting to Hitachi boards . . . . . . . . 18.3.2.2 Using the E7000 in-circuit emulator . . 147 147 147 147 149 150 150 151 151 152 152 152 152 153 154 v 18.4 19 Controlling GDB . . . . . . . . . . . . . . . . . . . . . . . 165 19.1 19.2 19.3 19.4 19.5 19.6 19.7 20 18.3.2.3 Special GDB commands for Hitachi micros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 18.3.3 H8/500 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 18.3.4 Intel i960 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 18.3.4.1 Startup with Nindy . . . . . . . . . . . . . . . . . 156 18.3.4.2 Options for Nindy . . . . . . . . . . . . . . . . . . 156 18.3.4.3 Nindy reset command . . . . . . . . . . . . . . . 156 18.3.5 Mitsubishi M32R/D . . . . . . . . . . . . . . . . . . . . . . . . . 156 18.3.6 M68k . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 18.3.7 MIPS Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 18.3.8 PowerPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 18.3.9 HP PA Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 18.3.10 Hitachi SH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 18.3.11 Tsqware Sparclet . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 18.3.11.1 Setting file to debug. . . . . . . . . . . . . . . . 160 18.3.11.2 Connecting to Sparclet . . . . . . . . . . . . . 160 18.3.11.3 Sparclet download . . . . . . . . . . . . . . . . . 161 18.3.11.4 Running and debugging . . . . . . . . . . . . 161 18.3.12 Fujitsu Sparclite . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 18.3.13 Tandem ST2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 18.3.14 Zilog Z8000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 18.4.1 A29K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 18.4.2 Alpha . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 18.4.3 MIPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Screen size. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Optional warnings and messages . . . . . . . . . . . . . . . . . . . . . . Optional messages about internal happenings. . . . . . . . . . . Canned Sequences of Commands . . . . . . . . 171 20.1 User-defined commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20.2 User-defined command hooks . . . . . . . . . . . . . . . . . . . . . . . . . 20.3 Command files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20.4 Commands for controlled output . . . . . . . . . . . . . . . . . . . . . . 21 165 165 165 167 167 168 169 171 172 173 174 GDB Text User Interface . . . . . . . . . . . . . . . 177 21.1 21.2 21.3 21.4 21.5 TUI TUI TUI TUI TUI overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Single Key Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . specific commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . configuration variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 178 179 179 180 vi Debugging with GDB 22 Using GDB under gnu Emacs . . . . . . . . . . . 183 23 GDB Annotations . . . . . . . . . . . . . . . . . . . . . . 185 23.1 23.2 23.3 23.4 23.5 23.6 23.7 23.8 23.9 23.10 23.11 23.12 24 What is an Annotation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Server Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Annotation for GDB Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Information on Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . Invalidation Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displaying Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Annotations We Might Want in the Future . . . . . . . . . . . . The gdb/mi Interface . . . . . . . . . . . . . . . . . . . 193 Function and Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Notation and Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.1 gdb/mi Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.1.1 gdb/mi Input Syntax . . . . . . . . . . . . . . . . . . . . . . . . 24.1.2 gdb/mi Output Syntax . . . . . . . . . . . . . . . . . . . . . . 24.1.3 Simple Examples of gdb/mi Interaction . . . . . . . 24.2 gdb/mi Compatibility with CLI . . . . . . . . . . . . . . . . . . . . . . . 24.3 gdb/mi Output Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.3.1 gdb/mi Result Records . . . . . . . . . . . . . . . . . . . . . . 24.3.2 gdb/mi Stream Records . . . . . . . . . . . . . . . . . . . . . 24.3.3 gdb/mi Out-of-band Records . . . . . . . . . . . . . . . . . 24.4 gdb/mi Command Description Format . . . . . . . . . . . . . . . . 24.5 gdb/mi Breakpoint table commands. . . . . . . . . . . . . . . . . . . 24.6 gdb/mi Data Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.7 gdb/mi Program control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.8 Miscellaneous GDB commands in gdb/mi. . . . . . . . . . . . . . 24.9 gdb/mi Stack Manipulation Commands . . . . . . . . . . . . . . . 24.10 gdb/mi Symbol Query Commands . . . . . . . . . . . . . . . . . . . 24.11 gdb/mi Target Manipulation Commands . . . . . . . . . . . . . 24.12 gdb/mi Thread Commands . . . . . . . . . . . . . . . . . . . . . . . . . . 24.13 gdb/mi Tracepoint Commands. . . . . . . . . . . . . . . . . . . . . . . 24.14 gdb/mi Variable Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 185 185 186 187 189 189 190 190 191 191 192 192 193 193 193 193 194 196 197 197 197 197 198 198 199 207 217 227 229 234 237 242 244 244 Reporting Bugs in GDB . . . . . . . . . . . . . . . . 249 25.1 25.2 Have you found a bug? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 How to report bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 vii 26 Command Line Editing . . . . . . . . . . . . . . . . . 253 26.1 26.2 26.3 26.4 26.5 27 Introduction to Line Editing . . . . . . . . . . . . . . . . . . . . . . . . . . Readline Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26.2.1 Readline Bare Essentials . . . . . . . . . . . . . . . . . . . . . 26.2.2 Readline Movement Commands . . . . . . . . . . . . . . . 26.2.3 Readline Killing Commands . . . . . . . . . . . . . . . . . . 26.2.4 Readline Arguments . . . . . . . . . . . . . . . . . . . . . . . . . 26.2.5 Searching for Commands in the History . . . . . . . Readline Init File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26.3.1 Readline Init File Syntax . . . . . . . . . . . . . . . . . . . . . 26.3.2 Conditional Init Constructs . . . . . . . . . . . . . . . . . . 26.3.3 Sample Init File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bindable Readline Commands . . . . . . . . . . . . . . . . . . . . . . . . . 26.4.1 Commands For Moving . . . . . . . . . . . . . . . . . . . . . . 26.4.2 Commands For Manipulating The History . . . . . 26.4.3 Commands For Changing Text . . . . . . . . . . . . . . . 26.4.4 Killing And Yanking . . . . . . . . . . . . . . . . . . . . . . . . . 26.4.5 Specifying Numeric Arguments . . . . . . . . . . . . . . . 26.4.6 Letting Readline Type For You . . . . . . . . . . . . . . . 26.4.7 Keyboard Macros. . . . . . . . . . . . . . . . . . . . . . . . . . . . 26.4.8 Some Miscellaneous Commands . . . . . . . . . . . . . . . Readline vi Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 253 253 254 254 255 255 256 256 260 261 264 264 264 265 266 267 268 268 269 270 Using History Interactively. . . . . . . . . . . . . . 271 27.1 History 27.1.1 27.1.2 27.1.3 Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Designators . . . . . . . . . . . . . . . . . . . . . . . . . . . Word Designators . . . . . . . . . . . . . . . . . . . . . . . . . . . Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 271 272 272 Appendix A Formatting Documentation . . . . 275 Appendix B Installing GDB . . . . . . . . . . . . . . . . 277 B.1 B.2 B.3 Compiling GDB in another directory . . . . . . . . . . . . . . . . . . . 278 Specifying names for hosts and targets . . . . . . . . . . . . . . . . . 279 configure options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 Appendix C Maintenance Commands . . . . . . . 281 Appendix D GDB Remote Serial Protocol . . 283 D.1 D.2 D.3 D.4 D.5 D.6 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stop Reply Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . General Query Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Register Packet Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 284 289 290 292 293 viii Debugging with GDB Appendix E GNU GENERAL PUBLIC LICENSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION . . . . . . . . . . . . . . . 296 How to Apply These Terms to Your New Programs . . . . . . . . . . . 300 Appendix F GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 ADDENDUM: How to use this License for your documents . . . . 308 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

23,217

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧