[Debugging Information in Separate Files]

  gdb allows you to put a program's debugging information in a file separate from the executable itself, in a way that allows gdb to find and load the debugging information automatically. Since debugging information can be very large—sometimes larger than the executable code itself—some systems distribute debugging information for their executables in separate files, which users can install only when they need to debug a problem.

gdb supports two ways of specifying the separate debug info file:

  • The executable contains a debug link that specifies the name of the separate debug info file. The separate debug file's name is usually executable.debug, where executable is the name of the corresponding executable file without leading directories (e.g., ls.debug for /usr/bin/ls). In addition, the debug link specifies a 32-bit Cyclic Redundancy Check (CRC) checksum for the debug file, which gdb uses to validate that the executable and the debug file came from the same build.
  • The executable contains a build ID, a unique bit string that is also present in the corresponding debug info file. (This is supported only on some operating systems, notably those which use the ELF format for binary files and the gnu Binutils.) For more details about this feature, see the description of the --build-id command-line option in Command Line Options. The debug info file's name is not specified explicitly by the build ID, but can be computed from the build ID, see below.

Depending on the way the debug info file is specified, gdb uses two different methods of looking for the debug file:  

  • For the “debug link” method, gdb (1) looks up the named file in the directory of the executable file, then (2) in a subdirectory of that directory named .debug, and finally (3) under each one of the global debug directories, in a subdirectory whose name is identical to the leading directories of the executable's absolute file name.
  • For the “build ID” method, gdb looks in the .build-id subdirectory of each one of the global debug directories for a file named nn/nnnnnnnn.debug, where nn are the first 2 hex characters of the build ID bit string, and nnnnnnnn are the rest of the bit string. (Real build ID strings are 32 or more hex characters, not 10.)

So, for example, suppose you ask gdb to debug /usr/bin/ls, which has a debug link that specifies the file ls.debug, and a build ID whose value in hex is abcdef1234. If the list of the global debug directories includes /usr/lib/debug, then gdb will look for the following debug information files, in the indicated order:

  • /usr/lib/debug/.build-id/ab/cdef1234.debug
  • /usr/bin/ls.debug
  • /usr/bin/.debug/ls.debug
  • /usr/lib/debug/usr/bin/ls.debug.

Global debugging info directories default to what is set by gdb configure option --with-separate-debug-dir. During gdb run you can also set the global debugging info directories, and view the list gdb is currently using.

set debug-file-directory directories

  Set the directories which gdb searches for separate debugging information files to directory. Multiple path components can be set concatenating them by a path separator.

show debug-file-directory
Show the directories gdb searches for separate debugging information files.
Any executable file format can carry a debug link, as long as it can contain a section named .gnu_debuglink with the contents described above.
 
The build ID is a special section in the executable file (and in other ELF binary files that gdb may consider). This section is often named .note.gnu.build-id, but that name is not mandatory. It contains unique identification for the built files—the ID remains the same across multiple builds of the same build tree. The default algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the content for the build ID string. The same section with an identical value is present in the original built binary with symbols, in its stripped variant, and in the separate debugging information file.

The debugging information file itself should be an ordinary executable, containing a full set of linker symbols, sections, and debugging information. The sections of the debugging information file should have the same names, addresses, and sizes as the original file, but they need not contain any data—much like a .bss section in an ordinary executable.

The gnu binary utilities (Binutils) package includes the ‘objcopy’ utility that can produce the separated executable / debugging information file pairs using the following commands:

     objcopy --only-keep-debug foo foo.debug
strip -g foo

These commands remove the debugging information from the executable file foo and place it in the file foo.debug. You can use the first, second or both methods to link the two files:

  • The debug link method needs the following additional command to also leave behind a debug link in foo:

              objcopy --add-gnu-debuglink=foo.debug foo
    

    Ulrich Drepper's elfutils package, starting with version 0.53, contains a version of the strip command such that the command strip foo -f foo.debug has the same functionality as the two objcopy commands and the ln -s command above, together.

  • Build ID gets embedded into the main executable using ld --build-id or the gcc counterpart gcc -Wl,--build-id. Build ID support plus compatibility fixes for debug files separation are present in gnu binary utilities (Binutils) package since version 2.18.

参考: https://sourceware.org/gdb/download/onlinedocs/gdb/Separate-Debug-Files.html#Separate-Debug-Files

