toolchain/share/doc/gdb/Index-Files.html

151 lines
7.5 KiB
HTML

<html lang="en">
<head>
<title>Index Files - Debugging with GDB</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Debugging with GDB">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="GDB-Files.html#GDB-Files" title="GDB Files">
<link rel="prev" href="MiniDebugInfo.html#MiniDebugInfo" title="MiniDebugInfo">
<link rel="next" href="Symbol-Errors.html#Symbol-Errors" title="Symbol Errors">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software'' and ``Free Software Needs
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below.
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom.''
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="Index-Files"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Symbol-Errors.html#Symbol-Errors">Symbol Errors</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="MiniDebugInfo.html#MiniDebugInfo">MiniDebugInfo</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="GDB-Files.html#GDB-Files">GDB Files</a>
<hr>
</div>
<h3 class="section">18.5 Index Files Speed Up <span class="sc">gdb</span></h3>
<p><a name="index-index-files-1292"></a><a name="index-g_t_0040samp_007b_002egdb_005findex_007d-section-1293"></a>
When <span class="sc">gdb</span> finds a symbol file, it scans the symbols in the
file in order to construct an internal symbol table. This lets most
<span class="sc">gdb</span> operations work quickly&mdash;at the cost of a delay early
on. For large programs, this delay can be quite lengthy, so
<span class="sc">gdb</span> provides a way to build an index, which speeds up
startup.
<p>For convenience, <span class="sc">gdb</span> comes with a program,
<samp><span class="command">gdb-add-index</span></samp>, which can be used to add the index to a
symbol file. It takes the symbol file as its only argument:
<pre class="smallexample"> $ gdb-add-index symfile
</pre>
<p>See <a href="gdb_002dadd_002dindex.html#gdb_002dadd_002dindex">gdb-add-index</a>.
<p>It is also possible to do the work manually. Here is what
<samp><span class="command">gdb-add-index</span></samp> does behind the curtains.
<p>The index is stored as a section in the symbol file. <span class="sc">gdb</span> can
write the index to a file, then you can put it into the symbol file
using <samp><span class="command">objcopy</span></samp>.
<p>To create an index file, use the <code>save gdb-index</code> command:
<dl>
<dt><code>save gdb-index [-dwarf-5] </code><var>directory</var><dd><a name="index-save-gdb_002dindex-1294"></a>Create index files for all symbol files currently known by
<span class="sc">gdb</span>. For each known <var>symbol-file</var>, this command by
default creates it produces a single file
<samp><var>symbol-file</var><span class="file">.gdb-index</span></samp>. If you invoke this command with
the <samp><span class="option">-dwarf-5</span></samp> option, it produces 2 files:
<samp><var>symbol-file</var><span class="file">.debug_names</span></samp> and
<samp><var>symbol-file</var><span class="file">.debug_str</span></samp>. The files are created in the
given <var>directory</var>.
</dl>
<p>Once you have created an index file you can merge it into your symbol
file, here named <samp><span class="file">symfile</span></samp>, using <samp><span class="command">objcopy</span></samp>:
<pre class="smallexample"> $ objcopy --add-section .gdb_index=symfile.gdb-index \
--set-section-flags .gdb_index=readonly symfile symfile
</pre>
<p>Or for <code>-dwarf-5</code>:
<pre class="smallexample"> $ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
$ cat symfile.debug_str &gt;&gt;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
</pre>
<p><span class="sc">gdb</span> will normally ignore older versions of <samp><span class="file">.gdb_index</span></samp>
sections that have been deprecated. Usually they are deprecated because
they are missing a new feature or have performance issues.
To tell <span class="sc">gdb</span> to use a deprecated index section anyway
specify <code>set use-deprecated-index-sections on</code>.
The default is <code>off</code>.
This can speed up startup, but may result in some functionality being lost.
See <a href="Index-Section-Format.html#Index-Section-Format">Index Section Format</a>.
<p><em>Warning:</em> Setting <code>use-deprecated-index-sections</code> to <code>on</code>
must be done before gdb reads the file. The following will not work:
<pre class="smallexample"> $ gdb -ex "set use-deprecated-index-sections on" &lt;program&gt;
</pre>
<p>Instead you must do, for example,
<pre class="smallexample"> $ gdb -iex "set use-deprecated-index-sections on" &lt;program&gt;
</pre>
<p>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.
<h4 class="subsection">18.5.1 Automatic symbol index cache</h4>
<p>It is possible for <span class="sc">gdb</span> to automatically save a copy of this index in a
cache on disk and retrieve it from there when loading the same binary in the
future. This feature can be turned on with <kbd>set index-cache on</kbd>. The
following commands can be used to tweak the behavior of the index cache.
<dl>
<dt><code>set index-cache on</code><dt><code>set index-cache off</code><dd>Enable or disable the use of the symbol index cache.
<br><dt><code>set index-cache directory </code><var>directory</var><dt><code>show index-cache directory</code><dd>Set/show the directory where index files will be saved.
<p>The default value for this directory depends on the host platform. On
most systems, the index is cached in the <samp><span class="file">gdb</span></samp> subdirectory of
the directory pointed to by the <samp><span class="env">XDG_CACHE_HOME</span></samp> environment
variable, if it is defined, else in the <samp><span class="file">.cache/gdb</span></samp> subdirectory
of your home directory. However, on some systems, the default may
differ according to local convention.
<p>There is no limit on the disk space used by index cache. It is perfectly safe
to delete the content of that directory to free up disk space.
<br><dt><code>show index-cache stats</code><dd>Print the number of cache hits and misses since the launch of <span class="sc">gdb</span>.
</dl>
</body></html>