Debian Codegraph @

src/bin/dwarfdump/dd_glflags.c

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 /* All the dwarfdump flags are gathered into a single
28 global struct as it has been hard to know how many there
29 were or what they were all for. */
30
31 #include <config.h>
32
33 #include <limits.h> /* INT_MAX */
34 #include <string.h> /* strcmp() strlen() */
35 #include <stdio.h> /* FILE decl for dd_esb.h */
36
37 #include "dwarf.h"
38 #include "libdwarf.h"
39 #include "dd_defined_types.h"
40 #include "dd_checkutil.h"
41 #include "dd_glflags.h"
42 #include "dd_globals.h"
43 #include "dd_esb.h" /* For flexible string buffer. */
44 #include "dd_dwconf.h"
45 #include "dd_safe_strcpy.h"
46
47 #ifdef TRIVIAL_NAMING /* for make rebuild */
48 struct glflags_s glflags;
49
50 #endif /*TRIVIAL_NAMING*/
51
52 static struct section_high_offsets_s _section_high_offsets_global;
53 static struct dwconf_s _config_file_data;
54
55 /* used in special_program_name() only */
56 static struct esb_s _newprogname;
57
58 static struct esb_s _cu_name;
59 static struct esb_s _config_file_path;
60 static struct esb_s _config_file_tiedpath;
61
62 void
63 init_global_flags(void)
64 {
65 glflags.gf_debug_names_flag = FALSE;
66 glflags.gf_info_flag = FALSE;
67 glflags.gf_use_old_dwarf_loclist = FALSE; /* This so both
68 dwarf_loclist_n() and dwarf_get_loclist_c()
69 and the dwarf_loclist_from_expr
70 variations can be
71 tested. Defaults to new
72 dwarf_get_loclist_c(). See -g option.
73 The original IRIX dwarf_loclist() no longer tested
74 as of October 2015. */
75
76 glflags.gf_line_flag_selection = s2l;
77 glflags.gf_line_flag = FALSE;
78
79 /* Setting this FALSE tells dwarfdump to use the old
80 line-table interfaces. using:
81 -x line5=no
82 The new interfaces allow for both two-level line tables
83 and access to line table headers in case
84 we have a DWARF5 skeleton line table (a line table
85 header with no lines).
86 */
87 glflags.gf_line_skeleton_flag = TRUE;
88 glflags.gf_line_print_pc = TRUE; /* Print <pc> addresses. */
89 glflags.gf_abbrev_flag = FALSE;
90 glflags.gf_frame_flag = FALSE; /* .debug_frame section. */
91 glflags.gf_eh_frame_flag = FALSE; /* GNU .eh_frame section. */
92 glflags.gf_pubnames_flag = FALSE;
93 glflags.gf_debug_addr_flag = FALSE;
94
95 /* DWARF2,3,4. Old macro section*/
96 glflags.gf_macinfo_flag = FALSE;
97
98 /* DWARF5(and DWARF4 extension) new macro section */
99 glflags.gf_macro_flag = FALSE;
100
101 glflags.gf_loc_flag = FALSE;
102 glflags.gf_aranges_flag = FALSE; /* .debug_aranges section. */
103 glflags.gf_ranges_flag = FALSE; /* .debug_ranges section. */
104 glflags.gf_string_flag = FALSE;
105 glflags.gf_reloc_flag = FALSE;
106 glflags.gf_static_func_flag = FALSE;
107 glflags.gf_static_var_flag = FALSE;
108 glflags.gf_types_flag = FALSE;
109 glflags.gf_weakname_flag = FALSE;
110 glflags.gf_show_args_flag = FALSE;
111
112 /* Control printing of Elf header. */
113 glflags.gf_header_flag = FALSE;
114
115 glflags.gf_gdbindex_flag = FALSE;
116 glflags.gf_print_utf8_flag = FALSE;
117
118 /* List of CUs per compiler */
119 glflags.gf_producer_children_flag = FALSE;
120
121 glflags.gf_check_abbrev_code = FALSE;
122 glflags.gf_check_pubname_attr = FALSE;
123 glflags.gf_check_reloc_offset = FALSE;
124 glflags.gf_check_tag_attr = FALSE;
125 glflags.gf_check_tag_tree = FALSE;
126 glflags.gf_check_type_offset = FALSE;
127 glflags.gf_check_decl_file = FALSE;
128 glflags.gf_check_macros = FALSE;
129 glflags.gf_check_lines = FALSE;
130 glflags.gf_check_fdes = FALSE;
131 glflags.gf_check_ranges = FALSE;
132 glflags.gf_check_aranges = FALSE;
133 glflags.gf_check_harmless = FALSE;
134 glflags.gf_check_abbreviations = FALSE;
135 glflags.gf_check_dwarf_constants = FALSE;
136 glflags.gf_check_di_gaps = FALSE;
137 glflags.gf_check_forward_decl = FALSE;
138 glflags.gf_check_self_references = FALSE;
139 glflags.gf_check_functions = FALSE;
140
141 /* Attributes encoding */
142 glflags.gf_check_attr_encoding = FALSE;
143
144 glflags.gf_generic_1200_regs = FALSE;
145 glflags.gf_suppress_check_extensions_tables = FALSE;
146 glflags.gf_check_duplicated_attributes = FALSE;
147 glflags.gf_no_sanitize_strings = FALSE;
148
149 /* lots of checks make no sense on a dwp debugfission object. */
150 glflags.gf_suppress_checking_on_dwp = FALSE;
151 glflags.gf_file_use_no_libelf = FALSE;
152
153 /* suppress_nested_name_search is a band-aid.
154 A workaround. A real fix for N**2 behavior is needed. */
155 glflags.gf_suppress_nested_name_search = FALSE;
156 glflags.gf_uri_options_translation = TRUE;
157 glflags.gf_do_print_uri_in_input = TRUE;
158
159 glflags.gf_machine_arch_flag = FALSE;
160
161 glflags.gf_print_unique_errors = FALSE;
162 glflags.gf_found_error_message = FALSE;
163
164 /* if TRUE, use old behavior of all expr ops joined on one line*/
165 glflags.gf_expr_ops_joined = FALSE;
166
167 glflags.gf_print_raw_rnglists = FALSE;
168 glflags.gf_check_names = FALSE;
169
170 /* During '-k' mode, display errors */
171 glflags.gf_check_verbose_mode = TRUE;
172
173 glflags.gf_check_frames = FALSE;
174
175 /* Extensive frames check */
176 glflags.gf_check_frames_extended = FALSE;
177
178 glflags.gf_check_locations = FALSE;
179 glflags.gf_print_usage_tag_attr = FALSE;
180 glflags.gf_check_all_compilers = TRUE;
181 glflags.gf_check_snc_compiler = FALSE;
182 glflags.gf_check_gcc_compiler = FALSE;
183 glflags.gf_print_summary_all = FALSE;
184
185 /* The check and print flags here make it easy to
186 allow check-only or print-only. We no longer support
187 check-and-print in a single run. */
188 glflags.gf_do_check_dwarf = FALSE;
189 glflags.gf_do_print_dwarf = FALSE;
190 glflags.gf_check_show_results = FALSE;
191 glflags.gf_record_dwarf_error = FALSE; /* A test has
192 failed, this
193 is normally set FALSE shortly after being set TRUE, it is
194 a short-range hint we should print something we might not
195 otherwise print (under the circumstances). */
196
197 glflags.gf_check_debug_names = FALSE;
198
199 /* Display parent/children when in wide format? */
200 glflags.gf_display_parent_tree = FALSE;
201 glflags.gf_display_children_tree = FALSE;
202 glflags.gf_stop_indent_level = 0;
203
204 /* 10 is sort of arbitrary, it tries to keep
205 the indentation sane ( a 500 level DIE tree
206 is just too much to represent with prefix
207 spaces).*/
208 glflags.gf_max_space_indent = 10;
209 /* Print search results in wide format? */
210 glflags.gf_search_wide_format = FALSE;
211 /* -S option: strings for 'any' and 'match' */
212 glflags.gf_search_is_on = FALSE;
213 glflags.gf_search_print_results = FALSE;
214 glflags.gf_cu_name_flag = FALSE;
215 glflags.gf_show_global_offsets = FALSE;
216 glflags.gf_display_offsets = TRUE;
217
218 /* Means we need to search by addr. Split Dwarf. */
219 glflags.gf_debug_addr_missing = 0;
220 glflags.gf_error_code_search_by_address = 0;
221 glflags.gf_all_cus_seen_search_by_address = 0;
222
223 /* Base address has a special meaning in
224 DWARF4 relative to address ranges. */
225 glflags.seen_PU = FALSE; /* Detected a PU */
226 glflags.seen_CU = FALSE; /* Detected a CU */
227 glflags.need_CU_name = TRUE; /* Need CU name */
228 glflags.need_CU_base_address = TRUE; /* Need CU Base address */
229 glflags.need_CU_high_address = TRUE; /* Need CU High address */
230 glflags.need_PU_valid_code = TRUE; /* Need PU valid code */
231
232 /* Involved with need_PU_valid_code (set
233 in dwarfdump.c), in_valid_code set when subprogram DIE
234 or CU DIE has lowpc and highpc. */
235 glflags.in_valid_code = FALSE;
236
237 /* Detected a Base address for PU */
238 glflags.seen_PU_base_address = FALSE;
239
240 /* Detected a High address for PU */
241 glflags.seen_PU_high_address = FALSE;
242
243 glflags.PU_base_address = 0; /* PU Base address */
244 glflags.PU_high_address = 0; /* PU High address */
245
246 glflags.DIE_offset = 0; /* DIE offset in compile unit */
247 glflags.DIE_section_offset = 0; /* DIE offset in .debug_info */
248
249 /* These globals enable better error reporting. */
250
251 /* CU DIE offset in compile unit */
252 glflags.DIE_CU_offset = 0;
253
254 /* CU DIE offset in .debug_info */
255 glflags.DIE_CU_overall_offset = 0;
256 glflags.current_section_id = 0; /* Section being process */
257
258 /* Base Address is needed for range lists and
259 must come from a CU.
260 Low address is for information and can come from a function
261 or something in the CU. */
262 glflags.CU_base_address = 0; /* CU Base address */
263 glflags.CU_low_address = 0; /* CU low address */
264 glflags.CU_high_address = 0; /* CU High address */
265
266 glflags.fde_offset_for_cu_low = DW_DLV_BADOFFSET;
267 glflags.fde_offset_for_cu_high = DW_DLV_BADOFFSET;
268
269 glflags.program_name = NULL;
270 glflags.program_fullname = NULL;
271
272 /* Able to generate report on search */
273 glflags.search_any_text = 0;
274 glflags.search_match_text = 0;
275 glflags.search_regex_text = 0;
276 glflags.search_occurrences = 0;
277
278 /* Start verbose at zero. verbose can
279 be incremented with -v but not decremented. */
280 glflags.verbose = 0;
281 glflags.gf_show_dwarfdump_conf = 0;
282
283 glflags.dense = FALSE;
284 glflags.ellipsis = FALSE;
285 glflags.show_form_used = FALSE;
286
287 /* break_after_n_units is mainly for testing.
288 It enables easy limiting of output size/running time
289 when one wants the output limited.
290 For example,
291 -H 2
292 limits the -i output to 2 compilation units and
293 the -f or -F output to 2 FDEs and 2 CIEs.
294 */
295 glflags.break_after_n_units = INT_MAX;
296
297 glflags.section_high_offsets_global =
298 &_section_high_offsets_global;
299
300 glflags.pRangesInfo = NULL;
301 glflags.pLinkonceInfo = NULL;
302 glflags.pVisitedInfo = NULL;
303
304 /* These names make diagnostic messages more complete, the
305 fixed length is safe, though ultra long names will get
306 truncated. */
307 glflags.PU_name[0] = 0;
308 glflags.CU_name[0] = 0;
309 glflags.CU_producer[0] = 0;
310
311 /* Options to enable debug tracing. */
312 {
313 int i = 0;
314 for ( ; i <= MAX_TRACE_LEVEL; ++i) {
315 glflags.nTrace[i] = 0;
316 }
317 }
318
319 /* Output filename */
320 glflags.output_file = 0;
321 glflags.group_number = 0;
322 glflags.gf_universalnumber = 0;/* for Mach-O universal binaries */
323
324 /* Global esb-buffers. */
325 glflags.newprogname = &_newprogname;
326 esb_constructor(glflags.newprogname);
327
328 glflags.cu_name = &_cu_name;
329 esb_constructor(glflags.cu_name);
330
331 glflags.config_file_path = &_config_file_path;
332 esb_constructor(glflags.config_file_path);
333
334 glflags.config_file_tiedpath = &_config_file_tiedpath;
335 esb_constructor(glflags.config_file_tiedpath);
336
337 glflags.config_file_data = &_config_file_data;
338
339 /* Check errors. */
340 glflags.check_error = 0;
341 }
342
343 void
344 reset_global_flags(void)
345 {
346 esb_destructor(glflags.newprogname);
347 esb_destructor(glflags.cu_name);
348 esb_destructor(glflags.config_file_path);
349 esb_destructor(glflags.config_file_tiedpath);
350 }
351
352 /* When we add a 'print' option after an option
353 requests one or more checks
354 we turn off all checking, putting it back to default
355 checking state. */
356 void
357 set_checks_off(void)
358 {
359 glflags.gf_check_abbrev_code = FALSE;
360 glflags.gf_check_pubname_attr = FALSE;
361 glflags.gf_check_reloc_offset = FALSE;
362 glflags.gf_check_tag_attr = FALSE;
363 glflags.gf_check_tag_tree = FALSE;
364 glflags.gf_check_type_offset = FALSE;
365 glflags.gf_check_decl_file = FALSE;
366 glflags.gf_check_lines = FALSE;
367 glflags.gf_check_fdes = FALSE;
368 glflags.gf_check_ranges = FALSE;
369 glflags.gf_check_aranges = FALSE;
370 glflags.gf_check_harmless = FALSE;
371 glflags.gf_check_abbreviations = FALSE;
372 glflags.gf_check_dwarf_constants = FALSE;
373 glflags.gf_check_di_gaps = FALSE;
374 glflags.gf_check_forward_decl = FALSE;
375 glflags.gf_check_self_references = FALSE;
376 glflags.gf_check_attr_encoding = FALSE;
377 glflags.gf_check_duplicated_attributes = FALSE;
378 glflags.gf_check_debug_names = FALSE;
379 }
380
381 /* Making this a named string makes it simpler to change
382 what the reset,or 'I do not know' value is for
383 CU name or producer name for PRINT_CU_INFO.
384 different string string is seen in dwarfdump.c
385 when getting producer name for the list of CUs
386 shown by -P --print-producers and
387 in 'Compilers detected' output. */
388 static const char * default_cu_producer = "<unknown>";
389 void
390 reset_overall_CU_error_data(void)
391 {
392 dd_safe_strcpy(glflags.CU_name,sizeof(glflags.CU_name),
393 default_cu_producer,strlen(default_cu_producer));
394 dd_safe_strcpy(glflags.CU_producer,sizeof(glflags.CU_producer),
395 default_cu_producer,strlen(default_cu_producer));
396 glflags.DIE_offset = 0;
397 glflags.DIE_section_offset = 0;
398 glflags.DIE_CU_offset = 0;
399 glflags.DIE_CU_overall_offset = 0;
400 glflags.CU_base_address = 0;
401 glflags.CU_high_address = 0;
402 glflags.CU_low_address = 0;
403 }
404
405 Dwarf_Bool
406 cu_data_is_set(void)
407 {
408 if (strcmp(glflags.CU_name,default_cu_producer) ||
409 strcmp(glflags.CU_producer,default_cu_producer)) {
410 return 1;
411 }
412 if (glflags.DIE_offset || glflags.DIE_section_offset) {
413 return 1;
414 }
415 if (glflags.CU_base_address || glflags.CU_low_address ||
416 glflags.CU_high_address) {
417 return 1;
418 }
419 return 0;
420 }