Debugging Information in Separate Files的更多相关文章

  1. Detailed Information for Outputted Files from Somatic Mutation Annotators(annovar 注释文件条目详细解释)

    CONTENTS *_annoTable.txt (ANNOVAR) *_annoTable.txt (SnpEff) *_genelist.txt (ANNOVAR & SnpEff) db ...

  2. hive: insert数据时Error during job, obtaining debugging information 以及beyond physical memory limits

    insert overwrite table canal_amt1...... 2014-10-09 10:40:27,368 Stage-1 map = 100%, reduce = 32%, Cu ...

  3. GDB技巧整理

    https://blog.atime.me/note/gdb-tricks.html 整理常用的gdb技巧. 常用命令 常用的gdb命令... 启动gdb 直接运行 gdb --args prog a ...

  4. Make命令完全详解教程

    Make命令完全详解教程 无论是在Linux还是在Unix环境中,make都是一个非常重要的编译命令.不管是自己进行项目开发还是安装应用软件,我们都经常要用到make或make install.利用m ...

  5. Beginning Linux Programming 学习-chapter2-Shell programming-Pipes and Redirection

    "为了从事创造性工作,人类需要孤独,可是在孤独中,广义的人类仍存在于内心."--(德国)奥铿                                             ...

  6. Options for Debugging Your Program or GCC

    [Options for Debugging Your Program or GCC] -g Produce debugging information in the operating system ...

  7. The Kernel Newbie Corner: Kernel Debugging with proc "Sequence" Files--Part 3

    转载:https://www.linux.com/learn/linux-career-center/44184-the-kernel-newbie-corner-kernel-debugging-w ...

  8. PDB Files: What Every Developer Must Know

    Reference:  http://www.wintellect.com/blogs/jrobbins/pdb-files-what-every-developer-must-know Most d ...

  9. Files and Directories

    Files and Directories Introduction     In the previous chapter we coveredthe basic functions that pe ...

随机推荐

  1. SharePoint的实体生成

    生成Linq实体 使用SPMetal工具生成Linq to SharePoint实体 工具安装目录: C:\Program Files\Common Files\Microsoft Shared\We ...

  2. HDU 1160 FatMouse's Speed

    半个下午,总算A过去了 毕竟水题 好歹是自己独立思考,debug,然后2A过的 我为人人的dp算法 题意: 为了支持你的观点,你需要从给的数据中找出尽量多的数据,说明老鼠越重速度越慢这一论点 本着“指 ...

  3. [转载]charisma-master 加载慢的原因及解决方法

    [我的总结] 原文中指出的地址有的已经转换,因为版本问题. 所以根据2014年11月获取的charisma-master版本,应做以下更改: 1.charisma-app.css 这个文件中的外链字体 ...

  4. 切记一定要防止恶意用户直接访问Ajax请求地址

    多年前的一个web项目, 有一个地方是用ajax发送短信验证码, 当时没考虑好, 没判断来路, 这几天被人恶意滥用发送了很多垃圾短信, 投诉到公司来了.  今天一看代码吓出一身冷汗! 以后一定要记得判 ...

  5. I.MX6 Linux、Jni ioctl 差异

    /*********************************************************************** * I.MX6 Linux.Jni ioctl 差异 ...

  6. mysql无法插入中文字符解决

    1. 基于可维护的角度,虽然latin1没什么问题,但是还是尽量换成utf8或者gb系列 2. 出现乱码时: SHOW VARIABLES LIKE 'character%'SHOW VARIABLE ...

  7. (转)Mac OS X写了个rm时将文件放入回收站的小工具

    上次由于公司里机器要面临重装,开始仓皇地将Mac本里的文件scp到我的台式机上.忙乱之中本来要删除一个无用的文件夹的,结果用rm -rf的时候tab了一下,补全出来的文件都没看清就按下了回车,毫无疑问 ...

  8. liunx的目录结构

    linux目录结构的最顶端是/目录 我们一般都称为root目录. linux有四种文件类型,分别是普通文件,目录文件,连接文件,特殊文件,可以用file来识别. 普通文件:文本文件 二进制文件 图像文 ...

  9. dynamic_cast

    作为四个内部类型转换操作符之一的dynamic_cast和传统的C风格的强制类型转换有着巨大的差别.除了dynamic_cast以外的转换,其行为的都是在编译期就得以确定的,转换是否成功,并不依赖被转 ...

  10. Android 一步一步教你使用ViewDragHelper

    在自定义viewgroup的时候 要重写onInterceptTouchEvent和onTouchEvent 这2个方法 是非常麻烦的事情,好在谷歌后来 推出了ViewDragHelper这个类.可以 ...