dwarf.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /* dwarf.h - DWARF support header file
  2. Copyright (C) 2005-2022 Free Software Foundation, Inc.
  3. This file is part of GNU Binutils.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "dwarf2.h" /* for enum dwarf_unit_type */
  17. typedef unsigned HOST_WIDEST_INT dwarf_vma;
  18. typedef HOST_WIDEST_INT dwarf_signed_vma;
  19. typedef unsigned HOST_WIDEST_INT dwarf_size_type;
  20. /* Structure found in the .debug_line section. */
  21. typedef struct
  22. {
  23. dwarf_vma li_length;
  24. unsigned short li_version;
  25. unsigned char li_address_size;
  26. unsigned char li_segment_size;
  27. dwarf_vma li_prologue_length;
  28. unsigned char li_min_insn_length;
  29. unsigned char li_max_ops_per_insn;
  30. unsigned char li_default_is_stmt;
  31. int li_line_base;
  32. unsigned char li_line_range;
  33. unsigned char li_opcode_base;
  34. unsigned int li_offset_size;
  35. }
  36. DWARF2_Internal_LineInfo;
  37. /* Structure found in .debug_pubnames section. */
  38. typedef struct
  39. {
  40. dwarf_vma pn_length;
  41. unsigned short pn_version;
  42. dwarf_vma pn_offset;
  43. dwarf_vma pn_size;
  44. }
  45. DWARF2_Internal_PubNames;
  46. /* Structure found in .debug_info section. */
  47. typedef struct
  48. {
  49. dwarf_vma cu_length;
  50. unsigned short cu_version;
  51. dwarf_vma cu_abbrev_offset;
  52. unsigned char cu_pointer_size;
  53. enum dwarf_unit_type cu_unit_type;
  54. }
  55. DWARF2_Internal_CompUnit;
  56. /* Structure found in .debug_aranges section. */
  57. typedef struct
  58. {
  59. dwarf_vma ar_length;
  60. unsigned short ar_version;
  61. dwarf_vma ar_info_offset;
  62. unsigned char ar_pointer_size;
  63. unsigned char ar_segment_size;
  64. }
  65. DWARF2_Internal_ARange;
  66. /* N.B. The order here must match the order in debug_displays. */
  67. enum dwarf_section_display_enum
  68. {
  69. abbrev = 0,
  70. aranges,
  71. frame,
  72. info,
  73. line,
  74. pubnames,
  75. gnu_pubnames,
  76. eh_frame,
  77. macinfo,
  78. macro,
  79. str,
  80. line_str,
  81. loc,
  82. loclists,
  83. pubtypes,
  84. gnu_pubtypes,
  85. ranges,
  86. rnglists,
  87. static_func,
  88. static_vars,
  89. types,
  90. weaknames,
  91. gdb_index,
  92. debug_names,
  93. trace_info,
  94. trace_abbrev,
  95. trace_aranges,
  96. info_dwo,
  97. abbrev_dwo,
  98. types_dwo,
  99. line_dwo,
  100. loc_dwo,
  101. macro_dwo,
  102. macinfo_dwo,
  103. str_dwo,
  104. str_index,
  105. str_index_dwo,
  106. debug_addr,
  107. dwp_cu_index,
  108. dwp_tu_index,
  109. gnu_debuglink,
  110. gnu_debugaltlink,
  111. debug_sup,
  112. separate_debug_str,
  113. note_gnu_build_id,
  114. max
  115. };
  116. struct dwarf_section
  117. {
  118. /* A debug section has a different name when it's stored compressed
  119. or not. XCOFF DWARF section also have a special name.
  120. COMPRESSED_NAME, UNCOMPRESSED_NAME and XCOFF_NAME are the three
  121. possibilities. NAME is set to whichever one is used for this
  122. input file, as determined by load_debug_section(). */
  123. const char * uncompressed_name;
  124. const char * compressed_name;
  125. const char * xcoff_name;
  126. const char * name;
  127. /* If non-NULL then FILENAME is the name of the separate debug info
  128. file containing the section. */
  129. const char * filename;
  130. unsigned char * start;
  131. dwarf_vma address;
  132. dwarf_size_type size;
  133. enum dwarf_section_display_enum abbrev_sec;
  134. /* Used by clients to help them implement the reloc_at callback. */
  135. void * reloc_info;
  136. unsigned long num_relocs;
  137. };
  138. /* A structure containing the name of a debug section
  139. and a pointer to a function that can decode it. */
  140. struct dwarf_section_display
  141. {
  142. struct dwarf_section section;
  143. int (*display) (struct dwarf_section *, void *);
  144. int *enabled;
  145. bool relocate;
  146. };
  147. extern struct dwarf_section_display debug_displays [];
  148. /* This structure records the information that
  149. we extract from the.debug_info section. */
  150. typedef struct
  151. {
  152. unsigned int pointer_size;
  153. unsigned int offset_size;
  154. int dwarf_version;
  155. dwarf_vma cu_offset;
  156. dwarf_vma base_address;
  157. /* This field is filled in when reading the attribute DW_AT_GNU_addr_base and
  158. is used with the form DW_FORM_GNU_addr_index. */
  159. dwarf_vma addr_base;
  160. /* This field is filled in when reading the attribute DW_AT_GNU_ranges_base and
  161. is used when calculating ranges. */
  162. dwarf_vma ranges_base;
  163. /* This is an array of offsets to the location list table. */
  164. dwarf_vma * loc_offsets;
  165. /* This is an array of offsets to the location view table. */
  166. dwarf_vma * loc_views;
  167. int * have_frame_base;
  168. /* Information for associating location lists with CUs. */
  169. unsigned int num_loc_offsets;
  170. unsigned int max_loc_offsets;
  171. unsigned int num_loc_views;
  172. dwarf_vma loclists_base;
  173. /* List of .debug_ranges offsets seen in this .debug_info. */
  174. dwarf_vma * range_lists;
  175. unsigned int num_range_lists;
  176. unsigned int max_range_lists;
  177. }
  178. debug_info;
  179. typedef struct separate_info
  180. {
  181. void * handle; /* The pointer returned by open_debug_file(). */
  182. const char * filename;
  183. struct separate_info * next;
  184. } separate_info;
  185. extern separate_info * first_separate_info;
  186. extern unsigned int eh_addr_size;
  187. extern int do_debug_info;
  188. extern int do_debug_abbrevs;
  189. extern int do_debug_lines;
  190. extern int do_debug_pubnames;
  191. extern int do_debug_pubtypes;
  192. extern int do_debug_aranges;
  193. extern int do_debug_ranges;
  194. extern int do_debug_frames;
  195. extern int do_debug_frames_interp;
  196. extern int do_debug_macinfo;
  197. extern int do_debug_str;
  198. extern int do_debug_str_offsets;
  199. extern int do_debug_loc;
  200. extern int do_gdb_index;
  201. extern int do_trace_info;
  202. extern int do_trace_abbrevs;
  203. extern int do_trace_aranges;
  204. extern int do_debug_addr;
  205. extern int do_debug_cu_index;
  206. extern int do_wide;
  207. extern int do_debug_links;
  208. extern int do_follow_links;
  209. #ifdef HAVE_LIBDEBUGINFOD
  210. extern int use_debuginfod;
  211. #endif
  212. extern bool do_checks;
  213. extern int dwarf_cutoff_level;
  214. extern unsigned long dwarf_start_die;
  215. extern int dwarf_check;
  216. extern void init_dwarf_regnames_by_elf_machine_code (unsigned int);
  217. extern void init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch,
  218. unsigned long mach);
  219. extern bool load_debug_section (enum dwarf_section_display_enum, void *);
  220. extern void free_debug_section (enum dwarf_section_display_enum);
  221. extern bool load_separate_debug_files (void *, const char *);
  222. extern void close_debug_file (void *);
  223. extern void *open_debug_file (const char *);
  224. extern void free_debug_memory (void);
  225. extern void dwarf_select_sections_by_names (const char *);
  226. extern void dwarf_select_sections_by_letters (const char *);
  227. extern void dwarf_select_sections_all (void);
  228. extern unsigned int * find_cu_tu_set (void *, unsigned int);
  229. extern void * cmalloc (size_t, size_t);
  230. extern void * xcalloc2 (size_t, size_t);
  231. extern void * xcmalloc (size_t, size_t);
  232. extern void * xcrealloc (void *, size_t, size_t);
  233. /* A callback into the client. Returns TRUE if there is a
  234. relocation against the given debug section at the given
  235. offset. */
  236. extern bool reloc_at (struct dwarf_section *, dwarf_vma);
  237. extern dwarf_vma read_leb128 (unsigned char *, const unsigned char *const,
  238. bool, unsigned int *, int *);
  239. #if HAVE_LIBDEBUGINFOD
  240. extern unsigned char * get_build_id (void *);
  241. #endif
  242. static inline void
  243. report_leb_status (int status)
  244. {
  245. if ((status & 1) != 0)
  246. error (_("end of data encountered whilst reading LEB\n"));
  247. else if ((status & 2) != 0)
  248. error (_("read LEB value is too large to store in destination variable\n"));
  249. }
  250. #define SKIP_ULEB(start, end) \
  251. do \
  252. { \
  253. unsigned int _len; \
  254. read_leb128 (start, end, false, &_len, NULL); \
  255. start += _len; \
  256. } \
  257. while (0)
  258. #define SKIP_SLEB(start, end) \
  259. do \
  260. { \
  261. unsigned int _len; \
  262. read_leb128 (start, end, true, &_len, NULL); \
  263. start += _len; \
  264. } \
  265. while (0)
  266. #define READ_ULEB(var, start, end) \
  267. do \
  268. { \
  269. dwarf_vma _val; \
  270. unsigned int _len; \
  271. int _status; \
  272. \
  273. _val = read_leb128 (start, end, false, &_len, &_status); \
  274. start += _len; \
  275. (var) = _val; \
  276. if ((var) != _val) \
  277. _status |= 2; \
  278. report_leb_status (_status); \
  279. } \
  280. while (0)
  281. #define READ_SLEB(var, start, end) \
  282. do \
  283. { \
  284. dwarf_signed_vma _val; \
  285. unsigned int _len; \
  286. int _status; \
  287. \
  288. _val = read_leb128 (start, end, true, &_len, &_status); \
  289. start += _len; \
  290. (var) = _val; \
  291. if ((var) != _val) \
  292. _status |= 2; \
  293. report_leb_status (_status); \
  294. } \
  295. while (0)