When gdb finds a symbol file, it scans the symbols in the file in order to construct an internal symbol table. This lets most gdb operations work quickly—at the cost of a delay early on. For large programs, this delay can be quite lengthy, so gdb provides a way to build an index, which speeds up startup.
For convenience, gdb comes with a program, gdb-add-index, which can be used to add the index to a symbol file. It takes the symbol file as its only argument:
$ gdb-add-index symfile
See gdb-add-index.
It is also possible to do the work manually. Here is what gdb-add-index does behind the curtains.
The index is stored as a section in the symbol file. gdb can write the index to a file, then you can put it into the symbol file using objcopy.
To create an index file, use the save gdb-index
command:
save gdb-index [-dwarf-5]
directoryOnce you have created an index file you can merge it into your symbol file, here named symfile, using objcopy:
$ objcopy --add-section .gdb_index=symfile.gdb-index \ --set-section-flags .gdb_index=readonly symfile symfile
Or for -dwarf-5
:
$ objcopy --dump-section .debug_str=symfile.debug_str.new symfile $ cat symfile.debug_str >>symfile.debug_str.new $ objcopy --add-section .debug_names=symfile.gdb-index \ --set-section-flags .debug_names=readonly \ --update-section .debug_str=symfile.debug_str.new symfile symfile
gdb will normally ignore older versions of .gdb_index
sections that have been deprecated. Usually they are deprecated because
they are missing a new feature or have performance issues.
To tell gdb to use a deprecated index section anyway
specify set use-deprecated-index-sections on
.
The default is off
.
This can speed up startup, but may result in some functionality being lost.
See Index Section Format.
Warning: Setting use-deprecated-index-sections
to on
must be done before gdb reads the file. The following will not work:
$ gdb -ex "set use-deprecated-index-sections on" <program>
Instead you must do, for example,
$ gdb -iex "set use-deprecated-index-sections on" <program>
There are currently some limitation on indices. They only work when for DWARF debugging information, not stabs. And, they do not currently work for programs using Ada.