1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<!-- Copyright (C) 1988-2021 Free Software Foundation, Inc. 4 5Permission is granted to copy, distribute and/or modify this document 6under the terms of the GNU Free Documentation License, Version 1.3 or 7any later version published by the Free Software Foundation; with the 8Invariant Sections being "Free Software" and "Free Software Needs 9Free Documentation", with the Front-Cover Texts being "A GNU Manual," 10and with the Back-Cover Texts as in (a) below. 11 12(a) The FSF's Back-Cover Text is: "You are free to copy and modify 13this GNU Manual. Buying copies from GNU Press supports the FSF in 14developing GNU and promoting software freedom." --> 15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 16<head> 17<title>Debugging with GDB: Index Files</title> 18 19<meta name="description" content="Debugging with GDB: Index Files"> 20<meta name="keywords" content="Debugging with GDB: Index Files"> 21<meta name="resource-type" content="document"> 22<meta name="distribution" content="global"> 23<meta name="Generator" content="makeinfo"> 24<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 25<link href="index.html#Top" rel="start" title="Top"> 26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> 27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 28<link href="GDB-Files.html#GDB-Files" rel="up" title="GDB Files"> 29<link href="Symbol-Errors.html#Symbol-Errors" rel="next" title="Symbol Errors"> 30<link href="MiniDebugInfo.html#MiniDebugInfo" rel="previous" title="MiniDebugInfo"> 31<style type="text/css"> 32<!-- 33a.summary-letter {text-decoration: none} 34blockquote.smallquotation {font-size: smaller} 35div.display {margin-left: 3.2em} 36div.example {margin-left: 3.2em} 37div.indentedblock {margin-left: 3.2em} 38div.lisp {margin-left: 3.2em} 39div.smalldisplay {margin-left: 3.2em} 40div.smallexample {margin-left: 3.2em} 41div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 42div.smalllisp {margin-left: 3.2em} 43kbd {font-style:oblique} 44pre.display {font-family: inherit} 45pre.format {font-family: inherit} 46pre.menu-comment {font-family: serif} 47pre.menu-preformatted {font-family: serif} 48pre.smalldisplay {font-family: inherit; font-size: smaller} 49pre.smallexample {font-size: smaller} 50pre.smallformat {font-family: inherit; font-size: smaller} 51pre.smalllisp {font-size: smaller} 52span.nocodebreak {white-space:nowrap} 53span.nolinebreak {white-space:nowrap} 54span.roman {font-family:serif; font-weight:normal} 55span.sansserif {font-family:sans-serif; font-weight:normal} 56ul.no-bullet {list-style: none} 57--> 58</style> 59 60 61</head> 62 63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 64<a name="Index-Files"></a> 65<div class="header"> 66<p> 67Next: <a href="Symbol-Errors.html#Symbol-Errors" accesskey="n" rel="next">Symbol Errors</a>, Previous: <a href="MiniDebugInfo.html#MiniDebugInfo" accesskey="p" rel="previous">MiniDebugInfo</a>, Up: <a href="GDB-Files.html#GDB-Files" accesskey="u" rel="up">GDB Files</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> 68</div> 69<hr> 70<a name="Index-Files-Speed-Up-GDB"></a> 71<h3 class="section">18.5 Index Files Speed Up <small>GDB</small></h3> 72<a name="index-index-files"></a> 73<a name="index-_002egdb_005findex-section"></a> 74 75<p>When <small>GDB</small> finds a symbol file, it scans the symbols in the 76file in order to construct an internal symbol table. This lets most 77<small>GDB</small> operations work quickly—at the cost of a delay early 78on. For large programs, this delay can be quite lengthy, so 79<small>GDB</small> provides a way to build an index, which speeds up 80startup. 81</p> 82<p>For convenience, <small>GDB</small> comes with a program, 83<code>gdb-add-index</code>, which can be used to add the index to a 84symbol file. It takes the symbol file as its only argument: 85</p> 86<div class="smallexample"> 87<pre class="smallexample">$ gdb-add-index symfile 88</pre></div> 89 90<p>See <a href="gdb_002dadd_002dindex-man.html#gdb_002dadd_002dindex">gdb-add-index</a>. 91</p> 92<p>It is also possible to do the work manually. Here is what 93<code>gdb-add-index</code> does behind the curtains. 94</p> 95<p>The index is stored as a section in the symbol file. <small>GDB</small> can 96write the index to a file, then you can put it into the symbol file 97using <code>objcopy</code>. 98</p> 99<p>To create an index file, use the <code>save gdb-index</code> command: 100</p> 101<dl compact="compact"> 102<dt><code>save gdb-index [-dwarf-5] <var>directory</var></code></dt> 103<dd><a name="index-save-gdb_002dindex"></a> 104<p>Create index files for all symbol files currently known by 105<small>GDB</small>. For each known <var>symbol-file</var>, this command by 106default creates it produces a single file 107<samp><var>symbol-file</var>.gdb-index</samp>. If you invoke this command with 108the <samp>-dwarf-5</samp> option, it produces 2 files: 109<samp><var>symbol-file</var>.debug_names</samp> and 110<samp><var>symbol-file</var>.debug_str</samp>. The files are created in the 111given <var>directory</var>. 112</p></dd> 113</dl> 114 115<p>Once you have created an index file you can merge it into your symbol 116file, here named <samp>symfile</samp>, using <code>objcopy</code>: 117</p> 118<div class="smallexample"> 119<pre class="smallexample">$ objcopy --add-section .gdb_index=symfile.gdb-index \ 120 --set-section-flags .gdb_index=readonly symfile symfile 121</pre></div> 122 123<p>Or for <code>-dwarf-5</code>: 124</p> 125<div class="smallexample"> 126<pre class="smallexample">$ objcopy --dump-section .debug_str=symfile.debug_str.new symfile 127$ cat symfile.debug_str >>symfile.debug_str.new 128$ objcopy --add-section .debug_names=symfile.gdb-index \ 129 --set-section-flags .debug_names=readonly \ 130 --update-section .debug_str=symfile.debug_str.new symfile symfile 131</pre></div> 132 133<p><small>GDB</small> will normally ignore older versions of <samp>.gdb_index</samp> 134sections that have been deprecated. Usually they are deprecated because 135they are missing a new feature or have performance issues. 136To tell <small>GDB</small> to use a deprecated index section anyway 137specify <code>set use-deprecated-index-sections on</code>. 138The default is <code>off</code>. 139This can speed up startup, but may result in some functionality being lost. 140See <a href="Index-Section-Format.html#Index-Section-Format">Index Section Format</a>. 141</p> 142<p><em>Warning:</em> Setting <code>use-deprecated-index-sections</code> to <code>on</code> 143must be done before gdb reads the file. The following will not work: 144</p> 145<div class="smallexample"> 146<pre class="smallexample">$ gdb -ex "set use-deprecated-index-sections on" <program> 147</pre></div> 148 149<p>Instead you must do, for example, 150</p> 151<div class="smallexample"> 152<pre class="smallexample">$ gdb -iex "set use-deprecated-index-sections on" <program> 153</pre></div> 154 155<p>Indices only work when using DWARF debugging information, not stabs. 156</p> 157<a name="Automatic-Symbol-Index-Cache"></a> 158<h4 class="subsection">18.5.1 Automatic Symbol Index Cache</h4> 159 160<a name="index-automatic-symbol-index-cache"></a> 161<p>It is possible for <small>GDB</small> to automatically save a copy of this index in a 162cache on disk and retrieve it from there when loading the same binary in the 163future. This feature can be turned on with <kbd>set index-cache on</kbd>. The 164following commands can be used to tweak the behavior of the index cache. 165</p> 166<dl compact="compact"> 167<dd> 168<a name="index-set-index_002dcache"></a> 169</dd> 170<dt><code>set index-cache on</code></dt> 171<dt><code>set index-cache off</code></dt> 172<dd><p>Enable or disable the use of the symbol index cache. 173</p> 174</dd> 175<dt><code>set index-cache directory <var>directory</var></code></dt> 176<dd><a name="index-show-index_002dcache"></a> 177</dd> 178<dt><code>show index-cache directory</code></dt> 179<dd><p>Set/show the directory where index files will be saved. 180</p> 181<p>The default value for this directory depends on the host platform. On 182most systems, the index is cached in the <samp>gdb</samp> subdirectory of 183the directory pointed to by the <code>XDG_CACHE_HOME</code> environment 184variable, if it is defined, else in the <samp>.cache/gdb</samp> subdirectory 185of your home directory. However, on some systems, the default may 186differ according to local convention. 187</p> 188<p>There is no limit on the disk space used by index cache. It is perfectly safe 189to delete the content of that directory to free up disk space. 190</p> 191</dd> 192<dt><code>show index-cache stats</code></dt> 193<dd><p>Print the number of cache hits and misses since the launch of <small>GDB</small>. 194</p> 195</dd> 196</dl> 197 198<hr> 199<div class="header"> 200<p> 201Next: <a href="Symbol-Errors.html#Symbol-Errors" accesskey="n" rel="next">Symbol Errors</a>, Previous: <a href="MiniDebugInfo.html#MiniDebugInfo" accesskey="p" rel="previous">MiniDebugInfo</a>, Up: <a href="GDB-Files.html#GDB-Files" accesskey="u" rel="up">GDB Files</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> 202</div> 203 204 205 206</body> 207</html> 208