You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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