linux编程出错: Value too large for defined data type

1. 背景

         有次在linux环境下,用交叉编译器编译一个简单的helloworld(C语音写的不超过10行代码),结果提示如下所示的错误信息:

cc1: error: /home/yx/test.c: Value too large for defined data type

         而奇怪的是同一个test.c文件,放在不同位置下,有的能编译通过,有的不行,对比结果如下:

#ls -lsi /root/test.c /home/test.c /home/yx/test.c

  16022526 4 -rw-r--r--. 1 root  root  149 7月  27 14:06 /home/test.c       # 编译通过

4312840465 4 -rw-r--r--. 1 root  root  149 7月  27 14:07 /home/yx/test.c    # 编译失败

 202907598 4 -rw-r--r--. 1 root  root  149 7月  27 14:02 /root/test.c        # 编译通过

         这个问题折腾我许久,最终发现跟挂载属性inode64有关系,如下是我环境的挂载属性。

#mount | grep -E '(home|root)'

/dev/mapper/centos-root on /     type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

/dev/mapper/centos-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

        

2. 理论依据

         查看文件系统xfs格式的帮助手册,里面有详细介绍inode32|inode64的注意要点。

man xfs

 

inode32|inode64

       When inode32 is specified, it indicates that XFS limits inode creation to locations which will not result in inode numbers with more than 32 bits of  signifi‐

       cance.

 

       When  inode64  is  specified,  it indicates that XFS is allowed to create inodes at any location in the filesystem, including those which will result in inode

       numbers occupying more than 32 bits of significance.

 

       inode32 is provided for backwards compatibility with older systems and applications, since 64 bits inode numbers might cause problems  for  some  applications

       that cannot handle large inode numbers.  If applications are in use which do not handle inode numbers bigger than 32 bits, the inode32 option should be speci‐

       fied.

 

       For kernel v3.7 and later, inode64 is the default.

 

3. 结合实际

         inode32最多能表达数字是4294967295,如果文件属性中的inode超过这个上限,就说明是inode64的。

         比较老的交叉编译器,只支持32位inode的文件访问,当遇到超过4294967295的文件,就会编译出错并提示:Value too large for defined data type

4.   解决方案

         如https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44116所说,在新版本的gcc中已经解决了该bug。那么解决方案就有两种:

Ø  升级交叉编译器版本,让其支持inode64的源文件。

Ø  交叉编译器版本不变,将文件系统挂载属性从inode64改为inode32。

 

5. inode32与inode64的区别

         在http://xfs.org/index.php/XFS_FAQ#Q:_What_is_the_inode64_mount_option_for.3F里面有这么一段话能诠释的5. inode32与inode64的区别:

 

By default, with 32bit inodes, XFS placesinodes only in the first 1TB of a disk. If you have a disk with 100TB, allinodes will be stuck in the first TB. This can lead to strange things like"disk full" when you still have plenty space free, but there's nomore place in the first TB to create a new inode. Also, performance sucks.

To come around this, use the inode64 mountoptions for filesystems >1TB. Inodes will then be placed in the locationwhere their data is, minimizing disk seeks.

Beware that some old programs might haveproblems reading 64bit inodes, especially over NFS. Your editor used inode64for over a year with recent (openSUSE 11.1 and higher) distributions using NFSand Samba without any corruptions, so that might be a recent enough distro.

 

         大意就是xfs文件系统会把inode存储在磁盘最开始的这1T空间里,如果这部分空间被完全填满了,那么就会出现磁盘空间不足的错误提示了。解决办法就是在挂载时,指定 inode64 选项。

6. 其他

http://blog.fmeh.org/2013/05/11/does-the-world-need-32-bit-inodes/

 

上面看到的只使用 32 位 inode 的程序占比结果 10% 还是比较令人满意的,只支持 32 位 inode 的程序现在越来越少了。

  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
