/src/binutils-gdb/binutils/dwarf.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* dwarf.c -- display DWARF contents of a BFD binary file |
2 | | Copyright (C) 2005-2025 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 of the License, or |
9 | | (at your option) 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, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
19 | | 02110-1301, USA. */ |
20 | | |
21 | | #include "sysdep.h" |
22 | | #include "libiberty.h" |
23 | | #include "bfd.h" |
24 | | #include <stdint.h> |
25 | | #include "bucomm.h" |
26 | | #include "elfcomm.h" |
27 | | #include "elf/common.h" |
28 | | #include "dwarf2.h" |
29 | | #include "dwarf.h" |
30 | | #include "gdb/gdb-index.h" |
31 | | #include "filenames.h" |
32 | | #include "safe-ctype.h" |
33 | | #include "sframe-api.h" |
34 | | #include <assert.h> |
35 | | |
36 | | #ifdef HAVE_LIBDEBUGINFOD |
37 | | #include <elfutils/debuginfod.h> |
38 | | #endif |
39 | | |
40 | | #include <limits.h> |
41 | | #ifndef CHAR_BIT |
42 | | #define CHAR_BIT 8 |
43 | | #endif |
44 | | |
45 | | #ifndef ENABLE_CHECKING |
46 | | #define ENABLE_CHECKING 0 |
47 | | #endif |
48 | | |
49 | | #undef MAX |
50 | | #undef MIN |
51 | 0 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
52 | | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
53 | | |
54 | | static const char *regname (unsigned int regno, int row); |
55 | | static const char *regname_internal_by_table_only (unsigned int regno); |
56 | | |
57 | | static int have_frame_base; |
58 | | static int frame_base_level = -1; /* To support nested DW_TAG_subprogram's. */ |
59 | | static int need_base_address; |
60 | | |
61 | | static unsigned int num_debug_info_entries = 0; |
62 | | static unsigned int alloc_num_debug_info_entries = 0; |
63 | | static debug_info *debug_information = NULL; |
64 | | /* Special value for num_debug_info_entries to indicate |
65 | | that the .debug_info section could not be loaded/parsed. */ |
66 | 51.1k | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 |
67 | | |
68 | | /* A .debug_info section can contain multiple links to separate |
69 | | DWO object files. We use these structures to record these links. */ |
70 | | typedef enum dwo_type |
71 | | { |
72 | | DWO_NAME, |
73 | | DWO_DIR, |
74 | | DWO_ID |
75 | | } dwo_type; |
76 | | |
77 | | typedef struct dwo_info |
78 | | { |
79 | | dwo_type type; |
80 | | const char * value; |
81 | | uint64_t cu_offset; |
82 | | struct dwo_info * next; |
83 | | } dwo_info; |
84 | | |
85 | | static dwo_info *first_dwo_info = NULL; |
86 | | static bool need_dwo_info; |
87 | | |
88 | | separate_info * first_separate_info = NULL; |
89 | | |
90 | | unsigned int eh_addr_size; |
91 | | |
92 | | int do_debug_info; |
93 | | int do_debug_abbrevs; |
94 | | int do_debug_lines; |
95 | | int do_debug_pubnames; |
96 | | int do_debug_pubtypes; |
97 | | int do_debug_aranges; |
98 | | int do_debug_ranges; |
99 | | int do_debug_frames; |
100 | | int do_debug_frames_interp; |
101 | | int do_debug_macinfo; |
102 | | int do_debug_str; |
103 | | int do_debug_str_offsets; |
104 | | int do_debug_loc; |
105 | | int do_gdb_index; |
106 | | int do_sframe; |
107 | | int do_trace_info; |
108 | | int do_trace_abbrevs; |
109 | | int do_trace_aranges; |
110 | | int do_debug_addr; |
111 | | int do_debug_cu_index; |
112 | | int do_wide; |
113 | | int do_debug_links; |
114 | | int do_follow_links = DEFAULT_FOR_FOLLOW_LINKS; |
115 | | #ifdef HAVE_LIBDEBUGINFOD |
116 | | int use_debuginfod = 1; |
117 | | #endif |
118 | | bool do_checks; |
119 | | |
120 | | int dwarf_cutoff_level = -1; |
121 | | unsigned long dwarf_start_die; |
122 | | |
123 | | int dwarf_check = 0; |
124 | | |
125 | | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
126 | | sections. For version 1 package files, each set is stored in SHNDX_POOL |
127 | | as a zero-terminated list of section indexes comprising one set of debug |
128 | | sections from a .dwo file. */ |
129 | | |
130 | | static unsigned int *shndx_pool = NULL; |
131 | | static unsigned int shndx_pool_size = 0; |
132 | | static unsigned int shndx_pool_used = 0; |
133 | | |
134 | | /* For version 2 package files, each set contains an array of section offsets |
135 | | and an array of section sizes, giving the offset and size of the |
136 | | contribution from a CU or TU within one of the debug sections. |
137 | | When displaying debug info from a package file, we need to use these |
138 | | tables to locate the corresponding contributions to each section. */ |
139 | | |
140 | | struct cu_tu_set |
141 | | { |
142 | | uint64_t signature; |
143 | | uint64_t section_offsets[DW_SECT_MAX]; |
144 | | size_t section_sizes[DW_SECT_MAX]; |
145 | | }; |
146 | | |
147 | | static int cu_count = 0; |
148 | | static int tu_count = 0; |
149 | | static struct cu_tu_set *cu_sets = NULL; |
150 | | static struct cu_tu_set *tu_sets = NULL; |
151 | | |
152 | | static bool load_cu_tu_indexes (void *); |
153 | | |
154 | | /* An array that indicates for a given level of CU nesting whether |
155 | | the latest DW_AT_type seen for that level was a signed type or |
156 | | an unsigned type. */ |
157 | 350k | #define MAX_CU_NESTING (1 << 8) |
158 | | static bool level_type_signed[MAX_CU_NESTING]; |
159 | | |
160 | | /* Values for do_debug_lines. */ |
161 | 71.2k | #define FLAG_DEBUG_LINES_RAW 1 |
162 | 1.53k | #define FLAG_DEBUG_LINES_DECODED 2 |
163 | | |
164 | | static unsigned int |
165 | | size_of_encoded_value (int encoding) |
166 | 156k | { |
167 | 156k | switch (encoding & 0x7) |
168 | 156k | { |
169 | 74 | default: /* ??? */ |
170 | 38.8k | case 0: return eh_addr_size; |
171 | 72 | case 2: return 2; |
172 | 118k | case 3: return 4; |
173 | 42 | case 4: return 8; |
174 | 156k | } |
175 | 156k | } |
176 | | |
177 | | static uint64_t |
178 | | get_encoded_value (unsigned char **pdata, |
179 | | int encoding, |
180 | | struct dwarf_section *section, |
181 | | unsigned char * end) |
182 | 95.7k | { |
183 | 95.7k | unsigned char * data = * pdata; |
184 | 95.7k | unsigned int size = size_of_encoded_value (encoding); |
185 | 95.7k | uint64_t val; |
186 | | |
187 | 95.7k | if (data >= end || size > (size_t) (end - data)) |
188 | 450 | { |
189 | 450 | warn (_("Encoded value extends past end of section\n")); |
190 | 450 | * pdata = end; |
191 | 450 | return 0; |
192 | 450 | } |
193 | | |
194 | | /* PR 17512: file: 002-829853-0.004. */ |
195 | 95.3k | if (size > 8) |
196 | 0 | { |
197 | 0 | warn (_("Encoded size of %d is too large to read\n"), size); |
198 | 0 | * pdata = end; |
199 | 0 | return 0; |
200 | 0 | } |
201 | | |
202 | | /* PR 17512: file: 1085-5603-0.004. */ |
203 | 95.3k | if (size == 0) |
204 | 0 | { |
205 | 0 | warn (_("Encoded size of 0 is too small to read\n")); |
206 | 0 | * pdata = end; |
207 | 0 | return 0; |
208 | 0 | } |
209 | | |
210 | 95.3k | if (encoding & DW_EH_PE_signed) |
211 | 58.3k | val = byte_get_signed (data, size); |
212 | 36.9k | else |
213 | 36.9k | val = byte_get (data, size); |
214 | | |
215 | 95.3k | if ((encoding & 0x70) == DW_EH_PE_pcrel) |
216 | 58.9k | val += section->address + (data - section->start); |
217 | | |
218 | 95.3k | * pdata = data + size; |
219 | 95.3k | return val; |
220 | 95.3k | } |
221 | | |
222 | | /* Print a uint64_t value (typically an address, offset or length) in |
223 | | hexadecimal format, followed by a space. The precision displayed is |
224 | | determined by the NUM_BYTES parameter. */ |
225 | | |
226 | | static void |
227 | | print_hex (uint64_t value, unsigned num_bytes) |
228 | 1.00M | { |
229 | 1.00M | if (num_bytes == 0) |
230 | 0 | num_bytes = 2; |
231 | | |
232 | 1.00M | printf ("%0*" PRIx64 " ", num_bytes * 2, |
233 | 1.00M | value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); |
234 | 1.00M | } |
235 | | |
236 | | /* Like print_hex, but no trailing space. */ |
237 | | |
238 | | static void |
239 | | print_hex_ns (uint64_t value, unsigned num_bytes) |
240 | 948k | { |
241 | 948k | if (num_bytes == 0) |
242 | 0 | num_bytes = 2; |
243 | | |
244 | 948k | printf ("%0*" PRIx64, num_bytes * 2, |
245 | 948k | value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); |
246 | 948k | } |
247 | | |
248 | | /* Print a view number in hexadecimal value, with the same width as |
249 | | print_hex would have printed it. */ |
250 | | |
251 | | static void |
252 | | print_view (uint64_t value, unsigned num_bytes) |
253 | 0 | { |
254 | 0 | if (num_bytes == 0) |
255 | 0 | num_bytes = 2; |
256 | |
|
257 | 0 | printf ("v%0*" PRIx64 " ", num_bytes * 2 - 1, |
258 | 0 | value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); |
259 | 0 | } |
260 | | |
261 | | static const char * |
262 | | null_name (const char *p) |
263 | 19 | { |
264 | 19 | if (p == NULL) |
265 | 5 | p = _("unknown"); |
266 | 19 | return p; |
267 | 19 | } |
268 | | |
269 | | /* Read in a LEB128 encoded value starting at address DATA. |
270 | | If SIGN is true, return a signed LEB128 value. |
271 | | If LENGTH_RETURN is not NULL, return in it the number of bytes read. |
272 | | If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the |
273 | | terminating byte was not found and with bit 1 set if the value |
274 | | overflows a uint64_t. |
275 | | No bytes will be read at address END or beyond. */ |
276 | | |
277 | | uint64_t |
278 | | read_leb128 (unsigned char *data, |
279 | | const unsigned char *const end, |
280 | | bool sign, |
281 | | unsigned int *length_return, |
282 | | int *status_return) |
283 | 25.0M | { |
284 | 25.0M | uint64_t result = 0; |
285 | 25.0M | unsigned int num_read = 0; |
286 | 25.0M | unsigned int shift = 0; |
287 | 25.0M | int status = 1; |
288 | | |
289 | 33.2M | while (data < end) |
290 | 33.2M | { |
291 | 33.2M | unsigned char byte = *data++; |
292 | 33.2M | unsigned char lost, mask; |
293 | | |
294 | 33.2M | num_read++; |
295 | | |
296 | 33.2M | if (shift < CHAR_BIT * sizeof (result)) |
297 | 32.3M | { |
298 | 32.3M | result |= ((uint64_t) (byte & 0x7f)) << shift; |
299 | | /* These bits overflowed. */ |
300 | 32.3M | lost = byte ^ (result >> shift); |
301 | | /* And this is the mask of possible overflow bits. */ |
302 | 32.3M | mask = 0x7f ^ ((uint64_t) 0x7f << shift >> shift); |
303 | 32.3M | shift += 7; |
304 | 32.3M | } |
305 | 928k | else |
306 | 928k | { |
307 | 928k | lost = byte; |
308 | 928k | mask = 0x7f; |
309 | 928k | } |
310 | 33.2M | if ((lost & mask) != (sign && (int64_t) result < 0 ? mask : 0)) |
311 | 962k | status |= 2; |
312 | | |
313 | 33.2M | if ((byte & 0x80) == 0) |
314 | 25.0M | { |
315 | 25.0M | status &= ~1; |
316 | 25.0M | if (sign && shift < CHAR_BIT * sizeof (result) && (byte & 0x40)) |
317 | 217k | result |= -((uint64_t) 1 << shift); |
318 | 25.0M | break; |
319 | 25.0M | } |
320 | 33.2M | } |
321 | | |
322 | 25.0M | if (length_return != NULL) |
323 | 25.0M | *length_return = num_read; |
324 | 25.0M | if (status_return != NULL) |
325 | 24.3M | *status_return = status; |
326 | | |
327 | 25.0M | return result; |
328 | 25.0M | } |
329 | | |
330 | | /* Read AMOUNT bytes from PTR and store them in VAL. |
331 | | Checks to make sure that the read will not reach or pass END. |
332 | | FUNC chooses whether the value read is unsigned or signed, and may |
333 | | be either byte_get or byte_get_signed. If INC is true, PTR is |
334 | | incremented after reading the value. |
335 | | This macro cannot protect against PTR values derived from user input. |
336 | | The C standard sections 6.5.6 and 6.5.8 say attempts to do so using |
337 | | pointers is undefined behaviour. */ |
338 | | #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \ |
339 | 4.64M | do \ |
340 | 4.64M | { \ |
341 | 4.64M | size_t amount = (AMOUNT); \ |
342 | 4.64M | if (sizeof (VAL) < amount) \ |
343 | 4.64M | { \ |
344 | 0 | error (ngettext ("internal error: attempt to read %d byte " \ |
345 | 0 | "of data in to %d sized variable", \ |
346 | 0 | "internal error: attempt to read %d bytes " \ |
347 | 0 | "of data in to %d sized variable", \ |
348 | 0 | amount), \ |
349 | 0 | (int) amount, (int) sizeof (VAL)); \ |
350 | 0 | amount = sizeof (VAL); \ |
351 | 0 | } \ |
352 | 4.64M | if (ENABLE_CHECKING) \ |
353 | 4.64M | assert ((PTR) <= (END)); \ |
354 | 4.64M | size_t avail = (END) - (PTR); \ |
355 | 4.64M | if ((PTR) > (END)) \ |
356 | 4.64M | avail = 0; \ |
357 | 4.64M | if (amount > avail) \ |
358 | 4.64M | amount = avail; \ |
359 | 4.64M | if (amount == 0) \ |
360 | 4.64M | (VAL) = 0; \ |
361 | 4.64M | else \ |
362 | 4.64M | (VAL) = (FUNC) ((PTR), amount); \ |
363 | 4.64M | if (INC) \ |
364 | 4.64M | (PTR) += amount; \ |
365 | 4.64M | } \ |
366 | 4.64M | while (0) |
367 | | |
368 | | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
369 | 681k | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false) |
370 | | |
371 | | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
372 | 3.46M | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true) |
373 | | |
374 | | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
375 | | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false) |
376 | | |
377 | | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
378 | 492k | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true) |
379 | | |
380 | | typedef struct State_Machine_Registers |
381 | | { |
382 | | uint64_t address; |
383 | | unsigned int view; |
384 | | unsigned int file; |
385 | | unsigned int line; |
386 | | unsigned int column; |
387 | | int is_stmt; |
388 | | int basic_block; |
389 | | unsigned char op_index; |
390 | | unsigned char end_sequence; |
391 | | /* This variable hold the number of the last entry seen |
392 | | in the File Table. */ |
393 | | unsigned int last_file_entry; |
394 | | } SMR; |
395 | | |
396 | | static SMR state_machine_regs; |
397 | | |
398 | | static void |
399 | | reset_state_machine (int is_stmt) |
400 | 16.4k | { |
401 | 16.4k | state_machine_regs.address = 0; |
402 | 16.4k | state_machine_regs.view = 0; |
403 | 16.4k | state_machine_regs.op_index = 0; |
404 | 16.4k | state_machine_regs.file = 1; |
405 | 16.4k | state_machine_regs.line = 1; |
406 | 16.4k | state_machine_regs.column = 0; |
407 | 16.4k | state_machine_regs.is_stmt = is_stmt; |
408 | 16.4k | state_machine_regs.basic_block = 0; |
409 | 16.4k | state_machine_regs.end_sequence = 0; |
410 | 16.4k | state_machine_regs.last_file_entry = 0; |
411 | 16.4k | } |
412 | | |
413 | | /* Handled an extend line op. |
414 | | Returns the number of bytes read. */ |
415 | | |
416 | | static size_t |
417 | | process_extended_line_op (unsigned char * data, |
418 | | int is_stmt, |
419 | | unsigned char * end) |
420 | 641k | { |
421 | 641k | unsigned char op_code; |
422 | 641k | size_t len, header_len; |
423 | 641k | unsigned char *name; |
424 | 641k | unsigned char *orig_data = data; |
425 | 641k | uint64_t adr, val; |
426 | | |
427 | 641k | READ_ULEB (len, data, end); |
428 | 641k | header_len = data - orig_data; |
429 | | |
430 | 641k | if (len == 0 || data >= end || len > (size_t) (end - data)) |
431 | 65.4k | { |
432 | 65.4k | warn (_("Badly formed extended line op encountered!\n")); |
433 | 65.4k | return header_len; |
434 | 65.4k | } |
435 | | |
436 | 575k | op_code = *data++; |
437 | | |
438 | 575k | printf (_(" Extended opcode %d: "), op_code); |
439 | | |
440 | 575k | switch (op_code) |
441 | 575k | { |
442 | 8.33k | case DW_LNE_end_sequence: |
443 | 8.33k | printf (_("End of Sequence\n\n")); |
444 | 8.33k | reset_state_machine (is_stmt); |
445 | 8.33k | break; |
446 | | |
447 | 555k | case DW_LNE_set_address: |
448 | | /* PR 17512: file: 002-100480-0.004. */ |
449 | 555k | if (len - 1 > 8) |
450 | 179 | { |
451 | 179 | warn (_("Length (%zu) of DW_LNE_set_address op is too long\n"), |
452 | 179 | len - 1); |
453 | 179 | adr = 0; |
454 | 179 | } |
455 | 555k | else |
456 | 555k | SAFE_BYTE_GET (adr, data, len - 1, end); |
457 | 555k | printf (_("set Address to %#" PRIx64 "\n"), adr); |
458 | 555k | state_machine_regs.address = adr; |
459 | 555k | state_machine_regs.view = 0; |
460 | 555k | state_machine_regs.op_index = 0; |
461 | 555k | break; |
462 | | |
463 | 162 | case DW_LNE_define_file: |
464 | 162 | printf (_("define new File Table entry\n")); |
465 | 162 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
466 | 162 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
467 | | |
468 | 162 | { |
469 | 162 | size_t l; |
470 | | |
471 | 162 | name = data; |
472 | 162 | l = strnlen ((char *) data, end - data); |
473 | 162 | data += l; |
474 | 162 | if (data < end) |
475 | 162 | data++; |
476 | 162 | READ_ULEB (val, data, end); |
477 | 162 | printf ("%" PRIu64 "\t", val); |
478 | 162 | READ_ULEB (val, data, end); |
479 | 162 | printf ("%" PRIu64 "\t", val); |
480 | 162 | READ_ULEB (val, data, end); |
481 | 162 | printf ("%" PRIu64 "\t", val); |
482 | 162 | printf ("%.*s\n\n", (int) l, name); |
483 | 162 | } |
484 | | |
485 | 162 | if (((size_t) (data - orig_data) != len + header_len) || data >= end) |
486 | 148 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
487 | 162 | break; |
488 | | |
489 | 1.46k | case DW_LNE_set_discriminator: |
490 | 1.46k | READ_ULEB (val, data, end); |
491 | 1.46k | printf (_("set Discriminator to %" PRIu64 "\n"), val); |
492 | 1.46k | break; |
493 | | |
494 | | /* HP extensions. */ |
495 | 41 | case DW_LNE_HP_negate_is_UV_update: |
496 | 41 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
497 | 41 | break; |
498 | 48 | case DW_LNE_HP_push_context: |
499 | 48 | printf ("DW_LNE_HP_push_context\n"); |
500 | 48 | break; |
501 | 94 | case DW_LNE_HP_pop_context: |
502 | 94 | printf ("DW_LNE_HP_pop_context\n"); |
503 | 94 | break; |
504 | 20 | case DW_LNE_HP_set_file_line_column: |
505 | 20 | printf ("DW_LNE_HP_set_file_line_column\n"); |
506 | 20 | break; |
507 | 32 | case DW_LNE_HP_set_routine_name: |
508 | 32 | printf ("DW_LNE_HP_set_routine_name\n"); |
509 | 32 | break; |
510 | 25 | case DW_LNE_HP_set_sequence: |
511 | 25 | printf ("DW_LNE_HP_set_sequence\n"); |
512 | 25 | break; |
513 | 31 | case DW_LNE_HP_negate_post_semantics: |
514 | 31 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
515 | 31 | break; |
516 | 67 | case DW_LNE_HP_negate_function_exit: |
517 | 67 | printf ("DW_LNE_HP_negate_function_exit\n"); |
518 | 67 | break; |
519 | 24 | case DW_LNE_HP_negate_front_end_logical: |
520 | 24 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
521 | 24 | break; |
522 | 243 | case DW_LNE_HP_define_proc: |
523 | 243 | printf ("DW_LNE_HP_define_proc\n"); |
524 | 243 | break; |
525 | 236 | case DW_LNE_HP_source_file_correlation: |
526 | 236 | { |
527 | 236 | unsigned char *edata = data + len - 1; |
528 | | |
529 | 236 | printf ("DW_LNE_HP_source_file_correlation\n"); |
530 | | |
531 | 730 | while (data < edata) |
532 | 494 | { |
533 | 494 | unsigned int opc; |
534 | | |
535 | 494 | READ_ULEB (opc, data, edata); |
536 | | |
537 | 494 | switch (opc) |
538 | 494 | { |
539 | 16 | case DW_LNE_HP_SFC_formfeed: |
540 | 16 | printf (" DW_LNE_HP_SFC_formfeed\n"); |
541 | 16 | break; |
542 | 80 | case DW_LNE_HP_SFC_set_listing_line: |
543 | 80 | READ_ULEB (val, data, edata); |
544 | 80 | printf (" DW_LNE_HP_SFC_set_listing_line (%" PRIu64 ")\n", |
545 | 80 | val); |
546 | 80 | break; |
547 | 199 | case DW_LNE_HP_SFC_associate: |
548 | 199 | printf (" DW_LNE_HP_SFC_associate "); |
549 | 199 | READ_ULEB (val, data, edata); |
550 | 199 | printf ("(%" PRIu64 , val); |
551 | 199 | READ_ULEB (val, data, edata); |
552 | 199 | printf (",%" PRIu64, val); |
553 | 199 | READ_ULEB (val, data, edata); |
554 | 199 | printf (",%" PRIu64 ")\n", val); |
555 | 199 | break; |
556 | 199 | default: |
557 | 199 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); |
558 | 199 | data = edata; |
559 | 199 | break; |
560 | 494 | } |
561 | 494 | } |
562 | 236 | } |
563 | 236 | break; |
564 | | |
565 | 8.96k | default: |
566 | 8.96k | { |
567 | 8.96k | unsigned int rlen = len - 1; |
568 | | |
569 | 8.96k | if (op_code >= DW_LNE_lo_user |
570 | | /* The test against DW_LNW_hi_user is redundant due to |
571 | | the limited range of the unsigned char data type used |
572 | | for op_code. */ |
573 | 8.96k | /*&& op_code <= DW_LNE_hi_user*/) |
574 | 2.58k | printf (_("user defined: ")); |
575 | 6.37k | else |
576 | 6.37k | printf (_("UNKNOWN: ")); |
577 | 8.96k | printf (_("length %d ["), rlen); |
578 | 1.04M | for (; rlen; rlen--) |
579 | 1.03M | printf (" %02x", *data++); |
580 | 8.96k | printf ("]\n"); |
581 | 8.96k | } |
582 | 8.96k | break; |
583 | 575k | } |
584 | | |
585 | 575k | return len + header_len; |
586 | 575k | } |
587 | | |
588 | | static const unsigned char * |
589 | | fetch_indirect_string (uint64_t offset) |
590 | 186k | { |
591 | 186k | struct dwarf_section *section = &debug_displays [str].section; |
592 | 186k | const unsigned char * ret; |
593 | | |
594 | 186k | if (section->start == NULL) |
595 | 186k | return (const unsigned char *) _("<no .debug_str section>"); |
596 | | |
597 | 0 | if (offset >= section->size) |
598 | 0 | { |
599 | 0 | warn (_("DW_FORM_strp offset too big: %#" PRIx64 "\n"), offset); |
600 | 0 | return (const unsigned char *) _("<offset is too big>"); |
601 | 0 | } |
602 | | |
603 | 0 | ret = section->start + offset; |
604 | | /* Unfortunately we cannot rely upon the .debug_str section ending with a |
605 | | NUL byte. Since our caller is expecting to receive a well formed C |
606 | | string we test for the lack of a terminating byte here. */ |
607 | 0 | if (strnlen ((const char *) ret, section->size - offset) |
608 | 0 | == section->size - offset) |
609 | 0 | ret = (const unsigned char *) |
610 | 0 | _("<no NUL byte at end of .debug_str section>"); |
611 | |
|
612 | 0 | return ret; |
613 | 0 | } |
614 | | |
615 | | static const unsigned char * |
616 | | fetch_indirect_line_string (uint64_t offset) |
617 | 3.81k | { |
618 | 3.81k | struct dwarf_section *section = &debug_displays [line_str].section; |
619 | 3.81k | const unsigned char * ret; |
620 | | |
621 | 3.81k | if (section->start == NULL) |
622 | 3.81k | return (const unsigned char *) _("<no .debug_line_str section>"); |
623 | | |
624 | 0 | if (offset >= section->size) |
625 | 0 | { |
626 | 0 | warn (_("DW_FORM_line_strp offset too big: %#" PRIx64 "\n"), offset); |
627 | 0 | return (const unsigned char *) _("<offset is too big>"); |
628 | 0 | } |
629 | | |
630 | 0 | ret = section->start + offset; |
631 | | /* Unfortunately we cannot rely upon the .debug_line_str section ending |
632 | | with a NUL byte. Since our caller is expecting to receive a well formed |
633 | | C string we test for the lack of a terminating byte here. */ |
634 | 0 | if (strnlen ((const char *) ret, section->size - offset) |
635 | 0 | == section->size - offset) |
636 | 0 | ret = (const unsigned char *) |
637 | 0 | _("<no NUL byte at end of .debug_line_str section>"); |
638 | |
|
639 | 0 | return ret; |
640 | 0 | } |
641 | | |
642 | | static const char * |
643 | | fetch_indexed_string (uint64_t idx, |
644 | | struct cu_tu_set *this_set, |
645 | | uint64_t offset_size, |
646 | | bool dwo, |
647 | | uint64_t str_offsets_base) |
648 | 1.26k | { |
649 | 1.26k | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; |
650 | 1.26k | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; |
651 | 1.26k | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; |
652 | 1.26k | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; |
653 | 1.26k | uint64_t index_offset; |
654 | 1.26k | uint64_t str_offset; |
655 | 1.26k | const char * ret; |
656 | | |
657 | 1.26k | if (index_section->start == NULL) |
658 | 1.26k | return (dwo ? _("<no .debug_str_offsets.dwo section>") |
659 | 1.26k | : _("<no .debug_str_offsets section>")); |
660 | | |
661 | 0 | if (str_section->start == NULL) |
662 | 0 | return (dwo ? _("<no .debug_str.dwo section>") |
663 | 0 | : _("<no .debug_str section>")); |
664 | | |
665 | 0 | if (_mul_overflow (idx, offset_size, &index_offset) |
666 | 0 | || (this_set != NULL |
667 | 0 | && ((index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]) |
668 | 0 | < this_set->section_offsets [DW_SECT_STR_OFFSETS])) |
669 | 0 | || (index_offset += str_offsets_base) < str_offsets_base |
670 | 0 | || index_offset + offset_size < offset_size |
671 | 0 | || index_offset + offset_size > index_section->size) |
672 | 0 | { |
673 | 0 | warn (_("string index of %" PRIu64 " converts to an offset of %#" PRIx64 |
674 | 0 | " which is too big for section %s\n"), |
675 | 0 | idx, index_offset, str_section->name); |
676 | |
|
677 | 0 | return _("<string index too big>"); |
678 | 0 | } |
679 | | |
680 | 0 | str_offset = byte_get (index_section->start + index_offset, offset_size); |
681 | |
|
682 | 0 | if (str_offset >= str_section->size) |
683 | 0 | { |
684 | 0 | warn (_("indirect offset too big: %#" PRIx64 "\n"), str_offset); |
685 | 0 | return _("<indirect index offset is too big>"); |
686 | 0 | } |
687 | | |
688 | 0 | ret = (const char *) str_section->start + str_offset; |
689 | | |
690 | | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. |
691 | | Since our caller is expecting to receive a well formed C string we test |
692 | | for the lack of a terminating byte here. */ |
693 | 0 | if (strnlen (ret, str_section->size - str_offset) |
694 | 0 | == str_section->size - str_offset) |
695 | 0 | return _("<no NUL byte at end of section>"); |
696 | | |
697 | 0 | return ret; |
698 | 0 | } |
699 | | |
700 | | static uint64_t |
701 | | fetch_indexed_addr (uint64_t offset, uint32_t num_bytes) |
702 | 938 | { |
703 | 938 | struct dwarf_section *section = &debug_displays [debug_addr].section; |
704 | | |
705 | 938 | if (section->start == NULL) |
706 | 938 | { |
707 | 938 | warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n")); |
708 | 938 | return 0; |
709 | 938 | } |
710 | | |
711 | 0 | if (offset + num_bytes > section->size) |
712 | 0 | { |
713 | 0 | warn (_("Offset into section %s too big: %#" PRIx64 "\n"), |
714 | 0 | section->name, offset); |
715 | 0 | return 0; |
716 | 0 | } |
717 | | |
718 | 0 | return byte_get (section->start + offset, num_bytes); |
719 | 0 | } |
720 | | |
721 | | /* This is for resolving DW_FORM_rnglistx and DW_FORM_loclistx. |
722 | | |
723 | | The memory layout is: base_address (taken from the CU's top DIE) points at a table of offsets, |
724 | | relative to the section start. |
725 | | The table of offsets contains the offsets of objects of interest relative to the table of offsets. |
726 | | IDX is the index of the desired object in said table of offsets. |
727 | | |
728 | | This returns the offset of the desired object relative to the section start or -1 upon failure. */ |
729 | | |
730 | | static uint64_t |
731 | | fetch_indexed_offset (uint64_t idx, |
732 | | enum dwarf_section_display_enum sec_enum, |
733 | | uint64_t base_address, |
734 | | uint64_t offset_size) |
735 | 4 | { |
736 | 4 | uint64_t offset_of_offset = base_address + idx * offset_size; |
737 | 4 | struct dwarf_section *section = &debug_displays [sec_enum].section; |
738 | | |
739 | 4 | if (section->start == NULL) |
740 | 4 | { |
741 | 4 | warn (_("Unable to locate %s section\n"), section->uncompressed_name); |
742 | 4 | return -1; |
743 | 4 | } |
744 | | |
745 | 0 | if (section->size < 4) |
746 | 0 | { |
747 | 0 | warn (_("Section %s is too small to contain an value indexed from another section!\n"), |
748 | 0 | section->name); |
749 | 0 | return -1; |
750 | 0 | } |
751 | | |
752 | 0 | if (offset_of_offset + offset_size >= section->size) |
753 | 0 | { |
754 | 0 | warn (_("Offset of %#" PRIx64 " is too big for section %s\n"), |
755 | 0 | offset_of_offset, section->name); |
756 | 0 | return -1; |
757 | 0 | } |
758 | | |
759 | 0 | return base_address + byte_get (section->start + offset_of_offset, offset_size); |
760 | 0 | } |
761 | | |
762 | | /* FIXME: There are better and more efficient ways to handle |
763 | | these structures. For now though, I just want something that |
764 | | is simple to implement. */ |
765 | | /* Records a single attribute in an abbrev. */ |
766 | | typedef struct abbrev_attr |
767 | | { |
768 | | unsigned long attribute; |
769 | | unsigned long form; |
770 | | int64_t implicit_const; |
771 | | struct abbrev_attr *next; |
772 | | } |
773 | | abbrev_attr; |
774 | | |
775 | | /* Records a single abbrev. */ |
776 | | typedef struct abbrev_entry |
777 | | { |
778 | | unsigned long number; |
779 | | unsigned long tag; |
780 | | int children; |
781 | | struct abbrev_attr * first_attr; |
782 | | struct abbrev_attr * last_attr; |
783 | | struct abbrev_entry * next; |
784 | | } |
785 | | abbrev_entry; |
786 | | |
787 | | /* Records a set of abbreviations. */ |
788 | | typedef struct abbrev_list |
789 | | { |
790 | | abbrev_entry * first_abbrev; |
791 | | abbrev_entry * last_abbrev; |
792 | | unsigned char * raw; |
793 | | struct abbrev_list * next; |
794 | | unsigned char * start_of_next_abbrevs; |
795 | | } |
796 | | abbrev_list; |
797 | | |
798 | | /* Records all the abbrevs found so far. */ |
799 | | static struct abbrev_list * abbrev_lists = NULL; |
800 | | |
801 | | typedef struct abbrev_map |
802 | | { |
803 | | uint64_t start; |
804 | | uint64_t end; |
805 | | abbrev_list *list; |
806 | | } abbrev_map; |
807 | | |
808 | | /* Maps between CU offsets and abbrev sets. */ |
809 | | static abbrev_map * cu_abbrev_map = NULL; |
810 | | static unsigned long num_abbrev_map_entries = 0; |
811 | | static unsigned long next_free_abbrev_map_entry = 0; |
812 | | |
813 | 613 | #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8 |
814 | 2.21k | #define ABBREV_MAP_ENTRIES_INCREMENT 8 |
815 | | |
816 | | static void |
817 | | record_abbrev_list_for_cu (uint64_t start, uint64_t end, |
818 | | abbrev_list *list, abbrev_list *free_list) |
819 | 18.5k | { |
820 | 18.5k | if (free_list != NULL) |
821 | 6.17k | { |
822 | 6.17k | list->next = abbrev_lists; |
823 | 6.17k | abbrev_lists = list; |
824 | 6.17k | } |
825 | | |
826 | 18.5k | if (cu_abbrev_map == NULL) |
827 | 613 | { |
828 | 613 | num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES; |
829 | 613 | cu_abbrev_map = xmalloc (num_abbrev_map_entries * sizeof (* cu_abbrev_map)); |
830 | 613 | } |
831 | 17.9k | else if (next_free_abbrev_map_entry == num_abbrev_map_entries) |
832 | 2.21k | { |
833 | 2.21k | num_abbrev_map_entries += ABBREV_MAP_ENTRIES_INCREMENT; |
834 | 2.21k | cu_abbrev_map = xrealloc (cu_abbrev_map, num_abbrev_map_entries * sizeof (* cu_abbrev_map)); |
835 | 2.21k | } |
836 | | |
837 | 18.5k | cu_abbrev_map[next_free_abbrev_map_entry].start = start; |
838 | 18.5k | cu_abbrev_map[next_free_abbrev_map_entry].end = end; |
839 | 18.5k | cu_abbrev_map[next_free_abbrev_map_entry].list = list; |
840 | 18.5k | next_free_abbrev_map_entry ++; |
841 | 18.5k | } |
842 | | |
843 | | static abbrev_list * |
844 | | free_abbrev_list (abbrev_list *list) |
845 | 2.40M | { |
846 | 2.40M | abbrev_entry *abbrv = list->first_abbrev; |
847 | | |
848 | 3.73M | while (abbrv) |
849 | 1.32M | { |
850 | 1.32M | abbrev_attr *attr = abbrv->first_attr; |
851 | | |
852 | 8.22M | while (attr) |
853 | 6.89M | { |
854 | 6.89M | abbrev_attr *next_attr = attr->next; |
855 | 6.89M | free (attr); |
856 | 6.89M | attr = next_attr; |
857 | 6.89M | } |
858 | | |
859 | 1.32M | abbrev_entry *next_abbrev = abbrv->next; |
860 | 1.32M | free (abbrv); |
861 | 1.32M | abbrv = next_abbrev; |
862 | 1.32M | } |
863 | | |
864 | 2.40M | abbrev_list *next = list->next; |
865 | 2.40M | free (list); |
866 | 2.40M | return next; |
867 | 2.40M | } |
868 | | |
869 | | static void |
870 | | free_all_abbrevs (void) |
871 | 129k | { |
872 | 136k | while (abbrev_lists) |
873 | 6.17k | abbrev_lists = free_abbrev_list (abbrev_lists); |
874 | | |
875 | 129k | free (cu_abbrev_map); |
876 | 129k | cu_abbrev_map = NULL; |
877 | 129k | next_free_abbrev_map_entry = 0; |
878 | 129k | } |
879 | | |
880 | | static abbrev_list * |
881 | | find_abbrev_list_by_raw_abbrev (unsigned char *raw) |
882 | 53.2k | { |
883 | 53.2k | abbrev_list * list; |
884 | | |
885 | 432k | for (list = abbrev_lists; list != NULL; list = list->next) |
886 | 391k | if (list->raw == raw) |
887 | 12.4k | return list; |
888 | | |
889 | 40.8k | return NULL; |
890 | 53.2k | } |
891 | | |
892 | | /* Find the abbreviation map for the CU that includes OFFSET. |
893 | | OFFSET is an absolute offset from the start of the .debug_info section. */ |
894 | | /* FIXME: This function is going to slow down readelf & objdump. |
895 | | Not caching abbrevs is likely the answer. */ |
896 | | |
897 | | static abbrev_map * |
898 | | find_abbrev_map_by_offset (uint64_t offset) |
899 | 318k | { |
900 | 318k | unsigned long i; |
901 | | |
902 | 5.07M | for (i = 0; i < next_free_abbrev_map_entry; i++) |
903 | 5.07M | if (cu_abbrev_map[i].start <= offset |
904 | 5.07M | && cu_abbrev_map[i].end > offset) |
905 | 318k | return cu_abbrev_map + i; |
906 | | |
907 | 0 | return NULL; |
908 | 318k | } |
909 | | |
910 | | static void |
911 | | add_abbrev (unsigned long number, |
912 | | unsigned long tag, |
913 | | int children, |
914 | | abbrev_list * list) |
915 | 1.32M | { |
916 | 1.32M | abbrev_entry * entry; |
917 | | |
918 | 1.32M | entry = (abbrev_entry *) xmalloc (sizeof (*entry)); |
919 | | |
920 | 1.32M | entry->number = number; |
921 | 1.32M | entry->tag = tag; |
922 | 1.32M | entry->children = children; |
923 | 1.32M | entry->first_attr = NULL; |
924 | 1.32M | entry->last_attr = NULL; |
925 | 1.32M | entry->next = NULL; |
926 | | |
927 | 1.32M | assert (list != NULL); |
928 | | |
929 | 1.32M | if (list->first_abbrev == NULL) |
930 | 510k | list->first_abbrev = entry; |
931 | 813k | else |
932 | 813k | list->last_abbrev->next = entry; |
933 | | |
934 | 1.32M | list->last_abbrev = entry; |
935 | 1.32M | } |
936 | | |
937 | | static void |
938 | | add_abbrev_attr (unsigned long attribute, |
939 | | unsigned long form, |
940 | | int64_t implicit_const, |
941 | | abbrev_list *list) |
942 | 6.89M | { |
943 | 6.89M | abbrev_attr *attr; |
944 | | |
945 | 6.89M | attr = (abbrev_attr *) xmalloc (sizeof (*attr)); |
946 | | |
947 | 6.89M | attr->attribute = attribute; |
948 | 6.89M | attr->form = form; |
949 | 6.89M | attr->implicit_const = implicit_const; |
950 | 6.89M | attr->next = NULL; |
951 | | |
952 | 6.89M | assert (list != NULL && list->last_abbrev != NULL); |
953 | | |
954 | 6.89M | if (list->last_abbrev->first_attr == NULL) |
955 | 1.32M | list->last_abbrev->first_attr = attr; |
956 | 5.57M | else |
957 | 5.57M | list->last_abbrev->last_attr->next = attr; |
958 | | |
959 | 6.89M | list->last_abbrev->last_attr = attr; |
960 | 6.89M | } |
961 | | |
962 | | /* Return processed (partial) contents of a .debug_abbrev section. |
963 | | Returns NULL on errors. */ |
964 | | |
965 | | static abbrev_list * |
966 | | process_abbrev_set (struct dwarf_section *section, |
967 | | unsigned char *start, |
968 | | unsigned char *end) |
969 | 2.40M | { |
970 | 2.40M | abbrev_list *list = xmalloc (sizeof (*list)); |
971 | 2.40M | list->first_abbrev = NULL; |
972 | 2.40M | list->last_abbrev = NULL; |
973 | 2.40M | list->raw = start; |
974 | 2.40M | list->next = NULL; |
975 | | |
976 | 3.73M | while (start < end) |
977 | 3.72M | { |
978 | 3.72M | unsigned long entry; |
979 | 3.72M | unsigned long tag; |
980 | 3.72M | unsigned long attribute; |
981 | 3.72M | int children; |
982 | | |
983 | 3.72M | READ_ULEB (entry, start, end); |
984 | | |
985 | | /* A single zero is supposed to end the set according |
986 | | to the standard. If there's more, then signal that to |
987 | | the caller. */ |
988 | 3.72M | if (start == end || entry == 0) |
989 | 2.40M | { |
990 | 2.40M | list->start_of_next_abbrevs = start != end ? start : NULL; |
991 | 2.40M | return list; |
992 | 2.40M | } |
993 | | |
994 | 1.32M | READ_ULEB (tag, start, end); |
995 | 1.32M | if (start == end) |
996 | 252 | return free_abbrev_list (list); |
997 | | |
998 | 1.32M | children = *start++; |
999 | | |
1000 | 1.32M | add_abbrev (entry, tag, children, list); |
1001 | | |
1002 | 1.32M | do |
1003 | 6.89M | { |
1004 | 6.89M | unsigned long form; |
1005 | | /* Initialize it due to a false compiler warning. */ |
1006 | 6.89M | int64_t implicit_const = -1; |
1007 | | |
1008 | 6.89M | READ_ULEB (attribute, start, end); |
1009 | 6.89M | if (start == end) |
1010 | 794 | break; |
1011 | | |
1012 | 6.89M | READ_ULEB (form, start, end); |
1013 | 6.89M | if (start == end) |
1014 | 719 | break; |
1015 | | |
1016 | 6.89M | if (form == DW_FORM_implicit_const) |
1017 | 18.3k | { |
1018 | 18.3k | READ_SLEB (implicit_const, start, end); |
1019 | 18.3k | if (start == end) |
1020 | 14 | break; |
1021 | 18.3k | } |
1022 | | |
1023 | 6.89M | add_abbrev_attr (attribute, form, implicit_const, list); |
1024 | 6.89M | } |
1025 | 6.89M | while (attribute != 0); |
1026 | 1.32M | } |
1027 | | |
1028 | | /* Report the missing single zero which ends the section. */ |
1029 | 1.52k | error (_("%s section not zero terminated\n"), section->name); |
1030 | | |
1031 | 1.52k | return free_abbrev_list (list); |
1032 | 2.40M | } |
1033 | | |
1034 | | /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE |
1035 | | plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE. |
1036 | | If FREE_LIST is non-NULL search the already decoded abbrevs on |
1037 | | abbrev_lists first and if found set *FREE_LIST to NULL. If |
1038 | | searching doesn't find a matching abbrev, set *FREE_LIST to the |
1039 | | newly allocated list. If FREE_LIST is NULL, no search is done and |
1040 | | the returned abbrev_list is always newly allocated. */ |
1041 | | |
1042 | | static abbrev_list * |
1043 | | find_and_process_abbrev_set (struct dwarf_section *section, |
1044 | | uint64_t abbrev_base, |
1045 | | uint64_t abbrev_size, |
1046 | | uint64_t abbrev_offset, |
1047 | | abbrev_list **free_list) |
1048 | 2.42M | { |
1049 | 2.42M | if (free_list) |
1050 | 53.2k | *free_list = NULL; |
1051 | | |
1052 | 2.42M | if (abbrev_base >= section->size |
1053 | 2.42M | || abbrev_size > section->size - abbrev_base) |
1054 | 15 | { |
1055 | | /* PR 17531: file:4bcd9ce9. */ |
1056 | 15 | warn (_("Debug info is corrupted, abbrev size (%#" PRIx64 ")" |
1057 | 15 | " is larger than abbrev section size (%#" PRIx64 ")\n"), |
1058 | 15 | abbrev_base + abbrev_size, section->size); |
1059 | 15 | return NULL; |
1060 | 15 | } |
1061 | 2.42M | if (abbrev_offset >= abbrev_size) |
1062 | 33 | { |
1063 | 33 | warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64 ")" |
1064 | 33 | " is larger than abbrev section size (%#" PRIx64 ")\n"), |
1065 | 33 | abbrev_offset, abbrev_size); |
1066 | 33 | return NULL; |
1067 | 33 | } |
1068 | | |
1069 | 2.42M | unsigned char *start = section->start + abbrev_base + abbrev_offset; |
1070 | 2.42M | unsigned char *end = section->start + abbrev_base + abbrev_size; |
1071 | 2.42M | abbrev_list *list = NULL; |
1072 | 2.42M | if (free_list) |
1073 | 53.2k | list = find_abbrev_list_by_raw_abbrev (start); |
1074 | 2.42M | if (list == NULL) |
1075 | 2.40M | { |
1076 | 2.40M | list = process_abbrev_set (section, start, end); |
1077 | 2.40M | if (free_list) |
1078 | 40.8k | *free_list = list; |
1079 | 2.40M | } |
1080 | 2.42M | return list; |
1081 | 2.42M | } |
1082 | | |
1083 | | static const char * |
1084 | | get_TAG_name (uint64_t tag) |
1085 | 1.46M | { |
1086 | 1.46M | const char *name = NULL; |
1087 | | |
1088 | 1.46M | if ((unsigned int) tag == tag) |
1089 | 1.45M | name = get_DW_TAG_name ((unsigned int) tag); |
1090 | 1.46M | if (name == NULL) |
1091 | 275k | { |
1092 | 275k | static char buffer[100]; |
1093 | | |
1094 | 275k | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1095 | 2.99k | snprintf (buffer, sizeof (buffer), |
1096 | 2.99k | _("User TAG value: %#" PRIx64), tag); |
1097 | 272k | else |
1098 | 272k | snprintf (buffer, sizeof (buffer), |
1099 | 272k | _("Unknown TAG value: %#" PRIx64), tag); |
1100 | 275k | return buffer; |
1101 | 275k | } |
1102 | | |
1103 | 1.19M | return name; |
1104 | 1.46M | } |
1105 | | |
1106 | | static const char * |
1107 | | get_FORM_name (unsigned long form) |
1108 | 5.67M | { |
1109 | 5.67M | const char *name = NULL; |
1110 | | |
1111 | 5.67M | if (form == 0) |
1112 | 1.05M | return "DW_FORM value: 0"; |
1113 | | |
1114 | 4.61M | if ((unsigned int) form == form) |
1115 | 4.48M | name = get_DW_FORM_name ((unsigned int) form); |
1116 | 4.61M | if (name == NULL) |
1117 | 3.00M | { |
1118 | 3.00M | static char buffer[100]; |
1119 | | |
1120 | 3.00M | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1121 | 3.00M | return buffer; |
1122 | 3.00M | } |
1123 | | |
1124 | 1.61M | return name; |
1125 | 4.61M | } |
1126 | | |
1127 | | static const char * |
1128 | | get_IDX_name (unsigned long idx) |
1129 | 0 | { |
1130 | 0 | const char *name = NULL; |
1131 | |
|
1132 | 0 | if ((unsigned int) idx == idx) |
1133 | 0 | name = get_DW_IDX_name ((unsigned int) idx); |
1134 | 0 | if (name == NULL) |
1135 | 0 | { |
1136 | 0 | static char buffer[100]; |
1137 | |
|
1138 | 0 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); |
1139 | 0 | return buffer; |
1140 | 0 | } |
1141 | | |
1142 | 0 | return name; |
1143 | 0 | } |
1144 | | |
1145 | | static unsigned char * |
1146 | | display_block (unsigned char *data, |
1147 | | uint64_t length, |
1148 | | const unsigned char * const end, char delimiter) |
1149 | 126k | { |
1150 | 126k | size_t maxlen; |
1151 | | |
1152 | 126k | printf (_("%c%" PRIu64 " byte block: "), delimiter, length); |
1153 | 126k | if (data > end) |
1154 | 0 | return (unsigned char *) end; |
1155 | | |
1156 | 126k | maxlen = end - data; |
1157 | 126k | length = length > maxlen ? maxlen : length; |
1158 | | |
1159 | 365k | while (length --) |
1160 | 239k | printf ("%" PRIx64 " ", byte_get (data++, 1)); |
1161 | | |
1162 | 126k | return data; |
1163 | 126k | } |
1164 | | |
1165 | | static int |
1166 | | decode_location_expression (unsigned char * data, |
1167 | | unsigned int pointer_size, |
1168 | | unsigned int offset_size, |
1169 | | int dwarf_version, |
1170 | | uint64_t length, |
1171 | | uint64_t cu_offset, |
1172 | | struct dwarf_section * section) |
1173 | 133k | { |
1174 | 133k | unsigned op; |
1175 | 133k | uint64_t uvalue; |
1176 | 133k | int64_t svalue; |
1177 | 133k | unsigned char *end = data + length; |
1178 | 133k | int need_frame_base = 0; |
1179 | | |
1180 | 336k | while (data < end) |
1181 | 205k | { |
1182 | 205k | op = *data++; |
1183 | | |
1184 | 205k | switch (op) |
1185 | 205k | { |
1186 | 7.26k | case DW_OP_addr: |
1187 | 7.26k | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1188 | 7.26k | printf ("DW_OP_addr: %" PRIx64, uvalue); |
1189 | 7.26k | break; |
1190 | 906 | case DW_OP_deref: |
1191 | 906 | printf ("DW_OP_deref"); |
1192 | 906 | break; |
1193 | 649 | case DW_OP_const1u: |
1194 | 649 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1195 | 649 | printf ("DW_OP_const1u: %" PRIu64, uvalue); |
1196 | 649 | break; |
1197 | 287 | case DW_OP_const1s: |
1198 | 287 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1199 | 287 | printf ("DW_OP_const1s: %" PRId64, svalue); |
1200 | 287 | break; |
1201 | 373 | case DW_OP_const2u: |
1202 | 373 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
1203 | 373 | printf ("DW_OP_const2u: %" PRIu64, uvalue); |
1204 | 373 | break; |
1205 | 486 | case DW_OP_const2s: |
1206 | 486 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1207 | 486 | printf ("DW_OP_const2s: %" PRId64, svalue); |
1208 | 486 | break; |
1209 | 136 | case DW_OP_const4u: |
1210 | 136 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1211 | 136 | printf ("DW_OP_const4u: %" PRIu64, uvalue); |
1212 | 136 | break; |
1213 | 246 | case DW_OP_const4s: |
1214 | 246 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1215 | 246 | printf ("DW_OP_const4s: %" PRId64, svalue); |
1216 | 246 | break; |
1217 | 93 | case DW_OP_const8u: |
1218 | 93 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
1219 | 93 | printf ("DW_OP_const8u: %" PRIu64, uvalue); |
1220 | 93 | break; |
1221 | 667 | case DW_OP_const8s: |
1222 | 667 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 8, end); |
1223 | 667 | printf ("DW_OP_const8s: %" PRId64, svalue); |
1224 | 667 | break; |
1225 | 10.8k | case DW_OP_constu: |
1226 | 10.8k | READ_ULEB (uvalue, data, end); |
1227 | 10.8k | printf ("DW_OP_constu: %" PRIu64, uvalue); |
1228 | 10.8k | break; |
1229 | 241 | case DW_OP_consts: |
1230 | 241 | READ_SLEB (svalue, data, end); |
1231 | 241 | printf ("DW_OP_consts: %" PRId64, svalue); |
1232 | 241 | break; |
1233 | 493 | case DW_OP_dup: |
1234 | 493 | printf ("DW_OP_dup"); |
1235 | 493 | break; |
1236 | 74 | case DW_OP_drop: |
1237 | 74 | printf ("DW_OP_drop"); |
1238 | 74 | break; |
1239 | 232 | case DW_OP_over: |
1240 | 232 | printf ("DW_OP_over"); |
1241 | 232 | break; |
1242 | 220 | case DW_OP_pick: |
1243 | 220 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1244 | 220 | printf ("DW_OP_pick: %" PRIu64, uvalue); |
1245 | 220 | break; |
1246 | 16.5k | case DW_OP_swap: |
1247 | 16.5k | printf ("DW_OP_swap"); |
1248 | 16.5k | break; |
1249 | 76 | case DW_OP_rot: |
1250 | 76 | printf ("DW_OP_rot"); |
1251 | 76 | break; |
1252 | 233 | case DW_OP_xderef: |
1253 | 233 | printf ("DW_OP_xderef"); |
1254 | 233 | break; |
1255 | 32 | case DW_OP_abs: |
1256 | 32 | printf ("DW_OP_abs"); |
1257 | 32 | break; |
1258 | 261 | case DW_OP_and: |
1259 | 261 | printf ("DW_OP_and"); |
1260 | 261 | break; |
1261 | 108 | case DW_OP_div: |
1262 | 108 | printf ("DW_OP_div"); |
1263 | 108 | break; |
1264 | 82 | case DW_OP_minus: |
1265 | 82 | printf ("DW_OP_minus"); |
1266 | 82 | break; |
1267 | 131 | case DW_OP_mod: |
1268 | 131 | printf ("DW_OP_mod"); |
1269 | 131 | break; |
1270 | 115 | case DW_OP_mul: |
1271 | 115 | printf ("DW_OP_mul"); |
1272 | 115 | break; |
1273 | 150 | case DW_OP_neg: |
1274 | 150 | printf ("DW_OP_neg"); |
1275 | 150 | break; |
1276 | 330 | case DW_OP_not: |
1277 | 330 | printf ("DW_OP_not"); |
1278 | 330 | break; |
1279 | 308 | case DW_OP_or: |
1280 | 308 | printf ("DW_OP_or"); |
1281 | 308 | break; |
1282 | 250 | case DW_OP_plus: |
1283 | 250 | printf ("DW_OP_plus"); |
1284 | 250 | break; |
1285 | 25.2k | case DW_OP_plus_uconst: |
1286 | 25.2k | READ_ULEB (uvalue, data, end); |
1287 | 25.2k | printf ("DW_OP_plus_uconst: %" PRIu64, uvalue); |
1288 | 25.2k | break; |
1289 | 291 | case DW_OP_shl: |
1290 | 291 | printf ("DW_OP_shl"); |
1291 | 291 | break; |
1292 | 38 | case DW_OP_shr: |
1293 | 38 | printf ("DW_OP_shr"); |
1294 | 38 | break; |
1295 | 99 | case DW_OP_shra: |
1296 | 99 | printf ("DW_OP_shra"); |
1297 | 99 | break; |
1298 | 115 | case DW_OP_xor: |
1299 | 115 | printf ("DW_OP_xor"); |
1300 | 115 | break; |
1301 | 317 | case DW_OP_bra: |
1302 | 317 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1303 | 317 | printf ("DW_OP_bra: %" PRId64, svalue); |
1304 | 317 | break; |
1305 | 244 | case DW_OP_eq: |
1306 | 244 | printf ("DW_OP_eq"); |
1307 | 244 | break; |
1308 | 362 | case DW_OP_ge: |
1309 | 362 | printf ("DW_OP_ge"); |
1310 | 362 | break; |
1311 | 189 | case DW_OP_gt: |
1312 | 189 | printf ("DW_OP_gt"); |
1313 | 189 | break; |
1314 | 230 | case DW_OP_le: |
1315 | 230 | printf ("DW_OP_le"); |
1316 | 230 | break; |
1317 | 502 | case DW_OP_lt: |
1318 | 502 | printf ("DW_OP_lt"); |
1319 | 502 | break; |
1320 | 459 | case DW_OP_ne: |
1321 | 459 | printf ("DW_OP_ne"); |
1322 | 459 | break; |
1323 | 161 | case DW_OP_skip: |
1324 | 161 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1325 | 161 | printf ("DW_OP_skip: %" PRId64, svalue); |
1326 | 161 | break; |
1327 | | |
1328 | 446 | case DW_OP_lit0: |
1329 | 813 | case DW_OP_lit1: |
1330 | 1.02k | case DW_OP_lit2: |
1331 | 1.35k | case DW_OP_lit3: |
1332 | 1.74k | case DW_OP_lit4: |
1333 | 2.02k | case DW_OP_lit5: |
1334 | 2.20k | case DW_OP_lit6: |
1335 | 2.37k | case DW_OP_lit7: |
1336 | 2.44k | case DW_OP_lit8: |
1337 | 2.56k | case DW_OP_lit9: |
1338 | 2.65k | case DW_OP_lit10: |
1339 | 3.10k | case DW_OP_lit11: |
1340 | 3.17k | case DW_OP_lit12: |
1341 | 3.21k | case DW_OP_lit13: |
1342 | 3.46k | case DW_OP_lit14: |
1343 | 3.95k | case DW_OP_lit15: |
1344 | 4.60k | case DW_OP_lit16: |
1345 | 4.68k | case DW_OP_lit17: |
1346 | 4.89k | case DW_OP_lit18: |
1347 | 5.01k | case DW_OP_lit19: |
1348 | 5.29k | case DW_OP_lit20: |
1349 | 5.34k | case DW_OP_lit21: |
1350 | 5.72k | case DW_OP_lit22: |
1351 | 6.12k | case DW_OP_lit23: |
1352 | 6.36k | case DW_OP_lit24: |
1353 | 6.54k | case DW_OP_lit25: |
1354 | 6.59k | case DW_OP_lit26: |
1355 | 6.61k | case DW_OP_lit27: |
1356 | 6.75k | case DW_OP_lit28: |
1357 | 6.91k | case DW_OP_lit29: |
1358 | 7.14k | case DW_OP_lit30: |
1359 | 7.36k | case DW_OP_lit31: |
1360 | 7.36k | printf ("DW_OP_lit%d", op - DW_OP_lit0); |
1361 | 7.36k | break; |
1362 | | |
1363 | 77 | case DW_OP_reg0: |
1364 | 3.22k | case DW_OP_reg1: |
1365 | 3.41k | case DW_OP_reg2: |
1366 | 4.12k | case DW_OP_reg3: |
1367 | 4.20k | case DW_OP_reg4: |
1368 | 4.31k | case DW_OP_reg5: |
1369 | 4.45k | case DW_OP_reg6: |
1370 | 4.59k | case DW_OP_reg7: |
1371 | 13.2k | case DW_OP_reg8: |
1372 | 15.3k | case DW_OP_reg9: |
1373 | 16.8k | case DW_OP_reg10: |
1374 | 18.9k | case DW_OP_reg11: |
1375 | 21.3k | case DW_OP_reg12: |
1376 | 24.7k | case DW_OP_reg13: |
1377 | 27.8k | case DW_OP_reg14: |
1378 | 28.8k | case DW_OP_reg15: |
1379 | 37.6k | case DW_OP_reg16: |
1380 | 42.2k | case DW_OP_reg17: |
1381 | 44.7k | case DW_OP_reg18: |
1382 | 46.7k | case DW_OP_reg19: |
1383 | 49.1k | case DW_OP_reg20: |
1384 | 50.7k | case DW_OP_reg21: |
1385 | 51.8k | case DW_OP_reg22: |
1386 | 53.3k | case DW_OP_reg23: |
1387 | 63.4k | case DW_OP_reg24: |
1388 | 72.2k | case DW_OP_reg25: |
1389 | 76.3k | case DW_OP_reg26: |
1390 | 79.4k | case DW_OP_reg27: |
1391 | 81.2k | case DW_OP_reg28: |
1392 | 82.8k | case DW_OP_reg29: |
1393 | 95.3k | case DW_OP_reg30: |
1394 | 95.7k | case DW_OP_reg31: |
1395 | 95.7k | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1396 | 95.7k | regname (op - DW_OP_reg0, 1)); |
1397 | 95.7k | break; |
1398 | | |
1399 | 159 | case DW_OP_breg0: |
1400 | 399 | case DW_OP_breg1: |
1401 | 794 | case DW_OP_breg2: |
1402 | 1.17k | case DW_OP_breg3: |
1403 | 1.33k | case DW_OP_breg4: |
1404 | 1.57k | case DW_OP_breg5: |
1405 | 1.65k | case DW_OP_breg6: |
1406 | 2.33k | case DW_OP_breg7: |
1407 | 2.59k | case DW_OP_breg8: |
1408 | 3.18k | case DW_OP_breg9: |
1409 | 3.88k | case DW_OP_breg10: |
1410 | 3.90k | case DW_OP_breg11: |
1411 | 3.95k | case DW_OP_breg12: |
1412 | 3.98k | case DW_OP_breg13: |
1413 | 4.12k | case DW_OP_breg14: |
1414 | 4.61k | case DW_OP_breg15: |
1415 | 4.84k | case DW_OP_breg16: |
1416 | 4.89k | case DW_OP_breg17: |
1417 | 4.91k | case DW_OP_breg18: |
1418 | 4.95k | case DW_OP_breg19: |
1419 | 4.98k | case DW_OP_breg20: |
1420 | 5.02k | case DW_OP_breg21: |
1421 | 5.29k | case DW_OP_breg22: |
1422 | 5.30k | case DW_OP_breg23: |
1423 | 5.33k | case DW_OP_breg24: |
1424 | 5.36k | case DW_OP_breg25: |
1425 | 5.38k | case DW_OP_breg26: |
1426 | 5.41k | case DW_OP_breg27: |
1427 | 5.43k | case DW_OP_breg28: |
1428 | 5.49k | case DW_OP_breg29: |
1429 | 5.56k | case DW_OP_breg30: |
1430 | 5.61k | case DW_OP_breg31: |
1431 | 5.61k | READ_SLEB (svalue, data, end); |
1432 | 5.61k | printf ("DW_OP_breg%d (%s): %" PRId64, |
1433 | 5.61k | op - DW_OP_breg0, regname (op - DW_OP_breg0, 1), svalue); |
1434 | 5.61k | break; |
1435 | | |
1436 | 704 | case DW_OP_regx: |
1437 | 704 | READ_ULEB (uvalue, data, end); |
1438 | 704 | printf ("DW_OP_regx: %" PRIu64 " (%s)", |
1439 | 704 | uvalue, regname (uvalue, 1)); |
1440 | 704 | break; |
1441 | 12.2k | case DW_OP_fbreg: |
1442 | 12.2k | need_frame_base = 1; |
1443 | 12.2k | READ_SLEB (svalue, data, end); |
1444 | 12.2k | printf ("DW_OP_fbreg: %" PRId64, svalue); |
1445 | 12.2k | break; |
1446 | 206 | case DW_OP_bregx: |
1447 | 206 | READ_ULEB (uvalue, data, end); |
1448 | 206 | READ_SLEB (svalue, data, end); |
1449 | 206 | printf ("DW_OP_bregx: %" PRIu64 " (%s) %" PRId64, |
1450 | 206 | uvalue, regname (uvalue, 1), svalue); |
1451 | 206 | break; |
1452 | 5.21k | case DW_OP_piece: |
1453 | 5.21k | READ_ULEB (uvalue, data, end); |
1454 | 5.21k | printf ("DW_OP_piece: %" PRIu64, uvalue); |
1455 | 5.21k | break; |
1456 | 120 | case DW_OP_deref_size: |
1457 | 120 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1458 | 120 | printf ("DW_OP_deref_size: %" PRIu64, uvalue); |
1459 | 120 | break; |
1460 | 178 | case DW_OP_xderef_size: |
1461 | 178 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1462 | 178 | printf ("DW_OP_xderef_size: %" PRIu64, uvalue); |
1463 | 178 | break; |
1464 | 393 | case DW_OP_nop: |
1465 | 393 | printf ("DW_OP_nop"); |
1466 | 393 | break; |
1467 | | |
1468 | | /* DWARF 3 extensions. */ |
1469 | 525 | case DW_OP_push_object_address: |
1470 | 525 | printf ("DW_OP_push_object_address"); |
1471 | 525 | break; |
1472 | 109 | case DW_OP_call2: |
1473 | | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
1474 | | this ought to be an 8-byte wide computation. */ |
1475 | 109 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1476 | 109 | printf ("DW_OP_call2: <%#" PRIx64 ">", svalue + cu_offset); |
1477 | 109 | break; |
1478 | 351 | case DW_OP_call4: |
1479 | | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
1480 | | this ought to be an 8-byte wide computation. */ |
1481 | 351 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1482 | 351 | printf ("DW_OP_call4: <%#" PRIx64 ">", svalue + cu_offset); |
1483 | 351 | break; |
1484 | 16 | case DW_OP_call_ref: |
1485 | | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
1486 | | this ought to be an 8-byte wide computation. */ |
1487 | 16 | if (dwarf_version == -1) |
1488 | 16 | { |
1489 | 16 | printf (_("(DW_OP_call_ref in frame info)")); |
1490 | | /* No way to tell where the next op is, so just bail. */ |
1491 | 16 | return need_frame_base; |
1492 | 16 | } |
1493 | 0 | if (dwarf_version == 2) |
1494 | 0 | { |
1495 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1496 | 0 | } |
1497 | 0 | else |
1498 | 0 | { |
1499 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1500 | 0 | } |
1501 | 0 | printf ("DW_OP_call_ref: <%#" PRIx64 ">", uvalue); |
1502 | 0 | break; |
1503 | 86 | case DW_OP_form_tls_address: |
1504 | 86 | printf ("DW_OP_form_tls_address"); |
1505 | 86 | break; |
1506 | 109 | case DW_OP_call_frame_cfa: |
1507 | 109 | printf ("DW_OP_call_frame_cfa"); |
1508 | 109 | break; |
1509 | 64 | case DW_OP_bit_piece: |
1510 | 64 | printf ("DW_OP_bit_piece: "); |
1511 | 64 | READ_ULEB (uvalue, data, end); |
1512 | 64 | printf (_("size: %" PRIu64 " "), uvalue); |
1513 | 64 | READ_ULEB (uvalue, data, end); |
1514 | 64 | printf (_("offset: %" PRIu64 " "), uvalue); |
1515 | 64 | break; |
1516 | | |
1517 | | /* DWARF 4 extensions. */ |
1518 | 308 | case DW_OP_stack_value: |
1519 | 308 | printf ("DW_OP_stack_value"); |
1520 | 308 | break; |
1521 | | |
1522 | 63 | case DW_OP_implicit_value: |
1523 | 63 | printf ("DW_OP_implicit_value"); |
1524 | 63 | READ_ULEB (uvalue, data, end); |
1525 | 63 | data = display_block (data, uvalue, end, ' '); |
1526 | 63 | break; |
1527 | | |
1528 | | /* GNU extensions. */ |
1529 | 203 | case DW_OP_GNU_push_tls_address: |
1530 | 203 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
1531 | 203 | break; |
1532 | 309 | case DW_OP_GNU_uninit: |
1533 | 309 | printf ("DW_OP_GNU_uninit"); |
1534 | | /* FIXME: Is there data associated with this OP ? */ |
1535 | 309 | break; |
1536 | 181 | case DW_OP_GNU_encoded_addr: |
1537 | 181 | { |
1538 | 181 | int encoding = 0; |
1539 | 181 | uint64_t addr; |
1540 | | |
1541 | 181 | if (data < end) |
1542 | 173 | encoding = *data++; |
1543 | 181 | addr = get_encoded_value (&data, encoding, section, end); |
1544 | | |
1545 | 181 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); |
1546 | 181 | print_hex_ns (addr, pointer_size); |
1547 | 181 | } |
1548 | 181 | break; |
1549 | 8 | case DW_OP_implicit_pointer: |
1550 | 27 | case DW_OP_GNU_implicit_pointer: |
1551 | | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
1552 | | this ought to be an 8-byte wide computation. */ |
1553 | 27 | if (dwarf_version == -1) |
1554 | 26 | { |
1555 | 26 | printf (_("(%s in frame info)"), |
1556 | 26 | (op == DW_OP_implicit_pointer |
1557 | 26 | ? "DW_OP_implicit_pointer" |
1558 | 26 | : "DW_OP_GNU_implicit_pointer")); |
1559 | | /* No way to tell where the next op is, so just bail. */ |
1560 | 26 | return need_frame_base; |
1561 | 26 | } |
1562 | 1 | if (dwarf_version == 2) |
1563 | 1 | { |
1564 | 1 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1565 | 1 | } |
1566 | 0 | else |
1567 | 0 | { |
1568 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1569 | 0 | } |
1570 | 1 | READ_SLEB (svalue, data, end); |
1571 | 1 | printf ("%s: <%#" PRIx64 "> %" PRId64, |
1572 | 1 | (op == DW_OP_implicit_pointer |
1573 | 1 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), |
1574 | 1 | uvalue, svalue); |
1575 | 1 | break; |
1576 | 39 | case DW_OP_entry_value: |
1577 | 186 | case DW_OP_GNU_entry_value: |
1578 | 186 | READ_ULEB (uvalue, data, end); |
1579 | | /* PR 17531: file: 0cc9cd00. */ |
1580 | 186 | if (uvalue > (size_t) (end - data)) |
1581 | 173 | uvalue = end - data; |
1582 | 186 | printf ("%s: (", (op == DW_OP_entry_value |
1583 | 186 | ? "DW_OP_entry_value" : "DW_OP_GNU_entry_value")); |
1584 | 186 | if (decode_location_expression (data, pointer_size, offset_size, |
1585 | 186 | dwarf_version, uvalue, |
1586 | 186 | cu_offset, section)) |
1587 | 42 | need_frame_base = 1; |
1588 | 186 | putchar (')'); |
1589 | 186 | data += uvalue; |
1590 | 186 | break; |
1591 | 28 | case DW_OP_const_type: |
1592 | 126 | case DW_OP_GNU_const_type: |
1593 | 126 | READ_ULEB (uvalue, data, end); |
1594 | 126 | printf ("%s: <%#" PRIx64 "> ", |
1595 | 126 | (op == DW_OP_const_type |
1596 | 126 | ? "DW_OP_const_type" : "DW_OP_GNU_const_type"), |
1597 | 126 | cu_offset + uvalue); |
1598 | 126 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1599 | 126 | data = display_block (data, uvalue, end, ' '); |
1600 | 126 | break; |
1601 | 31 | case DW_OP_regval_type: |
1602 | 258 | case DW_OP_GNU_regval_type: |
1603 | 258 | READ_ULEB (uvalue, data, end); |
1604 | 258 | printf ("%s: %" PRIu64 " (%s)", |
1605 | 258 | (op == DW_OP_regval_type |
1606 | 258 | ? "DW_OP_regval_type" : "DW_OP_GNU_regval_type"), |
1607 | 258 | uvalue, regname (uvalue, 1)); |
1608 | 258 | READ_ULEB (uvalue, data, end); |
1609 | 258 | printf (" <%#" PRIx64 ">", cu_offset + uvalue); |
1610 | 258 | break; |
1611 | 32 | case DW_OP_deref_type: |
1612 | 79 | case DW_OP_GNU_deref_type: |
1613 | 79 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1614 | 79 | printf ("%s: %" PRId64, |
1615 | 79 | (op == DW_OP_deref_type |
1616 | 79 | ? "DW_OP_deref_type" : "DW_OP_GNU_deref_type"), |
1617 | 79 | uvalue); |
1618 | 79 | READ_ULEB (uvalue, data, end); |
1619 | 79 | printf (" <%#" PRIx64 ">", cu_offset + uvalue); |
1620 | 79 | break; |
1621 | 27 | case DW_OP_convert: |
1622 | 57 | case DW_OP_GNU_convert: |
1623 | 57 | READ_ULEB (uvalue, data, end); |
1624 | 57 | printf ("%s <%#" PRIx64 ">", |
1625 | 57 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), |
1626 | 57 | uvalue ? cu_offset + uvalue : uvalue); |
1627 | 57 | break; |
1628 | 68 | case DW_OP_reinterpret: |
1629 | 257 | case DW_OP_GNU_reinterpret: |
1630 | 257 | READ_ULEB (uvalue, data, end); |
1631 | 257 | printf ("%s <%#" PRIx64 ">", |
1632 | 257 | (op == DW_OP_reinterpret |
1633 | 257 | ? "DW_OP_reinterpret" : "DW_OP_GNU_reinterpret"), |
1634 | 257 | uvalue ? cu_offset + uvalue : uvalue); |
1635 | 257 | break; |
1636 | 212 | case DW_OP_GNU_parameter_ref: |
1637 | 212 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1638 | 212 | printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64 ">", |
1639 | 212 | cu_offset + uvalue); |
1640 | 212 | break; |
1641 | 72 | case DW_OP_addrx: |
1642 | 72 | READ_ULEB (uvalue, data, end); |
1643 | 72 | printf ("DW_OP_addrx <%#" PRIx64 ">", uvalue); |
1644 | 72 | break; |
1645 | 85 | case DW_OP_GNU_addr_index: |
1646 | 85 | READ_ULEB (uvalue, data, end); |
1647 | 85 | printf ("DW_OP_GNU_addr_index <%#" PRIx64 ">", uvalue); |
1648 | 85 | break; |
1649 | 170 | case DW_OP_GNU_const_index: |
1650 | 170 | READ_ULEB (uvalue, data, end); |
1651 | 170 | printf ("DW_OP_GNU_const_index <%#" PRIx64 ">", uvalue); |
1652 | 170 | break; |
1653 | 44 | case DW_OP_GNU_variable_value: |
1654 | | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
1655 | | this ought to be an 8-byte wide computation. */ |
1656 | 44 | if (dwarf_version == -1) |
1657 | 44 | { |
1658 | 44 | printf (_("(DW_OP_GNU_variable_value in frame info)")); |
1659 | | /* No way to tell where the next op is, so just bail. */ |
1660 | 44 | return need_frame_base; |
1661 | 44 | } |
1662 | 0 | if (dwarf_version == 2) |
1663 | 0 | { |
1664 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1665 | 0 | } |
1666 | 0 | else |
1667 | 0 | { |
1668 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1669 | 0 | } |
1670 | 0 | printf ("DW_OP_GNU_variable_value: <%#" PRIx64 ">", uvalue); |
1671 | 0 | break; |
1672 | | |
1673 | | /* HP extensions. */ |
1674 | 153 | case DW_OP_HP_is_value: |
1675 | 153 | printf ("DW_OP_HP_is_value"); |
1676 | | /* FIXME: Is there data associated with this OP ? */ |
1677 | 153 | break; |
1678 | 250 | case DW_OP_HP_fltconst4: |
1679 | 250 | printf ("DW_OP_HP_fltconst4"); |
1680 | | /* FIXME: Is there data associated with this OP ? */ |
1681 | 250 | break; |
1682 | 117 | case DW_OP_HP_fltconst8: |
1683 | 117 | printf ("DW_OP_HP_fltconst8"); |
1684 | | /* FIXME: Is there data associated with this OP ? */ |
1685 | 117 | break; |
1686 | 96 | case DW_OP_HP_mod_range: |
1687 | 96 | printf ("DW_OP_HP_mod_range"); |
1688 | | /* FIXME: Is there data associated with this OP ? */ |
1689 | 96 | break; |
1690 | 543 | case DW_OP_HP_unmod_range: |
1691 | 543 | printf ("DW_OP_HP_unmod_range"); |
1692 | | /* FIXME: Is there data associated with this OP ? */ |
1693 | 543 | break; |
1694 | 235 | case DW_OP_HP_tls: |
1695 | 235 | printf ("DW_OP_HP_tls"); |
1696 | | /* FIXME: Is there data associated with this OP ? */ |
1697 | 235 | break; |
1698 | | |
1699 | | /* PGI (STMicroelectronics) extensions. */ |
1700 | 53 | case DW_OP_PGI_omp_thread_num: |
1701 | | /* Pushes the thread number for the current thread as it would be |
1702 | | returned by the standard OpenMP library function: |
1703 | | omp_get_thread_num(). The "current thread" is the thread for |
1704 | | which the expression is being evaluated. */ |
1705 | 53 | printf ("DW_OP_PGI_omp_thread_num"); |
1706 | 53 | break; |
1707 | | |
1708 | 2.40k | default: |
1709 | 2.40k | if (op >= DW_OP_lo_user |
1710 | 2.40k | && op <= DW_OP_hi_user) |
1711 | 423 | printf (_("(User defined location op %#x)"), op); |
1712 | 1.98k | else |
1713 | 1.98k | printf (_("(Unknown location op %#x)"), op); |
1714 | | /* No way to tell where the next op is, so just bail. */ |
1715 | 2.40k | return need_frame_base; |
1716 | 205k | } |
1717 | | |
1718 | | /* Separate the ops. */ |
1719 | 203k | if (data < end) |
1720 | 73.6k | printf ("; "); |
1721 | 203k | } |
1722 | | |
1723 | 130k | return need_frame_base; |
1724 | 133k | } |
1725 | | |
1726 | | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1727 | | This is used for DWARF package files. */ |
1728 | | |
1729 | | static struct cu_tu_set * |
1730 | | find_cu_tu_set_v2 (uint64_t cu_offset, int do_types) |
1731 | 101k | { |
1732 | 101k | struct cu_tu_set *p; |
1733 | 101k | unsigned int nsets; |
1734 | 101k | unsigned int dw_sect; |
1735 | | |
1736 | 101k | if (do_types) |
1737 | 543 | { |
1738 | 543 | p = tu_sets; |
1739 | 543 | nsets = tu_count; |
1740 | 543 | dw_sect = DW_SECT_TYPES; |
1741 | 543 | } |
1742 | 101k | else |
1743 | 101k | { |
1744 | 101k | p = cu_sets; |
1745 | 101k | nsets = cu_count; |
1746 | 101k | dw_sect = DW_SECT_INFO; |
1747 | 101k | } |
1748 | 101k | while (nsets > 0) |
1749 | 0 | { |
1750 | 0 | if (p->section_offsets [dw_sect] == cu_offset) |
1751 | 0 | return p; |
1752 | 0 | p++; |
1753 | 0 | nsets--; |
1754 | 0 | } |
1755 | 101k | return NULL; |
1756 | 101k | } |
1757 | | |
1758 | | static const char * |
1759 | | fetch_alt_indirect_string (uint64_t offset) |
1760 | 14 | { |
1761 | 14 | separate_info * i; |
1762 | | |
1763 | 14 | if (! do_follow_links) |
1764 | 14 | return ""; |
1765 | | |
1766 | 0 | if (first_separate_info == NULL) |
1767 | 0 | return _("<no links available>"); |
1768 | | |
1769 | 0 | for (i = first_separate_info; i != NULL; i = i->next) |
1770 | 0 | { |
1771 | 0 | struct dwarf_section * section; |
1772 | 0 | const char * ret; |
1773 | |
|
1774 | 0 | if (! load_debug_section (separate_debug_str, i->handle)) |
1775 | 0 | continue; |
1776 | | |
1777 | 0 | section = &debug_displays [separate_debug_str].section; |
1778 | |
|
1779 | 0 | if (section->start == NULL) |
1780 | 0 | continue; |
1781 | | |
1782 | 0 | if (offset >= section->size) |
1783 | 0 | continue; |
1784 | | |
1785 | 0 | ret = (const char *) (section->start + offset); |
1786 | | /* Unfortunately we cannot rely upon the .debug_str section ending with a |
1787 | | NUL byte. Since our caller is expecting to receive a well formed C |
1788 | | string we test for the lack of a terminating byte here. */ |
1789 | 0 | if (strnlen ((const char *) ret, section->size - offset) |
1790 | 0 | == section->size - offset) |
1791 | 0 | return _("<no NUL byte at end of alt .debug_str section>"); |
1792 | | |
1793 | 0 | return ret; |
1794 | 0 | } |
1795 | | |
1796 | 0 | warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64 ")" |
1797 | 0 | " too big or no string sections available\n"), offset); |
1798 | 0 | return _("<offset is too big>"); |
1799 | 0 | } |
1800 | | |
1801 | | static const char * |
1802 | | get_AT_name (unsigned long attribute) |
1803 | 6.95M | { |
1804 | 6.95M | const char *name; |
1805 | | |
1806 | 6.95M | if (attribute == 0) |
1807 | 1.11M | return "DW_AT value: 0"; |
1808 | | |
1809 | | /* One value is shared by the MIPS and HP extensions: */ |
1810 | 5.83M | if (attribute == DW_AT_MIPS_fde) |
1811 | 27 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; |
1812 | | |
1813 | 5.83M | name = get_DW_AT_name (attribute); |
1814 | | |
1815 | 5.83M | if (name == NULL) |
1816 | 1.59M | { |
1817 | 1.59M | static char buffer[100]; |
1818 | | |
1819 | 1.59M | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), |
1820 | 1.59M | attribute); |
1821 | 1.59M | return buffer; |
1822 | 1.59M | } |
1823 | | |
1824 | 4.24M | return name; |
1825 | 5.83M | } |
1826 | | |
1827 | | static void |
1828 | | add_dwo_info (const char * value, uint64_t cu_offset, dwo_type type) |
1829 | 0 | { |
1830 | 0 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); |
1831 | |
|
1832 | 0 | dwinfo->type = type; |
1833 | 0 | dwinfo->value = value; |
1834 | 0 | dwinfo->cu_offset = cu_offset; |
1835 | 0 | dwinfo->next = first_dwo_info; |
1836 | 0 | first_dwo_info = dwinfo; |
1837 | 0 | } |
1838 | | |
1839 | | static void |
1840 | | add_dwo_name (const char * name, uint64_t cu_offset) |
1841 | 0 | { |
1842 | 0 | add_dwo_info (name, cu_offset, DWO_NAME); |
1843 | 0 | } |
1844 | | |
1845 | | static void |
1846 | | add_dwo_dir (const char * dir, uint64_t cu_offset) |
1847 | 0 | { |
1848 | 0 | add_dwo_info (dir, cu_offset, DWO_DIR); |
1849 | 0 | } |
1850 | | |
1851 | | static void |
1852 | | add_dwo_id (const char * id, uint64_t cu_offset) |
1853 | 0 | { |
1854 | 0 | add_dwo_info (id, cu_offset, DWO_ID); |
1855 | 0 | } |
1856 | | |
1857 | | static void |
1858 | | free_dwo_info (void) |
1859 | 129k | { |
1860 | 129k | dwo_info * dwinfo; |
1861 | 129k | dwo_info * next; |
1862 | | |
1863 | 129k | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) |
1864 | 0 | { |
1865 | 0 | next = dwinfo->next; |
1866 | 0 | free (dwinfo); |
1867 | 0 | } |
1868 | 129k | first_dwo_info = NULL; |
1869 | 129k | } |
1870 | | |
1871 | | /* Ensure that START + UVALUE is less than END. |
1872 | | Return an adjusted UVALUE if necessary to ensure this relationship. */ |
1873 | | |
1874 | | static inline uint64_t |
1875 | | check_uvalue (const unsigned char *start, |
1876 | | uint64_t uvalue, |
1877 | | const unsigned char *end) |
1878 | 126k | { |
1879 | 126k | uint64_t max_uvalue = end - start; |
1880 | | |
1881 | | /* See PR 17512: file: 008-103549-0.001:0.1. |
1882 | | and PR 24829 for examples of where these tests are triggered. */ |
1883 | 126k | if (uvalue > max_uvalue) |
1884 | 102 | { |
1885 | 102 | warn (_("Corrupt attribute block length: %#" PRIx64 "\n"), uvalue); |
1886 | 102 | uvalue = max_uvalue; |
1887 | 102 | } |
1888 | | |
1889 | 126k | return uvalue; |
1890 | 126k | } |
1891 | | |
1892 | | static unsigned char * |
1893 | | skip_attr_bytes (unsigned long form, |
1894 | | unsigned char *data, |
1895 | | unsigned char *end, |
1896 | | uint64_t pointer_size, |
1897 | | uint64_t offset_size, |
1898 | | int dwarf_version, |
1899 | | uint64_t *value_return) |
1900 | 896k | { |
1901 | 896k | int64_t svalue; |
1902 | 896k | uint64_t uvalue = 0; |
1903 | 896k | uint64_t inc = 0; |
1904 | | |
1905 | 896k | * value_return = 0; |
1906 | | |
1907 | 896k | switch (form) |
1908 | 896k | { |
1909 | 0 | case DW_FORM_ref_addr: |
1910 | 0 | if (dwarf_version == 2) |
1911 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1912 | 0 | else if (dwarf_version > 2) |
1913 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1914 | 0 | else |
1915 | 0 | return NULL; |
1916 | 0 | break; |
1917 | | |
1918 | 8 | case DW_FORM_addr: |
1919 | 8 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1920 | 8 | break; |
1921 | | |
1922 | 161k | case DW_FORM_strp: |
1923 | 161k | case DW_FORM_line_strp: |
1924 | 161k | case DW_FORM_sec_offset: |
1925 | 161k | case DW_FORM_GNU_ref_alt: |
1926 | 161k | case DW_FORM_GNU_strp_alt: |
1927 | 161k | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1928 | 161k | break; |
1929 | | |
1930 | 161k | case DW_FORM_flag_present: |
1931 | 48 | uvalue = 1; |
1932 | 48 | break; |
1933 | | |
1934 | 0 | case DW_FORM_ref1: |
1935 | 3.89k | case DW_FORM_flag: |
1936 | 480k | case DW_FORM_data1: |
1937 | 480k | case DW_FORM_strx1: |
1938 | 480k | case DW_FORM_addrx1: |
1939 | 480k | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1940 | 480k | break; |
1941 | | |
1942 | 480k | case DW_FORM_strx3: |
1943 | 0 | case DW_FORM_addrx3: |
1944 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); |
1945 | 0 | break; |
1946 | | |
1947 | 0 | case DW_FORM_ref2: |
1948 | 25.1k | case DW_FORM_data2: |
1949 | 25.1k | case DW_FORM_strx2: |
1950 | 25.1k | case DW_FORM_addrx2: |
1951 | 25.1k | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
1952 | 25.1k | break; |
1953 | | |
1954 | 186k | case DW_FORM_ref4: |
1955 | 186k | case DW_FORM_data4: |
1956 | 186k | case DW_FORM_strx4: |
1957 | 186k | case DW_FORM_addrx4: |
1958 | 186k | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1959 | 186k | break; |
1960 | | |
1961 | 186k | case DW_FORM_sdata: |
1962 | 0 | READ_SLEB (svalue, data, end); |
1963 | 0 | uvalue = svalue; |
1964 | 0 | break; |
1965 | | |
1966 | 0 | case DW_FORM_ref_udata: |
1967 | 0 | case DW_FORM_udata: |
1968 | 0 | case DW_FORM_GNU_str_index: |
1969 | 0 | case DW_FORM_strx: |
1970 | 0 | case DW_FORM_GNU_addr_index: |
1971 | 0 | case DW_FORM_addrx: |
1972 | 0 | case DW_FORM_loclistx: |
1973 | 0 | case DW_FORM_rnglistx: |
1974 | 0 | READ_ULEB (uvalue, data, end); |
1975 | 0 | break; |
1976 | | |
1977 | 0 | case DW_FORM_ref8: |
1978 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
1979 | 0 | break; |
1980 | | |
1981 | 0 | case DW_FORM_data8: |
1982 | 39 | case DW_FORM_ref_sig8: |
1983 | 39 | inc = 8; |
1984 | 39 | break; |
1985 | | |
1986 | 0 | case DW_FORM_data16: |
1987 | 0 | inc = 16; |
1988 | 0 | break; |
1989 | | |
1990 | 41.7k | case DW_FORM_string: |
1991 | 41.7k | inc = strnlen ((char *) data, end - data) + 1; |
1992 | 41.7k | break; |
1993 | | |
1994 | 0 | case DW_FORM_block: |
1995 | 0 | case DW_FORM_exprloc: |
1996 | 0 | READ_ULEB (uvalue, data, end); |
1997 | 0 | inc = uvalue; |
1998 | 0 | break; |
1999 | | |
2000 | 7 | case DW_FORM_block1: |
2001 | 7 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2002 | 7 | inc = uvalue; |
2003 | 7 | break; |
2004 | | |
2005 | 0 | case DW_FORM_block2: |
2006 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2007 | 0 | inc = uvalue; |
2008 | 0 | break; |
2009 | | |
2010 | 0 | case DW_FORM_block4: |
2011 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2012 | 0 | inc = uvalue; |
2013 | 0 | break; |
2014 | | |
2015 | 0 | case DW_FORM_indirect: |
2016 | 0 | READ_ULEB (form, data, end); |
2017 | 0 | if (form == DW_FORM_implicit_const) |
2018 | 0 | SKIP_ULEB (data, end); |
2019 | 0 | return skip_attr_bytes (form, data, end, pointer_size, offset_size, |
2020 | 0 | dwarf_version, value_return); |
2021 | | |
2022 | 201 | default: |
2023 | 201 | return NULL; |
2024 | 896k | } |
2025 | | |
2026 | 896k | * value_return = uvalue; |
2027 | 896k | if (inc <= (size_t) (end - data)) |
2028 | 896k | data += inc; |
2029 | 0 | else |
2030 | 0 | data = end; |
2031 | 896k | return data; |
2032 | 896k | } |
2033 | | |
2034 | | /* Given form FORM with value UVALUE, locate and return the abbreviation |
2035 | | associated with it. */ |
2036 | | |
2037 | | static abbrev_entry * |
2038 | | get_type_abbrev_from_form (unsigned long form, |
2039 | | uint64_t uvalue, |
2040 | | uint64_t cu_offset, |
2041 | | unsigned char *cu_end, |
2042 | | const struct dwarf_section *section, |
2043 | | unsigned long *abbrev_num_return, |
2044 | | unsigned char **data_return, |
2045 | | abbrev_map **map_return) |
2046 | 318k | { |
2047 | 318k | switch (form) |
2048 | 318k | { |
2049 | 0 | case DW_FORM_GNU_ref_alt: |
2050 | 18 | case DW_FORM_ref_sig8: |
2051 | | /* FIXME: We are unable to handle this form at the moment. */ |
2052 | 18 | return NULL; |
2053 | | |
2054 | 0 | case DW_FORM_ref_addr: |
2055 | 0 | if (uvalue >= section->size) |
2056 | 0 | { |
2057 | 0 | warn (_("Unable to resolve ref_addr form: uvalue %" PRIx64 |
2058 | 0 | " >= section size %" PRIx64 " (%s)\n"), |
2059 | 0 | uvalue, section->size, section->name); |
2060 | 0 | return NULL; |
2061 | 0 | } |
2062 | 0 | break; |
2063 | | |
2064 | 0 | case DW_FORM_ref_sup4: |
2065 | 0 | case DW_FORM_ref_sup8: |
2066 | 0 | break; |
2067 | | |
2068 | 0 | case DW_FORM_ref1: |
2069 | 0 | case DW_FORM_ref2: |
2070 | 318k | case DW_FORM_ref4: |
2071 | 318k | case DW_FORM_ref8: |
2072 | 318k | case DW_FORM_ref_udata: |
2073 | 318k | if (uvalue + cu_offset < uvalue |
2074 | 318k | || uvalue + cu_offset > (size_t) (cu_end - section->start)) |
2075 | 50 | { |
2076 | 50 | warn (_("Unable to resolve ref form: uvalue %" PRIx64 |
2077 | 50 | " + cu_offset %" PRIx64 " > CU size %tx\n"), |
2078 | 50 | uvalue, cu_offset, cu_end - section->start); |
2079 | 50 | return NULL; |
2080 | 50 | } |
2081 | 318k | uvalue += cu_offset; |
2082 | 318k | break; |
2083 | | |
2084 | | /* FIXME: Are there other DW_FORMs that can be used by types ? */ |
2085 | | |
2086 | 10 | default: |
2087 | 10 | warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form); |
2088 | 10 | return NULL; |
2089 | 318k | } |
2090 | | |
2091 | 318k | abbrev_map *map = find_abbrev_map_by_offset (uvalue); |
2092 | | |
2093 | 318k | if (map == NULL) |
2094 | 0 | { |
2095 | 0 | warn (_("Unable to find abbreviations for CU offset %" PRIx64 "\n"), |
2096 | 0 | uvalue); |
2097 | 0 | return NULL; |
2098 | 0 | } |
2099 | 318k | if (map->list == NULL) |
2100 | 0 | { |
2101 | 0 | warn (_("Empty abbreviation list encountered for CU offset %" PRIx64 "\n"), |
2102 | 0 | uvalue); |
2103 | 0 | return NULL; |
2104 | 0 | } |
2105 | | |
2106 | 318k | if (map_return != NULL) |
2107 | 318k | { |
2108 | 318k | if (form == DW_FORM_ref_addr) |
2109 | 0 | *map_return = map; |
2110 | 318k | else |
2111 | 318k | *map_return = NULL; |
2112 | 318k | } |
2113 | | |
2114 | 318k | unsigned char *data = section->start + uvalue; |
2115 | 318k | if (form == DW_FORM_ref_addr) |
2116 | 0 | cu_end = section->start + map->end; |
2117 | | |
2118 | 318k | unsigned long abbrev_number; |
2119 | 318k | READ_ULEB (abbrev_number, data, cu_end); |
2120 | | |
2121 | 318k | if (abbrev_num_return != NULL) |
2122 | 0 | *abbrev_num_return = abbrev_number; |
2123 | | |
2124 | 318k | if (data_return != NULL) |
2125 | 318k | *data_return = data; |
2126 | | |
2127 | 318k | abbrev_entry *entry; |
2128 | 2.82M | for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next) |
2129 | 2.82M | if (entry->number == abbrev_number) |
2130 | 318k | break; |
2131 | | |
2132 | 318k | if (entry == NULL) |
2133 | 103 | warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number); |
2134 | | |
2135 | 318k | return entry; |
2136 | 318k | } |
2137 | | |
2138 | | /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY |
2139 | | can be determined to be a signed type. The data for ENTRY can be |
2140 | | found starting at DATA. */ |
2141 | | |
2142 | | static void |
2143 | | get_type_signedness (abbrev_entry *entry, |
2144 | | const struct dwarf_section *section, |
2145 | | unsigned char *data, |
2146 | | unsigned char *end, |
2147 | | uint64_t cu_offset, |
2148 | | uint64_t pointer_size, |
2149 | | uint64_t offset_size, |
2150 | | int dwarf_version, |
2151 | | bool *is_signed, |
2152 | | unsigned int nesting) |
2153 | 318k | { |
2154 | 318k | abbrev_attr * attr; |
2155 | | |
2156 | 318k | * is_signed = false; |
2157 | | |
2158 | 318k | #define MAX_NESTING 20 |
2159 | 318k | if (nesting > MAX_NESTING) |
2160 | 0 | { |
2161 | | /* FIXME: Warn - or is this expected ? |
2162 | | NB/ We need to avoid infinite recursion. */ |
2163 | 0 | return; |
2164 | 0 | } |
2165 | | |
2166 | 318k | for (attr = entry->first_attr; |
2167 | 1.21M | attr != NULL && attr->attribute; |
2168 | 896k | attr = attr->next) |
2169 | 896k | { |
2170 | 896k | unsigned char * orig_data = data; |
2171 | 896k | uint64_t uvalue = 0; |
2172 | | |
2173 | 896k | data = skip_attr_bytes (attr->form, data, end, pointer_size, |
2174 | 896k | offset_size, dwarf_version, & uvalue); |
2175 | 896k | if (data == NULL) |
2176 | 201 | return; |
2177 | | |
2178 | 896k | switch (attr->attribute) |
2179 | 896k | { |
2180 | 0 | case DW_AT_linkage_name: |
2181 | 203k | case DW_AT_name: |
2182 | 203k | if (do_wide) |
2183 | 0 | { |
2184 | 0 | if (attr->form == DW_FORM_strp) |
2185 | 0 | printf (", %s", fetch_indirect_string (uvalue)); |
2186 | 0 | else if (attr->form == DW_FORM_string) |
2187 | 0 | printf (", %.*s", (int) (end - orig_data), orig_data); |
2188 | 0 | } |
2189 | 203k | break; |
2190 | | |
2191 | 144k | case DW_AT_type: |
2192 | | /* Recurse. */ |
2193 | 144k | { |
2194 | 144k | abbrev_entry *type_abbrev; |
2195 | 144k | unsigned char *type_data; |
2196 | 144k | abbrev_map *map; |
2197 | | |
2198 | 144k | type_abbrev = get_type_abbrev_from_form (attr->form, |
2199 | 144k | uvalue, |
2200 | 144k | cu_offset, |
2201 | 144k | end, |
2202 | 144k | section, |
2203 | 144k | NULL /* abbrev num return */, |
2204 | 144k | &type_data, |
2205 | 144k | &map); |
2206 | 144k | if (type_abbrev == NULL) |
2207 | 110 | break; |
2208 | | |
2209 | 144k | get_type_signedness (type_abbrev, section, type_data, |
2210 | 144k | map ? section->start + map->end : end, |
2211 | 144k | map ? map->start : cu_offset, |
2212 | 144k | pointer_size, offset_size, dwarf_version, |
2213 | 144k | is_signed, nesting + 1); |
2214 | 144k | } |
2215 | 0 | break; |
2216 | | |
2217 | 128k | case DW_AT_encoding: |
2218 | | /* Determine signness. */ |
2219 | 128k | switch (uvalue) |
2220 | 128k | { |
2221 | 0 | case DW_ATE_address: |
2222 | | /* FIXME - some architectures have signed addresses. */ |
2223 | 9.45k | case DW_ATE_boolean: |
2224 | 42.9k | case DW_ATE_unsigned: |
2225 | 47.2k | case DW_ATE_unsigned_char: |
2226 | 47.2k | case DW_ATE_unsigned_fixed: |
2227 | 47.2k | * is_signed = false; |
2228 | 47.2k | break; |
2229 | | |
2230 | 9 | default: |
2231 | 9 | case DW_ATE_complex_float: |
2232 | 1.61k | case DW_ATE_float: |
2233 | 47.7k | case DW_ATE_signed: |
2234 | 81.2k | case DW_ATE_signed_char: |
2235 | 81.2k | case DW_ATE_imaginary_float: |
2236 | 81.2k | case DW_ATE_decimal_float: |
2237 | 81.2k | case DW_ATE_signed_fixed: |
2238 | 81.2k | * is_signed = true; |
2239 | 81.2k | break; |
2240 | 128k | } |
2241 | 128k | break; |
2242 | 896k | } |
2243 | 896k | } |
2244 | 318k | } |
2245 | | |
2246 | | static void |
2247 | | read_and_print_leb128 (unsigned char *data, |
2248 | | unsigned int *bytes_read, |
2249 | | unsigned const char *end, |
2250 | | bool is_signed) |
2251 | 0 | { |
2252 | 0 | int status; |
2253 | 0 | uint64_t val = read_leb128 (data, end, is_signed, bytes_read, &status); |
2254 | 0 | if (status != 0) |
2255 | 0 | report_leb_status (status); |
2256 | 0 | else if (is_signed) |
2257 | 0 | printf ("%" PRId64, val); |
2258 | 0 | else |
2259 | 0 | printf ("%" PRIu64, val); |
2260 | 0 | } |
2261 | | |
2262 | | static void |
2263 | | display_discr_list (unsigned long form, |
2264 | | uint64_t uvalue, |
2265 | | unsigned char *data, |
2266 | | int level) |
2267 | 0 | { |
2268 | 0 | unsigned char *end = data; |
2269 | |
|
2270 | 0 | if (uvalue == 0) |
2271 | 0 | { |
2272 | 0 | printf ("[default]"); |
2273 | 0 | return; |
2274 | 0 | } |
2275 | | |
2276 | 0 | switch (form) |
2277 | 0 | { |
2278 | 0 | case DW_FORM_block: |
2279 | 0 | case DW_FORM_block1: |
2280 | 0 | case DW_FORM_block2: |
2281 | 0 | case DW_FORM_block4: |
2282 | | /* Move data pointer back to the start of the byte array. */ |
2283 | 0 | data -= uvalue; |
2284 | 0 | break; |
2285 | 0 | default: |
2286 | 0 | printf ("<corrupt>\n"); |
2287 | 0 | warn (_("corrupt discr_list - not using a block form\n")); |
2288 | 0 | return; |
2289 | 0 | } |
2290 | | |
2291 | 0 | if (uvalue < 2) |
2292 | 0 | { |
2293 | 0 | printf ("<corrupt>\n"); |
2294 | 0 | warn (_("corrupt discr_list - block not long enough\n")); |
2295 | 0 | return; |
2296 | 0 | } |
2297 | | |
2298 | 0 | bool is_signed = (level > 0 && level <= MAX_CU_NESTING |
2299 | 0 | ? level_type_signed [level - 1] : false); |
2300 | |
|
2301 | 0 | printf ("("); |
2302 | 0 | while (data < end) |
2303 | 0 | { |
2304 | 0 | unsigned char discriminant; |
2305 | 0 | unsigned int bytes_read; |
2306 | |
|
2307 | 0 | SAFE_BYTE_GET_AND_INC (discriminant, data, 1, end); |
2308 | | |
2309 | 0 | switch (discriminant) |
2310 | 0 | { |
2311 | 0 | case DW_DSC_label: |
2312 | 0 | printf ("label "); |
2313 | 0 | read_and_print_leb128 (data, & bytes_read, end, is_signed); |
2314 | 0 | data += bytes_read; |
2315 | 0 | break; |
2316 | | |
2317 | 0 | case DW_DSC_range: |
2318 | 0 | printf ("range "); |
2319 | 0 | read_and_print_leb128 (data, & bytes_read, end, is_signed); |
2320 | 0 | data += bytes_read; |
2321 | |
|
2322 | 0 | printf (".."); |
2323 | 0 | read_and_print_leb128 (data, & bytes_read, end, is_signed); |
2324 | 0 | data += bytes_read; |
2325 | 0 | break; |
2326 | | |
2327 | 0 | default: |
2328 | 0 | printf ("<corrupt>\n"); |
2329 | 0 | warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"), |
2330 | 0 | discriminant); |
2331 | 0 | return; |
2332 | 0 | } |
2333 | | |
2334 | 0 | if (data < end) |
2335 | 0 | printf (", "); |
2336 | 0 | } |
2337 | | |
2338 | 0 | if (is_signed) |
2339 | 0 | printf (")(signed)"); |
2340 | 0 | else |
2341 | 0 | printf (")(unsigned)"); |
2342 | 0 | } |
2343 | | |
2344 | | static void |
2345 | | display_lang (uint64_t uvalue) |
2346 | 3.14k | { |
2347 | 3.14k | switch (uvalue) |
2348 | 3.14k | { |
2349 | | /* Ordered by the numeric value of these constants. */ |
2350 | 2.37k | case DW_LANG_C89: printf ("ANSI C"); break; |
2351 | 3 | case DW_LANG_C: printf ("non-ANSI C"); break; |
2352 | 3 | case DW_LANG_Ada83: printf ("Ada"); break; |
2353 | 2 | case DW_LANG_C_plus_plus: printf ("C++"); break; |
2354 | 2 | case DW_LANG_Cobol74: printf ("Cobol 74"); break; |
2355 | 0 | case DW_LANG_Cobol85: printf ("Cobol 85"); break; |
2356 | 0 | case DW_LANG_Fortran77: printf ("FORTRAN 77"); break; |
2357 | 1 | case DW_LANG_Fortran90: printf ("Fortran 90"); break; |
2358 | 1 | case DW_LANG_Pascal83: printf ("ANSI Pascal"); break; |
2359 | 2 | case DW_LANG_Modula2: printf ("Modula 2"); break; |
2360 | | |
2361 | | /* DWARF 2.1 values. */ |
2362 | 8 | case DW_LANG_Java: printf ("Java"); break; |
2363 | 582 | case DW_LANG_C99: printf ("ANSI C99"); break; |
2364 | 0 | case DW_LANG_Ada95: printf ("ADA 95"); break; |
2365 | 0 | case DW_LANG_Fortran95: printf ("Fortran 95"); break; |
2366 | | |
2367 | | /* DWARF 3 values. */ |
2368 | 3 | case DW_LANG_PLI: printf ("PLI"); break; |
2369 | 1 | case DW_LANG_ObjC: printf ("Objective C"); break; |
2370 | 1 | case DW_LANG_ObjC_plus_plus: printf ("Objective C++"); break; |
2371 | 1 | case DW_LANG_UPC: printf ("Unified Parallel C"); break; |
2372 | 2 | case DW_LANG_D: printf ("D"); break; |
2373 | | |
2374 | | /* DWARF 4 values. */ |
2375 | 1 | case DW_LANG_Python: printf ("Python"); break; |
2376 | | |
2377 | | /* DWARF 5 values. */ |
2378 | 1 | case DW_LANG_OpenCL: printf ("OpenCL"); break; |
2379 | 1 | case DW_LANG_Go: printf ("Go"); break; |
2380 | 0 | case DW_LANG_Modula3: printf ("Modula 3"); break; |
2381 | 0 | case DW_LANG_Haskell: printf ("Haskell"); break; |
2382 | 1 | case DW_LANG_C_plus_plus_03: printf ("C++03"); break; |
2383 | 0 | case DW_LANG_C_plus_plus_11: printf ("C++11"); break; |
2384 | 0 | case DW_LANG_OCaml: printf ("OCaml"); break; |
2385 | 2 | case DW_LANG_Rust: printf ("Rust"); break; |
2386 | 0 | case DW_LANG_C11: printf ("C11"); break; |
2387 | 0 | case DW_LANG_Swift: printf ("Swift"); break; |
2388 | 0 | case DW_LANG_Julia: printf ("Julia"); break; |
2389 | 0 | case DW_LANG_Dylan: printf ("Dylan"); break; |
2390 | 0 | case DW_LANG_C_plus_plus_14: printf ("C++14"); break; |
2391 | 0 | case DW_LANG_Fortran03: printf ("Fortran 03"); break; |
2392 | 1 | case DW_LANG_Fortran08: printf ("Fortran 08"); break; |
2393 | 1 | case DW_LANG_RenderScript: printf ("RenderScript"); break; |
2394 | 0 | case DW_LANG_C17: printf ("C17"); break; |
2395 | 0 | case DW_LANG_Fortran18: printf ("Fortran 18"); break; |
2396 | 1 | case DW_LANG_Ada2005: printf ("Ada 2005"); break; |
2397 | 0 | case DW_LANG_Ada2012: printf ("Ada 2012"); break; |
2398 | 0 | case DW_LANG_HIP: printf ("Hip"); break; |
2399 | 0 | case DW_LANG_Assembly: printf ("Assembler"); break; |
2400 | 1 | case DW_LANG_C_sharp: printf ("C Sharp"); break; |
2401 | 0 | case DW_LANG_Mojo: printf ("Mojo"); break; |
2402 | 0 | case DW_LANG_GLSL: printf ("GLSL"); break; |
2403 | 1 | case DW_LANG_GLSL_ES: printf ("GLSL_ES"); break; |
2404 | 1 | case DW_LANG_HLSL: printf ("HLSL"); break; |
2405 | 0 | case DW_LANG_OpenCL_CPP: printf ("OpenCL C++"); break; |
2406 | 0 | case DW_LANG_CPP_for_OpenCL: printf ("C++ for OpenCL"); break; |
2407 | 0 | case DW_LANG_SYCL: printf ("SYCL"); break; |
2408 | 2 | case DW_LANG_C_plus_plus_17: printf ("C++17"); break; |
2409 | 1 | case DW_LANG_C_plus_plus_20: printf ("C++20"); break; |
2410 | 1 | case DW_LANG_C_plus_plus_23: printf ("C++23"); break; |
2411 | 2 | case DW_LANG_Odin: printf ("Odin"); break; |
2412 | 0 | case DW_LANG_P4: printf ("P4"); break; |
2413 | 0 | case DW_LANG_Metal: printf ("C23"); break; |
2414 | 0 | case DW_LANG_C23: printf ("C23"); break; |
2415 | 0 | case DW_LANG_Fortran23: printf ("Fortran 23"); break; |
2416 | 0 | case DW_LANG_Ruby: printf ("Ruby"); break; |
2417 | 0 | case DW_LANG_Move: printf ("Move"); break; |
2418 | 0 | case DW_LANG_Hylo: printf ("Hylo"); break; |
2419 | | |
2420 | | /* MIPS extension. */ |
2421 | 0 | case DW_LANG_Mips_Assembler: printf ("MIPS assembler"); break; |
2422 | | |
2423 | | /* UPC extension. */ |
2424 | 0 | case DW_LANG_Upc: printf ("Unified Parallel C"); break; |
2425 | | |
2426 | 137 | default: |
2427 | 137 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
2428 | 5 | printf (_("implementation defined: %#" PRIx64 ""), uvalue); |
2429 | 132 | else |
2430 | 132 | printf (_("unknown: %#" PRIx64 ""), uvalue); |
2431 | 137 | break; |
2432 | 3.14k | } |
2433 | 3.14k | } |
2434 | | |
2435 | | static unsigned char * |
2436 | | read_and_display_attr_value (unsigned long attribute, |
2437 | | unsigned long form, |
2438 | | int64_t implicit_const, |
2439 | | unsigned char *start, |
2440 | | unsigned char *data, |
2441 | | unsigned char *end, |
2442 | | uint64_t cu_offset, |
2443 | | uint64_t pointer_size, |
2444 | | uint64_t offset_size, |
2445 | | int dwarf_version, |
2446 | | debug_info *debug_info_p, |
2447 | | int do_loc, |
2448 | | struct dwarf_section *section, |
2449 | | struct cu_tu_set *this_set, |
2450 | | char delimiter, |
2451 | | int level) |
2452 | 1.40M | { |
2453 | 1.40M | int64_t svalue; |
2454 | 1.40M | uint64_t uvalue = 0; |
2455 | 1.40M | uint64_t uvalue_hi = 0; |
2456 | 1.40M | unsigned char *block_start = NULL; |
2457 | 1.40M | unsigned char *orig_data = data; |
2458 | | |
2459 | 1.40M | if (data > end || (data == end && form != DW_FORM_flag_present)) |
2460 | 16.9k | { |
2461 | 16.9k | warn (_("Corrupt attribute\n")); |
2462 | 16.9k | return data; |
2463 | 16.9k | } |
2464 | | |
2465 | 1.38M | if (do_wide && ! do_loc) |
2466 | 0 | { |
2467 | | /* PR 26847: Display the name of the form. */ |
2468 | 0 | const char * name = get_FORM_name (form); |
2469 | | |
2470 | | /* For convenience we skip the DW_FORM_ prefix to the name. */ |
2471 | 0 | if (name[0] == 'D') |
2472 | 0 | name += 8; /* strlen ("DW_FORM_") */ |
2473 | 0 | printf ("%c(%s)", delimiter, name); |
2474 | 0 | } |
2475 | | |
2476 | 1.38M | switch (form) |
2477 | 1.38M | { |
2478 | 711 | case DW_FORM_ref_addr: |
2479 | 711 | if (dwarf_version == 2) |
2480 | 711 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
2481 | 708 | else if (dwarf_version > 2) |
2482 | 708 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
2483 | 0 | else |
2484 | 0 | error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); |
2485 | 711 | break; |
2486 | | |
2487 | 101k | case DW_FORM_addr: |
2488 | 101k | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
2489 | 101k | break; |
2490 | | |
2491 | 101k | case DW_FORM_strp_sup: |
2492 | 169k | case DW_FORM_strp: |
2493 | 177k | case DW_FORM_line_strp: |
2494 | 186k | case DW_FORM_sec_offset: |
2495 | 186k | case DW_FORM_GNU_ref_alt: |
2496 | 186k | case DW_FORM_GNU_strp_alt: |
2497 | 186k | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
2498 | 186k | break; |
2499 | | |
2500 | 186k | case DW_FORM_flag_present: |
2501 | 14.9k | uvalue = 1; |
2502 | 14.9k | break; |
2503 | | |
2504 | 73 | case DW_FORM_ref1: |
2505 | 28.1k | case DW_FORM_flag: |
2506 | 381k | case DW_FORM_data1: |
2507 | 381k | case DW_FORM_strx1: |
2508 | 381k | case DW_FORM_addrx1: |
2509 | 381k | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2510 | 381k | break; |
2511 | | |
2512 | 381k | case DW_FORM_ref2: |
2513 | 101k | case DW_FORM_data2: |
2514 | 101k | case DW_FORM_strx2: |
2515 | 101k | case DW_FORM_addrx2: |
2516 | 101k | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2517 | 101k | break; |
2518 | | |
2519 | 101k | case DW_FORM_strx3: |
2520 | 1.04k | case DW_FORM_addrx3: |
2521 | 1.04k | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); |
2522 | 1.04k | break; |
2523 | | |
2524 | 1.04k | case DW_FORM_ref_sup4: |
2525 | 310k | case DW_FORM_ref4: |
2526 | 330k | case DW_FORM_data4: |
2527 | 330k | case DW_FORM_strx4: |
2528 | 330k | case DW_FORM_addrx4: |
2529 | 330k | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2530 | 330k | break; |
2531 | | |
2532 | 330k | case DW_FORM_ref_sup8: |
2533 | 772 | case DW_FORM_ref8: |
2534 | 1.45k | case DW_FORM_data8: |
2535 | 3.72k | case DW_FORM_ref_sig8: |
2536 | 3.72k | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
2537 | 3.72k | break; |
2538 | | |
2539 | 3.72k | case DW_FORM_data16: |
2540 | 191 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
2541 | 191 | SAFE_BYTE_GET_AND_INC (uvalue_hi, data, 8, end); |
2542 | 191 | if (byte_get != byte_get_little_endian) |
2543 | 0 | { |
2544 | 0 | uint64_t utmp = uvalue; |
2545 | 0 | uvalue = uvalue_hi; |
2546 | 0 | uvalue_hi = utmp; |
2547 | 0 | } |
2548 | 191 | break; |
2549 | | |
2550 | 11.3k | case DW_FORM_sdata: |
2551 | 11.3k | READ_SLEB (svalue, data, end); |
2552 | 11.3k | uvalue = svalue; |
2553 | 11.3k | break; |
2554 | | |
2555 | 0 | case DW_FORM_GNU_str_index: |
2556 | 1.06k | case DW_FORM_strx: |
2557 | 2.67k | case DW_FORM_ref_udata: |
2558 | 7.55k | case DW_FORM_udata: |
2559 | 7.62k | case DW_FORM_GNU_addr_index: |
2560 | 7.83k | case DW_FORM_addrx: |
2561 | 7.91k | case DW_FORM_loclistx: |
2562 | 10.3k | case DW_FORM_rnglistx: |
2563 | 10.3k | READ_ULEB (uvalue, data, end); |
2564 | 10.3k | break; |
2565 | | |
2566 | 8.38k | case DW_FORM_indirect: |
2567 | 8.38k | READ_ULEB (form, data, end); |
2568 | 8.38k | if (!do_loc) |
2569 | 4.19k | printf ("%c%s", delimiter, get_FORM_name (form)); |
2570 | 8.38k | if (form == DW_FORM_implicit_const) |
2571 | 66 | READ_SLEB (implicit_const, data, end); |
2572 | 8.38k | return read_and_display_attr_value (attribute, form, implicit_const, |
2573 | 8.38k | start, data, end, |
2574 | 8.38k | cu_offset, pointer_size, |
2575 | 8.38k | offset_size, dwarf_version, |
2576 | 8.38k | debug_info_p, do_loc, |
2577 | 8.38k | section, this_set, delimiter, level); |
2578 | | |
2579 | 1.00k | case DW_FORM_implicit_const: |
2580 | 1.00k | uvalue = implicit_const; |
2581 | 1.00k | break; |
2582 | | |
2583 | 236k | default: |
2584 | 236k | break; |
2585 | 1.38M | } |
2586 | | |
2587 | 1.38M | switch (form) |
2588 | 1.38M | { |
2589 | 711 | case DW_FORM_ref_addr: |
2590 | 711 | if (!do_loc) |
2591 | 360 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue); |
2592 | 711 | break; |
2593 | | |
2594 | 24 | case DW_FORM_GNU_ref_alt: |
2595 | 24 | if (!do_loc) |
2596 | 12 | { |
2597 | 12 | if (do_wide) |
2598 | | /* We have already printed the form name. */ |
2599 | 0 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue); |
2600 | 12 | else |
2601 | 12 | printf ("%c<alt %#" PRIx64 ">", delimiter, uvalue); |
2602 | 12 | } |
2603 | | /* FIXME: Follow the reference... */ |
2604 | 24 | break; |
2605 | | |
2606 | 73 | case DW_FORM_ref1: |
2607 | 889 | case DW_FORM_ref2: |
2608 | 311k | case DW_FORM_ref4: |
2609 | 311k | case DW_FORM_ref_sup4: |
2610 | 312k | case DW_FORM_ref_udata: |
2611 | 312k | if (!do_loc) |
2612 | 311k | printf ("%c<%#" PRIx64 ">", delimiter, uvalue + cu_offset); |
2613 | 312k | break; |
2614 | | |
2615 | 19.6k | case DW_FORM_data4: |
2616 | 120k | case DW_FORM_addr: |
2617 | 129k | case DW_FORM_sec_offset: |
2618 | 129k | if (!do_loc) |
2619 | 128k | printf ("%c%#" PRIx64, delimiter, uvalue); |
2620 | 129k | break; |
2621 | | |
2622 | 14.9k | case DW_FORM_flag_present: |
2623 | 42.9k | case DW_FORM_flag: |
2624 | 395k | case DW_FORM_data1: |
2625 | 496k | case DW_FORM_data2: |
2626 | 508k | case DW_FORM_sdata: |
2627 | 508k | if (!do_loc) |
2628 | 506k | printf ("%c%" PRId64, delimiter, uvalue); |
2629 | 508k | break; |
2630 | | |
2631 | 4.87k | case DW_FORM_udata: |
2632 | 4.87k | if (!do_loc) |
2633 | 2.46k | printf ("%c%" PRIu64, delimiter, uvalue); |
2634 | 4.87k | break; |
2635 | | |
2636 | 1.00k | case DW_FORM_implicit_const: |
2637 | 1.00k | if (!do_loc) |
2638 | 503 | printf ("%c%" PRId64, delimiter, implicit_const); |
2639 | 1.00k | break; |
2640 | | |
2641 | 283 | case DW_FORM_ref_sup8: |
2642 | 772 | case DW_FORM_ref8: |
2643 | 1.45k | case DW_FORM_data8: |
2644 | 1.45k | if (!do_loc) |
2645 | 733 | { |
2646 | 733 | uint64_t utmp = uvalue; |
2647 | 733 | if (form == DW_FORM_ref8) |
2648 | 245 | utmp += cu_offset; |
2649 | 733 | printf ("%c%#" PRIx64, delimiter, utmp); |
2650 | 733 | } |
2651 | 1.45k | break; |
2652 | | |
2653 | 191 | case DW_FORM_data16: |
2654 | 191 | if (!do_loc) |
2655 | 96 | { |
2656 | 96 | if (uvalue_hi == 0) |
2657 | 3 | printf (" %#" PRIx64, uvalue); |
2658 | 93 | else |
2659 | 93 | printf (" %#" PRIx64 "%016" PRIx64, uvalue_hi, uvalue); |
2660 | 96 | } |
2661 | 191 | break; |
2662 | | |
2663 | 42.9k | case DW_FORM_string: |
2664 | 42.9k | if (!do_loc) |
2665 | 42.7k | printf ("%c%.*s", delimiter, (int) (end - data), data); |
2666 | 42.9k | data += strnlen ((char *) data, end - data); |
2667 | 42.9k | if (data < end) |
2668 | 42.8k | data++; |
2669 | 42.9k | break; |
2670 | | |
2671 | 125 | case DW_FORM_block: |
2672 | 1.58k | case DW_FORM_exprloc: |
2673 | 1.58k | READ_ULEB (uvalue, data, end); |
2674 | 126k | do_block: |
2675 | 126k | block_start = data; |
2676 | 126k | if (block_start >= end) |
2677 | 26 | { |
2678 | 26 | warn (_("Block ends prematurely\n")); |
2679 | 26 | uvalue = 0; |
2680 | 26 | block_start = end; |
2681 | 26 | } |
2682 | | |
2683 | 126k | uvalue = check_uvalue (block_start, uvalue, end); |
2684 | | |
2685 | 126k | data = block_start + uvalue; |
2686 | 126k | if (!do_loc) |
2687 | 125k | { |
2688 | 125k | unsigned char op; |
2689 | | |
2690 | 125k | SAFE_BYTE_GET (op, block_start, sizeof (op), end); |
2691 | 125k | if (op != DW_OP_addrx) |
2692 | 125k | data = display_block (block_start, uvalue, end, delimiter); |
2693 | 125k | } |
2694 | 126k | break; |
2695 | | |
2696 | 126k | case DW_FORM_block1: |
2697 | 124k | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2698 | 124k | goto do_block; |
2699 | | |
2700 | 124k | case DW_FORM_block2: |
2701 | 177 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2702 | 177 | goto do_block; |
2703 | | |
2704 | 177 | case DW_FORM_block4: |
2705 | 60 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2706 | 60 | goto do_block; |
2707 | | |
2708 | 169k | case DW_FORM_strp: |
2709 | 169k | if (!do_loc) |
2710 | 169k | { |
2711 | 169k | if (do_wide) |
2712 | | /* We have already displayed the form name. */ |
2713 | 0 | printf (_("%c(offset: %#" PRIx64 "): %s"), |
2714 | 0 | delimiter, uvalue, fetch_indirect_string (uvalue)); |
2715 | 169k | else |
2716 | 169k | printf (_("%c(indirect string, offset: %#" PRIx64 "): %s"), |
2717 | 169k | delimiter, uvalue, fetch_indirect_string (uvalue)); |
2718 | 169k | } |
2719 | 169k | break; |
2720 | | |
2721 | 7.61k | case DW_FORM_line_strp: |
2722 | 7.61k | if (!do_loc) |
2723 | 3.81k | { |
2724 | 3.81k | if (do_wide) |
2725 | | /* We have already displayed the form name. */ |
2726 | 0 | printf (_("%c(offset: %#" PRIx64 "): %s"), |
2727 | 0 | delimiter, uvalue, fetch_indirect_line_string (uvalue)); |
2728 | 3.81k | else |
2729 | 3.81k | printf (_("%c(indirect line string, offset: %#" PRIx64 "): %s"), |
2730 | 3.81k | delimiter, uvalue, fetch_indirect_line_string (uvalue)); |
2731 | 3.81k | } |
2732 | 7.61k | break; |
2733 | | |
2734 | 0 | case DW_FORM_GNU_str_index: |
2735 | 1.06k | case DW_FORM_strx: |
2736 | 1.63k | case DW_FORM_strx1: |
2737 | 1.64k | case DW_FORM_strx2: |
2738 | 1.82k | case DW_FORM_strx3: |
2739 | 2.19k | case DW_FORM_strx4: |
2740 | 2.19k | if (!do_loc) |
2741 | 1.11k | { |
2742 | 1.11k | const char *suffix = section ? strrchr (section->name, '.') : NULL; |
2743 | 1.11k | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
2744 | 1.11k | const char *strng; |
2745 | | |
2746 | 1.11k | strng = fetch_indexed_string (uvalue, this_set, offset_size, dwo, |
2747 | 1.11k | debug_info_p ? debug_info_p->str_offsets_base : 0); |
2748 | 1.11k | if (do_wide) |
2749 | | /* We have already displayed the form name. */ |
2750 | 0 | printf (_("%c(offset: %#" PRIx64 "): %s"), |
2751 | 0 | delimiter, uvalue, strng); |
2752 | 1.11k | else |
2753 | 1.11k | printf (_("%c(indexed string: %#" PRIx64 "): %s"), |
2754 | 1.11k | delimiter, uvalue, strng); |
2755 | 1.11k | } |
2756 | 2.19k | break; |
2757 | | |
2758 | 28 | case DW_FORM_GNU_strp_alt: |
2759 | 28 | if (!do_loc) |
2760 | 14 | { |
2761 | 14 | if (do_wide) |
2762 | | /* We have already displayed the form name. */ |
2763 | 0 | printf (_("%c(offset: %#" PRIx64 ") %s"), |
2764 | 0 | delimiter, uvalue, fetch_alt_indirect_string (uvalue)); |
2765 | 14 | else |
2766 | 14 | printf (_("%c(alt indirect string, offset: %#" PRIx64 ") %s"), |
2767 | 14 | delimiter, uvalue, fetch_alt_indirect_string (uvalue)); |
2768 | 14 | } |
2769 | 28 | break; |
2770 | | |
2771 | 0 | case DW_FORM_indirect: |
2772 | | /* Handled above. */ |
2773 | 0 | break; |
2774 | | |
2775 | 2.26k | case DW_FORM_ref_sig8: |
2776 | 2.26k | if (!do_loc) |
2777 | 1.16k | printf ("%c%s: %#" PRIx64, delimiter, do_wide ? "" : "signature", |
2778 | 1.16k | uvalue); |
2779 | 2.26k | break; |
2780 | | |
2781 | 74 | case DW_FORM_GNU_addr_index: |
2782 | 282 | case DW_FORM_addrx: |
2783 | 390 | case DW_FORM_addrx1: |
2784 | 587 | case DW_FORM_addrx2: |
2785 | 1.45k | case DW_FORM_addrx3: |
2786 | 1.84k | case DW_FORM_addrx4: |
2787 | 1.92k | case DW_FORM_loclistx: |
2788 | 4.39k | case DW_FORM_rnglistx: |
2789 | 4.39k | if (!do_loc) |
2790 | 2.21k | { |
2791 | 2.21k | uint64_t base, idx; |
2792 | 2.21k | const char *suffix = strrchr (section->name, '.'); |
2793 | 2.21k | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
2794 | | |
2795 | 2.21k | if (form == DW_FORM_loclistx) |
2796 | 43 | { |
2797 | 43 | if (debug_info_p == NULL) |
2798 | 37 | idx = -1; |
2799 | 6 | else if (dwo) |
2800 | 0 | { |
2801 | 0 | idx = fetch_indexed_offset (uvalue, loclists_dwo, |
2802 | 0 | debug_info_p->loclists_base, |
2803 | 0 | debug_info_p->offset_size); |
2804 | 0 | if (idx != (uint64_t) -1) |
2805 | 0 | idx += (offset_size == 8) ? 20 : 12; |
2806 | 0 | } |
2807 | 6 | else if (dwarf_version > 4) |
2808 | 0 | { |
2809 | 0 | idx = fetch_indexed_offset (uvalue, loclists, |
2810 | 0 | debug_info_p->loclists_base, |
2811 | 0 | debug_info_p->offset_size); |
2812 | 0 | } |
2813 | 6 | else |
2814 | 6 | { |
2815 | | /* We want to compute: |
2816 | | idx = fetch_indexed_value (uvalue, loclists, |
2817 | | debug_info_p->loclists_base); |
2818 | | idx += debug_info_p->loclists_base; |
2819 | | Fortunately we already have that sum cached in the |
2820 | | loc_offsets array. */ |
2821 | 6 | if (uvalue < debug_info_p->num_loc_offsets) |
2822 | 0 | idx = debug_info_p->loc_offsets [uvalue]; |
2823 | 6 | else |
2824 | 6 | { |
2825 | 6 | warn (_("loc_offset %" PRIu64 " too big\n"), uvalue); |
2826 | 6 | idx = -1; |
2827 | 6 | } |
2828 | 6 | } |
2829 | 43 | } |
2830 | 2.17k | else if (form == DW_FORM_rnglistx) |
2831 | 1.23k | { |
2832 | 1.23k | if (debug_info_p == NULL) |
2833 | 1.23k | idx = -1; |
2834 | 4 | else |
2835 | 4 | idx = fetch_indexed_offset (uvalue, |
2836 | 4 | dwo ? rnglists_dwo : rnglists, |
2837 | 4 | debug_info_p->rnglists_base, |
2838 | 4 | debug_info_p->offset_size); |
2839 | 1.23k | } |
2840 | 933 | else |
2841 | 933 | { |
2842 | 933 | if (debug_info_p == NULL) |
2843 | 908 | base = 0; |
2844 | 25 | else if (debug_info_p->addr_base == DEBUG_INFO_UNAVAILABLE) |
2845 | 16 | base = 0; |
2846 | 9 | else |
2847 | 9 | base = debug_info_p->addr_base; |
2848 | | |
2849 | 933 | base += uvalue * pointer_size; |
2850 | 933 | idx = fetch_indexed_addr (base, pointer_size); |
2851 | 933 | } |
2852 | | |
2853 | | /* We have already displayed the form name. */ |
2854 | 2.21k | if (idx != (uint64_t) -1) |
2855 | 933 | printf (_("%c(index: %#" PRIx64 "): %#" PRIx64), |
2856 | 933 | delimiter, uvalue, idx); |
2857 | 2.21k | } |
2858 | 4.39k | break; |
2859 | | |
2860 | 436 | case DW_FORM_strp_sup: |
2861 | 436 | if (!do_loc) |
2862 | 222 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue + cu_offset); |
2863 | 436 | break; |
2864 | | |
2865 | 67.2k | default: |
2866 | 67.2k | warn (_("Unrecognized form: %#lx\n"), form); |
2867 | | /* What to do? Consume a byte maybe? */ |
2868 | 67.2k | ++data; |
2869 | 67.2k | break; |
2870 | 1.38M | } |
2871 | | |
2872 | 1.38M | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) |
2873 | 1.38M | && num_debug_info_entries == 0 |
2874 | 1.38M | && debug_info_p != NULL) |
2875 | 734k | { |
2876 | 734k | switch (attribute) |
2877 | 734k | { |
2878 | 0 | case DW_AT_loclists_base: |
2879 | 0 | if (debug_info_p->loclists_base) |
2880 | 0 | warn (_("CU @ %#" PRIx64 " has multiple loclists_base values " |
2881 | 0 | "(%#" PRIx64 " and %#" PRIx64 ")\n"), |
2882 | 0 | debug_info_p->cu_offset, |
2883 | 0 | debug_info_p->loclists_base, uvalue); |
2884 | 0 | svalue = uvalue; |
2885 | 0 | if (svalue < 0) |
2886 | 0 | { |
2887 | 0 | warn (_("CU @ %#" PRIx64 " has has a negative loclists_base " |
2888 | 0 | "value of %#" PRIx64 " - treating as zero\n"), |
2889 | 0 | debug_info_p->cu_offset, svalue); |
2890 | 0 | uvalue = 0; |
2891 | 0 | } |
2892 | 0 | debug_info_p->loclists_base = uvalue; |
2893 | 0 | break; |
2894 | | |
2895 | 18 | case DW_AT_rnglists_base: |
2896 | | /* Assignment to debug_info_p->rnglists_base is now elsewhere. */ |
2897 | 18 | break; |
2898 | | |
2899 | 30 | case DW_AT_str_offsets_base: |
2900 | 30 | if (debug_info_p->str_offsets_base) |
2901 | 0 | warn (_("CU @ %#" PRIx64 " has multiple str_offsets_base values " |
2902 | 0 | "%#" PRIx64 " and %#" PRIx64 ")\n"), |
2903 | 0 | debug_info_p->cu_offset, |
2904 | 0 | debug_info_p->str_offsets_base, uvalue); |
2905 | 30 | svalue = uvalue; |
2906 | 30 | if (svalue < 0) |
2907 | 0 | { |
2908 | 0 | warn (_("CU @ %#" PRIx64 " has has a negative stroffsets_base " |
2909 | 0 | "value of %#" PRIx64 " - treating as zero\n"), |
2910 | 0 | debug_info_p->cu_offset, svalue); |
2911 | 0 | uvalue = 0; |
2912 | 0 | } |
2913 | 30 | debug_info_p->str_offsets_base = uvalue; |
2914 | 30 | break; |
2915 | | |
2916 | 7.41k | case DW_AT_frame_base: |
2917 | | /* This is crude; the have_frame_base is reset on the next |
2918 | | subprogram, not at the end of the current topmost one. */ |
2919 | 7.41k | have_frame_base = 1; |
2920 | 7.41k | frame_base_level = level; |
2921 | | /* Fall through. */ |
2922 | 57.2k | case DW_AT_location: |
2923 | 57.2k | case DW_AT_GNU_locviews: |
2924 | 57.2k | case DW_AT_string_length: |
2925 | 57.2k | case DW_AT_return_addr: |
2926 | 71.5k | case DW_AT_data_member_location: |
2927 | 71.5k | case DW_AT_vtable_elem_location: |
2928 | 71.5k | case DW_AT_segment: |
2929 | 71.5k | case DW_AT_static_link: |
2930 | 71.5k | case DW_AT_use_location: |
2931 | 71.5k | case DW_AT_call_value: |
2932 | 71.5k | case DW_AT_GNU_call_site_value: |
2933 | 71.5k | case DW_AT_call_data_value: |
2934 | 71.5k | case DW_AT_GNU_call_site_data_value: |
2935 | 71.5k | case DW_AT_call_target: |
2936 | 72.1k | case DW_AT_GNU_call_site_target: |
2937 | 72.1k | case DW_AT_call_target_clobbered: |
2938 | 72.1k | case DW_AT_GNU_call_site_target_clobbered: |
2939 | 72.1k | if ((dwarf_version < 4 |
2940 | 72.1k | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
2941 | 72.1k | || form == DW_FORM_sec_offset |
2942 | 72.1k | || form == DW_FORM_loclistx) |
2943 | 10 | { |
2944 | | /* Process location list. */ |
2945 | 10 | unsigned int lmax = debug_info_p->max_loc_offsets; |
2946 | 10 | unsigned int num = debug_info_p->num_loc_offsets; |
2947 | | |
2948 | 10 | if (lmax == 0 || num >= lmax) |
2949 | 4 | { |
2950 | 4 | lmax += 1024; |
2951 | 4 | debug_info_p->loc_offsets = (uint64_t *) |
2952 | 4 | xcrealloc (debug_info_p->loc_offsets, |
2953 | 4 | lmax, sizeof (*debug_info_p->loc_offsets)); |
2954 | 4 | debug_info_p->loc_views = (uint64_t *) |
2955 | 4 | xcrealloc (debug_info_p->loc_views, |
2956 | 4 | lmax, sizeof (*debug_info_p->loc_views)); |
2957 | 4 | debug_info_p->have_frame_base = (int *) |
2958 | 4 | xcrealloc (debug_info_p->have_frame_base, |
2959 | 4 | lmax, sizeof (*debug_info_p->have_frame_base)); |
2960 | 4 | debug_info_p->max_loc_offsets = lmax; |
2961 | 4 | } |
2962 | 10 | if (form == DW_FORM_loclistx) |
2963 | 0 | uvalue = fetch_indexed_offset (num, loclists, |
2964 | 0 | debug_info_p->loclists_base, |
2965 | 0 | debug_info_p->offset_size); |
2966 | 10 | else if (this_set != NULL) |
2967 | 0 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
2968 | | |
2969 | 10 | debug_info_p->have_frame_base [num] = have_frame_base; |
2970 | 10 | if (attribute != DW_AT_GNU_locviews) |
2971 | 10 | { |
2972 | | /* Corrupt DWARF info can produce more offsets than views. |
2973 | | See PR 23062 for an example. */ |
2974 | 10 | if (debug_info_p->num_loc_offsets |
2975 | 10 | > debug_info_p->num_loc_views) |
2976 | 0 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); |
2977 | 10 | else |
2978 | 10 | { |
2979 | 10 | debug_info_p->loc_offsets [num] = uvalue; |
2980 | 10 | debug_info_p->num_loc_offsets++; |
2981 | 10 | } |
2982 | 10 | } |
2983 | 0 | else |
2984 | 0 | { |
2985 | 0 | if (debug_info_p->num_loc_views > num) |
2986 | 0 | { |
2987 | 0 | warn (_("The number of views (%u) is greater than the number of locations (%u)\n"), |
2988 | 0 | debug_info_p->num_loc_views, num); |
2989 | 0 | debug_info_p->num_loc_views = num; |
2990 | 0 | } |
2991 | 0 | else |
2992 | 0 | num = debug_info_p->num_loc_views; |
2993 | 0 | if (num > debug_info_p->num_loc_offsets) |
2994 | 0 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); |
2995 | 0 | else |
2996 | 0 | { |
2997 | 0 | debug_info_p->loc_views [num] = uvalue; |
2998 | 0 | debug_info_p->num_loc_views++; |
2999 | 0 | } |
3000 | 0 | } |
3001 | 10 | } |
3002 | 72.1k | break; |
3003 | | |
3004 | 36.1k | case DW_AT_low_pc: |
3005 | 36.1k | if (need_base_address) |
3006 | 1.82k | { |
3007 | 1.82k | if (form == DW_FORM_addrx) |
3008 | 5 | uvalue = fetch_indexed_addr (debug_info_p->addr_base |
3009 | 5 | + uvalue * pointer_size, |
3010 | 5 | pointer_size); |
3011 | | |
3012 | 1.82k | debug_info_p->base_address = uvalue; |
3013 | 1.82k | } |
3014 | 36.1k | break; |
3015 | | |
3016 | 0 | case DW_AT_GNU_addr_base: |
3017 | 24 | case DW_AT_addr_base: |
3018 | 24 | debug_info_p->addr_base = uvalue; |
3019 | | /* Retrieved elsewhere so that it is in |
3020 | | place by the time we read low_pc. */ |
3021 | 24 | break; |
3022 | | |
3023 | 0 | case DW_AT_GNU_ranges_base: |
3024 | 0 | debug_info_p->ranges_base = uvalue; |
3025 | 0 | break; |
3026 | | |
3027 | 12.0k | case DW_AT_ranges: |
3028 | 12.0k | if ((dwarf_version < 4 |
3029 | 12.0k | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
3030 | 12.0k | || form == DW_FORM_sec_offset |
3031 | 12.0k | || form == DW_FORM_rnglistx) |
3032 | 12.0k | { |
3033 | | /* Process range list. */ |
3034 | 12.0k | unsigned int lmax = debug_info_p->max_range_lists; |
3035 | 12.0k | unsigned int num = debug_info_p->num_range_lists; |
3036 | | |
3037 | 12.0k | if (lmax == 0 || num >= lmax) |
3038 | 794 | { |
3039 | 794 | lmax += 1024; |
3040 | 794 | debug_info_p->range_lists = (uint64_t *) |
3041 | 794 | xcrealloc (debug_info_p->range_lists, |
3042 | 794 | lmax, sizeof (*debug_info_p->range_lists)); |
3043 | 794 | debug_info_p->max_range_lists = lmax; |
3044 | 794 | } |
3045 | | |
3046 | 12.0k | if (form == DW_FORM_rnglistx) |
3047 | 0 | uvalue = fetch_indexed_offset (uvalue, rnglists, |
3048 | 0 | debug_info_p->rnglists_base, |
3049 | 0 | debug_info_p->offset_size); |
3050 | | |
3051 | 12.0k | debug_info_p->range_lists [num] = uvalue; |
3052 | 12.0k | debug_info_p->num_range_lists++; |
3053 | 12.0k | } |
3054 | 12.0k | break; |
3055 | | |
3056 | 0 | case DW_AT_GNU_dwo_name: |
3057 | 0 | case DW_AT_dwo_name: |
3058 | 0 | if (need_dwo_info) |
3059 | 0 | switch (form) |
3060 | 0 | { |
3061 | 0 | case DW_FORM_strp: |
3062 | 0 | add_dwo_name ((const char *) fetch_indirect_string (uvalue), |
3063 | 0 | cu_offset); |
3064 | 0 | break; |
3065 | 0 | case DW_FORM_GNU_strp_alt: |
3066 | 0 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset); |
3067 | 0 | break; |
3068 | 0 | case DW_FORM_GNU_str_index: |
3069 | 0 | case DW_FORM_strx: |
3070 | 0 | case DW_FORM_strx1: |
3071 | 0 | case DW_FORM_strx2: |
3072 | 0 | case DW_FORM_strx3: |
3073 | 0 | case DW_FORM_strx4: |
3074 | 0 | add_dwo_name (fetch_indexed_string (uvalue, this_set, |
3075 | 0 | offset_size, false, |
3076 | 0 | debug_info_p->str_offsets_base), |
3077 | 0 | cu_offset); |
3078 | 0 | break; |
3079 | 0 | case DW_FORM_string: |
3080 | 0 | add_dwo_name ((const char *) orig_data, cu_offset); |
3081 | 0 | break; |
3082 | 0 | default: |
3083 | 0 | warn (_("Unsupported form (%s) for attribute %s\n"), |
3084 | 0 | get_FORM_name (form), get_AT_name (attribute)); |
3085 | 0 | break; |
3086 | 0 | } |
3087 | 0 | break; |
3088 | | |
3089 | 1.82k | case DW_AT_comp_dir: |
3090 | | /* FIXME: Also extract a build-id in a CU/TU. */ |
3091 | 1.82k | if (need_dwo_info) |
3092 | 0 | switch (form) |
3093 | 0 | { |
3094 | 0 | case DW_FORM_strp: |
3095 | 0 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue), cu_offset); |
3096 | 0 | break; |
3097 | 0 | case DW_FORM_GNU_strp_alt: |
3098 | 0 | add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset); |
3099 | 0 | break; |
3100 | 0 | case DW_FORM_line_strp: |
3101 | 0 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue), cu_offset); |
3102 | 0 | break; |
3103 | 0 | case DW_FORM_GNU_str_index: |
3104 | 0 | case DW_FORM_strx: |
3105 | 0 | case DW_FORM_strx1: |
3106 | 0 | case DW_FORM_strx2: |
3107 | 0 | case DW_FORM_strx3: |
3108 | 0 | case DW_FORM_strx4: |
3109 | 0 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false, |
3110 | 0 | debug_info_p->str_offsets_base), |
3111 | 0 | cu_offset); |
3112 | 0 | break; |
3113 | 0 | case DW_FORM_string: |
3114 | 0 | add_dwo_dir ((const char *) orig_data, cu_offset); |
3115 | 0 | break; |
3116 | 0 | default: |
3117 | 0 | warn (_("Unsupported form (%s) for attribute %s\n"), |
3118 | 0 | get_FORM_name (form), get_AT_name (attribute)); |
3119 | 0 | break; |
3120 | 0 | } |
3121 | 1.82k | break; |
3122 | | |
3123 | 1.82k | case DW_AT_GNU_dwo_id: |
3124 | 0 | if (need_dwo_info) |
3125 | 0 | switch (form) |
3126 | 0 | { |
3127 | 0 | case DW_FORM_data8: |
3128 | | /* FIXME: Record the length of the ID as well ? */ |
3129 | 0 | add_dwo_id ((const char *) (data - 8), cu_offset); |
3130 | 0 | break; |
3131 | 0 | default: |
3132 | 0 | warn (_("Unsupported form (%s) for attribute %s\n"), |
3133 | 0 | get_FORM_name (form), get_AT_name (attribute)); |
3134 | 0 | break; |
3135 | 0 | } |
3136 | 0 | break; |
3137 | | |
3138 | 612k | default: |
3139 | 612k | break; |
3140 | 734k | } |
3141 | 734k | } |
3142 | | |
3143 | 1.38M | if (do_loc || attribute == 0) |
3144 | 100k | return data; |
3145 | | |
3146 | | /* For some attributes we can display further information. */ |
3147 | 1.28M | switch (attribute) |
3148 | 1.28M | { |
3149 | 177k | case DW_AT_type: |
3150 | 177k | if (level >= 0 && level < MAX_CU_NESTING |
3151 | 177k | && uvalue < (size_t) (end - start)) |
3152 | 173k | { |
3153 | 173k | bool is_signed = false; |
3154 | 173k | abbrev_entry *type_abbrev; |
3155 | 173k | unsigned char *type_data; |
3156 | 173k | abbrev_map *map; |
3157 | | |
3158 | 173k | type_abbrev = get_type_abbrev_from_form (form, uvalue, |
3159 | 173k | cu_offset, end, |
3160 | 173k | section, NULL, |
3161 | 173k | &type_data, &map); |
3162 | 173k | if (type_abbrev != NULL) |
3163 | 173k | { |
3164 | 173k | get_type_signedness (type_abbrev, section, type_data, |
3165 | 173k | map ? section->start + map->end : end, |
3166 | 173k | map ? map->start : cu_offset, |
3167 | 173k | pointer_size, offset_size, dwarf_version, |
3168 | 173k | & is_signed, 0); |
3169 | 173k | } |
3170 | 173k | level_type_signed[level] = is_signed; |
3171 | 173k | } |
3172 | 177k | break; |
3173 | | |
3174 | 6.27k | case DW_AT_inline: |
3175 | 6.27k | printf ("\t"); |
3176 | 6.27k | switch (uvalue) |
3177 | 6.27k | { |
3178 | 97 | case DW_INL_not_inlined: |
3179 | 97 | printf (_("(not inlined)")); |
3180 | 97 | break; |
3181 | 4.42k | case DW_INL_inlined: |
3182 | 4.42k | printf (_("(inlined)")); |
3183 | 4.42k | break; |
3184 | 29 | case DW_INL_declared_not_inlined: |
3185 | 29 | printf (_("(declared as inline but ignored)")); |
3186 | 29 | break; |
3187 | 1.70k | case DW_INL_declared_inlined: |
3188 | 1.70k | printf (_("(declared as inline and inlined)")); |
3189 | 1.70k | break; |
3190 | 11 | default: |
3191 | 11 | printf (_(" (Unknown inline attribute value: %#" PRIx64 ")"), |
3192 | 11 | uvalue); |
3193 | 11 | break; |
3194 | 6.27k | } |
3195 | 6.27k | break; |
3196 | | |
3197 | 6.27k | case DW_AT_language: |
3198 | 3.14k | printf ("\t("); |
3199 | 3.14k | display_lang (uvalue); |
3200 | 3.14k | printf (")"); |
3201 | 3.14k | break; |
3202 | | |
3203 | 25.9k | case DW_AT_encoding: |
3204 | 25.9k | printf ("\t"); |
3205 | 25.9k | switch (uvalue) |
3206 | 25.9k | { |
3207 | 14 | case DW_ATE_void: printf ("(void)"); break; |
3208 | 1 | case DW_ATE_address: printf ("(machine address)"); break; |
3209 | 485 | case DW_ATE_boolean: printf ("(boolean)"); break; |
3210 | 1 | case DW_ATE_complex_float: printf ("(complex float)"); break; |
3211 | 2.68k | case DW_ATE_float: printf ("(float)"); break; |
3212 | 8.40k | case DW_ATE_signed: printf ("(signed)"); break; |
3213 | 2.32k | case DW_ATE_signed_char: printf ("(signed char)"); break; |
3214 | 10.0k | case DW_ATE_unsigned: printf ("(unsigned)"); break; |
3215 | 1.90k | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; |
3216 | | /* DWARF 2.1 values: */ |
3217 | 0 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
3218 | 1 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; |
3219 | | /* DWARF 3 values: */ |
3220 | 0 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; |
3221 | 0 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; |
3222 | 0 | case DW_ATE_edited: printf ("(edited)"); break; |
3223 | 0 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; |
3224 | 0 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; |
3225 | | /* DWARF 4 values: */ |
3226 | 0 | case DW_ATE_UTF: printf ("(unicode string)"); break; |
3227 | | /* DWARF 5 values: */ |
3228 | 0 | case DW_ATE_UCS: printf ("(UCS)"); break; |
3229 | 0 | case DW_ATE_ASCII: printf ("(ASCII)"); break; |
3230 | | |
3231 | | /* HP extensions: */ |
3232 | 0 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; |
3233 | 0 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; |
3234 | 0 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; |
3235 | 0 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; |
3236 | 0 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; |
3237 | 0 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; |
3238 | 0 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; |
3239 | | |
3240 | 13 | default: |
3241 | 13 | if (uvalue >= DW_ATE_lo_user |
3242 | 13 | && uvalue <= DW_ATE_hi_user) |
3243 | 1 | printf (_("(user defined type)")); |
3244 | 12 | else |
3245 | 12 | printf (_("(unknown type)")); |
3246 | 13 | break; |
3247 | 25.9k | } |
3248 | 25.9k | break; |
3249 | | |
3250 | 25.9k | case DW_AT_accessibility: |
3251 | 53 | printf ("\t"); |
3252 | 53 | switch (uvalue) |
3253 | 53 | { |
3254 | 0 | case DW_ACCESS_public: printf ("(public)"); break; |
3255 | 0 | case DW_ACCESS_protected: printf ("(protected)"); break; |
3256 | 0 | case DW_ACCESS_private: printf ("(private)"); break; |
3257 | 53 | default: |
3258 | 53 | printf (_("(unknown accessibility)")); |
3259 | 53 | break; |
3260 | 53 | } |
3261 | 53 | break; |
3262 | | |
3263 | 53 | case DW_AT_visibility: |
3264 | 6 | printf ("\t"); |
3265 | 6 | switch (uvalue) |
3266 | 6 | { |
3267 | 0 | case DW_VIS_local: printf ("(local)"); break; |
3268 | 0 | case DW_VIS_exported: printf ("(exported)"); break; |
3269 | 0 | case DW_VIS_qualified: printf ("(qualified)"); break; |
3270 | 6 | default: printf (_("(unknown visibility)")); break; |
3271 | 6 | } |
3272 | 6 | break; |
3273 | | |
3274 | 26 | case DW_AT_endianity: |
3275 | 26 | printf ("\t"); |
3276 | 26 | switch (uvalue) |
3277 | 26 | { |
3278 | 26 | case DW_END_default: printf ("(default)"); break; |
3279 | 0 | case DW_END_big: printf ("(big)"); break; |
3280 | 0 | case DW_END_little: printf ("(little)"); break; |
3281 | 0 | default: |
3282 | 0 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) |
3283 | 0 | printf (_("(user specified)")); |
3284 | 0 | else |
3285 | 0 | printf (_("(unknown endianity)")); |
3286 | 0 | break; |
3287 | 26 | } |
3288 | 26 | break; |
3289 | | |
3290 | 26 | case DW_AT_virtuality: |
3291 | 1 | printf ("\t"); |
3292 | 1 | switch (uvalue) |
3293 | 1 | { |
3294 | 1 | case DW_VIRTUALITY_none: printf ("(none)"); break; |
3295 | 0 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; |
3296 | 0 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; |
3297 | 0 | default: printf (_("(unknown virtuality)")); break; |
3298 | 1 | } |
3299 | 1 | break; |
3300 | | |
3301 | 3 | case DW_AT_identifier_case: |
3302 | 3 | printf ("\t"); |
3303 | 3 | switch (uvalue) |
3304 | 3 | { |
3305 | 3 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; |
3306 | 0 | case DW_ID_up_case: printf ("(up_case)"); break; |
3307 | 0 | case DW_ID_down_case: printf ("(down_case)"); break; |
3308 | 0 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; |
3309 | 0 | default: printf (_("(unknown case)")); break; |
3310 | 3 | } |
3311 | 3 | break; |
3312 | | |
3313 | 6 | case DW_AT_calling_convention: |
3314 | 6 | printf ("\t"); |
3315 | 6 | switch (uvalue) |
3316 | 6 | { |
3317 | 0 | case DW_CC_normal: printf ("(normal)"); break; |
3318 | 0 | case DW_CC_program: printf ("(program)"); break; |
3319 | 0 | case DW_CC_nocall: printf ("(nocall)"); break; |
3320 | 0 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
3321 | 0 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; |
3322 | 0 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; |
3323 | 0 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; |
3324 | 6 | default: |
3325 | 6 | if (uvalue >= DW_CC_lo_user |
3326 | 6 | && uvalue <= DW_CC_hi_user) |
3327 | 0 | printf (_("(user defined)")); |
3328 | 6 | else |
3329 | 6 | printf (_("(unknown convention)")); |
3330 | 6 | } |
3331 | 6 | break; |
3332 | | |
3333 | 6 | case DW_AT_ordering: |
3334 | 4 | printf ("\t"); |
3335 | 4 | switch (uvalue) |
3336 | 4 | { |
3337 | 0 | case 255: |
3338 | 0 | case -1: printf (_("(undefined)")); break; |
3339 | 2 | case 0: printf ("(row major)"); break; |
3340 | 0 | case 1: printf ("(column major)"); break; |
3341 | 4 | } |
3342 | 4 | break; |
3343 | | |
3344 | 4 | case DW_AT_decimal_sign: |
3345 | 0 | printf ("\t"); |
3346 | 0 | switch (uvalue) |
3347 | 0 | { |
3348 | 0 | case DW_DS_unsigned: printf (_("(unsigned)")); break; |
3349 | 0 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; |
3350 | 0 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; |
3351 | 0 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; |
3352 | 0 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; |
3353 | 0 | default: printf (_("(unrecognised)")); break; |
3354 | 0 | } |
3355 | 0 | break; |
3356 | | |
3357 | 0 | case DW_AT_defaulted: |
3358 | 0 | printf ("\t"); |
3359 | 0 | switch (uvalue) |
3360 | 0 | { |
3361 | 0 | case DW_DEFAULTED_no: printf (_("(no)")); break; |
3362 | 0 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; |
3363 | 0 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; |
3364 | 0 | default: printf (_("(unrecognised)")); break; |
3365 | 0 | } |
3366 | 0 | break; |
3367 | | |
3368 | 0 | case DW_AT_discr_list: |
3369 | 0 | printf ("\t"); |
3370 | 0 | display_discr_list (form, uvalue, data, level); |
3371 | 0 | break; |
3372 | | |
3373 | 12.9k | case DW_AT_frame_base: |
3374 | 12.9k | have_frame_base = 1; |
3375 | | /* Fall through. */ |
3376 | 99.1k | case DW_AT_location: |
3377 | 99.1k | case DW_AT_loclists_base: |
3378 | 99.2k | case DW_AT_rnglists_base: |
3379 | 99.2k | case DW_AT_str_offsets_base: |
3380 | 99.2k | case DW_AT_string_length: |
3381 | 99.2k | case DW_AT_return_addr: |
3382 | 124k | case DW_AT_data_member_location: |
3383 | 124k | case DW_AT_vtable_elem_location: |
3384 | 124k | case DW_AT_segment: |
3385 | 124k | case DW_AT_static_link: |
3386 | 124k | case DW_AT_use_location: |
3387 | 124k | case DW_AT_call_value: |
3388 | 124k | case DW_AT_GNU_call_site_value: |
3389 | 124k | case DW_AT_call_data_value: |
3390 | 124k | case DW_AT_GNU_call_site_data_value: |
3391 | 124k | case DW_AT_call_target: |
3392 | 126k | case DW_AT_GNU_call_site_target: |
3393 | 126k | case DW_AT_call_target_clobbered: |
3394 | 126k | case DW_AT_GNU_call_site_target_clobbered: |
3395 | 126k | if ((dwarf_version < 4 |
3396 | 126k | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
3397 | 126k | || form == DW_FORM_sec_offset |
3398 | 126k | || form == DW_FORM_loclistx) |
3399 | 21 | { |
3400 | 21 | if (attribute != DW_AT_rnglists_base |
3401 | 21 | && attribute != DW_AT_str_offsets_base) |
3402 | 14 | printf (_(" (location list)")); |
3403 | 21 | } |
3404 | | /* Fall through. */ |
3405 | 126k | case DW_AT_allocated: |
3406 | 126k | case DW_AT_associated: |
3407 | 126k | case DW_AT_data_location: |
3408 | 126k | case DW_AT_stride: |
3409 | 131k | case DW_AT_upper_bound: |
3410 | 131k | case DW_AT_lower_bound: |
3411 | 131k | case DW_AT_rank: |
3412 | 131k | if (block_start) |
3413 | 125k | { |
3414 | 125k | int need_frame_base; |
3415 | | |
3416 | 125k | printf ("\t("); |
3417 | 125k | need_frame_base = decode_location_expression (block_start, |
3418 | 125k | pointer_size, |
3419 | 125k | offset_size, |
3420 | 125k | dwarf_version, |
3421 | 125k | uvalue, |
3422 | 125k | cu_offset, section); |
3423 | 125k | printf (")"); |
3424 | 125k | if (need_frame_base && !have_frame_base) |
3425 | 21 | printf (_(" [without DW_AT_frame_base]")); |
3426 | 125k | } |
3427 | 131k | break; |
3428 | | |
3429 | 3 | case DW_AT_data_bit_offset: |
3430 | 47.3k | case DW_AT_byte_size: |
3431 | 50.8k | case DW_AT_bit_size: |
3432 | 50.8k | case DW_AT_string_length_byte_size: |
3433 | 50.8k | case DW_AT_string_length_bit_size: |
3434 | 50.9k | case DW_AT_bit_stride: |
3435 | 50.9k | if (form == DW_FORM_exprloc) |
3436 | 0 | { |
3437 | 0 | printf ("\t("); |
3438 | 0 | (void) decode_location_expression (block_start, pointer_size, |
3439 | 0 | offset_size, dwarf_version, |
3440 | 0 | uvalue, cu_offset, section); |
3441 | 0 | printf (")"); |
3442 | 0 | } |
3443 | 50.9k | break; |
3444 | | |
3445 | 2 | case DW_AT_import: |
3446 | 2 | { |
3447 | 2 | unsigned long abbrev_number; |
3448 | 2 | abbrev_entry *entry; |
3449 | | |
3450 | 2 | entry = get_type_abbrev_from_form (form, uvalue, cu_offset, end, |
3451 | 2 | section, & abbrev_number, NULL, NULL); |
3452 | 2 | if (entry == NULL) |
3453 | 2 | { |
3454 | 2 | if (form != DW_FORM_GNU_ref_alt) |
3455 | 2 | warn (_("Offset %#" PRIx64 " used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"), |
3456 | 2 | uvalue, |
3457 | 2 | orig_data - section->start); |
3458 | 2 | } |
3459 | 0 | else |
3460 | 0 | { |
3461 | 0 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
3462 | 0 | printf (" (%s)", get_TAG_name (entry->tag)); |
3463 | 0 | printf ("]"); |
3464 | 0 | } |
3465 | 2 | } |
3466 | 2 | break; |
3467 | | |
3468 | 886k | default: |
3469 | 886k | break; |
3470 | 1.28M | } |
3471 | | |
3472 | 1.28M | return data; |
3473 | 1.28M | } |
3474 | | |
3475 | | static unsigned char * |
3476 | | read_and_display_attr (unsigned long attribute, |
3477 | | unsigned long form, |
3478 | | int64_t implicit_const, |
3479 | | unsigned char *start, |
3480 | | unsigned char *data, |
3481 | | unsigned char *end, |
3482 | | uint64_t cu_offset, |
3483 | | uint64_t pointer_size, |
3484 | | uint64_t offset_size, |
3485 | | int dwarf_version, |
3486 | | debug_info *debug_info_p, |
3487 | | int do_loc, |
3488 | | struct dwarf_section *section, |
3489 | | struct cu_tu_set *this_set, |
3490 | | int level) |
3491 | 1.28M | { |
3492 | 1.28M | if (!do_loc) |
3493 | 1.28M | printf (" %-18s:", get_AT_name (attribute)); |
3494 | 1.28M | data = read_and_display_attr_value (attribute, form, implicit_const, |
3495 | 1.28M | start, data, end, |
3496 | 1.28M | cu_offset, pointer_size, offset_size, |
3497 | 1.28M | dwarf_version, debug_info_p, |
3498 | 1.28M | do_loc, section, this_set, ' ', level); |
3499 | 1.28M | if (!do_loc) |
3500 | 1.28M | printf ("\n"); |
3501 | 1.28M | return data; |
3502 | 1.28M | } |
3503 | | |
3504 | | /* Like load_debug_section, but if the ordinary call fails, and we are |
3505 | | following debug links, then attempt to load the requested section |
3506 | | from one of the separate debug info files. */ |
3507 | | |
3508 | | static bool |
3509 | | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, |
3510 | | void * handle) |
3511 | 10.9k | { |
3512 | 10.9k | if (load_debug_section (sec_enum, handle)) |
3513 | 0 | { |
3514 | 0 | if (debug_displays[sec_enum].section.filename == NULL) |
3515 | 0 | { |
3516 | | /* See if we can associate a filename with this section. */ |
3517 | 0 | separate_info * i; |
3518 | |
|
3519 | 0 | for (i = first_separate_info; i != NULL; i = i->next) |
3520 | 0 | if (i->handle == handle) |
3521 | 0 | { |
3522 | 0 | debug_displays[sec_enum].section.filename = i->filename; |
3523 | 0 | break; |
3524 | 0 | } |
3525 | 0 | } |
3526 | |
|
3527 | 0 | return true; |
3528 | 0 | } |
3529 | | |
3530 | 10.9k | if (do_follow_links) |
3531 | 0 | { |
3532 | 0 | separate_info * i; |
3533 | |
|
3534 | 0 | for (i = first_separate_info; i != NULL; i = i->next) |
3535 | 0 | { |
3536 | 0 | if (load_debug_section (sec_enum, i->handle)) |
3537 | 0 | { |
3538 | 0 | debug_displays[sec_enum].section.filename = i->filename; |
3539 | | |
3540 | | /* FIXME: We should check to see if any of the remaining debug info |
3541 | | files also contain this section, and, umm, do something about it. */ |
3542 | 0 | return true; |
3543 | 0 | } |
3544 | 0 | } |
3545 | 0 | } |
3546 | | |
3547 | 10.9k | return false; |
3548 | 10.9k | } |
3549 | | |
3550 | | static void |
3551 | | introduce (struct dwarf_section * section, bool raw) |
3552 | 14.0k | { |
3553 | 14.0k | if (raw) |
3554 | 1.53k | { |
3555 | 1.53k | if (do_follow_links && section->filename) |
3556 | 0 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), |
3557 | 0 | section->name, section->filename); |
3558 | 1.53k | else |
3559 | 1.53k | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); |
3560 | 1.53k | } |
3561 | 12.5k | else |
3562 | 12.5k | { |
3563 | 12.5k | if (do_follow_links && section->filename) |
3564 | 0 | printf (_("Contents of the %s section (loaded from %s):\n\n"), |
3565 | 0 | section->name, section->filename); |
3566 | 12.5k | else |
3567 | 12.5k | printf (_("Contents of the %s section:\n\n"), section->name); |
3568 | 12.5k | } |
3569 | 14.0k | } |
3570 | | |
3571 | | /* Free memory allocated for one unit in debug_information. */ |
3572 | | |
3573 | | static void |
3574 | | free_debug_information (debug_info *ent) |
3575 | 66.9k | { |
3576 | 66.9k | if (ent->max_loc_offsets) |
3577 | 4 | { |
3578 | 4 | free (ent->loc_offsets); |
3579 | 4 | free (ent->loc_views); |
3580 | 4 | free (ent->have_frame_base); |
3581 | 4 | } |
3582 | 66.9k | if (ent->max_range_lists) |
3583 | 794 | { |
3584 | 794 | free (ent->range_lists); |
3585 | 794 | } |
3586 | 66.9k | } |
3587 | | |
3588 | | /* For look-ahead in attributes. When you want to scan a DIE for one specific |
3589 | | attribute and ignore the rest. */ |
3590 | | |
3591 | | static unsigned char * |
3592 | | skip_attribute (unsigned long form, |
3593 | | unsigned char * data, |
3594 | | unsigned char * end, |
3595 | | uint64_t pointer_size, |
3596 | | uint64_t offset_size, |
3597 | | int dwarf_version) |
3598 | 56 | { |
3599 | 56 | uint64_t temp; |
3600 | 56 | size_t inc; |
3601 | | |
3602 | 56 | switch (form) |
3603 | 56 | { |
3604 | 0 | case DW_FORM_ref_addr: |
3605 | 0 | inc = dwarf_version == 2 ? pointer_size : offset_size; |
3606 | 0 | break; |
3607 | 0 | case DW_FORM_addr: |
3608 | 0 | inc = pointer_size; |
3609 | 0 | break; |
3610 | 0 | case DW_FORM_strp_sup: |
3611 | 0 | case DW_FORM_strp: |
3612 | 0 | case DW_FORM_line_strp: |
3613 | 14 | case DW_FORM_sec_offset: |
3614 | 14 | case DW_FORM_GNU_ref_alt: |
3615 | 14 | case DW_FORM_GNU_strp_alt: |
3616 | 14 | inc = offset_size; |
3617 | 14 | break; |
3618 | 0 | case DW_FORM_ref1: |
3619 | 0 | case DW_FORM_flag: |
3620 | 0 | case DW_FORM_data1: |
3621 | 21 | case DW_FORM_strx1: |
3622 | 21 | case DW_FORM_addrx1: |
3623 | 21 | inc = 1; |
3624 | 21 | break; |
3625 | 0 | case DW_FORM_ref2: |
3626 | 7 | case DW_FORM_data2: |
3627 | 7 | case DW_FORM_strx2: |
3628 | 7 | case DW_FORM_addrx2: |
3629 | 7 | inc = 2; |
3630 | 7 | break; |
3631 | 0 | case DW_FORM_strx3: |
3632 | 0 | case DW_FORM_addrx3: |
3633 | 0 | inc = 3; |
3634 | 0 | break; |
3635 | 0 | case DW_FORM_ref_sup4: |
3636 | 0 | case DW_FORM_ref4: |
3637 | 7 | case DW_FORM_data4: |
3638 | 7 | case DW_FORM_strx4: |
3639 | 7 | case DW_FORM_addrx4: |
3640 | 7 | inc = 4; |
3641 | 7 | break; |
3642 | 0 | case DW_FORM_ref_sup8: |
3643 | 0 | case DW_FORM_ref8: |
3644 | 0 | case DW_FORM_data8: |
3645 | 0 | case DW_FORM_ref_sig8: |
3646 | 0 | inc = 8; |
3647 | 0 | break; |
3648 | 0 | case DW_FORM_data16: |
3649 | 0 | inc = 16; |
3650 | 0 | break; |
3651 | 0 | case DW_FORM_sdata: |
3652 | 0 | SKIP_SLEB (data, end); |
3653 | 0 | return data; |
3654 | 0 | case DW_FORM_GNU_str_index: |
3655 | 0 | case DW_FORM_strx: |
3656 | 0 | case DW_FORM_ref_udata: |
3657 | 0 | case DW_FORM_udata: |
3658 | 0 | case DW_FORM_GNU_addr_index: |
3659 | 7 | case DW_FORM_addrx: |
3660 | 7 | case DW_FORM_loclistx: |
3661 | 7 | case DW_FORM_rnglistx: |
3662 | 7 | SKIP_ULEB (data, end); |
3663 | 7 | return data; |
3664 | 0 | case DW_FORM_indirect: |
3665 | 0 | while (form == DW_FORM_indirect) |
3666 | 0 | READ_ULEB (form, data, end); |
3667 | 0 | return skip_attribute (form, data, end, pointer_size, offset_size, |
3668 | 0 | dwarf_version); |
3669 | | |
3670 | 0 | case DW_FORM_string: |
3671 | 0 | inc = strnlen ((char *) data, end - data); |
3672 | 0 | break; |
3673 | 0 | case DW_FORM_block: |
3674 | 0 | case DW_FORM_exprloc: |
3675 | 0 | READ_ULEB (temp, data, end); |
3676 | 0 | inc = temp; |
3677 | 0 | break; |
3678 | 0 | case DW_FORM_block1: |
3679 | 0 | SAFE_BYTE_GET_AND_INC (temp, data, 1, end); |
3680 | 0 | inc = temp; |
3681 | 0 | break; |
3682 | 0 | case DW_FORM_block2: |
3683 | 0 | SAFE_BYTE_GET_AND_INC (temp, data, 2, end); |
3684 | 0 | inc = temp; |
3685 | 0 | break; |
3686 | 0 | case DW_FORM_block4: |
3687 | 0 | SAFE_BYTE_GET_AND_INC (temp, data, 4, end); |
3688 | 0 | inc = temp; |
3689 | 0 | break; |
3690 | 0 | case DW_FORM_implicit_const: |
3691 | 0 | case DW_FORM_flag_present: |
3692 | 0 | return data; |
3693 | 0 | default: |
3694 | 0 | warn (_("Unexpected form in top DIE\n")); |
3695 | 0 | return data; |
3696 | 56 | } |
3697 | 49 | if (inc <= (size_t) (end - data)) |
3698 | 46 | data += inc; |
3699 | 3 | else |
3700 | 3 | data = end; |
3701 | 49 | return data; |
3702 | 56 | } |
3703 | | |
3704 | | static void |
3705 | | read_bases (abbrev_entry * entry, |
3706 | | unsigned char * data, |
3707 | | unsigned char * end, |
3708 | | int64_t pointer_size, |
3709 | | uint64_t offset_size, |
3710 | | int dwarf_version, |
3711 | | debug_info * debug_info_p) |
3712 | 7 | { |
3713 | 7 | abbrev_attr *attr; |
3714 | | |
3715 | 7 | for (attr = entry->first_attr; |
3716 | 70 | attr && attr->attribute; |
3717 | 63 | attr = attr->next) |
3718 | 63 | { |
3719 | 63 | uint64_t uvalue; |
3720 | | |
3721 | 63 | if (attr->attribute == DW_AT_rnglists_base) |
3722 | 0 | { |
3723 | 0 | if (attr->form == DW_FORM_sec_offset) |
3724 | 0 | { |
3725 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
3726 | 0 | debug_info_p->rnglists_base = uvalue; |
3727 | 0 | } |
3728 | 0 | else |
3729 | 0 | warn (_("Unexpected form of DW_AT_rnglists_base in the top DIE\n")); |
3730 | 0 | } |
3731 | 63 | else if (attr->attribute == DW_AT_addr_base |
3732 | 63 | || attr->attribute == DW_AT_GNU_addr_base) |
3733 | 7 | { |
3734 | 7 | if (attr->form == DW_FORM_sec_offset) |
3735 | 7 | { |
3736 | 7 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
3737 | 7 | debug_info_p->addr_base = uvalue; |
3738 | 7 | } |
3739 | 0 | else |
3740 | 0 | warn (_("Unexpected form of DW_AT_addr_base in the top DIE\n")); |
3741 | 7 | } |
3742 | 56 | else |
3743 | 56 | data = skip_attribute (attr->form, data, end, pointer_size, |
3744 | 56 | offset_size, dwarf_version); |
3745 | 63 | } |
3746 | 7 | } |
3747 | | |
3748 | | /* Process the contents of a .debug_info section. |
3749 | | If do_loc is TRUE then we are scanning for location lists and dwo tags |
3750 | | and we do not want to display anything to the user. |
3751 | | If do_types is TRUE, we are processing a .debug_types section instead of |
3752 | | a .debug_info section. |
3753 | | The information displayed is restricted by the values in DWARF_START_DIE |
3754 | | and DWARF_CUTOFF_LEVEL. |
3755 | | Returns TRUE upon success. Otherwise an error or warning message is |
3756 | | printed and FALSE is returned. */ |
3757 | | |
3758 | | static bool |
3759 | | process_debug_info (struct dwarf_section * section, |
3760 | | void *file, |
3761 | | enum dwarf_section_display_enum abbrev_sec, |
3762 | | bool do_loc, |
3763 | | bool do_types) |
3764 | 1.03k | { |
3765 | 1.03k | unsigned char *start = section->start; |
3766 | 1.03k | unsigned char *end = start + section->size; |
3767 | 1.03k | unsigned char *section_begin; |
3768 | 1.03k | unsigned int unit; |
3769 | 1.03k | unsigned int num_units = 0; |
3770 | | |
3771 | | /* First scan the section to get the number of comp units. |
3772 | | Length sanity checks are done here. */ |
3773 | 59.0k | for (section_begin = start, num_units = 0; section_begin < end; |
3774 | 57.9k | num_units ++) |
3775 | 58.2k | { |
3776 | 58.2k | uint64_t length; |
3777 | | |
3778 | | /* Read the first 4 bytes. For a 32-bit DWARF section, this |
3779 | | will be the length. For a 64-bit DWARF section, it'll be |
3780 | | the escape code 0xffffffff followed by an 8 byte length. */ |
3781 | 58.2k | SAFE_BYTE_GET_AND_INC (length, section_begin, 4, end); |
3782 | | |
3783 | 58.2k | if (length == 0xffffffff) |
3784 | 58.2k | SAFE_BYTE_GET_AND_INC (length, section_begin, 8, end); |
3785 | 58.2k | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3786 | 2 | { |
3787 | 2 | warn (_("Reserved length value (%#" PRIx64 ") found in section %s\n"), |
3788 | 2 | length, section->name); |
3789 | 2 | return false; |
3790 | 2 | } |
3791 | | |
3792 | | /* Negative values are illegal, they may even cause infinite |
3793 | | looping. This can happen if we can't accurately apply |
3794 | | relocations to an object file, or if the file is corrupt. */ |
3795 | 58.2k | if (length > (size_t) (end - section_begin)) |
3796 | 292 | { |
3797 | 292 | warn (_("Corrupt unit length (got %#" PRIx64 |
3798 | 292 | " expected at most %#tx) in section %s\n"), |
3799 | 292 | length, end - section_begin, section->name); |
3800 | 292 | return false; |
3801 | 292 | } |
3802 | 57.9k | section_begin += length; |
3803 | 57.9k | } |
3804 | | |
3805 | 743 | if (num_units == 0) |
3806 | 0 | { |
3807 | 0 | error (_("No comp units in %s section ?\n"), section->name); |
3808 | 0 | return false; |
3809 | 0 | } |
3810 | | |
3811 | 743 | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) |
3812 | 743 | && alloc_num_debug_info_entries == 0 |
3813 | 743 | && !do_types) |
3814 | 692 | { |
3815 | | /* Then allocate an array to hold the information. */ |
3816 | 692 | debug_information = cmalloc (num_units, sizeof (*debug_information)); |
3817 | 692 | if (debug_information == NULL) |
3818 | 0 | { |
3819 | 0 | error (_("Not enough memory for a debug info array of %u entries\n"), |
3820 | 0 | num_units); |
3821 | 0 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
3822 | 0 | return false; |
3823 | 0 | } |
3824 | | |
3825 | | /* PR 17531: file: 92ca3797. |
3826 | | We cannot rely upon the debug_information array being initialised |
3827 | | before it is used. A corrupt file could easily contain references |
3828 | | to a unit for which information has not been made available. So |
3829 | | we ensure that the array is zeroed here. */ |
3830 | 692 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3831 | | |
3832 | 692 | alloc_num_debug_info_entries = num_units; |
3833 | 692 | } |
3834 | | |
3835 | 743 | if (!do_loc) |
3836 | 743 | { |
3837 | 743 | load_debug_section_with_follow (str, file); |
3838 | 743 | load_debug_section_with_follow (line_str, file); |
3839 | 743 | load_debug_section_with_follow (str_dwo, file); |
3840 | 743 | load_debug_section_with_follow (str_index, file); |
3841 | 743 | load_debug_section_with_follow (str_index_dwo, file); |
3842 | 743 | load_debug_section_with_follow (debug_addr, file); |
3843 | 743 | } |
3844 | | |
3845 | 743 | load_debug_section_with_follow (abbrev_sec, file); |
3846 | 743 | load_debug_section_with_follow (loclists, file); |
3847 | 743 | load_debug_section_with_follow (rnglists, file); |
3848 | 743 | load_debug_section_with_follow (loclists_dwo, file); |
3849 | 743 | load_debug_section_with_follow (rnglists_dwo, file); |
3850 | | |
3851 | 743 | if (debug_displays [abbrev_sec].section.start == NULL) |
3852 | 82 | { |
3853 | 82 | warn (_("Unable to locate %s section!\n"), |
3854 | 82 | debug_displays [abbrev_sec].section.uncompressed_name); |
3855 | 82 | return false; |
3856 | 82 | } |
3857 | | |
3858 | 661 | if (!do_loc && dwarf_start_die == 0) |
3859 | 661 | introduce (section, false); |
3860 | | |
3861 | 661 | free_all_abbrevs (); |
3862 | | |
3863 | | /* In order to be able to resolve DW_FORM_ref_addr forms we need |
3864 | | to load *all* of the abbrevs for all CUs in this .debug_info |
3865 | | section. This does effectively mean that we (partially) read |
3866 | | every CU header twice. */ |
3867 | 53.9k | for (section_begin = start; start < end;) |
3868 | 53.2k | { |
3869 | 53.2k | DWARF2_Internal_CompUnit compunit; |
3870 | 53.2k | unsigned char *hdrptr; |
3871 | 53.2k | uint64_t abbrev_base; |
3872 | 53.2k | size_t abbrev_size; |
3873 | 53.2k | uint64_t cu_offset; |
3874 | 53.2k | unsigned int offset_size; |
3875 | 53.2k | struct cu_tu_set *this_set; |
3876 | 53.2k | unsigned char *end_cu; |
3877 | | |
3878 | 53.2k | hdrptr = start; |
3879 | 53.2k | cu_offset = start - section_begin; |
3880 | | |
3881 | 53.2k | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
3882 | | |
3883 | 53.2k | if (compunit.cu_length == 0xffffffff) |
3884 | 0 | { |
3885 | 0 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
3886 | 0 | offset_size = 8; |
3887 | 0 | } |
3888 | 53.2k | else |
3889 | 53.2k | offset_size = 4; |
3890 | 53.2k | end_cu = hdrptr + compunit.cu_length; |
3891 | | |
3892 | 53.2k | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu); |
3893 | | |
3894 | 53.2k | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3895 | | |
3896 | 53.2k | if (compunit.cu_version < 5) |
3897 | 53.2k | { |
3898 | 53.2k | compunit.cu_unit_type = DW_UT_compile; |
3899 | | /* Initialize it due to a false compiler warning. */ |
3900 | 53.2k | compunit.cu_pointer_size = -1; |
3901 | 53.2k | } |
3902 | 21 | else |
3903 | 21 | { |
3904 | 21 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu); |
3905 | 21 | do_types = (compunit.cu_unit_type == DW_UT_type); |
3906 | | |
3907 | 21 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
3908 | 21 | } |
3909 | | |
3910 | 53.2k | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, |
3911 | 53.2k | end_cu); |
3912 | | |
3913 | 53.2k | if (compunit.cu_unit_type == DW_UT_split_compile |
3914 | 53.2k | || compunit.cu_unit_type == DW_UT_skeleton) |
3915 | 2 | { |
3916 | 2 | uint64_t dwo_id; |
3917 | 2 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu); |
3918 | 2 | } |
3919 | | |
3920 | 53.2k | if (this_set == NULL) |
3921 | 53.2k | { |
3922 | 53.2k | abbrev_base = 0; |
3923 | 53.2k | abbrev_size = debug_displays [abbrev_sec].section.size; |
3924 | 53.2k | } |
3925 | 0 | else |
3926 | 0 | { |
3927 | 0 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; |
3928 | 0 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; |
3929 | 0 | } |
3930 | | |
3931 | 53.2k | abbrev_list *list; |
3932 | 53.2k | abbrev_list *free_list; |
3933 | 53.2k | list = find_and_process_abbrev_set (&debug_displays[abbrev_sec].section, |
3934 | 53.2k | abbrev_base, abbrev_size, |
3935 | 53.2k | compunit.cu_abbrev_offset, |
3936 | 53.2k | &free_list); |
3937 | 53.2k | start = end_cu; |
3938 | 53.2k | if (list != NULL && list->first_abbrev != NULL) |
3939 | 18.5k | record_abbrev_list_for_cu (cu_offset, start - section_begin, |
3940 | 18.5k | list, free_list); |
3941 | 34.6k | else if (free_list != NULL) |
3942 | 34.6k | free_abbrev_list (free_list); |
3943 | 53.2k | } |
3944 | | |
3945 | 48.9k | for (start = section_begin, unit = 0; start < end; unit++) |
3946 | 48.5k | { |
3947 | 48.5k | DWARF2_Internal_CompUnit compunit; |
3948 | 48.5k | unsigned char *hdrptr; |
3949 | 48.5k | unsigned char *tags; |
3950 | 48.5k | int level, last_level, saved_level; |
3951 | 48.5k | uint64_t cu_offset; |
3952 | 48.5k | unsigned int offset_size; |
3953 | 48.5k | uint64_t signature = 0; |
3954 | 48.5k | uint64_t type_offset = 0; |
3955 | 48.5k | struct cu_tu_set *this_set; |
3956 | 48.5k | uint64_t abbrev_base; |
3957 | 48.5k | size_t abbrev_size; |
3958 | 48.5k | unsigned char *end_cu; |
3959 | | |
3960 | 48.5k | hdrptr = start; |
3961 | 48.5k | cu_offset = start - section_begin; |
3962 | | |
3963 | 48.5k | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
3964 | | |
3965 | 48.5k | if (compunit.cu_length == 0xffffffff) |
3966 | 0 | { |
3967 | 0 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
3968 | 0 | offset_size = 8; |
3969 | 0 | } |
3970 | 48.5k | else |
3971 | 48.5k | offset_size = 4; |
3972 | 48.5k | end_cu = hdrptr + compunit.cu_length; |
3973 | | |
3974 | 48.5k | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu); |
3975 | | |
3976 | 48.5k | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3977 | | |
3978 | 48.5k | if (compunit.cu_version < 5) |
3979 | 48.5k | { |
3980 | 48.5k | compunit.cu_unit_type = DW_UT_compile; |
3981 | | /* Initialize it due to a false compiler warning. */ |
3982 | 48.5k | compunit.cu_pointer_size = -1; |
3983 | 48.5k | } |
3984 | 19 | else |
3985 | 19 | { |
3986 | 19 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu); |
3987 | 19 | do_types = (compunit.cu_unit_type == DW_UT_type); |
3988 | | |
3989 | 19 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
3990 | 19 | } |
3991 | | |
3992 | 48.5k | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end_cu); |
3993 | | |
3994 | 48.5k | if (this_set == NULL) |
3995 | 48.5k | { |
3996 | 48.5k | abbrev_base = 0; |
3997 | 48.5k | abbrev_size = debug_displays [abbrev_sec].section.size; |
3998 | 48.5k | } |
3999 | 0 | else |
4000 | 0 | { |
4001 | 0 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; |
4002 | 0 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; |
4003 | 0 | } |
4004 | | |
4005 | 48.5k | if (compunit.cu_version < 5) |
4006 | 48.5k | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
4007 | | |
4008 | 48.5k | bool do_dwo_id = false; |
4009 | 48.5k | uint64_t dwo_id = 0; |
4010 | 48.5k | if (compunit.cu_unit_type == DW_UT_split_compile |
4011 | 48.5k | || compunit.cu_unit_type == DW_UT_skeleton) |
4012 | 2 | { |
4013 | 2 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu); |
4014 | 2 | do_dwo_id = true; |
4015 | 2 | } |
4016 | | |
4017 | | /* PR 17512: file: 001-108546-0.001:0.1. */ |
4018 | 48.5k | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) |
4019 | 45.5k | { |
4020 | 45.5k | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), |
4021 | 45.5k | compunit.cu_pointer_size, offset_size); |
4022 | 45.5k | compunit.cu_pointer_size = offset_size; |
4023 | 45.5k | } |
4024 | | |
4025 | 48.5k | if (do_types) |
4026 | 183 | { |
4027 | 183 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, end_cu); |
4028 | 183 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end_cu); |
4029 | 183 | } |
4030 | | |
4031 | 48.5k | if (dwarf_start_die >= (size_t) (end_cu - section_begin)) |
4032 | 0 | { |
4033 | 0 | start = end_cu; |
4034 | 0 | continue; |
4035 | 0 | } |
4036 | | |
4037 | 48.5k | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) |
4038 | 48.5k | && num_debug_info_entries == 0 |
4039 | 48.5k | && alloc_num_debug_info_entries > unit |
4040 | 48.5k | && ! do_types) |
4041 | 12.9k | { |
4042 | 12.9k | free_debug_information (&debug_information[unit]); |
4043 | 12.9k | memset (&debug_information[unit], 0, sizeof (*debug_information)); |
4044 | 12.9k | debug_information[unit].pointer_size = compunit.cu_pointer_size; |
4045 | 12.9k | debug_information[unit].offset_size = offset_size; |
4046 | 12.9k | debug_information[unit].dwarf_version = compunit.cu_version; |
4047 | 12.9k | debug_information[unit].cu_offset = cu_offset; |
4048 | 12.9k | debug_information[unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
4049 | 12.9k | debug_information[unit].ranges_base = DEBUG_INFO_UNAVAILABLE; |
4050 | 12.9k | } |
4051 | | |
4052 | 48.5k | if (!do_loc && dwarf_start_die == 0) |
4053 | 48.5k | { |
4054 | 48.5k | printf (_(" Compilation Unit @ offset %#" PRIx64 ":\n"), |
4055 | 48.5k | cu_offset); |
4056 | 48.5k | printf (_(" Length: %#" PRIx64 " (%s)\n"), |
4057 | 48.5k | compunit.cu_length, |
4058 | 48.5k | offset_size == 8 ? "64-bit" : "32-bit"); |
4059 | 48.5k | printf (_(" Version: %d\n"), compunit.cu_version); |
4060 | 48.5k | if (compunit.cu_version >= 5) |
4061 | 19 | { |
4062 | 19 | const char *name = get_DW_UT_name (compunit.cu_unit_type); |
4063 | | |
4064 | 19 | printf (_(" Unit Type: %s (%x)\n"), |
4065 | 19 | null_name (name), |
4066 | 19 | compunit.cu_unit_type); |
4067 | 19 | } |
4068 | 48.5k | printf (_(" Abbrev Offset: %#" PRIx64 "\n"), |
4069 | 48.5k | compunit.cu_abbrev_offset); |
4070 | 48.5k | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
4071 | 48.5k | if (do_types) |
4072 | 183 | { |
4073 | 183 | printf (_(" Signature: %#" PRIx64 "\n"), signature); |
4074 | 183 | printf (_(" Type Offset: %#" PRIx64 "\n"), type_offset); |
4075 | 183 | } |
4076 | 48.5k | if (do_dwo_id) |
4077 | 2 | printf (_(" DWO ID: %#" PRIx64 "\n"), dwo_id); |
4078 | 48.5k | if (this_set != NULL) |
4079 | 0 | { |
4080 | 0 | uint64_t *offsets = this_set->section_offsets; |
4081 | 0 | size_t *sizes = this_set->section_sizes; |
4082 | |
|
4083 | 0 | printf (_(" Section contributions:\n")); |
4084 | 0 | printf (_(" .debug_abbrev.dwo: %#" PRIx64 " %#zx\n"), |
4085 | 0 | offsets[DW_SECT_ABBREV], sizes[DW_SECT_ABBREV]); |
4086 | 0 | printf (_(" .debug_line.dwo: %#" PRIx64 " %#zx\n"), |
4087 | 0 | offsets[DW_SECT_LINE], sizes[DW_SECT_LINE]); |
4088 | 0 | printf (_(" .debug_loc.dwo: %#" PRIx64 " %#zx\n"), |
4089 | 0 | offsets[DW_SECT_LOC], sizes[DW_SECT_LOC]); |
4090 | 0 | printf (_(" .debug_str_offsets.dwo: %#" PRIx64 " %#zx\n"), |
4091 | 0 | offsets[DW_SECT_STR_OFFSETS], sizes[DW_SECT_STR_OFFSETS]); |
4092 | 0 | } |
4093 | 48.5k | } |
4094 | | |
4095 | 48.5k | tags = hdrptr; |
4096 | 48.5k | start = end_cu; |
4097 | | |
4098 | 48.5k | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
4099 | 45.4k | { |
4100 | 45.4k | warn (_("CU at offset %#" PRIx64 " contains corrupt or " |
4101 | 45.4k | "unsupported version number: %d.\n"), |
4102 | 45.4k | cu_offset, compunit.cu_version); |
4103 | 45.4k | continue; |
4104 | 45.4k | } |
4105 | | |
4106 | 3.08k | if (compunit.cu_unit_type != DW_UT_compile |
4107 | 3.08k | && compunit.cu_unit_type != DW_UT_partial |
4108 | 3.08k | && compunit.cu_unit_type != DW_UT_type |
4109 | 3.08k | && compunit.cu_unit_type != DW_UT_split_compile |
4110 | 3.08k | && compunit.cu_unit_type != DW_UT_skeleton) |
4111 | 0 | { |
4112 | 0 | warn (_("CU at offset %#" PRIx64 " contains corrupt or " |
4113 | 0 | "unsupported unit type: %d.\n"), |
4114 | 0 | cu_offset, compunit.cu_unit_type); |
4115 | 0 | continue; |
4116 | 0 | } |
4117 | | |
4118 | | /* Process the abbrevs used by this compilation unit. */ |
4119 | 3.08k | abbrev_list *list; |
4120 | 3.08k | list = find_and_process_abbrev_set (&debug_displays[abbrev_sec].section, |
4121 | 3.08k | abbrev_base, abbrev_size, |
4122 | 3.08k | compunit.cu_abbrev_offset, NULL); |
4123 | 3.08k | level = 0; |
4124 | 3.08k | last_level = level; |
4125 | 3.08k | saved_level = -1; |
4126 | 436k | while (tags < start) |
4127 | 433k | { |
4128 | 433k | unsigned long abbrev_number; |
4129 | 433k | unsigned long die_offset; |
4130 | 433k | abbrev_entry *entry; |
4131 | 433k | abbrev_attr *attr; |
4132 | 433k | int do_printing = 1; |
4133 | | |
4134 | 433k | die_offset = tags - section_begin; |
4135 | | |
4136 | 433k | READ_ULEB (abbrev_number, tags, start); |
4137 | | |
4138 | | /* A null DIE marks the end of a list of siblings or it may also be |
4139 | | a section padding. */ |
4140 | 433k | if (abbrev_number == 0) |
4141 | 78.6k | { |
4142 | | /* Check if it can be a section padding for the last CU. */ |
4143 | 78.6k | if (level == 0 && start == end) |
4144 | 136 | { |
4145 | 136 | unsigned char *chk; |
4146 | | |
4147 | 2.31k | for (chk = tags; chk < start; chk++) |
4148 | 2.29k | if (*chk != 0) |
4149 | 116 | break; |
4150 | 136 | if (chk == start) |
4151 | 20 | break; |
4152 | 136 | } |
4153 | | |
4154 | 78.6k | if (!do_loc && die_offset >= dwarf_start_die |
4155 | 78.6k | && (dwarf_cutoff_level == -1 |
4156 | 78.6k | || level < dwarf_cutoff_level)) |
4157 | 78.6k | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
4158 | 78.6k | level, die_offset); |
4159 | | |
4160 | 78.6k | --level; |
4161 | 78.6k | if (level < 0) |
4162 | 5.42k | { |
4163 | 5.42k | static unsigned num_bogus_warns = 0; |
4164 | | |
4165 | 5.42k | if (num_bogus_warns < 3) |
4166 | 6 | { |
4167 | 6 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
4168 | 6 | die_offset, section->name); |
4169 | 6 | num_bogus_warns ++; |
4170 | 6 | if (num_bogus_warns == 3) |
4171 | 2 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); |
4172 | 6 | } |
4173 | 5.42k | } |
4174 | 78.6k | if (dwarf_start_die != 0 && level < saved_level) |
4175 | 0 | { |
4176 | 0 | if (list != NULL) |
4177 | 0 | free_abbrev_list (list); |
4178 | 0 | return true; |
4179 | 0 | } |
4180 | 78.6k | continue; |
4181 | 78.6k | } |
4182 | | |
4183 | 354k | if (!do_loc) |
4184 | 354k | { |
4185 | 354k | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) |
4186 | 0 | do_printing = 0; |
4187 | 354k | else |
4188 | 354k | { |
4189 | 354k | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) |
4190 | 0 | saved_level = level; |
4191 | 354k | do_printing = (dwarf_cutoff_level == -1 |
4192 | 354k | || level < dwarf_cutoff_level); |
4193 | 354k | if (do_printing) |
4194 | 354k | printf (_(" <%d><%lx>: Abbrev Number: %lu"), |
4195 | 354k | level, die_offset, abbrev_number); |
4196 | 0 | else if (dwarf_cutoff_level == -1 |
4197 | 0 | || last_level < dwarf_cutoff_level) |
4198 | 0 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); |
4199 | 354k | last_level = level; |
4200 | 354k | } |
4201 | 354k | } |
4202 | | |
4203 | | /* Scan through the abbreviation list until we reach the |
4204 | | correct entry. */ |
4205 | 354k | entry = NULL; |
4206 | 354k | if (list != NULL) |
4207 | 8.98M | for (entry = list->first_abbrev; entry != NULL; entry = entry->next) |
4208 | 8.98M | if (entry->number == abbrev_number) |
4209 | 354k | break; |
4210 | | |
4211 | 354k | if (entry == NULL) |
4212 | 277 | { |
4213 | 277 | if (!do_loc && do_printing) |
4214 | 277 | { |
4215 | 277 | printf ("\n"); |
4216 | 277 | fflush (stdout); |
4217 | 277 | } |
4218 | 277 | warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"), |
4219 | 277 | die_offset, abbrev_number); |
4220 | 277 | if (list != NULL) |
4221 | 257 | free_abbrev_list (list); |
4222 | 277 | return false; |
4223 | 277 | } |
4224 | | |
4225 | 354k | if (!do_loc && do_printing) |
4226 | 354k | printf (" (%s)\n", get_TAG_name (entry->tag)); |
4227 | | |
4228 | 354k | switch (entry->tag) |
4229 | 354k | { |
4230 | 326k | default: |
4231 | 326k | need_base_address = 0; |
4232 | 326k | break; |
4233 | 2.95k | case DW_TAG_compile_unit: |
4234 | 2.95k | case DW_TAG_skeleton_unit: |
4235 | 2.95k | need_base_address = 1; |
4236 | 2.95k | need_dwo_info = do_loc; |
4237 | 2.95k | break; |
4238 | 0 | case DW_TAG_entry_point: |
4239 | 0 | need_base_address = 0; |
4240 | | /* Assuming that there is no DW_AT_frame_base. */ |
4241 | 0 | have_frame_base = 0; |
4242 | 0 | break; |
4243 | 25.2k | case DW_TAG_subprogram: |
4244 | 25.2k | need_base_address = 0; |
4245 | 25.2k | if (level <= frame_base_level) |
4246 | | /* Don't reset that for nested subprogram. */ |
4247 | 20.6k | have_frame_base = 0; |
4248 | 25.2k | break; |
4249 | 354k | } |
4250 | | |
4251 | 354k | debug_info *debug_info_p = ((debug_information |
4252 | 354k | && unit < alloc_num_debug_info_entries) |
4253 | 354k | ? debug_information + unit : NULL); |
4254 | | |
4255 | 354k | assert (!debug_info_p |
4256 | 354k | || (debug_info_p->num_loc_offsets |
4257 | 354k | == debug_info_p->num_loc_views)); |
4258 | | |
4259 | | /* Look ahead so that the values of DW_AT_rnglists_base, |
4260 | | DW_AT_[GNU_]addr_base are available before attributes that |
4261 | | reference them are parsed in the same DIE. |
4262 | | Only needed for the top DIE on DWARFv5+. |
4263 | | No simiar treatment for loclists_base because there should |
4264 | | be no loclist attributes in top DIE. */ |
4265 | 354k | if (debug_info_p && compunit.cu_version >= 5 && level == 0) |
4266 | 7 | { |
4267 | 7 | int64_t stemp; |
4268 | | |
4269 | 7 | read_bases (entry, |
4270 | 7 | tags, |
4271 | 7 | start, |
4272 | 7 | compunit.cu_pointer_size, |
4273 | 7 | offset_size, |
4274 | 7 | compunit.cu_version, |
4275 | 7 | debug_info_p); |
4276 | | |
4277 | | /* This check was in place before, keep it. */ |
4278 | 7 | stemp = debug_info_p->rnglists_base; |
4279 | 7 | if (stemp < 0) |
4280 | 0 | { |
4281 | 0 | warn (_("CU @ %#" PRIx64 " has has a negative rnglists_base " |
4282 | 0 | "value of %#" PRIx64 " - treating as zero\n"), |
4283 | 0 | debug_info_p->cu_offset, stemp); |
4284 | 0 | debug_info_p->rnglists_base = 0; |
4285 | 0 | } |
4286 | 7 | } |
4287 | | |
4288 | 354k | for (attr = entry->first_attr; |
4289 | 1.63M | attr && attr->attribute; |
4290 | 1.28M | attr = attr->next) |
4291 | 1.28M | { |
4292 | 1.28M | if (! do_loc && do_printing) |
4293 | | /* Show the offset from where the tag was extracted. */ |
4294 | 1.28M | printf (" <%tx>", tags - section_begin); |
4295 | 1.28M | tags = read_and_display_attr (attr->attribute, |
4296 | 1.28M | attr->form, |
4297 | 1.28M | attr->implicit_const, |
4298 | 1.28M | section_begin, |
4299 | 1.28M | tags, |
4300 | 1.28M | start, |
4301 | 1.28M | cu_offset, |
4302 | 1.28M | compunit.cu_pointer_size, |
4303 | 1.28M | offset_size, |
4304 | 1.28M | compunit.cu_version, |
4305 | 1.28M | debug_info_p, |
4306 | 1.28M | do_loc || ! do_printing, |
4307 | 1.28M | section, |
4308 | 1.28M | this_set, |
4309 | 1.28M | level); |
4310 | 1.28M | } |
4311 | | |
4312 | | /* If a locview attribute appears before a location one, |
4313 | | make sure we don't associate it with an earlier |
4314 | | loclist. */ |
4315 | 354k | if (debug_info_p) |
4316 | 351k | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) |
4317 | 351k | { |
4318 | 10 | case 1: |
4319 | 10 | debug_info_p->loc_views [debug_info_p->num_loc_views] = -1; |
4320 | 10 | debug_info_p->num_loc_views++; |
4321 | 10 | assert (debug_info_p->num_loc_views |
4322 | 10 | == debug_info_p->num_loc_offsets); |
4323 | 10 | break; |
4324 | | |
4325 | 351k | case 0: |
4326 | 351k | break; |
4327 | | |
4328 | 0 | case -1: |
4329 | 0 | warn (_("DIE has locviews without loclist\n")); |
4330 | 0 | debug_info_p->num_loc_views--; |
4331 | 0 | break; |
4332 | | |
4333 | 0 | default: |
4334 | 0 | assert (0); |
4335 | 351k | } |
4336 | | |
4337 | 354k | if (entry->children) |
4338 | 75.1k | ++level; |
4339 | 354k | } |
4340 | 2.80k | if (list != NULL) |
4341 | 2.80k | free_abbrev_list (list); |
4342 | 2.80k | } |
4343 | | |
4344 | | /* Set num_debug_info_entries here so that it can be used to check if |
4345 | | we need to process .debug_loc and .debug_ranges sections. */ |
4346 | 384 | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) |
4347 | 384 | && num_debug_info_entries == 0 |
4348 | 384 | && ! do_types) |
4349 | 283 | { |
4350 | 283 | if (num_units > alloc_num_debug_info_entries) |
4351 | 0 | num_debug_info_entries = alloc_num_debug_info_entries; |
4352 | 283 | else |
4353 | 283 | num_debug_info_entries = num_units; |
4354 | 283 | } |
4355 | | |
4356 | 384 | if (!do_loc) |
4357 | 384 | printf ("\n"); |
4358 | | |
4359 | 384 | return true; |
4360 | 661 | } |
4361 | | |
4362 | | /* Locate and scan the .debug_info section in the file and record the pointer |
4363 | | sizes and offsets for the compilation units in it. Usually an executable |
4364 | | will have just one pointer size, but this is not guaranteed, and so we try |
4365 | | not to make any assumptions. Returns zero upon failure, or the number of |
4366 | | compilation units upon success. */ |
4367 | | |
4368 | | static unsigned int |
4369 | | load_debug_info (void * file) |
4370 | 1.50k | { |
4371 | | /* If we have already tried and failed to load the .debug_info |
4372 | | section then do not bother to repeat the task. */ |
4373 | 1.50k | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
4374 | 971 | return 0; |
4375 | | |
4376 | | /* If we already have the information there is nothing else to do. */ |
4377 | 532 | if (num_debug_info_entries > 0) |
4378 | 200 | return num_debug_info_entries; |
4379 | | |
4380 | | /* If this is a DWARF package file, load the CU and TU indexes. */ |
4381 | 332 | (void) load_cu_tu_indexes (file); |
4382 | | |
4383 | 332 | if (load_debug_section_with_follow (info, file) |
4384 | 332 | && process_debug_info (&debug_displays [info].section, file, abbrev, true, false)) |
4385 | 0 | return num_debug_info_entries; |
4386 | | |
4387 | 332 | if (load_debug_section_with_follow (info_dwo, file) |
4388 | 332 | && process_debug_info (&debug_displays [info_dwo].section, file, |
4389 | 0 | abbrev_dwo, true, false)) |
4390 | 0 | return num_debug_info_entries; |
4391 | | |
4392 | 332 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
4393 | 332 | return 0; |
4394 | 332 | } |
4395 | | |
4396 | | /* Read a DWARF .debug_line section header starting at DATA. |
4397 | | Upon success returns an updated DATA pointer and the LINFO |
4398 | | structure and the END_OF_SEQUENCE pointer will be filled in. |
4399 | | Otherwise returns NULL. */ |
4400 | | |
4401 | | static unsigned char * |
4402 | | read_debug_line_header (struct dwarf_section * section, |
4403 | | unsigned char * data, |
4404 | | unsigned char * end, |
4405 | | DWARF2_Internal_LineInfo * linfo, |
4406 | | unsigned char ** end_of_sequence) |
4407 | 8.78k | { |
4408 | 8.78k | unsigned char *hdrptr; |
4409 | | |
4410 | | /* Extract information from the Line Number Program Header. |
4411 | | (section 6.2.4 in the Dwarf3 doc). */ |
4412 | 8.78k | hdrptr = data; |
4413 | | |
4414 | | /* Get and check the length of the block. */ |
4415 | 8.78k | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); |
4416 | | |
4417 | 8.78k | if (linfo->li_length == 0xffffffff) |
4418 | 26 | { |
4419 | | /* This section is 64-bit DWARF 3. */ |
4420 | 26 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
4421 | 26 | linfo->li_offset_size = 8; |
4422 | 26 | } |
4423 | 8.75k | else |
4424 | 8.75k | linfo->li_offset_size = 4; |
4425 | | |
4426 | 8.78k | if (linfo->li_length > (size_t) (end - hdrptr)) |
4427 | 465 | { |
4428 | | /* If the length field has a relocation against it, then we should |
4429 | | not complain if it is inaccurate (and probably negative). This |
4430 | | happens in object files when the .debug_line section is actually |
4431 | | comprised of several different .debug_line.* sections, (some of |
4432 | | which may be removed by linker garbage collection), and a relocation |
4433 | | is used to compute the correct length once that is done. */ |
4434 | 465 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
4435 | 4 | { |
4436 | 4 | linfo->li_length = end - hdrptr; |
4437 | 4 | } |
4438 | 461 | else |
4439 | 461 | { |
4440 | 461 | warn (_("The length field (%#" PRIx64 ")" |
4441 | 461 | " in the debug_line header is wrong" |
4442 | 461 | " - the section is too small\n"), |
4443 | 461 | linfo->li_length); |
4444 | 461 | return NULL; |
4445 | 461 | } |
4446 | 465 | } |
4447 | 8.32k | end = hdrptr + linfo->li_length; |
4448 | | |
4449 | | /* Get and check the version number. */ |
4450 | 8.32k | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); |
4451 | | |
4452 | 8.32k | if (linfo->li_version != 2 |
4453 | 8.32k | && linfo->li_version != 3 |
4454 | 8.32k | && linfo->li_version != 4 |
4455 | 8.32k | && linfo->li_version != 5) |
4456 | 176 | { |
4457 | 176 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
4458 | 176 | "is currently supported.\n")); |
4459 | 176 | return NULL; |
4460 | 176 | } |
4461 | | |
4462 | 8.14k | if (linfo->li_version >= 5) |
4463 | 647 | { |
4464 | 647 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
4465 | | |
4466 | 647 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
4467 | 647 | if (linfo->li_segment_size != 0) |
4468 | 3 | { |
4469 | 3 | warn (_("The %s section contains " |
4470 | 3 | "unsupported segment selector size: %d.\n"), |
4471 | 3 | section->name, linfo->li_segment_size); |
4472 | 3 | return NULL; |
4473 | 3 | } |
4474 | 647 | } |
4475 | | |
4476 | 8.14k | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, |
4477 | 8.14k | linfo->li_offset_size, end); |
4478 | 8.14k | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
4479 | | |
4480 | 8.14k | if (linfo->li_version >= 4) |
4481 | 1.21k | { |
4482 | 1.21k | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
4483 | | |
4484 | 1.21k | if (linfo->li_max_ops_per_insn == 0) |
4485 | 13 | { |
4486 | 13 | warn (_("Invalid maximum operations per insn.\n")); |
4487 | 13 | return NULL; |
4488 | 13 | } |
4489 | 1.21k | } |
4490 | 6.93k | else |
4491 | 6.93k | linfo->li_max_ops_per_insn = 1; |
4492 | | |
4493 | 8.13k | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
4494 | 8.13k | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
4495 | 8.13k | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
4496 | 8.13k | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); |
4497 | | |
4498 | 8.13k | *end_of_sequence = end; |
4499 | 8.13k | return hdrptr; |
4500 | 8.13k | } |
4501 | | |
4502 | | static unsigned char * |
4503 | | display_formatted_table (unsigned char *data, |
4504 | | unsigned char *start, |
4505 | | unsigned char *end, |
4506 | | const DWARF2_Internal_LineInfo *linfo, |
4507 | | struct dwarf_section *section, |
4508 | | bool is_dir) |
4509 | 1.27k | { |
4510 | 1.27k | unsigned char *format_start, format_count, *format, formati; |
4511 | 1.27k | uint64_t data_count, datai; |
4512 | 1.27k | unsigned int namepass, last_entry = 0; |
4513 | 1.27k | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
4514 | | |
4515 | 1.27k | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
4516 | 1.27k | if (do_checks && format_count > 5) |
4517 | 0 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), |
4518 | 0 | table_name, format_count); |
4519 | | |
4520 | 1.27k | format_start = data; |
4521 | 28.7k | for (formati = 0; formati < format_count; formati++) |
4522 | 27.4k | { |
4523 | 27.4k | SKIP_ULEB (data, end); |
4524 | 27.4k | SKIP_ULEB (data, end); |
4525 | 27.4k | if (data >= end) |
4526 | 13 | { |
4527 | 13 | warn (_("%s: Corrupt format description entry\n"), table_name); |
4528 | 13 | return data; |
4529 | 13 | } |
4530 | 27.4k | } |
4531 | | |
4532 | 1.25k | READ_ULEB (data_count, data, end); |
4533 | 1.25k | if (data_count == 0) |
4534 | 307 | { |
4535 | 307 | printf (_("\n The %s is empty.\n"), table_name); |
4536 | 307 | return data; |
4537 | 307 | } |
4538 | 950 | else if (data >= end |
4539 | 950 | || data_count > (size_t) (end - data)) |
4540 | 57 | { |
4541 | 57 | warn (_("%s: Corrupt entry count %#" PRIx64 "\n"), table_name, data_count); |
4542 | 57 | return data; |
4543 | 57 | } |
4544 | | |
4545 | 893 | else if (format_count == 0) |
4546 | 4 | { |
4547 | 4 | warn (_("%s: format count is zero, but the table is not empty\n"), |
4548 | 4 | table_name); |
4549 | 4 | return end; |
4550 | 4 | } |
4551 | | |
4552 | 889 | printf (_("\n The %s (offset %#tx, lines %" PRIu64 ", columns %u):\n"), |
4553 | 889 | table_name, data - start, data_count, format_count); |
4554 | | |
4555 | 889 | printf (_(" Entry")); |
4556 | | /* Delay displaying name as the last entry for better screen layout. */ |
4557 | 2.66k | for (namepass = 0; namepass < 2; namepass++) |
4558 | 1.77k | { |
4559 | 1.77k | format = format_start; |
4560 | 30.7k | for (formati = 0; formati < format_count; formati++) |
4561 | 28.9k | { |
4562 | 28.9k | uint64_t content_type; |
4563 | | |
4564 | 28.9k | READ_ULEB (content_type, format, end); |
4565 | 28.9k | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
4566 | 14.4k | switch (content_type) |
4567 | 14.4k | { |
4568 | 848 | case DW_LNCT_path: |
4569 | 848 | printf (_("\tName")); |
4570 | 848 | break; |
4571 | 484 | case DW_LNCT_directory_index: |
4572 | 484 | printf (_("\tDir")); |
4573 | 484 | break; |
4574 | 360 | case DW_LNCT_timestamp: |
4575 | 360 | printf (_("\tTime")); |
4576 | 360 | break; |
4577 | 73 | case DW_LNCT_size: |
4578 | 73 | printf (_("\tSize")); |
4579 | 73 | break; |
4580 | 172 | case DW_LNCT_MD5: |
4581 | 172 | printf (_("\tMD5\t\t\t")); |
4582 | 172 | break; |
4583 | 12.5k | default: |
4584 | 12.5k | printf (_("\t(Unknown format content type %" PRIu64 ")"), |
4585 | 12.5k | content_type); |
4586 | 14.4k | } |
4587 | 28.9k | SKIP_ULEB (format, end); |
4588 | 28.9k | } |
4589 | 1.77k | } |
4590 | 889 | putchar ('\n'); |
4591 | | |
4592 | 7.67k | for (datai = 0; datai < data_count; datai++) |
4593 | 6.95k | { |
4594 | 6.95k | unsigned char *datapass = data; |
4595 | | |
4596 | 6.95k | printf (" %d", last_entry++); |
4597 | | /* Delay displaying name as the last entry for better screen layout. */ |
4598 | 20.8k | for (namepass = 0; namepass < 2; namepass++) |
4599 | 13.9k | { |
4600 | 13.9k | format = format_start; |
4601 | 13.9k | data = datapass; |
4602 | 130k | for (formati = 0; formati < format_count; formati++) |
4603 | 116k | { |
4604 | 116k | uint64_t content_type, form; |
4605 | | |
4606 | 116k | READ_ULEB (content_type, format, end); |
4607 | 116k | READ_ULEB (form, format, end); |
4608 | 116k | data = read_and_display_attr_value (0, form, 0, start, data, end, |
4609 | 116k | 0, 0, linfo->li_offset_size, |
4610 | 116k | linfo->li_version, NULL, |
4611 | 116k | ((content_type == DW_LNCT_path) != (namepass == 1)), |
4612 | 116k | section, NULL, '\t', -1); |
4613 | 116k | } |
4614 | 13.9k | } |
4615 | | |
4616 | 6.95k | if (data >= end && (datai < data_count - 1)) |
4617 | 169 | { |
4618 | 169 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
4619 | 169 | return data; |
4620 | 169 | } |
4621 | 6.78k | putchar ('\n'); |
4622 | 6.78k | } |
4623 | 720 | return data; |
4624 | 889 | } |
4625 | | |
4626 | | static int |
4627 | | display_debug_sup (struct dwarf_section * section, |
4628 | | void * file ATTRIBUTE_UNUSED) |
4629 | 0 | { |
4630 | 0 | unsigned char * start = section->start; |
4631 | 0 | unsigned char * end = section->start + section->size; |
4632 | 0 | unsigned int version; |
4633 | 0 | char is_supplementary; |
4634 | 0 | const unsigned char * sup_filename; |
4635 | 0 | size_t sup_filename_len; |
4636 | 0 | unsigned int num_read; |
4637 | 0 | int status; |
4638 | 0 | uint64_t checksum_len; |
4639 | | |
4640 | |
|
4641 | 0 | introduce (section, true); |
4642 | 0 | if (section->size < 4) |
4643 | 0 | { |
4644 | 0 | error (_("corrupt .debug_sup section: size is too small\n")); |
4645 | 0 | return 0; |
4646 | 0 | } |
4647 | | |
4648 | | /* Read the data. */ |
4649 | 0 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); |
4650 | 0 | if (version < 5) |
4651 | 0 | warn (_("corrupt .debug_sup section: version < 5\n")); |
4652 | |
|
4653 | 0 | SAFE_BYTE_GET_AND_INC (is_supplementary, start, 1, end); |
4654 | 0 | if (is_supplementary != 0 && is_supplementary != 1) |
4655 | 0 | warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n")); |
4656 | |
|
4657 | 0 | sup_filename = start; |
4658 | 0 | if (is_supplementary && sup_filename[0] != 0) |
4659 | 0 | warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n")); |
4660 | |
|
4661 | 0 | sup_filename_len = strnlen ((const char *) start, end - start); |
4662 | 0 | if (sup_filename_len == (size_t) (end - start)) |
4663 | 0 | { |
4664 | 0 | error (_("corrupt .debug_sup section: filename is not NUL terminated\n")); |
4665 | 0 | return 0; |
4666 | 0 | } |
4667 | 0 | start += sup_filename_len + 1; |
4668 | |
|
4669 | 0 | checksum_len = read_leb128 (start, end, false /* unsigned */, & num_read, & status); |
4670 | 0 | if (status) |
4671 | 0 | { |
4672 | 0 | error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n")); |
4673 | 0 | checksum_len = 0; |
4674 | 0 | } |
4675 | 0 | start += num_read; |
4676 | 0 | if (checksum_len > (size_t) (end - start)) |
4677 | 0 | { |
4678 | 0 | error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n")); |
4679 | 0 | checksum_len = end - start; |
4680 | 0 | } |
4681 | 0 | else if (checksum_len < (size_t) (end - start)) |
4682 | 0 | { |
4683 | 0 | warn (_("corrupt .debug_sup section: there are %#" PRIx64 |
4684 | 0 | " extra, unused bytes at the end of the section\n"), |
4685 | 0 | (end - start) - checksum_len); |
4686 | 0 | } |
4687 | |
|
4688 | 0 | printf (_(" Version: %u\n"), version); |
4689 | 0 | printf (_(" Is Supp: %u\n"), is_supplementary); |
4690 | 0 | printf (_(" Filename: %s\n"), sup_filename); |
4691 | 0 | printf (_(" Checksum Len: %" PRIu64 "\n"), checksum_len); |
4692 | 0 | if (checksum_len > 0) |
4693 | 0 | { |
4694 | 0 | printf (_(" Checksum: ")); |
4695 | 0 | while (checksum_len--) |
4696 | 0 | printf ("0x%x ", * start++ ); |
4697 | 0 | printf ("\n"); |
4698 | 0 | } |
4699 | 0 | return 1; |
4700 | 0 | } |
4701 | | |
4702 | | static int |
4703 | | display_debug_lines_raw (struct dwarf_section * section, |
4704 | | unsigned char * data, |
4705 | | unsigned char * end, |
4706 | | void * file) |
4707 | 1.53k | { |
4708 | 1.53k | unsigned char *start = section->start; |
4709 | 1.53k | int verbose_view = 0; |
4710 | | |
4711 | 1.53k | introduce (section, true); |
4712 | | |
4713 | 9.64k | while (data < end) |
4714 | 8.78k | { |
4715 | 8.78k | static DWARF2_Internal_LineInfo saved_linfo; |
4716 | 8.78k | DWARF2_Internal_LineInfo linfo; |
4717 | 8.78k | unsigned char *standard_opcodes; |
4718 | 8.78k | unsigned char *end_of_sequence; |
4719 | 8.78k | int i; |
4720 | | |
4721 | 8.78k | if (startswith (section->name, ".debug_line.") |
4722 | | /* Note: the following does not apply to .debug_line.dwo sections. |
4723 | | These are full debug_line sections. */ |
4724 | 8.78k | && strcmp (section->name, ".debug_line.dwo") != 0) |
4725 | 0 | { |
4726 | | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
4727 | | section containing just the Line Number Statements. They are |
4728 | | created by the assembler and intended to be used alongside gcc's |
4729 | | -ffunction-sections command line option. When the linker's |
4730 | | garbage collection decides to discard a .text.<foo> section it |
4731 | | can then also discard the line number information in .debug_line.<foo>. |
4732 | | |
4733 | | Since the section is a fragment it does not have the details |
4734 | | needed to fill out a LineInfo structure, so instead we use the |
4735 | | details from the last full debug_line section that we processed. */ |
4736 | 0 | end_of_sequence = end; |
4737 | 0 | standard_opcodes = NULL; |
4738 | 0 | linfo = saved_linfo; |
4739 | | /* PR 17531: file: 0522b371. */ |
4740 | 0 | if (linfo.li_line_range == 0) |
4741 | 0 | { |
4742 | 0 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
4743 | 0 | return 0; |
4744 | 0 | } |
4745 | 0 | reset_state_machine (linfo.li_default_is_stmt); |
4746 | 0 | } |
4747 | 8.78k | else |
4748 | 8.78k | { |
4749 | 8.78k | unsigned char * hdrptr; |
4750 | | |
4751 | 8.78k | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4752 | 8.78k | & end_of_sequence)) == NULL) |
4753 | 653 | return 0; |
4754 | | |
4755 | 8.13k | printf (_(" Offset: %#tx\n"), data - start); |
4756 | 8.13k | printf (_(" Length: %" PRId64 "\n"), linfo.li_length); |
4757 | 8.13k | printf (_(" DWARF Version: %d\n"), linfo.li_version); |
4758 | 8.13k | if (linfo.li_version >= 5) |
4759 | 635 | { |
4760 | 635 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); |
4761 | 635 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); |
4762 | 635 | } |
4763 | 8.13k | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
4764 | 8.13k | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
4765 | 8.13k | if (linfo.li_version >= 4) |
4766 | 1.19k | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); |
4767 | 8.13k | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); |
4768 | 8.13k | printf (_(" Line Base: %d\n"), linfo.li_line_base); |
4769 | 8.13k | printf (_(" Line Range: %d\n"), linfo.li_line_range); |
4770 | 8.13k | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); |
4771 | | |
4772 | | /* PR 17512: file: 1665-6428-0.004. */ |
4773 | 8.13k | if (linfo.li_line_range == 0) |
4774 | 136 | { |
4775 | 136 | warn (_("Line range of 0 is invalid, using 1 instead\n")); |
4776 | 136 | linfo.li_line_range = 1; |
4777 | 136 | } |
4778 | | |
4779 | 8.13k | reset_state_machine (linfo.li_default_is_stmt); |
4780 | | |
4781 | | /* Display the contents of the Opcodes table. */ |
4782 | 8.13k | standard_opcodes = hdrptr; |
4783 | | |
4784 | | /* PR 17512: file: 002-417945-0.004. */ |
4785 | 8.13k | if (standard_opcodes + linfo.li_opcode_base >= end) |
4786 | 8 | { |
4787 | 8 | warn (_("Line Base extends beyond end of section\n")); |
4788 | 8 | return 0; |
4789 | 8 | } |
4790 | | |
4791 | 8.12k | printf (_("\n Opcodes:\n")); |
4792 | | |
4793 | 123k | for (i = 1; i < linfo.li_opcode_base; i++) |
4794 | 115k | printf (ngettext (" Opcode %d has %d arg\n", |
4795 | 115k | " Opcode %d has %d args\n", |
4796 | 115k | standard_opcodes[i - 1]), |
4797 | 115k | i, standard_opcodes[i - 1]); |
4798 | | |
4799 | | /* Display the contents of the Directory table. */ |
4800 | 8.12k | data = standard_opcodes + linfo.li_opcode_base - 1; |
4801 | | |
4802 | 8.12k | if (linfo.li_version >= 5) |
4803 | 635 | { |
4804 | 635 | load_debug_section_with_follow (line_str, file); |
4805 | | |
4806 | 635 | data = display_formatted_table (data, start, end, &linfo, section, |
4807 | 635 | true); |
4808 | 635 | data = display_formatted_table (data, start, end, &linfo, section, |
4809 | 635 | false); |
4810 | 635 | } |
4811 | 7.48k | else |
4812 | 7.48k | { |
4813 | 7.48k | if (*data == 0) |
4814 | 3.68k | printf (_("\n The Directory Table is empty.\n")); |
4815 | 3.80k | else |
4816 | 3.80k | { |
4817 | 3.80k | unsigned int last_dir_entry = 0; |
4818 | | |
4819 | 3.80k | printf (_("\n The Directory Table (offset %#tx):\n"), |
4820 | 3.80k | data - start); |
4821 | | |
4822 | 18.2k | while (data < end && *data != 0) |
4823 | 14.4k | { |
4824 | 14.4k | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); |
4825 | | |
4826 | 14.4k | data += strnlen ((char *) data, end - data); |
4827 | 14.4k | if (data < end) |
4828 | 14.3k | data++; |
4829 | 14.4k | } |
4830 | | |
4831 | | /* PR 17512: file: 002-132094-0.004. */ |
4832 | 3.80k | if (data >= end - 1) |
4833 | 7 | break; |
4834 | 3.80k | } |
4835 | | |
4836 | | /* Skip the NUL at the end of the table. */ |
4837 | 7.48k | if (data < end) |
4838 | 7.48k | data++; |
4839 | | |
4840 | | /* Display the contents of the File Name table. */ |
4841 | 7.48k | if (data >= end || *data == 0) |
4842 | 3.25k | printf (_("\n The File Name Table is empty.\n")); |
4843 | 4.23k | else |
4844 | 4.23k | { |
4845 | 4.23k | printf (_("\n The File Name Table (offset %#tx):\n"), |
4846 | 4.23k | data - start); |
4847 | 4.23k | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
4848 | | |
4849 | 70.1k | while (data < end && *data != 0) |
4850 | 65.9k | { |
4851 | 65.9k | unsigned char *name; |
4852 | 65.9k | uint64_t val; |
4853 | | |
4854 | 65.9k | printf (" %d\t", ++state_machine_regs.last_file_entry); |
4855 | 65.9k | name = data; |
4856 | 65.9k | data += strnlen ((char *) data, end - data); |
4857 | 65.9k | if (data < end) |
4858 | 65.9k | data++; |
4859 | | |
4860 | 65.9k | READ_ULEB (val, data, end); |
4861 | 65.9k | printf ("%" PRIu64 "\t", val); |
4862 | 65.9k | READ_ULEB (val, data, end); |
4863 | 65.9k | printf ("%" PRIu64 "\t", val); |
4864 | 65.9k | READ_ULEB (val, data, end); |
4865 | 65.9k | printf ("%" PRIu64 "\t", val); |
4866 | 65.9k | printf ("%.*s\n", (int)(end - name), name); |
4867 | | |
4868 | 65.9k | if (data >= end) |
4869 | 9 | { |
4870 | 9 | warn (_("Corrupt file name table entry\n")); |
4871 | 9 | break; |
4872 | 9 | } |
4873 | 65.9k | } |
4874 | 4.23k | } |
4875 | | |
4876 | | /* Skip the NUL at the end of the table. */ |
4877 | 7.48k | if (data < end) |
4878 | 7.47k | data++; |
4879 | 7.48k | } |
4880 | | |
4881 | 8.11k | putchar ('\n'); |
4882 | 8.11k | saved_linfo = linfo; |
4883 | 8.11k | } |
4884 | | |
4885 | | /* Now display the statements. */ |
4886 | 8.11k | if (data >= end_of_sequence) |
4887 | 3.37k | printf (_(" No Line Number Statements.\n")); |
4888 | 4.74k | else |
4889 | 4.74k | { |
4890 | 4.74k | printf (_(" Line Number Statements:\n")); |
4891 | | |
4892 | 2.92M | while (data < end_of_sequence) |
4893 | 2.92M | { |
4894 | 2.92M | unsigned char op_code; |
4895 | 2.92M | int adv; |
4896 | 2.92M | uint64_t uladv; |
4897 | | |
4898 | 2.92M | printf (" [0x%08tx]", data - start); |
4899 | | |
4900 | 2.92M | op_code = *data++; |
4901 | | |
4902 | 2.92M | if (op_code >= linfo.li_opcode_base) |
4903 | 1.05M | { |
4904 | 1.05M | op_code -= linfo.li_opcode_base; |
4905 | 1.05M | uladv = (op_code / linfo.li_line_range); |
4906 | 1.05M | if (linfo.li_max_ops_per_insn == 1) |
4907 | 1.03M | { |
4908 | 1.03M | uladv *= linfo.li_min_insn_length; |
4909 | 1.03M | state_machine_regs.address += uladv; |
4910 | 1.03M | if (uladv) |
4911 | 499k | state_machine_regs.view = 0; |
4912 | 1.03M | printf (_(" Special opcode %d: " |
4913 | 1.03M | "advance Address by %" PRIu64 |
4914 | 1.03M | " to %#" PRIx64 "%s"), |
4915 | 1.03M | op_code, uladv, state_machine_regs.address, |
4916 | 1.03M | verbose_view && uladv |
4917 | 1.03M | ? _(" (reset view)") : ""); |
4918 | 1.03M | } |
4919 | 13.1k | else |
4920 | 13.1k | { |
4921 | 13.1k | unsigned addrdelta |
4922 | 13.1k | = ((state_machine_regs.op_index + uladv) |
4923 | 13.1k | / linfo.li_max_ops_per_insn) |
4924 | 13.1k | * linfo.li_min_insn_length; |
4925 | | |
4926 | 13.1k | state_machine_regs.address += addrdelta; |
4927 | 13.1k | state_machine_regs.op_index |
4928 | 13.1k | = (state_machine_regs.op_index + uladv) |
4929 | 13.1k | % linfo.li_max_ops_per_insn; |
4930 | 13.1k | if (addrdelta) |
4931 | 3.15k | state_machine_regs.view = 0; |
4932 | 13.1k | printf (_(" Special opcode %d: " |
4933 | 13.1k | "advance Address by %" PRIu64 |
4934 | 13.1k | " to %#" PRIx64 "[%d]%s"), |
4935 | 13.1k | op_code, uladv, state_machine_regs.address, |
4936 | 13.1k | state_machine_regs.op_index, |
4937 | 13.1k | verbose_view && addrdelta |
4938 | 13.1k | ? _(" (reset view)") : ""); |
4939 | 13.1k | } |
4940 | 1.05M | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
4941 | 1.05M | state_machine_regs.line += adv; |
4942 | 1.05M | printf (_(" and Line by %d to %d"), |
4943 | 1.05M | adv, state_machine_regs.line); |
4944 | 1.05M | if (verbose_view || state_machine_regs.view) |
4945 | 81.5k | printf (_(" (view %u)\n"), state_machine_regs.view); |
4946 | 969k | else |
4947 | 969k | putchar ('\n'); |
4948 | 1.05M | state_machine_regs.view++; |
4949 | 1.05M | } |
4950 | 1.87M | else |
4951 | 1.87M | switch (op_code) |
4952 | 1.87M | { |
4953 | 641k | case DW_LNS_extended_op: |
4954 | 641k | data += process_extended_line_op (data, |
4955 | 641k | linfo.li_default_is_stmt, |
4956 | 641k | end); |
4957 | 641k | break; |
4958 | | |
4959 | 128k | case DW_LNS_copy: |
4960 | 128k | printf (_(" Copy")); |
4961 | 128k | if (verbose_view || state_machine_regs.view) |
4962 | 5.92k | printf (_(" (view %u)\n"), state_machine_regs.view); |
4963 | 122k | else |
4964 | 122k | putchar ('\n'); |
4965 | 128k | state_machine_regs.view++; |
4966 | 128k | break; |
4967 | | |
4968 | 29.6k | case DW_LNS_advance_pc: |
4969 | 29.6k | READ_ULEB (uladv, data, end); |
4970 | 29.6k | if (linfo.li_max_ops_per_insn == 1) |
4971 | 29.2k | { |
4972 | 29.2k | uladv *= linfo.li_min_insn_length; |
4973 | 29.2k | state_machine_regs.address += uladv; |
4974 | 29.2k | if (uladv) |
4975 | 28.6k | state_machine_regs.view = 0; |
4976 | 29.2k | printf (_(" Advance PC by %" PRIu64 |
4977 | 29.2k | " to %#" PRIx64 "%s\n"), |
4978 | 29.2k | uladv, state_machine_regs.address, |
4979 | 29.2k | verbose_view && uladv |
4980 | 29.2k | ? _(" (reset view)") : ""); |
4981 | 29.2k | } |
4982 | 415 | else |
4983 | 415 | { |
4984 | 415 | unsigned addrdelta |
4985 | 415 | = ((state_machine_regs.op_index + uladv) |
4986 | 415 | / linfo.li_max_ops_per_insn) |
4987 | 415 | * linfo.li_min_insn_length; |
4988 | 415 | state_machine_regs.address |
4989 | 415 | += addrdelta; |
4990 | 415 | state_machine_regs.op_index |
4991 | 415 | = (state_machine_regs.op_index + uladv) |
4992 | 415 | % linfo.li_max_ops_per_insn; |
4993 | 415 | if (addrdelta) |
4994 | 68 | state_machine_regs.view = 0; |
4995 | 415 | printf (_(" Advance PC by %" PRIu64 |
4996 | 415 | " to %#" PRIx64 "[%d]%s\n"), |
4997 | 415 | uladv, state_machine_regs.address, |
4998 | 415 | state_machine_regs.op_index, |
4999 | 415 | verbose_view && addrdelta |
5000 | 415 | ? _(" (reset view)") : ""); |
5001 | 415 | } |
5002 | 29.6k | break; |
5003 | | |
5004 | 334k | case DW_LNS_advance_line: |
5005 | 334k | READ_SLEB (adv, data, end); |
5006 | 334k | state_machine_regs.line += adv; |
5007 | 334k | printf (_(" Advance Line by %d to %d\n"), |
5008 | 334k | adv, state_machine_regs.line); |
5009 | 334k | break; |
5010 | | |
5011 | 53.8k | case DW_LNS_set_file: |
5012 | 53.8k | READ_ULEB (uladv, data, end); |
5013 | 53.8k | printf (_(" Set File Name to entry %" PRIu64 |
5014 | 53.8k | " in the File Name Table\n"), uladv); |
5015 | 53.8k | state_machine_regs.file = uladv; |
5016 | 53.8k | break; |
5017 | | |
5018 | 334k | case DW_LNS_set_column: |
5019 | 334k | READ_ULEB (uladv, data, end); |
5020 | 334k | printf (_(" Set column to %" PRIu64 "\n"), uladv); |
5021 | 334k | state_machine_regs.column = uladv; |
5022 | 334k | break; |
5023 | | |
5024 | 211k | case DW_LNS_negate_stmt: |
5025 | 211k | adv = state_machine_regs.is_stmt; |
5026 | 211k | adv = ! adv; |
5027 | 211k | printf (_(" Set is_stmt to %d\n"), adv); |
5028 | 211k | state_machine_regs.is_stmt = adv; |
5029 | 211k | break; |
5030 | | |
5031 | 1.00k | case DW_LNS_set_basic_block: |
5032 | 1.00k | printf (_(" Set basic block\n")); |
5033 | 1.00k | state_machine_regs.basic_block = 1; |
5034 | 1.00k | break; |
5035 | | |
5036 | 129k | case DW_LNS_const_add_pc: |
5037 | 129k | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); |
5038 | 129k | if (linfo.li_max_ops_per_insn) |
5039 | 129k | { |
5040 | 129k | uladv *= linfo.li_min_insn_length; |
5041 | 129k | state_machine_regs.address += uladv; |
5042 | 129k | if (uladv) |
5043 | 129k | state_machine_regs.view = 0; |
5044 | 129k | printf (_(" Advance PC by constant %" PRIu64 |
5045 | 129k | " to %#" PRIx64 "%s\n"), |
5046 | 129k | uladv, state_machine_regs.address, |
5047 | 129k | verbose_view && uladv |
5048 | 129k | ? _(" (reset view)") : ""); |
5049 | 129k | } |
5050 | 0 | else |
5051 | 0 | { |
5052 | 0 | unsigned addrdelta |
5053 | 0 | = ((state_machine_regs.op_index + uladv) |
5054 | 0 | / linfo.li_max_ops_per_insn) |
5055 | 0 | * linfo.li_min_insn_length; |
5056 | 0 | state_machine_regs.address |
5057 | 0 | += addrdelta; |
5058 | 0 | state_machine_regs.op_index |
5059 | 0 | = (state_machine_regs.op_index + uladv) |
5060 | 0 | % linfo.li_max_ops_per_insn; |
5061 | 0 | if (addrdelta) |
5062 | 0 | state_machine_regs.view = 0; |
5063 | 0 | printf (_(" Advance PC by constant %" PRIu64 |
5064 | 0 | " to %#" PRIx64 "[%d]%s\n"), |
5065 | 0 | uladv, state_machine_regs.address, |
5066 | 0 | state_machine_regs.op_index, |
5067 | 0 | verbose_view && addrdelta |
5068 | 0 | ? _(" (reset view)") : ""); |
5069 | 0 | } |
5070 | 129k | break; |
5071 | | |
5072 | 625 | case DW_LNS_fixed_advance_pc: |
5073 | 625 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); |
5074 | 625 | state_machine_regs.address += uladv; |
5075 | 625 | state_machine_regs.op_index = 0; |
5076 | 625 | printf (_(" Advance PC by fixed size amount %" PRIu64 |
5077 | 625 | " to %#" PRIx64 "\n"), |
5078 | 625 | uladv, state_machine_regs.address); |
5079 | | /* Do NOT reset view. */ |
5080 | 625 | break; |
5081 | | |
5082 | 4.47k | case DW_LNS_set_prologue_end: |
5083 | 4.47k | printf (_(" Set prologue_end to true\n")); |
5084 | 4.47k | break; |
5085 | | |
5086 | 422 | case DW_LNS_set_epilogue_begin: |
5087 | 422 | printf (_(" Set epilogue_begin to true\n")); |
5088 | 422 | break; |
5089 | | |
5090 | 215 | case DW_LNS_set_isa: |
5091 | 215 | READ_ULEB (uladv, data, end); |
5092 | 215 | printf (_(" Set ISA to %" PRIu64 "\n"), uladv); |
5093 | 215 | break; |
5094 | | |
5095 | 1.58k | default: |
5096 | 1.58k | printf (_(" Unknown opcode %d with operands: "), op_code); |
5097 | | |
5098 | 1.58k | if (standard_opcodes != NULL) |
5099 | 37.9k | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) |
5100 | 36.3k | { |
5101 | 36.3k | READ_ULEB (uladv, data, end); |
5102 | 36.3k | printf ("%#" PRIx64 "%s", uladv, i == 1 ? "" : ", "); |
5103 | 36.3k | } |
5104 | 1.58k | putchar ('\n'); |
5105 | 1.58k | break; |
5106 | 1.87M | } |
5107 | 2.92M | } |
5108 | 4.74k | putchar ('\n'); |
5109 | 4.74k | } |
5110 | 8.11k | } |
5111 | | |
5112 | 872 | return 1; |
5113 | 1.53k | } |
5114 | | |
5115 | | typedef struct |
5116 | | { |
5117 | | char *name; |
5118 | | unsigned int directory_index; |
5119 | | unsigned int modification_date; |
5120 | | unsigned int length; |
5121 | | } File_Entry; |
5122 | | |
5123 | | /* Output a decoded representation of the .debug_line section. */ |
5124 | | |
5125 | | static int |
5126 | | display_debug_lines_decoded (struct dwarf_section * section, |
5127 | | unsigned char * start, |
5128 | | unsigned char * data, |
5129 | | unsigned char * end, |
5130 | | void * fileptr) |
5131 | 0 | { |
5132 | 0 | static DWARF2_Internal_LineInfo saved_linfo; |
5133 | |
|
5134 | 0 | introduce (section, false); |
5135 | |
|
5136 | 0 | while (data < end) |
5137 | 0 | { |
5138 | | /* This loop amounts to one iteration per compilation unit. */ |
5139 | 0 | DWARF2_Internal_LineInfo linfo; |
5140 | 0 | unsigned char *standard_opcodes; |
5141 | 0 | unsigned char *end_of_sequence; |
5142 | 0 | int i; |
5143 | 0 | File_Entry *file_table = NULL; |
5144 | 0 | unsigned int n_files = 0; |
5145 | 0 | char **directory_table = NULL; |
5146 | 0 | unsigned int n_directories = 0; |
5147 | |
|
5148 | 0 | if (startswith (section->name, ".debug_line.") |
5149 | | /* Note: the following does not apply to .debug_line.dwo sections. |
5150 | | These are full debug_line sections. */ |
5151 | 0 | && strcmp (section->name, ".debug_line.dwo") != 0) |
5152 | 0 | { |
5153 | | /* See comment in display_debug_lines_raw(). */ |
5154 | 0 | end_of_sequence = end; |
5155 | 0 | standard_opcodes = NULL; |
5156 | 0 | linfo = saved_linfo; |
5157 | | /* PR 17531: file: 0522b371. */ |
5158 | 0 | if (linfo.li_line_range == 0) |
5159 | 0 | { |
5160 | 0 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
5161 | 0 | return 0; |
5162 | 0 | } |
5163 | 0 | reset_state_machine (linfo.li_default_is_stmt); |
5164 | 0 | } |
5165 | 0 | else |
5166 | 0 | { |
5167 | 0 | unsigned char *hdrptr; |
5168 | |
|
5169 | 0 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
5170 | 0 | & end_of_sequence)) == NULL) |
5171 | 0 | return 0; |
5172 | | |
5173 | | /* PR 17531: file: 0522b371. */ |
5174 | 0 | if (linfo.li_line_range == 0) |
5175 | 0 | { |
5176 | 0 | warn (_("Line range of 0 is invalid, using 1 instead\n")); |
5177 | 0 | linfo.li_line_range = 1; |
5178 | 0 | } |
5179 | 0 | reset_state_machine (linfo.li_default_is_stmt); |
5180 | | |
5181 | | /* Save a pointer to the contents of the Opcodes table. */ |
5182 | 0 | standard_opcodes = hdrptr; |
5183 | | |
5184 | | /* Traverse the Directory table just to count entries. */ |
5185 | 0 | data = standard_opcodes + linfo.li_opcode_base - 1; |
5186 | | /* PR 20440 */ |
5187 | 0 | if (data >= end) |
5188 | 0 | { |
5189 | 0 | warn (_("opcode base of %d extends beyond end of section\n"), |
5190 | 0 | linfo.li_opcode_base); |
5191 | 0 | return 0; |
5192 | 0 | } |
5193 | | |
5194 | 0 | if (linfo.li_version >= 5) |
5195 | 0 | { |
5196 | 0 | unsigned char *format_start, *format; |
5197 | 0 | unsigned int format_count, formati, entryi; |
5198 | |
|
5199 | 0 | load_debug_section_with_follow (line_str, fileptr); |
5200 | | |
5201 | | /* Skip directories format. */ |
5202 | 0 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
5203 | 0 | if (do_checks && format_count > 1) |
5204 | 0 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), |
5205 | 0 | format_count); |
5206 | 0 | format_start = data; |
5207 | 0 | for (formati = 0; formati < format_count; formati++) |
5208 | 0 | { |
5209 | 0 | SKIP_ULEB (data, end); |
5210 | 0 | SKIP_ULEB (data, end); |
5211 | 0 | } |
5212 | |
|
5213 | 0 | READ_ULEB (n_directories, data, end); |
5214 | 0 | if (data >= end) |
5215 | 0 | { |
5216 | 0 | warn (_("Corrupt directories list\n")); |
5217 | 0 | break; |
5218 | 0 | } |
5219 | | |
5220 | 0 | if (n_directories == 0) |
5221 | 0 | directory_table = NULL; |
5222 | 0 | else if (n_directories > section->size) |
5223 | 0 | { |
5224 | 0 | warn (_("number of directories (0x%x) exceeds size of section %s\n"), |
5225 | 0 | n_directories, section->name); |
5226 | 0 | return 0; |
5227 | 0 | } |
5228 | 0 | else |
5229 | 0 | directory_table = (char **) |
5230 | 0 | xcalloc (n_directories, sizeof (unsigned char *)); |
5231 | | |
5232 | 0 | for (entryi = 0; entryi < n_directories; entryi++) |
5233 | 0 | { |
5234 | 0 | char **pathp = &directory_table[entryi]; |
5235 | |
|
5236 | 0 | format = format_start; |
5237 | 0 | for (formati = 0; formati < format_count; formati++) |
5238 | 0 | { |
5239 | 0 | uint64_t content_type, form; |
5240 | 0 | uint64_t uvalue; |
5241 | |
|
5242 | 0 | READ_ULEB (content_type, format, end); |
5243 | 0 | READ_ULEB (form, format, end); |
5244 | 0 | if (data >= end) |
5245 | 0 | { |
5246 | 0 | warn (_("Corrupt directories list\n")); |
5247 | 0 | break; |
5248 | 0 | } |
5249 | 0 | switch (content_type) |
5250 | 0 | { |
5251 | 0 | case DW_LNCT_path: |
5252 | 0 | switch (form) |
5253 | 0 | { |
5254 | 0 | case DW_FORM_string: |
5255 | 0 | *pathp = (char *) data; |
5256 | 0 | break; |
5257 | 0 | case DW_FORM_line_strp: |
5258 | 0 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, |
5259 | 0 | end); |
5260 | | /* Remove const by the cast. */ |
5261 | 0 | *pathp = (char *) |
5262 | 0 | fetch_indirect_line_string (uvalue); |
5263 | 0 | break; |
5264 | 0 | } |
5265 | 0 | break; |
5266 | 0 | } |
5267 | 0 | data = read_and_display_attr_value (0, form, 0, start, |
5268 | 0 | data, end, 0, 0, |
5269 | 0 | linfo.li_offset_size, |
5270 | 0 | linfo.li_version, |
5271 | 0 | NULL, 1, section, |
5272 | 0 | NULL, '\t', -1); |
5273 | 0 | } |
5274 | 0 | if (data >= end) |
5275 | 0 | { |
5276 | 0 | warn (_("Corrupt directories list\n")); |
5277 | 0 | break; |
5278 | 0 | } |
5279 | 0 | } |
5280 | | |
5281 | | /* Skip files format. */ |
5282 | 0 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
5283 | 0 | if (do_checks && format_count > 5) |
5284 | 0 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), |
5285 | 0 | format_count); |
5286 | |
|
5287 | 0 | format_start = data; |
5288 | 0 | for (formati = 0; formati < format_count; formati++) |
5289 | 0 | { |
5290 | 0 | SKIP_ULEB (data, end); |
5291 | 0 | SKIP_ULEB (data, end); |
5292 | 0 | } |
5293 | |
|
5294 | 0 | READ_ULEB (n_files, data, end); |
5295 | 0 | if (data >= end && n_files > 0) |
5296 | 0 | { |
5297 | 0 | warn (_("Corrupt file name list\n")); |
5298 | 0 | break; |
5299 | 0 | } |
5300 | | |
5301 | 0 | if (n_files == 0) |
5302 | 0 | file_table = NULL; |
5303 | 0 | else if (n_files > section->size) |
5304 | 0 | { |
5305 | 0 | warn (_("number of files (0x%x) exceeds size of section %s\n"), |
5306 | 0 | n_files, section->name); |
5307 | 0 | return 0; |
5308 | 0 | } |
5309 | 0 | else |
5310 | 0 | file_table = (File_Entry *) xcalloc (n_files, |
5311 | 0 | sizeof (File_Entry)); |
5312 | | |
5313 | 0 | for (entryi = 0; entryi < n_files; entryi++) |
5314 | 0 | { |
5315 | 0 | File_Entry *file = &file_table[entryi]; |
5316 | |
|
5317 | 0 | format = format_start; |
5318 | 0 | for (formati = 0; formati < format_count; formati++) |
5319 | 0 | { |
5320 | 0 | uint64_t content_type, form; |
5321 | 0 | uint64_t uvalue; |
5322 | 0 | unsigned char *tmp; |
5323 | |
|
5324 | 0 | READ_ULEB (content_type, format, end); |
5325 | 0 | READ_ULEB (form, format, end); |
5326 | 0 | if (data >= end) |
5327 | 0 | { |
5328 | 0 | warn (_("Corrupt file name list\n")); |
5329 | 0 | break; |
5330 | 0 | } |
5331 | 0 | switch (content_type) |
5332 | 0 | { |
5333 | 0 | case DW_LNCT_path: |
5334 | 0 | switch (form) |
5335 | 0 | { |
5336 | 0 | case DW_FORM_string: |
5337 | 0 | file->name = (char *) data; |
5338 | 0 | break; |
5339 | 0 | case DW_FORM_line_strp: |
5340 | 0 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, |
5341 | 0 | end); |
5342 | | /* Remove const by the cast. */ |
5343 | 0 | file->name = (char *) |
5344 | 0 | fetch_indirect_line_string (uvalue); |
5345 | 0 | break; |
5346 | 0 | } |
5347 | 0 | break; |
5348 | 0 | case DW_LNCT_directory_index: |
5349 | 0 | switch (form) |
5350 | 0 | { |
5351 | 0 | case DW_FORM_data1: |
5352 | 0 | SAFE_BYTE_GET (file->directory_index, data, 1, |
5353 | 0 | end); |
5354 | 0 | break; |
5355 | 0 | case DW_FORM_data2: |
5356 | 0 | SAFE_BYTE_GET (file->directory_index, data, 2, |
5357 | 0 | end); |
5358 | 0 | break; |
5359 | 0 | case DW_FORM_udata: |
5360 | 0 | tmp = data; |
5361 | 0 | READ_ULEB (file->directory_index, tmp, end); |
5362 | 0 | break; |
5363 | 0 | } |
5364 | 0 | break; |
5365 | 0 | } |
5366 | 0 | data = read_and_display_attr_value (0, form, 0, start, |
5367 | 0 | data, end, 0, 0, |
5368 | 0 | linfo.li_offset_size, |
5369 | 0 | linfo.li_version, |
5370 | 0 | NULL, 1, section, |
5371 | 0 | NULL, '\t', -1); |
5372 | 0 | } |
5373 | 0 | if (data >= end) |
5374 | 0 | { |
5375 | 0 | warn (_("Corrupt file name list\n")); |
5376 | 0 | break; |
5377 | 0 | } |
5378 | 0 | } |
5379 | 0 | } |
5380 | 0 | else |
5381 | 0 | { |
5382 | 0 | if (*data != 0) |
5383 | 0 | { |
5384 | 0 | char *ptr_directory_table = (char *) data; |
5385 | |
|
5386 | 0 | while (data < end && *data != 0) |
5387 | 0 | { |
5388 | 0 | data += strnlen ((char *) data, end - data); |
5389 | 0 | if (data < end) |
5390 | 0 | data++; |
5391 | 0 | n_directories++; |
5392 | 0 | } |
5393 | | |
5394 | | /* PR 20440 */ |
5395 | 0 | if (data >= end) |
5396 | 0 | { |
5397 | 0 | warn (_("directory table ends unexpectedly\n")); |
5398 | 0 | n_directories = 0; |
5399 | 0 | break; |
5400 | 0 | } |
5401 | | |
5402 | | /* Go through the directory table again to save the directories. */ |
5403 | 0 | directory_table = (char **) |
5404 | 0 | xmalloc (n_directories * sizeof (unsigned char *)); |
5405 | |
|
5406 | 0 | i = 0; |
5407 | 0 | while (*ptr_directory_table != 0) |
5408 | 0 | { |
5409 | 0 | directory_table[i] = ptr_directory_table; |
5410 | 0 | ptr_directory_table += strlen (ptr_directory_table) + 1; |
5411 | 0 | i++; |
5412 | 0 | } |
5413 | 0 | } |
5414 | | /* Skip the NUL at the end of the table. */ |
5415 | 0 | data++; |
5416 | | |
5417 | | /* Traverse the File Name table just to count the entries. */ |
5418 | 0 | if (data < end && *data != 0) |
5419 | 0 | { |
5420 | 0 | unsigned char *ptr_file_name_table = data; |
5421 | |
|
5422 | 0 | while (data < end && *data != 0) |
5423 | 0 | { |
5424 | | /* Skip Name, directory index, last modification |
5425 | | time and length of file. */ |
5426 | 0 | data += strnlen ((char *) data, end - data); |
5427 | 0 | if (data < end) |
5428 | 0 | data++; |
5429 | 0 | SKIP_ULEB (data, end); |
5430 | 0 | SKIP_ULEB (data, end); |
5431 | 0 | SKIP_ULEB (data, end); |
5432 | 0 | n_files++; |
5433 | 0 | } |
5434 | |
|
5435 | 0 | if (data >= end) |
5436 | 0 | { |
5437 | 0 | warn (_("file table ends unexpectedly\n")); |
5438 | 0 | n_files = 0; |
5439 | 0 | break; |
5440 | 0 | } |
5441 | | |
5442 | | /* Go through the file table again to save the strings. */ |
5443 | 0 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); |
5444 | |
|
5445 | 0 | i = 0; |
5446 | 0 | while (*ptr_file_name_table != 0) |
5447 | 0 | { |
5448 | 0 | file_table[i].name = (char *) ptr_file_name_table; |
5449 | 0 | ptr_file_name_table |
5450 | 0 | += strlen ((char *) ptr_file_name_table) + 1; |
5451 | | |
5452 | | /* We are not interested in directory, time or size. */ |
5453 | 0 | READ_ULEB (file_table[i].directory_index, |
5454 | 0 | ptr_file_name_table, end); |
5455 | 0 | READ_ULEB (file_table[i].modification_date, |
5456 | 0 | ptr_file_name_table, end); |
5457 | 0 | READ_ULEB (file_table[i].length, |
5458 | 0 | ptr_file_name_table, end); |
5459 | 0 | i++; |
5460 | 0 | } |
5461 | 0 | i = 0; |
5462 | 0 | } |
5463 | | |
5464 | | /* Skip the NUL at the end of the table. */ |
5465 | 0 | data++; |
5466 | 0 | } |
5467 | | |
5468 | | /* Print the Compilation Unit's name and a header. */ |
5469 | 0 | if (file_table == NULL) |
5470 | 0 | printf (_("CU: No directory table\n")); |
5471 | 0 | else if (directory_table == NULL) |
5472 | 0 | printf (_("CU: %s:\n"), null_name (file_table[0].name)); |
5473 | 0 | else |
5474 | 0 | { |
5475 | 0 | unsigned int ix = file_table[0].directory_index; |
5476 | 0 | const char *directory; |
5477 | |
|
5478 | 0 | if (ix == 0 && linfo.li_version < 5) |
5479 | 0 | directory = "."; |
5480 | | /* PR 20439 */ |
5481 | 0 | else if (n_directories == 0) |
5482 | 0 | directory = _("<unknown>"); |
5483 | 0 | else |
5484 | 0 | { |
5485 | 0 | if (linfo.li_version < 5) |
5486 | 0 | --ix; |
5487 | 0 | if (ix >= n_directories) |
5488 | 0 | { |
5489 | 0 | warn (_("directory index %u " |
5490 | 0 | ">= number of directories %u\n"), |
5491 | 0 | ix, n_directories); |
5492 | 0 | directory = _("<corrupt>"); |
5493 | 0 | } |
5494 | 0 | else |
5495 | 0 | directory = directory_table[ix]; |
5496 | 0 | } |
5497 | 0 | if (do_wide) |
5498 | 0 | printf (_("CU: %s/%s:\n"), |
5499 | 0 | null_name (directory), |
5500 | 0 | null_name (file_table[0].name)); |
5501 | 0 | else |
5502 | 0 | printf ("%s:\n", null_name (file_table[0].name)); |
5503 | 0 | } |
5504 | |
|
5505 | 0 | if (n_files > 0) |
5506 | 0 | { |
5507 | 0 | if (do_wide) |
5508 | 0 | printf (_("File name Line number Starting address View Stmt\n")); |
5509 | 0 | else |
5510 | 0 | printf (_("File name Line number Starting address View Stmt\n")); |
5511 | 0 | } |
5512 | 0 | else |
5513 | 0 | printf (_("CU: Empty file name table\n")); |
5514 | 0 | saved_linfo = linfo; |
5515 | 0 | } |
5516 | | |
5517 | | /* This loop iterates through the Dwarf Line Number Program. */ |
5518 | 0 | while (data < end_of_sequence) |
5519 | 0 | { |
5520 | 0 | unsigned char op_code; |
5521 | 0 | int xop; |
5522 | 0 | int adv; |
5523 | 0 | unsigned long int uladv; |
5524 | 0 | int is_special_opcode = 0; |
5525 | |
|
5526 | 0 | op_code = *data++; |
5527 | 0 | xop = op_code; |
5528 | |
|
5529 | 0 | if (op_code >= linfo.li_opcode_base) |
5530 | 0 | { |
5531 | 0 | op_code -= linfo.li_opcode_base; |
5532 | 0 | uladv = (op_code / linfo.li_line_range); |
5533 | 0 | if (linfo.li_max_ops_per_insn == 1) |
5534 | 0 | { |
5535 | 0 | uladv *= linfo.li_min_insn_length; |
5536 | 0 | state_machine_regs.address += uladv; |
5537 | 0 | if (uladv) |
5538 | 0 | state_machine_regs.view = 0; |
5539 | 0 | } |
5540 | 0 | else |
5541 | 0 | { |
5542 | 0 | unsigned addrdelta |
5543 | 0 | = ((state_machine_regs.op_index + uladv) |
5544 | 0 | / linfo.li_max_ops_per_insn) |
5545 | 0 | * linfo.li_min_insn_length; |
5546 | 0 | state_machine_regs.address |
5547 | 0 | += addrdelta; |
5548 | 0 | state_machine_regs.op_index |
5549 | 0 | = (state_machine_regs.op_index + uladv) |
5550 | 0 | % linfo.li_max_ops_per_insn; |
5551 | 0 | if (addrdelta) |
5552 | 0 | state_machine_regs.view = 0; |
5553 | 0 | } |
5554 | |
|
5555 | 0 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
5556 | 0 | state_machine_regs.line += adv; |
5557 | 0 | is_special_opcode = 1; |
5558 | | /* Increment view after printing this row. */ |
5559 | 0 | } |
5560 | 0 | else |
5561 | 0 | switch (op_code) |
5562 | 0 | { |
5563 | 0 | case DW_LNS_extended_op: |
5564 | 0 | { |
5565 | 0 | unsigned int ext_op_code_len; |
5566 | 0 | unsigned char ext_op_code; |
5567 | 0 | unsigned char *op_code_end; |
5568 | 0 | unsigned char *op_code_data = data; |
5569 | |
|
5570 | 0 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); |
5571 | 0 | op_code_end = op_code_data + ext_op_code_len; |
5572 | 0 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) |
5573 | 0 | { |
5574 | 0 | warn (_("Badly formed extended line op encountered!\n")); |
5575 | 0 | break; |
5576 | 0 | } |
5577 | 0 | ext_op_code = *op_code_data++; |
5578 | 0 | xop = ext_op_code; |
5579 | 0 | xop = -xop; |
5580 | |
|
5581 | 0 | switch (ext_op_code) |
5582 | 0 | { |
5583 | 0 | case DW_LNE_end_sequence: |
5584 | | /* Reset stuff after printing this row. */ |
5585 | 0 | break; |
5586 | 0 | case DW_LNE_set_address: |
5587 | 0 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, |
5588 | 0 | op_code_data, |
5589 | 0 | op_code_end - op_code_data, |
5590 | 0 | op_code_end); |
5591 | 0 | state_machine_regs.op_index = 0; |
5592 | 0 | state_machine_regs.view = 0; |
5593 | 0 | break; |
5594 | 0 | case DW_LNE_define_file: |
5595 | 0 | file_table = (File_Entry *) xrealloc |
5596 | 0 | (file_table, (n_files + 1) * sizeof (File_Entry)); |
5597 | |
|
5598 | 0 | ++state_machine_regs.last_file_entry; |
5599 | | /* Source file name. */ |
5600 | 0 | file_table[n_files].name = (char *) op_code_data; |
5601 | 0 | op_code_data += strlen ((char *) op_code_data) + 1; |
5602 | | /* Directory index. */ |
5603 | 0 | READ_ULEB (file_table[n_files].directory_index, |
5604 | 0 | op_code_data, op_code_end); |
5605 | | /* Last modification time. */ |
5606 | 0 | READ_ULEB (file_table[n_files].modification_date, |
5607 | 0 | op_code_data, op_code_end); |
5608 | | /* File length. */ |
5609 | 0 | READ_ULEB (file_table[n_files].length, |
5610 | 0 | op_code_data, op_code_end); |
5611 | 0 | n_files++; |
5612 | 0 | break; |
5613 | | |
5614 | 0 | case DW_LNE_set_discriminator: |
5615 | 0 | case DW_LNE_HP_set_sequence: |
5616 | | /* Simply ignored. */ |
5617 | 0 | break; |
5618 | | |
5619 | 0 | default: |
5620 | 0 | printf (_("UNKNOWN (%u): length %ld\n"), |
5621 | 0 | ext_op_code, (long int) (op_code_data - data)); |
5622 | 0 | break; |
5623 | 0 | } |
5624 | 0 | data = op_code_end; |
5625 | 0 | break; |
5626 | 0 | } |
5627 | 0 | case DW_LNS_copy: |
5628 | | /* Increment view after printing this row. */ |
5629 | 0 | break; |
5630 | | |
5631 | 0 | case DW_LNS_advance_pc: |
5632 | 0 | READ_ULEB (uladv, data, end); |
5633 | 0 | if (linfo.li_max_ops_per_insn == 1) |
5634 | 0 | { |
5635 | 0 | uladv *= linfo.li_min_insn_length; |
5636 | 0 | state_machine_regs.address += uladv; |
5637 | 0 | if (uladv) |
5638 | 0 | state_machine_regs.view = 0; |
5639 | 0 | } |
5640 | 0 | else |
5641 | 0 | { |
5642 | 0 | unsigned addrdelta |
5643 | 0 | = ((state_machine_regs.op_index + uladv) |
5644 | 0 | / linfo.li_max_ops_per_insn) |
5645 | 0 | * linfo.li_min_insn_length; |
5646 | 0 | state_machine_regs.address |
5647 | 0 | += addrdelta; |
5648 | 0 | state_machine_regs.op_index |
5649 | 0 | = (state_machine_regs.op_index + uladv) |
5650 | 0 | % linfo.li_max_ops_per_insn; |
5651 | 0 | if (addrdelta) |
5652 | 0 | state_machine_regs.view = 0; |
5653 | 0 | } |
5654 | 0 | break; |
5655 | | |
5656 | 0 | case DW_LNS_advance_line: |
5657 | 0 | READ_SLEB (adv, data, end); |
5658 | 0 | state_machine_regs.line += adv; |
5659 | 0 | break; |
5660 | | |
5661 | 0 | case DW_LNS_set_file: |
5662 | 0 | READ_ULEB (uladv, data, end); |
5663 | 0 | state_machine_regs.file = uladv; |
5664 | |
|
5665 | 0 | unsigned file = state_machine_regs.file; |
5666 | 0 | if (linfo.li_version < 5) |
5667 | 0 | --file; |
5668 | |
|
5669 | 0 | if (file_table == NULL || n_files == 0) |
5670 | 0 | printf (_("\n [Use file table entry %d]\n"), file); |
5671 | | /* PR 20439 */ |
5672 | 0 | else if (file >= n_files) |
5673 | 0 | { |
5674 | 0 | warn (_("file index %u >= number of files %u\n"), |
5675 | 0 | file, n_files); |
5676 | 0 | printf (_("\n <over large file table index %u>"), file); |
5677 | 0 | } |
5678 | 0 | else |
5679 | 0 | { |
5680 | 0 | unsigned dir = file_table[file].directory_index; |
5681 | 0 | if (dir == 0 && linfo.li_version < 5) |
5682 | | /* If directory index is 0, that means compilation |
5683 | | current directory. bfd/dwarf2.c shows |
5684 | | DW_AT_comp_dir here but in keeping with the |
5685 | | readelf practice of minimal interpretation of |
5686 | | file data, we show "./". */ |
5687 | 0 | printf ("\n./%s:[++]\n", |
5688 | 0 | null_name (file_table[file].name)); |
5689 | 0 | else if (directory_table == NULL || n_directories == 0) |
5690 | 0 | printf (_("\n [Use file %s " |
5691 | 0 | "in directory table entry %d]\n"), |
5692 | 0 | null_name (file_table[file].name), dir); |
5693 | 0 | else |
5694 | 0 | { |
5695 | 0 | if (linfo.li_version < 5) |
5696 | 0 | --dir; |
5697 | | /* PR 20439 */ |
5698 | 0 | if (dir >= n_directories) |
5699 | 0 | { |
5700 | 0 | warn (_("directory index %u " |
5701 | 0 | ">= number of directories %u\n"), |
5702 | 0 | dir, n_directories); |
5703 | 0 | printf (_("\n <over large directory table entry " |
5704 | 0 | "%u>\n"), dir); |
5705 | 0 | } |
5706 | 0 | else |
5707 | 0 | printf ("\n%s/%s:\n", |
5708 | 0 | null_name (directory_table[dir]), |
5709 | 0 | null_name (file_table[file].name)); |
5710 | 0 | } |
5711 | 0 | } |
5712 | 0 | break; |
5713 | | |
5714 | 0 | case DW_LNS_set_column: |
5715 | 0 | READ_ULEB (uladv, data, end); |
5716 | 0 | state_machine_regs.column = uladv; |
5717 | 0 | break; |
5718 | | |
5719 | 0 | case DW_LNS_negate_stmt: |
5720 | 0 | adv = state_machine_regs.is_stmt; |
5721 | 0 | adv = ! adv; |
5722 | 0 | state_machine_regs.is_stmt = adv; |
5723 | 0 | break; |
5724 | | |
5725 | 0 | case DW_LNS_set_basic_block: |
5726 | 0 | state_machine_regs.basic_block = 1; |
5727 | 0 | break; |
5728 | | |
5729 | 0 | case DW_LNS_const_add_pc: |
5730 | 0 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); |
5731 | 0 | if (linfo.li_max_ops_per_insn == 1) |
5732 | 0 | { |
5733 | 0 | uladv *= linfo.li_min_insn_length; |
5734 | 0 | state_machine_regs.address += uladv; |
5735 | 0 | if (uladv) |
5736 | 0 | state_machine_regs.view = 0; |
5737 | 0 | } |
5738 | 0 | else |
5739 | 0 | { |
5740 | 0 | unsigned addrdelta |
5741 | 0 | = ((state_machine_regs.op_index + uladv) |
5742 | 0 | / linfo.li_max_ops_per_insn) |
5743 | 0 | * linfo.li_min_insn_length; |
5744 | 0 | state_machine_regs.address |
5745 | 0 | += addrdelta; |
5746 | 0 | state_machine_regs.op_index |
5747 | 0 | = (state_machine_regs.op_index + uladv) |
5748 | 0 | % linfo.li_max_ops_per_insn; |
5749 | 0 | if (addrdelta) |
5750 | 0 | state_machine_regs.view = 0; |
5751 | 0 | } |
5752 | 0 | break; |
5753 | | |
5754 | 0 | case DW_LNS_fixed_advance_pc: |
5755 | 0 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); |
5756 | 0 | state_machine_regs.address += uladv; |
5757 | 0 | state_machine_regs.op_index = 0; |
5758 | | /* Do NOT reset view. */ |
5759 | 0 | break; |
5760 | | |
5761 | 0 | case DW_LNS_set_prologue_end: |
5762 | 0 | break; |
5763 | | |
5764 | 0 | case DW_LNS_set_epilogue_begin: |
5765 | 0 | break; |
5766 | | |
5767 | 0 | case DW_LNS_set_isa: |
5768 | 0 | READ_ULEB (uladv, data, end); |
5769 | 0 | printf (_(" Set ISA to %lu\n"), uladv); |
5770 | 0 | break; |
5771 | | |
5772 | 0 | default: |
5773 | 0 | printf (_(" Unknown opcode %d with operands: "), op_code); |
5774 | |
|
5775 | 0 | if (standard_opcodes != NULL) |
5776 | 0 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) |
5777 | 0 | { |
5778 | 0 | uint64_t val; |
5779 | |
|
5780 | 0 | READ_ULEB (val, data, end); |
5781 | 0 | printf ("%#" PRIx64 "%s", val, i == 1 ? "" : ", "); |
5782 | 0 | } |
5783 | 0 | putchar ('\n'); |
5784 | 0 | break; |
5785 | 0 | } |
5786 | | |
5787 | | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
5788 | | to the DWARF address/line matrix. */ |
5789 | 0 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
5790 | 0 | || (xop == DW_LNS_copy)) |
5791 | 0 | { |
5792 | 0 | const unsigned int MAX_FILENAME_LENGTH = 35; |
5793 | 0 | char *fileName = NULL; |
5794 | 0 | char *newFileName = NULL; |
5795 | 0 | size_t fileNameLength; |
5796 | |
|
5797 | 0 | if (file_table) |
5798 | 0 | { |
5799 | 0 | unsigned indx = state_machine_regs.file; |
5800 | |
|
5801 | 0 | if (linfo.li_version < 5) |
5802 | 0 | --indx; |
5803 | | /* PR 20439 */ |
5804 | 0 | if (indx >= n_files) |
5805 | 0 | { |
5806 | 0 | warn (_("file index %u >= number of files %u\n"), |
5807 | 0 | indx, n_files); |
5808 | 0 | fileName = _("<corrupt>"); |
5809 | 0 | } |
5810 | 0 | else |
5811 | 0 | fileName = (char *) file_table[indx].name; |
5812 | 0 | } |
5813 | 0 | if (!fileName) |
5814 | 0 | fileName = _("<unknown>"); |
5815 | |
|
5816 | 0 | fileNameLength = strlen (fileName); |
5817 | 0 | newFileName = fileName; |
5818 | 0 | if (fileNameLength > MAX_FILENAME_LENGTH && !do_wide) |
5819 | 0 | { |
5820 | 0 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); |
5821 | | /* Truncate file name */ |
5822 | 0 | memcpy (newFileName, |
5823 | 0 | fileName + fileNameLength - MAX_FILENAME_LENGTH, |
5824 | 0 | MAX_FILENAME_LENGTH); |
5825 | 0 | newFileName[MAX_FILENAME_LENGTH] = 0; |
5826 | 0 | } |
5827 | | |
5828 | | /* A row with end_seq set to true has a meaningful address, but |
5829 | | the other information in the same row is not significant. |
5830 | | In such a row, print line as "-", and don't print |
5831 | | view/is_stmt. */ |
5832 | 0 | if (!do_wide || fileNameLength <= MAX_FILENAME_LENGTH) |
5833 | 0 | { |
5834 | 0 | if (linfo.li_max_ops_per_insn == 1) |
5835 | 0 | { |
5836 | 0 | if (xop == -DW_LNE_end_sequence) |
5837 | 0 | printf ("%-31s %11s %#18" PRIx64, |
5838 | 0 | newFileName, "-", |
5839 | 0 | state_machine_regs.address); |
5840 | 0 | else |
5841 | 0 | printf ("%-31s %11d %#18" PRIx64, |
5842 | 0 | newFileName, state_machine_regs.line, |
5843 | 0 | state_machine_regs.address); |
5844 | 0 | } |
5845 | 0 | else |
5846 | 0 | { |
5847 | 0 | if (xop == -DW_LNE_end_sequence) |
5848 | 0 | printf ("%-31s %11s %#18" PRIx64 "[%d]", |
5849 | 0 | newFileName, "-", |
5850 | 0 | state_machine_regs.address, |
5851 | 0 | state_machine_regs.op_index); |
5852 | 0 | else |
5853 | 0 | printf ("%-31s %11d %#18" PRIx64 "[%d]", |
5854 | 0 | newFileName, state_machine_regs.line, |
5855 | 0 | state_machine_regs.address, |
5856 | 0 | state_machine_regs.op_index); |
5857 | 0 | } |
5858 | 0 | } |
5859 | 0 | else |
5860 | 0 | { |
5861 | 0 | if (linfo.li_max_ops_per_insn == 1) |
5862 | 0 | { |
5863 | 0 | if (xop == -DW_LNE_end_sequence) |
5864 | 0 | printf ("%s %11s %#18" PRIx64, |
5865 | 0 | newFileName, "-", |
5866 | 0 | state_machine_regs.address); |
5867 | 0 | else |
5868 | 0 | printf ("%s %11d %#18" PRIx64, |
5869 | 0 | newFileName, state_machine_regs.line, |
5870 | 0 | state_machine_regs.address); |
5871 | 0 | } |
5872 | 0 | else |
5873 | 0 | { |
5874 | 0 | if (xop == -DW_LNE_end_sequence) |
5875 | 0 | printf ("%s %11s %#18" PRIx64 "[%d]", |
5876 | 0 | newFileName, "-", |
5877 | 0 | state_machine_regs.address, |
5878 | 0 | state_machine_regs.op_index); |
5879 | 0 | else |
5880 | 0 | printf ("%s %11d %#18" PRIx64 "[%d]", |
5881 | 0 | newFileName, state_machine_regs.line, |
5882 | 0 | state_machine_regs.address, |
5883 | 0 | state_machine_regs.op_index); |
5884 | 0 | } |
5885 | 0 | } |
5886 | |
|
5887 | 0 | if (xop != -DW_LNE_end_sequence) |
5888 | 0 | { |
5889 | 0 | if (state_machine_regs.view) |
5890 | 0 | printf (" %6u", state_machine_regs.view); |
5891 | 0 | else |
5892 | 0 | printf (" "); |
5893 | |
|
5894 | 0 | if (state_machine_regs.is_stmt) |
5895 | 0 | printf (" x"); |
5896 | 0 | } |
5897 | |
|
5898 | 0 | putchar ('\n'); |
5899 | 0 | state_machine_regs.view++; |
5900 | |
|
5901 | 0 | if (xop == -DW_LNE_end_sequence) |
5902 | 0 | { |
5903 | 0 | reset_state_machine (linfo.li_default_is_stmt); |
5904 | 0 | putchar ('\n'); |
5905 | 0 | } |
5906 | |
|
5907 | 0 | if (newFileName != fileName) |
5908 | 0 | free (newFileName); |
5909 | 0 | } |
5910 | 0 | } |
5911 | | |
5912 | 0 | if (file_table) |
5913 | 0 | { |
5914 | 0 | free (file_table); |
5915 | 0 | file_table = NULL; |
5916 | 0 | n_files = 0; |
5917 | 0 | } |
5918 | |
|
5919 | 0 | if (directory_table) |
5920 | 0 | { |
5921 | 0 | free (directory_table); |
5922 | 0 | directory_table = NULL; |
5923 | 0 | n_directories = 0; |
5924 | 0 | } |
5925 | |
|
5926 | 0 | putchar ('\n'); |
5927 | 0 | } |
5928 | | |
5929 | 0 | return 1; |
5930 | 0 | } |
5931 | | |
5932 | | static int |
5933 | | display_debug_lines (struct dwarf_section *section, void *file) |
5934 | 1.53k | { |
5935 | 1.53k | unsigned char *data = section->start; |
5936 | 1.53k | unsigned char *end = data + section->size; |
5937 | 1.53k | int retValRaw = 1; |
5938 | 1.53k | int retValDecoded = 1; |
5939 | | |
5940 | 1.53k | if (do_debug_lines == 0) |
5941 | 0 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; |
5942 | | |
5943 | 1.53k | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
5944 | 1.53k | retValRaw = display_debug_lines_raw (section, data, end, file); |
5945 | | |
5946 | 1.53k | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
5947 | 0 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
5948 | | |
5949 | 1.53k | if (!retValRaw || !retValDecoded) |
5950 | 661 | return 0; |
5951 | | |
5952 | 872 | return 1; |
5953 | 1.53k | } |
5954 | | |
5955 | | static debug_info * |
5956 | | find_debug_info_for_offset (uint64_t offset) |
5957 | 872 | { |
5958 | 872 | unsigned int i; |
5959 | | |
5960 | 872 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
5961 | 0 | return NULL; |
5962 | | |
5963 | 36.9k | for (i = 0; i < num_debug_info_entries; i++) |
5964 | 36.9k | if (debug_information[i].cu_offset == offset) |
5965 | 871 | return debug_information + i; |
5966 | | |
5967 | 1 | return NULL; |
5968 | 872 | } |
5969 | | |
5970 | | static const char * |
5971 | | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) |
5972 | 1.79k | { |
5973 | | /* See gdb/gdb-index.h. */ |
5974 | 1.79k | static const char * const kinds[] = |
5975 | 1.79k | { |
5976 | 1.79k | N_ ("no info"), |
5977 | 1.79k | N_ ("type"), |
5978 | 1.79k | N_ ("variable"), |
5979 | 1.79k | N_ ("function"), |
5980 | 1.79k | N_ ("other"), |
5981 | 1.79k | N_ ("unused5"), |
5982 | 1.79k | N_ ("unused6"), |
5983 | 1.79k | N_ ("unused7") |
5984 | 1.79k | }; |
5985 | | |
5986 | 1.79k | return _ (kinds[kind]); |
5987 | 1.79k | } |
5988 | | |
5989 | | static int |
5990 | | display_debug_pubnames_worker (struct dwarf_section *section, |
5991 | | void *file ATTRIBUTE_UNUSED, |
5992 | | int is_gnu) |
5993 | 366 | { |
5994 | 366 | DWARF2_Internal_PubNames names; |
5995 | 366 | unsigned char *start = section->start; |
5996 | 366 | unsigned char *end = start + section->size; |
5997 | | |
5998 | | /* It does not matter if this load fails, |
5999 | | we test for that later on. */ |
6000 | 366 | load_debug_info (file); |
6001 | | |
6002 | 366 | introduce (section, false); |
6003 | | |
6004 | 6.84k | while (start < end) |
6005 | 6.65k | { |
6006 | 6.65k | unsigned char *data; |
6007 | 6.65k | unsigned long sec_off = start - section->start; |
6008 | 6.65k | unsigned int offset_size; |
6009 | | |
6010 | 6.65k | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
6011 | 6.65k | if (names.pn_length == 0xffffffff) |
6012 | 2 | { |
6013 | 2 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
6014 | 2 | offset_size = 8; |
6015 | 2 | } |
6016 | 6.65k | else |
6017 | 6.65k | offset_size = 4; |
6018 | | |
6019 | 6.65k | if (names.pn_length > (size_t) (end - start)) |
6020 | 169 | { |
6021 | 169 | warn (_("Debug info is corrupted, " |
6022 | 169 | "%s header at %#lx has length %#" PRIx64 "\n"), |
6023 | 169 | section->name, sec_off, names.pn_length); |
6024 | 169 | break; |
6025 | 169 | } |
6026 | | |
6027 | 6.48k | data = start; |
6028 | 6.48k | start += names.pn_length; |
6029 | | |
6030 | 6.48k | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, start); |
6031 | 6.48k | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, start); |
6032 | | |
6033 | 6.48k | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
6034 | 6.48k | && num_debug_info_entries > 0 |
6035 | 6.48k | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6036 | 1 | warn (_(".debug_info offset of %#" PRIx64 |
6037 | 1 | " in %s section does not point to a CU header.\n"), |
6038 | 1 | names.pn_offset, section->name); |
6039 | | |
6040 | 6.48k | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, start); |
6041 | | |
6042 | 6.48k | printf (_(" Length: %" PRId64 "\n"), |
6043 | 6.48k | names.pn_length); |
6044 | 6.48k | printf (_(" Version: %d\n"), |
6045 | 6.48k | names.pn_version); |
6046 | 6.48k | printf (_(" Offset into .debug_info section: %#" PRIx64 "\n"), |
6047 | 6.48k | names.pn_offset); |
6048 | 6.48k | printf (_(" Size of area in .debug_info section: %" PRId64 "\n"), |
6049 | 6.48k | names.pn_size); |
6050 | | |
6051 | 6.48k | if (names.pn_version != 2 && names.pn_version != 3) |
6052 | 1.44k | { |
6053 | 1.44k | static int warned = 0; |
6054 | | |
6055 | 1.44k | if (! warned) |
6056 | 2 | { |
6057 | 2 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); |
6058 | 2 | warned = 1; |
6059 | 2 | } |
6060 | | |
6061 | 1.44k | continue; |
6062 | 1.44k | } |
6063 | | |
6064 | 5.03k | if (is_gnu) |
6065 | 113 | printf (_("\n Offset Kind Name\n")); |
6066 | 4.92k | else |
6067 | 4.92k | printf (_("\n Offset\tName\n")); |
6068 | | |
6069 | 19.6k | while (1) |
6070 | 19.6k | { |
6071 | 19.6k | size_t maxprint; |
6072 | 19.6k | uint64_t offset; |
6073 | | |
6074 | 19.6k | SAFE_BYTE_GET_AND_INC (offset, data, offset_size, start); |
6075 | | |
6076 | 19.6k | if (offset == 0) |
6077 | 5.01k | break; |
6078 | | |
6079 | 14.6k | if (data >= start) |
6080 | 10 | break; |
6081 | 14.6k | maxprint = (start - data) - 1; |
6082 | | |
6083 | 14.6k | if (is_gnu) |
6084 | 1.79k | { |
6085 | 1.79k | unsigned int kind_data; |
6086 | 1.79k | gdb_index_symbol_kind kind; |
6087 | 1.79k | const char *kind_name; |
6088 | 1.79k | int is_static; |
6089 | | |
6090 | 1.79k | SAFE_BYTE_GET_AND_INC (kind_data, data, 1, start); |
6091 | 1.79k | maxprint --; |
6092 | | /* GCC computes the kind as the upper byte in the CU index |
6093 | | word, and then right shifts it by the CU index size. |
6094 | | Left shift KIND to where the gdb-index.h accessor macros |
6095 | | can use it. */ |
6096 | 1.79k | kind_data <<= GDB_INDEX_CU_BITSIZE; |
6097 | 1.79k | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); |
6098 | 1.79k | kind_name = get_gdb_index_symbol_kind_name (kind); |
6099 | 1.79k | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); |
6100 | 1.79k | printf (" %-6" PRIx64 " %s,%-10s %.*s\n", |
6101 | 1.79k | offset, is_static ? _("s") : _("g"), |
6102 | 1.79k | kind_name, (int) maxprint, data); |
6103 | 1.79k | } |
6104 | 12.8k | else |
6105 | 12.8k | printf (" %-6" PRIx64 "\t%.*s\n", |
6106 | 12.8k | offset, (int) maxprint, data); |
6107 | | |
6108 | 14.6k | data += strnlen ((char *) data, maxprint); |
6109 | 14.6k | if (data < start) |
6110 | 14.6k | data++; |
6111 | 14.6k | if (data >= start) |
6112 | 16 | break; |
6113 | 14.6k | } |
6114 | 5.03k | } |
6115 | | |
6116 | 366 | printf ("\n"); |
6117 | 366 | return 1; |
6118 | 366 | } |
6119 | | |
6120 | | static int |
6121 | | display_debug_pubnames (struct dwarf_section *section, void *file) |
6122 | 206 | { |
6123 | 206 | return display_debug_pubnames_worker (section, file, 0); |
6124 | 206 | } |
6125 | | |
6126 | | static int |
6127 | | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) |
6128 | 160 | { |
6129 | 160 | return display_debug_pubnames_worker (section, file, 1); |
6130 | 160 | } |
6131 | | |
6132 | | static int |
6133 | | display_debug_macinfo (struct dwarf_section *section, |
6134 | | void *file ATTRIBUTE_UNUSED) |
6135 | 0 | { |
6136 | 0 | unsigned char *start = section->start; |
6137 | 0 | unsigned char *end = start + section->size; |
6138 | 0 | unsigned char *curr = start; |
6139 | 0 | enum dwarf_macinfo_record_type op; |
6140 | |
|
6141 | 0 | introduce (section, false); |
6142 | |
|
6143 | 0 | while (curr < end) |
6144 | 0 | { |
6145 | 0 | unsigned int lineno; |
6146 | 0 | const unsigned char *string; |
6147 | |
|
6148 | 0 | op = (enum dwarf_macinfo_record_type) *curr; |
6149 | 0 | curr++; |
6150 | |
|
6151 | 0 | switch (op) |
6152 | 0 | { |
6153 | 0 | case DW_MACINFO_start_file: |
6154 | 0 | { |
6155 | 0 | unsigned int filenum; |
6156 | |
|
6157 | 0 | READ_ULEB (lineno, curr, end); |
6158 | 0 | READ_ULEB (filenum, curr, end); |
6159 | 0 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
6160 | 0 | lineno, filenum); |
6161 | 0 | } |
6162 | 0 | break; |
6163 | | |
6164 | 0 | case DW_MACINFO_end_file: |
6165 | 0 | printf (_(" DW_MACINFO_end_file\n")); |
6166 | 0 | break; |
6167 | | |
6168 | 0 | case DW_MACINFO_define: |
6169 | 0 | READ_ULEB (lineno, curr, end); |
6170 | 0 | string = curr; |
6171 | 0 | curr += strnlen ((char *) string, end - string); |
6172 | 0 | printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"), |
6173 | 0 | lineno, (int) (curr - string), string); |
6174 | 0 | if (curr < end) |
6175 | 0 | curr++; |
6176 | 0 | break; |
6177 | | |
6178 | 0 | case DW_MACINFO_undef: |
6179 | 0 | READ_ULEB (lineno, curr, end); |
6180 | 0 | string = curr; |
6181 | 0 | curr += strnlen ((char *) string, end - string); |
6182 | 0 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"), |
6183 | 0 | lineno, (int) (curr - string), string); |
6184 | 0 | if (curr < end) |
6185 | 0 | curr++; |
6186 | 0 | break; |
6187 | | |
6188 | 0 | case DW_MACINFO_vendor_ext: |
6189 | 0 | { |
6190 | 0 | unsigned int constant; |
6191 | |
|
6192 | 0 | READ_ULEB (constant, curr, end); |
6193 | 0 | string = curr; |
6194 | 0 | curr += strnlen ((char *) string, end - string); |
6195 | 0 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"), |
6196 | 0 | constant, (int) (curr - string), string); |
6197 | 0 | if (curr < end) |
6198 | 0 | curr++; |
6199 | 0 | } |
6200 | 0 | break; |
6201 | 0 | } |
6202 | 0 | } |
6203 | | |
6204 | 0 | return 1; |
6205 | 0 | } |
6206 | | |
6207 | | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
6208 | | filename and dirname corresponding to file name table entry with index |
6209 | | FILEIDX. Return NULL on failure. */ |
6210 | | |
6211 | | static unsigned char * |
6212 | | get_line_filename_and_dirname (uint64_t line_offset, |
6213 | | uint64_t fileidx, |
6214 | | unsigned char **dir_name) |
6215 | 972 | { |
6216 | 972 | struct dwarf_section *section = &debug_displays [line].section; |
6217 | 972 | unsigned char *hdrptr, *dirtable, *file_name; |
6218 | 972 | unsigned int offset_size; |
6219 | 972 | unsigned int version, opcode_base; |
6220 | 972 | uint64_t length, diridx; |
6221 | 972 | const unsigned char * end; |
6222 | | |
6223 | 972 | *dir_name = NULL; |
6224 | 972 | if (section->start == NULL |
6225 | 972 | || line_offset >= section->size |
6226 | 972 | || fileidx == 0) |
6227 | 972 | return NULL; |
6228 | | |
6229 | 0 | hdrptr = section->start + line_offset; |
6230 | 0 | end = section->start + section->size; |
6231 | |
|
6232 | 0 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); |
6233 | 0 | if (length == 0xffffffff) |
6234 | 0 | { |
6235 | | /* This section is 64-bit DWARF 3. */ |
6236 | 0 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
6237 | 0 | offset_size = 8; |
6238 | 0 | } |
6239 | 0 | else |
6240 | 0 | offset_size = 4; |
6241 | | |
6242 | 0 | if (length > (size_t) (end - hdrptr) |
6243 | 0 | || length < 2 + offset_size + 1 + 3 + 1) |
6244 | 0 | return NULL; |
6245 | 0 | end = hdrptr + length; |
6246 | |
|
6247 | 0 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); |
6248 | 0 | if (version != 2 && version != 3 && version != 4) |
6249 | 0 | return NULL; |
6250 | 0 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ |
6251 | 0 | if (version >= 4) |
6252 | 0 | hdrptr++; /* Skip max_ops_per_insn. */ |
6253 | 0 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ |
6254 | |
|
6255 | 0 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); |
6256 | 0 | if (opcode_base == 0 |
6257 | 0 | || opcode_base - 1 >= (size_t) (end - hdrptr)) |
6258 | 0 | return NULL; |
6259 | | |
6260 | 0 | hdrptr += opcode_base - 1; |
6261 | |
|
6262 | 0 | dirtable = hdrptr; |
6263 | | /* Skip over dirname table. */ |
6264 | 0 | while (*hdrptr != '\0') |
6265 | 0 | { |
6266 | 0 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
6267 | 0 | if (hdrptr < end) |
6268 | 0 | hdrptr++; |
6269 | 0 | if (hdrptr >= end) |
6270 | 0 | return NULL; |
6271 | 0 | } |
6272 | 0 | hdrptr++; /* Skip the NUL at the end of the table. */ |
6273 | | |
6274 | | /* Now skip over preceding filename table entries. */ |
6275 | 0 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
6276 | 0 | { |
6277 | 0 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
6278 | 0 | if (hdrptr < end) |
6279 | 0 | hdrptr++; |
6280 | 0 | SKIP_ULEB (hdrptr, end); |
6281 | 0 | SKIP_ULEB (hdrptr, end); |
6282 | 0 | SKIP_ULEB (hdrptr, end); |
6283 | 0 | } |
6284 | 0 | if (hdrptr >= end || *hdrptr == '\0') |
6285 | 0 | return NULL; |
6286 | | |
6287 | 0 | file_name = hdrptr; |
6288 | 0 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
6289 | 0 | if (hdrptr < end) |
6290 | 0 | hdrptr++; |
6291 | 0 | if (hdrptr >= end) |
6292 | 0 | return NULL; |
6293 | 0 | READ_ULEB (diridx, hdrptr, end); |
6294 | 0 | if (diridx == 0) |
6295 | 0 | return file_name; |
6296 | 0 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
6297 | 0 | { |
6298 | 0 | dirtable += strnlen ((char *) dirtable, end - dirtable); |
6299 | 0 | if (dirtable < end) |
6300 | 0 | dirtable++; |
6301 | 0 | } |
6302 | 0 | if (dirtable >= end || *dirtable == '\0') |
6303 | 0 | return NULL; |
6304 | 0 | *dir_name = dirtable; |
6305 | 0 | return file_name; |
6306 | 0 | } |
6307 | | |
6308 | | static int |
6309 | | display_debug_macro (struct dwarf_section *section, |
6310 | | void *file) |
6311 | 273 | { |
6312 | 273 | unsigned char *start = section->start; |
6313 | 273 | unsigned char *end = start + section->size; |
6314 | 273 | unsigned char *curr = start; |
6315 | 273 | unsigned char *extended_op_buf[256]; |
6316 | 273 | bool is_dwo = false; |
6317 | 273 | const char *suffix = strrchr (section->name, '.'); |
6318 | | |
6319 | 273 | if (suffix && strcmp (suffix, ".dwo") == 0) |
6320 | 0 | is_dwo = true; |
6321 | | |
6322 | 273 | if (is_dwo) |
6323 | 0 | { |
6324 | 0 | load_debug_section_with_follow (str_dwo, file); |
6325 | 0 | load_debug_section_with_follow (str_index_dwo, file); |
6326 | 0 | } |
6327 | 273 | else |
6328 | 273 | { |
6329 | 273 | load_debug_section_with_follow (str, file); |
6330 | 273 | load_debug_section_with_follow (str_index, file); |
6331 | 273 | } |
6332 | 273 | load_debug_section_with_follow (line, file); |
6333 | | |
6334 | 273 | introduce (section, false); |
6335 | | |
6336 | 795 | while (curr < end) |
6337 | 776 | { |
6338 | 776 | unsigned int lineno, version, flags; |
6339 | 776 | unsigned int offset_size; |
6340 | 776 | const unsigned char *string; |
6341 | 776 | uint64_t line_offset = 0, sec_offset = curr - start, offset; |
6342 | 776 | unsigned char **extended_ops = NULL; |
6343 | | |
6344 | 776 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
6345 | 776 | if (version != 4 && version != 5) |
6346 | 70 | { |
6347 | 70 | error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"), |
6348 | 70 | section->name, version); |
6349 | 70 | return 0; |
6350 | 70 | } |
6351 | | |
6352 | 706 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
6353 | 706 | offset_size = (flags & 1) ? 8 : 4; |
6354 | 706 | printf (_(" Offset: %#" PRIx64 "\n"), sec_offset); |
6355 | 706 | printf (_(" Version: %d\n"), version); |
6356 | 706 | printf (_(" Offset size: %d\n"), offset_size); |
6357 | 706 | if (flags & 2) |
6358 | 133 | { |
6359 | 133 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
6360 | 133 | printf (_(" Offset into .debug_line: %#" PRIx64 "\n"), |
6361 | 133 | line_offset); |
6362 | 133 | } |
6363 | 706 | if (flags & 4) |
6364 | 103 | { |
6365 | 103 | unsigned int i, count, op; |
6366 | 103 | uint64_t nargs, n; |
6367 | | |
6368 | 103 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); |
6369 | | |
6370 | 103 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
6371 | 103 | extended_ops = extended_op_buf; |
6372 | 103 | if (count) |
6373 | 96 | { |
6374 | 96 | printf (_(" Extension opcode arguments:\n")); |
6375 | 2.03k | for (i = 0; i < count; i++) |
6376 | 1.97k | { |
6377 | 1.97k | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
6378 | 1.97k | extended_ops[op] = curr; |
6379 | 1.97k | READ_ULEB (nargs, curr, end); |
6380 | 1.97k | if (nargs == 0) |
6381 | 1.54k | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
6382 | 432 | else |
6383 | 432 | { |
6384 | 432 | printf (_(" DW_MACRO_%02x arguments: "), op); |
6385 | 3.14k | for (n = 0; n < nargs; n++) |
6386 | 2.75k | { |
6387 | 2.75k | unsigned int form; |
6388 | | |
6389 | 2.75k | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); |
6390 | 2.75k | printf ("%s%s", get_FORM_name (form), |
6391 | 2.75k | n == nargs - 1 ? "\n" : ", "); |
6392 | 2.75k | switch (form) |
6393 | 2.75k | { |
6394 | 2 | case DW_FORM_data1: |
6395 | 1.05k | case DW_FORM_data2: |
6396 | 1.11k | case DW_FORM_data4: |
6397 | 1.11k | case DW_FORM_data8: |
6398 | 1.31k | case DW_FORM_sdata: |
6399 | 1.40k | case DW_FORM_udata: |
6400 | 1.48k | case DW_FORM_block: |
6401 | 1.54k | case DW_FORM_block1: |
6402 | 1.57k | case DW_FORM_block2: |
6403 | 1.62k | case DW_FORM_block4: |
6404 | 1.68k | case DW_FORM_flag: |
6405 | 1.74k | case DW_FORM_string: |
6406 | 2.67k | case DW_FORM_strp: |
6407 | 2.71k | case DW_FORM_sec_offset: |
6408 | 2.71k | break; |
6409 | 41 | default: |
6410 | 41 | error (_("Invalid extension opcode form %s\n"), |
6411 | 41 | get_FORM_name (form)); |
6412 | 41 | return 0; |
6413 | 2.75k | } |
6414 | 2.75k | } |
6415 | 432 | } |
6416 | 1.97k | } |
6417 | 96 | } |
6418 | 103 | } |
6419 | 665 | printf ("\n"); |
6420 | | |
6421 | 26.4k | while (1) |
6422 | 26.4k | { |
6423 | 26.4k | unsigned int op; |
6424 | | |
6425 | 26.4k | if (curr >= end) |
6426 | 87 | { |
6427 | 87 | error (_(".debug_macro section not zero terminated\n")); |
6428 | 87 | return 0; |
6429 | 87 | } |
6430 | | |
6431 | 26.3k | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
6432 | 26.3k | if (op == 0) |
6433 | 522 | break; |
6434 | | |
6435 | 25.8k | switch (op) |
6436 | 25.8k | { |
6437 | 11.0k | case DW_MACRO_define: |
6438 | 11.0k | READ_ULEB (lineno, curr, end); |
6439 | 11.0k | string = curr; |
6440 | 11.0k | curr += strnlen ((char *) string, end - string); |
6441 | 11.0k | printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"), |
6442 | 11.0k | lineno, (int) (curr - string), string); |
6443 | 11.0k | if (curr < end) |
6444 | 11.0k | curr++; |
6445 | 11.0k | break; |
6446 | | |
6447 | 324 | case DW_MACRO_undef: |
6448 | 324 | READ_ULEB (lineno, curr, end); |
6449 | 324 | string = curr; |
6450 | 324 | curr += strnlen ((char *) string, end - string); |
6451 | 324 | printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"), |
6452 | 324 | lineno, (int) (curr - string), string); |
6453 | 324 | if (curr < end) |
6454 | 318 | curr++; |
6455 | 324 | break; |
6456 | | |
6457 | 1.02k | case DW_MACRO_start_file: |
6458 | 1.02k | { |
6459 | 1.02k | unsigned int filenum; |
6460 | 1.02k | unsigned char *file_name = NULL, *dir_name = NULL; |
6461 | | |
6462 | 1.02k | READ_ULEB (lineno, curr, end); |
6463 | 1.02k | READ_ULEB (filenum, curr, end); |
6464 | | |
6465 | 1.02k | if ((flags & 2) == 0) |
6466 | 50 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
6467 | 972 | else |
6468 | 972 | file_name |
6469 | 972 | = get_line_filename_and_dirname (line_offset, filenum, |
6470 | 972 | &dir_name); |
6471 | 1.02k | if (file_name == NULL) |
6472 | 1.02k | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
6473 | 1.02k | lineno, filenum); |
6474 | 0 | else |
6475 | 0 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
6476 | 0 | lineno, filenum, |
6477 | 0 | dir_name != NULL ? (const char *) dir_name : "", |
6478 | 0 | dir_name != NULL ? "/" : "", file_name); |
6479 | 1.02k | } |
6480 | 1.02k | break; |
6481 | | |
6482 | 993 | case DW_MACRO_end_file: |
6483 | 993 | printf (_(" DW_MACRO_end_file\n")); |
6484 | 993 | break; |
6485 | | |
6486 | 10.1k | case DW_MACRO_define_strp: |
6487 | 10.1k | READ_ULEB (lineno, curr, end); |
6488 | 10.1k | if (version == 4 && is_dwo) |
6489 | 0 | READ_ULEB (offset, curr, end); |
6490 | 10.1k | else |
6491 | 10.1k | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
6492 | 10.1k | string = fetch_indirect_string (offset); |
6493 | 10.1k | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
6494 | 10.1k | lineno, string); |
6495 | 10.1k | break; |
6496 | | |
6497 | 591 | case DW_MACRO_undef_strp: |
6498 | 591 | READ_ULEB (lineno, curr, end); |
6499 | 591 | if (version == 4 && is_dwo) |
6500 | 0 | READ_ULEB (offset, curr, end); |
6501 | 591 | else |
6502 | 591 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
6503 | 591 | string = fetch_indirect_string (offset); |
6504 | 591 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
6505 | 591 | lineno, string); |
6506 | 591 | break; |
6507 | | |
6508 | 499 | case DW_MACRO_import: |
6509 | 499 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
6510 | 499 | printf (_(" DW_MACRO_import - offset : %#" PRIx64 "\n"), |
6511 | 499 | offset); |
6512 | 499 | break; |
6513 | | |
6514 | 33 | case DW_MACRO_define_sup: |
6515 | 33 | READ_ULEB (lineno, curr, end); |
6516 | 33 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
6517 | 33 | printf (_(" DW_MACRO_define_sup - lineno : %d" |
6518 | 33 | " macro offset : %#" PRIx64 "\n"), |
6519 | 33 | lineno, offset); |
6520 | 33 | break; |
6521 | | |
6522 | 78 | case DW_MACRO_undef_sup: |
6523 | 78 | READ_ULEB (lineno, curr, end); |
6524 | 78 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
6525 | 78 | printf (_(" DW_MACRO_undef_sup - lineno : %d" |
6526 | 78 | " macro offset : %#" PRIx64 "\n"), |
6527 | 78 | lineno, offset); |
6528 | 78 | break; |
6529 | | |
6530 | 12 | case DW_MACRO_import_sup: |
6531 | 12 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
6532 | 12 | printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64 "\n"), |
6533 | 12 | offset); |
6534 | 12 | break; |
6535 | | |
6536 | 97 | case DW_MACRO_define_strx: |
6537 | 148 | case DW_MACRO_undef_strx: |
6538 | 148 | READ_ULEB (lineno, curr, end); |
6539 | 148 | READ_ULEB (offset, curr, end); |
6540 | 148 | string = (const unsigned char *) |
6541 | 148 | fetch_indexed_string (offset, NULL, offset_size, is_dwo, 0); |
6542 | 148 | if (op == DW_MACRO_define_strx) |
6543 | 97 | printf (" DW_MACRO_define_strx "); |
6544 | 51 | else |
6545 | 51 | printf (" DW_MACRO_undef_strx "); |
6546 | 148 | if (do_wide) |
6547 | 0 | printf (_("(with offset %#" PRIx64 ") "), offset); |
6548 | 148 | printf (_("lineno : %d macro : %s\n"), |
6549 | 148 | lineno, string); |
6550 | 148 | break; |
6551 | | |
6552 | 933 | default: |
6553 | 933 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) |
6554 | 703 | { |
6555 | 703 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); |
6556 | 703 | break; |
6557 | 703 | } |
6558 | | |
6559 | 230 | if (extended_ops == NULL || extended_ops[op] == NULL) |
6560 | 56 | { |
6561 | 56 | error (_(" Unknown macro opcode %02x seen\n"), op); |
6562 | 56 | return 0; |
6563 | 56 | } |
6564 | 174 | else |
6565 | 174 | { |
6566 | | /* Skip over unhandled opcodes. */ |
6567 | 174 | uint64_t nargs, n; |
6568 | 174 | unsigned char *desc = extended_ops[op]; |
6569 | 174 | READ_ULEB (nargs, desc, end); |
6570 | 174 | if (nargs == 0) |
6571 | 125 | { |
6572 | 125 | printf (_(" DW_MACRO_%02x\n"), op); |
6573 | 125 | break; |
6574 | 125 | } |
6575 | 49 | printf (_(" DW_MACRO_%02x -"), op); |
6576 | 604 | for (n = 0; n < nargs; n++) |
6577 | 555 | { |
6578 | 555 | int val; |
6579 | | |
6580 | | /* DW_FORM_implicit_const is not expected here. */ |
6581 | 555 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
6582 | 555 | curr |
6583 | 555 | = read_and_display_attr_value (0, val, 0, |
6584 | 555 | start, curr, end, 0, 0, |
6585 | 555 | offset_size, version, |
6586 | 555 | NULL, 0, section, |
6587 | 555 | NULL, ' ', -1); |
6588 | 555 | if (n != nargs - 1) |
6589 | 506 | printf (","); |
6590 | 555 | } |
6591 | 49 | printf ("\n"); |
6592 | 49 | } |
6593 | 49 | break; |
6594 | 25.8k | } |
6595 | 25.8k | } |
6596 | | |
6597 | 522 | printf ("\n"); |
6598 | 522 | } |
6599 | | |
6600 | 19 | return 1; |
6601 | 273 | } |
6602 | | |
6603 | | static int |
6604 | | display_debug_abbrev (struct dwarf_section *section, |
6605 | | void *file ATTRIBUTE_UNUSED) |
6606 | 3.27k | { |
6607 | 3.27k | abbrev_entry *entry; |
6608 | 3.27k | unsigned char *start = section->start; |
6609 | | |
6610 | 3.27k | introduce (section, false); |
6611 | | |
6612 | 3.27k | do |
6613 | 2.36M | { |
6614 | 2.36M | uint64_t offset = start - section->start; |
6615 | 2.36M | abbrev_list *list = find_and_process_abbrev_set (section, 0, |
6616 | 2.36M | section->size, offset, |
6617 | 2.36M | NULL); |
6618 | 2.36M | if (list == NULL) |
6619 | 1.76k | break; |
6620 | | |
6621 | 2.36M | if (list->first_abbrev) |
6622 | 499k | printf (_(" Number TAG (%#" PRIx64 ")\n"), offset); |
6623 | | |
6624 | 3.47M | for (entry = list->first_abbrev; entry; entry = entry->next) |
6625 | 1.11M | { |
6626 | 1.11M | abbrev_attr *attr; |
6627 | | |
6628 | 1.11M | printf (" %ld %s [%s]\n", |
6629 | 1.11M | entry->number, |
6630 | 1.11M | get_TAG_name (entry->tag), |
6631 | 1.11M | entry->children ? _("has children") : _("no children")); |
6632 | | |
6633 | 6.78M | for (attr = entry->first_attr; attr; attr = attr->next) |
6634 | 5.67M | { |
6635 | 5.67M | printf (" %-18s %s", |
6636 | 5.67M | get_AT_name (attr->attribute), |
6637 | 5.67M | get_FORM_name (attr->form)); |
6638 | 5.67M | if (attr->form == DW_FORM_implicit_const) |
6639 | 17.6k | printf (": %" PRId64, attr->implicit_const); |
6640 | 5.67M | putchar ('\n'); |
6641 | 5.67M | } |
6642 | 1.11M | } |
6643 | 2.36M | start = list->start_of_next_abbrevs; |
6644 | 2.36M | free_abbrev_list (list); |
6645 | 2.36M | } |
6646 | 2.36M | while (start); |
6647 | | |
6648 | 0 | printf ("\n"); |
6649 | | |
6650 | 3.27k | return 1; |
6651 | 3.27k | } |
6652 | | |
6653 | | /* Return true when ADDR is the maximum address, when addresses are |
6654 | | POINTER_SIZE bytes long. */ |
6655 | | |
6656 | | static bool |
6657 | | is_max_address (uint64_t addr, unsigned int pointer_size) |
6658 | 391k | { |
6659 | 391k | uint64_t mask = ~(~(uint64_t) 0 << 1 << (pointer_size * 8 - 1)); |
6660 | 391k | return ((addr & mask) == mask); |
6661 | 391k | } |
6662 | | |
6663 | | /* Display a view pair list starting at *VSTART_PTR and ending at |
6664 | | VLISTEND within SECTION. */ |
6665 | | |
6666 | | static void |
6667 | | display_view_pair_list (struct dwarf_section *section, |
6668 | | unsigned char **vstart_ptr, |
6669 | | unsigned int debug_info_entry, |
6670 | | unsigned char *vlistend) |
6671 | 0 | { |
6672 | 0 | unsigned char *vstart = *vstart_ptr; |
6673 | 0 | unsigned char *section_end = section->start + section->size; |
6674 | 0 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; |
6675 | |
|
6676 | 0 | if (vlistend < section_end) |
6677 | 0 | section_end = vlistend; |
6678 | |
|
6679 | 0 | putchar ('\n'); |
6680 | |
|
6681 | 0 | while (vstart < section_end) |
6682 | 0 | { |
6683 | 0 | uint64_t off = vstart - section->start; |
6684 | 0 | uint64_t vbegin, vend; |
6685 | |
|
6686 | 0 | READ_ULEB (vbegin, vstart, section_end); |
6687 | 0 | if (vstart == section_end) |
6688 | 0 | break; |
6689 | | |
6690 | 0 | READ_ULEB (vend, vstart, section_end); |
6691 | 0 | printf (" %8.8" PRIx64 " ", off); |
6692 | |
|
6693 | 0 | print_view (vbegin, pointer_size); |
6694 | 0 | print_view (vend, pointer_size); |
6695 | 0 | printf (_("location view pair\n")); |
6696 | 0 | } |
6697 | |
|
6698 | 0 | putchar ('\n'); |
6699 | 0 | *vstart_ptr = vstart; |
6700 | 0 | } |
6701 | | |
6702 | | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
6703 | | |
6704 | | static void |
6705 | | display_loc_list (struct dwarf_section *section, |
6706 | | unsigned char **start_ptr, |
6707 | | unsigned int debug_info_entry, |
6708 | | uint64_t offset, |
6709 | | uint64_t base_address, |
6710 | | unsigned char **vstart_ptr, |
6711 | | int has_frame_base) |
6712 | 0 | { |
6713 | 0 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
6714 | 0 | unsigned char *section_end = section->start + section->size; |
6715 | 0 | uint64_t cu_offset; |
6716 | 0 | unsigned int pointer_size; |
6717 | 0 | unsigned int offset_size; |
6718 | 0 | int dwarf_version; |
6719 | 0 | uint64_t begin; |
6720 | 0 | uint64_t end; |
6721 | 0 | unsigned short length; |
6722 | 0 | int need_frame_base; |
6723 | |
|
6724 | 0 | if (debug_info_entry >= num_debug_info_entries) |
6725 | 0 | { |
6726 | 0 | warn (_("No debug information available for loc lists of entry: %u\n"), |
6727 | 0 | debug_info_entry); |
6728 | 0 | return; |
6729 | 0 | } |
6730 | | |
6731 | 0 | cu_offset = debug_information [debug_info_entry].cu_offset; |
6732 | 0 | pointer_size = debug_information [debug_info_entry].pointer_size; |
6733 | 0 | offset_size = debug_information [debug_info_entry].offset_size; |
6734 | 0 | dwarf_version = debug_information [debug_info_entry].dwarf_version; |
6735 | |
|
6736 | 0 | if (pointer_size < 2 || pointer_size > 8) |
6737 | 0 | { |
6738 | 0 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), |
6739 | 0 | pointer_size, debug_info_entry); |
6740 | 0 | return; |
6741 | 0 | } |
6742 | | |
6743 | 0 | while (1) |
6744 | 0 | { |
6745 | 0 | uint64_t off = offset + (start - *start_ptr); |
6746 | 0 | uint64_t vbegin = -1, vend = -1; |
6747 | |
|
6748 | 0 | if (2 * pointer_size > (size_t) (section_end - start)) |
6749 | 0 | { |
6750 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
6751 | 0 | " is not terminated.\n"), offset); |
6752 | 0 | break; |
6753 | 0 | } |
6754 | | |
6755 | 0 | printf (" "); |
6756 | 0 | print_hex (off, 4); |
6757 | |
|
6758 | 0 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
6759 | 0 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); |
6760 | | |
6761 | 0 | if (begin == 0 && end == 0) |
6762 | 0 | { |
6763 | | /* PR 18374: In a object file we can have a location list that |
6764 | | starts with a begin and end of 0 because there are relocations |
6765 | | that need to be applied to the addresses. Actually applying |
6766 | | the relocations now does not help as they will probably resolve |
6767 | | to 0, since the object file has not been fully linked. Real |
6768 | | end of list markers will not have any relocations against them. */ |
6769 | 0 | if (! reloc_at (section, off) |
6770 | 0 | && ! reloc_at (section, off + pointer_size)) |
6771 | 0 | { |
6772 | 0 | printf (_("<End of list>\n")); |
6773 | 0 | break; |
6774 | 0 | } |
6775 | 0 | } |
6776 | | |
6777 | | /* Check base address specifiers. */ |
6778 | 0 | if (is_max_address (begin, pointer_size) |
6779 | 0 | && !is_max_address (end, pointer_size)) |
6780 | 0 | { |
6781 | 0 | base_address = end; |
6782 | 0 | print_hex (begin, pointer_size); |
6783 | 0 | print_hex (end, pointer_size); |
6784 | 0 | printf (_("(base address)\n")); |
6785 | 0 | continue; |
6786 | 0 | } |
6787 | | |
6788 | 0 | if (vstart) |
6789 | 0 | { |
6790 | 0 | off = offset + (vstart - *start_ptr); |
6791 | |
|
6792 | 0 | READ_ULEB (vbegin, vstart, section_end); |
6793 | 0 | print_view (vbegin, pointer_size); |
6794 | |
|
6795 | 0 | READ_ULEB (vend, vstart, section_end); |
6796 | 0 | print_view (vend, pointer_size); |
6797 | |
|
6798 | 0 | printf (_("views at %8.8" PRIx64 " for:\n %*s "), off, 8, ""); |
6799 | 0 | } |
6800 | |
|
6801 | 0 | if (2 > (size_t) (section_end - start)) |
6802 | 0 | { |
6803 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
6804 | 0 | " is not terminated.\n"), offset); |
6805 | 0 | break; |
6806 | 0 | } |
6807 | | |
6808 | 0 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
6809 | | |
6810 | 0 | if (length > (size_t) (section_end - start)) |
6811 | 0 | { |
6812 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
6813 | 0 | " is not terminated.\n"), offset); |
6814 | 0 | break; |
6815 | 0 | } |
6816 | | |
6817 | 0 | print_hex (begin + base_address, pointer_size); |
6818 | 0 | print_hex (end + base_address, pointer_size); |
6819 | |
|
6820 | 0 | putchar ('('); |
6821 | 0 | need_frame_base = decode_location_expression (start, |
6822 | 0 | pointer_size, |
6823 | 0 | offset_size, |
6824 | 0 | dwarf_version, |
6825 | 0 | length, |
6826 | 0 | cu_offset, section); |
6827 | 0 | putchar (')'); |
6828 | |
|
6829 | 0 | if (need_frame_base && !has_frame_base) |
6830 | 0 | printf (_(" [without DW_AT_frame_base]")); |
6831 | |
|
6832 | 0 | if (begin == end && vbegin == vend) |
6833 | 0 | fputs (_(" (start == end)"), stdout); |
6834 | 0 | else if (begin > end || (begin == end && vbegin > vend)) |
6835 | 0 | fputs (_(" (start > end)"), stdout); |
6836 | |
|
6837 | 0 | putchar ('\n'); |
6838 | |
|
6839 | 0 | start += length; |
6840 | 0 | } |
6841 | | |
6842 | 0 | *start_ptr = start; |
6843 | 0 | *vstart_ptr = vstart; |
6844 | 0 | } |
6845 | | |
6846 | | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6847 | | |
6848 | | static void |
6849 | | display_loclists_list (struct dwarf_section * section, |
6850 | | unsigned char ** start_ptr, |
6851 | | debug_info * debug_info_p, |
6852 | | uint64_t offset, |
6853 | | uint64_t base_address, |
6854 | | unsigned char ** vstart_ptr, |
6855 | | int has_frame_base) |
6856 | 0 | { |
6857 | 0 | unsigned char *start = *start_ptr; |
6858 | 0 | unsigned char *vstart = *vstart_ptr; |
6859 | 0 | unsigned char *section_end = section->start + section->size; |
6860 | 0 | uint64_t cu_offset; |
6861 | 0 | unsigned int pointer_size; |
6862 | 0 | unsigned int offset_size; |
6863 | 0 | unsigned int dwarf_version; |
6864 | 0 | uint64_t idx; |
6865 | | |
6866 | | /* Initialize it due to a false compiler warning. */ |
6867 | 0 | uint64_t begin = -1, vbegin = -1; |
6868 | 0 | uint64_t end = -1, vend = -1; |
6869 | 0 | uint64_t length; |
6870 | 0 | int need_frame_base; |
6871 | |
|
6872 | 0 | cu_offset = debug_info_p->cu_offset; |
6873 | 0 | pointer_size = debug_info_p->pointer_size; |
6874 | 0 | offset_size = debug_info_p->offset_size; |
6875 | 0 | dwarf_version = debug_info_p->dwarf_version; |
6876 | |
|
6877 | 0 | if (pointer_size < 2 || pointer_size > 8) |
6878 | 0 | { |
6879 | 0 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), |
6880 | 0 | pointer_size, (int)(debug_info_p - debug_information)); |
6881 | 0 | return; |
6882 | 0 | } |
6883 | | |
6884 | 0 | while (1) |
6885 | 0 | { |
6886 | 0 | uint64_t off = offset + (start - *start_ptr); |
6887 | 0 | enum dwarf_location_list_entry_type llet; |
6888 | |
|
6889 | 0 | if (start + 1 > section_end) |
6890 | 0 | { |
6891 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
6892 | 0 | " is not terminated.\n"), offset); |
6893 | 0 | break; |
6894 | 0 | } |
6895 | | |
6896 | 0 | printf (" "); |
6897 | 0 | print_hex (off, 4); |
6898 | |
|
6899 | 0 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); |
6900 | | |
6901 | 0 | if (vstart && (llet == DW_LLE_offset_pair |
6902 | 0 | || llet == DW_LLE_start_end |
6903 | 0 | || llet == DW_LLE_start_length)) |
6904 | 0 | { |
6905 | 0 | off = offset + (vstart - *start_ptr); |
6906 | |
|
6907 | 0 | READ_ULEB (vbegin, vstart, section_end); |
6908 | 0 | print_view (vbegin, pointer_size); |
6909 | |
|
6910 | 0 | READ_ULEB (vend, vstart, section_end); |
6911 | 0 | print_view (vend, pointer_size); |
6912 | |
|
6913 | 0 | printf (_("views at %8.8" PRIx64 " for:\n %*s "), off, 8, ""); |
6914 | 0 | } |
6915 | |
|
6916 | 0 | switch (llet) |
6917 | 0 | { |
6918 | 0 | case DW_LLE_end_of_list: |
6919 | 0 | printf (_("<End of list>\n")); |
6920 | 0 | break; |
6921 | | |
6922 | 0 | case DW_LLE_base_addressx: |
6923 | 0 | READ_ULEB (idx, start, section_end); |
6924 | 0 | print_hex (idx, pointer_size); |
6925 | 0 | printf (_("(index into .debug_addr) ")); |
6926 | 0 | base_address = fetch_indexed_addr |
6927 | 0 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); |
6928 | 0 | print_hex (base_address, pointer_size); |
6929 | 0 | printf (_("(base address)\n")); |
6930 | 0 | break; |
6931 | | |
6932 | 0 | case DW_LLE_startx_endx: |
6933 | 0 | READ_ULEB (idx, start, section_end); |
6934 | 0 | begin = fetch_indexed_addr |
6935 | 0 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); |
6936 | 0 | READ_ULEB (idx, start, section_end); |
6937 | 0 | end = fetch_indexed_addr |
6938 | 0 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); |
6939 | 0 | break; |
6940 | | |
6941 | 0 | case DW_LLE_startx_length: |
6942 | 0 | READ_ULEB (idx, start, section_end); |
6943 | 0 | begin = fetch_indexed_addr |
6944 | 0 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); |
6945 | 0 | READ_ULEB (end, start, section_end); |
6946 | 0 | end += begin; |
6947 | 0 | break; |
6948 | | |
6949 | 0 | case DW_LLE_default_location: |
6950 | 0 | begin = end = 0; |
6951 | 0 | break; |
6952 | | |
6953 | 0 | case DW_LLE_offset_pair: |
6954 | 0 | READ_ULEB (begin, start, section_end); |
6955 | 0 | begin += base_address; |
6956 | 0 | READ_ULEB (end, start, section_end); |
6957 | 0 | end += base_address; |
6958 | 0 | break; |
6959 | | |
6960 | 0 | case DW_LLE_base_address: |
6961 | 0 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, |
6962 | 0 | section_end); |
6963 | 0 | print_hex (base_address, pointer_size); |
6964 | 0 | printf (_("(base address)\n")); |
6965 | 0 | break; |
6966 | | |
6967 | 0 | case DW_LLE_start_end: |
6968 | 0 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
6969 | 0 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); |
6970 | 0 | break; |
6971 | | |
6972 | 0 | case DW_LLE_start_length: |
6973 | 0 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
6974 | 0 | READ_ULEB (end, start, section_end); |
6975 | 0 | end += begin; |
6976 | 0 | break; |
6977 | | |
6978 | 0 | #ifdef DW_LLE_view_pair |
6979 | 0 | case DW_LLE_view_pair: |
6980 | 0 | if (vstart) |
6981 | 0 | printf (_("View pair entry in loclist with locviews attribute\n")); |
6982 | 0 | READ_ULEB (vbegin, start, section_end); |
6983 | 0 | print_view (vbegin, pointer_size); |
6984 | |
|
6985 | 0 | READ_ULEB (vend, start, section_end); |
6986 | 0 | print_view (vend, pointer_size); |
6987 | |
|
6988 | 0 | printf (_("views for:\n")); |
6989 | 0 | continue; |
6990 | 0 | #endif |
6991 | | |
6992 | 0 | default: |
6993 | 0 | error (_("Invalid location list entry type %d\n"), llet); |
6994 | 0 | return; |
6995 | 0 | } |
6996 | | |
6997 | 0 | if (llet == DW_LLE_end_of_list) |
6998 | 0 | break; |
6999 | | |
7000 | 0 | if (llet == DW_LLE_base_address |
7001 | 0 | || llet == DW_LLE_base_addressx) |
7002 | 0 | continue; |
7003 | | |
7004 | 0 | if (start == section_end) |
7005 | 0 | { |
7006 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
7007 | 0 | " is not terminated.\n"), offset); |
7008 | 0 | break; |
7009 | 0 | } |
7010 | 0 | READ_ULEB (length, start, section_end); |
7011 | |
|
7012 | 0 | if (length > (size_t) (section_end - start)) |
7013 | 0 | { |
7014 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
7015 | 0 | " is not terminated.\n"), offset); |
7016 | 0 | break; |
7017 | 0 | } |
7018 | | |
7019 | 0 | print_hex (begin, pointer_size); |
7020 | 0 | print_hex (end, pointer_size); |
7021 | |
|
7022 | 0 | putchar ('('); |
7023 | 0 | need_frame_base = decode_location_expression (start, |
7024 | 0 | pointer_size, |
7025 | 0 | offset_size, |
7026 | 0 | dwarf_version, |
7027 | 0 | length, |
7028 | 0 | cu_offset, section); |
7029 | 0 | putchar (')'); |
7030 | |
|
7031 | 0 | if (need_frame_base && !has_frame_base) |
7032 | 0 | printf (_(" [without DW_AT_frame_base]")); |
7033 | |
|
7034 | 0 | if (begin == end && vbegin == vend) |
7035 | 0 | fputs (_(" (start == end)"), stdout); |
7036 | 0 | else if (begin > end || (begin == end && vbegin > vend)) |
7037 | 0 | fputs (_(" (start > end)"), stdout); |
7038 | |
|
7039 | 0 | putchar ('\n'); |
7040 | |
|
7041 | 0 | start += length; |
7042 | 0 | vbegin = vend = -1; |
7043 | 0 | } |
7044 | | |
7045 | 0 | if (vbegin != (uint64_t) -1 || vend != (uint64_t) -1) |
7046 | 0 | printf (_("Trailing view pair not used in a range")); |
7047 | |
|
7048 | 0 | *start_ptr = start; |
7049 | 0 | *vstart_ptr = vstart; |
7050 | 0 | } |
7051 | | |
7052 | | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
7053 | | right-adjusted in a field of length LEN, and followed by a space. */ |
7054 | | |
7055 | | static void |
7056 | | print_addr_index (unsigned int idx, unsigned int len) |
7057 | 0 | { |
7058 | 0 | static char buf[15]; |
7059 | 0 | snprintf (buf, sizeof (buf), "[%d]", idx); |
7060 | 0 | printf ("%*s ", len, buf); |
7061 | 0 | } |
7062 | | |
7063 | | /* Display a location list from a .dwo section. It uses address indexes rather |
7064 | | than embedded addresses. This code closely follows display_loc_list, but the |
7065 | | two are sufficiently different that combining things is very ugly. */ |
7066 | | |
7067 | | static void |
7068 | | display_loc_list_dwo (struct dwarf_section *section, |
7069 | | unsigned char **start_ptr, |
7070 | | unsigned int debug_info_entry, |
7071 | | uint64_t offset, |
7072 | | unsigned char **vstart_ptr, |
7073 | | int has_frame_base) |
7074 | 0 | { |
7075 | 0 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
7076 | 0 | unsigned char *section_end = section->start + section->size; |
7077 | 0 | uint64_t cu_offset; |
7078 | 0 | unsigned int pointer_size; |
7079 | 0 | unsigned int offset_size; |
7080 | 0 | int dwarf_version; |
7081 | 0 | int entry_type; |
7082 | 0 | unsigned short length; |
7083 | 0 | int need_frame_base; |
7084 | 0 | unsigned int idx; |
7085 | |
|
7086 | 0 | if (debug_info_entry >= num_debug_info_entries) |
7087 | 0 | { |
7088 | 0 | warn (_("No debug information for loc lists of entry: %u\n"), |
7089 | 0 | debug_info_entry); |
7090 | 0 | return; |
7091 | 0 | } |
7092 | | |
7093 | 0 | cu_offset = debug_information [debug_info_entry].cu_offset; |
7094 | 0 | pointer_size = debug_information [debug_info_entry].pointer_size; |
7095 | 0 | offset_size = debug_information [debug_info_entry].offset_size; |
7096 | 0 | dwarf_version = debug_information [debug_info_entry].dwarf_version; |
7097 | |
|
7098 | 0 | if (pointer_size < 2 || pointer_size > 8) |
7099 | 0 | { |
7100 | 0 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), |
7101 | 0 | pointer_size, debug_info_entry); |
7102 | 0 | return; |
7103 | 0 | } |
7104 | | |
7105 | 0 | while (1) |
7106 | 0 | { |
7107 | 0 | printf (" "); |
7108 | 0 | print_hex (offset + (start - *start_ptr), 4); |
7109 | |
|
7110 | 0 | if (start >= section_end) |
7111 | 0 | { |
7112 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
7113 | 0 | " is not terminated.\n"), offset); |
7114 | 0 | break; |
7115 | 0 | } |
7116 | | |
7117 | 0 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
7118 | | |
7119 | 0 | if (vstart) |
7120 | 0 | switch (entry_type) |
7121 | 0 | { |
7122 | 0 | default: |
7123 | 0 | break; |
7124 | | |
7125 | 0 | case 2: |
7126 | 0 | case 3: |
7127 | 0 | case 4: |
7128 | 0 | { |
7129 | 0 | uint64_t view; |
7130 | 0 | uint64_t off = offset + (vstart - *start_ptr); |
7131 | |
|
7132 | 0 | READ_ULEB (view, vstart, section_end); |
7133 | 0 | print_view (view, 8); |
7134 | |
|
7135 | 0 | READ_ULEB (view, vstart, section_end); |
7136 | 0 | print_view (view, 8); |
7137 | |
|
7138 | 0 | printf (_("views at %8.8" PRIx64 " for:\n %*s "), off, 8, ""); |
7139 | |
|
7140 | 0 | } |
7141 | 0 | break; |
7142 | 0 | } |
7143 | | |
7144 | 0 | switch (entry_type) |
7145 | 0 | { |
7146 | 0 | case 0: /* A terminating entry. */ |
7147 | 0 | *start_ptr = start; |
7148 | 0 | *vstart_ptr = vstart; |
7149 | 0 | printf (_("<End of list>\n")); |
7150 | 0 | return; |
7151 | 0 | case 1: /* A base-address entry. */ |
7152 | 0 | READ_ULEB (idx, start, section_end); |
7153 | 0 | print_addr_index (idx, 8); |
7154 | 0 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
7155 | 0 | printf (_("(base address selection entry)\n")); |
7156 | 0 | continue; |
7157 | 0 | case 2: /* A start/end entry. */ |
7158 | 0 | READ_ULEB (idx, start, section_end); |
7159 | 0 | print_addr_index (idx, 8); |
7160 | 0 | READ_ULEB (idx, start, section_end); |
7161 | 0 | print_addr_index (idx, 8); |
7162 | 0 | break; |
7163 | 0 | case 3: /* A start/length entry. */ |
7164 | 0 | READ_ULEB (idx, start, section_end); |
7165 | 0 | print_addr_index (idx, 8); |
7166 | 0 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); |
7167 | 0 | printf ("%08x ", idx); |
7168 | 0 | break; |
7169 | 0 | case 4: /* An offset pair entry. */ |
7170 | 0 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); |
7171 | 0 | printf ("%08x ", idx); |
7172 | 0 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); |
7173 | 0 | printf ("%08x ", idx); |
7174 | 0 | break; |
7175 | 0 | default: |
7176 | 0 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); |
7177 | 0 | *start_ptr = start; |
7178 | 0 | *vstart_ptr = vstart; |
7179 | 0 | return; |
7180 | 0 | } |
7181 | | |
7182 | 0 | if (2 > (size_t) (section_end - start)) |
7183 | 0 | { |
7184 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
7185 | 0 | " is not terminated.\n"), offset); |
7186 | 0 | break; |
7187 | 0 | } |
7188 | | |
7189 | 0 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
7190 | 0 | if (length > (size_t) (section_end - start)) |
7191 | 0 | { |
7192 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
7193 | 0 | " is not terminated.\n"), offset); |
7194 | 0 | break; |
7195 | 0 | } |
7196 | | |
7197 | 0 | putchar ('('); |
7198 | 0 | need_frame_base = decode_location_expression (start, |
7199 | 0 | pointer_size, |
7200 | 0 | offset_size, |
7201 | 0 | dwarf_version, |
7202 | 0 | length, |
7203 | 0 | cu_offset, section); |
7204 | 0 | putchar (')'); |
7205 | |
|
7206 | 0 | if (need_frame_base && !has_frame_base) |
7207 | 0 | printf (_(" [without DW_AT_frame_base]")); |
7208 | |
|
7209 | 0 | putchar ('\n'); |
7210 | |
|
7211 | 0 | start += length; |
7212 | 0 | } |
7213 | | |
7214 | 0 | *start_ptr = start; |
7215 | 0 | *vstart_ptr = vstart; |
7216 | 0 | } |
7217 | | |
7218 | | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
7219 | | loc_views. */ |
7220 | | |
7221 | | static uint64_t *loc_offsets, *loc_views; |
7222 | | |
7223 | | static int |
7224 | | loc_offsets_compar (const void *ap, const void *bp) |
7225 | 0 | { |
7226 | 0 | uint64_t a = loc_offsets[*(const unsigned int *) ap]; |
7227 | 0 | uint64_t b = loc_offsets[*(const unsigned int *) bp]; |
7228 | |
|
7229 | 0 | int ret = (a > b) - (b > a); |
7230 | 0 | if (ret) |
7231 | 0 | return ret; |
7232 | | |
7233 | 0 | a = loc_views[*(const unsigned int *) ap]; |
7234 | 0 | b = loc_views[*(const unsigned int *) bp]; |
7235 | |
|
7236 | 0 | ret = (a > b) - (b > a); |
7237 | |
|
7238 | 0 | return ret; |
7239 | 0 | } |
7240 | | |
7241 | | /* Reads and dumps the DWARFv5 loclists compiler unit header, |
7242 | | including the offset table. |
7243 | | Returns the offset of the next compile unit header. */ |
7244 | | |
7245 | | static uint64_t |
7246 | | display_loclists_unit_header (struct dwarf_section * section, |
7247 | | uint64_t header_offset, |
7248 | | uint32_t * offset_count, |
7249 | | unsigned char ** loclists_start) |
7250 | 0 | { |
7251 | 0 | uint64_t length; |
7252 | 0 | unsigned char *start = section->start + header_offset; |
7253 | 0 | unsigned char *end = section->start + section->size; |
7254 | 0 | unsigned short version; |
7255 | 0 | unsigned char address_size; |
7256 | 0 | unsigned char segment_selector_size; |
7257 | 0 | bool is_64bit; |
7258 | 0 | uint32_t i; |
7259 | |
|
7260 | 0 | printf (_("Table at Offset %#" PRIx64 "\n"), header_offset); |
7261 | |
|
7262 | 0 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
7263 | 0 | if (length == 0xffffffff) |
7264 | 0 | { |
7265 | 0 | is_64bit = true; |
7266 | 0 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
7267 | 0 | } |
7268 | 0 | else |
7269 | 0 | is_64bit = false; |
7270 | | |
7271 | 0 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); |
7272 | 0 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, end); |
7273 | 0 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, end); |
7274 | 0 | SAFE_BYTE_GET_AND_INC (*offset_count, start, 4, end); |
7275 | | |
7276 | 0 | printf (_(" Length: %#" PRIx64 "\n"), length); |
7277 | 0 | printf (_(" DWARF version: %u\n"), version); |
7278 | 0 | printf (_(" Address size: %u\n"), address_size); |
7279 | 0 | printf (_(" Segment size: %u\n"), segment_selector_size); |
7280 | 0 | printf (_(" Offset entries: %u\n"), *offset_count); |
7281 | |
|
7282 | 0 | if (segment_selector_size != 0) |
7283 | 0 | { |
7284 | 0 | warn (_("The %s section contains an " |
7285 | 0 | "unsupported segment selector size: %d.\n"), |
7286 | 0 | section->name, segment_selector_size); |
7287 | 0 | return (uint64_t)-1; |
7288 | 0 | } |
7289 | | |
7290 | 0 | if ( *offset_count) |
7291 | 0 | { |
7292 | 0 | printf (_("\n Offset Entries starting at %#tx:\n"), |
7293 | 0 | start - section->start); |
7294 | |
|
7295 | 0 | for (i = 0; i < *offset_count; i++) |
7296 | 0 | { |
7297 | 0 | uint64_t entry; |
7298 | |
|
7299 | 0 | SAFE_BYTE_GET_AND_INC (entry, start, is_64bit ? 8 : 4, end); |
7300 | 0 | printf (_(" [%6u] %#" PRIx64 "\n"), i, entry); |
7301 | 0 | } |
7302 | 0 | } |
7303 | | |
7304 | 0 | putchar ('\n'); |
7305 | 0 | *loclists_start = start; |
7306 | | |
7307 | | /* The length field doesn't include the length field itself. */ |
7308 | 0 | return header_offset + length + (is_64bit ? 12 : 4); |
7309 | 0 | } |
7310 | | |
7311 | | static int |
7312 | | display_debug_loc (struct dwarf_section *section, void *file) |
7313 | 104 | { |
7314 | 104 | unsigned char *start = section->start, *vstart = NULL; |
7315 | 104 | uint64_t bytes; |
7316 | 104 | unsigned char *section_begin = start; |
7317 | 104 | unsigned int num_loc_list = 0; |
7318 | 104 | uint64_t last_offset = 0; |
7319 | 104 | uint64_t last_view = 0; |
7320 | 104 | unsigned int first = 0; |
7321 | 104 | unsigned int i; |
7322 | 104 | unsigned int j; |
7323 | 104 | int seen_first_offset = 0; |
7324 | 104 | int locs_sorted = 1; |
7325 | 104 | unsigned char *next = start, *vnext = vstart; |
7326 | 104 | unsigned int *array = NULL; |
7327 | 104 | const char *suffix = strrchr (section->name, '.'); |
7328 | 104 | bool is_dwo = false; |
7329 | 104 | bool is_loclists = strstr (section->name, "debug_loclists") != NULL; |
7330 | 104 | uint64_t next_header_offset = 0; |
7331 | | |
7332 | 104 | if (suffix && strcmp (suffix, ".dwo") == 0) |
7333 | 3 | is_dwo = true; |
7334 | | |
7335 | 104 | bytes = section->size; |
7336 | | |
7337 | 104 | if (bytes == 0) |
7338 | 1 | { |
7339 | 1 | printf (_("\nThe %s section is empty.\n"), section->name); |
7340 | 1 | return 0; |
7341 | 1 | } |
7342 | | |
7343 | 103 | if (is_loclists) |
7344 | 53 | { |
7345 | 53 | unsigned char *hdrptr = section_begin; |
7346 | 53 | uint64_t ll_length; |
7347 | 53 | unsigned short ll_version; |
7348 | 53 | unsigned char *end = section_begin + section->size; |
7349 | 53 | unsigned char address_size, segment_selector_size; |
7350 | 53 | uint32_t offset_entry_count; |
7351 | | |
7352 | 53 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); |
7353 | 53 | if (ll_length == 0xffffffff) |
7354 | 53 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); |
7355 | | |
7356 | 53 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); |
7357 | 53 | if (ll_version != 5) |
7358 | 34 | { |
7359 | 34 | warn (_("The %s section contains corrupt or " |
7360 | 34 | "unsupported version number: %d.\n"), |
7361 | 34 | section->name, ll_version); |
7362 | 34 | return 0; |
7363 | 34 | } |
7364 | | |
7365 | 19 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); |
7366 | | |
7367 | 19 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); |
7368 | 19 | if (segment_selector_size != 0) |
7369 | 1 | { |
7370 | 1 | warn (_("The %s section contains " |
7371 | 1 | "unsupported segment selector size: %d.\n"), |
7372 | 1 | section->name, segment_selector_size); |
7373 | 1 | return 0; |
7374 | 1 | } |
7375 | | |
7376 | 18 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); |
7377 | | |
7378 | | /*if (offset_entry_count != 0) |
7379 | | return display_offset_entry_loclists (section);*/ |
7380 | | |
7381 | | //header_size = hdrptr - section_begin; |
7382 | 18 | } |
7383 | | |
7384 | 68 | if (load_debug_info (file) == 0) |
7385 | 68 | { |
7386 | 68 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), |
7387 | 68 | section->name); |
7388 | 68 | return 0; |
7389 | 68 | } |
7390 | | |
7391 | | /* Check the order of location list in .debug_info section. If |
7392 | | offsets of location lists are in the ascending order, we can |
7393 | | use `debug_information' directly. */ |
7394 | 0 | for (i = 0; i < num_debug_info_entries; i++) |
7395 | 0 | { |
7396 | 0 | unsigned int num; |
7397 | |
|
7398 | 0 | num = debug_information [i].num_loc_offsets; |
7399 | 0 | if (num > num_loc_list) |
7400 | 0 | num_loc_list = num; |
7401 | | |
7402 | | /* Check if we can use `debug_information' directly. */ |
7403 | 0 | if (locs_sorted && num != 0) |
7404 | 0 | { |
7405 | 0 | if (!seen_first_offset) |
7406 | 0 | { |
7407 | | /* This is the first location list. */ |
7408 | 0 | last_offset = debug_information [i].loc_offsets [0]; |
7409 | 0 | last_view = debug_information [i].loc_views [0]; |
7410 | 0 | first = i; |
7411 | 0 | seen_first_offset = 1; |
7412 | 0 | j = 1; |
7413 | 0 | } |
7414 | 0 | else |
7415 | 0 | j = 0; |
7416 | |
|
7417 | 0 | for (; j < num; j++) |
7418 | 0 | { |
7419 | 0 | if (last_offset > debug_information [i].loc_offsets [j] |
7420 | 0 | || (last_offset == debug_information [i].loc_offsets [j] |
7421 | 0 | && last_view > debug_information [i].loc_views [j])) |
7422 | 0 | { |
7423 | 0 | locs_sorted = 0; |
7424 | 0 | break; |
7425 | 0 | } |
7426 | 0 | last_offset = debug_information [i].loc_offsets [j]; |
7427 | 0 | last_view = debug_information [i].loc_views [j]; |
7428 | 0 | } |
7429 | 0 | } |
7430 | 0 | } |
7431 | |
|
7432 | 0 | if (!seen_first_offset) |
7433 | 0 | error (_("No location lists in .debug_info section!\n")); |
7434 | |
|
7435 | 0 | if (!locs_sorted) |
7436 | 0 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); |
7437 | |
|
7438 | 0 | introduce (section, false); |
7439 | |
|
7440 | 0 | if (reloc_at (section, 0)) |
7441 | 0 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); |
7442 | |
|
7443 | 0 | if (!is_loclists) |
7444 | 0 | printf (_(" Offset Begin End Expression\n")); |
7445 | |
|
7446 | 0 | for (i = first; i < num_debug_info_entries; i++) |
7447 | 0 | { |
7448 | 0 | uint64_t offset = 0, voffset = 0; |
7449 | 0 | uint64_t base_address; |
7450 | 0 | unsigned int k; |
7451 | 0 | int has_frame_base; |
7452 | 0 | debug_info *debug_info_p = debug_information + i; |
7453 | 0 | uint32_t offset_count; |
7454 | | |
7455 | | /* .debug_loclists section is loaded into debug_information as |
7456 | | DWARF-5 debug info and .debug_loc section is loaded into |
7457 | | debug_information as pre-DWARF-5 debug info. When dumping |
7458 | | .debug_loc section, we should only process pre-DWARF-5 debug |
7459 | | info in debug_information. When dumping .debug_loclists |
7460 | | section, we should only process DWARF-5 info in |
7461 | | debug_information. */ |
7462 | 0 | if ((debug_info_p->dwarf_version >= 5) != is_loclists) |
7463 | 0 | continue; |
7464 | | |
7465 | 0 | if (!locs_sorted) |
7466 | 0 | { |
7467 | 0 | for (k = 0; k < debug_info_p->num_loc_offsets; k++) |
7468 | 0 | array[k] = k; |
7469 | 0 | loc_offsets = debug_info_p->loc_offsets; |
7470 | 0 | loc_views = debug_info_p->loc_views; |
7471 | 0 | qsort (array, debug_info_p->num_loc_offsets, |
7472 | 0 | sizeof (*array), loc_offsets_compar); |
7473 | 0 | } |
7474 | | |
7475 | | /* .debug_loclists has a per-unit header. |
7476 | | Update start if we are detecting it. */ |
7477 | 0 | if (debug_info_p->dwarf_version >= 5) |
7478 | 0 | { |
7479 | 0 | j = locs_sorted ? 0 : array [0]; |
7480 | |
|
7481 | 0 | if (debug_info_p->num_loc_offsets) |
7482 | 0 | offset = debug_info_p->loc_offsets [j]; |
7483 | |
|
7484 | 0 | if (debug_info_p->num_loc_views) |
7485 | 0 | voffset = debug_info_p->loc_views [j]; |
7486 | | |
7487 | | /* Parse and dump unit headers in loclists. |
7488 | | This will misbehave if the order of CUs in debug_info |
7489 | | doesn't match the one in loclists. */ |
7490 | 0 | if (next_header_offset < offset) |
7491 | 0 | { |
7492 | 0 | while (next_header_offset < offset) |
7493 | 0 | { |
7494 | 0 | next_header_offset = display_loclists_unit_header |
7495 | 0 | (section, next_header_offset, &offset_count, &start); |
7496 | |
|
7497 | 0 | if (next_header_offset == (uint64_t)-1) |
7498 | | /* Header parsing error. */ |
7499 | 0 | return 0; |
7500 | 0 | } |
7501 | | |
7502 | 0 | printf (_("\ |
7503 | 0 | Offset Begin End Expression\n")); |
7504 | 0 | } |
7505 | 0 | } |
7506 | | |
7507 | 0 | int adjacent_view_loclists = 1; |
7508 | |
|
7509 | 0 | for (k = 0; k < debug_info_p->num_loc_offsets; k++) |
7510 | 0 | { |
7511 | 0 | j = locs_sorted ? k : array[k]; |
7512 | 0 | if (k |
7513 | 0 | && (debug_info_p->loc_offsets [locs_sorted |
7514 | 0 | ? k - 1 : array [k - 1]] |
7515 | 0 | == debug_info_p->loc_offsets [j]) |
7516 | 0 | && (debug_info_p->loc_views [locs_sorted |
7517 | 0 | ? k - 1 : array [k - 1]] |
7518 | 0 | == debug_info_p->loc_views [j])) |
7519 | 0 | continue; |
7520 | 0 | has_frame_base = debug_info_p->have_frame_base [j]; |
7521 | 0 | offset = debug_info_p->loc_offsets [j]; |
7522 | 0 | next = section_begin + offset; |
7523 | 0 | voffset = debug_info_p->loc_views [j]; |
7524 | 0 | if (voffset != (uint64_t) -1) |
7525 | 0 | vnext = section_begin + voffset; |
7526 | 0 | else |
7527 | 0 | vnext = NULL; |
7528 | 0 | base_address = debug_info_p->base_address; |
7529 | |
|
7530 | 0 | if (vnext && vnext < next) |
7531 | 0 | { |
7532 | 0 | vstart = vnext; |
7533 | 0 | display_view_pair_list (section, &vstart, i, next); |
7534 | 0 | if (start == vnext) |
7535 | 0 | start = vstart; |
7536 | 0 | } |
7537 | |
|
7538 | 0 | if (start < next) |
7539 | 0 | { |
7540 | 0 | if (vnext && vnext < next) |
7541 | 0 | warn (_("There is a hole [%#tx - %#" PRIx64 "]" |
7542 | 0 | " in %s section.\n"), |
7543 | 0 | start - section_begin, voffset, section->name); |
7544 | 0 | else |
7545 | 0 | warn (_("There is a hole [%#tx - %#" PRIx64 "]" |
7546 | 0 | " in %s section.\n"), |
7547 | 0 | start - section_begin, offset, section->name); |
7548 | 0 | } |
7549 | 0 | else if (start > next) |
7550 | 0 | warn (_("There is an overlap [%#tx - %#" PRIx64 "]" |
7551 | 0 | " in %s section.\n"), |
7552 | 0 | start - section_begin, offset, section->name); |
7553 | 0 | start = next; |
7554 | 0 | vstart = vnext; |
7555 | |
|
7556 | 0 | if (offset >= bytes) |
7557 | 0 | { |
7558 | 0 | warn (_("Offset %#" PRIx64 " is bigger than %s section size.\n"), |
7559 | 0 | offset, section->name); |
7560 | 0 | continue; |
7561 | 0 | } |
7562 | | |
7563 | 0 | if (vnext && voffset >= bytes) |
7564 | 0 | { |
7565 | 0 | warn (_("View Offset %#" PRIx64 " is bigger than %s section size.\n"), |
7566 | 0 | voffset, section->name); |
7567 | 0 | continue; |
7568 | 0 | } |
7569 | | |
7570 | 0 | if (!is_loclists) |
7571 | 0 | { |
7572 | 0 | if (is_dwo) |
7573 | 0 | display_loc_list_dwo (section, &start, i, offset, |
7574 | 0 | &vstart, has_frame_base); |
7575 | 0 | else |
7576 | 0 | display_loc_list (section, &start, i, offset, base_address, |
7577 | 0 | &vstart, has_frame_base); |
7578 | 0 | } |
7579 | 0 | else |
7580 | 0 | { |
7581 | 0 | if (is_dwo) |
7582 | 0 | warn (_("DWO is not yet supported.\n")); |
7583 | 0 | else |
7584 | 0 | display_loclists_list (section, &start, debug_info_p, offset, |
7585 | 0 | base_address, &vstart, has_frame_base); |
7586 | 0 | } |
7587 | | |
7588 | | /* FIXME: this arrangement is quite simplistic. Nothing |
7589 | | requires locview lists to be adjacent to corresponding |
7590 | | loclists, and a single loclist could be augmented by |
7591 | | different locview lists, and vice-versa, unlikely as it |
7592 | | is that it would make sense to do so. Hopefully we'll |
7593 | | have view pair support built into loclists before we ever |
7594 | | need to address all these possibilities. */ |
7595 | 0 | if (adjacent_view_loclists && vnext |
7596 | 0 | && vnext != start && vstart != next) |
7597 | 0 | { |
7598 | 0 | adjacent_view_loclists = 0; |
7599 | 0 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); |
7600 | 0 | } |
7601 | |
|
7602 | 0 | if (vnext && vnext == start) |
7603 | 0 | display_view_pair_list (section, &start, i, vstart); |
7604 | 0 | } |
7605 | 0 | } |
7606 | | |
7607 | 0 | if (start < section->start + section->size) |
7608 | 0 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
7609 | 0 | "There are %ld unused bytes at the end of section %s\n", |
7610 | 0 | (long) (section->start + section->size - start)), |
7611 | 0 | (long) (section->start + section->size - start), section->name); |
7612 | 0 | putchar ('\n'); |
7613 | 0 | free (array); |
7614 | 0 | return 1; |
7615 | 0 | } |
7616 | | |
7617 | | static int |
7618 | | display_debug_str (struct dwarf_section *section, |
7619 | | void *file ATTRIBUTE_UNUSED) |
7620 | 1.25k | { |
7621 | 1.25k | unsigned char *start = section->start; |
7622 | 1.25k | uint64_t bytes = section->size; |
7623 | 1.25k | uint64_t addr = section->address; |
7624 | | |
7625 | 1.25k | if (bytes == 0) |
7626 | 17 | { |
7627 | 17 | printf (_("\nThe %s section is empty.\n"), section->name); |
7628 | 17 | return 0; |
7629 | 17 | } |
7630 | | |
7631 | 1.23k | introduce (section, false); |
7632 | | |
7633 | 473k | while (bytes) |
7634 | 471k | { |
7635 | 471k | int j; |
7636 | 471k | int k; |
7637 | 471k | int lbytes; |
7638 | | |
7639 | 471k | lbytes = (bytes > 16 ? 16 : bytes); |
7640 | | |
7641 | 471k | printf (" 0x%8.8" PRIx64 " ", addr); |
7642 | | |
7643 | 8.02M | for (j = 0; j < 16; j++) |
7644 | 7.55M | { |
7645 | 7.55M | if (j < lbytes) |
7646 | 7.54M | printf ("%2.2x", start[j]); |
7647 | 7.95k | else |
7648 | 7.95k | printf (" "); |
7649 | | |
7650 | 7.55M | if ((j & 3) == 3) |
7651 | 1.88M | printf (" "); |
7652 | 7.55M | } |
7653 | | |
7654 | 8.01M | for (j = 0; j < lbytes; j++) |
7655 | 7.54M | { |
7656 | 7.54M | k = start[j]; |
7657 | 7.54M | if (k >= ' ' && k < 0x80) |
7658 | 5.52M | printf ("%c", k); |
7659 | 2.01M | else |
7660 | 2.01M | printf ("."); |
7661 | 7.54M | } |
7662 | | |
7663 | 471k | putchar ('\n'); |
7664 | | |
7665 | 471k | start += lbytes; |
7666 | 471k | addr += lbytes; |
7667 | 471k | bytes -= lbytes; |
7668 | 471k | } |
7669 | | |
7670 | 1.23k | putchar ('\n'); |
7671 | | |
7672 | 1.23k | return 1; |
7673 | 1.25k | } |
7674 | | |
7675 | | static int |
7676 | | display_debug_info (struct dwarf_section *section, void *file) |
7677 | 989 | { |
7678 | 989 | return process_debug_info (section, file, section->abbrev_sec, false, false); |
7679 | 989 | } |
7680 | | |
7681 | | static int |
7682 | | display_debug_types (struct dwarf_section *section, void *file) |
7683 | 48 | { |
7684 | 48 | return process_debug_info (section, file, section->abbrev_sec, false, true); |
7685 | 48 | } |
7686 | | |
7687 | | static int |
7688 | | display_trace_info (struct dwarf_section *section, void *file) |
7689 | 0 | { |
7690 | 0 | return process_debug_info (section, file, section->abbrev_sec, false, true); |
7691 | 0 | } |
7692 | | |
7693 | | static int |
7694 | | display_sframe (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) |
7695 | 0 | { |
7696 | 0 | sframe_decoder_ctx *sfd_ctx = NULL; |
7697 | 0 | unsigned char *data = section->start; |
7698 | 0 | size_t sf_size = section->size; |
7699 | 0 | int err = 0; |
7700 | |
|
7701 | 0 | if (strcmp (section->name, "") == 0) |
7702 | 0 | { |
7703 | 0 | error (_("Section name must be provided \n")); |
7704 | 0 | return false; |
7705 | 0 | } |
7706 | | |
7707 | | /* Decode the contents of the section. */ |
7708 | 0 | sfd_ctx = sframe_decode ((const char*)data, sf_size, &err); |
7709 | 0 | if (!sfd_ctx || err) |
7710 | 0 | { |
7711 | 0 | error (_("SFrame decode failure: %s\n"), sframe_errmsg (err)); |
7712 | 0 | return false; |
7713 | 0 | } |
7714 | | |
7715 | 0 | printf (_("Contents of the SFrame section %s:"), section->name); |
7716 | | /* Dump the contents as text. */ |
7717 | 0 | dump_sframe (sfd_ctx, section->address); |
7718 | |
|
7719 | 0 | sframe_decoder_free (&sfd_ctx); |
7720 | |
|
7721 | 0 | return true; |
7722 | 0 | } |
7723 | | |
7724 | | static int |
7725 | | display_debug_aranges (struct dwarf_section *section, |
7726 | | void *file ATTRIBUTE_UNUSED) |
7727 | 303 | { |
7728 | 303 | unsigned char *start = section->start; |
7729 | 303 | unsigned char *end = start + section->size; |
7730 | | |
7731 | 303 | introduce (section, false); |
7732 | | |
7733 | | /* It does not matter if this load fails, |
7734 | | we test for that later on. */ |
7735 | 303 | load_debug_info (file); |
7736 | | |
7737 | 5.06k | while (start < end) |
7738 | 4.92k | { |
7739 | 4.92k | unsigned char *hdrptr; |
7740 | 4.92k | DWARF2_Internal_ARange arange; |
7741 | 4.92k | unsigned char *addr_ranges; |
7742 | 4.92k | uint64_t length; |
7743 | 4.92k | uint64_t address; |
7744 | 4.92k | uint64_t sec_off; |
7745 | 4.92k | unsigned char address_size; |
7746 | 4.92k | unsigned int offset_size; |
7747 | 4.92k | unsigned char *end_ranges; |
7748 | | |
7749 | 4.92k | hdrptr = start; |
7750 | 4.92k | sec_off = hdrptr - section->start; |
7751 | | |
7752 | 4.92k | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
7753 | 4.92k | if (arange.ar_length == 0xffffffff) |
7754 | 2 | { |
7755 | 2 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
7756 | 2 | offset_size = 8; |
7757 | 2 | } |
7758 | 4.92k | else |
7759 | 4.92k | offset_size = 4; |
7760 | | |
7761 | 4.92k | if (arange.ar_length > (size_t) (end - hdrptr)) |
7762 | 120 | { |
7763 | 120 | warn (_("Debug info is corrupted, %s header at %#" PRIx64 |
7764 | 120 | " has length %#" PRIx64 "\n"), |
7765 | 120 | section->name, sec_off, arange.ar_length); |
7766 | 120 | break; |
7767 | 120 | } |
7768 | 4.80k | end_ranges = hdrptr + arange.ar_length; |
7769 | | |
7770 | 4.80k | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end_ranges); |
7771 | 4.80k | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, |
7772 | 4.80k | end_ranges); |
7773 | | |
7774 | 4.80k | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
7775 | 4.80k | && num_debug_info_entries > 0 |
7776 | 4.80k | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) |
7777 | 0 | warn (_(".debug_info offset of %#" PRIx64 |
7778 | 0 | " in %s section does not point to a CU header.\n"), |
7779 | 0 | arange.ar_info_offset, section->name); |
7780 | | |
7781 | 4.80k | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end_ranges); |
7782 | 4.80k | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end_ranges); |
7783 | | |
7784 | 4.80k | if (arange.ar_version != 2 && arange.ar_version != 3) |
7785 | 32 | { |
7786 | | /* PR 19872: A version number of 0 probably means that there is |
7787 | | padding at the end of the .debug_aranges section. Gold puts |
7788 | | it there when performing an incremental link, for example. |
7789 | | So do not generate a warning in this case. */ |
7790 | 32 | if (arange.ar_version) |
7791 | 13 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); |
7792 | 32 | break; |
7793 | 32 | } |
7794 | | |
7795 | 4.77k | printf (_(" Length: %" PRId64 "\n"), arange.ar_length); |
7796 | 4.77k | printf (_(" Version: %d\n"), arange.ar_version); |
7797 | 4.77k | printf (_(" Offset into .debug_info: %#" PRIx64 "\n"), |
7798 | 4.77k | arange.ar_info_offset); |
7799 | 4.77k | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
7800 | 4.77k | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); |
7801 | | |
7802 | 4.77k | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
7803 | | |
7804 | | /* PR 17512: file: 001-108546-0.001:0.1. */ |
7805 | 4.77k | if (address_size == 0 || address_size > 8) |
7806 | 13 | { |
7807 | 13 | error (_("Invalid address size in %s section!\n"), |
7808 | 13 | section->name); |
7809 | 13 | break; |
7810 | 13 | } |
7811 | | |
7812 | | /* The DWARF spec does not require that the address size be a power |
7813 | | of two, but we do. This will have to change if we ever encounter |
7814 | | an uneven architecture. */ |
7815 | 4.75k | if ((address_size & (address_size - 1)) != 0) |
7816 | 1 | { |
7817 | 1 | warn (_("Pointer size + Segment size is not a power of two.\n")); |
7818 | 1 | break; |
7819 | 1 | } |
7820 | | |
7821 | 4.75k | if (address_size > 4) |
7822 | 611 | printf (_("\n Address Length\n")); |
7823 | 4.14k | else |
7824 | 4.14k | printf (_("\n Address Length\n")); |
7825 | | |
7826 | 4.75k | addr_ranges = hdrptr; |
7827 | | |
7828 | | /* Must pad to an alignment boundary that is twice the address size. */ |
7829 | 4.75k | addr_ranges += (2 * address_size - 1 |
7830 | 4.75k | - (hdrptr - start - 1) % (2 * address_size)); |
7831 | | |
7832 | 14.2k | while (2 * address_size <= end_ranges - addr_ranges) |
7833 | 9.49k | { |
7834 | 9.49k | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, |
7835 | 9.49k | end_ranges); |
7836 | 9.49k | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, |
7837 | 9.49k | end_ranges); |
7838 | 9.49k | printf (" "); |
7839 | 9.49k | print_hex (address, address_size); |
7840 | 9.49k | print_hex_ns (length, address_size); |
7841 | 9.49k | putchar ('\n'); |
7842 | 9.49k | } |
7843 | | |
7844 | 4.75k | start = end_ranges; |
7845 | 4.75k | } |
7846 | | |
7847 | 303 | printf ("\n"); |
7848 | | |
7849 | 303 | return 1; |
7850 | 303 | } |
7851 | | |
7852 | | /* Comparison function for qsort. */ |
7853 | | static int |
7854 | | comp_addr_base (const void * v0, const void * v1) |
7855 | 0 | { |
7856 | 0 | debug_info *info0 = *(debug_info **) v0; |
7857 | 0 | debug_info *info1 = *(debug_info **) v1; |
7858 | 0 | return info0->addr_base - info1->addr_base; |
7859 | 0 | } |
7860 | | |
7861 | | /* Display the debug_addr section. */ |
7862 | | static int |
7863 | | display_debug_addr (struct dwarf_section *section, |
7864 | | void *file) |
7865 | 37 | { |
7866 | 37 | debug_info **debug_addr_info; |
7867 | 37 | unsigned char *entry; |
7868 | 37 | unsigned char *end; |
7869 | 37 | unsigned int i; |
7870 | 37 | unsigned int count; |
7871 | 37 | unsigned char * header; |
7872 | | |
7873 | 37 | if (section->size == 0) |
7874 | 1 | { |
7875 | 1 | printf (_("\nThe %s section is empty.\n"), section->name); |
7876 | 1 | return 0; |
7877 | 1 | } |
7878 | | |
7879 | 36 | if (load_debug_info (file) == 0) |
7880 | 31 | { |
7881 | 31 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), |
7882 | 31 | section->name); |
7883 | 31 | return 0; |
7884 | 31 | } |
7885 | | |
7886 | 5 | introduce (section, false); |
7887 | | |
7888 | | /* PR 17531: file: cf38d01b. |
7889 | | We use xcalloc because a corrupt file may not have initialised all of the |
7890 | | fields in the debug_info structure, which means that the sort below might |
7891 | | try to move uninitialised data. */ |
7892 | 5 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), |
7893 | 5 | sizeof (debug_info *)); |
7894 | | |
7895 | 5 | count = 0; |
7896 | 10 | for (i = 0; i < num_debug_info_entries; i++) |
7897 | 5 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
7898 | 5 | { |
7899 | | /* PR 17531: file: cf38d01b. */ |
7900 | 5 | if (debug_information[i].addr_base >= section->size) |
7901 | 0 | warn (_("Corrupt address base (%#" PRIx64 ")" |
7902 | 0 | " found in debug section %u\n"), |
7903 | 0 | debug_information[i].addr_base, i); |
7904 | 5 | else |
7905 | 5 | debug_addr_info [count++] = debug_information + i; |
7906 | 5 | } |
7907 | | |
7908 | | /* Add a sentinel to make iteration convenient. */ |
7909 | 5 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); |
7910 | 5 | debug_addr_info [count]->addr_base = section->size; |
7911 | 5 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
7912 | | |
7913 | 5 | header = section->start; |
7914 | 7 | for (i = 0; i < count; i++) |
7915 | 5 | { |
7916 | 5 | unsigned int idx; |
7917 | 5 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
7918 | | |
7919 | 5 | printf (_(" For compilation unit at offset %#" PRIx64 ":\n"), |
7920 | 5 | debug_addr_info [i]->cu_offset); |
7921 | | |
7922 | 5 | printf (_("\tIndex\tAddress\n")); |
7923 | 5 | entry = section->start + debug_addr_info [i]->addr_base; |
7924 | 5 | if (debug_addr_info [i]->dwarf_version >= 5) |
7925 | 5 | { |
7926 | 5 | size_t header_size = entry - header; |
7927 | 5 | unsigned char *curr_header = header; |
7928 | 5 | uint64_t length; |
7929 | 5 | int version; |
7930 | 5 | int segment_selector_size; |
7931 | | |
7932 | 5 | if (header_size != 8 && header_size != 16) |
7933 | 3 | { |
7934 | 3 | warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"), |
7935 | 3 | section->name, header_size); |
7936 | 3 | break; |
7937 | 3 | } |
7938 | | |
7939 | 2 | SAFE_BYTE_GET_AND_INC (length, curr_header, 4, entry); |
7940 | 2 | if (length == 0xffffffff) |
7941 | 2 | SAFE_BYTE_GET_AND_INC (length, curr_header, 8, entry); |
7942 | 2 | if (length > (size_t) (section->start + section->size - curr_header) |
7943 | 2 | || length < (size_t) (entry - curr_header)) |
7944 | 0 | { |
7945 | 0 | warn (_("Corrupt %s section: unit_length field of %#" PRIx64 |
7946 | 0 | " is invalid\n"), section->name, length); |
7947 | 0 | break; |
7948 | 0 | } |
7949 | 2 | end = curr_header + length; |
7950 | 2 | SAFE_BYTE_GET_AND_INC (version, curr_header, 2, entry); |
7951 | 2 | if (version != 5) |
7952 | 0 | warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"), |
7953 | 0 | section->name, version); |
7954 | | |
7955 | 2 | SAFE_BYTE_GET_AND_INC (address_size, curr_header, 1, entry); |
7956 | 2 | SAFE_BYTE_GET_AND_INC (segment_selector_size, curr_header, 1, entry); |
7957 | 2 | address_size += segment_selector_size; |
7958 | 2 | } |
7959 | 0 | else |
7960 | 0 | end = section->start + debug_addr_info [i + 1]->addr_base; |
7961 | | |
7962 | 2 | header = end; |
7963 | 2 | idx = 0; |
7964 | | |
7965 | 2 | if (address_size < 1 || address_size > sizeof (uint64_t)) |
7966 | 0 | { |
7967 | 0 | warn (_("Corrupt %s section: address size (%x) is wrong\n"), |
7968 | 0 | section->name, address_size); |
7969 | 0 | break; |
7970 | 0 | } |
7971 | | |
7972 | 4 | while ((size_t) (end - entry) >= address_size) |
7973 | 2 | { |
7974 | 2 | uint64_t base = byte_get (entry, address_size); |
7975 | 2 | printf (_("\t%d:\t"), idx); |
7976 | 2 | print_hex_ns (base, address_size); |
7977 | 2 | printf ("\n"); |
7978 | 2 | entry += address_size; |
7979 | 2 | idx++; |
7980 | 2 | } |
7981 | 2 | } |
7982 | 5 | printf ("\n"); |
7983 | | |
7984 | 5 | free (debug_addr_info[count]); |
7985 | 5 | free (debug_addr_info); |
7986 | 5 | return i == count; |
7987 | 5 | } |
7988 | | |
7989 | | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ |
7990 | | |
7991 | | static int |
7992 | | display_debug_str_offsets (struct dwarf_section *section, |
7993 | | void *file ATTRIBUTE_UNUSED) |
7994 | 29 | { |
7995 | 29 | unsigned long idx; |
7996 | | |
7997 | 29 | if (section->size == 0) |
7998 | 1 | { |
7999 | 1 | printf (_("\nThe %s section is empty.\n"), section->name); |
8000 | 1 | return 0; |
8001 | 1 | } |
8002 | | |
8003 | 28 | unsigned char *start = section->start; |
8004 | 28 | unsigned char *end = start + section->size; |
8005 | 28 | unsigned char *curr = start; |
8006 | 28 | uint64_t debug_str_offsets_hdr_len; |
8007 | | |
8008 | 28 | const char *suffix = strrchr (section->name, '.'); |
8009 | 28 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
8010 | | |
8011 | 28 | if (dwo) |
8012 | 0 | load_debug_section_with_follow (str_dwo, file); |
8013 | 28 | else |
8014 | 28 | load_debug_section_with_follow (str, file); |
8015 | | |
8016 | 28 | introduce (section, false); |
8017 | | |
8018 | 54 | while (curr < end) |
8019 | 34 | { |
8020 | 34 | uint64_t length; |
8021 | 34 | uint64_t entry_length; |
8022 | | |
8023 | 34 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); |
8024 | | /* FIXME: We assume that this means 64-bit DWARF is being used. */ |
8025 | 34 | if (length == 0xffffffff) |
8026 | 2 | { |
8027 | 2 | SAFE_BYTE_GET_AND_INC (length, curr, 8, end); |
8028 | 2 | entry_length = 8; |
8029 | 2 | debug_str_offsets_hdr_len = 16; |
8030 | 2 | } |
8031 | 32 | else |
8032 | 32 | { |
8033 | 32 | entry_length = 4; |
8034 | 32 | debug_str_offsets_hdr_len = 8; |
8035 | 32 | } |
8036 | | |
8037 | 34 | unsigned char *entries_end; |
8038 | 34 | if (length == 0) |
8039 | 3 | { |
8040 | | /* This is probably an old style .debug_str_offset section which |
8041 | | just contains offsets and no header (and the first offset is 0). */ |
8042 | 3 | length = section->size; |
8043 | 3 | curr = section->start; |
8044 | 3 | entries_end = end; |
8045 | 3 | debug_str_offsets_hdr_len = 0; |
8046 | | |
8047 | 3 | printf (_(" Length: %#" PRIx64 "\n"), length); |
8048 | 3 | printf (_(" Index Offset [String]\n")); |
8049 | 3 | } |
8050 | 31 | else |
8051 | 31 | { |
8052 | 31 | if (length <= (size_t) (end - curr)) |
8053 | 18 | entries_end = curr + length; |
8054 | 13 | else |
8055 | 13 | { |
8056 | 13 | warn (_("Section %s is too small %#" PRIx64 "\n"), |
8057 | 13 | section->name, section->size); |
8058 | 13 | entries_end = end; |
8059 | 13 | } |
8060 | | |
8061 | 31 | int version; |
8062 | 31 | SAFE_BYTE_GET_AND_INC (version, curr, 2, entries_end); |
8063 | 31 | if (version != 5) |
8064 | 19 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); |
8065 | | |
8066 | 31 | int padding; |
8067 | 31 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, entries_end); |
8068 | 31 | if (padding != 0) |
8069 | 9 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); |
8070 | | |
8071 | 31 | printf (_(" Length: %#" PRIx64 "\n"), length); |
8072 | 31 | printf (_(" Version: %#x\n"), version); |
8073 | 31 | printf (_(" Index Offset [String]\n")); |
8074 | 31 | } |
8075 | | |
8076 | 6.72k | for (idx = 0; curr < entries_end; idx++) |
8077 | 6.70k | { |
8078 | 6.70k | uint64_t offset; |
8079 | 6.70k | const unsigned char * string; |
8080 | | |
8081 | 6.70k | if ((size_t) (entries_end - curr) < entry_length) |
8082 | | /* Not enough space to read one entry_length, give up. */ |
8083 | 8 | return 0; |
8084 | | |
8085 | 6.69k | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, entries_end); |
8086 | 6.69k | if (dwo) |
8087 | 0 | string = (const unsigned char *) |
8088 | 0 | fetch_indexed_string (idx, NULL, entry_length, dwo, debug_str_offsets_hdr_len); |
8089 | 6.69k | else |
8090 | 6.69k | string = fetch_indirect_string (offset); |
8091 | | |
8092 | 6.69k | printf (" %8lu ", idx); |
8093 | 6.69k | print_hex (offset, entry_length); |
8094 | 6.69k | printf (" %s\n", string); |
8095 | 6.69k | } |
8096 | 34 | } |
8097 | | |
8098 | 20 | return 1; |
8099 | 28 | } |
8100 | | |
8101 | | /* Each debug_information[x].range_lists[y] gets this representation for |
8102 | | sorting purposes. */ |
8103 | | |
8104 | | struct range_entry |
8105 | | { |
8106 | | /* The debug_information[x].range_lists[y] value. */ |
8107 | | uint64_t ranges_offset; |
8108 | | |
8109 | | /* Original debug_information to find parameters of the data. */ |
8110 | | debug_info *debug_info_p; |
8111 | | }; |
8112 | | |
8113 | | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ |
8114 | | |
8115 | | static int |
8116 | | range_entry_compar (const void *ap, const void *bp) |
8117 | 28.9k | { |
8118 | 28.9k | const struct range_entry *a_re = (const struct range_entry *) ap; |
8119 | 28.9k | const struct range_entry *b_re = (const struct range_entry *) bp; |
8120 | 28.9k | const uint64_t a = a_re->ranges_offset; |
8121 | 28.9k | const uint64_t b = b_re->ranges_offset; |
8122 | | |
8123 | 28.9k | return (a > b) - (b > a); |
8124 | 28.9k | } |
8125 | | |
8126 | | static unsigned char * |
8127 | | display_debug_ranges_list (unsigned char * start, |
8128 | | unsigned char * finish, |
8129 | | unsigned int pointer_size, |
8130 | | uint64_t offset, |
8131 | | uint64_t base_address) |
8132 | 6.58k | { |
8133 | 398k | while (start < finish) |
8134 | 397k | { |
8135 | 397k | uint64_t begin; |
8136 | 397k | uint64_t end; |
8137 | | |
8138 | 397k | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); |
8139 | 397k | if (start >= finish) |
8140 | 0 | break; |
8141 | 397k | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); |
8142 | | |
8143 | 397k | printf (" "); |
8144 | 397k | print_hex (offset, 4); |
8145 | | |
8146 | 397k | if (begin == 0 && end == 0) |
8147 | 6.12k | { |
8148 | 6.12k | printf (_("<End of list>\n")); |
8149 | 6.12k | break; |
8150 | 6.12k | } |
8151 | | |
8152 | | /* Check base address specifiers. */ |
8153 | 391k | if (is_max_address (begin, pointer_size) |
8154 | 391k | && !is_max_address (end, pointer_size)) |
8155 | 0 | { |
8156 | 0 | base_address = end; |
8157 | 0 | print_hex (begin, pointer_size); |
8158 | 0 | print_hex (end, pointer_size); |
8159 | 0 | printf ("(base address)\n"); |
8160 | 0 | continue; |
8161 | 0 | } |
8162 | | |
8163 | 391k | print_hex (begin + base_address, pointer_size); |
8164 | 391k | print_hex_ns (end + base_address, pointer_size); |
8165 | | |
8166 | 391k | if (begin == end) |
8167 | 1.51k | fputs (_(" (start == end)"), stdout); |
8168 | 390k | else if (begin > end) |
8169 | 180k | fputs (_(" (start > end)"), stdout); |
8170 | | |
8171 | 391k | putchar ('\n'); |
8172 | 391k | } |
8173 | | |
8174 | 6.58k | return start; |
8175 | 6.58k | } |
8176 | | |
8177 | | static unsigned char * |
8178 | | display_debug_rnglists_list (unsigned char * start, |
8179 | | unsigned char * finish, |
8180 | | unsigned int pointer_size, |
8181 | | uint64_t offset, |
8182 | | uint64_t base_address, |
8183 | | uint64_t addr_base) |
8184 | 0 | { |
8185 | 0 | unsigned char *next = start; |
8186 | |
|
8187 | 0 | while (1) |
8188 | 0 | { |
8189 | 0 | uint64_t off = offset + (start - next); |
8190 | 0 | enum dwarf_range_list_entry rlet; |
8191 | | /* Initialize it due to a false compiler warning. */ |
8192 | 0 | uint64_t begin = -1, length, end = -1; |
8193 | |
|
8194 | 0 | if (start >= finish) |
8195 | 0 | { |
8196 | 0 | warn (_("Range list starting at offset %#" PRIx64 |
8197 | 0 | " is not terminated.\n"), offset); |
8198 | 0 | break; |
8199 | 0 | } |
8200 | | |
8201 | 0 | printf (" "); |
8202 | 0 | print_hex (off, 4); |
8203 | |
|
8204 | 0 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); |
8205 | | |
8206 | 0 | switch (rlet) |
8207 | 0 | { |
8208 | 0 | case DW_RLE_end_of_list: |
8209 | 0 | printf (_("<End of list>\n")); |
8210 | 0 | break; |
8211 | 0 | case DW_RLE_base_addressx: |
8212 | 0 | READ_ULEB (base_address, start, finish); |
8213 | 0 | print_hex (base_address, pointer_size); |
8214 | 0 | printf (_("(base address index) ")); |
8215 | 0 | base_address = fetch_indexed_addr (base_address * pointer_size + addr_base, |
8216 | 0 | pointer_size); |
8217 | 0 | print_hex (base_address, pointer_size); |
8218 | 0 | printf (_("(base address)\n")); |
8219 | 0 | break; |
8220 | 0 | case DW_RLE_startx_endx: |
8221 | 0 | READ_ULEB (begin, start, finish); |
8222 | 0 | READ_ULEB (end, start, finish); |
8223 | 0 | begin = fetch_indexed_addr (begin * pointer_size + addr_base, |
8224 | 0 | pointer_size); |
8225 | 0 | end = fetch_indexed_addr (end * pointer_size + addr_base, |
8226 | 0 | pointer_size); |
8227 | 0 | break; |
8228 | 0 | case DW_RLE_startx_length: |
8229 | 0 | READ_ULEB (begin, start, finish); |
8230 | 0 | READ_ULEB (length, start, finish); |
8231 | 0 | begin = fetch_indexed_addr (begin * pointer_size + addr_base, |
8232 | 0 | pointer_size); |
8233 | 0 | end = begin + length; |
8234 | 0 | break; |
8235 | 0 | case DW_RLE_offset_pair: |
8236 | 0 | READ_ULEB (begin, start, finish); |
8237 | 0 | READ_ULEB (end, start, finish); |
8238 | 0 | break; |
8239 | 0 | case DW_RLE_base_address: |
8240 | 0 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); |
8241 | 0 | print_hex (base_address, pointer_size); |
8242 | 0 | printf (_("(base address)\n")); |
8243 | 0 | break; |
8244 | 0 | case DW_RLE_start_end: |
8245 | 0 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); |
8246 | 0 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); |
8247 | 0 | break; |
8248 | 0 | case DW_RLE_start_length: |
8249 | 0 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); |
8250 | 0 | READ_ULEB (length, start, finish); |
8251 | 0 | end = begin + length; |
8252 | 0 | break; |
8253 | 0 | default: |
8254 | 0 | error (_("Invalid range list entry type %d\n"), rlet); |
8255 | 0 | rlet = DW_RLE_end_of_list; |
8256 | 0 | break; |
8257 | 0 | } |
8258 | | |
8259 | 0 | if (rlet == DW_RLE_end_of_list) |
8260 | 0 | break; |
8261 | 0 | if (rlet == DW_RLE_base_address || rlet == DW_RLE_base_addressx) |
8262 | 0 | continue; |
8263 | | |
8264 | | /* Only a DW_RLE_offset_pair needs the base address added. */ |
8265 | 0 | if (rlet == DW_RLE_offset_pair) |
8266 | 0 | { |
8267 | 0 | begin += base_address; |
8268 | 0 | end += base_address; |
8269 | 0 | } |
8270 | |
|
8271 | 0 | print_hex (begin, pointer_size); |
8272 | 0 | print_hex (end, pointer_size); |
8273 | |
|
8274 | 0 | if (begin == end) |
8275 | 0 | fputs (_(" (start == end)"), stdout); |
8276 | 0 | else if (begin > end) |
8277 | 0 | fputs (_(" (start > end)"), stdout); |
8278 | |
|
8279 | 0 | putchar ('\n'); |
8280 | 0 | } |
8281 | | |
8282 | 0 | return start; |
8283 | 0 | } |
8284 | | |
8285 | | static int |
8286 | | display_debug_rnglists_unit_header (struct dwarf_section * section, |
8287 | | uint64_t * unit_offset, |
8288 | | unsigned char * poffset_size) |
8289 | 0 | { |
8290 | 0 | uint64_t start_offset = *unit_offset; |
8291 | 0 | unsigned char * p = section->start + start_offset; |
8292 | 0 | unsigned char * finish = section->start + section->size; |
8293 | 0 | uint64_t initial_length; |
8294 | 0 | unsigned char segment_selector_size; |
8295 | 0 | unsigned int offset_entry_count; |
8296 | 0 | unsigned int i; |
8297 | 0 | unsigned short version; |
8298 | 0 | unsigned char address_size = 0; |
8299 | 0 | unsigned char offset_size; |
8300 | | |
8301 | | /* Get and check the length of the block. */ |
8302 | 0 | SAFE_BYTE_GET_AND_INC (initial_length, p, 4, finish); |
8303 | | |
8304 | 0 | if (initial_length == 0xffffffff) |
8305 | 0 | { |
8306 | | /* This section is 64-bit DWARF 3. */ |
8307 | 0 | SAFE_BYTE_GET_AND_INC (initial_length, p, 8, finish); |
8308 | 0 | *poffset_size = offset_size = 8; |
8309 | 0 | } |
8310 | 0 | else |
8311 | 0 | *poffset_size = offset_size = 4; |
8312 | | |
8313 | 0 | if (initial_length > (size_t) (finish - p)) |
8314 | 0 | { |
8315 | | /* If the length field has a relocation against it, then we should |
8316 | | not complain if it is inaccurate (and probably negative). |
8317 | | It is copied from .debug_line handling code. */ |
8318 | 0 | if (reloc_at (section, (p - section->start) - offset_size)) |
8319 | 0 | initial_length = finish - p; |
8320 | 0 | else |
8321 | 0 | { |
8322 | 0 | warn (_("The length field (%#" PRIx64 |
8323 | 0 | ") in the debug_rnglists header is wrong" |
8324 | 0 | " - the section is too small\n"), |
8325 | 0 | initial_length); |
8326 | 0 | return 0; |
8327 | 0 | } |
8328 | 0 | } |
8329 | | |
8330 | | /* Report the next unit offset to the caller. */ |
8331 | 0 | *unit_offset = (p - section->start) + initial_length; |
8332 | | |
8333 | | /* Get the other fields in the header. */ |
8334 | 0 | SAFE_BYTE_GET_AND_INC (version, p, 2, finish); |
8335 | 0 | SAFE_BYTE_GET_AND_INC (address_size, p, 1, finish); |
8336 | 0 | SAFE_BYTE_GET_AND_INC (segment_selector_size, p, 1, finish); |
8337 | 0 | SAFE_BYTE_GET_AND_INC (offset_entry_count, p, 4, finish); |
8338 | | |
8339 | 0 | printf (_(" Table at Offset: %#" PRIx64 ":\n"), start_offset); |
8340 | 0 | printf (_(" Length: %#" PRIx64 "\n"), initial_length); |
8341 | 0 | printf (_(" DWARF version: %u\n"), version); |
8342 | 0 | printf (_(" Address size: %u\n"), address_size); |
8343 | 0 | printf (_(" Segment size: %u\n"), segment_selector_size); |
8344 | 0 | printf (_(" Offset entries: %u\n"), offset_entry_count); |
8345 | | |
8346 | | /* Check the fields. */ |
8347 | 0 | if (segment_selector_size != 0) |
8348 | 0 | { |
8349 | 0 | warn (_("The %s section contains " |
8350 | 0 | "unsupported segment selector size: %d.\n"), |
8351 | 0 | section->name, segment_selector_size); |
8352 | 0 | return 0; |
8353 | 0 | } |
8354 | | |
8355 | 0 | if (version < 5) |
8356 | 0 | { |
8357 | 0 | warn (_("Only DWARF version 5+ debug_rnglists info " |
8358 | 0 | "is currently supported.\n")); |
8359 | 0 | return 0; |
8360 | 0 | } |
8361 | | |
8362 | 0 | if (offset_entry_count != 0) |
8363 | 0 | { |
8364 | 0 | printf (_("\n Offsets starting at %#tx:\n"), p - section->start); |
8365 | |
|
8366 | 0 | for (i = 0; i < offset_entry_count; i++) |
8367 | 0 | { |
8368 | 0 | uint64_t entry; |
8369 | |
|
8370 | 0 | SAFE_BYTE_GET_AND_INC (entry, p, offset_size, finish); |
8371 | 0 | printf (_(" [%6u] %#" PRIx64 "\n"), i, entry); |
8372 | 0 | } |
8373 | 0 | } |
8374 | | |
8375 | 0 | return 1; |
8376 | 0 | } |
8377 | | |
8378 | | static bool |
8379 | | is_range_list_for_this_section (bool is_rnglists, unsigned int version) |
8380 | 8.34k | { |
8381 | 8.34k | if (is_rnglists && version > 4) |
8382 | 0 | return true; |
8383 | | |
8384 | 8.34k | if (! is_rnglists && version < 5) |
8385 | 8.34k | return true; |
8386 | | |
8387 | 3 | return false; |
8388 | 8.34k | } |
8389 | | |
8390 | | static int |
8391 | | display_debug_ranges (struct dwarf_section *section, |
8392 | | void *file ATTRIBUTE_UNUSED) |
8393 | 734 | { |
8394 | 734 | unsigned char *start = section->start; |
8395 | 734 | unsigned char *last_start = start; |
8396 | 734 | unsigned char *last_end; |
8397 | 734 | uint64_t bytes = section->size; |
8398 | 734 | unsigned char *section_begin = start; |
8399 | 734 | unsigned char *finish = start + bytes; |
8400 | 734 | unsigned int num_range_list, i; |
8401 | 734 | struct range_entry *range_entries; |
8402 | 734 | struct range_entry *range_entry_fill; |
8403 | 734 | bool is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
8404 | 734 | uint64_t last_offset = 0; |
8405 | 734 | uint64_t next_rnglists_cu_offset = 0; |
8406 | 734 | unsigned char offset_size; |
8407 | | |
8408 | 734 | if (bytes == 0) |
8409 | 4 | { |
8410 | 4 | printf (_("\nThe %s section is empty.\n"), section->name); |
8411 | 4 | return 0; |
8412 | 4 | } |
8413 | | |
8414 | 730 | introduce (section, false); |
8415 | | |
8416 | 730 | if (load_debug_info (file) == 0) |
8417 | 557 | { |
8418 | 557 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), |
8419 | 557 | section->name); |
8420 | 557 | return 0; |
8421 | 557 | } |
8422 | | |
8423 | 173 | num_range_list = 0; |
8424 | 1.35k | for (i = 0; i < num_debug_info_entries; i++) |
8425 | 1.18k | if (is_range_list_for_this_section (is_rnglists, debug_information [i].dwarf_version)) |
8426 | 1.18k | num_range_list += debug_information [i].num_range_lists; |
8427 | | |
8428 | 173 | if (num_range_list == 0) |
8429 | 12 | { |
8430 | | /* This can happen when the file was compiled with -gsplit-debug |
8431 | | which removes references to range lists from the primary .o file. */ |
8432 | 12 | printf (_("No range lists referenced by .debug_info section.\n")); |
8433 | 12 | return 1; |
8434 | 12 | } |
8435 | | |
8436 | 161 | range_entry_fill = range_entries = XNEWVEC (struct range_entry, num_range_list); |
8437 | | |
8438 | 923 | for (i = 0; i < num_debug_info_entries; i++) |
8439 | 762 | { |
8440 | 762 | debug_info *debug_info_p = &debug_information[i]; |
8441 | 762 | unsigned int j; |
8442 | | |
8443 | 7.92k | for (j = 0; j < debug_info_p->num_range_lists; j++) |
8444 | 7.16k | { |
8445 | 7.16k | if (is_range_list_for_this_section (is_rnglists, debug_info_p->dwarf_version)) |
8446 | 7.16k | { |
8447 | 7.16k | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; |
8448 | 7.16k | range_entry_fill->debug_info_p = debug_info_p; |
8449 | 7.16k | range_entry_fill++; |
8450 | 7.16k | } |
8451 | 7.16k | } |
8452 | 762 | } |
8453 | | |
8454 | 161 | assert (range_entry_fill >= range_entries); |
8455 | 161 | assert (num_range_list >= (unsigned int)(range_entry_fill - range_entries)); |
8456 | 161 | num_range_list = range_entry_fill - range_entries; |
8457 | 161 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
8458 | 161 | range_entry_compar); |
8459 | | |
8460 | 161 | putchar ('\n'); |
8461 | 161 | if (!is_rnglists) |
8462 | 161 | printf (_(" Offset Begin End\n")); |
8463 | | |
8464 | 161 | last_end = NULL; |
8465 | 7.32k | for (i = 0; i < num_range_list; i++) |
8466 | 7.16k | { |
8467 | 7.16k | struct range_entry *range_entry = &range_entries[i]; |
8468 | 7.16k | debug_info *debug_info_p = range_entry->debug_info_p; |
8469 | 7.16k | unsigned int pointer_size; |
8470 | 7.16k | uint64_t offset; |
8471 | 7.16k | unsigned char *next; |
8472 | 7.16k | uint64_t base_address; |
8473 | | |
8474 | 7.16k | pointer_size = debug_info_p->pointer_size; |
8475 | 7.16k | offset = range_entry->ranges_offset; |
8476 | 7.16k | base_address = debug_info_p->base_address; |
8477 | | |
8478 | | /* PR 17512: file: 001-101485-0.001:0.1. */ |
8479 | 7.16k | if (pointer_size < 2 || pointer_size > 8) |
8480 | 0 | { |
8481 | 0 | warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64 "\n"), |
8482 | 0 | pointer_size, offset); |
8483 | 0 | continue; |
8484 | 0 | } |
8485 | | |
8486 | 7.16k | if (offset > (size_t) (finish - section_begin)) |
8487 | 20 | { |
8488 | 20 | warn (_("Corrupt offset (%#" PRIx64 ") in range entry %u\n"), |
8489 | 20 | offset, i); |
8490 | 20 | continue; |
8491 | 20 | } |
8492 | | |
8493 | | /* If we've moved on to the next compile unit in the rnglists section - dump the unit header(s). */ |
8494 | 7.14k | if (is_rnglists && next_rnglists_cu_offset < offset) |
8495 | 0 | { |
8496 | 0 | while (next_rnglists_cu_offset < offset) |
8497 | 0 | display_debug_rnglists_unit_header (section, &next_rnglists_cu_offset, &offset_size); |
8498 | 0 | printf (_(" Offset Begin End\n")); |
8499 | 0 | } |
8500 | | |
8501 | 7.14k | next = section_begin + offset; /* Offset is from the section start, the base has already been added. */ |
8502 | | |
8503 | 7.14k | if (i == 0) |
8504 | 161 | { |
8505 | 161 | last_end = section_begin; |
8506 | 161 | if (is_rnglists) |
8507 | 0 | last_end += 2 * offset_size - 4 + 2 + 1 + 1 + 4; |
8508 | 161 | } |
8509 | | /* If multiple DWARF entities reference the same range then we will |
8510 | | have multiple entries in the `range_entries' list for the same |
8511 | | offset. Thanks to the sort above these will all be consecutive in |
8512 | | the `range_entries' list, so we can easily ignore duplicates |
8513 | | here. */ |
8514 | 7.14k | if (i > 0 && last_offset == offset) |
8515 | 561 | continue; |
8516 | 6.58k | last_offset = offset; |
8517 | | |
8518 | 6.58k | if (dwarf_check != 0) |
8519 | 0 | { |
8520 | 0 | if (start < next) |
8521 | 0 | { |
8522 | 0 | if (last_end != next) |
8523 | 0 | warn (_("There is a hole [%#tx - %#tx] in %s section.\n"), |
8524 | 0 | last_end - section_begin, next - section_begin, |
8525 | 0 | section->name); |
8526 | 0 | } |
8527 | 0 | else if (start > next) |
8528 | 0 | { |
8529 | 0 | if (next == last_start) |
8530 | 0 | continue; |
8531 | 0 | warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"), |
8532 | 0 | start - section_begin, next - section_begin, section->name); |
8533 | 0 | } |
8534 | 0 | } |
8535 | | |
8536 | 6.58k | start = next; |
8537 | 6.58k | last_start = next; |
8538 | | |
8539 | 6.58k | if (is_rnglists) |
8540 | 0 | last_end |
8541 | 0 | = display_debug_rnglists_list |
8542 | 0 | (start, finish, pointer_size, offset, base_address, |
8543 | 0 | debug_info_p->addr_base); |
8544 | 6.58k | else |
8545 | 6.58k | last_end |
8546 | 6.58k | = display_debug_ranges_list |
8547 | 6.58k | (start, finish, pointer_size, offset, base_address); |
8548 | 6.58k | } |
8549 | | |
8550 | | /* Display trailing empty (or unreferenced) compile units, if any. */ |
8551 | 161 | if (is_rnglists) |
8552 | 0 | while (next_rnglists_cu_offset < section->size) |
8553 | 0 | display_debug_rnglists_unit_header (section, &next_rnglists_cu_offset, &offset_size); |
8554 | | |
8555 | 161 | putchar ('\n'); |
8556 | | |
8557 | 161 | free (range_entries); |
8558 | | |
8559 | 161 | return 1; |
8560 | 161 | } |
8561 | | |
8562 | | typedef struct Frame_Chunk |
8563 | | { |
8564 | | struct Frame_Chunk *next; |
8565 | | unsigned char *chunk_start; |
8566 | | unsigned int ncols; |
8567 | | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
8568 | | short int *col_type; |
8569 | | int64_t *col_offset; |
8570 | | char *augmentation; |
8571 | | unsigned int code_factor; |
8572 | | int data_factor; |
8573 | | uint64_t pc_begin; |
8574 | | uint64_t pc_range; |
8575 | | unsigned int cfa_reg; |
8576 | | uint64_t cfa_offset; |
8577 | | unsigned int ra; |
8578 | | unsigned char fde_encoding; |
8579 | | unsigned char cfa_exp; |
8580 | | unsigned char ptr_size; |
8581 | | unsigned char segment_size; |
8582 | | } |
8583 | | Frame_Chunk; |
8584 | | |
8585 | | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
8586 | | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; |
8587 | | static const char *const *dwarf_regnames; |
8588 | | static unsigned int dwarf_regnames_count; |
8589 | | static bool is_aarch64; |
8590 | | |
8591 | | /* A marker for a col_type that means this column was never referenced |
8592 | | in the frame info. */ |
8593 | 1.57M | #define DW_CFA_unreferenced (-1) |
8594 | | |
8595 | | /* Return 0 if no more space is needed, 1 if more space is needed, |
8596 | | -1 for invalid reg. */ |
8597 | | |
8598 | | static int |
8599 | | frame_need_space (Frame_Chunk *fc, unsigned int reg) |
8600 | 1.03M | { |
8601 | 1.03M | unsigned int prev = fc->ncols; |
8602 | | |
8603 | 1.03M | if (reg < (unsigned int) fc->ncols) |
8604 | 984k | return 0; |
8605 | | |
8606 | 55.4k | if (dwarf_regnames_count > 0 |
8607 | 55.4k | && reg > dwarf_regnames_count) |
8608 | 8.82k | return -1; |
8609 | | |
8610 | 46.5k | fc->ncols = reg + 1; |
8611 | | /* PR 17512: file: 10450-2643-0.004. |
8612 | | If reg == -1 then this can happen... */ |
8613 | 46.5k | if (fc->ncols == 0) |
8614 | 0 | return -1; |
8615 | | |
8616 | | /* PR 17512: file: 2844a11d. */ |
8617 | 46.5k | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
8618 | 0 | { |
8619 | 0 | error (_("Unfeasibly large register number: %u\n"), reg); |
8620 | 0 | fc->ncols = 0; |
8621 | | /* FIXME: 1024 is an arbitrary limit. Increase it if |
8622 | | we ever encounter a valid binary that exceeds it. */ |
8623 | 0 | return -1; |
8624 | 0 | } |
8625 | | |
8626 | 46.5k | fc->col_type = xcrealloc (fc->col_type, fc->ncols, |
8627 | 46.5k | sizeof (*fc->col_type)); |
8628 | 46.5k | fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, |
8629 | 46.5k | sizeof (*fc->col_offset)); |
8630 | | /* PR 17512: file:002-10025-0.005. */ |
8631 | 46.5k | if (fc->col_type == NULL || fc->col_offset == NULL) |
8632 | 0 | { |
8633 | 0 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), |
8634 | 0 | fc->ncols); |
8635 | 0 | fc->ncols = 0; |
8636 | 0 | return -1; |
8637 | 0 | } |
8638 | | |
8639 | 445k | while (prev < fc->ncols) |
8640 | 398k | { |
8641 | 398k | fc->col_type[prev] = DW_CFA_unreferenced; |
8642 | 398k | fc->col_offset[prev] = 0; |
8643 | 398k | prev++; |
8644 | 398k | } |
8645 | 46.5k | return 1; |
8646 | 46.5k | } |
8647 | | |
8648 | | static const char *const dwarf_regnames_i386[] = |
8649 | | { |
8650 | | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
8651 | | "esp", "ebp", "esi", "edi", /* 4 - 7 */ |
8652 | | "eip", "eflags", NULL, /* 8 - 10 */ |
8653 | | "st0", "st1", "st2", "st3", /* 11 - 14 */ |
8654 | | "st4", "st5", "st6", "st7", /* 15 - 18 */ |
8655 | | NULL, NULL, /* 19 - 20 */ |
8656 | | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ |
8657 | | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ |
8658 | | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ |
8659 | | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ |
8660 | | "fcw", "fsw", "mxcsr", /* 37 - 39 */ |
8661 | | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ |
8662 | | "tr", "ldtr", /* 48 - 49 */ |
8663 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ |
8664 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ |
8665 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ |
8666 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ |
8667 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ |
8668 | | NULL, NULL, NULL, /* 90 - 92 */ |
8669 | | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ |
8670 | | }; |
8671 | | |
8672 | | static const char *const dwarf_regnames_iamcu[] = |
8673 | | { |
8674 | | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
8675 | | "esp", "ebp", "esi", "edi", /* 4 - 7 */ |
8676 | | "eip", "eflags", NULL, /* 8 - 10 */ |
8677 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ |
8678 | | NULL, NULL, /* 19 - 20 */ |
8679 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ |
8680 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ |
8681 | | NULL, NULL, NULL, /* 37 - 39 */ |
8682 | | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ |
8683 | | "tr", "ldtr", /* 48 - 49 */ |
8684 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ |
8685 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ |
8686 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ |
8687 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ |
8688 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ |
8689 | | NULL, NULL, NULL, /* 90 - 92 */ |
8690 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ |
8691 | | }; |
8692 | | |
8693 | | static void |
8694 | | init_dwarf_regnames_i386 (void) |
8695 | 1.85k | { |
8696 | 1.85k | dwarf_regnames = dwarf_regnames_i386; |
8697 | 1.85k | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); |
8698 | 1.85k | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
8699 | 1.85k | } |
8700 | | |
8701 | | static void |
8702 | | init_dwarf_regnames_iamcu (void) |
8703 | 1.65k | { |
8704 | 1.65k | dwarf_regnames = dwarf_regnames_iamcu; |
8705 | 1.65k | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); |
8706 | 1.65k | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
8707 | 1.65k | } |
8708 | | |
8709 | | static const char *const DW_CFA_GNU_window_save_name[] = |
8710 | | { |
8711 | | "DW_CFA_GNU_window_save", |
8712 | | "DW_CFA_AARCH64_negate_ra_state" |
8713 | | }; |
8714 | | |
8715 | | static const char *const dwarf_regnames_x86_64[] = |
8716 | | { |
8717 | | "rax", "rdx", "rcx", "rbx", |
8718 | | "rsi", "rdi", "rbp", "rsp", |
8719 | | "r8", "r9", "r10", "r11", |
8720 | | "r12", "r13", "r14", "r15", |
8721 | | "rip", |
8722 | | "xmm0", "xmm1", "xmm2", "xmm3", |
8723 | | "xmm4", "xmm5", "xmm6", "xmm7", |
8724 | | "xmm8", "xmm9", "xmm10", "xmm11", |
8725 | | "xmm12", "xmm13", "xmm14", "xmm15", |
8726 | | "st0", "st1", "st2", "st3", |
8727 | | "st4", "st5", "st6", "st7", |
8728 | | "mm0", "mm1", "mm2", "mm3", |
8729 | | "mm4", "mm5", "mm6", "mm7", |
8730 | | "rflags", |
8731 | | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, |
8732 | | "fs.base", "gs.base", NULL, NULL, |
8733 | | "tr", "ldtr", |
8734 | | "mxcsr", "fcw", "fsw", |
8735 | | "xmm16", "xmm17", "xmm18", "xmm19", |
8736 | | "xmm20", "xmm21", "xmm22", "xmm23", |
8737 | | "xmm24", "xmm25", "xmm26", "xmm27", |
8738 | | "xmm28", "xmm29", "xmm30", "xmm31", |
8739 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ |
8740 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ |
8741 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ |
8742 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ |
8743 | | NULL, NULL, NULL, /* 115 - 117 */ |
8744 | | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7", |
8745 | | "bnd0", "bnd1", "bnd2", "bnd3", |
8746 | | }; |
8747 | | |
8748 | | static void |
8749 | | init_dwarf_regnames_x86_64 (void) |
8750 | 7.44k | { |
8751 | 7.44k | dwarf_regnames = dwarf_regnames_x86_64; |
8752 | 7.44k | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); |
8753 | 7.44k | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
8754 | 7.44k | } |
8755 | | |
8756 | | static const char *const dwarf_regnames_aarch64[] = |
8757 | | { |
8758 | | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
8759 | | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", |
8760 | | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
8761 | | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", |
8762 | | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, |
8763 | | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
8764 | | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", |
8765 | | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", |
8766 | | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
8767 | | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", |
8768 | | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
8769 | | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", |
8770 | | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
8771 | | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", |
8772 | | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", |
8773 | | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", |
8774 | | }; |
8775 | | |
8776 | | static void |
8777 | | init_dwarf_regnames_aarch64 (void) |
8778 | 4.16k | { |
8779 | 4.16k | dwarf_regnames = dwarf_regnames_aarch64; |
8780 | 4.16k | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); |
8781 | 4.16k | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
8782 | 4.16k | is_aarch64 = true; |
8783 | 4.16k | } |
8784 | | |
8785 | | static const char *const dwarf_regnames_s390[] = |
8786 | | { |
8787 | | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ |
8788 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
8789 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
8790 | | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", |
8791 | | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", |
8792 | | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", |
8793 | | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", |
8794 | | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", |
8795 | | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", |
8796 | | "pswm", "pswa", |
8797 | | NULL, NULL, |
8798 | | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", |
8799 | | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", |
8800 | | }; |
8801 | | |
8802 | | static void |
8803 | | init_dwarf_regnames_s390 (void) |
8804 | 734 | { |
8805 | 734 | dwarf_regnames = dwarf_regnames_s390; |
8806 | 734 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); |
8807 | 734 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
8808 | 734 | } |
8809 | | |
8810 | | static const char *const dwarf_regnames_riscv[] = |
8811 | | { |
8812 | | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ |
8813 | | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ |
8814 | | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ |
8815 | | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ |
8816 | | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ |
8817 | | "fs0", "fs1", /* 40 - 41 */ |
8818 | | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ |
8819 | | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ |
8820 | | "fs10", "fs11", /* 58 - 59 */ |
8821 | | "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */ |
8822 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 64 - 71 */ |
8823 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 72 - 79 */ |
8824 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 80 - 87 */ |
8825 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 88 - 95 */ |
8826 | | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */ |
8827 | | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */ |
8828 | | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */ |
8829 | | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */ |
8830 | | }; |
8831 | | |
8832 | | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
8833 | | the large number of CSRs. */ |
8834 | | |
8835 | | static const char * |
8836 | | regname_internal_riscv (unsigned int regno) |
8837 | 51 | { |
8838 | 51 | const char *name = NULL; |
8839 | | |
8840 | | /* Lookup in the table first, this covers GPR and FPR. */ |
8841 | 51 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) |
8842 | 44 | name = dwarf_regnames_riscv [regno]; |
8843 | 7 | else if (regno >= 4096 && regno <= 8191) |
8844 | 0 | { |
8845 | | /* This might be a CSR, these live in a sparse number space from 4096 |
8846 | | to 8191 These numbers are defined in the RISC-V ELF ABI |
8847 | | document. */ |
8848 | 0 | switch (regno) |
8849 | 0 | { |
8850 | 0 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
8851 | 0 | case VALUE + 4096: name = #NAME; break; |
8852 | 0 | #include "opcode/riscv-opc.h" |
8853 | 0 | #undef DECLARE_CSR |
8854 | | |
8855 | 0 | default: |
8856 | 0 | { |
8857 | 0 | static char csr_name[10]; |
8858 | 0 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); |
8859 | 0 | name = csr_name; |
8860 | 0 | } |
8861 | 0 | break; |
8862 | 0 | } |
8863 | 0 | } |
8864 | | |
8865 | 51 | return name; |
8866 | 51 | } |
8867 | | |
8868 | | static void |
8869 | | init_dwarf_regnames_riscv (void) |
8870 | 709 | { |
8871 | 709 | dwarf_regnames = NULL; |
8872 | 709 | dwarf_regnames_count = 8192; |
8873 | 709 | dwarf_regnames_lookup_func = regname_internal_riscv; |
8874 | 709 | } |
8875 | | |
8876 | | static const char *const dwarf_regnames_loongarch[] = |
8877 | | { |
8878 | | "$zero", "$ra", "$tp", "$sp", "$a0", "$a1", "$a2", "$a3", /* 0-7 */ |
8879 | | "$a4", "$a5", "$a6", "$a7", "$t0", "$t1", "$t2", "$t3", /* 8-15 */ |
8880 | | "$t4", "$t5", "$t6", "$t7", "$t8", "$r21","$fp", "$s0", /* 16-23 */ |
8881 | | "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7", "$s8", /* 24-31 */ |
8882 | | "$fa0", "$fa1", "$fa2", "$fa3", "$fa4", "$fa5", "$fa6", /* 32-38 */ |
8883 | | "$fa7", "$ft0", "$ft1", "$ft2", "$ft3", "$ft4", "$ft5", /* 39-45 */ |
8884 | | "$ft6", "$ft7", "$ft8", "$ft9", "$ft10", "$ft11", "$ft12", /* 46-52 */ |
8885 | | "$ft13", "$ft14", "$ft15", "$fs0", "$fs1", "$fs2", "$fs3", /* 53-59 */ |
8886 | | "$fs4", "$fs5", "$fs6", "$fs7", /* 60-63 */ |
8887 | | }; |
8888 | | |
8889 | | static void |
8890 | | init_dwarf_regnames_loongarch (void) |
8891 | 727 | { |
8892 | 727 | dwarf_regnames = dwarf_regnames_loongarch; |
8893 | 727 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_loongarch); |
8894 | 727 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
8895 | 727 | } |
8896 | | |
8897 | | void |
8898 | | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
8899 | 99.0k | { |
8900 | 99.0k | dwarf_regnames_lookup_func = NULL; |
8901 | 99.0k | is_aarch64 = false; |
8902 | | |
8903 | 99.0k | switch (e_machine) |
8904 | 99.0k | { |
8905 | 513 | case EM_386: |
8906 | 513 | init_dwarf_regnames_i386 (); |
8907 | 513 | break; |
8908 | | |
8909 | 1.65k | case EM_IAMCU: |
8910 | 1.65k | init_dwarf_regnames_iamcu (); |
8911 | 1.65k | break; |
8912 | | |
8913 | 1.11k | case EM_X86_64: |
8914 | 1.65k | case EM_L1OM: |
8915 | 1.99k | case EM_K1OM: |
8916 | 1.99k | init_dwarf_regnames_x86_64 (); |
8917 | 1.99k | break; |
8918 | | |
8919 | 2.11k | case EM_AARCH64: |
8920 | 2.11k | init_dwarf_regnames_aarch64 (); |
8921 | 2.11k | break; |
8922 | | |
8923 | 692 | case EM_S390: |
8924 | 692 | init_dwarf_regnames_s390 (); |
8925 | 692 | break; |
8926 | | |
8927 | 298 | case EM_RISCV: |
8928 | 298 | init_dwarf_regnames_riscv (); |
8929 | 298 | break; |
8930 | | |
8931 | 404 | case EM_LOONGARCH: |
8932 | 404 | init_dwarf_regnames_loongarch (); |
8933 | 404 | break; |
8934 | | |
8935 | 91.4k | default: |
8936 | 91.4k | break; |
8937 | 99.0k | } |
8938 | 99.0k | } |
8939 | | |
8940 | | /* Initialize the DWARF register name lookup state based on the |
8941 | | architecture and specific machine type of a BFD. */ |
8942 | | |
8943 | | void |
8944 | | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, |
8945 | | unsigned long mach) |
8946 | 21.5k | { |
8947 | 21.5k | dwarf_regnames_lookup_func = NULL; |
8948 | 21.5k | is_aarch64 = false; |
8949 | | |
8950 | 21.5k | switch (arch) |
8951 | 21.5k | { |
8952 | 6.78k | case bfd_arch_i386: |
8953 | 6.78k | switch (mach) |
8954 | 6.78k | { |
8955 | 5.43k | case bfd_mach_x86_64: |
8956 | 5.43k | case bfd_mach_x86_64_intel_syntax: |
8957 | 5.44k | case bfd_mach_x64_32: |
8958 | 5.44k | case bfd_mach_x64_32_intel_syntax: |
8959 | 5.44k | init_dwarf_regnames_x86_64 (); |
8960 | 5.44k | break; |
8961 | | |
8962 | 1.33k | default: |
8963 | 1.33k | init_dwarf_regnames_i386 (); |
8964 | 1.33k | break; |
8965 | 6.78k | } |
8966 | 6.78k | break; |
8967 | | |
8968 | 6.78k | case bfd_arch_iamcu: |
8969 | 1 | init_dwarf_regnames_iamcu (); |
8970 | 1 | break; |
8971 | | |
8972 | 2.04k | case bfd_arch_aarch64: |
8973 | 2.04k | init_dwarf_regnames_aarch64(); |
8974 | 2.04k | break; |
8975 | | |
8976 | 42 | case bfd_arch_s390: |
8977 | 42 | init_dwarf_regnames_s390 (); |
8978 | 42 | break; |
8979 | | |
8980 | 411 | case bfd_arch_riscv: |
8981 | 411 | init_dwarf_regnames_riscv (); |
8982 | 411 | break; |
8983 | | |
8984 | 323 | case bfd_arch_loongarch: |
8985 | 323 | init_dwarf_regnames_loongarch (); |
8986 | 323 | break; |
8987 | | |
8988 | 11.8k | default: |
8989 | 11.8k | break; |
8990 | 21.5k | } |
8991 | 21.5k | } |
8992 | | |
8993 | | static const char * |
8994 | | regname_internal_by_table_only (unsigned int regno) |
8995 | 643k | { |
8996 | 643k | if (dwarf_regnames != NULL |
8997 | 643k | && regno < dwarf_regnames_count |
8998 | 643k | && dwarf_regnames [regno] != NULL) |
8999 | 231k | return dwarf_regnames [regno]; |
9000 | | |
9001 | 411k | return NULL; |
9002 | 643k | } |
9003 | | |
9004 | | static const char * |
9005 | | regname (unsigned int regno, int name_only_p) |
9006 | 876k | { |
9007 | 876k | static char reg[64]; |
9008 | | |
9009 | 876k | const char *name = NULL; |
9010 | | |
9011 | 876k | if (dwarf_regnames_lookup_func != NULL) |
9012 | 643k | name = dwarf_regnames_lookup_func (regno); |
9013 | | |
9014 | 876k | if (name != NULL) |
9015 | 231k | { |
9016 | 231k | if (name_only_p) |
9017 | 7.19k | return name; |
9018 | 224k | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); |
9019 | 224k | } |
9020 | 645k | else |
9021 | 645k | snprintf (reg, sizeof (reg), "r%d", regno); |
9022 | 869k | return reg; |
9023 | 876k | } |
9024 | | |
9025 | | static void |
9026 | | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
9027 | 0 | { |
9028 | 0 | unsigned int r; |
9029 | 0 | char tmp[100]; |
9030 | |
|
9031 | 0 | if (*max_regs != fc->ncols) |
9032 | 0 | *max_regs = fc->ncols; |
9033 | |
|
9034 | 0 | if (*need_col_headers) |
9035 | 0 | { |
9036 | 0 | *need_col_headers = 0; |
9037 | |
|
9038 | 0 | printf ("%-*s CFA ", eh_addr_size * 2, " LOC"); |
9039 | |
|
9040 | 0 | for (r = 0; r < *max_regs; r++) |
9041 | 0 | if (fc->col_type[r] != DW_CFA_unreferenced) |
9042 | 0 | { |
9043 | 0 | if (r == fc->ra) |
9044 | 0 | printf ("ra "); |
9045 | 0 | else |
9046 | 0 | printf ("%-5s ", regname (r, 1)); |
9047 | 0 | } |
9048 | |
|
9049 | 0 | printf ("\n"); |
9050 | 0 | } |
9051 | |
|
9052 | 0 | print_hex (fc->pc_begin, eh_addr_size); |
9053 | 0 | if (fc->cfa_exp) |
9054 | 0 | strcpy (tmp, "exp"); |
9055 | 0 | else |
9056 | 0 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
9057 | 0 | printf ("%-8s ", tmp); |
9058 | |
|
9059 | 0 | for (r = 0; r < fc->ncols; r++) |
9060 | 0 | { |
9061 | 0 | if (fc->col_type[r] != DW_CFA_unreferenced) |
9062 | 0 | { |
9063 | 0 | switch (fc->col_type[r]) |
9064 | 0 | { |
9065 | 0 | case DW_CFA_undefined: |
9066 | 0 | strcpy (tmp, "u"); |
9067 | 0 | break; |
9068 | 0 | case DW_CFA_same_value: |
9069 | 0 | strcpy (tmp, "s"); |
9070 | 0 | break; |
9071 | 0 | case DW_CFA_offset: |
9072 | 0 | sprintf (tmp, "c%+" PRId64, fc->col_offset[r]); |
9073 | 0 | break; |
9074 | 0 | case DW_CFA_val_offset: |
9075 | 0 | sprintf (tmp, "v%+" PRId64, fc->col_offset[r]); |
9076 | 0 | break; |
9077 | 0 | case DW_CFA_register: |
9078 | 0 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
9079 | 0 | break; |
9080 | 0 | case DW_CFA_expression: |
9081 | 0 | strcpy (tmp, "exp"); |
9082 | 0 | break; |
9083 | 0 | case DW_CFA_val_expression: |
9084 | 0 | strcpy (tmp, "vexp"); |
9085 | 0 | break; |
9086 | 0 | default: |
9087 | 0 | strcpy (tmp, "n/a"); |
9088 | 0 | break; |
9089 | 0 | } |
9090 | 0 | printf ("%-5s ", tmp); |
9091 | 0 | } |
9092 | 0 | } |
9093 | 0 | printf ("\n"); |
9094 | 0 | } |
9095 | | |
9096 | 7.15k | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
9097 | | |
9098 | | static unsigned char * |
9099 | | read_cie (unsigned char *start, unsigned char *end, |
9100 | | Frame_Chunk **p_cie, int *p_version, |
9101 | | uint64_t *p_aug_len, unsigned char **p_aug) |
9102 | 7.64k | { |
9103 | 7.64k | int version; |
9104 | 7.64k | Frame_Chunk *fc; |
9105 | 7.64k | unsigned char *augmentation_data = NULL; |
9106 | 7.64k | uint64_t augmentation_data_len = 0; |
9107 | | |
9108 | 7.64k | * p_cie = NULL; |
9109 | | /* PR 17512: file: 001-228113-0.004. */ |
9110 | 7.64k | if (start >= end) |
9111 | 50 | return end; |
9112 | | |
9113 | 7.59k | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
9114 | 7.59k | memset (fc, 0, sizeof (Frame_Chunk)); |
9115 | | |
9116 | 7.59k | fc->col_type = xmalloc (sizeof (*fc->col_type)); |
9117 | 7.59k | fc->col_offset = xmalloc (sizeof (*fc->col_offset)); |
9118 | | |
9119 | 7.59k | version = *start++; |
9120 | | |
9121 | 7.59k | fc->augmentation = (char *) start; |
9122 | | /* PR 17512: file: 001-228113-0.004. |
9123 | | Skip past augmentation name, but avoid running off the end of the data. */ |
9124 | 16.4k | while (start < end) |
9125 | 16.4k | if (* start ++ == '\0') |
9126 | 7.58k | break; |
9127 | 7.59k | if (start == end) |
9128 | 15 | { |
9129 | 15 | warn (_("No terminator for augmentation name\n")); |
9130 | 15 | goto fail; |
9131 | 15 | } |
9132 | | |
9133 | 7.58k | if (strcmp (fc->augmentation, "eh") == 0) |
9134 | 1 | { |
9135 | 1 | if (eh_addr_size > (size_t) (end - start)) |
9136 | 0 | goto fail; |
9137 | 1 | start += eh_addr_size; |
9138 | 1 | } |
9139 | | |
9140 | 7.58k | if (version >= 4) |
9141 | 176 | { |
9142 | 176 | if (2 > (size_t) (end - start)) |
9143 | 8 | goto fail; |
9144 | 168 | GET (fc->ptr_size, 1); |
9145 | 168 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
9146 | 52 | { |
9147 | 52 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); |
9148 | 52 | goto fail; |
9149 | 52 | } |
9150 | | |
9151 | 116 | GET (fc->segment_size, 1); |
9152 | | /* PR 17512: file: e99d2804. */ |
9153 | 116 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) |
9154 | 6 | { |
9155 | 6 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); |
9156 | 6 | goto fail; |
9157 | 6 | } |
9158 | | |
9159 | 110 | eh_addr_size = fc->ptr_size; |
9160 | 110 | } |
9161 | 7.40k | else |
9162 | 7.40k | { |
9163 | 7.40k | fc->ptr_size = eh_addr_size; |
9164 | 7.40k | fc->segment_size = 0; |
9165 | 7.40k | } |
9166 | | |
9167 | 7.51k | READ_ULEB (fc->code_factor, start, end); |
9168 | 7.51k | READ_SLEB (fc->data_factor, start, end); |
9169 | | |
9170 | 7.51k | if (start >= end) |
9171 | 14 | goto fail; |
9172 | | |
9173 | 7.50k | if (version == 1) |
9174 | 6.86k | { |
9175 | 6.86k | GET (fc->ra, 1); |
9176 | 6.86k | } |
9177 | 632 | else |
9178 | 632 | { |
9179 | 632 | READ_ULEB (fc->ra, start, end); |
9180 | 632 | } |
9181 | | |
9182 | 7.50k | if (fc->augmentation[0] == 'z') |
9183 | 1.93k | { |
9184 | 1.93k | if (start >= end) |
9185 | 0 | goto fail; |
9186 | 1.93k | READ_ULEB (augmentation_data_len, start, end); |
9187 | 1.93k | augmentation_data = start; |
9188 | | /* PR 17512: file: 11042-2589-0.004. */ |
9189 | 1.93k | if (augmentation_data_len > (size_t) (end - start)) |
9190 | 16 | { |
9191 | 16 | warn (_("Augmentation data too long: %#" PRIx64 |
9192 | 16 | ", expected at most %#tx\n"), |
9193 | 16 | augmentation_data_len, end - start); |
9194 | 16 | goto fail; |
9195 | 16 | } |
9196 | 1.91k | start += augmentation_data_len; |
9197 | 1.91k | } |
9198 | | |
9199 | 7.48k | if (augmentation_data_len) |
9200 | 1.89k | { |
9201 | 1.89k | unsigned char *p; |
9202 | 1.89k | unsigned char *q; |
9203 | 1.89k | unsigned char *qend; |
9204 | | |
9205 | 1.89k | p = (unsigned char *) fc->augmentation + 1; |
9206 | 1.89k | q = augmentation_data; |
9207 | 1.89k | qend = q + augmentation_data_len; |
9208 | | |
9209 | 3.79k | while (p < end && q < qend) |
9210 | 1.91k | { |
9211 | 1.91k | if (*p == 'L') |
9212 | 10 | q++; |
9213 | 1.90k | else if (*p == 'P') |
9214 | 10 | q += 1 + size_of_encoded_value (*q); |
9215 | 1.89k | else if (*p == 'R') |
9216 | 1.87k | fc->fde_encoding = *q++; |
9217 | 21 | else if (*p == 'S') |
9218 | 0 | ; |
9219 | 21 | else if (*p == 'B') |
9220 | 0 | ; |
9221 | 21 | else |
9222 | 21 | break; |
9223 | 1.89k | p++; |
9224 | 1.89k | } |
9225 | | /* Note - it is OK if this loop terminates with q < qend. |
9226 | | Padding may have been inserted to align the end of the CIE. */ |
9227 | 1.89k | } |
9228 | | |
9229 | 7.48k | *p_cie = fc; |
9230 | 7.48k | if (p_version) |
9231 | 7.48k | *p_version = version; |
9232 | 7.48k | if (p_aug_len) |
9233 | 7.48k | { |
9234 | 7.48k | *p_aug_len = augmentation_data_len; |
9235 | 7.48k | *p_aug = augmentation_data; |
9236 | 7.48k | } |
9237 | 7.48k | return start; |
9238 | | |
9239 | 111 | fail: |
9240 | 111 | free (fc->col_offset); |
9241 | 111 | free (fc->col_type); |
9242 | 111 | free (fc); |
9243 | 111 | return end; |
9244 | 7.50k | } |
9245 | | |
9246 | | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
9247 | | If do_wide is not enabled, then formats the output to fit into 80 columns. |
9248 | | PRINTED contains the number of characters already written to the current |
9249 | | output line. */ |
9250 | | |
9251 | | static void |
9252 | | display_data (size_t printed, const unsigned char *data, size_t len) |
9253 | 3.87k | { |
9254 | 3.87k | if (do_wide || len < ((80 - printed) / 3)) |
9255 | 13.8k | for (printed = 0; printed < len; ++printed) |
9256 | 10.0k | printf (" %02x", data[printed]); |
9257 | 21 | else |
9258 | 21 | { |
9259 | 1.38k | for (printed = 0; printed < len; ++printed) |
9260 | 1.36k | { |
9261 | 1.36k | if (printed % (80 / 3) == 0) |
9262 | 60 | putchar ('\n'); |
9263 | 1.36k | printf (" %02x", data[printed]); |
9264 | 1.36k | } |
9265 | 21 | } |
9266 | 3.87k | } |
9267 | | |
9268 | | /* Prints out the contents on the augmentation data array. |
9269 | | If do_wide is not enabled, then formats the output to fit into 80 columns. */ |
9270 | | |
9271 | | static void |
9272 | | display_augmentation_data (const unsigned char * data, uint64_t len) |
9273 | 3.87k | { |
9274 | 3.87k | size_t i; |
9275 | | |
9276 | 3.87k | i = printf (_(" Augmentation data: ")); |
9277 | 3.87k | display_data (i, data, len); |
9278 | 3.87k | } |
9279 | | |
9280 | | static const char * |
9281 | | decode_eh_encoding (unsigned int value) |
9282 | 1.01k | { |
9283 | 1.01k | if (value == DW_EH_PE_omit) |
9284 | 3 | return "omit"; |
9285 | | |
9286 | 1.01k | char * format; |
9287 | 1.01k | switch (value & 0x0f) |
9288 | 1.01k | { |
9289 | 5 | case DW_EH_PE_uleb128: format = "uleb128"; break; |
9290 | 4 | case DW_EH_PE_udata2: format = "udata2"; break; |
9291 | 329 | case DW_EH_PE_udata4: format = "udata4"; break; |
9292 | 6 | case DW_EH_PE_udata8: format = "udata8"; break; |
9293 | 1 | case DW_EH_PE_sleb128: format = "sleb128"; break; |
9294 | 4 | case DW_EH_PE_sdata2: format = "sdata2"; break; |
9295 | 652 | case DW_EH_PE_sdata4: format = "sdata4"; break; |
9296 | 2 | case DW_EH_PE_sdata8: format = "sdata8"; break; |
9297 | | |
9298 | 11 | default: format = "<unknown format>"; break; /* FIXME: Generate a warning ? */ |
9299 | 1.01k | } |
9300 | | |
9301 | 1.01k | char * application; |
9302 | 1.01k | switch (value & 0xf0) |
9303 | 1.01k | { |
9304 | 347 | case DW_EH_PE_absptr: application = "absolute"; break; |
9305 | 327 | case DW_EH_PE_pcrel: application = "pcrel"; break; |
9306 | 2 | case DW_EH_PE_textrel: application = "textrel"; break; /* FIXME: Is this allowed ? */ |
9307 | 329 | case DW_EH_PE_datarel: application = "datarel"; break; |
9308 | 0 | case DW_EH_PE_funcrel: application = "funcrel"; break; /* FIXME: Is this allowed ? */ |
9309 | 1 | case DW_EH_PE_aligned: application = "aligned"; break; /* FIXME: Is this allowed ? */ |
9310 | 0 | case DW_EH_PE_indirect: application = "indirect"; break; /* FIXME: Is this allowed ? */ |
9311 | | |
9312 | 8 | default: application = "<unknown application method>"; break; /* FIXME: Generate a warning ? */ |
9313 | 1.01k | } |
9314 | | |
9315 | 1.01k | static char buffer[128]; |
9316 | 1.01k | sprintf (buffer, "%s, %s", format, application); |
9317 | 1.01k | return buffer; |
9318 | 1.01k | } |
9319 | | |
9320 | | /* Reads a value stored at START encoded according to ENCODING. |
9321 | | Does not read from, or past, END. |
9322 | | Upon success, returns the read value and sets * RETURN_LEN to |
9323 | | the number of bytes read. |
9324 | | Upon failure returns zero and sets * RETURN_LEN to 0. |
9325 | | |
9326 | | Note: does not perform any application transformations to the value. */ |
9327 | | |
9328 | | static uint64_t |
9329 | | get_encoded_eh_value (unsigned int encoding, |
9330 | | unsigned char * start, |
9331 | | unsigned char * end, |
9332 | | unsigned int * return_len) |
9333 | 84.1k | { |
9334 | 84.1k | uint64_t val; |
9335 | 84.1k | unsigned int len; |
9336 | 84.1k | int status; |
9337 | 84.1k | unsigned char * old_start; |
9338 | | |
9339 | 84.1k | switch (encoding & 0x0f) |
9340 | 84.1k | { |
9341 | 4 | case DW_EH_PE_uleb128: |
9342 | 4 | val = read_leb128 (start, end, false, & len, & status); |
9343 | 4 | if (status != 0) |
9344 | 0 | len = 0; |
9345 | 4 | break; |
9346 | | |
9347 | 1 | case DW_EH_PE_sleb128: |
9348 | 1 | val = read_leb128 (start, end, true, & len, & status); |
9349 | 1 | if (status != 0) |
9350 | 0 | len = 0; |
9351 | 1 | break; |
9352 | | |
9353 | 14 | case DW_EH_PE_udata2: |
9354 | 14 | old_start = start; |
9355 | 14 | SAFE_BYTE_GET_AND_INC (val, start, 2, end); |
9356 | 14 | len = start - old_start == 2 ? 2 : 0; |
9357 | 14 | break; |
9358 | | |
9359 | 328 | case DW_EH_PE_udata4: |
9360 | 328 | old_start = start; |
9361 | 328 | SAFE_BYTE_GET_AND_INC (val, start, 4, end); |
9362 | 328 | len = start - old_start == 4 ? 4 : 0; |
9363 | 328 | break; |
9364 | | |
9365 | 133 | case DW_EH_PE_udata8: |
9366 | 133 | old_start = start; |
9367 | 133 | SAFE_BYTE_GET_AND_INC (val, start, 8, end); |
9368 | 133 | len = start - old_start == 8 ? 8 : 0; |
9369 | 133 | break; |
9370 | | |
9371 | 3 | case DW_EH_PE_sdata2: |
9372 | 3 | old_start = start; |
9373 | 3 | SAFE_SIGNED_BYTE_GET_AND_INC (val, start, 2, end); |
9374 | 3 | len = start - old_start == 2 ? 2 : 0; |
9375 | 3 | break; |
9376 | | |
9377 | 83.6k | case DW_EH_PE_sdata4: |
9378 | 83.6k | old_start = start; |
9379 | 83.6k | SAFE_SIGNED_BYTE_GET_AND_INC (val, start, 4, end); |
9380 | 83.6k | len = start - old_start == 4 ? 4 : 0; |
9381 | 83.6k | break; |
9382 | | |
9383 | 1 | case DW_EH_PE_sdata8: |
9384 | 1 | old_start = start; |
9385 | 1 | SAFE_SIGNED_BYTE_GET_AND_INC (val, start, 8, end); |
9386 | 1 | len = start - old_start == 8 ? 8 : 0; |
9387 | 1 | break; |
9388 | | |
9389 | 6 | default: |
9390 | 6 | goto fail; |
9391 | 84.1k | } |
9392 | | |
9393 | 84.1k | * return_len = len; |
9394 | 84.1k | return val; |
9395 | | |
9396 | 6 | fail: |
9397 | 6 | * return_len = 0; |
9398 | 6 | return 0; |
9399 | 84.1k | } |
9400 | | |
9401 | | static uint64_t |
9402 | | encoded_eh_offset (unsigned int encoding, |
9403 | | struct dwarf_section * section, |
9404 | | uint64_t section_offset, |
9405 | | uint64_t value) |
9406 | 83.7k | { |
9407 | 83.7k | switch (encoding & 0xf0) |
9408 | 83.7k | { |
9409 | 133 | default: |
9410 | | /* This should not happen. FIXME: warn ? */ |
9411 | 138 | case DW_EH_PE_absptr: |
9412 | 138 | return value; |
9413 | | |
9414 | 326 | case DW_EH_PE_pcrel: |
9415 | 326 | return value + (uint64_t)(section->address + section_offset); |
9416 | | |
9417 | 83.3k | case DW_EH_PE_datarel: |
9418 | 83.3k | return value + (uint64_t)section->address; |
9419 | 83.7k | } |
9420 | 83.7k | } |
9421 | | |
9422 | | static int |
9423 | | display_eh_frame_hdr (struct dwarf_section *section, |
9424 | | void *file ATTRIBUTE_UNUSED) |
9425 | 429 | { |
9426 | 429 | unsigned char *start = section->start; |
9427 | 429 | unsigned char *end = start + section->size; |
9428 | | |
9429 | 429 | introduce (section, false); |
9430 | | |
9431 | 429 | if (section->size < 6) |
9432 | 2 | { |
9433 | 2 | warn (_(".eh_frame_hdr section is too small\n")); |
9434 | 2 | return 0; |
9435 | 2 | } |
9436 | | |
9437 | 427 | unsigned int version = start[0]; |
9438 | 427 | if (version != 1) |
9439 | 88 | { |
9440 | 88 | warn (_("Unsupported .eh_frame_hdr version %u\n"), version); |
9441 | 88 | return 0; |
9442 | 88 | } |
9443 | | |
9444 | 339 | printf (_(" Version: %u\n"), version); |
9445 | | |
9446 | 339 | unsigned int ptr_enc = start[1]; |
9447 | | /* Strictly speaking this is the encoding format of the eh_frame_ptr field below. */ |
9448 | 339 | printf (_(" Pointer Encoding Format: %#x (%s)\n"), ptr_enc, decode_eh_encoding (ptr_enc)); |
9449 | | |
9450 | 339 | unsigned int count_enc = start[2]; |
9451 | 339 | printf (_(" Count Encoding Format: %#x (%s)\n"), count_enc, decode_eh_encoding (count_enc)); |
9452 | | |
9453 | 339 | unsigned int table_enc = start[3]; |
9454 | 339 | printf (_(" Table Encoding Format: %#x (%s)\n"), table_enc, decode_eh_encoding (table_enc)); |
9455 | | |
9456 | 339 | start += 4; |
9457 | | |
9458 | 339 | unsigned int len; |
9459 | | |
9460 | 339 | uint64_t eh_frame_ptr = get_encoded_eh_value (ptr_enc, start, end, & len); |
9461 | 339 | if (len == 0) |
9462 | 4 | { |
9463 | 4 | warn (_("unable to read eh_frame_ptr field in .eh_frame_hdr section\n")); |
9464 | 4 | return 0; |
9465 | 4 | } |
9466 | 335 | printf (_(" Start of frame section: %#" PRIx64), eh_frame_ptr); |
9467 | | |
9468 | 335 | uint64_t offset_eh_frame_ptr = encoded_eh_offset (ptr_enc, section, 4, eh_frame_ptr); |
9469 | 335 | if (offset_eh_frame_ptr != eh_frame_ptr) |
9470 | 327 | printf (_(" (offset: %#" PRIx64 ")"), offset_eh_frame_ptr); |
9471 | | |
9472 | 335 | printf ("\n"); |
9473 | 335 | start += len; |
9474 | | |
9475 | 335 | if (count_enc == DW_EH_PE_omit) |
9476 | 1 | { |
9477 | 1 | warn (_("It is suspicious to have a .eh_frame_hdr section with an empty search table\n")); |
9478 | 1 | return 0; |
9479 | 1 | } |
9480 | | |
9481 | 334 | if (count_enc & 0xf0) |
9482 | 3 | { |
9483 | 3 | warn (_("The count field format should be absolute, not relative to an address\n")); |
9484 | 3 | return 0; |
9485 | 3 | } |
9486 | | |
9487 | 331 | uint64_t fde_count = get_encoded_eh_value (count_enc, start, end, & len); |
9488 | 331 | if (len == 0) |
9489 | 1 | { |
9490 | 1 | warn (_("unable to read fde_count field in .eh_frame_hdr section\n")); |
9491 | 1 | return 0; |
9492 | 1 | } |
9493 | 330 | printf (_(" Entries in search table: %#" PRIx64), fde_count); |
9494 | 330 | printf ("\n"); |
9495 | 330 | start += len; |
9496 | | |
9497 | 330 | if (fde_count != 0 && table_enc == DW_EH_PE_omit) |
9498 | 0 | { |
9499 | 0 | warn (_("It is suspicious to have a .eh_frame_hdr section an empty table but a non empty count field\n")); |
9500 | 0 | return 0; |
9501 | 0 | } |
9502 | | |
9503 | 330 | uint64_t i; |
9504 | | /* Read and display the search table. */ |
9505 | 42.0k | for (i = 0; i < fde_count; i++) |
9506 | 41.7k | { |
9507 | 41.7k | uint64_t location, address; |
9508 | 41.7k | unsigned char * row_start = start; |
9509 | | |
9510 | 41.7k | location = get_encoded_eh_value (table_enc, start, end, & len); |
9511 | 41.7k | if (len == 0) |
9512 | 9 | { |
9513 | 9 | warn (_("Failed to read location field for entry %#" PRIx64 " in the .eh_frame_hdr's search table\n"), i); |
9514 | 9 | return 0; |
9515 | 9 | } |
9516 | 41.7k | start += len; |
9517 | | |
9518 | 41.7k | address = get_encoded_eh_value (table_enc, start, end, & len); |
9519 | 41.7k | if (len == 0) |
9520 | 5 | { |
9521 | 5 | warn (_("Failed to read address field for entry %#" PRIx64 " in the .eh_frame_hdr's search table\n"), i); |
9522 | 5 | return 0; |
9523 | 5 | } |
9524 | 41.7k | start += len; |
9525 | | |
9526 | | /* This format is intended to be compatible with the output of eu-readelf's -e option. */ |
9527 | 41.7k | printf (" %#" PRIx64 " (offset: %#" PRIx64 ") -> %#" PRIx64 " fde=[ %5" PRIx64 "]\n", |
9528 | 41.7k | location, |
9529 | 41.7k | encoded_eh_offset (table_enc, section, row_start - section->start, location), |
9530 | 41.7k | address, |
9531 | 41.7k | encoded_eh_offset (table_enc, section, row_start - section->start, address) - offset_eh_frame_ptr); |
9532 | 41.7k | } |
9533 | | |
9534 | 316 | printf ("\n"); |
9535 | 316 | return 1; |
9536 | 330 | } |
9537 | | |
9538 | | static int |
9539 | | display_debug_frames (struct dwarf_section *section, |
9540 | | void *file ATTRIBUTE_UNUSED) |
9541 | 4.99k | { |
9542 | 4.99k | unsigned char *start = section->start; |
9543 | 4.99k | unsigned char *end = start + section->size; |
9544 | 4.99k | unsigned char *section_start = start; |
9545 | 4.99k | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
9546 | 4.99k | Frame_Chunk *remembered_state = NULL; |
9547 | 4.99k | Frame_Chunk *rs; |
9548 | 4.99k | bool is_eh = strcmp (section->name, ".eh_frame") == 0; |
9549 | 4.99k | unsigned int max_regs = 0; |
9550 | 4.99k | const char *bad_reg = _("bad register: "); |
9551 | 4.99k | unsigned int saved_eh_addr_size = eh_addr_size; |
9552 | | |
9553 | 4.99k | introduce (section, false); |
9554 | | |
9555 | 105k | while (start < end) |
9556 | 100k | { |
9557 | 100k | unsigned char *saved_start; |
9558 | 100k | unsigned char *block_end; |
9559 | 100k | uint64_t length; |
9560 | 100k | uint64_t cie_id; |
9561 | 100k | Frame_Chunk *fc; |
9562 | 100k | Frame_Chunk *cie; |
9563 | 100k | int need_col_headers = 1; |
9564 | 100k | unsigned char *augmentation_data = NULL; |
9565 | 100k | uint64_t augmentation_data_len = 0; |
9566 | 100k | unsigned int encoded_ptr_size = saved_eh_addr_size; |
9567 | 100k | unsigned int offset_size; |
9568 | 100k | bool all_nops; |
9569 | 100k | static Frame_Chunk fde_fc; |
9570 | | |
9571 | 100k | saved_start = start; |
9572 | | |
9573 | 100k | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
9574 | | |
9575 | 100k | if (length == 0) |
9576 | 1.58k | { |
9577 | 1.58k | printf ("\n%08tx ZERO terminator\n\n", |
9578 | 1.58k | saved_start - section_start); |
9579 | | /* Skip any zero terminators that directly follow. |
9580 | | A corrupt section size could have loaded a whole |
9581 | | slew of zero filled memory bytes. eg |
9582 | | PR 17512: file: 070-19381-0.004. */ |
9583 | 71.5k | while (start < end && * start == 0) |
9584 | 69.9k | ++ start; |
9585 | 1.58k | continue; |
9586 | 1.58k | } |
9587 | | |
9588 | 98.6k | if (length == 0xffffffff) |
9589 | 183 | { |
9590 | 183 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
9591 | 183 | offset_size = 8; |
9592 | 183 | } |
9593 | 98.4k | else |
9594 | 98.4k | offset_size = 4; |
9595 | | |
9596 | 98.6k | if (length > (size_t) (end - start)) |
9597 | 3.63k | { |
9598 | 3.63k | warn ("Invalid length %#" PRIx64 " in FDE at %#tx\n", |
9599 | 3.63k | length, saved_start - section_start); |
9600 | 3.63k | block_end = end; |
9601 | 3.63k | } |
9602 | 95.0k | else |
9603 | 95.0k | block_end = start + length; |
9604 | | |
9605 | 98.6k | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, block_end); |
9606 | | |
9607 | 98.6k | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
9608 | 26.6k | || (offset_size == 8 && cie_id == DW64_CIE_ID))) |
9609 | 7.62k | { |
9610 | 7.62k | int version; |
9611 | 7.62k | unsigned int mreg; |
9612 | | |
9613 | 7.62k | start = read_cie (start, block_end, &cie, &version, |
9614 | 7.62k | &augmentation_data_len, &augmentation_data); |
9615 | | /* PR 17512: file: 027-135133-0.005. */ |
9616 | 7.62k | if (cie == NULL) |
9617 | 151 | break; |
9618 | | |
9619 | 7.47k | fc = cie; |
9620 | 7.47k | fc->next = chunks; |
9621 | 7.47k | chunks = fc; |
9622 | 7.47k | fc->chunk_start = saved_start; |
9623 | 7.47k | mreg = max_regs > 0 ? max_regs - 1 : 0; |
9624 | 7.47k | if (mreg < fc->ra) |
9625 | 7.29k | mreg = fc->ra; |
9626 | 7.47k | if (frame_need_space (fc, mreg) < 0) |
9627 | 32 | break; |
9628 | 7.44k | if (fc->fde_encoding) |
9629 | 1.87k | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); |
9630 | | |
9631 | 7.44k | printf ("\n%08tx ", saved_start - section_start); |
9632 | 7.44k | print_hex (length, fc->ptr_size); |
9633 | 7.44k | print_hex (cie_id, offset_size); |
9634 | | |
9635 | 7.44k | if (do_debug_frames_interp) |
9636 | 0 | { |
9637 | 0 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, |
9638 | 0 | fc->code_factor, fc->data_factor, fc->ra); |
9639 | 0 | } |
9640 | 7.44k | else |
9641 | 7.44k | { |
9642 | 7.44k | printf ("CIE\n"); |
9643 | 7.44k | printf (" Version: %d\n", version); |
9644 | 7.44k | printf (" Augmentation: \"%s\"\n", fc->augmentation); |
9645 | 7.44k | if (version >= 4) |
9646 | 82 | { |
9647 | 82 | printf (" Pointer Size: %u\n", fc->ptr_size); |
9648 | 82 | printf (" Segment Size: %u\n", fc->segment_size); |
9649 | 82 | } |
9650 | 7.44k | printf (" Code alignment factor: %u\n", fc->code_factor); |
9651 | 7.44k | printf (" Data alignment factor: %d\n", fc->data_factor); |
9652 | 7.44k | printf (" Return address column: %d\n", fc->ra); |
9653 | | |
9654 | 7.44k | if (augmentation_data_len) |
9655 | 1.89k | display_augmentation_data (augmentation_data, augmentation_data_len); |
9656 | | |
9657 | 7.44k | putchar ('\n'); |
9658 | 7.44k | } |
9659 | 7.44k | } |
9660 | 91.0k | else |
9661 | 91.0k | { |
9662 | 91.0k | unsigned char *look_for; |
9663 | 91.0k | unsigned long segment_selector; |
9664 | 91.0k | uint64_t cie_off; |
9665 | | |
9666 | 91.0k | cie_off = cie_id; |
9667 | 91.0k | if (is_eh) |
9668 | 68.6k | { |
9669 | 68.6k | uint64_t sign = (uint64_t) 1 << (offset_size * 8 - 1); |
9670 | 68.6k | cie_off = (cie_off ^ sign) - sign; |
9671 | 68.6k | cie_off = start - 4 - section_start - cie_off; |
9672 | 68.6k | } |
9673 | | |
9674 | 91.0k | look_for = section_start + cie_off; |
9675 | 91.0k | if (cie_off <= (size_t) (saved_start - section_start)) |
9676 | 86.3k | { |
9677 | 94.3k | for (cie = chunks; cie ; cie = cie->next) |
9678 | 93.5k | if (cie->chunk_start == look_for) |
9679 | 85.5k | break; |
9680 | 86.3k | } |
9681 | 4.61k | else if (cie_off >= section->size) |
9682 | 4.22k | cie = NULL; |
9683 | 386 | else |
9684 | 386 | { |
9685 | 387 | for (cie = forward_refs; cie ; cie = cie->next) |
9686 | 1 | if (cie->chunk_start == look_for) |
9687 | 0 | break; |
9688 | 386 | if (!cie) |
9689 | 386 | { |
9690 | 386 | unsigned int off_size; |
9691 | 386 | unsigned char *cie_scan; |
9692 | | |
9693 | 386 | cie_scan = look_for; |
9694 | 386 | off_size = 4; |
9695 | 386 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); |
9696 | 386 | if (length == 0xffffffff) |
9697 | 44 | { |
9698 | 44 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); |
9699 | 44 | off_size = 8; |
9700 | 44 | } |
9701 | 386 | if (length != 0 && length <= (size_t) (end - cie_scan)) |
9702 | 47 | { |
9703 | 47 | uint64_t c_id; |
9704 | 47 | unsigned char *cie_end = cie_scan + length; |
9705 | | |
9706 | 47 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, |
9707 | 47 | cie_end); |
9708 | 47 | if (is_eh |
9709 | 47 | ? c_id == 0 |
9710 | 47 | : ((off_size == 4 && c_id == DW_CIE_ID) |
9711 | 30 | || (off_size == 8 && c_id == DW64_CIE_ID))) |
9712 | 19 | { |
9713 | 19 | int version; |
9714 | 19 | unsigned int mreg; |
9715 | | |
9716 | 19 | read_cie (cie_scan, cie_end, &cie, &version, |
9717 | 19 | &augmentation_data_len, &augmentation_data); |
9718 | | /* PR 17512: file: 3450-2098-0.004. */ |
9719 | 19 | if (cie == NULL) |
9720 | 10 | { |
9721 | 10 | warn (_("Failed to read CIE information\n")); |
9722 | 10 | break; |
9723 | 10 | } |
9724 | 9 | cie->next = forward_refs; |
9725 | 9 | forward_refs = cie; |
9726 | 9 | cie->chunk_start = look_for; |
9727 | 9 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
9728 | 9 | if (mreg < cie->ra) |
9729 | 3 | mreg = cie->ra; |
9730 | 9 | if (frame_need_space (cie, mreg) < 0) |
9731 | 1 | { |
9732 | 1 | warn (_("Invalid max register\n")); |
9733 | 1 | break; |
9734 | 1 | } |
9735 | 8 | if (cie->fde_encoding) |
9736 | 0 | encoded_ptr_size |
9737 | 0 | = size_of_encoded_value (cie->fde_encoding); |
9738 | 8 | } |
9739 | 47 | } |
9740 | 386 | } |
9741 | 386 | } |
9742 | | |
9743 | 90.9k | fc = &fde_fc; |
9744 | 90.9k | memset (fc, 0, sizeof (Frame_Chunk)); |
9745 | | |
9746 | 90.9k | if (!cie) |
9747 | 5.41k | { |
9748 | 5.41k | fc->ncols = 0; |
9749 | 5.41k | fc->col_type = xmalloc (sizeof (*fc->col_type)); |
9750 | 5.41k | fc->col_offset = xmalloc (sizeof (*fc->col_offset)); |
9751 | 5.41k | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
9752 | 0 | { |
9753 | 0 | warn (_("Invalid max register\n")); |
9754 | 0 | break; |
9755 | 0 | } |
9756 | 5.41k | cie = fc; |
9757 | 5.41k | fc->augmentation = ""; |
9758 | 5.41k | fc->fde_encoding = 0; |
9759 | 5.41k | fc->ptr_size = eh_addr_size; |
9760 | 5.41k | fc->segment_size = 0; |
9761 | 5.41k | } |
9762 | 85.5k | else |
9763 | 85.5k | { |
9764 | 85.5k | fc->ncols = cie->ncols; |
9765 | 85.5k | fc->col_type = xcmalloc (fc->ncols, sizeof (*fc->col_type)); |
9766 | 85.5k | fc->col_offset = xcmalloc (fc->ncols, sizeof (*fc->col_offset)); |
9767 | 85.5k | memcpy (fc->col_type, cie->col_type, |
9768 | 85.5k | fc->ncols * sizeof (*fc->col_type)); |
9769 | 85.5k | memcpy (fc->col_offset, cie->col_offset, |
9770 | 85.5k | fc->ncols * sizeof (*fc->col_offset)); |
9771 | 85.5k | fc->augmentation = cie->augmentation; |
9772 | 85.5k | fc->ptr_size = cie->ptr_size; |
9773 | 85.5k | eh_addr_size = cie->ptr_size; |
9774 | 85.5k | fc->segment_size = cie->segment_size; |
9775 | 85.5k | fc->code_factor = cie->code_factor; |
9776 | 85.5k | fc->data_factor = cie->data_factor; |
9777 | 85.5k | fc->cfa_reg = cie->cfa_reg; |
9778 | 85.5k | fc->cfa_offset = cie->cfa_offset; |
9779 | 85.5k | fc->ra = cie->ra; |
9780 | 85.5k | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
9781 | 0 | { |
9782 | 0 | warn (_("Invalid max register\n")); |
9783 | 0 | break; |
9784 | 0 | } |
9785 | 85.5k | fc->fde_encoding = cie->fde_encoding; |
9786 | 85.5k | } |
9787 | | |
9788 | 90.9k | if (fc->fde_encoding) |
9789 | 59.3k | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); |
9790 | | |
9791 | 90.9k | segment_selector = 0; |
9792 | 90.9k | if (fc->segment_size) |
9793 | 6 | { |
9794 | 6 | if (fc->segment_size > sizeof (segment_selector)) |
9795 | 0 | { |
9796 | | /* PR 17512: file: 9e196b3e. */ |
9797 | 0 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); |
9798 | 0 | fc->segment_size = 4; |
9799 | 0 | } |
9800 | 6 | SAFE_BYTE_GET_AND_INC (segment_selector, start, |
9801 | 6 | fc->segment_size, block_end); |
9802 | 6 | } |
9803 | | |
9804 | 90.9k | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, |
9805 | 90.9k | block_end); |
9806 | | |
9807 | | /* FIXME: It appears that sometimes the final pc_range value is |
9808 | | encoded in less than encoded_ptr_size bytes. See the x86_64 |
9809 | | run of the "objcopy on compressed debug sections" test for an |
9810 | | example of this. */ |
9811 | 90.9k | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, |
9812 | 90.9k | block_end); |
9813 | | |
9814 | 90.9k | if (cie->augmentation[0] == 'z') |
9815 | 59.3k | { |
9816 | 59.3k | READ_ULEB (augmentation_data_len, start, block_end); |
9817 | 59.3k | augmentation_data = start; |
9818 | | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
9819 | 59.3k | if (augmentation_data_len > (size_t) (block_end - start)) |
9820 | 70 | { |
9821 | 70 | warn (_("Augmentation data too long: %#" PRIx64 ", " |
9822 | 70 | "expected at most %#tx\n"), |
9823 | 70 | augmentation_data_len, block_end - start); |
9824 | 70 | start = block_end; |
9825 | 70 | augmentation_data = NULL; |
9826 | 70 | augmentation_data_len = 0; |
9827 | 70 | } |
9828 | 59.3k | start += augmentation_data_len; |
9829 | 59.3k | } |
9830 | | |
9831 | 90.9k | printf ("\n%08tx ", saved_start - section_start); |
9832 | 90.9k | print_hex (length, fc->ptr_size); |
9833 | 90.9k | print_hex (cie_id, offset_size); |
9834 | 90.9k | printf ("FDE "); |
9835 | | |
9836 | 90.9k | if (cie->chunk_start) |
9837 | 85.5k | printf ("cie=%08tx", cie->chunk_start - section_start); |
9838 | 5.41k | else |
9839 | | /* Ideally translate "invalid " to 8 chars, trailing space |
9840 | | is optional. */ |
9841 | 5.41k | printf (_("cie=invalid ")); |
9842 | | |
9843 | 90.9k | printf (" pc="); |
9844 | 90.9k | if (fc->segment_size) |
9845 | 6 | printf ("%04lx:", segment_selector); |
9846 | | |
9847 | 90.9k | print_hex_ns (fc->pc_begin, fc->ptr_size); |
9848 | 90.9k | printf (".."); |
9849 | 90.9k | print_hex_ns (fc->pc_begin + fc->pc_range, fc->ptr_size); |
9850 | 90.9k | printf ("\n"); |
9851 | | |
9852 | 90.9k | if (! do_debug_frames_interp && augmentation_data_len) |
9853 | 1.98k | { |
9854 | 1.98k | display_augmentation_data (augmentation_data, augmentation_data_len); |
9855 | 1.98k | putchar ('\n'); |
9856 | 1.98k | } |
9857 | 90.9k | } |
9858 | | |
9859 | | /* At this point, fc is the current chunk, cie (if any) is set, and |
9860 | | we're about to interpret instructions for the chunk. */ |
9861 | | /* ??? At present we need to do this always, since this sizes the |
9862 | | fc->col_type and fc->col_offset arrays, which we write into always. |
9863 | | We should probably split the interpreted and non-interpreted bits |
9864 | | into two different routines, since there's so much that doesn't |
9865 | | really overlap between them. */ |
9866 | 98.4k | if (1 || do_debug_frames_interp) |
9867 | 98.4k | { |
9868 | | /* Start by making a pass over the chunk, allocating storage |
9869 | | and taking note of what registers are used. */ |
9870 | 98.4k | unsigned char *tmp = start; |
9871 | | |
9872 | 3.09M | while (start < block_end) |
9873 | 3.00M | { |
9874 | 3.00M | unsigned int reg, op, opa; |
9875 | 3.00M | unsigned long temp; |
9876 | | |
9877 | 3.00M | op = *start++; |
9878 | 3.00M | opa = op & 0x3f; |
9879 | 3.00M | if (op & 0xc0) |
9880 | 1.40M | op &= 0xc0; |
9881 | | |
9882 | | /* Warning: if you add any more cases to this switch, be |
9883 | | sure to add them to the corresponding switch below. */ |
9884 | 3.00M | reg = -1u; |
9885 | 3.00M | switch (op) |
9886 | 3.00M | { |
9887 | 578k | case DW_CFA_advance_loc: |
9888 | 578k | break; |
9889 | 321k | case DW_CFA_offset: |
9890 | 321k | SKIP_ULEB (start, block_end); |
9891 | 321k | reg = opa; |
9892 | 321k | break; |
9893 | 510k | case DW_CFA_restore: |
9894 | 510k | reg = opa; |
9895 | 510k | break; |
9896 | 28.5k | case DW_CFA_set_loc: |
9897 | 28.5k | if ((size_t) (block_end - start) < encoded_ptr_size) |
9898 | 172 | start = block_end; |
9899 | 28.4k | else |
9900 | 28.4k | start += encoded_ptr_size; |
9901 | 28.5k | break; |
9902 | 50.4k | case DW_CFA_advance_loc1: |
9903 | 50.4k | if ((size_t) (block_end - start) < 1) |
9904 | 112 | start = block_end; |
9905 | 50.2k | else |
9906 | 50.2k | start += 1; |
9907 | 50.4k | break; |
9908 | 20.5k | case DW_CFA_advance_loc2: |
9909 | 20.5k | if ((size_t) (block_end - start) < 2) |
9910 | 46 | start = block_end; |
9911 | 20.5k | else |
9912 | 20.5k | start += 2; |
9913 | 20.5k | break; |
9914 | 29.5k | case DW_CFA_advance_loc4: |
9915 | 29.5k | if ((size_t) (block_end - start) < 4) |
9916 | 69 | start = block_end; |
9917 | 29.4k | else |
9918 | 29.4k | start += 4; |
9919 | 29.5k | break; |
9920 | 12.6k | case DW_CFA_offset_extended: |
9921 | 16.0k | case DW_CFA_val_offset: |
9922 | 16.0k | READ_ULEB (reg, start, block_end); |
9923 | 16.0k | SKIP_ULEB (start, block_end); |
9924 | 16.0k | break; |
9925 | 5.87k | case DW_CFA_restore_extended: |
9926 | 5.87k | READ_ULEB (reg, start, block_end); |
9927 | 5.87k | break; |
9928 | 4.64k | case DW_CFA_undefined: |
9929 | 4.64k | READ_ULEB (reg, start, block_end); |
9930 | 4.64k | break; |
9931 | 6.47k | case DW_CFA_same_value: |
9932 | 6.47k | READ_ULEB (reg, start, block_end); |
9933 | 6.47k | break; |
9934 | 19.0k | case DW_CFA_register: |
9935 | 19.0k | READ_ULEB (reg, start, block_end); |
9936 | 19.0k | SKIP_ULEB (start, block_end); |
9937 | 19.0k | break; |
9938 | 35.5k | case DW_CFA_def_cfa: |
9939 | 35.5k | SKIP_ULEB (start, block_end); |
9940 | 35.5k | SKIP_ULEB (start, block_end); |
9941 | 35.5k | break; |
9942 | 51.5k | case DW_CFA_def_cfa_register: |
9943 | 51.5k | SKIP_ULEB (start, block_end); |
9944 | 51.5k | break; |
9945 | 124k | case DW_CFA_def_cfa_offset: |
9946 | 124k | SKIP_ULEB (start, block_end); |
9947 | 124k | break; |
9948 | 3.38k | case DW_CFA_def_cfa_expression: |
9949 | 3.38k | READ_ULEB (temp, start, block_end); |
9950 | 3.38k | if ((size_t) (block_end - start) < temp) |
9951 | 414 | start = block_end; |
9952 | 2.97k | else |
9953 | 2.97k | start += temp; |
9954 | 3.38k | break; |
9955 | 7.77k | case DW_CFA_expression: |
9956 | 11.9k | case DW_CFA_val_expression: |
9957 | 11.9k | READ_ULEB (reg, start, block_end); |
9958 | 11.9k | READ_ULEB (temp, start, block_end); |
9959 | 11.9k | if ((size_t) (block_end - start) < temp) |
9960 | 796 | start = block_end; |
9961 | 11.1k | else |
9962 | 11.1k | start += temp; |
9963 | 11.9k | break; |
9964 | 2.34k | case DW_CFA_offset_extended_sf: |
9965 | 6.12k | case DW_CFA_val_offset_sf: |
9966 | 6.12k | READ_ULEB (reg, start, block_end); |
9967 | 6.12k | SKIP_SLEB (start, block_end); |
9968 | 6.12k | break; |
9969 | 6.09k | case DW_CFA_def_cfa_sf: |
9970 | 6.09k | SKIP_ULEB (start, block_end); |
9971 | 6.09k | SKIP_SLEB (start, block_end); |
9972 | 6.09k | break; |
9973 | 3.58k | case DW_CFA_def_cfa_offset_sf: |
9974 | 3.58k | SKIP_SLEB (start, block_end); |
9975 | 3.58k | break; |
9976 | 1.35k | case DW_CFA_MIPS_advance_loc8: |
9977 | 1.35k | if ((size_t) (block_end - start) < 8) |
9978 | 28 | start = block_end; |
9979 | 1.32k | else |
9980 | 1.32k | start += 8; |
9981 | 1.35k | break; |
9982 | 31.9k | case DW_CFA_GNU_args_size: |
9983 | 31.9k | SKIP_ULEB (start, block_end); |
9984 | 31.9k | break; |
9985 | 7.10k | case DW_CFA_GNU_negative_offset_extended: |
9986 | 7.10k | READ_ULEB (reg, start, block_end); |
9987 | 7.10k | SKIP_ULEB (start, block_end); |
9988 | 7.10k | break; |
9989 | 1.12M | default: |
9990 | 1.12M | break; |
9991 | 3.00M | } |
9992 | 3.00M | if (reg != -1u && frame_need_space (fc, reg) >= 0) |
9993 | 899k | { |
9994 | | /* Don't leave any reg as DW_CFA_unreferenced so |
9995 | | that frame_display_row prints name of regs in |
9996 | | header, and all referenced regs in each line. */ |
9997 | 899k | if (reg >= cie->ncols |
9998 | 899k | || cie->col_type[reg] == DW_CFA_unreferenced) |
9999 | 575k | fc->col_type[reg] = DW_CFA_undefined; |
10000 | 324k | else |
10001 | 324k | fc->col_type[reg] = cie->col_type[reg]; |
10002 | 899k | } |
10003 | 3.00M | } |
10004 | 98.4k | start = tmp; |
10005 | 98.4k | } |
10006 | | |
10007 | 98.4k | all_nops = true; |
10008 | | |
10009 | | /* Now we know what registers are used, make a second pass over |
10010 | | the chunk, this time actually printing out the info. */ |
10011 | | |
10012 | 1.80M | while (start < block_end) |
10013 | 1.71M | { |
10014 | 1.71M | unsigned op, opa; |
10015 | | /* Note: It is tempting to use an unsigned long for 'reg' but there |
10016 | | are various functions, notably frame_space_needed() that assume that |
10017 | | reg is an unsigned int. */ |
10018 | 1.71M | unsigned int reg; |
10019 | 1.71M | int64_t sofs; |
10020 | 1.71M | uint64_t ofs; |
10021 | 1.71M | const char *reg_prefix = ""; |
10022 | | |
10023 | 1.71M | op = *start++; |
10024 | 1.71M | opa = op & 0x3f; |
10025 | 1.71M | if (op & 0xc0) |
10026 | 948k | op &= 0xc0; |
10027 | | |
10028 | | /* Make a note if something other than DW_CFA_nop happens. */ |
10029 | 1.71M | if (op != DW_CFA_nop) |
10030 | 1.34M | all_nops = false; |
10031 | | |
10032 | | /* Warning: if you add any more cases to this switch, be |
10033 | | sure to add them to the corresponding switch above. */ |
10034 | 1.71M | switch (op) |
10035 | 1.71M | { |
10036 | 299k | case DW_CFA_advance_loc: |
10037 | 299k | opa *= fc->code_factor; |
10038 | 299k | if (do_debug_frames_interp) |
10039 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
10040 | 299k | else |
10041 | 299k | { |
10042 | 299k | printf (" DW_CFA_advance_loc: %d to ", opa); |
10043 | 299k | print_hex_ns (fc->pc_begin + opa, fc->ptr_size); |
10044 | 299k | printf ("\n"); |
10045 | 299k | } |
10046 | 299k | fc->pc_begin += opa; |
10047 | 299k | break; |
10048 | | |
10049 | 267k | case DW_CFA_offset: |
10050 | 267k | READ_ULEB (ofs, start, block_end); |
10051 | 267k | ofs *= fc->data_factor; |
10052 | 267k | if (opa >= fc->ncols) |
10053 | 586 | reg_prefix = bad_reg; |
10054 | 267k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10055 | 267k | printf (" DW_CFA_offset: %s%s at cfa%+" PRId64 "\n", |
10056 | 267k | reg_prefix, regname (opa, 0), ofs); |
10057 | 267k | if (*reg_prefix == '\0') |
10058 | 266k | { |
10059 | 266k | fc->col_type[opa] = DW_CFA_offset; |
10060 | 266k | fc->col_offset[opa] = ofs; |
10061 | 266k | } |
10062 | 267k | break; |
10063 | | |
10064 | 380k | case DW_CFA_restore: |
10065 | 380k | if (opa >= fc->ncols) |
10066 | 2.40k | reg_prefix = bad_reg; |
10067 | 380k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10068 | 380k | printf (" DW_CFA_restore: %s%s\n", |
10069 | 380k | reg_prefix, regname (opa, 0)); |
10070 | 380k | if (*reg_prefix != '\0') |
10071 | 2.40k | break; |
10072 | | |
10073 | 378k | if (opa >= cie->ncols |
10074 | 378k | || cie->col_type[opa] == DW_CFA_unreferenced) |
10075 | 261k | { |
10076 | 261k | fc->col_type[opa] = DW_CFA_undefined; |
10077 | 261k | fc->col_offset[opa] = 0; |
10078 | 261k | } |
10079 | 116k | else |
10080 | 116k | { |
10081 | 116k | fc->col_type[opa] = cie->col_type[opa]; |
10082 | 116k | fc->col_offset[opa] = cie->col_offset[opa]; |
10083 | 116k | } |
10084 | 378k | break; |
10085 | | |
10086 | 4.59k | case DW_CFA_set_loc: |
10087 | 4.59k | ofs = get_encoded_value (&start, fc->fde_encoding, section, |
10088 | 4.59k | block_end); |
10089 | 4.59k | if (do_debug_frames_interp) |
10090 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
10091 | 4.59k | else |
10092 | 4.59k | { |
10093 | 4.59k | printf (" DW_CFA_set_loc: "); |
10094 | 4.59k | print_hex_ns (ofs, fc->ptr_size); |
10095 | 4.59k | printf ("\n"); |
10096 | 4.59k | } |
10097 | 4.59k | fc->pc_begin = ofs; |
10098 | 4.59k | break; |
10099 | | |
10100 | 29.8k | case DW_CFA_advance_loc1: |
10101 | 29.8k | SAFE_BYTE_GET_AND_INC (ofs, start, 1, block_end); |
10102 | 29.8k | ofs *= fc->code_factor; |
10103 | 29.8k | if (do_debug_frames_interp) |
10104 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
10105 | 29.8k | else |
10106 | 29.8k | { |
10107 | 29.8k | printf (" DW_CFA_advance_loc1: %" PRId64 " to ", ofs); |
10108 | 29.8k | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); |
10109 | 29.8k | printf ("\n"); |
10110 | 29.8k | } |
10111 | 29.8k | fc->pc_begin += ofs; |
10112 | 29.8k | break; |
10113 | | |
10114 | 12.4k | case DW_CFA_advance_loc2: |
10115 | 12.4k | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
10116 | 12.4k | ofs *= fc->code_factor; |
10117 | 12.4k | if (do_debug_frames_interp) |
10118 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
10119 | 12.4k | else |
10120 | 12.4k | { |
10121 | 12.4k | printf (" DW_CFA_advance_loc2: %" PRId64 " to ", ofs); |
10122 | 12.4k | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); |
10123 | 12.4k | printf ("\n"); |
10124 | 12.4k | } |
10125 | 12.4k | fc->pc_begin += ofs; |
10126 | 12.4k | break; |
10127 | | |
10128 | 17.4k | case DW_CFA_advance_loc4: |
10129 | 17.4k | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
10130 | 17.4k | ofs *= fc->code_factor; |
10131 | 17.4k | if (do_debug_frames_interp) |
10132 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
10133 | 17.4k | else |
10134 | 17.4k | { |
10135 | 17.4k | printf (" DW_CFA_advance_loc4: %" PRId64 " to ", ofs); |
10136 | 17.4k | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); |
10137 | 17.4k | printf ("\n"); |
10138 | 17.4k | } |
10139 | 17.4k | fc->pc_begin += ofs; |
10140 | 17.4k | break; |
10141 | | |
10142 | 2.95k | case DW_CFA_offset_extended: |
10143 | 2.95k | READ_ULEB (reg, start, block_end); |
10144 | 2.95k | READ_ULEB (ofs, start, block_end); |
10145 | 2.95k | ofs *= fc->data_factor; |
10146 | 2.95k | if (reg >= fc->ncols) |
10147 | 519 | reg_prefix = bad_reg; |
10148 | 2.95k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10149 | 2.95k | printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64 "\n", |
10150 | 2.95k | reg_prefix, regname (reg, 0), ofs); |
10151 | 2.95k | if (*reg_prefix == '\0') |
10152 | 2.43k | { |
10153 | 2.43k | fc->col_type[reg] = DW_CFA_offset; |
10154 | 2.43k | fc->col_offset[reg] = ofs; |
10155 | 2.43k | } |
10156 | 2.95k | break; |
10157 | | |
10158 | 1.10k | case DW_CFA_val_offset: |
10159 | 1.10k | READ_ULEB (reg, start, block_end); |
10160 | 1.10k | READ_ULEB (ofs, start, block_end); |
10161 | 1.10k | ofs *= fc->data_factor; |
10162 | 1.10k | if (reg >= fc->ncols) |
10163 | 412 | reg_prefix = bad_reg; |
10164 | 1.10k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10165 | 1.10k | printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64 "\n", |
10166 | 1.10k | reg_prefix, regname (reg, 0), ofs); |
10167 | 1.10k | if (*reg_prefix == '\0') |
10168 | 693 | { |
10169 | 693 | fc->col_type[reg] = DW_CFA_val_offset; |
10170 | 693 | fc->col_offset[reg] = ofs; |
10171 | 693 | } |
10172 | 1.10k | break; |
10173 | | |
10174 | 2.74k | case DW_CFA_restore_extended: |
10175 | 2.74k | READ_ULEB (reg, start, block_end); |
10176 | 2.74k | if (reg >= fc->ncols) |
10177 | 361 | reg_prefix = bad_reg; |
10178 | 2.74k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10179 | 2.74k | printf (" DW_CFA_restore_extended: %s%s\n", |
10180 | 2.74k | reg_prefix, regname (reg, 0)); |
10181 | 2.74k | if (*reg_prefix != '\0') |
10182 | 361 | break; |
10183 | | |
10184 | 2.38k | if (reg >= cie->ncols |
10185 | 2.38k | || cie->col_type[reg] == DW_CFA_unreferenced) |
10186 | 183 | { |
10187 | 183 | fc->col_type[reg] = DW_CFA_undefined; |
10188 | 183 | fc->col_offset[reg] = 0; |
10189 | 183 | } |
10190 | 2.20k | else |
10191 | 2.20k | { |
10192 | 2.20k | fc->col_type[reg] = cie->col_type[reg]; |
10193 | 2.20k | fc->col_offset[reg] = cie->col_offset[reg]; |
10194 | 2.20k | } |
10195 | 2.38k | break; |
10196 | | |
10197 | 1.93k | case DW_CFA_undefined: |
10198 | 1.93k | READ_ULEB (reg, start, block_end); |
10199 | 1.93k | if (reg >= fc->ncols) |
10200 | 254 | reg_prefix = bad_reg; |
10201 | 1.93k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10202 | 1.93k | printf (" DW_CFA_undefined: %s%s\n", |
10203 | 1.93k | reg_prefix, regname (reg, 0)); |
10204 | 1.93k | if (*reg_prefix == '\0') |
10205 | 1.68k | { |
10206 | 1.68k | fc->col_type[reg] = DW_CFA_undefined; |
10207 | 1.68k | fc->col_offset[reg] = 0; |
10208 | 1.68k | } |
10209 | 1.93k | break; |
10210 | | |
10211 | 1.81k | case DW_CFA_same_value: |
10212 | 1.81k | READ_ULEB (reg, start, block_end); |
10213 | 1.81k | if (reg >= fc->ncols) |
10214 | 279 | reg_prefix = bad_reg; |
10215 | 1.81k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10216 | 1.81k | printf (" DW_CFA_same_value: %s%s\n", |
10217 | 1.81k | reg_prefix, regname (reg, 0)); |
10218 | 1.81k | if (*reg_prefix == '\0') |
10219 | 1.53k | { |
10220 | 1.53k | fc->col_type[reg] = DW_CFA_same_value; |
10221 | 1.53k | fc->col_offset[reg] = 0; |
10222 | 1.53k | } |
10223 | 1.81k | break; |
10224 | | |
10225 | 14.4k | case DW_CFA_register: |
10226 | 14.4k | READ_ULEB (reg, start, block_end); |
10227 | 14.4k | READ_ULEB (ofs, start, block_end); |
10228 | 14.4k | if (reg >= fc->ncols) |
10229 | 175 | reg_prefix = bad_reg; |
10230 | 14.4k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10231 | 14.4k | { |
10232 | 14.4k | printf (" DW_CFA_register: %s%s in ", |
10233 | 14.4k | reg_prefix, regname (reg, 0)); |
10234 | 14.4k | puts (regname (ofs, 0)); |
10235 | 14.4k | } |
10236 | 14.4k | if (*reg_prefix == '\0') |
10237 | 14.2k | { |
10238 | 14.2k | fc->col_type[reg] = DW_CFA_register; |
10239 | 14.2k | fc->col_offset[reg] = ofs; |
10240 | 14.2k | } |
10241 | 14.4k | break; |
10242 | | |
10243 | 33.4k | case DW_CFA_remember_state: |
10244 | 33.4k | if (! do_debug_frames_interp) |
10245 | 33.4k | printf (" DW_CFA_remember_state\n"); |
10246 | 33.4k | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
10247 | 33.4k | rs->cfa_offset = fc->cfa_offset; |
10248 | 33.4k | rs->cfa_reg = fc->cfa_reg; |
10249 | 33.4k | rs->ra = fc->ra; |
10250 | 33.4k | rs->cfa_exp = fc->cfa_exp; |
10251 | 33.4k | rs->ncols = fc->ncols; |
10252 | 33.4k | rs->col_type = xcmalloc (rs->ncols, sizeof (*rs->col_type)); |
10253 | 33.4k | rs->col_offset = xcmalloc (rs->ncols, sizeof (*rs->col_offset)); |
10254 | 33.4k | memcpy (rs->col_type, fc->col_type, |
10255 | 33.4k | rs->ncols * sizeof (*fc->col_type)); |
10256 | 33.4k | memcpy (rs->col_offset, fc->col_offset, |
10257 | 33.4k | rs->ncols * sizeof (*fc->col_offset)); |
10258 | 33.4k | rs->next = remembered_state; |
10259 | 33.4k | remembered_state = rs; |
10260 | 33.4k | break; |
10261 | | |
10262 | 35.4k | case DW_CFA_restore_state: |
10263 | 35.4k | if (! do_debug_frames_interp) |
10264 | 35.4k | printf (" DW_CFA_restore_state\n"); |
10265 | 35.4k | rs = remembered_state; |
10266 | 35.4k | if (rs) |
10267 | 32.5k | { |
10268 | 32.5k | remembered_state = rs->next; |
10269 | 32.5k | fc->cfa_offset = rs->cfa_offset; |
10270 | 32.5k | fc->cfa_reg = rs->cfa_reg; |
10271 | 32.5k | fc->ra = rs->ra; |
10272 | 32.5k | fc->cfa_exp = rs->cfa_exp; |
10273 | 32.5k | if (frame_need_space (fc, rs->ncols - 1) < 0) |
10274 | 0 | { |
10275 | 0 | warn (_("Invalid column number in saved frame state\n")); |
10276 | 0 | fc->ncols = 0; |
10277 | 0 | } |
10278 | 32.5k | else |
10279 | 32.5k | { |
10280 | 32.5k | memcpy (fc->col_type, rs->col_type, |
10281 | 32.5k | rs->ncols * sizeof (*rs->col_type)); |
10282 | 32.5k | memcpy (fc->col_offset, rs->col_offset, |
10283 | 32.5k | rs->ncols * sizeof (*rs->col_offset)); |
10284 | 32.5k | } |
10285 | 32.5k | free (rs->col_type); |
10286 | 32.5k | free (rs->col_offset); |
10287 | 32.5k | free (rs); |
10288 | 32.5k | } |
10289 | 2.86k | else if (do_debug_frames_interp) |
10290 | 0 | printf ("Mismatched DW_CFA_restore_state\n"); |
10291 | 35.4k | break; |
10292 | | |
10293 | 27.6k | case DW_CFA_def_cfa: |
10294 | 27.6k | READ_ULEB (fc->cfa_reg, start, block_end); |
10295 | 27.6k | READ_ULEB (fc->cfa_offset, start, block_end); |
10296 | 27.6k | fc->cfa_exp = 0; |
10297 | 27.6k | if (! do_debug_frames_interp) |
10298 | 27.6k | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
10299 | 27.6k | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
10300 | 27.6k | break; |
10301 | | |
10302 | 45.0k | case DW_CFA_def_cfa_register: |
10303 | 45.0k | READ_ULEB (fc->cfa_reg, start, block_end); |
10304 | 45.0k | fc->cfa_exp = 0; |
10305 | 45.0k | if (! do_debug_frames_interp) |
10306 | 45.0k | printf (" DW_CFA_def_cfa_register: %s\n", |
10307 | 45.0k | regname (fc->cfa_reg, 0)); |
10308 | 45.0k | break; |
10309 | | |
10310 | 112k | case DW_CFA_def_cfa_offset: |
10311 | 112k | READ_ULEB (fc->cfa_offset, start, block_end); |
10312 | 112k | if (! do_debug_frames_interp) |
10313 | 112k | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
10314 | 112k | break; |
10315 | | |
10316 | 362k | case DW_CFA_nop: |
10317 | 362k | if (! do_debug_frames_interp) |
10318 | 362k | printf (" DW_CFA_nop\n"); |
10319 | 362k | break; |
10320 | | |
10321 | 1.47k | case DW_CFA_def_cfa_expression: |
10322 | 1.47k | READ_ULEB (ofs, start, block_end); |
10323 | 1.47k | if (ofs > (size_t) (block_end - start)) |
10324 | 491 | { |
10325 | 491 | printf (_(" %s: <corrupt len %" PRIu64 ">\n"), |
10326 | 491 | "DW_CFA_def_cfa_expression", ofs); |
10327 | 491 | break; |
10328 | 491 | } |
10329 | 981 | if (! do_debug_frames_interp) |
10330 | 981 | { |
10331 | 981 | printf (" DW_CFA_def_cfa_expression ("); |
10332 | 981 | decode_location_expression (start, eh_addr_size, 0, -1, |
10333 | 981 | ofs, 0, section); |
10334 | 981 | printf (")\n"); |
10335 | 981 | } |
10336 | 981 | fc->cfa_exp = 1; |
10337 | 981 | start += ofs; |
10338 | 981 | break; |
10339 | | |
10340 | 4.81k | case DW_CFA_expression: |
10341 | 4.81k | READ_ULEB (reg, start, block_end); |
10342 | 4.81k | READ_ULEB (ofs, start, block_end); |
10343 | 4.81k | if (reg >= fc->ncols) |
10344 | 526 | reg_prefix = bad_reg; |
10345 | | /* PR 17512: file: 069-133014-0.006. */ |
10346 | | /* PR 17512: file: 98c02eb4. */ |
10347 | 4.81k | if (ofs > (size_t) (block_end - start)) |
10348 | 526 | { |
10349 | 526 | printf (_(" %s: <corrupt len %" PRIu64 ">\n"), |
10350 | 526 | "DW_CFA_expression", ofs); |
10351 | 526 | break; |
10352 | 526 | } |
10353 | 4.28k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10354 | 4.28k | { |
10355 | 4.28k | printf (" DW_CFA_expression: %s%s (", |
10356 | 4.28k | reg_prefix, regname (reg, 0)); |
10357 | 4.28k | decode_location_expression (start, eh_addr_size, 0, -1, |
10358 | 4.28k | ofs, 0, section); |
10359 | 4.28k | printf (")\n"); |
10360 | 4.28k | } |
10361 | 4.28k | if (*reg_prefix == '\0') |
10362 | 3.91k | fc->col_type[reg] = DW_CFA_expression; |
10363 | 4.28k | start += ofs; |
10364 | 4.28k | break; |
10365 | | |
10366 | 2.70k | case DW_CFA_val_expression: |
10367 | 2.70k | READ_ULEB (reg, start, block_end); |
10368 | 2.70k | READ_ULEB (ofs, start, block_end); |
10369 | 2.70k | if (reg >= fc->ncols) |
10370 | 310 | reg_prefix = bad_reg; |
10371 | 2.70k | if (ofs > (size_t) (block_end - start)) |
10372 | 464 | { |
10373 | 464 | printf (" %s: <corrupt len %" PRIu64 ">\n", |
10374 | 464 | "DW_CFA_val_expression", ofs); |
10375 | 464 | break; |
10376 | 464 | } |
10377 | 2.24k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10378 | 2.24k | { |
10379 | 2.24k | printf (" DW_CFA_val_expression: %s%s (", |
10380 | 2.24k | reg_prefix, regname (reg, 0)); |
10381 | 2.24k | decode_location_expression (start, eh_addr_size, 0, -1, |
10382 | 2.24k | ofs, 0, section); |
10383 | 2.24k | printf (")\n"); |
10384 | 2.24k | } |
10385 | 2.24k | if (*reg_prefix == '\0') |
10386 | 2.02k | fc->col_type[reg] = DW_CFA_val_expression; |
10387 | 2.24k | start += ofs; |
10388 | 2.24k | break; |
10389 | | |
10390 | 1.38k | case DW_CFA_offset_extended_sf: |
10391 | 1.38k | READ_ULEB (reg, start, block_end); |
10392 | 1.38k | READ_SLEB (sofs, start, block_end); |
10393 | | /* data_factor multiplicaton done here as unsigned to |
10394 | | avoid integer overflow warnings from asan on fuzzed |
10395 | | objects. */ |
10396 | 1.38k | ofs = sofs; |
10397 | 1.38k | ofs *= fc->data_factor; |
10398 | 1.38k | if (reg >= fc->ncols) |
10399 | 361 | reg_prefix = bad_reg; |
10400 | 1.38k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10401 | 1.38k | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64 "\n", |
10402 | 1.38k | reg_prefix, regname (reg, 0), ofs); |
10403 | 1.38k | if (*reg_prefix == '\0') |
10404 | 1.01k | { |
10405 | 1.01k | fc->col_type[reg] = DW_CFA_offset; |
10406 | 1.01k | fc->col_offset[reg] = ofs; |
10407 | 1.01k | } |
10408 | 1.38k | break; |
10409 | | |
10410 | 1.67k | case DW_CFA_val_offset_sf: |
10411 | 1.67k | READ_ULEB (reg, start, block_end); |
10412 | 1.67k | READ_SLEB (sofs, start, block_end); |
10413 | 1.67k | ofs = sofs; |
10414 | 1.67k | ofs *= fc->data_factor; |
10415 | 1.67k | if (reg >= fc->ncols) |
10416 | 127 | reg_prefix = bad_reg; |
10417 | 1.67k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10418 | 1.67k | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64 "\n", |
10419 | 1.67k | reg_prefix, regname (reg, 0), ofs); |
10420 | 1.67k | if (*reg_prefix == '\0') |
10421 | 1.54k | { |
10422 | 1.54k | fc->col_type[reg] = DW_CFA_val_offset; |
10423 | 1.54k | fc->col_offset[reg] = ofs; |
10424 | 1.54k | } |
10425 | 1.67k | break; |
10426 | | |
10427 | 1.11k | case DW_CFA_def_cfa_sf: |
10428 | 1.11k | READ_ULEB (fc->cfa_reg, start, block_end); |
10429 | 1.11k | READ_SLEB (sofs, start, block_end); |
10430 | 1.11k | ofs = sofs; |
10431 | 1.11k | ofs *= fc->data_factor; |
10432 | 1.11k | fc->cfa_offset = ofs; |
10433 | 1.11k | fc->cfa_exp = 0; |
10434 | 1.11k | if (! do_debug_frames_interp) |
10435 | 1.11k | printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64 "\n", |
10436 | 1.11k | regname (fc->cfa_reg, 0), ofs); |
10437 | 1.11k | break; |
10438 | | |
10439 | 581 | case DW_CFA_def_cfa_offset_sf: |
10440 | 581 | READ_SLEB (sofs, start, block_end); |
10441 | 581 | ofs = sofs; |
10442 | 581 | ofs *= fc->data_factor; |
10443 | 581 | fc->cfa_offset = ofs; |
10444 | 581 | if (! do_debug_frames_interp) |
10445 | 581 | printf (" DW_CFA_def_cfa_offset_sf: %" PRId64 "\n", ofs); |
10446 | 581 | break; |
10447 | | |
10448 | 480 | case DW_CFA_MIPS_advance_loc8: |
10449 | 480 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
10450 | 480 | ofs *= fc->code_factor; |
10451 | 480 | if (do_debug_frames_interp) |
10452 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
10453 | 480 | else |
10454 | 480 | { |
10455 | 480 | printf (" DW_CFA_MIPS_advance_loc8: %" PRId64 " to ", ofs); |
10456 | 480 | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); |
10457 | 480 | printf ("\n"); |
10458 | 480 | } |
10459 | 480 | fc->pc_begin += ofs; |
10460 | 480 | break; |
10461 | | |
10462 | 867 | case DW_CFA_AARCH64_negate_ra_state_with_pc: |
10463 | 867 | if (! do_debug_frames_interp) |
10464 | 867 | printf (" DW_CFA_AARCH64_negate_ra_state_with_pc\n"); |
10465 | 867 | break; |
10466 | | |
10467 | 14.6k | case DW_CFA_GNU_window_save: |
10468 | 14.6k | if (! do_debug_frames_interp) |
10469 | 14.6k | printf (" %s\n", DW_CFA_GNU_window_save_name[is_aarch64]); |
10470 | 14.6k | break; |
10471 | | |
10472 | 21.5k | case DW_CFA_GNU_args_size: |
10473 | 21.5k | READ_ULEB (ofs, start, block_end); |
10474 | 21.5k | if (! do_debug_frames_interp) |
10475 | 21.5k | printf (" DW_CFA_GNU_args_size: %" PRIu64 "\n", ofs); |
10476 | 21.5k | break; |
10477 | | |
10478 | 2.79k | case DW_CFA_GNU_negative_offset_extended: |
10479 | 2.79k | READ_ULEB (reg, start, block_end); |
10480 | 2.79k | READ_SLEB (sofs, start, block_end); |
10481 | 2.79k | ofs = sofs; |
10482 | 2.79k | ofs = -ofs * fc->data_factor; |
10483 | 2.79k | if (reg >= fc->ncols) |
10484 | 336 | reg_prefix = bad_reg; |
10485 | 2.79k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
10486 | 2.79k | printf (" DW_CFA_GNU_negative_offset_extended: %s%s " |
10487 | 2.79k | "at cfa%+" PRId64 "\n", |
10488 | 2.79k | reg_prefix, regname (reg, 0), ofs); |
10489 | 2.79k | if (*reg_prefix == '\0') |
10490 | 2.45k | { |
10491 | 2.45k | fc->col_type[reg] = DW_CFA_offset; |
10492 | 2.45k | fc->col_offset[reg] = ofs; |
10493 | 2.45k | } |
10494 | 2.79k | break; |
10495 | | |
10496 | 2.41k | default: |
10497 | 2.41k | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
10498 | 2.12k | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); |
10499 | 296 | else |
10500 | 296 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
10501 | 2.41k | start = block_end; |
10502 | 1.71M | } |
10503 | 1.71M | } |
10504 | | |
10505 | | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
10506 | 98.4k | if (do_debug_frames_interp && ! all_nops) |
10507 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
10508 | | |
10509 | 98.4k | if (fde_fc.col_type != NULL) |
10510 | 90.9k | { |
10511 | 90.9k | free (fde_fc.col_type); |
10512 | 90.9k | fde_fc.col_type = NULL; |
10513 | 90.9k | } |
10514 | 98.4k | if (fde_fc.col_offset != NULL) |
10515 | 90.9k | { |
10516 | 90.9k | free (fde_fc.col_offset); |
10517 | 90.9k | fde_fc.col_offset = NULL; |
10518 | 90.9k | } |
10519 | | |
10520 | 98.4k | start = block_end; |
10521 | 98.4k | eh_addr_size = saved_eh_addr_size; |
10522 | 98.4k | } |
10523 | | |
10524 | 4.99k | printf ("\n"); |
10525 | | |
10526 | 5.86k | while (remembered_state != NULL) |
10527 | 871 | { |
10528 | 871 | rs = remembered_state; |
10529 | 871 | remembered_state = rs->next; |
10530 | 871 | free (rs->col_type); |
10531 | 871 | free (rs->col_offset); |
10532 | 871 | rs->next = NULL; /* Paranoia. */ |
10533 | 871 | free (rs); |
10534 | 871 | } |
10535 | | |
10536 | 12.4k | while (chunks != NULL) |
10537 | 7.47k | { |
10538 | 7.47k | rs = chunks; |
10539 | 7.47k | chunks = rs->next; |
10540 | 7.47k | free (rs->col_type); |
10541 | 7.47k | free (rs->col_offset); |
10542 | 7.47k | rs->next = NULL; /* Paranoia. */ |
10543 | 7.47k | free (rs); |
10544 | 7.47k | } |
10545 | | |
10546 | 5.00k | while (forward_refs != NULL) |
10547 | 9 | { |
10548 | 9 | rs = forward_refs; |
10549 | 9 | forward_refs = rs->next; |
10550 | 9 | free (rs->col_type); |
10551 | 9 | free (rs->col_offset); |
10552 | 9 | rs->next = NULL; /* Paranoia. */ |
10553 | 9 | free (rs); |
10554 | 9 | } |
10555 | | |
10556 | 4.99k | return 1; |
10557 | 4.99k | } |
10558 | | |
10559 | | #undef GET |
10560 | | |
10561 | | static int |
10562 | | display_debug_names (struct dwarf_section *section, void *file) |
10563 | 0 | { |
10564 | 0 | unsigned char *hdrptr = section->start; |
10565 | 0 | uint64_t unit_length; |
10566 | 0 | unsigned char *unit_start; |
10567 | 0 | const unsigned char *const section_end = section->start + section->size; |
10568 | 0 | unsigned char *unit_end; |
10569 | |
|
10570 | 0 | introduce (section, false); |
10571 | |
|
10572 | 0 | load_debug_section_with_follow (str, file); |
10573 | |
|
10574 | 0 | for (; hdrptr < section_end; hdrptr = unit_end) |
10575 | 0 | { |
10576 | 0 | unsigned int offset_size; |
10577 | 0 | uint16_t dwarf_version, padding; |
10578 | 0 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; |
10579 | 0 | uint64_t bucket_count, name_count, abbrev_table_size; |
10580 | 0 | uint32_t augmentation_string_size; |
10581 | 0 | unsigned int i; |
10582 | 0 | bool augmentation_printable; |
10583 | 0 | const char *augmentation_string; |
10584 | 0 | size_t total; |
10585 | |
|
10586 | 0 | unit_start = hdrptr; |
10587 | | |
10588 | | /* Get and check the length of the block. */ |
10589 | 0 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); |
10590 | | |
10591 | 0 | if (unit_length == 0xffffffff) |
10592 | 0 | { |
10593 | | /* This section is 64-bit DWARF. */ |
10594 | 0 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); |
10595 | 0 | offset_size = 8; |
10596 | 0 | } |
10597 | 0 | else |
10598 | 0 | offset_size = 4; |
10599 | | |
10600 | 0 | if (unit_length > (size_t) (section_end - hdrptr) |
10601 | 0 | || unit_length < 2 + 2 + 4 * 7) |
10602 | 0 | { |
10603 | 0 | too_short: |
10604 | 0 | warn (_("Debug info is corrupted, %s header at %#tx" |
10605 | 0 | " has length %#" PRIx64 "\n"), |
10606 | 0 | section->name, unit_start - section->start, unit_length); |
10607 | 0 | return 0; |
10608 | 0 | } |
10609 | 0 | unit_end = hdrptr + unit_length; |
10610 | | |
10611 | | /* Get and check the version number. */ |
10612 | 0 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); |
10613 | 0 | printf (_("Version %d\n"), (int) dwarf_version); |
10614 | | |
10615 | | /* Prior versions did not exist, and future versions may not be |
10616 | | backwards compatible. */ |
10617 | 0 | if (dwarf_version != 5) |
10618 | 0 | { |
10619 | 0 | warn (_("Only DWARF version 5 .debug_names " |
10620 | 0 | "is currently supported.\n")); |
10621 | 0 | return 0; |
10622 | 0 | } |
10623 | | |
10624 | 0 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); |
10625 | 0 | if (padding != 0) |
10626 | 0 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), |
10627 | 0 | padding); |
10628 | |
|
10629 | 0 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); |
10630 | 0 | if (comp_unit_count == 0) |
10631 | 0 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); |
10632 | |
|
10633 | 0 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); |
10634 | 0 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); |
10635 | 0 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); |
10636 | 0 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); |
10637 | 0 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); |
10638 | | |
10639 | 0 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); |
10640 | 0 | if (augmentation_string_size % 4 != 0) |
10641 | 0 | { |
10642 | 0 | warn (_("Augmentation string length %u must be rounded up " |
10643 | 0 | "to a multiple of 4 in .debug_names.\n"), |
10644 | 0 | augmentation_string_size); |
10645 | 0 | augmentation_string_size += (-augmentation_string_size) & 3; |
10646 | 0 | } |
10647 | 0 | if (augmentation_string_size > (size_t) (unit_end - hdrptr)) |
10648 | 0 | goto too_short; |
10649 | | |
10650 | 0 | printf (_("Augmentation string:")); |
10651 | |
|
10652 | 0 | augmentation_printable = true; |
10653 | 0 | augmentation_string = (const char *) hdrptr; |
10654 | |
|
10655 | 0 | for (i = 0; i < augmentation_string_size; i++) |
10656 | 0 | { |
10657 | 0 | unsigned char uc; |
10658 | |
|
10659 | 0 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); |
10660 | 0 | printf (" %02x", uc); |
10661 | |
|
10662 | 0 | if (uc != 0 && !ISPRINT (uc)) |
10663 | 0 | augmentation_printable = false; |
10664 | 0 | } |
10665 | | |
10666 | 0 | if (augmentation_printable) |
10667 | 0 | { |
10668 | 0 | printf (" (\""); |
10669 | 0 | for (i = 0; |
10670 | 0 | i < augmentation_string_size && augmentation_string[i]; |
10671 | 0 | ++i) |
10672 | 0 | putchar (augmentation_string[i]); |
10673 | 0 | printf ("\")"); |
10674 | 0 | } |
10675 | 0 | putchar ('\n'); |
10676 | |
|
10677 | 0 | printf (_("CU table:\n")); |
10678 | 0 | if (_mul_overflow (comp_unit_count, offset_size, &total) |
10679 | 0 | || total > (size_t) (unit_end - hdrptr)) |
10680 | 0 | goto too_short; |
10681 | 0 | for (i = 0; i < comp_unit_count; i++) |
10682 | 0 | { |
10683 | 0 | uint64_t cu_offset; |
10684 | |
|
10685 | 0 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); |
10686 | 0 | printf ("[%3u] %#" PRIx64 "\n", i, cu_offset); |
10687 | 0 | } |
10688 | 0 | putchar ('\n'); |
10689 | |
|
10690 | 0 | printf (_("TU table:\n")); |
10691 | 0 | if (_mul_overflow (local_type_unit_count, offset_size, &total) |
10692 | 0 | || total > (size_t) (unit_end - hdrptr)) |
10693 | 0 | goto too_short; |
10694 | 0 | for (i = 0; i < local_type_unit_count; i++) |
10695 | 0 | { |
10696 | 0 | uint64_t tu_offset; |
10697 | |
|
10698 | 0 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); |
10699 | 0 | printf ("[%3u] %#" PRIx64 "\n", i, tu_offset); |
10700 | 0 | } |
10701 | 0 | putchar ('\n'); |
10702 | |
|
10703 | 0 | printf (_("Foreign TU table:\n")); |
10704 | 0 | if (_mul_overflow (foreign_type_unit_count, 8, &total) |
10705 | 0 | || total > (size_t) (unit_end - hdrptr)) |
10706 | 0 | goto too_short; |
10707 | 0 | for (i = 0; i < foreign_type_unit_count; i++) |
10708 | 0 | { |
10709 | 0 | uint64_t signature; |
10710 | |
|
10711 | 0 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); |
10712 | 0 | printf (_("[%3u] "), i); |
10713 | 0 | print_hex_ns (signature, 8); |
10714 | 0 | putchar ('\n'); |
10715 | 0 | } |
10716 | 0 | putchar ('\n'); |
10717 | |
|
10718 | 0 | uint64_t xtra = (bucket_count * sizeof (uint32_t) |
10719 | 0 | + name_count * (sizeof (uint32_t) + 2 * offset_size) |
10720 | 0 | + abbrev_table_size); |
10721 | 0 | if (xtra > (size_t) (unit_end - hdrptr)) |
10722 | 0 | { |
10723 | 0 | warn (_("Entry pool offset (%#" PRIx64 ") exceeds unit size %#tx " |
10724 | 0 | "for unit %#tx in the debug_names\n"), |
10725 | 0 | xtra, unit_end - unit_start, unit_start - section->start); |
10726 | 0 | return 0; |
10727 | 0 | } |
10728 | 0 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; |
10729 | 0 | hdrptr += bucket_count * sizeof (uint32_t); |
10730 | 0 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; |
10731 | 0 | if (bucket_count != 0) |
10732 | 0 | hdrptr += name_count * sizeof (uint32_t); |
10733 | 0 | unsigned char *const name_table_string_offsets = hdrptr; |
10734 | 0 | hdrptr += name_count * offset_size; |
10735 | 0 | unsigned char *const name_table_entry_offsets = hdrptr; |
10736 | 0 | hdrptr += name_count * offset_size; |
10737 | 0 | unsigned char *const abbrev_table = hdrptr; |
10738 | 0 | hdrptr += abbrev_table_size; |
10739 | 0 | const unsigned char *const abbrev_table_end = hdrptr; |
10740 | 0 | unsigned char *const entry_pool = hdrptr; |
10741 | |
|
10742 | 0 | size_t buckets_filled = 0; |
10743 | 0 | size_t bucketi; |
10744 | 0 | for (bucketi = 0; bucketi < bucket_count; bucketi++) |
10745 | 0 | { |
10746 | 0 | const uint32_t bucket = hash_table_buckets[bucketi]; |
10747 | |
|
10748 | 0 | if (bucket != 0) |
10749 | 0 | ++buckets_filled; |
10750 | 0 | } |
10751 | 0 | printf (ngettext ("Used %zu of %lu bucket.\n", |
10752 | 0 | "Used %zu of %lu buckets.\n", |
10753 | 0 | (unsigned long) bucket_count), |
10754 | 0 | buckets_filled, (unsigned long) bucket_count); |
10755 | |
|
10756 | 0 | if (bucket_count != 0) |
10757 | 0 | { |
10758 | 0 | uint32_t hash_prev = 0; |
10759 | 0 | size_t hash_clash_count = 0; |
10760 | 0 | size_t longest_clash = 0; |
10761 | 0 | size_t this_length = 0; |
10762 | 0 | size_t hashi; |
10763 | 0 | for (hashi = 0; hashi < name_count; hashi++) |
10764 | 0 | { |
10765 | 0 | const uint32_t hash_this = hash_table_hashes[hashi]; |
10766 | |
|
10767 | 0 | if (hashi > 0) |
10768 | 0 | { |
10769 | 0 | if (hash_prev % bucket_count == hash_this % bucket_count) |
10770 | 0 | { |
10771 | 0 | ++hash_clash_count; |
10772 | 0 | ++this_length; |
10773 | 0 | longest_clash = MAX (longest_clash, this_length); |
10774 | 0 | } |
10775 | 0 | else |
10776 | 0 | this_length = 0; |
10777 | 0 | } |
10778 | 0 | hash_prev = hash_this; |
10779 | 0 | } |
10780 | 0 | printf (_("Out of %" PRIu64 " items there are %zu bucket clashes" |
10781 | 0 | " (longest of %zu entries).\n"), |
10782 | 0 | name_count, hash_clash_count, longest_clash); |
10783 | |
|
10784 | 0 | if (name_count != buckets_filled + hash_clash_count) |
10785 | 0 | warn (_("The name_count (%" PRIu64 ")" |
10786 | 0 | " is not the same as the used bucket_count" |
10787 | 0 | " (%zu) + the hash clash count (%zu)\n"), |
10788 | 0 | name_count, buckets_filled, hash_clash_count); |
10789 | 0 | } |
10790 | |
|
10791 | 0 | struct abbrev_lookup_entry |
10792 | 0 | { |
10793 | 0 | uint64_t abbrev_tag; |
10794 | 0 | unsigned char *abbrev_lookup_ptr; |
10795 | 0 | }; |
10796 | 0 | struct abbrev_lookup_entry *abbrev_lookup = NULL; |
10797 | 0 | size_t abbrev_lookup_used = 0; |
10798 | 0 | size_t abbrev_lookup_allocated = 0; |
10799 | |
|
10800 | 0 | unsigned char *abbrevptr = abbrev_table; |
10801 | 0 | for (;;) |
10802 | 0 | { |
10803 | 0 | uint64_t abbrev_tag; |
10804 | |
|
10805 | 0 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); |
10806 | 0 | if (abbrev_tag == 0) |
10807 | 0 | break; |
10808 | 0 | if (abbrev_lookup_used == abbrev_lookup_allocated) |
10809 | 0 | { |
10810 | 0 | abbrev_lookup_allocated = MAX (0x100, |
10811 | 0 | abbrev_lookup_allocated * 2); |
10812 | 0 | abbrev_lookup = xrealloc (abbrev_lookup, |
10813 | 0 | (abbrev_lookup_allocated |
10814 | 0 | * sizeof (*abbrev_lookup))); |
10815 | 0 | } |
10816 | 0 | assert (abbrev_lookup_used < abbrev_lookup_allocated); |
10817 | 0 | struct abbrev_lookup_entry *entry; |
10818 | 0 | for (entry = abbrev_lookup; |
10819 | 0 | entry < abbrev_lookup + abbrev_lookup_used; |
10820 | 0 | entry++) |
10821 | 0 | if (entry->abbrev_tag == abbrev_tag) |
10822 | 0 | { |
10823 | 0 | warn (_("Duplicate abbreviation tag %" PRIu64 |
10824 | 0 | " in unit %#tx in the debug_names section\n"), |
10825 | 0 | abbrev_tag, unit_start - section->start); |
10826 | 0 | break; |
10827 | 0 | } |
10828 | 0 | entry = &abbrev_lookup[abbrev_lookup_used++]; |
10829 | 0 | entry->abbrev_tag = abbrev_tag; |
10830 | 0 | entry->abbrev_lookup_ptr = abbrevptr; |
10831 | | |
10832 | | /* Skip DWARF tag. */ |
10833 | 0 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
10834 | 0 | for (;;) |
10835 | 0 | { |
10836 | 0 | uint64_t xindex, form; |
10837 | |
|
10838 | 0 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); |
10839 | 0 | READ_ULEB (form, abbrevptr, abbrev_table_end); |
10840 | 0 | if (xindex == 0 && form == 0) |
10841 | 0 | break; |
10842 | 0 | } |
10843 | 0 | } |
10844 | | |
10845 | 0 | printf (_("\nSymbol table:\n")); |
10846 | 0 | uint32_t namei; |
10847 | 0 | for (namei = 0; namei < name_count; ++namei) |
10848 | 0 | { |
10849 | 0 | uint64_t string_offset, entry_offset; |
10850 | 0 | unsigned char *p; |
10851 | | /* We need to scan first whether there is a single or multiple |
10852 | | entries. TAGNO is -2 for the first entry, it is -1 for the |
10853 | | initial tag read of the second entry, then it becomes 0 for the |
10854 | | first entry for real printing etc. */ |
10855 | 0 | int tagno = -2; |
10856 | | /* Initialize it due to a false compiler warning. */ |
10857 | 0 | uint64_t second_abbrev_tag = -1; |
10858 | 0 | unsigned char *entryptr; |
10859 | |
|
10860 | 0 | p = name_table_string_offsets + namei * offset_size; |
10861 | 0 | SAFE_BYTE_GET (string_offset, p, offset_size, unit_end); |
10862 | | |
10863 | 0 | p = name_table_entry_offsets + namei * offset_size; |
10864 | 0 | SAFE_BYTE_GET (entry_offset, p, offset_size, unit_end); |
10865 | | |
10866 | | /* The name table is indexed starting at 1 according to |
10867 | | DWARF, so be sure to use the DWARF numbering here. */ |
10868 | 0 | printf ("[%3u] ", namei + 1); |
10869 | 0 | if (bucket_count != 0) |
10870 | 0 | printf ("#%08x ", hash_table_hashes[namei]); |
10871 | |
|
10872 | 0 | printf ("%s:", fetch_indirect_string (string_offset)); |
10873 | |
|
10874 | 0 | entryptr = entry_pool + entry_offset; |
10875 | | /* PR 31456: Check for invalid entry offset. */ |
10876 | 0 | if (entryptr < entry_pool || entryptr >= unit_end) |
10877 | 0 | { |
10878 | 0 | warn (_("Invalid entry offset value: %" PRIx64 "\n"), entry_offset); |
10879 | 0 | break; |
10880 | 0 | } |
10881 | | |
10882 | 0 | for (;;) |
10883 | 0 | { |
10884 | 0 | uint64_t abbrev_tag; |
10885 | 0 | uint64_t dwarf_tag; |
10886 | 0 | const struct abbrev_lookup_entry *entry; |
10887 | 0 | uint64_t this_entry = entryptr - entry_pool; |
10888 | |
|
10889 | 0 | READ_ULEB (abbrev_tag, entryptr, unit_end); |
10890 | 0 | if (tagno == -1) |
10891 | 0 | { |
10892 | 0 | second_abbrev_tag = abbrev_tag; |
10893 | 0 | tagno = 0; |
10894 | 0 | entryptr = entry_pool + entry_offset; |
10895 | 0 | continue; |
10896 | 0 | } |
10897 | 0 | if (abbrev_tag == 0) |
10898 | 0 | break; |
10899 | 0 | if (tagno >= 0) |
10900 | 0 | printf ("%s<%#" PRIx64 "><%" PRIu64 ">", |
10901 | 0 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), |
10902 | 0 | this_entry, abbrev_tag); |
10903 | |
|
10904 | 0 | for (entry = abbrev_lookup; |
10905 | 0 | entry < abbrev_lookup + abbrev_lookup_used; |
10906 | 0 | entry++) |
10907 | 0 | if (entry->abbrev_tag == abbrev_tag) |
10908 | 0 | break; |
10909 | 0 | if (entry >= abbrev_lookup + abbrev_lookup_used) |
10910 | 0 | { |
10911 | 0 | warn (_("Undefined abbreviation tag %" PRId64 |
10912 | 0 | " in unit %#tx in the debug_names section\n"), |
10913 | 0 | abbrev_tag, |
10914 | 0 | unit_start - section->start); |
10915 | 0 | break; |
10916 | 0 | } |
10917 | 0 | abbrevptr = entry->abbrev_lookup_ptr; |
10918 | 0 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
10919 | 0 | if (tagno >= 0) |
10920 | 0 | printf (" %s", get_TAG_name (dwarf_tag)); |
10921 | 0 | for (;;) |
10922 | 0 | { |
10923 | 0 | uint64_t xindex, form; |
10924 | |
|
10925 | 0 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); |
10926 | 0 | READ_ULEB (form, abbrevptr, abbrev_table_end); |
10927 | 0 | if (xindex == 0 && form == 0) |
10928 | 0 | break; |
10929 | | |
10930 | 0 | if (tagno >= 0) |
10931 | 0 | printf (" %s", get_IDX_name (xindex)); |
10932 | 0 | entryptr = read_and_display_attr_value (0, form, 0, |
10933 | 0 | unit_start, entryptr, unit_end, |
10934 | 0 | 0, 0, offset_size, |
10935 | 0 | dwarf_version, NULL, |
10936 | 0 | (tagno < 0), section, |
10937 | 0 | NULL, '=', -1); |
10938 | 0 | } |
10939 | 0 | ++tagno; |
10940 | 0 | } |
10941 | 0 | if (tagno <= 0) |
10942 | 0 | printf (_(" <no entries>")); |
10943 | 0 | putchar ('\n'); |
10944 | 0 | } |
10945 | | |
10946 | 0 | free (abbrev_lookup); |
10947 | 0 | } |
10948 | | |
10949 | 0 | return 1; |
10950 | 0 | } |
10951 | | |
10952 | | static int |
10953 | | display_debug_links (struct dwarf_section * section, |
10954 | | void * file ATTRIBUTE_UNUSED) |
10955 | 210 | { |
10956 | 210 | const unsigned char * filename; |
10957 | 210 | unsigned int filelen; |
10958 | | |
10959 | 210 | introduce (section, false); |
10960 | | |
10961 | | /* The .gnu_debuglink section is formatted as: |
10962 | | (c-string) Filename. |
10963 | | (padding) If needed to reach a 4 byte boundary. |
10964 | | (uint32_t) CRC32 value. |
10965 | | |
10966 | | The .gnu_debugaltlink section is formatted as: |
10967 | | (c-string) Filename. |
10968 | | (binary) Build-ID. */ |
10969 | | |
10970 | 210 | filename = section->start; |
10971 | 210 | filelen = strnlen ((const char *) filename, section->size); |
10972 | 210 | if (filelen == section->size) |
10973 | 2 | { |
10974 | 2 | warn (_("The debuglink filename is corrupt/missing\n")); |
10975 | 2 | return 0; |
10976 | 2 | } |
10977 | | |
10978 | 208 | printf (_(" Separate debug info file: %s\n"), filename); |
10979 | | |
10980 | 208 | if (startswith (section->name, ".gnu_debuglink")) |
10981 | 208 | { |
10982 | 208 | unsigned int crc32; |
10983 | 208 | unsigned int crc_offset; |
10984 | | |
10985 | 208 | crc_offset = filelen + 1; |
10986 | 208 | crc_offset = (crc_offset + 3) & ~3; |
10987 | 208 | if (crc_offset + 4 > section->size) |
10988 | 1 | { |
10989 | 1 | warn (_("CRC offset missing/truncated\n")); |
10990 | 1 | return 0; |
10991 | 1 | } |
10992 | | |
10993 | 207 | crc32 = byte_get (filename + crc_offset, 4); |
10994 | | |
10995 | 207 | printf (_(" CRC value: %#x\n"), crc32); |
10996 | | |
10997 | 207 | if (crc_offset + 4 < section->size) |
10998 | 16 | { |
10999 | 16 | warn (_("There are %#" PRIx64 |
11000 | 16 | " extraneous bytes at the end of the section\n"), |
11001 | 16 | section->size - (crc_offset + 4)); |
11002 | 16 | return 0; |
11003 | 16 | } |
11004 | 207 | } |
11005 | 0 | else /* startswith (section->name, ".gnu_debugaltlink") */ |
11006 | 0 | { |
11007 | 0 | const unsigned char *build_id = section->start + filelen + 1; |
11008 | 0 | size_t build_id_len = section->size - (filelen + 1); |
11009 | 0 | size_t printed; |
11010 | | |
11011 | | /* FIXME: Should we support smaller build-id notes ? */ |
11012 | 0 | if (build_id_len < 0x14) |
11013 | 0 | { |
11014 | 0 | warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len); |
11015 | 0 | return 0; |
11016 | 0 | } |
11017 | | |
11018 | 0 | printed = printf (_(" Build-ID (%#zx bytes):"), build_id_len); |
11019 | 0 | display_data (printed, build_id, build_id_len); |
11020 | 0 | putchar ('\n'); |
11021 | 0 | } |
11022 | | |
11023 | 191 | putchar ('\n'); |
11024 | 191 | return 1; |
11025 | 208 | } |
11026 | | |
11027 | | static int |
11028 | | display_gdb_index (struct dwarf_section *section, |
11029 | | void *file ATTRIBUTE_UNUSED) |
11030 | 0 | { |
11031 | 0 | unsigned char *start = section->start; |
11032 | 0 | uint32_t version; |
11033 | 0 | uint32_t cu_list_offset, tu_list_offset; |
11034 | 0 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset, |
11035 | 0 | shortcut_table_offset; |
11036 | 0 | unsigned int cu_list_elements, tu_list_elements; |
11037 | 0 | unsigned int address_table_elements, symbol_table_slots; |
11038 | 0 | unsigned char *cu_list, *tu_list; |
11039 | 0 | unsigned char *address_table, *symbol_table, *shortcut_table, *constant_pool; |
11040 | 0 | unsigned int i; |
11041 | | |
11042 | | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ |
11043 | |
|
11044 | 0 | introduce (section, false); |
11045 | |
|
11046 | 0 | version = section->size < 4 ? 0 : byte_get_little_endian (start, 4); |
11047 | 0 | size_t header_size = (version < 9 ? 6 : 7) * sizeof (uint32_t); |
11048 | 0 | if (section->size < header_size) |
11049 | 0 | { |
11050 | 0 | warn (_("Truncated header in the %s section.\n"), section->name); |
11051 | 0 | return 0; |
11052 | 0 | } |
11053 | | |
11054 | 0 | printf (_("Version %lu\n"), (unsigned long) version); |
11055 | | |
11056 | | /* Prior versions are obsolete, and future versions may not be |
11057 | | backwards compatible. */ |
11058 | 0 | if (version < 3 || version > 9) |
11059 | 0 | { |
11060 | 0 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
11061 | 0 | return 0; |
11062 | 0 | } |
11063 | 0 | if (version < 4) |
11064 | 0 | warn (_("The address table data in version 3 may be wrong.\n")); |
11065 | 0 | if (version < 5) |
11066 | 0 | warn (_("Version 4 does not support case insensitive lookups.\n")); |
11067 | 0 | if (version < 6) |
11068 | 0 | warn (_("Version 5 does not include inlined functions.\n")); |
11069 | 0 | if (version < 7) |
11070 | 0 | warn (_("Version 6 does not include symbol attributes.\n")); |
11071 | | /* Version 7 indices generated by Gold have bad type unit references, |
11072 | | PR binutils/15021. But we don't know if the index was generated by |
11073 | | Gold or not, so to avoid worrying users with gdb-generated indices |
11074 | | we say nothing for version 7 here. */ |
11075 | |
|
11076 | 0 | cu_list_offset = byte_get_little_endian (start + 4, 4); |
11077 | 0 | tu_list_offset = byte_get_little_endian (start + 8, 4); |
11078 | 0 | address_table_offset = byte_get_little_endian (start + 12, 4); |
11079 | 0 | symbol_table_offset = byte_get_little_endian (start + 16, 4); |
11080 | 0 | shortcut_table_offset = byte_get_little_endian (start + 20, 4); |
11081 | 0 | if (version < 9) |
11082 | 0 | constant_pool_offset = shortcut_table_offset; |
11083 | 0 | else |
11084 | 0 | constant_pool_offset = byte_get_little_endian (start + 24, 4); |
11085 | |
|
11086 | 0 | if (cu_list_offset > section->size |
11087 | 0 | || tu_list_offset > section->size |
11088 | 0 | || address_table_offset > section->size |
11089 | 0 | || symbol_table_offset > section->size |
11090 | 0 | || shortcut_table_offset > section->size |
11091 | 0 | || constant_pool_offset > section->size |
11092 | 0 | || tu_list_offset < cu_list_offset |
11093 | 0 | || address_table_offset < tu_list_offset |
11094 | 0 | || symbol_table_offset < address_table_offset |
11095 | 0 | || shortcut_table_offset < symbol_table_offset |
11096 | 0 | || constant_pool_offset < shortcut_table_offset) |
11097 | 0 | { |
11098 | 0 | warn (_("Corrupt header in the %s section.\n"), section->name); |
11099 | 0 | return 0; |
11100 | 0 | } |
11101 | | |
11102 | 0 | cu_list_elements = (tu_list_offset - cu_list_offset) / 16; |
11103 | 0 | tu_list_elements = (address_table_offset - tu_list_offset) / 24; |
11104 | 0 | address_table_elements = (symbol_table_offset - address_table_offset) / 20; |
11105 | 0 | symbol_table_slots = (shortcut_table_offset - symbol_table_offset) / 8; |
11106 | |
|
11107 | 0 | cu_list = start + cu_list_offset; |
11108 | 0 | tu_list = start + tu_list_offset; |
11109 | 0 | address_table = start + address_table_offset; |
11110 | 0 | symbol_table = start + symbol_table_offset; |
11111 | 0 | shortcut_table = start + shortcut_table_offset; |
11112 | 0 | constant_pool = start + constant_pool_offset; |
11113 | |
|
11114 | 0 | printf (_("\nCU table:\n")); |
11115 | 0 | for (i = 0; i < cu_list_elements; i++) |
11116 | 0 | { |
11117 | 0 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 16, 8); |
11118 | 0 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 16 + 8, 8); |
11119 | |
|
11120 | 0 | printf ("[%3u] %#" PRIx64 " - %#" PRIx64 "\n", |
11121 | 0 | i, cu_offset, cu_offset + cu_length - 1); |
11122 | 0 | } |
11123 | |
|
11124 | 0 | printf (_("\nTU table:\n")); |
11125 | 0 | for (i = 0; i < tu_list_elements; i++) |
11126 | 0 | { |
11127 | 0 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 24, 8); |
11128 | 0 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 24 + 8, 8); |
11129 | 0 | uint64_t signature = byte_get_little_endian (tu_list + i * 24 + 16, 8); |
11130 | |
|
11131 | 0 | printf ("[%3u] %#" PRIx64 " %#" PRIx64 " ", |
11132 | 0 | i, tu_offset, type_offset); |
11133 | 0 | print_hex_ns (signature, 8); |
11134 | 0 | printf ("\n"); |
11135 | 0 | } |
11136 | |
|
11137 | 0 | printf (_("\nAddress table:\n")); |
11138 | 0 | for (i = 0; i < address_table_elements; i++) |
11139 | 0 | { |
11140 | 0 | uint64_t low = byte_get_little_endian (address_table + i * 20, 8); |
11141 | 0 | uint64_t high = byte_get_little_endian (address_table + i * 20 + 8, 8); |
11142 | 0 | uint32_t cu_index = byte_get_little_endian (address_table + i * 20 + 16, 4); |
11143 | |
|
11144 | 0 | print_hex (low, 8); |
11145 | 0 | print_hex (high, 8); |
11146 | 0 | printf ("%" PRIu32 "\n", cu_index); |
11147 | 0 | } |
11148 | |
|
11149 | 0 | printf (_("\nSymbol table:\n")); |
11150 | 0 | for (i = 0; i < symbol_table_slots; ++i) |
11151 | 0 | { |
11152 | 0 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); |
11153 | 0 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); |
11154 | 0 | uint32_t num_cus, cu; |
11155 | |
|
11156 | 0 | if (name_offset != 0 |
11157 | 0 | || cu_vector_offset != 0) |
11158 | 0 | { |
11159 | 0 | unsigned int j; |
11160 | | |
11161 | | /* PR 17531: file: 5b7b07ad. */ |
11162 | 0 | if (name_offset >= section->size - constant_pool_offset) |
11163 | 0 | { |
11164 | 0 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); |
11165 | 0 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), |
11166 | 0 | name_offset, i); |
11167 | 0 | } |
11168 | 0 | else |
11169 | 0 | printf ("[%3u] %.*s:", i, |
11170 | 0 | (int) (section->size - (constant_pool_offset + name_offset)), |
11171 | 0 | constant_pool + name_offset); |
11172 | |
|
11173 | 0 | if (section->size - constant_pool_offset < 4 |
11174 | 0 | || cu_vector_offset > section->size - constant_pool_offset - 4) |
11175 | 0 | { |
11176 | 0 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); |
11177 | 0 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), |
11178 | 0 | cu_vector_offset, i); |
11179 | 0 | continue; |
11180 | 0 | } |
11181 | | |
11182 | 0 | num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4); |
11183 | |
|
11184 | 0 | if ((uint64_t) num_cus * 4 > section->size - (constant_pool_offset |
11185 | 0 | + cu_vector_offset + 4)) |
11186 | 0 | { |
11187 | 0 | printf ("<invalid number of CUs: %d>\n", num_cus); |
11188 | 0 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
11189 | 0 | num_cus, i); |
11190 | 0 | continue; |
11191 | 0 | } |
11192 | | |
11193 | 0 | if (num_cus > 1) |
11194 | 0 | printf ("\n"); |
11195 | |
|
11196 | 0 | for (j = 0; j < num_cus; ++j) |
11197 | 0 | { |
11198 | 0 | int is_static; |
11199 | 0 | gdb_index_symbol_kind kind; |
11200 | |
|
11201 | 0 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
11202 | 0 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
11203 | 0 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
11204 | 0 | cu = GDB_INDEX_CU_VALUE (cu); |
11205 | | /* Convert to TU number if it's for a type unit. */ |
11206 | 0 | if (cu >= cu_list_elements) |
11207 | 0 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
11208 | 0 | (unsigned long) cu - cu_list_elements); |
11209 | 0 | else |
11210 | 0 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
11211 | |
|
11212 | 0 | printf (" [%s, %s]", |
11213 | 0 | is_static ? _("static") : _("global"), |
11214 | 0 | get_gdb_index_symbol_kind_name (kind)); |
11215 | 0 | if (num_cus > 1) |
11216 | 0 | printf ("\n"); |
11217 | 0 | } |
11218 | 0 | if (num_cus <= 1) |
11219 | 0 | printf ("\n"); |
11220 | 0 | } |
11221 | 0 | } |
11222 | |
|
11223 | 0 | if (version >= 9) |
11224 | 0 | { |
11225 | 0 | printf (_("\nShortcut table:\n")); |
11226 | |
|
11227 | 0 | if (shortcut_table_offset + 8 > constant_pool_offset) |
11228 | 0 | { |
11229 | 0 | warn (_("Corrupt shortcut table in the %s section.\n"), section->name); |
11230 | 0 | return 0; |
11231 | 0 | } |
11232 | | |
11233 | 0 | uint32_t lang = byte_get_little_endian (shortcut_table, 4); |
11234 | 0 | printf (_("Language of main: ")); |
11235 | 0 | display_lang (lang); |
11236 | 0 | printf ("\n"); |
11237 | |
|
11238 | 0 | printf (_("Name of main: ")); |
11239 | 0 | if (lang == 0) |
11240 | 0 | printf (_("<unknown>\n")); |
11241 | 0 | else |
11242 | 0 | { |
11243 | 0 | uint32_t name_offset = byte_get_little_endian (shortcut_table + 4, 4); |
11244 | 0 | if (name_offset >= section->size - constant_pool_offset) |
11245 | 0 | { |
11246 | 0 | printf (_("<corrupt offset: %x>\n"), name_offset); |
11247 | 0 | warn (_("Corrupt name offset of 0x%x found for name of main\n"), |
11248 | 0 | name_offset); |
11249 | 0 | } |
11250 | 0 | else |
11251 | 0 | printf ("%s\n", constant_pool + name_offset); |
11252 | 0 | } |
11253 | 0 | } |
11254 | | |
11255 | 0 | return 1; |
11256 | 0 | } |
11257 | | |
11258 | | /* Pre-allocate enough space for the CU/TU sets needed. */ |
11259 | | |
11260 | | static void |
11261 | | prealloc_cu_tu_list (unsigned int nshndx) |
11262 | 0 | { |
11263 | 0 | if (nshndx == 0) |
11264 | | /* Always allocate at least one entry for the end-marker. */ |
11265 | 0 | nshndx = 1; |
11266 | |
|
11267 | 0 | if (shndx_pool == NULL) |
11268 | 0 | { |
11269 | 0 | shndx_pool_size = nshndx; |
11270 | 0 | shndx_pool_used = 0; |
11271 | 0 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, |
11272 | 0 | sizeof (unsigned int)); |
11273 | 0 | } |
11274 | 0 | else |
11275 | 0 | { |
11276 | 0 | shndx_pool_size = shndx_pool_used + nshndx; |
11277 | 0 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, |
11278 | 0 | sizeof (unsigned int)); |
11279 | 0 | } |
11280 | 0 | } |
11281 | | |
11282 | | static void |
11283 | | add_shndx_to_cu_tu_entry (unsigned int shndx) |
11284 | 0 | { |
11285 | 0 | shndx_pool [shndx_pool_used++] = shndx; |
11286 | 0 | } |
11287 | | |
11288 | | static void |
11289 | | end_cu_tu_entry (void) |
11290 | 0 | { |
11291 | 0 | shndx_pool [shndx_pool_used++] = 0; |
11292 | 0 | } |
11293 | | |
11294 | | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
11295 | | |
11296 | | static const char * |
11297 | | get_DW_SECT_short_name (unsigned int dw_sect) |
11298 | 0 | { |
11299 | 0 | static char buf[16]; |
11300 | |
|
11301 | 0 | switch (dw_sect) |
11302 | 0 | { |
11303 | 0 | case DW_SECT_INFO: |
11304 | 0 | return "info"; |
11305 | 0 | case DW_SECT_TYPES: |
11306 | 0 | return "types"; |
11307 | 0 | case DW_SECT_ABBREV: |
11308 | 0 | return "abbrev"; |
11309 | 0 | case DW_SECT_LINE: |
11310 | 0 | return "line"; |
11311 | 0 | case DW_SECT_LOC: |
11312 | 0 | return "loc"; |
11313 | 0 | case DW_SECT_STR_OFFSETS: |
11314 | 0 | return "str_off"; |
11315 | 0 | case DW_SECT_MACINFO: |
11316 | 0 | return "macinfo"; |
11317 | 0 | case DW_SECT_MACRO: |
11318 | 0 | return "macro"; |
11319 | 0 | default: |
11320 | 0 | break; |
11321 | 0 | } |
11322 | | |
11323 | 0 | snprintf (buf, sizeof (buf), "%d", dw_sect); |
11324 | 0 | return buf; |
11325 | 0 | } |
11326 | | |
11327 | | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. |
11328 | | These sections are extensions for Fission. |
11329 | | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ |
11330 | | |
11331 | | static bool |
11332 | | process_cu_tu_index (struct dwarf_section *section, int do_display) |
11333 | 19 | { |
11334 | 19 | unsigned char *phdr = section->start; |
11335 | 19 | unsigned char *limit = phdr + section->size; |
11336 | 19 | unsigned char *phash; |
11337 | 19 | unsigned char *pindex; |
11338 | 19 | unsigned char *ppool; |
11339 | 19 | unsigned int version; |
11340 | 19 | unsigned int ncols = 0; |
11341 | 19 | unsigned int nused; |
11342 | 19 | unsigned int nslots; |
11343 | 19 | unsigned int i; |
11344 | 19 | unsigned int j; |
11345 | 19 | uint64_t signature; |
11346 | 19 | size_t total; |
11347 | | |
11348 | | /* PR 17512: file: 002-168123-0.004. */ |
11349 | 19 | if (phdr == NULL) |
11350 | 0 | { |
11351 | 0 | warn (_("Section %s is empty\n"), section->name); |
11352 | 0 | return false; |
11353 | 0 | } |
11354 | | /* PR 17512: file: 002-376-0.004. */ |
11355 | 19 | if (section->size < 24) |
11356 | 4 | { |
11357 | 4 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
11358 | 4 | section->name); |
11359 | 4 | return false; |
11360 | 4 | } |
11361 | | |
11362 | 15 | phash = phdr; |
11363 | 15 | SAFE_BYTE_GET_AND_INC (version, phash, 4, limit); |
11364 | 15 | if (version >= 2) |
11365 | 15 | SAFE_BYTE_GET_AND_INC (ncols, phash, 4, limit); |
11366 | 15 | SAFE_BYTE_GET_AND_INC (nused, phash, 4, limit); |
11367 | 15 | SAFE_BYTE_GET_AND_INC (nslots, phash, 4, limit); |
11368 | | |
11369 | 15 | pindex = phash + (size_t) nslots * 8; |
11370 | 15 | ppool = pindex + (size_t) nslots * 4; |
11371 | | |
11372 | 15 | if (do_display) |
11373 | 15 | { |
11374 | 15 | introduce (section, false); |
11375 | | |
11376 | 15 | printf (_(" Version: %u\n"), version); |
11377 | 15 | if (version >= 2) |
11378 | 7 | printf (_(" Number of columns: %u\n"), ncols); |
11379 | 15 | printf (_(" Number of used entries: %u\n"), nused); |
11380 | 15 | printf (_(" Number of slots: %u\n\n"), nslots); |
11381 | 15 | } |
11382 | | |
11383 | | /* PR 17531: file: 45d69832. */ |
11384 | 15 | if (_mul_overflow ((size_t) nslots, 12, &total) |
11385 | 15 | || total > (size_t) (limit - phash)) |
11386 | 4 | { |
11387 | 4 | warn (ngettext ("Section %s is too small for %u slot\n", |
11388 | 4 | "Section %s is too small for %u slots\n", |
11389 | 4 | nslots), |
11390 | 4 | section->name, nslots); |
11391 | 4 | return false; |
11392 | 4 | } |
11393 | | |
11394 | 11 | if (version == 1) |
11395 | 2 | { |
11396 | 2 | unsigned char *shndx_list; |
11397 | 2 | unsigned int shndx; |
11398 | | |
11399 | 2 | if (!do_display) |
11400 | 0 | { |
11401 | 0 | prealloc_cu_tu_list ((limit - ppool) / 4); |
11402 | 0 | for (shndx_list = ppool + 4; shndx_list <= limit - 4; shndx_list += 4) |
11403 | 0 | { |
11404 | 0 | shndx = byte_get (shndx_list, 4); |
11405 | 0 | add_shndx_to_cu_tu_entry (shndx); |
11406 | 0 | } |
11407 | 0 | end_cu_tu_entry (); |
11408 | 0 | } |
11409 | 2 | else |
11410 | 2 | for (i = 0; i < nslots; i++) |
11411 | 0 | { |
11412 | 0 | SAFE_BYTE_GET (signature, phash, 8, limit); |
11413 | 0 | if (signature != 0) |
11414 | 0 | { |
11415 | 0 | SAFE_BYTE_GET (j, pindex, 4, limit); |
11416 | 0 | shndx_list = ppool + j * 4; |
11417 | | /* PR 17531: file: 705e010d. */ |
11418 | 0 | if (shndx_list < ppool) |
11419 | 0 | { |
11420 | 0 | warn (_("Section index pool located before start of section\n")); |
11421 | 0 | return false; |
11422 | 0 | } |
11423 | | |
11424 | 0 | printf (_(" [%3d] Signature: %#" PRIx64 " Sections: "), |
11425 | 0 | i, signature); |
11426 | 0 | for (;;) |
11427 | 0 | { |
11428 | 0 | if (shndx_list >= limit) |
11429 | 0 | { |
11430 | 0 | warn (_("Section %s too small for shndx pool\n"), |
11431 | 0 | section->name); |
11432 | 0 | return false; |
11433 | 0 | } |
11434 | 0 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
11435 | 0 | if (shndx == 0) |
11436 | 0 | break; |
11437 | 0 | printf (" %d", shndx); |
11438 | 0 | shndx_list += 4; |
11439 | 0 | } |
11440 | 0 | printf ("\n"); |
11441 | 0 | } |
11442 | 0 | phash += 8; |
11443 | 0 | pindex += 4; |
11444 | 0 | } |
11445 | 2 | } |
11446 | 9 | else if (version == 2) |
11447 | 0 | { |
11448 | 0 | unsigned int val; |
11449 | 0 | unsigned int dw_sect; |
11450 | 0 | unsigned char *ph = phash; |
11451 | 0 | unsigned char *pi = pindex; |
11452 | 0 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
11453 | 0 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; |
11454 | 0 | bool is_tu_index; |
11455 | 0 | struct cu_tu_set *this_set = NULL; |
11456 | 0 | unsigned int row; |
11457 | 0 | unsigned char *prow; |
11458 | 0 | size_t temp; |
11459 | |
|
11460 | 0 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; |
11461 | | |
11462 | | /* PR 17531: file: 0dd159bf. |
11463 | | Check for integer overflow (can occur when size_t is 32-bit) |
11464 | | with overlarge ncols or nused values. */ |
11465 | 0 | if (nused == -1u |
11466 | 0 | || _mul_overflow ((size_t) ncols, 4, &temp) |
11467 | 0 | || _mul_overflow ((size_t) nused + 1, temp, &total) |
11468 | 0 | || total > (size_t) (limit - ppool) |
11469 | | /* PR 30227: ncols could be 0. */ |
11470 | 0 | || _mul_overflow ((size_t) nused + 1, 4, &total) |
11471 | 0 | || total > (size_t) (limit - ppool)) |
11472 | 0 | { |
11473 | 0 | warn (_("Section %s too small for offset and size tables\n"), |
11474 | 0 | section->name); |
11475 | 0 | return false; |
11476 | 0 | } |
11477 | | |
11478 | 0 | if (do_display) |
11479 | 0 | { |
11480 | 0 | printf (_(" Offset table\n")); |
11481 | 0 | printf (" slot %-16s ", |
11482 | 0 | is_tu_index ? _("signature") : _("dwo_id")); |
11483 | 0 | } |
11484 | 0 | else |
11485 | 0 | { |
11486 | 0 | if (is_tu_index) |
11487 | 0 | { |
11488 | 0 | tu_count = nused; |
11489 | 0 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
11490 | 0 | this_set = tu_sets; |
11491 | 0 | } |
11492 | 0 | else |
11493 | 0 | { |
11494 | 0 | cu_count = nused; |
11495 | 0 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
11496 | 0 | this_set = cu_sets; |
11497 | 0 | } |
11498 | 0 | } |
11499 | |
|
11500 | 0 | if (do_display) |
11501 | 0 | { |
11502 | 0 | for (j = 0; j < ncols; j++) |
11503 | 0 | { |
11504 | 0 | unsigned char *p = ppool + j * 4; |
11505 | 0 | SAFE_BYTE_GET (dw_sect, p, 4, limit); |
11506 | 0 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
11507 | 0 | } |
11508 | 0 | printf ("\n"); |
11509 | 0 | } |
11510 | | |
11511 | 0 | for (i = 0; i < nslots; i++) |
11512 | 0 | { |
11513 | 0 | SAFE_BYTE_GET (signature, ph, 8, limit); |
11514 | | |
11515 | 0 | SAFE_BYTE_GET (row, pi, 4, limit); |
11516 | 0 | if (row != 0) |
11517 | 0 | { |
11518 | | /* PR 17531: file: a05f6ab3. */ |
11519 | 0 | if (row > nused) |
11520 | 0 | { |
11521 | 0 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), |
11522 | 0 | row, nused); |
11523 | 0 | return false; |
11524 | 0 | } |
11525 | | |
11526 | 0 | if (!do_display) |
11527 | 0 | { |
11528 | 0 | size_t num_copy = sizeof (uint64_t); |
11529 | |
|
11530 | 0 | memcpy (&this_set[row - 1].signature, ph, num_copy); |
11531 | 0 | } |
11532 | |
|
11533 | 0 | prow = poffsets + (row - 1) * ncols * 4; |
11534 | 0 | if (do_display) |
11535 | 0 | printf (" [%3d] %#" PRIx64, i, signature); |
11536 | 0 | for (j = 0; j < ncols; j++) |
11537 | 0 | { |
11538 | 0 | unsigned char *p = prow + j * 4; |
11539 | 0 | SAFE_BYTE_GET (val, p, 4, limit); |
11540 | 0 | if (do_display) |
11541 | 0 | printf (" %8d", val); |
11542 | 0 | else |
11543 | 0 | { |
11544 | 0 | p = ppool + j * 4; |
11545 | 0 | SAFE_BYTE_GET (dw_sect, p, 4, limit); |
11546 | | |
11547 | | /* PR 17531: file: 10796eb3. */ |
11548 | 0 | if (dw_sect >= DW_SECT_MAX) |
11549 | 0 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); |
11550 | 0 | else |
11551 | 0 | this_set [row - 1].section_offsets [dw_sect] = val; |
11552 | 0 | } |
11553 | 0 | } |
11554 | | |
11555 | 0 | if (do_display) |
11556 | 0 | printf ("\n"); |
11557 | 0 | } |
11558 | 0 | ph += 8; |
11559 | 0 | pi += 4; |
11560 | 0 | } |
11561 | | |
11562 | 0 | ph = phash; |
11563 | 0 | pi = pindex; |
11564 | 0 | if (do_display) |
11565 | 0 | { |
11566 | 0 | printf ("\n"); |
11567 | 0 | printf (_(" Size table\n")); |
11568 | 0 | printf (" slot %-16s ", |
11569 | 0 | is_tu_index ? _("signature") : _("dwo_id")); |
11570 | 0 | } |
11571 | |
|
11572 | 0 | for (j = 0; j < ncols; j++) |
11573 | 0 | { |
11574 | 0 | unsigned char *p = ppool + j * 4; |
11575 | 0 | SAFE_BYTE_GET (val, p, 4, limit); |
11576 | 0 | if (do_display) |
11577 | 0 | printf (" %8s", get_DW_SECT_short_name (val)); |
11578 | 0 | } |
11579 | | |
11580 | 0 | if (do_display) |
11581 | 0 | printf ("\n"); |
11582 | |
|
11583 | 0 | for (i = 0; i < nslots; i++) |
11584 | 0 | { |
11585 | 0 | SAFE_BYTE_GET (signature, ph, 8, limit); |
11586 | | |
11587 | 0 | SAFE_BYTE_GET (row, pi, 4, limit); |
11588 | 0 | if (row != 0) |
11589 | 0 | { |
11590 | 0 | prow = psizes + (row - 1) * ncols * 4; |
11591 | |
|
11592 | 0 | if (do_display) |
11593 | 0 | printf (" [%3d] %#" PRIx64, i, signature); |
11594 | |
|
11595 | 0 | for (j = 0; j < ncols; j++) |
11596 | 0 | { |
11597 | 0 | unsigned char *p = prow + j * 4; |
11598 | | |
11599 | | /* PR 28645: Check for overflow. Since we do not know how |
11600 | | many populated rows there will be, we cannot just |
11601 | | perform a single check at the start of this function. */ |
11602 | 0 | if (p > (limit - 4)) |
11603 | 0 | { |
11604 | 0 | if (do_display) |
11605 | 0 | printf ("\n"); |
11606 | 0 | warn (_("Too many rows/columns in DWARF index section %s\n"), |
11607 | 0 | section->name); |
11608 | 0 | return false; |
11609 | 0 | } |
11610 | | |
11611 | 0 | SAFE_BYTE_GET (val, p, 4, limit); |
11612 | | |
11613 | 0 | if (do_display) |
11614 | 0 | printf (" %8d", val); |
11615 | 0 | else |
11616 | 0 | { |
11617 | 0 | p = ppool + j * 4; |
11618 | 0 | SAFE_BYTE_GET (dw_sect, p, 4, limit); |
11619 | 0 | if (dw_sect >= DW_SECT_MAX) |
11620 | 0 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); |
11621 | 0 | else |
11622 | 0 | this_set [row - 1].section_sizes [dw_sect] = val; |
11623 | 0 | } |
11624 | 0 | } |
11625 | | |
11626 | 0 | if (do_display) |
11627 | 0 | printf ("\n"); |
11628 | 0 | } |
11629 | | |
11630 | 0 | ph += 8; |
11631 | 0 | pi += 4; |
11632 | 0 | } |
11633 | 0 | } |
11634 | 9 | else if (do_display) |
11635 | 9 | printf (_(" Unsupported version (%d)\n"), version); |
11636 | | |
11637 | 11 | if (do_display) |
11638 | 11 | printf ("\n"); |
11639 | | |
11640 | 11 | return true; |
11641 | 11 | } |
11642 | | |
11643 | | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
11644 | | |
11645 | | /* Load the CU and TU indexes if present. This will build a list of |
11646 | | section sets that we can use to associate a .debug_info.dwo section |
11647 | | with its associated .debug_abbrev.dwo section in a .dwp file. */ |
11648 | | |
11649 | | static bool |
11650 | | load_cu_tu_indexes (void *file) |
11651 | 332 | { |
11652 | | /* If we have already loaded (or tried to load) the CU and TU indexes |
11653 | | then do not bother to repeat the task. */ |
11654 | 332 | if (cu_tu_indexes_read == -1) |
11655 | 332 | { |
11656 | 332 | cu_tu_indexes_read = true; |
11657 | | |
11658 | 332 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
11659 | 0 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
11660 | 0 | cu_tu_indexes_read = false; |
11661 | | |
11662 | 332 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
11663 | 0 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
11664 | 0 | cu_tu_indexes_read = false; |
11665 | 332 | } |
11666 | | |
11667 | 332 | return (bool) cu_tu_indexes_read; |
11668 | 332 | } |
11669 | | |
11670 | | /* Find the set of sections that includes section SHNDX. */ |
11671 | | |
11672 | | unsigned int * |
11673 | | find_cu_tu_set (void *file, unsigned int shndx) |
11674 | 0 | { |
11675 | 0 | unsigned int i; |
11676 | |
|
11677 | 0 | if (! load_cu_tu_indexes (file)) |
11678 | 0 | return NULL; |
11679 | | |
11680 | | /* Find SHNDX in the shndx pool. */ |
11681 | 0 | for (i = 0; i < shndx_pool_used; i++) |
11682 | 0 | if (shndx_pool [i] == shndx) |
11683 | 0 | break; |
11684 | |
|
11685 | 0 | if (i >= shndx_pool_used) |
11686 | 0 | return NULL; |
11687 | | |
11688 | | /* Now backup to find the first entry in the set. */ |
11689 | 0 | while (i > 0 && shndx_pool [i - 1] != 0) |
11690 | 0 | i--; |
11691 | |
|
11692 | 0 | return shndx_pool + i; |
11693 | 0 | } |
11694 | | |
11695 | | /* Display a .debug_cu_index or .debug_tu_index section. */ |
11696 | | |
11697 | | static int |
11698 | | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) |
11699 | 19 | { |
11700 | 19 | return process_cu_tu_index (section, 1); |
11701 | 19 | } |
11702 | | |
11703 | | static int |
11704 | | display_debug_not_supported (struct dwarf_section *section, |
11705 | | void *file ATTRIBUTE_UNUSED) |
11706 | 0 | { |
11707 | 0 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), |
11708 | 0 | section->name); |
11709 | |
|
11710 | 0 | return 1; |
11711 | 0 | } |
11712 | | |
11713 | | /* Like malloc, but takes two parameters like calloc. |
11714 | | Verifies that the first parameter is not too large. |
11715 | | Note: does *not* initialise the allocated memory to zero. */ |
11716 | | |
11717 | | void * |
11718 | | cmalloc (uint64_t nmemb, size_t size) |
11719 | 318k | { |
11720 | | /* Check for overflow. */ |
11721 | 318k | if (nmemb >= ~(size_t) 0 / size) |
11722 | 0 | return NULL; |
11723 | | |
11724 | 318k | return xmalloc (nmemb * size); |
11725 | 318k | } |
11726 | | |
11727 | | /* Like xmalloc, but takes two parameters like calloc. |
11728 | | Verifies that the first parameter is not too large. |
11729 | | Note: does *not* initialise the allocated memory to zero. */ |
11730 | | |
11731 | | void * |
11732 | | xcmalloc (uint64_t nmemb, size_t size) |
11733 | 241k | { |
11734 | | /* Check for overflow. */ |
11735 | 241k | if (nmemb >= ~(size_t) 0 / size) |
11736 | 0 | { |
11737 | 0 | fprintf (stderr, |
11738 | 0 | _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64 "\n"), |
11739 | 0 | nmemb); |
11740 | 0 | xexit (1); |
11741 | 0 | } |
11742 | | |
11743 | 241k | return xmalloc (nmemb * size); |
11744 | 241k | } |
11745 | | |
11746 | | /* Like xrealloc, but takes three parameters. |
11747 | | Verifies that the second parameter is not too large. |
11748 | | Note: does *not* initialise any new memory to zero. */ |
11749 | | |
11750 | | void * |
11751 | | xcrealloc (void *ptr, uint64_t nmemb, size_t size) |
11752 | 93.9k | { |
11753 | | /* Check for overflow. */ |
11754 | 93.9k | if (nmemb >= ~(size_t) 0 / size) |
11755 | 0 | { |
11756 | 0 | error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64 "\n"), |
11757 | 0 | nmemb); |
11758 | 0 | xexit (1); |
11759 | 0 | } |
11760 | | |
11761 | 93.9k | return xrealloc (ptr, nmemb * size); |
11762 | 93.9k | } |
11763 | | |
11764 | | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
11765 | | |
11766 | | void * |
11767 | | xcalloc2 (uint64_t nmemb, size_t size) |
11768 | 0 | { |
11769 | | /* Check for overflow. */ |
11770 | 0 | if (nmemb >= ~(size_t) 0 / size) |
11771 | 0 | { |
11772 | 0 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64 "\n"), |
11773 | 0 | nmemb); |
11774 | 0 | xexit (1); |
11775 | 0 | } |
11776 | | |
11777 | 0 | return xcalloc (nmemb, size); |
11778 | 0 | } |
11779 | | |
11780 | | static unsigned long |
11781 | | calc_gnu_debuglink_crc32 (unsigned long crc, |
11782 | | const unsigned char *buf, |
11783 | | size_t len) |
11784 | 0 | { |
11785 | 0 | static const unsigned long crc32_table[256] = |
11786 | 0 | { |
11787 | 0 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, |
11788 | 0 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, |
11789 | 0 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, |
11790 | 0 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, |
11791 | 0 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, |
11792 | 0 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, |
11793 | 0 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, |
11794 | 0 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, |
11795 | 0 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, |
11796 | 0 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, |
11797 | 0 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, |
11798 | 0 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, |
11799 | 0 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, |
11800 | 0 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, |
11801 | 0 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, |
11802 | 0 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, |
11803 | 0 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, |
11804 | 0 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, |
11805 | 0 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, |
11806 | 0 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, |
11807 | 0 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, |
11808 | 0 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, |
11809 | 0 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, |
11810 | 0 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, |
11811 | 0 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, |
11812 | 0 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, |
11813 | 0 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, |
11814 | 0 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, |
11815 | 0 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, |
11816 | 0 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, |
11817 | 0 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, |
11818 | 0 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, |
11819 | 0 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, |
11820 | 0 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, |
11821 | 0 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, |
11822 | 0 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, |
11823 | 0 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, |
11824 | 0 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, |
11825 | 0 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, |
11826 | 0 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, |
11827 | 0 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, |
11828 | 0 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, |
11829 | 0 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, |
11830 | 0 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, |
11831 | 0 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, |
11832 | 0 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, |
11833 | 0 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, |
11834 | 0 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, |
11835 | 0 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, |
11836 | 0 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, |
11837 | 0 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, |
11838 | 0 | 0x2d02ef8d |
11839 | 0 | }; |
11840 | 0 | const unsigned char *end; |
11841 | |
|
11842 | 0 | crc = ~crc & 0xffffffff; |
11843 | 0 | for (end = buf + len; buf < end; ++ buf) |
11844 | 0 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); |
11845 | 0 | return ~crc & 0xffffffff; |
11846 | 0 | } |
11847 | | |
11848 | | typedef bool (*check_func_type) (const char *, void *); |
11849 | | typedef const char *(* parse_func_type) (struct dwarf_section *, void *); |
11850 | | |
11851 | | static bool |
11852 | | check_gnu_debuglink (const char * pathname, void * crc_pointer) |
11853 | 0 | { |
11854 | 0 | static unsigned char buffer[8 * 1024]; |
11855 | 0 | FILE *f; |
11856 | 0 | size_t count; |
11857 | 0 | unsigned long crc = 0; |
11858 | 0 | void *sep_data; |
11859 | |
|
11860 | 0 | sep_data = open_debug_file (pathname); |
11861 | 0 | if (sep_data == NULL) |
11862 | 0 | return false; |
11863 | | |
11864 | | /* Yes - we are opening the file twice... */ |
11865 | 0 | f = fopen (pathname, "rb"); |
11866 | 0 | if (f == NULL) |
11867 | 0 | { |
11868 | | /* Paranoia: This should never happen. */ |
11869 | 0 | close_debug_file (sep_data); |
11870 | 0 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); |
11871 | 0 | return false; |
11872 | 0 | } |
11873 | | |
11874 | 0 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) |
11875 | 0 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); |
11876 | |
|
11877 | 0 | fclose (f); |
11878 | 0 | close_debug_file (sep_data); |
11879 | |
|
11880 | 0 | if (crc != * (unsigned long *) crc_pointer) |
11881 | 0 | { |
11882 | 0 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), |
11883 | 0 | pathname); |
11884 | 0 | return false; |
11885 | 0 | } |
11886 | | |
11887 | 0 | return true; |
11888 | 0 | } |
11889 | | |
11890 | | static const char * |
11891 | | parse_gnu_debuglink (struct dwarf_section * section, void * data) |
11892 | 0 | { |
11893 | 0 | const char * name; |
11894 | 0 | unsigned int crc_offset; |
11895 | 0 | unsigned long * crc32 = (unsigned long *) data; |
11896 | | |
11897 | | /* The name is first. |
11898 | | The CRC value is stored after the filename, aligned up to 4 bytes. */ |
11899 | 0 | name = (const char *) section->start; |
11900 | |
|
11901 | 0 | crc_offset = strnlen (name, section->size) + 1; |
11902 | 0 | if (crc_offset == 1) |
11903 | 0 | return NULL; |
11904 | 0 | crc_offset = (crc_offset + 3) & ~3; |
11905 | 0 | if (crc_offset + 4 > section->size) |
11906 | 0 | return NULL; |
11907 | | |
11908 | 0 | * crc32 = byte_get (section->start + crc_offset, 4); |
11909 | 0 | return name; |
11910 | 0 | } |
11911 | | |
11912 | | static bool |
11913 | | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) |
11914 | 0 | { |
11915 | 0 | void * sep_data = open_debug_file (filename); |
11916 | |
|
11917 | 0 | if (sep_data == NULL) |
11918 | 0 | return false; |
11919 | | |
11920 | | /* FIXME: We should now extract the build-id in the separate file |
11921 | | and check it... */ |
11922 | | |
11923 | 0 | close_debug_file (sep_data); |
11924 | 0 | return true; |
11925 | 0 | } |
11926 | | |
11927 | | typedef struct build_id_data |
11928 | | { |
11929 | | size_t len; |
11930 | | const unsigned char *data; |
11931 | | } Build_id_data; |
11932 | | |
11933 | | static const char * |
11934 | | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) |
11935 | 0 | { |
11936 | 0 | const char *name; |
11937 | 0 | size_t namelen; |
11938 | 0 | size_t id_len; |
11939 | 0 | Build_id_data *build_id_data; |
11940 | | |
11941 | | /* The name is first. |
11942 | | The build-id follows immediately, with no padding, up to the section's end. */ |
11943 | |
|
11944 | 0 | name = (const char *) section->start; |
11945 | 0 | namelen = strnlen (name, section->size) + 1; |
11946 | 0 | if (namelen == 1) |
11947 | 0 | return NULL; |
11948 | 0 | if (namelen >= section->size) |
11949 | 0 | return NULL; |
11950 | | |
11951 | 0 | id_len = section->size - namelen; |
11952 | 0 | if (id_len < 0x14) |
11953 | 0 | return NULL; |
11954 | | |
11955 | 0 | build_id_data = (Build_id_data *) data; |
11956 | 0 | build_id_data->len = id_len; |
11957 | 0 | build_id_data->data = section->start + namelen; |
11958 | |
|
11959 | 0 | return name; |
11960 | 0 | } |
11961 | | |
11962 | | static void |
11963 | | add_separate_debug_file (const char * filename, void * handle) |
11964 | 0 | { |
11965 | 0 | separate_info * i = xmalloc (sizeof * i); |
11966 | |
|
11967 | 0 | i->filename = filename; |
11968 | 0 | i->handle = handle; |
11969 | 0 | i->next = first_separate_info; |
11970 | 0 | first_separate_info = i; |
11971 | 0 | } |
11972 | | |
11973 | | #if HAVE_LIBDEBUGINFOD |
11974 | | /* Query debuginfod servers for the target debuglink or debugaltlink |
11975 | | file. If successful, store the path of the file in filename and |
11976 | | return TRUE, otherwise return FALSE. */ |
11977 | | |
11978 | | static bool |
11979 | | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, |
11980 | | char ** filename, |
11981 | | void * file) |
11982 | | { |
11983 | | size_t build_id_len; |
11984 | | unsigned char * build_id; |
11985 | | |
11986 | | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) |
11987 | | { |
11988 | | /* Get the build-id of file. */ |
11989 | | build_id = get_build_id (file); |
11990 | | build_id_len = 0; |
11991 | | } |
11992 | | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) |
11993 | | { |
11994 | | /* Get the build-id of the debugaltlink file. */ |
11995 | | unsigned int filelen; |
11996 | | |
11997 | | filelen = strnlen ((const char *)section->start, section->size); |
11998 | | if (filelen == section->size) |
11999 | | /* Corrupt debugaltlink. */ |
12000 | | return false; |
12001 | | |
12002 | | build_id = section->start + filelen + 1; |
12003 | | build_id_len = section->size - (filelen + 1); |
12004 | | |
12005 | | if (build_id_len == 0) |
12006 | | return false; |
12007 | | } |
12008 | | else |
12009 | | return false; |
12010 | | |
12011 | | if (build_id) |
12012 | | { |
12013 | | int fd; |
12014 | | debuginfod_client * client; |
12015 | | |
12016 | | client = debuginfod_begin (); |
12017 | | if (client == NULL) |
12018 | | return false; |
12019 | | |
12020 | | /* Query debuginfod servers for the target file. If found its path |
12021 | | will be stored in filename. */ |
12022 | | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); |
12023 | | debuginfod_end (client); |
12024 | | |
12025 | | /* Only free build_id if we allocated space for a hex string |
12026 | | in get_build_id (). */ |
12027 | | if (build_id_len == 0) |
12028 | | free (build_id); |
12029 | | |
12030 | | if (fd >= 0) |
12031 | | { |
12032 | | /* File successfully retrieved. Close fd since we want to |
12033 | | use open_debug_file () on filename instead. */ |
12034 | | close (fd); |
12035 | | return true; |
12036 | | } |
12037 | | } |
12038 | | |
12039 | | return false; |
12040 | | } |
12041 | | #endif /* HAVE_LIBDEBUGINFOD */ |
12042 | | |
12043 | | static void * |
12044 | | load_separate_debug_info (const char * main_filename, |
12045 | | struct dwarf_section * xlink, |
12046 | | parse_func_type parse_func, |
12047 | | check_func_type check_func, |
12048 | | void * func_data, |
12049 | | void * file ATTRIBUTE_UNUSED) |
12050 | 0 | { |
12051 | 0 | const char * separate_filename; |
12052 | 0 | char * debug_filename; |
12053 | 0 | char * canon_dir; |
12054 | 0 | size_t canon_dirlen; |
12055 | 0 | size_t dirlen; |
12056 | 0 | char * canon_filename; |
12057 | 0 | char * canon_debug_filename; |
12058 | 0 | bool self; |
12059 | |
|
12060 | 0 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
12061 | 0 | { |
12062 | 0 | warn (_("Corrupt debuglink section: %s\n"), |
12063 | 0 | xlink->name ? xlink->name : xlink->uncompressed_name); |
12064 | 0 | return NULL; |
12065 | 0 | } |
12066 | | |
12067 | | /* Attempt to locate the separate file. |
12068 | | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ |
12069 | | |
12070 | 0 | canon_filename = lrealpath (main_filename); |
12071 | 0 | canon_dir = xstrdup (canon_filename); |
12072 | |
|
12073 | 0 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) |
12074 | 0 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) |
12075 | 0 | break; |
12076 | 0 | canon_dir[canon_dirlen] = '\0'; |
12077 | |
|
12078 | 0 | #ifndef DEBUGDIR |
12079 | 0 | #define DEBUGDIR "/lib/debug" |
12080 | 0 | #endif |
12081 | 0 | #ifndef EXTRA_DEBUG_ROOT1 |
12082 | 0 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" |
12083 | 0 | #endif |
12084 | 0 | #ifndef EXTRA_DEBUG_ROOT2 |
12085 | 0 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" |
12086 | 0 | #endif |
12087 | |
|
12088 | 0 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
12089 | 0 | + canon_dirlen |
12090 | 0 | + strlen (".debug/") |
12091 | 0 | #ifdef EXTRA_DEBUG_ROOT1 |
12092 | 0 | + strlen (EXTRA_DEBUG_ROOT1) |
12093 | 0 | #endif |
12094 | 0 | #ifdef EXTRA_DEBUG_ROOT2 |
12095 | 0 | + strlen (EXTRA_DEBUG_ROOT2) |
12096 | 0 | #endif |
12097 | 0 | + strlen (separate_filename) |
12098 | 0 | + 1); |
12099 | 0 | if (debug_filename == NULL) |
12100 | 0 | { |
12101 | 0 | warn (_("Out of memory\n")); |
12102 | 0 | free (canon_dir); |
12103 | 0 | free (canon_filename); |
12104 | 0 | return NULL; |
12105 | 0 | } |
12106 | | |
12107 | | /* First try in the current directory. */ |
12108 | 0 | sprintf (debug_filename, "%s", separate_filename); |
12109 | 0 | if (check_func (debug_filename, func_data)) |
12110 | 0 | goto found; |
12111 | | |
12112 | | /* Then try in a subdirectory called .debug. */ |
12113 | 0 | sprintf (debug_filename, ".debug/%s", separate_filename); |
12114 | 0 | if (check_func (debug_filename, func_data)) |
12115 | 0 | goto found; |
12116 | | |
12117 | | /* Then try in the same directory as the original file. */ |
12118 | 0 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
12119 | 0 | if (check_func (debug_filename, func_data)) |
12120 | 0 | goto found; |
12121 | | |
12122 | | /* And the .debug subdirectory of that directory. */ |
12123 | 0 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
12124 | 0 | if (check_func (debug_filename, func_data)) |
12125 | 0 | goto found; |
12126 | | |
12127 | 0 | #ifdef EXTRA_DEBUG_ROOT1 |
12128 | | /* Try the first extra debug file root. */ |
12129 | 0 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
12130 | 0 | if (check_func (debug_filename, func_data)) |
12131 | 0 | goto found; |
12132 | | |
12133 | | /* Try the first extra debug file root. */ |
12134 | 0 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
12135 | 0 | if (check_func (debug_filename, func_data)) |
12136 | 0 | goto found; |
12137 | 0 | #endif |
12138 | | |
12139 | 0 | #ifdef EXTRA_DEBUG_ROOT2 |
12140 | | /* Try the second extra debug file root. */ |
12141 | 0 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
12142 | 0 | if (check_func (debug_filename, func_data)) |
12143 | 0 | goto found; |
12144 | 0 | #endif |
12145 | | |
12146 | | /* Then try in the global debug_filename directory. */ |
12147 | 0 | strcpy (debug_filename, DEBUGDIR); |
12148 | 0 | dirlen = strlen (DEBUGDIR) - 1; |
12149 | 0 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') |
12150 | 0 | strcat (debug_filename, "/"); |
12151 | 0 | strcat (debug_filename, (const char *) separate_filename); |
12152 | |
|
12153 | 0 | if (check_func (debug_filename, func_data)) |
12154 | 0 | goto found; |
12155 | | |
12156 | | #if HAVE_LIBDEBUGINFOD |
12157 | | { |
12158 | | char * tmp_filename; |
12159 | | |
12160 | | if (use_debuginfod |
12161 | | && debuginfod_fetch_separate_debug_info (xlink, |
12162 | | & tmp_filename, |
12163 | | file)) |
12164 | | { |
12165 | | /* File successfully downloaded from server, replace |
12166 | | debug_filename with the file's path. */ |
12167 | | free (debug_filename); |
12168 | | debug_filename = tmp_filename; |
12169 | | goto found; |
12170 | | } |
12171 | | } |
12172 | | #endif |
12173 | | |
12174 | 0 | if (do_debug_links) |
12175 | 0 | { |
12176 | | /* Failed to find the file. */ |
12177 | 0 | warn (_("could not find separate debug file '%s'\n"), |
12178 | 0 | separate_filename); |
12179 | 0 | warn (_("tried: %s\n"), debug_filename); |
12180 | |
|
12181 | 0 | #ifdef EXTRA_DEBUG_ROOT2 |
12182 | 0 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, |
12183 | 0 | separate_filename); |
12184 | 0 | warn (_("tried: %s\n"), debug_filename); |
12185 | 0 | #endif |
12186 | |
|
12187 | 0 | #ifdef EXTRA_DEBUG_ROOT1 |
12188 | 0 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, |
12189 | 0 | canon_dir, separate_filename); |
12190 | 0 | warn (_("tried: %s\n"), debug_filename); |
12191 | |
|
12192 | 0 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, |
12193 | 0 | separate_filename); |
12194 | 0 | warn (_("tried: %s\n"), debug_filename); |
12195 | 0 | #endif |
12196 | |
|
12197 | 0 | sprintf (debug_filename, "%s.debug/%s", canon_dir, |
12198 | 0 | separate_filename); |
12199 | 0 | warn (_("tried: %s\n"), debug_filename); |
12200 | |
|
12201 | 0 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
12202 | 0 | warn (_("tried: %s\n"), debug_filename); |
12203 | |
|
12204 | 0 | sprintf (debug_filename, ".debug/%s", separate_filename); |
12205 | 0 | warn (_("tried: %s\n"), debug_filename); |
12206 | |
|
12207 | 0 | sprintf (debug_filename, "%s", separate_filename); |
12208 | 0 | warn (_("tried: %s\n"), debug_filename); |
12209 | |
|
12210 | | #if HAVE_LIBDEBUGINFOD |
12211 | | if (use_debuginfod) |
12212 | | { |
12213 | | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); |
12214 | | |
12215 | | if (urls == NULL) |
12216 | | urls = ""; |
12217 | | |
12218 | | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); |
12219 | | } |
12220 | | #endif |
12221 | 0 | } |
12222 | |
|
12223 | 0 | free (canon_dir); |
12224 | 0 | free (debug_filename); |
12225 | 0 | free (canon_filename); |
12226 | 0 | return NULL; |
12227 | | |
12228 | 0 | found: |
12229 | 0 | free (canon_dir); |
12230 | |
|
12231 | 0 | canon_debug_filename = lrealpath (debug_filename); |
12232 | 0 | self = strcmp (canon_debug_filename, canon_filename) == 0; |
12233 | 0 | free (canon_filename); |
12234 | 0 | free (canon_debug_filename); |
12235 | 0 | if (self) |
12236 | 0 | { |
12237 | 0 | free (debug_filename); |
12238 | 0 | return NULL; |
12239 | 0 | } |
12240 | | |
12241 | 0 | void * debug_handle; |
12242 | | |
12243 | | /* Now open the file.... */ |
12244 | 0 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
12245 | 0 | { |
12246 | 0 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
12247 | 0 | free (debug_filename); |
12248 | 0 | return NULL; |
12249 | 0 | } |
12250 | | |
12251 | | /* FIXME: We do not check to see if there are any other separate debug info |
12252 | | files that would also match. */ |
12253 | | |
12254 | 0 | if (do_debug_links) |
12255 | 0 | printf (_("\n%s: Found separate debug info file: %s\n"), main_filename, debug_filename); |
12256 | 0 | add_separate_debug_file (debug_filename, debug_handle); |
12257 | | |
12258 | | /* Do not free debug_filename - it might be referenced inside |
12259 | | the structure returned by open_debug_file(). */ |
12260 | 0 | return debug_handle; |
12261 | 0 | } |
12262 | | |
12263 | | /* Attempt to load a separate dwarf object file. */ |
12264 | | |
12265 | | static void * |
12266 | | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
12267 | 0 | { |
12268 | 0 | char * separate_filename; |
12269 | 0 | void * separate_handle; |
12270 | |
|
12271 | 0 | if (IS_ABSOLUTE_PATH (name)) |
12272 | 0 | separate_filename = strdup (name); |
12273 | 0 | else |
12274 | | /* FIXME: Skip adding / if dwo_dir ends in /. */ |
12275 | 0 | separate_filename = concat (dir, "/", name, NULL); |
12276 | 0 | if (separate_filename == NULL) |
12277 | 0 | { |
12278 | 0 | warn (_("Out of memory allocating dwo filename\n")); |
12279 | 0 | return NULL; |
12280 | 0 | } |
12281 | | |
12282 | 0 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
12283 | 0 | { |
12284 | 0 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
12285 | 0 | free (separate_filename); |
12286 | 0 | return NULL; |
12287 | 0 | } |
12288 | | |
12289 | | /* FIXME: We should check the dwo_id. */ |
12290 | | |
12291 | 0 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
12292 | |
|
12293 | 0 | add_separate_debug_file (separate_filename, separate_handle); |
12294 | | /* Note - separate_filename will be freed in free_debug_memory(). */ |
12295 | 0 | return separate_handle; |
12296 | 0 | } |
12297 | | |
12298 | | static void * |
12299 | | try_build_id_prefix (const char * prefix, char * filename, const unsigned char * data, unsigned long id_len) |
12300 | 0 | { |
12301 | 0 | char * f = filename; |
12302 | |
|
12303 | 0 | f += sprintf (f, "%s.build-id/%02x/", prefix, (unsigned) *data++); |
12304 | 0 | id_len --; |
12305 | 0 | while (id_len --) |
12306 | 0 | f += sprintf (f, "%02x", (unsigned) *data++); |
12307 | 0 | strcpy (f, ".debug"); |
12308 | |
|
12309 | 0 | return open_debug_file (filename); |
12310 | 0 | } |
12311 | | |
12312 | | /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */ |
12313 | | |
12314 | | static void |
12315 | | load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED, void * main_file) |
12316 | 30.4k | { |
12317 | 30.4k | if (! load_debug_section (note_gnu_build_id, main_file)) |
12318 | 30.4k | return; /* No .note.gnu.build-id section. */ |
12319 | | |
12320 | 0 | struct dwarf_section * section = & debug_displays [note_gnu_build_id].section; |
12321 | 0 | if (section == NULL) |
12322 | 0 | { |
12323 | 0 | warn (_("Unable to load the .note.gnu.build-id section\n")); |
12324 | 0 | return; |
12325 | 0 | } |
12326 | | |
12327 | 0 | if (section->start == NULL || section->size < 0x18) |
12328 | 0 | { |
12329 | 0 | warn (_(".note.gnu.build-id section is corrupt/empty\n")); |
12330 | 0 | return; |
12331 | 0 | } |
12332 | | |
12333 | | /* In theory we should extract the contents of the section into |
12334 | | a note structure and then check the fields. For now though |
12335 | | just use hard coded offsets instead: |
12336 | | |
12337 | | Field Bytes Contents |
12338 | | NSize 0...3 4 |
12339 | | DSize 4...7 8+ |
12340 | | Type 8..11 3 (NT_GNU_BUILD_ID) |
12341 | | Name 12.15 GNU\0 |
12342 | | Data 16.... */ |
12343 | | |
12344 | | /* FIXME: Check the name size, name and type fields. */ |
12345 | | |
12346 | 0 | unsigned long build_id_size; |
12347 | 0 | build_id_size = byte_get (section->start + 4, 4); |
12348 | 0 | if (build_id_size < 8) |
12349 | 0 | { |
12350 | 0 | warn (_(".note.gnu.build-id data size is too small\n")); |
12351 | 0 | return; |
12352 | 0 | } |
12353 | | |
12354 | 0 | if (build_id_size > (section->size - 16)) |
12355 | 0 | { |
12356 | 0 | warn (_(".note.gnu.build-id data size is too big\n")); |
12357 | 0 | return; |
12358 | 0 | } |
12359 | | |
12360 | 0 | char * filename; |
12361 | 0 | filename = xmalloc (strlen (".build-id/") |
12362 | 0 | + build_id_size * 2 + 2 |
12363 | 0 | + strlen (".debug") |
12364 | | /* The next string should be the same as the longest |
12365 | | name found in the prefixes[] array below. */ |
12366 | 0 | + strlen ("/usr/lib64/debug/usr/") |
12367 | 0 | + 1); |
12368 | 0 | void * handle; |
12369 | |
|
12370 | 0 | static const char * prefixes[] = |
12371 | 0 | { |
12372 | 0 | "", |
12373 | 0 | ".debug/", |
12374 | 0 | "/usr/lib/debug/", |
12375 | 0 | "/usr/lib/debug/usr/", |
12376 | 0 | "/usr/lib64/debug/", |
12377 | 0 | "/usr/lib64/debug/usr/" |
12378 | 0 | }; |
12379 | 0 | long unsigned int i; |
12380 | |
|
12381 | 0 | for (i = 0; i < ARRAY_SIZE (prefixes); i++) |
12382 | 0 | { |
12383 | 0 | handle = try_build_id_prefix (prefixes[i], filename, |
12384 | 0 | section->start + 16, build_id_size); |
12385 | 0 | if (handle != NULL) |
12386 | 0 | break; |
12387 | 0 | } |
12388 | | /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */ |
12389 | 0 | if (handle == NULL) |
12390 | 0 | { |
12391 | | /* Failed to find a debug file associated with the build-id. |
12392 | | This is not an error however, rather it just means that |
12393 | | the debug info has probably not been loaded on the system, |
12394 | | or that another method is being used to link to the debug |
12395 | | info. */ |
12396 | 0 | free (filename); |
12397 | 0 | return; |
12398 | 0 | } |
12399 | | |
12400 | 0 | add_separate_debug_file (filename, handle); |
12401 | 0 | } |
12402 | | |
12403 | | /* Try to load a debug file pointed to by the .debug_sup section. */ |
12404 | | |
12405 | | static void |
12406 | | load_debug_sup_file (const char * main_filename, void * file) |
12407 | 30.4k | { |
12408 | 30.4k | if (! load_debug_section (debug_sup, file)) |
12409 | 30.4k | return; /* No .debug_sup section. */ |
12410 | | |
12411 | 0 | struct dwarf_section * section; |
12412 | 0 | section = & debug_displays [debug_sup].section; |
12413 | 0 | assert (section != NULL); |
12414 | | |
12415 | 0 | if (section->start == NULL || section->size < 5) |
12416 | 0 | { |
12417 | 0 | warn (_(".debug_sup section is corrupt/empty\n")); |
12418 | 0 | return; |
12419 | 0 | } |
12420 | | |
12421 | 0 | if (section->start[2] != 0) |
12422 | 0 | return; /* This is a supplementary file. */ |
12423 | | |
12424 | 0 | const char * filename = (const char *) section->start + 3; |
12425 | 0 | if (strnlen (filename, section->size - 3) == section->size - 3) |
12426 | 0 | { |
12427 | 0 | warn (_("filename in .debug_sup section is corrupt\n")); |
12428 | 0 | return; |
12429 | 0 | } |
12430 | | |
12431 | 0 | if (filename[0] != '/' && strchr (main_filename, '/')) |
12432 | 0 | filename = xasprintf ("%.*s/%s", |
12433 | 0 | (int) (strrchr (main_filename, '/') - main_filename), |
12434 | 0 | main_filename, |
12435 | 0 | filename); |
12436 | 0 | else |
12437 | | /* PR 27796: Make sure that we pass a filename that can be free'd to |
12438 | | add_separate_debug_file(). */ |
12439 | 0 | filename = xstrdup (filename); |
12440 | |
|
12441 | 0 | void * handle = open_debug_file (filename); |
12442 | 0 | if (handle == NULL) |
12443 | 0 | { |
12444 | 0 | warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename); |
12445 | 0 | free ((void *) filename); |
12446 | 0 | return; |
12447 | 0 | } |
12448 | | |
12449 | 0 | printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename, filename); |
12450 | | |
12451 | | /* FIXME: Compare the checksums, if present. */ |
12452 | 0 | add_separate_debug_file (filename, handle); |
12453 | 0 | } |
12454 | | |
12455 | | /* Load a debuglink section and/or a debugaltlink section, if either are present. |
12456 | | Recursively check the loaded files for more of these sections. |
12457 | | Also follow any links in .debug_sup sections. |
12458 | | FIXME: Should also check for DWO_* entries in the newly loaded files. */ |
12459 | | |
12460 | | static void |
12461 | | check_for_and_load_links (void * file, const char * filename) |
12462 | 30.4k | { |
12463 | 30.4k | void * handle = NULL; |
12464 | | |
12465 | 30.4k | if (load_debug_section (gnu_debugaltlink, file)) |
12466 | 0 | { |
12467 | 0 | Build_id_data build_id_data; |
12468 | |
|
12469 | 0 | handle = load_separate_debug_info (filename, |
12470 | 0 | & debug_displays[gnu_debugaltlink].section, |
12471 | 0 | parse_gnu_debugaltlink, |
12472 | 0 | check_gnu_debugaltlink, |
12473 | 0 | & build_id_data, |
12474 | 0 | file); |
12475 | 0 | if (handle) |
12476 | 0 | { |
12477 | 0 | assert (handle == first_separate_info->handle); |
12478 | 0 | check_for_and_load_links (first_separate_info->handle, |
12479 | 0 | first_separate_info->filename); |
12480 | 0 | } |
12481 | 0 | } |
12482 | | |
12483 | 30.4k | if (load_debug_section (gnu_debuglink, file)) |
12484 | 0 | { |
12485 | 0 | unsigned long crc32; |
12486 | |
|
12487 | 0 | handle = load_separate_debug_info (filename, |
12488 | 0 | & debug_displays[gnu_debuglink].section, |
12489 | 0 | parse_gnu_debuglink, |
12490 | 0 | check_gnu_debuglink, |
12491 | 0 | & crc32, |
12492 | 0 | file); |
12493 | 0 | if (handle) |
12494 | 0 | { |
12495 | 0 | assert (handle == first_separate_info->handle); |
12496 | 0 | check_for_and_load_links (first_separate_info->handle, |
12497 | 0 | first_separate_info->filename); |
12498 | 0 | } |
12499 | 0 | } |
12500 | | |
12501 | 30.4k | load_debug_sup_file (filename, file); |
12502 | | |
12503 | 30.4k | load_build_id_debug_file (filename, file); |
12504 | 30.4k | } |
12505 | | |
12506 | | /* Load the separate debug info file(s) attached to FILE, if any exist. |
12507 | | Returns TRUE if any were found, FALSE otherwise. |
12508 | | If TRUE is returned then the linked list starting at first_separate_info |
12509 | | will be populated with open file handles. */ |
12510 | | |
12511 | | bool |
12512 | | load_separate_debug_files (void * file, const char * filename) |
12513 | 44.6k | { |
12514 | | /* Skip this operation if we are not interested in debug links. */ |
12515 | 44.6k | if (! do_follow_links && ! do_debug_links) |
12516 | 0 | return false; |
12517 | | |
12518 | | /* See if there are any dwo links. */ |
12519 | 44.6k | if (load_debug_section (str, file) |
12520 | 44.6k | && load_debug_section (abbrev, file) |
12521 | 44.6k | && load_debug_section (info, file)) |
12522 | 0 | { |
12523 | | /* Load the .debug_addr section, if it exists. */ |
12524 | 0 | load_debug_section (debug_addr, file); |
12525 | | /* Load the .debug_str_offsets section, if it exists. */ |
12526 | 0 | load_debug_section (str_index, file); |
12527 | | /* Load the .debug_loclists section, if it exists. */ |
12528 | 0 | load_debug_section (loclists, file); |
12529 | | /* Load the .debug_rnglists section, if it exists. */ |
12530 | 0 | load_debug_section (rnglists, file); |
12531 | |
|
12532 | 0 | free_dwo_info (); |
12533 | |
|
12534 | 0 | if (process_debug_info (& debug_displays[info].section, file, abbrev, |
12535 | 0 | true, false)) |
12536 | 0 | { |
12537 | 0 | bool introduced = false; |
12538 | 0 | dwo_info *dwinfo; |
12539 | 0 | const char *dir = NULL; |
12540 | 0 | const char *id = NULL; |
12541 | 0 | const char *name = NULL; |
12542 | |
|
12543 | 0 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) |
12544 | 0 | { |
12545 | | /* Accumulate NAME, DIR and ID fields. */ |
12546 | 0 | switch (dwinfo->type) |
12547 | 0 | { |
12548 | 0 | case DWO_NAME: |
12549 | 0 | if (name != NULL) |
12550 | 0 | warn (_("Multiple DWO_NAMEs encountered for the same CU\n")); |
12551 | 0 | name = dwinfo->value; |
12552 | 0 | break; |
12553 | | |
12554 | 0 | case DWO_DIR: |
12555 | | /* There can be multiple DW_AT_comp_dir entries in a CU, |
12556 | | so do not complain. */ |
12557 | 0 | dir = dwinfo->value; |
12558 | 0 | break; |
12559 | | |
12560 | 0 | case DWO_ID: |
12561 | 0 | if (id != NULL) |
12562 | 0 | warn (_("multiple DWO_IDs encountered for the same CU\n")); |
12563 | 0 | id = dwinfo->value; |
12564 | 0 | break; |
12565 | | |
12566 | 0 | default: |
12567 | 0 | error (_("Unexpected DWO INFO type")); |
12568 | 0 | break; |
12569 | 0 | } |
12570 | | |
12571 | | /* If we have reached the end of our list, or we are changing |
12572 | | CUs, then display the information that we have accumulated |
12573 | | so far. */ |
12574 | 0 | if (name != NULL |
12575 | 0 | && (dwinfo->next == NULL |
12576 | 0 | || dwinfo->next->cu_offset != dwinfo->cu_offset)) |
12577 | 0 | { |
12578 | 0 | if (do_debug_links) |
12579 | 0 | { |
12580 | 0 | if (! introduced) |
12581 | 0 | { |
12582 | 0 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), |
12583 | 0 | debug_displays [info].section.uncompressed_name); |
12584 | 0 | introduced = true; |
12585 | 0 | } |
12586 | |
|
12587 | 0 | printf (_(" Name: %s\n"), name); |
12588 | 0 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); |
12589 | 0 | if (id != NULL) |
12590 | 0 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); |
12591 | 0 | else if (debug_information[0].dwarf_version != 5) |
12592 | 0 | printf (_(" ID: <not specified>\n")); |
12593 | 0 | printf ("\n\n"); |
12594 | 0 | } |
12595 | |
|
12596 | 0 | if (do_follow_links) |
12597 | 0 | load_dwo_file (filename, name, dir, id); |
12598 | |
|
12599 | 0 | name = dir = id = NULL; |
12600 | 0 | } |
12601 | 0 | } |
12602 | 0 | } |
12603 | 0 | } |
12604 | | |
12605 | 44.6k | if (! do_follow_links) |
12606 | | /* The other debug links will be displayed by display_debug_links() |
12607 | | so we do not need to do any further processing here. */ |
12608 | 14.1k | return false; |
12609 | | |
12610 | | /* FIXME: We do not check for the presence of both link sections in the same file. */ |
12611 | | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
12612 | | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
12613 | | |
12614 | 30.4k | check_for_and_load_links (file, filename); |
12615 | 30.4k | if (first_separate_info != NULL) |
12616 | 0 | return true; |
12617 | | |
12618 | 30.4k | do_follow_links = 0; |
12619 | 30.4k | return false; |
12620 | 30.4k | } |
12621 | | |
12622 | | void |
12623 | | free_debug_memory (void) |
12624 | 129k | { |
12625 | 129k | unsigned int i; |
12626 | | |
12627 | 129k | free_all_abbrevs (); |
12628 | | |
12629 | 129k | free (shndx_pool); |
12630 | 129k | shndx_pool = NULL; |
12631 | 129k | shndx_pool_size = 0; |
12632 | 129k | shndx_pool_used = 0; |
12633 | 129k | free (cu_sets); |
12634 | 129k | cu_sets = NULL; |
12635 | 129k | cu_count = 0; |
12636 | 129k | free (tu_sets); |
12637 | 129k | tu_sets = NULL; |
12638 | 129k | tu_count = 0; |
12639 | | |
12640 | 129k | memset (level_type_signed, 0, sizeof level_type_signed); |
12641 | 129k | cu_tu_indexes_read = -1; |
12642 | | |
12643 | 6.46M | for (i = 0; i < max; i++) |
12644 | 6.33M | free_debug_section ((enum dwarf_section_display_enum) i); |
12645 | | |
12646 | 129k | if (debug_information != NULL) |
12647 | 692 | { |
12648 | 54.7k | for (i = 0; i < alloc_num_debug_info_entries; i++) |
12649 | 54.0k | free_debug_information (&debug_information[i]); |
12650 | 692 | free (debug_information); |
12651 | 692 | debug_information = NULL; |
12652 | 692 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
12653 | 692 | } |
12654 | | |
12655 | 129k | separate_info * d; |
12656 | 129k | separate_info * next; |
12657 | | |
12658 | 129k | for (d = first_separate_info; d != NULL; d = next) |
12659 | 0 | { |
12660 | 0 | close_debug_file (d->handle); |
12661 | 0 | free ((void *) d->filename); |
12662 | 0 | next = d->next; |
12663 | 0 | free ((void *) d); |
12664 | 0 | } |
12665 | 129k | first_separate_info = NULL; |
12666 | | |
12667 | 129k | free_dwo_info (); |
12668 | 129k | } |
12669 | | |
12670 | | typedef struct |
12671 | | { |
12672 | | const char letter; |
12673 | | const char *option; |
12674 | | int *variable; |
12675 | | int val; |
12676 | | } debug_dump_long_opts; |
12677 | | |
12678 | | static const debug_dump_long_opts debug_option_table[] = |
12679 | | { |
12680 | | { 'A', "addr", &do_debug_addr, 1 }, |
12681 | | { 'a', "abbrev", &do_debug_abbrevs, 1 }, |
12682 | | { 'c', "cu_index", &do_debug_cu_index, 1 }, |
12683 | | #ifdef HAVE_LIBDEBUGINFOD |
12684 | | { 'D', "use-debuginfod", &use_debuginfod, 1 }, |
12685 | | { 'E', "do-not-use-debuginfod", &use_debuginfod, 0 }, |
12686 | | #endif |
12687 | | { 'F', "frames-interp", &do_debug_frames_interp, 1 }, |
12688 | | { 'f', "frames", &do_debug_frames, 1 }, |
12689 | | { 'g', "gdb_index", &do_gdb_index, 1 }, |
12690 | | { 'i', "info", &do_debug_info, 1 }, |
12691 | | { 'K', "follow-links", &do_follow_links, 1 }, |
12692 | | { 'k', "links", &do_debug_links, 1 }, |
12693 | | { 'L', "decodedline", &do_debug_lines, FLAG_DEBUG_LINES_DECODED }, |
12694 | | { 'l', "rawline", &do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
12695 | | /* For compatibility with earlier versions of readelf. */ |
12696 | | { 'l', "line", &do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
12697 | | { 'm', "macro", &do_debug_macinfo, 1 }, |
12698 | | { 'N', "no-follow-links", &do_follow_links, 0 }, |
12699 | | { 'O', "str-offsets", &do_debug_str_offsets, 1 }, |
12700 | | { 'o', "loc", &do_debug_loc, 1 }, |
12701 | | { 'p', "pubnames", &do_debug_pubnames, 1 }, |
12702 | | { 'R', "Ranges", &do_debug_ranges, 1 }, |
12703 | | { 'r', "aranges", &do_debug_aranges, 1 }, |
12704 | | /* For compatibility with earlier versions of readelf. */ |
12705 | | { 'r', "ranges", &do_debug_aranges, 1 }, |
12706 | | { 's', "str", &do_debug_str, 1 }, |
12707 | | { '\0', "sframe-internal-only", &do_sframe, 1 }, |
12708 | | { 'T', "trace_aranges", &do_trace_aranges, 1 }, |
12709 | | { 't', "pubtypes", &do_debug_pubtypes, 1 }, |
12710 | | { 'U', "trace_info", &do_trace_info, 1 }, |
12711 | | { 'u', "trace_abbrev", &do_trace_abbrevs, 1 }, |
12712 | | { 0, NULL, NULL, 0 } |
12713 | | }; |
12714 | | |
12715 | | /* Enable display of specific DWARF sections as determined by the comma |
12716 | | separated strings in NAMES. Returns non-zero if any displaying was |
12717 | | enabled. */ |
12718 | | |
12719 | | int |
12720 | | dwarf_select_sections_by_names (const char *names) |
12721 | 0 | { |
12722 | 0 | const char *p; |
12723 | 0 | int result = 0; |
12724 | |
|
12725 | 0 | p = names; |
12726 | 0 | while (*p) |
12727 | 0 | { |
12728 | 0 | const debug_dump_long_opts *entry; |
12729 | |
|
12730 | 0 | for (entry = debug_option_table; entry->option; entry++) |
12731 | 0 | { |
12732 | 0 | size_t len = strlen (entry->option); |
12733 | |
|
12734 | 0 | if (strncmp (p, entry->option, len) == 0 |
12735 | 0 | && (p[len] == ',' || p[len] == '\0')) |
12736 | 0 | { |
12737 | 0 | if (entry->val == 0) |
12738 | 0 | * entry->variable = 0; |
12739 | 0 | else |
12740 | 0 | * entry->variable = entry->val; |
12741 | 0 | result |= entry->val; |
12742 | |
|
12743 | 0 | p += len; |
12744 | 0 | break; |
12745 | 0 | } |
12746 | 0 | } |
12747 | |
|
12748 | 0 | if (entry->option == NULL) |
12749 | 0 | { |
12750 | 0 | warn (_("Unrecognized debug option '%s'\n"), p); |
12751 | 0 | p = strchr (p, ','); |
12752 | 0 | if (p == NULL) |
12753 | 0 | break; |
12754 | 0 | } |
12755 | | |
12756 | 0 | if (*p == ',') |
12757 | 0 | p++; |
12758 | 0 | } |
12759 | | |
12760 | | /* The --debug-dump=frames-interp option also enables the |
12761 | | --debug-dump=frames option. */ |
12762 | 0 | if (do_debug_frames_interp) |
12763 | 0 | do_debug_frames = 1; |
12764 | |
|
12765 | 0 | return result; |
12766 | 0 | } |
12767 | | |
12768 | | /* Enable display of specific DWARF sections as determined by the characters |
12769 | | in LETTERS. Returns non-zero if any displaying was enabled. */ |
12770 | | |
12771 | | int |
12772 | | dwarf_select_sections_by_letters (const char *letters) |
12773 | 69.7k | { |
12774 | 69.7k | int result = 0; |
12775 | | |
12776 | 139k | while (* letters) |
12777 | 69.7k | { |
12778 | 69.7k | const debug_dump_long_opts *entry; |
12779 | | |
12780 | 697k | for (entry = debug_option_table; entry->letter; entry++) |
12781 | 697k | { |
12782 | 697k | if (entry->letter == * letters) |
12783 | 69.7k | { |
12784 | 69.7k | if (entry->val == 0) |
12785 | 0 | * entry->variable = 0; |
12786 | 69.7k | else |
12787 | 69.7k | * entry->variable |= entry->val; |
12788 | 69.7k | result |= entry->val; |
12789 | 69.7k | break; |
12790 | 69.7k | } |
12791 | 697k | } |
12792 | | |
12793 | 69.7k | if (entry->letter == 0) |
12794 | 0 | warn (_("Unrecognized debug letter option '%c'\n"), * letters); |
12795 | | |
12796 | 69.7k | letters ++; |
12797 | 69.7k | } |
12798 | | |
12799 | | /* The --debug-dump=frames-interp option also enables the |
12800 | | --debug-dump=frames option. */ |
12801 | 69.7k | if (do_debug_frames_interp) |
12802 | 0 | do_debug_frames = 1; |
12803 | | |
12804 | 69.7k | return result; |
12805 | 69.7k | } |
12806 | | |
12807 | | void |
12808 | | dwarf_select_sections_all (void) |
12809 | 69.7k | { |
12810 | 69.7k | do_debug_info = 1; |
12811 | 69.7k | do_debug_abbrevs = 1; |
12812 | 69.7k | do_debug_lines = FLAG_DEBUG_LINES_RAW; |
12813 | 69.7k | do_debug_pubnames = 1; |
12814 | 69.7k | do_debug_pubtypes = 1; |
12815 | 69.7k | do_debug_aranges = 1; |
12816 | 69.7k | do_debug_ranges = 1; |
12817 | 69.7k | do_debug_frames = 1; |
12818 | 69.7k | do_debug_macinfo = 1; |
12819 | 69.7k | do_debug_str = 1; |
12820 | 69.7k | do_debug_loc = 1; |
12821 | 69.7k | do_gdb_index = 1; |
12822 | 69.7k | do_trace_info = 1; |
12823 | 69.7k | do_trace_abbrevs = 1; |
12824 | 69.7k | do_trace_aranges = 1; |
12825 | 69.7k | do_debug_addr = 1; |
12826 | 69.7k | do_debug_cu_index = 1; |
12827 | 69.7k | do_follow_links = 1; |
12828 | 69.7k | do_debug_links = 1; |
12829 | 69.7k | do_debug_str_offsets = 1; |
12830 | 69.7k | } |
12831 | | |
12832 | | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0 |
12833 | | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0 |
12834 | | |
12835 | | /* N.B. The order here must match the order in section_display_enum. */ |
12836 | | |
12837 | | struct dwarf_section_display debug_displays[] = |
12838 | | { |
12839 | | { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, |
12840 | | { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, true }, |
12841 | | { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, |
12842 | | { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev)}, display_debug_info, &do_debug_info, true }, |
12843 | | { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, |
12844 | | { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, false }, |
12845 | | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, false }, |
12846 | | { { ".eh_frame", "", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, |
12847 | | { { ".eh_frame_hdr", "", "", NO_ABBREVS }, display_eh_frame_hdr, &do_debug_frames, true }, |
12848 | | { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, |
12849 | | { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, |
12850 | | { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, |
12851 | | { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, |
12852 | | { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, |
12853 | | { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, |
12854 | | { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, |
12855 | | { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, false }, |
12856 | | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, false }, |
12857 | | { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, |
12858 | | { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, |
12859 | | { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, |
12860 | | { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, |
12861 | | { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, |
12862 | | { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev) }, display_debug_types, &do_debug_info, true }, |
12863 | | { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, |
12864 | | { { ".gdb_index", "", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, false }, |
12865 | | { { ".debug_names", "", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, false }, |
12866 | | { { ".sframe", "", "", NO_ABBREVS }, display_sframe, &do_sframe, true }, |
12867 | | { { ".trace_info", "", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, true }, |
12868 | | { { ".trace_abbrev", "", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, false }, |
12869 | | { { ".trace_aranges", "", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, false }, |
12870 | | { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, true }, |
12871 | | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, |
12872 | | { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, true }, |
12873 | | { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, |
12874 | | { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, |
12875 | | { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, |
12876 | | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, |
12877 | | { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS }, display_debug_str, &do_debug_str, true }, |
12878 | | { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, |
12879 | | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, |
12880 | | { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS }, display_debug_addr, &do_debug_addr, true }, |
12881 | | { { ".debug_cu_index", "", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, |
12882 | | { { ".debug_tu_index", "", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, |
12883 | | { { ".gnu_debuglink", "", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, |
12884 | | { { ".gnu_debugaltlink", "", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, |
12885 | | { { ".debug_sup", "", "", NO_ABBREVS }, display_debug_sup, &do_debug_links, false }, |
12886 | | /* Separate debug info files can containt their own .debug_str section, |
12887 | | and this might be in *addition* to a .debug_str section already present |
12888 | | in the main file. Hence we need to have two entries for .debug_str. */ |
12889 | | { { ".debug_str", ".zdebug_str", "", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, |
12890 | | { { ".note.gnu.build-id", "", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, |
12891 | | }; |
12892 | | |
12893 | | /* A static assertion. */ |
12894 | | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |