Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

c - How to load multiple symbol files in 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...