如何在gdb中加载多个符号文件 [英] How to load multiple symbol files in gdb

查看:1367
本文介绍了如何在gdb中加载多个符号文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 gdb 中加载多个符号文件。我有一个可执行文件foo.out并加载模块bar.so.我已经创建了两个符号文件foo.symbol和bar.symbol。如何将这两个文件加载到gdb中。

 #gdb --core core 
#(gdb)
#(gdb)symbol-file foo .symbol

如何加载第二个符号文件。或者有什么办法加载 gdb中的所有文件目录

解决方案

p>要设置包含符号文件的目录,请使用

  set debug-file-directory< directory> 

并使用

 code> show debug-file-directory 

显示当前设置为目录包含符号文件。



如果符号文件的名称(无路径)由调试链接的二进制文件提供,则从该目录自动读取。






要添加附加符号,您可以使用 add-symbol-file



(因为 gdb onlinedocs 似乎是


添加符号文件文件名地址



add-symbol-file filename address [-readnow] [-mapped]



add-symbol-file filename -ssection address ...



add-symbol-file命令从文件filename中读取附加的符号表信息。当文件名已经被动态加载(通过其他方式)到运行的程序中时,您将使用此命令。地址应该是加载文件的内存地址; gdb本身无法证明这一点。您可以额外指定任意数量的 - 地址对,以给出该段的显式段名称和基址。您可以将任何地址指定为表达式。



将文件filename的符号表添加到最初使用symbol-file命令读取的符号表中。可以使用add-symbol-file命令多次;因此读取的新符号数据不断添加到旧的。要舍弃所有旧的符号数据,请使用符号文件命令,不带任何参数。



尽管文件名通常是共享库文件,可执行文件或其他对象文件已被完全重定位以加载到进程中,您还可以从可重定位的.o文件中加载符号信息,只要:




  • 该文件的符号信息仅指该文件中定义的链接器符号,而不是由其他目标文件定义的符号,

  • 文件的符号信息所指的每个部分实际上已被加载到下一个文件中,因为它出现在文件中,并且

  • 可以确定每个段加载的地址,并将其提供给add-symbol-file命令。某些嵌入式操作系统(如Sun Chorus和VxWorks)可以将可重定位文件加载到已经运行的程序中;



这样的系统通常使上述要求容易满足。然而,重要的是要认识到许多本地系统使用复杂的链接过程(例如,.linkonce部分因子分解和C ++构造函数表组合),使得需求难以满足。一般来说,我们不能假定使用add-symbol-file来读取可重定位对象文件的符号信息将具有与正常方式将可重定位对象文件链接到程序中的效果相同。





您可以使用 -mapped'和 -readnow'选项与symbol-file命令一样,更改gdb如何管理文件名的符号表信息。



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 --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

解决方案

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 addtional symbols you might use add-symbol-file.

(as the gdb onlinedocs seem to be unavailable at the moment I quote this here)

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.

这篇关于如何在gdb中加载多个符号文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