Debian Codegraph @

src/bin/dwarfdump/dd_glflags.h

raw
1 /*
2 Copyright (C) 2017-2020 David Anderson. All Rights Reserved.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of version 2 of the GNU General
6 Public License as published by the Free Software Foundation.
7
8 This program is distributed in the hope that it would be
9 useful, but WITHOUT ANY WARRANTY; without even the implied
10 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE.
12
13 Further, this software is distributed without any warranty
14 that it is free of the rightful claim of any third person
15 regarding infringement or the like. Any license provided
16 herein, whether implied or otherwise, applies only to this
17 software file. Patent licenses, if any, provided herein
18 do not apply to combinations of this program with other
19 software, or any other product whatsoever.
20
21 You should have received a copy of the GNU General Public
22 License along with this program; if not, write the Free
23 Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
24 Boston MA 02110-1301, USA.
25 */
26
27 #ifndef GLFLAGS_H
28 #define GLFLAGS_H
29
30 /* All the dwarfdump flags are gathered into a single
31 global struct as it has been hard to know how many there
32 were or what they were all for. */
33
34 struct esb_s;
35 struct dwconf_s;
36
37 enum line_flag_type_e {
38 singledw5,/* Meaning choose single table DWARF5 new interfaces. */
39 s2l, /* Meaning choose two-level DWARF5 new interfaces. */
40 orig, /* Meaning choose DWARF2,3,4 single level interface. */
41 orig2l /* Meaning choose DWARF 2,3,4 two-level interface. */
42 };
43
44 /* Check categories corresponding to the -k option */
45 typedef enum /* Dwarf_Check_Categories */ {
46 abbrev_code_result,
47 pubname_attr_result,
48 reloc_offset_result,
49 attr_tag_result,
50 tag_tree_result,
51 type_offset_result,
52 decl_file_result,
53 ranges_result,
54 lines_result,
55 aranges_result,
56 /* Harmless errors are errors detected inside libdwarf but
57 not reported via DW_DLE_ERROR returns because the errors
58 won't really affect client code. The 'harmless' errors
59 are reported and otherwise ignored. It is difficult to report
60 the error when the error is noticed by libdwarf, the error
61 is reported at a later time.
62 The other errors dwarfdump reports are also generally harmless
63 but are detected by dwarfdump so it's possble to report the
64 error as soon as the error is discovered. */
65 harmless_result,
66 fde_duplication,
67 frames_result,
68 locations_result,
69 names_result,
70 abbreviations_result,
71 dwarf_constants_result,
72 di_gaps_result,
73 forward_decl_result,
74 self_references_result,
75 attr_encoding_result,
76 duplicated_attributes_result,
77 total_check_result,
78 attr_formclass_result,
79 check_functions_result,
80 LAST_CATEGORY /* Must be last */
81 } Dwarf_Check_Categories;
82
83 struct section_high_offsets_s {
84 Dwarf_Unsigned debug_info_size;
85 Dwarf_Unsigned debug_abbrev_size;
86 Dwarf_Unsigned debug_line_size;
87 Dwarf_Unsigned debug_loc_size;
88 Dwarf_Unsigned debug_aranges_size;
89 Dwarf_Unsigned debug_macinfo_size;
90 Dwarf_Unsigned debug_pubnames_size;
91 Dwarf_Unsigned debug_str_size;
92 Dwarf_Unsigned debug_frame_size;
93 Dwarf_Unsigned debug_ranges_size;
94 Dwarf_Unsigned debug_pubtypes_size;
95 Dwarf_Unsigned debug_types_size;
96 Dwarf_Unsigned debug_macro_size;
97 Dwarf_Unsigned debug_str_offsets_size;
98 Dwarf_Unsigned debug_sup_size;
99 Dwarf_Unsigned debug_cu_index_size;
100 Dwarf_Unsigned debug_tu_index_size;
101 Dwarf_Unsigned debug_names_size;
102 Dwarf_Unsigned debug_loclists_size;
103 Dwarf_Unsigned debug_rnglists_size;
104 };
105
106 /* Options to enable debug tracing. */
107 #define MAX_TRACE_LEVEL 3
108
109 struct glflags_s {
110
111 /* This so both
112 dwarf_loclist_n() and dwarf_get_loclist_c()
113 and the dwarf_loclist_from_expr
114 variations can be
115 tested. Defaults to new
116 dwarf_get_loclist_c(). See -g option.
117 original IRIX dwarf_loclist() no longer tested
118 as of October 2015. */
119 Dwarf_Bool gf_use_old_dwarf_loclist;
120 enum line_flag_type_e gf_line_flag_selection;
121
122 Dwarf_Bool gf_abbrev_flag;
123 Dwarf_Bool gf_aranges_flag; /* .debug_aranges section. */
124 Dwarf_Bool gf_debug_names_flag; /* .debug_names section */
125 Dwarf_Bool gf_eh_frame_flag; /* GNU .eh_frame section. */
126 Dwarf_Bool gf_frame_flag; /* .debug_frame section. */
127 Dwarf_Bool gf_gdbindex_flag; /* .gdbindex section. */
128 Dwarf_Bool gf_gnu_debuglink_flag; /* .gnu_debuglink section. */
129 Dwarf_Bool gf_debug_gnu_flag; /* .debug_gnu_pubtypes, pubnames*/
130 Dwarf_Bool gf_debug_sup_flag; /* .debug_sup */
131 Dwarf_Bool gf_info_flag; /* .debug_info */
132 Dwarf_Bool gf_line_flag;
133 Dwarf_Bool gf_no_follow_debuglink;
134 Dwarf_Bool gf_line_print_pc;
135 Dwarf_Bool gf_line_skeleton_flag;
136 Dwarf_Bool gf_loc_flag;
137 Dwarf_Bool gf_macinfo_flag; /* DWARF2,3,4. Old macro section*/
138 Dwarf_Bool gf_macro_flag; /* DWARF5 */
139 Dwarf_Bool gf_pubnames_flag;
140 Dwarf_Bool gf_debug_addr_flag;
141 Dwarf_Bool gf_ranges_flag; /* .debug_ranges section. */
142 Dwarf_Bool gf_reloc_flag; /* Elf relocations, not DWARF. */
143 Dwarf_Bool gf_static_func_flag;/* SGI only */
144 Dwarf_Bool gf_static_var_flag; /* SGI only */
145 Dwarf_Bool gf_string_flag;
146 Dwarf_Bool gf_pubtypes_flag; /* SGI only */
147 Dwarf_Bool gf_types_flag; /* .debug_types, not all CU types */
148 Dwarf_Bool gf_weakname_flag; /* SGI only */
149
150 Dwarf_Bool gf_print_utf8_flag;
151
152 Dwarf_Bool gf_header_flag; /* Control printing of Elf header. */
153 Dwarf_Bool gf_section_groups_flag;
154
155 /* Print list of CUs per compiler */
156 Dwarf_Bool gf_producer_children_flag;
157
158 Dwarf_Bool gf_check_abbrev_code;
159 Dwarf_Bool gf_check_pubname_attr;
160 Dwarf_Bool gf_check_reloc_offset;
161 Dwarf_Bool gf_check_tag_attr;
162 Dwarf_Bool gf_check_tag_tree;
163 Dwarf_Bool gf_check_type_offset;
164 Dwarf_Bool gf_check_decl_file;
165 Dwarf_Bool gf_check_macros;
166 Dwarf_Bool gf_check_lines;
167 Dwarf_Bool gf_check_fdes;
168 Dwarf_Bool gf_check_ranges;
169 Dwarf_Bool gf_check_aranges;
170 Dwarf_Bool gf_check_harmless;
171 Dwarf_Bool gf_check_abbreviations;
172 Dwarf_Bool gf_check_dwarf_constants;
173 Dwarf_Bool gf_check_di_gaps;
174 Dwarf_Bool gf_check_forward_decl;
175 Dwarf_Bool gf_check_self_references;
176 Dwarf_Bool gf_check_attr_encoding; /* Attributes encoding */
177 Dwarf_Bool gf_generic_1200_regs;
178 Dwarf_Bool gf_suppress_check_extensions_tables;
179 Dwarf_Bool gf_check_duplicated_attributes;
180 Dwarf_Bool gf_check_functions;
181
182 /* lots of checks make no sense on a dwp debugfission object. */
183 Dwarf_Bool gf_suppress_checking_on_dwp;
184
185 /* suppress_nested_name_search is a band-aid.
186 A workaround. A real fix for N**2 behavior is needed. */
187 Dwarf_Bool gf_suppress_nested_name_search;
188 Dwarf_Bool gf_uri_options_translation;
189 Dwarf_Bool gf_do_print_uri_in_input;
190
191 /* Print global (unique) error messages */
192 Dwarf_Bool gf_print_unique_errors;
193 Dwarf_Bool gf_found_error_message;
194
195 Dwarf_Bool gf_check_names;
196
197 /* During '-k' mode, display errors */
198 Dwarf_Bool gf_check_verbose_mode;
199
200 Dwarf_Bool gf_check_frames;
201 Dwarf_Bool gf_check_frames_extended; /* Extensive frames check */
202 Dwarf_Bool gf_check_locations; /* Location list check */
203
204 Dwarf_Bool gf_print_usage_tag_attr; /* Print usage */
205
206 Dwarf_Bool gf_check_all_compilers;
207 Dwarf_Bool gf_check_snc_compiler; /* Check SNC compiler */
208 Dwarf_Bool gf_check_gcc_compiler;
209 Dwarf_Bool gf_print_summary_all;
210 Dwarf_Bool gf_file_use_no_libelf;
211
212 /* The check and print flags here make it easy to
213 allow check-only or print-only. We no longer support
214 check-and-print in a single run. */
215 Dwarf_Bool gf_do_check_dwarf;
216 Dwarf_Bool gf_do_print_dwarf;
217 Dwarf_Bool gf_check_show_results; /* Display checks results. */
218 Dwarf_Bool gf_record_dwarf_error; /* A test has failed, this
219 is normally set FALSE shortly after being set TRUE, it is
220 a short-range hint we should print something we might not
221 otherwise print (under the circumstances). */
222
223 Dwarf_Bool gf_check_debug_names;
224 Dwarf_Bool gf_no_sanitize_strings;
225
226 /* Display parent/children when in wide format? */
227 Dwarf_Bool gf_display_parent_tree;
228 Dwarf_Bool gf_display_children_tree;
229 int gf_stop_indent_level;
230
231 /* ====Searching for function name (printing frame data). */
232
233 /* split dwarf lookup by address or die.
234 if non-zero then .debug_addr is needed but missing.
235 Tells dwarfdump to only search by address
236 locally. */
237 char gf_debug_addr_missing;
238
239 /* Other error in lookup by address or by_die */
240 int gf_error_code_search_by_address;
241
242 /* Avoid some unneccesary work lookup by address. */
243 char gf_all_cus_seen_search_by_address;
244
245 /* Die indents >= this prefix an indent count instead
246 of actual spaces. */
247 int gf_max_space_indent;
248
249 /* ====End searching for function name. */
250
251 /* Print search results in wide format? */
252 Dwarf_Bool gf_search_wide_format;
253
254 /* -S option: strings for 'any' and 'match' */
255 Dwarf_Bool gf_search_is_on;
256
257 Dwarf_Bool gf_search_print_results;
258 Dwarf_Bool gf_cu_name_flag;
259 Dwarf_Bool gf_show_global_offsets;
260 Dwarf_Bool gf_display_offsets;
261 Dwarf_Bool gf_print_str_offsets;
262 Dwarf_Bool gf_machine_arch_flag;
263 Dwarf_Bool gf_expr_ops_joined;
264 Dwarf_Bool gf_print_raw_rnglists;
265 Dwarf_Bool gf_print_raw_loclists;
266
267 unsigned long gf_count_major_errors;
268 unsigned long gf_count_macronotes;
269
270 char ** gf_global_debuglink_paths;
271 unsigned gf_global_debuglink_count;
272 Dwarf_Bool gf_show_args_flag;
273
274 /* Base address has a special meaning in DWARF4,5
275 relative to address ranges. */
276 Dwarf_Bool seen_PU; /* Detected a PU */
277 Dwarf_Bool seen_CU; /* Detected a CU */
278 Dwarf_Bool need_CU_name; /* Need CU name */
279 Dwarf_Bool need_CU_base_address; /* Need CU Base address */
280 Dwarf_Bool need_CU_high_address; /* Need CU High address */
281 Dwarf_Bool need_PU_valid_code; /* Need PU valid code */
282 Dwarf_Bool in_valid_code; /* set/reset in subprogram
283 and compile-unit DIES.*/
284
285 Dwarf_Bool seen_PU_base_address; /* Detected a Base address
286 for PU */
287 Dwarf_Bool seen_PU_high_address; /* Detected a High address
288 for PU */
289 Dwarf_Addr PU_base_address; /* PU Base address */
290 Dwarf_Addr PU_high_address; /* PU High address */
291
292 Dwarf_Off DIE_offset; /* DIE offset in compile unit */
293 Dwarf_Off DIE_section_offset; /* DIE offset in .debug_info */
294
295 /* These globals enable better error reporting. */
296 Dwarf_Off DIE_CU_offset; /* CU DIE offset in compile unit */
297
298 /* CU DIE offset in .debug_info */
299 Dwarf_Off DIE_CU_overall_offset;
300
301 int current_section_id; /* Section being process */
302
303 /* Base Address is needed for range lists and
304 must come from a CU.
305 Low address is for information and can come from a function
306 or something in the CU. */
307 Dwarf_Addr CU_base_address; /* CU Base address */
308 Dwarf_Addr CU_low_address; /* CU low address */
309 Dwarf_Addr CU_high_address; /* CU High address */
310
311 Dwarf_Off fde_offset_for_cu_low;
312 Dwarf_Off fde_offset_for_cu_high;
313
314 const char *program_name;
315 const char *program_fullname;
316
317 const char *search_any_text;
318 const char *search_match_text;
319 const char *search_regex_text;
320 int search_occurrences;
321
322 /* Start verbose at zero. verbose can
323 be incremented with -v but not decremented. */
324 int verbose;
325 int gf_show_dwarfdump_conf;/* Incremented with
326 --show-dwarfdump-conf, never decremented */
327 Dwarf_Bool dense;
328 Dwarf_Bool ellipsis;
329 Dwarf_Bool show_form_used;
330
331 /* break_after_n_units is mainly for testing.
332 It enables easy limiting of output size/running time
333 when one wants the output limited.
334 For example,
335 -H 2
336 limits the -i output to 2 compilation units and
337 the -f or -F output to 2 FDEs and 2 CIEs.
338 */
339 int break_after_n_units;
340
341 struct section_high_offsets_s *section_high_offsets_global;
342
343 /* pRangesInfo records the DW_AT_high_pc and DW_AT_low_pc
344 and is used to check that line range info falls inside
345 the known valid ranges. The data is per CU, and is
346 reset per CU in tag_specific_checks_setup(). */
347 Bucket_Group *pRangesInfo;
348
349 /* pLinkonceInfo records data about the link once sections.
350 If a line range is not valid in the current CU it might
351 be valid in a linkonce section, this data records the
352 linkonce sections. So it is filled in when an
353 object file is read and remains unchanged for an entire
354 object file. */
355 Bucket_Group *pLinkonceInfo;
356
357 /* pVisitedInfo records a recursive traversal of DIE attributes
358 DW_AT_specification DW_AT_abstract_origin DW_AT_type
359 that let DWARF refer (as in a general graph) to
360 arbitrary other DIEs.
361 These traversals use pVisitedInfo to
362 detect any compiler errors that introduce circular references.
363 Printing of the traversals is also done on request.
364 Entries are added and deleted as they are visited in
365 a depth-first traversal. */
366 Bucket_Group *pVisitedInfo;
367
368 /* Compilation Unit information for improved error messages.
369 If the strings are too short we just truncate so fixed length
370 here is fine. */
371 #define COMPILE_UNIT_NAME_LEN 512
372 char PU_name[COMPILE_UNIT_NAME_LEN]; /* PU Name */
373 char CU_name[COMPILE_UNIT_NAME_LEN]; /* CU Name */
374 char CU_producer[COMPILE_UNIT_NAME_LEN]; /* CU Producer Name */
375
376 /* Options to enable debug tracing. */
377 int nTrace[MAX_TRACE_LEVEL + 1];
378
379 /* Output filename */
380 const char *output_file;
381 int group_number;
382 unsigned gf_universalnumber; /* for Mach-O universal binaries*/
383
384 /* Global esb-buffers. */
385 struct esb_s *newprogname;
386 struct esb_s *cu_name;
387 struct esb_s *config_file_path;
388 struct esb_s *config_file_tiedpath;
389 struct dwconf_s *config_file_data;
390
391 /* Check errors. */
392 int check_error;
393 };
394
395 extern struct glflags_s glflags;
396
397 void init_global_flags(void);
398 void reset_global_flags(void);
399 void set_checks_off(void);
400 void reset_overall_CU_error_data(void);
401 Dwarf_Bool cu_data_is_set(void);
402
403 /* Shortcuts for additional trace options */
404 #define KIND_OPTIONS 0 /* Dump options and stop. */
405 #define KIND_RANGES_INFO 1 /* Dump RangesInfo Table. */
406 #define KIND_LINKONCE_INFO 2 /* Dump Linkonce Table. */
407 #define KIND_VISITED_INFO 3 /* Dump Visited Info. */
408
409 #define dump_options glflags.nTrace[KIND_OPTIONS]
410 #define dump_ranges_info glflags.nTrace[KIND_RANGES_INFO]
411 #define dump_linkonce_info glflags.nTrace[KIND_LINKONCE_INFO]
412 #define dump_visited_info glflags.nTrace[KIND_VISITED_INFO]
413
414 /* Section IDs. See also libdwarfp/pro_opaque.h DEBUG_INFO etc
415 as we arbitrarily use the same numbering here.
416 In pro_opaque the numbering matters.
417 Here it helps us record where we are at any instant.
418 It's not necessary they match but seems good to do.
419 Here we have some extra sections not related to
420 relocations so we just add those beginning with 22 */
421 #define DEBUG_INFO 0
422 #define DEBUG_LINE 1
423 #define DEBUG_ABBREV 2
424 #define DEBUG_FRAME 3
425 #define DEBUG_ARANGES 4
426 #define DEBUG_PUBNAMES 5
427 #define DEBUG_FUNCNAMES 6
428 #define DEBUG_TYPENAMES 7
429 #define DEBUG_VARNAMES 8
430 #define DEBUG_WEAKNAMES 9
431 #define DEBUG_MACINFO 10 /* DWARF 2,3,4 only */
432 #define DEBUG_LOC 11
433 #define DEBUG_RANGES 12
434 #define DEBUG_TYPES 13
435 #define DEBUG_PUBTYPES 14
436 #define DEBUG_NAMES 15 /* DWARF5. aka dnames */
437 #define DEBUG_STR 16
438 #define DEBUG_LINE_STR 17
439 #define DEBUG_MACRO 18 /* DWARF 5. */
440 #define DEBUG_LOCLISTS 19 /* DWARF 5. */
441 #define DEBUG_RNGLISTS 20 /* DWARF 5. */
442 #define DEBUG_SUP 21 /* DWARF 5. */
443
444 #define DEBUG_GDB_INDEX 22
445 #define DEBUG_FRAME_EH_GNU 23
446 #define DEBUG_GNU_PUBNAMES 24
447 #define DEBUG_GNU_PUBTYPES 25
448
449 /* Print the information only if unique errors
450 is set and it is first time */
451 #define PRINTING_UNIQUE (!glflags.gf_found_error_message)
452 #endif /* GLFLAGS_H */