笔记本的风扇控制 ---------------------------------------- 09 November 2006. Summary of changes for version 20061109: 1) ACPI CA Core Subsystem: Optimized the Load ASL operator in the case where the source operand is an operation region. Simply map the operation region memory, instead of performing a bytewise read. (Region must be of type SystemMemory, see below.) Fixed the Load ASL operator for the case where the source operand is a region field. A buffer object is also allowed as the source operand. BZ 480 Fixed a problem where the Load ASL operator allowed the source operand to be an operation region of any type. It is now restricted to regions of type SystemMemory, as per the ACPI specification. BZ 481 Additional cleanup and optimizations for the new Table Manager code. AcpiEnable will now fail if all of the required ACPI tables are not loaded (FADT, FACS, DSDT). BZ 477 Added #pragma pack(8/4) to acobject.h to ensure that the structures in this header are always compiled as aligned. The ACPI_OPERAND_OBJECT has been manually optimized to be aligned and will not work if it is byte-packed. Example Code and Data Size: These are the sizes for the OS- independent acpica.lib produced by the Microsoft Visual C++ 6.0 32- bit compiler. The debug version of the code includes the debug output trace mechanism and has a much larger code and data size. Previous Release: Non-Debug Version: 78.1K Code, 17.1K Data, 95.2K Total Debug Version: 155.4K Code, 63.1K Data, 218.5K Total Current Release: Non-Debug Version: 77.9K Code, 17.0K Data, 94.9K Total Debug Version: 155.2K Code, 63.1K Data, 218.3K Total 2) iASL Compiler/Disassembler and Tools: Fixed a problem where the presence of the _OSI predefined control method within complex expressions could cause an internal compiler error. AcpiExec: Implemented full region support for multiple address spaces. SpaceId is now part of the REGION object. BZ 429 ---------------------------------------- 11 Oc
Ambiguous operators need parentheses -----------不明确的运算需要用括号括起 Ambiguous symbol ''xxx'' ----------------不明确的符号 Argument list syntax error ----------------参数表语法错误 Array bounds missing ------------------丢失数组界限符 Array size toolarge -----------------数组尺寸太大 Bad character in paramenters ------------------参数中有不适当的字符 Bad file name format in include directive --------------------包含命令中文件名格式不正确 Bad ifdef directive synatax ------------------------------编译预处理ifdef有语法错 Bad undef directive syntax ---------------------------编译预处理undef有语法错 Bit field too large ----------------位字段太长 Call of non-function -----------------调用未定义的函数 Call to function with no prototype ---------------调用函数时没有函数的说明 Cannot modify a const object ---------------不允许修改常量对象 Case outside of switch ----------------漏掉了case 语句 Case syntax error ------------------ Case 语法错误 Code has no effect -----------------代码不可述不可能执行到 Compound statement missing{ --------------------分程序漏掉"{" Conflicting type modifiers ------------------不明确的类型说明符 Constant expression required ----------------要求常量表达式 Constant out of range in comparison -----------------在比较中常量超出范围 Conversion may lose significant digits -----------------转换时会丢失意义的数字 Conversion of near pointer not allowed -----------------不允许转换近指针 Could not find file ''xxx'' -----------------------找不到XXX文件 Declaration missing ; ----------------说明缺少";" houjiuming Declaration syntax error -----------------说明中出现语法错误 Default outside of switch ------------------ Default 出现在switch语句之外 Define directive needs an identifier ------------------定义编译预处理需要标识符 Division by zero ------------------用零作除数 Do statement must have while ------------------ Do-while语句中缺少while部分 Enum syntax error ---------------------枚举类型语法错误 Enumeration constant syntax error -----------------枚举常数语法错误 Error directive :xxx ------------------------错误的编译预处理命令 Error writing output file ---------------------写输出文件错误 Expression syntax error -----------------------表达式语法错误 Extra parameter in call ------------------------调用时出现多余错误 File name too long ----------------文件名太长 Function call missing -----------------函数调用缺少右括号 Fuction definition out of place ------------------函数定义位置错误 Fuction should return a value ------------------函数必需返回一个值 Goto statement missing label ------------------ Goto语句没有标号 Hexadecimal or octal constant too large ------------------16进制或8进制常数太大 Illegal character ''x'' ------------------非法字符x Illegal initialization ------------------非法的初始化 Illegal octal digit ------------------非法的8进制数字 houjiuming Illegal pointer subtraction ------------------非法的指针相减 Illegal structure operation ------------------非法的结构体操作 Illegal use of floating point -----------------非法的浮点运算 Illegal use of pointer --------------------指针使用非法 Improper use of a typedefsymbol ----------------类型定义符号使用不恰当 In-line assembly not allowed -----------------不允许使用行间汇编 Incompatible storage class -----------------存储类别不相容 Incompatible type conversion --------------------不相容的类型转换 Incorrect number format -----------------------错误的数据格式 Incorrect use of default --------------------- Default使用不当 Invalid indirection ---------------------无效的间接运算 Invalid pointer addition ------------------指针相加无效 Irreducible expression tree -----------------------无法执行的表达式运算 Lvalue required ---------------------------需要逻辑值0或非0值 Macro argument syntax error -------------------宏参数语法错误 Macro expansion too long ----------------------宏的扩展以后太长 Mismatched number of parameters in definition ---------------------定义中参数个数不匹配 Misplaced break ---------------------此处不应出现break语句 Misplaced continue ------------------------此处不应出现continue语句 Misplaced decimal point --------------------此处不应出现小数点 Misplaced elif directive --------------------不应编译预处理elif Misplaced else ----------------------此处不应出现else houjiuming Misplaced else directive ------------------此处不应出现编译预处理else Misplaced endif directive -------------------此处不应出现编译预处理endif Must be addressable ----------------------必须是可以编址的 Must take address of memory location ------------------必须存储定位的地址 No declaration for function ''xxx'' -------------------没有函数xxx的说明 No stack ---------------缺少堆栈 No type information ------------------没有类型信息 Non-portable pointer assignment --------------------不可移动的指针(地址常数)赋值 Non-portable pointer comparison --------------------不可移动的指针(地址常数)比较 Non-portable pointer conversion ----------------------不可移动的指针(地址常数)转换 Not a valid expression format type ---------------------不合法的表达式格式 Not an allowed type ---------------------不允许使用的类型 Numeric constant too large -------------------数值常太大 Out of memory -------------------内存不够用 houjiuming Parameter ''xxx'' is never used ------------------能数xxx没有用到 Pointer required on left side of -> -----------------------符号->的左边必须是指针 Possible use of ''xxx'' before definition -------------------在定义之前就使用了xxx(警告) Possibly incorrect assignment ----------------赋值可能不正确 Redeclaration of ''xxx'' -------------------重复定义了xxx Redefinition of ''xxx'' is not identical ------------------- xxx的两次定义不一致 Register allocation failure ------------------寄存器定址失败 Repeat count needs an lvalue ------------------重复计数需要逻辑值 Size of structure or array not known ------------------结构体或数给大小不确定 Statement missing ; ------------------语句后缺少";" Structure or union syntax error --------------结构体或联合体语法错误 Structure size too large ----------------结构体尺寸太大 Sub scripting missing ] ----------------下标缺少右方括号 Superfluous & with function or array ------------------函数或数组中有多余的"&" Suspicious pointer conversion ---------------------可疑的指针转换 Symbol limit exceeded ---------------符号超限 Too few parameters in call -----------------函数调用时的实参少于函数的参数不 Too many default cases ------------------- Default太多(switch语句中一个) Too many error or warning messages --------------------错误或警告信息太多 Too many type in declaration -----------------说明中类型太多 houjiuming Too much auto memory in function -----------------函数用到的局部存储太多 Too much global data defined in file ------------------文件中全局数据太多 Two consecutive dots -----------------两个连续的句点 Type mismatch in parameter xxx ----------------参数xxx类型不匹配 Type mismatch in redeclaration of ''xxx'' ---------------- xxx重定义的类型不匹配 Unable to create output file ''xxx'' ----------------无法建立输出文件xxx Unable to open include file ''xxx'' ---------------无法打开被包含的文件xxx Unable to open input file ''xxx'' ----------------无法打开输入文件xxx Undefined label ''xxx'' -------------------没有定义的标号xxx Undefined structure ''xxx'' -----------------没有定义的结构xxx Undefined symbol ''xxx'' -----------------没有定义的符号xxx Unexpected end of file in comment started on line xxx ----------从xxx行开始的注解尚未结束文件不能结束 Unexpected end of file in conditional started on line xxx ----从xxx 开始的条件语句尚未结束文件不能结束 Unknown assemble instruction ----------------未知的汇编结构 houjiuming Unknown option ---------------未知的操作 Unknown preprocessor directive: ''xxx'' -----------------不认识的预处理命令xxx Unreachable code ------------------无路可达的代码 Unterminated string or character constant -----------------字符串缺少引号 User break ----------------用户强行中断了程序 Void functions may not return a value ----------------- Void类型的函数不应有返回值 Wrong number of arguments -----------------调用函数的参数数目错 ''xxx'' not an argument ----------------- xxx不是参数 ''xxx'' not part of structure -------------------- xxx不是结构体的一部分 xxx statement missing ( -------------------- xxx语句缺少左括号 xxx statement missing ) ------------------ xxx语句缺少右括号 xxx statement missing ; -------------------- xxx缺少分号 houjiuming xxx'' declared but never used -------------------说明了xxx但没有使用 xxx'' is assigned a value which is never used ----------------------给xxx赋了值但未用过 Zero length structure ------------------结构体的长度为零
Version 1.7 ----------- - ADD: Delphi/CBuilder 10.2 Tokyo now supported. - ADD: Delphi/CBuilder 10.1 Berlin now supported. - ADD: Delphi/CBuilder 10 Seattle now supported. - ADD: Delphi/CBuilder XE8 now supported. - ADD: Delphi/CBuilder XE7 now supported. - ADD: Delphi/CBuilder XE6 now supported. - ADD: Delphi/CBuilder XE5 now supported. - ADD: Delphi/CBuilder XE4 now supported. - ADD: Delphi/CBuilder XE3 now supported. - ADD: Delphi/CBuilder XE2 now supported. - ADD: Delphi/CBuilder XE now supported. - ADD: Delphi/CBuilder 2010 now supported. - ADD: Delphi/CBuilder 2009 now supported. - ADD: New demo project FlexCADImport. - FIX: The height of the TFlexRegularPolygon object incorrectly changes with its rotation. - FIX: Added division by zero protect in method TFlexControl.MovePathSegment. - FIX: The background beyond docuemnt wasn't filled when TFlexPanel.DocClipping=True. - FIX: In "Windows ClearType" font rendering mode (OS Windows mode) the "garbage" pixels can appear from the right and from the bottom sides of the painted rectangle of the TFlexText object. - FIX: The result rectangle incorrectly calculated in the TFlexText.GetRefreshRect method. - FIX: Added FPaintCache.rcPaint cleanup in the TFlexPanel.WMPaint method. Now it is possible to define is the drawing take place via WMPaint or via the PaintTo direct call (if rcPaint contain non-empty rectangle then WMPaint in progress). - FIX: The TFlexPanel.FPaintCache field moved in the protected class section. Added rcPaint field in FPaintCache that represents drawing rectangle. - ADD: In the text prcise mode (TFlexText.Precise=True) takes into account the rotation angle (TFlexText.Angle). - FIX: Removed FG_NEWTEXTROTATE directive (the TFlexText Precise mode should be used instead). - FIX: The TFlexRegularPolygon object clones incorrectly drawed in case when TFlexRegularPolygon have alternative brush (gradient, texture). - ADD: Add TFlexPanel.InvalidateControl virtual method which calls from TFle
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.1.3 What gdb Does During Startup . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Quitting gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 Shell Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4 Logging Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 11 12 13 15 16 16 16 gdb Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.1 Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.2 Command Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.3 Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 4 Running Programs Under gdb . . . . . . . . . . . . . 25 4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Starting your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3 Your Program’s Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4 Your Program’s Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.5 Your Program’s Working Directory . . . . . . . . . . . . . . . . . . . . . . . . . . 4.6 Your Program’s Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.7 Debugging an Already-running Process . . . . . . . . . . . . . . . . . . . . . . 4.8 Killing the Child Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.9 Debugging Programs with Multiple Threads . . . . . . . . . . . . . . . . . . 4.10 Debugging Programs with Multiple Processes. . . . . . . . . . . . . . . . 4.11 Setting a Bookmark to Return to Later . . . . . . . . . . . . . . . . . . . . . 4.11.1 A Non-obvious Benefit of Using Checkpoints . . . . . . . . . . . . 5 25 26 28 28 29 29 30 31 31 34 36 37 Stopping and Continuing . . . . . . . . . . . . . . . . . . 39 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 40 45 47 49 ii Debugging with gdb 5.1.5 Disabling Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.6 Break Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.7 Breakpoint Command Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.8 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.9 “Breakpoint address adjusted...” . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Continuing and Stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4 Stopping and Starting Multi-thread Programs . . . . . . . . . . . . . . . . 6 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . 61 6.1 6.2 6.3 6.4 7 Stack Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Selecting a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Information About a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 62 64 65 Examining Source Files . . . . . . . . . . . . . . . . . . . 67 7.1 Printing Source Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 Specifying a Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.3 Editing Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.3.1 Choosing your Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.4 Searching Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5 Specifying Source Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.6 Source and Machine Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 49 50 52 53 53 54 57 59 67 68 69 69 70 70 72 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . 75 8.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2 Ambiguous Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.3 Program Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.4 Artificial Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.5 Output Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.6 Examining Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.7 Automatic Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.8 Print Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.9 Value History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.10 Convenience Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.11 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.12 Floating Point Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.13 Vector Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.14 Operating System Auxiliary Information . . . . . . . . . . . . . . . . . . . . 8.15 Memory Region Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.15.1 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.15.1.1 Memory Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.15.1.2 Memory Access Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.15.1.3 Data Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.15.2 Memory Access Checking. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.16 Copy Between Memory and a File . . . . . . . . . . . . . . . . . . . . . . . . . . 8.17 How to Produce a Core File from Your Program . . . . . . . . . . . . . 75 76 77 79 79 81 82 84 90 90 92 93 94 94 94 95 95 96 96 96 96 97 iii 8.18 Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 8.19 Caching Data of Remote Targets . . . . . . . . . . . . . . . . . . . . . . . . . . 100 8.20 Search Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 9 C Preprocessor Macros . . . . . . . . . . . . . . . . . . 103 10 Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 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 Experiments . . . . . . . . . . . . . 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 11.1 11.2 11.3 11.4 12 107 107 108 108 109 110 110 111 111 113 114 114 How Overlays Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Overlay Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Automatic Overlay Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . Overlay Sample Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 116 118 119 Using gdb with Different Languages . . . . . 121 12.1 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 . . . . . . . . . . . . . . . . 12.2 Displaying the Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.3 Type and Range Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.3.1 An Overview of Type Checking . . . . . . . . . . . . . . . . . . . . . . . 12.3.2 An Overview of Range Checking . . . . . . . . . . . . . . . . . . . . . . 12.4 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.1.8 Decimal Floating Point format . . . . . . . . . . . . . . . . . . . 12.4.2 Objective-C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 121 122 122 122 123 123 124 125 125 126 127 128 129 129 129 130 131 131 iv Debugging with gdb 12.4.2.1 Method Names in Commands . . . . . . . . . . . . . . . . . . . . 12.4.2.2 The Print Command With Objective-C . . . . . . . . . . . 12.4.3 Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.3.1 Fortran Operators and Expressions . . . . . . . . . . . . . . . 12.4.3.2 Fortran Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.3.3 Special Fortran Commands . . . . . . . . . . . . . . . . . . . . . . 12.4.4 Pascal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.5 Modula-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.5.1 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.5.2 Built-in Functions and Procedures . . . . . . . . . . . . . . . . 12.4.5.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.5.4 Modula-2 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.5.5 Modula-2 Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.5.6 Deviations from Standard Modula-2 . . . . . . . . . . . . . . 12.4.5.7 Modula-2 Type and Range Checks . . . . . . . . . . . . . . . 12.4.5.8 The Scope Operators :: and . . . . . . . . . . . . . . . . . . . . 12.4.5.9 gdb and Modula-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.6 Ada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.6.2 Omissions from Ada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.6.3 Additions to Ada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.6.4 Stopping at the Very Beginning . . . . . . . . . . . . . . . . . . 12.4.6.5 Known Peculiarities of Ada Mode . . . . . . . . . . . . . . . . 12.5 Unsupported Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 132 132 132 133 133 133 133 133 135 136 136 138 138 138 139 139 139 139 140 141 143 143 143 13 Examining the Symbol Table . . . . . . . . . . . . 145 14 Altering Execution . . . . . . . . . . . . . . . . . . . . . 151 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 152 153 153 154 154 gdb Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 15.1 Commands to Specify Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 15.2 Debugging Information in Separate Files . . . . . . . . . . . . . . . . . . . 163 15.3 Errors Reading Symbol Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 16 Specifying a Debugging Target . . . . . . . . . . 169 16.1 Active Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 16.2 Commands for Managing Targets . . . . . . . . . . . . . . . . . . . . . . . . . . 170 16.3 Choosing Target Byte Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 v 17 Debugging Remote Programs . . . . . . . . . . . 173 17.1 Connecting to a Remote Target . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.2 Sending files to a remote system . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.3 Using the gdbserver Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.3.1 Running gdbserver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.3.1.1 Attaching to a Running Program . . . . . . . . . . . . . . . . . 17.3.1.2 Multi-Process Mode for gdbserver . . . . . . . . . . . . . . . 17.3.1.3 Other Command-Line Arguments for gdbserver . . 17.3.2 Connecting to gdbserver . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.3.3 Monitor Commands for gdbserver . . . . . . . . . . . . . . . . . . . . 17.4 Remote Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.5 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. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 173 175 175 175 176 176 177 177 177 178 181 182 183 184 Configuration-Specific Information . . . . . . . 185 18.1 Native. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.1 HP-UX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.2 BSD libkvm Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.3 SVR4 Process Information . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.4 Features for Debugging djgpp Programs . . . . . . . . . . . . . . 18.1.5 Features for Debugging MS Windows PE Executables . . 18.1.5.1 Support for DLLs without Debugging Symbols . . . . 18.1.5.2 DLL Name Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.5.3 Working with Minimal Symbols . . . . . . . . . . . . . . . . . . 18.1.6 Commands Specific to gnu Hurd Systems . . . . . . . . . . . . . 18.1.7 QNX Neutrino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 Renesas M32R/D and M32R/SDI . . . . . . . . . . . . . . . . . . . . . 18.3.3 M68k . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.4 MIPS Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.5 OpenRISC 1000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.6 PowerPC Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.7 HP PA Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.8 Tsqware Sparclet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.8.1 Setting File to Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.8.2 Connecting to Sparclet . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.8.3 Sparclet Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.8.4 Running and Debugging . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.9 Fujitsu Sparclite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.10 Zilog Z8000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 185 185 185 187 189 190 190 191 192 194 194 194 195 195 196 196 196 198 199 199 201 203 204 204 204 205 205 205 205 205 vi Debugging with gdb 18.3.11 Atmel AVR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.12 CRIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.13 Renesas Super-H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4 Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.1 x86 Architecture-specific Issues . . . . . . . . . . . . . . . . . . . . . . . 18.4.2 A29K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.3 Alpha . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.4 MIPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.5 HPPA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.6 Cell Broadband Engine SPU architecture . . . . . . . . . . . . . . 18.4.7 PowerPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Controlling gdb . . . . . . . . . . . . . . . . . . . . . . . . 211 19.1 19.2 19.3 19.4 19.5 19.6 19.7 19.8 20 206 206 207 207 207 207 207 208 209 209 210 Prompt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command Editing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command History. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Screen Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Configuring the Current ABI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Optional Warnings and Messages . . . . . . . . . . . . . . . . . . . . . . . . . . Optional Messages about Internal Happenings . . . . . . . . . . . . . . 211 211 211 213 214 214 215 217 Canned Sequences of Commands . . . . . . . . 221 20.1 20.2 20.3 20.4 User-defined Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . User-defined Command Hooks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Commands for Controlled Output . . . . . . . . . . . . . . . . . . . . . . . . . 221 222 223 224 21 Command Interpreters . . . . . . . . . . . . . . . . . . 227 22 gdb Text User Interface . . . . . . . . . . . . . . . . . 229 22.1 22.2 22.3 22.4 22.5 23 TUI Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TUI Key Bindings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TUI Single Key Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TUI-specific Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TUI Configuration Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 230 231 231 233 Using gdb under gnu Emacs . . . . . . . . . . . . 235 vii 24 The gdb/mi Interface . . . . . . . . . . . . . . . . . . . 237 Function and Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Notation and Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.3 gdb/mi Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.3.1 gdb/mi Input Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.3.2 gdb/mi Output Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.4 gdb/mi Compatibility with CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.5 gdb/mi Development and Front Ends . . . . . . . . . . . . . . . . . . . . . 24.6 gdb/mi Output Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.6.1 gdb/mi Result Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.6.2 gdb/mi Stream Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.6.3 gdb/mi Async Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.7 Simple Examples of gdb/mi Interaction. . . . . . . . . . . . . . . . . . . . 24.8 gdb/mi Command Description Format . . . . . . . . . . . . . . . . . . . . 24.9 gdb/mi Breakpoint Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.10 gdb/mi Program Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.11 gdb/mi Thread Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.12 gdb/mi Program Execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.13 gdb/mi Stack Manipulation Commands . . . . . . . . . . . . . . . . . . 24.14 gdb/mi Variable Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.15 gdb/mi Data Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.16 gdb/mi Tracepoint Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.17 gdb/mi Symbol Query Commands . . . . . . . . . . . . . . . . . . . . . . . 24.18 gdb/mi File Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.19 gdb/mi Target Manipulation Commands . . . . . . . . . . . . . . . . . 24.20 gdb/mi File Transfer Commands . . . . . . . . . . . . . . . . . . . . . . . . . 24.21 Miscellaneous gdb/mi Commands . . . . . . . . . . . . . . . . . . . . . . . . 25 gdb Annotations . . . . . . . . . . . . . . . . . . . . . . . 293 25.1 25.2 25.3 25.4 25.5 25.6 25.7 26 237 237 237 237 238 240 240 240 240 241 241 242 243 244 251 254 255 261 265 271 277 277 280 283 287 288 What is an Annotation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Server Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Annotation for gdb Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Invalidation Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displaying Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 294 294 294 295 295 296 Reporting Bugs in gdb . . . . . . . . . . . . . . . . . . 297 26.1 Have You Found a Bug? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 26.2 How to Report Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 viii Debugging with gdb 27 Command Line Editing . . . . . . . . . . . . . . . . . 301 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 301 301 301 302 302 303 303 304 304 309 310 313 313 313 315 316 317 317 317 318 319 Using History Interactively . . . . . . . . . . . . . . 321 28.1 History Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28.1.1 Event Designators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28.1.2 Word Designators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28.1.3 Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 321 321 322 Appendix A Formatting Documentation . . . . 325 Appendix B Installing gdb . . . . . . . . . . . . . . . . 327 B.1 B.2 B.3 B.4 B.5 Requirements for Building gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . Invoking the gdb ‘configure’ Script . . . . . . . . . . . . . . . . . . . . . . . Compiling gdb in Another Directory . . . . . . . . . . . . . . . . . . . . . . . Specifying Names for Hosts and Targets . . . . . . . . . . . . . . . . . . . . ‘configure’ Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Appendix C 327 327 329 330 330 Maintenance Commands . . . . . . 333 ix Appendix D gdb Remote Serial Protocol . . . 339 D.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.2 Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.3 Stop Reply Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.4 General Query Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.5 Register Packet Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.6 Tracepoint Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.7 Host I/O Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.8 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.9 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10 File-I/O Remote Protocol Extension . . . . . . . . . . . . . . . . . . . . . . D.10.1 File-I/O Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.2 Protocol Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.3 The F Request Packet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.4 The F Reply Packet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.5 The ‘Ctrl-C’ Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.6 Console I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.7 List of Supported Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . lseek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . rename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . unlink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . stat/fstat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . gettimeofday . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . isatty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.8 Protocol-specific Representation of Datatypes . . . . . . . . . Integral Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pointer Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Memory Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . struct stat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . struct timeval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.9 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Open Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . mode t Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Errno Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Lseek Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.10 File-I/O Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.11 Library List Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.12 Memory Map Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 340 347 348 358 358 360 362 362 363 363 363 364 364 365 365 365 366 367 367 367 368 368 369 369 370 370 370 371 371 371 372 372 372 373 373 373 373 374 374 374 375 376 x Debugging with gdb Appendix E The GDB Agent Expression Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Appendix F 377 379 383 384 384 386 Target Descriptions . . . . . . . . . . . 389 F.1 Retrieving Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.2 Target Description Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.2.1 Inclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.2.2 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.2.3 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.2.4 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.2.5 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.3 Predefined Target Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.4 Standard Target Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.4.1 ARM Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.4.2 MIPS Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.4.3 M68K Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.4.4 PowerPC Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389 390 390 390 391 391 391 392 393 393 393 394 394 Appendix G GNU GENERAL PUBLIC LICENSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION . . . . . . . . . . . . . . . . . . . 396 How to Apply These Terms to Your New Programs . . . . . . . . . . . . . . . 400 Appendix H GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401 H.1 ADDENDUM: How to use this License for your documents . . 407 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409 1 Summary of gdb The purpose of a debugger such as gdb is to allow you to see what is going on “inside” another program while it executes—or what another program was doing at the moment it crashed. gdb can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act: • Start your program, specifying anything that might affect its behavior. • Make your program stop on specified conditions. • Examine what has happened, when your program has stopped. • Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another. You can use gdb to debug programs written in C and C++. For more information, see Section 12.4 [Supported Languages], page 125. For more information, see Section 12.4.1 [C and C++], page 125. Support for Modula-2 is partial. [Modula-2], page 133. For information on Modula-2, see Section 12.4.5 Debugging Pascal programs which use sets, subranges, file variables, or nested functions does not currently work. gdb does not support entering expressions, printing values, or similar features using Pascal syntax. gdb can be used to debug programs written in Fortran, although it may be necessary to refer to some variables with a trailing underscore. gdb can be used to debug programs written in Objective-C, using either the Ap- ple/NeXT or the GNU Objective-C runtime. Free Software gdb is free software, protected by the gnu General Public License (GPL). The GPL gives you the freedom to copy or adapt a licensed program—but every person getting a copy also gets with it the freedom to modify that copy (which means that they must get access to the source code), and the freedom to distribute further copies. Typical software companies use copyrights to limit your freedoms; the Free Software Foundation uses the GPL to preserve these freedoms. Fundamentally, the General Public License is a license which says that you have these freedoms and that you cannot take these freedoms away from anyone else. Free Software Needs Free Documentation The biggest deficiency in the free software community today is not in the software—it is the lack of good free documentation that we can include with the free software. Many of our most important programs do not come with free reference manuals and free introductory texts. Documentation is an essential part of any software package; when an important free software package does not come with a free manual and a free tutorial, that is a major gap. We have many such gaps today. 2 Debugging with gdb Consider Perl, for instance. The tutorial manuals that people normally use are non-free. How did this come about? Because the authors of those manuals published them with restrictive terms—no copying, no modification, source files not available—which exclude them from the free software world. That wasn’t the first time this sort of thing happened, and it was far from the last. Many times we have heard a GNU user eagerly describe a manual that he is writing, his intended contribution to the community, only to learn that he had ruined everything by signing a publication contract to make it non-free. Free documentation, like free software, is a matter of freedom, not price. The problem with the non-free manual is not that publishers charge a price for printed copies—that in itself is fine. (The Free Software Foundation sells printed copies of manuals, too.) The problem is the restrictions on the use of the manual. Free manuals are available in source code form, and give you permission to copy and modify. Non-free manuals do not allow this. The criteria of freedom for a free manual are roughly the same as for free software. Redistribution (including the normal kinds of commercial redistribution) must be permitted, so that the manual can accompany every copy of the program, both on-line and on paper. Permission for modification of the technical content is crucial too. When people mod- ify the software, adding or changing features, if they are conscientious they will change the manual too—so they can provide accurate and clear documentation for the modified program. A manual that leaves you no choice but to write a new manual to document a changed version of the program is not really available to our community. Some kinds of limits on the way modification is handled are acceptable. For example, requirements to preserve the original author’s copyright notice, the distribution terms, or the list of authors, are ok. It is also no problem to require modified versions to include notice that they were modified. Even entire sections that may not be deleted or changed are acceptable, as long as they deal with nontechnical topics (like this one). These kinds of restrictions are acceptable because they don’t obstruct the community’s normal use of the manual. However, it must be possible to modify all the technical content of the manual, and then distribute the result in all the usual media, through all the usual channels. Otherwise, the restrictions obstruct the use of the manual, it is not free, and we need another manual to replace it. Please spread the word about this issue. Our community continues to lose manuals to proprietary publishing. If we spread the word that free software needs free reference manuals and free tutorials, perhaps the next person who wants to contribute by writing documentation will realize, before it is too late, that only free manuals contribute to the free software community. If you are writing documentation, please insist on publishing it under the GNU Free Documentation License or another free documentation license. Remember that this deci- sion requires your approval—you don’t have to let the publisher decide. Some commercial publishers will use a free license if you insist, but they will not propose the option; it is up to you to raise the issue and say firmly that this is what you want. If the publisher you are dealing with refuses, please try other publishers. If you’re not sure whether a proposed license is free, write to [email protected]. 3 You can encourage commercial publishers to sell more free, copylefted manuals and tutorials by buying them, and particularly by buying copies from the publishers that paid for their writing or for major improvements. Meanwhile, try to avoid buying non-free documentation at all. Check the distribution terms of a manual before you buy it, and insist that whoever seeks your business must respect your freedom. Check the history of the book, and try to reward the publishers that have paid or pay the authors to work on it. The Free Software Foundation maintains a list of free documentation published by other publishers, at http://www.fsf.org/doc/other-free-books.html. Contributors to gdb Richard Stallman was the original author of gdb, and of many other gnu programs. Many others have contributed to its development. This section attempts to credit major contrib- utors. One of the virtues of free software is that everyone is free to contribute to it; with regret, we cannot actually acknowledge everyone here. The file ‘ChangeLog’ in the gdb distribution approximates a blow-by-blow account. Changes much prior to version 2.0 are lost in the mists of time. Plea: Additions to this section are particularly welcome. If you or your friends (or enemies, to be evenhanded) have been unfairly omitted from this list, we would like to add your names! So that they may not regard their many labors as thankless, we particularly thank those who shepherded gdb through major releases: Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0); Jim Blandy (release 4.18); Jason Molenda (release 4.17); Stan Shebs (release 4.14); Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9); Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4); John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4, and 3.3); and Randy Smith (releases 3.2, 3.1, and 3.0). Richard Stallman, assisted at various times by Peter TerMaat, Chris Hanson, and Richard Mlynarik, handled releases through 2.8. Michael Tiemann is the author of most of the gnu C++ support in gdb, with significant additional contributions from Per Bothner and Daniel Berlin. James Clark wrote the gnu C++ demangler. Early work on C++ was by Peter TerMaat (who also did much general update work leading to release 3.0). gdb uses the BFD subroutine library to examine multiple object-file formats; BFD was a joint project of David V. Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore. David Johnson wrote the original COFF support; Pace Willison did the original support for encapsulated COFF. Brent Benson of Harris Computer Systems contributed DWARF 2 support. Adam de Boor and Bradley Davis contributed the ISI Optimum V support. Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS support. Jean-Daniel Fekete contributed Sun 386i support. Chris Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support. David Johnson con- tributed Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support. Jeff Law contributed HP PA and SOM support. Keith Packard contributed NS32K support. 4 Debugging with gdb Doug Rabson contributed Acorn Risc Machine support. Bob Rusk contributed Harris Nighthawk CX-UX support. Chris Smith contributed Convex support (and Fortran de- bugging). Jonathan Stone contributed Pyramid support. Michael Tiemann contributed SPARC support. Tim Tucker contributed support for the Gould NP1 and Gould Powern- ode. Pace Willison contributed Intel 386 support. Jay Vosburgh contributed Symmetry support. Marko Mlinar contributed OpenRISC 1000 support. Andreas Schwab contributed M68K gnu/Linux support. Rich Schaefer and Peter Schauer helped with support of SunOS shared libraries. Jay Fenlason and Roland McGrath ensured that gdb and GAS agree about several machine instruction sets. Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM contributed remote debugging modules for the i960, VxWorks, A29K UDI, and RDI targets, respectively. Brian Fox is the author of the readline libraries providing command-line editing and command history. Andrew Beers of SUNY Buffalo wrote the language-switching code, the Modula-2 sup- port, and contributed the Languages chapter of this manual. Fred Fish wrote most of the support for Unix System Vr4. He also enhanced the command-completion support to cover C++ overloaded symbols. Hitachi America (now Renesas America), Ltd. H8/500, and Super-H processors. sponsored the support for H8/300, NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors. Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D proces- sors. Toshiba sponsored the support for the TX39 Mips processor. Matsushita sponsored the support for the MN10200 and MN10300 processors. Fujitsu sponsored the support for SPARClite and FR30 processors. Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware watchpoints. Michael Snyder added support for tracepoints. Stu Grossman wrote gdbserver. Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made nearly innumerable bug fixes and cleanups throughout gdb. The following people at the Hewlett-Packard Company contributed support for the PA- RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0 (narrow mode), HP’s implementation of kernel threads, HP’s aC++ compiler, and the Text User Interface (nee Terminal User Interface): Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific information in this manual. DJ Delorie ported gdb to MS-DOS, for the DJGPP project. Robert Hoehne made significant contributions to the DJGPP port. Cygnus Solutions has sponsored gdb maintenance and much of its development since 1991. Cygnus engineers who have worked on gdb fulltime include Mark Alexander, Jim 5 Blandy, Per Bothner, Kevin Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler, Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton, JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner, Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David Zuhn have made contributions both large and small. Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for Cygnus Solu- tions, implemented the original gdb/mi interface. Jim Blandy added support for preprocessor macros, while working for Red Hat. Andrew Cagney designed gdb’s architecture vector. Many people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick Duffek, Richard Henderson, Mark Ket- tenis, Grace Sainsbury, Kei Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped with the migration of old architectures to this new framework. Andrew Cagney completely re-designed and re-implemented gdb’s unwinder framework, this consisting of a fresh new design featuring frame IDs, independent frame sniffers, and the sentinel frame. Mark Kettenis implemented the dwarf 2 unwinder, Jeff Johnston the libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and trad unwinders. The architecture-specific changes, each involving a complete rewrite of the architecture’s frame code, were carried out by Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich Weigand. Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from Tensilica, Inc. contributed support for Xtensa processors. Others who have worked on the Xtensa port of gdb in the past include Steve Tjiang, John Newlin, and Scott Foehner.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值