C语言 如何在gdb中加载多个符号文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20380204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to load multiple symbol files in gdb
提问by Ibrar Ahmed
How to load multiple symbol files in gdb. I have a executable foo.out and loading a module bar.so. I have created two symbol files foo.symbol and bar.symbol. How to load both the files into gdb.
如何在gdb. 我有一个可执行文件 foo.out 并加载了一个模块 bar.so。我创建了两个符号文件 foo.symbol 和 bar.symbol。如何将这两个文件加载到 gdb 中。
# gdb --core core
# (gdb)
# (gdb) symbol-file foo.symbol
How to load the second symbol file. Or is there any way to load all the files of directory in gdb
如何加载第二个符号文件。或者有什么方法可以加载目录中的所有文件gdb
回答by alk
To set the directory containing symbol file use
要设置包含符号文件的目录,请使用
set debug-file-directory <directory>
and use
并使用
show debug-file-directory
to show what currently is set as directory containing symbol files.
显示当前设置为包含符号文件的目录。
Symbol files are read automagically from this directory if their name (without path) is provided by the binary in terms of a debug-link.
如果二进制文件根据调试链接提供了符号文件的名称(不带路径),则会自动从此目录中读取符号文件。
To add additional symbols you might use add-symbol-file.
要添加其他符号,您可能会使用add-symbol-file.
(as the gdb onlinedocsseem to be unavailable at the moment I quote this here)
(因为gdb onlinedocs在我在这里引用的那一刻似乎不可用)
add-symbol-file filename address
add-symbol-file filename address [ -readnow ] [ -mapped ]
add-symbol-file filename -ssection address ...
The add-symbol-file command reads additional symbol table information from the file filename. You would use this command when filename has been dynamically loaded (by some other means) into the program that is running. address should be the memory address at which the file has been loaded; gdb cannot figure this out for itself. You can additionally specify an arbitrary number of `-ssection address' pairs, to give an explicit section name and base address for that section. You can specify any address as an expression.
The symbol table of the file filename is added to the symbol table originally read with the symbol-file command. You can use the add-symbol-file command any number of times; the new symbol data thus read keeps adding to the old. To discard all old symbol data instead, use the symbol-file command without any arguments.
Although filename is typically a shared library file, an executable file, or some other object file which has been fully relocated for loading into a process, you can also load symbolic information from relocatable .o files, as long as:
- the file's symbolic information refers only to linker symbols defined in that file, not to symbols defined by other object files,
- every section the file's symbolic information refers to has actually been loaded into the inferior, as it appears in the file, and
- you can determine the address at which every section was loaded, and provide these to the add-symbol-file command.
Some embedded operating systems, like Sun Chorus and VxWorks, can load relocatable files into an already running program; such systems typically make the requirements above easy to meet. However, it's important to recognize that many native systems use complex link procedures (.linkonce section factoring and C++ constructor table assembly, for example) that make the requirements difficult to meet. In general, one cannot assume that using add-symbol-file to read a relocatable object file's symbolic information will have the same effect as linking the relocatable object file into the program in the normal way.
add-symbol-file does not repeat if you press after using it.
You can use the
-mapped' and-readnow' options just as with the symbol-file command, to change how gdb manages the symbol table information for filename.
添加符号文件文件名地址
添加符号文件文件名地址 [ -readnow ] [ -mapped ]
添加符号文件文件名 -ssection 地址 ...
add-symbol-file 命令从文件 filename 中读取附加符号表信息。当文件名已被动态加载(通过其他方式)到正在运行的程序中时,您将使用此命令。address 应该是文件被加载的内存地址;gdb 无法自己解决这个问题。您还可以指定任意数量的“-ssection 地址”对,以便为该部分提供明确的部分名称和基址。您可以将任何地址指定为表达式。
文件filename 的符号表被添加到最初用symbol-file 命令读取的符号表中。您可以多次使用 add-symbol-file 命令;这样读取的新符号数据不断添加到旧符号数据中。要丢弃所有旧的符号数据,请使用不带任何参数的符号文件命令。
尽管文件名通常是共享库文件、可执行文件或其他一些已完全重定位以加载到进程中的目标文件,但您也可以从可重定位的 .o 文件中加载符号信息,只要:
- 文件的符号信息仅指该文件中定义的链接器符号,而不是其他目标文件定义的符号,
- 文件的符号信息所指的每个部分实际上都已加载到下级中,正如它在文件中出现的那样,并且
- 您可以确定加载每个部分的地址,并将这些地址提供给 add-symbol-file 命令。
一些嵌入式操作系统,如 Sun Chorus 和 VxWorks,可以将可重定位的文件加载到已经运行的程序中;此类系统通常可以轻松满足上述要求。但是,重要的是要认识到许多本地系统使用复杂的链接过程(例如,.linkonce 节分解和 C++ 构造函数表组装),这使得这些要求难以满足。通常,不能假设使用 add-symbol-file 读取可重定位目标文件的符号信息与以正常方式将可重定位目标文件链接到程序中具有相同的效果。
如果在使用后按下 add-symbol-file,则不会重复。
您可以
-mapped' and像使用符号文件命令一样使用-readnow' 选项来更改 gdb 如何管理文件名的符号表信息。
回答by Olivier
In addition of the alk's answer and its comments, the address asked is the address of the .textsection.
You can find it by using the readelfcommand
加上alk的回答和评论,问的地址就是.text版块地址。您可以使用readelf命令找到它
Here you have an example of a readelfuse for binary files The address where filename has been loaded is missing [GDB]
这里有一个readelf使用二进制文件的例子文件名被加载的地址丢失[GDB]
回答by Jaakko
Additional symbols can be loaded to the gdbdebug session with:
可以使用以下命令将其他符号加载到gdb调试会话中:
add-symbol-file filename address
Parameter addressis the address for .textsection. This address can be retrieved with:
参数address是段的地址.text。可以通过以下方式检索此地址:
readelf -WS path/to/file.elf | grep .text | awk '{ print "0x" }'
This can be automated in gdbby adding following entry to ~/.gdbinit:
这可以gdb通过添加以下条目来自动化~/.gdbinit:
define add-symbol-file-auto
# Parse .text address to temp file
shell echo set $text_address=$(readelf -WS $arg0 | grep .text | awk '{ print "0x" }') >/tmp/temp_gdb_text_address.txt
# Source .text address
source /tmp/temp_gdb_text_address.txt
# Clean tempfile
shell rm -f /tmp/temp_gdb_text_address.txt
# Load symbol table
add-symbol-file $arg0 $text_address
end
After above function definition add-symbol-file-autocan be used load additional symbols:
上面的函数定义后add-symbol-file-auto可以使用加载附加符号:
(gdb) add-symbol-file-auto path/to/bootloader.elf
add symbol table from file "path/to/bootloader.elf" at
.text_addr = 0x8010400
(gdb) add-symbol-file-auto path/to/application.elf
add symbol table from file "path/to/application.elf" at
.text_addr = 0x8000000
(gdb) break main
Breakpoint 1 at 0x8006cb0: main. (2 locations)
(gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep y <MULTIPLE>
1.1 y 0x08006cb0 in main() at ./source/main.cpp:114
1.2 y 0x080106a6 in main() at ./main.cpp:10
(gdb)
回答by the8472
Instead of attempting to load symbols manually into the correct location I have found it more convenient to merge the symbols back to the stripped executableswith eu-unstripand then reproduce the crash with symbols already present.
我发现将符号合并回剥离的可执行文件,eu-unstrip然后使用已经存在的符号重现崩溃,而不是尝试手动将符号加载到正确的位置更方便。
This approach does not depend on symbol files matching the naming scheme required by the path resolution mechanisms (debug linkand build id) that get used when you set debug-file-directory.
这种方法不依赖于通过匹配路径解决机制(所需的命名方案符号文件调试链接和构建标识,当你设置习惯)debug-file-directory。
回答by Frank Ren
add-symbol-file filename address
add-symbol-file filename address [ -readnow ] [ -mapped ]
add-symbol-file filename -ssection address ...

