/src/binutils-gdb/binutils/fuzz_objdump.h
Line | Count | Source |
1 | | /* objdump.c -- dump information about an object file. |
2 | | Copyright (C) 1990-2026 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of GNU Binutils. |
5 | | |
6 | | This program is free software; you can redistribute it and/or modify |
7 | | it under the terms of the GNU General Public License as published by |
8 | | the Free Software Foundation; either version 3, or (at your option) |
9 | | any later version. |
10 | | |
11 | | This program is distributed in the hope that it will be useful, |
12 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | GNU General Public License for more details. |
15 | | |
16 | | You should have received a copy of the GNU General Public License |
17 | | along with this program; if not, write to the Free Software |
18 | | Foundation, 51 Franklin Street - Fifth Floor, Boston, |
19 | | MA 02110-1301, USA. */ |
20 | | |
21 | | |
22 | | /* Objdump overview. |
23 | | |
24 | | Objdump displays information about one or more object files, either on |
25 | | their own, or inside libraries. It is commonly used as a disassembler, |
26 | | but it can also display information about file headers, symbol tables, |
27 | | relocations, debugging directives and more. |
28 | | |
29 | | The flow of execution is as follows: |
30 | | |
31 | | 1. Command line arguments are checked for control switches and the |
32 | | information to be displayed is selected. |
33 | | |
34 | | 2. Any remaining arguments are assumed to be object files, and they are |
35 | | processed in order by display_bfd(). If the file is an archive each |
36 | | of its elements is processed in turn. |
37 | | |
38 | | 3. The file's target architecture and binary file format are determined |
39 | | by bfd_check_format(). If they are recognised, then dump_bfd() is |
40 | | called. |
41 | | |
42 | | 4. dump_bfd() in turn calls separate functions to display the requested |
43 | | item(s) of information(s). For example disassemble_data() is called if |
44 | | a disassembly has been requested. |
45 | | |
46 | | When disassembling the code loops through blocks of instructions bounded |
47 | | by symbols, calling disassemble_bytes() on each block. The actual |
48 | | disassembling is done by the libopcodes library, via a function pointer |
49 | | supplied by the disassembler() function. */ |
50 | | |
51 | | #include "sysdep.h" |
52 | | #include "bfd.h" |
53 | | #include "elf-bfd.h" |
54 | | #include "coff-bfd.h" |
55 | | #include "bucomm.h" |
56 | | #include "elfcomm.h" |
57 | | #include "demanguse.h" |
58 | | #include "dwarf.h" |
59 | | #include "ctf-api.h" |
60 | | #include "sframe-api.h" |
61 | | #include "getopt.h" |
62 | | #include "safe-ctype.h" |
63 | | #include "dis-asm.h" |
64 | | #include "libiberty.h" |
65 | | #include "demangle.h" |
66 | | #include "filenames.h" |
67 | | #include "debug.h" |
68 | | #include "budbg.h" |
69 | | #include "objdump.h" |
70 | | |
71 | | #ifdef HAVE_MMAP |
72 | | #include <sys/mman.h> |
73 | | #endif |
74 | | |
75 | | #ifdef HAVE_LIBDEBUGINFOD |
76 | | #include <elfutils/debuginfod.h> |
77 | | #endif |
78 | | |
79 | | /* Internal headers for the ELF .stab-dump code - sorry. */ |
80 | | #define BYTES_IN_WORD 32 |
81 | | #include "aout/aout64.h" |
82 | | |
83 | | /* Exit status. */ |
84 | | static int exit_status = 0; |
85 | | |
86 | | static char *default_target = NULL; /* Default at runtime. */ |
87 | | |
88 | | /* The following variables are set based on arguments passed on the |
89 | | command line. */ |
90 | | static int show_version = 0; /* Show the version number. */ |
91 | | static int dump_section_contents; /* -s */ |
92 | | static int dump_section_headers; /* -h */ |
93 | | static bool dump_file_header; /* -f */ |
94 | | static int dump_symtab; /* -t */ |
95 | | static int dump_dynamic_symtab; /* -T */ |
96 | | static int dump_reloc_info; /* -r */ |
97 | | static int dump_dynamic_reloc_info; /* -R */ |
98 | | static int dump_ar_hdrs; /* -a */ |
99 | | static int dump_private_headers; /* -p */ |
100 | | static char *dump_private_options; /* -P */ |
101 | | static int no_addresses; /* --no-addresses */ |
102 | | static int prefix_addresses; /* --prefix-addresses */ |
103 | | static int with_line_numbers; /* -l */ |
104 | | static bool with_source_code; /* -S */ |
105 | | static int show_raw_insn; /* --show-raw-insn */ |
106 | | static int dump_dwarf_section_info; /* --dwarf */ |
107 | | static int dump_stab_section_info; /* --stabs */ |
108 | | static int dump_ctf_section_info; /* --ctf */ |
109 | | static char *dump_ctf_section_name; |
110 | | static char *dump_ctf_parent_name; /* --ctf-parent */ |
111 | | static char *dump_ctf_parent_section_name; /* --ctf-parent-section */ |
112 | | static int dump_sframe_section_info; /* --sframe */ |
113 | | static char *dump_sframe_section_name; |
114 | | static int do_demangle; /* -C, --demangle */ |
115 | | static bool disassemble; /* -d */ |
116 | | static bool disassemble_all; /* -D */ |
117 | | static int disassemble_zeroes; /* --disassemble-zeroes */ |
118 | | static bool formats_info; /* -i */ |
119 | | int wide_output; /* -w */ |
120 | 0 | #define MAX_INSN_WIDTH 49 |
121 | | static unsigned long insn_width; /* --insn-width */ |
122 | | static bfd_vma start_address = (bfd_vma) -1; /* --start-address */ |
123 | | static bfd_vma stop_address = (bfd_vma) -1; /* --stop-address */ |
124 | | static int dump_debugging; /* --debugging */ |
125 | | static int dump_debugging_tags; /* --debugging-tags */ |
126 | | static int suppress_bfd_header; |
127 | | static int dump_special_syms = 0; /* --special-syms */ |
128 | | static bfd_vma adjust_section_vma = 0; /* --adjust-vma */ |
129 | | static int file_start_context = 0; /* --file-start-context */ |
130 | | static bool display_file_offsets; /* -F */ |
131 | | static const char *prefix; /* --prefix */ |
132 | | static int prefix_strip; /* --prefix-strip */ |
133 | | static size_t prefix_length; |
134 | | static bool unwind_inlines; /* --inlines. */ |
135 | | static const char * source_comment; /* --source_comment. */ |
136 | | static bool visualize_jumps = false; /* --visualize-jumps. */ |
137 | | static bool color_output = false; /* --visualize-jumps=color. */ |
138 | | static bool extended_color_output = false; /* --visualize-jumps=extended-color. */ |
139 | | static int process_links = false; /* --process-links. */ |
140 | | static int show_all_symbols; /* --show-all-symbols. */ |
141 | | static bool dump_global_vars; /* --map-global-vars. */ |
142 | | static bool decompressed_dumps = false; /* -Z, --decompress. */ |
143 | | |
144 | | static struct symbol_entry |
145 | | { |
146 | | const char *name; |
147 | | struct symbol_entry *next; |
148 | | } *disasm_sym_list; /* Disassembly start symbol(s). */ |
149 | | |
150 | | static enum color_selection |
151 | | { |
152 | | on_if_terminal_output, |
153 | | on, /* --disassembler-color=color. */ |
154 | | off, /* --disassembler-color=off. */ |
155 | | extended /* --disassembler-color=extended-color. */ |
156 | | } disassembler_color = |
157 | | #if DEFAULT_FOR_COLORED_DISASSEMBLY |
158 | | on_if_terminal_output; |
159 | | #else |
160 | | off; |
161 | | #endif |
162 | | |
163 | | static int demangle_flags = DMGL_ANSI | DMGL_PARAMS; |
164 | | |
165 | | /* This is reset to false each time we enter the disassembler, and set true |
166 | | when the disassembler emits something in the dis_style_comment_start |
167 | | style. Once this is true, all further output on that line is done in |
168 | | the comment style. This only has an effect when disassembler coloring |
169 | | is turned on. */ |
170 | | static bool disassembler_in_comment = false; |
171 | | |
172 | | /* A structure to record the sections mentioned in -j switches. */ |
173 | | struct only |
174 | | { |
175 | | const char *name; /* The name of the section. */ |
176 | | bool seen; /* A flag to indicate that the section has been found in one or more input files. */ |
177 | | struct only *next; /* Pointer to the next structure in the list. */ |
178 | | }; |
179 | | /* Pointer to an array of 'only' structures. |
180 | | This pointer is NULL if the -j switch has not been used. */ |
181 | | static struct only * only_list = NULL; |
182 | | |
183 | | /* Variables for handling include file path table. */ |
184 | | static const char **include_paths; |
185 | | static int include_path_count; |
186 | | |
187 | | /* Extra info to pass to the section disassembler and address printing |
188 | | function. */ |
189 | | struct objdump_disasm_info |
190 | | { |
191 | | bfd *abfd; |
192 | | bool require_sec; |
193 | | disassembler_ftype disassemble_fn; |
194 | | arelent *reloc; |
195 | | struct symbol_entry *symbol_list; |
196 | | }; |
197 | | |
198 | | /* Architecture to disassemble for, or default if NULL. */ |
199 | | static char *machine = NULL; |
200 | | |
201 | | /* Target specific options to the disassembler. */ |
202 | | static char *disassembler_options = NULL; |
203 | | |
204 | | /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */ |
205 | | static enum bfd_endian endian = BFD_ENDIAN_UNKNOWN; |
206 | | |
207 | | /* The symbol table. */ |
208 | | static asymbol **syms; |
209 | | |
210 | | /* Number of symbols in `syms'. */ |
211 | | static long symcount = 0; |
212 | | |
213 | | /* The sorted symbol table. */ |
214 | | static asymbol **sorted_syms; |
215 | | |
216 | | /* Number of symbols in `sorted_syms'. */ |
217 | | static long sorted_symcount = 0; |
218 | | |
219 | | /* The dynamic symbol table. */ |
220 | | static asymbol **dynsyms; |
221 | | |
222 | | /* The synthetic symbol table. */ |
223 | | static asymbol *synthsyms; |
224 | | static long synthcount = 0; |
225 | | |
226 | | /* Number of symbols in `dynsyms'. */ |
227 | | static long dynsymcount = 0; |
228 | | |
229 | | static bfd_byte *stabs; |
230 | | static bfd_size_type stab_size; |
231 | | |
232 | | static bfd_byte *strtab; |
233 | | static bfd_size_type stabstr_size; |
234 | | |
235 | | /* Handlers for -P/--private. */ |
236 | | static const struct objdump_private_desc * const objdump_private_vectors[] = |
237 | | { |
238 | | OBJDUMP_PRIVATE_VECTORS |
239 | | NULL |
240 | | }; |
241 | | |
242 | | /* The list of detected jumps inside a function. */ |
243 | | static struct jump_info *detected_jumps = NULL; |
244 | | |
245 | | typedef enum unicode_display_type |
246 | | { |
247 | | unicode_default = 0, |
248 | | unicode_locale, |
249 | | unicode_escape, |
250 | | unicode_hex, |
251 | | unicode_highlight, |
252 | | unicode_invalid |
253 | | } unicode_display_type; |
254 | | |
255 | | static unicode_display_type unicode_display = unicode_default; |
256 | | |
257 | | static void usage (FILE *, int) ATTRIBUTE_NORETURN; |
258 | | static void |
259 | | usage (FILE *stream, int status) |
260 | 0 | { |
261 | 0 | fprintf (stream, _("Usage: %s <option(s)> <file(s)>\n"), program_name); |
262 | 0 | fprintf (stream, _(" Display information from object <file(s)>.\n")); |
263 | 0 | fprintf (stream, _(" At least one of the following switches must be given:\n")); |
264 | 0 | fprintf (stream, _("\ |
265 | 0 | -a, --archive-headers Display archive header information\n")); |
266 | 0 | fprintf (stream, _("\ |
267 | 0 | -f, --file-headers Display the contents of the overall file header\n")); |
268 | 0 | fprintf (stream, _("\ |
269 | 0 | -p, --private-headers Display object format specific file header contents\n")); |
270 | 0 | fprintf (stream, _("\ |
271 | 0 | -P, --private=OPT,OPT... Display object format specific contents\n")); |
272 | 0 | fprintf (stream, _("\ |
273 | 0 | -h, --[section-]headers Display the contents of the section headers\n")); |
274 | 0 | fprintf (stream, _("\ |
275 | 0 | -x, --all-headers Display the contents of all headers\n")); |
276 | 0 | fprintf (stream, _("\ |
277 | 0 | -d, --disassemble Display assembler contents of executable sections\n")); |
278 | 0 | fprintf (stream, _("\ |
279 | 0 | -D, --disassemble-all Display assembler contents of all sections\n")); |
280 | 0 | fprintf (stream, _("\ |
281 | 0 | --disassemble=<sym> Display assembler contents from <sym>\n")); |
282 | 0 | fprintf (stream, _("\ |
283 | 0 | -S, --source Intermix source code with disassembly\n")); |
284 | 0 | fprintf (stream, _("\ |
285 | 0 | --source-comment[=<txt>] Prefix lines of source code with <txt>\n")); |
286 | 0 | fprintf (stream, _("\ |
287 | 0 | -s, --full-contents Display the full contents of all sections requested\n")); |
288 | 0 | fprintf (stream, _("\ |
289 | 0 | -Z, --decompress Decompress section(s) before displaying their contents\n")); |
290 | 0 | fprintf (stream, _("\ |
291 | 0 | -g, --debugging Display debug information in object file\n")); |
292 | 0 | fprintf (stream, _("\ |
293 | 0 | -e, --debugging-tags Display debug information using ctags style\n")); |
294 | 0 | fprintf (stream, _("\ |
295 | 0 | -G, --stabs Display (in raw form) any STABS info in the file\n")); |
296 | 0 | fprintf (stream, _("\ |
297 | 0 | -W, --dwarf[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\ |
298 | 0 | f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\ |
299 | 0 | m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\ |
300 | 0 | s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\ |
301 | 0 | U/=trace_info]\n\ |
302 | 0 | Display the contents of DWARF debug sections\n")); |
303 | 0 | fprintf (stream, _("\ |
304 | 0 | -Wk,--dwarf=links Display the contents of sections that link to\n\ |
305 | 0 | separate debuginfo files\n")); |
306 | 0 | #if DEFAULT_FOR_FOLLOW_LINKS |
307 | 0 | fprintf (stream, _("\ |
308 | 0 | -WK,--dwarf=follow-links\n\ |
309 | 0 | Follow links to separate debug info files (default)\n")); |
310 | 0 | fprintf (stream, _("\ |
311 | 0 | -WN,--dwarf=no-follow-links\n\ |
312 | 0 | Do not follow links to separate debug info files\n")); |
313 | | #else |
314 | | fprintf (stream, _("\ |
315 | | -WK,--dwarf=follow-links\n\ |
316 | | Follow links to separate debug info files\n")); |
317 | | fprintf (stream, _("\ |
318 | | -WN,--dwarf=no-follow-links\n\ |
319 | | Do not follow links to separate debug info files\n\ |
320 | | (default)\n")); |
321 | | #endif |
322 | | #if HAVE_LIBDEBUGINFOD |
323 | | fprintf (stream, _("\ |
324 | | -WD --dwarf=use-debuginfod\n\ |
325 | | When following links, also query debuginfod servers (default)\n")); |
326 | | fprintf (stream, _("\ |
327 | | -WE --dwarf=do-not-use-debuginfod\n\ |
328 | | When following links, do not query debuginfod servers\n")); |
329 | | #endif |
330 | 0 | fprintf (stream, _("\ |
331 | 0 | --debug-dir=<DIR> Search DIR for debug info files\n")); |
332 | 0 | fprintf (stream, _("\ |
333 | 0 | --map-global-vars Display memory mapping of global variables\n")); |
334 | 0 | fprintf (stream, _("\ |
335 | 0 | -L, --process-links Display the contents of non-debug sections in\n\ |
336 | 0 | separate debuginfo files. (Implies -WK)\n")); |
337 | 0 | #ifdef ENABLE_LIBCTF |
338 | 0 | fprintf (stream, _("\ |
339 | 0 | --ctf[=SECTION] Display CTF info from SECTION, (default `.ctf')\n")); |
340 | 0 | #endif |
341 | 0 | fprintf (stream, _("\ |
342 | 0 | --sframe[=SECTION] Display SFrame info from SECTION, (default '.sframe')\n")); |
343 | 0 | fprintf (stream, _("\ |
344 | 0 | -t, --syms Display the contents of the symbol table(s)\n")); |
345 | 0 | fprintf (stream, _("\ |
346 | 0 | -T, --dynamic-syms Display the contents of the dynamic symbol table\n")); |
347 | 0 | fprintf (stream, _("\ |
348 | 0 | -r, --reloc Display the relocation entries in the file\n")); |
349 | 0 | fprintf (stream, _("\ |
350 | 0 | -R, --dynamic-reloc Display the dynamic relocation entries in the file\n")); |
351 | 0 | fprintf (stream, _("\ |
352 | 0 | @<file> Read options from <file>\n")); |
353 | 0 | fprintf (stream, _("\ |
354 | 0 | -v, --version Display this program's version number\n")); |
355 | 0 | fprintf (stream, _("\ |
356 | 0 | -i, --info List object formats and architectures supported\n")); |
357 | 0 | fprintf (stream, _("\ |
358 | 0 | -H, --help Display this information\n")); |
359 | |
|
360 | 0 | if (status != 2) |
361 | 0 | { |
362 | 0 | const struct objdump_private_desc * const *desc; |
363 | |
|
364 | 0 | fprintf (stream, _("\n The following switches are optional:\n")); |
365 | 0 | fprintf (stream, _("\ |
366 | 0 | -b, --target=BFDNAME Specify the target object format as BFDNAME\n")); |
367 | 0 | fprintf (stream, _("\ |
368 | 0 | -m, --architecture=MACHINE Specify the target architecture as MACHINE\n")); |
369 | 0 | fprintf (stream, _("\ |
370 | 0 | -j, --section=NAME Only display information for section NAME\n")); |
371 | 0 | fprintf (stream, _("\ |
372 | 0 | -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n")); |
373 | 0 | fprintf (stream, _("\ |
374 | 0 | -EB --endian=big Assume big endian format when disassembling\n")); |
375 | 0 | fprintf (stream, _("\ |
376 | 0 | -EL --endian=little Assume little endian format when disassembling\n")); |
377 | 0 | fprintf (stream, _("\ |
378 | 0 | --file-start-context Include context from start of file (with -S)\n")); |
379 | 0 | fprintf (stream, _("\ |
380 | 0 | -I, --include=DIR Add DIR to search list for source files\n")); |
381 | 0 | fprintf (stream, _("\ |
382 | 0 | -l, --line-numbers Include line numbers and filenames in output\n")); |
383 | 0 | fprintf (stream, _("\ |
384 | 0 | -F, --file-offsets Include file offsets when displaying information\n")); |
385 | 0 | fprintf (stream, _("\ |
386 | 0 | -C, --demangle[=STYLE] Decode mangled/processed symbol names\n")); |
387 | 0 | display_demangler_styles (stream, _("\ |
388 | 0 | STYLE can be ")); |
389 | 0 | fprintf (stream, _("\ |
390 | 0 | --recurse-limit Enable a limit on recursion whilst demangling\n\ |
391 | 0 | (default)\n")); |
392 | 0 | fprintf (stream, _("\ |
393 | 0 | --no-recurse-limit Disable a limit on recursion whilst demangling\n")); |
394 | 0 | fprintf (stream, _("\ |
395 | 0 | -w, --wide Format output for more than 80 columns\n")); |
396 | 0 | fprintf (stream, _("\ |
397 | 0 | -U[d|l|i|x|e|h] Controls the display of UTF-8 unicode characters\n\ |
398 | 0 | --unicode=[default|locale|invalid|hex|escape|highlight]\n")); |
399 | 0 | fprintf (stream, _("\ |
400 | 0 | -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n")); |
401 | 0 | fprintf (stream, _("\ |
402 | 0 | --start-address=ADDR Only process data whose address is >= ADDR\n")); |
403 | 0 | fprintf (stream, _("\ |
404 | 0 | --stop-address=ADDR Only process data whose address is < ADDR\n")); |
405 | 0 | fprintf (stream, _("\ |
406 | 0 | --no-addresses Do not print address alongside disassembly\n")); |
407 | 0 | fprintf (stream, _("\ |
408 | 0 | --prefix-addresses Print complete address alongside disassembly\n")); |
409 | 0 | fprintf (stream, _("\ |
410 | 0 | --[no-]show-raw-insn Display hex alongside symbolic disassembly\n")); |
411 | 0 | fprintf (stream, _("\ |
412 | 0 | --insn-width=WIDTH Display WIDTH bytes on a single line for -d\n")); |
413 | 0 | fprintf (stream, _("\ |
414 | 0 | --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n")); |
415 | 0 | fprintf (stream, _("\ |
416 | 0 | --show-all-symbols When disassembling, display all symbols at a given address\n")); |
417 | 0 | fprintf (stream, _("\ |
418 | 0 | --special-syms Include special symbols in symbol dumps\n")); |
419 | 0 | fprintf (stream, _("\ |
420 | 0 | --inlines Print all inlines for source line (with -l)\n")); |
421 | 0 | fprintf (stream, _("\ |
422 | 0 | --prefix=PREFIX Add PREFIX to absolute paths for -S\n")); |
423 | 0 | fprintf (stream, _("\ |
424 | 0 | --prefix-strip=LEVEL Strip initial directory names for -S\n")); |
425 | 0 | fprintf (stream, _("\ |
426 | 0 | --dwarf-depth=N Do not display DIEs at depth N or greater\n")); |
427 | 0 | fprintf (stream, _("\ |
428 | 0 | --dwarf-start=N Display DIEs starting at offset N\n")); |
429 | 0 | fprintf (stream, _("\ |
430 | 0 | --dwarf-check Make additional dwarf consistency checks.\n")); |
431 | 0 | #ifdef ENABLE_LIBCTF |
432 | 0 | fprintf (stream, _("\ |
433 | 0 | --ctf-parent=NAME Use CTF archive member NAME as the CTF parent\n")); |
434 | 0 | #endif |
435 | 0 | fprintf (stream, _("\ |
436 | 0 | --visualize-jumps Visualize jumps by drawing ASCII art lines\n")); |
437 | 0 | fprintf (stream, _("\ |
438 | 0 | --visualize-jumps=color Use colors in the ASCII art\n")); |
439 | 0 | fprintf (stream, _("\ |
440 | 0 | --visualize-jumps=extended-color\n\ |
441 | 0 | Use extended 8-bit color codes\n")); |
442 | 0 | fprintf (stream, _("\ |
443 | 0 | --visualize-jumps=off Disable jump visualization\n")); |
444 | | #if DEFAULT_FOR_COLORED_DISASSEMBLY |
445 | | fprintf (stream, _("\ |
446 | | --disassembler-color=off Disable disassembler color output.\n")); |
447 | | fprintf (stream, _("\ |
448 | | --disassembler-color=terminal Enable disassembler color output if displaying on a terminal. (default)\n")); |
449 | | #else |
450 | 0 | fprintf (stream, _("\ |
451 | 0 | --disassembler-color=off Disable disassembler color output. (default)\n")); |
452 | 0 | fprintf (stream, _("\ |
453 | 0 | --disassembler-color=terminal Enable disassembler color output if displaying on a terminal.\n")); |
454 | 0 | #endif |
455 | 0 | fprintf (stream, _("\ |
456 | 0 | --disassembler-color=on Enable disassembler color output.\n")); |
457 | 0 | fprintf (stream, _("\ |
458 | 0 | --disassembler-color=extended Use 8-bit colors in disassembler output.\n\n")); |
459 | |
|
460 | 0 | list_supported_targets (program_name, stream); |
461 | 0 | list_supported_architectures (program_name, stream); |
462 | |
|
463 | 0 | disassembler_usage (stream); |
464 | |
|
465 | 0 | if (objdump_private_vectors[0] != NULL) |
466 | 0 | { |
467 | 0 | fprintf (stream, |
468 | 0 | _("\nOptions supported for -P/--private switch:\n")); |
469 | 0 | for (desc = objdump_private_vectors; *desc != NULL; desc++) |
470 | 0 | (*desc)->help (stream); |
471 | 0 | } |
472 | 0 | } |
473 | 0 | if (REPORT_BUGS_TO[0] && status == 0) |
474 | 0 | fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO); |
475 | 0 | exit (status); |
476 | 0 | } Unexecuted instantiation: fuzz_objdump.c:usage Unexecuted instantiation: fuzz_dwarf.c:usage |
477 | | |
478 | | /* 150 isn't special; it's just an arbitrary non-ASCII char value. */ |
479 | | enum option_values |
480 | | { |
481 | | OPTION_ENDIAN=150, |
482 | | OPTION_START_ADDRESS, |
483 | | OPTION_STOP_ADDRESS, |
484 | | OPTION_DWARF, |
485 | | OPTION_DEBUG_DIR, |
486 | | OPTION_PREFIX, |
487 | | OPTION_PREFIX_STRIP, |
488 | | OPTION_INSN_WIDTH, |
489 | | OPTION_ADJUST_VMA, |
490 | | OPTION_DWARF_DEPTH, |
491 | | OPTION_DWARF_CHECK, |
492 | | OPTION_DWARF_START, |
493 | | OPTION_RECURSE_LIMIT, |
494 | | OPTION_NO_RECURSE_LIMIT, |
495 | | OPTION_INLINES, |
496 | | OPTION_SOURCE_COMMENT, |
497 | | #ifdef ENABLE_LIBCTF |
498 | | OPTION_CTF, |
499 | | OPTION_CTF_PARENT, |
500 | | OPTION_CTF_PARENT_SECTION, |
501 | | #endif |
502 | | OPTION_SFRAME, |
503 | | OPTION_VISUALIZE_JUMPS, |
504 | | OPTION_DISASSEMBLER_COLOR, |
505 | | OPTION_MAP_GLOBAL_VARS |
506 | | }; |
507 | | |
508 | | static struct option long_options[]= |
509 | | { |
510 | | {"adjust-vma", required_argument, NULL, OPTION_ADJUST_VMA}, |
511 | | {"all-headers", no_argument, NULL, 'x'}, |
512 | | {"architecture", required_argument, NULL, 'm'}, |
513 | | {"archive-headers", no_argument, NULL, 'a'}, |
514 | | #ifdef ENABLE_LIBCTF |
515 | | {"ctf", optional_argument, NULL, OPTION_CTF}, |
516 | | {"ctf-parent", required_argument, NULL, OPTION_CTF_PARENT}, |
517 | | {"ctf-parent-section", required_argument, NULL, OPTION_CTF_PARENT_SECTION}, |
518 | | #endif |
519 | | {"debug-dir", required_argument, NULL, OPTION_DEBUG_DIR}, |
520 | | {"debugging", no_argument, NULL, 'g'}, |
521 | | {"debugging-tags", no_argument, NULL, 'e'}, |
522 | | {"decompress", no_argument, NULL, 'Z'}, |
523 | | {"demangle", optional_argument, NULL, 'C'}, |
524 | | {"disassemble", optional_argument, NULL, 'd'}, |
525 | | {"disassemble-all", no_argument, NULL, 'D'}, |
526 | | {"disassemble-zeroes", no_argument, NULL, 'z'}, |
527 | | {"disassembler-options", required_argument, NULL, 'M'}, |
528 | | {"dwarf", optional_argument, NULL, OPTION_DWARF}, |
529 | | {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK}, |
530 | | {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH}, |
531 | | {"dwarf-start", required_argument, 0, OPTION_DWARF_START}, |
532 | | {"dynamic-reloc", no_argument, NULL, 'R'}, |
533 | | {"dynamic-syms", no_argument, NULL, 'T'}, |
534 | | {"endian", required_argument, NULL, OPTION_ENDIAN}, |
535 | | {"file-headers", no_argument, NULL, 'f'}, |
536 | | {"file-offsets", no_argument, NULL, 'F'}, |
537 | | {"file-start-context", no_argument, &file_start_context, 1}, |
538 | | {"full-contents", no_argument, NULL, 's'}, |
539 | | {"headers", no_argument, NULL, 'h'}, |
540 | | {"help", no_argument, NULL, 'H'}, |
541 | | {"include", required_argument, NULL, 'I'}, |
542 | | {"info", no_argument, NULL, 'i'}, |
543 | | {"inlines", no_argument, 0, OPTION_INLINES}, |
544 | | {"insn-width", required_argument, NULL, OPTION_INSN_WIDTH}, |
545 | | {"line-numbers", no_argument, NULL, 'l'}, |
546 | | {"no-addresses", no_argument, &no_addresses, 1}, |
547 | | {"no-recurse-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, |
548 | | {"no-recursion-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, |
549 | | {"no-show-raw-insn", no_argument, &show_raw_insn, -1}, |
550 | | {"prefix", required_argument, NULL, OPTION_PREFIX}, |
551 | | {"prefix-addresses", no_argument, &prefix_addresses, 1}, |
552 | | {"prefix-strip", required_argument, NULL, OPTION_PREFIX_STRIP}, |
553 | | {"private", required_argument, NULL, 'P'}, |
554 | | {"private-headers", no_argument, NULL, 'p'}, |
555 | | {"process-links", no_argument, &process_links, true}, |
556 | | {"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT}, |
557 | | {"recursion-limit", no_argument, NULL, OPTION_RECURSE_LIMIT}, |
558 | | {"reloc", no_argument, NULL, 'r'}, |
559 | | {"section", required_argument, NULL, 'j'}, |
560 | | {"section-headers", no_argument, NULL, 'h'}, |
561 | | {"sframe", optional_argument, NULL, OPTION_SFRAME}, |
562 | | {"show-all-symbols", no_argument, &show_all_symbols, 1}, |
563 | | {"show-raw-insn", no_argument, &show_raw_insn, 1}, |
564 | | {"source", no_argument, NULL, 'S'}, |
565 | | {"source-comment", optional_argument, NULL, OPTION_SOURCE_COMMENT}, |
566 | | {"special-syms", no_argument, &dump_special_syms, 1}, |
567 | | {"stabs", no_argument, NULL, 'G'}, |
568 | | {"start-address", required_argument, NULL, OPTION_START_ADDRESS}, |
569 | | {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS}, |
570 | | {"syms", no_argument, NULL, 't'}, |
571 | | {"target", required_argument, NULL, 'b'}, |
572 | | {"unicode", required_argument, NULL, 'U'}, |
573 | | {"version", no_argument, NULL, 'V'}, |
574 | | {"visualize-jumps", optional_argument, 0, OPTION_VISUALIZE_JUMPS}, |
575 | | {"wide", no_argument, NULL, 'w'}, |
576 | | {"disassembler-color", required_argument, NULL, OPTION_DISASSEMBLER_COLOR}, |
577 | | {"map-global-vars", no_argument, NULL, OPTION_MAP_GLOBAL_VARS}, |
578 | | {NULL, no_argument, NULL, 0} |
579 | | }; |
580 | | |
581 | | static void |
582 | | my_bfd_nonfatal (const char *msg) |
583 | 263k | { |
584 | 263k | bfd_nonfatal (msg); |
585 | 263k | exit_status = 1; |
586 | 263k | } fuzz_objdump.c:my_bfd_nonfatal Line | Count | Source | 583 | 263k | { | 584 | 263k | bfd_nonfatal (msg); | 585 | 263k | exit_status = 1; | 586 | 263k | } |
Unexecuted instantiation: fuzz_dwarf.c:my_bfd_nonfatal |
587 | | |
588 | | /* Convert a potential UTF-8 encoded sequence in IN into characters in OUT. |
589 | | The conversion format is controlled by the unicode_display variable. |
590 | | Returns the number of characters added to OUT. |
591 | | Returns the number of bytes consumed from IN in CONSUMED. |
592 | | Always consumes at least one byte and displays at least one character. */ |
593 | | |
594 | | static unsigned int |
595 | | display_utf8 (const unsigned char * in, char * out, unsigned int * consumed) |
596 | 0 | { |
597 | 0 | char * orig_out = out; |
598 | 0 | unsigned int nchars = 0; |
599 | 0 | unsigned int j; |
600 | |
|
601 | 0 | if (unicode_display == unicode_default) |
602 | 0 | goto invalid; |
603 | | |
604 | 0 | if (in[0] < 0xc0) |
605 | 0 | goto invalid; |
606 | | |
607 | 0 | if ((in[1] & 0xc0) != 0x80) |
608 | 0 | goto invalid; |
609 | | |
610 | 0 | if ((in[0] & 0x20) == 0) |
611 | 0 | { |
612 | 0 | nchars = 2; |
613 | 0 | goto valid; |
614 | 0 | } |
615 | | |
616 | 0 | if ((in[2] & 0xc0) != 0x80) |
617 | 0 | goto invalid; |
618 | | |
619 | 0 | if ((in[0] & 0x10) == 0) |
620 | 0 | { |
621 | 0 | nchars = 3; |
622 | 0 | goto valid; |
623 | 0 | } |
624 | | |
625 | 0 | if ((in[3] & 0xc0) != 0x80) |
626 | 0 | goto invalid; |
627 | | |
628 | 0 | nchars = 4; |
629 | |
|
630 | 0 | valid: |
631 | 0 | switch (unicode_display) |
632 | 0 | { |
633 | 0 | case unicode_locale: |
634 | | /* Copy the bytes into the output buffer as is. */ |
635 | 0 | memcpy (out, in, nchars); |
636 | 0 | out += nchars; |
637 | 0 | break; |
638 | | |
639 | 0 | case unicode_invalid: |
640 | 0 | case unicode_hex: |
641 | 0 | *out++ = unicode_display == unicode_hex ? '<' : '{'; |
642 | 0 | *out++ = '0'; |
643 | 0 | *out++ = 'x'; |
644 | 0 | for (j = 0; j < nchars; j++) |
645 | 0 | out += sprintf (out, "%02x", in [j]); |
646 | 0 | *out++ = unicode_display == unicode_hex ? '>' : '}'; |
647 | 0 | break; |
648 | | |
649 | 0 | case unicode_highlight: |
650 | 0 | if (isatty (1)) |
651 | 0 | out += sprintf (out, "\x1B[31;47m"); /* Red. */ |
652 | | /* Fall through. */ |
653 | 0 | case unicode_escape: |
654 | 0 | switch (nchars) |
655 | 0 | { |
656 | 0 | case 2: |
657 | 0 | out += sprintf (out, "\\u%02x%02x", |
658 | 0 | ((in[0] & 0x1c) >> 2), |
659 | 0 | ((in[0] & 0x03) << 6) | (in[1] & 0x3f)); |
660 | 0 | break; |
661 | | |
662 | 0 | case 3: |
663 | 0 | out += sprintf (out, "\\u%02x%02x", |
664 | 0 | ((in[0] & 0x0f) << 4) | ((in[1] & 0x3c) >> 2), |
665 | 0 | ((in[1] & 0x03) << 6) | ((in[2] & 0x3f))); |
666 | 0 | break; |
667 | | |
668 | 0 | case 4: |
669 | 0 | out += sprintf (out, "\\u%02x%02x%02x", |
670 | 0 | ((in[0] & 0x07) << 2) | ((in[1] & 0x30) >> 4), |
671 | 0 | ((in[1] & 0x0f) << 4) | ((in[2] & 0x3c) >> 2), |
672 | 0 | ((in[2] & 0x03) << 6) | ((in[3] & 0x3f))); |
673 | 0 | break; |
674 | 0 | default: |
675 | | /* URG. */ |
676 | 0 | break; |
677 | 0 | } |
678 | | |
679 | 0 | if (unicode_display == unicode_highlight && isatty (1)) |
680 | 0 | out += sprintf (out, "\x1B[0m"); /* Default colour. */ |
681 | 0 | break; |
682 | | |
683 | 0 | default: |
684 | | /* URG */ |
685 | 0 | break; |
686 | 0 | } |
687 | | |
688 | 0 | * consumed = nchars; |
689 | 0 | return out - orig_out; |
690 | | |
691 | 0 | invalid: |
692 | | /* Not a valid UTF-8 sequence. */ |
693 | 0 | *out = *in; |
694 | 0 | * consumed = 1; |
695 | 0 | return 1; |
696 | 0 | } Unexecuted instantiation: fuzz_objdump.c:display_utf8 Unexecuted instantiation: fuzz_dwarf.c:display_utf8 |
697 | | |
698 | | /* Returns a version of IN with any control characters |
699 | | replaced by escape sequences. Uses a static buffer |
700 | | if necessary. |
701 | | |
702 | | If unicode display is enabled, then also handles the |
703 | | conversion of unicode characters. */ |
704 | | |
705 | | static const char * |
706 | | sanitize_string (const char * in) |
707 | 1.80M | { |
708 | 1.80M | static char * buffer = NULL; |
709 | 1.80M | static size_t buffer_len = 0; |
710 | 1.80M | const char * original = in; |
711 | 1.80M | char * out; |
712 | | |
713 | | /* Paranoia. */ |
714 | 1.80M | if (in == NULL) |
715 | 0 | return ""; |
716 | | |
717 | | /* See if any conversion is necessary. In the majority |
718 | | of cases it will not be needed. */ |
719 | 1.80M | do |
720 | 16.2M | { |
721 | 16.2M | unsigned char c = *in++; |
722 | | |
723 | 16.2M | if (c == 0) |
724 | 1.44M | return original; |
725 | | |
726 | 14.8M | if (ISCNTRL (c)) |
727 | 365k | break; |
728 | | |
729 | 14.4M | if (unicode_display != unicode_default && c >= 0xc0) |
730 | 0 | break; |
731 | 14.4M | } |
732 | 14.4M | while (1); |
733 | | |
734 | | /* Copy the input, translating as needed. */ |
735 | 365k | in = original; |
736 | | /* For 2 char unicode, max out is 12 (colour escapes) + 6, ie. 9 per in |
737 | | For hex, max out is 8 for 2 char unicode, ie. 4 per in. |
738 | | 3 and 4 char unicode produce less output for input. */ |
739 | 365k | size_t max_needed = strlen (in) * 9 + 1; |
740 | 365k | if (buffer_len < max_needed) |
741 | 19 | { |
742 | 19 | buffer_len = max_needed; |
743 | 19 | free (buffer); |
744 | 19 | buffer = xmalloc (buffer_len); |
745 | 19 | } |
746 | | |
747 | 365k | out = buffer; |
748 | 365k | do |
749 | 6.75M | { |
750 | 6.75M | unsigned char c = *in++; |
751 | | |
752 | 6.75M | if (c == 0) |
753 | 365k | break; |
754 | | |
755 | 6.39M | if (ISCNTRL (c)) |
756 | 1.25M | { |
757 | 1.25M | *out++ = '^'; |
758 | 1.25M | *out++ = c + 0x40; |
759 | 1.25M | } |
760 | 5.14M | else if (unicode_display != unicode_default && c >= 0xc0) |
761 | 0 | { |
762 | 0 | unsigned int num_consumed; |
763 | |
|
764 | 0 | out += display_utf8 ((const unsigned char *) --in, out, &num_consumed); |
765 | 0 | in += num_consumed; |
766 | 0 | } |
767 | 5.14M | else |
768 | 5.14M | *out++ = c; |
769 | 6.39M | } |
770 | 6.39M | while (1); |
771 | | |
772 | 365k | *out = 0; |
773 | 365k | return buffer; |
774 | 1.80M | } fuzz_objdump.c:sanitize_string Line | Count | Source | 707 | 1.80M | { | 708 | 1.80M | static char * buffer = NULL; | 709 | 1.80M | static size_t buffer_len = 0; | 710 | 1.80M | const char * original = in; | 711 | 1.80M | char * out; | 712 | | | 713 | | /* Paranoia. */ | 714 | 1.80M | if (in == NULL) | 715 | 0 | return ""; | 716 | | | 717 | | /* See if any conversion is necessary. In the majority | 718 | | of cases it will not be needed. */ | 719 | 1.80M | do | 720 | 16.2M | { | 721 | 16.2M | unsigned char c = *in++; | 722 | | | 723 | 16.2M | if (c == 0) | 724 | 1.44M | return original; | 725 | | | 726 | 14.8M | if (ISCNTRL (c)) | 727 | 365k | break; | 728 | | | 729 | 14.4M | if (unicode_display != unicode_default && c >= 0xc0) | 730 | 0 | break; | 731 | 14.4M | } | 732 | 14.4M | while (1); | 733 | | | 734 | | /* Copy the input, translating as needed. */ | 735 | 365k | in = original; | 736 | | /* For 2 char unicode, max out is 12 (colour escapes) + 6, ie. 9 per in | 737 | | For hex, max out is 8 for 2 char unicode, ie. 4 per in. | 738 | | 3 and 4 char unicode produce less output for input. */ | 739 | 365k | size_t max_needed = strlen (in) * 9 + 1; | 740 | 365k | if (buffer_len < max_needed) | 741 | 19 | { | 742 | 19 | buffer_len = max_needed; | 743 | 19 | free (buffer); | 744 | 19 | buffer = xmalloc (buffer_len); | 745 | 19 | } | 746 | | | 747 | 365k | out = buffer; | 748 | 365k | do | 749 | 6.75M | { | 750 | 6.75M | unsigned char c = *in++; | 751 | | | 752 | 6.75M | if (c == 0) | 753 | 365k | break; | 754 | | | 755 | 6.39M | if (ISCNTRL (c)) | 756 | 1.25M | { | 757 | 1.25M | *out++ = '^'; | 758 | 1.25M | *out++ = c + 0x40; | 759 | 1.25M | } | 760 | 5.14M | else if (unicode_display != unicode_default && c >= 0xc0) | 761 | 0 | { | 762 | 0 | unsigned int num_consumed; | 763 | |
| 764 | 0 | out += display_utf8 ((const unsigned char *) --in, out, &num_consumed); | 765 | 0 | in += num_consumed; | 766 | 0 | } | 767 | 5.14M | else | 768 | 5.14M | *out++ = c; | 769 | 6.39M | } | 770 | 6.39M | while (1); | 771 | | | 772 | 365k | *out = 0; | 773 | 365k | return buffer; | 774 | 1.80M | } |
Unexecuted instantiation: fuzz_dwarf.c:sanitize_string |
775 | | |
776 | | |
777 | | /* Returns TRUE if the specified section should be dumped. */ |
778 | | |
779 | | static bool |
780 | | process_section_p (asection * section) |
781 | 899k | { |
782 | 899k | struct only * only; |
783 | | |
784 | 899k | if (only_list == NULL) |
785 | 899k | return true; |
786 | | |
787 | 0 | for (only = only_list; only; only = only->next) |
788 | 0 | if (strcmp (only->name, section->name) == 0) |
789 | 0 | { |
790 | 0 | only->seen = true; |
791 | 0 | return true; |
792 | 0 | } |
793 | | |
794 | 0 | return false; |
795 | 0 | } fuzz_objdump.c:process_section_p Line | Count | Source | 781 | 899k | { | 782 | 899k | struct only * only; | 783 | | | 784 | 899k | if (only_list == NULL) | 785 | 899k | return true; | 786 | | | 787 | 0 | for (only = only_list; only; only = only->next) | 788 | 0 | if (strcmp (only->name, section->name) == 0) | 789 | 0 | { | 790 | 0 | only->seen = true; | 791 | 0 | return true; | 792 | 0 | } | 793 | | | 794 | 0 | return false; | 795 | 0 | } |
Unexecuted instantiation: fuzz_dwarf.c:process_section_p |
796 | | |
797 | | /* Add an entry to the 'only' list. */ |
798 | | |
799 | | static void |
800 | | add_only (char * name) |
801 | 0 | { |
802 | 0 | struct only * only; |
803 | | |
804 | | /* First check to make sure that we do not |
805 | | already have an entry for this name. */ |
806 | 0 | for (only = only_list; only; only = only->next) |
807 | 0 | if (strcmp (only->name, name) == 0) |
808 | 0 | return; |
809 | | |
810 | 0 | only = xmalloc (sizeof * only); |
811 | 0 | only->name = name; |
812 | 0 | only->seen = false; |
813 | 0 | only->next = only_list; |
814 | 0 | only_list = only; |
815 | 0 | } Unexecuted instantiation: fuzz_objdump.c:add_only Unexecuted instantiation: fuzz_dwarf.c:add_only |
816 | | |
817 | | /* Release the memory used by the 'only' list. |
818 | | PR 11225: Issue a warning message for unseen sections. |
819 | | Only do this if none of the sections were seen. This is mainly to support |
820 | | tools like the GAS testsuite where an object file is dumped with a list of |
821 | | generic section names known to be present in a range of different file |
822 | | formats. */ |
823 | | |
824 | | static void |
825 | | free_only_list (void) |
826 | 0 | { |
827 | 0 | bool at_least_one_seen = false; |
828 | 0 | struct only * only; |
829 | 0 | struct only * next; |
830 | |
|
831 | 0 | if (only_list == NULL) |
832 | 0 | return; |
833 | | |
834 | 0 | for (only = only_list; only; only = only->next) |
835 | 0 | if (only->seen) |
836 | 0 | { |
837 | 0 | at_least_one_seen = true; |
838 | 0 | break; |
839 | 0 | } |
840 | |
|
841 | 0 | for (only = only_list; only; only = next) |
842 | 0 | { |
843 | 0 | if (! at_least_one_seen) |
844 | 0 | { |
845 | 0 | non_fatal (_("section '%s' mentioned in a -j option, " |
846 | 0 | "but not found in any input file"), |
847 | 0 | only->name); |
848 | 0 | exit_status = 1; |
849 | 0 | } |
850 | 0 | next = only->next; |
851 | 0 | free (only); |
852 | 0 | } |
853 | 0 | } Unexecuted instantiation: fuzz_objdump.c:free_only_list Unexecuted instantiation: fuzz_dwarf.c:free_only_list |
854 | | |
855 | | |
856 | | static void |
857 | | dump_section_header (bfd *abfd, asection *section, void *data) |
858 | 899k | { |
859 | 899k | char *comma = ""; |
860 | 899k | unsigned int opb = bfd_octets_per_byte (abfd, section); |
861 | 899k | int longest_section_name = *((int *) data); |
862 | | |
863 | | /* Ignore linker created section. See elfNN_ia64_object_p in |
864 | | bfd/elfxx-ia64.c. */ |
865 | 899k | if (section->flags & SEC_LINKER_CREATED) |
866 | 152 | return; |
867 | | |
868 | | /* PR 10413: Skip sections that we are ignoring. */ |
869 | 899k | if (! process_section_p (section)) |
870 | 0 | return; |
871 | | |
872 | 899k | printf ("%3d %-*s %08lx ", section->index, longest_section_name, |
873 | 899k | sanitize_string (bfd_section_name (section)), |
874 | 899k | (unsigned long) bfd_section_size (section) / opb); |
875 | 899k | bfd_printf_vma (abfd, bfd_section_vma (section)); |
876 | 899k | printf (" "); |
877 | 899k | bfd_printf_vma (abfd, section->lma); |
878 | 899k | printf (" %08lx 2**%u", (unsigned long) section->filepos, |
879 | 899k | bfd_section_alignment (section)); |
880 | 899k | if (! wide_output) |
881 | 899k | printf ("\n "); |
882 | 899k | printf (" "); |
883 | | |
884 | 899k | #define PF(x, y) \ |
885 | 15.5M | if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; } |
886 | | |
887 | 899k | PF (SEC_HAS_CONTENTS, "CONTENTS"); |
888 | 899k | PF (SEC_ALLOC, "ALLOC"); |
889 | 899k | PF (SEC_CONSTRUCTOR, "CONSTRUCTOR"); |
890 | 899k | PF (SEC_LOAD, "LOAD"); |
891 | 899k | PF (SEC_RELOC, "RELOC"); |
892 | 899k | PF (SEC_READONLY, "READONLY"); |
893 | 899k | PF (SEC_CODE, "CODE"); |
894 | 899k | PF (SEC_DATA, "DATA"); |
895 | 899k | PF (SEC_ROM, "ROM"); |
896 | 899k | PF (SEC_DEBUGGING, "DEBUGGING"); |
897 | 899k | PF (SEC_NEVER_LOAD, "NEVER_LOAD"); |
898 | 899k | PF (SEC_EXCLUDE, "EXCLUDE"); |
899 | 899k | PF (SEC_SORT_ENTRIES, "SORT_ENTRIES"); |
900 | 899k | if (bfd_get_arch (abfd) == bfd_arch_tic54x) |
901 | 15.6k | { |
902 | 15.6k | PF (SEC_TIC54X_BLOCK, "BLOCK"); |
903 | 15.6k | PF (SEC_TIC54X_CLINK, "CLINK"); |
904 | 15.6k | } |
905 | 899k | PF (SEC_SMALL_DATA, "SMALL_DATA"); |
906 | 899k | if (bfd_get_flavour (abfd) == bfd_target_coff_flavour) |
907 | 241k | { |
908 | 241k | PF (SEC_COFF_SHARED, "SHARED"); |
909 | 241k | PF (SEC_COFF_NOREAD, "NOREAD"); |
910 | 241k | } |
911 | 657k | else if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) |
912 | 319k | { |
913 | 319k | PF (SEC_ELF_OCTETS, "OCTETS"); |
914 | 319k | PF (SEC_ELF_PURECODE, "PURECODE"); |
915 | 319k | } |
916 | 899k | PF (SEC_THREAD_LOCAL, "THREAD_LOCAL"); |
917 | 899k | PF (SEC_GROUP, "GROUP"); |
918 | 899k | if (bfd_get_arch (abfd) == bfd_arch_mep) |
919 | 87 | { |
920 | 87 | PF (SEC_MEP_VLIW, "VLIW"); |
921 | 87 | } |
922 | | |
923 | 899k | if ((section->flags & SEC_LINK_ONCE) != 0) |
924 | 8.96k | { |
925 | 8.96k | const char *ls; |
926 | 8.96k | struct coff_comdat_info *comdat; |
927 | | |
928 | 8.96k | switch (section->flags & SEC_LINK_DUPLICATES) |
929 | 8.96k | { |
930 | 0 | default: |
931 | 0 | abort (); |
932 | 8.96k | case SEC_LINK_DUPLICATES_DISCARD: |
933 | 8.96k | ls = "LINK_ONCE_DISCARD"; |
934 | 8.96k | break; |
935 | 0 | case SEC_LINK_DUPLICATES_ONE_ONLY: |
936 | 0 | ls = "LINK_ONCE_ONE_ONLY"; |
937 | 0 | break; |
938 | 0 | case SEC_LINK_DUPLICATES_SAME_SIZE: |
939 | 0 | ls = "LINK_ONCE_SAME_SIZE"; |
940 | 0 | break; |
941 | 0 | case SEC_LINK_DUPLICATES_SAME_CONTENTS: |
942 | 0 | ls = "LINK_ONCE_SAME_CONTENTS"; |
943 | 0 | break; |
944 | 8.96k | } |
945 | 8.96k | printf ("%s%s", comma, ls); |
946 | | |
947 | 8.96k | comdat = bfd_coff_get_comdat_section (abfd, section); |
948 | 8.96k | if (comdat != NULL) |
949 | 15 | printf (" (COMDAT %s %ld)", comdat->name, comdat->symbol); |
950 | | |
951 | 8.96k | comma = ", "; |
952 | 8.96k | } |
953 | | |
954 | 899k | if (bfd_is_section_compressed (abfd, section)) |
955 | 437 | printf ("%sCOMPRESSED", comma); |
956 | | |
957 | 899k | printf ("\n"); |
958 | 899k | #undef PF |
959 | 899k | } fuzz_objdump.c:dump_section_header Line | Count | Source | 858 | 899k | { | 859 | 899k | char *comma = ""; | 860 | 899k | unsigned int opb = bfd_octets_per_byte (abfd, section); | 861 | 899k | int longest_section_name = *((int *) data); | 862 | | | 863 | | /* Ignore linker created section. See elfNN_ia64_object_p in | 864 | | bfd/elfxx-ia64.c. */ | 865 | 899k | if (section->flags & SEC_LINKER_CREATED) | 866 | 152 | return; | 867 | | | 868 | | /* PR 10413: Skip sections that we are ignoring. */ | 869 | 899k | if (! process_section_p (section)) | 870 | 0 | return; | 871 | | | 872 | 899k | printf ("%3d %-*s %08lx ", section->index, longest_section_name, | 873 | 899k | sanitize_string (bfd_section_name (section)), | 874 | 899k | (unsigned long) bfd_section_size (section) / opb); | 875 | 899k | bfd_printf_vma (abfd, bfd_section_vma (section)); | 876 | 899k | printf (" "); | 877 | 899k | bfd_printf_vma (abfd, section->lma); | 878 | 899k | printf (" %08lx 2**%u", (unsigned long) section->filepos, | 879 | 899k | bfd_section_alignment (section)); | 880 | 899k | if (! wide_output) | 881 | 899k | printf ("\n "); | 882 | 899k | printf (" "); | 883 | | | 884 | 899k | #define PF(x, y) \ | 885 | 899k | if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; } | 886 | | | 887 | 899k | PF (SEC_HAS_CONTENTS, "CONTENTS"); | 888 | 899k | PF (SEC_ALLOC, "ALLOC"); | 889 | 899k | PF (SEC_CONSTRUCTOR, "CONSTRUCTOR"); | 890 | 899k | PF (SEC_LOAD, "LOAD"); | 891 | 899k | PF (SEC_RELOC, "RELOC"); | 892 | 899k | PF (SEC_READONLY, "READONLY"); | 893 | 899k | PF (SEC_CODE, "CODE"); | 894 | 899k | PF (SEC_DATA, "DATA"); | 895 | 899k | PF (SEC_ROM, "ROM"); | 896 | 899k | PF (SEC_DEBUGGING, "DEBUGGING"); | 897 | 899k | PF (SEC_NEVER_LOAD, "NEVER_LOAD"); | 898 | 899k | PF (SEC_EXCLUDE, "EXCLUDE"); | 899 | 899k | PF (SEC_SORT_ENTRIES, "SORT_ENTRIES"); | 900 | 899k | if (bfd_get_arch (abfd) == bfd_arch_tic54x) | 901 | 15.6k | { | 902 | 15.6k | PF (SEC_TIC54X_BLOCK, "BLOCK"); | 903 | 15.6k | PF (SEC_TIC54X_CLINK, "CLINK"); | 904 | 15.6k | } | 905 | 899k | PF (SEC_SMALL_DATA, "SMALL_DATA"); | 906 | 899k | if (bfd_get_flavour (abfd) == bfd_target_coff_flavour) | 907 | 241k | { | 908 | 241k | PF (SEC_COFF_SHARED, "SHARED"); | 909 | 241k | PF (SEC_COFF_NOREAD, "NOREAD"); | 910 | 241k | } | 911 | 657k | else if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) | 912 | 319k | { | 913 | 319k | PF (SEC_ELF_OCTETS, "OCTETS"); | 914 | 319k | PF (SEC_ELF_PURECODE, "PURECODE"); | 915 | 319k | } | 916 | 899k | PF (SEC_THREAD_LOCAL, "THREAD_LOCAL"); | 917 | 899k | PF (SEC_GROUP, "GROUP"); | 918 | 899k | if (bfd_get_arch (abfd) == bfd_arch_mep) | 919 | 87 | { | 920 | 87 | PF (SEC_MEP_VLIW, "VLIW"); | 921 | 87 | } | 922 | | | 923 | 899k | if ((section->flags & SEC_LINK_ONCE) != 0) | 924 | 8.96k | { | 925 | 8.96k | const char *ls; | 926 | 8.96k | struct coff_comdat_info *comdat; | 927 | | | 928 | 8.96k | switch (section->flags & SEC_LINK_DUPLICATES) | 929 | 8.96k | { | 930 | 0 | default: | 931 | 0 | abort (); | 932 | 8.96k | case SEC_LINK_DUPLICATES_DISCARD: | 933 | 8.96k | ls = "LINK_ONCE_DISCARD"; | 934 | 8.96k | break; | 935 | 0 | case SEC_LINK_DUPLICATES_ONE_ONLY: | 936 | 0 | ls = "LINK_ONCE_ONE_ONLY"; | 937 | 0 | break; | 938 | 0 | case SEC_LINK_DUPLICATES_SAME_SIZE: | 939 | 0 | ls = "LINK_ONCE_SAME_SIZE"; | 940 | 0 | break; | 941 | 0 | case SEC_LINK_DUPLICATES_SAME_CONTENTS: | 942 | 0 | ls = "LINK_ONCE_SAME_CONTENTS"; | 943 | 0 | break; | 944 | 8.96k | } | 945 | 8.96k | printf ("%s%s", comma, ls); | 946 | | | 947 | 8.96k | comdat = bfd_coff_get_comdat_section (abfd, section); | 948 | 8.96k | if (comdat != NULL) | 949 | 15 | printf (" (COMDAT %s %ld)", comdat->name, comdat->symbol); | 950 | | | 951 | 8.96k | comma = ", "; | 952 | 8.96k | } | 953 | | | 954 | 899k | if (bfd_is_section_compressed (abfd, section)) | 955 | 437 | printf ("%sCOMPRESSED", comma); | 956 | | | 957 | 899k | printf ("\n"); | 958 | 899k | #undef PF | 959 | 899k | } |
Unexecuted instantiation: fuzz_dwarf.c:dump_section_header |
960 | | |
961 | | /* Called on each SECTION in ABFD, update the int variable pointed to by |
962 | | DATA which contains the string length of the longest section name. */ |
963 | | |
964 | | static void |
965 | | find_longest_section_name (bfd *abfd ATTRIBUTE_UNUSED, |
966 | | asection *section, void *data) |
967 | 0 | { |
968 | 0 | int *longest_so_far = (int *) data; |
969 | 0 | const char *name; |
970 | 0 | int len; |
971 | | |
972 | | /* Ignore linker created section. */ |
973 | 0 | if (section->flags & SEC_LINKER_CREATED) |
974 | 0 | return; |
975 | | |
976 | | /* Skip sections that we are ignoring. */ |
977 | 0 | if (! process_section_p (section)) |
978 | 0 | return; |
979 | | |
980 | 0 | name = bfd_section_name (section); |
981 | 0 | len = (int) strlen (name); |
982 | 0 | if (len > *longest_so_far) |
983 | 0 | *longest_so_far = len; |
984 | 0 | } Unexecuted instantiation: fuzz_objdump.c:find_longest_section_name Unexecuted instantiation: fuzz_dwarf.c:find_longest_section_name |
985 | | |
986 | | static void |
987 | | dump_headers (bfd *abfd) |
988 | 31.5k | { |
989 | | /* The default width of 13 is just an arbitrary choice. */ |
990 | 31.5k | int max_section_name_length = 13; |
991 | 31.5k | int bfd_vma_width; |
992 | | |
993 | | #ifndef BFD64 |
994 | | bfd_vma_width = 10; |
995 | | #else |
996 | | /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */ |
997 | 31.5k | if (bfd_get_arch_size (abfd) == 32) |
998 | 19.5k | bfd_vma_width = 10; |
999 | 12.0k | else |
1000 | 12.0k | bfd_vma_width = 18; |
1001 | 31.5k | #endif |
1002 | | |
1003 | 31.5k | printf (_("Sections:\n")); |
1004 | | |
1005 | 31.5k | if (wide_output) |
1006 | 0 | bfd_map_over_sections (abfd, find_longest_section_name, |
1007 | 0 | &max_section_name_length); |
1008 | | |
1009 | 31.5k | printf (_("Idx %-*s Size %-*s%-*sFile off Algn"), |
1010 | 31.5k | max_section_name_length, "Name", |
1011 | 31.5k | bfd_vma_width, "VMA", |
1012 | 31.5k | bfd_vma_width, "LMA"); |
1013 | | |
1014 | 31.5k | if (wide_output) |
1015 | 0 | printf (_(" Flags")); |
1016 | 31.5k | printf ("\n"); |
1017 | | |
1018 | 31.5k | bfd_map_over_sections (abfd, dump_section_header, |
1019 | 31.5k | &max_section_name_length); |
1020 | 31.5k | } fuzz_objdump.c:dump_headers Line | Count | Source | 988 | 31.5k | { | 989 | | /* The default width of 13 is just an arbitrary choice. */ | 990 | 31.5k | int max_section_name_length = 13; | 991 | 31.5k | int bfd_vma_width; | 992 | | | 993 | | #ifndef BFD64 | 994 | | bfd_vma_width = 10; | 995 | | #else | 996 | | /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */ | 997 | 31.5k | if (bfd_get_arch_size (abfd) == 32) | 998 | 19.5k | bfd_vma_width = 10; | 999 | 12.0k | else | 1000 | 12.0k | bfd_vma_width = 18; | 1001 | 31.5k | #endif | 1002 | | | 1003 | 31.5k | printf (_("Sections:\n")); | 1004 | | | 1005 | 31.5k | if (wide_output) | 1006 | 0 | bfd_map_over_sections (abfd, find_longest_section_name, | 1007 | 0 | &max_section_name_length); | 1008 | | | 1009 | 31.5k | printf (_("Idx %-*s Size %-*s%-*sFile off Algn"), | 1010 | 31.5k | max_section_name_length, "Name", | 1011 | 31.5k | bfd_vma_width, "VMA", | 1012 | 31.5k | bfd_vma_width, "LMA"); | 1013 | | | 1014 | 31.5k | if (wide_output) | 1015 | 0 | printf (_(" Flags")); | 1016 | 31.5k | printf ("\n"); | 1017 | | | 1018 | 31.5k | bfd_map_over_sections (abfd, dump_section_header, | 1019 | 31.5k | &max_section_name_length); | 1020 | 31.5k | } |
Unexecuted instantiation: fuzz_dwarf.c:dump_headers |
1021 | | |
1022 | | static asymbol ** |
1023 | | slurp_symtab (bfd *abfd) |
1024 | 31.5k | { |
1025 | 31.5k | symcount = 0; |
1026 | 31.5k | if (!(bfd_get_file_flags (abfd) & HAS_SYMS)) |
1027 | 22.8k | return NULL; |
1028 | | |
1029 | 8.73k | long storage = bfd_get_symtab_upper_bound (abfd); |
1030 | 8.73k | if (storage < 0) |
1031 | 6.71k | { |
1032 | 6.71k | non_fatal (_("failed to read symbol table from: %s"), |
1033 | 6.71k | bfd_get_filename (abfd)); |
1034 | 6.71k | my_bfd_nonfatal (_("error message was")); |
1035 | 6.71k | } |
1036 | | |
1037 | 8.73k | if (storage <= 0) |
1038 | 6.79k | return NULL; |
1039 | | |
1040 | 1.93k | asymbol **sy = (asymbol **) xmalloc (storage); |
1041 | 1.93k | symcount = bfd_canonicalize_symtab (abfd, sy); |
1042 | 1.93k | if (symcount < 0) |
1043 | 440 | { |
1044 | 440 | my_bfd_nonfatal (bfd_get_filename (abfd)); |
1045 | 440 | free (sy); |
1046 | 440 | sy = NULL; |
1047 | 440 | symcount = 0; |
1048 | 440 | } |
1049 | 1.93k | return sy; |
1050 | 8.73k | } fuzz_objdump.c:slurp_symtab Line | Count | Source | 1024 | 31.5k | { | 1025 | 31.5k | symcount = 0; | 1026 | 31.5k | if (!(bfd_get_file_flags (abfd) & HAS_SYMS)) | 1027 | 22.8k | return NULL; | 1028 | | | 1029 | 8.73k | long storage = bfd_get_symtab_upper_bound (abfd); | 1030 | 8.73k | if (storage < 0) | 1031 | 6.71k | { | 1032 | 6.71k | non_fatal (_("failed to read symbol table from: %s"), | 1033 | 6.71k | bfd_get_filename (abfd)); | 1034 | 6.71k | my_bfd_nonfatal (_("error message was")); | 1035 | 6.71k | } | 1036 | | | 1037 | 8.73k | if (storage <= 0) | 1038 | 6.79k | return NULL; | 1039 | | | 1040 | 1.93k | asymbol **sy = (asymbol **) xmalloc (storage); | 1041 | 1.93k | symcount = bfd_canonicalize_symtab (abfd, sy); | 1042 | 1.93k | if (symcount < 0) | 1043 | 440 | { | 1044 | 440 | my_bfd_nonfatal (bfd_get_filename (abfd)); | 1045 | 440 | free (sy); | 1046 | | sy = NULL; | 1047 | 440 | symcount = 0; | 1048 | 440 | } | 1049 | 1.93k | return sy; | 1050 | 8.73k | } |
Unexecuted instantiation: fuzz_dwarf.c:slurp_symtab |
1051 | | |
1052 | | /* Read in the dynamic symbols. */ |
1053 | | |
1054 | | static asymbol ** |
1055 | | slurp_dynamic_symtab (bfd *abfd) |
1056 | 306 | { |
1057 | 306 | dynsymcount = 0; |
1058 | 306 | long storage = bfd_get_dynamic_symtab_upper_bound (abfd); |
1059 | 306 | if (storage < 0) |
1060 | 0 | { |
1061 | 0 | if (!(bfd_get_file_flags (abfd) & DYNAMIC)) |
1062 | 0 | { |
1063 | 0 | non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd)); |
1064 | 0 | exit_status = 1; |
1065 | 0 | return NULL; |
1066 | 0 | } |
1067 | | |
1068 | 0 | my_bfd_nonfatal (bfd_get_filename (abfd)); |
1069 | 0 | } |
1070 | | |
1071 | 306 | if (storage <= 0) |
1072 | 0 | return NULL; |
1073 | | |
1074 | 306 | asymbol **sy = (asymbol **) xmalloc (storage); |
1075 | 306 | dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy); |
1076 | 306 | if (dynsymcount < 0) |
1077 | 61 | { |
1078 | 61 | my_bfd_nonfatal (bfd_get_filename (abfd)); |
1079 | 61 | free (sy); |
1080 | 61 | sy = NULL; |
1081 | 61 | dynsymcount = 0; |
1082 | 61 | } |
1083 | 306 | return sy; |
1084 | 306 | } fuzz_objdump.c:slurp_dynamic_symtab Line | Count | Source | 1056 | 306 | { | 1057 | 306 | dynsymcount = 0; | 1058 | 306 | long storage = bfd_get_dynamic_symtab_upper_bound (abfd); | 1059 | 306 | if (storage < 0) | 1060 | 0 | { | 1061 | 0 | if (!(bfd_get_file_flags (abfd) & DYNAMIC)) | 1062 | 0 | { | 1063 | 0 | non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd)); | 1064 | 0 | exit_status = 1; | 1065 | 0 | return NULL; | 1066 | 0 | } | 1067 | | | 1068 | 0 | my_bfd_nonfatal (bfd_get_filename (abfd)); | 1069 | 0 | } | 1070 | | | 1071 | 306 | if (storage <= 0) | 1072 | 0 | return NULL; | 1073 | | | 1074 | 306 | asymbol **sy = (asymbol **) xmalloc (storage); | 1075 | 306 | dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy); | 1076 | 306 | if (dynsymcount < 0) | 1077 | 61 | { | 1078 | 61 | my_bfd_nonfatal (bfd_get_filename (abfd)); | 1079 | 61 | free (sy); | 1080 | | sy = NULL; | 1081 | 61 | dynsymcount = 0; | 1082 | 61 | } | 1083 | 306 | return sy; | 1084 | 306 | } |
Unexecuted instantiation: fuzz_dwarf.c:slurp_dynamic_symtab |
1085 | | |
1086 | | /* Some symbol names are significant and should be kept in the |
1087 | | table of sorted symbol names, even if they are marked as |
1088 | | debugging/section symbols. */ |
1089 | | |
1090 | | static bool |
1091 | | is_significant_symbol_name (const char * name) |
1092 | 2.93k | { |
1093 | 2.93k | return startswith (name, ".plt") || startswith (name, ".got"); |
1094 | 2.93k | } fuzz_objdump.c:is_significant_symbol_name Line | Count | Source | 1092 | 2.93k | { | 1093 | 2.93k | return startswith (name, ".plt") || startswith (name, ".got"); | 1094 | 2.93k | } |
Unexecuted instantiation: fuzz_dwarf.c:is_significant_symbol_name |
1095 | | |
1096 | | /* Filter out (in place) symbols that are useless for disassembly. |
1097 | | COUNT is the number of elements in SYMBOLS. |
1098 | | Return the number of useful symbols. */ |
1099 | | |
1100 | | static long |
1101 | | remove_useless_symbols (asymbol **symbols, long count) |
1102 | 1.03k | { |
1103 | 1.03k | asymbol **in_ptr = symbols, **out_ptr = symbols; |
1104 | | |
1105 | 16.0k | while (--count >= 0) |
1106 | 15.0k | { |
1107 | 15.0k | asymbol *sym = *in_ptr++; |
1108 | | |
1109 | 15.0k | if (sym->name == NULL || sym->name[0] == '\0') |
1110 | 6.05k | continue; |
1111 | 9.00k | if ((sym->flags & (BSF_DEBUGGING | BSF_SECTION_SYM)) |
1112 | 2.93k | && ! is_significant_symbol_name (sym->name)) |
1113 | 2.88k | continue; |
1114 | 6.11k | if (bfd_is_und_section (sym->section) |
1115 | 3.91k | || bfd_is_com_section (sym->section)) |
1116 | 2.53k | continue; |
1117 | 3.58k | if (strstr (sym->name, "gnu_compiled") |
1118 | 3.58k | || strstr (sym->name, "gcc2_compiled")) |
1119 | 1 | continue; |
1120 | | |
1121 | 3.57k | *out_ptr++ = sym; |
1122 | 3.57k | } |
1123 | 1.03k | return out_ptr - symbols; |
1124 | 1.03k | } fuzz_objdump.c:remove_useless_symbols Line | Count | Source | 1102 | 1.03k | { | 1103 | 1.03k | asymbol **in_ptr = symbols, **out_ptr = symbols; | 1104 | | | 1105 | 16.0k | while (--count >= 0) | 1106 | 15.0k | { | 1107 | 15.0k | asymbol *sym = *in_ptr++; | 1108 | | | 1109 | 15.0k | if (sym->name == NULL || sym->name[0] == '\0') | 1110 | 6.05k | continue; | 1111 | 9.00k | if ((sym->flags & (BSF_DEBUGGING | BSF_SECTION_SYM)) | 1112 | 2.93k | && ! is_significant_symbol_name (sym->name)) | 1113 | 2.88k | continue; | 1114 | 6.11k | if (bfd_is_und_section (sym->section) | 1115 | 3.91k | || bfd_is_com_section (sym->section)) | 1116 | 2.53k | continue; | 1117 | 3.58k | if (strstr (sym->name, "gnu_compiled") | 1118 | 3.58k | || strstr (sym->name, "gcc2_compiled")) | 1119 | 1 | continue; | 1120 | | | 1121 | 3.57k | *out_ptr++ = sym; | 1122 | 3.57k | } | 1123 | 1.03k | return out_ptr - symbols; | 1124 | 1.03k | } |
Unexecuted instantiation: fuzz_dwarf.c:remove_useless_symbols |
1125 | | |
1126 | | /* Return true iff SEC1 and SEC2 are the same section. |
1127 | | This would just be a simple pointer comparison except that one of |
1128 | | the sections might be from a separate debug info file. */ |
1129 | | |
1130 | | static bool |
1131 | | is_same_section (const asection *sec1, const asection *sec2) |
1132 | 157k | { |
1133 | 157k | if (sec1 == sec2) |
1134 | 21.6k | return true; |
1135 | 136k | if (sec1->owner == sec2->owner |
1136 | 7.03k | || sec1->owner == NULL |
1137 | 7.03k | || sec2->owner == NULL) |
1138 | 136k | return false; |
1139 | | /* OK, so we have one section in a debug info file. (Or they both |
1140 | | are, but the way this function is currently used sec1 will be in |
1141 | | a normal object.) Compare names, vma and size. This ought to |
1142 | | cover all the usual cases. */ |
1143 | 0 | return (sec1->vma == sec2->vma |
1144 | 0 | && sec1->size == sec2->size |
1145 | 0 | && strcmp (sec1->name, sec2->name) == 0); |
1146 | 136k | } fuzz_objdump.c:is_same_section Line | Count | Source | 1132 | 157k | { | 1133 | 157k | if (sec1 == sec2) | 1134 | 21.6k | return true; | 1135 | 136k | if (sec1->owner == sec2->owner | 1136 | 7.03k | || sec1->owner == NULL | 1137 | 7.03k | || sec2->owner == NULL) | 1138 | 136k | return false; | 1139 | | /* OK, so we have one section in a debug info file. (Or they both | 1140 | | are, but the way this function is currently used sec1 will be in | 1141 | | a normal object.) Compare names, vma and size. This ought to | 1142 | | cover all the usual cases. */ | 1143 | 0 | return (sec1->vma == sec2->vma | 1144 | 0 | && sec1->size == sec2->size | 1145 | 0 | && strcmp (sec1->name, sec2->name) == 0); | 1146 | 136k | } |
Unexecuted instantiation: fuzz_dwarf.c:is_same_section |
1147 | | |
1148 | | static const asection *compare_section; |
1149 | | |
1150 | | /* Sort symbols into value order. */ |
1151 | | |
1152 | | static int |
1153 | | compare_symbols (const void *ap, const void *bp) |
1154 | 51.8k | { |
1155 | 51.8k | const asymbol *a = * (const asymbol **) ap; |
1156 | 51.8k | const asymbol *b = * (const asymbol **) bp; |
1157 | 51.8k | const char *an; |
1158 | 51.8k | const char *bn; |
1159 | 51.8k | size_t anl; |
1160 | 51.8k | size_t bnl; |
1161 | 51.8k | bool as, af, bs, bf; |
1162 | 51.8k | flagword aflags; |
1163 | 51.8k | flagword bflags; |
1164 | | |
1165 | 51.8k | if (bfd_asymbol_value (a) > bfd_asymbol_value (b)) |
1166 | 1.38k | return 1; |
1167 | 50.4k | else if (bfd_asymbol_value (a) < bfd_asymbol_value (b)) |
1168 | 39.8k | return -1; |
1169 | | |
1170 | | /* Prefer symbols from the section currently being disassembled. |
1171 | | Don't sort symbols from other sections by section, since there |
1172 | | isn't much reason to prefer one section over another otherwise. */ |
1173 | 10.5k | as = is_same_section (compare_section, a->section); |
1174 | 10.5k | bs = is_same_section (compare_section, b->section); |
1175 | 10.5k | if (as && !bs) |
1176 | 387 | return -1; |
1177 | 10.2k | if (!as && bs) |
1178 | 391 | return 1; |
1179 | | |
1180 | 9.82k | an = bfd_asymbol_name (a); |
1181 | 9.82k | bn = bfd_asymbol_name (b); |
1182 | 9.82k | anl = strlen (an); |
1183 | 9.82k | bnl = strlen (bn); |
1184 | | |
1185 | | /* We use a heuristic for the file name, to try to sort it after |
1186 | | more useful symbols. It may not work on non Unix systems, but it |
1187 | | doesn't really matter; the only difference is precisely which |
1188 | | symbol names get printed. */ |
1189 | | |
1190 | 9.82k | #define file_symbol(s, sn, snl) \ |
1191 | 19.6k | (((s)->flags & BSF_FILE) != 0 \ |
1192 | 19.6k | || ((snl) > 2 \ |
1193 | 19.6k | && (sn)[(snl) - 2] == '.' \ |
1194 | 19.6k | && ((sn)[(snl) - 1] == 'o' \ |
1195 | 329 | || (sn)[(snl) - 1] == 'a'))) |
1196 | | |
1197 | 9.82k | af = file_symbol (a, an, anl); |
1198 | 9.82k | bf = file_symbol (b, bn, bnl); |
1199 | | |
1200 | 9.82k | if (af && ! bf) |
1201 | 7 | return 1; |
1202 | 9.81k | if (! af && bf) |
1203 | 17 | return -1; |
1204 | | |
1205 | | /* Sort function and object symbols before global symbols before |
1206 | | local symbols before section symbols before debugging symbols. */ |
1207 | | |
1208 | 9.79k | aflags = a->flags; |
1209 | 9.79k | bflags = b->flags; |
1210 | | |
1211 | 9.79k | if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING)) |
1212 | 425 | { |
1213 | 425 | if ((aflags & BSF_DEBUGGING) != 0) |
1214 | 10 | return 1; |
1215 | 415 | else |
1216 | 415 | return -1; |
1217 | 425 | } |
1218 | 9.37k | if ((aflags & BSF_SECTION_SYM) != (bflags & BSF_SECTION_SYM)) |
1219 | 0 | { |
1220 | 0 | if ((aflags & BSF_SECTION_SYM) != 0) |
1221 | 0 | return 1; |
1222 | 0 | else |
1223 | 0 | return -1; |
1224 | 0 | } |
1225 | 9.37k | if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION)) |
1226 | 2.60k | { |
1227 | 2.60k | if ((aflags & BSF_FUNCTION) != 0) |
1228 | 2.23k | return -1; |
1229 | 374 | else |
1230 | 374 | return 1; |
1231 | 2.60k | } |
1232 | 6.76k | if ((aflags & BSF_OBJECT) != (bflags & BSF_OBJECT)) |
1233 | 711 | { |
1234 | 711 | if ((aflags & BSF_OBJECT) != 0) |
1235 | 700 | return -1; |
1236 | 11 | else |
1237 | 11 | return 1; |
1238 | 711 | } |
1239 | 6.05k | if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL)) |
1240 | 1.58k | { |
1241 | 1.58k | if ((aflags & BSF_LOCAL) != 0) |
1242 | 183 | return 1; |
1243 | 1.40k | else |
1244 | 1.40k | return -1; |
1245 | 1.58k | } |
1246 | 4.47k | if ((aflags & BSF_GLOBAL) != (bflags & BSF_GLOBAL)) |
1247 | 102 | { |
1248 | 102 | if ((aflags & BSF_GLOBAL) != 0) |
1249 | 95 | return -1; |
1250 | 7 | else |
1251 | 7 | return 1; |
1252 | 102 | } |
1253 | | |
1254 | | /* Sort larger size ELF symbols before smaller. See PR20337. */ |
1255 | 4.36k | bfd_vma asz = 0; |
1256 | 4.36k | if ((a->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0 |
1257 | 4.36k | && bfd_get_flavour (bfd_asymbol_bfd (a)) == bfd_target_elf_flavour) |
1258 | 4.24k | asz = ((elf_symbol_type *) a)->internal_elf_sym.st_size; |
1259 | 4.36k | bfd_vma bsz = 0; |
1260 | 4.36k | if ((b->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0 |
1261 | 4.36k | && bfd_get_flavour (bfd_asymbol_bfd (b)) == bfd_target_elf_flavour) |
1262 | 4.24k | bsz = ((elf_symbol_type *) b)->internal_elf_sym.st_size; |
1263 | 4.36k | if (asz != bsz) |
1264 | 2.07k | return asz > bsz ? -1 : 1; |
1265 | | |
1266 | | /* Symbols that start with '.' might be section names, so sort them |
1267 | | after symbols that don't start with '.'. */ |
1268 | 2.29k | if (an[0] == '.' && bn[0] != '.') |
1269 | 4 | return 1; |
1270 | 2.29k | if (an[0] != '.' && bn[0] == '.') |
1271 | 11 | return -1; |
1272 | | |
1273 | | /* Finally, if we can't distinguish them in any other way, try to |
1274 | | get consistent results by sorting the symbols by name. */ |
1275 | 2.28k | return strcmp (an, bn); |
1276 | 2.29k | } fuzz_objdump.c:compare_symbols Line | Count | Source | 1154 | 51.8k | { | 1155 | 51.8k | const asymbol *a = * (const asymbol **) ap; | 1156 | 51.8k | const asymbol *b = * (const asymbol **) bp; | 1157 | 51.8k | const char *an; | 1158 | 51.8k | const char *bn; | 1159 | 51.8k | size_t anl; | 1160 | 51.8k | size_t bnl; | 1161 | 51.8k | bool as, af, bs, bf; | 1162 | 51.8k | flagword aflags; | 1163 | 51.8k | flagword bflags; | 1164 | | | 1165 | 51.8k | if (bfd_asymbol_value (a) > bfd_asymbol_value (b)) | 1166 | 1.38k | return 1; | 1167 | 50.4k | else if (bfd_asymbol_value (a) < bfd_asymbol_value (b)) | 1168 | 39.8k | return -1; | 1169 | | | 1170 | | /* Prefer symbols from the section currently being disassembled. | 1171 | | Don't sort symbols from other sections by section, since there | 1172 | | isn't much reason to prefer one section over another otherwise. */ | 1173 | 10.5k | as = is_same_section (compare_section, a->section); | 1174 | 10.5k | bs = is_same_section (compare_section, b->section); | 1175 | 10.5k | if (as && !bs) | 1176 | 387 | return -1; | 1177 | 10.2k | if (!as && bs) | 1178 | 391 | return 1; | 1179 | | | 1180 | 9.82k | an = bfd_asymbol_name (a); | 1181 | 9.82k | bn = bfd_asymbol_name (b); | 1182 | 9.82k | anl = strlen (an); | 1183 | 9.82k | bnl = strlen (bn); | 1184 | | | 1185 | | /* We use a heuristic for the file name, to try to sort it after | 1186 | | more useful symbols. It may not work on non Unix systems, but it | 1187 | | doesn't really matter; the only difference is precisely which | 1188 | | symbol names get printed. */ | 1189 | | | 1190 | 9.82k | #define file_symbol(s, sn, snl) \ | 1191 | 9.82k | (((s)->flags & BSF_FILE) != 0 \ | 1192 | 9.82k | || ((snl) > 2 \ | 1193 | 9.82k | && (sn)[(snl) - 2] == '.' \ | 1194 | 9.82k | && ((sn)[(snl) - 1] == 'o' \ | 1195 | 9.82k | || (sn)[(snl) - 1] == 'a'))) | 1196 | | | 1197 | 9.82k | af = file_symbol (a, an, anl); | 1198 | 9.82k | bf = file_symbol (b, bn, bnl); | 1199 | | | 1200 | 9.82k | if (af && ! bf) | 1201 | 7 | return 1; | 1202 | 9.81k | if (! af && bf) | 1203 | 17 | return -1; | 1204 | | | 1205 | | /* Sort function and object symbols before global symbols before | 1206 | | local symbols before section symbols before debugging symbols. */ | 1207 | | | 1208 | 9.79k | aflags = a->flags; | 1209 | 9.79k | bflags = b->flags; | 1210 | | | 1211 | 9.79k | if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING)) | 1212 | 425 | { | 1213 | 425 | if ((aflags & BSF_DEBUGGING) != 0) | 1214 | 10 | return 1; | 1215 | 415 | else | 1216 | 415 | return -1; | 1217 | 425 | } | 1218 | 9.37k | if ((aflags & BSF_SECTION_SYM) != (bflags & BSF_SECTION_SYM)) | 1219 | 0 | { | 1220 | 0 | if ((aflags & BSF_SECTION_SYM) != 0) | 1221 | 0 | return 1; | 1222 | 0 | else | 1223 | 0 | return -1; | 1224 | 0 | } | 1225 | 9.37k | if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION)) | 1226 | 2.60k | { | 1227 | 2.60k | if ((aflags & BSF_FUNCTION) != 0) | 1228 | 2.23k | return -1; | 1229 | 374 | else | 1230 | 374 | return 1; | 1231 | 2.60k | } | 1232 | 6.76k | if ((aflags & BSF_OBJECT) != (bflags & BSF_OBJECT)) | 1233 | 711 | { | 1234 | 711 | if ((aflags & BSF_OBJECT) != 0) | 1235 | 700 | return -1; | 1236 | 11 | else | 1237 | 11 | return 1; | 1238 | 711 | } | 1239 | 6.05k | if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL)) | 1240 | 1.58k | { | 1241 | 1.58k | if ((aflags & BSF_LOCAL) != 0) | 1242 | 183 | return 1; | 1243 | 1.40k | else | 1244 | 1.40k | return -1; | 1245 | 1.58k | } | 1246 | 4.47k | if ((aflags & BSF_GLOBAL) != (bflags & BSF_GLOBAL)) | 1247 | 102 | { | 1248 | 102 | if ((aflags & BSF_GLOBAL) != 0) | 1249 | 95 | return -1; | 1250 | 7 | else | 1251 | 7 | return 1; | 1252 | 102 | } | 1253 | | | 1254 | | /* Sort larger size ELF symbols before smaller. See PR20337. */ | 1255 | 4.36k | bfd_vma asz = 0; | 1256 | 4.36k | if ((a->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0 | 1257 | 4.36k | && bfd_get_flavour (bfd_asymbol_bfd (a)) == bfd_target_elf_flavour) | 1258 | 4.24k | asz = ((elf_symbol_type *) a)->internal_elf_sym.st_size; | 1259 | 4.36k | bfd_vma bsz = 0; | 1260 | 4.36k | if ((b->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0 | 1261 | 4.36k | && bfd_get_flavour (bfd_asymbol_bfd (b)) == bfd_target_elf_flavour) | 1262 | 4.24k | bsz = ((elf_symbol_type *) b)->internal_elf_sym.st_size; | 1263 | 4.36k | if (asz != bsz) | 1264 | 2.07k | return asz > bsz ? -1 : 1; | 1265 | | | 1266 | | /* Symbols that start with '.' might be section names, so sort them | 1267 | | after symbols that don't start with '.'. */ | 1268 | 2.29k | if (an[0] == '.' && bn[0] != '.') | 1269 | 4 | return 1; | 1270 | 2.29k | if (an[0] != '.' && bn[0] == '.') | 1271 | 11 | return -1; | 1272 | | | 1273 | | /* Finally, if we can't distinguish them in any other way, try to | 1274 | | get consistent results by sorting the symbols by name. */ | 1275 | 2.28k | return strcmp (an, bn); | 1276 | 2.29k | } |
Unexecuted instantiation: fuzz_dwarf.c:compare_symbols |
1277 | | |
1278 | | /* Sort relocs into address order. */ |
1279 | | |
1280 | | static int |
1281 | | compare_relocs (const void *ap, const void *bp) |
1282 | 681k | { |
1283 | 681k | const arelent *a = * (const arelent **) ap; |
1284 | 681k | const arelent *b = * (const arelent **) bp; |
1285 | | |
1286 | 681k | if (a->address > b->address) |
1287 | 263k | return 1; |
1288 | 417k | else if (a->address < b->address) |
1289 | 325k | return -1; |
1290 | | |
1291 | | /* So that associated relocations tied to the same address show up |
1292 | | in the correct order, we don't do any further sorting. */ |
1293 | 92.4k | if (a > b) |
1294 | 0 | return 1; |
1295 | 92.4k | else if (a < b) |
1296 | 92.4k | return -1; |
1297 | 0 | else |
1298 | 0 | return 0; |
1299 | 92.4k | } fuzz_objdump.c:compare_relocs Line | Count | Source | 1282 | 681k | { | 1283 | 681k | const arelent *a = * (const arelent **) ap; | 1284 | 681k | const arelent *b = * (const arelent **) bp; | 1285 | | | 1286 | 681k | if (a->address > b->address) | 1287 | 263k | return 1; | 1288 | 417k | else if (a->address < b->address) | 1289 | 325k | return -1; | 1290 | | | 1291 | | /* So that associated relocations tied to the same address show up | 1292 | | in the correct order, we don't do any further sorting. */ | 1293 | 92.4k | if (a > b) | 1294 | 0 | return 1; | 1295 | 92.4k | else if (a < b) | 1296 | 92.4k | return -1; | 1297 | 0 | else | 1298 | 0 | return 0; | 1299 | 92.4k | } |
Unexecuted instantiation: fuzz_dwarf.c:compare_relocs |
1300 | | |
1301 | | /* Print an address (VMA) to the output stream in INFO. |
1302 | | If SKIP_ZEROES is TRUE, omit leading zeroes. */ |
1303 | | |
1304 | | static void |
1305 | | objdump_print_value (bfd_vma vma, struct disassemble_info *inf, |
1306 | | bool skip_zeroes) |
1307 | 7.47M | { |
1308 | 7.47M | char buf[30]; |
1309 | 7.47M | char *p; |
1310 | 7.47M | struct objdump_disasm_info *aux; |
1311 | | |
1312 | 7.47M | aux = (struct objdump_disasm_info *) inf->application_data; |
1313 | 7.47M | bfd_sprintf_vma (aux->abfd, buf, vma); |
1314 | 7.47M | if (! skip_zeroes) |
1315 | 87.0k | p = buf; |
1316 | 7.38M | else |
1317 | 7.38M | { |
1318 | 34.8M | for (p = buf; *p == '0'; ++p) |
1319 | 27.4M | ; |
1320 | 7.38M | if (*p == '\0') |
1321 | 32.3k | --p; |
1322 | 7.38M | } |
1323 | 7.47M | (*inf->fprintf_styled_func) (inf->stream, dis_style_address, "%s", p); |
1324 | 7.47M | } fuzz_objdump.c:objdump_print_value Line | Count | Source | 1307 | 7.47M | { | 1308 | 7.47M | char buf[30]; | 1309 | 7.47M | char *p; | 1310 | 7.47M | struct objdump_disasm_info *aux; | 1311 | | | 1312 | 7.47M | aux = (struct objdump_disasm_info *) inf->application_data; | 1313 | 7.47M | bfd_sprintf_vma (aux->abfd, buf, vma); | 1314 | 7.47M | if (! skip_zeroes) | 1315 | 87.0k | p = buf; | 1316 | 7.38M | else | 1317 | 7.38M | { | 1318 | 34.8M | for (p = buf; *p == '0'; ++p) | 1319 | 27.4M | ; | 1320 | 7.38M | if (*p == '\0') | 1321 | 32.3k | --p; | 1322 | 7.38M | } | 1323 | 7.47M | (*inf->fprintf_styled_func) (inf->stream, dis_style_address, "%s", p); | 1324 | 7.47M | } |
Unexecuted instantiation: fuzz_dwarf.c:objdump_print_value |
1325 | | |
1326 | | /* Print the name of a symbol. */ |
1327 | | |
1328 | | static void |
1329 | | objdump_print_symname (bfd *abfd, struct disassemble_info *inf, |
1330 | | asymbol *sym) |
1331 | 65.4k | { |
1332 | 65.4k | char *alloc; |
1333 | 65.4k | const char *name, *version_string = NULL; |
1334 | 65.4k | bool hidden = false; |
1335 | | |
1336 | 65.4k | alloc = NULL; |
1337 | 65.4k | name = bfd_asymbol_name (sym); |
1338 | 65.4k | if (do_demangle && name[0] != '\0') |
1339 | 0 | { |
1340 | | /* Demangle the name. */ |
1341 | 0 | alloc = bfd_demangle (abfd, name, demangle_flags); |
1342 | 0 | if (alloc != NULL) |
1343 | 0 | name = alloc; |
1344 | 0 | } |
1345 | | |
1346 | 65.4k | if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0) |
1347 | 29.2k | version_string = bfd_get_symbol_version_string (abfd, sym, true, |
1348 | 65.4k | &hidden); |
1349 | | |
1350 | 65.4k | if (bfd_is_und_section (bfd_asymbol_section (sym))) |
1351 | 1.28k | hidden = true; |
1352 | | |
1353 | 65.4k | name = sanitize_string (name); |
1354 | | |
1355 | 65.4k | if (inf != NULL) |
1356 | 65.4k | { |
1357 | 65.4k | (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol, "%s", name); |
1358 | 65.4k | if (version_string && *version_string != '\0') |
1359 | 4.67k | (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol, |
1360 | 4.67k | hidden ? "@%s" : "@@%s", |
1361 | 4.67k | version_string); |
1362 | 65.4k | } |
1363 | 0 | else |
1364 | 0 | { |
1365 | 0 | printf ("%s", name); |
1366 | 0 | if (version_string && *version_string != '\0') |
1367 | 0 | printf (hidden ? "@%s" : "@@%s", version_string); |
1368 | 0 | } |
1369 | | |
1370 | 65.4k | if (alloc != NULL) |
1371 | 0 | free (alloc); |
1372 | 65.4k | } fuzz_objdump.c:objdump_print_symname Line | Count | Source | 1331 | 65.4k | { | 1332 | 65.4k | char *alloc; | 1333 | 65.4k | const char *name, *version_string = NULL; | 1334 | 65.4k | bool hidden = false; | 1335 | | | 1336 | 65.4k | alloc = NULL; | 1337 | 65.4k | name = bfd_asymbol_name (sym); | 1338 | 65.4k | if (do_demangle && name[0] != '\0') | 1339 | 0 | { | 1340 | | /* Demangle the name. */ | 1341 | 0 | alloc = bfd_demangle (abfd, name, demangle_flags); | 1342 | 0 | if (alloc != NULL) | 1343 | 0 | name = alloc; | 1344 | 0 | } | 1345 | | | 1346 | 65.4k | if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0) | 1347 | 29.2k | version_string = bfd_get_symbol_version_string (abfd, sym, true, | 1348 | 65.4k | &hidden); | 1349 | | | 1350 | 65.4k | if (bfd_is_und_section (bfd_asymbol_section (sym))) | 1351 | 1.28k | hidden = true; | 1352 | | | 1353 | 65.4k | name = sanitize_string (name); | 1354 | | | 1355 | 65.4k | if (inf != NULL) | 1356 | 65.4k | { | 1357 | 65.4k | (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol, "%s", name); | 1358 | 65.4k | if (version_string && *version_string != '\0') | 1359 | 4.67k | (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol, | 1360 | 4.67k | hidden ? "@%s" : "@@%s", | 1361 | 4.67k | version_string); | 1362 | 65.4k | } | 1363 | 0 | else | 1364 | 0 | { | 1365 | 0 | printf ("%s", name); | 1366 | 0 | if (version_string && *version_string != '\0') | 1367 | 0 | printf (hidden ? "@%s" : "@@%s", version_string); | 1368 | 0 | } | 1369 | | | 1370 | 65.4k | if (alloc != NULL) | 1371 | 0 | free (alloc); | 1372 | 65.4k | } |
Unexecuted instantiation: fuzz_dwarf.c:objdump_print_symname |
1373 | | |
1374 | | static inline bool |
1375 | | sym_ok (bool want_section, |
1376 | | bfd *abfd ATTRIBUTE_UNUSED, |
1377 | | long place, |
1378 | | asection *sec, |
1379 | | struct disassemble_info *inf) |
1380 | 151k | { |
1381 | 151k | if (want_section && !is_same_section (sec, sorted_syms[place]->section)) |
1382 | 117k | return false; |
1383 | | |
1384 | 34.5k | return inf->symbol_is_valid (sorted_syms[place], inf); |
1385 | 151k | } Line | Count | Source | 1380 | 151k | { | 1381 | 151k | if (want_section && !is_same_section (sec, sorted_syms[place]->section)) | 1382 | 117k | return false; | 1383 | | | 1384 | 34.5k | return inf->symbol_is_valid (sorted_syms[place], inf); | 1385 | 151k | } |
Unexecuted instantiation: fuzz_dwarf.c:sym_ok |
1386 | | |
1387 | | /* Locate a symbol given a bfd and a section (from INFO->application_data), |
1388 | | and a VMA. If INFO->application_data->require_sec is TRUE, then always |
1389 | | require the symbol to be in the section. Returns NULL if there is no |
1390 | | suitable symbol. If PLACE is not NULL, then *PLACE is set to the index |
1391 | | of the symbol in sorted_syms. */ |
1392 | | |
1393 | | static asymbol * |
1394 | | find_symbol_for_address (bfd_vma vma, |
1395 | | struct disassemble_info *inf, |
1396 | | long *place) |
1397 | 507k | { |
1398 | | /* @@ Would it speed things up to cache the last two symbols returned, |
1399 | | and maybe their address ranges? For many processors, only one memory |
1400 | | operand can be present at a time, so the 2-entry cache wouldn't be |
1401 | | constantly churned by code doing heavy memory accesses. */ |
1402 | | |
1403 | | /* Indices in `sorted_syms'. */ |
1404 | 507k | long min = 0; |
1405 | 507k | long max_count = sorted_symcount; |
1406 | 507k | long thisplace; |
1407 | 507k | struct objdump_disasm_info *aux; |
1408 | 507k | bfd *abfd; |
1409 | 507k | asection *sec; |
1410 | 507k | unsigned int opb; |
1411 | 507k | bool want_section; |
1412 | 507k | long rel_count; |
1413 | | |
1414 | 507k | if (sorted_symcount < 1) |
1415 | 463k | return NULL; |
1416 | | |
1417 | 44.0k | aux = (struct objdump_disasm_info *) inf->application_data; |
1418 | 44.0k | abfd = aux->abfd; |
1419 | 44.0k | sec = inf->section; |
1420 | 44.0k | opb = inf->octets_per_byte; |
1421 | | |
1422 | | /* Perform a binary search looking for the closest symbol to the |
1423 | | required value. We are searching the range (min, max_count]. */ |
1424 | 116k | while (min + 1 < max_count) |
1425 | 74.9k | { |
1426 | 74.9k | asymbol *sym; |
1427 | | |
1428 | 74.9k | thisplace = (max_count + min) / 2; |
1429 | 74.9k | sym = sorted_syms[thisplace]; |
1430 | | |
1431 | 74.9k | if (bfd_asymbol_value (sym) > vma) |
1432 | 40.0k | max_count = thisplace; |
1433 | 34.8k | else if (bfd_asymbol_value (sym) < vma) |
1434 | 32.1k | min = thisplace; |
1435 | 2.69k | else |
1436 | 2.69k | { |
1437 | 2.69k | min = thisplace; |
1438 | 2.69k | break; |
1439 | 2.69k | } |
1440 | 74.9k | } |
1441 | | |
1442 | | /* The symbol we want is now in min, the low end of the range we |
1443 | | were searching. If there are several symbols with the same |
1444 | | value, we want the first one. */ |
1445 | 44.0k | thisplace = min; |
1446 | 55.0k | while (thisplace > 0 |
1447 | 22.6k | && (bfd_asymbol_value (sorted_syms[thisplace]) |
1448 | 22.6k | == bfd_asymbol_value (sorted_syms[thisplace - 1]))) |
1449 | 10.9k | --thisplace; |
1450 | | |
1451 | | /* Prefer a symbol in the current section if we have multple symbols |
1452 | | with the same value, as can occur with overlays or zero size |
1453 | | sections. */ |
1454 | 44.0k | min = thisplace; |
1455 | 78.3k | while (min < max_count |
1456 | 52.1k | && (bfd_asymbol_value (sorted_syms[min]) |
1457 | 52.1k | == bfd_asymbol_value (sorted_syms[thisplace]))) |
1458 | 51.0k | { |
1459 | 51.0k | if (sym_ok (true, abfd, min, sec, inf)) |
1460 | 16.7k | { |
1461 | 16.7k | thisplace = min; |
1462 | | |
1463 | 16.7k | if (place != NULL) |
1464 | 13.8k | *place = thisplace; |
1465 | | |
1466 | 16.7k | return sorted_syms[thisplace]; |
1467 | 16.7k | } |
1468 | 34.2k | ++min; |
1469 | 34.2k | } |
1470 | | |
1471 | | /* If the file is relocatable, and the symbol could be from this |
1472 | | section, prefer a symbol from this section over symbols from |
1473 | | others, even if the other symbol's value might be closer. |
1474 | | |
1475 | | Note that this may be wrong for some symbol references if the |
1476 | | sections have overlapping memory ranges, but in that case there's |
1477 | | no way to tell what's desired without looking at the relocation |
1478 | | table. |
1479 | | |
1480 | | Also give the target a chance to reject symbols. */ |
1481 | 27.3k | want_section = (aux->require_sec |
1482 | 23.8k | || ((abfd->flags & HAS_RELOC) != 0 |
1483 | 12.9k | && vma >= bfd_section_vma (sec) |
1484 | 12.7k | && vma < (bfd_section_vma (sec) |
1485 | 12.7k | + bfd_section_size (sec) / opb))); |
1486 | | |
1487 | 27.3k | if (! sym_ok (want_section, abfd, thisplace, sec, inf)) |
1488 | 12.3k | { |
1489 | 12.3k | long i; |
1490 | 12.3k | long newplace = sorted_symcount; |
1491 | | |
1492 | 45.7k | for (i = min - 1; i >= 0; i--) |
1493 | 33.3k | { |
1494 | 33.3k | if (sym_ok (want_section, abfd, i, sec, inf)) |
1495 | 1.24k | { |
1496 | 1.24k | if (newplace == sorted_symcount) |
1497 | 1.22k | newplace = i; |
1498 | | |
1499 | 1.24k | if (bfd_asymbol_value (sorted_syms[i]) |
1500 | 1.24k | != bfd_asymbol_value (sorted_syms[newplace])) |
1501 | 10 | break; |
1502 | | |
1503 | | /* Remember this symbol and keep searching until we reach |
1504 | | an earlier address. */ |
1505 | 1.23k | newplace = i; |
1506 | 1.23k | } |
1507 | 33.3k | } |
1508 | | |
1509 | 12.3k | if (newplace != sorted_symcount) |
1510 | 1.22k | thisplace = newplace; |
1511 | 11.1k | else |
1512 | 11.1k | { |
1513 | | /* We didn't find a good symbol with a smaller value. |
1514 | | Look for one with a larger value. */ |
1515 | 38.7k | for (i = thisplace + 1; i < sorted_symcount; i++) |
1516 | 27.7k | { |
1517 | 27.7k | if (sym_ok (want_section, abfd, i, sec, inf)) |
1518 | 103 | { |
1519 | 103 | thisplace = i; |
1520 | 103 | break; |
1521 | 103 | } |
1522 | 27.7k | } |
1523 | 11.1k | } |
1524 | | |
1525 | 12.3k | if (! sym_ok (want_section, abfd, thisplace, sec, inf)) |
1526 | | /* There is no suitable symbol. */ |
1527 | 11.0k | return NULL; |
1528 | 12.3k | } |
1529 | | |
1530 | | /* If we have not found an exact match for the specified address |
1531 | | and we have dynamic relocations available, then we can produce |
1532 | | a better result by matching a relocation to the address and |
1533 | | using the symbol associated with that relocation. */ |
1534 | 16.2k | rel_count = inf->dynrelcount; |
1535 | 16.2k | if (!want_section |
1536 | 14.9k | && sorted_syms[thisplace]->value != vma |
1537 | 14.9k | && rel_count > 0 |
1538 | 8.52k | && inf->dynrelbuf != NULL |
1539 | 8.52k | && inf->dynrelbuf[0]->address <= vma |
1540 | 1.99k | && inf->dynrelbuf[rel_count - 1]->address >= vma |
1541 | | /* If we have matched a synthetic symbol, then stick with that. */ |
1542 | 803 | && (sorted_syms[thisplace]->flags & BSF_SYNTHETIC) == 0) |
1543 | 711 | { |
1544 | 711 | arelent ** rel_low; |
1545 | 711 | arelent ** rel_high; |
1546 | | |
1547 | 711 | rel_low = inf->dynrelbuf; |
1548 | 711 | rel_high = rel_low + rel_count - 1; |
1549 | 2.36k | while (rel_low <= rel_high) |
1550 | 2.36k | { |
1551 | 2.36k | arelent **rel_mid = &rel_low[(rel_high - rel_low) / 2]; |
1552 | 2.36k | arelent * rel = *rel_mid; |
1553 | | |
1554 | 2.36k | if (rel->address == vma) |
1555 | 352 | { |
1556 | | /* Absolute relocations do not provide a more helpful |
1557 | | symbolic address. Find a non-absolute relocation |
1558 | | with the same address. */ |
1559 | 352 | arelent **rel_vma = rel_mid; |
1560 | 352 | for (rel_mid--; |
1561 | 352 | rel_mid >= rel_low && rel_mid[0]->address == vma; |
1562 | 352 | rel_mid--) |
1563 | 0 | rel_vma = rel_mid; |
1564 | | |
1565 | 434 | for (; rel_vma <= rel_high && rel_vma[0]->address == vma; |
1566 | 352 | rel_vma++) |
1567 | 353 | { |
1568 | 353 | rel = *rel_vma; |
1569 | 353 | if (rel->sym_ptr_ptr != NULL |
1570 | 353 | && ! bfd_is_abs_section ((* rel->sym_ptr_ptr)->section)) |
1571 | 271 | { |
1572 | 271 | if (place != NULL) |
1573 | 271 | * place = thisplace; |
1574 | 271 | return * rel->sym_ptr_ptr; |
1575 | 271 | } |
1576 | 353 | } |
1577 | 81 | break; |
1578 | 352 | } |
1579 | | |
1580 | 2.00k | if (vma < rel->address) |
1581 | 573 | rel_high = rel_mid; |
1582 | 1.43k | else if (vma >= rel_mid[1]->address) |
1583 | 1.07k | rel_low = rel_mid + 1; |
1584 | 359 | else |
1585 | 359 | break; |
1586 | 2.00k | } |
1587 | 711 | } |
1588 | | |
1589 | 15.9k | if (place != NULL) |
1590 | 15.9k | *place = thisplace; |
1591 | | |
1592 | 15.9k | return sorted_syms[thisplace]; |
1593 | 16.2k | } fuzz_objdump.c:find_symbol_for_address Line | Count | Source | 1397 | 507k | { | 1398 | | /* @@ Would it speed things up to cache the last two symbols returned, | 1399 | | and maybe their address ranges? For many processors, only one memory | 1400 | | operand can be present at a time, so the 2-entry cache wouldn't be | 1401 | | constantly churned by code doing heavy memory accesses. */ | 1402 | | | 1403 | | /* Indices in `sorted_syms'. */ | 1404 | 507k | long min = 0; | 1405 | 507k | long max_count = sorted_symcount; | 1406 | 507k | long thisplace; | 1407 | 507k | struct objdump_disasm_info *aux; | 1408 | 507k | bfd *abfd; | 1409 | 507k | asection *sec; | 1410 | 507k | unsigned int opb; | 1411 | 507k | bool want_section; | 1412 | 507k | long rel_count; | 1413 | | | 1414 | 507k | if (sorted_symcount < 1) | 1415 | 463k | return NULL; | 1416 | | | 1417 | 44.0k | aux = (struct objdump_disasm_info *) inf->application_data; | 1418 | 44.0k | abfd = aux->abfd; | 1419 | 44.0k | sec = inf->section; | 1420 | 44.0k | opb = inf->octets_per_byte; | 1421 | | | 1422 | | /* Perform a binary search looking for the closest symbol to the | 1423 | | required value. We are searching the range (min, max_count]. */ | 1424 | 116k | while (min + 1 < max_count) | 1425 | 74.9k | { | 1426 | 74.9k | asymbol *sym; | 1427 | | | 1428 | 74.9k | thisplace = (max_count + min) / 2; | 1429 | 74.9k | sym = sorted_syms[thisplace]; | 1430 | | | 1431 | 74.9k | if (bfd_asymbol_value (sym) > vma) | 1432 | 40.0k | max_count = thisplace; | 1433 | 34.8k | else if (bfd_asymbol_value (sym) < vma) | 1434 | 32.1k | min = thisplace; | 1435 | 2.69k | else | 1436 | 2.69k | { | 1437 | 2.69k | min = thisplace; | 1438 | 2.69k | break; | 1439 | 2.69k | } | 1440 | 74.9k | } | 1441 | | | 1442 | | /* The symbol we want is now in min, the low end of the range we | 1443 | | were searching. If there are several symbols with the same | 1444 | | value, we want the first one. */ | 1445 | 44.0k | thisplace = min; | 1446 | 55.0k | while (thisplace > 0 | 1447 | 22.6k | && (bfd_asymbol_value (sorted_syms[thisplace]) | 1448 | 22.6k | == bfd_asymbol_value (sorted_syms[thisplace - 1]))) | 1449 | 10.9k | --thisplace; | 1450 | | | 1451 | | /* Prefer a symbol in the current section if we have multple symbols | 1452 | | with the same value, as can occur with overlays or zero size | 1453 | | sections. */ | 1454 | 44.0k | min = thisplace; | 1455 | 78.3k | while (min < max_count | 1456 | 52.1k | && (bfd_asymbol_value (sorted_syms[min]) | 1457 | 52.1k | == bfd_asymbol_value (sorted_syms[thisplace]))) | 1458 | 51.0k | { | 1459 | 51.0k | if (sym_ok (true, abfd, min, sec, inf)) | 1460 | 16.7k | { | 1461 | 16.7k | thisplace = min; | 1462 | | | 1463 | 16.7k | if (place != NULL) | 1464 | 13.8k | *place = thisplace; | 1465 | | | 1466 | 16.7k | return sorted_syms[thisplace]; | 1467 | 16.7k | } | 1468 | 34.2k | ++min; | 1469 | 34.2k | } | 1470 | | | 1471 | | /* If the file is relocatable, and the symbol could be from this | 1472 | | section, prefer a symbol from this section over symbols from | 1473 | | others, even if the other symbol's value might be closer. | 1474 | | | 1475 | | Note that this may be wrong for some symbol references if the | 1476 | | sections have overlapping memory ranges, but in that case there's | 1477 | | no way to tell what's desired without looking at the relocation | 1478 | | table. | 1479 | | | 1480 | | Also give the target a chance to reject symbols. */ | 1481 | 27.3k | want_section = (aux->require_sec | 1482 | 23.8k | || ((abfd->flags & HAS_RELOC) != 0 | 1483 | 12.9k | && vma >= bfd_section_vma (sec) | 1484 | 12.7k | && vma < (bfd_section_vma (sec) | 1485 | 12.7k | + bfd_section_size (sec) / opb))); | 1486 | | | 1487 | 27.3k | if (! sym_ok (want_section, abfd, thisplace, sec, inf)) | 1488 | 12.3k | { | 1489 | 12.3k | long i; | 1490 | 12.3k | long newplace = sorted_symcount; | 1491 | | | 1492 | 45.7k | for (i = min - 1; i >= 0; i--) | 1493 | 33.3k | { | 1494 | 33.3k | if (sym_ok (want_section, abfd, i, sec, inf)) | 1495 | 1.24k | { | 1496 | 1.24k | if (newplace == sorted_symcount) | 1497 | 1.22k | newplace = i; | 1498 | | | 1499 | 1.24k | if (bfd_asymbol_value (sorted_syms[i]) | 1500 | 1.24k | != bfd_asymbol_value (sorted_syms[newplace])) | 1501 | 10 | break; | 1502 | | | 1503 | | /* Remember this symbol and keep searching until we reach | 1504 | | an earlier address. */ | 1505 | 1.23k | newplace = i; | 1506 | 1.23k | } | 1507 | 33.3k | } | 1508 | | | 1509 | 12.3k | if (newplace != sorted_symcount) | 1510 | 1.22k | thisplace = newplace; | 1511 | 11.1k | else | 1512 | 11.1k | { | 1513 | | /* We didn't find a good symbol with a smaller value. | 1514 | | Look for one with a larger value. */ | 1515 | 38.7k | for (i = thisplace + 1; i < sorted_symcount; i++) | 1516 | 27.7k | { | 1517 | 27.7k | if (sym_ok (want_section, abfd, i, sec, inf)) | 1518 | 103 | { | 1519 | 103 | thisplace = i; | 1520 | 103 | break; | 1521 | 103 | } | 1522 | 27.7k | } | 1523 | 11.1k | } | 1524 | | | 1525 | 12.3k | if (! sym_ok (want_section, abfd, thisplace, sec, inf)) | 1526 | | /* There is no suitable symbol. */ | 1527 | 11.0k | return NULL; | 1528 | 12.3k | } | 1529 | | | 1530 | | /* If we have not found an exact match for the specified address | 1531 | | and we have dynamic relocations available, then we can produce | 1532 | | a better result by matching a relocation to the address and | 1533 | | using the symbol associated with that relocation. */ | 1534 | 16.2k | rel_count = inf->dynrelcount; | 1535 | 16.2k | if (!want_section | 1536 | 14.9k | && sorted_syms[thisplace]->value != vma | 1537 | 14.9k | && rel_count > 0 | 1538 | 8.52k | && inf->dynrelbuf != NULL | 1539 | 8.52k | && inf->dynrelbuf[0]->address <= vma | 1540 | 1.99k | && inf->dynrelbuf[rel_count - 1]->address >= vma | 1541 | | /* If we have matched a synthetic symbol, then stick with that. */ | 1542 | 803 | && (sorted_syms[thisplace]->flags & BSF_SYNTHETIC) == 0) | 1543 | 711 | { | 1544 | 711 | arelent ** rel_low; | 1545 | 711 | arelent ** rel_high; | 1546 | | | 1547 | 711 | rel_low = inf->dynrelbuf; | 1548 | 711 | rel_high = rel_low + rel_count - 1; | 1549 | 2.36k | while (rel_low <= rel_high) | 1550 | 2.36k | { | 1551 | 2.36k | arelent **rel_mid = &rel_low[(rel_high - rel_low) / 2]; | 1552 | 2.36k | arelent * rel = *rel_mid; | 1553 | | | 1554 | 2.36k | if (rel->address == vma) | 1555 | 352 | { | 1556 | | /* Absolute relocations do not provide a more helpful | 1557 | | symbolic address. Find a non-absolute relocation | 1558 | | with the same address. */ | 1559 | 352 | arelent **rel_vma = rel_mid; | 1560 | 352 | for (rel_mid--; | 1561 | 352 | rel_mid >= rel_low && rel_mid[0]->address == vma; | 1562 | 352 | rel_mid--) | 1563 | 0 | rel_vma = rel_mid; | 1564 | | | 1565 | 434 | for (; rel_vma <= rel_high && rel_vma[0]->address == vma; | 1566 | 352 | rel_vma++) | 1567 | 353 | { | 1568 | 353 | rel = *rel_vma; | 1569 | 353 | if (rel->sym_ptr_ptr != NULL | 1570 | 353 | && ! bfd_is_abs_section ((* rel->sym_ptr_ptr)->section)) | 1571 | 271 | { | 1572 | 271 | if (place != NULL) | 1573 | 271 | * place = thisplace; | 1574 | 271 | return * rel->sym_ptr_ptr; | 1575 | 271 | } | 1576 | 353 | } | 1577 | 81 | break; | 1578 | 352 | } | 1579 | | | 1580 | 2.00k | if (vma < rel->address) | 1581 | 573 | rel_high = rel_mid; | 1582 | 1.43k | else if (vma >= rel_mid[1]->address) | 1583 | 1.07k | rel_low = rel_mid + 1; | 1584 | 359 | else | 1585 | 359 | break; | 1586 | 2.00k | } | 1587 | 711 | } | 1588 | | | 1589 | 15.9k | if (place != NULL) | 1590 | 15.9k | *place = thisplace; | 1591 | | | 1592 | 15.9k | return sorted_syms[thisplace]; | 1593 | 16.2k | } |
Unexecuted instantiation: fuzz_dwarf.c:find_symbol_for_address |
1594 | | |
1595 | | /* Print an address and the offset to the nearest symbol. */ |
1596 | | |
1597 | | static void |
1598 | | objdump_print_addr_with_sym (bfd *abfd, asection *sec, asymbol *sym, |
1599 | | bfd_vma vma, struct disassemble_info *inf, |
1600 | | bool skip_zeroes) |
1601 | 123k | { |
1602 | 123k | if (!no_addresses) |
1603 | 123k | { |
1604 | 123k | objdump_print_value (vma, inf, skip_zeroes); |
1605 | 123k | (*inf->fprintf_styled_func) (inf->stream, dis_style_text, " "); |
1606 | 123k | } |
1607 | | |
1608 | 123k | if (sym == NULL) |
1609 | 92.9k | { |
1610 | 92.9k | bfd_vma secaddr; |
1611 | | |
1612 | 92.9k | (*inf->fprintf_styled_func) (inf->stream, dis_style_text,"<"); |
1613 | 92.9k | (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol, "%s", |
1614 | 92.9k | sanitize_string (bfd_section_name (sec))); |
1615 | 92.9k | secaddr = bfd_section_vma (sec); |
1616 | 92.9k | if (vma < secaddr) |
1617 | 0 | { |
1618 | 0 | (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate, |
1619 | 0 | "-0x"); |
1620 | 0 | objdump_print_value (secaddr - vma, inf, true); |
1621 | 0 | } |
1622 | 92.9k | else if (vma > secaddr) |
1623 | 7.63k | { |
1624 | 7.63k | (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate, "+0x"); |
1625 | 7.63k | objdump_print_value (vma - secaddr, inf, true); |
1626 | 7.63k | } |
1627 | 92.9k | (*inf->fprintf_styled_func) (inf->stream, dis_style_text, ">"); |
1628 | 92.9k | } |
1629 | 30.7k | else |
1630 | 30.7k | { |
1631 | 30.7k | (*inf->fprintf_styled_func) (inf->stream, dis_style_text, "<"); |
1632 | | |
1633 | 30.7k | objdump_print_symname (abfd, inf, sym); |
1634 | | |
1635 | 30.7k | if (bfd_asymbol_value (sym) == vma) |
1636 | 2.14k | ; |
1637 | | /* Undefined symbols in an executables and dynamic objects do not have |
1638 | | a value associated with them, so it does not make sense to display |
1639 | | an offset relative to them. Normally we would not be provided with |
1640 | | this kind of symbol, but the target backend might choose to do so, |
1641 | | and the code in find_symbol_for_address might return an as yet |
1642 | | unresolved symbol associated with a dynamic reloc. */ |
1643 | 28.6k | else if ((bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC)) |
1644 | 17.1k | && bfd_is_und_section (sym->section)) |
1645 | 226 | ; |
1646 | 28.4k | else if (bfd_asymbol_value (sym) > vma) |
1647 | 7.69k | { |
1648 | 7.69k | (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate,"-0x"); |
1649 | 7.69k | objdump_print_value (bfd_asymbol_value (sym) - vma, inf, true); |
1650 | 7.69k | } |
1651 | 20.7k | else if (vma > bfd_asymbol_value (sym)) |
1652 | 20.7k | { |
1653 | 20.7k | (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate, "+0x"); |
1654 | 20.7k | objdump_print_value (vma - bfd_asymbol_value (sym), inf, true); |
1655 | 20.7k | } |
1656 | | |
1657 | 30.7k | (*inf->fprintf_styled_func) (inf->stream, dis_style_text, ">"); |
1658 | 30.7k | } |
1659 | | |
1660 | 123k | if (display_file_offsets) |
1661 | 0 | inf->fprintf_styled_func (inf->stream, dis_style_text, |
1662 | 0 | _(" (File Offset: 0x%lx)"), |
1663 | 0 | (long int)(sec->filepos + (vma - sec->vma))); |
1664 | 123k | } fuzz_objdump.c:objdump_print_addr_with_sym Line | Count | Source | 1601 | 123k | { | 1602 | 123k | if (!no_addresses) | 1603 | 123k | { | 1604 | 123k | objdump_print_value (vma, inf, skip_zeroes); | 1605 | 123k | (*inf->fprintf_styled_func) (inf->stream, dis_style_text, " "); | 1606 | 123k | } | 1607 | | | 1608 | 123k | if (sym == NULL) | 1609 | 92.9k | { | 1610 | 92.9k | bfd_vma secaddr; | 1611 | | | 1612 | 92.9k | (*inf->fprintf_styled_func) (inf->stream, dis_style_text,"<"); | 1613 | 92.9k | (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol, "%s", | 1614 | 92.9k | sanitize_string (bfd_section_name (sec))); | 1615 | 92.9k | secaddr = bfd_section_vma (sec); | 1616 | 92.9k | if (vma < secaddr) | 1617 | 0 | { | 1618 | 0 | (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate, | 1619 | 0 | "-0x"); | 1620 | 0 | objdump_print_value (secaddr - vma, inf, true); | 1621 | 0 | } | 1622 | 92.9k | else if (vma > secaddr) | 1623 | 7.63k | { | 1624 | 7.63k | (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate, "+0x"); | 1625 | 7.63k | objdump_print_value (vma - secaddr, inf, true); | 1626 | 7.63k | } | 1627 | 92.9k | (*inf->fprintf_styled_func) (inf->stream, dis_style_text, ">"); | 1628 | 92.9k | } | 1629 | 30.7k | else | 1630 | 30.7k | { | 1631 | 30.7k | (*inf->fprintf_styled_func) (inf->stream, dis_style_text, "<"); | 1632 | | | 1633 | 30.7k | objdump_print_symname (abfd, inf, sym); | 1634 | | | 1635 | 30.7k | if (bfd_asymbol_value (sym) == vma) | 1636 | 2.14k | ; | 1637 | | /* Undefined symbols in an executables and dynamic objects do not have | 1638 | | a value associated with them, so it does not make sense to display | 1639 | | an offset relative to them. Normally we would not be provided with | 1640 | | this kind of symbol, but the target backend might choose to do so, | 1641 | | and the code in find_symbol_for_address might return an as yet | 1642 | | unresolved symbol associated with a dynamic reloc. */ | 1643 | 28.6k | else if ((bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC)) | 1644 | 17.1k | && bfd_is_und_section (sym->section)) | 1645 | 226 | ; | 1646 | 28.4k | else if (bfd_asymbol_value (sym) > vma) | 1647 | 7.69k | { | 1648 | 7.69k | (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate,"-0x"); | 1649 | 7.69k | objdump_print_value (bfd_asymbol_value (sym) - vma, inf, true); | 1650 | 7.69k | } | 1651 | 20.7k | else if (vma > bfd_asymbol_value (sym)) | 1652 | 20.7k | { | 1653 | 20.7k | (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate, "+0x"); | 1654 | 20.7k | objdump_print_value (vma - bfd_asymbol_value (sym), inf, true); | 1655 | 20.7k | } | 1656 | | | 1657 | 30.7k | (*inf->fprintf_styled_func) (inf->stream, dis_style_text, ">"); | 1658 | 30.7k | } | 1659 | | | 1660 | 123k | if (display_file_offsets) | 1661 | 0 | inf->fprintf_styled_func (inf->stream, dis_style_text, | 1662 | | _(" (File Offset: 0x%lx)"), | 1663 | 0 | (long int)(sec->filepos + (vma - sec->vma))); | 1664 | 123k | } |
Unexecuted instantiation: fuzz_dwarf.c:objdump_print_addr_with_sym |
1665 | | |
1666 | | /* Displays all symbols in the sorted symbol table starting at PLACE |
1667 | | which match the address VMA. Assumes that show_all_symbols == true. */ |
1668 | | |
1669 | | static void |
1670 | | display_extra_syms (long place, |
1671 | | bfd_vma vma, |
1672 | | struct disassemble_info *inf) |
1673 | 0 | { |
1674 | 0 | struct objdump_disasm_info *aux = (struct objdump_disasm_info *) inf->application_data; |
1675 | |
|
1676 | 0 | if (place == 0) |
1677 | 0 | return; |
1678 | | |
1679 | 0 | bool first = true; |
1680 | |
|
1681 | 0 | for (; place < sorted_symcount; place++) |
1682 | 0 | { |
1683 | 0 | asymbol *sym = sorted_syms[place]; |
1684 | | |
1685 | 0 | if (bfd_asymbol_value (sym) != vma) |
1686 | 0 | break; |
1687 | | |
1688 | 0 | if (! inf->symbol_is_valid (sym, inf)) |
1689 | 0 | continue; |
1690 | | |
1691 | 0 | if (first && ! do_wide) |
1692 | 0 | inf->fprintf_styled_func (inf->stream, dis_style_immediate, ",\n\t<"); |
1693 | 0 | else |
1694 | 0 | inf->fprintf_styled_func (inf->stream, dis_style_immediate, ", <"); |
1695 | |
|
1696 | 0 | objdump_print_symname (aux->abfd, inf, sym); |
1697 | 0 | inf->fprintf_styled_func (inf->stream, dis_style_immediate, ">"); |
1698 | 0 | first = false; |
1699 | 0 | } |
1700 | 0 | } Unexecuted instantiation: fuzz_objdump.c:display_extra_syms Unexecuted instantiation: fuzz_dwarf.c:display_extra_syms |
1701 | | |
1702 | | /* Print an address (VMA), symbolically if possible. |
1703 | | If SKIP_ZEROES is TRUE, don't output leading zeroes. */ |
1704 | | |
1705 | | static void |
1706 | | objdump_print_addr (bfd_vma vma, |
1707 | | struct disassemble_info *inf, |
1708 | | bool skip_zeroes) |
1709 | 7.31M | { |
1710 | 7.31M | struct objdump_disasm_info *aux; |
1711 | 7.31M | asymbol *sym = NULL; |
1712 | 7.31M | bool skip_find = false; |
1713 | 7.31M | long place = 0; |
1714 | | |
1715 | 7.31M | aux = (struct objdump_disasm_info *) inf->application_data; |
1716 | | |
1717 | 7.31M | if (sorted_symcount < 1) |
1718 | 7.27M | { |
1719 | 7.27M | if (!no_addresses) |
1720 | 7.27M | { |
1721 | 7.27M | (*inf->fprintf_styled_func) (inf->stream, dis_style_address, "0x"); |
1722 | 7.27M | objdump_print_value (vma, inf, skip_zeroes); |
1723 | 7.27M | } |
1724 | | |
1725 | 7.27M | if (display_file_offsets) |
1726 | 0 | inf->fprintf_styled_func (inf->stream, dis_style_text, |
1727 | 0 | _(" (File Offset: 0x%lx)"), |
1728 | 0 | (long int) (inf->section->filepos |
1729 | 0 | + (vma - inf->section->vma))); |
1730 | 7.27M | return; |
1731 | 7.27M | } |
1732 | | |
1733 | 36.7k | if (aux->reloc != NULL |
1734 | 91 | && aux->reloc->sym_ptr_ptr != NULL |
1735 | 91 | && * aux->reloc->sym_ptr_ptr != NULL) |
1736 | 91 | { |
1737 | 91 | sym = * aux->reloc->sym_ptr_ptr; |
1738 | | |
1739 | | /* Adjust the vma to the reloc. */ |
1740 | 91 | vma += bfd_asymbol_value (sym); |
1741 | | |
1742 | 91 | if (bfd_is_und_section (bfd_asymbol_section (sym))) |
1743 | 0 | skip_find = true; |
1744 | 91 | } |
1745 | | |
1746 | 36.7k | if (!skip_find) |
1747 | 36.7k | sym = find_symbol_for_address (vma, inf, &place); |
1748 | | |
1749 | 36.7k | objdump_print_addr_with_sym (aux->abfd, inf->section, sym, vma, inf, |
1750 | 36.7k | skip_zeroes); |
1751 | | |
1752 | | /* If requested, display any extra symbols at this address. */ |
1753 | 36.7k | if (sym == NULL || ! show_all_symbols) |
1754 | 36.7k | return; |
1755 | | |
1756 | 0 | if (place) |
1757 | 0 | display_extra_syms (place + 1, vma, inf); |
1758 | | |
1759 | | /* If we found an absolute symbol in the reloc (ie: "*ABS*+0x....") |
1760 | | and there is a valid symbol at the address contained in the absolute symbol |
1761 | | then display any extra symbols that match this address. This helps |
1762 | | particularly with relocations for PLT entries. */ |
1763 | 0 | if (startswith (sym->name, BFD_ABS_SECTION_NAME "+")) |
1764 | 0 | { |
1765 | 0 | bfd_vma addr = strtoul (sym->name + strlen (BFD_ABS_SECTION_NAME "+"), NULL, 0); |
1766 | |
|
1767 | 0 | if (addr && addr != vma) |
1768 | 0 | { |
1769 | 0 | sym = find_symbol_for_address (addr, inf, &place); |
1770 | |
|
1771 | 0 | if (sym) |
1772 | 0 | display_extra_syms (place, addr, inf); |
1773 | 0 | } |
1774 | 0 | } |
1775 | 0 | } fuzz_objdump.c:objdump_print_addr Line | Count | Source | 1709 | 7.31M | { | 1710 | 7.31M | struct objdump_disasm_info *aux; | 1711 | 7.31M | asymbol *sym = NULL; | 1712 | 7.31M | bool skip_find = false; | 1713 | 7.31M | long place = 0; | 1714 | | | 1715 | 7.31M | aux = (struct objdump_disasm_info *) inf->application_data; | 1716 | | | 1717 | 7.31M | if (sorted_symcount < 1) | 1718 | 7.27M | { | 1719 | 7.27M | if (!no_addresses) | 1720 | 7.27M | { | 1721 | 7.27M | (*inf->fprintf_styled_func) (inf->stream, dis_style_address, "0x"); | 1722 | 7.27M | objdump_print_value (vma, inf, skip_zeroes); | 1723 | 7.27M | } | 1724 | | | 1725 | 7.27M | if (display_file_offsets) | 1726 | 0 | inf->fprintf_styled_func (inf->stream, dis_style_text, | 1727 | 0 | _(" (File Offset: 0x%lx)"), | 1728 | 0 | (long int) (inf->section->filepos | 1729 | 0 | + (vma - inf->section->vma))); | 1730 | 7.27M | return; | 1731 | 7.27M | } | 1732 | | | 1733 | 36.7k | if (aux->reloc != NULL | 1734 | 91 | && aux->reloc->sym_ptr_ptr != NULL | 1735 | 91 | && * aux->reloc->sym_ptr_ptr != NULL) | 1736 | 91 | { | 1737 | 91 | sym = * aux->reloc->sym_ptr_ptr; | 1738 | | | 1739 | | /* Adjust the vma to the reloc. */ | 1740 | 91 | vma += bfd_asymbol_value (sym); | 1741 | | | 1742 | 91 | if (bfd_is_und_section (bfd_asymbol_section (sym))) | 1743 | 0 | skip_find = true; | 1744 | 91 | } | 1745 | | | 1746 | 36.7k | if (!skip_find) | 1747 | 36.7k | sym = find_symbol_for_address (vma, inf, &place); | 1748 | | | 1749 | 36.7k | objdump_print_addr_with_sym (aux->abfd, inf->section, sym, vma, inf, | 1750 | 36.7k | skip_zeroes); | 1751 | | | 1752 | | /* If requested, display any extra symbols at this address. */ | 1753 | 36.7k | if (sym == NULL || ! show_all_symbols) | 1754 | 36.7k | return; | 1755 | | | 1756 | 0 | if (place) | 1757 | 0 | display_extra_syms (place + 1, vma, inf); | 1758 | | | 1759 | | /* If we found an absolute symbol in the reloc (ie: "*ABS*+0x....") | 1760 | | and there is a valid symbol at the address contained in the absolute symbol | 1761 | | then display any extra symbols that match this address. This helps | 1762 | | particularly with relocations for PLT entries. */ | 1763 | 0 | if (startswith (sym->name, BFD_ABS_SECTION_NAME "+")) | 1764 | 0 | { | 1765 | 0 | bfd_vma addr = strtoul (sym->name + strlen (BFD_ABS_SECTION_NAME "+"), NULL, 0); | 1766 | |
| 1767 | 0 | if (addr && addr != vma) | 1768 | 0 | { | 1769 | 0 | sym = find_symbol_for_address (addr, inf, &place); | 1770 | |
| 1771 | 0 | if (sym) | 1772 | 0 | display_extra_syms (place, addr, inf); | 1773 | 0 | } | 1774 | 0 | } | 1775 | 0 | } |
Unexecuted instantiation: fuzz_dwarf.c:objdump_print_addr |
1776 | | |
1777 | | /* Print VMA to INFO. This function is passed to the disassembler |
1778 | | routine. */ |
1779 | | |
1780 | | static void |
1781 | | objdump_print_address (bfd_vma vma, struct disassemble_info *inf) |
1782 | 7.31M | { |
1783 | 7.31M | objdump_print_addr (vma, inf, ! prefix_addresses); |
1784 | 7.31M | } fuzz_objdump.c:objdump_print_address Line | Count | Source | 1782 | 7.31M | { | 1783 | 7.31M | objdump_print_addr (vma, inf, ! prefix_addresses); | 1784 | 7.31M | } |
Unexecuted instantiation: fuzz_dwarf.c:objdump_print_address |
1785 | | |
1786 | | /* Determine if the given address has a symbol associated with it. */ |
1787 | | |
1788 | | static asymbol * |
1789 | | objdump_symbol_at_address (bfd_vma vma, struct disassemble_info * inf) |
1790 | 384k | { |
1791 | 384k | asymbol * sym; |
1792 | | |
1793 | 384k | sym = find_symbol_for_address (vma, inf, NULL); |
1794 | 384k | if (sym != NULL && bfd_asymbol_value (sym) == vma) |
1795 | 6 | return sym; |
1796 | | |
1797 | 384k | return NULL; |
1798 | 384k | } fuzz_objdump.c:objdump_symbol_at_address Line | Count | Source | 1790 | 384k | { | 1791 | 384k | asymbol * sym; | 1792 | | | 1793 | 384k | sym = find_symbol_for_address (vma, inf, NULL); | 1794 | 384k | if (sym != NULL && bfd_asymbol_value (sym) == vma) | 1795 | 6 | return sym; | 1796 | | | 1797 | 384k | return NULL; | 1798 | 384k | } |
Unexecuted instantiation: fuzz_dwarf.c:objdump_symbol_at_address |
1799 | | |
1800 | | /* Hold the last function name and the last line number we displayed |
1801 | | in a disassembly. */ |
1802 | | |
1803 | | static char *prev_functionname; |
1804 | | static unsigned int prev_line; |
1805 | | static unsigned int prev_discriminator; |
1806 | | |
1807 | | /* We keep a list of all files that we have seen when doing a |
1808 | | disassembly with source, so that we know how much of the file to |
1809 | | display. This can be important for inlined functions. */ |
1810 | | |
1811 | | struct print_file_list |
1812 | | { |
1813 | | struct print_file_list *next; |
1814 | | const char *filename; |
1815 | | const char *modname; |
1816 | | const char *map; |
1817 | | size_t mapsize; |
1818 | | const char **linemap; |
1819 | | unsigned maxline; |
1820 | | unsigned last_line; |
1821 | | unsigned max_printed; |
1822 | | int first; |
1823 | | }; |
1824 | | |
1825 | | static struct print_file_list *print_files; |
1826 | | |
1827 | | /* The number of preceding context lines to show when we start |
1828 | | displaying a file for the first time. */ |
1829 | | |
1830 | 0 | #define SHOW_PRECEDING_CONTEXT_LINES (5) |
1831 | | |
1832 | | #if HAVE_LIBDEBUGINFOD |
1833 | | /* Return a hex string represention of the build-id. */ |
1834 | | |
1835 | | unsigned char * |
1836 | | get_build_id (void * data) |
1837 | | { |
1838 | | unsigned i; |
1839 | | char * build_id_str; |
1840 | | bfd * abfd = (bfd *) data; |
1841 | | const struct bfd_build_id * build_id; |
1842 | | |
1843 | | build_id = abfd->build_id; |
1844 | | if (build_id == NULL) |
1845 | | return NULL; |
1846 | | |
1847 | | build_id_str = malloc (build_id->size * 2 + 1); |
1848 | | if (build_id_str == NULL) |
1849 | | return NULL; |
1850 | | |
1851 | | for (i = 0; i < build_id->size; i++) |
1852 | | sprintf (build_id_str + (i * 2), "%02x", build_id->data[i]); |
1853 | | build_id_str[build_id->size * 2] = '\0'; |
1854 | | |
1855 | | return (unsigned char *) build_id_str; |
1856 | | } |
1857 | | |
1858 | | /* Search for a separate debug file matching ABFD's build-id. */ |
1859 | | |
1860 | | static bfd * |
1861 | | find_separate_debug (const bfd * abfd) |
1862 | | { |
1863 | | const struct bfd_build_id * build_id = abfd->build_id; |
1864 | | separate_info * i = first_separate_info; |
1865 | | |
1866 | | if (build_id == NULL || i == NULL) |
1867 | | return NULL; |
1868 | | |
1869 | | while (i != NULL) |
1870 | | { |
1871 | | const bfd * i_bfd = (bfd *) i->handle; |
1872 | | |
1873 | | if (abfd != NULL && i_bfd->build_id != NULL) |
1874 | | { |
1875 | | const unsigned char * data = i_bfd->build_id->data; |
1876 | | size_t size = i_bfd->build_id->size; |
1877 | | |
1878 | | if (size == build_id->size |
1879 | | && memcmp (data, build_id->data, size) == 0) |
1880 | | return (bfd *) i->handle; |
1881 | | } |
1882 | | |
1883 | | i = i->next; |
1884 | | } |
1885 | | |
1886 | | return NULL; |
1887 | | } |
1888 | | |
1889 | | /* Search for a separate debug file matching ABFD's .gnu_debugaltlink |
1890 | | build-id. */ |
1891 | | |
1892 | | static bfd * |
1893 | | find_alt_debug (const bfd * abfd) |
1894 | | { |
1895 | | size_t namelen; |
1896 | | size_t id_len; |
1897 | | const char * name; |
1898 | | struct dwarf_section * section; |
1899 | | const struct bfd_build_id * build_id = abfd->build_id; |
1900 | | separate_info * i = first_separate_info; |
1901 | | |
1902 | | if (i == NULL |
1903 | | || build_id == NULL |
1904 | | || !load_debug_section (gnu_debugaltlink, (void *) abfd)) |
1905 | | return NULL; |
1906 | | |
1907 | | section = &debug_displays[gnu_debugaltlink].section; |
1908 | | if (section == NULL) |
1909 | | return NULL; |
1910 | | |
1911 | | name = (const char *) section->start; |
1912 | | namelen = strnlen (name, section->size) + 1; |
1913 | | if (namelen == 1) |
1914 | | return NULL; |
1915 | | if (namelen >= section->size) |
1916 | | return NULL; |
1917 | | |
1918 | | id_len = section->size - namelen; |
1919 | | if (id_len < 0x14) |
1920 | | return NULL; |
1921 | | |
1922 | | /* Compare the .gnu_debugaltlink build-id with the build-ids of the |
1923 | | known separate_info files. */ |
1924 | | while (i != NULL) |
1925 | | { |
1926 | | const bfd * i_bfd = (bfd *) i->handle; |
1927 | | |
1928 | | if (i_bfd != NULL && i_bfd->build_id != NULL) |
1929 | | { |
1930 | | const unsigned char * data = i_bfd->build_id->data; |
1931 | | size_t size = i_bfd->build_id->size; |
1932 | | |
1933 | | if (id_len == size |
1934 | | && memcmp (section->start + namelen, data, size) == 0) |
1935 | | return (bfd *) i->handle; |
1936 | | } |
1937 | | |
1938 | | i = i->next; |
1939 | | } |
1940 | | |
1941 | | return NULL; |
1942 | | } |
1943 | | |
1944 | | #endif /* HAVE_LIBDEBUGINFOD */ |
1945 | | |
1946 | | /* Reads the contents of file FN into memory. Returns a pointer to the buffer. |
1947 | | Also returns the size of the buffer in SIZE_RETURN and a filled out |
1948 | | stat structure in FST_RETURN. Returns NULL upon failure. */ |
1949 | | |
1950 | | static const char * |
1951 | | slurp_file (const char * fn, |
1952 | | size_t * size_return, |
1953 | | struct stat * fst_return, |
1954 | | bfd * abfd ATTRIBUTE_UNUSED) |
1955 | 0 | { |
1956 | 0 | #ifdef HAVE_MMAP |
1957 | 0 | int ps; |
1958 | 0 | size_t msize; |
1959 | 0 | #endif |
1960 | 0 | const char *map; |
1961 | 0 | int fd; |
1962 | | |
1963 | | /* Paranoia. */ |
1964 | 0 | if (fn == NULL || * fn == 0 || size_return == NULL || fst_return == NULL) |
1965 | 0 | return NULL; |
1966 | | |
1967 | 0 | fd = open (fn, O_RDONLY | O_BINARY); |
1968 | |
|
1969 | | #if HAVE_LIBDEBUGINFOD |
1970 | | if (fd < 0 && use_debuginfod && fn[0] == '/' && abfd != NULL) |
1971 | | { |
1972 | | unsigned char *build_id = get_build_id (abfd); |
1973 | | |
1974 | | if (build_id) |
1975 | | { |
1976 | | debuginfod_client *client = debuginfod_begin (); |
1977 | | |
1978 | | if (client) |
1979 | | { |
1980 | | fd = debuginfod_find_source (client, build_id, 0, fn, NULL); |
1981 | | debuginfod_end (client); |
1982 | | } |
1983 | | free (build_id); |
1984 | | } |
1985 | | } |
1986 | | #endif |
1987 | |
|
1988 | 0 | if (fd < 0) |
1989 | 0 | return NULL; |
1990 | | |
1991 | 0 | if (fstat (fd, fst_return) < 0) |
1992 | 0 | { |
1993 | 0 | close (fd); |
1994 | 0 | return NULL; |
1995 | 0 | } |
1996 | | |
1997 | 0 | *size_return = fst_return->st_size; |
1998 | |
|
1999 | 0 | #ifdef HAVE_MMAP |
2000 | 0 | ps = getpagesize (); |
2001 | 0 | msize = (*size_return + ps - 1) & ~(ps - 1); |
2002 | 0 | map = mmap (NULL, msize, PROT_READ, MAP_SHARED, fd, 0); |
2003 | 0 | if (map != (char *) -1L) |
2004 | 0 | { |
2005 | 0 | close (fd); |
2006 | 0 | return map; |
2007 | 0 | } |
2008 | 0 | #endif |
2009 | | |
2010 | 0 | map = (const char *) malloc (*size_return); |
2011 | 0 | if (!map || (size_t) read (fd, (char *) map, *size_return) != *size_return) |
2012 | 0 | { |
2013 | 0 | free ((void *) map); |
2014 | 0 | map = NULL; |
2015 | 0 | } |
2016 | 0 | close (fd); |
2017 | 0 | return map; |
2018 | 0 | } Unexecuted instantiation: fuzz_objdump.c:slurp_file Unexecuted instantiation: fuzz_dwarf.c:slurp_file |
2019 | | |
2020 | 0 | #define line_map_decrease 5 |
2021 | | |
2022 | | /* Precompute array of lines for a mapped file. */ |
2023 | | |
2024 | | static const char ** |
2025 | | index_file (const char *map, size_t size, unsigned int *maxline) |
2026 | 0 | { |
2027 | 0 | const char *p, *lstart, *end; |
2028 | 0 | int chars_per_line = 45; /* First iteration will use 40. */ |
2029 | 0 | unsigned int lineno; |
2030 | 0 | const char **linemap = NULL; |
2031 | 0 | unsigned long line_map_size = 0; |
2032 | |
|
2033 | 0 | lineno = 0; |
2034 | 0 | lstart = map; |
2035 | 0 | end = map + size; |
2036 | |
|
2037 | 0 | for (p = map; p < end; p++) |
2038 | 0 | { |
2039 | 0 | if (*p == '\n') |
2040 | 0 | { |
2041 | 0 | if (p + 1 < end && p[1] == '\r') |
2042 | 0 | p++; |
2043 | 0 | } |
2044 | 0 | else if (*p == '\r') |
2045 | 0 | { |
2046 | 0 | if (p + 1 < end && p[1] == '\n') |
2047 | 0 | p++; |
2048 | 0 | } |
2049 | 0 | else |
2050 | 0 | continue; |
2051 | | |
2052 | | /* End of line found. */ |
2053 | | |
2054 | 0 | if (linemap == NULL || line_map_size < lineno + 1) |
2055 | 0 | { |
2056 | 0 | unsigned long newsize; |
2057 | |
|
2058 | 0 | chars_per_line -= line_map_decrease; |
2059 | 0 | if (chars_per_line <= 1) |
2060 | 0 | chars_per_line = 1; |
2061 | 0 | line_map_size = size / chars_per_line + 1; |
2062 | 0 | if (line_map_size < lineno + 1) |
2063 | 0 | line_map_size = lineno + 1; |
2064 | 0 | newsize = line_map_size * sizeof (char *); |
2065 | 0 | linemap = (const char **) xrealloc (linemap, newsize); |
2066 | 0 | } |
2067 | |
|
2068 | 0 | linemap[lineno++] = lstart; |
2069 | 0 | lstart = p + 1; |
2070 | 0 | } |
2071 | |
|
2072 | 0 | *maxline = lineno; |
2073 | 0 | return linemap; |
2074 | 0 | } Unexecuted instantiation: fuzz_objdump.c:index_file Unexecuted instantiation: fuzz_dwarf.c:index_file |
2075 | | |
2076 | | /* Tries to open MODNAME, and if successful adds a node to print_files |
2077 | | linked list and returns that node. Also fills in the stat structure |
2078 | | pointed to by FST_RETURN. Returns NULL on failure. */ |
2079 | | |
2080 | | static struct print_file_list * |
2081 | | try_print_file_open (const char * origname, |
2082 | | const char * modname, |
2083 | | struct stat * fst_return, |
2084 | | bfd * abfd) |
2085 | 0 | { |
2086 | 0 | struct print_file_list *p; |
2087 | |
|
2088 | 0 | p = (struct print_file_list *) xmalloc (sizeof (struct print_file_list)); |
2089 | |
|
2090 | 0 | p->map = slurp_file (modname, &p->mapsize, fst_return, abfd); |
2091 | 0 | if (p->map == NULL) |
2092 | 0 | { |
2093 | 0 | free (p); |
2094 | 0 | return NULL; |
2095 | 0 | } |
2096 | | |
2097 | 0 | p->linemap = index_file (p->map, p->mapsize, &p->maxline); |
2098 | 0 | p->last_line = 0; |
2099 | 0 | p->max_printed = 0; |
2100 | 0 | p->filename = origname; |
2101 | 0 | p->modname = modname; |
2102 | 0 | p->next = print_files; |
2103 | 0 | p->first = 1; |
2104 | 0 | print_files = p; |
2105 | 0 | return p; |
2106 | 0 | } Unexecuted instantiation: fuzz_objdump.c:try_print_file_open Unexecuted instantiation: fuzz_dwarf.c:try_print_file_open |
2107 | | |
2108 | | /* If the source file, as described in the symtab, is not found |
2109 | | try to locate it in one of the paths specified with -I |
2110 | | If found, add location to print_files linked list. */ |
2111 | | |
2112 | | static struct print_file_list * |
2113 | | update_source_path (const char *filename, bfd *abfd) |
2114 | 0 | { |
2115 | 0 | struct print_file_list *p; |
2116 | 0 | const char *fname; |
2117 | 0 | struct stat fst; |
2118 | 0 | int i; |
2119 | |
|
2120 | 0 | p = try_print_file_open (filename, filename, &fst, abfd); |
2121 | 0 | if (p == NULL) |
2122 | 0 | { |
2123 | 0 | if (include_path_count == 0) |
2124 | 0 | return NULL; |
2125 | | |
2126 | | /* Get the name of the file. */ |
2127 | 0 | fname = lbasename (filename); |
2128 | | |
2129 | | /* If file exists under a new path, we need to add it to the list |
2130 | | so that show_line knows about it. */ |
2131 | 0 | for (i = 0; i < include_path_count; i++) |
2132 | 0 | { |
2133 | 0 | char *modname = concat (include_paths[i], "/", fname, |
2134 | 0 | (const char *) 0); |
2135 | |
|
2136 | 0 | p = try_print_file_open (filename, modname, &fst, abfd); |
2137 | 0 | if (p) |
2138 | 0 | break; |
2139 | | |
2140 | 0 | free (modname); |
2141 | 0 | } |
2142 | 0 | } |
2143 | | |
2144 | 0 | if (p != NULL) |
2145 | 0 | { |
2146 | 0 | long mtime = bfd_get_mtime (abfd); |
2147 | |
|
2148 | 0 | if (fst.st_mtime > mtime) |
2149 | 0 | warn (_("source file %s is more recent than object file\n"), |
2150 | 0 | filename); |
2151 | 0 | } |
2152 | |
|
2153 | 0 | return p; |
2154 | 0 | } Unexecuted instantiation: fuzz_objdump.c:update_source_path Unexecuted instantiation: fuzz_dwarf.c:update_source_path |
2155 | | |
2156 | | /* Print a source file line. */ |
2157 | | |
2158 | | static void |
2159 | | print_line (struct print_file_list *p, unsigned int linenum) |
2160 | 0 | { |
2161 | 0 | const char *l; |
2162 | 0 | size_t len; |
2163 | |
|
2164 | 0 | if (linenum >= p->maxline) |
2165 | 0 | return; |
2166 | 0 | l = p->linemap [linenum]; |
2167 | 0 | if (source_comment != NULL && strlen (l) > 0) |
2168 | 0 | printf ("%s", source_comment); |
2169 | 0 | len = strcspn (l, "\n\r"); |
2170 | | /* Test fwrite return value to quiet glibc warning. */ |
2171 | 0 | if (len == 0 || fwrite (l, len, 1, stdout) == 1) |
2172 | 0 | putchar ('\n'); |
2173 | 0 | } Unexecuted instantiation: fuzz_objdump.c:print_line Unexecuted instantiation: fuzz_dwarf.c:print_line |
2174 | | |
2175 | | /* Print a range of source code lines. */ |
2176 | | |
2177 | | static void |
2178 | | dump_lines (struct print_file_list *p, unsigned int start, unsigned int end) |
2179 | 0 | { |
2180 | 0 | if (p->map == NULL) |
2181 | 0 | return; |
2182 | 0 | if (start != 0) |
2183 | 0 | --start; |
2184 | 0 | while (start < end) |
2185 | 0 | { |
2186 | 0 | print_line (p, start); |
2187 | 0 | start++; |
2188 | 0 | } |
2189 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_lines Unexecuted instantiation: fuzz_dwarf.c:dump_lines |
2190 | | |
2191 | | /* Show the line number, or the source line, in a disassembly |
2192 | | listing. */ |
2193 | | |
2194 | | static void |
2195 | | show_line (bfd *abfd, asection *section, bfd_vma addr_offset) |
2196 | 0 | { |
2197 | 0 | const char *filename; |
2198 | 0 | const char *functionname; |
2199 | 0 | unsigned int linenumber; |
2200 | 0 | unsigned int discriminator; |
2201 | 0 | bool reloc; |
2202 | 0 | char *path = NULL; |
2203 | |
|
2204 | 0 | if (! with_line_numbers && ! with_source_code) |
2205 | 0 | return; |
2206 | | |
2207 | | #ifdef HAVE_LIBDEBUGINFOD |
2208 | | { |
2209 | | bfd *debug_bfd; |
2210 | | const char *alt_filename = NULL; |
2211 | | |
2212 | | if (use_debuginfod) |
2213 | | { |
2214 | | bfd *alt_bfd; |
2215 | | |
2216 | | /* PR 29075: Check for separate debuginfo and .gnu_debugaltlink files. |
2217 | | They need to be passed to bfd_find_nearest_line_with_alt in case they |
2218 | | were downloaded from debuginfod. Otherwise libbfd will attempt to |
2219 | | search for them and fail to locate them. */ |
2220 | | debug_bfd = find_separate_debug (abfd); |
2221 | | if (debug_bfd == NULL) |
2222 | | debug_bfd = abfd; |
2223 | | |
2224 | | alt_bfd = find_alt_debug (debug_bfd); |
2225 | | if (alt_bfd != NULL) |
2226 | | alt_filename = bfd_get_filename (alt_bfd); |
2227 | | } |
2228 | | else |
2229 | | debug_bfd = abfd; |
2230 | | |
2231 | | bfd_set_error (bfd_error_no_error); |
2232 | | if (! bfd_find_nearest_line_with_alt (debug_bfd, alt_filename, |
2233 | | section, syms, |
2234 | | addr_offset, &filename, |
2235 | | &functionname, &linenumber, |
2236 | | &discriminator)) |
2237 | | { |
2238 | | if (bfd_get_error () == bfd_error_no_error) |
2239 | | return; |
2240 | | if (! bfd_find_nearest_line_discriminator (abfd, section, syms, |
2241 | | addr_offset, &filename, |
2242 | | &functionname, &linenumber, |
2243 | | &discriminator)) |
2244 | | return; |
2245 | | } |
2246 | | } |
2247 | | #else |
2248 | 0 | if (! bfd_find_nearest_line_discriminator (abfd, section, syms, addr_offset, |
2249 | 0 | &filename, &functionname, |
2250 | 0 | &linenumber, &discriminator)) |
2251 | 0 | return; |
2252 | 0 | #endif |
2253 | | |
2254 | 0 | if (filename != NULL && *filename == '\0') |
2255 | 0 | filename = NULL; |
2256 | 0 | if (functionname != NULL && *functionname == '\0') |
2257 | 0 | functionname = NULL; |
2258 | |
|
2259 | 0 | if (filename |
2260 | 0 | && IS_ABSOLUTE_PATH (filename) |
2261 | 0 | && prefix) |
2262 | 0 | { |
2263 | 0 | char *path_up; |
2264 | 0 | const char *fname = filename; |
2265 | |
|
2266 | 0 | path = xmalloc (prefix_length + 1 + strlen (filename)); |
2267 | |
|
2268 | 0 | if (prefix_length) |
2269 | 0 | memcpy (path, prefix, prefix_length); |
2270 | 0 | path_up = path + prefix_length; |
2271 | | |
2272 | | /* Build relocated filename, stripping off leading directories |
2273 | | from the initial filename if requested. */ |
2274 | 0 | if (prefix_strip > 0) |
2275 | 0 | { |
2276 | 0 | int level = 0; |
2277 | 0 | const char *s; |
2278 | | |
2279 | | /* Skip selected directory levels. */ |
2280 | 0 | for (s = fname + 1; *s != '\0' && level < prefix_strip; s++) |
2281 | 0 | if (IS_DIR_SEPARATOR (*s)) |
2282 | 0 | { |
2283 | 0 | fname = s; |
2284 | 0 | level++; |
2285 | 0 | } |
2286 | 0 | } |
2287 | | |
2288 | | /* Update complete filename. */ |
2289 | 0 | strcpy (path_up, fname); |
2290 | |
|
2291 | 0 | filename = path; |
2292 | 0 | reloc = true; |
2293 | 0 | } |
2294 | 0 | else |
2295 | 0 | reloc = false; |
2296 | |
|
2297 | 0 | if (with_line_numbers) |
2298 | 0 | { |
2299 | 0 | if (functionname != NULL |
2300 | 0 | && (prev_functionname == NULL |
2301 | 0 | || strcmp (functionname, prev_functionname) != 0)) |
2302 | 0 | { |
2303 | 0 | char *demangle_alloc = NULL; |
2304 | 0 | if (do_demangle && functionname[0] != '\0') |
2305 | 0 | { |
2306 | | /* Demangle the name. */ |
2307 | 0 | demangle_alloc = bfd_demangle (abfd, functionname, |
2308 | 0 | demangle_flags); |
2309 | 0 | } |
2310 | | |
2311 | | /* Demangling adds trailing parens, so don't print those. */ |
2312 | 0 | if (demangle_alloc != NULL) |
2313 | 0 | printf ("%s:\n", sanitize_string (demangle_alloc)); |
2314 | 0 | else |
2315 | 0 | printf ("%s():\n", sanitize_string (functionname)); |
2316 | |
|
2317 | 0 | prev_line = -1; |
2318 | 0 | free (demangle_alloc); |
2319 | 0 | } |
2320 | 0 | if (linenumber > 0 |
2321 | 0 | && (linenumber != prev_line |
2322 | 0 | || discriminator != prev_discriminator)) |
2323 | 0 | { |
2324 | 0 | if (discriminator > 0) |
2325 | 0 | printf ("%s:%u (discriminator %u)\n", |
2326 | 0 | filename == NULL ? "???" : sanitize_string (filename), |
2327 | 0 | linenumber, discriminator); |
2328 | 0 | else |
2329 | 0 | printf ("%s:%u\n", filename == NULL |
2330 | 0 | ? "???" : sanitize_string (filename), |
2331 | 0 | linenumber); |
2332 | 0 | } |
2333 | 0 | if (unwind_inlines) |
2334 | 0 | { |
2335 | 0 | const char *filename2; |
2336 | 0 | const char *functionname2; |
2337 | 0 | unsigned line2; |
2338 | |
|
2339 | 0 | while (bfd_find_inliner_info (abfd, &filename2, &functionname2, |
2340 | 0 | &line2)) |
2341 | 0 | { |
2342 | 0 | printf ("inlined by %s:%u", |
2343 | 0 | sanitize_string (filename2), line2); |
2344 | 0 | printf (" (%s)\n", sanitize_string (functionname2)); |
2345 | 0 | } |
2346 | 0 | } |
2347 | 0 | } |
2348 | |
|
2349 | 0 | if (with_source_code |
2350 | 0 | && filename != NULL |
2351 | 0 | && linenumber > 0) |
2352 | 0 | { |
2353 | 0 | struct print_file_list **pp, *p; |
2354 | 0 | unsigned l; |
2355 | |
|
2356 | 0 | for (pp = &print_files; *pp != NULL; pp = &(*pp)->next) |
2357 | 0 | if (filename_cmp ((*pp)->filename, filename) == 0) |
2358 | 0 | break; |
2359 | 0 | p = *pp; |
2360 | |
|
2361 | 0 | if (p == NULL) |
2362 | 0 | { |
2363 | 0 | if (reloc) |
2364 | 0 | filename = xstrdup (filename); |
2365 | 0 | p = update_source_path (filename, abfd); |
2366 | 0 | } |
2367 | |
|
2368 | 0 | if (p != NULL && linenumber != p->last_line) |
2369 | 0 | { |
2370 | 0 | if (file_start_context && p->first) |
2371 | 0 | l = 1; |
2372 | 0 | else |
2373 | 0 | { |
2374 | 0 | l = linenumber - SHOW_PRECEDING_CONTEXT_LINES; |
2375 | 0 | if (l >= linenumber) |
2376 | 0 | l = 1; |
2377 | 0 | if (p->max_printed >= l) |
2378 | 0 | { |
2379 | 0 | if (p->max_printed < linenumber) |
2380 | 0 | l = p->max_printed + 1; |
2381 | 0 | else |
2382 | 0 | l = linenumber; |
2383 | 0 | } |
2384 | 0 | } |
2385 | 0 | dump_lines (p, l, linenumber); |
2386 | 0 | if (p->max_printed < linenumber) |
2387 | 0 | p->max_printed = linenumber; |
2388 | 0 | p->last_line = linenumber; |
2389 | 0 | p->first = 0; |
2390 | 0 | } |
2391 | 0 | } |
2392 | |
|
2393 | 0 | if (functionname != NULL |
2394 | 0 | && (prev_functionname == NULL |
2395 | 0 | || strcmp (functionname, prev_functionname) != 0)) |
2396 | 0 | { |
2397 | 0 | if (prev_functionname != NULL) |
2398 | 0 | free (prev_functionname); |
2399 | 0 | prev_functionname = (char *) xmalloc (strlen (functionname) + 1); |
2400 | 0 | strcpy (prev_functionname, functionname); |
2401 | 0 | } |
2402 | |
|
2403 | 0 | if (linenumber > 0 && linenumber != prev_line) |
2404 | 0 | prev_line = linenumber; |
2405 | |
|
2406 | 0 | if (discriminator != prev_discriminator) |
2407 | 0 | prev_discriminator = discriminator; |
2408 | |
|
2409 | 0 | if (path) |
2410 | 0 | free (path); |
2411 | 0 | } Unexecuted instantiation: fuzz_objdump.c:show_line Unexecuted instantiation: fuzz_dwarf.c:show_line |
2412 | | |
2413 | | /* Pseudo FILE object for strings. */ |
2414 | | typedef struct |
2415 | | { |
2416 | | char *buffer; |
2417 | | size_t pos; |
2418 | | size_t alloc; |
2419 | | } SFILE; |
2420 | | |
2421 | | /* sprintf to a "stream". */ |
2422 | | |
2423 | | static int ATTRIBUTE_PRINTF_2 |
2424 | | objdump_sprintf (SFILE *f, const char *format, ...) |
2425 | 198M | { |
2426 | 198M | size_t n; |
2427 | 198M | va_list args; |
2428 | | |
2429 | 198M | while (1) |
2430 | 198M | { |
2431 | 198M | size_t space = f->alloc - f->pos; |
2432 | | |
2433 | 198M | va_start (args, format); |
2434 | 198M | n = vsnprintf (f->buffer + f->pos, space, format, args); |
2435 | 198M | va_end (args); |
2436 | | |
2437 | 198M | if (space > n) |
2438 | 198M | break; |
2439 | | |
2440 | 592 | f->alloc = (f->alloc + n) * 2; |
2441 | 592 | f->buffer = (char *) xrealloc (f->buffer, f->alloc); |
2442 | 592 | } |
2443 | 198M | f->pos += n; |
2444 | | |
2445 | 198M | return n; |
2446 | 198M | } fuzz_objdump.c:objdump_sprintf Line | Count | Source | 2425 | 198M | { | 2426 | 198M | size_t n; | 2427 | 198M | va_list args; | 2428 | | | 2429 | 198M | while (1) | 2430 | 198M | { | 2431 | 198M | size_t space = f->alloc - f->pos; | 2432 | | | 2433 | 198M | va_start (args, format); | 2434 | 198M | n = vsnprintf (f->buffer + f->pos, space, format, args); | 2435 | 198M | va_end (args); | 2436 | | | 2437 | 198M | if (space > n) | 2438 | 198M | break; | 2439 | | | 2440 | 592 | f->alloc = (f->alloc + n) * 2; | 2441 | 592 | f->buffer = (char *) xrealloc (f->buffer, f->alloc); | 2442 | 592 | } | 2443 | 198M | f->pos += n; | 2444 | | | 2445 | 198M | return n; | 2446 | 198M | } |
Unexecuted instantiation: fuzz_dwarf.c:objdump_sprintf |
2447 | | |
2448 | | /* Return an integer greater than, or equal to zero, representing the color |
2449 | | for STYLE, or -1 if no color should be used. */ |
2450 | | |
2451 | | static int |
2452 | | objdump_color_for_disassembler_style (enum disassembler_style style) |
2453 | 166M | { |
2454 | 166M | int color = -1; |
2455 | | |
2456 | 166M | if (style == dis_style_comment_start) |
2457 | 16.3M | disassembler_in_comment = true; |
2458 | | |
2459 | 166M | if (disassembler_color == on) |
2460 | 0 | { |
2461 | 0 | if (disassembler_in_comment) |
2462 | 0 | return color; |
2463 | | |
2464 | 0 | switch (style) |
2465 | 0 | { |
2466 | 0 | case dis_style_symbol: |
2467 | 0 | color = 32; |
2468 | 0 | break; |
2469 | 0 | case dis_style_assembler_directive: |
2470 | 0 | case dis_style_sub_mnemonic: |
2471 | 0 | case dis_style_mnemonic: |
2472 | 0 | color = 33; |
2473 | 0 | break; |
2474 | 0 | case dis_style_register: |
2475 | 0 | color = 34; |
2476 | 0 | break; |
2477 | 0 | case dis_style_address: |
2478 | 0 | case dis_style_address_offset: |
2479 | 0 | case dis_style_immediate: |
2480 | 0 | color = 35; |
2481 | 0 | break; |
2482 | 0 | default: |
2483 | 0 | case dis_style_text: |
2484 | 0 | color = -1; |
2485 | 0 | break; |
2486 | 0 | } |
2487 | 0 | } |
2488 | 166M | else if (disassembler_color == extended) |
2489 | 0 | { |
2490 | 0 | if (disassembler_in_comment) |
2491 | 0 | return 250; |
2492 | | |
2493 | 0 | switch (style) |
2494 | 0 | { |
2495 | 0 | case dis_style_symbol: |
2496 | 0 | color = 40; |
2497 | 0 | break; |
2498 | 0 | case dis_style_assembler_directive: |
2499 | 0 | case dis_style_sub_mnemonic: |
2500 | 0 | case dis_style_mnemonic: |
2501 | 0 | color = 142; |
2502 | 0 | break; |
2503 | 0 | case dis_style_register: |
2504 | 0 | color = 27; |
2505 | 0 | break; |
2506 | 0 | case dis_style_address: |
2507 | 0 | case dis_style_address_offset: |
2508 | 0 | case dis_style_immediate: |
2509 | 0 | color = 134; |
2510 | 0 | break; |
2511 | 0 | default: |
2512 | 0 | case dis_style_text: |
2513 | 0 | color = -1; |
2514 | 0 | break; |
2515 | 0 | } |
2516 | 0 | } |
2517 | 166M | else if (disassembler_color != off) |
2518 | 0 | bfd_fatal (_("disassembly color not correctly selected")); |
2519 | | |
2520 | 166M | return color; |
2521 | 166M | } fuzz_objdump.c:objdump_color_for_disassembler_style Line | Count | Source | 2453 | 166M | { | 2454 | 166M | int color = -1; | 2455 | | | 2456 | 166M | if (style == dis_style_comment_start) | 2457 | 16.3M | disassembler_in_comment = true; | 2458 | | | 2459 | 166M | if (disassembler_color == on) | 2460 | 0 | { | 2461 | 0 | if (disassembler_in_comment) | 2462 | 0 | return color; | 2463 | | | 2464 | 0 | switch (style) | 2465 | 0 | { | 2466 | 0 | case dis_style_symbol: | 2467 | 0 | color = 32; | 2468 | 0 | break; | 2469 | 0 | case dis_style_assembler_directive: | 2470 | 0 | case dis_style_sub_mnemonic: | 2471 | 0 | case dis_style_mnemonic: | 2472 | 0 | color = 33; | 2473 | 0 | break; | 2474 | 0 | case dis_style_register: | 2475 | 0 | color = 34; | 2476 | 0 | break; | 2477 | 0 | case dis_style_address: | 2478 | 0 | case dis_style_address_offset: | 2479 | 0 | case dis_style_immediate: | 2480 | 0 | color = 35; | 2481 | 0 | break; | 2482 | 0 | default: | 2483 | 0 | case dis_style_text: | 2484 | 0 | color = -1; | 2485 | 0 | break; | 2486 | 0 | } | 2487 | 0 | } | 2488 | 166M | else if (disassembler_color == extended) | 2489 | 0 | { | 2490 | 0 | if (disassembler_in_comment) | 2491 | 0 | return 250; | 2492 | | | 2493 | 0 | switch (style) | 2494 | 0 | { | 2495 | 0 | case dis_style_symbol: | 2496 | 0 | color = 40; | 2497 | 0 | break; | 2498 | 0 | case dis_style_assembler_directive: | 2499 | 0 | case dis_style_sub_mnemonic: | 2500 | 0 | case dis_style_mnemonic: | 2501 | 0 | color = 142; | 2502 | 0 | break; | 2503 | 0 | case dis_style_register: | 2504 | 0 | color = 27; | 2505 | 0 | break; | 2506 | 0 | case dis_style_address: | 2507 | 0 | case dis_style_address_offset: | 2508 | 0 | case dis_style_immediate: | 2509 | 0 | color = 134; | 2510 | 0 | break; | 2511 | 0 | default: | 2512 | 0 | case dis_style_text: | 2513 | 0 | color = -1; | 2514 | 0 | break; | 2515 | 0 | } | 2516 | 0 | } | 2517 | 166M | else if (disassembler_color != off) | 2518 | 0 | bfd_fatal (_("disassembly color not correctly selected")); | 2519 | | | 2520 | 166M | return color; | 2521 | 166M | } |
Unexecuted instantiation: fuzz_dwarf.c:objdump_color_for_disassembler_style |
2522 | | |
2523 | | /* Like objdump_sprintf, but add in escape sequences to highlight the |
2524 | | content according to STYLE. */ |
2525 | | |
2526 | | static int ATTRIBUTE_PRINTF_3 |
2527 | | objdump_styled_sprintf (SFILE *f, enum disassembler_style style, |
2528 | | const char *format, ...) |
2529 | 166M | { |
2530 | 166M | size_t n; |
2531 | 166M | va_list args; |
2532 | 166M | int color = objdump_color_for_disassembler_style (style); |
2533 | | |
2534 | 166M | if (color >= 0) |
2535 | 0 | { |
2536 | 0 | while (1) |
2537 | 0 | { |
2538 | 0 | size_t space = f->alloc - f->pos; |
2539 | |
|
2540 | 0 | if (disassembler_color == on) |
2541 | 0 | n = snprintf (f->buffer + f->pos, space, "\033[%dm", color); |
2542 | 0 | else |
2543 | 0 | n = snprintf (f->buffer + f->pos, space, "\033[38;5;%dm", color); |
2544 | 0 | if (space > n) |
2545 | 0 | break; |
2546 | | |
2547 | 0 | f->alloc = (f->alloc + n) * 2; |
2548 | 0 | f->buffer = (char *) xrealloc (f->buffer, f->alloc); |
2549 | 0 | } |
2550 | 0 | f->pos += n; |
2551 | 0 | } |
2552 | | |
2553 | 166M | while (1) |
2554 | 166M | { |
2555 | 166M | size_t space = f->alloc - f->pos; |
2556 | | |
2557 | 166M | va_start (args, format); |
2558 | 166M | n = vsnprintf (f->buffer + f->pos, space, format, args); |
2559 | 166M | va_end (args); |
2560 | | |
2561 | 166M | if (space > n) |
2562 | 166M | break; |
2563 | | |
2564 | 288 | f->alloc = (f->alloc + n) * 2; |
2565 | 288 | f->buffer = (char *) xrealloc (f->buffer, f->alloc); |
2566 | 288 | } |
2567 | 166M | f->pos += n; |
2568 | | |
2569 | 166M | if (color >= 0) |
2570 | 0 | { |
2571 | 0 | while (1) |
2572 | 0 | { |
2573 | 0 | size_t space = f->alloc - f->pos; |
2574 | |
|
2575 | 0 | n = snprintf (f->buffer + f->pos, space, "\033[0m"); |
2576 | |
|
2577 | 0 | if (space > n) |
2578 | 0 | break; |
2579 | | |
2580 | 0 | f->alloc = (f->alloc + n) * 2; |
2581 | 0 | f->buffer = (char *) xrealloc (f->buffer, f->alloc); |
2582 | 0 | } |
2583 | 0 | f->pos += n; |
2584 | 0 | } |
2585 | | |
2586 | 166M | return n; |
2587 | 166M | } fuzz_objdump.c:objdump_styled_sprintf Line | Count | Source | 2529 | 166M | { | 2530 | 166M | size_t n; | 2531 | 166M | va_list args; | 2532 | 166M | int color = objdump_color_for_disassembler_style (style); | 2533 | | | 2534 | 166M | if (color >= 0) | 2535 | 0 | { | 2536 | 0 | while (1) | 2537 | 0 | { | 2538 | 0 | size_t space = f->alloc - f->pos; | 2539 | |
| 2540 | 0 | if (disassembler_color == on) | 2541 | 0 | n = snprintf (f->buffer + f->pos, space, "\033[%dm", color); | 2542 | 0 | else | 2543 | 0 | n = snprintf (f->buffer + f->pos, space, "\033[38;5;%dm", color); | 2544 | 0 | if (space > n) | 2545 | 0 | break; | 2546 | | | 2547 | 0 | f->alloc = (f->alloc + n) * 2; | 2548 | 0 | f->buffer = (char *) xrealloc (f->buffer, f->alloc); | 2549 | 0 | } | 2550 | 0 | f->pos += n; | 2551 | 0 | } | 2552 | | | 2553 | 166M | while (1) | 2554 | 166M | { | 2555 | 166M | size_t space = f->alloc - f->pos; | 2556 | | | 2557 | 166M | va_start (args, format); | 2558 | 166M | n = vsnprintf (f->buffer + f->pos, space, format, args); | 2559 | 166M | va_end (args); | 2560 | | | 2561 | 166M | if (space > n) | 2562 | 166M | break; | 2563 | | | 2564 | 288 | f->alloc = (f->alloc + n) * 2; | 2565 | 288 | f->buffer = (char *) xrealloc (f->buffer, f->alloc); | 2566 | 288 | } | 2567 | 166M | f->pos += n; | 2568 | | | 2569 | 166M | if (color >= 0) | 2570 | 0 | { | 2571 | 0 | while (1) | 2572 | 0 | { | 2573 | 0 | size_t space = f->alloc - f->pos; | 2574 | |
| 2575 | 0 | n = snprintf (f->buffer + f->pos, space, "\033[0m"); | 2576 | |
| 2577 | 0 | if (space > n) | 2578 | 0 | break; | 2579 | | | 2580 | 0 | f->alloc = (f->alloc + n) * 2; | 2581 | 0 | f->buffer = (char *) xrealloc (f->buffer, f->alloc); | 2582 | 0 | } | 2583 | 0 | f->pos += n; | 2584 | 0 | } | 2585 | | | 2586 | 166M | return n; | 2587 | 166M | } |
Unexecuted instantiation: fuzz_dwarf.c:objdump_styled_sprintf |
2588 | | |
2589 | | /* We discard the styling information here. This function is only used |
2590 | | when objdump is printing auxiliary information, the symbol headers, and |
2591 | | disassembly address, or the bytes of the disassembled instruction. We |
2592 | | don't (currently) apply styling to any of this stuff, so, for now, just |
2593 | | print the content with no additional style added. */ |
2594 | | |
2595 | | static int ATTRIBUTE_PRINTF_3 |
2596 | | fprintf_styled (FILE *f, enum disassembler_style style ATTRIBUTE_UNUSED, |
2597 | | const char *fmt, ...) |
2598 | 511k | { |
2599 | 511k | int res; |
2600 | 511k | va_list ap; |
2601 | | |
2602 | 511k | va_start (ap, fmt); |
2603 | 511k | res = vfprintf (f, fmt, ap); |
2604 | 511k | va_end (ap); |
2605 | | |
2606 | 511k | return res; |
2607 | 511k | } fuzz_objdump.c:fprintf_styled Line | Count | Source | 2598 | 511k | { | 2599 | 511k | int res; | 2600 | 511k | va_list ap; | 2601 | | | 2602 | 511k | va_start (ap, fmt); | 2603 | 511k | res = vfprintf (f, fmt, ap); | 2604 | 511k | va_end (ap); | 2605 | | | 2606 | 511k | return res; | 2607 | 511k | } |
Unexecuted instantiation: fuzz_dwarf.c:fprintf_styled |
2608 | | |
2609 | | /* Code for generating (colored) diagrams of control flow start and end |
2610 | | points. */ |
2611 | | |
2612 | | /* Structure used to store the properties of a jump. */ |
2613 | | |
2614 | | struct jump_info |
2615 | | { |
2616 | | /* The next jump, or NULL if this is the last object. */ |
2617 | | struct jump_info *next; |
2618 | | /* The previous jump, or NULL if this is the first object. */ |
2619 | | struct jump_info *prev; |
2620 | | /* The start addresses of the jump. */ |
2621 | | struct |
2622 | | { |
2623 | | /* The list of start addresses. */ |
2624 | | bfd_vma *addresses; |
2625 | | /* The number of elements. */ |
2626 | | size_t count; |
2627 | | /* The maximum number of elements that fit into the array. */ |
2628 | | size_t max_count; |
2629 | | } start; |
2630 | | /* The end address of the jump. */ |
2631 | | bfd_vma end; |
2632 | | /* The drawing level of the jump. */ |
2633 | | int level; |
2634 | | }; |
2635 | | |
2636 | | /* Construct a jump object for a jump from start |
2637 | | to end with the corresponding level. */ |
2638 | | |
2639 | | static struct jump_info * |
2640 | | jump_info_new (bfd_vma start, bfd_vma end, int level) |
2641 | 0 | { |
2642 | 0 | struct jump_info *result = xmalloc (sizeof (struct jump_info)); |
2643 | |
|
2644 | 0 | result->next = NULL; |
2645 | 0 | result->prev = NULL; |
2646 | 0 | result->start.addresses = xmalloc (sizeof (bfd_vma *) * 2); |
2647 | 0 | result->start.addresses[0] = start; |
2648 | 0 | result->start.count = 1; |
2649 | 0 | result->start.max_count = 2; |
2650 | 0 | result->end = end; |
2651 | 0 | result->level = level; |
2652 | |
|
2653 | 0 | return result; |
2654 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_new Unexecuted instantiation: fuzz_dwarf.c:jump_info_new |
2655 | | |
2656 | | /* Free a jump object and return the next object |
2657 | | or NULL if this was the last one. */ |
2658 | | |
2659 | | static struct jump_info * |
2660 | | jump_info_free (struct jump_info *ji) |
2661 | 0 | { |
2662 | 0 | struct jump_info *result = NULL; |
2663 | |
|
2664 | 0 | if (ji) |
2665 | 0 | { |
2666 | 0 | result = ji->next; |
2667 | 0 | if (ji->start.addresses) |
2668 | 0 | free (ji->start.addresses); |
2669 | 0 | free (ji); |
2670 | 0 | } |
2671 | |
|
2672 | 0 | return result; |
2673 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_free Unexecuted instantiation: fuzz_dwarf.c:jump_info_free |
2674 | | |
2675 | | /* Get the smallest value of all start and end addresses. */ |
2676 | | |
2677 | | static bfd_vma |
2678 | | jump_info_min_address (const struct jump_info *ji) |
2679 | 0 | { |
2680 | 0 | bfd_vma min_address = ji->end; |
2681 | 0 | size_t i; |
2682 | |
|
2683 | 0 | for (i = ji->start.count; i-- > 0;) |
2684 | 0 | if (ji->start.addresses[i] < min_address) |
2685 | 0 | min_address = ji->start.addresses[i]; |
2686 | 0 | return min_address; |
2687 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_min_address Unexecuted instantiation: fuzz_dwarf.c:jump_info_min_address |
2688 | | |
2689 | | /* Get the largest value of all start and end addresses. */ |
2690 | | |
2691 | | static bfd_vma |
2692 | | jump_info_max_address (const struct jump_info *ji) |
2693 | 0 | { |
2694 | 0 | bfd_vma max_address = ji->end; |
2695 | 0 | size_t i; |
2696 | |
|
2697 | 0 | for (i = ji->start.count; i-- > 0;) |
2698 | 0 | if (ji->start.addresses[i] > max_address) |
2699 | 0 | max_address = ji->start.addresses[i]; |
2700 | 0 | return max_address; |
2701 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_max_address Unexecuted instantiation: fuzz_dwarf.c:jump_info_max_address |
2702 | | |
2703 | | /* Get the target address of a jump. */ |
2704 | | |
2705 | | static bfd_vma |
2706 | | jump_info_end_address (const struct jump_info *ji) |
2707 | 0 | { |
2708 | 0 | return ji->end; |
2709 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_end_address Unexecuted instantiation: fuzz_dwarf.c:jump_info_end_address |
2710 | | |
2711 | | /* Test if an address is one of the start addresses of a jump. */ |
2712 | | |
2713 | | static bool |
2714 | | jump_info_is_start_address (const struct jump_info *ji, bfd_vma address) |
2715 | 0 | { |
2716 | 0 | bool result = false; |
2717 | 0 | size_t i; |
2718 | |
|
2719 | 0 | for (i = ji->start.count; i-- > 0;) |
2720 | 0 | if (address == ji->start.addresses[i]) |
2721 | 0 | { |
2722 | 0 | result = true; |
2723 | 0 | break; |
2724 | 0 | } |
2725 | |
|
2726 | 0 | return result; |
2727 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_is_start_address Unexecuted instantiation: fuzz_dwarf.c:jump_info_is_start_address |
2728 | | |
2729 | | /* Test if an address is the target address of a jump. */ |
2730 | | |
2731 | | static bool |
2732 | | jump_info_is_end_address (const struct jump_info *ji, bfd_vma address) |
2733 | 0 | { |
2734 | 0 | return (address == ji->end); |
2735 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_is_end_address Unexecuted instantiation: fuzz_dwarf.c:jump_info_is_end_address |
2736 | | |
2737 | | /* Get the difference between the smallest and largest address of a jump. */ |
2738 | | |
2739 | | static bfd_vma |
2740 | | jump_info_size (const struct jump_info *ji) |
2741 | 0 | { |
2742 | 0 | return jump_info_max_address (ji) - jump_info_min_address (ji); |
2743 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_size Unexecuted instantiation: fuzz_dwarf.c:jump_info_size |
2744 | | |
2745 | | /* Unlink a jump object from a list. */ |
2746 | | |
2747 | | static void |
2748 | | jump_info_unlink (struct jump_info *node, |
2749 | | struct jump_info **base) |
2750 | 0 | { |
2751 | 0 | if (node->next) |
2752 | 0 | node->next->prev = node->prev; |
2753 | 0 | if (node->prev) |
2754 | 0 | node->prev->next = node->next; |
2755 | 0 | else |
2756 | 0 | *base = node->next; |
2757 | 0 | node->next = NULL; |
2758 | 0 | node->prev = NULL; |
2759 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_unlink Unexecuted instantiation: fuzz_dwarf.c:jump_info_unlink |
2760 | | |
2761 | | /* Insert unlinked jump info node into a list. */ |
2762 | | |
2763 | | static void |
2764 | | jump_info_insert (struct jump_info *node, |
2765 | | struct jump_info *target, |
2766 | | struct jump_info **base) |
2767 | 0 | { |
2768 | 0 | node->next = target; |
2769 | 0 | node->prev = target->prev; |
2770 | 0 | target->prev = node; |
2771 | 0 | if (node->prev) |
2772 | 0 | node->prev->next = node; |
2773 | 0 | else |
2774 | 0 | *base = node; |
2775 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_insert Unexecuted instantiation: fuzz_dwarf.c:jump_info_insert |
2776 | | |
2777 | | /* Add unlinked node to the front of a list. */ |
2778 | | |
2779 | | static void |
2780 | | jump_info_add_front (struct jump_info *node, |
2781 | | struct jump_info **base) |
2782 | 0 | { |
2783 | 0 | node->next = *base; |
2784 | 0 | if (node->next) |
2785 | 0 | node->next->prev = node; |
2786 | 0 | node->prev = NULL; |
2787 | 0 | *base = node; |
2788 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_add_front Unexecuted instantiation: fuzz_dwarf.c:jump_info_add_front |
2789 | | |
2790 | | /* Move linked node to target position. */ |
2791 | | |
2792 | | static void |
2793 | | jump_info_move_linked (struct jump_info *node, |
2794 | | struct jump_info *target, |
2795 | | struct jump_info **base) |
2796 | 0 | { |
2797 | | /* Unlink node. */ |
2798 | 0 | jump_info_unlink (node, base); |
2799 | | /* Insert node at target position. */ |
2800 | 0 | jump_info_insert (node, target, base); |
2801 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_move_linked Unexecuted instantiation: fuzz_dwarf.c:jump_info_move_linked |
2802 | | |
2803 | | /* Test if two jumps intersect. */ |
2804 | | |
2805 | | static bool |
2806 | | jump_info_intersect (const struct jump_info *a, |
2807 | | const struct jump_info *b) |
2808 | 0 | { |
2809 | 0 | return ((jump_info_max_address (a) >= jump_info_min_address (b)) |
2810 | 0 | && (jump_info_min_address (a) <= jump_info_max_address (b))); |
2811 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_intersect Unexecuted instantiation: fuzz_dwarf.c:jump_info_intersect |
2812 | | |
2813 | | /* Merge two compatible jump info objects. */ |
2814 | | |
2815 | | static void |
2816 | | jump_info_merge (struct jump_info **base) |
2817 | 0 | { |
2818 | 0 | struct jump_info *a; |
2819 | |
|
2820 | 0 | for (a = *base; a; a = a->next) |
2821 | 0 | { |
2822 | 0 | struct jump_info *b; |
2823 | |
|
2824 | 0 | for (b = a->next; b; b = b->next) |
2825 | 0 | { |
2826 | | /* Merge both jumps into one. */ |
2827 | 0 | if (a->end == b->end) |
2828 | 0 | { |
2829 | | /* Reallocate addresses. */ |
2830 | 0 | size_t needed_size = a->start.count + b->start.count; |
2831 | 0 | size_t i; |
2832 | |
|
2833 | 0 | if (needed_size > a->start.max_count) |
2834 | 0 | { |
2835 | 0 | a->start.max_count += b->start.max_count; |
2836 | 0 | a->start.addresses = |
2837 | 0 | xrealloc (a->start.addresses, |
2838 | 0 | a->start.max_count * sizeof (bfd_vma *)); |
2839 | 0 | } |
2840 | | |
2841 | | /* Append start addresses. */ |
2842 | 0 | for (i = 0; i < b->start.count; ++i) |
2843 | 0 | a->start.addresses[a->start.count++] = |
2844 | 0 | b->start.addresses[i]; |
2845 | | |
2846 | | /* Remove and delete jump. */ |
2847 | 0 | struct jump_info *tmp = b->prev; |
2848 | 0 | jump_info_unlink (b, base); |
2849 | 0 | jump_info_free (b); |
2850 | 0 | b = tmp; |
2851 | 0 | } |
2852 | 0 | } |
2853 | 0 | } |
2854 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_merge Unexecuted instantiation: fuzz_dwarf.c:jump_info_merge |
2855 | | |
2856 | | /* Sort jumps by their size and starting point using a stable |
2857 | | minsort. This could be improved if sorting performance is |
2858 | | an issue, for example by using mergesort. */ |
2859 | | |
2860 | | static void |
2861 | | jump_info_sort (struct jump_info **base) |
2862 | 0 | { |
2863 | 0 | struct jump_info *current_element = *base; |
2864 | |
|
2865 | 0 | while (current_element) |
2866 | 0 | { |
2867 | 0 | struct jump_info *best_match = current_element; |
2868 | 0 | struct jump_info *runner = current_element->next; |
2869 | 0 | bfd_vma best_size = jump_info_size (best_match); |
2870 | |
|
2871 | 0 | while (runner) |
2872 | 0 | { |
2873 | 0 | bfd_vma runner_size = jump_info_size (runner); |
2874 | |
|
2875 | 0 | if ((runner_size < best_size) |
2876 | 0 | || ((runner_size == best_size) |
2877 | 0 | && (jump_info_min_address (runner) |
2878 | 0 | < jump_info_min_address (best_match)))) |
2879 | 0 | { |
2880 | 0 | best_match = runner; |
2881 | 0 | best_size = runner_size; |
2882 | 0 | } |
2883 | |
|
2884 | 0 | runner = runner->next; |
2885 | 0 | } |
2886 | |
|
2887 | 0 | if (best_match == current_element) |
2888 | 0 | current_element = current_element->next; |
2889 | 0 | else |
2890 | 0 | jump_info_move_linked (best_match, current_element, base); |
2891 | 0 | } |
2892 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_sort Unexecuted instantiation: fuzz_dwarf.c:jump_info_sort |
2893 | | |
2894 | | /* Visualize all jumps at a given address. */ |
2895 | | |
2896 | | static void |
2897 | | jump_info_visualize_address (bfd_vma address, |
2898 | | int max_level, |
2899 | | char *line_buffer, |
2900 | | uint8_t *color_buffer) |
2901 | 0 | { |
2902 | 0 | struct jump_info *ji = detected_jumps; |
2903 | 0 | size_t len = (max_level + 1) * 3; |
2904 | | |
2905 | | /* Clear line buffer. */ |
2906 | 0 | memset (line_buffer, ' ', len); |
2907 | 0 | memset (color_buffer, 0, len); |
2908 | | |
2909 | | /* Iterate over jumps and add their ASCII art. */ |
2910 | 0 | while (ji) |
2911 | 0 | { |
2912 | | /* Discard jumps that are never needed again. */ |
2913 | 0 | if (jump_info_max_address (ji) < address) |
2914 | 0 | { |
2915 | 0 | struct jump_info *tmp = ji; |
2916 | |
|
2917 | 0 | ji = ji->next; |
2918 | 0 | jump_info_unlink (tmp, &detected_jumps); |
2919 | 0 | jump_info_free (tmp); |
2920 | 0 | continue; |
2921 | 0 | } |
2922 | | |
2923 | | /* This jump intersects with the current address. */ |
2924 | 0 | if (jump_info_min_address (ji) <= address) |
2925 | 0 | { |
2926 | | /* Hash target address to get an even |
2927 | | distribution between all values. */ |
2928 | 0 | bfd_vma hash_address = jump_info_end_address (ji); |
2929 | 0 | uint8_t color = iterative_hash_object (hash_address, 0); |
2930 | | /* Fetch line offset. */ |
2931 | 0 | int offset = (max_level - ji->level) * 3; |
2932 | | |
2933 | | /* Draw start line. */ |
2934 | 0 | if (jump_info_is_start_address (ji, address)) |
2935 | 0 | { |
2936 | 0 | size_t i = offset + 1; |
2937 | |
|
2938 | 0 | for (; i < len - 1; ++i) |
2939 | 0 | if (line_buffer[i] == ' ') |
2940 | 0 | { |
2941 | 0 | line_buffer[i] = '-'; |
2942 | 0 | color_buffer[i] = color; |
2943 | 0 | } |
2944 | |
|
2945 | 0 | if (line_buffer[i] == ' ') |
2946 | 0 | { |
2947 | 0 | line_buffer[i] = '-'; |
2948 | 0 | color_buffer[i] = color; |
2949 | 0 | } |
2950 | 0 | else if (line_buffer[i] == '>') |
2951 | 0 | { |
2952 | 0 | line_buffer[i] = 'X'; |
2953 | 0 | color_buffer[i] = color; |
2954 | 0 | } |
2955 | |
|
2956 | 0 | if (line_buffer[offset] == ' ') |
2957 | 0 | { |
2958 | 0 | if (address <= ji->end) |
2959 | 0 | line_buffer[offset] = |
2960 | 0 | (jump_info_min_address (ji) == address) ? ',': '+'; |
2961 | 0 | else |
2962 | 0 | line_buffer[offset] = |
2963 | 0 | (jump_info_max_address (ji) == address) ? '\'': '+'; |
2964 | 0 | color_buffer[offset] = color; |
2965 | 0 | } |
2966 | 0 | } |
2967 | | /* Draw jump target. */ |
2968 | 0 | else if (jump_info_is_end_address (ji, address)) |
2969 | 0 | { |
2970 | 0 | size_t i = offset + 1; |
2971 | |
|
2972 | 0 | for (; i < len - 1; ++i) |
2973 | 0 | if (line_buffer[i] == ' ') |
2974 | 0 | { |
2975 | 0 | line_buffer[i] = '-'; |
2976 | 0 | color_buffer[i] = color; |
2977 | 0 | } |
2978 | |
|
2979 | 0 | if (line_buffer[i] == ' ') |
2980 | 0 | { |
2981 | 0 | line_buffer[i] = '>'; |
2982 | 0 | color_buffer[i] = color; |
2983 | 0 | } |
2984 | 0 | else if (line_buffer[i] == '-') |
2985 | 0 | { |
2986 | 0 | line_buffer[i] = 'X'; |
2987 | 0 | color_buffer[i] = color; |
2988 | 0 | } |
2989 | |
|
2990 | 0 | if (line_buffer[offset] == ' ') |
2991 | 0 | { |
2992 | 0 | if (jump_info_min_address (ji) < address) |
2993 | 0 | line_buffer[offset] = |
2994 | 0 | (jump_info_max_address (ji) > address) ? '>' : '\''; |
2995 | 0 | else |
2996 | 0 | line_buffer[offset] = ','; |
2997 | 0 | color_buffer[offset] = color; |
2998 | 0 | } |
2999 | 0 | } |
3000 | | /* Draw intermediate line segment. */ |
3001 | 0 | else if (line_buffer[offset] == ' ') |
3002 | 0 | { |
3003 | 0 | line_buffer[offset] = '|'; |
3004 | 0 | color_buffer[offset] = color; |
3005 | 0 | } |
3006 | 0 | } |
3007 | |
|
3008 | 0 | ji = ji->next; |
3009 | 0 | } |
3010 | 0 | } Unexecuted instantiation: fuzz_objdump.c:jump_info_visualize_address Unexecuted instantiation: fuzz_dwarf.c:jump_info_visualize_address |
3011 | | |
3012 | | /* Clone of disassemble_bytes to detect jumps inside a function. */ |
3013 | | /* FIXME: is this correct? Can we strip it down even further? */ |
3014 | | |
3015 | | static struct jump_info * |
3016 | | disassemble_jumps (struct disassemble_info * inf, |
3017 | | disassembler_ftype disassemble_fn, |
3018 | | bfd_vma start_offset, |
3019 | | bfd_vma stop_offset, |
3020 | | bfd_vma rel_offset, |
3021 | | arelent ** relpp, |
3022 | | arelent ** relppend) |
3023 | 0 | { |
3024 | 0 | struct objdump_disasm_info *aux; |
3025 | 0 | struct jump_info *jumps = NULL; |
3026 | 0 | asection *section; |
3027 | 0 | bfd_vma addr_offset; |
3028 | 0 | unsigned int opb = inf->octets_per_byte; |
3029 | 0 | int octets = opb; |
3030 | 0 | SFILE sfile; |
3031 | |
|
3032 | 0 | aux = (struct objdump_disasm_info *) inf->application_data; |
3033 | 0 | section = inf->section; |
3034 | |
|
3035 | 0 | sfile.alloc = 120; |
3036 | 0 | sfile.buffer = (char *) xmalloc (sfile.alloc); |
3037 | 0 | sfile.pos = 0; |
3038 | |
|
3039 | 0 | inf->insn_info_valid = 0; |
3040 | 0 | disassemble_set_printf (inf, &sfile, (fprintf_ftype) objdump_sprintf, |
3041 | 0 | (fprintf_styled_ftype) objdump_styled_sprintf); |
3042 | |
|
3043 | 0 | addr_offset = start_offset; |
3044 | 0 | while (addr_offset < stop_offset) |
3045 | 0 | { |
3046 | 0 | int previous_octets; |
3047 | | |
3048 | | /* Remember the length of the previous instruction. */ |
3049 | 0 | previous_octets = octets; |
3050 | 0 | octets = 0; |
3051 | |
|
3052 | 0 | sfile.pos = 0; |
3053 | 0 | inf->bytes_per_line = 0; |
3054 | 0 | inf->bytes_per_chunk = 0; |
3055 | 0 | inf->flags = ((disassemble_all ? DISASSEMBLE_DATA : 0) |
3056 | 0 | | (wide_output ? WIDE_OUTPUT : 0)); |
3057 | 0 | if (machine) |
3058 | 0 | inf->flags |= USER_SPECIFIED_MACHINE_TYPE; |
3059 | |
|
3060 | 0 | if (inf->disassembler_needs_relocs |
3061 | 0 | && (bfd_get_file_flags (aux->abfd) & EXEC_P) == 0 |
3062 | 0 | && (bfd_get_file_flags (aux->abfd) & DYNAMIC) == 0 |
3063 | 0 | && relpp < relppend) |
3064 | 0 | { |
3065 | 0 | bfd_signed_vma distance_to_rel; |
3066 | |
|
3067 | 0 | distance_to_rel = (*relpp)->address - (rel_offset + addr_offset); |
3068 | | |
3069 | | /* Check to see if the current reloc is associated with |
3070 | | the instruction that we are about to disassemble. */ |
3071 | 0 | if (distance_to_rel == 0 |
3072 | | /* FIXME: This is wrong. We are trying to catch |
3073 | | relocs that are addressed part way through the |
3074 | | current instruction, as might happen with a packed |
3075 | | VLIW instruction. Unfortunately we do not know the |
3076 | | length of the current instruction since we have not |
3077 | | disassembled it yet. Instead we take a guess based |
3078 | | upon the length of the previous instruction. The |
3079 | | proper solution is to have a new target-specific |
3080 | | disassembler function which just returns the length |
3081 | | of an instruction at a given address without trying |
3082 | | to display its disassembly. */ |
3083 | 0 | || (distance_to_rel > 0 |
3084 | 0 | && distance_to_rel < (bfd_signed_vma) (previous_octets/ opb))) |
3085 | 0 | { |
3086 | 0 | inf->flags |= INSN_HAS_RELOC; |
3087 | 0 | } |
3088 | 0 | } |
3089 | |
|
3090 | 0 | if (! disassemble_all |
3091 | 0 | && (section->flags & (SEC_CODE | SEC_HAS_CONTENTS)) |
3092 | 0 | == (SEC_CODE | SEC_HAS_CONTENTS)) |
3093 | | /* Set a stop_vma so that the disassembler will not read |
3094 | | beyond the next symbol. We assume that symbols appear on |
3095 | | the boundaries between instructions. We only do this when |
3096 | | disassembling code of course, and when -D is in effect. */ |
3097 | 0 | inf->stop_vma = section->vma + stop_offset; |
3098 | |
|
3099 | 0 | inf->stop_offset = stop_offset; |
3100 | | |
3101 | | /* Extract jump information. */ |
3102 | 0 | inf->insn_info_valid = 0; |
3103 | 0 | disassembler_in_comment = false; |
3104 | 0 | octets = (*disassemble_fn) (section->vma + addr_offset, inf); |
3105 | | /* Test if a jump was detected. */ |
3106 | 0 | if (inf->insn_info_valid |
3107 | 0 | && ((inf->insn_type == dis_branch) |
3108 | 0 | || (inf->insn_type == dis_condbranch) |
3109 | 0 | || (inf->insn_type == dis_jsr) |
3110 | 0 | || (inf->insn_type == dis_condjsr)) |
3111 | 0 | && (inf->target >= section->vma + start_offset) |
3112 | 0 | && (inf->target < section->vma + stop_offset)) |
3113 | 0 | { |
3114 | 0 | struct jump_info *ji = |
3115 | 0 | jump_info_new (section->vma + addr_offset, inf->target, -1); |
3116 | 0 | jump_info_add_front (ji, &jumps); |
3117 | 0 | } |
3118 | |
|
3119 | 0 | inf->stop_vma = 0; |
3120 | |
|
3121 | 0 | addr_offset += octets / opb; |
3122 | 0 | } |
3123 | |
|
3124 | 0 | disassemble_set_printf (inf, (void *) stdout, (fprintf_ftype) fprintf, |
3125 | 0 | (fprintf_styled_ftype) fprintf_styled); |
3126 | 0 | free (sfile.buffer); |
3127 | | |
3128 | | /* Merge jumps. */ |
3129 | 0 | jump_info_merge (&jumps); |
3130 | | /* Process jumps. */ |
3131 | 0 | jump_info_sort (&jumps); |
3132 | | |
3133 | | /* Group jumps by level. */ |
3134 | 0 | struct jump_info *last_jump = jumps; |
3135 | 0 | int max_level = -1; |
3136 | |
|
3137 | 0 | while (last_jump) |
3138 | 0 | { |
3139 | | /* The last jump is part of the next group. */ |
3140 | 0 | struct jump_info *base = last_jump; |
3141 | | /* Increment level. */ |
3142 | 0 | base->level = ++max_level; |
3143 | | |
3144 | | /* Find jumps that can be combined on the same |
3145 | | level, with the largest jumps tested first. |
3146 | | This has the advantage that large jumps are on |
3147 | | lower levels and do not intersect with small |
3148 | | jumps that get grouped on higher levels. */ |
3149 | 0 | struct jump_info *exchange_item = last_jump->next; |
3150 | 0 | struct jump_info *it = exchange_item; |
3151 | |
|
3152 | 0 | for (; it; it = it->next) |
3153 | 0 | { |
3154 | | /* Test if the jump intersects with any |
3155 | | jump from current group. */ |
3156 | 0 | bool ok = true; |
3157 | 0 | struct jump_info *it_collision; |
3158 | |
|
3159 | 0 | for (it_collision = base; |
3160 | 0 | it_collision != exchange_item; |
3161 | 0 | it_collision = it_collision->next) |
3162 | 0 | { |
3163 | | /* This jump intersects so we leave it out. */ |
3164 | 0 | if (jump_info_intersect (it_collision, it)) |
3165 | 0 | { |
3166 | 0 | ok = false; |
3167 | 0 | break; |
3168 | 0 | } |
3169 | 0 | } |
3170 | | |
3171 | | /* Add jump to group. */ |
3172 | 0 | if (ok) |
3173 | 0 | { |
3174 | | /* Move current element to the front. */ |
3175 | 0 | if (it != exchange_item) |
3176 | 0 | { |
3177 | 0 | struct jump_info *save = it->prev; |
3178 | 0 | jump_info_move_linked (it, exchange_item, &jumps); |
3179 | 0 | last_jump = it; |
3180 | 0 | it = save; |
3181 | 0 | } |
3182 | 0 | else |
3183 | 0 | { |
3184 | 0 | last_jump = exchange_item; |
3185 | 0 | exchange_item = exchange_item->next; |
3186 | 0 | } |
3187 | 0 | last_jump->level = max_level; |
3188 | 0 | } |
3189 | 0 | } |
3190 | | |
3191 | | /* Move to next group. */ |
3192 | 0 | last_jump = exchange_item; |
3193 | 0 | } |
3194 | |
|
3195 | 0 | return jumps; |
3196 | 0 | } Unexecuted instantiation: fuzz_objdump.c:disassemble_jumps Unexecuted instantiation: fuzz_dwarf.c:disassemble_jumps |
3197 | | |
3198 | | /* The number of zeroes we want to see before we start skipping them. |
3199 | | The number is arbitrarily chosen. */ |
3200 | | |
3201 | 28.9k | #define DEFAULT_SKIP_ZEROES 8 |
3202 | | |
3203 | | /* The number of zeroes to skip at the end of a section. If the |
3204 | | number of zeroes at the end is between SKIP_ZEROES_AT_END and |
3205 | | SKIP_ZEROES, they will be disassembled. If there are fewer than |
3206 | | SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic |
3207 | | attempt to avoid disassembling zeroes inserted by section |
3208 | | alignment. */ |
3209 | | |
3210 | 28.9k | #define DEFAULT_SKIP_ZEROES_AT_END 3 |
3211 | | |
3212 | | static int |
3213 | | null_print (const void * stream ATTRIBUTE_UNUSED, const char * format ATTRIBUTE_UNUSED, ...) |
3214 | 0 | { |
3215 | 0 | return 1; |
3216 | 0 | } Unexecuted instantiation: fuzz_objdump.c:null_print Unexecuted instantiation: fuzz_dwarf.c:null_print |
3217 | | |
3218 | | /* Like null_print, but takes the extra STYLE argument. As this is not |
3219 | | going to print anything, the extra argument is just ignored. */ |
3220 | | |
3221 | | static int |
3222 | | null_styled_print (const void * stream ATTRIBUTE_UNUSED, |
3223 | | enum disassembler_style style ATTRIBUTE_UNUSED, |
3224 | | const char * format ATTRIBUTE_UNUSED, ...) |
3225 | 0 | { |
3226 | 0 | return 1; |
3227 | 0 | } Unexecuted instantiation: fuzz_objdump.c:null_styled_print Unexecuted instantiation: fuzz_dwarf.c:null_styled_print |
3228 | | |
3229 | | /* Print out jump visualization. */ |
3230 | | |
3231 | | static void |
3232 | | print_jump_visualisation (bfd_vma addr, int max_level, char *line_buffer, |
3233 | | uint8_t *color_buffer) |
3234 | 59.8M | { |
3235 | 59.8M | if (!line_buffer) |
3236 | 59.8M | return; |
3237 | | |
3238 | 0 | jump_info_visualize_address (addr, max_level, line_buffer, color_buffer); |
3239 | |
|
3240 | 0 | size_t line_buffer_size = strlen (line_buffer); |
3241 | 0 | char last_color = 0; |
3242 | 0 | size_t i; |
3243 | |
|
3244 | 0 | for (i = 0; i <= line_buffer_size; ++i) |
3245 | 0 | { |
3246 | 0 | if (color_output) |
3247 | 0 | { |
3248 | 0 | uint8_t color = (i < line_buffer_size) ? color_buffer[i]: 0; |
3249 | |
|
3250 | 0 | if (color != last_color) |
3251 | 0 | { |
3252 | 0 | if (color) |
3253 | 0 | if (extended_color_output) |
3254 | | /* Use extended 8bit color, but |
3255 | | do not choose dark colors. */ |
3256 | 0 | printf ("\033[38;5;%dm", 124 + (color % 108)); |
3257 | 0 | else |
3258 | | /* Use simple terminal colors. */ |
3259 | 0 | printf ("\033[%dm", 31 + (color % 7)); |
3260 | 0 | else |
3261 | | /* Clear color. */ |
3262 | 0 | printf ("\033[0m"); |
3263 | 0 | last_color = color; |
3264 | 0 | } |
3265 | 0 | } |
3266 | 0 | putchar ((i < line_buffer_size) ? line_buffer[i]: ' '); |
3267 | 0 | } |
3268 | 0 | } fuzz_objdump.c:print_jump_visualisation Line | Count | Source | 3234 | 59.8M | { | 3235 | 59.8M | if (!line_buffer) | 3236 | 59.8M | return; | 3237 | | | 3238 | 0 | jump_info_visualize_address (addr, max_level, line_buffer, color_buffer); | 3239 | |
| 3240 | 0 | size_t line_buffer_size = strlen (line_buffer); | 3241 | 0 | char last_color = 0; | 3242 | 0 | size_t i; | 3243 | |
| 3244 | 0 | for (i = 0; i <= line_buffer_size; ++i) | 3245 | 0 | { | 3246 | 0 | if (color_output) | 3247 | 0 | { | 3248 | 0 | uint8_t color = (i < line_buffer_size) ? color_buffer[i]: 0; | 3249 | |
| 3250 | 0 | if (color != last_color) | 3251 | 0 | { | 3252 | 0 | if (color) | 3253 | 0 | if (extended_color_output) | 3254 | | /* Use extended 8bit color, but | 3255 | | do not choose dark colors. */ | 3256 | 0 | printf ("\033[38;5;%dm", 124 + (color % 108)); | 3257 | 0 | else | 3258 | | /* Use simple terminal colors. */ | 3259 | 0 | printf ("\033[%dm", 31 + (color % 7)); | 3260 | 0 | else | 3261 | | /* Clear color. */ | 3262 | 0 | printf ("\033[0m"); | 3263 | 0 | last_color = color; | 3264 | 0 | } | 3265 | 0 | } | 3266 | 0 | putchar ((i < line_buffer_size) ? line_buffer[i]: ' '); | 3267 | 0 | } | 3268 | 0 | } |
Unexecuted instantiation: fuzz_dwarf.c:print_jump_visualisation |
3269 | | |
3270 | | /* Disassemble some data in memory between given values. */ |
3271 | | |
3272 | | static void |
3273 | | disassemble_bytes (struct disassemble_info *inf, |
3274 | | disassembler_ftype disassemble_fn, |
3275 | | bool insns, |
3276 | | bfd_byte *data, |
3277 | | bfd_vma start_offset, |
3278 | | bfd_vma stop_offset, |
3279 | | bfd_vma rel_offset, |
3280 | | arelent **relpp, |
3281 | | arelent **relppend) |
3282 | 87.0k | { |
3283 | 87.0k | struct objdump_disasm_info *aux; |
3284 | 87.0k | asection *section; |
3285 | 87.0k | unsigned int octets_per_line; |
3286 | 87.0k | unsigned int skip_addr_chars; |
3287 | 87.0k | bfd_vma addr_offset; |
3288 | 87.0k | unsigned int opb = inf->octets_per_byte; |
3289 | 87.0k | unsigned int skip_zeroes = inf->skip_zeroes; |
3290 | 87.0k | unsigned int skip_zeroes_at_end = inf->skip_zeroes_at_end; |
3291 | 87.0k | size_t octets; |
3292 | 87.0k | SFILE sfile; |
3293 | | |
3294 | 87.0k | aux = (struct objdump_disasm_info *) inf->application_data; |
3295 | 87.0k | section = inf->section; |
3296 | | |
3297 | 87.0k | sfile.alloc = 120; |
3298 | 87.0k | sfile.buffer = (char *) xmalloc (sfile.alloc); |
3299 | 87.0k | sfile.pos = 0; |
3300 | | |
3301 | 87.0k | if (insn_width) |
3302 | 0 | octets_per_line = insn_width; |
3303 | 87.0k | else if (insns) |
3304 | 87.0k | octets_per_line = 4; |
3305 | 0 | else |
3306 | 0 | octets_per_line = 16; |
3307 | | |
3308 | | /* Figure out how many characters to skip at the start of an |
3309 | | address, to make the disassembly look nicer. We discard leading |
3310 | | zeroes in chunks of 4, ensuring that there is always a leading |
3311 | | zero remaining. */ |
3312 | 87.0k | skip_addr_chars = 0; |
3313 | 87.0k | if (!no_addresses && !prefix_addresses) |
3314 | 87.0k | { |
3315 | 87.0k | char buf[30]; |
3316 | | |
3317 | 87.0k | bfd_sprintf_vma (aux->abfd, buf, section->vma + section->size / opb); |
3318 | | |
3319 | 534k | while (buf[skip_addr_chars] == '0') |
3320 | 447k | ++skip_addr_chars; |
3321 | | |
3322 | | /* Don't discard zeros on overflow. */ |
3323 | 87.0k | if (buf[skip_addr_chars] == '\0' && section->vma != 0) |
3324 | 4 | skip_addr_chars = 0; |
3325 | | |
3326 | 87.0k | if (skip_addr_chars != 0) |
3327 | 76.3k | skip_addr_chars = (skip_addr_chars - 1) & -4; |
3328 | 87.0k | } |
3329 | | |
3330 | 87.0k | inf->insn_info_valid = 0; |
3331 | | |
3332 | | /* Determine maximum level. */ |
3333 | 87.0k | uint8_t *color_buffer = NULL; |
3334 | 87.0k | char *line_buffer = NULL; |
3335 | 87.0k | int max_level = -1; |
3336 | | |
3337 | | /* Some jumps were detected. */ |
3338 | 87.0k | if (detected_jumps) |
3339 | 0 | { |
3340 | 0 | struct jump_info *ji; |
3341 | | |
3342 | | /* Find maximum jump level. */ |
3343 | 0 | for (ji = detected_jumps; ji; ji = ji->next) |
3344 | 0 | { |
3345 | 0 | if (ji->level > max_level) |
3346 | 0 | max_level = ji->level; |
3347 | 0 | } |
3348 | | |
3349 | | /* Allocate buffers. */ |
3350 | 0 | size_t len = (max_level + 1) * 3 + 1; |
3351 | 0 | line_buffer = xmalloc (len); |
3352 | 0 | line_buffer[len - 1] = 0; |
3353 | 0 | color_buffer = xmalloc (len); |
3354 | 0 | color_buffer[len - 1] = 0; |
3355 | 0 | } |
3356 | | |
3357 | 87.0k | addr_offset = start_offset; |
3358 | 60.9M | while (addr_offset < stop_offset) |
3359 | 60.8M | { |
3360 | 60.8M | bool need_nl = false; |
3361 | | |
3362 | 60.8M | octets = 0; |
3363 | | |
3364 | | /* Make sure we don't use relocs from previous instructions. */ |
3365 | 60.8M | aux->reloc = NULL; |
3366 | | |
3367 | | /* If we see more than SKIP_ZEROES octets of zeroes, we just |
3368 | | print `...'. */ |
3369 | 60.8M | if (! disassemble_zeroes) |
3370 | 140M | for (; octets < (stop_offset - addr_offset) * opb; octets++) |
3371 | 140M | if (data[addr_offset * opb + octets] != 0) |
3372 | 60.8M | break; |
3373 | 60.8M | if (! disassemble_zeroes |
3374 | 60.8M | && (inf->insn_info_valid == 0 |
3375 | 17.1M | || inf->branch_delay_insns == 0) |
3376 | 60.6M | && (octets >= skip_zeroes |
3377 | 59.3M | || (octets == (stop_offset - addr_offset) * opb |
3378 | 26.2k | && octets < skip_zeroes_at_end))) |
3379 | 1.31M | { |
3380 | | /* If there are more nonzero octets to follow, we only skip |
3381 | | zeroes in multiples of 4, to try to avoid running over |
3382 | | the start of an instruction which happens to start with |
3383 | | zero. */ |
3384 | 1.31M | if (octets != (stop_offset - addr_offset) * opb) |
3385 | 1.29M | octets &= ~3; |
3386 | | |
3387 | | /* If we are going to display more data, and we are displaying |
3388 | | file offsets, then tell the user how many zeroes we skip |
3389 | | and the file offset from where we resume dumping. */ |
3390 | 1.31M | if (display_file_offsets |
3391 | 0 | && octets / opb < stop_offset - addr_offset) |
3392 | 0 | printf (_("\t... (skipping %lu zeroes, " |
3393 | 0 | "resuming at file offset: 0x%lx)\n"), |
3394 | 0 | (unsigned long) (octets / opb), |
3395 | 0 | (unsigned long) (section->filepos |
3396 | 0 | + addr_offset + octets / opb)); |
3397 | 1.31M | else |
3398 | 1.31M | printf ("\t...\n"); |
3399 | 1.31M | } |
3400 | 59.5M | else |
3401 | 59.5M | { |
3402 | 59.5M | char buf[MAX_INSN_WIDTH + 1]; |
3403 | 59.5M | unsigned int bpc = 0; |
3404 | 59.5M | unsigned int pb = 0; |
3405 | | |
3406 | 59.5M | if (with_line_numbers || with_source_code) |
3407 | 0 | show_line (aux->abfd, section, addr_offset); |
3408 | | |
3409 | 59.5M | if (no_addresses) |
3410 | 0 | printf ("\t"); |
3411 | 59.5M | else if (!prefix_addresses) |
3412 | 59.5M | { |
3413 | 59.5M | char *s; |
3414 | | |
3415 | 59.5M | bfd_sprintf_vma (aux->abfd, buf, section->vma + addr_offset); |
3416 | 219M | for (s = buf + skip_addr_chars; *s == '0'; s++) |
3417 | 159M | *s = ' '; |
3418 | 59.5M | if (*s == '\0') |
3419 | 25.6k | *--s = '0'; |
3420 | 59.5M | printf ("%s:\t", buf + skip_addr_chars); |
3421 | 59.5M | } |
3422 | 0 | else |
3423 | 0 | { |
3424 | 0 | aux->require_sec = true; |
3425 | 0 | objdump_print_address (section->vma + addr_offset, inf); |
3426 | 0 | aux->require_sec = false; |
3427 | 0 | putchar (' '); |
3428 | 0 | } |
3429 | | |
3430 | 59.5M | print_jump_visualisation (section->vma + addr_offset, |
3431 | 59.5M | max_level, line_buffer, |
3432 | 59.5M | color_buffer); |
3433 | | |
3434 | 59.5M | if (insns) |
3435 | 59.5M | { |
3436 | 59.5M | int insn_size; |
3437 | | |
3438 | 59.5M | sfile.pos = 0; |
3439 | 59.5M | disassemble_set_printf |
3440 | 59.5M | (inf, &sfile, (fprintf_ftype) objdump_sprintf, |
3441 | 59.5M | (fprintf_styled_ftype) objdump_styled_sprintf); |
3442 | 59.5M | inf->bytes_per_line = 0; |
3443 | 59.5M | inf->bytes_per_chunk = 0; |
3444 | 59.5M | inf->flags = ((disassemble_all ? DISASSEMBLE_DATA : 0) |
3445 | 59.5M | | (wide_output ? WIDE_OUTPUT : 0)); |
3446 | 59.5M | if (machine) |
3447 | 0 | inf->flags |= USER_SPECIFIED_MACHINE_TYPE; |
3448 | | |
3449 | 59.5M | if (inf->disassembler_needs_relocs |
3450 | 11.7M | && (bfd_get_file_flags (aux->abfd) & EXEC_P) == 0 |
3451 | 10.7M | && (bfd_get_file_flags (aux->abfd) & DYNAMIC) == 0 |
3452 | 10.7M | && relpp < relppend) |
3453 | 3.43k | { |
3454 | 3.43k | bfd_signed_vma distance_to_rel; |
3455 | 3.43k | int max_reloc_offset |
3456 | 3.43k | = aux->abfd->arch_info->max_reloc_offset_into_insn; |
3457 | | |
3458 | 3.43k | distance_to_rel = ((*relpp)->address - rel_offset |
3459 | 3.43k | - addr_offset); |
3460 | | |
3461 | 3.43k | insn_size = 0; |
3462 | 3.43k | if (distance_to_rel > 0 |
3463 | 1.31k | && (max_reloc_offset < 0 |
3464 | 1.31k | || distance_to_rel <= max_reloc_offset)) |
3465 | 0 | { |
3466 | | /* This reloc *might* apply to the current insn, |
3467 | | starting somewhere inside it. Discover the length |
3468 | | of the current insn so that the check below will |
3469 | | work. */ |
3470 | 0 | if (insn_width) |
3471 | 0 | insn_size = insn_width; |
3472 | 0 | else |
3473 | 0 | { |
3474 | | /* We find the length by calling the dissassembler |
3475 | | function with a dummy print handler. This should |
3476 | | work unless the disassembler is not expecting to |
3477 | | be called multiple times for the same address. |
3478 | | |
3479 | | This does mean disassembling the instruction |
3480 | | twice, but we only do this when there is a high |
3481 | | probability that there is a reloc that will |
3482 | | affect the instruction. */ |
3483 | 0 | disassemble_set_printf |
3484 | 0 | (inf, inf->stream, (fprintf_ftype) null_print, |
3485 | 0 | (fprintf_styled_ftype) null_styled_print); |
3486 | 0 | insn_size = disassemble_fn (section->vma |
3487 | 0 | + addr_offset, inf); |
3488 | 0 | disassemble_set_printf |
3489 | 0 | (inf, inf->stream, |
3490 | 0 | (fprintf_ftype) objdump_sprintf, |
3491 | 0 | (fprintf_styled_ftype) objdump_styled_sprintf); |
3492 | 0 | } |
3493 | 0 | } |
3494 | | |
3495 | | /* Check to see if the current reloc is associated with |
3496 | | the instruction that we are about to disassemble. */ |
3497 | 3.43k | if (distance_to_rel == 0 |
3498 | 3.14k | || (distance_to_rel > 0 |
3499 | 1.31k | && distance_to_rel < insn_size / (int) opb)) |
3500 | 292 | { |
3501 | 292 | inf->flags |= INSN_HAS_RELOC; |
3502 | 292 | aux->reloc = *relpp; |
3503 | 292 | } |
3504 | 3.43k | } |
3505 | | |
3506 | 59.5M | if (! disassemble_all |
3507 | 0 | && ((section->flags & (SEC_CODE | SEC_HAS_CONTENTS)) |
3508 | 0 | == (SEC_CODE | SEC_HAS_CONTENTS))) |
3509 | | /* Set a stop_vma so that the disassembler will not read |
3510 | | beyond the next symbol. We assume that symbols appear on |
3511 | | the boundaries between instructions. We only do this when |
3512 | | disassembling code of course, and when -D is in effect. */ |
3513 | 0 | inf->stop_vma = section->vma + stop_offset; |
3514 | | |
3515 | 59.5M | inf->stop_offset = stop_offset; |
3516 | 59.5M | disassembler_in_comment = false; |
3517 | 59.5M | insn_size = (*disassemble_fn) (section->vma + addr_offset, inf); |
3518 | 59.5M | octets = insn_size; |
3519 | | |
3520 | 59.5M | inf->stop_vma = 0; |
3521 | 59.5M | disassemble_set_printf (inf, stdout, (fprintf_ftype) fprintf, |
3522 | 59.5M | (fprintf_styled_ftype) fprintf_styled); |
3523 | 59.5M | if (insn_width == 0 && inf->bytes_per_line != 0) |
3524 | 40.6M | octets_per_line = inf->bytes_per_line; |
3525 | 59.5M | if (insn_size < (int) opb) |
3526 | 28.2k | { |
3527 | 28.2k | if (sfile.pos) |
3528 | 26.4k | printf ("%s\n", sfile.buffer); |
3529 | 28.2k | if (insn_size >= 0) |
3530 | 0 | { |
3531 | 0 | non_fatal (_("disassemble_fn returned length %d"), |
3532 | 0 | insn_size); |
3533 | 0 | exit_status = 1; |
3534 | 0 | } |
3535 | 28.2k | break; |
3536 | 28.2k | } |
3537 | 59.5M | } |
3538 | 0 | else |
3539 | 0 | { |
3540 | 0 | bfd_vma j; |
3541 | |
|
3542 | 0 | octets = octets_per_line; |
3543 | 0 | if (octets / opb > stop_offset - addr_offset) |
3544 | 0 | octets = (stop_offset - addr_offset) * opb; |
3545 | |
|
3546 | 0 | for (j = addr_offset * opb; j < addr_offset * opb + octets; ++j) |
3547 | 0 | { |
3548 | 0 | if (ISPRINT (data[j])) |
3549 | 0 | buf[j - addr_offset * opb] = data[j]; |
3550 | 0 | else |
3551 | 0 | buf[j - addr_offset * opb] = '.'; |
3552 | 0 | } |
3553 | 0 | buf[j - addr_offset * opb] = '\0'; |
3554 | 0 | } |
3555 | | |
3556 | 59.5M | if (prefix_addresses |
3557 | 59.5M | ? show_raw_insn > 0 |
3558 | 59.5M | : show_raw_insn >= 0) |
3559 | 59.5M | { |
3560 | 59.5M | bfd_vma j; |
3561 | | |
3562 | | /* If ! prefix_addresses and ! wide_output, we print |
3563 | | octets_per_line octets per line. */ |
3564 | 59.5M | pb = octets; |
3565 | 59.5M | if (pb > octets_per_line && ! prefix_addresses && ! wide_output) |
3566 | 294k | pb = octets_per_line; |
3567 | | |
3568 | 59.5M | if (inf->bytes_per_chunk) |
3569 | 21.5M | bpc = inf->bytes_per_chunk; |
3570 | 37.9M | else |
3571 | 37.9M | bpc = 1; |
3572 | | |
3573 | 159M | for (j = addr_offset * opb; j < addr_offset * opb + pb; j += bpc) |
3574 | 99.9M | { |
3575 | | /* PR 21580: Check for a buffer ending early. */ |
3576 | 99.9M | if (j + bpc <= stop_offset * opb) |
3577 | 99.9M | { |
3578 | 99.9M | unsigned int k; |
3579 | | |
3580 | 99.9M | if (inf->display_endian == BFD_ENDIAN_LITTLE) |
3581 | 32.2M | { |
3582 | 99.7M | for (k = bpc; k-- != 0; ) |
3583 | 67.5M | printf ("%02x", (unsigned) data[j + k]); |
3584 | 32.2M | } |
3585 | 67.7M | else |
3586 | 67.7M | { |
3587 | 153M | for (k = 0; k < bpc; k++) |
3588 | 86.1M | printf ("%02x", (unsigned) data[j + k]); |
3589 | 67.7M | } |
3590 | 99.9M | } |
3591 | 99.9M | putchar (' '); |
3592 | 99.9M | } |
3593 | | |
3594 | 300M | for (; pb < octets_per_line; pb += bpc) |
3595 | 240M | { |
3596 | 240M | unsigned int k; |
3597 | | |
3598 | 503M | for (k = 0; k < bpc; k++) |
3599 | 262M | printf (" "); |
3600 | 240M | putchar (' '); |
3601 | 240M | } |
3602 | | |
3603 | | /* Separate raw data from instruction by extra space. */ |
3604 | 59.5M | if (insns) |
3605 | 59.5M | putchar ('\t'); |
3606 | 0 | else |
3607 | 0 | printf (" "); |
3608 | 59.5M | } |
3609 | | |
3610 | 59.5M | if (! insns) |
3611 | 0 | printf ("%s", buf); |
3612 | 59.5M | else if (sfile.pos) |
3613 | 59.5M | printf ("%s", sfile.buffer); |
3614 | | |
3615 | 59.5M | if (prefix_addresses |
3616 | 59.5M | ? show_raw_insn > 0 |
3617 | 59.5M | : show_raw_insn >= 0) |
3618 | 59.5M | { |
3619 | 59.8M | while (pb < octets) |
3620 | 308k | { |
3621 | 308k | bfd_vma j; |
3622 | 308k | char *s; |
3623 | | |
3624 | 308k | putchar ('\n'); |
3625 | 308k | j = addr_offset * opb + pb; |
3626 | | |
3627 | 308k | if (no_addresses) |
3628 | 0 | printf ("\t"); |
3629 | 308k | else |
3630 | 308k | { |
3631 | 308k | bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb); |
3632 | 1.27M | for (s = buf + skip_addr_chars; *s == '0'; s++) |
3633 | 968k | *s = ' '; |
3634 | 308k | if (*s == '\0') |
3635 | 1 | *--s = '0'; |
3636 | 308k | printf ("%s:\t", buf + skip_addr_chars); |
3637 | 308k | } |
3638 | | |
3639 | 308k | print_jump_visualisation (section->vma + j / opb, |
3640 | 308k | max_level, line_buffer, |
3641 | 308k | color_buffer); |
3642 | | |
3643 | 308k | pb += octets_per_line; |
3644 | 308k | if (pb > octets) |
3645 | 188k | pb = octets; |
3646 | 801k | for (; j < addr_offset * opb + pb; j += bpc) |
3647 | 492k | { |
3648 | | /* PR 21619: Check for a buffer ending early. */ |
3649 | 492k | if (j + bpc <= stop_offset * opb) |
3650 | 492k | { |
3651 | 492k | unsigned int k; |
3652 | | |
3653 | 492k | if (inf->display_endian == BFD_ENDIAN_LITTLE) |
3654 | 372k | { |
3655 | 899k | for (k = bpc; k-- != 0; ) |
3656 | 527k | printf ("%02x", (unsigned) data[j + k]); |
3657 | 372k | } |
3658 | 120k | else |
3659 | 120k | { |
3660 | 287k | for (k = 0; k < bpc; k++) |
3661 | 167k | printf ("%02x", (unsigned) data[j + k]); |
3662 | 120k | } |
3663 | 492k | } |
3664 | 492k | putchar (' '); |
3665 | 492k | } |
3666 | 308k | } |
3667 | 59.5M | } |
3668 | | |
3669 | 59.5M | if (!wide_output) |
3670 | 59.5M | putchar ('\n'); |
3671 | 0 | else |
3672 | 0 | need_nl = true; |
3673 | 59.5M | } |
3674 | | |
3675 | 60.9M | while (relpp < relppend |
3676 | 103k | && (*relpp)->address < rel_offset + addr_offset + octets / opb) |
3677 | 35.2k | { |
3678 | 35.2k | if (dump_reloc_info || dump_dynamic_reloc_info) |
3679 | 35.2k | { |
3680 | 35.2k | arelent *q; |
3681 | | |
3682 | 35.2k | q = *relpp; |
3683 | | |
3684 | 35.2k | if (wide_output) |
3685 | 0 | putchar ('\t'); |
3686 | 35.2k | else |
3687 | 35.2k | printf ("\t\t\t"); |
3688 | | |
3689 | 35.2k | if (!no_addresses) |
3690 | 35.2k | { |
3691 | 35.2k | objdump_print_value (section->vma - rel_offset + q->address, |
3692 | 35.2k | inf, true); |
3693 | 35.2k | printf (": "); |
3694 | 35.2k | } |
3695 | | |
3696 | 35.2k | if (q->howto == NULL) |
3697 | 431 | printf ("*unknown*\t"); |
3698 | 34.8k | else if (q->howto->name) |
3699 | 34.6k | printf ("%s\t", q->howto->name); |
3700 | 161 | else |
3701 | 161 | printf ("%d\t", q->howto->type); |
3702 | | |
3703 | 35.2k | if (q->sym_ptr_ptr == NULL || *q->sym_ptr_ptr == NULL) |
3704 | 0 | printf ("*unknown*"); |
3705 | 35.2k | else |
3706 | 35.2k | { |
3707 | 35.2k | const char *sym_name; |
3708 | | |
3709 | 35.2k | sym_name = bfd_asymbol_name (*q->sym_ptr_ptr); |
3710 | 35.2k | if (sym_name != NULL && *sym_name != '\0') |
3711 | 34.7k | objdump_print_symname (aux->abfd, inf, *q->sym_ptr_ptr); |
3712 | 564 | else |
3713 | 564 | { |
3714 | 564 | asection *sym_sec; |
3715 | | |
3716 | 564 | sym_sec = bfd_asymbol_section (*q->sym_ptr_ptr); |
3717 | 564 | sym_name = bfd_section_name (sym_sec); |
3718 | 564 | if (sym_name == NULL || *sym_name == '\0') |
3719 | 131 | sym_name = "*unknown*"; |
3720 | 564 | printf ("%s", sanitize_string (sym_name)); |
3721 | 564 | } |
3722 | 35.2k | } |
3723 | | |
3724 | 35.2k | if (q->addend) |
3725 | 5.71k | { |
3726 | 5.71k | bfd_vma addend = q->addend; |
3727 | 5.71k | if ((bfd_signed_vma) addend < 0) |
3728 | 1.76k | { |
3729 | 1.76k | printf ("-0x"); |
3730 | 1.76k | addend = -addend; |
3731 | 1.76k | } |
3732 | 3.95k | else |
3733 | 3.95k | printf ("+0x"); |
3734 | 5.71k | objdump_print_value (addend, inf, true); |
3735 | 5.71k | } |
3736 | | |
3737 | 35.2k | printf ("\n"); |
3738 | 35.2k | need_nl = false; |
3739 | 35.2k | } |
3740 | 35.2k | ++relpp; |
3741 | 35.2k | } |
3742 | | |
3743 | 60.8M | if (need_nl) |
3744 | 0 | printf ("\n"); |
3745 | | |
3746 | 60.8M | addr_offset += octets / opb; |
3747 | 60.8M | } |
3748 | | |
3749 | 87.0k | free (sfile.buffer); |
3750 | 87.0k | free (line_buffer); |
3751 | 87.0k | free (color_buffer); |
3752 | 87.0k | } fuzz_objdump.c:disassemble_bytes Line | Count | Source | 3282 | 87.0k | { | 3283 | 87.0k | struct objdump_disasm_info *aux; | 3284 | 87.0k | asection *section; | 3285 | 87.0k | unsigned int octets_per_line; | 3286 | 87.0k | unsigned int skip_addr_chars; | 3287 | 87.0k | bfd_vma addr_offset; | 3288 | 87.0k | unsigned int opb = inf->octets_per_byte; | 3289 | 87.0k | unsigned int skip_zeroes = inf->skip_zeroes; | 3290 | 87.0k | unsigned int skip_zeroes_at_end = inf->skip_zeroes_at_end; | 3291 | 87.0k | size_t octets; | 3292 | 87.0k | SFILE sfile; | 3293 | | | 3294 | 87.0k | aux = (struct objdump_disasm_info *) inf->application_data; | 3295 | 87.0k | section = inf->section; | 3296 | | | 3297 | 87.0k | sfile.alloc = 120; | 3298 | 87.0k | sfile.buffer = (char *) xmalloc (sfile.alloc); | 3299 | 87.0k | sfile.pos = 0; | 3300 | | | 3301 | 87.0k | if (insn_width) | 3302 | 0 | octets_per_line = insn_width; | 3303 | 87.0k | else if (insns) | 3304 | 87.0k | octets_per_line = 4; | 3305 | 0 | else | 3306 | 0 | octets_per_line = 16; | 3307 | | | 3308 | | /* Figure out how many characters to skip at the start of an | 3309 | | address, to make the disassembly look nicer. We discard leading | 3310 | | zeroes in chunks of 4, ensuring that there is always a leading | 3311 | | zero remaining. */ | 3312 | 87.0k | skip_addr_chars = 0; | 3313 | 87.0k | if (!no_addresses && !prefix_addresses) | 3314 | 87.0k | { | 3315 | 87.0k | char buf[30]; | 3316 | | | 3317 | 87.0k | bfd_sprintf_vma (aux->abfd, buf, section->vma + section->size / opb); | 3318 | | | 3319 | 534k | while (buf[skip_addr_chars] == '0') | 3320 | 447k | ++skip_addr_chars; | 3321 | | | 3322 | | /* Don't discard zeros on overflow. */ | 3323 | 87.0k | if (buf[skip_addr_chars] == '\0' && section->vma != 0) | 3324 | 4 | skip_addr_chars = 0; | 3325 | | | 3326 | 87.0k | if (skip_addr_chars != 0) | 3327 | 76.3k | skip_addr_chars = (skip_addr_chars - 1) & -4; | 3328 | 87.0k | } | 3329 | | | 3330 | 87.0k | inf->insn_info_valid = 0; | 3331 | | | 3332 | | /* Determine maximum level. */ | 3333 | 87.0k | uint8_t *color_buffer = NULL; | 3334 | 87.0k | char *line_buffer = NULL; | 3335 | 87.0k | int max_level = -1; | 3336 | | | 3337 | | /* Some jumps were detected. */ | 3338 | 87.0k | if (detected_jumps) | 3339 | 0 | { | 3340 | 0 | struct jump_info *ji; | 3341 | | | 3342 | | /* Find maximum jump level. */ | 3343 | 0 | for (ji = detected_jumps; ji; ji = ji->next) | 3344 | 0 | { | 3345 | 0 | if (ji->level > max_level) | 3346 | 0 | max_level = ji->level; | 3347 | 0 | } | 3348 | | | 3349 | | /* Allocate buffers. */ | 3350 | 0 | size_t len = (max_level + 1) * 3 + 1; | 3351 | 0 | line_buffer = xmalloc (len); | 3352 | 0 | line_buffer[len - 1] = 0; | 3353 | 0 | color_buffer = xmalloc (len); | 3354 | 0 | color_buffer[len - 1] = 0; | 3355 | 0 | } | 3356 | | | 3357 | 87.0k | addr_offset = start_offset; | 3358 | 60.9M | while (addr_offset < stop_offset) | 3359 | 60.8M | { | 3360 | 60.8M | bool need_nl = false; | 3361 | | | 3362 | 60.8M | octets = 0; | 3363 | | | 3364 | | /* Make sure we don't use relocs from previous instructions. */ | 3365 | 60.8M | aux->reloc = NULL; | 3366 | | | 3367 | | /* If we see more than SKIP_ZEROES octets of zeroes, we just | 3368 | | print `...'. */ | 3369 | 60.8M | if (! disassemble_zeroes) | 3370 | 140M | for (; octets < (stop_offset - addr_offset) * opb; octets++) | 3371 | 140M | if (data[addr_offset * opb + octets] != 0) | 3372 | 60.8M | break; | 3373 | 60.8M | if (! disassemble_zeroes | 3374 | 60.8M | && (inf->insn_info_valid == 0 | 3375 | 17.1M | || inf->branch_delay_insns == 0) | 3376 | 60.6M | && (octets >= skip_zeroes | 3377 | 59.3M | || (octets == (stop_offset - addr_offset) * opb | 3378 | 26.2k | && octets < skip_zeroes_at_end))) | 3379 | 1.31M | { | 3380 | | /* If there are more nonzero octets to follow, we only skip | 3381 | | zeroes in multiples of 4, to try to avoid running over | 3382 | | the start of an instruction which happens to start with | 3383 | | zero. */ | 3384 | 1.31M | if (octets != (stop_offset - addr_offset) * opb) | 3385 | 1.29M | octets &= ~3; | 3386 | | | 3387 | | /* If we are going to display more data, and we are displaying | 3388 | | file offsets, then tell the user how many zeroes we skip | 3389 | | and the file offset from where we resume dumping. */ | 3390 | 1.31M | if (display_file_offsets | 3391 | 0 | && octets / opb < stop_offset - addr_offset) | 3392 | 0 | printf (_("\t... (skipping %lu zeroes, " | 3393 | 0 | "resuming at file offset: 0x%lx)\n"), | 3394 | 0 | (unsigned long) (octets / opb), | 3395 | 0 | (unsigned long) (section->filepos | 3396 | 0 | + addr_offset + octets / opb)); | 3397 | 1.31M | else | 3398 | 1.31M | printf ("\t...\n"); | 3399 | 1.31M | } | 3400 | 59.5M | else | 3401 | 59.5M | { | 3402 | 59.5M | char buf[MAX_INSN_WIDTH + 1]; | 3403 | 59.5M | unsigned int bpc = 0; | 3404 | 59.5M | unsigned int pb = 0; | 3405 | | | 3406 | 59.5M | if (with_line_numbers || with_source_code) | 3407 | 0 | show_line (aux->abfd, section, addr_offset); | 3408 | | | 3409 | 59.5M | if (no_addresses) | 3410 | 0 | printf ("\t"); | 3411 | 59.5M | else if (!prefix_addresses) | 3412 | 59.5M | { | 3413 | 59.5M | char *s; | 3414 | | | 3415 | 59.5M | bfd_sprintf_vma (aux->abfd, buf, section->vma + addr_offset); | 3416 | 219M | for (s = buf + skip_addr_chars; *s == '0'; s++) | 3417 | 159M | *s = ' '; | 3418 | 59.5M | if (*s == '\0') | 3419 | 25.6k | *--s = '0'; | 3420 | 59.5M | printf ("%s:\t", buf + skip_addr_chars); | 3421 | 59.5M | } | 3422 | 0 | else | 3423 | 0 | { | 3424 | 0 | aux->require_sec = true; | 3425 | 0 | objdump_print_address (section->vma + addr_offset, inf); | 3426 | 0 | aux->require_sec = false; | 3427 | 0 | putchar (' '); | 3428 | 0 | } | 3429 | | | 3430 | 59.5M | print_jump_visualisation (section->vma + addr_offset, | 3431 | 59.5M | max_level, line_buffer, | 3432 | 59.5M | color_buffer); | 3433 | | | 3434 | 59.5M | if (insns) | 3435 | 59.5M | { | 3436 | 59.5M | int insn_size; | 3437 | | | 3438 | 59.5M | sfile.pos = 0; | 3439 | 59.5M | disassemble_set_printf | 3440 | 59.5M | (inf, &sfile, (fprintf_ftype) objdump_sprintf, | 3441 | 59.5M | (fprintf_styled_ftype) objdump_styled_sprintf); | 3442 | 59.5M | inf->bytes_per_line = 0; | 3443 | 59.5M | inf->bytes_per_chunk = 0; | 3444 | 59.5M | inf->flags = ((disassemble_all ? DISASSEMBLE_DATA : 0) | 3445 | 59.5M | | (wide_output ? WIDE_OUTPUT : 0)); | 3446 | 59.5M | if (machine) | 3447 | 0 | inf->flags |= USER_SPECIFIED_MACHINE_TYPE; | 3448 | | | 3449 | 59.5M | if (inf->disassembler_needs_relocs | 3450 | 11.7M | && (bfd_get_file_flags (aux->abfd) & EXEC_P) == 0 | 3451 | 10.7M | && (bfd_get_file_flags (aux->abfd) & DYNAMIC) == 0 | 3452 | 10.7M | && relpp < relppend) | 3453 | 3.43k | { | 3454 | 3.43k | bfd_signed_vma distance_to_rel; | 3455 | 3.43k | int max_reloc_offset | 3456 | 3.43k | = aux->abfd->arch_info->max_reloc_offset_into_insn; | 3457 | | | 3458 | 3.43k | distance_to_rel = ((*relpp)->address - rel_offset | 3459 | 3.43k | - addr_offset); | 3460 | | | 3461 | 3.43k | insn_size = 0; | 3462 | 3.43k | if (distance_to_rel > 0 | 3463 | 1.31k | && (max_reloc_offset < 0 | 3464 | 1.31k | || distance_to_rel <= max_reloc_offset)) | 3465 | 0 | { | 3466 | | /* This reloc *might* apply to the current insn, | 3467 | | starting somewhere inside it. Discover the length | 3468 | | of the current insn so that the check below will | 3469 | | work. */ | 3470 | 0 | if (insn_width) | 3471 | 0 | insn_size = insn_width; | 3472 | 0 | else | 3473 | 0 | { | 3474 | | /* We find the length by calling the dissassembler | 3475 | | function with a dummy print handler. This should | 3476 | | work unless the disassembler is not expecting to | 3477 | | be called multiple times for the same address. | 3478 | | | 3479 | | This does mean disassembling the instruction | 3480 | | twice, but we only do this when there is a high | 3481 | | probability that there is a reloc that will | 3482 | | affect the instruction. */ | 3483 | 0 | disassemble_set_printf | 3484 | 0 | (inf, inf->stream, (fprintf_ftype) null_print, | 3485 | 0 | (fprintf_styled_ftype) null_styled_print); | 3486 | 0 | insn_size = disassemble_fn (section->vma | 3487 | 0 | + addr_offset, inf); | 3488 | 0 | disassemble_set_printf | 3489 | 0 | (inf, inf->stream, | 3490 | 0 | (fprintf_ftype) objdump_sprintf, | 3491 | 0 | (fprintf_styled_ftype) objdump_styled_sprintf); | 3492 | 0 | } | 3493 | 0 | } | 3494 | | | 3495 | | /* Check to see if the current reloc is associated with | 3496 | | the instruction that we are about to disassemble. */ | 3497 | 3.43k | if (distance_to_rel == 0 | 3498 | 3.14k | || (distance_to_rel > 0 | 3499 | 1.31k | && distance_to_rel < insn_size / (int) opb)) | 3500 | 292 | { | 3501 | 292 | inf->flags |= INSN_HAS_RELOC; | 3502 | 292 | aux->reloc = *relpp; | 3503 | 292 | } | 3504 | 3.43k | } | 3505 | | | 3506 | 59.5M | if (! disassemble_all | 3507 | 0 | && ((section->flags & (SEC_CODE | SEC_HAS_CONTENTS)) | 3508 | 0 | == (SEC_CODE | SEC_HAS_CONTENTS))) | 3509 | | /* Set a stop_vma so that the disassembler will not read | 3510 | | beyond the next symbol. We assume that symbols appear on | 3511 | | the boundaries between instructions. We only do this when | 3512 | | disassembling code of course, and when -D is in effect. */ | 3513 | 0 | inf->stop_vma = section->vma + stop_offset; | 3514 | | | 3515 | 59.5M | inf->stop_offset = stop_offset; | 3516 | 59.5M | disassembler_in_comment = false; | 3517 | 59.5M | insn_size = (*disassemble_fn) (section->vma + addr_offset, inf); | 3518 | 59.5M | octets = insn_size; | 3519 | | | 3520 | 59.5M | inf->stop_vma = 0; | 3521 | 59.5M | disassemble_set_printf (inf, stdout, (fprintf_ftype) fprintf, | 3522 | 59.5M | (fprintf_styled_ftype) fprintf_styled); | 3523 | 59.5M | if (insn_width == 0 && inf->bytes_per_line != 0) | 3524 | 40.6M | octets_per_line = inf->bytes_per_line; | 3525 | 59.5M | if (insn_size < (int) opb) | 3526 | 28.2k | { | 3527 | 28.2k | if (sfile.pos) | 3528 | 26.4k | printf ("%s\n", sfile.buffer); | 3529 | 28.2k | if (insn_size >= 0) | 3530 | 0 | { | 3531 | 0 | non_fatal (_("disassemble_fn returned length %d"), | 3532 | 0 | insn_size); | 3533 | 0 | exit_status = 1; | 3534 | 0 | } | 3535 | 28.2k | break; | 3536 | 28.2k | } | 3537 | 59.5M | } | 3538 | 0 | else | 3539 | 0 | { | 3540 | 0 | bfd_vma j; | 3541 | |
| 3542 | 0 | octets = octets_per_line; | 3543 | 0 | if (octets / opb > stop_offset - addr_offset) | 3544 | 0 | octets = (stop_offset - addr_offset) * opb; | 3545 | |
| 3546 | 0 | for (j = addr_offset * opb; j < addr_offset * opb + octets; ++j) | 3547 | 0 | { | 3548 | 0 | if (ISPRINT (data[j])) | 3549 | 0 | buf[j - addr_offset * opb] = data[j]; | 3550 | 0 | else | 3551 | 0 | buf[j - addr_offset * opb] = '.'; | 3552 | 0 | } | 3553 | 0 | buf[j - addr_offset * opb] = '\0'; | 3554 | 0 | } | 3555 | | | 3556 | 59.5M | if (prefix_addresses | 3557 | 59.5M | ? show_raw_insn > 0 | 3558 | 59.5M | : show_raw_insn >= 0) | 3559 | 59.5M | { | 3560 | 59.5M | bfd_vma j; | 3561 | | | 3562 | | /* If ! prefix_addresses and ! wide_output, we print | 3563 | | octets_per_line octets per line. */ | 3564 | 59.5M | pb = octets; | 3565 | 59.5M | if (pb > octets_per_line && ! prefix_addresses && ! wide_output) | 3566 | 294k | pb = octets_per_line; | 3567 | | | 3568 | 59.5M | if (inf->bytes_per_chunk) | 3569 | 21.5M | bpc = inf->bytes_per_chunk; | 3570 | 37.9M | else | 3571 | 37.9M | bpc = 1; | 3572 | | | 3573 | 159M | for (j = addr_offset * opb; j < addr_offset * opb + pb; j += bpc) | 3574 | 99.9M | { | 3575 | | /* PR 21580: Check for a buffer ending early. */ | 3576 | 99.9M | if (j + bpc <= stop_offset * opb) | 3577 | 99.9M | { | 3578 | 99.9M | unsigned int k; | 3579 | | | 3580 | 99.9M | if (inf->display_endian == BFD_ENDIAN_LITTLE) | 3581 | 32.2M | { | 3582 | 99.7M | for (k = bpc; k-- != 0; ) | 3583 | 67.5M | printf ("%02x", (unsigned) data[j + k]); | 3584 | 32.2M | } | 3585 | 67.7M | else | 3586 | 67.7M | { | 3587 | 153M | for (k = 0; k < bpc; k++) | 3588 | 86.1M | printf ("%02x", (unsigned) data[j + k]); | 3589 | 67.7M | } | 3590 | 99.9M | } | 3591 | 99.9M | putchar (' '); | 3592 | 99.9M | } | 3593 | | | 3594 | 300M | for (; pb < octets_per_line; pb += bpc) | 3595 | 240M | { | 3596 | 240M | unsigned int k; | 3597 | | | 3598 | 503M | for (k = 0; k < bpc; k++) | 3599 | 262M | printf (" "); | 3600 | 240M | putchar (' '); | 3601 | 240M | } | 3602 | | | 3603 | | /* Separate raw data from instruction by extra space. */ | 3604 | 59.5M | if (insns) | 3605 | 59.5M | putchar ('\t'); | 3606 | 0 | else | 3607 | 0 | printf (" "); | 3608 | 59.5M | } | 3609 | | | 3610 | 59.5M | if (! insns) | 3611 | 0 | printf ("%s", buf); | 3612 | 59.5M | else if (sfile.pos) | 3613 | 59.5M | printf ("%s", sfile.buffer); | 3614 | | | 3615 | 59.5M | if (prefix_addresses | 3616 | 59.5M | ? show_raw_insn > 0 | 3617 | 59.5M | : show_raw_insn >= 0) | 3618 | 59.5M | { | 3619 | 59.8M | while (pb < octets) | 3620 | 308k | { | 3621 | 308k | bfd_vma j; | 3622 | 308k | char *s; | 3623 | | | 3624 | 308k | putchar ('\n'); | 3625 | 308k | j = addr_offset * opb + pb; | 3626 | | | 3627 | 308k | if (no_addresses) | 3628 | 0 | printf ("\t"); | 3629 | 308k | else | 3630 | 308k | { | 3631 | 308k | bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb); | 3632 | 1.27M | for (s = buf + skip_addr_chars; *s == '0'; s++) | 3633 | 968k | *s = ' '; | 3634 | 308k | if (*s == '\0') | 3635 | 1 | *--s = '0'; | 3636 | 308k | printf ("%s:\t", buf + skip_addr_chars); | 3637 | 308k | } | 3638 | | | 3639 | 308k | print_jump_visualisation (section->vma + j / opb, | 3640 | 308k | max_level, line_buffer, | 3641 | 308k | color_buffer); | 3642 | | | 3643 | 308k | pb += octets_per_line; | 3644 | 308k | if (pb > octets) | 3645 | 188k | pb = octets; | 3646 | 801k | for (; j < addr_offset * opb + pb; j += bpc) | 3647 | 492k | { | 3648 | | /* PR 21619: Check for a buffer ending early. */ | 3649 | 492k | if (j + bpc <= stop_offset * opb) | 3650 | 492k | { | 3651 | 492k | unsigned int k; | 3652 | | | 3653 | 492k | if (inf->display_endian == BFD_ENDIAN_LITTLE) | 3654 | 372k | { | 3655 | 899k | for (k = bpc; k-- != 0; ) | 3656 | 527k | printf ("%02x", (unsigned) data[j + k]); | 3657 | 372k | } | 3658 | 120k | else | 3659 | 120k | { | 3660 | 287k | for (k = 0; k < bpc; k++) | 3661 | 167k | printf ("%02x", (unsigned) data[j + k]); | 3662 | 120k | } | 3663 | 492k | } | 3664 | 492k | putchar (' '); | 3665 | 492k | } | 3666 | 308k | } | 3667 | 59.5M | } | 3668 | | | 3669 | 59.5M | if (!wide_output) | 3670 | 59.5M | putchar ('\n'); | 3671 | 0 | else | 3672 | 0 | need_nl = true; | 3673 | 59.5M | } | 3674 | | | 3675 | 60.9M | while (relpp < relppend | 3676 | 103k | && (*relpp)->address < rel_offset + addr_offset + octets / opb) | 3677 | 35.2k | { | 3678 | 35.2k | if (dump_reloc_info || dump_dynamic_reloc_info) | 3679 | 35.2k | { | 3680 | 35.2k | arelent *q; | 3681 | | | 3682 | 35.2k | q = *relpp; | 3683 | | | 3684 | 35.2k | if (wide_output) | 3685 | 0 | putchar ('\t'); | 3686 | 35.2k | else | 3687 | 35.2k | printf ("\t\t\t"); | 3688 | | | 3689 | 35.2k | if (!no_addresses) | 3690 | 35.2k | { | 3691 | 35.2k | objdump_print_value (section->vma - rel_offset + q->address, | 3692 | 35.2k | inf, true); | 3693 | 35.2k | printf (": "); | 3694 | 35.2k | } | 3695 | | | 3696 | 35.2k | if (q->howto == NULL) | 3697 | 431 | printf ("*unknown*\t"); | 3698 | 34.8k | else if (q->howto->name) | 3699 | 34.6k | printf ("%s\t", q->howto->name); | 3700 | 161 | else | 3701 | 161 | printf ("%d\t", q->howto->type); | 3702 | | | 3703 | 35.2k | if (q->sym_ptr_ptr == NULL || *q->sym_ptr_ptr == NULL) | 3704 | 0 | printf ("*unknown*"); | 3705 | 35.2k | else | 3706 | 35.2k | { | 3707 | 35.2k | const char *sym_name; | 3708 | | | 3709 | 35.2k | sym_name = bfd_asymbol_name (*q->sym_ptr_ptr); | 3710 | 35.2k | if (sym_name != NULL && *sym_name != '\0') | 3711 | 34.7k | objdump_print_symname (aux->abfd, inf, *q->sym_ptr_ptr); | 3712 | 564 | else | 3713 | 564 | { | 3714 | 564 | asection *sym_sec; | 3715 | | | 3716 | 564 | sym_sec = bfd_asymbol_section (*q->sym_ptr_ptr); | 3717 | 564 | sym_name = bfd_section_name (sym_sec); | 3718 | 564 | if (sym_name == NULL || *sym_name == '\0') | 3719 | 131 | sym_name = "*unknown*"; | 3720 | 564 | printf ("%s", sanitize_string (sym_name)); | 3721 | 564 | } | 3722 | 35.2k | } | 3723 | | | 3724 | 35.2k | if (q->addend) | 3725 | 5.71k | { | 3726 | 5.71k | bfd_vma addend = q->addend; | 3727 | 5.71k | if ((bfd_signed_vma) addend < 0) | 3728 | 1.76k | { | 3729 | 1.76k | printf ("-0x"); | 3730 | 1.76k | addend = -addend; | 3731 | 1.76k | } | 3732 | 3.95k | else | 3733 | 3.95k | printf ("+0x"); | 3734 | 5.71k | objdump_print_value (addend, inf, true); | 3735 | 5.71k | } | 3736 | | | 3737 | 35.2k | printf ("\n"); | 3738 | 35.2k | need_nl = false; | 3739 | 35.2k | } | 3740 | 35.2k | ++relpp; | 3741 | 35.2k | } | 3742 | | | 3743 | 60.8M | if (need_nl) | 3744 | 0 | printf ("\n"); | 3745 | | | 3746 | 60.8M | addr_offset += octets / opb; | 3747 | 60.8M | } | 3748 | | | 3749 | 87.0k | free (sfile.buffer); | 3750 | 87.0k | free (line_buffer); | 3751 | 87.0k | free (color_buffer); | 3752 | 87.0k | } |
Unexecuted instantiation: fuzz_dwarf.c:disassemble_bytes |
3753 | | |
3754 | | static void |
3755 | | disassemble_section (bfd *abfd, asection *section, void *inf) |
3756 | 773k | { |
3757 | 773k | elf_backend_data *bed; |
3758 | 773k | bfd_vma sign_adjust = 0; |
3759 | 773k | struct disassemble_info *pinfo = (struct disassemble_info *) inf; |
3760 | 773k | struct objdump_disasm_info *paux; |
3761 | 773k | unsigned int opb = pinfo->octets_per_byte; |
3762 | 773k | bfd_byte *data = NULL; |
3763 | 773k | bfd_size_type datasize = 0; |
3764 | 773k | arelent **rel_pp = NULL; |
3765 | 773k | arelent **rel_ppstart = NULL; |
3766 | 773k | arelent **rel_ppend; |
3767 | 773k | bfd_vma stop_offset; |
3768 | 773k | asymbol *sym = NULL; |
3769 | 773k | long place = 0; |
3770 | 773k | long rel_count; |
3771 | 773k | bfd_vma rel_offset; |
3772 | 773k | unsigned long addr_offset; |
3773 | 773k | bool do_print; |
3774 | 773k | enum loop_control |
3775 | 773k | { |
3776 | 773k | stop_offset_reached, |
3777 | 773k | function_sym, |
3778 | 773k | next_sym |
3779 | 773k | } loop_until; |
3780 | | |
3781 | 773k | if (only_list == NULL) |
3782 | 773k | { |
3783 | | /* Sections that do not contain machine |
3784 | | code are not normally disassembled. */ |
3785 | 773k | if ((section->flags & SEC_HAS_CONTENTS) == 0) |
3786 | 188k | return; |
3787 | | |
3788 | 585k | if (! disassemble_all |
3789 | 0 | && (section->flags & SEC_CODE) == 0) |
3790 | 0 | return; |
3791 | 585k | } |
3792 | 0 | else if (!process_section_p (section)) |
3793 | 0 | return; |
3794 | | |
3795 | 585k | datasize = bfd_section_size (section); |
3796 | 585k | if (datasize == 0) |
3797 | 38.7k | return; |
3798 | | |
3799 | 546k | if (start_address == (bfd_vma) -1 |
3800 | 0 | || start_address < section->vma) |
3801 | 546k | addr_offset = 0; |
3802 | 0 | else |
3803 | 0 | addr_offset = start_address - section->vma; |
3804 | | |
3805 | 546k | if (stop_address == (bfd_vma) -1) |
3806 | 546k | stop_offset = datasize / opb; |
3807 | 0 | else |
3808 | 0 | { |
3809 | 0 | if (stop_address < section->vma) |
3810 | 0 | stop_offset = 0; |
3811 | 0 | else |
3812 | 0 | stop_offset = stop_address - section->vma; |
3813 | 0 | if (stop_offset > datasize / opb) |
3814 | 0 | stop_offset = datasize / opb; |
3815 | 0 | } |
3816 | | |
3817 | 546k | if (addr_offset >= stop_offset) |
3818 | 0 | return; |
3819 | | |
3820 | | /* Decide which set of relocs to use. Load them if necessary. */ |
3821 | 546k | paux = (struct objdump_disasm_info *) pinfo->application_data; |
3822 | 546k | if (pinfo->dynrelbuf && dump_dynamic_reloc_info) |
3823 | 0 | { |
3824 | 0 | rel_pp = pinfo->dynrelbuf; |
3825 | 0 | rel_count = pinfo->dynrelcount; |
3826 | | /* Dynamic reloc addresses are absolute, non-dynamic are section |
3827 | | relative. REL_OFFSET specifies the reloc address corresponding |
3828 | | to the start of this section. */ |
3829 | 0 | rel_offset = section->vma; |
3830 | 0 | } |
3831 | 546k | else |
3832 | 546k | { |
3833 | 546k | rel_count = 0; |
3834 | 546k | rel_pp = NULL; |
3835 | 546k | rel_offset = 0; |
3836 | | |
3837 | 546k | if ((section->flags & SEC_RELOC) != 0 |
3838 | 251k | && (dump_reloc_info || pinfo->disassembler_needs_relocs)) |
3839 | 251k | { |
3840 | 251k | long relsize; |
3841 | | |
3842 | 251k | relsize = bfd_get_reloc_upper_bound (abfd, section); |
3843 | 251k | if (relsize < 0) |
3844 | 203k | my_bfd_nonfatal (bfd_get_filename (abfd)); |
3845 | | |
3846 | 251k | if (relsize > 0) |
3847 | 47.7k | { |
3848 | 47.7k | rel_pp = (arelent **) xmalloc (relsize); |
3849 | 47.7k | rel_count = bfd_canonicalize_reloc (abfd, section, rel_pp, syms); |
3850 | 47.7k | if (rel_count < 0) |
3851 | 45.7k | { |
3852 | 45.7k | my_bfd_nonfatal (bfd_get_filename (abfd)); |
3853 | 45.7k | free (rel_pp); |
3854 | 45.7k | rel_pp = NULL; |
3855 | 45.7k | rel_count = 0; |
3856 | 45.7k | } |
3857 | 2.00k | else if (rel_count > 1) |
3858 | | /* Sort the relocs by address. */ |
3859 | 1.49k | qsort (rel_pp, rel_count, sizeof (arelent *), compare_relocs); |
3860 | 47.7k | rel_ppstart = rel_pp; |
3861 | 47.7k | } |
3862 | 251k | } |
3863 | 546k | } |
3864 | 546k | rel_ppend = PTR_ADD (rel_pp, rel_count); |
3865 | | |
3866 | 546k | if (!bfd_malloc_and_get_section (abfd, section, &data)) |
3867 | 460k | { |
3868 | 460k | non_fatal (_("Reading section %s failed because: %s"), |
3869 | 460k | section->name, bfd_errmsg (bfd_get_error ())); |
3870 | 460k | free (rel_ppstart); |
3871 | 460k | return; |
3872 | 460k | } |
3873 | | |
3874 | 86.3k | pinfo->buffer = data; |
3875 | 86.3k | pinfo->buffer_vma = section->vma; |
3876 | 86.3k | pinfo->buffer_length = datasize; |
3877 | 86.3k | pinfo->section = section; |
3878 | | |
3879 | | /* Sort the symbols into value and section order. */ |
3880 | 86.3k | compare_section = section; |
3881 | 86.3k | if (sorted_symcount > 1) |
3882 | 3.84k | qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols); |
3883 | | |
3884 | 86.3k | printf (_("\nDisassembly of section %s:\n"), sanitize_string (section->name)); |
3885 | | |
3886 | | /* Find the nearest symbol forwards from our current position. */ |
3887 | 86.3k | paux->require_sec = true; |
3888 | 86.3k | sym = (asymbol *) find_symbol_for_address (section->vma + addr_offset, |
3889 | 86.3k | (struct disassemble_info *) inf, |
3890 | 86.3k | &place); |
3891 | 86.3k | paux->require_sec = false; |
3892 | | |
3893 | | /* PR 9774: If the target used signed addresses then we must make |
3894 | | sure that we sign extend the value that we calculate for 'addr' |
3895 | | in the loop below. */ |
3896 | 86.3k | if (bfd_get_flavour (abfd) == bfd_target_elf_flavour |
3897 | 50.0k | && (bed = get_elf_backend_data (abfd)) != NULL |
3898 | 50.0k | && bed->sign_extend_vma) |
3899 | 1.98k | sign_adjust = (bfd_vma) 1 << (bed->s->arch_size - 1); |
3900 | | |
3901 | | /* Disassemble a block of instructions up to the address associated with |
3902 | | the symbol we have just found. Then print the symbol and find the |
3903 | | next symbol on. Repeat until we have disassembled the entire section |
3904 | | or we have reached the end of the address range we are interested in. */ |
3905 | 86.3k | do_print = paux->symbol_list == NULL; |
3906 | 86.3k | loop_until = stop_offset_reached; |
3907 | | |
3908 | 173k | while (addr_offset < stop_offset) |
3909 | 87.0k | { |
3910 | 87.0k | bfd_vma addr; |
3911 | 87.0k | asymbol *nextsym; |
3912 | 87.0k | bfd_vma nextstop_offset; |
3913 | 87.0k | bool insns; |
3914 | | |
3915 | | /* Skip over the relocs belonging to addresses below the |
3916 | | start address. */ |
3917 | 87.0k | while (rel_pp < rel_ppend |
3918 | 1.77k | && (*rel_pp)->address < rel_offset + addr_offset) |
3919 | 68 | ++rel_pp; |
3920 | | |
3921 | 87.0k | addr = section->vma + addr_offset; |
3922 | 87.0k | addr = ((addr & ((sign_adjust << 1) - 1)) ^ sign_adjust) - sign_adjust; |
3923 | | |
3924 | 87.0k | if (sym != NULL && bfd_asymbol_value (sym) <= addr) |
3925 | 1.50k | { |
3926 | 1.50k | int x; |
3927 | | |
3928 | 1.50k | for (x = place; |
3929 | 4.68k | (x < sorted_symcount |
3930 | 4.20k | && (bfd_asymbol_value (sorted_syms[x]) <= addr)); |
3931 | 3.18k | ++x) |
3932 | 3.18k | continue; |
3933 | | |
3934 | 1.50k | pinfo->symbols = sorted_syms + place; |
3935 | 1.50k | pinfo->num_symbols = x - place; |
3936 | 1.50k | pinfo->symtab_pos = place; |
3937 | 1.50k | } |
3938 | 85.5k | else |
3939 | 85.5k | { |
3940 | 85.5k | pinfo->symbols = NULL; |
3941 | 85.5k | pinfo->num_symbols = 0; |
3942 | 85.5k | pinfo->symtab_pos = -1; |
3943 | 85.5k | } |
3944 | | |
3945 | | /* If we are only disassembling from specific symbols, |
3946 | | check to see if we should start or stop displaying. */ |
3947 | 87.0k | if (sym && paux->symbol_list) |
3948 | 0 | { |
3949 | 0 | if (do_print) |
3950 | 0 | { |
3951 | | /* See if we should stop printing. */ |
3952 | 0 | switch (loop_until) |
3953 | 0 | { |
3954 | 0 | case function_sym: |
3955 | 0 | if (sym->flags & BSF_FUNCTION) |
3956 | 0 | do_print = false; |
3957 | 0 | break; |
3958 | | |
3959 | 0 | case stop_offset_reached: |
3960 | | /* Handled by the while loop. */ |
3961 | 0 | break; |
3962 | | |
3963 | 0 | case next_sym: |
3964 | 0 | if (! bfd_is_local_label (abfd, sym)) |
3965 | 0 | do_print = false; |
3966 | 0 | break; |
3967 | 0 | } |
3968 | 0 | } |
3969 | | |
3970 | 0 | if (!do_print) |
3971 | 0 | { |
3972 | 0 | const char * name = bfd_asymbol_name (sym); |
3973 | 0 | char * alloc = NULL; |
3974 | |
|
3975 | 0 | if (do_demangle && name[0] != '\0') |
3976 | 0 | { |
3977 | | /* Demangle the name. */ |
3978 | 0 | alloc = bfd_demangle (abfd, name, demangle_flags); |
3979 | 0 | if (alloc != NULL) |
3980 | 0 | name = alloc; |
3981 | 0 | } |
3982 | | |
3983 | | /* We are not currently printing. Check to see |
3984 | | if the current symbol matches any of the requested symbols. */ |
3985 | 0 | for (const struct symbol_entry *ent = paux->symbol_list; |
3986 | 0 | ent; |
3987 | 0 | ent = ent->next) |
3988 | 0 | if (streq (name, ent->name)) |
3989 | 0 | { |
3990 | 0 | do_print = true; |
3991 | 0 | break; |
3992 | 0 | } |
3993 | 0 | if (do_print |
3994 | 0 | && bfd_asymbol_value (sym) <= addr) |
3995 | 0 | { |
3996 | 0 | do_print = true; |
3997 | |
|
3998 | 0 | loop_until = next_sym; |
3999 | 0 | if (sym->flags & BSF_FUNCTION) |
4000 | 0 | { |
4001 | 0 | loop_until = function_sym; |
4002 | |
|
4003 | 0 | if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) |
4004 | 0 | { |
4005 | 0 | bfd_size_type fsize = |
4006 | 0 | ((elf_symbol_type *) sym)->internal_elf_sym.st_size; |
4007 | 0 | bfd_vma fend = |
4008 | 0 | bfd_asymbol_value (sym) - section->vma + fsize; |
4009 | 0 | if (fend > addr_offset && fend <= stop_offset) |
4010 | 0 | { |
4011 | | /* Sym is a function symbol with a valid |
4012 | | size associated with it. Disassemble |
4013 | | to the end of the function. */ |
4014 | 0 | stop_offset = fend; |
4015 | 0 | loop_until = stop_offset_reached; |
4016 | 0 | } |
4017 | 0 | } |
4018 | 0 | } |
4019 | 0 | } |
4020 | |
|
4021 | 0 | free (alloc); |
4022 | 0 | } |
4023 | 0 | } |
4024 | | |
4025 | 87.0k | if (! prefix_addresses && do_print) |
4026 | 87.0k | { |
4027 | 87.0k | pinfo->fprintf_func (pinfo->stream, "\n"); |
4028 | 87.0k | objdump_print_addr_with_sym (abfd, section, sym, addr, |
4029 | 87.0k | pinfo, false); |
4030 | 87.0k | pinfo->fprintf_func (pinfo->stream, ":\n"); |
4031 | | |
4032 | 87.0k | if (sym != NULL && show_all_symbols) |
4033 | 0 | { |
4034 | 0 | for (++place; place < sorted_symcount; place++) |
4035 | 0 | { |
4036 | 0 | sym = sorted_syms[place]; |
4037 | | |
4038 | 0 | if (bfd_asymbol_value (sym) != addr) |
4039 | 0 | break; |
4040 | 0 | if (! pinfo->symbol_is_valid (sym, pinfo)) |
4041 | 0 | continue; |
4042 | 0 | if (strcmp (bfd_section_name (sym->section), bfd_section_name (section)) != 0) |
4043 | 0 | break; |
4044 | | |
4045 | 0 | objdump_print_addr_with_sym (abfd, section, sym, addr, pinfo, false); |
4046 | 0 | pinfo->fprintf_func (pinfo->stream, ":\n"); |
4047 | 0 | } |
4048 | 0 | } |
4049 | 87.0k | } |
4050 | | |
4051 | 87.0k | if (sym != NULL && bfd_asymbol_value (sym) > addr) |
4052 | 198 | nextsym = sym; |
4053 | 86.8k | else if (sym == NULL) |
4054 | 85.3k | nextsym = NULL; |
4055 | 1.50k | else |
4056 | 1.50k | { |
4057 | 1.50k | #define is_valid_next_sym(SYM) \ |
4058 | 6.33k | (strcmp (bfd_section_name ((SYM)->section), bfd_section_name (section)) == 0 \ |
4059 | 6.33k | && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \ |
4060 | 6.33k | && pinfo->symbol_is_valid (SYM, pinfo)) |
4061 | | |
4062 | | /* Search forward for the next appropriate symbol in |
4063 | | SECTION. Note that all the symbols are sorted |
4064 | | together into one big array, and that some sections |
4065 | | may have overlapping addresses. */ |
4066 | 7.25k | while (place < sorted_symcount |
4067 | 6.33k | && ! is_valid_next_sym (sorted_syms [place])) |
4068 | 5.75k | ++place; |
4069 | | |
4070 | 1.50k | if (place >= sorted_symcount) |
4071 | 919 | nextsym = NULL; |
4072 | 581 | else |
4073 | 581 | nextsym = sorted_syms[place]; |
4074 | 1.50k | } |
4075 | | |
4076 | 87.0k | if (sym != NULL && bfd_asymbol_value (sym) > addr) |
4077 | 198 | nextstop_offset = bfd_asymbol_value (sym) - section->vma; |
4078 | 86.8k | else if (nextsym == NULL) |
4079 | 86.2k | nextstop_offset = stop_offset; |
4080 | 581 | else |
4081 | 581 | nextstop_offset = bfd_asymbol_value (nextsym) - section->vma; |
4082 | | |
4083 | 87.0k | if (nextstop_offset > stop_offset |
4084 | 86.9k | || nextstop_offset <= addr_offset) |
4085 | 64 | nextstop_offset = stop_offset; |
4086 | | |
4087 | | /* To better handle embedded data in a code section, just dump |
4088 | | the bytes without disassembling them if we hit an object |
4089 | | symbol. Exclude _PROCEDURE_LINKAGE_TABLE_ as some ABIs |
4090 | | require it to be an object even though code is expected. |
4091 | | Take no notice of symbols if the user has explicity asked for |
4092 | | a non-code section to be disassembled. */ |
4093 | 87.0k | if (disassemble_all |
4094 | 0 | || (section->flags & SEC_CODE) == 0 |
4095 | 0 | || sym == NULL |
4096 | 0 | || sym->section != section |
4097 | 0 | || bfd_asymbol_value (sym) > addr |
4098 | 0 | || (sym->flags & BSF_OBJECT) == 0 |
4099 | 0 | || (sym->flags & BSF_FUNCTION) != 0 |
4100 | 0 | || strcmp (sym->name, "_PROCEDURE_LINKAGE_TABLE_") == 0) |
4101 | 87.0k | insns = true; |
4102 | 0 | else |
4103 | 0 | insns = false; |
4104 | | |
4105 | 87.0k | if (do_print) |
4106 | 87.0k | { |
4107 | | /* Resolve symbol name. */ |
4108 | 87.0k | if (visualize_jumps && abfd && sym && sym->name) |
4109 | 0 | { |
4110 | 0 | struct disassemble_info di; |
4111 | 0 | SFILE sf; |
4112 | |
|
4113 | 0 | sf.alloc = strlen (sym->name) + 40; |
4114 | 0 | sf.buffer = (char*) xmalloc (sf.alloc); |
4115 | 0 | sf.pos = 0; |
4116 | 0 | disassemble_set_printf |
4117 | 0 | (&di, &sf, (fprintf_ftype) objdump_sprintf, |
4118 | 0 | (fprintf_styled_ftype) objdump_styled_sprintf); |
4119 | |
|
4120 | 0 | objdump_print_symname (abfd, &di, sym); |
4121 | | |
4122 | | /* Fetch jump information. */ |
4123 | 0 | detected_jumps = disassemble_jumps (pinfo, paux->disassemble_fn, |
4124 | 0 | addr_offset, nextstop_offset, |
4125 | 0 | rel_offset, rel_pp, rel_ppend); |
4126 | | /* Free symbol name. */ |
4127 | 0 | free (sf.buffer); |
4128 | 0 | } |
4129 | | |
4130 | | /* Add jumps to output. */ |
4131 | 87.0k | disassemble_bytes (pinfo, paux->disassemble_fn, insns, data, |
4132 | 87.0k | addr_offset, nextstop_offset, |
4133 | 87.0k | rel_offset, rel_pp, rel_ppend); |
4134 | | |
4135 | | /* Free jumps. */ |
4136 | 87.0k | while (detected_jumps) |
4137 | 0 | { |
4138 | 0 | detected_jumps = jump_info_free (detected_jumps); |
4139 | 0 | } |
4140 | 87.0k | } |
4141 | | |
4142 | 87.0k | addr_offset = nextstop_offset; |
4143 | 87.0k | sym = nextsym; |
4144 | 87.0k | } |
4145 | | |
4146 | 86.3k | free (data); |
4147 | 86.3k | free (rel_ppstart); |
4148 | 86.3k | } fuzz_objdump.c:disassemble_section Line | Count | Source | 3756 | 773k | { | 3757 | 773k | elf_backend_data *bed; | 3758 | 773k | bfd_vma sign_adjust = 0; | 3759 | 773k | struct disassemble_info *pinfo = (struct disassemble_info *) inf; | 3760 | 773k | struct objdump_disasm_info *paux; | 3761 | 773k | unsigned int opb = pinfo->octets_per_byte; | 3762 | 773k | bfd_byte *data = NULL; | 3763 | 773k | bfd_size_type datasize = 0; | 3764 | 773k | arelent **rel_pp = NULL; | 3765 | 773k | arelent **rel_ppstart = NULL; | 3766 | 773k | arelent **rel_ppend; | 3767 | 773k | bfd_vma stop_offset; | 3768 | 773k | asymbol *sym = NULL; | 3769 | 773k | long place = 0; | 3770 | 773k | long rel_count; | 3771 | 773k | bfd_vma rel_offset; | 3772 | 773k | unsigned long addr_offset; | 3773 | 773k | bool do_print; | 3774 | 773k | enum loop_control | 3775 | 773k | { | 3776 | 773k | stop_offset_reached, | 3777 | 773k | function_sym, | 3778 | 773k | next_sym | 3779 | 773k | } loop_until; | 3780 | | | 3781 | 773k | if (only_list == NULL) | 3782 | 773k | { | 3783 | | /* Sections that do not contain machine | 3784 | | code are not normally disassembled. */ | 3785 | 773k | if ((section->flags & SEC_HAS_CONTENTS) == 0) | 3786 | 188k | return; | 3787 | | | 3788 | 585k | if (! disassemble_all | 3789 | 0 | && (section->flags & SEC_CODE) == 0) | 3790 | 0 | return; | 3791 | 585k | } | 3792 | 0 | else if (!process_section_p (section)) | 3793 | 0 | return; | 3794 | | | 3795 | 585k | datasize = bfd_section_size (section); | 3796 | 585k | if (datasize == 0) | 3797 | 38.7k | return; | 3798 | | | 3799 | 546k | if (start_address == (bfd_vma) -1 | 3800 | 0 | || start_address < section->vma) | 3801 | 546k | addr_offset = 0; | 3802 | 0 | else | 3803 | 0 | addr_offset = start_address - section->vma; | 3804 | | | 3805 | 546k | if (stop_address == (bfd_vma) -1) | 3806 | 546k | stop_offset = datasize / opb; | 3807 | 0 | else | 3808 | 0 | { | 3809 | 0 | if (stop_address < section->vma) | 3810 | 0 | stop_offset = 0; | 3811 | 0 | else | 3812 | 0 | stop_offset = stop_address - section->vma; | 3813 | 0 | if (stop_offset > datasize / opb) | 3814 | 0 | stop_offset = datasize / opb; | 3815 | 0 | } | 3816 | | | 3817 | 546k | if (addr_offset >= stop_offset) | 3818 | 0 | return; | 3819 | | | 3820 | | /* Decide which set of relocs to use. Load them if necessary. */ | 3821 | 546k | paux = (struct objdump_disasm_info *) pinfo->application_data; | 3822 | 546k | if (pinfo->dynrelbuf && dump_dynamic_reloc_info) | 3823 | 0 | { | 3824 | 0 | rel_pp = pinfo->dynrelbuf; | 3825 | 0 | rel_count = pinfo->dynrelcount; | 3826 | | /* Dynamic reloc addresses are absolute, non-dynamic are section | 3827 | | relative. REL_OFFSET specifies the reloc address corresponding | 3828 | | to the start of this section. */ | 3829 | 0 | rel_offset = section->vma; | 3830 | 0 | } | 3831 | 546k | else | 3832 | 546k | { | 3833 | 546k | rel_count = 0; | 3834 | 546k | rel_pp = NULL; | 3835 | 546k | rel_offset = 0; | 3836 | | | 3837 | 546k | if ((section->flags & SEC_RELOC) != 0 | 3838 | 251k | && (dump_reloc_info || pinfo->disassembler_needs_relocs)) | 3839 | 251k | { | 3840 | 251k | long relsize; | 3841 | | | 3842 | 251k | relsize = bfd_get_reloc_upper_bound (abfd, section); | 3843 | 251k | if (relsize < 0) | 3844 | 203k | my_bfd_nonfatal (bfd_get_filename (abfd)); | 3845 | | | 3846 | 251k | if (relsize > 0) | 3847 | 47.7k | { | 3848 | 47.7k | rel_pp = (arelent **) xmalloc (relsize); | 3849 | 47.7k | rel_count = bfd_canonicalize_reloc (abfd, section, rel_pp, syms); | 3850 | 47.7k | if (rel_count < 0) | 3851 | 45.7k | { | 3852 | 45.7k | my_bfd_nonfatal (bfd_get_filename (abfd)); | 3853 | 45.7k | free (rel_pp); | 3854 | 45.7k | rel_pp = NULL; | 3855 | 45.7k | rel_count = 0; | 3856 | 45.7k | } | 3857 | 2.00k | else if (rel_count > 1) | 3858 | | /* Sort the relocs by address. */ | 3859 | 1.49k | qsort (rel_pp, rel_count, sizeof (arelent *), compare_relocs); | 3860 | 47.7k | rel_ppstart = rel_pp; | 3861 | 47.7k | } | 3862 | 251k | } | 3863 | 546k | } | 3864 | 546k | rel_ppend = PTR_ADD (rel_pp, rel_count); | 3865 | | | 3866 | 546k | if (!bfd_malloc_and_get_section (abfd, section, &data)) | 3867 | 460k | { | 3868 | 460k | non_fatal (_("Reading section %s failed because: %s"), | 3869 | 460k | section->name, bfd_errmsg (bfd_get_error ())); | 3870 | 460k | free (rel_ppstart); | 3871 | 460k | return; | 3872 | 460k | } | 3873 | | | 3874 | 86.3k | pinfo->buffer = data; | 3875 | 86.3k | pinfo->buffer_vma = section->vma; | 3876 | 86.3k | pinfo->buffer_length = datasize; | 3877 | 86.3k | pinfo->section = section; | 3878 | | | 3879 | | /* Sort the symbols into value and section order. */ | 3880 | 86.3k | compare_section = section; | 3881 | 86.3k | if (sorted_symcount > 1) | 3882 | 3.84k | qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols); | 3883 | | | 3884 | 86.3k | printf (_("\nDisassembly of section %s:\n"), sanitize_string (section->name)); | 3885 | | | 3886 | | /* Find the nearest symbol forwards from our current position. */ | 3887 | 86.3k | paux->require_sec = true; | 3888 | 86.3k | sym = (asymbol *) find_symbol_for_address (section->vma + addr_offset, | 3889 | 86.3k | (struct disassemble_info *) inf, | 3890 | 86.3k | &place); | 3891 | 86.3k | paux->require_sec = false; | 3892 | | | 3893 | | /* PR 9774: If the target used signed addresses then we must make | 3894 | | sure that we sign extend the value that we calculate for 'addr' | 3895 | | in the loop below. */ | 3896 | 86.3k | if (bfd_get_flavour (abfd) == bfd_target_elf_flavour | 3897 | 50.0k | && (bed = get_elf_backend_data (abfd)) != NULL | 3898 | 50.0k | && bed->sign_extend_vma) | 3899 | 1.98k | sign_adjust = (bfd_vma) 1 << (bed->s->arch_size - 1); | 3900 | | | 3901 | | /* Disassemble a block of instructions up to the address associated with | 3902 | | the symbol we have just found. Then print the symbol and find the | 3903 | | next symbol on. Repeat until we have disassembled the entire section | 3904 | | or we have reached the end of the address range we are interested in. */ | 3905 | 86.3k | do_print = paux->symbol_list == NULL; | 3906 | 86.3k | loop_until = stop_offset_reached; | 3907 | | | 3908 | 173k | while (addr_offset < stop_offset) | 3909 | 87.0k | { | 3910 | 87.0k | bfd_vma addr; | 3911 | 87.0k | asymbol *nextsym; | 3912 | 87.0k | bfd_vma nextstop_offset; | 3913 | 87.0k | bool insns; | 3914 | | | 3915 | | /* Skip over the relocs belonging to addresses below the | 3916 | | start address. */ | 3917 | 87.0k | while (rel_pp < rel_ppend | 3918 | 1.77k | && (*rel_pp)->address < rel_offset + addr_offset) | 3919 | 68 | ++rel_pp; | 3920 | | | 3921 | 87.0k | addr = section->vma + addr_offset; | 3922 | 87.0k | addr = ((addr & ((sign_adjust << 1) - 1)) ^ sign_adjust) - sign_adjust; | 3923 | | | 3924 | 87.0k | if (sym != NULL && bfd_asymbol_value (sym) <= addr) | 3925 | 1.50k | { | 3926 | 1.50k | int x; | 3927 | | | 3928 | 1.50k | for (x = place; | 3929 | 4.68k | (x < sorted_symcount | 3930 | 4.20k | && (bfd_asymbol_value (sorted_syms[x]) <= addr)); | 3931 | 3.18k | ++x) | 3932 | 3.18k | continue; | 3933 | | | 3934 | 1.50k | pinfo->symbols = sorted_syms + place; | 3935 | 1.50k | pinfo->num_symbols = x - place; | 3936 | 1.50k | pinfo->symtab_pos = place; | 3937 | 1.50k | } | 3938 | 85.5k | else | 3939 | 85.5k | { | 3940 | 85.5k | pinfo->symbols = NULL; | 3941 | 85.5k | pinfo->num_symbols = 0; | 3942 | 85.5k | pinfo->symtab_pos = -1; | 3943 | 85.5k | } | 3944 | | | 3945 | | /* If we are only disassembling from specific symbols, | 3946 | | check to see if we should start or stop displaying. */ | 3947 | 87.0k | if (sym && paux->symbol_list) | 3948 | 0 | { | 3949 | 0 | if (do_print) | 3950 | 0 | { | 3951 | | /* See if we should stop printing. */ | 3952 | 0 | switch (loop_until) | 3953 | 0 | { | 3954 | 0 | case function_sym: | 3955 | 0 | if (sym->flags & BSF_FUNCTION) | 3956 | 0 | do_print = false; | 3957 | 0 | break; | 3958 | | | 3959 | 0 | case stop_offset_reached: | 3960 | | /* Handled by the while loop. */ | 3961 | 0 | break; | 3962 | | | 3963 | 0 | case next_sym: | 3964 | 0 | if (! bfd_is_local_label (abfd, sym)) | 3965 | 0 | do_print = false; | 3966 | 0 | break; | 3967 | 0 | } | 3968 | 0 | } | 3969 | | | 3970 | 0 | if (!do_print) | 3971 | 0 | { | 3972 | 0 | const char * name = bfd_asymbol_name (sym); | 3973 | 0 | char * alloc = NULL; | 3974 | |
| 3975 | 0 | if (do_demangle && name[0] != '\0') | 3976 | 0 | { | 3977 | | /* Demangle the name. */ | 3978 | 0 | alloc = bfd_demangle (abfd, name, demangle_flags); | 3979 | 0 | if (alloc != NULL) | 3980 | 0 | name = alloc; | 3981 | 0 | } | 3982 | | | 3983 | | /* We are not currently printing. Check to see | 3984 | | if the current symbol matches any of the requested symbols. */ | 3985 | 0 | for (const struct symbol_entry *ent = paux->symbol_list; | 3986 | 0 | ent; | 3987 | 0 | ent = ent->next) | 3988 | 0 | if (streq (name, ent->name)) | 3989 | 0 | { | 3990 | 0 | do_print = true; | 3991 | 0 | break; | 3992 | 0 | } | 3993 | 0 | if (do_print | 3994 | 0 | && bfd_asymbol_value (sym) <= addr) | 3995 | 0 | { | 3996 | 0 | do_print = true; | 3997 | |
| 3998 | 0 | loop_until = next_sym; | 3999 | 0 | if (sym->flags & BSF_FUNCTION) | 4000 | 0 | { | 4001 | 0 | loop_until = function_sym; | 4002 | |
| 4003 | 0 | if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) | 4004 | 0 | { | 4005 | 0 | bfd_size_type fsize = | 4006 | 0 | ((elf_symbol_type *) sym)->internal_elf_sym.st_size; | 4007 | 0 | bfd_vma fend = | 4008 | 0 | bfd_asymbol_value (sym) - section->vma + fsize; | 4009 | 0 | if (fend > addr_offset && fend <= stop_offset) | 4010 | 0 | { | 4011 | | /* Sym is a function symbol with a valid | 4012 | | size associated with it. Disassemble | 4013 | | to the end of the function. */ | 4014 | 0 | stop_offset = fend; | 4015 | 0 | loop_until = stop_offset_reached; | 4016 | 0 | } | 4017 | 0 | } | 4018 | 0 | } | 4019 | 0 | } | 4020 | |
| 4021 | 0 | free (alloc); | 4022 | 0 | } | 4023 | 0 | } | 4024 | | | 4025 | 87.0k | if (! prefix_addresses && do_print) | 4026 | 87.0k | { | 4027 | 87.0k | pinfo->fprintf_func (pinfo->stream, "\n"); | 4028 | 87.0k | objdump_print_addr_with_sym (abfd, section, sym, addr, | 4029 | 87.0k | pinfo, false); | 4030 | 87.0k | pinfo->fprintf_func (pinfo->stream, ":\n"); | 4031 | | | 4032 | 87.0k | if (sym != NULL && show_all_symbols) | 4033 | 0 | { | 4034 | 0 | for (++place; place < sorted_symcount; place++) | 4035 | 0 | { | 4036 | 0 | sym = sorted_syms[place]; | 4037 | | | 4038 | 0 | if (bfd_asymbol_value (sym) != addr) | 4039 | 0 | break; | 4040 | 0 | if (! pinfo->symbol_is_valid (sym, pinfo)) | 4041 | 0 | continue; | 4042 | 0 | if (strcmp (bfd_section_name (sym->section), bfd_section_name (section)) != 0) | 4043 | 0 | break; | 4044 | | | 4045 | 0 | objdump_print_addr_with_sym (abfd, section, sym, addr, pinfo, false); | 4046 | 0 | pinfo->fprintf_func (pinfo->stream, ":\n"); | 4047 | 0 | } | 4048 | 0 | } | 4049 | 87.0k | } | 4050 | | | 4051 | 87.0k | if (sym != NULL && bfd_asymbol_value (sym) > addr) | 4052 | 198 | nextsym = sym; | 4053 | 86.8k | else if (sym == NULL) | 4054 | 85.3k | nextsym = NULL; | 4055 | 1.50k | else | 4056 | 1.50k | { | 4057 | 1.50k | #define is_valid_next_sym(SYM) \ | 4058 | 1.50k | (strcmp (bfd_section_name ((SYM)->section), bfd_section_name (section)) == 0 \ | 4059 | 1.50k | && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \ | 4060 | 1.50k | && pinfo->symbol_is_valid (SYM, pinfo)) | 4061 | | | 4062 | | /* Search forward for the next appropriate symbol in | 4063 | | SECTION. Note that all the symbols are sorted | 4064 | | together into one big array, and that some sections | 4065 | | may have overlapping addresses. */ | 4066 | 7.25k | while (place < sorted_symcount | 4067 | 6.33k | && ! is_valid_next_sym (sorted_syms [place])) | 4068 | 5.75k | ++place; | 4069 | | | 4070 | 1.50k | if (place >= sorted_symcount) | 4071 | 919 | nextsym = NULL; | 4072 | 581 | else | 4073 | 581 | nextsym = sorted_syms[place]; | 4074 | 1.50k | } | 4075 | | | 4076 | 87.0k | if (sym != NULL && bfd_asymbol_value (sym) > addr) | 4077 | 198 | nextstop_offset = bfd_asymbol_value (sym) - section->vma; | 4078 | 86.8k | else if (nextsym == NULL) | 4079 | 86.2k | nextstop_offset = stop_offset; | 4080 | 581 | else | 4081 | 581 | nextstop_offset = bfd_asymbol_value (nextsym) - section->vma; | 4082 | | | 4083 | 87.0k | if (nextstop_offset > stop_offset | 4084 | 86.9k | || nextstop_offset <= addr_offset) | 4085 | 64 | nextstop_offset = stop_offset; | 4086 | | | 4087 | | /* To better handle embedded data in a code section, just dump | 4088 | | the bytes without disassembling them if we hit an object | 4089 | | symbol. Exclude _PROCEDURE_LINKAGE_TABLE_ as some ABIs | 4090 | | require it to be an object even though code is expected. | 4091 | | Take no notice of symbols if the user has explicity asked for | 4092 | | a non-code section to be disassembled. */ | 4093 | 87.0k | if (disassemble_all | 4094 | 0 | || (section->flags & SEC_CODE) == 0 | 4095 | 0 | || sym == NULL | 4096 | 0 | || sym->section != section | 4097 | 0 | || bfd_asymbol_value (sym) > addr | 4098 | 0 | || (sym->flags & BSF_OBJECT) == 0 | 4099 | 0 | || (sym->flags & BSF_FUNCTION) != 0 | 4100 | 0 | || strcmp (sym->name, "_PROCEDURE_LINKAGE_TABLE_") == 0) | 4101 | 87.0k | insns = true; | 4102 | 0 | else | 4103 | 0 | insns = false; | 4104 | | | 4105 | 87.0k | if (do_print) | 4106 | 87.0k | { | 4107 | | /* Resolve symbol name. */ | 4108 | 87.0k | if (visualize_jumps && abfd && sym && sym->name) | 4109 | 0 | { | 4110 | 0 | struct disassemble_info di; | 4111 | 0 | SFILE sf; | 4112 | |
| 4113 | 0 | sf.alloc = strlen (sym->name) + 40; | 4114 | 0 | sf.buffer = (char*) xmalloc (sf.alloc); | 4115 | 0 | sf.pos = 0; | 4116 | 0 | disassemble_set_printf | 4117 | 0 | (&di, &sf, (fprintf_ftype) objdump_sprintf, | 4118 | 0 | (fprintf_styled_ftype) objdump_styled_sprintf); | 4119 | |
| 4120 | 0 | objdump_print_symname (abfd, &di, sym); | 4121 | | | 4122 | | /* Fetch jump information. */ | 4123 | 0 | detected_jumps = disassemble_jumps (pinfo, paux->disassemble_fn, | 4124 | 0 | addr_offset, nextstop_offset, | 4125 | 0 | rel_offset, rel_pp, rel_ppend); | 4126 | | /* Free symbol name. */ | 4127 | 0 | free (sf.buffer); | 4128 | 0 | } | 4129 | | | 4130 | | /* Add jumps to output. */ | 4131 | 87.0k | disassemble_bytes (pinfo, paux->disassemble_fn, insns, data, | 4132 | 87.0k | addr_offset, nextstop_offset, | 4133 | 87.0k | rel_offset, rel_pp, rel_ppend); | 4134 | | | 4135 | | /* Free jumps. */ | 4136 | 87.0k | while (detected_jumps) | 4137 | 0 | { | 4138 | 0 | detected_jumps = jump_info_free (detected_jumps); | 4139 | 0 | } | 4140 | 87.0k | } | 4141 | | | 4142 | 87.0k | addr_offset = nextstop_offset; | 4143 | 87.0k | sym = nextsym; | 4144 | 87.0k | } | 4145 | | | 4146 | 86.3k | free (data); | 4147 | 86.3k | free (rel_ppstart); | 4148 | 86.3k | } |
Unexecuted instantiation: fuzz_dwarf.c:disassemble_section |
4149 | | |
4150 | | /* Disassemble the contents of an object file. */ |
4151 | | |
4152 | | static void |
4153 | | disassemble_data (bfd *abfd) |
4154 | 29.3k | { |
4155 | 29.3k | struct disassemble_info disasm_info; |
4156 | 29.3k | struct objdump_disasm_info aux; |
4157 | 29.3k | long i; |
4158 | | |
4159 | 29.3k | print_files = NULL; |
4160 | 29.3k | prev_functionname = NULL; |
4161 | 29.3k | prev_line = -1; |
4162 | 29.3k | prev_discriminator = 0; |
4163 | | |
4164 | | /* We make a copy of syms to sort. We don't want to sort syms |
4165 | | because that will screw up the relocs. */ |
4166 | 29.3k | sorted_symcount = symcount ? symcount : dynsymcount; |
4167 | 29.3k | sorted_syms = (asymbol **) xmalloc ((sorted_symcount + synthcount) |
4168 | 29.3k | * sizeof (asymbol *)); |
4169 | 29.3k | if (sorted_symcount != 0) |
4170 | 1.03k | { |
4171 | 1.03k | memcpy (sorted_syms, symcount ? syms : dynsyms, |
4172 | 1.03k | sorted_symcount * sizeof (asymbol *)); |
4173 | | |
4174 | 1.03k | sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount); |
4175 | 1.03k | } |
4176 | | |
4177 | 29.5k | for (i = 0; i < synthcount; ++i) |
4178 | 249 | { |
4179 | 249 | sorted_syms[sorted_symcount] = synthsyms + i; |
4180 | 249 | ++sorted_symcount; |
4181 | 249 | } |
4182 | | |
4183 | 29.3k | init_disassemble_info (&disasm_info, stdout, (fprintf_ftype) fprintf, |
4184 | 29.3k | (fprintf_styled_ftype) fprintf_styled); |
4185 | 29.3k | disasm_info.application_data = (void *) &aux; |
4186 | 29.3k | aux.abfd = abfd; |
4187 | 29.3k | aux.require_sec = false; |
4188 | 29.3k | disasm_info.dynrelbuf = NULL; |
4189 | 29.3k | disasm_info.dynrelcount = 0; |
4190 | 29.3k | aux.reloc = NULL; |
4191 | 29.3k | aux.symbol_list = disasm_sym_list; |
4192 | | |
4193 | 29.3k | disasm_info.print_address_func = objdump_print_address; |
4194 | 29.3k | disasm_info.symbol_at_address_func = objdump_symbol_at_address; |
4195 | | |
4196 | 29.3k | if (machine != NULL) |
4197 | 0 | { |
4198 | 0 | const bfd_arch_info_type *inf = bfd_scan_arch (machine); |
4199 | |
|
4200 | 0 | if (inf == NULL) |
4201 | 0 | { |
4202 | 0 | non_fatal (_("can't use supplied machine %s"), machine); |
4203 | 0 | exit_status = 1; |
4204 | 0 | } |
4205 | 0 | else |
4206 | 0 | abfd->arch_info = inf; |
4207 | 0 | } |
4208 | | |
4209 | 29.3k | const struct bfd_target *old_xvec = NULL; |
4210 | 29.3k | if (endian != BFD_ENDIAN_UNKNOWN) |
4211 | 0 | { |
4212 | 0 | struct bfd_target *xvec = xmalloc (sizeof (*xvec)); |
4213 | 0 | old_xvec = abfd->xvec; |
4214 | 0 | memcpy (xvec, old_xvec, sizeof (*xvec)); |
4215 | 0 | xvec->byteorder = endian; |
4216 | 0 | abfd->xvec = xvec; |
4217 | 0 | } |
4218 | | |
4219 | | /* Use libopcodes to locate a suitable disassembler. */ |
4220 | 29.3k | aux.disassemble_fn = disassembler (bfd_get_arch (abfd), |
4221 | 29.3k | bfd_big_endian (abfd), |
4222 | 29.3k | bfd_get_mach (abfd), abfd); |
4223 | 29.3k | if (!aux.disassemble_fn) |
4224 | 387 | { |
4225 | 387 | non_fatal (_("can't disassemble for architecture %s\n"), |
4226 | 387 | bfd_printable_arch_mach (bfd_get_arch (abfd), 0)); |
4227 | 387 | exit_status = 1; |
4228 | 387 | goto out; |
4229 | 387 | } |
4230 | | |
4231 | 28.9k | disasm_info.flavour = bfd_get_flavour (abfd); |
4232 | 28.9k | disasm_info.arch = bfd_get_arch (abfd); |
4233 | 28.9k | disasm_info.mach = bfd_get_mach (abfd); |
4234 | 28.9k | disasm_info.disassembler_options = disassembler_options; |
4235 | 28.9k | disasm_info.octets_per_byte = bfd_octets_per_byte (abfd, NULL); |
4236 | 28.9k | disasm_info.skip_zeroes = DEFAULT_SKIP_ZEROES; |
4237 | 28.9k | disasm_info.skip_zeroes_at_end = DEFAULT_SKIP_ZEROES_AT_END; |
4238 | 28.9k | disasm_info.disassembler_needs_relocs = false; |
4239 | | |
4240 | 28.9k | if (bfd_big_endian (abfd)) |
4241 | 11.7k | disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG; |
4242 | 17.1k | else if (bfd_little_endian (abfd)) |
4243 | 17.1k | disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_LITTLE; |
4244 | 0 | else |
4245 | | /* ??? Aborting here seems too drastic. We could default to big or little |
4246 | | instead. */ |
4247 | 0 | disasm_info.endian = BFD_ENDIAN_UNKNOWN; |
4248 | | |
4249 | 28.9k | disasm_info.endian_code = disasm_info.endian; |
4250 | | |
4251 | | /* Allow the target to customize the info structure. */ |
4252 | 28.9k | disassemble_init_for_target (& disasm_info); |
4253 | | |
4254 | | /* Pre-load the dynamic relocs as we may need them during the disassembly. */ |
4255 | 28.9k | long relsize = bfd_get_dynamic_reloc_upper_bound (abfd); |
4256 | | |
4257 | 28.9k | if (relsize > 0) |
4258 | 239 | { |
4259 | 239 | disasm_info.dynrelbuf = (arelent **) xmalloc (relsize); |
4260 | 239 | disasm_info.dynrelcount |
4261 | 239 | = bfd_canonicalize_dynamic_reloc (abfd, disasm_info.dynrelbuf, dynsyms); |
4262 | 239 | if (disasm_info.dynrelcount < 0) |
4263 | 19 | { |
4264 | 19 | my_bfd_nonfatal (bfd_get_filename (abfd)); |
4265 | 19 | free (disasm_info.dynrelbuf); |
4266 | 19 | disasm_info.dynrelbuf = NULL; |
4267 | 19 | disasm_info.dynrelcount = 0; |
4268 | 19 | } |
4269 | 220 | else if (disasm_info.dynrelcount > 1) |
4270 | | /* Sort the relocs by address. */ |
4271 | 61 | qsort (disasm_info.dynrelbuf, disasm_info.dynrelcount, |
4272 | 61 | sizeof (arelent *), compare_relocs); |
4273 | 239 | } |
4274 | | |
4275 | 28.9k | disasm_info.symtab = sorted_syms; |
4276 | 28.9k | disasm_info.symtab_size = sorted_symcount; |
4277 | | |
4278 | 28.9k | bfd_map_over_sections (abfd, disassemble_section, & disasm_info); |
4279 | | |
4280 | 28.9k | free (disasm_info.dynrelbuf); |
4281 | 28.9k | disasm_info.dynrelbuf = NULL; |
4282 | 28.9k | disassemble_free_target (&disasm_info); |
4283 | 29.3k | out: |
4284 | 29.3k | free (sorted_syms); |
4285 | 29.3k | sorted_syms = NULL; |
4286 | 29.3k | if (old_xvec) |
4287 | 0 | { |
4288 | 0 | free ((void *) abfd->xvec); |
4289 | 0 | abfd->xvec = old_xvec; |
4290 | 0 | } |
4291 | 29.3k | } fuzz_objdump.c:disassemble_data Line | Count | Source | 4154 | 29.3k | { | 4155 | 29.3k | struct disassemble_info disasm_info; | 4156 | 29.3k | struct objdump_disasm_info aux; | 4157 | 29.3k | long i; | 4158 | | | 4159 | 29.3k | print_files = NULL; | 4160 | 29.3k | prev_functionname = NULL; | 4161 | 29.3k | prev_line = -1; | 4162 | 29.3k | prev_discriminator = 0; | 4163 | | | 4164 | | /* We make a copy of syms to sort. We don't want to sort syms | 4165 | | because that will screw up the relocs. */ | 4166 | 29.3k | sorted_symcount = symcount ? symcount : dynsymcount; | 4167 | 29.3k | sorted_syms = (asymbol **) xmalloc ((sorted_symcount + synthcount) | 4168 | 29.3k | * sizeof (asymbol *)); | 4169 | 29.3k | if (sorted_symcount != 0) | 4170 | 1.03k | { | 4171 | 1.03k | memcpy (sorted_syms, symcount ? syms : dynsyms, | 4172 | 1.03k | sorted_symcount * sizeof (asymbol *)); | 4173 | | | 4174 | 1.03k | sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount); | 4175 | 1.03k | } | 4176 | | | 4177 | 29.5k | for (i = 0; i < synthcount; ++i) | 4178 | 249 | { | 4179 | 249 | sorted_syms[sorted_symcount] = synthsyms + i; | 4180 | 249 | ++sorted_symcount; | 4181 | 249 | } | 4182 | | | 4183 | 29.3k | init_disassemble_info (&disasm_info, stdout, (fprintf_ftype) fprintf, | 4184 | 29.3k | (fprintf_styled_ftype) fprintf_styled); | 4185 | 29.3k | disasm_info.application_data = (void *) &aux; | 4186 | 29.3k | aux.abfd = abfd; | 4187 | 29.3k | aux.require_sec = false; | 4188 | 29.3k | disasm_info.dynrelbuf = NULL; | 4189 | 29.3k | disasm_info.dynrelcount = 0; | 4190 | 29.3k | aux.reloc = NULL; | 4191 | 29.3k | aux.symbol_list = disasm_sym_list; | 4192 | | | 4193 | 29.3k | disasm_info.print_address_func = objdump_print_address; | 4194 | 29.3k | disasm_info.symbol_at_address_func = objdump_symbol_at_address; | 4195 | | | 4196 | 29.3k | if (machine != NULL) | 4197 | 0 | { | 4198 | 0 | const bfd_arch_info_type *inf = bfd_scan_arch (machine); | 4199 | |
| 4200 | 0 | if (inf == NULL) | 4201 | 0 | { | 4202 | 0 | non_fatal (_("can't use supplied machine %s"), machine); | 4203 | 0 | exit_status = 1; | 4204 | 0 | } | 4205 | 0 | else | 4206 | 0 | abfd->arch_info = inf; | 4207 | 0 | } | 4208 | | | 4209 | 29.3k | const struct bfd_target *old_xvec = NULL; | 4210 | 29.3k | if (endian != BFD_ENDIAN_UNKNOWN) | 4211 | 0 | { | 4212 | 0 | struct bfd_target *xvec = xmalloc (sizeof (*xvec)); | 4213 | 0 | old_xvec = abfd->xvec; | 4214 | 0 | memcpy (xvec, old_xvec, sizeof (*xvec)); | 4215 | 0 | xvec->byteorder = endian; | 4216 | 0 | abfd->xvec = xvec; | 4217 | 0 | } | 4218 | | | 4219 | | /* Use libopcodes to locate a suitable disassembler. */ | 4220 | 29.3k | aux.disassemble_fn = disassembler (bfd_get_arch (abfd), | 4221 | 29.3k | bfd_big_endian (abfd), | 4222 | 29.3k | bfd_get_mach (abfd), abfd); | 4223 | 29.3k | if (!aux.disassemble_fn) | 4224 | 387 | { | 4225 | 387 | non_fatal (_("can't disassemble for architecture %s\n"), | 4226 | 387 | bfd_printable_arch_mach (bfd_get_arch (abfd), 0)); | 4227 | 387 | exit_status = 1; | 4228 | 387 | goto out; | 4229 | 387 | } | 4230 | | | 4231 | 28.9k | disasm_info.flavour = bfd_get_flavour (abfd); | 4232 | 28.9k | disasm_info.arch = bfd_get_arch (abfd); | 4233 | 28.9k | disasm_info.mach = bfd_get_mach (abfd); | 4234 | 28.9k | disasm_info.disassembler_options = disassembler_options; | 4235 | 28.9k | disasm_info.octets_per_byte = bfd_octets_per_byte (abfd, NULL); | 4236 | 28.9k | disasm_info.skip_zeroes = DEFAULT_SKIP_ZEROES; | 4237 | 28.9k | disasm_info.skip_zeroes_at_end = DEFAULT_SKIP_ZEROES_AT_END; | 4238 | 28.9k | disasm_info.disassembler_needs_relocs = false; | 4239 | | | 4240 | 28.9k | if (bfd_big_endian (abfd)) | 4241 | 11.7k | disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG; | 4242 | 17.1k | else if (bfd_little_endian (abfd)) | 4243 | 17.1k | disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_LITTLE; | 4244 | 0 | else | 4245 | | /* ??? Aborting here seems too drastic. We could default to big or little | 4246 | | instead. */ | 4247 | 0 | disasm_info.endian = BFD_ENDIAN_UNKNOWN; | 4248 | | | 4249 | 28.9k | disasm_info.endian_code = disasm_info.endian; | 4250 | | | 4251 | | /* Allow the target to customize the info structure. */ | 4252 | 28.9k | disassemble_init_for_target (& disasm_info); | 4253 | | | 4254 | | /* Pre-load the dynamic relocs as we may need them during the disassembly. */ | 4255 | 28.9k | long relsize = bfd_get_dynamic_reloc_upper_bound (abfd); | 4256 | | | 4257 | 28.9k | if (relsize > 0) | 4258 | 239 | { | 4259 | 239 | disasm_info.dynrelbuf = (arelent **) xmalloc (relsize); | 4260 | 239 | disasm_info.dynrelcount | 4261 | 239 | = bfd_canonicalize_dynamic_reloc (abfd, disasm_info.dynrelbuf, dynsyms); | 4262 | 239 | if (disasm_info.dynrelcount < 0) | 4263 | 19 | { | 4264 | 19 | my_bfd_nonfatal (bfd_get_filename (abfd)); | 4265 | 19 | free (disasm_info.dynrelbuf); | 4266 | 19 | disasm_info.dynrelbuf = NULL; | 4267 | 19 | disasm_info.dynrelcount = 0; | 4268 | 19 | } | 4269 | 220 | else if (disasm_info.dynrelcount > 1) | 4270 | | /* Sort the relocs by address. */ | 4271 | 61 | qsort (disasm_info.dynrelbuf, disasm_info.dynrelcount, | 4272 | 61 | sizeof (arelent *), compare_relocs); | 4273 | 239 | } | 4274 | | | 4275 | 28.9k | disasm_info.symtab = sorted_syms; | 4276 | 28.9k | disasm_info.symtab_size = sorted_symcount; | 4277 | | | 4278 | 28.9k | bfd_map_over_sections (abfd, disassemble_section, & disasm_info); | 4279 | | | 4280 | 28.9k | free (disasm_info.dynrelbuf); | 4281 | 28.9k | disasm_info.dynrelbuf = NULL; | 4282 | 28.9k | disassemble_free_target (&disasm_info); | 4283 | 29.3k | out: | 4284 | 29.3k | free (sorted_syms); | 4285 | 29.3k | sorted_syms = NULL; | 4286 | 29.3k | if (old_xvec) | 4287 | 0 | { | 4288 | 0 | free ((void *) abfd->xvec); | 4289 | 0 | abfd->xvec = old_xvec; | 4290 | 0 | } | 4291 | 29.3k | } |
Unexecuted instantiation: fuzz_dwarf.c:disassemble_data |
4292 | | |
4293 | | static bool |
4294 | | load_specific_debug_section (enum dwarf_section_display_enum debug, |
4295 | | asection *sec, void *file) |
4296 | 12.0k | { |
4297 | 12.0k | struct dwarf_section *section = &debug_displays [debug].section; |
4298 | 12.0k | bfd *abfd = (bfd *) file; |
4299 | 12.0k | bfd_byte *contents; |
4300 | 12.0k | bfd_size_type amt; |
4301 | 12.0k | size_t alloced; |
4302 | 12.0k | bool ret; |
4303 | | |
4304 | 12.0k | if (section->start != NULL) |
4305 | 2.23k | { |
4306 | | /* If it is already loaded, do nothing. */ |
4307 | 2.23k | if (streq (section->filename, bfd_get_filename (abfd))) |
4308 | 2.23k | return true; |
4309 | 0 | free (section->start); |
4310 | 0 | section->start = NULL; |
4311 | 0 | } |
4312 | | |
4313 | 9.85k | section->filename = bfd_get_filename (abfd); |
4314 | 9.85k | section->reloc_info = NULL; |
4315 | 9.85k | section->num_relocs = 0; |
4316 | 9.85k | section->address = bfd_section_vma (sec); |
4317 | 9.85k | section->size = bfd_section_size (sec); |
4318 | | /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */ |
4319 | 9.85k | alloced = amt = section->size + 1; |
4320 | 9.85k | if (alloced != amt |
4321 | 9.85k | || alloced == 0 |
4322 | 9.85k | || bfd_section_size_insane (abfd, sec)) |
4323 | 418 | { |
4324 | 418 | printf (_("\nSection '%s' has an invalid size: %#" PRIx64 ".\n"), |
4325 | 418 | sanitize_string (section->name), |
4326 | 418 | section->size); |
4327 | 418 | free_debug_section (debug); |
4328 | 418 | return false; |
4329 | 418 | } |
4330 | | |
4331 | 9.44k | ret = false; |
4332 | 9.44k | if ((sec->flags & SEC_HAS_CONTENTS) != 0) |
4333 | 9.43k | { |
4334 | 9.43k | section->start = contents = xmalloc (alloced); |
4335 | | /* Ensure any string section has a terminating NUL. */ |
4336 | 9.43k | section->start[section->size] = 0; |
4337 | | |
4338 | 9.43k | if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0 |
4339 | 6.29k | && debug_displays [debug].relocate) |
4340 | 4.67k | { |
4341 | 4.67k | ret = bfd_simple_get_relocated_section_contents (abfd, |
4342 | 4.67k | sec, |
4343 | 4.67k | section->start, |
4344 | 4.67k | syms) != NULL; |
4345 | 4.67k | if (ret) |
4346 | 3.19k | { |
4347 | 3.19k | long reloc_size = bfd_get_reloc_upper_bound (abfd, sec); |
4348 | | |
4349 | 3.19k | if (reloc_size > 0) |
4350 | 3.05k | { |
4351 | 3.05k | long reloc_count; |
4352 | 3.05k | arelent **relocs; |
4353 | | |
4354 | 3.05k | relocs = (arelent **) xmalloc (reloc_size); |
4355 | | |
4356 | 3.05k | reloc_count = bfd_canonicalize_reloc (abfd, sec, relocs, syms); |
4357 | 3.05k | if (reloc_count <= 0) |
4358 | 2.31k | free (relocs); |
4359 | 745 | else |
4360 | 745 | { |
4361 | 745 | section->reloc_info = relocs; |
4362 | 745 | section->num_relocs = reloc_count; |
4363 | 745 | } |
4364 | 3.05k | } |
4365 | 3.19k | } |
4366 | 4.67k | } |
4367 | 4.75k | else |
4368 | 4.75k | ret = bfd_get_full_section_contents (abfd, sec, &contents); |
4369 | 9.43k | } |
4370 | | |
4371 | 9.44k | if (!ret) |
4372 | 1.48k | { |
4373 | 1.48k | printf (_("\nCan't get contents for section '%s'.\n"), |
4374 | 1.48k | sanitize_string (section->name)); |
4375 | 1.48k | free_debug_section (debug); |
4376 | 1.48k | return false; |
4377 | 1.48k | } |
4378 | | |
4379 | 7.95k | return true; |
4380 | 9.44k | } fuzz_objdump.c:load_specific_debug_section Line | Count | Source | 4296 | 12.0k | { | 4297 | 12.0k | struct dwarf_section *section = &debug_displays [debug].section; | 4298 | 12.0k | bfd *abfd = (bfd *) file; | 4299 | 12.0k | bfd_byte *contents; | 4300 | 12.0k | bfd_size_type amt; | 4301 | 12.0k | size_t alloced; | 4302 | 12.0k | bool ret; | 4303 | | | 4304 | 12.0k | if (section->start != NULL) | 4305 | 2.23k | { | 4306 | | /* If it is already loaded, do nothing. */ | 4307 | 2.23k | if (streq (section->filename, bfd_get_filename (abfd))) | 4308 | 2.23k | return true; | 4309 | 0 | free (section->start); | 4310 | 0 | section->start = NULL; | 4311 | 0 | } | 4312 | | | 4313 | 9.85k | section->filename = bfd_get_filename (abfd); | 4314 | 9.85k | section->reloc_info = NULL; | 4315 | 9.85k | section->num_relocs = 0; | 4316 | 9.85k | section->address = bfd_section_vma (sec); | 4317 | 9.85k | section->size = bfd_section_size (sec); | 4318 | | /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */ | 4319 | 9.85k | alloced = amt = section->size + 1; | 4320 | 9.85k | if (alloced != amt | 4321 | 9.85k | || alloced == 0 | 4322 | 9.85k | || bfd_section_size_insane (abfd, sec)) | 4323 | 418 | { | 4324 | 418 | printf (_("\nSection '%s' has an invalid size: %#" PRIx64 ".\n"), | 4325 | 418 | sanitize_string (section->name), | 4326 | 418 | section->size); | 4327 | 418 | free_debug_section (debug); | 4328 | 418 | return false; | 4329 | 418 | } | 4330 | | | 4331 | 9.44k | ret = false; | 4332 | 9.44k | if ((sec->flags & SEC_HAS_CONTENTS) != 0) | 4333 | 9.43k | { | 4334 | 9.43k | section->start = contents = xmalloc (alloced); | 4335 | | /* Ensure any string section has a terminating NUL. */ | 4336 | 9.43k | section->start[section->size] = 0; | 4337 | | | 4338 | 9.43k | if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0 | 4339 | 6.29k | && debug_displays [debug].relocate) | 4340 | 4.67k | { | 4341 | 4.67k | ret = bfd_simple_get_relocated_section_contents (abfd, | 4342 | 4.67k | sec, | 4343 | 4.67k | section->start, | 4344 | 4.67k | syms) != NULL; | 4345 | 4.67k | if (ret) | 4346 | 3.19k | { | 4347 | 3.19k | long reloc_size = bfd_get_reloc_upper_bound (abfd, sec); | 4348 | | | 4349 | 3.19k | if (reloc_size > 0) | 4350 | 3.05k | { | 4351 | 3.05k | long reloc_count; | 4352 | 3.05k | arelent **relocs; | 4353 | | | 4354 | 3.05k | relocs = (arelent **) xmalloc (reloc_size); | 4355 | | | 4356 | 3.05k | reloc_count = bfd_canonicalize_reloc (abfd, sec, relocs, syms); | 4357 | 3.05k | if (reloc_count <= 0) | 4358 | 2.31k | free (relocs); | 4359 | 745 | else | 4360 | 745 | { | 4361 | 745 | section->reloc_info = relocs; | 4362 | 745 | section->num_relocs = reloc_count; | 4363 | 745 | } | 4364 | 3.05k | } | 4365 | 3.19k | } | 4366 | 4.67k | } | 4367 | 4.75k | else | 4368 | 4.75k | ret = bfd_get_full_section_contents (abfd, sec, &contents); | 4369 | 9.43k | } | 4370 | | | 4371 | 9.44k | if (!ret) | 4372 | 1.48k | { | 4373 | 1.48k | printf (_("\nCan't get contents for section '%s'.\n"), | 4374 | 1.48k | sanitize_string (section->name)); | 4375 | 1.48k | free_debug_section (debug); | 4376 | 1.48k | return false; | 4377 | 1.48k | } | 4378 | | | 4379 | 7.95k | return true; | 4380 | 9.44k | } |
Unexecuted instantiation: fuzz_dwarf.c:load_specific_debug_section |
4381 | | |
4382 | | bool |
4383 | | reloc_at (struct dwarf_section * dsec, uint64_t offset) |
4384 | 105 | { |
4385 | 105 | arelent ** relocs; |
4386 | 105 | arelent * rp; |
4387 | | |
4388 | 105 | if (dsec == NULL || dsec->reloc_info == NULL) |
4389 | 79 | return false; |
4390 | | |
4391 | 26 | relocs = (arelent **) dsec->reloc_info; |
4392 | | |
4393 | 58 | for (; (rp = * relocs) != NULL; ++ relocs) |
4394 | 35 | if (rp->address == offset) |
4395 | 3 | return true; |
4396 | | |
4397 | 23 | return false; |
4398 | 26 | } |
4399 | | |
4400 | | bool |
4401 | | load_debug_section (enum dwarf_section_display_enum debug, void *file) |
4402 | 165k | { |
4403 | 165k | struct dwarf_section *section = &debug_displays [debug].section; |
4404 | 165k | bfd *abfd = (bfd *) file; |
4405 | 165k | asection *sec; |
4406 | 165k | const char *name; |
4407 | | |
4408 | | /* If it is already loaded, do nothing. */ |
4409 | 165k | if (section->start != NULL) |
4410 | 1.20k | { |
4411 | 1.20k | if (streq (section->filename, bfd_get_filename (abfd))) |
4412 | 1.20k | return true; |
4413 | 1.20k | } |
4414 | | /* Locate the debug section. */ |
4415 | 163k | name = section->uncompressed_name; |
4416 | 163k | sec = bfd_get_section_by_name (abfd, name); |
4417 | 163k | if (sec == NULL) |
4418 | 161k | { |
4419 | 161k | name = section->compressed_name; |
4420 | 161k | if (*name) |
4421 | 35.5k | sec = bfd_get_section_by_name (abfd, name); |
4422 | 161k | } |
4423 | 163k | if (sec == NULL) |
4424 | 161k | { |
4425 | 161k | name = section->xcoff_name; |
4426 | 161k | if (*name) |
4427 | 31.2k | sec = bfd_get_section_by_name (abfd, name); |
4428 | 161k | } |
4429 | 163k | if (sec == NULL) |
4430 | 161k | return false; |
4431 | | |
4432 | 2.20k | section->name = name; |
4433 | 2.20k | return load_specific_debug_section (debug, sec, file); |
4434 | 163k | } |
4435 | | |
4436 | | void |
4437 | | free_debug_section (enum dwarf_section_display_enum debug) |
4438 | 1.60M | { |
4439 | 1.60M | struct dwarf_section *section = &debug_displays [debug].section; |
4440 | | |
4441 | 1.60M | free ((char *) section->start); |
4442 | 1.60M | section->start = NULL; |
4443 | 1.60M | section->address = 0; |
4444 | 1.60M | section->size = 0; |
4445 | 1.60M | free ((char*) section->reloc_info); |
4446 | 1.60M | section->reloc_info = NULL; |
4447 | 1.60M | section->num_relocs= 0; |
4448 | 1.60M | } |
4449 | | |
4450 | | void |
4451 | | close_debug_file (void * file) |
4452 | 41.1k | { |
4453 | 41.1k | bfd * abfd = (bfd *) file; |
4454 | | |
4455 | 41.1k | bfd_close (abfd); |
4456 | 41.1k | } |
4457 | | |
4458 | | void * |
4459 | | open_debug_file (const char * pathname) |
4460 | 658 | { |
4461 | 658 | bfd * data; |
4462 | | |
4463 | 658 | data = bfd_openr (pathname, NULL); |
4464 | 658 | if (data == NULL) |
4465 | 658 | return NULL; |
4466 | | |
4467 | | /* Decompress sections unless dumping the section contents. */ |
4468 | 0 | if (!dump_section_contents || decompressed_dumps) |
4469 | 0 | data->flags |= BFD_DECOMPRESS; |
4470 | |
|
4471 | 0 | if (! bfd_check_format (data, bfd_object)) |
4472 | 0 | return NULL; |
4473 | | |
4474 | 0 | return data; |
4475 | 0 | } |
4476 | | |
4477 | | static void |
4478 | | dump_dwarf_section (bfd *abfd, asection *section, |
4479 | | void *arg) |
4480 | 898k | { |
4481 | 898k | const char *name = bfd_section_name (section); |
4482 | 898k | const char *match; |
4483 | 898k | int i; |
4484 | 898k | bool is_mainfile = *(bool *) arg; |
4485 | | |
4486 | 898k | if (*name == 0) |
4487 | 137k | return; |
4488 | | |
4489 | 761k | if (!is_mainfile && !process_links |
4490 | 0 | && (section->flags & SEC_DEBUGGING) == 0) |
4491 | 0 | return; |
4492 | | |
4493 | 761k | if (startswith (name, ".gnu.linkonce.wi.")) |
4494 | 1 | match = ".debug_info"; |
4495 | 761k | else |
4496 | 761k | match = name; |
4497 | | |
4498 | 38.3M | for (i = 0; i < max; i++) |
4499 | 37.6M | if ((strcmp (debug_displays [i].section.uncompressed_name, match) == 0 |
4500 | 37.6M | || strcmp (debug_displays [i].section.compressed_name, match) == 0 |
4501 | 37.6M | || strcmp (debug_displays [i].section.xcoff_name, match) == 0) |
4502 | 9.95k | && debug_displays [i].enabled != NULL |
4503 | 9.89k | && *debug_displays [i].enabled) |
4504 | 9.89k | { |
4505 | 9.89k | struct dwarf_section *sec = &debug_displays [i].section; |
4506 | | |
4507 | 9.89k | if (strcmp (sec->uncompressed_name, match) == 0) |
4508 | 4.55k | sec->name = sec->uncompressed_name; |
4509 | 5.33k | else if (strcmp (sec->compressed_name, match) == 0) |
4510 | 24 | sec->name = sec->compressed_name; |
4511 | 5.31k | else |
4512 | 5.31k | sec->name = sec->xcoff_name; |
4513 | 9.89k | if (load_specific_debug_section ((enum dwarf_section_display_enum) i, |
4514 | 9.89k | section, abfd)) |
4515 | 8.31k | { |
4516 | 8.31k | debug_displays [i].display (sec, abfd); |
4517 | | |
4518 | 8.31k | if (i != info && i != abbrev) |
4519 | 5.01k | free_debug_section ((enum dwarf_section_display_enum) i); |
4520 | 8.31k | } |
4521 | 9.89k | break; |
4522 | 9.89k | } |
4523 | 761k | } fuzz_objdump.c:dump_dwarf_section Line | Count | Source | 4480 | 898k | { | 4481 | 898k | const char *name = bfd_section_name (section); | 4482 | 898k | const char *match; | 4483 | 898k | int i; | 4484 | 898k | bool is_mainfile = *(bool *) arg; | 4485 | | | 4486 | 898k | if (*name == 0) | 4487 | 137k | return; | 4488 | | | 4489 | 761k | if (!is_mainfile && !process_links | 4490 | 0 | && (section->flags & SEC_DEBUGGING) == 0) | 4491 | 0 | return; | 4492 | | | 4493 | 761k | if (startswith (name, ".gnu.linkonce.wi.")) | 4494 | 1 | match = ".debug_info"; | 4495 | 761k | else | 4496 | 761k | match = name; | 4497 | | | 4498 | 38.3M | for (i = 0; i < max; i++) | 4499 | 37.6M | if ((strcmp (debug_displays [i].section.uncompressed_name, match) == 0 | 4500 | 37.6M | || strcmp (debug_displays [i].section.compressed_name, match) == 0 | 4501 | 37.6M | || strcmp (debug_displays [i].section.xcoff_name, match) == 0) | 4502 | 9.95k | && debug_displays [i].enabled != NULL | 4503 | 9.89k | && *debug_displays [i].enabled) | 4504 | 9.89k | { | 4505 | 9.89k | struct dwarf_section *sec = &debug_displays [i].section; | 4506 | | | 4507 | 9.89k | if (strcmp (sec->uncompressed_name, match) == 0) | 4508 | 4.55k | sec->name = sec->uncompressed_name; | 4509 | 5.33k | else if (strcmp (sec->compressed_name, match) == 0) | 4510 | 24 | sec->name = sec->compressed_name; | 4511 | 5.31k | else | 4512 | 5.31k | sec->name = sec->xcoff_name; | 4513 | 9.89k | if (load_specific_debug_section ((enum dwarf_section_display_enum) i, | 4514 | 9.89k | section, abfd)) | 4515 | 8.31k | { | 4516 | 8.31k | debug_displays [i].display (sec, abfd); | 4517 | | | 4518 | 8.31k | if (i != info && i != abbrev) | 4519 | 5.01k | free_debug_section ((enum dwarf_section_display_enum) i); | 4520 | 8.31k | } | 4521 | 9.89k | break; | 4522 | 9.89k | } | 4523 | 761k | } |
Unexecuted instantiation: fuzz_dwarf.c:dump_dwarf_section |
4524 | | |
4525 | | static void |
4526 | | dump_global_variable_info (bfd *abfd, asection *section, |
4527 | | void *arg) |
4528 | 0 | { |
4529 | 0 | const char *name = bfd_section_name (section); |
4530 | 0 | const char *match; |
4531 | 0 | bool is_mainfile = *(bool *) arg; |
4532 | |
|
4533 | 0 | if (*name == 0) |
4534 | 0 | return; |
4535 | | |
4536 | 0 | if (!is_mainfile && !process_links |
4537 | 0 | && (section->flags & SEC_DEBUGGING) == 0) |
4538 | 0 | return; |
4539 | | |
4540 | 0 | if (startswith (name, ".gnu.linkonce.wi.")) |
4541 | 0 | match = ".debug_info"; |
4542 | 0 | else |
4543 | 0 | match = name; |
4544 | |
|
4545 | 0 | if (((strcmp (debug_displays [info].section.uncompressed_name,match) == 0 |
4546 | 0 | || strcmp (debug_displays [info].section.compressed_name, match) == 0 |
4547 | 0 | || strcmp (debug_displays [info].section.xcoff_name, match) == 0)) |
4548 | 0 | && debug_displays [info].enabled != NULL |
4549 | 0 | && *debug_displays [info].enabled) |
4550 | 0 | { |
4551 | 0 | struct dwarf_section *sec = &debug_displays [info].section; |
4552 | |
|
4553 | 0 | if (load_specific_debug_section (info, section, abfd)) |
4554 | 0 | { |
4555 | 0 | debug_displays [debug_variable_info].display (sec, abfd); |
4556 | 0 | resolve_and_display_variable_info (); |
4557 | 0 | free_mapping_info_struct (); |
4558 | 0 | free_debug_section (info); |
4559 | 0 | } |
4560 | 0 | } |
4561 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_global_variable_info Unexecuted instantiation: fuzz_dwarf.c:dump_global_variable_info |
4562 | | |
4563 | | /* Dump the dwarf debugging information helper. */ |
4564 | | static void |
4565 | | dump_dwarf_info (bfd *abfd, |
4566 | | void (*operation) (bfd *, asection *, void *), |
4567 | | bool is_mainfile) |
4568 | 31.5k | { |
4569 | | /* The byte_get pointer should have been set at the start of dump_bfd(). */ |
4570 | 31.5k | if (byte_get == NULL) |
4571 | 33 | { |
4572 | 33 | warn (_("File %s does not contain any dwarf debug information\n"), |
4573 | 33 | bfd_get_filename (abfd)); |
4574 | 33 | return; |
4575 | 33 | } |
4576 | | |
4577 | 31.5k | switch (bfd_get_arch (abfd)) |
4578 | 31.5k | { |
4579 | 259 | case bfd_arch_s12z: |
4580 | | /* S12Z has a 24 bit address space. But the only known |
4581 | | producer of dwarf_info encodes addresses into 32 bits. */ |
4582 | 259 | eh_addr_size = 4; |
4583 | 259 | break; |
4584 | | |
4585 | 31.2k | default: |
4586 | 31.2k | eh_addr_size = bfd_arch_bits_per_address (abfd) / 8; |
4587 | 31.2k | break; |
4588 | 31.5k | } |
4589 | | |
4590 | 31.5k | init_dwarf_by_bfd_arch_and_mach (bfd_get_arch (abfd), |
4591 | 31.5k | bfd_get_mach (abfd)); |
4592 | | |
4593 | 31.5k | bfd_map_over_sections (abfd, operation, (void *) &is_mainfile); |
4594 | 31.5k | } fuzz_objdump.c:dump_dwarf_info Line | Count | Source | 4568 | 31.5k | { | 4569 | | /* The byte_get pointer should have been set at the start of dump_bfd(). */ | 4570 | 31.5k | if (byte_get == NULL) | 4571 | 33 | { | 4572 | 33 | warn (_("File %s does not contain any dwarf debug information\n"), | 4573 | 33 | bfd_get_filename (abfd)); | 4574 | 33 | return; | 4575 | 33 | } | 4576 | | | 4577 | 31.5k | switch (bfd_get_arch (abfd)) | 4578 | 31.5k | { | 4579 | 259 | case bfd_arch_s12z: | 4580 | | /* S12Z has a 24 bit address space. But the only known | 4581 | | producer of dwarf_info encodes addresses into 32 bits. */ | 4582 | 259 | eh_addr_size = 4; | 4583 | 259 | break; | 4584 | | | 4585 | 31.2k | default: | 4586 | 31.2k | eh_addr_size = bfd_arch_bits_per_address (abfd) / 8; | 4587 | 31.2k | break; | 4588 | 31.5k | } | 4589 | | | 4590 | 31.5k | init_dwarf_by_bfd_arch_and_mach (bfd_get_arch (abfd), | 4591 | 31.5k | bfd_get_mach (abfd)); | 4592 | | | 4593 | 31.5k | bfd_map_over_sections (abfd, operation, (void *) &is_mainfile); | 4594 | 31.5k | } |
Unexecuted instantiation: fuzz_dwarf.c:dump_dwarf_info |
4595 | | |
4596 | | /* Dump the dwarf debugging information. */ |
4597 | | |
4598 | | static void |
4599 | | dump_dwarf (bfd *abfd, bool is_mainfile) |
4600 | 31.5k | { |
4601 | 31.5k | dump_dwarf_info (abfd, dump_dwarf_section, is_mainfile); |
4602 | 31.5k | } fuzz_objdump.c:dump_dwarf Line | Count | Source | 4600 | 31.5k | { | 4601 | 31.5k | dump_dwarf_info (abfd, dump_dwarf_section, is_mainfile); | 4602 | 31.5k | } |
Unexecuted instantiation: fuzz_dwarf.c:dump_dwarf |
4603 | | |
4604 | | /* Dump all global variable information in memory. */ |
4605 | | |
4606 | | static void |
4607 | | dump_global_vars_info (bfd *abfd, bool is_mainfile) |
4608 | 0 | { |
4609 | 0 | dump_dwarf_info (abfd, dump_global_variable_info, is_mainfile); |
4610 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_global_vars_info Unexecuted instantiation: fuzz_dwarf.c:dump_global_vars_info |
4611 | | |
4612 | | /* Read ABFD's section SECT_NAME into *CONTENTS, and return a pointer to |
4613 | | the section. Return NULL on failure. */ |
4614 | | |
4615 | | static asection * |
4616 | | read_section (bfd *abfd, const char *sect_name, bfd_byte **contents) |
4617 | 335 | { |
4618 | 335 | asection *sec; |
4619 | | |
4620 | 335 | *contents = NULL; |
4621 | 335 | sec = bfd_get_section_by_name (abfd, sect_name); |
4622 | 335 | if (sec == NULL) |
4623 | 206 | { |
4624 | 206 | printf (_("No %s section present\n\n"), sanitize_string (sect_name)); |
4625 | 206 | return NULL; |
4626 | 206 | } |
4627 | | |
4628 | 129 | if ((bfd_section_flags (sec) & SEC_HAS_CONTENTS) == 0) |
4629 | 1 | bfd_set_error (bfd_error_no_contents); |
4630 | 128 | else if (bfd_malloc_and_get_section (abfd, sec, contents)) |
4631 | 116 | return sec; |
4632 | | |
4633 | 13 | non_fatal (_("reading %s section of %s failed: %s"), |
4634 | 13 | sect_name, bfd_get_filename (abfd), |
4635 | 13 | bfd_errmsg (bfd_get_error ())); |
4636 | 13 | exit_status = 1; |
4637 | 13 | return NULL; |
4638 | 129 | } fuzz_objdump.c:read_section Line | Count | Source | 4617 | 335 | { | 4618 | 335 | asection *sec; | 4619 | | | 4620 | 335 | *contents = NULL; | 4621 | 335 | sec = bfd_get_section_by_name (abfd, sect_name); | 4622 | 335 | if (sec == NULL) | 4623 | 206 | { | 4624 | 206 | printf (_("No %s section present\n\n"), sanitize_string (sect_name)); | 4625 | 206 | return NULL; | 4626 | 206 | } | 4627 | | | 4628 | 129 | if ((bfd_section_flags (sec) & SEC_HAS_CONTENTS) == 0) | 4629 | 1 | bfd_set_error (bfd_error_no_contents); | 4630 | 128 | else if (bfd_malloc_and_get_section (abfd, sec, contents)) | 4631 | 116 | return sec; | 4632 | | | 4633 | 13 | non_fatal (_("reading %s section of %s failed: %s"), | 4634 | 13 | sect_name, bfd_get_filename (abfd), | 4635 | 13 | bfd_errmsg (bfd_get_error ())); | 4636 | 13 | exit_status = 1; | 4637 | | return NULL; | 4638 | 129 | } |
Unexecuted instantiation: fuzz_dwarf.c:read_section |
4639 | | |
4640 | | /* Stabs entries use a 12 byte format: |
4641 | | 4 byte string table index |
4642 | | 1 byte stab type |
4643 | | 1 byte stab other field |
4644 | | 2 byte stab desc field |
4645 | | 4 byte stab value |
4646 | | FIXME: This will have to change for a 64 bit object format. */ |
4647 | | |
4648 | | #define STRDXOFF (0) |
4649 | | #define TYPEOFF (4) |
4650 | | #define OTHEROFF (5) |
4651 | | #define DESCOFF (6) |
4652 | | #define VALOFF (8) |
4653 | 4.89k | #define STABSIZE (12) |
4654 | | |
4655 | | /* Print ABFD's stabs section STABSECT_NAME (in `stabs'), |
4656 | | using string table section STRSECT_NAME (in `strtab'). */ |
4657 | | |
4658 | | static void |
4659 | | print_section_stabs (bfd *abfd, |
4660 | | const char *stabsect_name, |
4661 | | unsigned *string_offset_ptr) |
4662 | 56 | { |
4663 | 56 | int i; |
4664 | 56 | unsigned file_string_table_offset = 0; |
4665 | 56 | unsigned next_file_string_table_offset = *string_offset_ptr; |
4666 | 56 | bfd_byte *stabp, *stabs_end; |
4667 | | |
4668 | 56 | stabp = stabs; |
4669 | 56 | stabs_end = PTR_ADD (stabp, stab_size); |
4670 | | |
4671 | 56 | printf (_("Contents of %s section:\n\n"), sanitize_string (stabsect_name)); |
4672 | 56 | printf ("Symnum n_type n_othr n_desc n_value n_strx String\n"); |
4673 | | |
4674 | | /* Loop through all symbols and print them. |
4675 | | |
4676 | | We start the index at -1 because there is a dummy symbol on |
4677 | | the front of stabs-in-{coff,elf} sections that supplies sizes. */ |
4678 | 2.47k | for (i = -1; (size_t) (stabs_end - stabp) >= STABSIZE; stabp += STABSIZE, i++) |
4679 | 2.41k | { |
4680 | 2.41k | const char *name; |
4681 | 2.41k | unsigned long strx; |
4682 | 2.41k | unsigned char type, other; |
4683 | 2.41k | unsigned short desc; |
4684 | 2.41k | bfd_vma value; |
4685 | | |
4686 | 2.41k | strx = bfd_h_get_32 (abfd, stabp + STRDXOFF); |
4687 | 2.41k | type = bfd_h_get_8 (abfd, stabp + TYPEOFF); |
4688 | 2.41k | other = bfd_h_get_8 (abfd, stabp + OTHEROFF); |
4689 | 2.41k | desc = bfd_h_get_16 (abfd, stabp + DESCOFF); |
4690 | 2.41k | value = bfd_h_get_32 (abfd, stabp + VALOFF); |
4691 | | |
4692 | 2.41k | printf ("\n%-6d ", i); |
4693 | | /* Either print the stab name, or, if unnamed, print its number |
4694 | | again (makes consistent formatting for tools like awk). */ |
4695 | 2.41k | name = bfd_get_stab_name (type); |
4696 | 2.41k | if (name != NULL) |
4697 | 433 | printf ("%-6s", sanitize_string (name)); |
4698 | 1.98k | else if (type == N_UNDF) |
4699 | 773 | printf ("HdrSym"); |
4700 | 1.21k | else |
4701 | 1.21k | printf ("%-6d", type); |
4702 | 2.41k | printf (" %-6d %-6d ", other, desc); |
4703 | 2.41k | bfd_printf_vma (abfd, value); |
4704 | 2.41k | printf (" %-6lu", strx); |
4705 | | |
4706 | | /* Symbols with type == 0 (N_UNDF) specify the length of the |
4707 | | string table associated with this file. We use that info |
4708 | | to know how to relocate the *next* file's string table indices. */ |
4709 | 2.41k | if (type == N_UNDF) |
4710 | 773 | { |
4711 | 773 | file_string_table_offset = next_file_string_table_offset; |
4712 | 773 | next_file_string_table_offset += value; |
4713 | 773 | } |
4714 | 1.64k | else |
4715 | 1.64k | { |
4716 | 1.64k | bfd_size_type amt = strx + file_string_table_offset; |
4717 | | |
4718 | | /* Using the (possibly updated) string table offset, print the |
4719 | | string (if any) associated with this symbol. */ |
4720 | 1.64k | if (amt < stabstr_size) |
4721 | | /* PR 17512: file: 079-79389-0.001:0.1. |
4722 | | FIXME: May need to sanitize this string before displaying. */ |
4723 | 159 | printf (" %.*s", (int)(stabstr_size - amt), strtab + amt); |
4724 | 1.48k | else |
4725 | 1.48k | printf (" *"); |
4726 | 1.64k | } |
4727 | 2.41k | } |
4728 | 56 | printf ("\n\n"); |
4729 | 56 | *string_offset_ptr = next_file_string_table_offset; |
4730 | 56 | } fuzz_objdump.c:print_section_stabs Line | Count | Source | 4662 | 56 | { | 4663 | 56 | int i; | 4664 | 56 | unsigned file_string_table_offset = 0; | 4665 | 56 | unsigned next_file_string_table_offset = *string_offset_ptr; | 4666 | 56 | bfd_byte *stabp, *stabs_end; | 4667 | | | 4668 | 56 | stabp = stabs; | 4669 | 56 | stabs_end = PTR_ADD (stabp, stab_size); | 4670 | | | 4671 | 56 | printf (_("Contents of %s section:\n\n"), sanitize_string (stabsect_name)); | 4672 | 56 | printf ("Symnum n_type n_othr n_desc n_value n_strx String\n"); | 4673 | | | 4674 | | /* Loop through all symbols and print them. | 4675 | | | 4676 | | We start the index at -1 because there is a dummy symbol on | 4677 | | the front of stabs-in-{coff,elf} sections that supplies sizes. */ | 4678 | 2.47k | for (i = -1; (size_t) (stabs_end - stabp) >= STABSIZE; stabp += STABSIZE, i++) | 4679 | 2.41k | { | 4680 | 2.41k | const char *name; | 4681 | 2.41k | unsigned long strx; | 4682 | 2.41k | unsigned char type, other; | 4683 | 2.41k | unsigned short desc; | 4684 | 2.41k | bfd_vma value; | 4685 | | | 4686 | 2.41k | strx = bfd_h_get_32 (abfd, stabp + STRDXOFF); | 4687 | 2.41k | type = bfd_h_get_8 (abfd, stabp + TYPEOFF); | 4688 | 2.41k | other = bfd_h_get_8 (abfd, stabp + OTHEROFF); | 4689 | 2.41k | desc = bfd_h_get_16 (abfd, stabp + DESCOFF); | 4690 | 2.41k | value = bfd_h_get_32 (abfd, stabp + VALOFF); | 4691 | | | 4692 | 2.41k | printf ("\n%-6d ", i); | 4693 | | /* Either print the stab name, or, if unnamed, print its number | 4694 | | again (makes consistent formatting for tools like awk). */ | 4695 | 2.41k | name = bfd_get_stab_name (type); | 4696 | 2.41k | if (name != NULL) | 4697 | 433 | printf ("%-6s", sanitize_string (name)); | 4698 | 1.98k | else if (type == N_UNDF) | 4699 | 773 | printf ("HdrSym"); | 4700 | 1.21k | else | 4701 | 1.21k | printf ("%-6d", type); | 4702 | 2.41k | printf (" %-6d %-6d ", other, desc); | 4703 | 2.41k | bfd_printf_vma (abfd, value); | 4704 | 2.41k | printf (" %-6lu", strx); | 4705 | | | 4706 | | /* Symbols with type == 0 (N_UNDF) specify the length of the | 4707 | | string table associated with this file. We use that info | 4708 | | to know how to relocate the *next* file's string table indices. */ | 4709 | 2.41k | if (type == N_UNDF) | 4710 | 773 | { | 4711 | 773 | file_string_table_offset = next_file_string_table_offset; | 4712 | 773 | next_file_string_table_offset += value; | 4713 | 773 | } | 4714 | 1.64k | else | 4715 | 1.64k | { | 4716 | 1.64k | bfd_size_type amt = strx + file_string_table_offset; | 4717 | | | 4718 | | /* Using the (possibly updated) string table offset, print the | 4719 | | string (if any) associated with this symbol. */ | 4720 | 1.64k | if (amt < stabstr_size) | 4721 | | /* PR 17512: file: 079-79389-0.001:0.1. | 4722 | | FIXME: May need to sanitize this string before displaying. */ | 4723 | 159 | printf (" %.*s", (int)(stabstr_size - amt), strtab + amt); | 4724 | 1.48k | else | 4725 | 1.48k | printf (" *"); | 4726 | 1.64k | } | 4727 | 2.41k | } | 4728 | 56 | printf ("\n\n"); | 4729 | 56 | *string_offset_ptr = next_file_string_table_offset; | 4730 | 56 | } |
Unexecuted instantiation: fuzz_dwarf.c:print_section_stabs |
4731 | | |
4732 | | typedef struct |
4733 | | { |
4734 | | const char * section_name; |
4735 | | const char * string_section_name; |
4736 | | unsigned string_offset; |
4737 | | } |
4738 | | stab_section_names; |
4739 | | |
4740 | | static void |
4741 | | find_stabs_section (bfd *abfd, asection *section, void *names) |
4742 | 4.49M | { |
4743 | 4.49M | int len; |
4744 | 4.49M | stab_section_names * sought = (stab_section_names *) names; |
4745 | | |
4746 | | /* Check for section names for which stabsect_name is a prefix, to |
4747 | | handle .stab.N, etc. */ |
4748 | 4.49M | len = strlen (sought->section_name); |
4749 | | |
4750 | | /* If the prefix matches, and the files section name ends with a |
4751 | | nul or a digit, then we match. I.e., we want either an exact |
4752 | | match or a section followed by a number. */ |
4753 | 4.49M | if (strncmp (sought->section_name, section->name, len) == 0 |
4754 | 1.21k | && (section->name[len] == 0 |
4755 | 935 | || (section->name[len] == '.' && ISDIGIT (section->name[len + 1])))) |
4756 | 278 | { |
4757 | 278 | asection *s; |
4758 | 278 | if (strtab == NULL) |
4759 | 274 | { |
4760 | 274 | s = read_section (abfd, sought->string_section_name, &strtab); |
4761 | 274 | if (s != NULL) |
4762 | 60 | stabstr_size = bfd_section_size (s); |
4763 | 274 | } |
4764 | | |
4765 | 278 | if (strtab) |
4766 | 61 | { |
4767 | 61 | s = read_section (abfd, section->name, &stabs); |
4768 | 61 | if (s != NULL) |
4769 | 56 | { |
4770 | 56 | stab_size = bfd_section_size (s); |
4771 | 56 | print_section_stabs (abfd, section->name, &sought->string_offset); |
4772 | 56 | free (stabs); |
4773 | 56 | } |
4774 | 61 | } |
4775 | 278 | } |
4776 | 4.49M | } fuzz_objdump.c:find_stabs_section Line | Count | Source | 4742 | 4.49M | { | 4743 | 4.49M | int len; | 4744 | 4.49M | stab_section_names * sought = (stab_section_names *) names; | 4745 | | | 4746 | | /* Check for section names for which stabsect_name is a prefix, to | 4747 | | handle .stab.N, etc. */ | 4748 | 4.49M | len = strlen (sought->section_name); | 4749 | | | 4750 | | /* If the prefix matches, and the files section name ends with a | 4751 | | nul or a digit, then we match. I.e., we want either an exact | 4752 | | match or a section followed by a number. */ | 4753 | 4.49M | if (strncmp (sought->section_name, section->name, len) == 0 | 4754 | 1.21k | && (section->name[len] == 0 | 4755 | 935 | || (section->name[len] == '.' && ISDIGIT (section->name[len + 1])))) | 4756 | 278 | { | 4757 | 278 | asection *s; | 4758 | 278 | if (strtab == NULL) | 4759 | 274 | { | 4760 | 274 | s = read_section (abfd, sought->string_section_name, &strtab); | 4761 | 274 | if (s != NULL) | 4762 | 60 | stabstr_size = bfd_section_size (s); | 4763 | 274 | } | 4764 | | | 4765 | 278 | if (strtab) | 4766 | 61 | { | 4767 | 61 | s = read_section (abfd, section->name, &stabs); | 4768 | 61 | if (s != NULL) | 4769 | 56 | { | 4770 | 56 | stab_size = bfd_section_size (s); | 4771 | 56 | print_section_stabs (abfd, section->name, &sought->string_offset); | 4772 | 56 | free (stabs); | 4773 | 56 | } | 4774 | 61 | } | 4775 | 278 | } | 4776 | 4.49M | } |
Unexecuted instantiation: fuzz_dwarf.c:find_stabs_section |
4777 | | |
4778 | | static void |
4779 | | dump_stabs_section (bfd *abfd, char *stabsect_name, char *strsect_name) |
4780 | 157k | { |
4781 | 157k | stab_section_names s; |
4782 | | |
4783 | 157k | s.section_name = stabsect_name; |
4784 | 157k | s.string_section_name = strsect_name; |
4785 | 157k | s.string_offset = 0; |
4786 | | |
4787 | 157k | bfd_map_over_sections (abfd, find_stabs_section, & s); |
4788 | | |
4789 | 157k | free (strtab); |
4790 | 157k | strtab = NULL; |
4791 | 157k | } fuzz_objdump.c:dump_stabs_section Line | Count | Source | 4780 | 157k | { | 4781 | 157k | stab_section_names s; | 4782 | | | 4783 | 157k | s.section_name = stabsect_name; | 4784 | 157k | s.string_section_name = strsect_name; | 4785 | 157k | s.string_offset = 0; | 4786 | | | 4787 | 157k | bfd_map_over_sections (abfd, find_stabs_section, & s); | 4788 | | | 4789 | 157k | free (strtab); | 4790 | | strtab = NULL; | 4791 | 157k | } |
Unexecuted instantiation: fuzz_dwarf.c:dump_stabs_section |
4792 | | |
4793 | | /* Dump the any sections containing stabs debugging information. */ |
4794 | | |
4795 | | static void |
4796 | | dump_stabs (bfd *abfd) |
4797 | 31.5k | { |
4798 | 31.5k | dump_stabs_section (abfd, ".stab", ".stabstr"); |
4799 | 31.5k | dump_stabs_section (abfd, ".stab.excl", ".stab.exclstr"); |
4800 | 31.5k | dump_stabs_section (abfd, ".stab.index", ".stab.indexstr"); |
4801 | | |
4802 | | /* For Darwin. */ |
4803 | 31.5k | dump_stabs_section (abfd, "LC_SYMTAB.stabs", "LC_SYMTAB.stabstr"); |
4804 | | |
4805 | 31.5k | dump_stabs_section (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$"); |
4806 | 31.5k | } fuzz_objdump.c:dump_stabs Line | Count | Source | 4797 | 31.5k | { | 4798 | 31.5k | dump_stabs_section (abfd, ".stab", ".stabstr"); | 4799 | 31.5k | dump_stabs_section (abfd, ".stab.excl", ".stab.exclstr"); | 4800 | 31.5k | dump_stabs_section (abfd, ".stab.index", ".stab.indexstr"); | 4801 | | | 4802 | | /* For Darwin. */ | 4803 | 31.5k | dump_stabs_section (abfd, "LC_SYMTAB.stabs", "LC_SYMTAB.stabstr"); | 4804 | | | 4805 | 31.5k | dump_stabs_section (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$"); | 4806 | 31.5k | } |
Unexecuted instantiation: fuzz_dwarf.c:dump_stabs |
4807 | | |
4808 | | static void |
4809 | | dump_bfd_header (bfd *abfd) |
4810 | 0 | { |
4811 | 0 | char *comma = ""; |
4812 | |
|
4813 | 0 | printf (_("architecture: %s, "), |
4814 | 0 | bfd_printable_arch_mach (bfd_get_arch (abfd), |
4815 | 0 | bfd_get_mach (abfd))); |
4816 | 0 | printf (_("flags 0x%08x:\n"), abfd->flags & ~BFD_FLAGS_FOR_BFD_USE_MASK); |
4817 | |
|
4818 | 0 | #define PF(x, y) if (abfd->flags & x) {printf ("%s%s", comma, y); comma=", ";} |
4819 | 0 | PF (HAS_RELOC, "HAS_RELOC"); |
4820 | 0 | PF (EXEC_P, "EXEC_P"); |
4821 | 0 | PF (HAS_LINENO, "HAS_LINENO"); |
4822 | 0 | PF (HAS_DEBUG, "HAS_DEBUG"); |
4823 | 0 | PF (HAS_SYMS, "HAS_SYMS"); |
4824 | 0 | PF (HAS_LOCALS, "HAS_LOCALS"); |
4825 | 0 | PF (DYNAMIC, "DYNAMIC"); |
4826 | 0 | PF (WP_TEXT, "WP_TEXT"); |
4827 | 0 | PF (D_PAGED, "D_PAGED"); |
4828 | 0 | PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE"); |
4829 | 0 | printf (_("\nstart address 0x")); |
4830 | 0 | bfd_printf_vma (abfd, abfd->start_address); |
4831 | 0 | printf ("\n"); |
4832 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_bfd_header Unexecuted instantiation: fuzz_dwarf.c:dump_bfd_header |
4833 | | |
4834 | | |
4835 | | #ifdef ENABLE_LIBCTF |
4836 | | /* Formatting callback function passed to ctf_dump. Returns either the pointer |
4837 | | it is passed, or a pointer to newly-allocated storage, in which case |
4838 | | dump_ctf() will free it when it no longer needs it. */ |
4839 | | |
4840 | | static char * |
4841 | | dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED, |
4842 | | char *s, void *arg) |
4843 | 0 | { |
4844 | 0 | const char *blanks = arg; |
4845 | 0 | return xasprintf ("%s%s", blanks, s); |
4846 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_ctf_indent_lines Unexecuted instantiation: fuzz_dwarf.c:dump_ctf_indent_lines |
4847 | | |
4848 | | /* Make a ctfsect suitable for ctf_bfdopen_ctfsect(). */ |
4849 | | static ctf_sect_t |
4850 | | make_ctfsect (const char *name, bfd_byte *data, |
4851 | | bfd_size_type size) |
4852 | 0 | { |
4853 | 0 | ctf_sect_t ctfsect; |
4854 | |
|
4855 | 0 | ctfsect.cts_name = name; |
4856 | 0 | ctfsect.cts_entsize = 1; |
4857 | 0 | ctfsect.cts_size = size; |
4858 | 0 | ctfsect.cts_data = data; |
4859 | |
|
4860 | 0 | return ctfsect; |
4861 | 0 | } Unexecuted instantiation: fuzz_objdump.c:make_ctfsect Unexecuted instantiation: fuzz_dwarf.c:make_ctfsect |
4862 | | |
4863 | | /* Dump CTF errors/warnings. */ |
4864 | | static void |
4865 | | dump_ctf_errs (ctf_dict_t *fp) |
4866 | 0 | { |
4867 | 0 | ctf_next_t *it = NULL; |
4868 | 0 | char *errtext; |
4869 | 0 | int is_warning; |
4870 | 0 | int err; |
4871 | | |
4872 | | /* Dump accumulated errors and warnings. */ |
4873 | 0 | while ((errtext = ctf_errwarning_next (fp, &it, &is_warning, &err)) != NULL) |
4874 | 0 | { |
4875 | 0 | non_fatal (_("%s: %s"), is_warning ? _("warning"): _("error"), |
4876 | 0 | errtext); |
4877 | 0 | free (errtext); |
4878 | 0 | } |
4879 | 0 | if (err != ECTF_NEXT_END) |
4880 | 0 | { |
4881 | 0 | non_fatal (_("CTF error: cannot get CTF errors: `%s'"), |
4882 | 0 | ctf_errmsg (err)); |
4883 | 0 | } |
4884 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_ctf_errs Unexecuted instantiation: fuzz_dwarf.c:dump_ctf_errs |
4885 | | |
4886 | | /* Dump one CTF archive member. */ |
4887 | | |
4888 | | static void |
4889 | | dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, ctf_dict_t *parent, |
4890 | | size_t member) |
4891 | 0 | { |
4892 | 0 | const char *things[] = {"Header", "Labels", "Data objects", |
4893 | 0 | "Function objects", "Variables", "Types", "Strings", |
4894 | 0 | ""}; |
4895 | 0 | const char **thing; |
4896 | 0 | size_t i; |
4897 | | |
4898 | | /* Don't print out the name of the default-named archive member if it appears |
4899 | | first in the list. The name .ctf appears everywhere, even for things that |
4900 | | aren't really archives, so printing it out is liable to be confusing; also, |
4901 | | the common case by far is for only one archive member to exist, and hiding |
4902 | | it in that case seems worthwhile. */ |
4903 | |
|
4904 | 0 | if (strcmp (name, ".ctf") != 0 || member != 0) |
4905 | 0 | printf (_("\nCTF archive member: %s:\n"), sanitize_string (name)); |
4906 | |
|
4907 | 0 | if (ctf_parent_name (ctf) != NULL) |
4908 | 0 | ctf_import (ctf, parent); |
4909 | |
|
4910 | 0 | for (i = 0, thing = things; *thing[0]; thing++, i++) |
4911 | 0 | { |
4912 | 0 | ctf_dump_state_t *s = NULL; |
4913 | 0 | char *item; |
4914 | |
|
4915 | 0 | printf ("\n %s:\n", *thing); |
4916 | 0 | while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines, |
4917 | 0 | (void *) " ")) != NULL) |
4918 | 0 | { |
4919 | 0 | printf ("%s\n", item); |
4920 | 0 | free (item); |
4921 | 0 | } |
4922 | |
|
4923 | 0 | if (ctf_errno (ctf)) |
4924 | 0 | { |
4925 | 0 | non_fatal (_("Iteration failed: %s, %s"), *thing, |
4926 | 0 | ctf_errmsg (ctf_errno (ctf))); |
4927 | 0 | break; |
4928 | 0 | } |
4929 | 0 | } |
4930 | |
|
4931 | 0 | dump_ctf_errs (ctf); |
4932 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_ctf_archive_member Unexecuted instantiation: fuzz_dwarf.c:dump_ctf_archive_member |
4933 | | |
4934 | | /* Dump the CTF debugging information. */ |
4935 | | |
4936 | | static void |
4937 | | dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name, |
4938 | | const char *parent_sect_name) |
4939 | 0 | { |
4940 | 0 | asection *sec, *psec = NULL; |
4941 | 0 | ctf_archive_t *ctfa; |
4942 | 0 | ctf_archive_t *ctfpa = NULL; |
4943 | 0 | bfd_byte *ctfdata = NULL; |
4944 | 0 | bfd_byte *ctfpdata = NULL; |
4945 | 0 | ctf_sect_t ctfsect; |
4946 | 0 | ctf_dict_t *parent; |
4947 | 0 | ctf_dict_t *fp; |
4948 | 0 | ctf_next_t *i = NULL; |
4949 | 0 | const char *name; |
4950 | 0 | size_t member = 0; |
4951 | 0 | int err; |
4952 | |
|
4953 | 0 | if (sect_name == NULL) |
4954 | 0 | sect_name = ".ctf"; |
4955 | |
|
4956 | 0 | sec = read_section (abfd, sect_name, &ctfdata); |
4957 | 0 | if (sec == NULL) |
4958 | 0 | { |
4959 | 0 | my_bfd_nonfatal (bfd_get_filename (abfd)); |
4960 | 0 | return; |
4961 | 0 | } |
4962 | | |
4963 | | /* Load the CTF file and dump it. Preload the parent dict, since it will |
4964 | | need to be imported into every child in turn. The parent dict may come |
4965 | | from a different section entirely. */ |
4966 | | |
4967 | 0 | ctfsect = make_ctfsect (sect_name, ctfdata, bfd_section_size (sec)); |
4968 | 0 | if ((ctfa = ctf_bfdopen_ctfsect (abfd, &ctfsect, &err)) == NULL) |
4969 | 0 | { |
4970 | 0 | dump_ctf_errs (NULL); |
4971 | 0 | non_fatal (_("CTF open failure: %s"), ctf_errmsg (err)); |
4972 | 0 | my_bfd_nonfatal (bfd_get_filename (abfd)); |
4973 | 0 | free (ctfdata); |
4974 | 0 | return; |
4975 | 0 | } |
4976 | | |
4977 | 0 | if (parent_sect_name) |
4978 | 0 | { |
4979 | 0 | psec = read_section (abfd, parent_sect_name, &ctfpdata); |
4980 | 0 | if (sec == NULL) |
4981 | 0 | { |
4982 | 0 | my_bfd_nonfatal (bfd_get_filename (abfd)); |
4983 | 0 | free (ctfdata); |
4984 | 0 | return; |
4985 | 0 | } |
4986 | | |
4987 | 0 | ctfsect = make_ctfsect (parent_sect_name, ctfpdata, bfd_section_size (psec)); |
4988 | 0 | if ((ctfpa = ctf_bfdopen_ctfsect (abfd, &ctfsect, &err)) == NULL) |
4989 | 0 | { |
4990 | 0 | dump_ctf_errs (NULL); |
4991 | 0 | non_fatal (_("CTF open failure: %s"), ctf_errmsg (err)); |
4992 | 0 | my_bfd_nonfatal (bfd_get_filename (abfd)); |
4993 | 0 | free (ctfdata); |
4994 | 0 | free (ctfpdata); |
4995 | 0 | return; |
4996 | 0 | } |
4997 | 0 | } |
4998 | 0 | else |
4999 | 0 | ctfpa = ctfa; |
5000 | | |
5001 | 0 | if ((parent = ctf_dict_open (ctfpa, parent_name, &err)) == NULL) |
5002 | 0 | { |
5003 | 0 | dump_ctf_errs (NULL); |
5004 | 0 | non_fatal (_("CTF open failure: %s"), ctf_errmsg (err)); |
5005 | 0 | my_bfd_nonfatal (bfd_get_filename (abfd)); |
5006 | 0 | ctf_close (ctfa); |
5007 | 0 | free (ctfdata); |
5008 | 0 | free (ctfpdata); |
5009 | 0 | return; |
5010 | 0 | } |
5011 | | |
5012 | 0 | printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name)); |
5013 | |
|
5014 | 0 | while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL) |
5015 | 0 | { |
5016 | 0 | dump_ctf_archive_member (fp, name, parent, member++); |
5017 | 0 | ctf_dict_close (fp); |
5018 | 0 | } |
5019 | 0 | if (err != ECTF_NEXT_END) |
5020 | 0 | { |
5021 | 0 | dump_ctf_errs (NULL); |
5022 | 0 | non_fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err)); |
5023 | 0 | my_bfd_nonfatal (bfd_get_filename (abfd)); |
5024 | 0 | } |
5025 | 0 | ctf_dict_close (parent); |
5026 | 0 | ctf_close (ctfa); |
5027 | 0 | free (ctfdata); |
5028 | 0 | if (parent_sect_name) |
5029 | 0 | { |
5030 | 0 | ctf_close (ctfpa); |
5031 | 0 | free (ctfpdata); |
5032 | 0 | } |
5033 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_ctf Unexecuted instantiation: fuzz_dwarf.c:dump_ctf |
5034 | | #else |
5035 | | static void |
5036 | | dump_ctf (bfd *abfd ATTRIBUTE_UNUSED, const char *sect_name ATTRIBUTE_UNUSED, |
5037 | | const char *parent_name ATTRIBUTE_UNUSED, |
5038 | | const char *parent_sect_name ATTRIBUTE_UNUSED) {} |
5039 | | #endif |
5040 | | |
5041 | | static void |
5042 | | dump_sframe_section (bfd *abfd, const char *sect_name) |
5043 | | |
5044 | 0 | { |
5045 | | /* Error checking for user provided SFrame section name, if any. */ |
5046 | 0 | asection *sec = bfd_get_section_by_name (abfd, sect_name); |
5047 | 0 | if (sec == NULL) |
5048 | 0 | { |
5049 | 0 | printf (_("No %s section present\n\n"), sanitize_string (sect_name)); |
5050 | 0 | return; |
5051 | 0 | } |
5052 | | /* Starting with Binutils 2.45, SFrame sections have section type |
5053 | | SHT_GNU_SFRAME. For SFrame sections from Binutils 2.44 or earlier, |
5054 | | check explcitly for SFrame sections of type SHT_PROGBITS and name |
5055 | | ".sframe" to allow them. */ |
5056 | 0 | else if (bfd_get_flavour (abfd) != bfd_target_elf_flavour |
5057 | 0 | || (elf_section_type (sec) != SHT_GNU_SFRAME |
5058 | 0 | && !(elf_section_type (sec) == SHT_PROGBITS |
5059 | 0 | && strcmp (sect_name, ".sframe") == 0))) |
5060 | 0 | { |
5061 | 0 | printf (_("Section %s does not contain SFrame data\n\n"), |
5062 | 0 | sanitize_string (sect_name)); |
5063 | 0 | return; |
5064 | 0 | } |
5065 | | |
5066 | 0 | if (!load_specific_debug_section (sframe, sec, (void *) abfd)) |
5067 | 0 | return; |
5068 | | |
5069 | 0 | struct dwarf_section *section = &debug_displays[sframe].section; |
5070 | 0 | section->name = sect_name; |
5071 | 0 | debug_displays[sframe].display (section, abfd); |
5072 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_sframe_section Unexecuted instantiation: fuzz_dwarf.c:dump_sframe_section |
5073 | | |
5074 | | |
5075 | | static void |
5076 | | dump_bfd_private_header (bfd *abfd) |
5077 | 31.5k | { |
5078 | 31.5k | if (!bfd_print_private_bfd_data (abfd, stdout)) |
5079 | 63 | non_fatal (_("warning: private headers incomplete: %s"), |
5080 | 63 | bfd_errmsg (bfd_get_error ())); |
5081 | 31.5k | } fuzz_objdump.c:dump_bfd_private_header Line | Count | Source | 5077 | 31.5k | { | 5078 | 31.5k | if (!bfd_print_private_bfd_data (abfd, stdout)) | 5079 | 63 | non_fatal (_("warning: private headers incomplete: %s"), | 5080 | 63 | bfd_errmsg (bfd_get_error ())); | 5081 | 31.5k | } |
Unexecuted instantiation: fuzz_dwarf.c:dump_bfd_private_header |
5082 | | |
5083 | | static void |
5084 | | dump_target_specific (bfd *abfd) |
5085 | 0 | { |
5086 | 0 | const struct objdump_private_desc * const *desc; |
5087 | 0 | struct objdump_private_option *opt; |
5088 | 0 | char *e, *b; |
5089 | | |
5090 | | /* Find the desc. */ |
5091 | 0 | for (desc = objdump_private_vectors; *desc != NULL; desc++) |
5092 | 0 | if ((*desc)->filter (abfd)) |
5093 | 0 | break; |
5094 | |
|
5095 | 0 | if (*desc == NULL) |
5096 | 0 | { |
5097 | 0 | non_fatal (_("option -P/--private not supported by this file")); |
5098 | 0 | return; |
5099 | 0 | } |
5100 | | |
5101 | | /* Clear all options. */ |
5102 | 0 | for (opt = (*desc)->options; opt->name; opt++) |
5103 | 0 | opt->selected = false; |
5104 | | |
5105 | | /* Decode options. */ |
5106 | 0 | b = dump_private_options; |
5107 | 0 | do |
5108 | 0 | { |
5109 | 0 | e = strchr (b, ','); |
5110 | |
|
5111 | 0 | if (e) |
5112 | 0 | *e = 0; |
5113 | |
|
5114 | 0 | for (opt = (*desc)->options; opt->name; opt++) |
5115 | 0 | if (strcmp (opt->name, b) == 0) |
5116 | 0 | { |
5117 | 0 | opt->selected = true; |
5118 | 0 | break; |
5119 | 0 | } |
5120 | 0 | if (opt->name == NULL) |
5121 | 0 | non_fatal (_("target specific dump '%s' not supported"), b); |
5122 | |
|
5123 | 0 | if (e) |
5124 | 0 | { |
5125 | 0 | *e = ','; |
5126 | 0 | b = e + 1; |
5127 | 0 | } |
5128 | 0 | } |
5129 | 0 | while (e != NULL); |
5130 | | |
5131 | | /* Dump. */ |
5132 | 0 | (*desc)->dump (abfd); |
5133 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_target_specific Unexecuted instantiation: fuzz_dwarf.c:dump_target_specific |
5134 | | |
5135 | | /* Display a section in hexadecimal format with associated characters. |
5136 | | Each line prefixed by the zero padded address. */ |
5137 | | |
5138 | | static void |
5139 | | dump_section (bfd *abfd, asection *section, void *dummy ATTRIBUTE_UNUSED) |
5140 | 899k | { |
5141 | 899k | bfd_byte *data = NULL; |
5142 | 899k | bfd_size_type datasize; |
5143 | 899k | bfd_vma addr_offset; |
5144 | 899k | bfd_vma start_offset; |
5145 | 899k | bfd_vma stop_offset; |
5146 | 899k | unsigned int opb = bfd_octets_per_byte (abfd, section); |
5147 | | /* Bytes per line. */ |
5148 | 899k | const int onaline = 16; |
5149 | 899k | char buf[64]; |
5150 | 899k | int count; |
5151 | 899k | int width; |
5152 | | |
5153 | 899k | if (only_list == NULL) |
5154 | 899k | { |
5155 | 899k | if ((section->flags & SEC_HAS_CONTENTS) == 0) |
5156 | 220k | return; |
5157 | 899k | } |
5158 | 0 | else if (!process_section_p (section)) |
5159 | 0 | return; |
5160 | | |
5161 | 678k | if ((datasize = bfd_section_size (section)) == 0) |
5162 | 48.8k | return; |
5163 | | |
5164 | | /* Compute the address range to display. */ |
5165 | 629k | if (start_address == (bfd_vma) -1 |
5166 | 0 | || start_address < section->vma) |
5167 | 629k | start_offset = 0; |
5168 | 0 | else |
5169 | 0 | start_offset = start_address - section->vma; |
5170 | | |
5171 | 629k | if (stop_address == (bfd_vma) -1) |
5172 | 629k | stop_offset = datasize / opb; |
5173 | 0 | else |
5174 | 0 | { |
5175 | 0 | if (stop_address < section->vma) |
5176 | 0 | stop_offset = 0; |
5177 | 0 | else |
5178 | 0 | stop_offset = stop_address - section->vma; |
5179 | |
|
5180 | 0 | if (stop_offset > datasize / opb) |
5181 | 0 | stop_offset = datasize / opb; |
5182 | 0 | } |
5183 | | |
5184 | 629k | if (start_offset >= stop_offset) |
5185 | 0 | return; |
5186 | | |
5187 | 629k | printf (_("Contents of section %s:"), sanitize_string (section->name)); |
5188 | 629k | if (display_file_offsets) |
5189 | 0 | printf (_(" (Starting at file offset: 0x%lx)"), |
5190 | 0 | (unsigned long) (section->filepos + start_offset)); |
5191 | 629k | printf ("\n"); |
5192 | | |
5193 | 629k | if (bfd_is_section_compressed (abfd, section) && ! decompressed_dumps) |
5194 | 437 | printf (_(" NOTE: This section is compressed, but its contents have NOT been expanded for this dump.\n")); |
5195 | | |
5196 | 629k | if (!bfd_get_full_section_contents (abfd, section, &data)) |
5197 | 530k | { |
5198 | 530k | non_fatal (_("Reading section %s failed because: %s"), |
5199 | 530k | section->name, bfd_errmsg (bfd_get_error ())); |
5200 | 530k | return; |
5201 | 530k | } |
5202 | | |
5203 | 99.3k | width = 4; |
5204 | | |
5205 | 99.3k | bfd_sprintf_vma (abfd, buf, start_offset + section->vma); |
5206 | 99.3k | if (strlen (buf) >= sizeof (buf)) |
5207 | 0 | abort (); |
5208 | | |
5209 | 99.3k | count = 0; |
5210 | 730k | while (buf[count] == '0' && buf[count+1] != '\0') |
5211 | 631k | count++; |
5212 | 99.3k | count = strlen (buf) - count; |
5213 | 99.3k | if (count > width) |
5214 | 37.2k | width = count; |
5215 | | |
5216 | 99.3k | bfd_sprintf_vma (abfd, buf, stop_offset + section->vma - 1); |
5217 | 99.3k | if (strlen (buf) >= sizeof (buf)) |
5218 | 0 | abort (); |
5219 | | |
5220 | 99.3k | count = 0; |
5221 | 663k | while (buf[count] == '0' && buf[count+1] != '\0') |
5222 | 564k | count++; |
5223 | 99.3k | count = strlen (buf) - count; |
5224 | 99.3k | if (count > width) |
5225 | 532 | width = count; |
5226 | | |
5227 | 99.3k | for (addr_offset = start_offset; |
5228 | 12.4M | addr_offset < stop_offset; addr_offset += onaline / opb) |
5229 | 12.3M | { |
5230 | 12.3M | bfd_size_type j; |
5231 | | |
5232 | 12.3M | bfd_sprintf_vma (abfd, buf, (addr_offset + section->vma)); |
5233 | 12.3M | count = strlen (buf); |
5234 | 12.3M | if ((size_t) count >= sizeof (buf)) |
5235 | 0 | abort (); |
5236 | | |
5237 | 12.3M | putchar (' '); |
5238 | 12.3M | while (count < width) |
5239 | 0 | { |
5240 | 0 | putchar ('0'); |
5241 | 0 | count++; |
5242 | 0 | } |
5243 | 12.3M | fputs (buf + count - width, stdout); |
5244 | 12.3M | putchar (' '); |
5245 | | |
5246 | 12.3M | for (j = addr_offset * opb; |
5247 | 209M | j < addr_offset * opb + onaline; j++) |
5248 | 197M | { |
5249 | 197M | if (j < stop_offset * opb) |
5250 | 197M | printf ("%02x", (unsigned) (data[j])); |
5251 | 578k | else |
5252 | 578k | printf (" "); |
5253 | 197M | if ((j & 3) == 3) |
5254 | 49.4M | printf (" "); |
5255 | 197M | } |
5256 | | |
5257 | 12.3M | printf (" "); |
5258 | 12.3M | for (j = addr_offset * opb; |
5259 | 209M | j < addr_offset * opb + onaline; j++) |
5260 | 197M | { |
5261 | 197M | if (j >= stop_offset * opb) |
5262 | 578k | printf (" "); |
5263 | 197M | else |
5264 | 197M | printf ("%c", ISPRINT (data[j]) ? data[j] : '.'); |
5265 | 197M | } |
5266 | 12.3M | putchar ('\n'); |
5267 | 12.3M | } |
5268 | 99.3k | free (data); |
5269 | 99.3k | } fuzz_objdump.c:dump_section Line | Count | Source | 5140 | 899k | { | 5141 | 899k | bfd_byte *data = NULL; | 5142 | 899k | bfd_size_type datasize; | 5143 | 899k | bfd_vma addr_offset; | 5144 | 899k | bfd_vma start_offset; | 5145 | 899k | bfd_vma stop_offset; | 5146 | 899k | unsigned int opb = bfd_octets_per_byte (abfd, section); | 5147 | | /* Bytes per line. */ | 5148 | 899k | const int onaline = 16; | 5149 | 899k | char buf[64]; | 5150 | 899k | int count; | 5151 | 899k | int width; | 5152 | | | 5153 | 899k | if (only_list == NULL) | 5154 | 899k | { | 5155 | 899k | if ((section->flags & SEC_HAS_CONTENTS) == 0) | 5156 | 220k | return; | 5157 | 899k | } | 5158 | 0 | else if (!process_section_p (section)) | 5159 | 0 | return; | 5160 | | | 5161 | 678k | if ((datasize = bfd_section_size (section)) == 0) | 5162 | 48.8k | return; | 5163 | | | 5164 | | /* Compute the address range to display. */ | 5165 | 629k | if (start_address == (bfd_vma) -1 | 5166 | 0 | || start_address < section->vma) | 5167 | 629k | start_offset = 0; | 5168 | 0 | else | 5169 | 0 | start_offset = start_address - section->vma; | 5170 | | | 5171 | 629k | if (stop_address == (bfd_vma) -1) | 5172 | 629k | stop_offset = datasize / opb; | 5173 | 0 | else | 5174 | 0 | { | 5175 | 0 | if (stop_address < section->vma) | 5176 | 0 | stop_offset = 0; | 5177 | 0 | else | 5178 | 0 | stop_offset = stop_address - section->vma; | 5179 | |
| 5180 | 0 | if (stop_offset > datasize / opb) | 5181 | 0 | stop_offset = datasize / opb; | 5182 | 0 | } | 5183 | | | 5184 | 629k | if (start_offset >= stop_offset) | 5185 | 0 | return; | 5186 | | | 5187 | 629k | printf (_("Contents of section %s:"), sanitize_string (section->name)); | 5188 | 629k | if (display_file_offsets) | 5189 | 0 | printf (_(" (Starting at file offset: 0x%lx)"), | 5190 | 0 | (unsigned long) (section->filepos + start_offset)); | 5191 | 629k | printf ("\n"); | 5192 | | | 5193 | 629k | if (bfd_is_section_compressed (abfd, section) && ! decompressed_dumps) | 5194 | 437 | printf (_(" NOTE: This section is compressed, but its contents have NOT been expanded for this dump.\n")); | 5195 | | | 5196 | 629k | if (!bfd_get_full_section_contents (abfd, section, &data)) | 5197 | 530k | { | 5198 | 530k | non_fatal (_("Reading section %s failed because: %s"), | 5199 | 530k | section->name, bfd_errmsg (bfd_get_error ())); | 5200 | 530k | return; | 5201 | 530k | } | 5202 | | | 5203 | 99.3k | width = 4; | 5204 | | | 5205 | 99.3k | bfd_sprintf_vma (abfd, buf, start_offset + section->vma); | 5206 | 99.3k | if (strlen (buf) >= sizeof (buf)) | 5207 | 0 | abort (); | 5208 | | | 5209 | 99.3k | count = 0; | 5210 | 730k | while (buf[count] == '0' && buf[count+1] != '\0') | 5211 | 631k | count++; | 5212 | 99.3k | count = strlen (buf) - count; | 5213 | 99.3k | if (count > width) | 5214 | 37.2k | width = count; | 5215 | | | 5216 | 99.3k | bfd_sprintf_vma (abfd, buf, stop_offset + section->vma - 1); | 5217 | 99.3k | if (strlen (buf) >= sizeof (buf)) | 5218 | 0 | abort (); | 5219 | | | 5220 | 99.3k | count = 0; | 5221 | 663k | while (buf[count] == '0' && buf[count+1] != '\0') | 5222 | 564k | count++; | 5223 | 99.3k | count = strlen (buf) - count; | 5224 | 99.3k | if (count > width) | 5225 | 532 | width = count; | 5226 | | | 5227 | 99.3k | for (addr_offset = start_offset; | 5228 | 12.4M | addr_offset < stop_offset; addr_offset += onaline / opb) | 5229 | 12.3M | { | 5230 | 12.3M | bfd_size_type j; | 5231 | | | 5232 | 12.3M | bfd_sprintf_vma (abfd, buf, (addr_offset + section->vma)); | 5233 | 12.3M | count = strlen (buf); | 5234 | 12.3M | if ((size_t) count >= sizeof (buf)) | 5235 | 0 | abort (); | 5236 | | | 5237 | 12.3M | putchar (' '); | 5238 | 12.3M | while (count < width) | 5239 | 0 | { | 5240 | 0 | putchar ('0'); | 5241 | 0 | count++; | 5242 | 0 | } | 5243 | 12.3M | fputs (buf + count - width, stdout); | 5244 | 12.3M | putchar (' '); | 5245 | | | 5246 | 12.3M | for (j = addr_offset * opb; | 5247 | 209M | j < addr_offset * opb + onaline; j++) | 5248 | 197M | { | 5249 | 197M | if (j < stop_offset * opb) | 5250 | 197M | printf ("%02x", (unsigned) (data[j])); | 5251 | 578k | else | 5252 | 578k | printf (" "); | 5253 | 197M | if ((j & 3) == 3) | 5254 | 49.4M | printf (" "); | 5255 | 197M | } | 5256 | | | 5257 | 12.3M | printf (" "); | 5258 | 12.3M | for (j = addr_offset * opb; | 5259 | 209M | j < addr_offset * opb + onaline; j++) | 5260 | 197M | { | 5261 | 197M | if (j >= stop_offset * opb) | 5262 | 578k | printf (" "); | 5263 | 197M | else | 5264 | 197M | printf ("%c", ISPRINT (data[j]) ? data[j] : '.'); | 5265 | 197M | } | 5266 | 12.3M | putchar ('\n'); | 5267 | 12.3M | } | 5268 | 99.3k | free (data); | 5269 | 99.3k | } |
Unexecuted instantiation: fuzz_dwarf.c:dump_section |
5270 | | |
5271 | | /* Actually display the various requested regions. */ |
5272 | | |
5273 | | static void |
5274 | | dump_data (bfd *abfd) |
5275 | 31.5k | { |
5276 | 31.5k | bfd_map_over_sections (abfd, dump_section, NULL); |
5277 | 31.5k | } Line | Count | Source | 5275 | 31.5k | { | 5276 | | bfd_map_over_sections (abfd, dump_section, NULL); | 5277 | 31.5k | } |
Unexecuted instantiation: fuzz_dwarf.c:dump_data |
5278 | | |
5279 | | /* Should perhaps share code and display with nm? */ |
5280 | | |
5281 | | static void |
5282 | | dump_symbols (bfd *abfd ATTRIBUTE_UNUSED, bool dynamic) |
5283 | 0 | { |
5284 | 0 | asymbol **current; |
5285 | 0 | long max_count; |
5286 | 0 | long count; |
5287 | |
|
5288 | 0 | if (dynamic) |
5289 | 0 | { |
5290 | 0 | current = dynsyms; |
5291 | 0 | max_count = dynsymcount; |
5292 | 0 | printf ("DYNAMIC SYMBOL TABLE:\n"); |
5293 | 0 | } |
5294 | 0 | else |
5295 | 0 | { |
5296 | 0 | current = syms; |
5297 | 0 | max_count = symcount; |
5298 | 0 | printf ("SYMBOL TABLE:\n"); |
5299 | 0 | } |
5300 | |
|
5301 | 0 | if (max_count == 0) |
5302 | 0 | printf (_("no symbols\n")); |
5303 | |
|
5304 | 0 | for (count = 0; count < max_count; count++) |
5305 | 0 | { |
5306 | 0 | bfd *cur_bfd; |
5307 | |
|
5308 | 0 | if (*current == NULL) |
5309 | 0 | printf (_("no information for symbol number %ld\n"), count); |
5310 | | |
5311 | 0 | else if ((cur_bfd = bfd_asymbol_bfd (*current)) == NULL) |
5312 | 0 | printf (_("could not determine the type of symbol number %ld\n"), |
5313 | 0 | count); |
5314 | | |
5315 | 0 | else if (process_section_p ((* current)->section) |
5316 | 0 | && (dump_special_syms |
5317 | 0 | || !bfd_is_target_special_symbol (cur_bfd, *current))) |
5318 | 0 | { |
5319 | 0 | const char *name = (*current)->name; |
5320 | |
|
5321 | 0 | if (do_demangle && name != NULL && *name != '\0') |
5322 | 0 | { |
5323 | 0 | char *alloc; |
5324 | | |
5325 | | /* If we want to demangle the name, we demangle it |
5326 | | here, and temporarily clobber it while calling |
5327 | | bfd_print_symbol. FIXME: This is a gross hack. */ |
5328 | 0 | alloc = bfd_demangle (cur_bfd, name, demangle_flags); |
5329 | 0 | if (alloc != NULL) |
5330 | 0 | (*current)->name = alloc; |
5331 | 0 | bfd_print_symbol (cur_bfd, stdout, *current, |
5332 | 0 | bfd_print_symbol_all); |
5333 | 0 | if (alloc != NULL) |
5334 | 0 | { |
5335 | 0 | (*current)->name = name; |
5336 | 0 | free (alloc); |
5337 | 0 | } |
5338 | 0 | } |
5339 | 0 | else if (unicode_display != unicode_default |
5340 | 0 | && name != NULL && *name != '\0') |
5341 | 0 | { |
5342 | 0 | const char * sanitized_name; |
5343 | | |
5344 | | /* If we want to sanitize the name, we do it here, and |
5345 | | temporarily clobber it while calling bfd_print_symbol. |
5346 | | FIXME: This is a gross hack. */ |
5347 | 0 | sanitized_name = sanitize_string (name); |
5348 | 0 | if (sanitized_name != name) |
5349 | 0 | (*current)->name = sanitized_name; |
5350 | 0 | else |
5351 | 0 | sanitized_name = NULL; |
5352 | 0 | bfd_print_symbol (cur_bfd, stdout, *current, |
5353 | 0 | bfd_print_symbol_all); |
5354 | 0 | if (sanitized_name != NULL) |
5355 | 0 | (*current)->name = name; |
5356 | 0 | } |
5357 | 0 | else |
5358 | 0 | bfd_print_symbol (cur_bfd, stdout, *current, |
5359 | 0 | bfd_print_symbol_all); |
5360 | 0 | printf ("\n"); |
5361 | 0 | } |
5362 | |
|
5363 | 0 | current++; |
5364 | 0 | } |
5365 | 0 | printf ("\n\n"); |
5366 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_symbols Unexecuted instantiation: fuzz_dwarf.c:dump_symbols |
5367 | | |
5368 | | static void |
5369 | | dump_reloc_set (bfd *abfd, asection *sec, arelent **relpp, long relcount) |
5370 | 0 | { |
5371 | 0 | arelent **p; |
5372 | 0 | char *last_filename, *last_functionname; |
5373 | 0 | unsigned int last_line; |
5374 | 0 | unsigned int last_discriminator; |
5375 | | |
5376 | | /* Get column headers lined up reasonably. */ |
5377 | 0 | { |
5378 | 0 | static int width; |
5379 | |
|
5380 | 0 | if (width == 0) |
5381 | 0 | { |
5382 | 0 | char buf[30]; |
5383 | |
|
5384 | 0 | bfd_sprintf_vma (abfd, buf, (bfd_vma) -1); |
5385 | 0 | width = strlen (buf) - 7; |
5386 | 0 | } |
5387 | 0 | printf ("OFFSET %*s TYPE %*s VALUE\n", width, "", 12, ""); |
5388 | 0 | } |
5389 | |
|
5390 | 0 | last_filename = NULL; |
5391 | 0 | last_functionname = NULL; |
5392 | 0 | last_line = 0; |
5393 | 0 | last_discriminator = 0; |
5394 | |
|
5395 | 0 | for (p = relpp; relcount && *p != NULL; p++, relcount--) |
5396 | 0 | { |
5397 | 0 | arelent *q = *p; |
5398 | 0 | const char *filename, *functionname; |
5399 | 0 | unsigned int linenumber; |
5400 | 0 | unsigned int discriminator; |
5401 | 0 | const char *sym_name; |
5402 | 0 | const char *section_name; |
5403 | 0 | bfd_vma addend2 = 0; |
5404 | |
|
5405 | 0 | if (start_address != (bfd_vma) -1 |
5406 | 0 | && q->address < start_address) |
5407 | 0 | continue; |
5408 | 0 | if (stop_address != (bfd_vma) -1 |
5409 | 0 | && q->address > stop_address) |
5410 | 0 | continue; |
5411 | | |
5412 | 0 | if (with_line_numbers |
5413 | 0 | && sec != NULL |
5414 | 0 | && bfd_find_nearest_line_discriminator (abfd, sec, syms, q->address, |
5415 | 0 | &filename, &functionname, |
5416 | 0 | &linenumber, &discriminator)) |
5417 | 0 | { |
5418 | 0 | if (functionname != NULL |
5419 | 0 | && (last_functionname == NULL |
5420 | 0 | || strcmp (functionname, last_functionname) != 0)) |
5421 | 0 | { |
5422 | 0 | printf ("%s():\n", sanitize_string (functionname)); |
5423 | 0 | if (last_functionname != NULL) |
5424 | 0 | free (last_functionname); |
5425 | 0 | last_functionname = xstrdup (functionname); |
5426 | 0 | } |
5427 | |
|
5428 | 0 | if (linenumber > 0 |
5429 | 0 | && (linenumber != last_line |
5430 | 0 | || (filename != NULL |
5431 | 0 | && last_filename != NULL |
5432 | 0 | && filename_cmp (filename, last_filename) != 0) |
5433 | 0 | || (discriminator != last_discriminator))) |
5434 | 0 | { |
5435 | 0 | if (discriminator > 0) |
5436 | 0 | printf ("%s:%u\n", filename == NULL ? "???" : |
5437 | 0 | sanitize_string (filename), linenumber); |
5438 | 0 | else |
5439 | 0 | printf ("%s:%u (discriminator %u)\n", |
5440 | 0 | filename == NULL ? "???" : sanitize_string (filename), |
5441 | 0 | linenumber, discriminator); |
5442 | 0 | last_line = linenumber; |
5443 | 0 | last_discriminator = discriminator; |
5444 | 0 | if (last_filename != NULL) |
5445 | 0 | free (last_filename); |
5446 | 0 | if (filename == NULL) |
5447 | 0 | last_filename = NULL; |
5448 | 0 | else |
5449 | 0 | last_filename = xstrdup (filename); |
5450 | 0 | } |
5451 | 0 | } |
5452 | |
|
5453 | 0 | if (q->sym_ptr_ptr && *q->sym_ptr_ptr) |
5454 | 0 | { |
5455 | 0 | sym_name = (*(q->sym_ptr_ptr))->name; |
5456 | 0 | section_name = (*(q->sym_ptr_ptr))->section->name; |
5457 | 0 | } |
5458 | 0 | else |
5459 | 0 | { |
5460 | 0 | sym_name = NULL; |
5461 | 0 | section_name = NULL; |
5462 | 0 | } |
5463 | |
|
5464 | 0 | bfd_printf_vma (abfd, q->address); |
5465 | 0 | if (q->howto == NULL) |
5466 | 0 | printf (" *unknown* "); |
5467 | 0 | else if (q->howto->name) |
5468 | 0 | { |
5469 | 0 | const char *name = q->howto->name; |
5470 | | |
5471 | | /* R_SPARC_OLO10 relocations contain two addends. |
5472 | | But because 'arelent' lacks enough storage to |
5473 | | store them both, the 64-bit ELF Sparc backend |
5474 | | records this as two relocations. One R_SPARC_LO10 |
5475 | | and one R_SPARC_13, both pointing to the same |
5476 | | address. This is merely so that we have some |
5477 | | place to store both addend fields. |
5478 | | |
5479 | | Undo this transformation, otherwise the output |
5480 | | will be confusing. */ |
5481 | 0 | if (abfd->xvec->flavour == bfd_target_elf_flavour |
5482 | 0 | && elf_tdata (abfd)->elf_header->e_machine == EM_SPARCV9 |
5483 | 0 | && relcount > 1 |
5484 | 0 | && !strcmp (q->howto->name, "R_SPARC_LO10")) |
5485 | 0 | { |
5486 | 0 | arelent *q2 = *(p + 1); |
5487 | 0 | if (q2 != NULL |
5488 | 0 | && q2->howto |
5489 | 0 | && q->address == q2->address |
5490 | 0 | && !strcmp (q2->howto->name, "R_SPARC_13")) |
5491 | 0 | { |
5492 | 0 | name = "R_SPARC_OLO10"; |
5493 | 0 | addend2 = q2->addend; |
5494 | 0 | p++; |
5495 | 0 | } |
5496 | 0 | } |
5497 | 0 | printf (" %-16s ", name); |
5498 | 0 | } |
5499 | 0 | else |
5500 | 0 | printf (" %-16d ", q->howto->type); |
5501 | |
|
5502 | 0 | if (sym_name) |
5503 | 0 | { |
5504 | 0 | objdump_print_symname (abfd, NULL, *q->sym_ptr_ptr); |
5505 | 0 | } |
5506 | 0 | else |
5507 | 0 | { |
5508 | 0 | if (section_name == NULL) |
5509 | 0 | section_name = "*unknown*"; |
5510 | 0 | printf ("[%s]", sanitize_string (section_name)); |
5511 | 0 | } |
5512 | |
|
5513 | 0 | if (q->addend) |
5514 | 0 | { |
5515 | 0 | bfd_signed_vma addend = q->addend; |
5516 | 0 | if (addend < 0) |
5517 | 0 | { |
5518 | 0 | printf ("-0x"); |
5519 | 0 | addend = -addend; |
5520 | 0 | } |
5521 | 0 | else |
5522 | 0 | printf ("+0x"); |
5523 | 0 | bfd_printf_vma (abfd, addend); |
5524 | 0 | } |
5525 | 0 | if (addend2) |
5526 | 0 | { |
5527 | 0 | printf ("+0x"); |
5528 | 0 | bfd_printf_vma (abfd, addend2); |
5529 | 0 | } |
5530 | |
|
5531 | 0 | printf ("\n"); |
5532 | 0 | } |
5533 | |
|
5534 | 0 | if (last_filename != NULL) |
5535 | 0 | free (last_filename); |
5536 | 0 | if (last_functionname != NULL) |
5537 | 0 | free (last_functionname); |
5538 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_reloc_set Unexecuted instantiation: fuzz_dwarf.c:dump_reloc_set |
5539 | | |
5540 | | static void |
5541 | | dump_relocs_in_section (bfd *abfd, |
5542 | | asection *section, |
5543 | | void *counter) |
5544 | 0 | { |
5545 | 0 | arelent **relpp; |
5546 | 0 | long relcount; |
5547 | 0 | long relsize; |
5548 | |
|
5549 | 0 | if ( bfd_is_abs_section (section) |
5550 | 0 | || bfd_is_und_section (section) |
5551 | 0 | || bfd_is_com_section (section) |
5552 | 0 | || (! process_section_p (section)) |
5553 | 0 | || ((section->flags & SEC_RELOC) == 0)) |
5554 | 0 | return; |
5555 | | |
5556 | 0 | printf ("RELOCATION RECORDS FOR [%s]:", sanitize_string (section->name)); |
5557 | |
|
5558 | 0 | relsize = bfd_get_reloc_upper_bound (abfd, section); |
5559 | 0 | if (relsize == 0) |
5560 | 0 | { |
5561 | 0 | printf (" (none)\n\n"); |
5562 | 0 | return; |
5563 | 0 | } |
5564 | | |
5565 | 0 | if (relsize < 0) |
5566 | 0 | { |
5567 | 0 | relpp = NULL; |
5568 | 0 | relcount = relsize; |
5569 | 0 | } |
5570 | 0 | else |
5571 | 0 | { |
5572 | 0 | relpp = (arelent **) xmalloc (relsize); |
5573 | 0 | relcount = bfd_canonicalize_reloc (abfd, section, relpp, syms); |
5574 | 0 | } |
5575 | |
|
5576 | 0 | if (relcount < 0) |
5577 | 0 | { |
5578 | 0 | printf ("\n"); |
5579 | 0 | non_fatal (_("failed to read relocs in: %s"), |
5580 | 0 | sanitize_string (bfd_get_filename (abfd))); |
5581 | 0 | my_bfd_nonfatal (_("error message was")); |
5582 | 0 | } |
5583 | 0 | else if (relcount == 0) |
5584 | 0 | printf (" (none)\n\n"); |
5585 | 0 | else |
5586 | 0 | { |
5587 | 0 | printf ("\n"); |
5588 | 0 | dump_reloc_set (abfd, section, relpp, relcount); |
5589 | 0 | printf ("\n\n"); |
5590 | 0 | } |
5591 | 0 | free (relpp); |
5592 | |
|
5593 | 0 | * ((unsigned int *) counter) += 1; |
5594 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_relocs_in_section Unexecuted instantiation: fuzz_dwarf.c:dump_relocs_in_section |
5595 | | |
5596 | | static void |
5597 | | is_relr_section (bfd *abfd ATTRIBUTE_UNUSED, |
5598 | | asection * section, void *data) |
5599 | 0 | { |
5600 | 0 | if (section->flags & SEC_LINKER_CREATED) |
5601 | 0 | return; |
5602 | | |
5603 | 0 | struct bfd_elf_section_data * esd = elf_section_data (section); |
5604 | 0 | if (esd == NULL) |
5605 | 0 | return; |
5606 | | |
5607 | 0 | if (esd->this_hdr.sh_type == SHT_RELR) |
5608 | 0 | * ((bool *) data) = true; |
5609 | 0 | } Unexecuted instantiation: fuzz_objdump.c:is_relr_section Unexecuted instantiation: fuzz_dwarf.c:is_relr_section |
5610 | | |
5611 | | static bool |
5612 | | contains_relr_relocs (bfd *abfd) |
5613 | 0 | { |
5614 | 0 | if (bfd_get_flavour (abfd) != bfd_target_elf_flavour) |
5615 | 0 | return false; |
5616 | | |
5617 | 0 | bool result = false; |
5618 | |
|
5619 | 0 | bfd_map_over_sections (abfd, is_relr_section, &result); |
5620 | |
|
5621 | 0 | return result; |
5622 | 0 | } Unexecuted instantiation: fuzz_objdump.c:contains_relr_relocs Unexecuted instantiation: fuzz_dwarf.c:contains_relr_relocs |
5623 | | |
5624 | | static void |
5625 | | dump_relocs (bfd *abfd) |
5626 | 0 | { |
5627 | 0 | unsigned int counter = 0; |
5628 | |
|
5629 | 0 | bfd_map_over_sections (abfd, dump_relocs_in_section, & counter); |
5630 | |
|
5631 | 0 | if (counter == 0 && contains_relr_relocs (abfd)) |
5632 | 0 | { |
5633 | 0 | printf (_("%s: This file does not contain any ordinary relocations.\n"), |
5634 | 0 | sanitize_string (bfd_get_filename (abfd))); |
5635 | |
|
5636 | 0 | printf (_("%s: It does however contain RELR relocations. These can be displayed by the readelf program\n"), |
5637 | 0 | sanitize_string (bfd_get_filename (abfd))); |
5638 | 0 | } |
5639 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_relocs Unexecuted instantiation: fuzz_dwarf.c:dump_relocs |
5640 | | |
5641 | | static void |
5642 | | dump_dynamic_relocs (bfd *abfd) |
5643 | 0 | { |
5644 | 0 | long relsize; |
5645 | 0 | arelent **relpp = NULL; |
5646 | 0 | long relcount; |
5647 | |
|
5648 | 0 | relsize = bfd_get_dynamic_reloc_upper_bound (abfd); |
5649 | |
|
5650 | 0 | printf ("DYNAMIC RELOCATION RECORDS"); |
5651 | |
|
5652 | 0 | if (relsize <= 0) |
5653 | 0 | goto none; |
5654 | | |
5655 | 0 | relpp = (arelent **) xmalloc (relsize); |
5656 | 0 | relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms); |
5657 | |
|
5658 | 0 | if (relcount < 0) |
5659 | 0 | { |
5660 | 0 | printf ("\n"); |
5661 | 0 | non_fatal (_("failed to read relocs in: %s"), |
5662 | 0 | sanitize_string (bfd_get_filename (abfd))); |
5663 | 0 | my_bfd_nonfatal (_("error message was")); |
5664 | 0 | } |
5665 | 0 | else if (relcount == 0) |
5666 | 0 | goto none; |
5667 | 0 | else |
5668 | 0 | { |
5669 | 0 | printf ("\n"); |
5670 | 0 | dump_reloc_set (abfd, NULL, relpp, relcount); |
5671 | 0 | printf ("\n\n"); |
5672 | 0 | } |
5673 | 0 | free (relpp); |
5674 | 0 | return; |
5675 | | |
5676 | 0 | none: |
5677 | 0 | printf (" (none)\n\n"); |
5678 | |
|
5679 | 0 | if (contains_relr_relocs (abfd)) |
5680 | 0 | printf (_("%s: contains RELR relocations which are not displayed by %s.\n\ |
5681 | 0 | These can be displayed by the readelf program instead.\n"), |
5682 | 0 | sanitize_string (bfd_get_filename (abfd)), |
5683 | 0 | program_name); |
5684 | |
|
5685 | 0 | free (relpp); |
5686 | 0 | } Unexecuted instantiation: fuzz_objdump.c:dump_dynamic_relocs Unexecuted instantiation: fuzz_dwarf.c:dump_dynamic_relocs |
5687 | | |
5688 | | /* Creates a table of paths, to search for source files. */ |
5689 | | |
5690 | | static void |
5691 | | add_include_path (const char *path) |
5692 | 0 | { |
5693 | 0 | if (path[0] == 0) |
5694 | 0 | return; |
5695 | 0 | include_path_count++; |
5696 | 0 | include_paths = (const char **) |
5697 | 0 | xrealloc (include_paths, include_path_count * sizeof (*include_paths)); |
5698 | | #ifdef HAVE_DOS_BASED_FILE_SYSTEM |
5699 | | if (path[1] == ':' && path[2] == 0) |
5700 | | path = concat (path, ".", (const char *) 0); |
5701 | | #endif |
5702 | 0 | include_paths[include_path_count - 1] = path; |
5703 | 0 | } Unexecuted instantiation: fuzz_objdump.c:add_include_path Unexecuted instantiation: fuzz_dwarf.c:add_include_path |
5704 | | |
5705 | | static void |
5706 | | adjust_addresses (bfd *abfd ATTRIBUTE_UNUSED, |
5707 | | asection *section, |
5708 | | void *arg) |
5709 | 0 | { |
5710 | 0 | if ((section->flags & SEC_DEBUGGING) == 0) |
5711 | 0 | { |
5712 | 0 | bool *has_reloc_p = (bool *) arg; |
5713 | 0 | section->vma += adjust_section_vma; |
5714 | 0 | if (*has_reloc_p) |
5715 | 0 | section->lma += adjust_section_vma; |
5716 | 0 | } |
5717 | 0 | } Unexecuted instantiation: fuzz_objdump.c:adjust_addresses Unexecuted instantiation: fuzz_dwarf.c:adjust_addresses |
5718 | | |
5719 | | /* Return the sign-extended form of an ARCH_SIZE sized VMA. */ |
5720 | | |
5721 | | static bfd_vma |
5722 | | sign_extend_address (bfd *abfd ATTRIBUTE_UNUSED, |
5723 | | bfd_vma vma, |
5724 | | unsigned arch_size) |
5725 | 1.23k | { |
5726 | 1.23k | bfd_vma mask; |
5727 | 1.23k | mask = (bfd_vma) 1 << (arch_size - 1); |
5728 | 1.23k | return (((vma & ((mask << 1) - 1)) ^ mask) - mask); |
5729 | 1.23k | } fuzz_objdump.c:sign_extend_address Line | Count | Source | 5725 | 1.23k | { | 5726 | 1.23k | bfd_vma mask; | 5727 | 1.23k | mask = (bfd_vma) 1 << (arch_size - 1); | 5728 | 1.23k | return (((vma & ((mask << 1) - 1)) ^ mask) - mask); | 5729 | 1.23k | } |
Unexecuted instantiation: fuzz_dwarf.c:sign_extend_address |
5730 | | |
5731 | | static bool |
5732 | | might_need_separate_debug_info (bool is_mainfile) |
5733 | 31.5k | { |
5734 | | /* We do not follow links from debug info files. */ |
5735 | 31.5k | if (! is_mainfile) |
5736 | 0 | return false; |
5737 | | |
5738 | | /* Since do_follow_links might be enabled by default, only treat it as an |
5739 | | indication that separate files should be loaded if setting it was a |
5740 | | deliberate user action. */ |
5741 | 31.5k | if (DEFAULT_FOR_FOLLOW_LINKS == 0 && do_follow_links) |
5742 | 0 | return true; |
5743 | | |
5744 | 31.5k | if (process_links || dump_symtab || dump_debugging |
5745 | | /* Disassembly benefits from symbol tables, which might |
5746 | | be stored in the separate debug info file. */ |
5747 | 0 | || disassemble |
5748 | 0 | || dump_dwarf_section_info || with_source_code) |
5749 | 31.5k | return true; |
5750 | | |
5751 | 0 | return false; |
5752 | 31.5k | } fuzz_objdump.c:might_need_separate_debug_info Line | Count | Source | 5733 | 31.5k | { | 5734 | | /* We do not follow links from debug info files. */ | 5735 | 31.5k | if (! is_mainfile) | 5736 | 0 | return false; | 5737 | | | 5738 | | /* Since do_follow_links might be enabled by default, only treat it as an | 5739 | | indication that separate files should be loaded if setting it was a | 5740 | | deliberate user action. */ | 5741 | 31.5k | if (DEFAULT_FOR_FOLLOW_LINKS == 0 && do_follow_links) | 5742 | 0 | return true; | 5743 | | | 5744 | 31.5k | if (process_links || dump_symtab || dump_debugging | 5745 | | /* Disassembly benefits from symbol tables, which might | 5746 | | be stored in the separate debug info file. */ | 5747 | 0 | || disassemble | 5748 | 0 | || dump_dwarf_section_info || with_source_code) | 5749 | 31.5k | return true; | 5750 | | | 5751 | 0 | return false; | 5752 | 31.5k | } |
Unexecuted instantiation: fuzz_dwarf.c:might_need_separate_debug_info |
5753 | | |
5754 | | /* Dump selected contents of ABFD. */ |
5755 | | |
5756 | | static void |
5757 | | dump_bfd (bfd *abfd, bool is_mainfile) |
5758 | 31.5k | { |
5759 | 31.5k | elf_backend_data *bed; |
5760 | | |
5761 | 31.5k | if (bfd_big_endian (abfd)) |
5762 | 12.2k | byte_get = byte_get_big_endian; |
5763 | 19.3k | else if (bfd_little_endian (abfd)) |
5764 | 19.3k | byte_get = byte_get_little_endian; |
5765 | 33 | else |
5766 | 33 | byte_get = NULL; |
5767 | | |
5768 | | /* Load any separate debug information files. */ |
5769 | 31.5k | if (byte_get != NULL && might_need_separate_debug_info (is_mainfile)) |
5770 | 31.5k | { |
5771 | | /* Since it is possible that there are no separate debug files, |
5772 | | do not complain if calling load_separate_debug_files returns false. */ |
5773 | 31.5k | (void) load_separate_debug_files (abfd, bfd_get_filename (abfd)); |
5774 | | |
5775 | | /* If asked to do so, recursively dump the separate files. */ |
5776 | 31.5k | if (do_follow_links) |
5777 | 0 | { |
5778 | 0 | separate_info * i; |
5779 | |
|
5780 | 0 | for (i = first_separate_info; i != NULL; i = i->next) |
5781 | 0 | dump_bfd (i->handle, false); |
5782 | 0 | } |
5783 | 31.5k | } |
5784 | | |
5785 | | /* Adjust user-specified start and stop limits for targets that use |
5786 | | signed addresses. */ |
5787 | 31.5k | if (bfd_get_flavour (abfd) == bfd_target_elf_flavour |
5788 | 17.2k | && (bed = get_elf_backend_data (abfd)) != NULL |
5789 | 17.2k | && bed->sign_extend_vma) |
5790 | 615 | { |
5791 | 615 | start_address = sign_extend_address (abfd, start_address, |
5792 | 615 | bed->s->arch_size); |
5793 | 615 | stop_address = sign_extend_address (abfd, stop_address, |
5794 | 615 | bed->s->arch_size); |
5795 | 615 | } |
5796 | | |
5797 | | /* If we are adjusting section VMA's, change them all now. Changing |
5798 | | the BFD information is a hack. However, we must do it, or |
5799 | | bfd_find_nearest_line will not do the right thing. */ |
5800 | 31.5k | if (adjust_section_vma != 0) |
5801 | 0 | { |
5802 | 0 | bool has_reloc = (abfd->flags & HAS_RELOC); |
5803 | 0 | bfd_map_over_sections (abfd, adjust_addresses, &has_reloc); |
5804 | 0 | } |
5805 | | |
5806 | 31.5k | if (is_mainfile || process_links) |
5807 | 31.5k | { |
5808 | 31.5k | if (! dump_debugging_tags && ! suppress_bfd_header) |
5809 | 31.5k | printf (_("\n%s: file format %s\n"), |
5810 | 31.5k | sanitize_string (bfd_get_filename (abfd)), |
5811 | 31.5k | abfd->xvec->name); |
5812 | 31.5k | if (dump_ar_hdrs) |
5813 | 31.5k | print_arelt_descr (stdout, abfd, true, false); |
5814 | 31.5k | if (dump_file_header) |
5815 | 0 | dump_bfd_header (abfd); |
5816 | 31.5k | if (dump_private_headers) |
5817 | 31.5k | dump_bfd_private_header (abfd); |
5818 | 31.5k | if (dump_private_options != NULL) |
5819 | 0 | dump_target_specific (abfd); |
5820 | 31.5k | if (! dump_debugging_tags && ! suppress_bfd_header) |
5821 | 31.5k | putchar ('\n'); |
5822 | 31.5k | } |
5823 | | |
5824 | 31.5k | if (dump_symtab |
5825 | 31.5k | || dump_reloc_info |
5826 | 2.24k | || disassemble |
5827 | 2.24k | || dump_debugging |
5828 | 0 | || dump_dwarf_section_info) |
5829 | 31.5k | { |
5830 | 31.5k | syms = slurp_symtab (abfd); |
5831 | | |
5832 | | /* If following links, load any symbol tables from the linked files as well. */ |
5833 | 31.5k | if (do_follow_links && is_mainfile) |
5834 | 33 | { |
5835 | 33 | separate_info * i; |
5836 | | |
5837 | 33 | for (i = first_separate_info; i != NULL; i = i->next) |
5838 | 0 | { |
5839 | 0 | asymbol ** extra_syms; |
5840 | 0 | long old_symcount = symcount; |
5841 | |
|
5842 | 0 | extra_syms = slurp_symtab (i->handle); |
5843 | |
|
5844 | 0 | if (extra_syms) |
5845 | 0 | { |
5846 | 0 | if (old_symcount == 0) |
5847 | 0 | { |
5848 | 0 | free (syms); |
5849 | 0 | syms = extra_syms; |
5850 | 0 | } |
5851 | 0 | else |
5852 | 0 | { |
5853 | 0 | syms = xrealloc (syms, ((symcount + old_symcount + 1) |
5854 | 0 | * sizeof (asymbol *))); |
5855 | 0 | memcpy (syms + old_symcount, |
5856 | 0 | extra_syms, |
5857 | 0 | (symcount + 1) * sizeof (asymbol *)); |
5858 | 0 | free (extra_syms); |
5859 | 0 | } |
5860 | 0 | } |
5861 | |
|
5862 | 0 | symcount += old_symcount; |
5863 | 0 | } |
5864 | 33 | } |
5865 | 31.5k | } |
5866 | | |
5867 | 31.5k | if (is_mainfile || process_links) |
5868 | 31.5k | { |
5869 | 31.5k | if (dump_section_headers) |
5870 | 31.5k | dump_headers (abfd); |
5871 | | |
5872 | 31.5k | if (dump_dynamic_symtab || dump_dynamic_reloc_info |
5873 | 31.5k | || (disassemble && bfd_get_dynamic_symtab_upper_bound (abfd) > 0)) |
5874 | 306 | dynsyms = slurp_dynamic_symtab (abfd); |
5875 | | |
5876 | 31.5k | if (disassemble) |
5877 | 29.3k | { |
5878 | 29.3k | synthcount = bfd_get_synthetic_symtab (abfd, symcount, syms, |
5879 | 29.3k | dynsymcount, dynsyms, |
5880 | 29.3k | &synthsyms); |
5881 | 29.3k | if (synthcount < 0) |
5882 | 12.2k | synthcount = 0; |
5883 | 29.3k | } |
5884 | | |
5885 | 31.5k | if (dump_symtab) |
5886 | 0 | dump_symbols (abfd, false); |
5887 | 31.5k | if (dump_dynamic_symtab) |
5888 | 0 | dump_symbols (abfd, true); |
5889 | 31.5k | } |
5890 | 31.5k | if (dump_global_vars) |
5891 | 0 | dump_global_vars_info (abfd, is_mainfile); |
5892 | 31.5k | if (dump_dwarf_section_info) |
5893 | 31.5k | dump_dwarf (abfd, is_mainfile); |
5894 | 31.5k | if (is_mainfile || process_links) |
5895 | 31.5k | { |
5896 | 31.5k | if (dump_ctf_section_info) |
5897 | 0 | dump_ctf (abfd, dump_ctf_section_name, dump_ctf_parent_name, |
5898 | 0 | dump_ctf_parent_section_name); |
5899 | 31.5k | if (dump_sframe_section_info) |
5900 | 0 | dump_sframe_section (abfd, dump_sframe_section_name); |
5901 | 31.5k | if (dump_stab_section_info) |
5902 | 31.5k | dump_stabs (abfd); |
5903 | 31.5k | if (dump_reloc_info && ! disassemble) |
5904 | 0 | dump_relocs (abfd); |
5905 | 31.5k | if (dump_dynamic_reloc_info && ! disassemble) |
5906 | 0 | dump_dynamic_relocs (abfd); |
5907 | 31.5k | if (dump_section_contents) |
5908 | 31.5k | dump_data (abfd); |
5909 | 31.5k | if (disassemble) |
5910 | 29.3k | disassemble_data (abfd); |
5911 | 31.5k | } |
5912 | | |
5913 | 31.5k | if (dump_debugging) |
5914 | 31.5k | { |
5915 | 31.5k | void *dhandle; |
5916 | | |
5917 | 31.5k | dhandle = read_debugging_info (abfd, syms, symcount, true); |
5918 | 31.5k | if (dhandle != NULL) |
5919 | 122 | { |
5920 | 122 | if (!print_debugging_info (stdout, dhandle, abfd, syms, |
5921 | 122 | bfd_demangle, |
5922 | 122 | dump_debugging_tags != 0)) |
5923 | 0 | { |
5924 | 0 | non_fatal (_("%s: printing debugging information failed"), |
5925 | 0 | bfd_get_filename (abfd)); |
5926 | 0 | exit_status = 1; |
5927 | 0 | } |
5928 | 122 | } |
5929 | | /* PR 6483: If there was no STABS debug info in the file, try |
5930 | | DWARF instead. */ |
5931 | 31.4k | else if (! dump_dwarf_section_info) |
5932 | 0 | { |
5933 | 0 | dwarf_select_sections_all (); |
5934 | 0 | dump_dwarf (abfd, is_mainfile); |
5935 | 0 | } |
5936 | 31.5k | } |
5937 | | |
5938 | 31.5k | if (syms) |
5939 | 1.49k | { |
5940 | 1.49k | free (syms); |
5941 | 1.49k | syms = NULL; |
5942 | 1.49k | } |
5943 | | |
5944 | 31.5k | if (dynsyms) |
5945 | 245 | { |
5946 | 245 | free (dynsyms); |
5947 | 245 | dynsyms = NULL; |
5948 | 245 | } |
5949 | | |
5950 | 31.5k | if (synthsyms) |
5951 | 262 | { |
5952 | 262 | free (synthsyms); |
5953 | 262 | synthsyms = NULL; |
5954 | 262 | } |
5955 | | |
5956 | 31.5k | symcount = 0; |
5957 | 31.5k | dynsymcount = 0; |
5958 | 31.5k | synthcount = 0; |
5959 | | |
5960 | 31.5k | if (is_mainfile) |
5961 | 31.5k | free_debug_memory (); |
5962 | 31.5k | } Line | Count | Source | 5758 | 31.5k | { | 5759 | 31.5k | elf_backend_data *bed; | 5760 | | | 5761 | 31.5k | if (bfd_big_endian (abfd)) | 5762 | 12.2k | byte_get = byte_get_big_endian; | 5763 | 19.3k | else if (bfd_little_endian (abfd)) | 5764 | 19.3k | byte_get = byte_get_little_endian; | 5765 | 33 | else | 5766 | 33 | byte_get = NULL; | 5767 | | | 5768 | | /* Load any separate debug information files. */ | 5769 | 31.5k | if (byte_get != NULL && might_need_separate_debug_info (is_mainfile)) | 5770 | 31.5k | { | 5771 | | /* Since it is possible that there are no separate debug files, | 5772 | | do not complain if calling load_separate_debug_files returns false. */ | 5773 | 31.5k | (void) load_separate_debug_files (abfd, bfd_get_filename (abfd)); | 5774 | | | 5775 | | /* If asked to do so, recursively dump the separate files. */ | 5776 | 31.5k | if (do_follow_links) | 5777 | 0 | { | 5778 | 0 | separate_info * i; | 5779 | |
| 5780 | 0 | for (i = first_separate_info; i != NULL; i = i->next) | 5781 | 0 | dump_bfd (i->handle, false); | 5782 | 0 | } | 5783 | 31.5k | } | 5784 | | | 5785 | | /* Adjust user-specified start and stop limits for targets that use | 5786 | | signed addresses. */ | 5787 | 31.5k | if (bfd_get_flavour (abfd) == bfd_target_elf_flavour | 5788 | 17.2k | && (bed = get_elf_backend_data (abfd)) != NULL | 5789 | 17.2k | && bed->sign_extend_vma) | 5790 | 615 | { | 5791 | 615 | start_address = sign_extend_address (abfd, start_address, | 5792 | 615 | bed->s->arch_size); | 5793 | 615 | stop_address = sign_extend_address (abfd, stop_address, | 5794 | 615 | bed->s->arch_size); | 5795 | 615 | } | 5796 | | | 5797 | | /* If we are adjusting section VMA's, change them all now. Changing | 5798 | | the BFD information is a hack. However, we must do it, or | 5799 | | bfd_find_nearest_line will not do the right thing. */ | 5800 | 31.5k | if (adjust_section_vma != 0) | 5801 | 0 | { | 5802 | 0 | bool has_reloc = (abfd->flags & HAS_RELOC); | 5803 | 0 | bfd_map_over_sections (abfd, adjust_addresses, &has_reloc); | 5804 | 0 | } | 5805 | | | 5806 | 31.5k | if (is_mainfile || process_links) | 5807 | 31.5k | { | 5808 | 31.5k | if (! dump_debugging_tags && ! suppress_bfd_header) | 5809 | 31.5k | printf (_("\n%s: file format %s\n"), | 5810 | 31.5k | sanitize_string (bfd_get_filename (abfd)), | 5811 | 31.5k | abfd->xvec->name); | 5812 | 31.5k | if (dump_ar_hdrs) | 5813 | 31.5k | print_arelt_descr (stdout, abfd, true, false); | 5814 | 31.5k | if (dump_file_header) | 5815 | 0 | dump_bfd_header (abfd); | 5816 | 31.5k | if (dump_private_headers) | 5817 | 31.5k | dump_bfd_private_header (abfd); | 5818 | 31.5k | if (dump_private_options != NULL) | 5819 | 0 | dump_target_specific (abfd); | 5820 | 31.5k | if (! dump_debugging_tags && ! suppress_bfd_header) | 5821 | 31.5k | putchar ('\n'); | 5822 | 31.5k | } | 5823 | | | 5824 | 31.5k | if (dump_symtab | 5825 | 31.5k | || dump_reloc_info | 5826 | 2.24k | || disassemble | 5827 | 2.24k | || dump_debugging | 5828 | 0 | || dump_dwarf_section_info) | 5829 | 31.5k | { | 5830 | 31.5k | syms = slurp_symtab (abfd); | 5831 | | | 5832 | | /* If following links, load any symbol tables from the linked files as well. */ | 5833 | 31.5k | if (do_follow_links && is_mainfile) | 5834 | 33 | { | 5835 | 33 | separate_info * i; | 5836 | | | 5837 | 33 | for (i = first_separate_info; i != NULL; i = i->next) | 5838 | 0 | { | 5839 | 0 | asymbol ** extra_syms; | 5840 | 0 | long old_symcount = symcount; | 5841 | |
| 5842 | 0 | extra_syms = slurp_symtab (i->handle); | 5843 | |
| 5844 | 0 | if (extra_syms) | 5845 | 0 | { | 5846 | 0 | if (old_symcount == 0) | 5847 | 0 | { | 5848 | 0 | free (syms); | 5849 | 0 | syms = extra_syms; | 5850 | 0 | } | 5851 | 0 | else | 5852 | 0 | { | 5853 | 0 | syms = xrealloc (syms, ((symcount + old_symcount + 1) | 5854 | 0 | * sizeof (asymbol *))); | 5855 | 0 | memcpy (syms + old_symcount, | 5856 | 0 | extra_syms, | 5857 | 0 | (symcount + 1) * sizeof (asymbol *)); | 5858 | 0 | free (extra_syms); | 5859 | 0 | } | 5860 | 0 | } | 5861 | |
| 5862 | 0 | symcount += old_symcount; | 5863 | 0 | } | 5864 | 33 | } | 5865 | 31.5k | } | 5866 | | | 5867 | 31.5k | if (is_mainfile || process_links) | 5868 | 31.5k | { | 5869 | 31.5k | if (dump_section_headers) | 5870 | 31.5k | dump_headers (abfd); | 5871 | | | 5872 | 31.5k | if (dump_dynamic_symtab || dump_dynamic_reloc_info | 5873 | 31.5k | || (disassemble && bfd_get_dynamic_symtab_upper_bound (abfd) > 0)) | 5874 | 306 | dynsyms = slurp_dynamic_symtab (abfd); | 5875 | | | 5876 | 31.5k | if (disassemble) | 5877 | 29.3k | { | 5878 | 29.3k | synthcount = bfd_get_synthetic_symtab (abfd, symcount, syms, | 5879 | 29.3k | dynsymcount, dynsyms, | 5880 | 29.3k | &synthsyms); | 5881 | 29.3k | if (synthcount < 0) | 5882 | 12.2k | synthcount = 0; | 5883 | 29.3k | } | 5884 | | | 5885 | 31.5k | if (dump_symtab) | 5886 | 0 | dump_symbols (abfd, false); | 5887 | 31.5k | if (dump_dynamic_symtab) | 5888 | 0 | dump_symbols (abfd, true); | 5889 | 31.5k | } | 5890 | 31.5k | if (dump_global_vars) | 5891 | 0 | dump_global_vars_info (abfd, is_mainfile); | 5892 | 31.5k | if (dump_dwarf_section_info) | 5893 | 31.5k | dump_dwarf (abfd, is_mainfile); | 5894 | 31.5k | if (is_mainfile || process_links) | 5895 | 31.5k | { | 5896 | 31.5k | if (dump_ctf_section_info) | 5897 | 0 | dump_ctf (abfd, dump_ctf_section_name, dump_ctf_parent_name, | 5898 | 0 | dump_ctf_parent_section_name); | 5899 | 31.5k | if (dump_sframe_section_info) | 5900 | 0 | dump_sframe_section (abfd, dump_sframe_section_name); | 5901 | 31.5k | if (dump_stab_section_info) | 5902 | 31.5k | dump_stabs (abfd); | 5903 | 31.5k | if (dump_reloc_info && ! disassemble) | 5904 | 0 | dump_relocs (abfd); | 5905 | 31.5k | if (dump_dynamic_reloc_info && ! disassemble) | 5906 | 0 | dump_dynamic_relocs (abfd); | 5907 | 31.5k | if (dump_section_contents) | 5908 | 31.5k | dump_data (abfd); | 5909 | 31.5k | if (disassemble) | 5910 | 29.3k | disassemble_data (abfd); | 5911 | 31.5k | } | 5912 | | | 5913 | 31.5k | if (dump_debugging) | 5914 | 31.5k | { | 5915 | 31.5k | void *dhandle; | 5916 | | | 5917 | 31.5k | dhandle = read_debugging_info (abfd, syms, symcount, true); | 5918 | 31.5k | if (dhandle != NULL) | 5919 | 122 | { | 5920 | 122 | if (!print_debugging_info (stdout, dhandle, abfd, syms, | 5921 | 122 | bfd_demangle, | 5922 | 122 | dump_debugging_tags != 0)) | 5923 | 0 | { | 5924 | 0 | non_fatal (_("%s: printing debugging information failed"), | 5925 | 0 | bfd_get_filename (abfd)); | 5926 | 0 | exit_status = 1; | 5927 | 0 | } | 5928 | 122 | } | 5929 | | /* PR 6483: If there was no STABS debug info in the file, try | 5930 | | DWARF instead. */ | 5931 | 31.4k | else if (! dump_dwarf_section_info) | 5932 | 0 | { | 5933 | 0 | dwarf_select_sections_all (); | 5934 | 0 | dump_dwarf (abfd, is_mainfile); | 5935 | 0 | } | 5936 | 31.5k | } | 5937 | | | 5938 | 31.5k | if (syms) | 5939 | 1.49k | { | 5940 | 1.49k | free (syms); | 5941 | 1.49k | syms = NULL; | 5942 | 1.49k | } | 5943 | | | 5944 | 31.5k | if (dynsyms) | 5945 | 245 | { | 5946 | 245 | free (dynsyms); | 5947 | 245 | dynsyms = NULL; | 5948 | 245 | } | 5949 | | | 5950 | 31.5k | if (synthsyms) | 5951 | 262 | { | 5952 | 262 | free (synthsyms); | 5953 | 262 | synthsyms = NULL; | 5954 | 262 | } | 5955 | | | 5956 | 31.5k | symcount = 0; | 5957 | 31.5k | dynsymcount = 0; | 5958 | 31.5k | synthcount = 0; | 5959 | | | 5960 | 31.5k | if (is_mainfile) | 5961 | 31.5k | free_debug_memory (); | 5962 | 31.5k | } |
Unexecuted instantiation: fuzz_dwarf.c:dump_bfd |
5963 | | |
5964 | | static void |
5965 | | display_object_bfd (bfd *abfd) |
5966 | 38.5k | { |
5967 | 38.5k | char **matching; |
5968 | | |
5969 | 38.5k | if (bfd_check_format_matches (abfd, bfd_object, &matching)) |
5970 | 20.0k | { |
5971 | 20.0k | dump_bfd (abfd, true); |
5972 | 20.0k | return; |
5973 | 20.0k | } |
5974 | | |
5975 | 18.5k | if (bfd_get_error () == bfd_error_file_ambiguously_recognized) |
5976 | 456 | { |
5977 | 456 | my_bfd_nonfatal (bfd_get_filename (abfd)); |
5978 | 456 | list_matching_formats (matching); |
5979 | 456 | return; |
5980 | 456 | } |
5981 | | |
5982 | 18.0k | if (bfd_get_error () != bfd_error_file_not_recognized) |
5983 | 1.66k | { |
5984 | 1.66k | my_bfd_nonfatal (bfd_get_filename (abfd)); |
5985 | 1.66k | return; |
5986 | 1.66k | } |
5987 | | |
5988 | 16.3k | if (bfd_check_format_matches (abfd, bfd_core, &matching)) |
5989 | 11.4k | { |
5990 | 11.4k | dump_bfd (abfd, true); |
5991 | 11.4k | return; |
5992 | 11.4k | } |
5993 | | |
5994 | 4.88k | my_bfd_nonfatal (bfd_get_filename (abfd)); |
5995 | | |
5996 | 4.88k | if (bfd_get_error () == bfd_error_file_ambiguously_recognized) |
5997 | 0 | list_matching_formats (matching); |
5998 | 4.88k | } fuzz_objdump.c:display_object_bfd Line | Count | Source | 5966 | 38.5k | { | 5967 | 38.5k | char **matching; | 5968 | | | 5969 | 38.5k | if (bfd_check_format_matches (abfd, bfd_object, &matching)) | 5970 | 20.0k | { | 5971 | 20.0k | dump_bfd (abfd, true); | 5972 | 20.0k | return; | 5973 | 20.0k | } | 5974 | | | 5975 | 18.5k | if (bfd_get_error () == bfd_error_file_ambiguously_recognized) | 5976 | 456 | { | 5977 | 456 | my_bfd_nonfatal (bfd_get_filename (abfd)); | 5978 | 456 | list_matching_formats (matching); | 5979 | 456 | return; | 5980 | 456 | } | 5981 | | | 5982 | 18.0k | if (bfd_get_error () != bfd_error_file_not_recognized) | 5983 | 1.66k | { | 5984 | 1.66k | my_bfd_nonfatal (bfd_get_filename (abfd)); | 5985 | 1.66k | return; | 5986 | 1.66k | } | 5987 | | | 5988 | 16.3k | if (bfd_check_format_matches (abfd, bfd_core, &matching)) | 5989 | 11.4k | { | 5990 | 11.4k | dump_bfd (abfd, true); | 5991 | 11.4k | return; | 5992 | 11.4k | } | 5993 | | | 5994 | 4.88k | my_bfd_nonfatal (bfd_get_filename (abfd)); | 5995 | | | 5996 | 4.88k | if (bfd_get_error () == bfd_error_file_ambiguously_recognized) | 5997 | 0 | list_matching_formats (matching); | 5998 | 4.88k | } |
Unexecuted instantiation: fuzz_dwarf.c:display_object_bfd |
5999 | | |
6000 | | static void |
6001 | | display_any_bfd (bfd *file, int level) |
6002 | 39.5k | { |
6003 | | /* Decompress sections unless dumping the section contents. */ |
6004 | 39.5k | if (!dump_section_contents || decompressed_dumps) |
6005 | 0 | file->flags |= BFD_DECOMPRESS; |
6006 | | |
6007 | | /* If the file is an archive, process all of its elements. */ |
6008 | 39.5k | if (bfd_check_format (file, bfd_archive)) |
6009 | 941 | { |
6010 | 941 | if (level == 0) |
6011 | 717 | printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file))); |
6012 | 224 | else if (level > 100) |
6013 | 0 | { |
6014 | | /* Prevent corrupted files from spinning us into an |
6015 | | infinite loop. 100 is an arbitrary heuristic. */ |
6016 | 0 | non_fatal (_("Archive nesting is too deep")); |
6017 | 0 | exit_status = 1; |
6018 | 0 | return; |
6019 | 0 | } |
6020 | 224 | else |
6021 | 224 | printf (_("In nested archive %s:\n"), |
6022 | 224 | sanitize_string (bfd_get_filename (file))); |
6023 | | |
6024 | 941 | bfd *last_arfile = NULL; |
6025 | 941 | for (;;) |
6026 | 6.95k | { |
6027 | 6.95k | bfd *arfile = bfd_openr_next_archived_file (file, last_arfile); |
6028 | 6.95k | if (arfile == NULL |
6029 | 6.01k | || arfile == last_arfile) |
6030 | 941 | { |
6031 | 941 | if (arfile != NULL) |
6032 | 0 | bfd_set_error (bfd_error_malformed_archive); |
6033 | 941 | if (bfd_get_error () != bfd_error_no_more_archived_files) |
6034 | 372 | my_bfd_nonfatal (bfd_get_filename (file)); |
6035 | 941 | break; |
6036 | 941 | } |
6037 | | |
6038 | 6.01k | if (last_arfile != NULL) |
6039 | 5.11k | bfd_close (last_arfile); |
6040 | | |
6041 | 6.01k | display_any_bfd (arfile, level + 1); |
6042 | | |
6043 | 6.01k | last_arfile = arfile; |
6044 | 6.01k | } |
6045 | | |
6046 | 941 | if (last_arfile != NULL) |
6047 | 893 | bfd_close (last_arfile); |
6048 | 941 | } |
6049 | 38.5k | else |
6050 | 38.5k | display_object_bfd (file); |
6051 | 39.5k | } fuzz_objdump.c:display_any_bfd Line | Count | Source | 6002 | 39.5k | { | 6003 | | /* Decompress sections unless dumping the section contents. */ | 6004 | 39.5k | if (!dump_section_contents || decompressed_dumps) | 6005 | 0 | file->flags |= BFD_DECOMPRESS; | 6006 | | | 6007 | | /* If the file is an archive, process all of its elements. */ | 6008 | 39.5k | if (bfd_check_format (file, bfd_archive)) | 6009 | 941 | { | 6010 | 941 | if (level == 0) | 6011 | 717 | printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file))); | 6012 | 224 | else if (level > 100) | 6013 | 0 | { | 6014 | | /* Prevent corrupted files from spinning us into an | 6015 | | infinite loop. 100 is an arbitrary heuristic. */ | 6016 | 0 | non_fatal (_("Archive nesting is too deep")); | 6017 | 0 | exit_status = 1; | 6018 | 0 | return; | 6019 | 0 | } | 6020 | 224 | else | 6021 | 224 | printf (_("In nested archive %s:\n"), | 6022 | 224 | sanitize_string (bfd_get_filename (file))); | 6023 | | | 6024 | 941 | bfd *last_arfile = NULL; | 6025 | 941 | for (;;) | 6026 | 6.95k | { | 6027 | 6.95k | bfd *arfile = bfd_openr_next_archived_file (file, last_arfile); | 6028 | 6.95k | if (arfile == NULL | 6029 | 6.01k | || arfile == last_arfile) | 6030 | 941 | { | 6031 | 941 | if (arfile != NULL) | 6032 | 0 | bfd_set_error (bfd_error_malformed_archive); | 6033 | 941 | if (bfd_get_error () != bfd_error_no_more_archived_files) | 6034 | 372 | my_bfd_nonfatal (bfd_get_filename (file)); | 6035 | 941 | break; | 6036 | 941 | } | 6037 | | | 6038 | 6.01k | if (last_arfile != NULL) | 6039 | 5.11k | bfd_close (last_arfile); | 6040 | | | 6041 | 6.01k | display_any_bfd (arfile, level + 1); | 6042 | | | 6043 | 6.01k | last_arfile = arfile; | 6044 | 6.01k | } | 6045 | | | 6046 | 941 | if (last_arfile != NULL) | 6047 | 893 | bfd_close (last_arfile); | 6048 | 941 | } | 6049 | 38.5k | else | 6050 | 38.5k | display_object_bfd (file); | 6051 | 39.5k | } |
Unexecuted instantiation: fuzz_dwarf.c:display_any_bfd |
6052 | | |
6053 | | static void |
6054 | | display_file (char *filename, char *target) |
6055 | 33.5k | { |
6056 | 33.5k | bfd *file; |
6057 | | |
6058 | 33.5k | if (get_file_size (filename) < 1) |
6059 | 0 | { |
6060 | 0 | exit_status = 1; |
6061 | 0 | return; |
6062 | 0 | } |
6063 | | |
6064 | 33.5k | file = bfd_openr (filename, target); |
6065 | 33.5k | if (file == NULL) |
6066 | 0 | { |
6067 | 0 | my_bfd_nonfatal (filename); |
6068 | 0 | return; |
6069 | 0 | } |
6070 | | |
6071 | 33.5k | display_any_bfd (file, 0); |
6072 | | |
6073 | 33.5k | bfd_close (file); |
6074 | 33.5k | } Unexecuted instantiation: fuzz_dwarf.c:display_file |
6075 | | |
6076 | | int |
6077 | | old_main32 (int argc, char **argv); |
6078 | | int old_main32 (int argc, char **argv) |
6079 | 0 | { |
6080 | 0 | int c; |
6081 | 0 | char *target = default_target; |
6082 | 0 | bool seenflag = false; |
6083 | |
|
6084 | 0 | #ifdef HAVE_LC_MESSAGES |
6085 | 0 | setlocale (LC_MESSAGES, ""); |
6086 | 0 | #endif |
6087 | 0 | setlocale (LC_CTYPE, ""); |
6088 | |
|
6089 | 0 | bindtextdomain (PACKAGE, LOCALEDIR); |
6090 | 0 | textdomain (PACKAGE); |
6091 | |
|
6092 | 0 | program_name = *argv; |
6093 | 0 | xmalloc_set_program_name (program_name); |
6094 | 0 | bfd_set_error_program_name (program_name); |
6095 | |
|
6096 | 0 | expandargv (&argc, &argv); |
6097 | |
|
6098 | 0 | if (bfd_init () != BFD_INIT_MAGIC) |
6099 | 0 | fatal (_("fatal error: libbfd ABI mismatch")); |
6100 | 0 | set_default_bfd_target (); |
6101 | |
|
6102 | 0 | while ((c = getopt_long (argc, argv, |
6103 | 0 | "CDE:FGHI:LM:P:RSTU:VW::Zab:defghij:lm:prstvwxz", |
6104 | 0 | long_options, (int *) 0)) |
6105 | 0 | != EOF) |
6106 | 0 | { |
6107 | 0 | switch (c) |
6108 | 0 | { |
6109 | 0 | case 0: |
6110 | 0 | break; /* We've been given a long option. */ |
6111 | 0 | case 'm': |
6112 | 0 | machine = optarg; |
6113 | 0 | break; |
6114 | 0 | case 'Z': |
6115 | 0 | decompressed_dumps = true; |
6116 | 0 | break; |
6117 | 0 | case 'M': |
6118 | 0 | { |
6119 | 0 | char *options; |
6120 | 0 | if (disassembler_options) |
6121 | 0 | options = concat (disassembler_options, ",", |
6122 | 0 | optarg, (const char *) NULL); |
6123 | 0 | else |
6124 | 0 | options = xstrdup (optarg); |
6125 | 0 | free (disassembler_options); |
6126 | 0 | disassembler_options = remove_whitespace_and_extra_commas (options); |
6127 | 0 | if (!disassembler_options) |
6128 | 0 | free (options); |
6129 | 0 | } |
6130 | 0 | break; |
6131 | 0 | case 'j': |
6132 | 0 | add_only (optarg); |
6133 | 0 | break; |
6134 | 0 | case 'F': |
6135 | 0 | display_file_offsets = true; |
6136 | 0 | break; |
6137 | 0 | case 'l': |
6138 | 0 | with_line_numbers = true; |
6139 | 0 | break; |
6140 | 0 | case 'b': |
6141 | 0 | target = optarg; |
6142 | 0 | break; |
6143 | 0 | case 'C': |
6144 | 0 | do_demangle = true; |
6145 | 0 | if (optarg != NULL) |
6146 | 0 | { |
6147 | 0 | enum demangling_styles style; |
6148 | |
|
6149 | 0 | style = cplus_demangle_name_to_style (optarg); |
6150 | 0 | if (style == unknown_demangling) |
6151 | 0 | fatal (_("unknown demangling style `%s'"), |
6152 | 0 | optarg); |
6153 | | |
6154 | 0 | cplus_demangle_set_style (style); |
6155 | 0 | } |
6156 | 0 | break; |
6157 | 0 | case OPTION_RECURSE_LIMIT: |
6158 | 0 | demangle_flags &= ~ DMGL_NO_RECURSE_LIMIT; |
6159 | 0 | break; |
6160 | 0 | case OPTION_NO_RECURSE_LIMIT: |
6161 | 0 | demangle_flags |= DMGL_NO_RECURSE_LIMIT; |
6162 | 0 | break; |
6163 | 0 | case 'w': |
6164 | 0 | do_wide = wide_output = true; |
6165 | 0 | break; |
6166 | 0 | case OPTION_ADJUST_VMA: |
6167 | 0 | adjust_section_vma = parse_vma (optarg, "--adjust-vma"); |
6168 | 0 | break; |
6169 | 0 | case OPTION_START_ADDRESS: |
6170 | 0 | start_address = parse_vma (optarg, "--start-address"); |
6171 | 0 | if ((stop_address != (bfd_vma) -1) && stop_address <= start_address) |
6172 | 0 | fatal (_("error: the start address should be before the end address")); |
6173 | 0 | break; |
6174 | 0 | case OPTION_STOP_ADDRESS: |
6175 | 0 | stop_address = parse_vma (optarg, "--stop-address"); |
6176 | 0 | if ((start_address != (bfd_vma) -1) && stop_address <= start_address) |
6177 | 0 | fatal (_("error: the stop address should be after the start address")); |
6178 | 0 | break; |
6179 | 0 | case OPTION_PREFIX: |
6180 | 0 | prefix = optarg; |
6181 | 0 | prefix_length = strlen (prefix); |
6182 | | /* Remove an unnecessary trailing '/' */ |
6183 | 0 | while (IS_DIR_SEPARATOR (prefix[prefix_length - 1])) |
6184 | 0 | prefix_length--; |
6185 | 0 | break; |
6186 | 0 | case OPTION_PREFIX_STRIP: |
6187 | 0 | prefix_strip = atoi (optarg); |
6188 | 0 | if (prefix_strip < 0) |
6189 | 0 | fatal (_("error: prefix strip must be non-negative")); |
6190 | 0 | break; |
6191 | 0 | case OPTION_INSN_WIDTH: |
6192 | 0 | insn_width = strtoul (optarg, NULL, 0); |
6193 | 0 | if (insn_width - 1 >= MAX_INSN_WIDTH) |
6194 | 0 | fatal (_("error: instruction width must be in the range 1 to " |
6195 | 0 | XSTRING (MAX_INSN_WIDTH))); |
6196 | 0 | break; |
6197 | 0 | case OPTION_INLINES: |
6198 | 0 | unwind_inlines = true; |
6199 | 0 | break; |
6200 | 0 | case OPTION_VISUALIZE_JUMPS: |
6201 | 0 | visualize_jumps = true; |
6202 | 0 | color_output = false; |
6203 | 0 | extended_color_output = false; |
6204 | 0 | if (optarg != NULL) |
6205 | 0 | { |
6206 | 0 | if (streq (optarg, "color")) |
6207 | 0 | color_output = true; |
6208 | 0 | else if (streq (optarg, "extended-color")) |
6209 | 0 | { |
6210 | 0 | color_output = true; |
6211 | 0 | extended_color_output = true; |
6212 | 0 | } |
6213 | 0 | else if (streq (optarg, "off")) |
6214 | 0 | visualize_jumps = false; |
6215 | 0 | else |
6216 | 0 | { |
6217 | 0 | non_fatal (_("unrecognized argument to --visualize-option")); |
6218 | 0 | usage (stderr, 1); |
6219 | 0 | } |
6220 | 0 | } |
6221 | 0 | break; |
6222 | 0 | case OPTION_DISASSEMBLER_COLOR: |
6223 | 0 | if (streq (optarg, "off")) |
6224 | 0 | disassembler_color = off; |
6225 | 0 | else if (streq (optarg, "terminal")) |
6226 | 0 | disassembler_color = on_if_terminal_output; |
6227 | 0 | else if (streq (optarg, "color") |
6228 | 0 | || streq (optarg, "colour") |
6229 | 0 | || streq (optarg, "on")) |
6230 | 0 | disassembler_color = on; |
6231 | 0 | else if (streq (optarg, "extended") |
6232 | 0 | || streq (optarg, "extended-color") |
6233 | 0 | || streq (optarg, "extended-colour")) |
6234 | 0 | disassembler_color = extended; |
6235 | 0 | else |
6236 | 0 | { |
6237 | 0 | non_fatal (_("unrecognized argument to --disassembler-color")); |
6238 | 0 | usage (stderr, 1); |
6239 | 0 | } |
6240 | 0 | break; |
6241 | 0 | case 'E': |
6242 | 0 | if (strcmp (optarg, "B") == 0) |
6243 | 0 | endian = BFD_ENDIAN_BIG; |
6244 | 0 | else if (strcmp (optarg, "L") == 0) |
6245 | 0 | endian = BFD_ENDIAN_LITTLE; |
6246 | 0 | else |
6247 | 0 | { |
6248 | 0 | non_fatal (_("unrecognized -E option")); |
6249 | 0 | usage (stderr, 1); |
6250 | 0 | } |
6251 | 0 | break; |
6252 | 0 | case OPTION_ENDIAN: |
6253 | 0 | if (strncmp (optarg, "big", strlen (optarg)) == 0) |
6254 | 0 | endian = BFD_ENDIAN_BIG; |
6255 | 0 | else if (strncmp (optarg, "little", strlen (optarg)) == 0) |
6256 | 0 | endian = BFD_ENDIAN_LITTLE; |
6257 | 0 | else |
6258 | 0 | { |
6259 | 0 | non_fatal (_("unrecognized --endian type `%s'"), optarg); |
6260 | 0 | usage (stderr, 1); |
6261 | 0 | } |
6262 | 0 | break; |
6263 | | |
6264 | 0 | case 'f': |
6265 | 0 | dump_file_header = true; |
6266 | 0 | seenflag = true; |
6267 | 0 | break; |
6268 | 0 | case 'i': |
6269 | 0 | formats_info = true; |
6270 | 0 | seenflag = true; |
6271 | 0 | break; |
6272 | 0 | case 'I': |
6273 | 0 | add_include_path (optarg); |
6274 | 0 | break; |
6275 | 0 | case 'p': |
6276 | 0 | dump_private_headers = true; |
6277 | 0 | seenflag = true; |
6278 | 0 | break; |
6279 | 0 | case 'P': |
6280 | 0 | dump_private_options = optarg; |
6281 | 0 | seenflag = true; |
6282 | 0 | break; |
6283 | 0 | case 'x': |
6284 | 0 | dump_private_headers = true; |
6285 | 0 | dump_symtab = true; |
6286 | 0 | dump_reloc_info = true; |
6287 | 0 | dump_file_header = true; |
6288 | 0 | dump_ar_hdrs = true; |
6289 | 0 | dump_section_headers = true; |
6290 | 0 | seenflag = true; |
6291 | 0 | break; |
6292 | 0 | case 't': |
6293 | 0 | dump_symtab = true; |
6294 | 0 | seenflag = true; |
6295 | 0 | break; |
6296 | 0 | case 'T': |
6297 | 0 | dump_dynamic_symtab = true; |
6298 | 0 | seenflag = true; |
6299 | 0 | break; |
6300 | 0 | case 'd': |
6301 | 0 | disassemble = true; |
6302 | 0 | seenflag = true; |
6303 | 0 | if (optarg) |
6304 | 0 | { |
6305 | 0 | struct symbol_entry *sym = xmalloc (sizeof (*sym)); |
6306 | |
|
6307 | 0 | sym->name = optarg; |
6308 | 0 | sym->next = disasm_sym_list; |
6309 | 0 | disasm_sym_list = sym; |
6310 | 0 | } |
6311 | 0 | break; |
6312 | 0 | case 'z': |
6313 | 0 | disassemble_zeroes = true; |
6314 | 0 | break; |
6315 | 0 | case 'D': |
6316 | 0 | disassemble = true; |
6317 | 0 | disassemble_all = true; |
6318 | 0 | seenflag = true; |
6319 | 0 | break; |
6320 | 0 | case 'S': |
6321 | 0 | disassemble = true; |
6322 | 0 | with_source_code = true; |
6323 | 0 | seenflag = true; |
6324 | 0 | break; |
6325 | 0 | case OPTION_SOURCE_COMMENT: |
6326 | 0 | disassemble = true; |
6327 | 0 | with_source_code = true; |
6328 | 0 | seenflag = true; |
6329 | 0 | if (optarg) |
6330 | 0 | source_comment = xstrdup (sanitize_string (optarg)); |
6331 | 0 | else |
6332 | 0 | source_comment = xstrdup ("# "); |
6333 | 0 | break; |
6334 | 0 | case 'g': |
6335 | 0 | dump_debugging = 1; |
6336 | 0 | seenflag = true; |
6337 | 0 | break; |
6338 | 0 | case 'e': |
6339 | 0 | dump_debugging = 1; |
6340 | 0 | dump_debugging_tags = 1; |
6341 | 0 | do_demangle = true; |
6342 | 0 | seenflag = true; |
6343 | 0 | break; |
6344 | 0 | case 'L': |
6345 | 0 | process_links = true; |
6346 | 0 | do_follow_links = true; |
6347 | 0 | break; |
6348 | 0 | case OPTION_MAP_GLOBAL_VARS: |
6349 | 0 | dump_global_vars = true; |
6350 | 0 | dwarf_select_sections_all (); |
6351 | 0 | seenflag = true; |
6352 | 0 | break; |
6353 | 0 | case 'W': |
6354 | 0 | seenflag = true; |
6355 | 0 | if (optarg) |
6356 | 0 | { |
6357 | 0 | if (dwarf_select_sections_by_letters (optarg)) |
6358 | 0 | dump_dwarf_section_info = true; |
6359 | 0 | } |
6360 | 0 | else |
6361 | 0 | { |
6362 | 0 | dump_dwarf_section_info = true; |
6363 | 0 | dwarf_select_sections_all (); |
6364 | 0 | } |
6365 | 0 | break; |
6366 | 0 | case OPTION_DWARF: |
6367 | 0 | seenflag = true; |
6368 | 0 | if (optarg) |
6369 | 0 | { |
6370 | 0 | if (dwarf_select_sections_by_names (optarg)) |
6371 | 0 | dump_dwarf_section_info = true; |
6372 | 0 | } |
6373 | 0 | else |
6374 | 0 | { |
6375 | 0 | dwarf_select_sections_all (); |
6376 | 0 | dump_dwarf_section_info = true; |
6377 | 0 | } |
6378 | 0 | break; |
6379 | 0 | case OPTION_DWARF_DEPTH: |
6380 | 0 | { |
6381 | 0 | char *cp; |
6382 | 0 | dwarf_cutoff_level = strtoul (optarg, & cp, 0); |
6383 | 0 | } |
6384 | 0 | break; |
6385 | 0 | case OPTION_DWARF_START: |
6386 | 0 | { |
6387 | 0 | char *cp; |
6388 | 0 | dwarf_start_die = strtoul (optarg, & cp, 0); |
6389 | 0 | suppress_bfd_header = 1; |
6390 | 0 | } |
6391 | 0 | break; |
6392 | 0 | case OPTION_DWARF_CHECK: |
6393 | 0 | dwarf_check = true; |
6394 | 0 | break; |
6395 | 0 | case OPTION_DEBUG_DIR: |
6396 | 0 | separate_debug_info_dir = optarg; |
6397 | 0 | break; |
6398 | 0 | #ifdef ENABLE_LIBCTF |
6399 | 0 | case OPTION_CTF: |
6400 | 0 | dump_ctf_section_info = true; |
6401 | 0 | if (optarg) |
6402 | 0 | dump_ctf_section_name = xstrdup (optarg); |
6403 | 0 | seenflag = true; |
6404 | 0 | break; |
6405 | 0 | case OPTION_CTF_PARENT: |
6406 | 0 | dump_ctf_parent_name = xstrdup (optarg); |
6407 | 0 | break; |
6408 | 0 | case OPTION_CTF_PARENT_SECTION: |
6409 | 0 | dump_ctf_parent_section_name = xstrdup (optarg); |
6410 | 0 | break; |
6411 | 0 | #endif |
6412 | 0 | case OPTION_SFRAME: |
6413 | 0 | dump_sframe_section_info = true; |
6414 | |
|
6415 | 0 | if (optarg) |
6416 | 0 | dump_sframe_section_name = xstrdup (optarg); |
6417 | 0 | else |
6418 | 0 | dump_sframe_section_name = xstrdup (".sframe"); |
6419 | |
|
6420 | 0 | seenflag = true; |
6421 | 0 | break; |
6422 | 0 | case 'G': |
6423 | 0 | dump_stab_section_info = true; |
6424 | 0 | seenflag = true; |
6425 | 0 | break; |
6426 | 0 | case 's': |
6427 | 0 | dump_section_contents = true; |
6428 | 0 | seenflag = true; |
6429 | 0 | break; |
6430 | 0 | case 'r': |
6431 | 0 | dump_reloc_info = true; |
6432 | 0 | seenflag = true; |
6433 | 0 | break; |
6434 | 0 | case 'R': |
6435 | 0 | dump_dynamic_reloc_info = true; |
6436 | 0 | seenflag = true; |
6437 | 0 | break; |
6438 | 0 | case 'a': |
6439 | 0 | dump_ar_hdrs = true; |
6440 | 0 | seenflag = true; |
6441 | 0 | break; |
6442 | 0 | case 'h': |
6443 | 0 | dump_section_headers = true; |
6444 | 0 | seenflag = true; |
6445 | 0 | break; |
6446 | 0 | case 'v': |
6447 | 0 | case 'V': |
6448 | 0 | show_version = true; |
6449 | 0 | seenflag = true; |
6450 | 0 | break; |
6451 | | |
6452 | 0 | case 'U': |
6453 | 0 | if (streq (optarg, "default") || streq (optarg, "d")) |
6454 | 0 | unicode_display = unicode_default; |
6455 | 0 | else if (streq (optarg, "locale") || streq (optarg, "l")) |
6456 | 0 | unicode_display = unicode_locale; |
6457 | 0 | else if (streq (optarg, "escape") || streq (optarg, "e")) |
6458 | 0 | unicode_display = unicode_escape; |
6459 | 0 | else if (streq (optarg, "invalid") || streq (optarg, "i")) |
6460 | 0 | unicode_display = unicode_invalid; |
6461 | 0 | else if (streq (optarg, "hex") || streq (optarg, "x")) |
6462 | 0 | unicode_display = unicode_hex; |
6463 | 0 | else if (streq (optarg, "highlight") || streq (optarg, "h")) |
6464 | 0 | unicode_display = unicode_highlight; |
6465 | 0 | else |
6466 | 0 | fatal (_("invalid argument to -U/--unicode: %s"), optarg); |
6467 | 0 | break; |
6468 | | |
6469 | 0 | case 'H': |
6470 | 0 | usage (stdout, 0); |
6471 | | /* No need to set seenflag or to break - usage() does not return. */ |
6472 | 0 | default: |
6473 | 0 | usage (stderr, 1); |
6474 | 0 | } |
6475 | 0 | } |
6476 | | |
6477 | 0 | if (disassembler_color == on_if_terminal_output) |
6478 | 0 | disassembler_color = isatty (1) ? on : off; |
6479 | |
|
6480 | 0 | if (show_version) |
6481 | 0 | print_version ("objdump"); |
6482 | |
|
6483 | 0 | if (!seenflag) |
6484 | 0 | usage (stderr, 2); |
6485 | | |
6486 | 0 | if (formats_info) |
6487 | 0 | exit_status = display_info (); |
6488 | 0 | else |
6489 | 0 | { |
6490 | 0 | if (optind == argc) |
6491 | 0 | display_file ("a.out", target); |
6492 | 0 | else |
6493 | 0 | for (; optind < argc;) |
6494 | 0 | { |
6495 | 0 | display_file (argv[optind], target); |
6496 | 0 | optind++; |
6497 | 0 | } |
6498 | 0 | } |
6499 | |
|
6500 | 0 | free_only_list (); |
6501 | 0 | free (dump_ctf_section_name); |
6502 | 0 | free (dump_ctf_parent_name); |
6503 | 0 | free ((void *) source_comment); |
6504 | 0 | free (dump_ctf_parent_section_name); |
6505 | 0 | free (dump_sframe_section_name); |
6506 | |
|
6507 | 0 | return exit_status; |
6508 | 0 | } |