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.

308 lines
12KB

  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 Section Format (Debugging with GDB)</title>
  17. <meta name="description" content="Index Section Format (Debugging with GDB)">
  18. <meta name="keywords" content="Index Section Format (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="index.html#Top" rel="up" title="Top">
  26. <link href="Man-Pages.html#Man-Pages" rel="next" title="Man Pages">
  27. <link href="Trace-File-Format.html#Trace-File-Format" rel="prev" title="Trace File Format">
  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-Section-Format"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Man-Pages.html#Man-Pages" accesskey="n" rel="next">Man Pages</a>, Previous: <a href="Trace-File-Format.html#Trace-File-Format" accesskey="p" rel="prev">Trace File Format</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</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="g_t_002egdb_005findex-section-format"></a>
  64. <h2 class="appendix">Appendix J <code>.gdb_index</code> section format</h2>
  65. <a name="index-_002egdb_005findex-section-format"></a>
  66. <a name="index-index-section-format"></a>
  67. <p>This section documents the index section that is created by <code>save
  68. gdb-index</code> (see <a href="Index-Files.html#Index-Files">Index Files</a>). The index section is
  69. DWARF-specific; some knowledge of DWARF is assumed in this
  70. description.
  71. </p>
  72. <p>The mapped index file format is designed to be directly
  73. <code>mmap</code>able on any architecture. In most cases, a datum is
  74. represented using a little-endian 32-bit integer value, called an
  75. <code>offset_type</code>. Big endian machines must byte-swap the values
  76. before using them. Exceptions to this rule are noted. The data is
  77. laid out such that alignment is always respected.
  78. </p>
  79. <p>A mapped index consists of several areas, laid out in order.
  80. </p>
  81. <ol>
  82. <li> The file header. This is a sequence of values, of <code>offset_type</code>
  83. unless otherwise noted:
  84. <ol>
  85. <li> The version number, currently 8. Versions 1, 2 and 3 are obsolete.
  86. Version 4 uses a different hashing function from versions 5 and 6.
  87. Version 6 includes symbols for inlined functions, whereas versions 4
  88. and 5 do not. Version 7 adds attributes to the CU indices in the
  89. symbol table. Version 8 specifies that symbols from DWARF type units
  90. (&lsquo;<samp>DW_TAG_type_unit</samp>&rsquo;) refer to the type unit&rsquo;s symbol table and not the
  91. compilation unit (&lsquo;<samp>DW_TAG_comp_unit</samp>&rsquo;) using the type.
  92. <p><small>GDB</small> will only read version 4, 5, or 6 indices
  93. by specifying <code>set use-deprecated-index-sections on</code>.
  94. GDB has a workaround for potentially broken version 7 indices so it is
  95. currently not flagged as deprecated.
  96. </p>
  97. </li><li> The offset, from the start of the file, of the CU list.
  98. </li><li> The offset, from the start of the file, of the types CU list. Note
  99. that this area can be empty, in which case this offset will be equal
  100. to the next offset.
  101. </li><li> The offset, from the start of the file, of the address area.
  102. </li><li> The offset, from the start of the file, of the symbol table.
  103. </li><li> The offset, from the start of the file, of the constant pool.
  104. </li></ol>
  105. </li><li> The CU list. This is a sequence of pairs of 64-bit little-endian
  106. values, sorted by the CU offset. The first element in each pair is
  107. the offset of a CU in the <code>.debug_info</code> section. The second
  108. element in each pair is the length of that CU. References to a CU
  109. elsewhere in the map are done using a CU index, which is just the
  110. 0-based index into this table. Note that if there are type CUs, then
  111. conceptually CUs and type CUs form a single list for the purposes of
  112. CU indices.
  113. </li><li> The types CU list. This is a sequence of triplets of 64-bit
  114. little-endian values. In a triplet, the first value is the CU offset,
  115. the second value is the type offset in the CU, and the third value is
  116. the type signature. The types CU list is not sorted.
  117. </li><li> The address area. The address area consists of a sequence of address
  118. entries. Each address entry has three elements:
  119. <ol>
  120. <li> The low address. This is a 64-bit little-endian value.
  121. </li><li> The high address. This is a 64-bit little-endian value. Like
  122. <code>DW_AT_high_pc</code>, the value is one byte beyond the end.
  123. </li><li> The CU index. This is an <code>offset_type</code> value.
  124. </li></ol>
  125. </li><li> The symbol table. This is an open-addressed hash table. The size of
  126. the hash table is always a power of 2.
  127. <p>Each slot in the hash table consists of a pair of <code>offset_type</code>
  128. values. The first value is the offset of the symbol&rsquo;s name in the
  129. constant pool. The second value is the offset of the CU vector in the
  130. constant pool.
  131. </p>
  132. <p>If both values are 0, then this slot in the hash table is empty. This
  133. is ok because while 0 is a valid constant pool index, it cannot be a
  134. valid index for both a string and a CU vector.
  135. </p>
  136. <p>The hash value for a table entry is computed by applying an
  137. iterative hash function to the symbol&rsquo;s name. Starting with an
  138. initial value of <code>r = 0</code>, each (unsigned) character &lsquo;<samp>c</samp>&rsquo; in
  139. the string is incorporated into the hash using the formula depending on the
  140. index version:
  141. </p>
  142. <dl compact="compact">
  143. <dt>Version 4</dt>
  144. <dd><p>The formula is <code>r = r * 67 + c - 113</code>.
  145. </p>
  146. </dd>
  147. <dt>Versions 5 to 7</dt>
  148. <dd><p>The formula is <code>r = r * 67 + tolower (c) - 113</code>.
  149. </p></dd>
  150. </dl>
  151. <p>The terminating &lsquo;<samp>\0</samp>&rsquo; is not incorporated into the hash.
  152. </p>
  153. <p>The step size used in the hash table is computed via
  154. <code>((hash * 17) &amp; (size - 1)) | 1</code>, where &lsquo;<samp>hash</samp>&rsquo; is the hash
  155. value, and &lsquo;<samp>size</samp>&rsquo; is the size of the hash table. The step size
  156. is used to find the next candidate slot when handling a hash
  157. collision.
  158. </p>
  159. <p>The names of C<tt>++</tt> symbols in the hash table are canonicalized. We
  160. don&rsquo;t currently have a simple description of the canonicalization
  161. algorithm; if you intend to create new index sections, you must read
  162. the code.
  163. </p>
  164. </li><li> The constant pool. This is simply a bunch of bytes. It is organized
  165. so that alignment is correct: CU vectors are stored first, followed by
  166. strings.
  167. <p>A CU vector in the constant pool is a sequence of <code>offset_type</code>
  168. values. The first value is the number of CU indices in the vector.
  169. Each subsequent value is the index and symbol attributes of a CU in
  170. the CU list. This element in the hash table is used to indicate which
  171. CUs define the symbol and how the symbol is used.
  172. See below for the format of each CU index+attributes entry.
  173. </p>
  174. <p>A string in the constant pool is zero-terminated.
  175. </p></li></ol>
  176. <p>Attributes were added to CU index values in <code>.gdb_index</code> version 7.
  177. If a symbol has multiple uses within a CU then there is one
  178. CU index+attributes value for each use.
  179. </p>
  180. <p>The format of each CU index+attributes entry is as follows
  181. (bit 0 = LSB):
  182. </p>
  183. <dl compact="compact">
  184. <dt>Bits 0-23</dt>
  185. <dd><p>This is the index of the CU in the CU list.
  186. </p></dd>
  187. <dt>Bits 24-27</dt>
  188. <dd><p>These bits are reserved for future purposes and must be zero.
  189. </p></dd>
  190. <dt>Bits 28-30</dt>
  191. <dd><p>The kind of the symbol in the CU.
  192. </p>
  193. <dl compact="compact">
  194. <dt>0</dt>
  195. <dd><p>This value is reserved and should not be used.
  196. By reserving zero the full <code>offset_type</code> value is backwards compatible
  197. with previous versions of the index.
  198. </p></dd>
  199. <dt>1</dt>
  200. <dd><p>The symbol is a type.
  201. </p></dd>
  202. <dt>2</dt>
  203. <dd><p>The symbol is a variable or an enum value.
  204. </p></dd>
  205. <dt>3</dt>
  206. <dd><p>The symbol is a function.
  207. </p></dd>
  208. <dt>4</dt>
  209. <dd><p>Any other kind of symbol.
  210. </p></dd>
  211. <dt>5,6,7</dt>
  212. <dd><p>These values are reserved.
  213. </p></dd>
  214. </dl>
  215. </dd>
  216. <dt>Bit 31</dt>
  217. <dd><p>This bit is zero if the value is global and one if it is static.
  218. </p>
  219. <p>The determination of whether a symbol is global or static is complicated.
  220. The authorative reference is the file <samp>dwarf2read.c</samp> in
  221. <small>GDB</small> sources.
  222. </p>
  223. </dd>
  224. </dl>
  225. <p>This pseudo-code describes the computation of a symbol&rsquo;s kind and
  226. global/static attributes in the index.
  227. </p>
  228. <div class="smallexample">
  229. <pre class="smallexample">is_external = get_attribute (die, DW_AT_external);
  230. language = get_attribute (cu_die, DW_AT_language);
  231. switch (die-&gt;tag)
  232. {
  233. case DW_TAG_typedef:
  234. case DW_TAG_base_type:
  235. case DW_TAG_subrange_type:
  236. kind = TYPE;
  237. is_static = 1;
  238. break;
  239. case DW_TAG_enumerator:
  240. kind = VARIABLE;
  241. is_static = language != CPLUS;
  242. break;
  243. case DW_TAG_subprogram:
  244. kind = FUNCTION;
  245. is_static = ! (is_external || language == ADA);
  246. break;
  247. case DW_TAG_constant:
  248. kind = VARIABLE;
  249. is_static = ! is_external;
  250. break;
  251. case DW_TAG_variable:
  252. kind = VARIABLE;
  253. is_static = ! is_external;
  254. break;
  255. case DW_TAG_namespace:
  256. kind = TYPE;
  257. is_static = 0;
  258. break;
  259. case DW_TAG_class_type:
  260. case DW_TAG_interface_type:
  261. case DW_TAG_structure_type:
  262. case DW_TAG_union_type:
  263. case DW_TAG_enumeration_type:
  264. kind = TYPE;
  265. is_static = language != CPLUS;
  266. break;
  267. default:
  268. assert (0);
  269. }
  270. </pre></div>
  271. <hr>
  272. <div class="header">
  273. <p>
  274. Next: <a href="Man-Pages.html#Man-Pages" accesskey="n" rel="next">Man Pages</a>, Previous: <a href="Trace-File-Format.html#Trace-File-Format" accesskey="p" rel="prev">Trace File Format</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</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>
  275. </div>
  276. </body>
  277. </html>