]>
Commit | Line | Data |
---|---|---|
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 <assert.h> | |
34 | ||
35 | #ifdef HAVE_LIBDEBUGINFOD | |
36 | #include <elfutils/debuginfod.h> | |
37 | #endif | |
38 | ||
39 | #include <limits.h> | |
40 | #ifndef CHAR_BIT | |
41 | #define CHAR_BIT 8 | |
42 | #endif | |
43 | ||
44 | #ifndef ENABLE_CHECKING | |
45 | #define ENABLE_CHECKING 0 | |
46 | #endif | |
47 | ||
48 | #undef MAX | |
49 | #undef MIN | |
50 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
51 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
52 | ||
53 | static const char *regname (unsigned int regno, int row); | |
54 | static const char *regname_internal_by_table_only (unsigned int regno); | |
55 | ||
56 | static int have_frame_base; | |
57 | static int frame_base_level = -1; /* To support nested DW_TAG_subprogram's. */ | |
58 | static int need_base_address; | |
59 | ||
60 | static unsigned int num_debug_info_entries = 0; | |
61 | static unsigned int alloc_num_debug_info_entries = 0; | |
62 | static debug_info *debug_information = NULL; | |
63 | /* Special value for num_debug_info_entries to indicate | |
64 | that the .debug_info section could not be loaded/parsed. */ | |
65 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
66 | ||
67 | /* A .debug_info section can contain multiple links to separate | |
68 | DWO object files. We use these structures to record these links. */ | |
69 | typedef enum dwo_type | |
70 | { | |
71 | DWO_NAME, | |
72 | DWO_DIR, | |
73 | DWO_ID | |
74 | } dwo_type; | |
75 | ||
76 | typedef struct dwo_info | |
77 | { | |
78 | dwo_type type; | |
79 | const char * value; | |
80 | uint64_t cu_offset; | |
81 | struct dwo_info * next; | |
82 | } dwo_info; | |
83 | ||
84 | static dwo_info *first_dwo_info = NULL; | |
85 | static bool need_dwo_info; | |
86 | ||
87 | separate_info * first_separate_info = NULL; | |
88 | ||
89 | unsigned int eh_addr_size; | |
90 | ||
91 | int do_debug_info; | |
92 | int do_debug_abbrevs; | |
93 | int do_debug_lines; | |
94 | int do_debug_pubnames; | |
95 | int do_debug_pubtypes; | |
96 | int do_debug_aranges; | |
97 | int do_debug_ranges; | |
98 | int do_debug_frames; | |
99 | int do_debug_frames_interp; | |
100 | int do_debug_macinfo; | |
101 | int do_debug_str; | |
102 | int do_debug_str_offsets; | |
103 | int do_debug_loc; | |
104 | int do_gdb_index; | |
105 | int do_trace_info; | |
106 | int do_trace_abbrevs; | |
107 | int do_trace_aranges; | |
108 | int do_debug_addr; | |
109 | int do_debug_cu_index; | |
110 | int do_wide; | |
111 | int do_debug_links; | |
112 | int do_follow_links = DEFAULT_FOR_FOLLOW_LINKS; | |
113 | #ifdef HAVE_LIBDEBUGINFOD | |
114 | int use_debuginfod = 1; | |
115 | #endif | |
116 | bool do_checks; | |
117 | ||
118 | int dwarf_cutoff_level = -1; | |
119 | unsigned long dwarf_start_die; | |
120 | ||
121 | int dwarf_check = 0; | |
122 | ||
123 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index | |
124 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
125 | as a zero-terminated list of section indexes comprising one set of debug | |
126 | sections from a .dwo file. */ | |
127 | ||
128 | static unsigned int *shndx_pool = NULL; | |
129 | static unsigned int shndx_pool_size = 0; | |
130 | static unsigned int shndx_pool_used = 0; | |
131 | ||
132 | /* For version 2 package files, each set contains an array of section offsets | |
133 | and an array of section sizes, giving the offset and size of the | |
134 | contribution from a CU or TU within one of the debug sections. | |
135 | When displaying debug info from a package file, we need to use these | |
136 | tables to locate the corresponding contributions to each section. */ | |
137 | ||
138 | struct cu_tu_set | |
139 | { | |
140 | uint64_t signature; | |
141 | uint64_t section_offsets[DW_SECT_MAX]; | |
142 | size_t section_sizes[DW_SECT_MAX]; | |
143 | }; | |
144 | ||
145 | static int cu_count = 0; | |
146 | static int tu_count = 0; | |
147 | static struct cu_tu_set *cu_sets = NULL; | |
148 | static struct cu_tu_set *tu_sets = NULL; | |
149 | ||
150 | static bool load_cu_tu_indexes (void *); | |
151 | ||
152 | /* An array that indicates for a given level of CU nesting whether | |
153 | the latest DW_AT_type seen for that level was a signed type or | |
154 | an unsigned type. */ | |
155 | #define MAX_CU_NESTING (1 << 8) | |
156 | static bool level_type_signed[MAX_CU_NESTING]; | |
157 | ||
158 | /* Values for do_debug_lines. */ | |
159 | #define FLAG_DEBUG_LINES_RAW 1 | |
160 | #define FLAG_DEBUG_LINES_DECODED 2 | |
161 | ||
162 | static unsigned int | |
163 | size_of_encoded_value (int encoding) | |
164 | { | |
165 | switch (encoding & 0x7) | |
166 | { | |
167 | default: /* ??? */ | |
168 | case 0: return eh_addr_size; | |
169 | case 2: return 2; | |
170 | case 3: return 4; | |
171 | case 4: return 8; | |
172 | } | |
173 | } | |
174 | ||
175 | static uint64_t | |
176 | get_encoded_value (unsigned char **pdata, | |
177 | int encoding, | |
178 | struct dwarf_section *section, | |
179 | unsigned char * end) | |
180 | { | |
181 | unsigned char * data = * pdata; | |
182 | unsigned int size = size_of_encoded_value (encoding); | |
183 | uint64_t val; | |
184 | ||
185 | if (data >= end || size > (size_t) (end - data)) | |
186 | { | |
187 | warn (_("Encoded value extends past end of section\n")); | |
188 | * pdata = end; | |
189 | return 0; | |
190 | } | |
191 | ||
192 | /* PR 17512: file: 002-829853-0.004. */ | |
193 | if (size > 8) | |
194 | { | |
195 | warn (_("Encoded size of %d is too large to read\n"), size); | |
196 | * pdata = end; | |
197 | return 0; | |
198 | } | |
199 | ||
200 | /* PR 17512: file: 1085-5603-0.004. */ | |
201 | if (size == 0) | |
202 | { | |
203 | warn (_("Encoded size of 0 is too small to read\n")); | |
204 | * pdata = end; | |
205 | return 0; | |
206 | } | |
207 | ||
208 | if (encoding & DW_EH_PE_signed) | |
209 | val = byte_get_signed (data, size); | |
210 | else | |
211 | val = byte_get (data, size); | |
212 | ||
213 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
214 | val += section->address + (data - section->start); | |
215 | ||
216 | * pdata = data + size; | |
217 | return val; | |
218 | } | |
219 | ||
220 | /* Print a uint64_t value (typically an address, offset or length) in | |
221 | hexadecimal format, followed by a space. The precision displayed is | |
222 | determined by the NUM_BYTES parameter. */ | |
223 | ||
224 | static void | |
225 | print_hex (uint64_t value, unsigned num_bytes) | |
226 | { | |
227 | if (num_bytes == 0) | |
228 | num_bytes = 2; | |
229 | ||
230 | printf ("%0*" PRIx64 " ", num_bytes * 2, | |
231 | value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); | |
232 | } | |
233 | ||
234 | /* Like print_hex, but no trailing space. */ | |
235 | ||
236 | static void | |
237 | print_hex_ns (uint64_t value, unsigned num_bytes) | |
238 | { | |
239 | if (num_bytes == 0) | |
240 | num_bytes = 2; | |
241 | ||
242 | printf ("%0*" PRIx64, num_bytes * 2, | |
243 | value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); | |
244 | } | |
245 | ||
246 | /* Print a view number in hexadecimal value, with the same width as | |
247 | print_hex would have printed it. */ | |
248 | ||
249 | static void | |
250 | print_view (uint64_t value, unsigned num_bytes) | |
251 | { | |
252 | if (num_bytes == 0) | |
253 | num_bytes = 2; | |
254 | ||
255 | printf ("v%0*" PRIx64 " ", num_bytes * 2 - 1, | |
256 | value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); | |
257 | } | |
258 | ||
259 | static const char * | |
260 | null_name (const char *p) | |
261 | { | |
262 | if (p == NULL) | |
263 | p = _("unknown"); | |
264 | return p; | |
265 | } | |
266 | ||
267 | /* Read in a LEB128 encoded value starting at address DATA. | |
268 | If SIGN is true, return a signed LEB128 value. | |
269 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
270 | If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the | |
271 | terminating byte was not found and with bit 1 set if the value | |
272 | overflows a uint64_t. | |
273 | No bytes will be read at address END or beyond. */ | |
274 | ||
275 | uint64_t | |
276 | read_leb128 (unsigned char *data, | |
277 | const unsigned char *const end, | |
278 | bool sign, | |
279 | unsigned int *length_return, | |
280 | int *status_return) | |
281 | { | |
282 | uint64_t result = 0; | |
283 | unsigned int num_read = 0; | |
284 | unsigned int shift = 0; | |
285 | int status = 1; | |
286 | ||
287 | while (data < end) | |
288 | { | |
289 | unsigned char byte = *data++; | |
290 | unsigned char lost, mask; | |
291 | ||
292 | num_read++; | |
293 | ||
294 | if (shift < CHAR_BIT * sizeof (result)) | |
295 | { | |
296 | result |= ((uint64_t) (byte & 0x7f)) << shift; | |
297 | /* These bits overflowed. */ | |
298 | lost = byte ^ (result >> shift); | |
299 | /* And this is the mask of possible overflow bits. */ | |
300 | mask = 0x7f ^ ((uint64_t) 0x7f << shift >> shift); | |
301 | shift += 7; | |
302 | } | |
303 | else | |
304 | { | |
305 | lost = byte; | |
306 | mask = 0x7f; | |
307 | } | |
308 | if ((lost & mask) != (sign && (int64_t) result < 0 ? mask : 0)) | |
309 | status |= 2; | |
310 | ||
311 | if ((byte & 0x80) == 0) | |
312 | { | |
313 | status &= ~1; | |
314 | if (sign && shift < CHAR_BIT * sizeof (result) && (byte & 0x40)) | |
315 | result |= -((uint64_t) 1 << shift); | |
316 | break; | |
317 | } | |
318 | } | |
319 | ||
320 | if (length_return != NULL) | |
321 | *length_return = num_read; | |
322 | if (status_return != NULL) | |
323 | *status_return = status; | |
324 | ||
325 | return result; | |
326 | } | |
327 | ||
328 | /* Read AMOUNT bytes from PTR and store them in VAL. | |
329 | Checks to make sure that the read will not reach or pass END. | |
330 | FUNC chooses whether the value read is unsigned or signed, and may | |
331 | be either byte_get or byte_get_signed. If INC is true, PTR is | |
332 | incremented after reading the value. | |
333 | This macro cannot protect against PTR values derived from user input. | |
334 | The C standard sections 6.5.6 and 6.5.8 say attempts to do so using | |
335 | pointers is undefined behaviour. */ | |
336 | #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \ | |
337 | do \ | |
338 | { \ | |
339 | size_t amount = (AMOUNT); \ | |
340 | if (sizeof (VAL) < amount) \ | |
341 | { \ | |
342 | error (ngettext ("internal error: attempt to read %d byte " \ | |
343 | "of data in to %d sized variable", \ | |
344 | "internal error: attempt to read %d bytes " \ | |
345 | "of data in to %d sized variable", \ | |
346 | amount), \ | |
347 | (int) amount, (int) sizeof (VAL)); \ | |
348 | amount = sizeof (VAL); \ | |
349 | } \ | |
350 | if (ENABLE_CHECKING) \ | |
351 | assert ((PTR) <= (END)); \ | |
352 | size_t avail = (END) - (PTR); \ | |
353 | if ((PTR) > (END)) \ | |
354 | avail = 0; \ | |
355 | if (amount > avail) \ | |
356 | amount = avail; \ | |
357 | if (amount == 0) \ | |
358 | (VAL) = 0; \ | |
359 | else \ | |
360 | (VAL) = (FUNC) ((PTR), amount); \ | |
361 | if (INC) \ | |
362 | (PTR) += amount; \ | |
363 | } \ | |
364 | while (0) | |
365 | ||
366 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ | |
367 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false) | |
368 | ||
369 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ | |
370 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true) | |
371 | ||
372 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ | |
373 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false) | |
374 | ||
375 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ | |
376 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true) | |
377 | ||
378 | typedef struct State_Machine_Registers | |
379 | { | |
380 | uint64_t address; | |
381 | unsigned int view; | |
382 | unsigned int file; | |
383 | unsigned int line; | |
384 | unsigned int column; | |
385 | int is_stmt; | |
386 | int basic_block; | |
387 | unsigned char op_index; | |
388 | unsigned char end_sequence; | |
389 | /* This variable hold the number of the last entry seen | |
390 | in the File Table. */ | |
391 | unsigned int last_file_entry; | |
392 | } SMR; | |
393 | ||
394 | static SMR state_machine_regs; | |
395 | ||
396 | static void | |
397 | reset_state_machine (int is_stmt) | |
398 | { | |
399 | state_machine_regs.address = 0; | |
400 | state_machine_regs.view = 0; | |
401 | state_machine_regs.op_index = 0; | |
402 | state_machine_regs.file = 1; | |
403 | state_machine_regs.line = 1; | |
404 | state_machine_regs.column = 0; | |
405 | state_machine_regs.is_stmt = is_stmt; | |
406 | state_machine_regs.basic_block = 0; | |
407 | state_machine_regs.end_sequence = 0; | |
408 | state_machine_regs.last_file_entry = 0; | |
409 | } | |
410 | ||
411 | /* Handled an extend line op. | |
412 | Returns the number of bytes read. */ | |
413 | ||
414 | static size_t | |
415 | process_extended_line_op (unsigned char * data, | |
416 | int is_stmt, | |
417 | unsigned char * end) | |
418 | { | |
419 | unsigned char op_code; | |
420 | size_t len, header_len; | |
421 | unsigned char *name; | |
422 | unsigned char *orig_data = data; | |
423 | uint64_t adr, val; | |
424 | ||
425 | READ_ULEB (len, data, end); | |
426 | header_len = data - orig_data; | |
427 | ||
428 | if (len == 0 || data >= end || len > (size_t) (end - data)) | |
429 | { | |
430 | warn (_("Badly formed extended line op encountered!\n")); | |
431 | return header_len; | |
432 | } | |
433 | ||
434 | op_code = *data++; | |
435 | ||
436 | printf (_(" Extended opcode %d: "), op_code); | |
437 | ||
438 | switch (op_code) | |
439 | { | |
440 | case DW_LNE_end_sequence: | |
441 | printf (_("End of Sequence\n\n")); | |
442 | reset_state_machine (is_stmt); | |
443 | break; | |
444 | ||
445 | case DW_LNE_set_address: | |
446 | /* PR 17512: file: 002-100480-0.004. */ | |
447 | if (len - 1 > 8) | |
448 | { | |
449 | warn (_("Length (%zu) of DW_LNE_set_address op is too long\n"), | |
450 | len - 1); | |
451 | adr = 0; | |
452 | } | |
453 | else | |
454 | SAFE_BYTE_GET (adr, data, len - 1, end); | |
455 | printf (_("set Address to %#" PRIx64 "\n"), adr); | |
456 | state_machine_regs.address = adr; | |
457 | state_machine_regs.view = 0; | |
458 | state_machine_regs.op_index = 0; | |
459 | break; | |
460 | ||
461 | case DW_LNE_define_file: | |
462 | printf (_("define new File Table entry\n")); | |
463 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
464 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
465 | ||
466 | { | |
467 | size_t l; | |
468 | ||
469 | name = data; | |
470 | l = strnlen ((char *) data, end - data); | |
471 | data += l; | |
472 | if (data < end) | |
473 | data++; | |
474 | READ_ULEB (val, data, end); | |
475 | printf ("%" PRIu64 "\t", val); | |
476 | READ_ULEB (val, data, end); | |
477 | printf ("%" PRIu64 "\t", val); | |
478 | READ_ULEB (val, data, end); | |
479 | printf ("%" PRIu64 "\t", val); | |
480 | printf ("%.*s\n\n", (int) l, name); | |
481 | } | |
482 | ||
483 | if (((size_t) (data - orig_data) != len + header_len) || data >= end) | |
484 | warn (_("DW_LNE_define_file: Bad opcode length\n")); | |
485 | break; | |
486 | ||
487 | case DW_LNE_set_discriminator: | |
488 | READ_ULEB (val, data, end); | |
489 | printf (_("set Discriminator to %" PRIu64 "\n"), val); | |
490 | break; | |
491 | ||
492 | /* HP extensions. */ | |
493 | case DW_LNE_HP_negate_is_UV_update: | |
494 | printf ("DW_LNE_HP_negate_is_UV_update\n"); | |
495 | break; | |
496 | case DW_LNE_HP_push_context: | |
497 | printf ("DW_LNE_HP_push_context\n"); | |
498 | break; | |
499 | case DW_LNE_HP_pop_context: | |
500 | printf ("DW_LNE_HP_pop_context\n"); | |
501 | break; | |
502 | case DW_LNE_HP_set_file_line_column: | |
503 | printf ("DW_LNE_HP_set_file_line_column\n"); | |
504 | break; | |
505 | case DW_LNE_HP_set_routine_name: | |
506 | printf ("DW_LNE_HP_set_routine_name\n"); | |
507 | break; | |
508 | case DW_LNE_HP_set_sequence: | |
509 | printf ("DW_LNE_HP_set_sequence\n"); | |
510 | break; | |
511 | case DW_LNE_HP_negate_post_semantics: | |
512 | printf ("DW_LNE_HP_negate_post_semantics\n"); | |
513 | break; | |
514 | case DW_LNE_HP_negate_function_exit: | |
515 | printf ("DW_LNE_HP_negate_function_exit\n"); | |
516 | break; | |
517 | case DW_LNE_HP_negate_front_end_logical: | |
518 | printf ("DW_LNE_HP_negate_front_end_logical\n"); | |
519 | break; | |
520 | case DW_LNE_HP_define_proc: | |
521 | printf ("DW_LNE_HP_define_proc\n"); | |
522 | break; | |
523 | case DW_LNE_HP_source_file_correlation: | |
524 | { | |
525 | unsigned char *edata = data + len - 1; | |
526 | ||
527 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
528 | ||
529 | while (data < edata) | |
530 | { | |
531 | unsigned int opc; | |
532 | ||
533 | READ_ULEB (opc, data, edata); | |
534 | ||
535 | switch (opc) | |
536 | { | |
537 | case DW_LNE_HP_SFC_formfeed: | |
538 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
539 | break; | |
540 | case DW_LNE_HP_SFC_set_listing_line: | |
541 | READ_ULEB (val, data, edata); | |
542 | printf (" DW_LNE_HP_SFC_set_listing_line (%" PRIu64 ")\n", | |
543 | val); | |
544 | break; | |
545 | case DW_LNE_HP_SFC_associate: | |
546 | printf (" DW_LNE_HP_SFC_associate "); | |
547 | READ_ULEB (val, data, edata); | |
548 | printf ("(%" PRIu64 , val); | |
549 | READ_ULEB (val, data, edata); | |
550 | printf (",%" PRIu64, val); | |
551 | READ_ULEB (val, data, edata); | |
552 | printf (",%" PRIu64 ")\n", val); | |
553 | break; | |
554 | default: | |
555 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
556 | data = edata; | |
557 | break; | |
558 | } | |
559 | } | |
560 | } | |
561 | break; | |
562 | ||
563 | default: | |
564 | { | |
565 | unsigned int rlen = len - 1; | |
566 | ||
567 | if (op_code >= DW_LNE_lo_user | |
568 | /* The test against DW_LNW_hi_user is redundant due to | |
569 | the limited range of the unsigned char data type used | |
570 | for op_code. */ | |
571 | /*&& op_code <= DW_LNE_hi_user*/) | |
572 | printf (_("user defined: ")); | |
573 | else | |
574 | printf (_("UNKNOWN: ")); | |
575 | printf (_("length %d ["), rlen); | |
576 | for (; rlen; rlen--) | |
577 | printf (" %02x", *data++); | |
578 | printf ("]\n"); | |
579 | } | |
580 | break; | |
581 | } | |
582 | ||
583 | return len + header_len; | |
584 | } | |
585 | ||
586 | static const unsigned char * | |
587 | fetch_indirect_string (uint64_t offset) | |
588 | { | |
589 | struct dwarf_section *section = &debug_displays [str].section; | |
590 | const unsigned char * ret; | |
591 | ||
592 | if (section->start == NULL) | |
593 | return (const unsigned char *) _("<no .debug_str section>"); | |
594 | ||
595 | if (offset >= section->size) | |
596 | { | |
597 | warn (_("DW_FORM_strp offset too big: %#" PRIx64 "\n"), offset); | |
598 | return (const unsigned char *) _("<offset is too big>"); | |
599 | } | |
600 | ||
601 | ret = section->start + offset; | |
602 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
603 | NUL byte. Since our caller is expecting to receive a well formed C | |
604 | string we test for the lack of a terminating byte here. */ | |
605 | if (strnlen ((const char *) ret, section->size - offset) | |
606 | == section->size - offset) | |
607 | ret = (const unsigned char *) | |
608 | _("<no NUL byte at end of .debug_str section>"); | |
609 | ||
610 | return ret; | |
611 | } | |
612 | ||
613 | static const unsigned char * | |
614 | fetch_indirect_line_string (uint64_t offset) | |
615 | { | |
616 | struct dwarf_section *section = &debug_displays [line_str].section; | |
617 | const unsigned char * ret; | |
618 | ||
619 | if (section->start == NULL) | |
620 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
621 | ||
622 | if (offset >= section->size) | |
623 | { | |
624 | warn (_("DW_FORM_line_strp offset too big: %#" PRIx64 "\n"), offset); | |
625 | return (const unsigned char *) _("<offset is too big>"); | |
626 | } | |
627 | ||
628 | ret = section->start + offset; | |
629 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
630 | with a NUL byte. Since our caller is expecting to receive a well formed | |
631 | C string we test for the lack of a terminating byte here. */ | |
632 | if (strnlen ((const char *) ret, section->size - offset) | |
633 | == section->size - offset) | |
634 | ret = (const unsigned char *) | |
635 | _("<no NUL byte at end of .debug_line_str section>"); | |
636 | ||
637 | return ret; | |
638 | } | |
639 | ||
640 | static const char * | |
641 | fetch_indexed_string (uint64_t idx, | |
642 | struct cu_tu_set *this_set, | |
643 | uint64_t offset_size, | |
644 | bool dwo, | |
645 | uint64_t str_offsets_base) | |
646 | { | |
647 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
648 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
649 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
650 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
651 | uint64_t index_offset; | |
652 | uint64_t str_offset; | |
653 | const char * ret; | |
654 | ||
655 | if (index_section->start == NULL) | |
656 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
657 | : _("<no .debug_str_offsets section>")); | |
658 | ||
659 | if (str_section->start == NULL) | |
660 | return (dwo ? _("<no .debug_str.dwo section>") | |
661 | : _("<no .debug_str section>")); | |
662 | ||
663 | if (_mul_overflow (idx, offset_size, &index_offset) | |
664 | || (this_set != NULL | |
665 | && ((index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]) | |
666 | < this_set->section_offsets [DW_SECT_STR_OFFSETS])) | |
667 | || (index_offset += str_offsets_base) < str_offsets_base | |
668 | || index_offset + offset_size < offset_size | |
669 | || index_offset + offset_size > index_section->size) | |
670 | { | |
671 | warn (_("string index of %" PRIu64 " converts to an offset of %#" PRIx64 | |
672 | " which is too big for section %s\n"), | |
673 | idx, index_offset, str_section->name); | |
674 | ||
675 | return _("<string index too big>"); | |
676 | } | |
677 | ||
678 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
679 | ||
680 | if (str_offset >= str_section->size) | |
681 | { | |
682 | warn (_("indirect offset too big: %#" PRIx64 "\n"), str_offset); | |
683 | return _("<indirect index offset is too big>"); | |
684 | } | |
685 | ||
686 | ret = (const char *) str_section->start + str_offset; | |
687 | ||
688 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
689 | Since our caller is expecting to receive a well formed C string we test | |
690 | for the lack of a terminating byte here. */ | |
691 | if (strnlen (ret, str_section->size - str_offset) | |
692 | == str_section->size - str_offset) | |
693 | return _("<no NUL byte at end of section>"); | |
694 | ||
695 | return ret; | |
696 | } | |
697 | ||
698 | static uint64_t | |
699 | fetch_indexed_addr (uint64_t offset, uint32_t num_bytes) | |
700 | { | |
701 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
702 | ||
703 | if (section->start == NULL) | |
704 | { | |
705 | warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n")); | |
706 | return 0; | |
707 | } | |
708 | ||
709 | if (offset + num_bytes > section->size) | |
710 | { | |
711 | warn (_("Offset into section %s too big: %#" PRIx64 "\n"), | |
712 | section->name, offset); | |
713 | return 0; | |
714 | } | |
715 | ||
716 | return byte_get (section->start + offset, num_bytes); | |
717 | } | |
718 | ||
719 | /* This is for resolving DW_FORM_rnglistx and DW_FORM_loclistx. | |
720 | ||
721 | The memory layout is: base_address (taken from the CU's top DIE) points at a table of offsets, | |
722 | relative to the section start. | |
723 | The table of offsets contains the offsets of objects of interest relative to the table of offsets. | |
724 | IDX is the index of the desired object in said table of offsets. | |
725 | ||
726 | This returns the offset of the desired object relative to the section start or -1 upon failure. */ | |
727 | ||
728 | static uint64_t | |
729 | fetch_indexed_offset (uint64_t idx, | |
730 | enum dwarf_section_display_enum sec_enum, | |
731 | uint64_t base_address, | |
732 | uint64_t offset_size) | |
733 | { | |
734 | uint64_t offset_of_offset = base_address + idx * offset_size; | |
735 | struct dwarf_section *section = &debug_displays [sec_enum].section; | |
736 | ||
737 | if (section->start == NULL) | |
738 | { | |
739 | warn (_("Unable to locate %s section\n"), section->uncompressed_name); | |
740 | return -1; | |
741 | } | |
742 | ||
743 | if (section->size < 4) | |
744 | { | |
745 | warn (_("Section %s is too small to contain an value indexed from another section!\n"), | |
746 | section->name); | |
747 | return -1; | |
748 | } | |
749 | ||
750 | if (offset_of_offset + offset_size >= section->size) | |
751 | { | |
752 | warn (_("Offset of %#" PRIx64 " is too big for section %s\n"), | |
753 | offset_of_offset, section->name); | |
754 | return -1; | |
755 | } | |
756 | ||
757 | return base_address + byte_get (section->start + offset_of_offset, offset_size); | |
758 | } | |
759 | ||
760 | /* FIXME: There are better and more efficient ways to handle | |
761 | these structures. For now though, I just want something that | |
762 | is simple to implement. */ | |
763 | /* Records a single attribute in an abbrev. */ | |
764 | typedef struct abbrev_attr | |
765 | { | |
766 | unsigned long attribute; | |
767 | unsigned long form; | |
768 | int64_t implicit_const; | |
769 | struct abbrev_attr *next; | |
770 | } | |
771 | abbrev_attr; | |
772 | ||
773 | /* Records a single abbrev. */ | |
774 | typedef struct abbrev_entry | |
775 | { | |
776 | unsigned long number; | |
777 | unsigned long tag; | |
778 | int children; | |
779 | struct abbrev_attr * first_attr; | |
780 | struct abbrev_attr * last_attr; | |
781 | struct abbrev_entry * next; | |
782 | } | |
783 | abbrev_entry; | |
784 | ||
785 | /* Records a set of abbreviations. */ | |
786 | typedef struct abbrev_list | |
787 | { | |
788 | abbrev_entry * first_abbrev; | |
789 | abbrev_entry * last_abbrev; | |
790 | unsigned char * raw; | |
791 | struct abbrev_list * next; | |
792 | unsigned char * start_of_next_abbrevs; | |
793 | } | |
794 | abbrev_list; | |
795 | ||
796 | /* Records all the abbrevs found so far. */ | |
797 | static struct abbrev_list * abbrev_lists = NULL; | |
798 | ||
799 | typedef struct abbrev_map | |
800 | { | |
801 | uint64_t start; | |
802 | uint64_t end; | |
803 | abbrev_list *list; | |
804 | } abbrev_map; | |
805 | ||
806 | /* Maps between CU offsets and abbrev sets. */ | |
807 | static abbrev_map * cu_abbrev_map = NULL; | |
808 | static unsigned long num_abbrev_map_entries = 0; | |
809 | static unsigned long next_free_abbrev_map_entry = 0; | |
810 | ||
811 | #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8 | |
812 | #define ABBREV_MAP_ENTRIES_INCREMENT 8 | |
813 | ||
814 | static void | |
815 | record_abbrev_list_for_cu (uint64_t start, uint64_t end, | |
816 | abbrev_list *list, abbrev_list *free_list) | |
817 | { | |
818 | if (free_list != NULL) | |
819 | { | |
820 | list->next = abbrev_lists; | |
821 | abbrev_lists = list; | |
822 | } | |
823 | ||
824 | if (cu_abbrev_map == NULL) | |
825 | { | |
826 | num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES; | |
827 | cu_abbrev_map = xmalloc (num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
828 | } | |
829 | else if (next_free_abbrev_map_entry == num_abbrev_map_entries) | |
830 | { | |
831 | num_abbrev_map_entries += ABBREV_MAP_ENTRIES_INCREMENT; | |
832 | cu_abbrev_map = xrealloc (cu_abbrev_map, num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
833 | } | |
834 | ||
835 | cu_abbrev_map[next_free_abbrev_map_entry].start = start; | |
836 | cu_abbrev_map[next_free_abbrev_map_entry].end = end; | |
837 | cu_abbrev_map[next_free_abbrev_map_entry].list = list; | |
838 | next_free_abbrev_map_entry ++; | |
839 | } | |
840 | ||
841 | static abbrev_list * | |
842 | free_abbrev_list (abbrev_list *list) | |
843 | { | |
844 | abbrev_entry *abbrv = list->first_abbrev; | |
845 | ||
846 | while (abbrv) | |
847 | { | |
848 | abbrev_attr *attr = abbrv->first_attr; | |
849 | ||
850 | while (attr) | |
851 | { | |
852 | abbrev_attr *next_attr = attr->next; | |
853 | free (attr); | |
854 | attr = next_attr; | |
855 | } | |
856 | ||
857 | abbrev_entry *next_abbrev = abbrv->next; | |
858 | free (abbrv); | |
859 | abbrv = next_abbrev; | |
860 | } | |
861 | ||
862 | abbrev_list *next = list->next; | |
863 | free (list); | |
864 | return next; | |
865 | } | |
866 | ||
867 | static void | |
868 | free_all_abbrevs (void) | |
869 | { | |
870 | while (abbrev_lists) | |
871 | abbrev_lists = free_abbrev_list (abbrev_lists); | |
872 | ||
873 | free (cu_abbrev_map); | |
874 | cu_abbrev_map = NULL; | |
875 | next_free_abbrev_map_entry = 0; | |
876 | } | |
877 | ||
878 | static abbrev_list * | |
879 | find_abbrev_list_by_raw_abbrev (unsigned char *raw) | |
880 | { | |
881 | abbrev_list * list; | |
882 | ||
883 | for (list = abbrev_lists; list != NULL; list = list->next) | |
884 | if (list->raw == raw) | |
885 | return list; | |
886 | ||
887 | return NULL; | |
888 | } | |
889 | ||
890 | /* Find the abbreviation map for the CU that includes OFFSET. | |
891 | OFFSET is an absolute offset from the start of the .debug_info section. */ | |
892 | /* FIXME: This function is going to slow down readelf & objdump. | |
893 | Not caching abbrevs is likely the answer. */ | |
894 | ||
895 | static abbrev_map * | |
896 | find_abbrev_map_by_offset (uint64_t offset) | |
897 | { | |
898 | unsigned long i; | |
899 | ||
900 | for (i = 0; i < next_free_abbrev_map_entry; i++) | |
901 | if (cu_abbrev_map[i].start <= offset | |
902 | && cu_abbrev_map[i].end > offset) | |
903 | return cu_abbrev_map + i; | |
904 | ||
905 | return NULL; | |
906 | } | |
907 | ||
908 | static void | |
909 | add_abbrev (unsigned long number, | |
910 | unsigned long tag, | |
911 | int children, | |
912 | abbrev_list * list) | |
913 | { | |
914 | abbrev_entry * entry; | |
915 | ||
916 | entry = (abbrev_entry *) xmalloc (sizeof (*entry)); | |
917 | ||
918 | entry->number = number; | |
919 | entry->tag = tag; | |
920 | entry->children = children; | |
921 | entry->first_attr = NULL; | |
922 | entry->last_attr = NULL; | |
923 | entry->next = NULL; | |
924 | ||
925 | assert (list != NULL); | |
926 | ||
927 | if (list->first_abbrev == NULL) | |
928 | list->first_abbrev = entry; | |
929 | else | |
930 | list->last_abbrev->next = entry; | |
931 | ||
932 | list->last_abbrev = entry; | |
933 | } | |
934 | ||
935 | static void | |
936 | add_abbrev_attr (unsigned long attribute, | |
937 | unsigned long form, | |
938 | int64_t implicit_const, | |
939 | abbrev_list *list) | |
940 | { | |
941 | abbrev_attr *attr; | |
942 | ||
943 | attr = (abbrev_attr *) xmalloc (sizeof (*attr)); | |
944 | ||
945 | attr->attribute = attribute; | |
946 | attr->form = form; | |
947 | attr->implicit_const = implicit_const; | |
948 | attr->next = NULL; | |
949 | ||
950 | assert (list != NULL && list->last_abbrev != NULL); | |
951 | ||
952 | if (list->last_abbrev->first_attr == NULL) | |
953 | list->last_abbrev->first_attr = attr; | |
954 | else | |
955 | list->last_abbrev->last_attr->next = attr; | |
956 | ||
957 | list->last_abbrev->last_attr = attr; | |
958 | } | |
959 | ||
960 | /* Return processed (partial) contents of a .debug_abbrev section. | |
961 | Returns NULL on errors. */ | |
962 | ||
963 | static abbrev_list * | |
964 | process_abbrev_set (struct dwarf_section *section, | |
965 | unsigned char *start, | |
966 | unsigned char *end) | |
967 | { | |
968 | abbrev_list *list = xmalloc (sizeof (*list)); | |
969 | list->first_abbrev = NULL; | |
970 | list->last_abbrev = NULL; | |
971 | list->raw = start; | |
972 | list->next = NULL; | |
973 | ||
974 | while (start < end) | |
975 | { | |
976 | unsigned long entry; | |
977 | unsigned long tag; | |
978 | unsigned long attribute; | |
979 | int children; | |
980 | ||
981 | READ_ULEB (entry, start, end); | |
982 | ||
983 | /* A single zero is supposed to end the set according | |
984 | to the standard. If there's more, then signal that to | |
985 | the caller. */ | |
986 | if (start == end || entry == 0) | |
987 | { | |
988 | list->start_of_next_abbrevs = start != end ? start : NULL; | |
989 | return list; | |
990 | } | |
991 | ||
992 | READ_ULEB (tag, start, end); | |
993 | if (start == end) | |
994 | return free_abbrev_list (list); | |
995 | ||
996 | children = *start++; | |
997 | ||
998 | add_abbrev (entry, tag, children, list); | |
999 | ||
1000 | do | |
1001 | { | |
1002 | unsigned long form; | |
1003 | /* Initialize it due to a false compiler warning. */ | |
1004 | int64_t implicit_const = -1; | |
1005 | ||
1006 | READ_ULEB (attribute, start, end); | |
1007 | if (start == end) | |
1008 | break; | |
1009 | ||
1010 | READ_ULEB (form, start, end); | |
1011 | if (start == end) | |
1012 | break; | |
1013 | ||
1014 | if (form == DW_FORM_implicit_const) | |
1015 | { | |
1016 | READ_SLEB (implicit_const, start, end); | |
1017 | if (start == end) | |
1018 | break; | |
1019 | } | |
1020 | ||
1021 | add_abbrev_attr (attribute, form, implicit_const, list); | |
1022 | } | |
1023 | while (attribute != 0); | |
1024 | } | |
1025 | ||
1026 | /* Report the missing single zero which ends the section. */ | |
1027 | error (_("%s section not zero terminated\n"), section->name); | |
1028 | ||
1029 | return free_abbrev_list (list); | |
1030 | } | |
1031 | ||
1032 | /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE | |
1033 | plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE. | |
1034 | If FREE_LIST is non-NULL search the already decoded abbrevs on | |
1035 | abbrev_lists first and if found set *FREE_LIST to NULL. If | |
1036 | searching doesn't find a matching abbrev, set *FREE_LIST to the | |
1037 | newly allocated list. If FREE_LIST is NULL, no search is done and | |
1038 | the returned abbrev_list is always newly allocated. */ | |
1039 | ||
1040 | static abbrev_list * | |
1041 | find_and_process_abbrev_set (struct dwarf_section *section, | |
1042 | uint64_t abbrev_base, | |
1043 | uint64_t abbrev_size, | |
1044 | uint64_t abbrev_offset, | |
1045 | abbrev_list **free_list) | |
1046 | { | |
1047 | if (free_list) | |
1048 | *free_list = NULL; | |
1049 | ||
1050 | if (abbrev_base >= section->size | |
1051 | || abbrev_size > section->size - abbrev_base) | |
1052 | { | |
1053 | /* PR 17531: file:4bcd9ce9. */ | |
1054 | warn (_("Debug info is corrupted, abbrev size (%#" PRIx64 ")" | |
1055 | " is larger than abbrev section size (%#" PRIx64 ")\n"), | |
1056 | abbrev_base + abbrev_size, section->size); | |
1057 | return NULL; | |
1058 | } | |
1059 | if (abbrev_offset >= abbrev_size) | |
1060 | { | |
1061 | warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64 ")" | |
1062 | " is larger than abbrev section size (%#" PRIx64 ")\n"), | |
1063 | abbrev_offset, abbrev_size); | |
1064 | return NULL; | |
1065 | } | |
1066 | ||
1067 | unsigned char *start = section->start + abbrev_base + abbrev_offset; | |
1068 | unsigned char *end = section->start + abbrev_base + abbrev_size; | |
1069 | abbrev_list *list = NULL; | |
1070 | if (free_list) | |
1071 | list = find_abbrev_list_by_raw_abbrev (start); | |
1072 | if (list == NULL) | |
1073 | { | |
1074 | list = process_abbrev_set (section, start, end); | |
1075 | if (free_list) | |
1076 | *free_list = list; | |
1077 | } | |
1078 | return list; | |
1079 | } | |
1080 | ||
1081 | static const char * | |
1082 | get_TAG_name (uint64_t tag) | |
1083 | { | |
1084 | const char *name = NULL; | |
1085 | ||
1086 | if ((unsigned int) tag == tag) | |
1087 | name = get_DW_TAG_name ((unsigned int) tag); | |
1088 | if (name == NULL) | |
1089 | { | |
1090 | static char buffer[100]; | |
1091 | ||
1092 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) | |
1093 | snprintf (buffer, sizeof (buffer), | |
1094 | _("User TAG value: %#" PRIx64), tag); | |
1095 | else | |
1096 | snprintf (buffer, sizeof (buffer), | |
1097 | _("Unknown TAG value: %#" PRIx64), tag); | |
1098 | return buffer; | |
1099 | } | |
1100 | ||
1101 | return name; | |
1102 | } | |
1103 | ||
1104 | static const char * | |
1105 | get_FORM_name (unsigned long form) | |
1106 | { | |
1107 | const char *name = NULL; | |
1108 | ||
1109 | if (form == 0) | |
1110 | return "DW_FORM value: 0"; | |
1111 | ||
1112 | if ((unsigned int) form == form) | |
1113 | name = get_DW_FORM_name ((unsigned int) form); | |
1114 | if (name == NULL) | |
1115 | { | |
1116 | static char buffer[100]; | |
1117 | ||
1118 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); | |
1119 | return buffer; | |
1120 | } | |
1121 | ||
1122 | return name; | |
1123 | } | |
1124 | ||
1125 | static const char * | |
1126 | get_IDX_name (unsigned long idx) | |
1127 | { | |
1128 | const char *name = NULL; | |
1129 | ||
1130 | if ((unsigned int) idx == idx) | |
1131 | name = get_DW_IDX_name ((unsigned int) idx); | |
1132 | if (name == NULL) | |
1133 | { | |
1134 | static char buffer[100]; | |
1135 | ||
1136 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1137 | return buffer; | |
1138 | } | |
1139 | ||
1140 | return name; | |
1141 | } | |
1142 | ||
1143 | static unsigned char * | |
1144 | display_block (unsigned char *data, | |
1145 | uint64_t length, | |
1146 | const unsigned char * const end, char delimiter) | |
1147 | { | |
1148 | size_t maxlen; | |
1149 | ||
1150 | printf (_("%c%" PRIu64 " byte block: "), delimiter, length); | |
1151 | if (data > end) | |
1152 | return (unsigned char *) end; | |
1153 | ||
1154 | maxlen = end - data; | |
1155 | length = length > maxlen ? maxlen : length; | |
1156 | ||
1157 | while (length --) | |
1158 | printf ("%" PRIx64 " ", byte_get (data++, 1)); | |
1159 | ||
1160 | return data; | |
1161 | } | |
1162 | ||
1163 | static int | |
1164 | decode_location_expression (unsigned char * data, | |
1165 | unsigned int pointer_size, | |
1166 | unsigned int offset_size, | |
1167 | int dwarf_version, | |
1168 | uint64_t length, | |
1169 | uint64_t cu_offset, | |
1170 | struct dwarf_section * section) | |
1171 | { | |
1172 | unsigned op; | |
1173 | uint64_t uvalue; | |
1174 | int64_t svalue; | |
1175 | unsigned char *end = data + length; | |
1176 | int need_frame_base = 0; | |
1177 | ||
1178 | while (data < end) | |
1179 | { | |
1180 | op = *data++; | |
1181 | ||
1182 | switch (op) | |
1183 | { | |
1184 | case DW_OP_addr: | |
1185 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1186 | printf ("DW_OP_addr: %" PRIx64, uvalue); | |
1187 | break; | |
1188 | case DW_OP_deref: | |
1189 | printf ("DW_OP_deref"); | |
1190 | break; | |
1191 | case DW_OP_const1u: | |
1192 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1193 | printf ("DW_OP_const1u: %" PRIu64, uvalue); | |
1194 | break; | |
1195 | case DW_OP_const1s: | |
1196 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); | |
1197 | printf ("DW_OP_const1s: %" PRId64, svalue); | |
1198 | break; | |
1199 | case DW_OP_const2u: | |
1200 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
1201 | printf ("DW_OP_const2u: %" PRIu64, uvalue); | |
1202 | break; | |
1203 | case DW_OP_const2s: | |
1204 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); | |
1205 | printf ("DW_OP_const2s: %" PRId64, svalue); | |
1206 | break; | |
1207 | case DW_OP_const4u: | |
1208 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1209 | printf ("DW_OP_const4u: %" PRIu64, uvalue); | |
1210 | break; | |
1211 | case DW_OP_const4s: | |
1212 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1213 | printf ("DW_OP_const4s: %" PRId64, svalue); | |
1214 | break; | |
1215 | case DW_OP_const8u: | |
1216 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); | |
1217 | printf ("DW_OP_const8u: %" PRIu64, uvalue); | |
1218 | break; | |
1219 | case DW_OP_const8s: | |
1220 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 8, end); | |
1221 | printf ("DW_OP_const8s: %" PRId64, svalue); | |
1222 | break; | |
1223 | case DW_OP_constu: | |
1224 | READ_ULEB (uvalue, data, end); | |
1225 | printf ("DW_OP_constu: %" PRIu64, uvalue); | |
1226 | break; | |
1227 | case DW_OP_consts: | |
1228 | READ_SLEB (svalue, data, end); | |
1229 | printf ("DW_OP_consts: %" PRId64, svalue); | |
1230 | break; | |
1231 | case DW_OP_dup: | |
1232 | printf ("DW_OP_dup"); | |
1233 | break; | |
1234 | case DW_OP_drop: | |
1235 | printf ("DW_OP_drop"); | |
1236 | break; | |
1237 | case DW_OP_over: | |
1238 | printf ("DW_OP_over"); | |
1239 | break; | |
1240 | case DW_OP_pick: | |
1241 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1242 | printf ("DW_OP_pick: %" PRIu64, uvalue); | |
1243 | break; | |
1244 | case DW_OP_swap: | |
1245 | printf ("DW_OP_swap"); | |
1246 | break; | |
1247 | case DW_OP_rot: | |
1248 | printf ("DW_OP_rot"); | |
1249 | break; | |
1250 | case DW_OP_xderef: | |
1251 | printf ("DW_OP_xderef"); | |
1252 | break; | |
1253 | case DW_OP_abs: | |
1254 | printf ("DW_OP_abs"); | |
1255 | break; | |
1256 | case DW_OP_and: | |
1257 | printf ("DW_OP_and"); | |
1258 | break; | |
1259 | case DW_OP_div: | |
1260 | printf ("DW_OP_div"); | |
1261 | break; | |
1262 | case DW_OP_minus: | |
1263 | printf ("DW_OP_minus"); | |
1264 | break; | |
1265 | case DW_OP_mod: | |
1266 | printf ("DW_OP_mod"); | |
1267 | break; | |
1268 | case DW_OP_mul: | |
1269 | printf ("DW_OP_mul"); | |
1270 | break; | |
1271 | case DW_OP_neg: | |
1272 | printf ("DW_OP_neg"); | |
1273 | break; | |
1274 | case DW_OP_not: | |
1275 | printf ("DW_OP_not"); | |
1276 | break; | |
1277 | case DW_OP_or: | |
1278 | printf ("DW_OP_or"); | |
1279 | break; | |
1280 | case DW_OP_plus: | |
1281 | printf ("DW_OP_plus"); | |
1282 | break; | |
1283 | case DW_OP_plus_uconst: | |
1284 | READ_ULEB (uvalue, data, end); | |
1285 | printf ("DW_OP_plus_uconst: %" PRIu64, uvalue); | |
1286 | break; | |
1287 | case DW_OP_shl: | |
1288 | printf ("DW_OP_shl"); | |
1289 | break; | |
1290 | case DW_OP_shr: | |
1291 | printf ("DW_OP_shr"); | |
1292 | break; | |
1293 | case DW_OP_shra: | |
1294 | printf ("DW_OP_shra"); | |
1295 | break; | |
1296 | case DW_OP_xor: | |
1297 | printf ("DW_OP_xor"); | |
1298 | break; | |
1299 | case DW_OP_bra: | |
1300 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); | |
1301 | printf ("DW_OP_bra: %" PRId64, svalue); | |
1302 | break; | |
1303 | case DW_OP_eq: | |
1304 | printf ("DW_OP_eq"); | |
1305 | break; | |
1306 | case DW_OP_ge: | |
1307 | printf ("DW_OP_ge"); | |
1308 | break; | |
1309 | case DW_OP_gt: | |
1310 | printf ("DW_OP_gt"); | |
1311 | break; | |
1312 | case DW_OP_le: | |
1313 | printf ("DW_OP_le"); | |
1314 | break; | |
1315 | case DW_OP_lt: | |
1316 | printf ("DW_OP_lt"); | |
1317 | break; | |
1318 | case DW_OP_ne: | |
1319 | printf ("DW_OP_ne"); | |
1320 | break; | |
1321 | case DW_OP_skip: | |
1322 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); | |
1323 | printf ("DW_OP_skip: %" PRId64, svalue); | |
1324 | break; | |
1325 | ||
1326 | case DW_OP_lit0: | |
1327 | case DW_OP_lit1: | |
1328 | case DW_OP_lit2: | |
1329 | case DW_OP_lit3: | |
1330 | case DW_OP_lit4: | |
1331 | case DW_OP_lit5: | |
1332 | case DW_OP_lit6: | |
1333 | case DW_OP_lit7: | |
1334 | case DW_OP_lit8: | |
1335 | case DW_OP_lit9: | |
1336 | case DW_OP_lit10: | |
1337 | case DW_OP_lit11: | |
1338 | case DW_OP_lit12: | |
1339 | case DW_OP_lit13: | |
1340 | case DW_OP_lit14: | |
1341 | case DW_OP_lit15: | |
1342 | case DW_OP_lit16: | |
1343 | case DW_OP_lit17: | |
1344 | case DW_OP_lit18: | |
1345 | case DW_OP_lit19: | |
1346 | case DW_OP_lit20: | |
1347 | case DW_OP_lit21: | |
1348 | case DW_OP_lit22: | |
1349 | case DW_OP_lit23: | |
1350 | case DW_OP_lit24: | |
1351 | case DW_OP_lit25: | |
1352 | case DW_OP_lit26: | |
1353 | case DW_OP_lit27: | |
1354 | case DW_OP_lit28: | |
1355 | case DW_OP_lit29: | |
1356 | case DW_OP_lit30: | |
1357 | case DW_OP_lit31: | |
1358 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1359 | break; | |
1360 | ||
1361 | case DW_OP_reg0: | |
1362 | case DW_OP_reg1: | |
1363 | case DW_OP_reg2: | |
1364 | case DW_OP_reg3: | |
1365 | case DW_OP_reg4: | |
1366 | case DW_OP_reg5: | |
1367 | case DW_OP_reg6: | |
1368 | case DW_OP_reg7: | |
1369 | case DW_OP_reg8: | |
1370 | case DW_OP_reg9: | |
1371 | case DW_OP_reg10: | |
1372 | case DW_OP_reg11: | |
1373 | case DW_OP_reg12: | |
1374 | case DW_OP_reg13: | |
1375 | case DW_OP_reg14: | |
1376 | case DW_OP_reg15: | |
1377 | case DW_OP_reg16: | |
1378 | case DW_OP_reg17: | |
1379 | case DW_OP_reg18: | |
1380 | case DW_OP_reg19: | |
1381 | case DW_OP_reg20: | |
1382 | case DW_OP_reg21: | |
1383 | case DW_OP_reg22: | |
1384 | case DW_OP_reg23: | |
1385 | case DW_OP_reg24: | |
1386 | case DW_OP_reg25: | |
1387 | case DW_OP_reg26: | |
1388 | case DW_OP_reg27: | |
1389 | case DW_OP_reg28: | |
1390 | case DW_OP_reg29: | |
1391 | case DW_OP_reg30: | |
1392 | case DW_OP_reg31: | |
1393 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, | |
1394 | regname (op - DW_OP_reg0, 1)); | |
1395 | break; | |
1396 | ||
1397 | case DW_OP_breg0: | |
1398 | case DW_OP_breg1: | |
1399 | case DW_OP_breg2: | |
1400 | case DW_OP_breg3: | |
1401 | case DW_OP_breg4: | |
1402 | case DW_OP_breg5: | |
1403 | case DW_OP_breg6: | |
1404 | case DW_OP_breg7: | |
1405 | case DW_OP_breg8: | |
1406 | case DW_OP_breg9: | |
1407 | case DW_OP_breg10: | |
1408 | case DW_OP_breg11: | |
1409 | case DW_OP_breg12: | |
1410 | case DW_OP_breg13: | |
1411 | case DW_OP_breg14: | |
1412 | case DW_OP_breg15: | |
1413 | case DW_OP_breg16: | |
1414 | case DW_OP_breg17: | |
1415 | case DW_OP_breg18: | |
1416 | case DW_OP_breg19: | |
1417 | case DW_OP_breg20: | |
1418 | case DW_OP_breg21: | |
1419 | case DW_OP_breg22: | |
1420 | case DW_OP_breg23: | |
1421 | case DW_OP_breg24: | |
1422 | case DW_OP_breg25: | |
1423 | case DW_OP_breg26: | |
1424 | case DW_OP_breg27: | |
1425 | case DW_OP_breg28: | |
1426 | case DW_OP_breg29: | |
1427 | case DW_OP_breg30: | |
1428 | case DW_OP_breg31: | |
1429 | READ_SLEB (svalue, data, end); | |
1430 | printf ("DW_OP_breg%d (%s): %" PRId64, | |
1431 | op - DW_OP_breg0, regname (op - DW_OP_breg0, 1), svalue); | |
1432 | break; | |
1433 | ||
1434 | case DW_OP_regx: | |
1435 | READ_ULEB (uvalue, data, end); | |
1436 | printf ("DW_OP_regx: %" PRIu64 " (%s)", | |
1437 | uvalue, regname (uvalue, 1)); | |
1438 | break; | |
1439 | case DW_OP_fbreg: | |
1440 | need_frame_base = 1; | |
1441 | READ_SLEB (svalue, data, end); | |
1442 | printf ("DW_OP_fbreg: %" PRId64, svalue); | |
1443 | break; | |
1444 | case DW_OP_bregx: | |
1445 | READ_ULEB (uvalue, data, end); | |
1446 | READ_SLEB (svalue, data, end); | |
1447 | printf ("DW_OP_bregx: %" PRIu64 " (%s) %" PRId64, | |
1448 | uvalue, regname (uvalue, 1), svalue); | |
1449 | break; | |
1450 | case DW_OP_piece: | |
1451 | READ_ULEB (uvalue, data, end); | |
1452 | printf ("DW_OP_piece: %" PRIu64, uvalue); | |
1453 | break; | |
1454 | case DW_OP_deref_size: | |
1455 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1456 | printf ("DW_OP_deref_size: %" PRIu64, uvalue); | |
1457 | break; | |
1458 | case DW_OP_xderef_size: | |
1459 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1460 | printf ("DW_OP_xderef_size: %" PRIu64, uvalue); | |
1461 | break; | |
1462 | case DW_OP_nop: | |
1463 | printf ("DW_OP_nop"); | |
1464 | break; | |
1465 | ||
1466 | /* DWARF 3 extensions. */ | |
1467 | case DW_OP_push_object_address: | |
1468 | printf ("DW_OP_push_object_address"); | |
1469 | break; | |
1470 | case DW_OP_call2: | |
1471 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1472 | this ought to be an 8-byte wide computation. */ | |
1473 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); | |
1474 | printf ("DW_OP_call2: <%#" PRIx64 ">", svalue + cu_offset); | |
1475 | break; | |
1476 | case DW_OP_call4: | |
1477 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1478 | this ought to be an 8-byte wide computation. */ | |
1479 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1480 | printf ("DW_OP_call4: <%#" PRIx64 ">", svalue + cu_offset); | |
1481 | break; | |
1482 | case DW_OP_call_ref: | |
1483 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1484 | this ought to be an 8-byte wide computation. */ | |
1485 | if (dwarf_version == -1) | |
1486 | { | |
1487 | printf (_("(DW_OP_call_ref in frame info)")); | |
1488 | /* No way to tell where the next op is, so just bail. */ | |
1489 | return need_frame_base; | |
1490 | } | |
1491 | if (dwarf_version == 2) | |
1492 | { | |
1493 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1494 | } | |
1495 | else | |
1496 | { | |
1497 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1498 | } | |
1499 | printf ("DW_OP_call_ref: <%#" PRIx64 ">", uvalue); | |
1500 | break; | |
1501 | case DW_OP_form_tls_address: | |
1502 | printf ("DW_OP_form_tls_address"); | |
1503 | break; | |
1504 | case DW_OP_call_frame_cfa: | |
1505 | printf ("DW_OP_call_frame_cfa"); | |
1506 | break; | |
1507 | case DW_OP_bit_piece: | |
1508 | printf ("DW_OP_bit_piece: "); | |
1509 | READ_ULEB (uvalue, data, end); | |
1510 | printf (_("size: %" PRIu64 " "), uvalue); | |
1511 | READ_ULEB (uvalue, data, end); | |
1512 | printf (_("offset: %" PRIu64 " "), uvalue); | |
1513 | break; | |
1514 | ||
1515 | /* DWARF 4 extensions. */ | |
1516 | case DW_OP_stack_value: | |
1517 | printf ("DW_OP_stack_value"); | |
1518 | break; | |
1519 | ||
1520 | case DW_OP_implicit_value: | |
1521 | printf ("DW_OP_implicit_value"); | |
1522 | READ_ULEB (uvalue, data, end); | |
1523 | data = display_block (data, uvalue, end, ' '); | |
1524 | break; | |
1525 | ||
1526 | /* GNU extensions. */ | |
1527 | case DW_OP_GNU_push_tls_address: | |
1528 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); | |
1529 | break; | |
1530 | case DW_OP_GNU_uninit: | |
1531 | printf ("DW_OP_GNU_uninit"); | |
1532 | /* FIXME: Is there data associated with this OP ? */ | |
1533 | break; | |
1534 | case DW_OP_GNU_encoded_addr: | |
1535 | { | |
1536 | int encoding = 0; | |
1537 | uint64_t addr; | |
1538 | ||
1539 | if (data < end) | |
1540 | encoding = *data++; | |
1541 | addr = get_encoded_value (&data, encoding, section, end); | |
1542 | ||
1543 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1544 | print_hex_ns (addr, pointer_size); | |
1545 | } | |
1546 | break; | |
1547 | case DW_OP_implicit_pointer: | |
1548 | case DW_OP_GNU_implicit_pointer: | |
1549 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1550 | this ought to be an 8-byte wide computation. */ | |
1551 | if (dwarf_version == -1) | |
1552 | { | |
1553 | printf (_("(%s in frame info)"), | |
1554 | (op == DW_OP_implicit_pointer | |
1555 | ? "DW_OP_implicit_pointer" | |
1556 | : "DW_OP_GNU_implicit_pointer")); | |
1557 | /* No way to tell where the next op is, so just bail. */ | |
1558 | return need_frame_base; | |
1559 | } | |
1560 | if (dwarf_version == 2) | |
1561 | { | |
1562 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1563 | } | |
1564 | else | |
1565 | { | |
1566 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1567 | } | |
1568 | READ_SLEB (svalue, data, end); | |
1569 | printf ("%s: <%#" PRIx64 "> %" PRId64, | |
1570 | (op == DW_OP_implicit_pointer | |
1571 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
1572 | uvalue, svalue); | |
1573 | break; | |
1574 | case DW_OP_entry_value: | |
1575 | case DW_OP_GNU_entry_value: | |
1576 | READ_ULEB (uvalue, data, end); | |
1577 | /* PR 17531: file: 0cc9cd00. */ | |
1578 | if (uvalue > (size_t) (end - data)) | |
1579 | uvalue = end - data; | |
1580 | printf ("%s: (", (op == DW_OP_entry_value | |
1581 | ? "DW_OP_entry_value" : "DW_OP_GNU_entry_value")); | |
1582 | if (decode_location_expression (data, pointer_size, offset_size, | |
1583 | dwarf_version, uvalue, | |
1584 | cu_offset, section)) | |
1585 | need_frame_base = 1; | |
1586 | putchar (')'); | |
1587 | data += uvalue; | |
1588 | break; | |
1589 | case DW_OP_const_type: | |
1590 | case DW_OP_GNU_const_type: | |
1591 | READ_ULEB (uvalue, data, end); | |
1592 | printf ("%s: <%#" PRIx64 "> ", | |
1593 | (op == DW_OP_const_type | |
1594 | ? "DW_OP_const_type" : "DW_OP_GNU_const_type"), | |
1595 | cu_offset + uvalue); | |
1596 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1597 | data = display_block (data, uvalue, end, ' '); | |
1598 | break; | |
1599 | case DW_OP_regval_type: | |
1600 | case DW_OP_GNU_regval_type: | |
1601 | READ_ULEB (uvalue, data, end); | |
1602 | printf ("%s: %" PRIu64 " (%s)", | |
1603 | (op == DW_OP_regval_type | |
1604 | ? "DW_OP_regval_type" : "DW_OP_GNU_regval_type"), | |
1605 | uvalue, regname (uvalue, 1)); | |
1606 | READ_ULEB (uvalue, data, end); | |
1607 | printf (" <%#" PRIx64 ">", cu_offset + uvalue); | |
1608 | break; | |
1609 | case DW_OP_deref_type: | |
1610 | case DW_OP_GNU_deref_type: | |
1611 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1612 | printf ("%s: %" PRId64, | |
1613 | (op == DW_OP_deref_type | |
1614 | ? "DW_OP_deref_type" : "DW_OP_GNU_deref_type"), | |
1615 | uvalue); | |
1616 | READ_ULEB (uvalue, data, end); | |
1617 | printf (" <%#" PRIx64 ">", cu_offset + uvalue); | |
1618 | break; | |
1619 | case DW_OP_convert: | |
1620 | case DW_OP_GNU_convert: | |
1621 | READ_ULEB (uvalue, data, end); | |
1622 | printf ("%s <%#" PRIx64 ">", | |
1623 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
1624 | uvalue ? cu_offset + uvalue : uvalue); | |
1625 | break; | |
1626 | case DW_OP_reinterpret: | |
1627 | case DW_OP_GNU_reinterpret: | |
1628 | READ_ULEB (uvalue, data, end); | |
1629 | printf ("%s <%#" PRIx64 ">", | |
1630 | (op == DW_OP_reinterpret | |
1631 | ? "DW_OP_reinterpret" : "DW_OP_GNU_reinterpret"), | |
1632 | uvalue ? cu_offset + uvalue : uvalue); | |
1633 | break; | |
1634 | case DW_OP_GNU_parameter_ref: | |
1635 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1636 | printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64 ">", | |
1637 | cu_offset + uvalue); | |
1638 | break; | |
1639 | case DW_OP_addrx: | |
1640 | READ_ULEB (uvalue, data, end); | |
1641 | printf ("DW_OP_addrx <%#" PRIx64 ">", uvalue); | |
1642 | break; | |
1643 | case DW_OP_GNU_addr_index: | |
1644 | READ_ULEB (uvalue, data, end); | |
1645 | printf ("DW_OP_GNU_addr_index <%#" PRIx64 ">", uvalue); | |
1646 | break; | |
1647 | case DW_OP_GNU_const_index: | |
1648 | READ_ULEB (uvalue, data, end); | |
1649 | printf ("DW_OP_GNU_const_index <%#" PRIx64 ">", uvalue); | |
1650 | break; | |
1651 | case DW_OP_GNU_variable_value: | |
1652 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1653 | this ought to be an 8-byte wide computation. */ | |
1654 | if (dwarf_version == -1) | |
1655 | { | |
1656 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1657 | /* No way to tell where the next op is, so just bail. */ | |
1658 | return need_frame_base; | |
1659 | } | |
1660 | if (dwarf_version == 2) | |
1661 | { | |
1662 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1663 | } | |
1664 | else | |
1665 | { | |
1666 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1667 | } | |
1668 | printf ("DW_OP_GNU_variable_value: <%#" PRIx64 ">", uvalue); | |
1669 | break; | |
1670 | ||
1671 | /* HP extensions. */ | |
1672 | case DW_OP_HP_is_value: | |
1673 | printf ("DW_OP_HP_is_value"); | |
1674 | /* FIXME: Is there data associated with this OP ? */ | |
1675 | break; | |
1676 | case DW_OP_HP_fltconst4: | |
1677 | printf ("DW_OP_HP_fltconst4"); | |
1678 | /* FIXME: Is there data associated with this OP ? */ | |
1679 | break; | |
1680 | case DW_OP_HP_fltconst8: | |
1681 | printf ("DW_OP_HP_fltconst8"); | |
1682 | /* FIXME: Is there data associated with this OP ? */ | |
1683 | break; | |
1684 | case DW_OP_HP_mod_range: | |
1685 | printf ("DW_OP_HP_mod_range"); | |
1686 | /* FIXME: Is there data associated with this OP ? */ | |
1687 | break; | |
1688 | case DW_OP_HP_unmod_range: | |
1689 | printf ("DW_OP_HP_unmod_range"); | |
1690 | /* FIXME: Is there data associated with this OP ? */ | |
1691 | break; | |
1692 | case DW_OP_HP_tls: | |
1693 | printf ("DW_OP_HP_tls"); | |
1694 | /* FIXME: Is there data associated with this OP ? */ | |
1695 | break; | |
1696 | ||
1697 | /* PGI (STMicroelectronics) extensions. */ | |
1698 | case DW_OP_PGI_omp_thread_num: | |
1699 | /* Pushes the thread number for the current thread as it would be | |
1700 | returned by the standard OpenMP library function: | |
1701 | omp_get_thread_num(). The "current thread" is the thread for | |
1702 | which the expression is being evaluated. */ | |
1703 | printf ("DW_OP_PGI_omp_thread_num"); | |
1704 | break; | |
1705 | ||
1706 | default: | |
1707 | if (op >= DW_OP_lo_user | |
1708 | && op <= DW_OP_hi_user) | |
1709 | printf (_("(User defined location op %#x)"), op); | |
1710 | else | |
1711 | printf (_("(Unknown location op %#x)"), op); | |
1712 | /* No way to tell where the next op is, so just bail. */ | |
1713 | return need_frame_base; | |
1714 | } | |
1715 | ||
1716 | /* Separate the ops. */ | |
1717 | if (data < end) | |
1718 | printf ("; "); | |
1719 | } | |
1720 | ||
1721 | return need_frame_base; | |
1722 | } | |
1723 | ||
1724 | /* Find the CU or TU set corresponding to the given CU_OFFSET. | |
1725 | This is used for DWARF package files. */ | |
1726 | ||
1727 | static struct cu_tu_set * | |
1728 | find_cu_tu_set_v2 (uint64_t cu_offset, int do_types) | |
1729 | { | |
1730 | struct cu_tu_set *p; | |
1731 | unsigned int nsets; | |
1732 | unsigned int dw_sect; | |
1733 | ||
1734 | if (do_types) | |
1735 | { | |
1736 | p = tu_sets; | |
1737 | nsets = tu_count; | |
1738 | dw_sect = DW_SECT_TYPES; | |
1739 | } | |
1740 | else | |
1741 | { | |
1742 | p = cu_sets; | |
1743 | nsets = cu_count; | |
1744 | dw_sect = DW_SECT_INFO; | |
1745 | } | |
1746 | while (nsets > 0) | |
1747 | { | |
1748 | if (p->section_offsets [dw_sect] == cu_offset) | |
1749 | return p; | |
1750 | p++; | |
1751 | nsets--; | |
1752 | } | |
1753 | return NULL; | |
1754 | } | |
1755 | ||
1756 | static const char * | |
1757 | fetch_alt_indirect_string (uint64_t offset) | |
1758 | { | |
1759 | separate_info * i; | |
1760 | ||
1761 | if (! do_follow_links) | |
1762 | return ""; | |
1763 | ||
1764 | if (first_separate_info == NULL) | |
1765 | return _("<no links available>"); | |
1766 | ||
1767 | for (i = first_separate_info; i != NULL; i = i->next) | |
1768 | { | |
1769 | struct dwarf_section * section; | |
1770 | const char * ret; | |
1771 | ||
1772 | if (! load_debug_section (separate_debug_str, i->handle)) | |
1773 | continue; | |
1774 | ||
1775 | section = &debug_displays [separate_debug_str].section; | |
1776 | ||
1777 | if (section->start == NULL) | |
1778 | continue; | |
1779 | ||
1780 | if (offset >= section->size) | |
1781 | continue; | |
1782 | ||
1783 | ret = (const char *) (section->start + offset); | |
1784 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1785 | NUL byte. Since our caller is expecting to receive a well formed C | |
1786 | string we test for the lack of a terminating byte here. */ | |
1787 | if (strnlen ((const char *) ret, section->size - offset) | |
1788 | == section->size - offset) | |
1789 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1790 | ||
1791 | return ret; | |
1792 | } | |
1793 | ||
1794 | warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64 ")" | |
1795 | " too big or no string sections available\n"), offset); | |
1796 | return _("<offset is too big>"); | |
1797 | } | |
1798 | ||
1799 | static const char * | |
1800 | get_AT_name (unsigned long attribute) | |
1801 | { | |
1802 | const char *name; | |
1803 | ||
1804 | if (attribute == 0) | |
1805 | return "DW_AT value: 0"; | |
1806 | ||
1807 | /* One value is shared by the MIPS and HP extensions: */ | |
1808 | if (attribute == DW_AT_MIPS_fde) | |
1809 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1810 | ||
1811 | name = get_DW_AT_name (attribute); | |
1812 | ||
1813 | if (name == NULL) | |
1814 | { | |
1815 | static char buffer[100]; | |
1816 | ||
1817 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1818 | attribute); | |
1819 | return buffer; | |
1820 | } | |
1821 | ||
1822 | return name; | |
1823 | } | |
1824 | ||
1825 | static void | |
1826 | add_dwo_info (const char * value, uint64_t cu_offset, dwo_type type) | |
1827 | { | |
1828 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1829 | ||
1830 | dwinfo->type = type; | |
1831 | dwinfo->value = value; | |
1832 | dwinfo->cu_offset = cu_offset; | |
1833 | dwinfo->next = first_dwo_info; | |
1834 | first_dwo_info = dwinfo; | |
1835 | } | |
1836 | ||
1837 | static void | |
1838 | add_dwo_name (const char * name, uint64_t cu_offset) | |
1839 | { | |
1840 | add_dwo_info (name, cu_offset, DWO_NAME); | |
1841 | } | |
1842 | ||
1843 | static void | |
1844 | add_dwo_dir (const char * dir, uint64_t cu_offset) | |
1845 | { | |
1846 | add_dwo_info (dir, cu_offset, DWO_DIR); | |
1847 | } | |
1848 | ||
1849 | static void | |
1850 | add_dwo_id (const char * id, uint64_t cu_offset) | |
1851 | { | |
1852 | add_dwo_info (id, cu_offset, DWO_ID); | |
1853 | } | |
1854 | ||
1855 | static void | |
1856 | free_dwo_info (void) | |
1857 | { | |
1858 | dwo_info * dwinfo; | |
1859 | dwo_info * next; | |
1860 | ||
1861 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1862 | { | |
1863 | next = dwinfo->next; | |
1864 | free (dwinfo); | |
1865 | } | |
1866 | first_dwo_info = NULL; | |
1867 | } | |
1868 | ||
1869 | /* Ensure that START + UVALUE is less than END. | |
1870 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1871 | ||
1872 | static inline uint64_t | |
1873 | check_uvalue (const unsigned char *start, | |
1874 | uint64_t uvalue, | |
1875 | const unsigned char *end) | |
1876 | { | |
1877 | uint64_t max_uvalue = end - start; | |
1878 | ||
1879 | /* See PR 17512: file: 008-103549-0.001:0.1. | |
1880 | and PR 24829 for examples of where these tests are triggered. */ | |
1881 | if (uvalue > max_uvalue) | |
1882 | { | |
1883 | warn (_("Corrupt attribute block length: %#" PRIx64 "\n"), uvalue); | |
1884 | uvalue = max_uvalue; | |
1885 | } | |
1886 | ||
1887 | return uvalue; | |
1888 | } | |
1889 | ||
1890 | static unsigned char * | |
1891 | skip_attr_bytes (unsigned long form, | |
1892 | unsigned char *data, | |
1893 | unsigned char *end, | |
1894 | uint64_t pointer_size, | |
1895 | uint64_t offset_size, | |
1896 | int dwarf_version, | |
1897 | uint64_t *value_return) | |
1898 | { | |
1899 | int64_t svalue; | |
1900 | uint64_t uvalue = 0; | |
1901 | uint64_t inc = 0; | |
1902 | ||
1903 | * value_return = 0; | |
1904 | ||
1905 | switch (form) | |
1906 | { | |
1907 | case DW_FORM_ref_addr: | |
1908 | if (dwarf_version == 2) | |
1909 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1910 | else if (dwarf_version > 2) | |
1911 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1912 | else | |
1913 | return NULL; | |
1914 | break; | |
1915 | ||
1916 | case DW_FORM_addr: | |
1917 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1918 | break; | |
1919 | ||
1920 | case DW_FORM_strp: | |
1921 | case DW_FORM_line_strp: | |
1922 | case DW_FORM_sec_offset: | |
1923 | case DW_FORM_GNU_ref_alt: | |
1924 | case DW_FORM_GNU_strp_alt: | |
1925 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1926 | break; | |
1927 | ||
1928 | case DW_FORM_flag_present: | |
1929 | uvalue = 1; | |
1930 | break; | |
1931 | ||
1932 | case DW_FORM_ref1: | |
1933 | case DW_FORM_flag: | |
1934 | case DW_FORM_data1: | |
1935 | case DW_FORM_strx1: | |
1936 | case DW_FORM_addrx1: | |
1937 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1938 | break; | |
1939 | ||
1940 | case DW_FORM_strx3: | |
1941 | case DW_FORM_addrx3: | |
1942 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); | |
1943 | break; | |
1944 | ||
1945 | case DW_FORM_ref2: | |
1946 | case DW_FORM_data2: | |
1947 | case DW_FORM_strx2: | |
1948 | case DW_FORM_addrx2: | |
1949 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
1950 | break; | |
1951 | ||
1952 | case DW_FORM_ref4: | |
1953 | case DW_FORM_data4: | |
1954 | case DW_FORM_strx4: | |
1955 | case DW_FORM_addrx4: | |
1956 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1957 | break; | |
1958 | ||
1959 | case DW_FORM_sdata: | |
1960 | READ_SLEB (svalue, data, end); | |
1961 | uvalue = svalue; | |
1962 | break; | |
1963 | ||
1964 | case DW_FORM_ref_udata: | |
1965 | case DW_FORM_udata: | |
1966 | case DW_FORM_GNU_str_index: | |
1967 | case DW_FORM_strx: | |
1968 | case DW_FORM_GNU_addr_index: | |
1969 | case DW_FORM_addrx: | |
1970 | case DW_FORM_loclistx: | |
1971 | case DW_FORM_rnglistx: | |
1972 | READ_ULEB (uvalue, data, end); | |
1973 | break; | |
1974 | ||
1975 | case DW_FORM_ref8: | |
1976 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); | |
1977 | break; | |
1978 | ||
1979 | case DW_FORM_data8: | |
1980 | case DW_FORM_ref_sig8: | |
1981 | inc = 8; | |
1982 | break; | |
1983 | ||
1984 | case DW_FORM_data16: | |
1985 | inc = 16; | |
1986 | break; | |
1987 | ||
1988 | case DW_FORM_string: | |
1989 | inc = strnlen ((char *) data, end - data) + 1; | |
1990 | break; | |
1991 | ||
1992 | case DW_FORM_block: | |
1993 | case DW_FORM_exprloc: | |
1994 | READ_ULEB (uvalue, data, end); | |
1995 | inc = uvalue; | |
1996 | break; | |
1997 | ||
1998 | case DW_FORM_block1: | |
1999 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
2000 | inc = uvalue; | |
2001 | break; | |
2002 | ||
2003 | case DW_FORM_block2: | |
2004 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
2005 | inc = uvalue; | |
2006 | break; | |
2007 | ||
2008 | case DW_FORM_block4: | |
2009 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
2010 | inc = uvalue; | |
2011 | break; | |
2012 | ||
2013 | case DW_FORM_indirect: | |
2014 | READ_ULEB (form, data, end); | |
2015 | if (form == DW_FORM_implicit_const) | |
2016 | SKIP_ULEB (data, end); | |
2017 | return skip_attr_bytes (form, data, end, pointer_size, offset_size, | |
2018 | dwarf_version, value_return); | |
2019 | ||
2020 | default: | |
2021 | return NULL; | |
2022 | } | |
2023 | ||
2024 | * value_return = uvalue; | |
2025 | if (inc <= (size_t) (end - data)) | |
2026 | data += inc; | |
2027 | else | |
2028 | data = end; | |
2029 | return data; | |
2030 | } | |
2031 | ||
2032 | /* Given form FORM with value UVALUE, locate and return the abbreviation | |
2033 | associated with it. */ | |
2034 | ||
2035 | static abbrev_entry * | |
2036 | get_type_abbrev_from_form (unsigned long form, | |
2037 | uint64_t uvalue, | |
2038 | uint64_t cu_offset, | |
2039 | unsigned char *cu_end, | |
2040 | const struct dwarf_section *section, | |
2041 | unsigned long *abbrev_num_return, | |
2042 | unsigned char **data_return, | |
2043 | abbrev_map **map_return) | |
2044 | { | |
2045 | switch (form) | |
2046 | { | |
2047 | case DW_FORM_GNU_ref_alt: | |
2048 | case DW_FORM_ref_sig8: | |
2049 | /* FIXME: We are unable to handle this form at the moment. */ | |
2050 | return NULL; | |
2051 | ||
2052 | case DW_FORM_ref_addr: | |
2053 | if (uvalue >= section->size) | |
2054 | { | |
2055 | warn (_("Unable to resolve ref_addr form: uvalue %" PRIx64 | |
2056 | " >= section size %" PRIx64 " (%s)\n"), | |
2057 | uvalue, section->size, section->name); | |
2058 | return NULL; | |
2059 | } | |
2060 | break; | |
2061 | ||
2062 | case DW_FORM_ref_sup4: | |
2063 | case DW_FORM_ref_sup8: | |
2064 | break; | |
2065 | ||
2066 | case DW_FORM_ref1: | |
2067 | case DW_FORM_ref2: | |
2068 | case DW_FORM_ref4: | |
2069 | case DW_FORM_ref8: | |
2070 | case DW_FORM_ref_udata: | |
2071 | if (uvalue + cu_offset < uvalue | |
2072 | || uvalue + cu_offset > (size_t) (cu_end - section->start)) | |
2073 | { | |
2074 | warn (_("Unable to resolve ref form: uvalue %" PRIx64 | |
2075 | " + cu_offset %" PRIx64 " > CU size %tx\n"), | |
2076 | uvalue, cu_offset, cu_end - section->start); | |
2077 | return NULL; | |
2078 | } | |
2079 | uvalue += cu_offset; | |
2080 | break; | |
2081 | ||
2082 | /* FIXME: Are there other DW_FORMs that can be used by types ? */ | |
2083 | ||
2084 | default: | |
2085 | warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form); | |
2086 | return NULL; | |
2087 | } | |
2088 | ||
2089 | abbrev_map *map = find_abbrev_map_by_offset (uvalue); | |
2090 | ||
2091 | if (map == NULL) | |
2092 | { | |
2093 | warn (_("Unable to find abbreviations for CU offset %" PRIx64 "\n"), | |
2094 | uvalue); | |
2095 | return NULL; | |
2096 | } | |
2097 | if (map->list == NULL) | |
2098 | { | |
2099 | warn (_("Empty abbreviation list encountered for CU offset %" PRIx64 "\n"), | |
2100 | uvalue); | |
2101 | return NULL; | |
2102 | } | |
2103 | ||
2104 | if (map_return != NULL) | |
2105 | { | |
2106 | if (form == DW_FORM_ref_addr) | |
2107 | *map_return = map; | |
2108 | else | |
2109 | *map_return = NULL; | |
2110 | } | |
2111 | ||
2112 | unsigned char *data = section->start + uvalue; | |
2113 | if (form == DW_FORM_ref_addr) | |
2114 | cu_end = section->start + map->end; | |
2115 | ||
2116 | unsigned long abbrev_number; | |
2117 | READ_ULEB (abbrev_number, data, cu_end); | |
2118 | ||
2119 | if (abbrev_num_return != NULL) | |
2120 | *abbrev_num_return = abbrev_number; | |
2121 | ||
2122 | if (data_return != NULL) | |
2123 | *data_return = data; | |
2124 | ||
2125 | abbrev_entry *entry; | |
2126 | for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next) | |
2127 | if (entry->number == abbrev_number) | |
2128 | break; | |
2129 | ||
2130 | if (entry == NULL) | |
2131 | warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number); | |
2132 | ||
2133 | return entry; | |
2134 | } | |
2135 | ||
2136 | /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY | |
2137 | can be determined to be a signed type. The data for ENTRY can be | |
2138 | found starting at DATA. */ | |
2139 | ||
2140 | static void | |
2141 | get_type_signedness (abbrev_entry *entry, | |
2142 | const struct dwarf_section *section, | |
2143 | unsigned char *data, | |
2144 | unsigned char *end, | |
2145 | uint64_t cu_offset, | |
2146 | uint64_t pointer_size, | |
2147 | uint64_t offset_size, | |
2148 | int dwarf_version, | |
2149 | bool *is_signed, | |
2150 | unsigned int nesting) | |
2151 | { | |
2152 | abbrev_attr * attr; | |
2153 | ||
2154 | * is_signed = false; | |
2155 | ||
2156 | #define MAX_NESTING 20 | |
2157 | if (nesting > MAX_NESTING) | |
2158 | { | |
2159 | /* FIXME: Warn - or is this expected ? | |
2160 | NB/ We need to avoid infinite recursion. */ | |
2161 | return; | |
2162 | } | |
2163 | ||
2164 | for (attr = entry->first_attr; | |
2165 | attr != NULL && attr->attribute; | |
2166 | attr = attr->next) | |
2167 | { | |
2168 | unsigned char * orig_data = data; | |
2169 | uint64_t uvalue = 0; | |
2170 | ||
2171 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
2172 | offset_size, dwarf_version, & uvalue); | |
2173 | if (data == NULL) | |
2174 | return; | |
2175 | ||
2176 | switch (attr->attribute) | |
2177 | { | |
2178 | case DW_AT_linkage_name: | |
2179 | case DW_AT_name: | |
2180 | if (do_wide) | |
2181 | { | |
2182 | if (attr->form == DW_FORM_strp) | |
2183 | printf (", %s", fetch_indirect_string (uvalue)); | |
2184 | else if (attr->form == DW_FORM_string) | |
2185 | printf (", %.*s", (int) (end - orig_data), orig_data); | |
2186 | } | |
2187 | break; | |
2188 | ||
2189 | case DW_AT_type: | |
2190 | /* Recurse. */ | |
2191 | { | |
2192 | abbrev_entry *type_abbrev; | |
2193 | unsigned char *type_data; | |
2194 | abbrev_map *map; | |
2195 | ||
2196 | type_abbrev = get_type_abbrev_from_form (attr->form, | |
2197 | uvalue, | |
2198 | cu_offset, | |
2199 | end, | |
2200 | section, | |
2201 | NULL /* abbrev num return */, | |
2202 | &type_data, | |
2203 | &map); | |
2204 | if (type_abbrev == NULL) | |
2205 | break; | |
2206 | ||
2207 | get_type_signedness (type_abbrev, section, type_data, | |
2208 | map ? section->start + map->end : end, | |
2209 | map ? map->start : cu_offset, | |
2210 | pointer_size, offset_size, dwarf_version, | |
2211 | is_signed, nesting + 1); | |
2212 | } | |
2213 | break; | |
2214 | ||
2215 | case DW_AT_encoding: | |
2216 | /* Determine signness. */ | |
2217 | switch (uvalue) | |
2218 | { | |
2219 | case DW_ATE_address: | |
2220 | /* FIXME - some architectures have signed addresses. */ | |
2221 | case DW_ATE_boolean: | |
2222 | case DW_ATE_unsigned: | |
2223 | case DW_ATE_unsigned_char: | |
2224 | case DW_ATE_unsigned_fixed: | |
2225 | * is_signed = false; | |
2226 | break; | |
2227 | ||
2228 | default: | |
2229 | case DW_ATE_complex_float: | |
2230 | case DW_ATE_float: | |
2231 | case DW_ATE_signed: | |
2232 | case DW_ATE_signed_char: | |
2233 | case DW_ATE_imaginary_float: | |
2234 | case DW_ATE_decimal_float: | |
2235 | case DW_ATE_signed_fixed: | |
2236 | * is_signed = true; | |
2237 | break; | |
2238 | } | |
2239 | break; | |
2240 | } | |
2241 | } | |
2242 | } | |
2243 | ||
2244 | static void | |
2245 | read_and_print_leb128 (unsigned char *data, | |
2246 | unsigned int *bytes_read, | |
2247 | unsigned const char *end, | |
2248 | bool is_signed) | |
2249 | { | |
2250 | int status; | |
2251 | uint64_t val = read_leb128 (data, end, is_signed, bytes_read, &status); | |
2252 | if (status != 0) | |
2253 | report_leb_status (status); | |
2254 | else if (is_signed) | |
2255 | printf ("%" PRId64, val); | |
2256 | else | |
2257 | printf ("%" PRIu64, val); | |
2258 | } | |
2259 | ||
2260 | static void | |
2261 | display_discr_list (unsigned long form, | |
2262 | uint64_t uvalue, | |
2263 | unsigned char *data, | |
2264 | int level) | |
2265 | { | |
2266 | unsigned char *end = data; | |
2267 | ||
2268 | if (uvalue == 0) | |
2269 | { | |
2270 | printf ("[default]"); | |
2271 | return; | |
2272 | } | |
2273 | ||
2274 | switch (form) | |
2275 | { | |
2276 | case DW_FORM_block: | |
2277 | case DW_FORM_block1: | |
2278 | case DW_FORM_block2: | |
2279 | case DW_FORM_block4: | |
2280 | /* Move data pointer back to the start of the byte array. */ | |
2281 | data -= uvalue; | |
2282 | break; | |
2283 | default: | |
2284 | printf ("<corrupt>\n"); | |
2285 | warn (_("corrupt discr_list - not using a block form\n")); | |
2286 | return; | |
2287 | } | |
2288 | ||
2289 | if (uvalue < 2) | |
2290 | { | |
2291 | printf ("<corrupt>\n"); | |
2292 | warn (_("corrupt discr_list - block not long enough\n")); | |
2293 | return; | |
2294 | } | |
2295 | ||
2296 | bool is_signed = (level > 0 && level <= MAX_CU_NESTING | |
2297 | ? level_type_signed [level - 1] : false); | |
2298 | ||
2299 | printf ("("); | |
2300 | while (data < end) | |
2301 | { | |
2302 | unsigned char discriminant; | |
2303 | unsigned int bytes_read; | |
2304 | ||
2305 | SAFE_BYTE_GET_AND_INC (discriminant, data, 1, end); | |
2306 | ||
2307 | switch (discriminant) | |
2308 | { | |
2309 | case DW_DSC_label: | |
2310 | printf ("label "); | |
2311 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2312 | data += bytes_read; | |
2313 | break; | |
2314 | ||
2315 | case DW_DSC_range: | |
2316 | printf ("range "); | |
2317 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2318 | data += bytes_read; | |
2319 | ||
2320 | printf (".."); | |
2321 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2322 | data += bytes_read; | |
2323 | break; | |
2324 | ||
2325 | default: | |
2326 | printf ("<corrupt>\n"); | |
2327 | warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"), | |
2328 | discriminant); | |
2329 | return; | |
2330 | } | |
2331 | ||
2332 | if (data < end) | |
2333 | printf (", "); | |
2334 | } | |
2335 | ||
2336 | if (is_signed) | |
2337 | printf (")(signed)"); | |
2338 | else | |
2339 | printf (")(unsigned)"); | |
2340 | } | |
2341 | ||
2342 | static void | |
2343 | display_lang (uint64_t uvalue) | |
2344 | { | |
2345 | switch (uvalue) | |
2346 | { | |
2347 | /* Ordered by the numeric value of these constants. */ | |
2348 | case DW_LANG_C89: printf ("ANSI C"); break; | |
2349 | case DW_LANG_C: printf ("non-ANSI C"); break; | |
2350 | case DW_LANG_Ada83: printf ("Ada"); break; | |
2351 | case DW_LANG_C_plus_plus: printf ("C++"); break; | |
2352 | case DW_LANG_Cobol74: printf ("Cobol 74"); break; | |
2353 | case DW_LANG_Cobol85: printf ("Cobol 85"); break; | |
2354 | case DW_LANG_Fortran77: printf ("FORTRAN 77"); break; | |
2355 | case DW_LANG_Fortran90: printf ("Fortran 90"); break; | |
2356 | case DW_LANG_Pascal83: printf ("ANSI Pascal"); break; | |
2357 | case DW_LANG_Modula2: printf ("Modula 2"); break; | |
2358 | ||
2359 | /* DWARF 2.1 values. */ | |
2360 | case DW_LANG_Java: printf ("Java"); break; | |
2361 | case DW_LANG_C99: printf ("ANSI C99"); break; | |
2362 | case DW_LANG_Ada95: printf ("ADA 95"); break; | |
2363 | case DW_LANG_Fortran95: printf ("Fortran 95"); break; | |
2364 | ||
2365 | /* DWARF 3 values. */ | |
2366 | case DW_LANG_PLI: printf ("PLI"); break; | |
2367 | case DW_LANG_ObjC: printf ("Objective C"); break; | |
2368 | case DW_LANG_ObjC_plus_plus: printf ("Objective C++"); break; | |
2369 | case DW_LANG_UPC: printf ("Unified Parallel C"); break; | |
2370 | case DW_LANG_D: printf ("D"); break; | |
2371 | ||
2372 | /* DWARF 4 values. */ | |
2373 | case DW_LANG_Python: printf ("Python"); break; | |
2374 | ||
2375 | /* DWARF 5 values. */ | |
2376 | case DW_LANG_OpenCL: printf ("OpenCL"); break; | |
2377 | case DW_LANG_Go: printf ("Go"); break; | |
2378 | case DW_LANG_Modula3: printf ("Modula 3"); break; | |
2379 | case DW_LANG_Haskell: printf ("Haskell"); break; | |
2380 | case DW_LANG_C_plus_plus_03: printf ("C++03"); break; | |
2381 | case DW_LANG_C_plus_plus_11: printf ("C++11"); break; | |
2382 | case DW_LANG_OCaml: printf ("OCaml"); break; | |
2383 | case DW_LANG_Rust: printf ("Rust"); break; | |
2384 | case DW_LANG_C11: printf ("C11"); break; | |
2385 | case DW_LANG_Swift: printf ("Swift"); break; | |
2386 | case DW_LANG_Julia: printf ("Julia"); break; | |
2387 | case DW_LANG_Dylan: printf ("Dylan"); break; | |
2388 | case DW_LANG_C_plus_plus_14: printf ("C++14"); break; | |
2389 | case DW_LANG_Fortran03: printf ("Fortran 03"); break; | |
2390 | case DW_LANG_Fortran08: printf ("Fortran 08"); break; | |
2391 | case DW_LANG_RenderScript: printf ("RenderScript"); break; | |
2392 | case DW_LANG_C17: printf ("C17"); break; | |
2393 | case DW_LANG_Fortran18: printf ("Fortran 18"); break; | |
2394 | case DW_LANG_Ada2005: printf ("Ada 2005"); break; | |
2395 | case DW_LANG_Ada2012: printf ("Ada 2012"); break; | |
2396 | case DW_LANG_HIP: printf ("Hip"); break; | |
2397 | case DW_LANG_Assembly: printf ("Assembler"); break; | |
2398 | case DW_LANG_C_sharp: printf ("C Sharp"); break; | |
2399 | case DW_LANG_Mojo: printf ("Mojo"); break; | |
2400 | case DW_LANG_GLSL: printf ("GLSL"); break; | |
2401 | case DW_LANG_GLSL_ES: printf ("GLSL_ES"); break; | |
2402 | case DW_LANG_HLSL: printf ("HLSL"); break; | |
2403 | case DW_LANG_OpenCL_CPP: printf ("OpenCL C++"); break; | |
2404 | case DW_LANG_CPP_for_OpenCL: printf ("C++ for OpenCL"); break; | |
2405 | case DW_LANG_SYCL: printf ("SYCL"); break; | |
2406 | case DW_LANG_C_plus_plus_17: printf ("C++17"); break; | |
2407 | case DW_LANG_C_plus_plus_20: printf ("C++20"); break; | |
2408 | case DW_LANG_C_plus_plus_23: printf ("C++23"); break; | |
2409 | case DW_LANG_Odin: printf ("Odin"); break; | |
2410 | case DW_LANG_P4: printf ("P4"); break; | |
2411 | case DW_LANG_Metal: printf ("C23"); break; | |
2412 | case DW_LANG_C23: printf ("C23"); break; | |
2413 | case DW_LANG_Fortran23: printf ("Fortran 23"); break; | |
2414 | case DW_LANG_Ruby: printf ("Ruby"); break; | |
2415 | case DW_LANG_Move: printf ("Move"); break; | |
2416 | case DW_LANG_Hylo: printf ("Hylo"); break; | |
2417 | ||
2418 | /* MIPS extension. */ | |
2419 | case DW_LANG_Mips_Assembler: printf ("MIPS assembler"); break; | |
2420 | ||
2421 | /* UPC extension. */ | |
2422 | case DW_LANG_Upc: printf ("Unified Parallel C"); break; | |
2423 | ||
2424 | default: | |
2425 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) | |
2426 | printf (_("implementation defined: %#" PRIx64 ""), uvalue); | |
2427 | else | |
2428 | printf (_("unknown: %#" PRIx64 ""), uvalue); | |
2429 | break; | |
2430 | } | |
2431 | } | |
2432 | ||
2433 | static unsigned char * | |
2434 | read_and_display_attr_value (unsigned long attribute, | |
2435 | unsigned long form, | |
2436 | int64_t implicit_const, | |
2437 | unsigned char *start, | |
2438 | unsigned char *data, | |
2439 | unsigned char *end, | |
2440 | uint64_t cu_offset, | |
2441 | uint64_t pointer_size, | |
2442 | uint64_t offset_size, | |
2443 | int dwarf_version, | |
2444 | debug_info *debug_info_p, | |
2445 | int do_loc, | |
2446 | struct dwarf_section *section, | |
2447 | struct cu_tu_set *this_set, | |
2448 | char delimiter, | |
2449 | int level) | |
2450 | { | |
2451 | int64_t svalue; | |
2452 | uint64_t uvalue = 0; | |
2453 | uint64_t uvalue_hi = 0; | |
2454 | unsigned char *block_start = NULL; | |
2455 | unsigned char *orig_data = data; | |
2456 | ||
2457 | if (data > end || (data == end && form != DW_FORM_flag_present)) | |
2458 | { | |
2459 | warn (_("Corrupt attribute\n")); | |
2460 | return data; | |
2461 | } | |
2462 | ||
2463 | if (do_wide && ! do_loc) | |
2464 | { | |
2465 | /* PR 26847: Display the name of the form. */ | |
2466 | const char * name = get_FORM_name (form); | |
2467 | ||
2468 | /* For convenience we skip the DW_FORM_ prefix to the name. */ | |
2469 | if (name[0] == 'D') | |
2470 | name += 8; /* strlen ("DW_FORM_") */ | |
2471 | printf ("%c(%s)", delimiter, name); | |
2472 | } | |
2473 | ||
2474 | switch (form) | |
2475 | { | |
2476 | case DW_FORM_ref_addr: | |
2477 | if (dwarf_version == 2) | |
2478 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
2479 | else if (dwarf_version > 2) | |
2480 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
2481 | else | |
2482 | error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); | |
2483 | break; | |
2484 | ||
2485 | case DW_FORM_addr: | |
2486 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
2487 | break; | |
2488 | ||
2489 | case DW_FORM_strp_sup: | |
2490 | case DW_FORM_strp: | |
2491 | case DW_FORM_line_strp: | |
2492 | case DW_FORM_sec_offset: | |
2493 | case DW_FORM_GNU_ref_alt: | |
2494 | case DW_FORM_GNU_strp_alt: | |
2495 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
2496 | break; | |
2497 | ||
2498 | case DW_FORM_flag_present: | |
2499 | uvalue = 1; | |
2500 | break; | |
2501 | ||
2502 | case DW_FORM_ref1: | |
2503 | case DW_FORM_flag: | |
2504 | case DW_FORM_data1: | |
2505 | case DW_FORM_strx1: | |
2506 | case DW_FORM_addrx1: | |
2507 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
2508 | break; | |
2509 | ||
2510 | case DW_FORM_ref2: | |
2511 | case DW_FORM_data2: | |
2512 | case DW_FORM_strx2: | |
2513 | case DW_FORM_addrx2: | |
2514 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
2515 | break; | |
2516 | ||
2517 | case DW_FORM_strx3: | |
2518 | case DW_FORM_addrx3: | |
2519 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); | |
2520 | break; | |
2521 | ||
2522 | case DW_FORM_ref_sup4: | |
2523 | case DW_FORM_ref4: | |
2524 | case DW_FORM_data4: | |
2525 | case DW_FORM_strx4: | |
2526 | case DW_FORM_addrx4: | |
2527 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
2528 | break; | |
2529 | ||
2530 | case DW_FORM_ref_sup8: | |
2531 | case DW_FORM_ref8: | |
2532 | case DW_FORM_data8: | |
2533 | case DW_FORM_ref_sig8: | |
2534 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); | |
2535 | break; | |
2536 | ||
2537 | case DW_FORM_data16: | |
2538 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); | |
2539 | SAFE_BYTE_GET_AND_INC (uvalue_hi, data, 8, end); | |
2540 | if (byte_get != byte_get_little_endian) | |
2541 | { | |
2542 | uint64_t utmp = uvalue; | |
2543 | uvalue = uvalue_hi; | |
2544 | uvalue_hi = utmp; | |
2545 | } | |
2546 | break; | |
2547 | ||
2548 | case DW_FORM_sdata: | |
2549 | READ_SLEB (svalue, data, end); | |
2550 | uvalue = svalue; | |
2551 | break; | |
2552 | ||
2553 | case DW_FORM_GNU_str_index: | |
2554 | case DW_FORM_strx: | |
2555 | case DW_FORM_ref_udata: | |
2556 | case DW_FORM_udata: | |
2557 | case DW_FORM_GNU_addr_index: | |
2558 | case DW_FORM_addrx: | |
2559 | case DW_FORM_loclistx: | |
2560 | case DW_FORM_rnglistx: | |
2561 | READ_ULEB (uvalue, data, end); | |
2562 | break; | |
2563 | ||
2564 | case DW_FORM_indirect: | |
2565 | READ_ULEB (form, data, end); | |
2566 | if (!do_loc) | |
2567 | printf ("%c%s", delimiter, get_FORM_name (form)); | |
2568 | if (form == DW_FORM_implicit_const) | |
2569 | READ_SLEB (implicit_const, data, end); | |
2570 | return read_and_display_attr_value (attribute, form, implicit_const, | |
2571 | start, data, end, | |
2572 | cu_offset, pointer_size, | |
2573 | offset_size, dwarf_version, | |
2574 | debug_info_p, do_loc, | |
2575 | section, this_set, delimiter, level); | |
2576 | ||
2577 | case DW_FORM_implicit_const: | |
2578 | uvalue = implicit_const; | |
2579 | break; | |
2580 | ||
2581 | default: | |
2582 | break; | |
2583 | } | |
2584 | ||
2585 | switch (form) | |
2586 | { | |
2587 | case DW_FORM_ref_addr: | |
2588 | if (!do_loc) | |
2589 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue); | |
2590 | break; | |
2591 | ||
2592 | case DW_FORM_GNU_ref_alt: | |
2593 | if (!do_loc) | |
2594 | { | |
2595 | if (do_wide) | |
2596 | /* We have already printed the form name. */ | |
2597 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue); | |
2598 | else | |
2599 | printf ("%c<alt %#" PRIx64 ">", delimiter, uvalue); | |
2600 | } | |
2601 | /* FIXME: Follow the reference... */ | |
2602 | break; | |
2603 | ||
2604 | case DW_FORM_ref1: | |
2605 | case DW_FORM_ref2: | |
2606 | case DW_FORM_ref4: | |
2607 | case DW_FORM_ref_sup4: | |
2608 | case DW_FORM_ref_udata: | |
2609 | if (!do_loc) | |
2610 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue + cu_offset); | |
2611 | break; | |
2612 | ||
2613 | case DW_FORM_data4: | |
2614 | case DW_FORM_addr: | |
2615 | case DW_FORM_sec_offset: | |
2616 | if (!do_loc) | |
2617 | printf ("%c%#" PRIx64, delimiter, uvalue); | |
2618 | break; | |
2619 | ||
2620 | case DW_FORM_flag_present: | |
2621 | case DW_FORM_flag: | |
2622 | case DW_FORM_data1: | |
2623 | case DW_FORM_data2: | |
2624 | case DW_FORM_sdata: | |
2625 | if (!do_loc) | |
2626 | printf ("%c%" PRId64, delimiter, uvalue); | |
2627 | break; | |
2628 | ||
2629 | case DW_FORM_udata: | |
2630 | if (!do_loc) | |
2631 | printf ("%c%" PRIu64, delimiter, uvalue); | |
2632 | break; | |
2633 | ||
2634 | case DW_FORM_implicit_const: | |
2635 | if (!do_loc) | |
2636 | printf ("%c%" PRId64, delimiter, implicit_const); | |
2637 | break; | |
2638 | ||
2639 | case DW_FORM_ref_sup8: | |
2640 | case DW_FORM_ref8: | |
2641 | case DW_FORM_data8: | |
2642 | if (!do_loc) | |
2643 | { | |
2644 | uint64_t utmp = uvalue; | |
2645 | if (form == DW_FORM_ref8) | |
2646 | utmp += cu_offset; | |
2647 | printf ("%c%#" PRIx64, delimiter, utmp); | |
2648 | } | |
2649 | break; | |
2650 | ||
2651 | case DW_FORM_data16: | |
2652 | if (!do_loc) | |
2653 | { | |
2654 | if (uvalue_hi == 0) | |
2655 | printf (" %#" PRIx64, uvalue); | |
2656 | else | |
2657 | printf (" %#" PRIx64 "%016" PRIx64, uvalue_hi, uvalue); | |
2658 | } | |
2659 | break; | |
2660 | ||
2661 | case DW_FORM_string: | |
2662 | if (!do_loc) | |
2663 | printf ("%c%.*s", delimiter, (int) (end - data), data); | |
2664 | data += strnlen ((char *) data, end - data); | |
2665 | if (data < end) | |
2666 | data++; | |
2667 | break; | |
2668 | ||
2669 | case DW_FORM_block: | |
2670 | case DW_FORM_exprloc: | |
2671 | READ_ULEB (uvalue, data, end); | |
2672 | do_block: | |
2673 | block_start = data; | |
2674 | if (block_start >= end) | |
2675 | { | |
2676 | warn (_("Block ends prematurely\n")); | |
2677 | uvalue = 0; | |
2678 | block_start = end; | |
2679 | } | |
2680 | ||
2681 | uvalue = check_uvalue (block_start, uvalue, end); | |
2682 | ||
2683 | data = block_start + uvalue; | |
2684 | if (!do_loc) | |
2685 | { | |
2686 | unsigned char op; | |
2687 | ||
2688 | SAFE_BYTE_GET (op, block_start, sizeof (op), end); | |
2689 | if (op != DW_OP_addrx) | |
2690 | data = display_block (block_start, uvalue, end, delimiter); | |
2691 | } | |
2692 | break; | |
2693 | ||
2694 | case DW_FORM_block1: | |
2695 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
2696 | goto do_block; | |
2697 | ||
2698 | case DW_FORM_block2: | |
2699 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
2700 | goto do_block; | |
2701 | ||
2702 | case DW_FORM_block4: | |
2703 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
2704 | goto do_block; | |
2705 | ||
2706 | case DW_FORM_strp: | |
2707 | if (!do_loc) | |
2708 | { | |
2709 | if (do_wide) | |
2710 | /* We have already displayed the form name. */ | |
2711 | printf (_("%c(offset: %#" PRIx64 "): %s"), | |
2712 | delimiter, uvalue, fetch_indirect_string (uvalue)); | |
2713 | else | |
2714 | printf (_("%c(indirect string, offset: %#" PRIx64 "): %s"), | |
2715 | delimiter, uvalue, fetch_indirect_string (uvalue)); | |
2716 | } | |
2717 | break; | |
2718 | ||
2719 | case DW_FORM_line_strp: | |
2720 | if (!do_loc) | |
2721 | { | |
2722 | if (do_wide) | |
2723 | /* We have already displayed the form name. */ | |
2724 | printf (_("%c(offset: %#" PRIx64 "): %s"), | |
2725 | delimiter, uvalue, fetch_indirect_line_string (uvalue)); | |
2726 | else | |
2727 | printf (_("%c(indirect line string, offset: %#" PRIx64 "): %s"), | |
2728 | delimiter, uvalue, fetch_indirect_line_string (uvalue)); | |
2729 | } | |
2730 | break; | |
2731 | ||
2732 | case DW_FORM_GNU_str_index: | |
2733 | case DW_FORM_strx: | |
2734 | case DW_FORM_strx1: | |
2735 | case DW_FORM_strx2: | |
2736 | case DW_FORM_strx3: | |
2737 | case DW_FORM_strx4: | |
2738 | if (!do_loc) | |
2739 | { | |
2740 | const char *suffix = section ? strrchr (section->name, '.') : NULL; | |
2741 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; | |
2742 | const char *strng; | |
2743 | ||
2744 | strng = fetch_indexed_string (uvalue, this_set, offset_size, dwo, | |
2745 | debug_info_p ? debug_info_p->str_offsets_base : 0); | |
2746 | if (do_wide) | |
2747 | /* We have already displayed the form name. */ | |
2748 | printf (_("%c(offset: %#" PRIx64 "): %s"), | |
2749 | delimiter, uvalue, strng); | |
2750 | else | |
2751 | printf (_("%c(indexed string: %#" PRIx64 "): %s"), | |
2752 | delimiter, uvalue, strng); | |
2753 | } | |
2754 | break; | |
2755 | ||
2756 | case DW_FORM_GNU_strp_alt: | |
2757 | if (!do_loc) | |
2758 | { | |
2759 | if (do_wide) | |
2760 | /* We have already displayed the form name. */ | |
2761 | printf (_("%c(offset: %#" PRIx64 ") %s"), | |
2762 | delimiter, uvalue, fetch_alt_indirect_string (uvalue)); | |
2763 | else | |
2764 | printf (_("%c(alt indirect string, offset: %#" PRIx64 ") %s"), | |
2765 | delimiter, uvalue, fetch_alt_indirect_string (uvalue)); | |
2766 | } | |
2767 | break; | |
2768 | ||
2769 | case DW_FORM_indirect: | |
2770 | /* Handled above. */ | |
2771 | break; | |
2772 | ||
2773 | case DW_FORM_ref_sig8: | |
2774 | if (!do_loc) | |
2775 | printf ("%c%s: %#" PRIx64, delimiter, do_wide ? "" : "signature", | |
2776 | uvalue); | |
2777 | break; | |
2778 | ||
2779 | case DW_FORM_GNU_addr_index: | |
2780 | case DW_FORM_addrx: | |
2781 | case DW_FORM_addrx1: | |
2782 | case DW_FORM_addrx2: | |
2783 | case DW_FORM_addrx3: | |
2784 | case DW_FORM_addrx4: | |
2785 | case DW_FORM_loclistx: | |
2786 | case DW_FORM_rnglistx: | |
2787 | if (!do_loc) | |
2788 | { | |
2789 | uint64_t base, idx; | |
2790 | const char *suffix = strrchr (section->name, '.'); | |
2791 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; | |
2792 | ||
2793 | if (form == DW_FORM_loclistx) | |
2794 | { | |
2795 | if (debug_info_p == NULL) | |
2796 | idx = -1; | |
2797 | else if (dwo) | |
2798 | { | |
2799 | idx = fetch_indexed_offset (uvalue, loclists_dwo, | |
2800 | debug_info_p->loclists_base, | |
2801 | debug_info_p->offset_size); | |
2802 | if (idx != (uint64_t) -1) | |
2803 | idx += (offset_size == 8) ? 20 : 12; | |
2804 | } | |
2805 | else if (dwarf_version > 4) | |
2806 | { | |
2807 | idx = fetch_indexed_offset (uvalue, loclists, | |
2808 | debug_info_p->loclists_base, | |
2809 | debug_info_p->offset_size); | |
2810 | } | |
2811 | else | |
2812 | { | |
2813 | /* We want to compute: | |
2814 | idx = fetch_indexed_value (uvalue, loclists, | |
2815 | debug_info_p->loclists_base); | |
2816 | idx += debug_info_p->loclists_base; | |
2817 | Fortunately we already have that sum cached in the | |
2818 | loc_offsets array. */ | |
2819 | if (uvalue < debug_info_p->num_loc_offsets) | |
2820 | idx = debug_info_p->loc_offsets [uvalue]; | |
2821 | else | |
2822 | { | |
2823 | warn (_("loc_offset %" PRIu64 " too big\n"), uvalue); | |
2824 | idx = -1; | |
2825 | } | |
2826 | } | |
2827 | } | |
2828 | else if (form == DW_FORM_rnglistx) | |
2829 | { | |
2830 | if (debug_info_p == NULL) | |
2831 | idx = -1; | |
2832 | else | |
2833 | idx = fetch_indexed_offset (uvalue, | |
2834 | dwo ? rnglists_dwo : rnglists, | |
2835 | debug_info_p->rnglists_base, | |
2836 | debug_info_p->offset_size); | |
2837 | } | |
2838 | else | |
2839 | { | |
2840 | if (debug_info_p == NULL) | |
2841 | base = 0; | |
2842 | else if (debug_info_p->addr_base == DEBUG_INFO_UNAVAILABLE) | |
2843 | base = 0; | |
2844 | else | |
2845 | base = debug_info_p->addr_base; | |
2846 | ||
2847 | base += uvalue * pointer_size; | |
2848 | idx = fetch_indexed_addr (base, pointer_size); | |
2849 | } | |
2850 | ||
2851 | /* We have already displayed the form name. */ | |
2852 | if (idx != (uint64_t) -1) | |
2853 | printf (_("%c(index: %#" PRIx64 "): %#" PRIx64), | |
2854 | delimiter, uvalue, idx); | |
2855 | } | |
2856 | break; | |
2857 | ||
2858 | case DW_FORM_strp_sup: | |
2859 | if (!do_loc) | |
2860 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue + cu_offset); | |
2861 | break; | |
2862 | ||
2863 | default: | |
2864 | warn (_("Unrecognized form: %#lx\n"), form); | |
2865 | /* What to do? Consume a byte maybe? */ | |
2866 | ++data; | |
2867 | break; | |
2868 | } | |
2869 | ||
2870 | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) | |
2871 | && num_debug_info_entries == 0 | |
2872 | && debug_info_p != NULL) | |
2873 | { | |
2874 | switch (attribute) | |
2875 | { | |
2876 | case DW_AT_loclists_base: | |
2877 | if (debug_info_p->loclists_base) | |
2878 | warn (_("CU @ %#" PRIx64 " has multiple loclists_base values " | |
2879 | "(%#" PRIx64 " and %#" PRIx64 ")\n"), | |
2880 | debug_info_p->cu_offset, | |
2881 | debug_info_p->loclists_base, uvalue); | |
2882 | svalue = uvalue; | |
2883 | if (svalue < 0) | |
2884 | { | |
2885 | warn (_("CU @ %#" PRIx64 " has has a negative loclists_base " | |
2886 | "value of %#" PRIx64 " - treating as zero\n"), | |
2887 | debug_info_p->cu_offset, svalue); | |
2888 | uvalue = 0; | |
2889 | } | |
2890 | debug_info_p->loclists_base = uvalue; | |
2891 | break; | |
2892 | ||
2893 | case DW_AT_rnglists_base: | |
2894 | /* Assignment to debug_info_p->rnglists_base is now elsewhere. */ | |
2895 | break; | |
2896 | ||
2897 | case DW_AT_str_offsets_base: | |
2898 | if (debug_info_p->str_offsets_base) | |
2899 | warn (_("CU @ %#" PRIx64 " has multiple str_offsets_base values " | |
2900 | "%#" PRIx64 " and %#" PRIx64 ")\n"), | |
2901 | debug_info_p->cu_offset, | |
2902 | debug_info_p->str_offsets_base, uvalue); | |
2903 | svalue = uvalue; | |
2904 | if (svalue < 0) | |
2905 | { | |
2906 | warn (_("CU @ %#" PRIx64 " has has a negative stroffsets_base " | |
2907 | "value of %#" PRIx64 " - treating as zero\n"), | |
2908 | debug_info_p->cu_offset, svalue); | |
2909 | uvalue = 0; | |
2910 | } | |
2911 | debug_info_p->str_offsets_base = uvalue; | |
2912 | break; | |
2913 | ||
2914 | case DW_AT_frame_base: | |
2915 | /* This is crude; the have_frame_base is reset on the next | |
2916 | subprogram, not at the end of the current topmost one. */ | |
2917 | have_frame_base = 1; | |
2918 | frame_base_level = level; | |
2919 | /* Fall through. */ | |
2920 | case DW_AT_location: | |
2921 | case DW_AT_GNU_locviews: | |
2922 | case DW_AT_string_length: | |
2923 | case DW_AT_return_addr: | |
2924 | case DW_AT_data_member_location: | |
2925 | case DW_AT_vtable_elem_location: | |
2926 | case DW_AT_segment: | |
2927 | case DW_AT_static_link: | |
2928 | case DW_AT_use_location: | |
2929 | case DW_AT_call_value: | |
2930 | case DW_AT_GNU_call_site_value: | |
2931 | case DW_AT_call_data_value: | |
2932 | case DW_AT_GNU_call_site_data_value: | |
2933 | case DW_AT_call_target: | |
2934 | case DW_AT_GNU_call_site_target: | |
2935 | case DW_AT_call_target_clobbered: | |
2936 | case DW_AT_GNU_call_site_target_clobbered: | |
2937 | if ((dwarf_version < 4 | |
2938 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) | |
2939 | || form == DW_FORM_sec_offset | |
2940 | || form == DW_FORM_loclistx) | |
2941 | { | |
2942 | /* Process location list. */ | |
2943 | unsigned int lmax = debug_info_p->max_loc_offsets; | |
2944 | unsigned int num = debug_info_p->num_loc_offsets; | |
2945 | ||
2946 | if (lmax == 0 || num >= lmax) | |
2947 | { | |
2948 | lmax += 1024; | |
2949 | debug_info_p->loc_offsets = (uint64_t *) | |
2950 | xcrealloc (debug_info_p->loc_offsets, | |
2951 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
2952 | debug_info_p->loc_views = (uint64_t *) | |
2953 | xcrealloc (debug_info_p->loc_views, | |
2954 | lmax, sizeof (*debug_info_p->loc_views)); | |
2955 | debug_info_p->have_frame_base = (int *) | |
2956 | xcrealloc (debug_info_p->have_frame_base, | |
2957 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
2958 | debug_info_p->max_loc_offsets = lmax; | |
2959 | } | |
2960 | if (form == DW_FORM_loclistx) | |
2961 | uvalue = fetch_indexed_offset (num, loclists, | |
2962 | debug_info_p->loclists_base, | |
2963 | debug_info_p->offset_size); | |
2964 | else if (this_set != NULL) | |
2965 | uvalue += this_set->section_offsets [DW_SECT_LOC]; | |
2966 | ||
2967 | debug_info_p->have_frame_base [num] = have_frame_base; | |
2968 | if (attribute != DW_AT_GNU_locviews) | |
2969 | { | |
2970 | /* Corrupt DWARF info can produce more offsets than views. | |
2971 | See PR 23062 for an example. */ | |
2972 | if (debug_info_p->num_loc_offsets | |
2973 | > debug_info_p->num_loc_views) | |
2974 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2975 | else | |
2976 | { | |
2977 | debug_info_p->loc_offsets [num] = uvalue; | |
2978 | debug_info_p->num_loc_offsets++; | |
2979 | } | |
2980 | } | |
2981 | else | |
2982 | { | |
2983 | if (debug_info_p->num_loc_views > num) | |
2984 | { | |
2985 | warn (_("The number of views (%u) is greater than the number of locations (%u)\n"), | |
2986 | debug_info_p->num_loc_views, num); | |
2987 | debug_info_p->num_loc_views = num; | |
2988 | } | |
2989 | else | |
2990 | num = debug_info_p->num_loc_views; | |
2991 | if (num > debug_info_p->num_loc_offsets) | |
2992 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2993 | else | |
2994 | { | |
2995 | debug_info_p->loc_views [num] = uvalue; | |
2996 | debug_info_p->num_loc_views++; | |
2997 | } | |
2998 | } | |
2999 | } | |
3000 | break; | |
3001 | ||
3002 | case DW_AT_low_pc: | |
3003 | if (need_base_address) | |
3004 | { | |
3005 | if (form == DW_FORM_addrx) | |
3006 | uvalue = fetch_indexed_addr (debug_info_p->addr_base | |
3007 | + uvalue * pointer_size, | |
3008 | pointer_size); | |
3009 | ||
3010 | debug_info_p->base_address = uvalue; | |
3011 | } | |
3012 | break; | |
3013 | ||
3014 | case DW_AT_GNU_addr_base: | |
3015 | case DW_AT_addr_base: | |
3016 | debug_info_p->addr_base = uvalue; | |
3017 | /* Retrieved elsewhere so that it is in | |
3018 | place by the time we read low_pc. */ | |
3019 | break; | |
3020 | ||
3021 | case DW_AT_GNU_ranges_base: | |
3022 | debug_info_p->ranges_base = uvalue; | |
3023 | break; | |
3024 | ||
3025 | case DW_AT_ranges: | |
3026 | if ((dwarf_version < 4 | |
3027 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) | |
3028 | || form == DW_FORM_sec_offset | |
3029 | || form == DW_FORM_rnglistx) | |
3030 | { | |
3031 | /* Process range list. */ | |
3032 | unsigned int lmax = debug_info_p->max_range_lists; | |
3033 | unsigned int num = debug_info_p->num_range_lists; | |
3034 | ||
3035 | if (lmax == 0 || num >= lmax) | |
3036 | { | |
3037 | lmax += 1024; | |
3038 | debug_info_p->range_lists = (uint64_t *) | |
3039 | xcrealloc (debug_info_p->range_lists, | |
3040 | lmax, sizeof (*debug_info_p->range_lists)); | |
3041 | debug_info_p->max_range_lists = lmax; | |
3042 | } | |
3043 | ||
3044 | if (form == DW_FORM_rnglistx) | |
3045 | uvalue = fetch_indexed_offset (uvalue, rnglists, | |
3046 | debug_info_p->rnglists_base, | |
3047 | debug_info_p->offset_size); | |
3048 | ||
3049 | debug_info_p->range_lists [num] = uvalue; | |
3050 | debug_info_p->num_range_lists++; | |
3051 | } | |
3052 | break; | |
3053 | ||
3054 | case DW_AT_GNU_dwo_name: | |
3055 | case DW_AT_dwo_name: | |
3056 | if (need_dwo_info) | |
3057 | switch (form) | |
3058 | { | |
3059 | case DW_FORM_strp: | |
3060 | add_dwo_name ((const char *) fetch_indirect_string (uvalue), | |
3061 | cu_offset); | |
3062 | break; | |
3063 | case DW_FORM_GNU_strp_alt: | |
3064 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset); | |
3065 | break; | |
3066 | case DW_FORM_GNU_str_index: | |
3067 | case DW_FORM_strx: | |
3068 | case DW_FORM_strx1: | |
3069 | case DW_FORM_strx2: | |
3070 | case DW_FORM_strx3: | |
3071 | case DW_FORM_strx4: | |
3072 | add_dwo_name (fetch_indexed_string (uvalue, this_set, | |
3073 | offset_size, false, | |
3074 | debug_info_p->str_offsets_base), | |
3075 | cu_offset); | |
3076 | break; | |
3077 | case DW_FORM_string: | |
3078 | add_dwo_name ((const char *) orig_data, cu_offset); | |
3079 | break; | |
3080 | default: | |
3081 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
3082 | get_FORM_name (form), get_AT_name (attribute)); | |
3083 | break; | |
3084 | } | |
3085 | break; | |
3086 | ||
3087 | case DW_AT_comp_dir: | |
3088 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
3089 | if (need_dwo_info) | |
3090 | switch (form) | |
3091 | { | |
3092 | case DW_FORM_strp: | |
3093 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue), cu_offset); | |
3094 | break; | |
3095 | case DW_FORM_GNU_strp_alt: | |
3096 | add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset); | |
3097 | break; | |
3098 | case DW_FORM_line_strp: | |
3099 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue), cu_offset); | |
3100 | break; | |
3101 | case DW_FORM_GNU_str_index: | |
3102 | case DW_FORM_strx: | |
3103 | case DW_FORM_strx1: | |
3104 | case DW_FORM_strx2: | |
3105 | case DW_FORM_strx3: | |
3106 | case DW_FORM_strx4: | |
3107 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false, | |
3108 | debug_info_p->str_offsets_base), | |
3109 | cu_offset); | |
3110 | break; | |
3111 | case DW_FORM_string: | |
3112 | add_dwo_dir ((const char *) orig_data, cu_offset); | |
3113 | break; | |
3114 | default: | |
3115 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
3116 | get_FORM_name (form), get_AT_name (attribute)); | |
3117 | break; | |
3118 | } | |
3119 | break; | |
3120 | ||
3121 | case DW_AT_GNU_dwo_id: | |
3122 | if (need_dwo_info) | |
3123 | switch (form) | |
3124 | { | |
3125 | case DW_FORM_data8: | |
3126 | /* FIXME: Record the length of the ID as well ? */ | |
3127 | add_dwo_id ((const char *) (data - 8), cu_offset); | |
3128 | break; | |
3129 | default: | |
3130 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
3131 | get_FORM_name (form), get_AT_name (attribute)); | |
3132 | break; | |
3133 | } | |
3134 | break; | |
3135 | ||
3136 | default: | |
3137 | break; | |
3138 | } | |
3139 | } | |
3140 | ||
3141 | if (do_loc || attribute == 0) | |
3142 | return data; | |
3143 | ||
3144 | /* For some attributes we can display further information. */ | |
3145 | switch (attribute) | |
3146 | { | |
3147 | case DW_AT_type: | |
3148 | if (level >= 0 && level < MAX_CU_NESTING | |
3149 | && uvalue < (size_t) (end - start)) | |
3150 | { | |
3151 | bool is_signed = false; | |
3152 | abbrev_entry *type_abbrev; | |
3153 | unsigned char *type_data; | |
3154 | abbrev_map *map; | |
3155 | ||
3156 | type_abbrev = get_type_abbrev_from_form (form, uvalue, | |
3157 | cu_offset, end, | |
3158 | section, NULL, | |
3159 | &type_data, &map); | |
3160 | if (type_abbrev != NULL) | |
3161 | { | |
3162 | get_type_signedness (type_abbrev, section, type_data, | |
3163 | map ? section->start + map->end : end, | |
3164 | map ? map->start : cu_offset, | |
3165 | pointer_size, offset_size, dwarf_version, | |
3166 | & is_signed, 0); | |
3167 | } | |
3168 | level_type_signed[level] = is_signed; | |
3169 | } | |
3170 | break; | |
3171 | ||
3172 | case DW_AT_inline: | |
3173 | printf ("\t"); | |
3174 | switch (uvalue) | |
3175 | { | |
3176 | case DW_INL_not_inlined: | |
3177 | printf (_("(not inlined)")); | |
3178 | break; | |
3179 | case DW_INL_inlined: | |
3180 | printf (_("(inlined)")); | |
3181 | break; | |
3182 | case DW_INL_declared_not_inlined: | |
3183 | printf (_("(declared as inline but ignored)")); | |
3184 | break; | |
3185 | case DW_INL_declared_inlined: | |
3186 | printf (_("(declared as inline and inlined)")); | |
3187 | break; | |
3188 | default: | |
3189 | printf (_(" (Unknown inline attribute value: %#" PRIx64 ")"), | |
3190 | uvalue); | |
3191 | break; | |
3192 | } | |
3193 | break; | |
3194 | ||
3195 | case DW_AT_language: | |
3196 | printf ("\t("); | |
3197 | display_lang (uvalue); | |
3198 | printf (")"); | |
3199 | break; | |
3200 | ||
3201 | case DW_AT_encoding: | |
3202 | printf ("\t"); | |
3203 | switch (uvalue) | |
3204 | { | |
3205 | case DW_ATE_void: printf ("(void)"); break; | |
3206 | case DW_ATE_address: printf ("(machine address)"); break; | |
3207 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
3208 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
3209 | case DW_ATE_float: printf ("(float)"); break; | |
3210 | case DW_ATE_signed: printf ("(signed)"); break; | |
3211 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
3212 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
3213 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
3214 | /* DWARF 2.1 values: */ | |
3215 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; | |
3216 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
3217 | /* DWARF 3 values: */ | |
3218 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
3219 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
3220 | case DW_ATE_edited: printf ("(edited)"); break; | |
3221 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
3222 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
3223 | /* DWARF 4 values: */ | |
3224 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
3225 | /* DWARF 5 values: */ | |
3226 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
3227 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
3228 | ||
3229 | /* HP extensions: */ | |
3230 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
3231 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
3232 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
3233 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
3234 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
3235 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
3236 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
3237 | ||
3238 | default: | |
3239 | if (uvalue >= DW_ATE_lo_user | |
3240 | && uvalue <= DW_ATE_hi_user) | |
3241 | printf (_("(user defined type)")); | |
3242 | else | |
3243 | printf (_("(unknown type)")); | |
3244 | break; | |
3245 | } | |
3246 | break; | |
3247 | ||
3248 | case DW_AT_accessibility: | |
3249 | printf ("\t"); | |
3250 | switch (uvalue) | |
3251 | { | |
3252 | case DW_ACCESS_public: printf ("(public)"); break; | |
3253 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
3254 | case DW_ACCESS_private: printf ("(private)"); break; | |
3255 | default: | |
3256 | printf (_("(unknown accessibility)")); | |
3257 | break; | |
3258 | } | |
3259 | break; | |
3260 | ||
3261 | case DW_AT_visibility: | |
3262 | printf ("\t"); | |
3263 | switch (uvalue) | |
3264 | { | |
3265 | case DW_VIS_local: printf ("(local)"); break; | |
3266 | case DW_VIS_exported: printf ("(exported)"); break; | |
3267 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
3268 | default: printf (_("(unknown visibility)")); break; | |
3269 | } | |
3270 | break; | |
3271 | ||
3272 | case DW_AT_endianity: | |
3273 | printf ("\t"); | |
3274 | switch (uvalue) | |
3275 | { | |
3276 | case DW_END_default: printf ("(default)"); break; | |
3277 | case DW_END_big: printf ("(big)"); break; | |
3278 | case DW_END_little: printf ("(little)"); break; | |
3279 | default: | |
3280 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
3281 | printf (_("(user specified)")); | |
3282 | else | |
3283 | printf (_("(unknown endianity)")); | |
3284 | break; | |
3285 | } | |
3286 | break; | |
3287 | ||
3288 | case DW_AT_virtuality: | |
3289 | printf ("\t"); | |
3290 | switch (uvalue) | |
3291 | { | |
3292 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
3293 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
3294 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
3295 | default: printf (_("(unknown virtuality)")); break; | |
3296 | } | |
3297 | break; | |
3298 | ||
3299 | case DW_AT_identifier_case: | |
3300 | printf ("\t"); | |
3301 | switch (uvalue) | |
3302 | { | |
3303 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
3304 | case DW_ID_up_case: printf ("(up_case)"); break; | |
3305 | case DW_ID_down_case: printf ("(down_case)"); break; | |
3306 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
3307 | default: printf (_("(unknown case)")); break; | |
3308 | } | |
3309 | break; | |
3310 | ||
3311 | case DW_AT_calling_convention: | |
3312 | printf ("\t"); | |
3313 | switch (uvalue) | |
3314 | { | |
3315 | case DW_CC_normal: printf ("(normal)"); break; | |
3316 | case DW_CC_program: printf ("(program)"); break; | |
3317 | case DW_CC_nocall: printf ("(nocall)"); break; | |
3318 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; | |
3319 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
3320 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
3321 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
3322 | default: | |
3323 | if (uvalue >= DW_CC_lo_user | |
3324 | && uvalue <= DW_CC_hi_user) | |
3325 | printf (_("(user defined)")); | |
3326 | else | |
3327 | printf (_("(unknown convention)")); | |
3328 | } | |
3329 | break; | |
3330 | ||
3331 | case DW_AT_ordering: | |
3332 | printf ("\t"); | |
3333 | switch (uvalue) | |
3334 | { | |
3335 | case 255: | |
3336 | case -1: printf (_("(undefined)")); break; | |
3337 | case 0: printf ("(row major)"); break; | |
3338 | case 1: printf ("(column major)"); break; | |
3339 | } | |
3340 | break; | |
3341 | ||
3342 | case DW_AT_decimal_sign: | |
3343 | printf ("\t"); | |
3344 | switch (uvalue) | |
3345 | { | |
3346 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
3347 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
3348 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
3349 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
3350 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
3351 | default: printf (_("(unrecognised)")); break; | |
3352 | } | |
3353 | break; | |
3354 | ||
3355 | case DW_AT_defaulted: | |
3356 | printf ("\t"); | |
3357 | switch (uvalue) | |
3358 | { | |
3359 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
3360 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
3361 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
3362 | default: printf (_("(unrecognised)")); break; | |
3363 | } | |
3364 | break; | |
3365 | ||
3366 | case DW_AT_discr_list: | |
3367 | printf ("\t"); | |
3368 | display_discr_list (form, uvalue, data, level); | |
3369 | break; | |
3370 | ||
3371 | case DW_AT_frame_base: | |
3372 | have_frame_base = 1; | |
3373 | /* Fall through. */ | |
3374 | case DW_AT_location: | |
3375 | case DW_AT_loclists_base: | |
3376 | case DW_AT_rnglists_base: | |
3377 | case DW_AT_str_offsets_base: | |
3378 | case DW_AT_string_length: | |
3379 | case DW_AT_return_addr: | |
3380 | case DW_AT_data_member_location: | |
3381 | case DW_AT_vtable_elem_location: | |
3382 | case DW_AT_segment: | |
3383 | case DW_AT_static_link: | |
3384 | case DW_AT_use_location: | |
3385 | case DW_AT_call_value: | |
3386 | case DW_AT_GNU_call_site_value: | |
3387 | case DW_AT_call_data_value: | |
3388 | case DW_AT_GNU_call_site_data_value: | |
3389 | case DW_AT_call_target: | |
3390 | case DW_AT_GNU_call_site_target: | |
3391 | case DW_AT_call_target_clobbered: | |
3392 | case DW_AT_GNU_call_site_target_clobbered: | |
3393 | if ((dwarf_version < 4 | |
3394 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) | |
3395 | || form == DW_FORM_sec_offset | |
3396 | || form == DW_FORM_loclistx) | |
3397 | { | |
3398 | if (attribute != DW_AT_rnglists_base | |
3399 | && attribute != DW_AT_str_offsets_base) | |
3400 | printf (_(" (location list)")); | |
3401 | } | |
3402 | /* Fall through. */ | |
3403 | case DW_AT_allocated: | |
3404 | case DW_AT_associated: | |
3405 | case DW_AT_data_location: | |
3406 | case DW_AT_stride: | |
3407 | case DW_AT_upper_bound: | |
3408 | case DW_AT_lower_bound: | |
3409 | case DW_AT_rank: | |
3410 | if (block_start) | |
3411 | { | |
3412 | int need_frame_base; | |
3413 | ||
3414 | printf ("\t("); | |
3415 | need_frame_base = decode_location_expression (block_start, | |
3416 | pointer_size, | |
3417 | offset_size, | |
3418 | dwarf_version, | |
3419 | uvalue, | |
3420 | cu_offset, section); | |
3421 | printf (")"); | |
3422 | if (need_frame_base && !have_frame_base) | |
3423 | printf (_(" [without DW_AT_frame_base]")); | |
3424 | } | |
3425 | break; | |
3426 | ||
3427 | case DW_AT_data_bit_offset: | |
3428 | case DW_AT_byte_size: | |
3429 | case DW_AT_bit_size: | |
3430 | case DW_AT_string_length_byte_size: | |
3431 | case DW_AT_string_length_bit_size: | |
3432 | case DW_AT_bit_stride: | |
3433 | if (form == DW_FORM_exprloc) | |
3434 | { | |
3435 | printf ("\t("); | |
3436 | (void) decode_location_expression (block_start, pointer_size, | |
3437 | offset_size, dwarf_version, | |
3438 | uvalue, cu_offset, section); | |
3439 | printf (")"); | |
3440 | } | |
3441 | break; | |
3442 | ||
3443 | case DW_AT_import: | |
3444 | { | |
3445 | unsigned long abbrev_number; | |
3446 | abbrev_entry *entry; | |
3447 | ||
3448 | entry = get_type_abbrev_from_form (form, uvalue, cu_offset, end, | |
3449 | section, & abbrev_number, NULL, NULL); | |
3450 | if (entry == NULL) | |
3451 | { | |
3452 | if (form != DW_FORM_GNU_ref_alt) | |
3453 | warn (_("Offset %#" PRIx64 " used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"), | |
3454 | uvalue, | |
3455 | orig_data - section->start); | |
3456 | } | |
3457 | else | |
3458 | { | |
3459 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); | |
3460 | printf (" (%s)", get_TAG_name (entry->tag)); | |
3461 | printf ("]"); | |
3462 | } | |
3463 | } | |
3464 | break; | |
3465 | ||
3466 | default: | |
3467 | break; | |
3468 | } | |
3469 | ||
3470 | return data; | |
3471 | } | |
3472 | ||
3473 | static unsigned char * | |
3474 | read_and_display_attr (unsigned long attribute, | |
3475 | unsigned long form, | |
3476 | int64_t implicit_const, | |
3477 | unsigned char *start, | |
3478 | unsigned char *data, | |
3479 | unsigned char *end, | |
3480 | uint64_t cu_offset, | |
3481 | uint64_t pointer_size, | |
3482 | uint64_t offset_size, | |
3483 | int dwarf_version, | |
3484 | debug_info *debug_info_p, | |
3485 | int do_loc, | |
3486 | struct dwarf_section *section, | |
3487 | struct cu_tu_set *this_set, | |
3488 | int level) | |
3489 | { | |
3490 | if (!do_loc) | |
3491 | printf (" %-18s:", get_AT_name (attribute)); | |
3492 | data = read_and_display_attr_value (attribute, form, implicit_const, | |
3493 | start, data, end, | |
3494 | cu_offset, pointer_size, offset_size, | |
3495 | dwarf_version, debug_info_p, | |
3496 | do_loc, section, this_set, ' ', level); | |
3497 | if (!do_loc) | |
3498 | printf ("\n"); | |
3499 | return data; | |
3500 | } | |
3501 | ||
3502 | /* Like load_debug_section, but if the ordinary call fails, and we are | |
3503 | following debug links, then attempt to load the requested section | |
3504 | from one of the separate debug info files. */ | |
3505 | ||
3506 | static bool | |
3507 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
3508 | void * handle) | |
3509 | { | |
3510 | if (load_debug_section (sec_enum, handle)) | |
3511 | { | |
3512 | if (debug_displays[sec_enum].section.filename == NULL) | |
3513 | { | |
3514 | /* See if we can associate a filename with this section. */ | |
3515 | separate_info * i; | |
3516 | ||
3517 | for (i = first_separate_info; i != NULL; i = i->next) | |
3518 | if (i->handle == handle) | |
3519 | { | |
3520 | debug_displays[sec_enum].section.filename = i->filename; | |
3521 | break; | |
3522 | } | |
3523 | } | |
3524 | ||
3525 | return true; | |
3526 | } | |
3527 | ||
3528 | if (do_follow_links) | |
3529 | { | |
3530 | separate_info * i; | |
3531 | ||
3532 | for (i = first_separate_info; i != NULL; i = i->next) | |
3533 | { | |
3534 | if (load_debug_section (sec_enum, i->handle)) | |
3535 | { | |
3536 | debug_displays[sec_enum].section.filename = i->filename; | |
3537 | ||
3538 | /* FIXME: We should check to see if any of the remaining debug info | |
3539 | files also contain this section, and, umm, do something about it. */ | |
3540 | return true; | |
3541 | } | |
3542 | } | |
3543 | } | |
3544 | ||
3545 | return false; | |
3546 | } | |
3547 | ||
3548 | static void | |
3549 | introduce (struct dwarf_section * section, bool raw) | |
3550 | { | |
3551 | if (raw) | |
3552 | { | |
3553 | if (do_follow_links && section->filename) | |
3554 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3555 | section->name, section->filename); | |
3556 | else | |
3557 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3558 | } | |
3559 | else | |
3560 | { | |
3561 | if (do_follow_links && section->filename) | |
3562 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3563 | section->name, section->filename); | |
3564 | else | |
3565 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3566 | } | |
3567 | } | |
3568 | ||
3569 | /* Free memory allocated for one unit in debug_information. */ | |
3570 | ||
3571 | static void | |
3572 | free_debug_information (debug_info *ent) | |
3573 | { | |
3574 | if (ent->max_loc_offsets) | |
3575 | { | |
3576 | free (ent->loc_offsets); | |
3577 | free (ent->loc_views); | |
3578 | free (ent->have_frame_base); | |
3579 | } | |
3580 | if (ent->max_range_lists) | |
3581 | { | |
3582 | free (ent->range_lists); | |
3583 | } | |
3584 | } | |
3585 | ||
3586 | /* For look-ahead in attributes. When you want to scan a DIE for one specific | |
3587 | attribute and ignore the rest. */ | |
3588 | ||
3589 | static unsigned char * | |
3590 | skip_attribute (unsigned long form, | |
3591 | unsigned char * data, | |
3592 | unsigned char * end, | |
3593 | uint64_t pointer_size, | |
3594 | uint64_t offset_size, | |
3595 | int dwarf_version) | |
3596 | { | |
3597 | uint64_t temp; | |
3598 | size_t inc; | |
3599 | ||
3600 | switch (form) | |
3601 | { | |
3602 | case DW_FORM_ref_addr: | |
3603 | inc = dwarf_version == 2 ? pointer_size : offset_size; | |
3604 | break; | |
3605 | case DW_FORM_addr: | |
3606 | inc = pointer_size; | |
3607 | break; | |
3608 | case DW_FORM_strp_sup: | |
3609 | case DW_FORM_strp: | |
3610 | case DW_FORM_line_strp: | |
3611 | case DW_FORM_sec_offset: | |
3612 | case DW_FORM_GNU_ref_alt: | |
3613 | case DW_FORM_GNU_strp_alt: | |
3614 | inc = offset_size; | |
3615 | break; | |
3616 | case DW_FORM_ref1: | |
3617 | case DW_FORM_flag: | |
3618 | case DW_FORM_data1: | |
3619 | case DW_FORM_strx1: | |
3620 | case DW_FORM_addrx1: | |
3621 | inc = 1; | |
3622 | break; | |
3623 | case DW_FORM_ref2: | |
3624 | case DW_FORM_data2: | |
3625 | case DW_FORM_strx2: | |
3626 | case DW_FORM_addrx2: | |
3627 | inc = 2; | |
3628 | break; | |
3629 | case DW_FORM_strx3: | |
3630 | case DW_FORM_addrx3: | |
3631 | inc = 3; | |
3632 | break; | |
3633 | case DW_FORM_ref_sup4: | |
3634 | case DW_FORM_ref4: | |
3635 | case DW_FORM_data4: | |
3636 | case DW_FORM_strx4: | |
3637 | case DW_FORM_addrx4: | |
3638 | inc = 4; | |
3639 | break; | |
3640 | case DW_FORM_ref_sup8: | |
3641 | case DW_FORM_ref8: | |
3642 | case DW_FORM_data8: | |
3643 | case DW_FORM_ref_sig8: | |
3644 | inc = 8; | |
3645 | break; | |
3646 | case DW_FORM_data16: | |
3647 | inc = 16; | |
3648 | break; | |
3649 | case DW_FORM_sdata: | |
3650 | SKIP_SLEB (data, end); | |
3651 | return data; | |
3652 | case DW_FORM_GNU_str_index: | |
3653 | case DW_FORM_strx: | |
3654 | case DW_FORM_ref_udata: | |
3655 | case DW_FORM_udata: | |
3656 | case DW_FORM_GNU_addr_index: | |
3657 | case DW_FORM_addrx: | |
3658 | case DW_FORM_loclistx: | |
3659 | case DW_FORM_rnglistx: | |
3660 | SKIP_ULEB (data, end); | |
3661 | return data; | |
3662 | case DW_FORM_indirect: | |
3663 | while (form == DW_FORM_indirect) | |
3664 | READ_ULEB (form, data, end); | |
3665 | return skip_attribute (form, data, end, pointer_size, offset_size, | |
3666 | dwarf_version); | |
3667 | ||
3668 | case DW_FORM_string: | |
3669 | inc = strnlen ((char *) data, end - data); | |
3670 | break; | |
3671 | case DW_FORM_block: | |
3672 | case DW_FORM_exprloc: | |
3673 | READ_ULEB (temp, data, end); | |
3674 | inc = temp; | |
3675 | break; | |
3676 | case DW_FORM_block1: | |
3677 | SAFE_BYTE_GET_AND_INC (temp, data, 1, end); | |
3678 | inc = temp; | |
3679 | break; | |
3680 | case DW_FORM_block2: | |
3681 | SAFE_BYTE_GET_AND_INC (temp, data, 2, end); | |
3682 | inc = temp; | |
3683 | break; | |
3684 | case DW_FORM_block4: | |
3685 | SAFE_BYTE_GET_AND_INC (temp, data, 4, end); | |
3686 | inc = temp; | |
3687 | break; | |
3688 | case DW_FORM_implicit_const: | |
3689 | case DW_FORM_flag_present: | |
3690 | return data; | |
3691 | default: | |
3692 | warn (_("Unexpected form in top DIE\n")); | |
3693 | return data; | |
3694 | } | |
3695 | if (inc <= (size_t) (end - data)) | |
3696 | data += inc; | |
3697 | else | |
3698 | data = end; | |
3699 | return data; | |
3700 | } | |
3701 | ||
3702 | static void | |
3703 | read_bases (abbrev_entry * entry, | |
3704 | unsigned char * data, | |
3705 | unsigned char * end, | |
3706 | int64_t pointer_size, | |
3707 | uint64_t offset_size, | |
3708 | int dwarf_version, | |
3709 | debug_info * debug_info_p) | |
3710 | { | |
3711 | abbrev_attr *attr; | |
3712 | ||
3713 | for (attr = entry->first_attr; | |
3714 | attr && attr->attribute; | |
3715 | attr = attr->next) | |
3716 | { | |
3717 | uint64_t uvalue; | |
3718 | ||
3719 | if (attr->attribute == DW_AT_rnglists_base) | |
3720 | { | |
3721 | if (attr->form == DW_FORM_sec_offset) | |
3722 | { | |
3723 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
3724 | debug_info_p->rnglists_base = uvalue; | |
3725 | } | |
3726 | else | |
3727 | warn (_("Unexpected form of DW_AT_rnglists_base in the top DIE\n")); | |
3728 | } | |
3729 | else if (attr->attribute == DW_AT_addr_base | |
3730 | || attr->attribute == DW_AT_GNU_addr_base) | |
3731 | { | |
3732 | if (attr->form == DW_FORM_sec_offset) | |
3733 | { | |
3734 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
3735 | debug_info_p->addr_base = uvalue; | |
3736 | } | |
3737 | else | |
3738 | warn (_("Unexpected form of DW_AT_addr_base in the top DIE\n")); | |
3739 | } | |
3740 | else | |
3741 | data = skip_attribute (attr->form, data, end, pointer_size, | |
3742 | offset_size, dwarf_version); | |
3743 | } | |
3744 | } | |
3745 | ||
3746 | /* Process the contents of a .debug_info section. | |
3747 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3748 | and we do not want to display anything to the user. | |
3749 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3750 | a .debug_info section. | |
3751 | The information displayed is restricted by the values in DWARF_START_DIE | |
3752 | and DWARF_CUTOFF_LEVEL. | |
3753 | Returns TRUE upon success. Otherwise an error or warning message is | |
3754 | printed and FALSE is returned. */ | |
3755 | ||
3756 | static bool | |
3757 | process_debug_info (struct dwarf_section * section, | |
3758 | void *file, | |
3759 | enum dwarf_section_display_enum abbrev_sec, | |
3760 | bool do_loc, | |
3761 | bool do_types) | |
3762 | { | |
3763 | unsigned char *start = section->start; | |
3764 | unsigned char *end = start + section->size; | |
3765 | unsigned char *section_begin; | |
3766 | unsigned int unit; | |
3767 | unsigned int num_units = 0; | |
3768 | ||
3769 | /* First scan the section to get the number of comp units. | |
3770 | Length sanity checks are done here. */ | |
3771 | for (section_begin = start, num_units = 0; section_begin < end; | |
3772 | num_units ++) | |
3773 | { | |
3774 | uint64_t length; | |
3775 | ||
3776 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3777 | will be the length. For a 64-bit DWARF section, it'll be | |
3778 | the escape code 0xffffffff followed by an 8 byte length. */ | |
3779 | SAFE_BYTE_GET_AND_INC (length, section_begin, 4, end); | |
3780 | ||
3781 | if (length == 0xffffffff) | |
3782 | SAFE_BYTE_GET_AND_INC (length, section_begin, 8, end); | |
3783 | else if (length >= 0xfffffff0 && length < 0xffffffff) | |
3784 | { | |
3785 | warn (_("Reserved length value (%#" PRIx64 ") found in section %s\n"), | |
3786 | length, section->name); | |
3787 | return false; | |
3788 | } | |
3789 | ||
3790 | /* Negative values are illegal, they may even cause infinite | |
3791 | looping. This can happen if we can't accurately apply | |
3792 | relocations to an object file, or if the file is corrupt. */ | |
3793 | if (length > (size_t) (end - section_begin)) | |
3794 | { | |
3795 | warn (_("Corrupt unit length (got %#" PRIx64 | |
3796 | " expected at most %#tx) in section %s\n"), | |
3797 | length, end - section_begin, section->name); | |
3798 | return false; | |
3799 | } | |
3800 | section_begin += length; | |
3801 | } | |
3802 | ||
3803 | if (num_units == 0) | |
3804 | { | |
3805 | error (_("No comp units in %s section ?\n"), section->name); | |
3806 | return false; | |
3807 | } | |
3808 | ||
3809 | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) | |
3810 | && alloc_num_debug_info_entries == 0 | |
3811 | && !do_types) | |
3812 | { | |
3813 | /* Then allocate an array to hold the information. */ | |
3814 | debug_information = cmalloc (num_units, sizeof (*debug_information)); | |
3815 | if (debug_information == NULL) | |
3816 | { | |
3817 | error (_("Not enough memory for a debug info array of %u entries\n"), | |
3818 | num_units); | |
3819 | alloc_num_debug_info_entries = num_debug_info_entries = 0; | |
3820 | return false; | |
3821 | } | |
3822 | ||
3823 | /* PR 17531: file: 92ca3797. | |
3824 | We cannot rely upon the debug_information array being initialised | |
3825 | before it is used. A corrupt file could easily contain references | |
3826 | to a unit for which information has not been made available. So | |
3827 | we ensure that the array is zeroed here. */ | |
3828 | memset (debug_information, 0, num_units * sizeof (*debug_information)); | |
3829 | ||
3830 | alloc_num_debug_info_entries = num_units; | |
3831 | } | |
3832 | ||
3833 | if (!do_loc) | |
3834 | { | |
3835 | load_debug_section_with_follow (str, file); | |
3836 | load_debug_section_with_follow (line_str, file); | |
3837 | load_debug_section_with_follow (str_dwo, file); | |
3838 | load_debug_section_with_follow (str_index, file); | |
3839 | load_debug_section_with_follow (str_index_dwo, file); | |
3840 | load_debug_section_with_follow (debug_addr, file); | |
3841 | } | |
3842 | ||
3843 | load_debug_section_with_follow (abbrev_sec, file); | |
3844 | load_debug_section_with_follow (loclists, file); | |
3845 | load_debug_section_with_follow (rnglists, file); | |
3846 | load_debug_section_with_follow (loclists_dwo, file); | |
3847 | load_debug_section_with_follow (rnglists_dwo, file); | |
3848 | ||
3849 | if (debug_displays [abbrev_sec].section.start == NULL) | |
3850 | { | |
3851 | warn (_("Unable to locate %s section!\n"), | |
3852 | debug_displays [abbrev_sec].section.uncompressed_name); | |
3853 | return false; | |
3854 | } | |
3855 | ||
3856 | if (!do_loc && dwarf_start_die == 0) | |
3857 | introduce (section, false); | |
3858 | ||
3859 | free_all_abbrevs (); | |
3860 | ||
3861 | /* In order to be able to resolve DW_FORM_ref_addr forms we need | |
3862 | to load *all* of the abbrevs for all CUs in this .debug_info | |
3863 | section. This does effectively mean that we (partially) read | |
3864 | every CU header twice. */ | |
3865 | for (section_begin = start; start < end;) | |
3866 | { | |
3867 | DWARF2_Internal_CompUnit compunit; | |
3868 | unsigned char *hdrptr; | |
3869 | uint64_t abbrev_base; | |
3870 | size_t abbrev_size; | |
3871 | uint64_t cu_offset; | |
3872 | unsigned int offset_size; | |
3873 | struct cu_tu_set *this_set; | |
3874 | unsigned char *end_cu; | |
3875 | ||
3876 | hdrptr = start; | |
3877 | cu_offset = start - section_begin; | |
3878 | ||
3879 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); | |
3880 | ||
3881 | if (compunit.cu_length == 0xffffffff) | |
3882 | { | |
3883 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); | |
3884 | offset_size = 8; | |
3885 | } | |
3886 | else | |
3887 | offset_size = 4; | |
3888 | end_cu = hdrptr + compunit.cu_length; | |
3889 | ||
3890 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu); | |
3891 | ||
3892 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); | |
3893 | ||
3894 | if (compunit.cu_version < 5) | |
3895 | { | |
3896 | compunit.cu_unit_type = DW_UT_compile; | |
3897 | /* Initialize it due to a false compiler warning. */ | |
3898 | compunit.cu_pointer_size = -1; | |
3899 | } | |
3900 | else | |
3901 | { | |
3902 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu); | |
3903 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3904 | ||
3905 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); | |
3906 | } | |
3907 | ||
3908 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, | |
3909 | end_cu); | |
3910 | ||
3911 | if (compunit.cu_unit_type == DW_UT_split_compile | |
3912 | || compunit.cu_unit_type == DW_UT_skeleton) | |
3913 | { | |
3914 | uint64_t dwo_id; | |
3915 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu); | |
3916 | } | |
3917 | ||
3918 | if (this_set == NULL) | |
3919 | { | |
3920 | abbrev_base = 0; | |
3921 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3922 | } | |
3923 | else | |
3924 | { | |
3925 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3926 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3927 | } | |
3928 | ||
3929 | abbrev_list *list; | |
3930 | abbrev_list *free_list; | |
3931 | list = find_and_process_abbrev_set (&debug_displays[abbrev_sec].section, | |
3932 | abbrev_base, abbrev_size, | |
3933 | compunit.cu_abbrev_offset, | |
3934 | &free_list); | |
3935 | start = end_cu; | |
3936 | if (list != NULL && list->first_abbrev != NULL) | |
3937 | record_abbrev_list_for_cu (cu_offset, start - section_begin, | |
3938 | list, free_list); | |
3939 | else if (free_list != NULL) | |
3940 | free_abbrev_list (free_list); | |
3941 | } | |
3942 | ||
3943 | for (start = section_begin, unit = 0; start < end; unit++) | |
3944 | { | |
3945 | DWARF2_Internal_CompUnit compunit; | |
3946 | unsigned char *hdrptr; | |
3947 | unsigned char *tags; | |
3948 | int level, last_level, saved_level; | |
3949 | uint64_t cu_offset; | |
3950 | unsigned int offset_size; | |
3951 | uint64_t signature = 0; | |
3952 | uint64_t type_offset = 0; | |
3953 | struct cu_tu_set *this_set; | |
3954 | uint64_t abbrev_base; | |
3955 | size_t abbrev_size; | |
3956 | unsigned char *end_cu; | |
3957 | ||
3958 | hdrptr = start; | |
3959 | cu_offset = start - section_begin; | |
3960 | ||
3961 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); | |
3962 | ||
3963 | if (compunit.cu_length == 0xffffffff) | |
3964 | { | |
3965 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); | |
3966 | offset_size = 8; | |
3967 | } | |
3968 | else | |
3969 | offset_size = 4; | |
3970 | end_cu = hdrptr + compunit.cu_length; | |
3971 | ||
3972 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu); | |
3973 | ||
3974 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); | |
3975 | ||
3976 | if (compunit.cu_version < 5) | |
3977 | { | |
3978 | compunit.cu_unit_type = DW_UT_compile; | |
3979 | /* Initialize it due to a false compiler warning. */ | |
3980 | compunit.cu_pointer_size = -1; | |
3981 | } | |
3982 | else | |
3983 | { | |
3984 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu); | |
3985 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3986 | ||
3987 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); | |
3988 | } | |
3989 | ||
3990 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end_cu); | |
3991 | ||
3992 | if (this_set == NULL) | |
3993 | { | |
3994 | abbrev_base = 0; | |
3995 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3996 | } | |
3997 | else | |
3998 | { | |
3999 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
4000 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
4001 | } | |
4002 | ||
4003 | if (compunit.cu_version < 5) | |
4004 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); | |
4005 | ||
4006 | bool do_dwo_id = false; | |
4007 | uint64_t dwo_id = 0; | |
4008 | if (compunit.cu_unit_type == DW_UT_split_compile | |
4009 | || compunit.cu_unit_type == DW_UT_skeleton) | |
4010 | { | |
4011 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu); | |
4012 | do_dwo_id = true; | |
4013 | } | |
4014 | ||
4015 | /* PR 17512: file: 001-108546-0.001:0.1. */ | |
4016 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
4017 | { | |
4018 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
4019 | compunit.cu_pointer_size, offset_size); | |
4020 | compunit.cu_pointer_size = offset_size; | |
4021 | } | |
4022 | ||
4023 | if (do_types) | |
4024 | { | |
4025 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, end_cu); | |
4026 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end_cu); | |
4027 | } | |
4028 | ||
4029 | if (dwarf_start_die >= (size_t) (end_cu - section_begin)) | |
4030 | { | |
4031 | start = end_cu; | |
4032 | continue; | |
4033 | } | |
4034 | ||
4035 | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) | |
4036 | && num_debug_info_entries == 0 | |
4037 | && alloc_num_debug_info_entries > unit | |
4038 | && ! do_types) | |
4039 | { | |
4040 | free_debug_information (&debug_information[unit]); | |
4041 | memset (&debug_information[unit], 0, sizeof (*debug_information)); | |
4042 | debug_information[unit].pointer_size = compunit.cu_pointer_size; | |
4043 | debug_information[unit].offset_size = offset_size; | |
4044 | debug_information[unit].dwarf_version = compunit.cu_version; | |
4045 | debug_information[unit].cu_offset = cu_offset; | |
4046 | debug_information[unit].addr_base = DEBUG_INFO_UNAVAILABLE; | |
4047 | debug_information[unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
4048 | } | |
4049 | ||
4050 | if (!do_loc && dwarf_start_die == 0) | |
4051 | { | |
4052 | printf (_(" Compilation Unit @ offset %#" PRIx64 ":\n"), | |
4053 | cu_offset); | |
4054 | printf (_(" Length: %#" PRIx64 " (%s)\n"), | |
4055 | compunit.cu_length, | |
4056 | offset_size == 8 ? "64-bit" : "32-bit"); | |
4057 | printf (_(" Version: %d\n"), compunit.cu_version); | |
4058 | if (compunit.cu_version >= 5) | |
4059 | { | |
4060 | const char *name = get_DW_UT_name (compunit.cu_unit_type); | |
4061 | ||
4062 | printf (_(" Unit Type: %s (%x)\n"), | |
4063 | null_name (name), | |
4064 | compunit.cu_unit_type); | |
4065 | } | |
4066 | printf (_(" Abbrev Offset: %#" PRIx64 "\n"), | |
4067 | compunit.cu_abbrev_offset); | |
4068 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); | |
4069 | if (do_types) | |
4070 | { | |
4071 | printf (_(" Signature: %#" PRIx64 "\n"), signature); | |
4072 | printf (_(" Type Offset: %#" PRIx64 "\n"), type_offset); | |
4073 | } | |
4074 | if (do_dwo_id) | |
4075 | printf (_(" DWO ID: %#" PRIx64 "\n"), dwo_id); | |
4076 | if (this_set != NULL) | |
4077 | { | |
4078 | uint64_t *offsets = this_set->section_offsets; | |
4079 | size_t *sizes = this_set->section_sizes; | |
4080 | ||
4081 | printf (_(" Section contributions:\n")); | |
4082 | printf (_(" .debug_abbrev.dwo: %#" PRIx64 " %#zx\n"), | |
4083 | offsets[DW_SECT_ABBREV], sizes[DW_SECT_ABBREV]); | |
4084 | printf (_(" .debug_line.dwo: %#" PRIx64 " %#zx\n"), | |
4085 | offsets[DW_SECT_LINE], sizes[DW_SECT_LINE]); | |
4086 | printf (_(" .debug_loc.dwo: %#" PRIx64 " %#zx\n"), | |
4087 | offsets[DW_SECT_LOC], sizes[DW_SECT_LOC]); | |
4088 | printf (_(" .debug_str_offsets.dwo: %#" PRIx64 " %#zx\n"), | |
4089 | offsets[DW_SECT_STR_OFFSETS], sizes[DW_SECT_STR_OFFSETS]); | |
4090 | } | |
4091 | } | |
4092 | ||
4093 | tags = hdrptr; | |
4094 | start = end_cu; | |
4095 | ||
4096 | if (compunit.cu_version < 2 || compunit.cu_version > 5) | |
4097 | { | |
4098 | warn (_("CU at offset %#" PRIx64 " contains corrupt or " | |
4099 | "unsupported version number: %d.\n"), | |
4100 | cu_offset, compunit.cu_version); | |
4101 | continue; | |
4102 | } | |
4103 | ||
4104 | if (compunit.cu_unit_type != DW_UT_compile | |
4105 | && compunit.cu_unit_type != DW_UT_partial | |
4106 | && compunit.cu_unit_type != DW_UT_type | |
4107 | && compunit.cu_unit_type != DW_UT_split_compile | |
4108 | && compunit.cu_unit_type != DW_UT_skeleton) | |
4109 | { | |
4110 | warn (_("CU at offset %#" PRIx64 " contains corrupt or " | |
4111 | "unsupported unit type: %d.\n"), | |
4112 | cu_offset, compunit.cu_unit_type); | |
4113 | continue; | |
4114 | } | |
4115 | ||
4116 | /* Process the abbrevs used by this compilation unit. */ | |
4117 | abbrev_list *list; | |
4118 | list = find_and_process_abbrev_set (&debug_displays[abbrev_sec].section, | |
4119 | abbrev_base, abbrev_size, | |
4120 | compunit.cu_abbrev_offset, NULL); | |
4121 | level = 0; | |
4122 | last_level = level; | |
4123 | saved_level = -1; | |
4124 | while (tags < start) | |
4125 | { | |
4126 | unsigned long abbrev_number; | |
4127 | unsigned long die_offset; | |
4128 | abbrev_entry *entry; | |
4129 | abbrev_attr *attr; | |
4130 | int do_printing = 1; | |
4131 | ||
4132 | die_offset = tags - section_begin; | |
4133 | ||
4134 | READ_ULEB (abbrev_number, tags, start); | |
4135 | ||
4136 | /* A null DIE marks the end of a list of siblings or it may also be | |
4137 | a section padding. */ | |
4138 | if (abbrev_number == 0) | |
4139 | { | |
4140 | /* Check if it can be a section padding for the last CU. */ | |
4141 | if (level == 0 && start == end) | |
4142 | { | |
4143 | unsigned char *chk; | |
4144 | ||
4145 | for (chk = tags; chk < start; chk++) | |
4146 | if (*chk != 0) | |
4147 | break; | |
4148 | if (chk == start) | |
4149 | break; | |
4150 | } | |
4151 | ||
4152 | if (!do_loc && die_offset >= dwarf_start_die | |
4153 | && (dwarf_cutoff_level == -1 | |
4154 | || level < dwarf_cutoff_level)) | |
4155 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), | |
4156 | level, die_offset); | |
4157 | ||
4158 | --level; | |
4159 | if (level < 0) | |
4160 | { | |
4161 | static unsigned num_bogus_warns = 0; | |
4162 | ||
4163 | if (num_bogus_warns < 3) | |
4164 | { | |
4165 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), | |
4166 | die_offset, section->name); | |
4167 | num_bogus_warns ++; | |
4168 | if (num_bogus_warns == 3) | |
4169 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
4170 | } | |
4171 | } | |
4172 | if (dwarf_start_die != 0 && level < saved_level) | |
4173 | { | |
4174 | if (list != NULL) | |
4175 | free_abbrev_list (list); | |
4176 | return true; | |
4177 | } | |
4178 | continue; | |
4179 | } | |
4180 | ||
4181 | if (!do_loc) | |
4182 | { | |
4183 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
4184 | do_printing = 0; | |
4185 | else | |
4186 | { | |
4187 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
4188 | saved_level = level; | |
4189 | do_printing = (dwarf_cutoff_level == -1 | |
4190 | || level < dwarf_cutoff_level); | |
4191 | if (do_printing) | |
4192 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
4193 | level, die_offset, abbrev_number); | |
4194 | else if (dwarf_cutoff_level == -1 | |
4195 | || last_level < dwarf_cutoff_level) | |
4196 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
4197 | last_level = level; | |
4198 | } | |
4199 | } | |
4200 | ||
4201 | /* Scan through the abbreviation list until we reach the | |
4202 | correct entry. */ | |
4203 | entry = NULL; | |
4204 | if (list != NULL) | |
4205 | for (entry = list->first_abbrev; entry != NULL; entry = entry->next) | |
4206 | if (entry->number == abbrev_number) | |
4207 | break; | |
4208 | ||
4209 | if (entry == NULL) | |
4210 | { | |
4211 | if (!do_loc && do_printing) | |
4212 | { | |
4213 | printf ("\n"); | |
4214 | fflush (stdout); | |
4215 | } | |
4216 | warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"), | |
4217 | die_offset, abbrev_number); | |
4218 | if (list != NULL) | |
4219 | free_abbrev_list (list); | |
4220 | return false; | |
4221 | } | |
4222 | ||
4223 | if (!do_loc && do_printing) | |
4224 | printf (" (%s)\n", get_TAG_name (entry->tag)); | |
4225 | ||
4226 | switch (entry->tag) | |
4227 | { | |
4228 | default: | |
4229 | need_base_address = 0; | |
4230 | break; | |
4231 | case DW_TAG_compile_unit: | |
4232 | case DW_TAG_skeleton_unit: | |
4233 | need_base_address = 1; | |
4234 | need_dwo_info = do_loc; | |
4235 | break; | |
4236 | case DW_TAG_entry_point: | |
4237 | need_base_address = 0; | |
4238 | /* Assuming that there is no DW_AT_frame_base. */ | |
4239 | have_frame_base = 0; | |
4240 | break; | |
4241 | case DW_TAG_subprogram: | |
4242 | need_base_address = 0; | |
4243 | if (level <= frame_base_level) | |
4244 | /* Don't reset that for nested subprogram. */ | |
4245 | have_frame_base = 0; | |
4246 | break; | |
4247 | } | |
4248 | ||
4249 | debug_info *debug_info_p = ((debug_information | |
4250 | && unit < alloc_num_debug_info_entries) | |
4251 | ? debug_information + unit : NULL); | |
4252 | ||
4253 | assert (!debug_info_p | |
4254 | || (debug_info_p->num_loc_offsets | |
4255 | == debug_info_p->num_loc_views)); | |
4256 | ||
4257 | /* Look ahead so that the values of DW_AT_rnglists_base, | |
4258 | DW_AT_[GNU_]addr_base are available before attributes that | |
4259 | reference them are parsed in the same DIE. | |
4260 | Only needed for the top DIE on DWARFv5+. | |
4261 | No simiar treatment for loclists_base because there should | |
4262 | be no loclist attributes in top DIE. */ | |
4263 | if (debug_info_p && compunit.cu_version >= 5 && level == 0) | |
4264 | { | |
4265 | int64_t stemp; | |
4266 | ||
4267 | read_bases (entry, | |
4268 | tags, | |
4269 | start, | |
4270 | compunit.cu_pointer_size, | |
4271 | offset_size, | |
4272 | compunit.cu_version, | |
4273 | debug_info_p); | |
4274 | ||
4275 | /* This check was in place before, keep it. */ | |
4276 | stemp = debug_info_p->rnglists_base; | |
4277 | if (stemp < 0) | |
4278 | { | |
4279 | warn (_("CU @ %#" PRIx64 " has has a negative rnglists_base " | |
4280 | "value of %#" PRIx64 " - treating as zero\n"), | |
4281 | debug_info_p->cu_offset, stemp); | |
4282 | debug_info_p->rnglists_base = 0; | |
4283 | } | |
4284 | } | |
4285 | ||
4286 | for (attr = entry->first_attr; | |
4287 | attr && attr->attribute; | |
4288 | attr = attr->next) | |
4289 | { | |
4290 | if (! do_loc && do_printing) | |
4291 | /* Show the offset from where the tag was extracted. */ | |
4292 | printf (" <%tx>", tags - section_begin); | |
4293 | tags = read_and_display_attr (attr->attribute, | |
4294 | attr->form, | |
4295 | attr->implicit_const, | |
4296 | section_begin, | |
4297 | tags, | |
4298 | start, | |
4299 | cu_offset, | |
4300 | compunit.cu_pointer_size, | |
4301 | offset_size, | |
4302 | compunit.cu_version, | |
4303 | debug_info_p, | |
4304 | do_loc || ! do_printing, | |
4305 | section, | |
4306 | this_set, | |
4307 | level); | |
4308 | } | |
4309 | ||
4310 | /* If a locview attribute appears before a location one, | |
4311 | make sure we don't associate it with an earlier | |
4312 | loclist. */ | |
4313 | if (debug_info_p) | |
4314 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
4315 | { | |
4316 | case 1: | |
4317 | debug_info_p->loc_views [debug_info_p->num_loc_views] = -1; | |
4318 | debug_info_p->num_loc_views++; | |
4319 | assert (debug_info_p->num_loc_views | |
4320 | == debug_info_p->num_loc_offsets); | |
4321 | break; | |
4322 | ||
4323 | case 0: | |
4324 | break; | |
4325 | ||
4326 | case -1: | |
4327 | warn (_("DIE has locviews without loclist\n")); | |
4328 | debug_info_p->num_loc_views--; | |
4329 | break; | |
4330 | ||
4331 | default: | |
4332 | assert (0); | |
4333 | } | |
4334 | ||
4335 | if (entry->children) | |
4336 | ++level; | |
4337 | } | |
4338 | if (list != NULL) | |
4339 | free_abbrev_list (list); | |
4340 | } | |
4341 | ||
4342 | /* Set num_debug_info_entries here so that it can be used to check if | |
4343 | we need to process .debug_loc and .debug_ranges sections. */ | |
4344 | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) | |
4345 | && num_debug_info_entries == 0 | |
4346 | && ! do_types) | |
4347 | { | |
4348 | if (num_units > alloc_num_debug_info_entries) | |
4349 | num_debug_info_entries = alloc_num_debug_info_entries; | |
4350 | else | |
4351 | num_debug_info_entries = num_units; | |
4352 | } | |
4353 | ||
4354 | if (!do_loc) | |
4355 | printf ("\n"); | |
4356 | ||
4357 | return true; | |
4358 | } | |
4359 | ||
4360 | /* Locate and scan the .debug_info section in the file and record the pointer | |
4361 | sizes and offsets for the compilation units in it. Usually an executable | |
4362 | will have just one pointer size, but this is not guaranteed, and so we try | |
4363 | not to make any assumptions. Returns zero upon failure, or the number of | |
4364 | compilation units upon success. */ | |
4365 | ||
4366 | static unsigned int | |
4367 | load_debug_info (void * file) | |
4368 | { | |
4369 | /* If we have already tried and failed to load the .debug_info | |
4370 | section then do not bother to repeat the task. */ | |
4371 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
4372 | return 0; | |
4373 | ||
4374 | /* If we already have the information there is nothing else to do. */ | |
4375 | if (num_debug_info_entries > 0) | |
4376 | return num_debug_info_entries; | |
4377 | ||
4378 | /* If this is a DWARF package file, load the CU and TU indexes. */ | |
4379 | (void) load_cu_tu_indexes (file); | |
4380 | ||
4381 | if (load_debug_section_with_follow (info, file) | |
4382 | && process_debug_info (&debug_displays [info].section, file, abbrev, true, false)) | |
4383 | return num_debug_info_entries; | |
4384 | ||
4385 | if (load_debug_section_with_follow (info_dwo, file) | |
4386 | && process_debug_info (&debug_displays [info_dwo].section, file, | |
4387 | abbrev_dwo, true, false)) | |
4388 | return num_debug_info_entries; | |
4389 | ||
4390 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; | |
4391 | return 0; | |
4392 | } | |
4393 | ||
4394 | /* Read a DWARF .debug_line section header starting at DATA. | |
4395 | Upon success returns an updated DATA pointer and the LINFO | |
4396 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
4397 | Otherwise returns NULL. */ | |
4398 | ||
4399 | static unsigned char * | |
4400 | read_debug_line_header (struct dwarf_section * section, | |
4401 | unsigned char * data, | |
4402 | unsigned char * end, | |
4403 | DWARF2_Internal_LineInfo * linfo, | |
4404 | unsigned char ** end_of_sequence) | |
4405 | { | |
4406 | unsigned char *hdrptr; | |
4407 | ||
4408 | /* Extract information from the Line Number Program Header. | |
4409 | (section 6.2.4 in the Dwarf3 doc). */ | |
4410 | hdrptr = data; | |
4411 | ||
4412 | /* Get and check the length of the block. */ | |
4413 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
4414 | ||
4415 | if (linfo->li_length == 0xffffffff) | |
4416 | { | |
4417 | /* This section is 64-bit DWARF 3. */ | |
4418 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); | |
4419 | linfo->li_offset_size = 8; | |
4420 | } | |
4421 | else | |
4422 | linfo->li_offset_size = 4; | |
4423 | ||
4424 | if (linfo->li_length > (size_t) (end - hdrptr)) | |
4425 | { | |
4426 | /* If the length field has a relocation against it, then we should | |
4427 | not complain if it is inaccurate (and probably negative). This | |
4428 | happens in object files when the .debug_line section is actually | |
4429 | comprised of several different .debug_line.* sections, (some of | |
4430 | which may be removed by linker garbage collection), and a relocation | |
4431 | is used to compute the correct length once that is done. */ | |
4432 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) | |
4433 | { | |
4434 | linfo->li_length = end - hdrptr; | |
4435 | } | |
4436 | else | |
4437 | { | |
4438 | warn (_("The length field (%#" PRIx64 ")" | |
4439 | " in the debug_line header is wrong" | |
4440 | " - the section is too small\n"), | |
4441 | linfo->li_length); | |
4442 | return NULL; | |
4443 | } | |
4444 | } | |
4445 | end = hdrptr + linfo->li_length; | |
4446 | ||
4447 | /* Get and check the version number. */ | |
4448 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
4449 | ||
4450 | if (linfo->li_version != 2 | |
4451 | && linfo->li_version != 3 | |
4452 | && linfo->li_version != 4 | |
4453 | && linfo->li_version != 5) | |
4454 | { | |
4455 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " | |
4456 | "is currently supported.\n")); | |
4457 | return NULL; | |
4458 | } | |
4459 | ||
4460 | if (linfo->li_version >= 5) | |
4461 | { | |
4462 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); | |
4463 | ||
4464 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); | |
4465 | if (linfo->li_segment_size != 0) | |
4466 | { | |
4467 | warn (_("The %s section contains " | |
4468 | "unsupported segment selector size: %d.\n"), | |
4469 | section->name, linfo->li_segment_size); | |
4470 | return NULL; | |
4471 | } | |
4472 | } | |
4473 | ||
4474 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
4475 | linfo->li_offset_size, end); | |
4476 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); | |
4477 | ||
4478 | if (linfo->li_version >= 4) | |
4479 | { | |
4480 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); | |
4481 | ||
4482 | if (linfo->li_max_ops_per_insn == 0) | |
4483 | { | |
4484 | warn (_("Invalid maximum operations per insn.\n")); | |
4485 | return NULL; | |
4486 | } | |
4487 | } | |
4488 | else | |
4489 | linfo->li_max_ops_per_insn = 1; | |
4490 | ||
4491 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); | |
4492 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); | |
4493 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); | |
4494 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
4495 | ||
4496 | *end_of_sequence = end; | |
4497 | return hdrptr; | |
4498 | } | |
4499 | ||
4500 | static unsigned char * | |
4501 | display_formatted_table (unsigned char *data, | |
4502 | unsigned char *start, | |
4503 | unsigned char *end, | |
4504 | const DWARF2_Internal_LineInfo *linfo, | |
4505 | struct dwarf_section *section, | |
4506 | bool is_dir) | |
4507 | { | |
4508 | unsigned char *format_start, format_count, *format, formati; | |
4509 | uint64_t data_count, datai; | |
4510 | unsigned int namepass, last_entry = 0; | |
4511 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); | |
4512 | ||
4513 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4514 | if (do_checks && format_count > 5) | |
4515 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), | |
4516 | table_name, format_count); | |
4517 | ||
4518 | format_start = data; | |
4519 | for (formati = 0; formati < format_count; formati++) | |
4520 | { | |
4521 | SKIP_ULEB (data, end); | |
4522 | SKIP_ULEB (data, end); | |
4523 | if (data >= end) | |
4524 | { | |
4525 | warn (_("%s: Corrupt format description entry\n"), table_name); | |
4526 | return data; | |
4527 | } | |
4528 | } | |
4529 | ||
4530 | READ_ULEB (data_count, data, end); | |
4531 | if (data_count == 0) | |
4532 | { | |
4533 | printf (_("\n The %s is empty.\n"), table_name); | |
4534 | return data; | |
4535 | } | |
4536 | else if (data >= end | |
4537 | || data_count > (size_t) (end - data)) | |
4538 | { | |
4539 | warn (_("%s: Corrupt entry count %#" PRIx64 "\n"), table_name, data_count); | |
4540 | return data; | |
4541 | } | |
4542 | ||
4543 | else if (format_count == 0) | |
4544 | { | |
4545 | warn (_("%s: format count is zero, but the table is not empty\n"), | |
4546 | table_name); | |
4547 | return end; | |
4548 | } | |
4549 | ||
4550 | printf (_("\n The %s (offset %#tx, lines %" PRIu64 ", columns %u):\n"), | |
4551 | table_name, data - start, data_count, format_count); | |
4552 | ||
4553 | printf (_(" Entry")); | |
4554 | /* Delay displaying name as the last entry for better screen layout. */ | |
4555 | for (namepass = 0; namepass < 2; namepass++) | |
4556 | { | |
4557 | format = format_start; | |
4558 | for (formati = 0; formati < format_count; formati++) | |
4559 | { | |
4560 | uint64_t content_type; | |
4561 | ||
4562 | READ_ULEB (content_type, format, end); | |
4563 | if ((content_type == DW_LNCT_path) == (namepass == 1)) | |
4564 | switch (content_type) | |
4565 | { | |
4566 | case DW_LNCT_path: | |
4567 | printf (_("\tName")); | |
4568 | break; | |
4569 | case DW_LNCT_directory_index: | |
4570 | printf (_("\tDir")); | |
4571 | break; | |
4572 | case DW_LNCT_timestamp: | |
4573 | printf (_("\tTime")); | |
4574 | break; | |
4575 | case DW_LNCT_size: | |
4576 | printf (_("\tSize")); | |
4577 | break; | |
4578 | case DW_LNCT_MD5: | |
4579 | printf (_("\tMD5\t\t\t")); | |
4580 | break; | |
4581 | default: | |
4582 | printf (_("\t(Unknown format content type %" PRIu64 ")"), | |
4583 | content_type); | |
4584 | } | |
4585 | SKIP_ULEB (format, end); | |
4586 | } | |
4587 | } | |
4588 | putchar ('\n'); | |
4589 | ||
4590 | for (datai = 0; datai < data_count; datai++) | |
4591 | { | |
4592 | unsigned char *datapass = data; | |
4593 | ||
4594 | printf (" %d", last_entry++); | |
4595 | /* Delay displaying name as the last entry for better screen layout. */ | |
4596 | for (namepass = 0; namepass < 2; namepass++) | |
4597 | { | |
4598 | format = format_start; | |
4599 | data = datapass; | |
4600 | for (formati = 0; formati < format_count; formati++) | |
4601 | { | |
4602 | uint64_t content_type, form; | |
4603 | ||
4604 | READ_ULEB (content_type, format, end); | |
4605 | READ_ULEB (form, format, end); | |
4606 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
4607 | 0, 0, linfo->li_offset_size, | |
4608 | linfo->li_version, NULL, | |
4609 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
4610 | section, NULL, '\t', -1); | |
4611 | } | |
4612 | } | |
4613 | ||
4614 | if (data >= end && (datai < data_count - 1)) | |
4615 | { | |
4616 | warn (_("\n%s: Corrupt entries list\n"), table_name); | |
4617 | return data; | |
4618 | } | |
4619 | putchar ('\n'); | |
4620 | } | |
4621 | return data; | |
4622 | } | |
4623 | ||
4624 | static int | |
4625 | display_debug_sup (struct dwarf_section * section, | |
4626 | void * file ATTRIBUTE_UNUSED) | |
4627 | { | |
4628 | unsigned char * start = section->start; | |
4629 | unsigned char * end = section->start + section->size; | |
4630 | unsigned int version; | |
4631 | char is_supplementary; | |
4632 | const unsigned char * sup_filename; | |
4633 | size_t sup_filename_len; | |
4634 | unsigned int num_read; | |
4635 | int status; | |
4636 | uint64_t checksum_len; | |
4637 | ||
4638 | ||
4639 | introduce (section, true); | |
4640 | if (section->size < 4) | |
4641 | { | |
4642 | error (_("corrupt .debug_sup section: size is too small\n")); | |
4643 | return 0; | |
4644 | } | |
4645 | ||
4646 | /* Read the data. */ | |
4647 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); | |
4648 | if (version < 5) | |
4649 | warn (_("corrupt .debug_sup section: version < 5\n")); | |
4650 | ||
4651 | SAFE_BYTE_GET_AND_INC (is_supplementary, start, 1, end); | |
4652 | if (is_supplementary != 0 && is_supplementary != 1) | |
4653 | warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n")); | |
4654 | ||
4655 | sup_filename = start; | |
4656 | if (is_supplementary && sup_filename[0] != 0) | |
4657 | warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n")); | |
4658 | ||
4659 | sup_filename_len = strnlen ((const char *) start, end - start); | |
4660 | if (sup_filename_len == (size_t) (end - start)) | |
4661 | { | |
4662 | error (_("corrupt .debug_sup section: filename is not NUL terminated\n")); | |
4663 | return 0; | |
4664 | } | |
4665 | start += sup_filename_len + 1; | |
4666 | ||
4667 | checksum_len = read_leb128 (start, end, false /* unsigned */, & num_read, & status); | |
4668 | if (status) | |
4669 | { | |
4670 | error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n")); | |
4671 | checksum_len = 0; | |
4672 | } | |
4673 | start += num_read; | |
4674 | if (checksum_len > (size_t) (end - start)) | |
4675 | { | |
4676 | error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n")); | |
4677 | checksum_len = end - start; | |
4678 | } | |
4679 | else if (checksum_len < (size_t) (end - start)) | |
4680 | { | |
4681 | warn (_("corrupt .debug_sup section: there are %#" PRIx64 | |
4682 | " extra, unused bytes at the end of the section\n"), | |
4683 | (end - start) - checksum_len); | |
4684 | } | |
4685 | ||
4686 | printf (_(" Version: %u\n"), version); | |
4687 | printf (_(" Is Supp: %u\n"), is_supplementary); | |
4688 | printf (_(" Filename: %s\n"), sup_filename); | |
4689 | printf (_(" Checksum Len: %" PRIu64 "\n"), checksum_len); | |
4690 | if (checksum_len > 0) | |
4691 | { | |
4692 | printf (_(" Checksum: ")); | |
4693 | while (checksum_len--) | |
4694 | printf ("0x%x ", * start++ ); | |
4695 | printf ("\n"); | |
4696 | } | |
4697 | return 1; | |
4698 | } | |
4699 | ||
4700 | static int | |
4701 | display_debug_lines_raw (struct dwarf_section * section, | |
4702 | unsigned char * data, | |
4703 | unsigned char * end, | |
4704 | void * file) | |
4705 | { | |
4706 | unsigned char *start = section->start; | |
4707 | int verbose_view = 0; | |
4708 | ||
4709 | introduce (section, true); | |
4710 | ||
4711 | while (data < end) | |
4712 | { | |
4713 | static DWARF2_Internal_LineInfo saved_linfo; | |
4714 | DWARF2_Internal_LineInfo linfo; | |
4715 | unsigned char *standard_opcodes; | |
4716 | unsigned char *end_of_sequence; | |
4717 | int i; | |
4718 | ||
4719 | if (startswith (section->name, ".debug_line.") | |
4720 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4721 | These are full debug_line sections. */ | |
4722 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
4723 | { | |
4724 | /* Sections named .debug_line.<foo> are fragments of a .debug_line | |
4725 | section containing just the Line Number Statements. They are | |
4726 | created by the assembler and intended to be used alongside gcc's | |
4727 | -ffunction-sections command line option. When the linker's | |
4728 | garbage collection decides to discard a .text.<foo> section it | |
4729 | can then also discard the line number information in .debug_line.<foo>. | |
4730 | ||
4731 | Since the section is a fragment it does not have the details | |
4732 | needed to fill out a LineInfo structure, so instead we use the | |
4733 | details from the last full debug_line section that we processed. */ | |
4734 | end_of_sequence = end; | |
4735 | standard_opcodes = NULL; | |
4736 | linfo = saved_linfo; | |
4737 | /* PR 17531: file: 0522b371. */ | |
4738 | if (linfo.li_line_range == 0) | |
4739 | { | |
4740 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); | |
4741 | return 0; | |
4742 | } | |
4743 | reset_state_machine (linfo.li_default_is_stmt); | |
4744 | } | |
4745 | else | |
4746 | { | |
4747 | unsigned char * hdrptr; | |
4748 | ||
4749 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, | |
4750 | & end_of_sequence)) == NULL) | |
4751 | return 0; | |
4752 | ||
4753 | printf (_(" Offset: %#tx\n"), data - start); | |
4754 | printf (_(" Length: %" PRId64 "\n"), linfo.li_length); | |
4755 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
4756 | if (linfo.li_version >= 5) | |
4757 | { | |
4758 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); | |
4759 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); | |
4760 | } | |
4761 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); | |
4762 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); | |
4763 | if (linfo.li_version >= 4) | |
4764 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
4765 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
4766 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4767 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4768 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
4769 | ||
4770 | /* PR 17512: file: 1665-6428-0.004. */ | |
4771 | if (linfo.li_line_range == 0) | |
4772 | { | |
4773 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4774 | linfo.li_line_range = 1; | |
4775 | } | |
4776 | ||
4777 | reset_state_machine (linfo.li_default_is_stmt); | |
4778 | ||
4779 | /* Display the contents of the Opcodes table. */ | |
4780 | standard_opcodes = hdrptr; | |
4781 | ||
4782 | /* PR 17512: file: 002-417945-0.004. */ | |
4783 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4784 | { | |
4785 | warn (_("Line Base extends beyond end of section\n")); | |
4786 | return 0; | |
4787 | } | |
4788 | ||
4789 | printf (_("\n Opcodes:\n")); | |
4790 | ||
4791 | for (i = 1; i < linfo.li_opcode_base; i++) | |
4792 | printf (ngettext (" Opcode %d has %d arg\n", | |
4793 | " Opcode %d has %d args\n", | |
4794 | standard_opcodes[i - 1]), | |
4795 | i, standard_opcodes[i - 1]); | |
4796 | ||
4797 | /* Display the contents of the Directory table. */ | |
4798 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
4799 | ||
4800 | if (linfo.li_version >= 5) | |
4801 | { | |
4802 | load_debug_section_with_follow (line_str, file); | |
4803 | ||
4804 | data = display_formatted_table (data, start, end, &linfo, section, | |
4805 | true); | |
4806 | data = display_formatted_table (data, start, end, &linfo, section, | |
4807 | false); | |
4808 | } | |
4809 | else | |
4810 | { | |
4811 | if (*data == 0) | |
4812 | printf (_("\n The Directory Table is empty.\n")); | |
4813 | else | |
4814 | { | |
4815 | unsigned int last_dir_entry = 0; | |
4816 | ||
4817 | printf (_("\n The Directory Table (offset %#tx):\n"), | |
4818 | data - start); | |
4819 | ||
4820 | while (data < end && *data != 0) | |
4821 | { | |
4822 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
4823 | ||
4824 | data += strnlen ((char *) data, end - data); | |
4825 | if (data < end) | |
4826 | data++; | |
4827 | } | |
4828 | ||
4829 | /* PR 17512: file: 002-132094-0.004. */ | |
4830 | if (data >= end - 1) | |
4831 | break; | |
4832 | } | |
4833 | ||
4834 | /* Skip the NUL at the end of the table. */ | |
4835 | if (data < end) | |
4836 | data++; | |
4837 | ||
4838 | /* Display the contents of the File Name table. */ | |
4839 | if (data >= end || *data == 0) | |
4840 | printf (_("\n The File Name Table is empty.\n")); | |
4841 | else | |
4842 | { | |
4843 | printf (_("\n The File Name Table (offset %#tx):\n"), | |
4844 | data - start); | |
4845 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
4846 | ||
4847 | while (data < end && *data != 0) | |
4848 | { | |
4849 | unsigned char *name; | |
4850 | uint64_t val; | |
4851 | ||
4852 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4853 | name = data; | |
4854 | data += strnlen ((char *) data, end - data); | |
4855 | if (data < end) | |
4856 | data++; | |
4857 | ||
4858 | READ_ULEB (val, data, end); | |
4859 | printf ("%" PRIu64 "\t", val); | |
4860 | READ_ULEB (val, data, end); | |
4861 | printf ("%" PRIu64 "\t", val); | |
4862 | READ_ULEB (val, data, end); | |
4863 | printf ("%" PRIu64 "\t", val); | |
4864 | printf ("%.*s\n", (int)(end - name), name); | |
4865 | ||
4866 | if (data >= end) | |
4867 | { | |
4868 | warn (_("Corrupt file name table entry\n")); | |
4869 | break; | |
4870 | } | |
4871 | } | |
4872 | } | |
4873 | ||
4874 | /* Skip the NUL at the end of the table. */ | |
4875 | if (data < end) | |
4876 | data++; | |
4877 | } | |
4878 | ||
4879 | putchar ('\n'); | |
4880 | saved_linfo = linfo; | |
4881 | } | |
4882 | ||
4883 | /* Now display the statements. */ | |
4884 | if (data >= end_of_sequence) | |
4885 | printf (_(" No Line Number Statements.\n")); | |
4886 | else | |
4887 | { | |
4888 | printf (_(" Line Number Statements:\n")); | |
4889 | ||
4890 | while (data < end_of_sequence) | |
4891 | { | |
4892 | unsigned char op_code; | |
4893 | int adv; | |
4894 | uint64_t uladv; | |
4895 | ||
4896 | printf (" [0x%08tx]", data - start); | |
4897 | ||
4898 | op_code = *data++; | |
4899 | ||
4900 | if (op_code >= linfo.li_opcode_base) | |
4901 | { | |
4902 | op_code -= linfo.li_opcode_base; | |
4903 | uladv = (op_code / linfo.li_line_range); | |
4904 | if (linfo.li_max_ops_per_insn == 1) | |
4905 | { | |
4906 | uladv *= linfo.li_min_insn_length; | |
4907 | state_machine_regs.address += uladv; | |
4908 | if (uladv) | |
4909 | state_machine_regs.view = 0; | |
4910 | printf (_(" Special opcode %d: " | |
4911 | "advance Address by %" PRIu64 | |
4912 | " to %#" PRIx64 "%s"), | |
4913 | op_code, uladv, state_machine_regs.address, | |
4914 | verbose_view && uladv | |
4915 | ? _(" (reset view)") : ""); | |
4916 | } | |
4917 | else | |
4918 | { | |
4919 | unsigned addrdelta | |
4920 | = ((state_machine_regs.op_index + uladv) | |
4921 | / linfo.li_max_ops_per_insn) | |
4922 | * linfo.li_min_insn_length; | |
4923 | ||
4924 | state_machine_regs.address += addrdelta; | |
4925 | state_machine_regs.op_index | |
4926 | = (state_machine_regs.op_index + uladv) | |
4927 | % linfo.li_max_ops_per_insn; | |
4928 | if (addrdelta) | |
4929 | state_machine_regs.view = 0; | |
4930 | printf (_(" Special opcode %d: " | |
4931 | "advance Address by %" PRIu64 | |
4932 | " to %#" PRIx64 "[%d]%s"), | |
4933 | op_code, uladv, state_machine_regs.address, | |
4934 | state_machine_regs.op_index, | |
4935 | verbose_view && addrdelta | |
4936 | ? _(" (reset view)") : ""); | |
4937 | } | |
4938 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4939 | state_machine_regs.line += adv; | |
4940 | printf (_(" and Line by %d to %d"), | |
4941 | adv, state_machine_regs.line); | |
4942 | if (verbose_view || state_machine_regs.view) | |
4943 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4944 | else | |
4945 | putchar ('\n'); | |
4946 | state_machine_regs.view++; | |
4947 | } | |
4948 | else | |
4949 | switch (op_code) | |
4950 | { | |
4951 | case DW_LNS_extended_op: | |
4952 | data += process_extended_line_op (data, | |
4953 | linfo.li_default_is_stmt, | |
4954 | end); | |
4955 | break; | |
4956 | ||
4957 | case DW_LNS_copy: | |
4958 | printf (_(" Copy")); | |
4959 | if (verbose_view || state_machine_regs.view) | |
4960 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4961 | else | |
4962 | putchar ('\n'); | |
4963 | state_machine_regs.view++; | |
4964 | break; | |
4965 | ||
4966 | case DW_LNS_advance_pc: | |
4967 | READ_ULEB (uladv, data, end); | |
4968 | if (linfo.li_max_ops_per_insn == 1) | |
4969 | { | |
4970 | uladv *= linfo.li_min_insn_length; | |
4971 | state_machine_regs.address += uladv; | |
4972 | if (uladv) | |
4973 | state_machine_regs.view = 0; | |
4974 | printf (_(" Advance PC by %" PRIu64 | |
4975 | " to %#" PRIx64 "%s\n"), | |
4976 | uladv, state_machine_regs.address, | |
4977 | verbose_view && uladv | |
4978 | ? _(" (reset view)") : ""); | |
4979 | } | |
4980 | else | |
4981 | { | |
4982 | unsigned addrdelta | |
4983 | = ((state_machine_regs.op_index + uladv) | |
4984 | / linfo.li_max_ops_per_insn) | |
4985 | * linfo.li_min_insn_length; | |
4986 | state_machine_regs.address | |
4987 | += addrdelta; | |
4988 | state_machine_regs.op_index | |
4989 | = (state_machine_regs.op_index + uladv) | |
4990 | % linfo.li_max_ops_per_insn; | |
4991 | if (addrdelta) | |
4992 | state_machine_regs.view = 0; | |
4993 | printf (_(" Advance PC by %" PRIu64 | |
4994 | " to %#" PRIx64 "[%d]%s\n"), | |
4995 | uladv, state_machine_regs.address, | |
4996 | state_machine_regs.op_index, | |
4997 | verbose_view && addrdelta | |
4998 | ? _(" (reset view)") : ""); | |
4999 | } | |
5000 | break; | |
5001 | ||
5002 | case DW_LNS_advance_line: | |
5003 | READ_SLEB (adv, data, end); | |
5004 | state_machine_regs.line += adv; | |
5005 | printf (_(" Advance Line by %d to %d\n"), | |
5006 | adv, state_machine_regs.line); | |
5007 | break; | |
5008 | ||
5009 | case DW_LNS_set_file: | |
5010 | READ_ULEB (uladv, data, end); | |
5011 | printf (_(" Set File Name to entry %" PRIu64 | |
5012 | " in the File Name Table\n"), uladv); | |
5013 | state_machine_regs.file = uladv; | |
5014 | break; | |
5015 | ||
5016 | case DW_LNS_set_column: | |
5017 | READ_ULEB (uladv, data, end); | |
5018 | printf (_(" Set column to %" PRIu64 "\n"), uladv); | |
5019 | state_machine_regs.column = uladv; | |
5020 | break; | |
5021 | ||
5022 | case DW_LNS_negate_stmt: | |
5023 | adv = state_machine_regs.is_stmt; | |
5024 | adv = ! adv; | |
5025 | printf (_(" Set is_stmt to %d\n"), adv); | |
5026 | state_machine_regs.is_stmt = adv; | |
5027 | break; | |
5028 | ||
5029 | case DW_LNS_set_basic_block: | |
5030 | printf (_(" Set basic block\n")); | |
5031 | state_machine_regs.basic_block = 1; | |
5032 | break; | |
5033 | ||
5034 | case DW_LNS_const_add_pc: | |
5035 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
5036 | if (linfo.li_max_ops_per_insn) | |
5037 | { | |
5038 | uladv *= linfo.li_min_insn_length; | |
5039 | state_machine_regs.address += uladv; | |
5040 | if (uladv) | |
5041 | state_machine_regs.view = 0; | |
5042 | printf (_(" Advance PC by constant %" PRIu64 | |
5043 | " to %#" PRIx64 "%s\n"), | |
5044 | uladv, state_machine_regs.address, | |
5045 | verbose_view && uladv | |
5046 | ? _(" (reset view)") : ""); | |
5047 | } | |
5048 | else | |
5049 | { | |
5050 | unsigned addrdelta | |
5051 | = ((state_machine_regs.op_index + uladv) | |
5052 | / linfo.li_max_ops_per_insn) | |
5053 | * linfo.li_min_insn_length; | |
5054 | state_machine_regs.address | |
5055 | += addrdelta; | |
5056 | state_machine_regs.op_index | |
5057 | = (state_machine_regs.op_index + uladv) | |
5058 | % linfo.li_max_ops_per_insn; | |
5059 | if (addrdelta) | |
5060 | state_machine_regs.view = 0; | |
5061 | printf (_(" Advance PC by constant %" PRIu64 | |
5062 | " to %#" PRIx64 "[%d]%s\n"), | |
5063 | uladv, state_machine_regs.address, | |
5064 | state_machine_regs.op_index, | |
5065 | verbose_view && addrdelta | |
5066 | ? _(" (reset view)") : ""); | |
5067 | } | |
5068 | break; | |
5069 | ||
5070 | case DW_LNS_fixed_advance_pc: | |
5071 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5072 | state_machine_regs.address += uladv; | |
5073 | state_machine_regs.op_index = 0; | |
5074 | printf (_(" Advance PC by fixed size amount %" PRIu64 | |
5075 | " to %#" PRIx64 "\n"), | |
5076 | uladv, state_machine_regs.address); | |
5077 | /* Do NOT reset view. */ | |
5078 | break; | |
5079 | ||
5080 | case DW_LNS_set_prologue_end: | |
5081 | printf (_(" Set prologue_end to true\n")); | |
5082 | break; | |
5083 | ||
5084 | case DW_LNS_set_epilogue_begin: | |
5085 | printf (_(" Set epilogue_begin to true\n")); | |
5086 | break; | |
5087 | ||
5088 | case DW_LNS_set_isa: | |
5089 | READ_ULEB (uladv, data, end); | |
5090 | printf (_(" Set ISA to %" PRIu64 "\n"), uladv); | |
5091 | break; | |
5092 | ||
5093 | default: | |
5094 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5095 | ||
5096 | if (standard_opcodes != NULL) | |
5097 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5098 | { | |
5099 | READ_ULEB (uladv, data, end); | |
5100 | printf ("%#" PRIx64 "%s", uladv, i == 1 ? "" : ", "); | |
5101 | } | |
5102 | putchar ('\n'); | |
5103 | break; | |
5104 | } | |
5105 | } | |
5106 | putchar ('\n'); | |
5107 | } | |
5108 | } | |
5109 | ||
5110 | return 1; | |
5111 | } | |
5112 | ||
5113 | typedef struct | |
5114 | { | |
5115 | char *name; | |
5116 | unsigned int directory_index; | |
5117 | unsigned int modification_date; | |
5118 | unsigned int length; | |
5119 | } File_Entry; | |
5120 | ||
5121 | /* Output a decoded representation of the .debug_line section. */ | |
5122 | ||
5123 | static int | |
5124 | display_debug_lines_decoded (struct dwarf_section * section, | |
5125 | unsigned char * start, | |
5126 | unsigned char * data, | |
5127 | unsigned char * end, | |
5128 | void * fileptr) | |
5129 | { | |
5130 | static DWARF2_Internal_LineInfo saved_linfo; | |
5131 | ||
5132 | introduce (section, false); | |
5133 | ||
5134 | while (data < end) | |
5135 | { | |
5136 | /* This loop amounts to one iteration per compilation unit. */ | |
5137 | DWARF2_Internal_LineInfo linfo; | |
5138 | unsigned char *standard_opcodes; | |
5139 | unsigned char *end_of_sequence; | |
5140 | int i; | |
5141 | File_Entry *file_table = NULL; | |
5142 | unsigned int n_files = 0; | |
5143 | char **directory_table = NULL; | |
5144 | unsigned int n_directories = 0; | |
5145 | ||
5146 | if (startswith (section->name, ".debug_line.") | |
5147 | /* Note: the following does not apply to .debug_line.dwo sections. | |
5148 | These are full debug_line sections. */ | |
5149 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
5150 | { | |
5151 | /* See comment in display_debug_lines_raw(). */ | |
5152 | end_of_sequence = end; | |
5153 | standard_opcodes = NULL; | |
5154 | linfo = saved_linfo; | |
5155 | /* PR 17531: file: 0522b371. */ | |
5156 | if (linfo.li_line_range == 0) | |
5157 | { | |
5158 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); | |
5159 | return 0; | |
5160 | } | |
5161 | reset_state_machine (linfo.li_default_is_stmt); | |
5162 | } | |
5163 | else | |
5164 | { | |
5165 | unsigned char *hdrptr; | |
5166 | ||
5167 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, | |
5168 | & end_of_sequence)) == NULL) | |
5169 | return 0; | |
5170 | ||
5171 | /* PR 17531: file: 0522b371. */ | |
5172 | if (linfo.li_line_range == 0) | |
5173 | { | |
5174 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
5175 | linfo.li_line_range = 1; | |
5176 | } | |
5177 | reset_state_machine (linfo.li_default_is_stmt); | |
5178 | ||
5179 | /* Save a pointer to the contents of the Opcodes table. */ | |
5180 | standard_opcodes = hdrptr; | |
5181 | ||
5182 | /* Traverse the Directory table just to count entries. */ | |
5183 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
5184 | /* PR 20440 */ | |
5185 | if (data >= end) | |
5186 | { | |
5187 | warn (_("opcode base of %d extends beyond end of section\n"), | |
5188 | linfo.li_opcode_base); | |
5189 | return 0; | |
5190 | } | |
5191 | ||
5192 | if (linfo.li_version >= 5) | |
5193 | { | |
5194 | unsigned char *format_start, *format; | |
5195 | unsigned int format_count, formati, entryi; | |
5196 | ||
5197 | load_debug_section_with_follow (line_str, fileptr); | |
5198 | ||
5199 | /* Skip directories format. */ | |
5200 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
5201 | if (do_checks && format_count > 1) | |
5202 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), | |
5203 | format_count); | |
5204 | format_start = data; | |
5205 | for (formati = 0; formati < format_count; formati++) | |
5206 | { | |
5207 | SKIP_ULEB (data, end); | |
5208 | SKIP_ULEB (data, end); | |
5209 | } | |
5210 | ||
5211 | READ_ULEB (n_directories, data, end); | |
5212 | if (data >= end) | |
5213 | { | |
5214 | warn (_("Corrupt directories list\n")); | |
5215 | break; | |
5216 | } | |
5217 | ||
5218 | if (n_directories == 0) | |
5219 | directory_table = NULL; | |
5220 | else if (n_directories > section->size) | |
5221 | { | |
5222 | warn (_("number of directories (0x%x) exceeds size of section %s\n"), | |
5223 | n_directories, section->name); | |
5224 | return 0; | |
5225 | } | |
5226 | else | |
5227 | directory_table = (char **) | |
5228 | xcalloc (n_directories, sizeof (unsigned char *)); | |
5229 | ||
5230 | for (entryi = 0; entryi < n_directories; entryi++) | |
5231 | { | |
5232 | char **pathp = &directory_table[entryi]; | |
5233 | ||
5234 | format = format_start; | |
5235 | for (formati = 0; formati < format_count; formati++) | |
5236 | { | |
5237 | uint64_t content_type, form; | |
5238 | uint64_t uvalue; | |
5239 | ||
5240 | READ_ULEB (content_type, format, end); | |
5241 | READ_ULEB (form, format, end); | |
5242 | if (data >= end) | |
5243 | { | |
5244 | warn (_("Corrupt directories list\n")); | |
5245 | break; | |
5246 | } | |
5247 | switch (content_type) | |
5248 | { | |
5249 | case DW_LNCT_path: | |
5250 | switch (form) | |
5251 | { | |
5252 | case DW_FORM_string: | |
5253 | *pathp = (char *) data; | |
5254 | break; | |
5255 | case DW_FORM_line_strp: | |
5256 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
5257 | end); | |
5258 | /* Remove const by the cast. */ | |
5259 | *pathp = (char *) | |
5260 | fetch_indirect_line_string (uvalue); | |
5261 | break; | |
5262 | } | |
5263 | break; | |
5264 | } | |
5265 | data = read_and_display_attr_value (0, form, 0, start, | |
5266 | data, end, 0, 0, | |
5267 | linfo.li_offset_size, | |
5268 | linfo.li_version, | |
5269 | NULL, 1, section, | |
5270 | NULL, '\t', -1); | |
5271 | } | |
5272 | if (data >= end) | |
5273 | { | |
5274 | warn (_("Corrupt directories list\n")); | |
5275 | break; | |
5276 | } | |
5277 | } | |
5278 | ||
5279 | /* Skip files format. */ | |
5280 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
5281 | if (do_checks && format_count > 5) | |
5282 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), | |
5283 | format_count); | |
5284 | ||
5285 | format_start = data; | |
5286 | for (formati = 0; formati < format_count; formati++) | |
5287 | { | |
5288 | SKIP_ULEB (data, end); | |
5289 | SKIP_ULEB (data, end); | |
5290 | } | |
5291 | ||
5292 | READ_ULEB (n_files, data, end); | |
5293 | if (data >= end && n_files > 0) | |
5294 | { | |
5295 | warn (_("Corrupt file name list\n")); | |
5296 | break; | |
5297 | } | |
5298 | ||
5299 | if (n_files == 0) | |
5300 | file_table = NULL; | |
5301 | else if (n_files > section->size) | |
5302 | { | |
5303 | warn (_("number of files (0x%x) exceeds size of section %s\n"), | |
5304 | n_files, section->name); | |
5305 | return 0; | |
5306 | } | |
5307 | else | |
5308 | file_table = (File_Entry *) xcalloc (n_files, | |
5309 | sizeof (File_Entry)); | |
5310 | ||
5311 | for (entryi = 0; entryi < n_files; entryi++) | |
5312 | { | |
5313 | File_Entry *file = &file_table[entryi]; | |
5314 | ||
5315 | format = format_start; | |
5316 | for (formati = 0; formati < format_count; formati++) | |
5317 | { | |
5318 | uint64_t content_type, form; | |
5319 | uint64_t uvalue; | |
5320 | unsigned char *tmp; | |
5321 | ||
5322 | READ_ULEB (content_type, format, end); | |
5323 | READ_ULEB (form, format, end); | |
5324 | if (data >= end) | |
5325 | { | |
5326 | warn (_("Corrupt file name list\n")); | |
5327 | break; | |
5328 | } | |
5329 | switch (content_type) | |
5330 | { | |
5331 | case DW_LNCT_path: | |
5332 | switch (form) | |
5333 | { | |
5334 | case DW_FORM_string: | |
5335 | file->name = (char *) data; | |
5336 | break; | |
5337 | case DW_FORM_line_strp: | |
5338 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
5339 | end); | |
5340 | /* Remove const by the cast. */ | |
5341 | file->name = (char *) | |
5342 | fetch_indirect_line_string (uvalue); | |
5343 | break; | |
5344 | } | |
5345 | break; | |
5346 | case DW_LNCT_directory_index: | |
5347 | switch (form) | |
5348 | { | |
5349 | case DW_FORM_data1: | |
5350 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
5351 | end); | |
5352 | break; | |
5353 | case DW_FORM_data2: | |
5354 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
5355 | end); | |
5356 | break; | |
5357 | case DW_FORM_udata: | |
5358 | tmp = data; | |
5359 | READ_ULEB (file->directory_index, tmp, end); | |
5360 | break; | |
5361 | } | |
5362 | break; | |
5363 | } | |
5364 | data = read_and_display_attr_value (0, form, 0, start, | |
5365 | data, end, 0, 0, | |
5366 | linfo.li_offset_size, | |
5367 | linfo.li_version, | |
5368 | NULL, 1, section, | |
5369 | NULL, '\t', -1); | |
5370 | } | |
5371 | if (data >= end) | |
5372 | { | |
5373 | warn (_("Corrupt file name list\n")); | |
5374 | break; | |
5375 | } | |
5376 | } | |
5377 | } | |
5378 | else | |
5379 | { | |
5380 | if (*data != 0) | |
5381 | { | |
5382 | char *ptr_directory_table = (char *) data; | |
5383 | ||
5384 | while (data < end && *data != 0) | |
5385 | { | |
5386 | data += strnlen ((char *) data, end - data); | |
5387 | if (data < end) | |
5388 | data++; | |
5389 | n_directories++; | |
5390 | } | |
5391 | ||
5392 | /* PR 20440 */ | |
5393 | if (data >= end) | |
5394 | { | |
5395 | warn (_("directory table ends unexpectedly\n")); | |
5396 | n_directories = 0; | |
5397 | break; | |
5398 | } | |
5399 | ||
5400 | /* Go through the directory table again to save the directories. */ | |
5401 | directory_table = (char **) | |
5402 | xmalloc (n_directories * sizeof (unsigned char *)); | |
5403 | ||
5404 | i = 0; | |
5405 | while (*ptr_directory_table != 0) | |
5406 | { | |
5407 | directory_table[i] = ptr_directory_table; | |
5408 | ptr_directory_table += strlen (ptr_directory_table) + 1; | |
5409 | i++; | |
5410 | } | |
5411 | } | |
5412 | /* Skip the NUL at the end of the table. */ | |
5413 | data++; | |
5414 | ||
5415 | /* Traverse the File Name table just to count the entries. */ | |
5416 | if (data < end && *data != 0) | |
5417 | { | |
5418 | unsigned char *ptr_file_name_table = data; | |
5419 | ||
5420 | while (data < end && *data != 0) | |
5421 | { | |
5422 | /* Skip Name, directory index, last modification | |
5423 | time and length of file. */ | |
5424 | data += strnlen ((char *) data, end - data); | |
5425 | if (data < end) | |
5426 | data++; | |
5427 | SKIP_ULEB (data, end); | |
5428 | SKIP_ULEB (data, end); | |
5429 | SKIP_ULEB (data, end); | |
5430 | n_files++; | |
5431 | } | |
5432 | ||
5433 | if (data >= end) | |
5434 | { | |
5435 | warn (_("file table ends unexpectedly\n")); | |
5436 | n_files = 0; | |
5437 | break; | |
5438 | } | |
5439 | ||
5440 | /* Go through the file table again to save the strings. */ | |
5441 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
5442 | ||
5443 | i = 0; | |
5444 | while (*ptr_file_name_table != 0) | |
5445 | { | |
5446 | file_table[i].name = (char *) ptr_file_name_table; | |
5447 | ptr_file_name_table | |
5448 | += strlen ((char *) ptr_file_name_table) + 1; | |
5449 | ||
5450 | /* We are not interested in directory, time or size. */ | |
5451 | READ_ULEB (file_table[i].directory_index, | |
5452 | ptr_file_name_table, end); | |
5453 | READ_ULEB (file_table[i].modification_date, | |
5454 | ptr_file_name_table, end); | |
5455 | READ_ULEB (file_table[i].length, | |
5456 | ptr_file_name_table, end); | |
5457 | i++; | |
5458 | } | |
5459 | i = 0; | |
5460 | } | |
5461 | ||
5462 | /* Skip the NUL at the end of the table. */ | |
5463 | data++; | |
5464 | } | |
5465 | ||
5466 | /* Print the Compilation Unit's name and a header. */ | |
5467 | if (file_table == NULL) | |
5468 | printf (_("CU: No directory table\n")); | |
5469 | else if (directory_table == NULL) | |
5470 | printf (_("CU: %s:\n"), null_name (file_table[0].name)); | |
5471 | else | |
5472 | { | |
5473 | unsigned int ix = file_table[0].directory_index; | |
5474 | const char *directory; | |
5475 | ||
5476 | if (ix == 0 && linfo.li_version < 5) | |
5477 | directory = "."; | |
5478 | /* PR 20439 */ | |
5479 | else if (n_directories == 0) | |
5480 | directory = _("<unknown>"); | |
5481 | else | |
5482 | { | |
5483 | if (linfo.li_version < 5) | |
5484 | --ix; | |
5485 | if (ix >= n_directories) | |
5486 | { | |
5487 | warn (_("directory index %u " | |
5488 | ">= number of directories %u\n"), | |
5489 | ix, n_directories); | |
5490 | directory = _("<corrupt>"); | |
5491 | } | |
5492 | else | |
5493 | directory = directory_table[ix]; | |
5494 | } | |
5495 | if (do_wide) | |
5496 | printf (_("CU: %s/%s:\n"), | |
5497 | null_name (directory), | |
5498 | null_name (file_table[0].name)); | |
5499 | else | |
5500 | printf ("%s:\n", null_name (file_table[0].name)); | |
5501 | } | |
5502 | ||
5503 | if (n_files > 0) | |
5504 | { | |
5505 | if (do_wide) | |
5506 | printf (_("File name Line number Starting address View Stmt\n")); | |
5507 | else | |
5508 | printf (_("File name Line number Starting address View Stmt\n")); | |
5509 | } | |
5510 | else | |
5511 | printf (_("CU: Empty file name table\n")); | |
5512 | saved_linfo = linfo; | |
5513 | } | |
5514 | ||
5515 | /* This loop iterates through the Dwarf Line Number Program. */ | |
5516 | while (data < end_of_sequence) | |
5517 | { | |
5518 | unsigned char op_code; | |
5519 | int xop; | |
5520 | int adv; | |
5521 | unsigned long int uladv; | |
5522 | int is_special_opcode = 0; | |
5523 | ||
5524 | op_code = *data++; | |
5525 | xop = op_code; | |
5526 | ||
5527 | if (op_code >= linfo.li_opcode_base) | |
5528 | { | |
5529 | op_code -= linfo.li_opcode_base; | |
5530 | uladv = (op_code / linfo.li_line_range); | |
5531 | if (linfo.li_max_ops_per_insn == 1) | |
5532 | { | |
5533 | uladv *= linfo.li_min_insn_length; | |
5534 | state_machine_regs.address += uladv; | |
5535 | if (uladv) | |
5536 | state_machine_regs.view = 0; | |
5537 | } | |
5538 | else | |
5539 | { | |
5540 | unsigned addrdelta | |
5541 | = ((state_machine_regs.op_index + uladv) | |
5542 | / linfo.li_max_ops_per_insn) | |
5543 | * linfo.li_min_insn_length; | |
5544 | state_machine_regs.address | |
5545 | += addrdelta; | |
5546 | state_machine_regs.op_index | |
5547 | = (state_machine_regs.op_index + uladv) | |
5548 | % linfo.li_max_ops_per_insn; | |
5549 | if (addrdelta) | |
5550 | state_machine_regs.view = 0; | |
5551 | } | |
5552 | ||
5553 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
5554 | state_machine_regs.line += adv; | |
5555 | is_special_opcode = 1; | |
5556 | /* Increment view after printing this row. */ | |
5557 | } | |
5558 | else | |
5559 | switch (op_code) | |
5560 | { | |
5561 | case DW_LNS_extended_op: | |
5562 | { | |
5563 | unsigned int ext_op_code_len; | |
5564 | unsigned char ext_op_code; | |
5565 | unsigned char *op_code_end; | |
5566 | unsigned char *op_code_data = data; | |
5567 | ||
5568 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
5569 | op_code_end = op_code_data + ext_op_code_len; | |
5570 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
5571 | { | |
5572 | warn (_("Badly formed extended line op encountered!\n")); | |
5573 | break; | |
5574 | } | |
5575 | ext_op_code = *op_code_data++; | |
5576 | xop = ext_op_code; | |
5577 | xop = -xop; | |
5578 | ||
5579 | switch (ext_op_code) | |
5580 | { | |
5581 | case DW_LNE_end_sequence: | |
5582 | /* Reset stuff after printing this row. */ | |
5583 | break; | |
5584 | case DW_LNE_set_address: | |
5585 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
5586 | op_code_data, | |
5587 | op_code_end - op_code_data, | |
5588 | op_code_end); | |
5589 | state_machine_regs.op_index = 0; | |
5590 | state_machine_regs.view = 0; | |
5591 | break; | |
5592 | case DW_LNE_define_file: | |
5593 | file_table = (File_Entry *) xrealloc | |
5594 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
5595 | ||
5596 | ++state_machine_regs.last_file_entry; | |
5597 | /* Source file name. */ | |
5598 | file_table[n_files].name = (char *) op_code_data; | |
5599 | op_code_data += strlen ((char *) op_code_data) + 1; | |
5600 | /* Directory index. */ | |
5601 | READ_ULEB (file_table[n_files].directory_index, | |
5602 | op_code_data, op_code_end); | |
5603 | /* Last modification time. */ | |
5604 | READ_ULEB (file_table[n_files].modification_date, | |
5605 | op_code_data, op_code_end); | |
5606 | /* File length. */ | |
5607 | READ_ULEB (file_table[n_files].length, | |
5608 | op_code_data, op_code_end); | |
5609 | n_files++; | |
5610 | break; | |
5611 | ||
5612 | case DW_LNE_set_discriminator: | |
5613 | case DW_LNE_HP_set_sequence: | |
5614 | /* Simply ignored. */ | |
5615 | break; | |
5616 | ||
5617 | default: | |
5618 | printf (_("UNKNOWN (%u): length %ld\n"), | |
5619 | ext_op_code, (long int) (op_code_data - data)); | |
5620 | break; | |
5621 | } | |
5622 | data = op_code_end; | |
5623 | break; | |
5624 | } | |
5625 | case DW_LNS_copy: | |
5626 | /* Increment view after printing this row. */ | |
5627 | break; | |
5628 | ||
5629 | case DW_LNS_advance_pc: | |
5630 | READ_ULEB (uladv, data, end); | |
5631 | if (linfo.li_max_ops_per_insn == 1) | |
5632 | { | |
5633 | uladv *= linfo.li_min_insn_length; | |
5634 | state_machine_regs.address += uladv; | |
5635 | if (uladv) | |
5636 | state_machine_regs.view = 0; | |
5637 | } | |
5638 | else | |
5639 | { | |
5640 | unsigned addrdelta | |
5641 | = ((state_machine_regs.op_index + uladv) | |
5642 | / linfo.li_max_ops_per_insn) | |
5643 | * linfo.li_min_insn_length; | |
5644 | state_machine_regs.address | |
5645 | += addrdelta; | |
5646 | state_machine_regs.op_index | |
5647 | = (state_machine_regs.op_index + uladv) | |
5648 | % linfo.li_max_ops_per_insn; | |
5649 | if (addrdelta) | |
5650 | state_machine_regs.view = 0; | |
5651 | } | |
5652 | break; | |
5653 | ||
5654 | case DW_LNS_advance_line: | |
5655 | READ_SLEB (adv, data, end); | |
5656 | state_machine_regs.line += adv; | |
5657 | break; | |
5658 | ||
5659 | case DW_LNS_set_file: | |
5660 | READ_ULEB (uladv, data, end); | |
5661 | state_machine_regs.file = uladv; | |
5662 | ||
5663 | unsigned file = state_machine_regs.file; | |
5664 | if (linfo.li_version < 5) | |
5665 | --file; | |
5666 | ||
5667 | if (file_table == NULL || n_files == 0) | |
5668 | printf (_("\n [Use file table entry %d]\n"), file); | |
5669 | /* PR 20439 */ | |
5670 | else if (file >= n_files) | |
5671 | { | |
5672 | warn (_("file index %u >= number of files %u\n"), | |
5673 | file, n_files); | |
5674 | printf (_("\n <over large file table index %u>"), file); | |
5675 | } | |
5676 | else | |
5677 | { | |
5678 | unsigned dir = file_table[file].directory_index; | |
5679 | if (dir == 0 && linfo.li_version < 5) | |
5680 | /* If directory index is 0, that means compilation | |
5681 | current directory. bfd/dwarf2.c shows | |
5682 | DW_AT_comp_dir here but in keeping with the | |
5683 | readelf practice of minimal interpretation of | |
5684 | file data, we show "./". */ | |
5685 | printf ("\n./%s:[++]\n", | |
5686 | null_name (file_table[file].name)); | |
5687 | else if (directory_table == NULL || n_directories == 0) | |
5688 | printf (_("\n [Use file %s " | |
5689 | "in directory table entry %d]\n"), | |
5690 | null_name (file_table[file].name), dir); | |
5691 | else | |
5692 | { | |
5693 | if (linfo.li_version < 5) | |
5694 | --dir; | |
5695 | /* PR 20439 */ | |
5696 | if (dir >= n_directories) | |
5697 | { | |
5698 | warn (_("directory index %u " | |
5699 | ">= number of directories %u\n"), | |
5700 | dir, n_directories); | |
5701 | printf (_("\n <over large directory table entry " | |
5702 | "%u>\n"), dir); | |
5703 | } | |
5704 | else | |
5705 | printf ("\n%s/%s:\n", | |
5706 | null_name (directory_table[dir]), | |
5707 | null_name (file_table[file].name)); | |
5708 | } | |
5709 | } | |
5710 | break; | |
5711 | ||
5712 | case DW_LNS_set_column: | |
5713 | READ_ULEB (uladv, data, end); | |
5714 | state_machine_regs.column = uladv; | |
5715 | break; | |
5716 | ||
5717 | case DW_LNS_negate_stmt: | |
5718 | adv = state_machine_regs.is_stmt; | |
5719 | adv = ! adv; | |
5720 | state_machine_regs.is_stmt = adv; | |
5721 | break; | |
5722 | ||
5723 | case DW_LNS_set_basic_block: | |
5724 | state_machine_regs.basic_block = 1; | |
5725 | break; | |
5726 | ||
5727 | case DW_LNS_const_add_pc: | |
5728 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
5729 | if (linfo.li_max_ops_per_insn == 1) | |
5730 | { | |
5731 | uladv *= linfo.li_min_insn_length; | |
5732 | state_machine_regs.address += uladv; | |
5733 | if (uladv) | |
5734 | state_machine_regs.view = 0; | |
5735 | } | |
5736 | else | |
5737 | { | |
5738 | unsigned addrdelta | |
5739 | = ((state_machine_regs.op_index + uladv) | |
5740 | / linfo.li_max_ops_per_insn) | |
5741 | * linfo.li_min_insn_length; | |
5742 | state_machine_regs.address | |
5743 | += addrdelta; | |
5744 | state_machine_regs.op_index | |
5745 | = (state_machine_regs.op_index + uladv) | |
5746 | % linfo.li_max_ops_per_insn; | |
5747 | if (addrdelta) | |
5748 | state_machine_regs.view = 0; | |
5749 | } | |
5750 | break; | |
5751 | ||
5752 | case DW_LNS_fixed_advance_pc: | |
5753 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5754 | state_machine_regs.address += uladv; | |
5755 | state_machine_regs.op_index = 0; | |
5756 | /* Do NOT reset view. */ | |
5757 | break; | |
5758 | ||
5759 | case DW_LNS_set_prologue_end: | |
5760 | break; | |
5761 | ||
5762 | case DW_LNS_set_epilogue_begin: | |
5763 | break; | |
5764 | ||
5765 | case DW_LNS_set_isa: | |
5766 | READ_ULEB (uladv, data, end); | |
5767 | printf (_(" Set ISA to %lu\n"), uladv); | |
5768 | break; | |
5769 | ||
5770 | default: | |
5771 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5772 | ||
5773 | if (standard_opcodes != NULL) | |
5774 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5775 | { | |
5776 | uint64_t val; | |
5777 | ||
5778 | READ_ULEB (val, data, end); | |
5779 | printf ("%#" PRIx64 "%s", val, i == 1 ? "" : ", "); | |
5780 | } | |
5781 | putchar ('\n'); | |
5782 | break; | |
5783 | } | |
5784 | ||
5785 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row | |
5786 | to the DWARF address/line matrix. */ | |
5787 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) | |
5788 | || (xop == DW_LNS_copy)) | |
5789 | { | |
5790 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
5791 | char *fileName = NULL; | |
5792 | char *newFileName = NULL; | |
5793 | size_t fileNameLength; | |
5794 | ||
5795 | if (file_table) | |
5796 | { | |
5797 | unsigned indx = state_machine_regs.file; | |
5798 | ||
5799 | if (linfo.li_version < 5) | |
5800 | --indx; | |
5801 | /* PR 20439 */ | |
5802 | if (indx >= n_files) | |
5803 | { | |
5804 | warn (_("file index %u >= number of files %u\n"), | |
5805 | indx, n_files); | |
5806 | fileName = _("<corrupt>"); | |
5807 | } | |
5808 | else | |
5809 | fileName = (char *) file_table[indx].name; | |
5810 | } | |
5811 | if (!fileName) | |
5812 | fileName = _("<unknown>"); | |
5813 | ||
5814 | fileNameLength = strlen (fileName); | |
5815 | newFileName = fileName; | |
5816 | if (fileNameLength > MAX_FILENAME_LENGTH && !do_wide) | |
5817 | { | |
5818 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5819 | /* Truncate file name */ | |
5820 | memcpy (newFileName, | |
5821 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5822 | MAX_FILENAME_LENGTH); | |
5823 | newFileName[MAX_FILENAME_LENGTH] = 0; | |
5824 | } | |
5825 | ||
5826 | /* A row with end_seq set to true has a meaningful address, but | |
5827 | the other information in the same row is not significant. | |
5828 | In such a row, print line as "-", and don't print | |
5829 | view/is_stmt. */ | |
5830 | if (!do_wide || fileNameLength <= MAX_FILENAME_LENGTH) | |
5831 | { | |
5832 | if (linfo.li_max_ops_per_insn == 1) | |
5833 | { | |
5834 | if (xop == -DW_LNE_end_sequence) | |
5835 | printf ("%-31s %11s %#18" PRIx64, | |
5836 | newFileName, "-", | |
5837 | state_machine_regs.address); | |
5838 | else | |
5839 | printf ("%-31s %11d %#18" PRIx64, | |
5840 | newFileName, state_machine_regs.line, | |
5841 | state_machine_regs.address); | |
5842 | } | |
5843 | else | |
5844 | { | |
5845 | if (xop == -DW_LNE_end_sequence) | |
5846 | printf ("%-31s %11s %#18" PRIx64 "[%d]", | |
5847 | newFileName, "-", | |
5848 | state_machine_regs.address, | |
5849 | state_machine_regs.op_index); | |
5850 | else | |
5851 | printf ("%-31s %11d %#18" PRIx64 "[%d]", | |
5852 | newFileName, state_machine_regs.line, | |
5853 | state_machine_regs.address, | |
5854 | state_machine_regs.op_index); | |
5855 | } | |
5856 | } | |
5857 | else | |
5858 | { | |
5859 | if (linfo.li_max_ops_per_insn == 1) | |
5860 | { | |
5861 | if (xop == -DW_LNE_end_sequence) | |
5862 | printf ("%s %11s %#18" PRIx64, | |
5863 | newFileName, "-", | |
5864 | state_machine_regs.address); | |
5865 | else | |
5866 | printf ("%s %11d %#18" PRIx64, | |
5867 | newFileName, state_machine_regs.line, | |
5868 | state_machine_regs.address); | |
5869 | } | |
5870 | else | |
5871 | { | |
5872 | if (xop == -DW_LNE_end_sequence) | |
5873 | printf ("%s %11s %#18" PRIx64 "[%d]", | |
5874 | newFileName, "-", | |
5875 | state_machine_regs.address, | |
5876 | state_machine_regs.op_index); | |
5877 | else | |
5878 | printf ("%s %11d %#18" PRIx64 "[%d]", | |
5879 | newFileName, state_machine_regs.line, | |
5880 | state_machine_regs.address, | |
5881 | state_machine_regs.op_index); | |
5882 | } | |
5883 | } | |
5884 | ||
5885 | if (xop != -DW_LNE_end_sequence) | |
5886 | { | |
5887 | if (state_machine_regs.view) | |
5888 | printf (" %6u", state_machine_regs.view); | |
5889 | else | |
5890 | printf (" "); | |
5891 | ||
5892 | if (state_machine_regs.is_stmt) | |
5893 | printf (" x"); | |
5894 | } | |
5895 | ||
5896 | putchar ('\n'); | |
5897 | state_machine_regs.view++; | |
5898 | ||
5899 | if (xop == -DW_LNE_end_sequence) | |
5900 | { | |
5901 | reset_state_machine (linfo.li_default_is_stmt); | |
5902 | putchar ('\n'); | |
5903 | } | |
5904 | ||
5905 | if (newFileName != fileName) | |
5906 | free (newFileName); | |
5907 | } | |
5908 | } | |
5909 | ||
5910 | if (file_table) | |
5911 | { | |
5912 | free (file_table); | |
5913 | file_table = NULL; | |
5914 | n_files = 0; | |
5915 | } | |
5916 | ||
5917 | if (directory_table) | |
5918 | { | |
5919 | free (directory_table); | |
5920 | directory_table = NULL; | |
5921 | n_directories = 0; | |
5922 | } | |
5923 | ||
5924 | putchar ('\n'); | |
5925 | } | |
5926 | ||
5927 | return 1; | |
5928 | } | |
5929 | ||
5930 | static int | |
5931 | display_debug_lines (struct dwarf_section *section, void *file) | |
5932 | { | |
5933 | unsigned char *data = section->start; | |
5934 | unsigned char *end = data + section->size; | |
5935 | int retValRaw = 1; | |
5936 | int retValDecoded = 1; | |
5937 | ||
5938 | if (do_debug_lines == 0) | |
5939 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5940 | ||
5941 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) | |
5942 | retValRaw = display_debug_lines_raw (section, data, end, file); | |
5943 | ||
5944 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) | |
5945 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); | |
5946 | ||
5947 | if (!retValRaw || !retValDecoded) | |
5948 | return 0; | |
5949 | ||
5950 | return 1; | |
5951 | } | |
5952 | ||
5953 | static debug_info * | |
5954 | find_debug_info_for_offset (uint64_t offset) | |
5955 | { | |
5956 | unsigned int i; | |
5957 | ||
5958 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5959 | return NULL; | |
5960 | ||
5961 | for (i = 0; i < num_debug_info_entries; i++) | |
5962 | if (debug_information[i].cu_offset == offset) | |
5963 | return debug_information + i; | |
5964 | ||
5965 | return NULL; | |
5966 | } | |
5967 | ||
5968 | static const char * | |
5969 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5970 | { | |
5971 | /* See gdb/gdb-index.h. */ | |
5972 | static const char * const kinds[] = | |
5973 | { | |
5974 | N_ ("no info"), | |
5975 | N_ ("type"), | |
5976 | N_ ("variable"), | |
5977 | N_ ("function"), | |
5978 | N_ ("other"), | |
5979 | N_ ("unused5"), | |
5980 | N_ ("unused6"), | |
5981 | N_ ("unused7") | |
5982 | }; | |
5983 | ||
5984 | return _ (kinds[kind]); | |
5985 | } | |
5986 | ||
5987 | static int | |
5988 | display_debug_pubnames_worker (struct dwarf_section *section, | |
5989 | void *file ATTRIBUTE_UNUSED, | |
5990 | int is_gnu) | |
5991 | { | |
5992 | DWARF2_Internal_PubNames names; | |
5993 | unsigned char *start = section->start; | |
5994 | unsigned char *end = start + section->size; | |
5995 | ||
5996 | /* It does not matter if this load fails, | |
5997 | we test for that later on. */ | |
5998 | load_debug_info (file); | |
5999 | ||
6000 | introduce (section, false); | |
6001 | ||
6002 | while (start < end) | |
6003 | { | |
6004 | unsigned char *data; | |
6005 | unsigned long sec_off = start - section->start; | |
6006 | unsigned int offset_size; | |
6007 | ||
6008 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); | |
6009 | if (names.pn_length == 0xffffffff) | |
6010 | { | |
6011 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); | |
6012 | offset_size = 8; | |
6013 | } | |
6014 | else | |
6015 | offset_size = 4; | |
6016 | ||
6017 | if (names.pn_length > (size_t) (end - start)) | |
6018 | { | |
6019 | warn (_("Debug info is corrupted, " | |
6020 | "%s header at %#lx has length %#" PRIx64 "\n"), | |
6021 | section->name, sec_off, names.pn_length); | |
6022 | break; | |
6023 | } | |
6024 | ||
6025 | data = start; | |
6026 | start += names.pn_length; | |
6027 | ||
6028 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, start); | |
6029 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, start); | |
6030 | ||
6031 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
6032 | && num_debug_info_entries > 0 | |
6033 | && find_debug_info_for_offset (names.pn_offset) == NULL) | |
6034 | warn (_(".debug_info offset of %#" PRIx64 | |
6035 | " in %s section does not point to a CU header.\n"), | |
6036 | names.pn_offset, section->name); | |
6037 | ||
6038 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, start); | |
6039 | ||
6040 | printf (_(" Length: %" PRId64 "\n"), | |
6041 | names.pn_length); | |
6042 | printf (_(" Version: %d\n"), | |
6043 | names.pn_version); | |
6044 | printf (_(" Offset into .debug_info section: %#" PRIx64 "\n"), | |
6045 | names.pn_offset); | |
6046 | printf (_(" Size of area in .debug_info section: %" PRId64 "\n"), | |
6047 | names.pn_size); | |
6048 | ||
6049 | if (names.pn_version != 2 && names.pn_version != 3) | |
6050 | { | |
6051 | static int warned = 0; | |
6052 | ||
6053 | if (! warned) | |
6054 | { | |
6055 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
6056 | warned = 1; | |
6057 | } | |
6058 | ||
6059 | continue; | |
6060 | } | |
6061 | ||
6062 | if (is_gnu) | |
6063 | printf (_("\n Offset Kind Name\n")); | |
6064 | else | |
6065 | printf (_("\n Offset\tName\n")); | |
6066 | ||
6067 | while (1) | |
6068 | { | |
6069 | size_t maxprint; | |
6070 | uint64_t offset; | |
6071 | ||
6072 | SAFE_BYTE_GET_AND_INC (offset, data, offset_size, start); | |
6073 | ||
6074 | if (offset == 0) | |
6075 | break; | |
6076 | ||
6077 | if (data >= start) | |
6078 | break; | |
6079 | maxprint = (start - data) - 1; | |
6080 | ||
6081 | if (is_gnu) | |
6082 | { | |
6083 | unsigned int kind_data; | |
6084 | gdb_index_symbol_kind kind; | |
6085 | const char *kind_name; | |
6086 | int is_static; | |
6087 | ||
6088 | SAFE_BYTE_GET_AND_INC (kind_data, data, 1, start); | |
6089 | maxprint --; | |
6090 | /* GCC computes the kind as the upper byte in the CU index | |
6091 | word, and then right shifts it by the CU index size. | |
6092 | Left shift KIND to where the gdb-index.h accessor macros | |
6093 | can use it. */ | |
6094 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
6095 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
6096 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
6097 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
6098 | printf (" %-6" PRIx64 " %s,%-10s %.*s\n", | |
6099 | offset, is_static ? _("s") : _("g"), | |
6100 | kind_name, (int) maxprint, data); | |
6101 | } | |
6102 | else | |
6103 | printf (" %-6" PRIx64 "\t%.*s\n", | |
6104 | offset, (int) maxprint, data); | |
6105 | ||
6106 | data += strnlen ((char *) data, maxprint); | |
6107 | if (data < start) | |
6108 | data++; | |
6109 | if (data >= start) | |
6110 | break; | |
6111 | } | |
6112 | } | |
6113 | ||
6114 | printf ("\n"); | |
6115 | return 1; | |
6116 | } | |
6117 | ||
6118 | static int | |
6119 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
6120 | { | |
6121 | return display_debug_pubnames_worker (section, file, 0); | |
6122 | } | |
6123 | ||
6124 | static int | |
6125 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
6126 | { | |
6127 | return display_debug_pubnames_worker (section, file, 1); | |
6128 | } | |
6129 | ||
6130 | static int | |
6131 | display_debug_macinfo (struct dwarf_section *section, | |
6132 | void *file ATTRIBUTE_UNUSED) | |
6133 | { | |
6134 | unsigned char *start = section->start; | |
6135 | unsigned char *end = start + section->size; | |
6136 | unsigned char *curr = start; | |
6137 | enum dwarf_macinfo_record_type op; | |
6138 | ||
6139 | introduce (section, false); | |
6140 | ||
6141 | while (curr < end) | |
6142 | { | |
6143 | unsigned int lineno; | |
6144 | const unsigned char *string; | |
6145 | ||
6146 | op = (enum dwarf_macinfo_record_type) *curr; | |
6147 | curr++; | |
6148 | ||
6149 | switch (op) | |
6150 | { | |
6151 | case DW_MACINFO_start_file: | |
6152 | { | |
6153 | unsigned int filenum; | |
6154 | ||
6155 | READ_ULEB (lineno, curr, end); | |
6156 | READ_ULEB (filenum, curr, end); | |
6157 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
6158 | lineno, filenum); | |
6159 | } | |
6160 | break; | |
6161 | ||
6162 | case DW_MACINFO_end_file: | |
6163 | printf (_(" DW_MACINFO_end_file\n")); | |
6164 | break; | |
6165 | ||
6166 | case DW_MACINFO_define: | |
6167 | READ_ULEB (lineno, curr, end); | |
6168 | string = curr; | |
6169 | curr += strnlen ((char *) string, end - string); | |
6170 | printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"), | |
6171 | lineno, (int) (curr - string), string); | |
6172 | if (curr < end) | |
6173 | curr++; | |
6174 | break; | |
6175 | ||
6176 | case DW_MACINFO_undef: | |
6177 | READ_ULEB (lineno, curr, end); | |
6178 | string = curr; | |
6179 | curr += strnlen ((char *) string, end - string); | |
6180 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"), | |
6181 | lineno, (int) (curr - string), string); | |
6182 | if (curr < end) | |
6183 | curr++; | |
6184 | break; | |
6185 | ||
6186 | case DW_MACINFO_vendor_ext: | |
6187 | { | |
6188 | unsigned int constant; | |
6189 | ||
6190 | READ_ULEB (constant, curr, end); | |
6191 | string = curr; | |
6192 | curr += strnlen ((char *) string, end - string); | |
6193 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"), | |
6194 | constant, (int) (curr - string), string); | |
6195 | if (curr < end) | |
6196 | curr++; | |
6197 | } | |
6198 | break; | |
6199 | } | |
6200 | } | |
6201 | ||
6202 | return 1; | |
6203 | } | |
6204 | ||
6205 | /* Given LINE_OFFSET into the .debug_line section, attempt to return | |
6206 | filename and dirname corresponding to file name table entry with index | |
6207 | FILEIDX. Return NULL on failure. */ | |
6208 | ||
6209 | static unsigned char * | |
6210 | get_line_filename_and_dirname (uint64_t line_offset, | |
6211 | uint64_t fileidx, | |
6212 | unsigned char **dir_name) | |
6213 | { | |
6214 | struct dwarf_section *section = &debug_displays [line].section; | |
6215 | unsigned char *hdrptr, *dirtable, *file_name; | |
6216 | unsigned int offset_size; | |
6217 | unsigned int version, opcode_base; | |
6218 | uint64_t length, diridx; | |
6219 | const unsigned char * end; | |
6220 | ||
6221 | *dir_name = NULL; | |
6222 | if (section->start == NULL | |
6223 | || line_offset >= section->size | |
6224 | || fileidx == 0) | |
6225 | return NULL; | |
6226 | ||
6227 | hdrptr = section->start + line_offset; | |
6228 | end = section->start + section->size; | |
6229 | ||
6230 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
6231 | if (length == 0xffffffff) | |
6232 | { | |
6233 | /* This section is 64-bit DWARF 3. */ | |
6234 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); | |
6235 | offset_size = 8; | |
6236 | } | |
6237 | else | |
6238 | offset_size = 4; | |
6239 | ||
6240 | if (length > (size_t) (end - hdrptr) | |
6241 | || length < 2 + offset_size + 1 + 3 + 1) | |
6242 | return NULL; | |
6243 | end = hdrptr + length; | |
6244 | ||
6245 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
6246 | if (version != 2 && version != 3 && version != 4) | |
6247 | return NULL; | |
6248 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
6249 | if (version >= 4) | |
6250 | hdrptr++; /* Skip max_ops_per_insn. */ | |
6251 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
6252 | ||
6253 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
6254 | if (opcode_base == 0 | |
6255 | || opcode_base - 1 >= (size_t) (end - hdrptr)) | |
6256 | return NULL; | |
6257 | ||
6258 | hdrptr += opcode_base - 1; | |
6259 | ||
6260 | dirtable = hdrptr; | |
6261 | /* Skip over dirname table. */ | |
6262 | while (*hdrptr != '\0') | |
6263 | { | |
6264 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); | |
6265 | if (hdrptr < end) | |
6266 | hdrptr++; | |
6267 | if (hdrptr >= end) | |
6268 | return NULL; | |
6269 | } | |
6270 | hdrptr++; /* Skip the NUL at the end of the table. */ | |
6271 | ||
6272 | /* Now skip over preceding filename table entries. */ | |
6273 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) | |
6274 | { | |
6275 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); | |
6276 | if (hdrptr < end) | |
6277 | hdrptr++; | |
6278 | SKIP_ULEB (hdrptr, end); | |
6279 | SKIP_ULEB (hdrptr, end); | |
6280 | SKIP_ULEB (hdrptr, end); | |
6281 | } | |
6282 | if (hdrptr >= end || *hdrptr == '\0') | |
6283 | return NULL; | |
6284 | ||
6285 | file_name = hdrptr; | |
6286 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); | |
6287 | if (hdrptr < end) | |
6288 | hdrptr++; | |
6289 | if (hdrptr >= end) | |
6290 | return NULL; | |
6291 | READ_ULEB (diridx, hdrptr, end); | |
6292 | if (diridx == 0) | |
6293 | return file_name; | |
6294 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) | |
6295 | { | |
6296 | dirtable += strnlen ((char *) dirtable, end - dirtable); | |
6297 | if (dirtable < end) | |
6298 | dirtable++; | |
6299 | } | |
6300 | if (dirtable >= end || *dirtable == '\0') | |
6301 | return NULL; | |
6302 | *dir_name = dirtable; | |
6303 | return file_name; | |
6304 | } | |
6305 | ||
6306 | static int | |
6307 | display_debug_macro (struct dwarf_section *section, | |
6308 | void *file) | |
6309 | { | |
6310 | unsigned char *start = section->start; | |
6311 | unsigned char *end = start + section->size; | |
6312 | unsigned char *curr = start; | |
6313 | unsigned char *extended_op_buf[256]; | |
6314 | bool is_dwo = false; | |
6315 | const char *suffix = strrchr (section->name, '.'); | |
6316 | ||
6317 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
6318 | is_dwo = true; | |
6319 | ||
6320 | if (is_dwo) | |
6321 | { | |
6322 | load_debug_section_with_follow (str_dwo, file); | |
6323 | load_debug_section_with_follow (str_index_dwo, file); | |
6324 | } | |
6325 | else | |
6326 | { | |
6327 | load_debug_section_with_follow (str, file); | |
6328 | load_debug_section_with_follow (str_index, file); | |
6329 | } | |
6330 | load_debug_section_with_follow (line, file); | |
6331 | ||
6332 | introduce (section, false); | |
6333 | ||
6334 | while (curr < end) | |
6335 | { | |
6336 | unsigned int lineno, version, flags; | |
6337 | unsigned int offset_size; | |
6338 | const unsigned char *string; | |
6339 | uint64_t line_offset = 0, sec_offset = curr - start, offset; | |
6340 | unsigned char **extended_ops = NULL; | |
6341 | ||
6342 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); | |
6343 | if (version != 4 && version != 5) | |
6344 | { | |
6345 | error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"), | |
6346 | section->name, version); | |
6347 | return 0; | |
6348 | } | |
6349 | ||
6350 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); | |
6351 | offset_size = (flags & 1) ? 8 : 4; | |
6352 | printf (_(" Offset: %#" PRIx64 "\n"), sec_offset); | |
6353 | printf (_(" Version: %d\n"), version); | |
6354 | printf (_(" Offset size: %d\n"), offset_size); | |
6355 | if (flags & 2) | |
6356 | { | |
6357 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); | |
6358 | printf (_(" Offset into .debug_line: %#" PRIx64 "\n"), | |
6359 | line_offset); | |
6360 | } | |
6361 | if (flags & 4) | |
6362 | { | |
6363 | unsigned int i, count, op; | |
6364 | uint64_t nargs, n; | |
6365 | ||
6366 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
6367 | ||
6368 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); | |
6369 | extended_ops = extended_op_buf; | |
6370 | if (count) | |
6371 | { | |
6372 | printf (_(" Extension opcode arguments:\n")); | |
6373 | for (i = 0; i < count; i++) | |
6374 | { | |
6375 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); | |
6376 | extended_ops[op] = curr; | |
6377 | READ_ULEB (nargs, curr, end); | |
6378 | if (nargs == 0) | |
6379 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); | |
6380 | else | |
6381 | { | |
6382 | printf (_(" DW_MACRO_%02x arguments: "), op); | |
6383 | for (n = 0; n < nargs; n++) | |
6384 | { | |
6385 | unsigned int form; | |
6386 | ||
6387 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
6388 | printf ("%s%s", get_FORM_name (form), | |
6389 | n == nargs - 1 ? "\n" : ", "); | |
6390 | switch (form) | |
6391 | { | |
6392 | case DW_FORM_data1: | |
6393 | case DW_FORM_data2: | |
6394 | case DW_FORM_data4: | |
6395 | case DW_FORM_data8: | |
6396 | case DW_FORM_sdata: | |
6397 | case DW_FORM_udata: | |
6398 | case DW_FORM_block: | |
6399 | case DW_FORM_block1: | |
6400 | case DW_FORM_block2: | |
6401 | case DW_FORM_block4: | |
6402 | case DW_FORM_flag: | |
6403 | case DW_FORM_string: | |
6404 | case DW_FORM_strp: | |
6405 | case DW_FORM_sec_offset: | |
6406 | break; | |
6407 | default: | |
6408 | error (_("Invalid extension opcode form %s\n"), | |
6409 | get_FORM_name (form)); | |
6410 | return 0; | |
6411 | } | |
6412 | } | |
6413 | } | |
6414 | } | |
6415 | } | |
6416 | } | |
6417 | printf ("\n"); | |
6418 | ||
6419 | while (1) | |
6420 | { | |
6421 | unsigned int op; | |
6422 | ||
6423 | if (curr >= end) | |
6424 | { | |
6425 | error (_(".debug_macro section not zero terminated\n")); | |
6426 | return 0; | |
6427 | } | |
6428 | ||
6429 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); | |
6430 | if (op == 0) | |
6431 | break; | |
6432 | ||
6433 | switch (op) | |
6434 | { | |
6435 | case DW_MACRO_define: | |
6436 | READ_ULEB (lineno, curr, end); | |
6437 | string = curr; | |
6438 | curr += strnlen ((char *) string, end - string); | |
6439 | printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"), | |
6440 | lineno, (int) (curr - string), string); | |
6441 | if (curr < end) | |
6442 | curr++; | |
6443 | break; | |
6444 | ||
6445 | case DW_MACRO_undef: | |
6446 | READ_ULEB (lineno, curr, end); | |
6447 | string = curr; | |
6448 | curr += strnlen ((char *) string, end - string); | |
6449 | printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"), | |
6450 | lineno, (int) (curr - string), string); | |
6451 | if (curr < end) | |
6452 | curr++; | |
6453 | break; | |
6454 | ||
6455 | case DW_MACRO_start_file: | |
6456 | { | |
6457 | unsigned int filenum; | |
6458 | unsigned char *file_name = NULL, *dir_name = NULL; | |
6459 | ||
6460 | READ_ULEB (lineno, curr, end); | |
6461 | READ_ULEB (filenum, curr, end); | |
6462 | ||
6463 | if ((flags & 2) == 0) | |
6464 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); | |
6465 | else | |
6466 | file_name | |
6467 | = get_line_filename_and_dirname (line_offset, filenum, | |
6468 | &dir_name); | |
6469 | if (file_name == NULL) | |
6470 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), | |
6471 | lineno, filenum); | |
6472 | else | |
6473 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), | |
6474 | lineno, filenum, | |
6475 | dir_name != NULL ? (const char *) dir_name : "", | |
6476 | dir_name != NULL ? "/" : "", file_name); | |
6477 | } | |
6478 | break; | |
6479 | ||
6480 | case DW_MACRO_end_file: | |
6481 | printf (_(" DW_MACRO_end_file\n")); | |
6482 | break; | |
6483 | ||
6484 | case DW_MACRO_define_strp: | |
6485 | READ_ULEB (lineno, curr, end); | |
6486 | if (version == 4 && is_dwo) | |
6487 | READ_ULEB (offset, curr, end); | |
6488 | else | |
6489 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
6490 | string = fetch_indirect_string (offset); | |
6491 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), | |
6492 | lineno, string); | |
6493 | break; | |
6494 | ||
6495 | case DW_MACRO_undef_strp: | |
6496 | READ_ULEB (lineno, curr, end); | |
6497 | if (version == 4 && is_dwo) | |
6498 | READ_ULEB (offset, curr, end); | |
6499 | else | |
6500 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
6501 | string = fetch_indirect_string (offset); | |
6502 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), | |
6503 | lineno, string); | |
6504 | break; | |
6505 | ||
6506 | case DW_MACRO_import: | |
6507 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
6508 | printf (_(" DW_MACRO_import - offset : %#" PRIx64 "\n"), | |
6509 | offset); | |
6510 | break; | |
6511 | ||
6512 | case DW_MACRO_define_sup: | |
6513 | READ_ULEB (lineno, curr, end); | |
6514 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
6515 | printf (_(" DW_MACRO_define_sup - lineno : %d" | |
6516 | " macro offset : %#" PRIx64 "\n"), | |
6517 | lineno, offset); | |
6518 | break; | |
6519 | ||
6520 | case DW_MACRO_undef_sup: | |
6521 | READ_ULEB (lineno, curr, end); | |
6522 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
6523 | printf (_(" DW_MACRO_undef_sup - lineno : %d" | |
6524 | " macro offset : %#" PRIx64 "\n"), | |
6525 | lineno, offset); | |
6526 | break; | |
6527 | ||
6528 | case DW_MACRO_import_sup: | |
6529 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
6530 | printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64 "\n"), | |
6531 | offset); | |
6532 | break; | |
6533 | ||
6534 | case DW_MACRO_define_strx: | |
6535 | case DW_MACRO_undef_strx: | |
6536 | READ_ULEB (lineno, curr, end); | |
6537 | READ_ULEB (offset, curr, end); | |
6538 | string = (const unsigned char *) | |
6539 | fetch_indexed_string (offset, NULL, offset_size, is_dwo, 0); | |
6540 | if (op == DW_MACRO_define_strx) | |
6541 | printf (" DW_MACRO_define_strx "); | |
6542 | else | |
6543 | printf (" DW_MACRO_undef_strx "); | |
6544 | if (do_wide) | |
6545 | printf (_("(with offset %#" PRIx64 ") "), offset); | |
6546 | printf (_("lineno : %d macro : %s\n"), | |
6547 | lineno, string); | |
6548 | break; | |
6549 | ||
6550 | default: | |
6551 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) | |
6552 | { | |
6553 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); | |
6554 | break; | |
6555 | } | |
6556 | ||
6557 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
6558 | { | |
6559 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
6560 | return 0; | |
6561 | } | |
6562 | else | |
6563 | { | |
6564 | /* Skip over unhandled opcodes. */ | |
6565 | uint64_t nargs, n; | |
6566 | unsigned char *desc = extended_ops[op]; | |
6567 | READ_ULEB (nargs, desc, end); | |
6568 | if (nargs == 0) | |
6569 | { | |
6570 | printf (_(" DW_MACRO_%02x\n"), op); | |
6571 | break; | |
6572 | } | |
6573 | printf (_(" DW_MACRO_%02x -"), op); | |
6574 | for (n = 0; n < nargs; n++) | |
6575 | { | |
6576 | int val; | |
6577 | ||
6578 | /* DW_FORM_implicit_const is not expected here. */ | |
6579 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); | |
6580 | curr | |
6581 | = read_and_display_attr_value (0, val, 0, | |
6582 | start, curr, end, 0, 0, | |
6583 | offset_size, version, | |
6584 | NULL, 0, section, | |
6585 | NULL, ' ', -1); | |
6586 | if (n != nargs - 1) | |
6587 | printf (","); | |
6588 | } | |
6589 | printf ("\n"); | |
6590 | } | |
6591 | break; | |
6592 | } | |
6593 | } | |
6594 | ||
6595 | printf ("\n"); | |
6596 | } | |
6597 | ||
6598 | return 1; | |
6599 | } | |
6600 | ||
6601 | static int | |
6602 | display_debug_abbrev (struct dwarf_section *section, | |
6603 | void *file ATTRIBUTE_UNUSED) | |
6604 | { | |
6605 | abbrev_entry *entry; | |
6606 | unsigned char *start = section->start; | |
6607 | ||
6608 | introduce (section, false); | |
6609 | ||
6610 | do | |
6611 | { | |
6612 | uint64_t offset = start - section->start; | |
6613 | abbrev_list *list = find_and_process_abbrev_set (section, 0, | |
6614 | section->size, offset, | |
6615 | NULL); | |
6616 | if (list == NULL) | |
6617 | break; | |
6618 | ||
6619 | if (list->first_abbrev) | |
6620 | printf (_(" Number TAG (%#" PRIx64 ")\n"), offset); | |
6621 | ||
6622 | for (entry = list->first_abbrev; entry; entry = entry->next) | |
6623 | { | |
6624 | abbrev_attr *attr; | |
6625 | ||
6626 | printf (" %ld %s [%s]\n", | |
6627 | entry->number, | |
6628 | get_TAG_name (entry->tag), | |
6629 | entry->children ? _("has children") : _("no children")); | |
6630 | ||
6631 | for (attr = entry->first_attr; attr; attr = attr->next) | |
6632 | { | |
6633 | printf (" %-18s %s", | |
6634 | get_AT_name (attr->attribute), | |
6635 | get_FORM_name (attr->form)); | |
6636 | if (attr->form == DW_FORM_implicit_const) | |
6637 | printf (": %" PRId64, attr->implicit_const); | |
6638 | putchar ('\n'); | |
6639 | } | |
6640 | } | |
6641 | start = list->start_of_next_abbrevs; | |
6642 | free_abbrev_list (list); | |
6643 | } | |
6644 | while (start); | |
6645 | ||
6646 | printf ("\n"); | |
6647 | ||
6648 | return 1; | |
6649 | } | |
6650 | ||
6651 | /* Return true when ADDR is the maximum address, when addresses are | |
6652 | POINTER_SIZE bytes long. */ | |
6653 | ||
6654 | static bool | |
6655 | is_max_address (uint64_t addr, unsigned int pointer_size) | |
6656 | { | |
6657 | uint64_t mask = ~(~(uint64_t) 0 << 1 << (pointer_size * 8 - 1)); | |
6658 | return ((addr & mask) == mask); | |
6659 | } | |
6660 | ||
6661 | /* Display a view pair list starting at *VSTART_PTR and ending at | |
6662 | VLISTEND within SECTION. */ | |
6663 | ||
6664 | static void | |
6665 | display_view_pair_list (struct dwarf_section *section, | |
6666 | unsigned char **vstart_ptr, | |
6667 | unsigned int debug_info_entry, | |
6668 | unsigned char *vlistend) | |
6669 | { | |
6670 | unsigned char *vstart = *vstart_ptr; | |
6671 | unsigned char *section_end = section->start + section->size; | |
6672 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
6673 | ||
6674 | if (vlistend < section_end) | |
6675 | section_end = vlistend; | |
6676 | ||
6677 | putchar ('\n'); | |
6678 | ||
6679 | while (vstart < section_end) | |
6680 | { | |
6681 | uint64_t off = vstart - section->start; | |
6682 | uint64_t vbegin, vend; | |
6683 | ||
6684 | READ_ULEB (vbegin, vstart, section_end); | |
6685 | if (vstart == section_end) | |
6686 | break; | |
6687 | ||
6688 | READ_ULEB (vend, vstart, section_end); | |
6689 | printf (" %8.8" PRIx64 " ", off); | |
6690 | ||
6691 | print_view (vbegin, pointer_size); | |
6692 | print_view (vend, pointer_size); | |
6693 | printf (_("location view pair\n")); | |
6694 | } | |
6695 | ||
6696 | putchar ('\n'); | |
6697 | *vstart_ptr = vstart; | |
6698 | } | |
6699 | ||
6700 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ | |
6701 | ||
6702 | static void | |
6703 | display_loc_list (struct dwarf_section *section, | |
6704 | unsigned char **start_ptr, | |
6705 | unsigned int debug_info_entry, | |
6706 | uint64_t offset, | |
6707 | uint64_t base_address, | |
6708 | unsigned char **vstart_ptr, | |
6709 | int has_frame_base) | |
6710 | { | |
6711 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; | |
6712 | unsigned char *section_end = section->start + section->size; | |
6713 | uint64_t cu_offset; | |
6714 | unsigned int pointer_size; | |
6715 | unsigned int offset_size; | |
6716 | int dwarf_version; | |
6717 | uint64_t begin; | |
6718 | uint64_t end; | |
6719 | unsigned short length; | |
6720 | int need_frame_base; | |
6721 | ||
6722 | if (debug_info_entry >= num_debug_info_entries) | |
6723 | { | |
6724 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
6725 | debug_info_entry); | |
6726 | return; | |
6727 | } | |
6728 | ||
6729 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6730 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6731 | offset_size = debug_information [debug_info_entry].offset_size; | |
6732 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6733 | ||
6734 | if (pointer_size < 2 || pointer_size > 8) | |
6735 | { | |
6736 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6737 | pointer_size, debug_info_entry); | |
6738 | return; | |
6739 | } | |
6740 | ||
6741 | while (1) | |
6742 | { | |
6743 | uint64_t off = offset + (start - *start_ptr); | |
6744 | uint64_t vbegin = -1, vend = -1; | |
6745 | ||
6746 | if (2 * pointer_size > (size_t) (section_end - start)) | |
6747 | { | |
6748 | warn (_("Location list starting at offset %#" PRIx64 | |
6749 | " is not terminated.\n"), offset); | |
6750 | break; | |
6751 | } | |
6752 | ||
6753 | printf (" "); | |
6754 | print_hex (off, 4); | |
6755 | ||
6756 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6757 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
6758 | ||
6759 | if (begin == 0 && end == 0) | |
6760 | { | |
6761 | /* PR 18374: In a object file we can have a location list that | |
6762 | starts with a begin and end of 0 because there are relocations | |
6763 | that need to be applied to the addresses. Actually applying | |
6764 | the relocations now does not help as they will probably resolve | |
6765 | to 0, since the object file has not been fully linked. Real | |
6766 | end of list markers will not have any relocations against them. */ | |
6767 | if (! reloc_at (section, off) | |
6768 | && ! reloc_at (section, off + pointer_size)) | |
6769 | { | |
6770 | printf (_("<End of list>\n")); | |
6771 | break; | |
6772 | } | |
6773 | } | |
6774 | ||
6775 | /* Check base address specifiers. */ | |
6776 | if (is_max_address (begin, pointer_size) | |
6777 | && !is_max_address (end, pointer_size)) | |
6778 | { | |
6779 | base_address = end; | |
6780 | print_hex (begin, pointer_size); | |
6781 | print_hex (end, pointer_size); | |
6782 | printf (_("(base address)\n")); | |
6783 | continue; | |
6784 | } | |
6785 | ||
6786 | if (vstart) | |
6787 | { | |
6788 | off = offset + (vstart - *start_ptr); | |
6789 | ||
6790 | READ_ULEB (vbegin, vstart, section_end); | |
6791 | print_view (vbegin, pointer_size); | |
6792 | ||
6793 | READ_ULEB (vend, vstart, section_end); | |
6794 | print_view (vend, pointer_size); | |
6795 | ||
6796 | printf (_("views at %8.8" PRIx64 " for:\n %*s "), off, 8, ""); | |
6797 | } | |
6798 | ||
6799 | if (2 > (size_t) (section_end - start)) | |
6800 | { | |
6801 | warn (_("Location list starting at offset %#" PRIx64 | |
6802 | " is not terminated.\n"), offset); | |
6803 | break; | |
6804 | } | |
6805 | ||
6806 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); | |
6807 | ||
6808 | if (length > (size_t) (section_end - start)) | |
6809 | { | |
6810 | warn (_("Location list starting at offset %#" PRIx64 | |
6811 | " is not terminated.\n"), offset); | |
6812 | break; | |
6813 | } | |
6814 | ||
6815 | print_hex (begin + base_address, pointer_size); | |
6816 | print_hex (end + base_address, pointer_size); | |
6817 | ||
6818 | putchar ('('); | |
6819 | need_frame_base = decode_location_expression (start, | |
6820 | pointer_size, | |
6821 | offset_size, | |
6822 | dwarf_version, | |
6823 | length, | |
6824 | cu_offset, section); | |
6825 | putchar (')'); | |
6826 | ||
6827 | if (need_frame_base && !has_frame_base) | |
6828 | printf (_(" [without DW_AT_frame_base]")); | |
6829 | ||
6830 | if (begin == end && vbegin == vend) | |
6831 | fputs (_(" (start == end)"), stdout); | |
6832 | else if (begin > end || (begin == end && vbegin > vend)) | |
6833 | fputs (_(" (start > end)"), stdout); | |
6834 | ||
6835 | putchar ('\n'); | |
6836 | ||
6837 | start += length; | |
6838 | } | |
6839 | ||
6840 | *start_ptr = start; | |
6841 | *vstart_ptr = vstart; | |
6842 | } | |
6843 | ||
6844 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ | |
6845 | ||
6846 | static void | |
6847 | display_loclists_list (struct dwarf_section * section, | |
6848 | unsigned char ** start_ptr, | |
6849 | debug_info * debug_info_p, | |
6850 | uint64_t offset, | |
6851 | uint64_t base_address, | |
6852 | unsigned char ** vstart_ptr, | |
6853 | int has_frame_base) | |
6854 | { | |
6855 | unsigned char *start = *start_ptr; | |
6856 | unsigned char *vstart = *vstart_ptr; | |
6857 | unsigned char *section_end = section->start + section->size; | |
6858 | uint64_t cu_offset; | |
6859 | unsigned int pointer_size; | |
6860 | unsigned int offset_size; | |
6861 | unsigned int dwarf_version; | |
6862 | uint64_t idx; | |
6863 | ||
6864 | /* Initialize it due to a false compiler warning. */ | |
6865 | uint64_t begin = -1, vbegin = -1; | |
6866 | uint64_t end = -1, vend = -1; | |
6867 | uint64_t length; | |
6868 | int need_frame_base; | |
6869 | ||
6870 | cu_offset = debug_info_p->cu_offset; | |
6871 | pointer_size = debug_info_p->pointer_size; | |
6872 | offset_size = debug_info_p->offset_size; | |
6873 | dwarf_version = debug_info_p->dwarf_version; | |
6874 | ||
6875 | if (pointer_size < 2 || pointer_size > 8) | |
6876 | { | |
6877 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6878 | pointer_size, (int)(debug_info_p - debug_information)); | |
6879 | return; | |
6880 | } | |
6881 | ||
6882 | while (1) | |
6883 | { | |
6884 | uint64_t off = offset + (start - *start_ptr); | |
6885 | enum dwarf_location_list_entry_type llet; | |
6886 | ||
6887 | if (start + 1 > section_end) | |
6888 | { | |
6889 | warn (_("Location list starting at offset %#" PRIx64 | |
6890 | " is not terminated.\n"), offset); | |
6891 | break; | |
6892 | } | |
6893 | ||
6894 | printf (" "); | |
6895 | print_hex (off, 4); | |
6896 | ||
6897 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6898 | ||
6899 | if (vstart && (llet == DW_LLE_offset_pair | |
6900 | || llet == DW_LLE_start_end | |
6901 | || llet == DW_LLE_start_length)) | |
6902 | { | |
6903 | off = offset + (vstart - *start_ptr); | |
6904 | ||
6905 | READ_ULEB (vbegin, vstart, section_end); | |
6906 | print_view (vbegin, pointer_size); | |
6907 | ||
6908 | READ_ULEB (vend, vstart, section_end); | |
6909 | print_view (vend, pointer_size); | |
6910 | ||
6911 | printf (_("views at %8.8" PRIx64 " for:\n %*s "), off, 8, ""); | |
6912 | } | |
6913 | ||
6914 | switch (llet) | |
6915 | { | |
6916 | case DW_LLE_end_of_list: | |
6917 | printf (_("<End of list>\n")); | |
6918 | break; | |
6919 | ||
6920 | case DW_LLE_base_addressx: | |
6921 | READ_ULEB (idx, start, section_end); | |
6922 | print_hex (idx, pointer_size); | |
6923 | printf (_("(index into .debug_addr) ")); | |
6924 | base_address = fetch_indexed_addr | |
6925 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); | |
6926 | print_hex (base_address, pointer_size); | |
6927 | printf (_("(base address)\n")); | |
6928 | break; | |
6929 | ||
6930 | case DW_LLE_startx_endx: | |
6931 | READ_ULEB (idx, start, section_end); | |
6932 | begin = fetch_indexed_addr | |
6933 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); | |
6934 | READ_ULEB (idx, start, section_end); | |
6935 | end = fetch_indexed_addr | |
6936 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); | |
6937 | break; | |
6938 | ||
6939 | case DW_LLE_startx_length: | |
6940 | READ_ULEB (idx, start, section_end); | |
6941 | begin = fetch_indexed_addr | |
6942 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); | |
6943 | READ_ULEB (end, start, section_end); | |
6944 | end += begin; | |
6945 | break; | |
6946 | ||
6947 | case DW_LLE_default_location: | |
6948 | begin = end = 0; | |
6949 | break; | |
6950 | ||
6951 | case DW_LLE_offset_pair: | |
6952 | READ_ULEB (begin, start, section_end); | |
6953 | begin += base_address; | |
6954 | READ_ULEB (end, start, section_end); | |
6955 | end += base_address; | |
6956 | break; | |
6957 | ||
6958 | case DW_LLE_base_address: | |
6959 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6960 | section_end); | |
6961 | print_hex (base_address, pointer_size); | |
6962 | printf (_("(base address)\n")); | |
6963 | break; | |
6964 | ||
6965 | case DW_LLE_start_end: | |
6966 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6967 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
6968 | break; | |
6969 | ||
6970 | case DW_LLE_start_length: | |
6971 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6972 | READ_ULEB (end, start, section_end); | |
6973 | end += begin; | |
6974 | break; | |
6975 | ||
6976 | #ifdef DW_LLE_view_pair | |
6977 | case DW_LLE_view_pair: | |
6978 | if (vstart) | |
6979 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
6980 | READ_ULEB (vbegin, start, section_end); | |
6981 | print_view (vbegin, pointer_size); | |
6982 | ||
6983 | READ_ULEB (vend, start, section_end); | |
6984 | print_view (vend, pointer_size); | |
6985 | ||
6986 | printf (_("views for:\n")); | |
6987 | continue; | |
6988 | #endif | |
6989 | ||
6990 | default: | |
6991 | error (_("Invalid location list entry type %d\n"), llet); | |
6992 | return; | |
6993 | } | |
6994 | ||
6995 | if (llet == DW_LLE_end_of_list) | |
6996 | break; | |
6997 | ||
6998 | if (llet == DW_LLE_base_address | |
6999 | || llet == DW_LLE_base_addressx) | |
7000 | continue; | |
7001 | ||
7002 | if (start == section_end) | |
7003 | { | |
7004 | warn (_("Location list starting at offset %#" PRIx64 | |
7005 | " is not terminated.\n"), offset); | |
7006 | break; | |
7007 | } | |
7008 | READ_ULEB (length, start, section_end); | |
7009 | ||
7010 | if (length > (size_t) (section_end - start)) | |
7011 | { | |
7012 | warn (_("Location list starting at offset %#" PRIx64 | |
7013 | " is not terminated.\n"), offset); | |
7014 | break; | |
7015 | } | |
7016 | ||
7017 | print_hex (begin, pointer_size); | |
7018 | print_hex (end, pointer_size); | |
7019 | ||
7020 | putchar ('('); | |
7021 | need_frame_base = decode_location_expression (start, | |
7022 | pointer_size, | |
7023 | offset_size, | |
7024 | dwarf_version, | |
7025 | length, | |
7026 | cu_offset, section); | |
7027 | putchar (')'); | |
7028 | ||
7029 | if (need_frame_base && !has_frame_base) | |
7030 | printf (_(" [without DW_AT_frame_base]")); | |
7031 | ||
7032 | if (begin == end && vbegin == vend) | |
7033 | fputs (_(" (start == end)"), stdout); | |
7034 | else if (begin > end || (begin == end && vbegin > vend)) | |
7035 | fputs (_(" (start > end)"), stdout); | |
7036 | ||
7037 | putchar ('\n'); | |
7038 | ||
7039 | start += length; | |
7040 | vbegin = vend = -1; | |
7041 | } | |
7042 | ||
7043 | if (vbegin != (uint64_t) -1 || vend != (uint64_t) -1) | |
7044 | printf (_("Trailing view pair not used in a range")); | |
7045 | ||
7046 | *start_ptr = start; | |
7047 | *vstart_ptr = vstart; | |
7048 | } | |
7049 | ||
7050 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, | |
7051 | right-adjusted in a field of length LEN, and followed by a space. */ | |
7052 | ||
7053 | static void | |
7054 | print_addr_index (unsigned int idx, unsigned int len) | |
7055 | { | |
7056 | static char buf[15]; | |
7057 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
7058 | printf ("%*s ", len, buf); | |
7059 | } | |
7060 | ||
7061 | /* Display a location list from a .dwo section. It uses address indexes rather | |
7062 | than embedded addresses. This code closely follows display_loc_list, but the | |
7063 | two are sufficiently different that combining things is very ugly. */ | |
7064 | ||
7065 | static void | |
7066 | display_loc_list_dwo (struct dwarf_section *section, | |
7067 | unsigned char **start_ptr, | |
7068 | unsigned int debug_info_entry, | |
7069 | uint64_t offset, | |
7070 | unsigned char **vstart_ptr, | |
7071 | int has_frame_base) | |
7072 | { | |
7073 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; | |
7074 | unsigned char *section_end = section->start + section->size; | |
7075 | uint64_t cu_offset; | |
7076 | unsigned int pointer_size; | |
7077 | unsigned int offset_size; | |
7078 | int dwarf_version; | |
7079 | int entry_type; | |
7080 | unsigned short length; | |
7081 | int need_frame_base; | |
7082 | unsigned int idx; | |
7083 | ||
7084 | if (debug_info_entry >= num_debug_info_entries) | |
7085 | { | |
7086 | warn (_("No debug information for loc lists of entry: %u\n"), | |
7087 | debug_info_entry); | |
7088 | return; | |
7089 | } | |
7090 | ||
7091 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
7092 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
7093 | offset_size = debug_information [debug_info_entry].offset_size; | |
7094 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
7095 | ||
7096 | if (pointer_size < 2 || pointer_size > 8) | |
7097 | { | |
7098 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
7099 | pointer_size, debug_info_entry); | |
7100 | return; | |
7101 | } | |
7102 | ||
7103 | while (1) | |
7104 | { | |
7105 | printf (" "); | |
7106 | print_hex (offset + (start - *start_ptr), 4); | |
7107 | ||
7108 | if (start >= section_end) | |
7109 | { | |
7110 | warn (_("Location list starting at offset %#" PRIx64 | |
7111 | " is not terminated.\n"), offset); | |
7112 | break; | |
7113 | } | |
7114 | ||
7115 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); | |
7116 | ||
7117 | if (vstart) | |
7118 | switch (entry_type) | |
7119 | { | |
7120 | default: | |
7121 | break; | |
7122 | ||
7123 | case 2: | |
7124 | case 3: | |
7125 | case 4: | |
7126 | { | |
7127 | uint64_t view; | |
7128 | uint64_t off = offset + (vstart - *start_ptr); | |
7129 | ||
7130 | READ_ULEB (view, vstart, section_end); | |
7131 | print_view (view, 8); | |
7132 | ||
7133 | READ_ULEB (view, vstart, section_end); | |
7134 | print_view (view, 8); | |
7135 | ||
7136 | printf (_("views at %8.8" PRIx64 " for:\n %*s "), off, 8, ""); | |
7137 | ||
7138 | } | |
7139 | break; | |
7140 | } | |
7141 | ||
7142 | switch (entry_type) | |
7143 | { | |
7144 | case 0: /* A terminating entry. */ | |
7145 | *start_ptr = start; | |
7146 | *vstart_ptr = vstart; | |
7147 | printf (_("<End of list>\n")); | |
7148 | return; | |
7149 | case 1: /* A base-address entry. */ | |
7150 | READ_ULEB (idx, start, section_end); | |
7151 | print_addr_index (idx, 8); | |
7152 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); | |
7153 | printf (_("(base address selection entry)\n")); | |
7154 | continue; | |
7155 | case 2: /* A start/end entry. */ | |
7156 | READ_ULEB (idx, start, section_end); | |
7157 | print_addr_index (idx, 8); | |
7158 | READ_ULEB (idx, start, section_end); | |
7159 | print_addr_index (idx, 8); | |
7160 | break; | |
7161 | case 3: /* A start/length entry. */ | |
7162 | READ_ULEB (idx, start, section_end); | |
7163 | print_addr_index (idx, 8); | |
7164 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
7165 | printf ("%08x ", idx); | |
7166 | break; | |
7167 | case 4: /* An offset pair entry. */ | |
7168 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
7169 | printf ("%08x ", idx); | |
7170 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
7171 | printf ("%08x ", idx); | |
7172 | break; | |
7173 | default: | |
7174 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
7175 | *start_ptr = start; | |
7176 | *vstart_ptr = vstart; | |
7177 | return; | |
7178 | } | |
7179 | ||
7180 | if (2 > (size_t) (section_end - start)) | |
7181 | { | |
7182 | warn (_("Location list starting at offset %#" PRIx64 | |
7183 | " is not terminated.\n"), offset); | |
7184 | break; | |
7185 | } | |
7186 | ||
7187 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); | |
7188 | if (length > (size_t) (section_end - start)) | |
7189 | { | |
7190 | warn (_("Location list starting at offset %#" PRIx64 | |
7191 | " is not terminated.\n"), offset); | |
7192 | break; | |
7193 | } | |
7194 | ||
7195 | putchar ('('); | |
7196 | need_frame_base = decode_location_expression (start, | |
7197 | pointer_size, | |
7198 | offset_size, | |
7199 | dwarf_version, | |
7200 | length, | |
7201 | cu_offset, section); | |
7202 | putchar (')'); | |
7203 | ||
7204 | if (need_frame_base && !has_frame_base) | |
7205 | printf (_(" [without DW_AT_frame_base]")); | |
7206 | ||
7207 | putchar ('\n'); | |
7208 | ||
7209 | start += length; | |
7210 | } | |
7211 | ||
7212 | *start_ptr = start; | |
7213 | *vstart_ptr = vstart; | |
7214 | } | |
7215 | ||
7216 | /* Sort array of indexes in ascending order of loc_offsets[idx] and | |
7217 | loc_views. */ | |
7218 | ||
7219 | static uint64_t *loc_offsets, *loc_views; | |
7220 | ||
7221 | static int | |
7222 | loc_offsets_compar (const void *ap, const void *bp) | |
7223 | { | |
7224 | uint64_t a = loc_offsets[*(const unsigned int *) ap]; | |
7225 | uint64_t b = loc_offsets[*(const unsigned int *) bp]; | |
7226 | ||
7227 | int ret = (a > b) - (b > a); | |
7228 | if (ret) | |
7229 | return ret; | |
7230 | ||
7231 | a = loc_views[*(const unsigned int *) ap]; | |
7232 | b = loc_views[*(const unsigned int *) bp]; | |
7233 | ||
7234 | ret = (a > b) - (b > a); | |
7235 | ||
7236 | return ret; | |
7237 | } | |
7238 | ||
7239 | /* Reads and dumps the DWARFv5 loclists compiler unit header, | |
7240 | including the offset table. | |
7241 | Returns the offset of the next compile unit header. */ | |
7242 | ||
7243 | static uint64_t | |
7244 | display_loclists_unit_header (struct dwarf_section * section, | |
7245 | uint64_t header_offset, | |
7246 | uint32_t * offset_count, | |
7247 | unsigned char ** loclists_start) | |
7248 | { | |
7249 | uint64_t length; | |
7250 | unsigned char *start = section->start + header_offset; | |
7251 | unsigned char *end = section->start + section->size; | |
7252 | unsigned short version; | |
7253 | unsigned char address_size; | |
7254 | unsigned char segment_selector_size; | |
7255 | bool is_64bit; | |
7256 | uint32_t i; | |
7257 | ||
7258 | printf (_("Table at Offset %#" PRIx64 "\n"), header_offset); | |
7259 | ||
7260 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); | |
7261 | if (length == 0xffffffff) | |
7262 | { | |
7263 | is_64bit = true; | |
7264 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); | |
7265 | } | |
7266 | else | |
7267 | is_64bit = false; | |
7268 | ||
7269 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); | |
7270 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, end); | |
7271 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, end); | |
7272 | SAFE_BYTE_GET_AND_INC (*offset_count, start, 4, end); | |
7273 | ||
7274 | printf (_(" Length: %#" PRIx64 "\n"), length); | |
7275 | printf (_(" DWARF version: %u\n"), version); | |
7276 | printf (_(" Address size: %u\n"), address_size); | |
7277 | printf (_(" Segment size: %u\n"), segment_selector_size); | |
7278 | printf (_(" Offset entries: %u\n"), *offset_count); | |
7279 | ||
7280 | if (segment_selector_size != 0) | |
7281 | { | |
7282 | warn (_("The %s section contains an " | |
7283 | "unsupported segment selector size: %d.\n"), | |
7284 | section->name, segment_selector_size); | |
7285 | return (uint64_t)-1; | |
7286 | } | |
7287 | ||
7288 | if ( *offset_count) | |
7289 | { | |
7290 | printf (_("\n Offset Entries starting at %#tx:\n"), | |
7291 | start - section->start); | |
7292 | ||
7293 | for (i = 0; i < *offset_count; i++) | |
7294 | { | |
7295 | uint64_t entry; | |
7296 | ||
7297 | SAFE_BYTE_GET_AND_INC (entry, start, is_64bit ? 8 : 4, end); | |
7298 | printf (_(" [%6u] %#" PRIx64 "\n"), i, entry); | |
7299 | } | |
7300 | } | |
7301 | ||
7302 | putchar ('\n'); | |
7303 | *loclists_start = start; | |
7304 | ||
7305 | /* The length field doesn't include the length field itself. */ | |
7306 | return header_offset + length + (is_64bit ? 12 : 4); | |
7307 | } | |
7308 | ||
7309 | static int | |
7310 | display_debug_loc (struct dwarf_section *section, void *file) | |
7311 | { | |
7312 | unsigned char *start = section->start, *vstart = NULL; | |
7313 | uint64_t bytes; | |
7314 | unsigned char *section_begin = start; | |
7315 | unsigned int num_loc_list = 0; | |
7316 | uint64_t last_offset = 0; | |
7317 | uint64_t last_view = 0; | |
7318 | unsigned int first = 0; | |
7319 | unsigned int i; | |
7320 | unsigned int j; | |
7321 | int seen_first_offset = 0; | |
7322 | int locs_sorted = 1; | |
7323 | unsigned char *next = start, *vnext = vstart; | |
7324 | unsigned int *array = NULL; | |
7325 | const char *suffix = strrchr (section->name, '.'); | |
7326 | bool is_dwo = false; | |
7327 | bool is_loclists = strstr (section->name, "debug_loclists") != NULL; | |
7328 | uint64_t next_header_offset = 0; | |
7329 | ||
7330 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
7331 | is_dwo = true; | |
7332 | ||
7333 | bytes = section->size; | |
7334 | ||
7335 | if (bytes == 0) | |
7336 | { | |
7337 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7338 | return 0; | |
7339 | } | |
7340 | ||
7341 | if (is_loclists) | |
7342 | { | |
7343 | unsigned char *hdrptr = section_begin; | |
7344 | uint64_t ll_length; | |
7345 | unsigned short ll_version; | |
7346 | unsigned char *end = section_begin + section->size; | |
7347 | unsigned char address_size, segment_selector_size; | |
7348 | uint32_t offset_entry_count; | |
7349 | ||
7350 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
7351 | if (ll_length == 0xffffffff) | |
7352 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
7353 | ||
7354 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
7355 | if (ll_version != 5) | |
7356 | { | |
7357 | warn (_("The %s section contains corrupt or " | |
7358 | "unsupported version number: %d.\n"), | |
7359 | section->name, ll_version); | |
7360 | return 0; | |
7361 | } | |
7362 | ||
7363 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
7364 | ||
7365 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
7366 | if (segment_selector_size != 0) | |
7367 | { | |
7368 | warn (_("The %s section contains " | |
7369 | "unsupported segment selector size: %d.\n"), | |
7370 | section->name, segment_selector_size); | |
7371 | return 0; | |
7372 | } | |
7373 | ||
7374 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
7375 | ||
7376 | /*if (offset_entry_count != 0) | |
7377 | return display_offset_entry_loclists (section);*/ | |
7378 | ||
7379 | //header_size = hdrptr - section_begin; | |
7380 | } | |
7381 | ||
7382 | if (load_debug_info (file) == 0) | |
7383 | { | |
7384 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7385 | section->name); | |
7386 | return 0; | |
7387 | } | |
7388 | ||
7389 | /* Check the order of location list in .debug_info section. If | |
7390 | offsets of location lists are in the ascending order, we can | |
7391 | use `debug_information' directly. */ | |
7392 | for (i = 0; i < num_debug_info_entries; i++) | |
7393 | { | |
7394 | unsigned int num; | |
7395 | ||
7396 | num = debug_information [i].num_loc_offsets; | |
7397 | if (num > num_loc_list) | |
7398 | num_loc_list = num; | |
7399 | ||
7400 | /* Check if we can use `debug_information' directly. */ | |
7401 | if (locs_sorted && num != 0) | |
7402 | { | |
7403 | if (!seen_first_offset) | |
7404 | { | |
7405 | /* This is the first location list. */ | |
7406 | last_offset = debug_information [i].loc_offsets [0]; | |
7407 | last_view = debug_information [i].loc_views [0]; | |
7408 | first = i; | |
7409 | seen_first_offset = 1; | |
7410 | j = 1; | |
7411 | } | |
7412 | else | |
7413 | j = 0; | |
7414 | ||
7415 | for (; j < num; j++) | |
7416 | { | |
7417 | if (last_offset > debug_information [i].loc_offsets [j] | |
7418 | || (last_offset == debug_information [i].loc_offsets [j] | |
7419 | && last_view > debug_information [i].loc_views [j])) | |
7420 | { | |
7421 | locs_sorted = 0; | |
7422 | break; | |
7423 | } | |
7424 | last_offset = debug_information [i].loc_offsets [j]; | |
7425 | last_view = debug_information [i].loc_views [j]; | |
7426 | } | |
7427 | } | |
7428 | } | |
7429 | ||
7430 | if (!seen_first_offset) | |
7431 | error (_("No location lists in .debug_info section!\n")); | |
7432 | ||
7433 | if (!locs_sorted) | |
7434 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
7435 | ||
7436 | introduce (section, false); | |
7437 | ||
7438 | if (reloc_at (section, 0)) | |
7439 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
7440 | ||
7441 | if (!is_loclists) | |
7442 | printf (_(" Offset Begin End Expression\n")); | |
7443 | ||
7444 | for (i = first; i < num_debug_info_entries; i++) | |
7445 | { | |
7446 | uint64_t offset = 0, voffset = 0; | |
7447 | uint64_t base_address; | |
7448 | unsigned int k; | |
7449 | int has_frame_base; | |
7450 | debug_info *debug_info_p = debug_information + i; | |
7451 | uint32_t offset_count; | |
7452 | ||
7453 | /* .debug_loclists section is loaded into debug_information as | |
7454 | DWARF-5 debug info and .debug_loc section is loaded into | |
7455 | debug_information as pre-DWARF-5 debug info. When dumping | |
7456 | .debug_loc section, we should only process pre-DWARF-5 debug | |
7457 | info in debug_information. When dumping .debug_loclists | |
7458 | section, we should only process DWARF-5 info in | |
7459 | debug_information. */ | |
7460 | if ((debug_info_p->dwarf_version >= 5) != is_loclists) | |
7461 | continue; | |
7462 | ||
7463 | if (!locs_sorted) | |
7464 | { | |
7465 | for (k = 0; k < debug_info_p->num_loc_offsets; k++) | |
7466 | array[k] = k; | |
7467 | loc_offsets = debug_info_p->loc_offsets; | |
7468 | loc_views = debug_info_p->loc_views; | |
7469 | qsort (array, debug_info_p->num_loc_offsets, | |
7470 | sizeof (*array), loc_offsets_compar); | |
7471 | } | |
7472 | ||
7473 | /* .debug_loclists has a per-unit header. | |
7474 | Update start if we are detecting it. */ | |
7475 | if (debug_info_p->dwarf_version >= 5) | |
7476 | { | |
7477 | j = locs_sorted ? 0 : array [0]; | |
7478 | ||
7479 | if (debug_info_p->num_loc_offsets) | |
7480 | offset = debug_info_p->loc_offsets [j]; | |
7481 | ||
7482 | if (debug_info_p->num_loc_views) | |
7483 | voffset = debug_info_p->loc_views [j]; | |
7484 | ||
7485 | /* Parse and dump unit headers in loclists. | |
7486 | This will misbehave if the order of CUs in debug_info | |
7487 | doesn't match the one in loclists. */ | |
7488 | if (next_header_offset < offset) | |
7489 | { | |
7490 | while (next_header_offset < offset) | |
7491 | { | |
7492 | next_header_offset = display_loclists_unit_header | |
7493 | (section, next_header_offset, &offset_count, &start); | |
7494 | ||
7495 | if (next_header_offset == (uint64_t)-1) | |
7496 | /* Header parsing error. */ | |
7497 | return 0; | |
7498 | } | |
7499 | ||
7500 | printf (_("\ | |
7501 | Offset Begin End Expression\n")); | |
7502 | } | |
7503 | } | |
7504 | ||
7505 | int adjacent_view_loclists = 1; | |
7506 | ||
7507 | for (k = 0; k < debug_info_p->num_loc_offsets; k++) | |
7508 | { | |
7509 | j = locs_sorted ? k : array[k]; | |
7510 | if (k | |
7511 | && (debug_info_p->loc_offsets [locs_sorted | |
7512 | ? k - 1 : array [k - 1]] | |
7513 | == debug_info_p->loc_offsets [j]) | |
7514 | && (debug_info_p->loc_views [locs_sorted | |
7515 | ? k - 1 : array [k - 1]] | |
7516 | == debug_info_p->loc_views [j])) | |
7517 | continue; | |
7518 | has_frame_base = debug_info_p->have_frame_base [j]; | |
7519 | offset = debug_info_p->loc_offsets [j]; | |
7520 | next = section_begin + offset; | |
7521 | voffset = debug_info_p->loc_views [j]; | |
7522 | if (voffset != (uint64_t) -1) | |
7523 | vnext = section_begin + voffset; | |
7524 | else | |
7525 | vnext = NULL; | |
7526 | base_address = debug_info_p->base_address; | |
7527 | ||
7528 | if (vnext && vnext < next) | |
7529 | { | |
7530 | vstart = vnext; | |
7531 | display_view_pair_list (section, &vstart, i, next); | |
7532 | if (start == vnext) | |
7533 | start = vstart; | |
7534 | } | |
7535 | ||
7536 | if (start < next) | |
7537 | { | |
7538 | if (vnext && vnext < next) | |
7539 | warn (_("There is a hole [%#tx - %#" PRIx64 "]" | |
7540 | " in %s section.\n"), | |
7541 | start - section_begin, voffset, section->name); | |
7542 | else | |
7543 | warn (_("There is a hole [%#tx - %#" PRIx64 "]" | |
7544 | " in %s section.\n"), | |
7545 | start - section_begin, offset, section->name); | |
7546 | } | |
7547 | else if (start > next) | |
7548 | warn (_("There is an overlap [%#tx - %#" PRIx64 "]" | |
7549 | " in %s section.\n"), | |
7550 | start - section_begin, offset, section->name); | |
7551 | start = next; | |
7552 | vstart = vnext; | |
7553 | ||
7554 | if (offset >= bytes) | |
7555 | { | |
7556 | warn (_("Offset %#" PRIx64 " is bigger than %s section size.\n"), | |
7557 | offset, section->name); | |
7558 | continue; | |
7559 | } | |
7560 | ||
7561 | if (vnext && voffset >= bytes) | |
7562 | { | |
7563 | warn (_("View Offset %#" PRIx64 " is bigger than %s section size.\n"), | |
7564 | voffset, section->name); | |
7565 | continue; | |
7566 | } | |
7567 | ||
7568 | if (!is_loclists) | |
7569 | { | |
7570 | if (is_dwo) | |
7571 | display_loc_list_dwo (section, &start, i, offset, | |
7572 | &vstart, has_frame_base); | |
7573 | else | |
7574 | display_loc_list (section, &start, i, offset, base_address, | |
7575 | &vstart, has_frame_base); | |
7576 | } | |
7577 | else | |
7578 | { | |
7579 | if (is_dwo) | |
7580 | warn (_("DWO is not yet supported.\n")); | |
7581 | else | |
7582 | display_loclists_list (section, &start, debug_info_p, offset, | |
7583 | base_address, &vstart, has_frame_base); | |
7584 | } | |
7585 | ||
7586 | /* FIXME: this arrangement is quite simplistic. Nothing | |
7587 | requires locview lists to be adjacent to corresponding | |
7588 | loclists, and a single loclist could be augmented by | |
7589 | different locview lists, and vice-versa, unlikely as it | |
7590 | is that it would make sense to do so. Hopefully we'll | |
7591 | have view pair support built into loclists before we ever | |
7592 | need to address all these possibilities. */ | |
7593 | if (adjacent_view_loclists && vnext | |
7594 | && vnext != start && vstart != next) | |
7595 | { | |
7596 | adjacent_view_loclists = 0; | |
7597 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
7598 | } | |
7599 | ||
7600 | if (vnext && vnext == start) | |
7601 | display_view_pair_list (section, &start, i, vstart); | |
7602 | } | |
7603 | } | |
7604 | ||
7605 | if (start < section->start + section->size) | |
7606 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", | |
7607 | "There are %ld unused bytes at the end of section %s\n", | |
7608 | (long) (section->start + section->size - start)), | |
7609 | (long) (section->start + section->size - start), section->name); | |
7610 | putchar ('\n'); | |
7611 | free (array); | |
7612 | return 1; | |
7613 | } | |
7614 | ||
7615 | static int | |
7616 | display_debug_str (struct dwarf_section *section, | |
7617 | void *file ATTRIBUTE_UNUSED) | |
7618 | { | |
7619 | unsigned char *start = section->start; | |
7620 | uint64_t bytes = section->size; | |
7621 | uint64_t addr = section->address; | |
7622 | ||
7623 | if (bytes == 0) | |
7624 | { | |
7625 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7626 | return 0; | |
7627 | } | |
7628 | ||
7629 | introduce (section, false); | |
7630 | ||
7631 | while (bytes) | |
7632 | { | |
7633 | int j; | |
7634 | int k; | |
7635 | int lbytes; | |
7636 | ||
7637 | lbytes = (bytes > 16 ? 16 : bytes); | |
7638 | ||
7639 | printf (" 0x%8.8" PRIx64 " ", addr); | |
7640 | ||
7641 | for (j = 0; j < 16; j++) | |
7642 | { | |
7643 | if (j < lbytes) | |
7644 | printf ("%2.2x", start[j]); | |
7645 | else | |
7646 | printf (" "); | |
7647 | ||
7648 | if ((j & 3) == 3) | |
7649 | printf (" "); | |
7650 | } | |
7651 | ||
7652 | for (j = 0; j < lbytes; j++) | |
7653 | { | |
7654 | k = start[j]; | |
7655 | if (k >= ' ' && k < 0x80) | |
7656 | printf ("%c", k); | |
7657 | else | |
7658 | printf ("."); | |
7659 | } | |
7660 | ||
7661 | putchar ('\n'); | |
7662 | ||
7663 | start += lbytes; | |
7664 | addr += lbytes; | |
7665 | bytes -= lbytes; | |
7666 | } | |
7667 | ||
7668 | putchar ('\n'); | |
7669 | ||
7670 | return 1; | |
7671 | } | |
7672 | ||
7673 | static int | |
7674 | display_debug_info (struct dwarf_section *section, void *file) | |
7675 | { | |
7676 | return process_debug_info (section, file, section->abbrev_sec, false, false); | |
7677 | } | |
7678 | ||
7679 | static int | |
7680 | display_debug_types (struct dwarf_section *section, void *file) | |
7681 | { | |
7682 | return process_debug_info (section, file, section->abbrev_sec, false, true); | |
7683 | } | |
7684 | ||
7685 | static int | |
7686 | display_trace_info (struct dwarf_section *section, void *file) | |
7687 | { | |
7688 | return process_debug_info (section, file, section->abbrev_sec, false, true); | |
7689 | } | |
7690 | ||
7691 | static int | |
7692 | display_debug_aranges (struct dwarf_section *section, | |
7693 | void *file ATTRIBUTE_UNUSED) | |
7694 | { | |
7695 | unsigned char *start = section->start; | |
7696 | unsigned char *end = start + section->size; | |
7697 | ||
7698 | introduce (section, false); | |
7699 | ||
7700 | /* It does not matter if this load fails, | |
7701 | we test for that later on. */ | |
7702 | load_debug_info (file); | |
7703 | ||
7704 | while (start < end) | |
7705 | { | |
7706 | unsigned char *hdrptr; | |
7707 | DWARF2_Internal_ARange arange; | |
7708 | unsigned char *addr_ranges; | |
7709 | uint64_t length; | |
7710 | uint64_t address; | |
7711 | uint64_t sec_off; | |
7712 | unsigned char address_size; | |
7713 | unsigned int offset_size; | |
7714 | unsigned char *end_ranges; | |
7715 | ||
7716 | hdrptr = start; | |
7717 | sec_off = hdrptr - section->start; | |
7718 | ||
7719 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); | |
7720 | if (arange.ar_length == 0xffffffff) | |
7721 | { | |
7722 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); | |
7723 | offset_size = 8; | |
7724 | } | |
7725 | else | |
7726 | offset_size = 4; | |
7727 | ||
7728 | if (arange.ar_length > (size_t) (end - hdrptr)) | |
7729 | { | |
7730 | warn (_("Debug info is corrupted, %s header at %#" PRIx64 | |
7731 | " has length %#" PRIx64 "\n"), | |
7732 | section->name, sec_off, arange.ar_length); | |
7733 | break; | |
7734 | } | |
7735 | end_ranges = hdrptr + arange.ar_length; | |
7736 | ||
7737 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end_ranges); | |
7738 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, | |
7739 | end_ranges); | |
7740 | ||
7741 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
7742 | && num_debug_info_entries > 0 | |
7743 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
7744 | warn (_(".debug_info offset of %#" PRIx64 | |
7745 | " in %s section does not point to a CU header.\n"), | |
7746 | arange.ar_info_offset, section->name); | |
7747 | ||
7748 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end_ranges); | |
7749 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end_ranges); | |
7750 | ||
7751 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
7752 | { | |
7753 | /* PR 19872: A version number of 0 probably means that there is | |
7754 | padding at the end of the .debug_aranges section. Gold puts | |
7755 | it there when performing an incremental link, for example. | |
7756 | So do not generate a warning in this case. */ | |
7757 | if (arange.ar_version) | |
7758 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
7759 | break; | |
7760 | } | |
7761 | ||
7762 | printf (_(" Length: %" PRId64 "\n"), arange.ar_length); | |
7763 | printf (_(" Version: %d\n"), arange.ar_version); | |
7764 | printf (_(" Offset into .debug_info: %#" PRIx64 "\n"), | |
7765 | arange.ar_info_offset); | |
7766 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); | |
7767 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
7768 | ||
7769 | address_size = arange.ar_pointer_size + arange.ar_segment_size; | |
7770 | ||
7771 | /* PR 17512: file: 001-108546-0.001:0.1. */ | |
7772 | if (address_size == 0 || address_size > 8) | |
7773 | { | |
7774 | error (_("Invalid address size in %s section!\n"), | |
7775 | section->name); | |
7776 | break; | |
7777 | } | |
7778 | ||
7779 | /* The DWARF spec does not require that the address size be a power | |
7780 | of two, but we do. This will have to change if we ever encounter | |
7781 | an uneven architecture. */ | |
7782 | if ((address_size & (address_size - 1)) != 0) | |
7783 | { | |
7784 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
7785 | break; | |
7786 | } | |
7787 | ||
7788 | if (address_size > 4) | |
7789 | printf (_("\n Address Length\n")); | |
7790 | else | |
7791 | printf (_("\n Address Length\n")); | |
7792 | ||
7793 | addr_ranges = hdrptr; | |
7794 | ||
7795 | /* Must pad to an alignment boundary that is twice the address size. */ | |
7796 | addr_ranges += (2 * address_size - 1 | |
7797 | - (hdrptr - start - 1) % (2 * address_size)); | |
7798 | ||
7799 | while (2 * address_size <= end_ranges - addr_ranges) | |
7800 | { | |
7801 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, | |
7802 | end_ranges); | |
7803 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, | |
7804 | end_ranges); | |
7805 | printf (" "); | |
7806 | print_hex (address, address_size); | |
7807 | print_hex_ns (length, address_size); | |
7808 | putchar ('\n'); | |
7809 | } | |
7810 | ||
7811 | start = end_ranges; | |
7812 | } | |
7813 | ||
7814 | printf ("\n"); | |
7815 | ||
7816 | return 1; | |
7817 | } | |
7818 | ||
7819 | /* Comparison function for qsort. */ | |
7820 | static int | |
7821 | comp_addr_base (const void * v0, const void * v1) | |
7822 | { | |
7823 | debug_info *info0 = *(debug_info **) v0; | |
7824 | debug_info *info1 = *(debug_info **) v1; | |
7825 | return info0->addr_base - info1->addr_base; | |
7826 | } | |
7827 | ||
7828 | /* Display the debug_addr section. */ | |
7829 | static int | |
7830 | display_debug_addr (struct dwarf_section *section, | |
7831 | void *file) | |
7832 | { | |
7833 | debug_info **debug_addr_info; | |
7834 | unsigned char *entry; | |
7835 | unsigned char *end; | |
7836 | unsigned int i; | |
7837 | unsigned int count; | |
7838 | unsigned char * header; | |
7839 | ||
7840 | if (section->size == 0) | |
7841 | { | |
7842 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7843 | return 0; | |
7844 | } | |
7845 | ||
7846 | if (load_debug_info (file) == 0) | |
7847 | { | |
7848 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7849 | section->name); | |
7850 | return 0; | |
7851 | } | |
7852 | ||
7853 | introduce (section, false); | |
7854 | ||
7855 | /* PR 17531: file: cf38d01b. | |
7856 | We use xcalloc because a corrupt file may not have initialised all of the | |
7857 | fields in the debug_info structure, which means that the sort below might | |
7858 | try to move uninitialised data. */ | |
7859 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
7860 | sizeof (debug_info *)); | |
7861 | ||
7862 | count = 0; | |
7863 | for (i = 0; i < num_debug_info_entries; i++) | |
7864 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) | |
7865 | { | |
7866 | /* PR 17531: file: cf38d01b. */ | |
7867 | if (debug_information[i].addr_base >= section->size) | |
7868 | warn (_("Corrupt address base (%#" PRIx64 ")" | |
7869 | " found in debug section %u\n"), | |
7870 | debug_information[i].addr_base, i); | |
7871 | else | |
7872 | debug_addr_info [count++] = debug_information + i; | |
7873 | } | |
7874 | ||
7875 | /* Add a sentinel to make iteration convenient. */ | |
7876 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
7877 | debug_addr_info [count]->addr_base = section->size; | |
7878 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); | |
7879 | ||
7880 | header = section->start; | |
7881 | for (i = 0; i < count; i++) | |
7882 | { | |
7883 | unsigned int idx; | |
7884 | unsigned int address_size = debug_addr_info [i]->pointer_size; | |
7885 | ||
7886 | printf (_(" For compilation unit at offset %#" PRIx64 ":\n"), | |
7887 | debug_addr_info [i]->cu_offset); | |
7888 | ||
7889 | printf (_("\tIndex\tAddress\n")); | |
7890 | entry = section->start + debug_addr_info [i]->addr_base; | |
7891 | if (debug_addr_info [i]->dwarf_version >= 5) | |
7892 | { | |
7893 | size_t header_size = entry - header; | |
7894 | unsigned char *curr_header = header; | |
7895 | uint64_t length; | |
7896 | int version; | |
7897 | int segment_selector_size; | |
7898 | ||
7899 | if (header_size != 8 && header_size != 16) | |
7900 | { | |
7901 | warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"), | |
7902 | section->name, header_size); | |
7903 | break; | |
7904 | } | |
7905 | ||
7906 | SAFE_BYTE_GET_AND_INC (length, curr_header, 4, entry); | |
7907 | if (length == 0xffffffff) | |
7908 | SAFE_BYTE_GET_AND_INC (length, curr_header, 8, entry); | |
7909 | if (length > (size_t) (section->start + section->size - curr_header) | |
7910 | || length < (size_t) (entry - curr_header)) | |
7911 | { | |
7912 | warn (_("Corrupt %s section: unit_length field of %#" PRIx64 | |
7913 | " is invalid\n"), section->name, length); | |
7914 | break; | |
7915 | } | |
7916 | end = curr_header + length; | |
7917 | SAFE_BYTE_GET_AND_INC (version, curr_header, 2, entry); | |
7918 | if (version != 5) | |
7919 | warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"), | |
7920 | section->name, version); | |
7921 | ||
7922 | SAFE_BYTE_GET_AND_INC (address_size, curr_header, 1, entry); | |
7923 | SAFE_BYTE_GET_AND_INC (segment_selector_size, curr_header, 1, entry); | |
7924 | address_size += segment_selector_size; | |
7925 | } | |
7926 | else | |
7927 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
7928 | ||
7929 | header = end; | |
7930 | idx = 0; | |
7931 | ||
7932 | if (address_size < 1 || address_size > sizeof (uint64_t)) | |
7933 | { | |
7934 | warn (_("Corrupt %s section: address size (%x) is wrong\n"), | |
7935 | section->name, address_size); | |
7936 | break; | |
7937 | } | |
7938 | ||
7939 | while ((size_t) (end - entry) >= address_size) | |
7940 | { | |
7941 | uint64_t base = byte_get (entry, address_size); | |
7942 | printf (_("\t%d:\t"), idx); | |
7943 | print_hex_ns (base, address_size); | |
7944 | printf ("\n"); | |
7945 | entry += address_size; | |
7946 | idx++; | |
7947 | } | |
7948 | } | |
7949 | printf ("\n"); | |
7950 | ||
7951 | free (debug_addr_info[count]); | |
7952 | free (debug_addr_info); | |
7953 | return i == count; | |
7954 | } | |
7955 | ||
7956 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
7957 | ||
7958 | static int | |
7959 | display_debug_str_offsets (struct dwarf_section *section, | |
7960 | void *file ATTRIBUTE_UNUSED) | |
7961 | { | |
7962 | unsigned long idx; | |
7963 | ||
7964 | if (section->size == 0) | |
7965 | { | |
7966 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7967 | return 0; | |
7968 | } | |
7969 | ||
7970 | unsigned char *start = section->start; | |
7971 | unsigned char *end = start + section->size; | |
7972 | unsigned char *curr = start; | |
7973 | uint64_t debug_str_offsets_hdr_len; | |
7974 | ||
7975 | const char *suffix = strrchr (section->name, '.'); | |
7976 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; | |
7977 | ||
7978 | if (dwo) | |
7979 | load_debug_section_with_follow (str_dwo, file); | |
7980 | else | |
7981 | load_debug_section_with_follow (str, file); | |
7982 | ||
7983 | introduce (section, false); | |
7984 | ||
7985 | while (curr < end) | |
7986 | { | |
7987 | uint64_t length; | |
7988 | uint64_t entry_length; | |
7989 | ||
7990 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
7991 | /* FIXME: We assume that this means 64-bit DWARF is being used. */ | |
7992 | if (length == 0xffffffff) | |
7993 | { | |
7994 | SAFE_BYTE_GET_AND_INC (length, curr, 8, end); | |
7995 | entry_length = 8; | |
7996 | debug_str_offsets_hdr_len = 16; | |
7997 | } | |
7998 | else | |
7999 | { | |
8000 | entry_length = 4; | |
8001 | debug_str_offsets_hdr_len = 8; | |
8002 | } | |
8003 | ||
8004 | unsigned char *entries_end; | |
8005 | if (length == 0) | |
8006 | { | |
8007 | /* This is probably an old style .debug_str_offset section which | |
8008 | just contains offsets and no header (and the first offset is 0). */ | |
8009 | length = section->size; | |
8010 | curr = section->start; | |
8011 | entries_end = end; | |
8012 | debug_str_offsets_hdr_len = 0; | |
8013 | ||
8014 | printf (_(" Length: %#" PRIx64 "\n"), length); | |
8015 | printf (_(" Index Offset [String]\n")); | |
8016 | } | |
8017 | else | |
8018 | { | |
8019 | if (length <= (size_t) (end - curr)) | |
8020 | entries_end = curr + length; | |
8021 | else | |
8022 | { | |
8023 | warn (_("Section %s is too small %#" PRIx64 "\n"), | |
8024 | section->name, section->size); | |
8025 | entries_end = end; | |
8026 | } | |
8027 | ||
8028 | int version; | |
8029 | SAFE_BYTE_GET_AND_INC (version, curr, 2, entries_end); | |
8030 | if (version != 5) | |
8031 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); | |
8032 | ||
8033 | int padding; | |
8034 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, entries_end); | |
8035 | if (padding != 0) | |
8036 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); | |
8037 | ||
8038 | printf (_(" Length: %#" PRIx64 "\n"), length); | |
8039 | printf (_(" Version: %#x\n"), version); | |
8040 | printf (_(" Index Offset [String]\n")); | |
8041 | } | |
8042 | ||
8043 | for (idx = 0; curr < entries_end; idx++) | |
8044 | { | |
8045 | uint64_t offset; | |
8046 | const unsigned char * string; | |
8047 | ||
8048 | if ((size_t) (entries_end - curr) < entry_length) | |
8049 | /* Not enough space to read one entry_length, give up. */ | |
8050 | return 0; | |
8051 | ||
8052 | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, entries_end); | |
8053 | if (dwo) | |
8054 | string = (const unsigned char *) | |
8055 | fetch_indexed_string (idx, NULL, entry_length, dwo, debug_str_offsets_hdr_len); | |
8056 | else | |
8057 | string = fetch_indirect_string (offset); | |
8058 | ||
8059 | printf (" %8lu ", idx); | |
8060 | print_hex (offset, entry_length); | |
8061 | printf (" %s\n", string); | |
8062 | } | |
8063 | } | |
8064 | ||
8065 | return 1; | |
8066 | } | |
8067 | ||
8068 | /* Each debug_information[x].range_lists[y] gets this representation for | |
8069 | sorting purposes. */ | |
8070 | ||
8071 | struct range_entry | |
8072 | { | |
8073 | /* The debug_information[x].range_lists[y] value. */ | |
8074 | uint64_t ranges_offset; | |
8075 | ||
8076 | /* Original debug_information to find parameters of the data. */ | |
8077 | debug_info *debug_info_p; | |
8078 | }; | |
8079 | ||
8080 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
8081 | ||
8082 | static int | |
8083 | range_entry_compar (const void *ap, const void *bp) | |
8084 | { | |
8085 | const struct range_entry *a_re = (const struct range_entry *) ap; | |
8086 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
8087 | const uint64_t a = a_re->ranges_offset; | |
8088 | const uint64_t b = b_re->ranges_offset; | |
8089 | ||
8090 | return (a > b) - (b > a); | |
8091 | } | |
8092 | ||
8093 | static unsigned char * | |
8094 | display_debug_ranges_list (unsigned char * start, | |
8095 | unsigned char * finish, | |
8096 | unsigned int pointer_size, | |
8097 | uint64_t offset, | |
8098 | uint64_t base_address) | |
8099 | { | |
8100 | while (start < finish) | |
8101 | { | |
8102 | uint64_t begin; | |
8103 | uint64_t end; | |
8104 | ||
8105 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
8106 | if (start >= finish) | |
8107 | break; | |
8108 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
8109 | ||
8110 | printf (" "); | |
8111 | print_hex (offset, 4); | |
8112 | ||
8113 | if (begin == 0 && end == 0) | |
8114 | { | |
8115 | printf (_("<End of list>\n")); | |
8116 | break; | |
8117 | } | |
8118 | ||
8119 | /* Check base address specifiers. */ | |
8120 | if (is_max_address (begin, pointer_size) | |
8121 | && !is_max_address (end, pointer_size)) | |
8122 | { | |
8123 | base_address = end; | |
8124 | print_hex (begin, pointer_size); | |
8125 | print_hex (end, pointer_size); | |
8126 | printf ("(base address)\n"); | |
8127 | continue; | |
8128 | } | |
8129 | ||
8130 | print_hex (begin + base_address, pointer_size); | |
8131 | print_hex_ns (end + base_address, pointer_size); | |
8132 | ||
8133 | if (begin == end) | |
8134 | fputs (_(" (start == end)"), stdout); | |
8135 | else if (begin > end) | |
8136 | fputs (_(" (start > end)"), stdout); | |
8137 | ||
8138 | putchar ('\n'); | |
8139 | } | |
8140 | ||
8141 | return start; | |
8142 | } | |
8143 | ||
8144 | static unsigned char * | |
8145 | display_debug_rnglists_list (unsigned char * start, | |
8146 | unsigned char * finish, | |
8147 | unsigned int pointer_size, | |
8148 | uint64_t offset, | |
8149 | uint64_t base_address, | |
8150 | uint64_t addr_base) | |
8151 | { | |
8152 | unsigned char *next = start; | |
8153 | ||
8154 | while (1) | |
8155 | { | |
8156 | uint64_t off = offset + (start - next); | |
8157 | enum dwarf_range_list_entry rlet; | |
8158 | /* Initialize it due to a false compiler warning. */ | |
8159 | uint64_t begin = -1, length, end = -1; | |
8160 | ||
8161 | if (start >= finish) | |
8162 | { | |
8163 | warn (_("Range list starting at offset %#" PRIx64 | |
8164 | " is not terminated.\n"), offset); | |
8165 | break; | |
8166 | } | |
8167 | ||
8168 | printf (" "); | |
8169 | print_hex (off, 4); | |
8170 | ||
8171 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
8172 | ||
8173 | switch (rlet) | |
8174 | { | |
8175 | case DW_RLE_end_of_list: | |
8176 | printf (_("<End of list>\n")); | |
8177 | break; | |
8178 | case DW_RLE_base_addressx: | |
8179 | READ_ULEB (base_address, start, finish); | |
8180 | print_hex (base_address, pointer_size); | |
8181 | printf (_("(base address index) ")); | |
8182 | base_address = fetch_indexed_addr (base_address * pointer_size + addr_base, | |
8183 | pointer_size); | |
8184 | print_hex (base_address, pointer_size); | |
8185 | printf (_("(base address)\n")); | |
8186 | break; | |
8187 | case DW_RLE_startx_endx: | |
8188 | READ_ULEB (begin, start, finish); | |
8189 | READ_ULEB (end, start, finish); | |
8190 | begin = fetch_indexed_addr (begin * pointer_size + addr_base, | |
8191 | pointer_size); | |
8192 | end = fetch_indexed_addr (end * pointer_size + addr_base, | |
8193 | pointer_size); | |
8194 | break; | |
8195 | case DW_RLE_startx_length: | |
8196 | READ_ULEB (begin, start, finish); | |
8197 | READ_ULEB (length, start, finish); | |
8198 | begin = fetch_indexed_addr (begin * pointer_size + addr_base, | |
8199 | pointer_size); | |
8200 | end = begin + length; | |
8201 | break; | |
8202 | case DW_RLE_offset_pair: | |
8203 | READ_ULEB (begin, start, finish); | |
8204 | READ_ULEB (end, start, finish); | |
8205 | break; | |
8206 | case DW_RLE_base_address: | |
8207 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
8208 | print_hex (base_address, pointer_size); | |
8209 | printf (_("(base address)\n")); | |
8210 | break; | |
8211 | case DW_RLE_start_end: | |
8212 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
8213 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
8214 | break; | |
8215 | case DW_RLE_start_length: | |
8216 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
8217 | READ_ULEB (length, start, finish); | |
8218 | end = begin + length; | |
8219 | break; | |
8220 | default: | |
8221 | error (_("Invalid range list entry type %d\n"), rlet); | |
8222 | rlet = DW_RLE_end_of_list; | |
8223 | break; | |
8224 | } | |
8225 | ||
8226 | if (rlet == DW_RLE_end_of_list) | |
8227 | break; | |
8228 | if (rlet == DW_RLE_base_address || rlet == DW_RLE_base_addressx) | |
8229 | continue; | |
8230 | ||
8231 | /* Only a DW_RLE_offset_pair needs the base address added. */ | |
8232 | if (rlet == DW_RLE_offset_pair) | |
8233 | { | |
8234 | begin += base_address; | |
8235 | end += base_address; | |
8236 | } | |
8237 | ||
8238 | print_hex (begin, pointer_size); | |
8239 | print_hex (end, pointer_size); | |
8240 | ||
8241 | if (begin == end) | |
8242 | fputs (_(" (start == end)"), stdout); | |
8243 | else if (begin > end) | |
8244 | fputs (_(" (start > end)"), stdout); | |
8245 | ||
8246 | putchar ('\n'); | |
8247 | } | |
8248 | ||
8249 | return start; | |
8250 | } | |
8251 | ||
8252 | static int | |
8253 | display_debug_rnglists_unit_header (struct dwarf_section * section, | |
8254 | uint64_t * unit_offset, | |
8255 | unsigned char * poffset_size) | |
8256 | { | |
8257 | uint64_t start_offset = *unit_offset; | |
8258 | unsigned char * p = section->start + start_offset; | |
8259 | unsigned char * finish = section->start + section->size; | |
8260 | uint64_t initial_length; | |
8261 | unsigned char segment_selector_size; | |
8262 | unsigned int offset_entry_count; | |
8263 | unsigned int i; | |
8264 | unsigned short version; | |
8265 | unsigned char address_size = 0; | |
8266 | unsigned char offset_size; | |
8267 | ||
8268 | /* Get and check the length of the block. */ | |
8269 | SAFE_BYTE_GET_AND_INC (initial_length, p, 4, finish); | |
8270 | ||
8271 | if (initial_length == 0xffffffff) | |
8272 | { | |
8273 | /* This section is 64-bit DWARF 3. */ | |
8274 | SAFE_BYTE_GET_AND_INC (initial_length, p, 8, finish); | |
8275 | *poffset_size = offset_size = 8; | |
8276 | } | |
8277 | else | |
8278 | *poffset_size = offset_size = 4; | |
8279 | ||
8280 | if (initial_length > (size_t) (finish - p)) | |
8281 | { | |
8282 | /* If the length field has a relocation against it, then we should | |
8283 | not complain if it is inaccurate (and probably negative). | |
8284 | It is copied from .debug_line handling code. */ | |
8285 | if (reloc_at (section, (p - section->start) - offset_size)) | |
8286 | initial_length = finish - p; | |
8287 | else | |
8288 | { | |
8289 | warn (_("The length field (%#" PRIx64 | |
8290 | ") in the debug_rnglists header is wrong" | |
8291 | " - the section is too small\n"), | |
8292 | initial_length); | |
8293 | return 0; | |
8294 | } | |
8295 | } | |
8296 | ||
8297 | /* Report the next unit offset to the caller. */ | |
8298 | *unit_offset = (p - section->start) + initial_length; | |
8299 | ||
8300 | /* Get the other fields in the header. */ | |
8301 | SAFE_BYTE_GET_AND_INC (version, p, 2, finish); | |
8302 | SAFE_BYTE_GET_AND_INC (address_size, p, 1, finish); | |
8303 | SAFE_BYTE_GET_AND_INC (segment_selector_size, p, 1, finish); | |
8304 | SAFE_BYTE_GET_AND_INC (offset_entry_count, p, 4, finish); | |
8305 | ||
8306 | printf (_(" Table at Offset: %#" PRIx64 ":\n"), start_offset); | |
8307 | printf (_(" Length: %#" PRIx64 "\n"), initial_length); | |
8308 | printf (_(" DWARF version: %u\n"), version); | |
8309 | printf (_(" Address size: %u\n"), address_size); | |
8310 | printf (_(" Segment size: %u\n"), segment_selector_size); | |
8311 | printf (_(" Offset entries: %u\n"), offset_entry_count); | |
8312 | ||
8313 | /* Check the fields. */ | |
8314 | if (segment_selector_size != 0) | |
8315 | { | |
8316 | warn (_("The %s section contains " | |
8317 | "unsupported segment selector size: %d.\n"), | |
8318 | section->name, segment_selector_size); | |
8319 | return 0; | |
8320 | } | |
8321 | ||
8322 | if (version < 5) | |
8323 | { | |
8324 | warn (_("Only DWARF version 5+ debug_rnglists info " | |
8325 | "is currently supported.\n")); | |
8326 | return 0; | |
8327 | } | |
8328 | ||
8329 | if (offset_entry_count != 0) | |
8330 | { | |
8331 | printf (_("\n Offsets starting at %#tx:\n"), p - section->start); | |
8332 | ||
8333 | for (i = 0; i < offset_entry_count; i++) | |
8334 | { | |
8335 | uint64_t entry; | |
8336 | ||
8337 | SAFE_BYTE_GET_AND_INC (entry, p, offset_size, finish); | |
8338 | printf (_(" [%6u] %#" PRIx64 "\n"), i, entry); | |
8339 | } | |
8340 | } | |
8341 | ||
8342 | return 1; | |
8343 | } | |
8344 | ||
8345 | static bool | |
8346 | is_range_list_for_this_section (bool is_rnglists, unsigned int version) | |
8347 | { | |
8348 | if (is_rnglists && version > 4) | |
8349 | return true; | |
8350 | ||
8351 | if (! is_rnglists && version < 5) | |
8352 | return true; | |
8353 | ||
8354 | return false; | |
8355 | } | |
8356 | ||
8357 | static int | |
8358 | display_debug_ranges (struct dwarf_section *section, | |
8359 | void *file ATTRIBUTE_UNUSED) | |
8360 | { | |
8361 | unsigned char *start = section->start; | |
8362 | unsigned char *last_start = start; | |
8363 | unsigned char *last_end; | |
8364 | uint64_t bytes = section->size; | |
8365 | unsigned char *section_begin = start; | |
8366 | unsigned char *finish = start + bytes; | |
8367 | unsigned int num_range_list, i; | |
8368 | struct range_entry *range_entries; | |
8369 | struct range_entry *range_entry_fill; | |
8370 | bool is_rnglists = strstr (section->name, "debug_rnglists") != NULL; | |
8371 | uint64_t last_offset = 0; | |
8372 | uint64_t next_rnglists_cu_offset = 0; | |
8373 | unsigned char offset_size; | |
8374 | ||
8375 | if (bytes == 0) | |
8376 | { | |
8377 | printf (_("\nThe %s section is empty.\n"), section->name); | |
8378 | return 0; | |
8379 | } | |
8380 | ||
8381 | introduce (section, false); | |
8382 | ||
8383 | if (load_debug_info (file) == 0) | |
8384 | { | |
8385 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
8386 | section->name); | |
8387 | return 0; | |
8388 | } | |
8389 | ||
8390 | num_range_list = 0; | |
8391 | for (i = 0; i < num_debug_info_entries; i++) | |
8392 | if (is_range_list_for_this_section (is_rnglists, debug_information [i].dwarf_version)) | |
8393 | num_range_list += debug_information [i].num_range_lists; | |
8394 | ||
8395 | if (num_range_list == 0) | |
8396 | { | |
8397 | /* This can happen when the file was compiled with -gsplit-debug | |
8398 | which removes references to range lists from the primary .o file. */ | |
8399 | printf (_("No range lists referenced by .debug_info section.\n")); | |
8400 | return 1; | |
8401 | } | |
8402 | ||
8403 | range_entry_fill = range_entries = XNEWVEC (struct range_entry, num_range_list); | |
8404 | ||
8405 | for (i = 0; i < num_debug_info_entries; i++) | |
8406 | { | |
8407 | debug_info *debug_info_p = &debug_information[i]; | |
8408 | unsigned int j; | |
8409 | ||
8410 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
8411 | { | |
8412 | if (is_range_list_for_this_section (is_rnglists, debug_info_p->dwarf_version)) | |
8413 | { | |
8414 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
8415 | range_entry_fill->debug_info_p = debug_info_p; | |
8416 | range_entry_fill++; | |
8417 | } | |
8418 | } | |
8419 | } | |
8420 | ||
8421 | assert (range_entry_fill >= range_entries); | |
8422 | assert (num_range_list >= (unsigned int)(range_entry_fill - range_entries)); | |
8423 | num_range_list = range_entry_fill - range_entries; | |
8424 | qsort (range_entries, num_range_list, sizeof (*range_entries), | |
8425 | range_entry_compar); | |
8426 | ||
8427 | putchar ('\n'); | |
8428 | if (!is_rnglists) | |
8429 | printf (_(" Offset Begin End\n")); | |
8430 | ||
8431 | last_end = NULL; | |
8432 | for (i = 0; i < num_range_list; i++) | |
8433 | { | |
8434 | struct range_entry *range_entry = &range_entries[i]; | |
8435 | debug_info *debug_info_p = range_entry->debug_info_p; | |
8436 | unsigned int pointer_size; | |
8437 | uint64_t offset; | |
8438 | unsigned char *next; | |
8439 | uint64_t base_address; | |
8440 | ||
8441 | pointer_size = debug_info_p->pointer_size; | |
8442 | offset = range_entry->ranges_offset; | |
8443 | base_address = debug_info_p->base_address; | |
8444 | ||
8445 | /* PR 17512: file: 001-101485-0.001:0.1. */ | |
8446 | if (pointer_size < 2 || pointer_size > 8) | |
8447 | { | |
8448 | warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64 "\n"), | |
8449 | pointer_size, offset); | |
8450 | continue; | |
8451 | } | |
8452 | ||
8453 | if (offset > (size_t) (finish - section_begin)) | |
8454 | { | |
8455 | warn (_("Corrupt offset (%#" PRIx64 ") in range entry %u\n"), | |
8456 | offset, i); | |
8457 | continue; | |
8458 | } | |
8459 | ||
8460 | /* If we've moved on to the next compile unit in the rnglists section - dump the unit header(s). */ | |
8461 | if (is_rnglists && next_rnglists_cu_offset < offset) | |
8462 | { | |
8463 | while (next_rnglists_cu_offset < offset) | |
8464 | display_debug_rnglists_unit_header (section, &next_rnglists_cu_offset, &offset_size); | |
8465 | printf (_(" Offset Begin End\n")); | |
8466 | } | |
8467 | ||
8468 | next = section_begin + offset; /* Offset is from the section start, the base has already been added. */ | |
8469 | ||
8470 | if (i == 0) | |
8471 | { | |
8472 | last_end = section_begin; | |
8473 | if (is_rnglists) | |
8474 | last_end += 2 * offset_size - 4 + 2 + 1 + 1 + 4; | |
8475 | } | |
8476 | /* If multiple DWARF entities reference the same range then we will | |
8477 | have multiple entries in the `range_entries' list for the same | |
8478 | offset. Thanks to the sort above these will all be consecutive in | |
8479 | the `range_entries' list, so we can easily ignore duplicates | |
8480 | here. */ | |
8481 | if (i > 0 && last_offset == offset) | |
8482 | continue; | |
8483 | last_offset = offset; | |
8484 | ||
8485 | if (dwarf_check != 0) | |
8486 | { | |
8487 | if (start < next) | |
8488 | { | |
8489 | if (last_end != next) | |
8490 | warn (_("There is a hole [%#tx - %#tx] in %s section.\n"), | |
8491 | last_end - section_begin, next - section_begin, | |
8492 | section->name); | |
8493 | } | |
8494 | else if (start > next) | |
8495 | { | |
8496 | if (next == last_start) | |
8497 | continue; | |
8498 | warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"), | |
8499 | start - section_begin, next - section_begin, section->name); | |
8500 | } | |
8501 | } | |
8502 | ||
8503 | start = next; | |
8504 | last_start = next; | |
8505 | ||
8506 | if (is_rnglists) | |
8507 | last_end | |
8508 | = display_debug_rnglists_list | |
8509 | (start, finish, pointer_size, offset, base_address, | |
8510 | debug_info_p->addr_base); | |
8511 | else | |
8512 | last_end | |
8513 | = display_debug_ranges_list | |
8514 | (start, finish, pointer_size, offset, base_address); | |
8515 | } | |
8516 | ||
8517 | /* Display trailing empty (or unreferenced) compile units, if any. */ | |
8518 | if (is_rnglists) | |
8519 | while (next_rnglists_cu_offset < section->size) | |
8520 | display_debug_rnglists_unit_header (section, &next_rnglists_cu_offset, &offset_size); | |
8521 | ||
8522 | putchar ('\n'); | |
8523 | ||
8524 | free (range_entries); | |
8525 | ||
8526 | return 1; | |
8527 | } | |
8528 | ||
8529 | typedef struct Frame_Chunk | |
8530 | { | |
8531 | struct Frame_Chunk *next; | |
8532 | unsigned char *chunk_start; | |
8533 | unsigned int ncols; | |
8534 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ | |
8535 | short int *col_type; | |
8536 | int64_t *col_offset; | |
8537 | char *augmentation; | |
8538 | unsigned int code_factor; | |
8539 | int data_factor; | |
8540 | uint64_t pc_begin; | |
8541 | uint64_t pc_range; | |
8542 | unsigned int cfa_reg; | |
8543 | uint64_t cfa_offset; | |
8544 | unsigned int ra; | |
8545 | unsigned char fde_encoding; | |
8546 | unsigned char cfa_exp; | |
8547 | unsigned char ptr_size; | |
8548 | unsigned char segment_size; | |
8549 | } | |
8550 | Frame_Chunk; | |
8551 | ||
8552 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); | |
8553 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
8554 | static const char *const *dwarf_regnames; | |
8555 | static unsigned int dwarf_regnames_count; | |
8556 | static bool is_aarch64; | |
8557 | ||
8558 | /* A marker for a col_type that means this column was never referenced | |
8559 | in the frame info. */ | |
8560 | #define DW_CFA_unreferenced (-1) | |
8561 | ||
8562 | /* Return 0 if no more space is needed, 1 if more space is needed, | |
8563 | -1 for invalid reg. */ | |
8564 | ||
8565 | static int | |
8566 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
8567 | { | |
8568 | unsigned int prev = fc->ncols; | |
8569 | ||
8570 | if (reg < (unsigned int) fc->ncols) | |
8571 | return 0; | |
8572 | ||
8573 | if (dwarf_regnames_count > 0 | |
8574 | && reg > dwarf_regnames_count) | |
8575 | return -1; | |
8576 | ||
8577 | fc->ncols = reg + 1; | |
8578 | /* PR 17512: file: 10450-2643-0.004. | |
8579 | If reg == -1 then this can happen... */ | |
8580 | if (fc->ncols == 0) | |
8581 | return -1; | |
8582 | ||
8583 | /* PR 17512: file: 2844a11d. */ | |
8584 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) | |
8585 | { | |
8586 | error (_("Unfeasibly large register number: %u\n"), reg); | |
8587 | fc->ncols = 0; | |
8588 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
8589 | we ever encounter a valid binary that exceeds it. */ | |
8590 | return -1; | |
8591 | } | |
8592 | ||
8593 | fc->col_type = xcrealloc (fc->col_type, fc->ncols, | |
8594 | sizeof (*fc->col_type)); | |
8595 | fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, | |
8596 | sizeof (*fc->col_offset)); | |
8597 | /* PR 17512: file:002-10025-0.005. */ | |
8598 | if (fc->col_type == NULL || fc->col_offset == NULL) | |
8599 | { | |
8600 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
8601 | fc->ncols); | |
8602 | fc->ncols = 0; | |
8603 | return -1; | |
8604 | } | |
8605 | ||
8606 | while (prev < fc->ncols) | |
8607 | { | |
8608 | fc->col_type[prev] = DW_CFA_unreferenced; | |
8609 | fc->col_offset[prev] = 0; | |
8610 | prev++; | |
8611 | } | |
8612 | return 1; | |
8613 | } | |
8614 | ||
8615 | static const char *const dwarf_regnames_i386[] = | |
8616 | { | |
8617 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
8618 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
8619 | "eip", "eflags", NULL, /* 8 - 10 */ | |
8620 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
8621 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
8622 | NULL, NULL, /* 19 - 20 */ | |
8623 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
8624 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
8625 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
8626 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
8627 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
8628 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
8629 | "tr", "ldtr", /* 48 - 49 */ | |
8630 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
8631 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
8632 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
8633 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
8634 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
8635 | NULL, NULL, NULL, /* 90 - 92 */ | |
8636 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
8637 | }; | |
8638 | ||
8639 | static const char *const dwarf_regnames_iamcu[] = | |
8640 | { | |
8641 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
8642 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
8643 | "eip", "eflags", NULL, /* 8 - 10 */ | |
8644 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
8645 | NULL, NULL, /* 19 - 20 */ | |
8646 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
8647 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
8648 | NULL, NULL, NULL, /* 37 - 39 */ | |
8649 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
8650 | "tr", "ldtr", /* 48 - 49 */ | |
8651 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
8652 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
8653 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
8654 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
8655 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
8656 | NULL, NULL, NULL, /* 90 - 92 */ | |
8657 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
8658 | }; | |
8659 | ||
8660 | static void | |
8661 | init_dwarf_regnames_i386 (void) | |
8662 | { | |
8663 | dwarf_regnames = dwarf_regnames_i386; | |
8664 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
8665 | dwarf_regnames_lookup_func = regname_internal_by_table_only; | |
8666 | } | |
8667 | ||
8668 | static void | |
8669 | init_dwarf_regnames_iamcu (void) | |
8670 | { | |
8671 | dwarf_regnames = dwarf_regnames_iamcu; | |
8672 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
8673 | dwarf_regnames_lookup_func = regname_internal_by_table_only; | |
8674 | } | |
8675 | ||
8676 | static const char *const DW_CFA_GNU_window_save_name[] = | |
8677 | { | |
8678 | "DW_CFA_GNU_window_save", | |
8679 | "DW_CFA_AARCH64_negate_ra_state" | |
8680 | }; | |
8681 | ||
8682 | static const char *const dwarf_regnames_x86_64[] = | |
8683 | { | |
8684 | "rax", "rdx", "rcx", "rbx", | |
8685 | "rsi", "rdi", "rbp", "rsp", | |
8686 | "r8", "r9", "r10", "r11", | |
8687 | "r12", "r13", "r14", "r15", | |
8688 | "rip", | |
8689 | "xmm0", "xmm1", "xmm2", "xmm3", | |
8690 | "xmm4", "xmm5", "xmm6", "xmm7", | |
8691 | "xmm8", "xmm9", "xmm10", "xmm11", | |
8692 | "xmm12", "xmm13", "xmm14", "xmm15", | |
8693 | "st0", "st1", "st2", "st3", | |
8694 | "st4", "st5", "st6", "st7", | |
8695 | "mm0", "mm1", "mm2", "mm3", | |
8696 | "mm4", "mm5", "mm6", "mm7", | |
8697 | "rflags", | |
8698 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
8699 | "fs.base", "gs.base", NULL, NULL, | |
8700 | "tr", "ldtr", | |
8701 | "mxcsr", "fcw", "fsw", | |
8702 | "xmm16", "xmm17", "xmm18", "xmm19", | |
8703 | "xmm20", "xmm21", "xmm22", "xmm23", | |
8704 | "xmm24", "xmm25", "xmm26", "xmm27", | |
8705 | "xmm28", "xmm29", "xmm30", "xmm31", | |
8706 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
8707 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
8708 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
8709 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
8710 | NULL, NULL, NULL, /* 115 - 117 */ | |
8711 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7", | |
8712 | "bnd0", "bnd1", "bnd2", "bnd3", | |
8713 | }; | |
8714 | ||
8715 | static void | |
8716 | init_dwarf_regnames_x86_64 (void) | |
8717 | { | |
8718 | dwarf_regnames = dwarf_regnames_x86_64; | |
8719 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
8720 | dwarf_regnames_lookup_func = regname_internal_by_table_only; | |
8721 | } | |
8722 | ||
8723 | static const char *const dwarf_regnames_aarch64[] = | |
8724 | { | |
8725 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", | |
8726 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
8727 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", | |
8728 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
8729 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
8730 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", | |
8731 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
8732 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
8733 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", | |
8734 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
8735 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", | |
8736 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
8737 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", | |
8738 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
8739 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
8740 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
8741 | }; | |
8742 | ||
8743 | static void | |
8744 | init_dwarf_regnames_aarch64 (void) | |
8745 | { | |
8746 | dwarf_regnames = dwarf_regnames_aarch64; | |
8747 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
8748 | dwarf_regnames_lookup_func = regname_internal_by_table_only; | |
8749 | is_aarch64 = true; | |
8750 | } | |
8751 | ||
8752 | static const char *const dwarf_regnames_s390[] = | |
8753 | { | |
8754 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
8755 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8756 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8757 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
8758 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
8759 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
8760 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
8761 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
8762 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
8763 | "pswm", "pswa", | |
8764 | NULL, NULL, | |
8765 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
8766 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
8767 | }; | |
8768 | ||
8769 | static void | |
8770 | init_dwarf_regnames_s390 (void) | |
8771 | { | |
8772 | dwarf_regnames = dwarf_regnames_s390; | |
8773 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
8774 | dwarf_regnames_lookup_func = regname_internal_by_table_only; | |
8775 | } | |
8776 | ||
8777 | static const char *const dwarf_regnames_riscv[] = | |
8778 | { | |
8779 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
8780 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
8781 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
8782 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
8783 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
8784 | "fs0", "fs1", /* 40 - 41 */ | |
8785 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
8786 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
8787 | "fs10", "fs11", /* 58 - 59 */ | |
8788 | "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */ | |
8789 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 64 - 71 */ | |
8790 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 72 - 79 */ | |
8791 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 80 - 87 */ | |
8792 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 88 - 95 */ | |
8793 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */ | |
8794 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */ | |
8795 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */ | |
8796 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */ | |
8797 | }; | |
8798 | ||
8799 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles | |
8800 | the large number of CSRs. */ | |
8801 | ||
8802 | static const char * | |
8803 | regname_internal_riscv (unsigned int regno) | |
8804 | { | |
8805 | const char *name = NULL; | |
8806 | ||
8807 | /* Lookup in the table first, this covers GPR and FPR. */ | |
8808 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
8809 | name = dwarf_regnames_riscv [regno]; | |
8810 | else if (regno >= 4096 && regno <= 8191) | |
8811 | { | |
8812 | /* This might be a CSR, these live in a sparse number space from 4096 | |
8813 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
8814 | document. */ | |
8815 | switch (regno) | |
8816 | { | |
8817 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ | |
8818 | case VALUE + 4096: name = #NAME; break; | |
8819 | #include "opcode/riscv-opc.h" | |
8820 | #undef DECLARE_CSR | |
8821 | ||
8822 | default: | |
8823 | { | |
8824 | static char csr_name[10]; | |
8825 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
8826 | name = csr_name; | |
8827 | } | |
8828 | break; | |
8829 | } | |
8830 | } | |
8831 | ||
8832 | return name; | |
8833 | } | |
8834 | ||
8835 | static void | |
8836 | init_dwarf_regnames_riscv (void) | |
8837 | { | |
8838 | dwarf_regnames = NULL; | |
8839 | dwarf_regnames_count = 8192; | |
8840 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
8841 | } | |
8842 | ||
8843 | static const char *const dwarf_regnames_loongarch[] = | |
8844 | { | |
8845 | "$zero", "$ra", "$tp", "$sp", "$a0", "$a1", "$a2", "$a3", /* 0-7 */ | |
8846 | "$a4", "$a5", "$a6", "$a7", "$t0", "$t1", "$t2", "$t3", /* 8-15 */ | |
8847 | "$t4", "$t5", "$t6", "$t7", "$t8", "$r21","$fp", "$s0", /* 16-23 */ | |
8848 | "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7", "$s8", /* 24-31 */ | |
8849 | "$fa0", "$fa1", "$fa2", "$fa3", "$fa4", "$fa5", "$fa6", /* 32-38 */ | |
8850 | "$fa7", "$ft0", "$ft1", "$ft2", "$ft3", "$ft4", "$ft5", /* 39-45 */ | |
8851 | "$ft6", "$ft7", "$ft8", "$ft9", "$ft10", "$ft11", "$ft12", /* 46-52 */ | |
8852 | "$ft13", "$ft14", "$ft15", "$fs0", "$fs1", "$fs2", "$fs3", /* 53-59 */ | |
8853 | "$fs4", "$fs5", "$fs6", "$fs7", /* 60-63 */ | |
8854 | }; | |
8855 | ||
8856 | static void | |
8857 | init_dwarf_regnames_loongarch (void) | |
8858 | { | |
8859 | dwarf_regnames = dwarf_regnames_loongarch; | |
8860 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_loongarch); | |
8861 | dwarf_regnames_lookup_func = regname_internal_by_table_only; | |
8862 | } | |
8863 | ||
8864 | void | |
8865 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) | |
8866 | { | |
8867 | dwarf_regnames_lookup_func = NULL; | |
8868 | is_aarch64 = false; | |
8869 | ||
8870 | switch (e_machine) | |
8871 | { | |
8872 | case EM_386: | |
8873 | init_dwarf_regnames_i386 (); | |
8874 | break; | |
8875 | ||
8876 | case EM_IAMCU: | |
8877 | init_dwarf_regnames_iamcu (); | |
8878 | break; | |
8879 | ||
8880 | case EM_X86_64: | |
8881 | case EM_L1OM: | |
8882 | case EM_K1OM: | |
8883 | init_dwarf_regnames_x86_64 (); | |
8884 | break; | |
8885 | ||
8886 | case EM_AARCH64: | |
8887 | init_dwarf_regnames_aarch64 (); | |
8888 | break; | |
8889 | ||
8890 | case EM_S390: | |
8891 | init_dwarf_regnames_s390 (); | |
8892 | break; | |
8893 | ||
8894 | case EM_RISCV: | |
8895 | init_dwarf_regnames_riscv (); | |
8896 | break; | |
8897 | ||
8898 | case EM_LOONGARCH: | |
8899 | init_dwarf_regnames_loongarch (); | |
8900 | break; | |
8901 | ||
8902 | default: | |
8903 | break; | |
8904 | } | |
8905 | } | |
8906 | ||
8907 | /* Initialize the DWARF register name lookup state based on the | |
8908 | architecture and specific machine type of a BFD. */ | |
8909 | ||
8910 | void | |
8911 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
8912 | unsigned long mach) | |
8913 | { | |
8914 | dwarf_regnames_lookup_func = NULL; | |
8915 | is_aarch64 = false; | |
8916 | ||
8917 | switch (arch) | |
8918 | { | |
8919 | case bfd_arch_i386: | |
8920 | switch (mach) | |
8921 | { | |
8922 | case bfd_mach_x86_64: | |
8923 | case bfd_mach_x86_64_intel_syntax: | |
8924 | case bfd_mach_x64_32: | |
8925 | case bfd_mach_x64_32_intel_syntax: | |
8926 | init_dwarf_regnames_x86_64 (); | |
8927 | break; | |
8928 | ||
8929 | default: | |
8930 | init_dwarf_regnames_i386 (); | |
8931 | break; | |
8932 | } | |
8933 | break; | |
8934 | ||
8935 | case bfd_arch_iamcu: | |
8936 | init_dwarf_regnames_iamcu (); | |
8937 | break; | |
8938 | ||
8939 | case bfd_arch_aarch64: | |
8940 | init_dwarf_regnames_aarch64(); | |
8941 | break; | |
8942 | ||
8943 | case bfd_arch_s390: | |
8944 | init_dwarf_regnames_s390 (); | |
8945 | break; | |
8946 | ||
8947 | case bfd_arch_riscv: | |
8948 | init_dwarf_regnames_riscv (); | |
8949 | break; | |
8950 | ||
8951 | case bfd_arch_loongarch: | |
8952 | init_dwarf_regnames_loongarch (); | |
8953 | break; | |
8954 | ||
8955 | default: | |
8956 | break; | |
8957 | } | |
8958 | } | |
8959 | ||
8960 | static const char * | |
8961 | regname_internal_by_table_only (unsigned int regno) | |
8962 | { | |
8963 | if (dwarf_regnames != NULL | |
8964 | && regno < dwarf_regnames_count | |
8965 | && dwarf_regnames [regno] != NULL) | |
8966 | return dwarf_regnames [regno]; | |
8967 | ||
8968 | return NULL; | |
8969 | } | |
8970 | ||
8971 | static const char * | |
8972 | regname (unsigned int regno, int name_only_p) | |
8973 | { | |
8974 | static char reg[64]; | |
8975 | ||
8976 | const char *name = NULL; | |
8977 | ||
8978 | if (dwarf_regnames_lookup_func != NULL) | |
8979 | name = dwarf_regnames_lookup_func (regno); | |
8980 | ||
8981 | if (name != NULL) | |
8982 | { | |
8983 | if (name_only_p) | |
8984 | return name; | |
8985 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
8986 | } | |
8987 | else | |
8988 | snprintf (reg, sizeof (reg), "r%d", regno); | |
8989 | return reg; | |
8990 | } | |
8991 | ||
8992 | static void | |
8993 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) | |
8994 | { | |
8995 | unsigned int r; | |
8996 | char tmp[100]; | |
8997 | ||
8998 | if (*max_regs != fc->ncols) | |
8999 | *max_regs = fc->ncols; | |
9000 | ||
9001 | if (*need_col_headers) | |
9002 | { | |
9003 | *need_col_headers = 0; | |
9004 | ||
9005 | printf ("%-*s CFA ", eh_addr_size * 2, " LOC"); | |
9006 | ||
9007 | for (r = 0; r < *max_regs; r++) | |
9008 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
9009 | { | |
9010 | if (r == fc->ra) | |
9011 | printf ("ra "); | |
9012 | else | |
9013 | printf ("%-5s ", regname (r, 1)); | |
9014 | } | |
9015 | ||
9016 | printf ("\n"); | |
9017 | } | |
9018 | ||
9019 | print_hex (fc->pc_begin, eh_addr_size); | |
9020 | if (fc->cfa_exp) | |
9021 | strcpy (tmp, "exp"); | |
9022 | else | |
9023 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); | |
9024 | printf ("%-8s ", tmp); | |
9025 | ||
9026 | for (r = 0; r < fc->ncols; r++) | |
9027 | { | |
9028 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
9029 | { | |
9030 | switch (fc->col_type[r]) | |
9031 | { | |
9032 | case DW_CFA_undefined: | |
9033 | strcpy (tmp, "u"); | |
9034 | break; | |
9035 | case DW_CFA_same_value: | |
9036 | strcpy (tmp, "s"); | |
9037 | break; | |
9038 | case DW_CFA_offset: | |
9039 | sprintf (tmp, "c%+" PRId64, fc->col_offset[r]); | |
9040 | break; | |
9041 | case DW_CFA_val_offset: | |
9042 | sprintf (tmp, "v%+" PRId64, fc->col_offset[r]); | |
9043 | break; | |
9044 | case DW_CFA_register: | |
9045 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); | |
9046 | break; | |
9047 | case DW_CFA_expression: | |
9048 | strcpy (tmp, "exp"); | |
9049 | break; | |
9050 | case DW_CFA_val_expression: | |
9051 | strcpy (tmp, "vexp"); | |
9052 | break; | |
9053 | default: | |
9054 | strcpy (tmp, "n/a"); | |
9055 | break; | |
9056 | } | |
9057 | printf ("%-5s ", tmp); | |
9058 | } | |
9059 | } | |
9060 | printf ("\n"); | |
9061 | } | |
9062 | ||
9063 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) | |
9064 | ||
9065 | static unsigned char * | |
9066 | read_cie (unsigned char *start, unsigned char *end, | |
9067 | Frame_Chunk **p_cie, int *p_version, | |
9068 | uint64_t *p_aug_len, unsigned char **p_aug) | |
9069 | { | |
9070 | int version; | |
9071 | Frame_Chunk *fc; | |
9072 | unsigned char *augmentation_data = NULL; | |
9073 | uint64_t augmentation_data_len = 0; | |
9074 | ||
9075 | * p_cie = NULL; | |
9076 | /* PR 17512: file: 001-228113-0.004. */ | |
9077 | if (start >= end) | |
9078 | return end; | |
9079 | ||
9080 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); | |
9081 | memset (fc, 0, sizeof (Frame_Chunk)); | |
9082 | ||
9083 | fc->col_type = xmalloc (sizeof (*fc->col_type)); | |
9084 | fc->col_offset = xmalloc (sizeof (*fc->col_offset)); | |
9085 | ||
9086 | version = *start++; | |
9087 | ||
9088 | fc->augmentation = (char *) start; | |
9089 | /* PR 17512: file: 001-228113-0.004. | |
9090 | Skip past augmentation name, but avoid running off the end of the data. */ | |
9091 | while (start < end) | |
9092 | if (* start ++ == '\0') | |
9093 | break; | |
9094 | if (start == end) | |
9095 | { | |
9096 | warn (_("No terminator for augmentation name\n")); | |
9097 | goto fail; | |
9098 | } | |
9099 | ||
9100 | if (strcmp (fc->augmentation, "eh") == 0) | |
9101 | { | |
9102 | if (eh_addr_size > (size_t) (end - start)) | |
9103 | goto fail; | |
9104 | start += eh_addr_size; | |
9105 | } | |
9106 | ||
9107 | if (version >= 4) | |
9108 | { | |
9109 | if (2 > (size_t) (end - start)) | |
9110 | goto fail; | |
9111 | GET (fc->ptr_size, 1); | |
9112 | if (fc->ptr_size < 1 || fc->ptr_size > 8) | |
9113 | { | |
9114 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
9115 | goto fail; | |
9116 | } | |
9117 | ||
9118 | GET (fc->segment_size, 1); | |
9119 | /* PR 17512: file: e99d2804. */ | |
9120 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
9121 | { | |
9122 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
9123 | goto fail; | |
9124 | } | |
9125 | ||
9126 | eh_addr_size = fc->ptr_size; | |
9127 | } | |
9128 | else | |
9129 | { | |
9130 | fc->ptr_size = eh_addr_size; | |
9131 | fc->segment_size = 0; | |
9132 | } | |
9133 | ||
9134 | READ_ULEB (fc->code_factor, start, end); | |
9135 | READ_SLEB (fc->data_factor, start, end); | |
9136 | ||
9137 | if (start >= end) | |
9138 | goto fail; | |
9139 | ||
9140 | if (version == 1) | |
9141 | { | |
9142 | GET (fc->ra, 1); | |
9143 | } | |
9144 | else | |
9145 | { | |
9146 | READ_ULEB (fc->ra, start, end); | |
9147 | } | |
9148 | ||
9149 | if (fc->augmentation[0] == 'z') | |
9150 | { | |
9151 | if (start >= end) | |
9152 | goto fail; | |
9153 | READ_ULEB (augmentation_data_len, start, end); | |
9154 | augmentation_data = start; | |
9155 | /* PR 17512: file: 11042-2589-0.004. */ | |
9156 | if (augmentation_data_len > (size_t) (end - start)) | |
9157 | { | |
9158 | warn (_("Augmentation data too long: %#" PRIx64 | |
9159 | ", expected at most %#tx\n"), | |
9160 | augmentation_data_len, end - start); | |
9161 | goto fail; | |
9162 | } | |
9163 | start += augmentation_data_len; | |
9164 | } | |
9165 | ||
9166 | if (augmentation_data_len) | |
9167 | { | |
9168 | unsigned char *p; | |
9169 | unsigned char *q; | |
9170 | unsigned char *qend; | |
9171 | ||
9172 | p = (unsigned char *) fc->augmentation + 1; | |
9173 | q = augmentation_data; | |
9174 | qend = q + augmentation_data_len; | |
9175 | ||
9176 | while (p < end && q < qend) | |
9177 | { | |
9178 | if (*p == 'L') | |
9179 | q++; | |
9180 | else if (*p == 'P') | |
9181 | q += 1 + size_of_encoded_value (*q); | |
9182 | else if (*p == 'R') | |
9183 | fc->fde_encoding = *q++; | |
9184 | else if (*p == 'S') | |
9185 | ; | |
9186 | else if (*p == 'B') | |
9187 | ; | |
9188 | else | |
9189 | break; | |
9190 | p++; | |
9191 | } | |
9192 | /* Note - it is OK if this loop terminates with q < qend. | |
9193 | Padding may have been inserted to align the end of the CIE. */ | |
9194 | } | |
9195 | ||
9196 | *p_cie = fc; | |
9197 | if (p_version) | |
9198 | *p_version = version; | |
9199 | if (p_aug_len) | |
9200 | { | |
9201 | *p_aug_len = augmentation_data_len; | |
9202 | *p_aug = augmentation_data; | |
9203 | } | |
9204 | return start; | |
9205 | ||
9206 | fail: | |
9207 | free (fc->col_offset); | |
9208 | free (fc->col_type); | |
9209 | free (fc); | |
9210 | return end; | |
9211 | } | |
9212 | ||
9213 | /* Prints out the contents on the DATA array formatted as unsigned bytes. | |
9214 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
9215 | PRINTED contains the number of characters already written to the current | |
9216 | output line. */ | |
9217 | ||
9218 | static void | |
9219 | display_data (size_t printed, const unsigned char *data, size_t len) | |
9220 | { | |
9221 | if (do_wide || len < ((80 - printed) / 3)) | |
9222 | for (printed = 0; printed < len; ++printed) | |
9223 | printf (" %02x", data[printed]); | |
9224 | else | |
9225 | { | |
9226 | for (printed = 0; printed < len; ++printed) | |
9227 | { | |
9228 | if (printed % (80 / 3) == 0) | |
9229 | putchar ('\n'); | |
9230 | printf (" %02x", data[printed]); | |
9231 | } | |
9232 | } | |
9233 | } | |
9234 | ||
9235 | /* Prints out the contents on the augmentation data array. | |
9236 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
9237 | ||
9238 | static void | |
9239 | display_augmentation_data (const unsigned char * data, uint64_t len) | |
9240 | { | |
9241 | size_t i; | |
9242 | ||
9243 | i = printf (_(" Augmentation data: ")); | |
9244 | display_data (i, data, len); | |
9245 | } | |
9246 | ||
9247 | static const char * | |
9248 | decode_eh_encoding (unsigned int value) | |
9249 | { | |
9250 | if (value == DW_EH_PE_omit) | |
9251 | return "omit"; | |
9252 | ||
9253 | char * format; | |
9254 | switch (value & 0x0f) | |
9255 | { | |
9256 | case DW_EH_PE_uleb128: format = "uleb128"; break; | |
9257 | case DW_EH_PE_udata2: format = "udata2"; break; | |
9258 | case DW_EH_PE_udata4: format = "udata4"; break; | |
9259 | case DW_EH_PE_udata8: format = "udata8"; break; | |
9260 | case DW_EH_PE_sleb128: format = "sleb128"; break; | |
9261 | case DW_EH_PE_sdata2: format = "sdata2"; break; | |
9262 | case DW_EH_PE_sdata4: format = "sdata4"; break; | |
9263 | case DW_EH_PE_sdata8: format = "sdata8"; break; | |
9264 | ||
9265 | default: format = "<unknown format>"; break; /* FIXME: Generate a warning ? */ | |
9266 | } | |
9267 | ||
9268 | char * application; | |
9269 | switch (value & 0xf0) | |
9270 | { | |
9271 | case DW_EH_PE_absptr: application = "absolute"; break; | |
9272 | case DW_EH_PE_pcrel: application = "pcrel"; break; | |
9273 | case DW_EH_PE_textrel: application = "textrel"; break; /* FIXME: Is this allowed ? */ | |
9274 | case DW_EH_PE_datarel: application = "datarel"; break; | |
9275 | case DW_EH_PE_funcrel: application = "funcrel"; break; /* FIXME: Is this allowed ? */ | |
9276 | case DW_EH_PE_aligned: application = "aligned"; break; /* FIXME: Is this allowed ? */ | |
9277 | case DW_EH_PE_indirect: application = "indirect"; break; /* FIXME: Is this allowed ? */ | |
9278 | ||
9279 | default: application = "<unknown application method>"; break; /* FIXME: Generate a warning ? */ | |
9280 | } | |
9281 | ||
9282 | static char buffer[128]; | |
9283 | sprintf (buffer, "%s, %s", format, application); | |
9284 | return buffer; | |
9285 | } | |
9286 | ||
9287 | /* Reads a value stored at START encoded according to ENCODING. | |
9288 | Does not read from, or past, END. | |
9289 | Upon success, returns the read value and sets * RETURN_LEN to | |
9290 | the number of bytes read. | |
9291 | Upon failure returns zero and sets * RETURN_LEN to 0. | |
9292 | ||
9293 | Note: does not perform any application transformations to the value. */ | |
9294 | ||
9295 | static uint64_t | |
9296 | get_encoded_eh_value (unsigned int encoding, | |
9297 | unsigned char * start, | |
9298 | unsigned char * end, | |
9299 | unsigned int * return_len) | |
9300 | { | |
9301 | uint64_t val; | |
9302 | unsigned int len; | |
9303 | int status; | |
9304 | unsigned char * old_start; | |
9305 | ||
9306 | switch (encoding & 0x0f) | |
9307 | { | |
9308 | case DW_EH_PE_uleb128: | |
9309 | val = read_leb128 (start, end, false, & len, & status); | |
9310 | if (status != 0) | |
9311 | len = 0; | |
9312 | break; | |
9313 | ||
9314 | case DW_EH_PE_sleb128: | |
9315 | val = read_leb128 (start, end, true, & len, & status); | |
9316 | if (status != 0) | |
9317 | len = 0; | |
9318 | break; | |
9319 | ||
9320 | case DW_EH_PE_udata2: | |
9321 | old_start = start; | |
9322 | SAFE_BYTE_GET_AND_INC (val, start, 2, end); | |
9323 | len = start - old_start == 2 ? 2 : 0; | |
9324 | break; | |
9325 | ||
9326 | case DW_EH_PE_udata4: | |
9327 | old_start = start; | |
9328 | SAFE_BYTE_GET_AND_INC (val, start, 4, end); | |
9329 | len = start - old_start == 4 ? 4 : 0; | |
9330 | break; | |
9331 | ||
9332 | case DW_EH_PE_udata8: | |
9333 | old_start = start; | |
9334 | SAFE_BYTE_GET_AND_INC (val, start, 8, end); | |
9335 | len = start - old_start == 8 ? 8 : 0; | |
9336 | break; | |
9337 | ||
9338 | case DW_EH_PE_sdata2: | |
9339 | old_start = start; | |
9340 | SAFE_SIGNED_BYTE_GET_AND_INC (val, start, 2, end); | |
9341 | len = start - old_start == 2 ? 2 : 0; | |
9342 | break; | |
9343 | ||
9344 | case DW_EH_PE_sdata4: | |
9345 | old_start = start; | |
9346 | SAFE_SIGNED_BYTE_GET_AND_INC (val, start, 4, end); | |
9347 | len = start - old_start == 4 ? 4 : 0; | |
9348 | break; | |
9349 | ||
9350 | case DW_EH_PE_sdata8: | |
9351 | old_start = start; | |
9352 | SAFE_SIGNED_BYTE_GET_AND_INC (val, start, 8, end); | |
9353 | len = start - old_start == 8 ? 8 : 0; | |
9354 | break; | |
9355 | ||
9356 | default: | |
9357 | goto fail; | |
9358 | } | |
9359 | ||
9360 | * return_len = len; | |
9361 | return val; | |
9362 | ||
9363 | fail: | |
9364 | * return_len = 0; | |
9365 | return 0; | |
9366 | } | |
9367 | ||
9368 | static uint64_t | |
9369 | encoded_eh_offset (unsigned int encoding, | |
9370 | struct dwarf_section * section, | |
9371 | uint64_t section_offset, | |
9372 | uint64_t value) | |
9373 | { | |
9374 | switch (encoding & 0xf0) | |
9375 | { | |
9376 | default: | |
9377 | /* This should not happen. FIXME: warn ? */ | |
9378 | case DW_EH_PE_absptr: | |
9379 | return value; | |
9380 | ||
9381 | case DW_EH_PE_pcrel: | |
9382 | return value + (uint64_t)(section->address + section_offset); | |
9383 | ||
9384 | case DW_EH_PE_datarel: | |
9385 | return value + (uint64_t)section->address; | |
9386 | } | |
9387 | } | |
9388 | ||
9389 | static int | |
9390 | display_eh_frame_hdr (struct dwarf_section *section, | |
9391 | void *file ATTRIBUTE_UNUSED) | |
9392 | { | |
9393 | unsigned char *start = section->start; | |
9394 | unsigned char *end = start + section->size; | |
9395 | ||
9396 | introduce (section, false); | |
9397 | ||
9398 | if (section->size < 6) | |
9399 | { | |
9400 | warn (_(".eh_frame_hdr section is too small\n")); | |
9401 | return 0; | |
9402 | } | |
9403 | ||
9404 | unsigned int version = start[0]; | |
9405 | if (version != 1) | |
9406 | { | |
9407 | warn (_("Unsupported .eh_frame_hdr version %u\n"), version); | |
9408 | return 0; | |
9409 | } | |
9410 | ||
9411 | printf (_(" Version: %u\n"), version); | |
9412 | ||
9413 | unsigned int ptr_enc = start[1]; | |
9414 | /* Strictly speaking this is the encoding format of the eh_frame_ptr field below. */ | |
9415 | printf (_(" Pointer Encoding Format: %#x (%s)\n"), ptr_enc, decode_eh_encoding (ptr_enc)); | |
9416 | ||
9417 | unsigned int count_enc = start[2]; | |
9418 | printf (_(" Count Encoding Format: %#x (%s)\n"), count_enc, decode_eh_encoding (count_enc)); | |
9419 | ||
9420 | unsigned int table_enc = start[3]; | |
9421 | printf (_(" Table Encoding Format: %#x (%s)\n"), table_enc, decode_eh_encoding (table_enc)); | |
9422 | ||
9423 | start += 4; | |
9424 | ||
9425 | unsigned int len; | |
9426 | ||
9427 | uint64_t eh_frame_ptr = get_encoded_eh_value (ptr_enc, start, end, & len); | |
9428 | if (len == 0) | |
9429 | { | |
9430 | warn (_("unable to read eh_frame_ptr field in .eh_frame_hdr section\n")); | |
9431 | return 0; | |
9432 | } | |
9433 | printf (_(" Start of frame section: %#" PRIx64), eh_frame_ptr); | |
9434 | ||
9435 | uint64_t offset_eh_frame_ptr = encoded_eh_offset (ptr_enc, section, 4, eh_frame_ptr); | |
9436 | if (offset_eh_frame_ptr != eh_frame_ptr) | |
9437 | printf (_(" (offset: %#" PRIx64 ")"), offset_eh_frame_ptr); | |
9438 | ||
9439 | printf ("\n"); | |
9440 | start += len; | |
9441 | ||
9442 | if (count_enc == DW_EH_PE_omit) | |
9443 | { | |
9444 | warn (_("It is suspicious to have a .eh_frame_hdr section with an empty search table\n")); | |
9445 | return 0; | |
9446 | } | |
9447 | ||
9448 | if (count_enc & 0xf0) | |
9449 | { | |
9450 | warn (_("The count field format should be absolute, not relative to an address\n")); | |
9451 | return 0; | |
9452 | } | |
9453 | ||
9454 | uint64_t fde_count = get_encoded_eh_value (count_enc, start, end, & len); | |
9455 | if (len == 0) | |
9456 | { | |
9457 | warn (_("unable to read fde_count field in .eh_frame_hdr section\n")); | |
9458 | return 0; | |
9459 | } | |
9460 | printf (_(" Entries in search table: %#" PRIx64), fde_count); | |
9461 | printf ("\n"); | |
9462 | start += len; | |
9463 | ||
9464 | if (fde_count != 0 && table_enc == DW_EH_PE_omit) | |
9465 | { | |
9466 | warn (_("It is suspicious to have a .eh_frame_hdr section an empty table but a non empty count field\n")); | |
9467 | return 0; | |
9468 | } | |
9469 | ||
9470 | uint64_t i; | |
9471 | /* Read and display the search table. */ | |
9472 | for (i = 0; i < fde_count; i++) | |
9473 | { | |
9474 | uint64_t location, address; | |
9475 | unsigned char * row_start = start; | |
9476 | ||
9477 | location = get_encoded_eh_value (table_enc, start, end, & len); | |
9478 | if (len == 0) | |
9479 | { | |
9480 | warn (_("Failed to read location field for entry %#" PRIx64 " in the .eh_frame_hdr's search table\n"), i); | |
9481 | return 0; | |
9482 | } | |
9483 | start += len; | |
9484 | ||
9485 | address = get_encoded_eh_value (table_enc, start, end, & len); | |
9486 | if (len == 0) | |
9487 | { | |
9488 | warn (_("Failed to read address field for entry %#" PRIx64 " in the .eh_frame_hdr's search table\n"), i); | |
9489 | return 0; | |
9490 | } | |
9491 | start += len; | |
9492 | ||
9493 | /* This format is intended to be compatible with the output of eu-readelf's -e option. */ | |
9494 | printf (" %#" PRIx64 " (offset: %#" PRIx64 ") -> %#" PRIx64 " fde=[ %5" PRIx64 "]\n", | |
9495 | location, | |
9496 | encoded_eh_offset (table_enc, section, row_start - section->start, location), | |
9497 | address, | |
9498 | encoded_eh_offset (table_enc, section, row_start - section->start, address) - offset_eh_frame_ptr); | |
9499 | } | |
9500 | ||
9501 | printf ("\n"); | |
9502 | return 1; | |
9503 | } | |
9504 | ||
9505 | static int | |
9506 | display_debug_frames (struct dwarf_section *section, | |
9507 | void *file ATTRIBUTE_UNUSED) | |
9508 | { | |
9509 | unsigned char *start = section->start; | |
9510 | unsigned char *end = start + section->size; | |
9511 | unsigned char *section_start = start; | |
9512 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; | |
9513 | Frame_Chunk *remembered_state = NULL; | |
9514 | Frame_Chunk *rs; | |
9515 | bool is_eh = strcmp (section->name, ".eh_frame") == 0; | |
9516 | unsigned int max_regs = 0; | |
9517 | const char *bad_reg = _("bad register: "); | |
9518 | unsigned int saved_eh_addr_size = eh_addr_size; | |
9519 | ||
9520 | introduce (section, false); | |
9521 | ||
9522 | while (start < end) | |
9523 | { | |
9524 | unsigned char *saved_start; | |
9525 | unsigned char *block_end; | |
9526 | uint64_t length; | |
9527 | uint64_t cie_id; | |
9528 | Frame_Chunk *fc; | |
9529 | Frame_Chunk *cie; | |
9530 | int need_col_headers = 1; | |
9531 | unsigned char *augmentation_data = NULL; | |
9532 | uint64_t augmentation_data_len = 0; | |
9533 | unsigned int encoded_ptr_size = saved_eh_addr_size; | |
9534 | unsigned int offset_size; | |
9535 | bool all_nops; | |
9536 | static Frame_Chunk fde_fc; | |
9537 | ||
9538 | saved_start = start; | |
9539 | ||
9540 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); | |
9541 | ||
9542 | if (length == 0) | |
9543 | { | |
9544 | printf ("\n%08tx ZERO terminator\n\n", | |
9545 | saved_start - section_start); | |
9546 | /* Skip any zero terminators that directly follow. | |
9547 | A corrupt section size could have loaded a whole | |
9548 | slew of zero filled memory bytes. eg | |
9549 | PR 17512: file: 070-19381-0.004. */ | |
9550 | while (start < end && * start == 0) | |
9551 | ++ start; | |
9552 | continue; | |
9553 | } | |
9554 | ||
9555 | if (length == 0xffffffff) | |
9556 | { | |
9557 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); | |
9558 | offset_size = 8; | |
9559 | } | |
9560 | else | |
9561 | offset_size = 4; | |
9562 | ||
9563 | if (length > (size_t) (end - start)) | |
9564 | { | |
9565 | warn ("Invalid length %#" PRIx64 " in FDE at %#tx\n", | |
9566 | length, saved_start - section_start); | |
9567 | block_end = end; | |
9568 | } | |
9569 | else | |
9570 | block_end = start + length; | |
9571 | ||
9572 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, block_end); | |
9573 | ||
9574 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) | |
9575 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
9576 | { | |
9577 | int version; | |
9578 | unsigned int mreg; | |
9579 | ||
9580 | start = read_cie (start, block_end, &cie, &version, | |
9581 | &augmentation_data_len, &augmentation_data); | |
9582 | /* PR 17512: file: 027-135133-0.005. */ | |
9583 | if (cie == NULL) | |
9584 | break; | |
9585 | ||
9586 | fc = cie; | |
9587 | fc->next = chunks; | |
9588 | chunks = fc; | |
9589 | fc->chunk_start = saved_start; | |
9590 | mreg = max_regs > 0 ? max_regs - 1 : 0; | |
9591 | if (mreg < fc->ra) | |
9592 | mreg = fc->ra; | |
9593 | if (frame_need_space (fc, mreg) < 0) | |
9594 | break; | |
9595 | if (fc->fde_encoding) | |
9596 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
9597 | ||
9598 | printf ("\n%08tx ", saved_start - section_start); | |
9599 | print_hex (length, fc->ptr_size); | |
9600 | print_hex (cie_id, offset_size); | |
9601 | ||
9602 | if (do_debug_frames_interp) | |
9603 | { | |
9604 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
9605 | fc->code_factor, fc->data_factor, fc->ra); | |
9606 | } | |
9607 | else | |
9608 | { | |
9609 | printf ("CIE\n"); | |
9610 | printf (" Version: %d\n", version); | |
9611 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
9612 | if (version >= 4) | |
9613 | { | |
9614 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
9615 | printf (" Segment Size: %u\n", fc->segment_size); | |
9616 | } | |
9617 | printf (" Code alignment factor: %u\n", fc->code_factor); | |
9618 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
9619 | printf (" Return address column: %d\n", fc->ra); | |
9620 | ||
9621 | if (augmentation_data_len) | |
9622 | display_augmentation_data (augmentation_data, augmentation_data_len); | |
9623 | ||
9624 | putchar ('\n'); | |
9625 | } | |
9626 | } | |
9627 | else | |
9628 | { | |
9629 | unsigned char *look_for; | |
9630 | unsigned long segment_selector; | |
9631 | uint64_t cie_off; | |
9632 | ||
9633 | cie_off = cie_id; | |
9634 | if (is_eh) | |
9635 | { | |
9636 | uint64_t sign = (uint64_t) 1 << (offset_size * 8 - 1); | |
9637 | cie_off = (cie_off ^ sign) - sign; | |
9638 | cie_off = start - 4 - section_start - cie_off; | |
9639 | } | |
9640 | ||
9641 | look_for = section_start + cie_off; | |
9642 | if (cie_off <= (size_t) (saved_start - section_start)) | |
9643 | { | |
9644 | for (cie = chunks; cie ; cie = cie->next) | |
9645 | if (cie->chunk_start == look_for) | |
9646 | break; | |
9647 | } | |
9648 | else if (cie_off >= section->size) | |
9649 | cie = NULL; | |
9650 | else | |
9651 | { | |
9652 | for (cie = forward_refs; cie ; cie = cie->next) | |
9653 | if (cie->chunk_start == look_for) | |
9654 | break; | |
9655 | if (!cie) | |
9656 | { | |
9657 | unsigned int off_size; | |
9658 | unsigned char *cie_scan; | |
9659 | ||
9660 | cie_scan = look_for; | |
9661 | off_size = 4; | |
9662 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
9663 | if (length == 0xffffffff) | |
9664 | { | |
9665 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
9666 | off_size = 8; | |
9667 | } | |
9668 | if (length != 0 && length <= (size_t) (end - cie_scan)) | |
9669 | { | |
9670 | uint64_t c_id; | |
9671 | unsigned char *cie_end = cie_scan + length; | |
9672 | ||
9673 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, | |
9674 | cie_end); | |
9675 | if (is_eh | |
9676 | ? c_id == 0 | |
9677 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
9678 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
9679 | { | |
9680 | int version; | |
9681 | unsigned int mreg; | |
9682 | ||
9683 | read_cie (cie_scan, cie_end, &cie, &version, | |
9684 | &augmentation_data_len, &augmentation_data); | |
9685 | /* PR 17512: file: 3450-2098-0.004. */ | |
9686 | if (cie == NULL) | |
9687 | { | |
9688 | warn (_("Failed to read CIE information\n")); | |
9689 | break; | |
9690 | } | |
9691 | cie->next = forward_refs; | |
9692 | forward_refs = cie; | |
9693 | cie->chunk_start = look_for; | |
9694 | mreg = max_regs > 0 ? max_regs - 1 : 0; | |
9695 | if (mreg < cie->ra) | |
9696 | mreg = cie->ra; | |
9697 | if (frame_need_space (cie, mreg) < 0) | |
9698 | { | |
9699 | warn (_("Invalid max register\n")); | |
9700 | break; | |
9701 | } | |
9702 | if (cie->fde_encoding) | |
9703 | encoded_ptr_size | |
9704 | = size_of_encoded_value (cie->fde_encoding); | |
9705 | } | |
9706 | } | |
9707 | } | |
9708 | } | |
9709 | ||
9710 | fc = &fde_fc; | |
9711 | memset (fc, 0, sizeof (Frame_Chunk)); | |
9712 | ||
9713 | if (!cie) | |
9714 | { | |
9715 | fc->ncols = 0; | |
9716 | fc->col_type = xmalloc (sizeof (*fc->col_type)); | |
9717 | fc->col_offset = xmalloc (sizeof (*fc->col_offset)); | |
9718 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) | |
9719 | { | |
9720 | warn (_("Invalid max register\n")); | |
9721 | break; | |
9722 | } | |
9723 | cie = fc; | |
9724 | fc->augmentation = ""; | |
9725 | fc->fde_encoding = 0; | |
9726 | fc->ptr_size = eh_addr_size; | |
9727 | fc->segment_size = 0; | |
9728 | } | |
9729 | else | |
9730 | { | |
9731 | fc->ncols = cie->ncols; | |
9732 | fc->col_type = xcmalloc (fc->ncols, sizeof (*fc->col_type)); | |
9733 | fc->col_offset = xcmalloc (fc->ncols, sizeof (*fc->col_offset)); | |
9734 | memcpy (fc->col_type, cie->col_type, | |
9735 | fc->ncols * sizeof (*fc->col_type)); | |
9736 | memcpy (fc->col_offset, cie->col_offset, | |
9737 | fc->ncols * sizeof (*fc->col_offset)); | |
9738 | fc->augmentation = cie->augmentation; | |
9739 | fc->ptr_size = cie->ptr_size; | |
9740 | eh_addr_size = cie->ptr_size; | |
9741 | fc->segment_size = cie->segment_size; | |
9742 | fc->code_factor = cie->code_factor; | |
9743 | fc->data_factor = cie->data_factor; | |
9744 | fc->cfa_reg = cie->cfa_reg; | |
9745 | fc->cfa_offset = cie->cfa_offset; | |
9746 | fc->ra = cie->ra; | |
9747 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) | |
9748 | { | |
9749 | warn (_("Invalid max register\n")); | |
9750 | break; | |
9751 | } | |
9752 | fc->fde_encoding = cie->fde_encoding; | |
9753 | } | |
9754 | ||
9755 | if (fc->fde_encoding) | |
9756 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
9757 | ||
9758 | segment_selector = 0; | |
9759 | if (fc->segment_size) | |
9760 | { | |
9761 | if (fc->segment_size > sizeof (segment_selector)) | |
9762 | { | |
9763 | /* PR 17512: file: 9e196b3e. */ | |
9764 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
9765 | fc->segment_size = 4; | |
9766 | } | |
9767 | SAFE_BYTE_GET_AND_INC (segment_selector, start, | |
9768 | fc->segment_size, block_end); | |
9769 | } | |
9770 | ||
9771 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, | |
9772 | block_end); | |
9773 | ||
9774 | /* FIXME: It appears that sometimes the final pc_range value is | |
9775 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
9776 | run of the "objcopy on compressed debug sections" test for an | |
9777 | example of this. */ | |
9778 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, | |
9779 | block_end); | |
9780 | ||
9781 | if (cie->augmentation[0] == 'z') | |
9782 | { | |
9783 | READ_ULEB (augmentation_data_len, start, block_end); | |
9784 | augmentation_data = start; | |
9785 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ | |
9786 | if (augmentation_data_len > (size_t) (block_end - start)) | |
9787 | { | |
9788 | warn (_("Augmentation data too long: %#" PRIx64 ", " | |
9789 | "expected at most %#tx\n"), | |
9790 | augmentation_data_len, block_end - start); | |
9791 | start = block_end; | |
9792 | augmentation_data = NULL; | |
9793 | augmentation_data_len = 0; | |
9794 | } | |
9795 | start += augmentation_data_len; | |
9796 | } | |
9797 | ||
9798 | printf ("\n%08tx ", saved_start - section_start); | |
9799 | print_hex (length, fc->ptr_size); | |
9800 | print_hex (cie_id, offset_size); | |
9801 | printf ("FDE "); | |
9802 | ||
9803 | if (cie->chunk_start) | |
9804 | printf ("cie=%08tx", cie->chunk_start - section_start); | |
9805 | else | |
9806 | /* Ideally translate "invalid " to 8 chars, trailing space | |
9807 | is optional. */ | |
9808 | printf (_("cie=invalid ")); | |
9809 | ||
9810 | printf (" pc="); | |
9811 | if (fc->segment_size) | |
9812 | printf ("%04lx:", segment_selector); | |
9813 | ||
9814 | print_hex_ns (fc->pc_begin, fc->ptr_size); | |
9815 | printf (".."); | |
9816 | print_hex_ns (fc->pc_begin + fc->pc_range, fc->ptr_size); | |
9817 | printf ("\n"); | |
9818 | ||
9819 | if (! do_debug_frames_interp && augmentation_data_len) | |
9820 | { | |
9821 | display_augmentation_data (augmentation_data, augmentation_data_len); | |
9822 | putchar ('\n'); | |
9823 | } | |
9824 | } | |
9825 | ||
9826 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
9827 | we're about to interpret instructions for the chunk. */ | |
9828 | /* ??? At present we need to do this always, since this sizes the | |
9829 | fc->col_type and fc->col_offset arrays, which we write into always. | |
9830 | We should probably split the interpreted and non-interpreted bits | |
9831 | into two different routines, since there's so much that doesn't | |
9832 | really overlap between them. */ | |
9833 | if (1 || do_debug_frames_interp) | |
9834 | { | |
9835 | /* Start by making a pass over the chunk, allocating storage | |
9836 | and taking note of what registers are used. */ | |
9837 | unsigned char *tmp = start; | |
9838 | ||
9839 | while (start < block_end) | |
9840 | { | |
9841 | unsigned int reg, op, opa; | |
9842 | unsigned long temp; | |
9843 | ||
9844 | op = *start++; | |
9845 | opa = op & 0x3f; | |
9846 | if (op & 0xc0) | |
9847 | op &= 0xc0; | |
9848 | ||
9849 | /* Warning: if you add any more cases to this switch, be | |
9850 | sure to add them to the corresponding switch below. */ | |
9851 | reg = -1u; | |
9852 | switch (op) | |
9853 | { | |
9854 | case DW_CFA_advance_loc: | |
9855 | break; | |
9856 | case DW_CFA_offset: | |
9857 | SKIP_ULEB (start, block_end); | |
9858 | reg = opa; | |
9859 | break; | |
9860 | case DW_CFA_restore: | |
9861 | reg = opa; | |
9862 | break; | |
9863 | case DW_CFA_set_loc: | |
9864 | if ((size_t) (block_end - start) < encoded_ptr_size) | |
9865 | start = block_end; | |
9866 | else | |
9867 | start += encoded_ptr_size; | |
9868 | break; | |
9869 | case DW_CFA_advance_loc1: | |
9870 | if ((size_t) (block_end - start) < 1) | |
9871 | start = block_end; | |
9872 | else | |
9873 | start += 1; | |
9874 | break; | |
9875 | case DW_CFA_advance_loc2: | |
9876 | if ((size_t) (block_end - start) < 2) | |
9877 | start = block_end; | |
9878 | else | |
9879 | start += 2; | |
9880 | break; | |
9881 | case DW_CFA_advance_loc4: | |
9882 | if ((size_t) (block_end - start) < 4) | |
9883 | start = block_end; | |
9884 | else | |
9885 | start += 4; | |
9886 | break; | |
9887 | case DW_CFA_offset_extended: | |
9888 | case DW_CFA_val_offset: | |
9889 | READ_ULEB (reg, start, block_end); | |
9890 | SKIP_ULEB (start, block_end); | |
9891 | break; | |
9892 | case DW_CFA_restore_extended: | |
9893 | READ_ULEB (reg, start, block_end); | |
9894 | break; | |
9895 | case DW_CFA_undefined: | |
9896 | READ_ULEB (reg, start, block_end); | |
9897 | break; | |
9898 | case DW_CFA_same_value: | |
9899 | READ_ULEB (reg, start, block_end); | |
9900 | break; | |
9901 | case DW_CFA_register: | |
9902 | READ_ULEB (reg, start, block_end); | |
9903 | SKIP_ULEB (start, block_end); | |
9904 | break; | |
9905 | case DW_CFA_def_cfa: | |
9906 | SKIP_ULEB (start, block_end); | |
9907 | SKIP_ULEB (start, block_end); | |
9908 | break; | |
9909 | case DW_CFA_def_cfa_register: | |
9910 | SKIP_ULEB (start, block_end); | |
9911 | break; | |
9912 | case DW_CFA_def_cfa_offset: | |
9913 | SKIP_ULEB (start, block_end); | |
9914 | break; | |
9915 | case DW_CFA_def_cfa_expression: | |
9916 | READ_ULEB (temp, start, block_end); | |
9917 | if ((size_t) (block_end - start) < temp) | |
9918 | start = block_end; | |
9919 | else | |
9920 | start += temp; | |
9921 | break; | |
9922 | case DW_CFA_expression: | |
9923 | case DW_CFA_val_expression: | |
9924 | READ_ULEB (reg, start, block_end); | |
9925 | READ_ULEB (temp, start, block_end); | |
9926 | if ((size_t) (block_end - start) < temp) | |
9927 | start = block_end; | |
9928 | else | |
9929 | start += temp; | |
9930 | break; | |
9931 | case DW_CFA_offset_extended_sf: | |
9932 | case DW_CFA_val_offset_sf: | |
9933 | READ_ULEB (reg, start, block_end); | |
9934 | SKIP_SLEB (start, block_end); | |
9935 | break; | |
9936 | case DW_CFA_def_cfa_sf: | |
9937 | SKIP_ULEB (start, block_end); | |
9938 | SKIP_SLEB (start, block_end); | |
9939 | break; | |
9940 | case DW_CFA_def_cfa_offset_sf: | |
9941 | SKIP_SLEB (start, block_end); | |
9942 | break; | |
9943 | case DW_CFA_MIPS_advance_loc8: | |
9944 | if ((size_t) (block_end - start) < 8) | |
9945 | start = block_end; | |
9946 | else | |
9947 | start += 8; | |
9948 | break; | |
9949 | case DW_CFA_GNU_args_size: | |
9950 | SKIP_ULEB (start, block_end); | |
9951 | break; | |
9952 | case DW_CFA_GNU_negative_offset_extended: | |
9953 | READ_ULEB (reg, start, block_end); | |
9954 | SKIP_ULEB (start, block_end); | |
9955 | break; | |
9956 | default: | |
9957 | break; | |
9958 | } | |
9959 | if (reg != -1u && frame_need_space (fc, reg) >= 0) | |
9960 | { | |
9961 | /* Don't leave any reg as DW_CFA_unreferenced so | |
9962 | that frame_display_row prints name of regs in | |
9963 | header, and all referenced regs in each line. */ | |
9964 | if (reg >= cie->ncols | |
9965 | || cie->col_type[reg] == DW_CFA_unreferenced) | |
9966 | fc->col_type[reg] = DW_CFA_undefined; | |
9967 | else | |
9968 | fc->col_type[reg] = cie->col_type[reg]; | |
9969 | } | |
9970 | } | |
9971 | start = tmp; | |
9972 | } | |
9973 | ||
9974 | all_nops = true; | |
9975 | ||
9976 | /* Now we know what registers are used, make a second pass over | |
9977 | the chunk, this time actually printing out the info. */ | |
9978 | ||
9979 | while (start < block_end) | |
9980 | { | |
9981 | unsigned op, opa; | |
9982 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
9983 | are various functions, notably frame_space_needed() that assume that | |
9984 | reg is an unsigned int. */ | |
9985 | unsigned int reg; | |
9986 | int64_t sofs; | |
9987 | uint64_t ofs; | |
9988 | const char *reg_prefix = ""; | |
9989 | ||
9990 | op = *start++; | |
9991 | opa = op & 0x3f; | |
9992 | if (op & 0xc0) | |
9993 | op &= 0xc0; | |
9994 | ||
9995 | /* Make a note if something other than DW_CFA_nop happens. */ | |
9996 | if (op != DW_CFA_nop) | |
9997 | all_nops = false; | |
9998 | ||
9999 | /* Warning: if you add any more cases to this switch, be | |
10000 | sure to add them to the corresponding switch above. */ | |
10001 | switch (op) | |
10002 | { | |
10003 | case DW_CFA_advance_loc: | |
10004 | opa *= fc->code_factor; | |
10005 | if (do_debug_frames_interp) | |
10006 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10007 | else | |
10008 | { | |
10009 | printf (" DW_CFA_advance_loc: %d to ", opa); | |
10010 | print_hex_ns (fc->pc_begin + opa, fc->ptr_size); | |
10011 | printf ("\n"); | |
10012 | } | |
10013 | fc->pc_begin += opa; | |
10014 | break; | |
10015 | ||
10016 | case DW_CFA_offset: | |
10017 | READ_ULEB (ofs, start, block_end); | |
10018 | ofs *= fc->data_factor; | |
10019 | if (opa >= fc->ncols) | |
10020 | reg_prefix = bad_reg; | |
10021 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10022 | printf (" DW_CFA_offset: %s%s at cfa%+" PRId64 "\n", | |
10023 | reg_prefix, regname (opa, 0), ofs); | |
10024 | if (*reg_prefix == '\0') | |
10025 | { | |
10026 | fc->col_type[opa] = DW_CFA_offset; | |
10027 | fc->col_offset[opa] = ofs; | |
10028 | } | |
10029 | break; | |
10030 | ||
10031 | case DW_CFA_restore: | |
10032 | if (opa >= fc->ncols) | |
10033 | reg_prefix = bad_reg; | |
10034 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10035 | printf (" DW_CFA_restore: %s%s\n", | |
10036 | reg_prefix, regname (opa, 0)); | |
10037 | if (*reg_prefix != '\0') | |
10038 | break; | |
10039 | ||
10040 | if (opa >= cie->ncols | |
10041 | || cie->col_type[opa] == DW_CFA_unreferenced) | |
10042 | { | |
10043 | fc->col_type[opa] = DW_CFA_undefined; | |
10044 | fc->col_offset[opa] = 0; | |
10045 | } | |
10046 | else | |
10047 | { | |
10048 | fc->col_type[opa] = cie->col_type[opa]; | |
10049 | fc->col_offset[opa] = cie->col_offset[opa]; | |
10050 | } | |
10051 | break; | |
10052 | ||
10053 | case DW_CFA_set_loc: | |
10054 | ofs = get_encoded_value (&start, fc->fde_encoding, section, | |
10055 | block_end); | |
10056 | if (do_debug_frames_interp) | |
10057 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10058 | else | |
10059 | { | |
10060 | printf (" DW_CFA_set_loc: "); | |
10061 | print_hex_ns (ofs, fc->ptr_size); | |
10062 | printf ("\n"); | |
10063 | } | |
10064 | fc->pc_begin = ofs; | |
10065 | break; | |
10066 | ||
10067 | case DW_CFA_advance_loc1: | |
10068 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, block_end); | |
10069 | ofs *= fc->code_factor; | |
10070 | if (do_debug_frames_interp) | |
10071 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10072 | else | |
10073 | { | |
10074 | printf (" DW_CFA_advance_loc1: %" PRId64 " to ", ofs); | |
10075 | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); | |
10076 | printf ("\n"); | |
10077 | } | |
10078 | fc->pc_begin += ofs; | |
10079 | break; | |
10080 | ||
10081 | case DW_CFA_advance_loc2: | |
10082 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); | |
10083 | ofs *= fc->code_factor; | |
10084 | if (do_debug_frames_interp) | |
10085 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10086 | else | |
10087 | { | |
10088 | printf (" DW_CFA_advance_loc2: %" PRId64 " to ", ofs); | |
10089 | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); | |
10090 | printf ("\n"); | |
10091 | } | |
10092 | fc->pc_begin += ofs; | |
10093 | break; | |
10094 | ||
10095 | case DW_CFA_advance_loc4: | |
10096 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); | |
10097 | ofs *= fc->code_factor; | |
10098 | if (do_debug_frames_interp) | |
10099 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10100 | else | |
10101 | { | |
10102 | printf (" DW_CFA_advance_loc4: %" PRId64 " to ", ofs); | |
10103 | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); | |
10104 | printf ("\n"); | |
10105 | } | |
10106 | fc->pc_begin += ofs; | |
10107 | break; | |
10108 | ||
10109 | case DW_CFA_offset_extended: | |
10110 | READ_ULEB (reg, start, block_end); | |
10111 | READ_ULEB (ofs, start, block_end); | |
10112 | ofs *= fc->data_factor; | |
10113 | if (reg >= fc->ncols) | |
10114 | reg_prefix = bad_reg; | |
10115 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10116 | printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64 "\n", | |
10117 | reg_prefix, regname (reg, 0), ofs); | |
10118 | if (*reg_prefix == '\0') | |
10119 | { | |
10120 | fc->col_type[reg] = DW_CFA_offset; | |
10121 | fc->col_offset[reg] = ofs; | |
10122 | } | |
10123 | break; | |
10124 | ||
10125 | case DW_CFA_val_offset: | |
10126 | READ_ULEB (reg, start, block_end); | |
10127 | READ_ULEB (ofs, start, block_end); | |
10128 | ofs *= fc->data_factor; | |
10129 | if (reg >= fc->ncols) | |
10130 | reg_prefix = bad_reg; | |
10131 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10132 | printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64 "\n", | |
10133 | reg_prefix, regname (reg, 0), ofs); | |
10134 | if (*reg_prefix == '\0') | |
10135 | { | |
10136 | fc->col_type[reg] = DW_CFA_val_offset; | |
10137 | fc->col_offset[reg] = ofs; | |
10138 | } | |
10139 | break; | |
10140 | ||
10141 | case DW_CFA_restore_extended: | |
10142 | READ_ULEB (reg, start, block_end); | |
10143 | if (reg >= fc->ncols) | |
10144 | reg_prefix = bad_reg; | |
10145 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10146 | printf (" DW_CFA_restore_extended: %s%s\n", | |
10147 | reg_prefix, regname (reg, 0)); | |
10148 | if (*reg_prefix != '\0') | |
10149 | break; | |
10150 | ||
10151 | if (reg >= cie->ncols | |
10152 | || cie->col_type[reg] == DW_CFA_unreferenced) | |
10153 | { | |
10154 | fc->col_type[reg] = DW_CFA_undefined; | |
10155 | fc->col_offset[reg] = 0; | |
10156 | } | |
10157 | else | |
10158 | { | |
10159 | fc->col_type[reg] = cie->col_type[reg]; | |
10160 | fc->col_offset[reg] = cie->col_offset[reg]; | |
10161 | } | |
10162 | break; | |
10163 | ||
10164 | case DW_CFA_undefined: | |
10165 | READ_ULEB (reg, start, block_end); | |
10166 | if (reg >= fc->ncols) | |
10167 | reg_prefix = bad_reg; | |
10168 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10169 | printf (" DW_CFA_undefined: %s%s\n", | |
10170 | reg_prefix, regname (reg, 0)); | |
10171 | if (*reg_prefix == '\0') | |
10172 | { | |
10173 | fc->col_type[reg] = DW_CFA_undefined; | |
10174 | fc->col_offset[reg] = 0; | |
10175 | } | |
10176 | break; | |
10177 | ||
10178 | case DW_CFA_same_value: | |
10179 | READ_ULEB (reg, start, block_end); | |
10180 | if (reg >= fc->ncols) | |
10181 | reg_prefix = bad_reg; | |
10182 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10183 | printf (" DW_CFA_same_value: %s%s\n", | |
10184 | reg_prefix, regname (reg, 0)); | |
10185 | if (*reg_prefix == '\0') | |
10186 | { | |
10187 | fc->col_type[reg] = DW_CFA_same_value; | |
10188 | fc->col_offset[reg] = 0; | |
10189 | } | |
10190 | break; | |
10191 | ||
10192 | case DW_CFA_register: | |
10193 | READ_ULEB (reg, start, block_end); | |
10194 | READ_ULEB (ofs, start, block_end); | |
10195 | if (reg >= fc->ncols) | |
10196 | reg_prefix = bad_reg; | |
10197 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10198 | { | |
10199 | printf (" DW_CFA_register: %s%s in ", | |
10200 | reg_prefix, regname (reg, 0)); | |
10201 | puts (regname (ofs, 0)); | |
10202 | } | |
10203 | if (*reg_prefix == '\0') | |
10204 | { | |
10205 | fc->col_type[reg] = DW_CFA_register; | |
10206 | fc->col_offset[reg] = ofs; | |
10207 | } | |
10208 | break; | |
10209 | ||
10210 | case DW_CFA_remember_state: | |
10211 | if (! do_debug_frames_interp) | |
10212 | printf (" DW_CFA_remember_state\n"); | |
10213 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); | |
10214 | rs->cfa_offset = fc->cfa_offset; | |
10215 | rs->cfa_reg = fc->cfa_reg; | |
10216 | rs->ra = fc->ra; | |
10217 | rs->cfa_exp = fc->cfa_exp; | |
10218 | rs->ncols = fc->ncols; | |
10219 | rs->col_type = xcmalloc (rs->ncols, sizeof (*rs->col_type)); | |
10220 | rs->col_offset = xcmalloc (rs->ncols, sizeof (*rs->col_offset)); | |
10221 | memcpy (rs->col_type, fc->col_type, | |
10222 | rs->ncols * sizeof (*fc->col_type)); | |
10223 | memcpy (rs->col_offset, fc->col_offset, | |
10224 | rs->ncols * sizeof (*fc->col_offset)); | |
10225 | rs->next = remembered_state; | |
10226 | remembered_state = rs; | |
10227 | break; | |
10228 | ||
10229 | case DW_CFA_restore_state: | |
10230 | if (! do_debug_frames_interp) | |
10231 | printf (" DW_CFA_restore_state\n"); | |
10232 | rs = remembered_state; | |
10233 | if (rs) | |
10234 | { | |
10235 | remembered_state = rs->next; | |
10236 | fc->cfa_offset = rs->cfa_offset; | |
10237 | fc->cfa_reg = rs->cfa_reg; | |
10238 | fc->ra = rs->ra; | |
10239 | fc->cfa_exp = rs->cfa_exp; | |
10240 | if (frame_need_space (fc, rs->ncols - 1) < 0) | |
10241 | { | |
10242 | warn (_("Invalid column number in saved frame state\n")); | |
10243 | fc->ncols = 0; | |
10244 | } | |
10245 | else | |
10246 | { | |
10247 | memcpy (fc->col_type, rs->col_type, | |
10248 | rs->ncols * sizeof (*rs->col_type)); | |
10249 | memcpy (fc->col_offset, rs->col_offset, | |
10250 | rs->ncols * sizeof (*rs->col_offset)); | |
10251 | } | |
10252 | free (rs->col_type); | |
10253 | free (rs->col_offset); | |
10254 | free (rs); | |
10255 | } | |
10256 | else if (do_debug_frames_interp) | |
10257 | printf ("Mismatched DW_CFA_restore_state\n"); | |
10258 | break; | |
10259 | ||
10260 | case DW_CFA_def_cfa: | |
10261 | READ_ULEB (fc->cfa_reg, start, block_end); | |
10262 | READ_ULEB (fc->cfa_offset, start, block_end); | |
10263 | fc->cfa_exp = 0; | |
10264 | if (! do_debug_frames_interp) | |
10265 | printf (" DW_CFA_def_cfa: %s ofs %d\n", | |
10266 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); | |
10267 | break; | |
10268 | ||
10269 | case DW_CFA_def_cfa_register: | |
10270 | READ_ULEB (fc->cfa_reg, start, block_end); | |
10271 | fc->cfa_exp = 0; | |
10272 | if (! do_debug_frames_interp) | |
10273 | printf (" DW_CFA_def_cfa_register: %s\n", | |
10274 | regname (fc->cfa_reg, 0)); | |
10275 | break; | |
10276 | ||
10277 | case DW_CFA_def_cfa_offset: | |
10278 | READ_ULEB (fc->cfa_offset, start, block_end); | |
10279 | if (! do_debug_frames_interp) | |
10280 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); | |
10281 | break; | |
10282 | ||
10283 | case DW_CFA_nop: | |
10284 | if (! do_debug_frames_interp) | |
10285 | printf (" DW_CFA_nop\n"); | |
10286 | break; | |
10287 | ||
10288 | case DW_CFA_def_cfa_expression: | |
10289 | READ_ULEB (ofs, start, block_end); | |
10290 | if (ofs > (size_t) (block_end - start)) | |
10291 | { | |
10292 | printf (_(" %s: <corrupt len %" PRIu64 ">\n"), | |
10293 | "DW_CFA_def_cfa_expression", ofs); | |
10294 | break; | |
10295 | } | |
10296 | if (! do_debug_frames_interp) | |
10297 | { | |
10298 | printf (" DW_CFA_def_cfa_expression ("); | |
10299 | decode_location_expression (start, eh_addr_size, 0, -1, | |
10300 | ofs, 0, section); | |
10301 | printf (")\n"); | |
10302 | } | |
10303 | fc->cfa_exp = 1; | |
10304 | start += ofs; | |
10305 | break; | |
10306 | ||
10307 | case DW_CFA_expression: | |
10308 | READ_ULEB (reg, start, block_end); | |
10309 | READ_ULEB (ofs, start, block_end); | |
10310 | if (reg >= fc->ncols) | |
10311 | reg_prefix = bad_reg; | |
10312 | /* PR 17512: file: 069-133014-0.006. */ | |
10313 | /* PR 17512: file: 98c02eb4. */ | |
10314 | if (ofs > (size_t) (block_end - start)) | |
10315 | { | |
10316 | printf (_(" %s: <corrupt len %" PRIu64 ">\n"), | |
10317 | "DW_CFA_expression", ofs); | |
10318 | break; | |
10319 | } | |
10320 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10321 | { | |
10322 | printf (" DW_CFA_expression: %s%s (", | |
10323 | reg_prefix, regname (reg, 0)); | |
10324 | decode_location_expression (start, eh_addr_size, 0, -1, | |
10325 | ofs, 0, section); | |
10326 | printf (")\n"); | |
10327 | } | |
10328 | if (*reg_prefix == '\0') | |
10329 | fc->col_type[reg] = DW_CFA_expression; | |
10330 | start += ofs; | |
10331 | break; | |
10332 | ||
10333 | case DW_CFA_val_expression: | |
10334 | READ_ULEB (reg, start, block_end); | |
10335 | READ_ULEB (ofs, start, block_end); | |
10336 | if (reg >= fc->ncols) | |
10337 | reg_prefix = bad_reg; | |
10338 | if (ofs > (size_t) (block_end - start)) | |
10339 | { | |
10340 | printf (" %s: <corrupt len %" PRIu64 ">\n", | |
10341 | "DW_CFA_val_expression", ofs); | |
10342 | break; | |
10343 | } | |
10344 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10345 | { | |
10346 | printf (" DW_CFA_val_expression: %s%s (", | |
10347 | reg_prefix, regname (reg, 0)); | |
10348 | decode_location_expression (start, eh_addr_size, 0, -1, | |
10349 | ofs, 0, section); | |
10350 | printf (")\n"); | |
10351 | } | |
10352 | if (*reg_prefix == '\0') | |
10353 | fc->col_type[reg] = DW_CFA_val_expression; | |
10354 | start += ofs; | |
10355 | break; | |
10356 | ||
10357 | case DW_CFA_offset_extended_sf: | |
10358 | READ_ULEB (reg, start, block_end); | |
10359 | READ_SLEB (sofs, start, block_end); | |
10360 | /* data_factor multiplicaton done here as unsigned to | |
10361 | avoid integer overflow warnings from asan on fuzzed | |
10362 | objects. */ | |
10363 | ofs = sofs; | |
10364 | ofs *= fc->data_factor; | |
10365 | if (reg >= fc->ncols) | |
10366 | reg_prefix = bad_reg; | |
10367 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10368 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64 "\n", | |
10369 | reg_prefix, regname (reg, 0), ofs); | |
10370 | if (*reg_prefix == '\0') | |
10371 | { | |
10372 | fc->col_type[reg] = DW_CFA_offset; | |
10373 | fc->col_offset[reg] = ofs; | |
10374 | } | |
10375 | break; | |
10376 | ||
10377 | case DW_CFA_val_offset_sf: | |
10378 | READ_ULEB (reg, start, block_end); | |
10379 | READ_SLEB (sofs, start, block_end); | |
10380 | ofs = sofs; | |
10381 | ofs *= fc->data_factor; | |
10382 | if (reg >= fc->ncols) | |
10383 | reg_prefix = bad_reg; | |
10384 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10385 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64 "\n", | |
10386 | reg_prefix, regname (reg, 0), ofs); | |
10387 | if (*reg_prefix == '\0') | |
10388 | { | |
10389 | fc->col_type[reg] = DW_CFA_val_offset; | |
10390 | fc->col_offset[reg] = ofs; | |
10391 | } | |
10392 | break; | |
10393 | ||
10394 | case DW_CFA_def_cfa_sf: | |
10395 | READ_ULEB (fc->cfa_reg, start, block_end); | |
10396 | READ_SLEB (sofs, start, block_end); | |
10397 | ofs = sofs; | |
10398 | ofs *= fc->data_factor; | |
10399 | fc->cfa_offset = ofs; | |
10400 | fc->cfa_exp = 0; | |
10401 | if (! do_debug_frames_interp) | |
10402 | printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64 "\n", | |
10403 | regname (fc->cfa_reg, 0), ofs); | |
10404 | break; | |
10405 | ||
10406 | case DW_CFA_def_cfa_offset_sf: | |
10407 | READ_SLEB (sofs, start, block_end); | |
10408 | ofs = sofs; | |
10409 | ofs *= fc->data_factor; | |
10410 | fc->cfa_offset = ofs; | |
10411 | if (! do_debug_frames_interp) | |
10412 | printf (" DW_CFA_def_cfa_offset_sf: %" PRId64 "\n", ofs); | |
10413 | break; | |
10414 | ||
10415 | case DW_CFA_MIPS_advance_loc8: | |
10416 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); | |
10417 | ofs *= fc->code_factor; | |
10418 | if (do_debug_frames_interp) | |
10419 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10420 | else | |
10421 | { | |
10422 | printf (" DW_CFA_MIPS_advance_loc8: %" PRId64 " to ", ofs); | |
10423 | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); | |
10424 | printf ("\n"); | |
10425 | } | |
10426 | fc->pc_begin += ofs; | |
10427 | break; | |
10428 | ||
10429 | case DW_CFA_AARCH64_negate_ra_state_with_pc: | |
10430 | if (! do_debug_frames_interp) | |
10431 | printf (" DW_CFA_AARCH64_negate_ra_state_with_pc\n"); | |
10432 | break; | |
10433 | ||
10434 | case DW_CFA_GNU_window_save: | |
10435 | if (! do_debug_frames_interp) | |
10436 | printf (" %s\n", DW_CFA_GNU_window_save_name[is_aarch64]); | |
10437 | break; | |
10438 | ||
10439 | case DW_CFA_GNU_args_size: | |
10440 | READ_ULEB (ofs, start, block_end); | |
10441 | if (! do_debug_frames_interp) | |
10442 | printf (" DW_CFA_GNU_args_size: %" PRIu64 "\n", ofs); | |
10443 | break; | |
10444 | ||
10445 | case DW_CFA_GNU_negative_offset_extended: | |
10446 | READ_ULEB (reg, start, block_end); | |
10447 | READ_SLEB (sofs, start, block_end); | |
10448 | ofs = sofs; | |
10449 | ofs = -ofs * fc->data_factor; | |
10450 | if (reg >= fc->ncols) | |
10451 | reg_prefix = bad_reg; | |
10452 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10453 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s " | |
10454 | "at cfa%+" PRId64 "\n", | |
10455 | reg_prefix, regname (reg, 0), ofs); | |
10456 | if (*reg_prefix == '\0') | |
10457 | { | |
10458 | fc->col_type[reg] = DW_CFA_offset; | |
10459 | fc->col_offset[reg] = ofs; | |
10460 | } | |
10461 | break; | |
10462 | ||
10463 | default: | |
10464 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) | |
10465 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
10466 | else | |
10467 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); | |
10468 | start = block_end; | |
10469 | } | |
10470 | } | |
10471 | ||
10472 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ | |
10473 | if (do_debug_frames_interp && ! all_nops) | |
10474 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10475 | ||
10476 | if (fde_fc.col_type != NULL) | |
10477 | { | |
10478 | free (fde_fc.col_type); | |
10479 | fde_fc.col_type = NULL; | |
10480 | } | |
10481 | if (fde_fc.col_offset != NULL) | |
10482 | { | |
10483 | free (fde_fc.col_offset); | |
10484 | fde_fc.col_offset = NULL; | |
10485 | } | |
10486 | ||
10487 | start = block_end; | |
10488 | eh_addr_size = saved_eh_addr_size; | |
10489 | } | |
10490 | ||
10491 | printf ("\n"); | |
10492 | ||
10493 | while (remembered_state != NULL) | |
10494 | { | |
10495 | rs = remembered_state; | |
10496 | remembered_state = rs->next; | |
10497 | free (rs->col_type); | |
10498 | free (rs->col_offset); | |
10499 | rs->next = NULL; /* Paranoia. */ | |
10500 | free (rs); | |
10501 | } | |
10502 | ||
10503 | while (chunks != NULL) | |
10504 | { | |
10505 | rs = chunks; | |
10506 | chunks = rs->next; | |
10507 | free (rs->col_type); | |
10508 | free (rs->col_offset); | |
10509 | rs->next = NULL; /* Paranoia. */ | |
10510 | free (rs); | |
10511 | } | |
10512 | ||
10513 | while (forward_refs != NULL) | |
10514 | { | |
10515 | rs = forward_refs; | |
10516 | forward_refs = rs->next; | |
10517 | free (rs->col_type); | |
10518 | free (rs->col_offset); | |
10519 | rs->next = NULL; /* Paranoia. */ | |
10520 | free (rs); | |
10521 | } | |
10522 | ||
10523 | return 1; | |
10524 | } | |
10525 | ||
10526 | #undef GET | |
10527 | ||
10528 | static int | |
10529 | display_debug_names (struct dwarf_section *section, void *file) | |
10530 | { | |
10531 | unsigned char *hdrptr = section->start; | |
10532 | uint64_t unit_length; | |
10533 | unsigned char *unit_start; | |
10534 | const unsigned char *const section_end = section->start + section->size; | |
10535 | unsigned char *unit_end; | |
10536 | ||
10537 | introduce (section, false); | |
10538 | ||
10539 | load_debug_section_with_follow (str, file); | |
10540 | ||
10541 | for (; hdrptr < section_end; hdrptr = unit_end) | |
10542 | { | |
10543 | unsigned int offset_size; | |
10544 | uint16_t dwarf_version, padding; | |
10545 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
10546 | uint64_t bucket_count, name_count, abbrev_table_size; | |
10547 | uint32_t augmentation_string_size; | |
10548 | unsigned int i; | |
10549 | bool augmentation_printable; | |
10550 | const char *augmentation_string; | |
10551 | size_t total; | |
10552 | ||
10553 | unit_start = hdrptr; | |
10554 | ||
10555 | /* Get and check the length of the block. */ | |
10556 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
10557 | ||
10558 | if (unit_length == 0xffffffff) | |
10559 | { | |
10560 | /* This section is 64-bit DWARF. */ | |
10561 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
10562 | offset_size = 8; | |
10563 | } | |
10564 | else | |
10565 | offset_size = 4; | |
10566 | ||
10567 | if (unit_length > (size_t) (section_end - hdrptr) | |
10568 | || unit_length < 2 + 2 + 4 * 7) | |
10569 | { | |
10570 | too_short: | |
10571 | warn (_("Debug info is corrupted, %s header at %#tx" | |
10572 | " has length %#" PRIx64 "\n"), | |
10573 | section->name, unit_start - section->start, unit_length); | |
10574 | return 0; | |
10575 | } | |
10576 | unit_end = hdrptr + unit_length; | |
10577 | ||
10578 | /* Get and check the version number. */ | |
10579 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
10580 | printf (_("Version %d\n"), (int) dwarf_version); | |
10581 | ||
10582 | /* Prior versions did not exist, and future versions may not be | |
10583 | backwards compatible. */ | |
10584 | if (dwarf_version != 5) | |
10585 | { | |
10586 | warn (_("Only DWARF version 5 .debug_names " | |
10587 | "is currently supported.\n")); | |
10588 | return 0; | |
10589 | } | |
10590 | ||
10591 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
10592 | if (padding != 0) | |
10593 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
10594 | padding); | |
10595 | ||
10596 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
10597 | if (comp_unit_count == 0) | |
10598 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
10599 | ||
10600 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
10601 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
10602 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
10603 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
10604 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
10605 | ||
10606 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
10607 | if (augmentation_string_size % 4 != 0) | |
10608 | { | |
10609 | warn (_("Augmentation string length %u must be rounded up " | |
10610 | "to a multiple of 4 in .debug_names.\n"), | |
10611 | augmentation_string_size); | |
10612 | augmentation_string_size += (-augmentation_string_size) & 3; | |
10613 | } | |
10614 | if (augmentation_string_size > (size_t) (unit_end - hdrptr)) | |
10615 | goto too_short; | |
10616 | ||
10617 | printf (_("Augmentation string:")); | |
10618 | ||
10619 | augmentation_printable = true; | |
10620 | augmentation_string = (const char *) hdrptr; | |
10621 | ||
10622 | for (i = 0; i < augmentation_string_size; i++) | |
10623 | { | |
10624 | unsigned char uc; | |
10625 | ||
10626 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
10627 | printf (" %02x", uc); | |
10628 | ||
10629 | if (uc != 0 && !ISPRINT (uc)) | |
10630 | augmentation_printable = false; | |
10631 | } | |
10632 | ||
10633 | if (augmentation_printable) | |
10634 | { | |
10635 | printf (" (\""); | |
10636 | for (i = 0; | |
10637 | i < augmentation_string_size && augmentation_string[i]; | |
10638 | ++i) | |
10639 | putchar (augmentation_string[i]); | |
10640 | printf ("\")"); | |
10641 | } | |
10642 | putchar ('\n'); | |
10643 | ||
10644 | printf (_("CU table:\n")); | |
10645 | if (_mul_overflow (comp_unit_count, offset_size, &total) | |
10646 | || total > (size_t) (unit_end - hdrptr)) | |
10647 | goto too_short; | |
10648 | for (i = 0; i < comp_unit_count; i++) | |
10649 | { | |
10650 | uint64_t cu_offset; | |
10651 | ||
10652 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
10653 | printf ("[%3u] %#" PRIx64 "\n", i, cu_offset); | |
10654 | } | |
10655 | putchar ('\n'); | |
10656 | ||
10657 | printf (_("TU table:\n")); | |
10658 | if (_mul_overflow (local_type_unit_count, offset_size, &total) | |
10659 | || total > (size_t) (unit_end - hdrptr)) | |
10660 | goto too_short; | |
10661 | for (i = 0; i < local_type_unit_count; i++) | |
10662 | { | |
10663 | uint64_t tu_offset; | |
10664 | ||
10665 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
10666 | printf ("[%3u] %#" PRIx64 "\n", i, tu_offset); | |
10667 | } | |
10668 | putchar ('\n'); | |
10669 | ||
10670 | printf (_("Foreign TU table:\n")); | |
10671 | if (_mul_overflow (foreign_type_unit_count, 8, &total) | |
10672 | || total > (size_t) (unit_end - hdrptr)) | |
10673 | goto too_short; | |
10674 | for (i = 0; i < foreign_type_unit_count; i++) | |
10675 | { | |
10676 | uint64_t signature; | |
10677 | ||
10678 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
10679 | printf (_("[%3u] "), i); | |
10680 | print_hex_ns (signature, 8); | |
10681 | putchar ('\n'); | |
10682 | } | |
10683 | putchar ('\n'); | |
10684 | ||
10685 | uint64_t xtra = (bucket_count * sizeof (uint32_t) | |
10686 | + name_count * (sizeof (uint32_t) + 2 * offset_size) | |
10687 | + abbrev_table_size); | |
10688 | if (xtra > (size_t) (unit_end - hdrptr)) | |
10689 | { | |
10690 | warn (_("Entry pool offset (%#" PRIx64 ") exceeds unit size %#tx " | |
10691 | "for unit %#tx in the debug_names\n"), | |
10692 | xtra, unit_end - unit_start, unit_start - section->start); | |
10693 | return 0; | |
10694 | } | |
10695 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
10696 | hdrptr += bucket_count * sizeof (uint32_t); | |
10697 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
10698 | if (bucket_count != 0) | |
10699 | hdrptr += name_count * sizeof (uint32_t); | |
10700 | unsigned char *const name_table_string_offsets = hdrptr; | |
10701 | hdrptr += name_count * offset_size; | |
10702 | unsigned char *const name_table_entry_offsets = hdrptr; | |
10703 | hdrptr += name_count * offset_size; | |
10704 | unsigned char *const abbrev_table = hdrptr; | |
10705 | hdrptr += abbrev_table_size; | |
10706 | const unsigned char *const abbrev_table_end = hdrptr; | |
10707 | unsigned char *const entry_pool = hdrptr; | |
10708 | ||
10709 | size_t buckets_filled = 0; | |
10710 | size_t bucketi; | |
10711 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
10712 | { | |
10713 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
10714 | ||
10715 | if (bucket != 0) | |
10716 | ++buckets_filled; | |
10717 | } | |
10718 | printf (ngettext ("Used %zu of %lu bucket.\n", | |
10719 | "Used %zu of %lu buckets.\n", | |
10720 | (unsigned long) bucket_count), | |
10721 | buckets_filled, (unsigned long) bucket_count); | |
10722 | ||
10723 | if (bucket_count != 0) | |
10724 | { | |
10725 | uint32_t hash_prev = 0; | |
10726 | size_t hash_clash_count = 0; | |
10727 | size_t longest_clash = 0; | |
10728 | size_t this_length = 0; | |
10729 | size_t hashi; | |
10730 | for (hashi = 0; hashi < name_count; hashi++) | |
10731 | { | |
10732 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
10733 | ||
10734 | if (hashi > 0) | |
10735 | { | |
10736 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
10737 | { | |
10738 | ++hash_clash_count; | |
10739 | ++this_length; | |
10740 | longest_clash = MAX (longest_clash, this_length); | |
10741 | } | |
10742 | else | |
10743 | this_length = 0; | |
10744 | } | |
10745 | hash_prev = hash_this; | |
10746 | } | |
10747 | printf (_("Out of %" PRIu64 " items there are %zu bucket clashes" | |
10748 | " (longest of %zu entries).\n"), | |
10749 | name_count, hash_clash_count, longest_clash); | |
10750 | ||
10751 | if (name_count != buckets_filled + hash_clash_count) | |
10752 | warn (_("The name_count (%" PRIu64 ")" | |
10753 | " is not the same as the used bucket_count" | |
10754 | " (%zu) + the hash clash count (%zu)\n"), | |
10755 | name_count, buckets_filled, hash_clash_count); | |
10756 | } | |
10757 | ||
10758 | struct abbrev_lookup_entry | |
10759 | { | |
10760 | uint64_t abbrev_tag; | |
10761 | unsigned char *abbrev_lookup_ptr; | |
10762 | }; | |
10763 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
10764 | size_t abbrev_lookup_used = 0; | |
10765 | size_t abbrev_lookup_allocated = 0; | |
10766 | ||
10767 | unsigned char *abbrevptr = abbrev_table; | |
10768 | for (;;) | |
10769 | { | |
10770 | uint64_t abbrev_tag; | |
10771 | ||
10772 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
10773 | if (abbrev_tag == 0) | |
10774 | break; | |
10775 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
10776 | { | |
10777 | abbrev_lookup_allocated = MAX (0x100, | |
10778 | abbrev_lookup_allocated * 2); | |
10779 | abbrev_lookup = xrealloc (abbrev_lookup, | |
10780 | (abbrev_lookup_allocated | |
10781 | * sizeof (*abbrev_lookup))); | |
10782 | } | |
10783 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
10784 | struct abbrev_lookup_entry *entry; | |
10785 | for (entry = abbrev_lookup; | |
10786 | entry < abbrev_lookup + abbrev_lookup_used; | |
10787 | entry++) | |
10788 | if (entry->abbrev_tag == abbrev_tag) | |
10789 | { | |
10790 | warn (_("Duplicate abbreviation tag %" PRIu64 | |
10791 | " in unit %#tx in the debug_names section\n"), | |
10792 | abbrev_tag, unit_start - section->start); | |
10793 | break; | |
10794 | } | |
10795 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
10796 | entry->abbrev_tag = abbrev_tag; | |
10797 | entry->abbrev_lookup_ptr = abbrevptr; | |
10798 | ||
10799 | /* Skip DWARF tag. */ | |
10800 | SKIP_ULEB (abbrevptr, abbrev_table_end); | |
10801 | for (;;) | |
10802 | { | |
10803 | uint64_t xindex, form; | |
10804 | ||
10805 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
10806 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
10807 | if (xindex == 0 && form == 0) | |
10808 | break; | |
10809 | } | |
10810 | } | |
10811 | ||
10812 | printf (_("\nSymbol table:\n")); | |
10813 | uint32_t namei; | |
10814 | for (namei = 0; namei < name_count; ++namei) | |
10815 | { | |
10816 | uint64_t string_offset, entry_offset; | |
10817 | unsigned char *p; | |
10818 | /* We need to scan first whether there is a single or multiple | |
10819 | entries. TAGNO is -2 for the first entry, it is -1 for the | |
10820 | initial tag read of the second entry, then it becomes 0 for the | |
10821 | first entry for real printing etc. */ | |
10822 | int tagno = -2; | |
10823 | /* Initialize it due to a false compiler warning. */ | |
10824 | uint64_t second_abbrev_tag = -1; | |
10825 | unsigned char *entryptr; | |
10826 | ||
10827 | p = name_table_string_offsets + namei * offset_size; | |
10828 | SAFE_BYTE_GET (string_offset, p, offset_size, unit_end); | |
10829 | ||
10830 | p = name_table_entry_offsets + namei * offset_size; | |
10831 | SAFE_BYTE_GET (entry_offset, p, offset_size, unit_end); | |
10832 | ||
10833 | /* The name table is indexed starting at 1 according to | |
10834 | DWARF, so be sure to use the DWARF numbering here. */ | |
10835 | printf ("[%3u] ", namei + 1); | |
10836 | if (bucket_count != 0) | |
10837 | printf ("#%08x ", hash_table_hashes[namei]); | |
10838 | ||
10839 | printf ("%s:", fetch_indirect_string (string_offset)); | |
10840 | ||
10841 | entryptr = entry_pool + entry_offset; | |
10842 | /* PR 31456: Check for invalid entry offset. */ | |
10843 | if (entryptr < entry_pool || entryptr >= unit_end) | |
10844 | { | |
10845 | warn (_("Invalid entry offset value: %" PRIx64 "\n"), entry_offset); | |
10846 | break; | |
10847 | } | |
10848 | ||
10849 | for (;;) | |
10850 | { | |
10851 | uint64_t abbrev_tag; | |
10852 | uint64_t dwarf_tag; | |
10853 | const struct abbrev_lookup_entry *entry; | |
10854 | uint64_t this_entry = entryptr - entry_pool; | |
10855 | ||
10856 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
10857 | if (tagno == -1) | |
10858 | { | |
10859 | second_abbrev_tag = abbrev_tag; | |
10860 | tagno = 0; | |
10861 | entryptr = entry_pool + entry_offset; | |
10862 | continue; | |
10863 | } | |
10864 | if (abbrev_tag == 0) | |
10865 | break; | |
10866 | if (tagno >= 0) | |
10867 | printf ("%s<%#" PRIx64 "><%" PRIu64 ">", | |
10868 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
10869 | this_entry, abbrev_tag); | |
10870 | ||
10871 | for (entry = abbrev_lookup; | |
10872 | entry < abbrev_lookup + abbrev_lookup_used; | |
10873 | entry++) | |
10874 | if (entry->abbrev_tag == abbrev_tag) | |
10875 | break; | |
10876 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
10877 | { | |
10878 | warn (_("Undefined abbreviation tag %" PRId64 | |
10879 | " in unit %#tx in the debug_names section\n"), | |
10880 | abbrev_tag, | |
10881 | unit_start - section->start); | |
10882 | break; | |
10883 | } | |
10884 | abbrevptr = entry->abbrev_lookup_ptr; | |
10885 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); | |
10886 | if (tagno >= 0) | |
10887 | printf (" %s", get_TAG_name (dwarf_tag)); | |
10888 | for (;;) | |
10889 | { | |
10890 | uint64_t xindex, form; | |
10891 | ||
10892 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
10893 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
10894 | if (xindex == 0 && form == 0) | |
10895 | break; | |
10896 | ||
10897 | if (tagno >= 0) | |
10898 | printf (" %s", get_IDX_name (xindex)); | |
10899 | entryptr = read_and_display_attr_value (0, form, 0, | |
10900 | unit_start, entryptr, unit_end, | |
10901 | 0, 0, offset_size, | |
10902 | dwarf_version, NULL, | |
10903 | (tagno < 0), section, | |
10904 | NULL, '=', -1); | |
10905 | } | |
10906 | ++tagno; | |
10907 | } | |
10908 | if (tagno <= 0) | |
10909 | printf (_(" <no entries>")); | |
10910 | putchar ('\n'); | |
10911 | } | |
10912 | ||
10913 | free (abbrev_lookup); | |
10914 | } | |
10915 | ||
10916 | return 1; | |
10917 | } | |
10918 | ||
10919 | static int | |
10920 | display_debug_links (struct dwarf_section * section, | |
10921 | void * file ATTRIBUTE_UNUSED) | |
10922 | { | |
10923 | const unsigned char * filename; | |
10924 | unsigned int filelen; | |
10925 | ||
10926 | introduce (section, false); | |
10927 | ||
10928 | /* The .gnu_debuglink section is formatted as: | |
10929 | (c-string) Filename. | |
10930 | (padding) If needed to reach a 4 byte boundary. | |
10931 | (uint32_t) CRC32 value. | |
10932 | ||
10933 | The .gnu_debugaltlink section is formatted as: | |
10934 | (c-string) Filename. | |
10935 | (binary) Build-ID. */ | |
10936 | ||
10937 | filename = section->start; | |
10938 | filelen = strnlen ((const char *) filename, section->size); | |
10939 | if (filelen == section->size) | |
10940 | { | |
10941 | warn (_("The debuglink filename is corrupt/missing\n")); | |
10942 | return 0; | |
10943 | } | |
10944 | ||
10945 | printf (_(" Separate debug info file: %s\n"), filename); | |
10946 | ||
10947 | if (startswith (section->name, ".gnu_debuglink")) | |
10948 | { | |
10949 | unsigned int crc32; | |
10950 | unsigned int crc_offset; | |
10951 | ||
10952 | crc_offset = filelen + 1; | |
10953 | crc_offset = (crc_offset + 3) & ~3; | |
10954 | if (crc_offset + 4 > section->size) | |
10955 | { | |
10956 | warn (_("CRC offset missing/truncated\n")); | |
10957 | return 0; | |
10958 | } | |
10959 | ||
10960 | crc32 = byte_get (filename + crc_offset, 4); | |
10961 | ||
10962 | printf (_(" CRC value: %#x\n"), crc32); | |
10963 | ||
10964 | if (crc_offset + 4 < section->size) | |
10965 | { | |
10966 | warn (_("There are %#" PRIx64 | |
10967 | " extraneous bytes at the end of the section\n"), | |
10968 | section->size - (crc_offset + 4)); | |
10969 | return 0; | |
10970 | } | |
10971 | } | |
10972 | else /* startswith (section->name, ".gnu_debugaltlink") */ | |
10973 | { | |
10974 | const unsigned char *build_id = section->start + filelen + 1; | |
10975 | size_t build_id_len = section->size - (filelen + 1); | |
10976 | size_t printed; | |
10977 | ||
10978 | /* FIXME: Should we support smaller build-id notes ? */ | |
10979 | if (build_id_len < 0x14) | |
10980 | { | |
10981 | warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len); | |
10982 | return 0; | |
10983 | } | |
10984 | ||
10985 | printed = printf (_(" Build-ID (%#zx bytes):"), build_id_len); | |
10986 | display_data (printed, build_id, build_id_len); | |
10987 | putchar ('\n'); | |
10988 | } | |
10989 | ||
10990 | putchar ('\n'); | |
10991 | return 1; | |
10992 | } | |
10993 | ||
10994 | static int | |
10995 | display_gdb_index (struct dwarf_section *section, | |
10996 | void *file ATTRIBUTE_UNUSED) | |
10997 | { | |
10998 | unsigned char *start = section->start; | |
10999 | uint32_t version; | |
11000 | uint32_t cu_list_offset, tu_list_offset; | |
11001 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset, | |
11002 | shortcut_table_offset; | |
11003 | unsigned int cu_list_elements, tu_list_elements; | |
11004 | unsigned int address_table_elements, symbol_table_slots; | |
11005 | unsigned char *cu_list, *tu_list; | |
11006 | unsigned char *address_table, *symbol_table, *shortcut_table, *constant_pool; | |
11007 | unsigned int i; | |
11008 | ||
11009 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
11010 | ||
11011 | introduce (section, false); | |
11012 | ||
11013 | version = section->size < 4 ? 0 : byte_get_little_endian (start, 4); | |
11014 | size_t header_size = (version < 9 ? 6 : 7) * sizeof (uint32_t); | |
11015 | if (section->size < header_size) | |
11016 | { | |
11017 | warn (_("Truncated header in the %s section.\n"), section->name); | |
11018 | return 0; | |
11019 | } | |
11020 | ||
11021 | printf (_("Version %lu\n"), (unsigned long) version); | |
11022 | ||
11023 | /* Prior versions are obsolete, and future versions may not be | |
11024 | backwards compatible. */ | |
11025 | if (version < 3 || version > 9) | |
11026 | { | |
11027 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); | |
11028 | return 0; | |
11029 | } | |
11030 | if (version < 4) | |
11031 | warn (_("The address table data in version 3 may be wrong.\n")); | |
11032 | if (version < 5) | |
11033 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
11034 | if (version < 6) | |
11035 | warn (_("Version 5 does not include inlined functions.\n")); | |
11036 | if (version < 7) | |
11037 | warn (_("Version 6 does not include symbol attributes.\n")); | |
11038 | /* Version 7 indices generated by Gold have bad type unit references, | |
11039 | PR binutils/15021. But we don't know if the index was generated by | |
11040 | Gold or not, so to avoid worrying users with gdb-generated indices | |
11041 | we say nothing for version 7 here. */ | |
11042 | ||
11043 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
11044 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
11045 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
11046 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
11047 | shortcut_table_offset = byte_get_little_endian (start + 20, 4); | |
11048 | if (version < 9) | |
11049 | constant_pool_offset = shortcut_table_offset; | |
11050 | else | |
11051 | constant_pool_offset = byte_get_little_endian (start + 24, 4); | |
11052 | ||
11053 | if (cu_list_offset > section->size | |
11054 | || tu_list_offset > section->size | |
11055 | || address_table_offset > section->size | |
11056 | || symbol_table_offset > section->size | |
11057 | || shortcut_table_offset > section->size | |
11058 | || constant_pool_offset > section->size | |
11059 | || tu_list_offset < cu_list_offset | |
11060 | || address_table_offset < tu_list_offset | |
11061 | || symbol_table_offset < address_table_offset | |
11062 | || shortcut_table_offset < symbol_table_offset | |
11063 | || constant_pool_offset < shortcut_table_offset) | |
11064 | { | |
11065 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
11066 | return 0; | |
11067 | } | |
11068 | ||
11069 | cu_list_elements = (tu_list_offset - cu_list_offset) / 16; | |
11070 | tu_list_elements = (address_table_offset - tu_list_offset) / 24; | |
11071 | address_table_elements = (symbol_table_offset - address_table_offset) / 20; | |
11072 | symbol_table_slots = (shortcut_table_offset - symbol_table_offset) / 8; | |
11073 | ||
11074 | cu_list = start + cu_list_offset; | |
11075 | tu_list = start + tu_list_offset; | |
11076 | address_table = start + address_table_offset; | |
11077 | symbol_table = start + symbol_table_offset; | |
11078 | shortcut_table = start + shortcut_table_offset; | |
11079 | constant_pool = start + constant_pool_offset; | |
11080 | ||
11081 | printf (_("\nCU table:\n")); | |
11082 | for (i = 0; i < cu_list_elements; i++) | |
11083 | { | |
11084 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 16, 8); | |
11085 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 16 + 8, 8); | |
11086 | ||
11087 | printf ("[%3u] %#" PRIx64 " - %#" PRIx64 "\n", | |
11088 | i, cu_offset, cu_offset + cu_length - 1); | |
11089 | } | |
11090 | ||
11091 | printf (_("\nTU table:\n")); | |
11092 | for (i = 0; i < tu_list_elements; i++) | |
11093 | { | |
11094 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 24, 8); | |
11095 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 24 + 8, 8); | |
11096 | uint64_t signature = byte_get_little_endian (tu_list + i * 24 + 16, 8); | |
11097 | ||
11098 | printf ("[%3u] %#" PRIx64 " %#" PRIx64 " ", | |
11099 | i, tu_offset, type_offset); | |
11100 | print_hex_ns (signature, 8); | |
11101 | printf ("\n"); | |
11102 | } | |
11103 | ||
11104 | printf (_("\nAddress table:\n")); | |
11105 | for (i = 0; i < address_table_elements; i++) | |
11106 | { | |
11107 | uint64_t low = byte_get_little_endian (address_table + i * 20, 8); | |
11108 | uint64_t high = byte_get_little_endian (address_table + i * 20 + 8, 8); | |
11109 | uint32_t cu_index = byte_get_little_endian (address_table + i * 20 + 16, 4); | |
11110 | ||
11111 | print_hex (low, 8); | |
11112 | print_hex (high, 8); | |
11113 | printf ("%" PRIu32 "\n", cu_index); | |
11114 | } | |
11115 | ||
11116 | printf (_("\nSymbol table:\n")); | |
11117 | for (i = 0; i < symbol_table_slots; ++i) | |
11118 | { | |
11119 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
11120 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
11121 | uint32_t num_cus, cu; | |
11122 | ||
11123 | if (name_offset != 0 | |
11124 | || cu_vector_offset != 0) | |
11125 | { | |
11126 | unsigned int j; | |
11127 | ||
11128 | /* PR 17531: file: 5b7b07ad. */ | |
11129 | if (name_offset >= section->size - constant_pool_offset) | |
11130 | { | |
11131 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
11132 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
11133 | name_offset, i); | |
11134 | } | |
11135 | else | |
11136 | printf ("[%3u] %.*s:", i, | |
11137 | (int) (section->size - (constant_pool_offset + name_offset)), | |
11138 | constant_pool + name_offset); | |
11139 | ||
11140 | if (section->size - constant_pool_offset < 4 | |
11141 | || cu_vector_offset > section->size - constant_pool_offset - 4) | |
11142 | { | |
11143 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
11144 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
11145 | cu_vector_offset, i); | |
11146 | continue; | |
11147 | } | |
11148 | ||
11149 | num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4); | |
11150 | ||
11151 | if ((uint64_t) num_cus * 4 > section->size - (constant_pool_offset | |
11152 | + cu_vector_offset + 4)) | |
11153 | { | |
11154 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
11155 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), | |
11156 | num_cus, i); | |
11157 | continue; | |
11158 | } | |
11159 | ||
11160 | if (num_cus > 1) | |
11161 | printf ("\n"); | |
11162 | ||
11163 | for (j = 0; j < num_cus; ++j) | |
11164 | { | |
11165 | int is_static; | |
11166 | gdb_index_symbol_kind kind; | |
11167 | ||
11168 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); | |
11169 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); | |
11170 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); | |
11171 | cu = GDB_INDEX_CU_VALUE (cu); | |
11172 | /* Convert to TU number if it's for a type unit. */ | |
11173 | if (cu >= cu_list_elements) | |
11174 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', | |
11175 | (unsigned long) cu - cu_list_elements); | |
11176 | else | |
11177 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); | |
11178 | ||
11179 | printf (" [%s, %s]", | |
11180 | is_static ? _("static") : _("global"), | |
11181 | get_gdb_index_symbol_kind_name (kind)); | |
11182 | if (num_cus > 1) | |
11183 | printf ("\n"); | |
11184 | } | |
11185 | if (num_cus <= 1) | |
11186 | printf ("\n"); | |
11187 | } | |
11188 | } | |
11189 | ||
11190 | if (version >= 9) | |
11191 | { | |
11192 | printf (_("\nShortcut table:\n")); | |
11193 | ||
11194 | if (shortcut_table_offset + 8 > constant_pool_offset) | |
11195 | { | |
11196 | warn (_("Corrupt shortcut table in the %s section.\n"), section->name); | |
11197 | return 0; | |
11198 | } | |
11199 | ||
11200 | uint32_t lang = byte_get_little_endian (shortcut_table, 4); | |
11201 | printf (_("Language of main: ")); | |
11202 | display_lang (lang); | |
11203 | printf ("\n"); | |
11204 | ||
11205 | printf (_("Name of main: ")); | |
11206 | if (lang == 0) | |
11207 | printf (_("<unknown>\n")); | |
11208 | else | |
11209 | { | |
11210 | uint32_t name_offset = byte_get_little_endian (shortcut_table + 4, 4); | |
11211 | if (name_offset >= section->size - constant_pool_offset) | |
11212 | { | |
11213 | printf (_("<corrupt offset: %x>\n"), name_offset); | |
11214 | warn (_("Corrupt name offset of 0x%x found for name of main\n"), | |
11215 | name_offset); | |
11216 | } | |
11217 | else | |
11218 | printf ("%s\n", constant_pool + name_offset); | |
11219 | } | |
11220 | } | |
11221 | ||
11222 | return 1; | |
11223 | } | |
11224 | ||
11225 | /* Pre-allocate enough space for the CU/TU sets needed. */ | |
11226 | ||
11227 | static void | |
11228 | prealloc_cu_tu_list (unsigned int nshndx) | |
11229 | { | |
11230 | if (nshndx == 0) | |
11231 | /* Always allocate at least one entry for the end-marker. */ | |
11232 | nshndx = 1; | |
11233 | ||
11234 | if (shndx_pool == NULL) | |
11235 | { | |
11236 | shndx_pool_size = nshndx; | |
11237 | shndx_pool_used = 0; | |
11238 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
11239 | sizeof (unsigned int)); | |
11240 | } | |
11241 | else | |
11242 | { | |
11243 | shndx_pool_size = shndx_pool_used + nshndx; | |
11244 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
11245 | sizeof (unsigned int)); | |
11246 | } | |
11247 | } | |
11248 | ||
11249 | static void | |
11250 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
11251 | { | |
11252 | shndx_pool [shndx_pool_used++] = shndx; | |
11253 | } | |
11254 | ||
11255 | static void | |
11256 | end_cu_tu_entry (void) | |
11257 | { | |
11258 | shndx_pool [shndx_pool_used++] = 0; | |
11259 | } | |
11260 | ||
11261 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ | |
11262 | ||
11263 | static const char * | |
11264 | get_DW_SECT_short_name (unsigned int dw_sect) | |
11265 | { | |
11266 | static char buf[16]; | |
11267 | ||
11268 | switch (dw_sect) | |
11269 | { | |
11270 | case DW_SECT_INFO: | |
11271 | return "info"; | |
11272 | case DW_SECT_TYPES: | |
11273 | return "types"; | |
11274 | case DW_SECT_ABBREV: | |
11275 | return "abbrev"; | |
11276 | case DW_SECT_LINE: | |
11277 | return "line"; | |
11278 | case DW_SECT_LOC: | |
11279 | return "loc"; | |
11280 | case DW_SECT_STR_OFFSETS: | |
11281 | return "str_off"; | |
11282 | case DW_SECT_MACINFO: | |
11283 | return "macinfo"; | |
11284 | case DW_SECT_MACRO: | |
11285 | return "macro"; | |
11286 | default: | |
11287 | break; | |
11288 | } | |
11289 | ||
11290 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
11291 | return buf; | |
11292 | } | |
11293 | ||
11294 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
11295 | These sections are extensions for Fission. | |
11296 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
11297 | ||
11298 | static bool | |
11299 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
11300 | { | |
11301 | unsigned char *phdr = section->start; | |
11302 | unsigned char *limit = phdr + section->size; | |
11303 | unsigned char *phash; | |
11304 | unsigned char *pindex; | |
11305 | unsigned char *ppool; | |
11306 | unsigned int version; | |
11307 | unsigned int ncols = 0; | |
11308 | unsigned int nused; | |
11309 | unsigned int nslots; | |
11310 | unsigned int i; | |
11311 | unsigned int j; | |
11312 | uint64_t signature; | |
11313 | size_t total; | |
11314 | ||
11315 | /* PR 17512: file: 002-168123-0.004. */ | |
11316 | if (phdr == NULL) | |
11317 | { | |
11318 | warn (_("Section %s is empty\n"), section->name); | |
11319 | return false; | |
11320 | } | |
11321 | /* PR 17512: file: 002-376-0.004. */ | |
11322 | if (section->size < 24) | |
11323 | { | |
11324 | warn (_("Section %s is too small to contain a CU/TU header\n"), | |
11325 | section->name); | |
11326 | return false; | |
11327 | } | |
11328 | ||
11329 | phash = phdr; | |
11330 | SAFE_BYTE_GET_AND_INC (version, phash, 4, limit); | |
11331 | if (version >= 2) | |
11332 | SAFE_BYTE_GET_AND_INC (ncols, phash, 4, limit); | |
11333 | SAFE_BYTE_GET_AND_INC (nused, phash, 4, limit); | |
11334 | SAFE_BYTE_GET_AND_INC (nslots, phash, 4, limit); | |
11335 | ||
11336 | pindex = phash + (size_t) nslots * 8; | |
11337 | ppool = pindex + (size_t) nslots * 4; | |
11338 | ||
11339 | if (do_display) | |
11340 | { | |
11341 | introduce (section, false); | |
11342 | ||
11343 | printf (_(" Version: %u\n"), version); | |
11344 | if (version >= 2) | |
11345 | printf (_(" Number of columns: %u\n"), ncols); | |
11346 | printf (_(" Number of used entries: %u\n"), nused); | |
11347 | printf (_(" Number of slots: %u\n\n"), nslots); | |
11348 | } | |
11349 | ||
11350 | /* PR 17531: file: 45d69832. */ | |
11351 | if (_mul_overflow ((size_t) nslots, 12, &total) | |
11352 | || total > (size_t) (limit - phash)) | |
11353 | { | |
11354 | warn (ngettext ("Section %s is too small for %u slot\n", | |
11355 | "Section %s is too small for %u slots\n", | |
11356 | nslots), | |
11357 | section->name, nslots); | |
11358 | return false; | |
11359 | } | |
11360 | ||
11361 | if (version == 1) | |
11362 | { | |
11363 | unsigned char *shndx_list; | |
11364 | unsigned int shndx; | |
11365 | ||
11366 | if (!do_display) | |
11367 | { | |
11368 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
11369 | for (shndx_list = ppool + 4; shndx_list <= limit - 4; shndx_list += 4) | |
11370 | { | |
11371 | shndx = byte_get (shndx_list, 4); | |
11372 | add_shndx_to_cu_tu_entry (shndx); | |
11373 | } | |
11374 | end_cu_tu_entry (); | |
11375 | } | |
11376 | else | |
11377 | for (i = 0; i < nslots; i++) | |
11378 | { | |
11379 | SAFE_BYTE_GET (signature, phash, 8, limit); | |
11380 | if (signature != 0) | |
11381 | { | |
11382 | SAFE_BYTE_GET (j, pindex, 4, limit); | |
11383 | shndx_list = ppool + j * 4; | |
11384 | /* PR 17531: file: 705e010d. */ | |
11385 | if (shndx_list < ppool) | |
11386 | { | |
11387 | warn (_("Section index pool located before start of section\n")); | |
11388 | return false; | |
11389 | } | |
11390 | ||
11391 | printf (_(" [%3d] Signature: %#" PRIx64 " Sections: "), | |
11392 | i, signature); | |
11393 | for (;;) | |
11394 | { | |
11395 | if (shndx_list >= limit) | |
11396 | { | |
11397 | warn (_("Section %s too small for shndx pool\n"), | |
11398 | section->name); | |
11399 | return false; | |
11400 | } | |
11401 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); | |
11402 | if (shndx == 0) | |
11403 | break; | |
11404 | printf (" %d", shndx); | |
11405 | shndx_list += 4; | |
11406 | } | |
11407 | printf ("\n"); | |
11408 | } | |
11409 | phash += 8; | |
11410 | pindex += 4; | |
11411 | } | |
11412 | } | |
11413 | else if (version == 2) | |
11414 | { | |
11415 | unsigned int val; | |
11416 | unsigned int dw_sect; | |
11417 | unsigned char *ph = phash; | |
11418 | unsigned char *pi = pindex; | |
11419 | unsigned char *poffsets = ppool + (size_t) ncols * 4; | |
11420 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
11421 | bool is_tu_index; | |
11422 | struct cu_tu_set *this_set = NULL; | |
11423 | unsigned int row; | |
11424 | unsigned char *prow; | |
11425 | size_t temp; | |
11426 | ||
11427 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
11428 | ||
11429 | /* PR 17531: file: 0dd159bf. | |
11430 | Check for integer overflow (can occur when size_t is 32-bit) | |
11431 | with overlarge ncols or nused values. */ | |
11432 | if (nused == -1u | |
11433 | || _mul_overflow ((size_t) ncols, 4, &temp) | |
11434 | || _mul_overflow ((size_t) nused + 1, temp, &total) | |
11435 | || total > (size_t) (limit - ppool) | |
11436 | /* PR 30227: ncols could be 0. */ | |
11437 | || _mul_overflow ((size_t) nused + 1, 4, &total) | |
11438 | || total > (size_t) (limit - ppool)) | |
11439 | { | |
11440 | warn (_("Section %s too small for offset and size tables\n"), | |
11441 | section->name); | |
11442 | return false; | |
11443 | } | |
11444 | ||
11445 | if (do_display) | |
11446 | { | |
11447 | printf (_(" Offset table\n")); | |
11448 | printf (" slot %-16s ", | |
11449 | is_tu_index ? _("signature") : _("dwo_id")); | |
11450 | } | |
11451 | else | |
11452 | { | |
11453 | if (is_tu_index) | |
11454 | { | |
11455 | tu_count = nused; | |
11456 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); | |
11457 | this_set = tu_sets; | |
11458 | } | |
11459 | else | |
11460 | { | |
11461 | cu_count = nused; | |
11462 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); | |
11463 | this_set = cu_sets; | |
11464 | } | |
11465 | } | |
11466 | ||
11467 | if (do_display) | |
11468 | { | |
11469 | for (j = 0; j < ncols; j++) | |
11470 | { | |
11471 | unsigned char *p = ppool + j * 4; | |
11472 | SAFE_BYTE_GET (dw_sect, p, 4, limit); | |
11473 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); | |
11474 | } | |
11475 | printf ("\n"); | |
11476 | } | |
11477 | ||
11478 | for (i = 0; i < nslots; i++) | |
11479 | { | |
11480 | SAFE_BYTE_GET (signature, ph, 8, limit); | |
11481 | ||
11482 | SAFE_BYTE_GET (row, pi, 4, limit); | |
11483 | if (row != 0) | |
11484 | { | |
11485 | /* PR 17531: file: a05f6ab3. */ | |
11486 | if (row > nused) | |
11487 | { | |
11488 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
11489 | row, nused); | |
11490 | return false; | |
11491 | } | |
11492 | ||
11493 | if (!do_display) | |
11494 | { | |
11495 | size_t num_copy = sizeof (uint64_t); | |
11496 | ||
11497 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
11498 | } | |
11499 | ||
11500 | prow = poffsets + (row - 1) * ncols * 4; | |
11501 | if (do_display) | |
11502 | printf (" [%3d] %#" PRIx64, i, signature); | |
11503 | for (j = 0; j < ncols; j++) | |
11504 | { | |
11505 | unsigned char *p = prow + j * 4; | |
11506 | SAFE_BYTE_GET (val, p, 4, limit); | |
11507 | if (do_display) | |
11508 | printf (" %8d", val); | |
11509 | else | |
11510 | { | |
11511 | p = ppool + j * 4; | |
11512 | SAFE_BYTE_GET (dw_sect, p, 4, limit); | |
11513 | ||
11514 | /* PR 17531: file: 10796eb3. */ | |
11515 | if (dw_sect >= DW_SECT_MAX) | |
11516 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
11517 | else | |
11518 | this_set [row - 1].section_offsets [dw_sect] = val; | |
11519 | } | |
11520 | } | |
11521 | ||
11522 | if (do_display) | |
11523 | printf ("\n"); | |
11524 | } | |
11525 | ph += 8; | |
11526 | pi += 4; | |
11527 | } | |
11528 | ||
11529 | ph = phash; | |
11530 | pi = pindex; | |
11531 | if (do_display) | |
11532 | { | |
11533 | printf ("\n"); | |
11534 | printf (_(" Size table\n")); | |
11535 | printf (" slot %-16s ", | |
11536 | is_tu_index ? _("signature") : _("dwo_id")); | |
11537 | } | |
11538 | ||
11539 | for (j = 0; j < ncols; j++) | |
11540 | { | |
11541 | unsigned char *p = ppool + j * 4; | |
11542 | SAFE_BYTE_GET (val, p, 4, limit); | |
11543 | if (do_display) | |
11544 | printf (" %8s", get_DW_SECT_short_name (val)); | |
11545 | } | |
11546 | ||
11547 | if (do_display) | |
11548 | printf ("\n"); | |
11549 | ||
11550 | for (i = 0; i < nslots; i++) | |
11551 | { | |
11552 | SAFE_BYTE_GET (signature, ph, 8, limit); | |
11553 | ||
11554 | SAFE_BYTE_GET (row, pi, 4, limit); | |
11555 | if (row != 0) | |
11556 | { | |
11557 | prow = psizes + (row - 1) * ncols * 4; | |
11558 | ||
11559 | if (do_display) | |
11560 | printf (" [%3d] %#" PRIx64, i, signature); | |
11561 | ||
11562 | for (j = 0; j < ncols; j++) | |
11563 | { | |
11564 | unsigned char *p = prow + j * 4; | |
11565 | ||
11566 | /* PR 28645: Check for overflow. Since we do not know how | |
11567 | many populated rows there will be, we cannot just | |
11568 | perform a single check at the start of this function. */ | |
11569 | if (p > (limit - 4)) | |
11570 | { | |
11571 | if (do_display) | |
11572 | printf ("\n"); | |
11573 | warn (_("Too many rows/columns in DWARF index section %s\n"), | |
11574 | section->name); | |
11575 | return false; | |
11576 | } | |
11577 | ||
11578 | SAFE_BYTE_GET (val, p, 4, limit); | |
11579 | ||
11580 | if (do_display) | |
11581 | printf (" %8d", val); | |
11582 | else | |
11583 | { | |
11584 | p = ppool + j * 4; | |
11585 | SAFE_BYTE_GET (dw_sect, p, 4, limit); | |
11586 | if (dw_sect >= DW_SECT_MAX) | |
11587 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
11588 | else | |
11589 | this_set [row - 1].section_sizes [dw_sect] = val; | |
11590 | } | |
11591 | } | |
11592 | ||
11593 | if (do_display) | |
11594 | printf ("\n"); | |
11595 | } | |
11596 | ||
11597 | ph += 8; | |
11598 | pi += 4; | |
11599 | } | |
11600 | } | |
11601 | else if (do_display) | |
11602 | printf (_(" Unsupported version (%d)\n"), version); | |
11603 | ||
11604 | if (do_display) | |
11605 | printf ("\n"); | |
11606 | ||
11607 | return true; | |
11608 | } | |
11609 | ||
11610 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ | |
11611 | ||
11612 | /* Load the CU and TU indexes if present. This will build a list of | |
11613 | section sets that we can use to associate a .debug_info.dwo section | |
11614 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
11615 | ||
11616 | static bool | |
11617 | load_cu_tu_indexes (void *file) | |
11618 | { | |
11619 | /* If we have already loaded (or tried to load) the CU and TU indexes | |
11620 | then do not bother to repeat the task. */ | |
11621 | if (cu_tu_indexes_read == -1) | |
11622 | { | |
11623 | cu_tu_indexes_read = true; | |
11624 | ||
11625 | if (load_debug_section_with_follow (dwp_cu_index, file)) | |
11626 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) | |
11627 | cu_tu_indexes_read = false; | |
11628 | ||
11629 | if (load_debug_section_with_follow (dwp_tu_index, file)) | |
11630 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) | |
11631 | cu_tu_indexes_read = false; | |
11632 | } | |
11633 | ||
11634 | return (bool) cu_tu_indexes_read; | |
11635 | } | |
11636 | ||
11637 | /* Find the set of sections that includes section SHNDX. */ | |
11638 | ||
11639 | unsigned int * | |
11640 | find_cu_tu_set (void *file, unsigned int shndx) | |
11641 | { | |
11642 | unsigned int i; | |
11643 | ||
11644 | if (! load_cu_tu_indexes (file)) | |
11645 | return NULL; | |
11646 | ||
11647 | /* Find SHNDX in the shndx pool. */ | |
11648 | for (i = 0; i < shndx_pool_used; i++) | |
11649 | if (shndx_pool [i] == shndx) | |
11650 | break; | |
11651 | ||
11652 | if (i >= shndx_pool_used) | |
11653 | return NULL; | |
11654 | ||
11655 | /* Now backup to find the first entry in the set. */ | |
11656 | while (i > 0 && shndx_pool [i - 1] != 0) | |
11657 | i--; | |
11658 | ||
11659 | return shndx_pool + i; | |
11660 | } | |
11661 | ||
11662 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
11663 | ||
11664 | static int | |
11665 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
11666 | { | |
11667 | return process_cu_tu_index (section, 1); | |
11668 | } | |
11669 | ||
11670 | static int | |
11671 | display_debug_not_supported (struct dwarf_section *section, | |
11672 | void *file ATTRIBUTE_UNUSED) | |
11673 | { | |
11674 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
11675 | section->name); | |
11676 | ||
11677 | return 1; | |
11678 | } | |
11679 | ||
11680 | /* Like malloc, but takes two parameters like calloc. | |
11681 | Verifies that the first parameter is not too large. | |
11682 | Note: does *not* initialise the allocated memory to zero. */ | |
11683 | ||
11684 | void * | |
11685 | cmalloc (uint64_t nmemb, size_t size) | |
11686 | { | |
11687 | /* Check for overflow. */ | |
11688 | if (nmemb >= ~(size_t) 0 / size) | |
11689 | return NULL; | |
11690 | ||
11691 | return xmalloc (nmemb * size); | |
11692 | } | |
11693 | ||
11694 | /* Like xmalloc, but takes two parameters like calloc. | |
11695 | Verifies that the first parameter is not too large. | |
11696 | Note: does *not* initialise the allocated memory to zero. */ | |
11697 | ||
11698 | void * | |
11699 | xcmalloc (uint64_t nmemb, size_t size) | |
11700 | { | |
11701 | /* Check for overflow. */ | |
11702 | if (nmemb >= ~(size_t) 0 / size) | |
11703 | { | |
11704 | fprintf (stderr, | |
11705 | _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64 "\n"), | |
11706 | nmemb); | |
11707 | xexit (1); | |
11708 | } | |
11709 | ||
11710 | return xmalloc (nmemb * size); | |
11711 | } | |
11712 | ||
11713 | /* Like xrealloc, but takes three parameters. | |
11714 | Verifies that the second parameter is not too large. | |
11715 | Note: does *not* initialise any new memory to zero. */ | |
11716 | ||
11717 | void * | |
11718 | xcrealloc (void *ptr, uint64_t nmemb, size_t size) | |
11719 | { | |
11720 | /* Check for overflow. */ | |
11721 | if (nmemb >= ~(size_t) 0 / size) | |
11722 | { | |
11723 | error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64 "\n"), | |
11724 | nmemb); | |
11725 | xexit (1); | |
11726 | } | |
11727 | ||
11728 | return xrealloc (ptr, nmemb * size); | |
11729 | } | |
11730 | ||
11731 | /* Like xcalloc, but verifies that the first parameter is not too large. */ | |
11732 | ||
11733 | void * | |
11734 | xcalloc2 (uint64_t nmemb, size_t size) | |
11735 | { | |
11736 | /* Check for overflow. */ | |
11737 | if (nmemb >= ~(size_t) 0 / size) | |
11738 | { | |
11739 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64 "\n"), | |
11740 | nmemb); | |
11741 | xexit (1); | |
11742 | } | |
11743 | ||
11744 | return xcalloc (nmemb, size); | |
11745 | } | |
11746 | ||
11747 | static unsigned long | |
11748 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
11749 | const unsigned char *buf, | |
11750 | size_t len) | |
11751 | { | |
11752 | static const unsigned long crc32_table[256] = | |
11753 | { | |
11754 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
11755 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
11756 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
11757 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
11758 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
11759 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
11760 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
11761 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
11762 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
11763 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
11764 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
11765 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
11766 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
11767 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
11768 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
11769 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
11770 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
11771 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
11772 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
11773 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
11774 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
11775 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
11776 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
11777 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
11778 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
11779 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
11780 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
11781 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
11782 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
11783 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
11784 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
11785 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
11786 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
11787 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
11788 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
11789 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
11790 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
11791 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
11792 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
11793 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
11794 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
11795 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
11796 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
11797 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
11798 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
11799 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
11800 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
11801 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
11802 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
11803 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
11804 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
11805 | 0x2d02ef8d | |
11806 | }; | |
11807 | const unsigned char *end; | |
11808 | ||
11809 | crc = ~crc & 0xffffffff; | |
11810 | for (end = buf + len; buf < end; ++ buf) | |
11811 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
11812 | return ~crc & 0xffffffff; | |
11813 | } | |
11814 | ||
11815 | typedef bool (*check_func_type) (const char *, void *); | |
11816 | typedef const char *(* parse_func_type) (struct dwarf_section *, void *); | |
11817 | ||
11818 | static bool | |
11819 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
11820 | { | |
11821 | static unsigned char buffer[8 * 1024]; | |
11822 | FILE *f; | |
11823 | size_t count; | |
11824 | unsigned long crc = 0; | |
11825 | void *sep_data; | |
11826 | ||
11827 | sep_data = open_debug_file (pathname); | |
11828 | if (sep_data == NULL) | |
11829 | return false; | |
11830 | ||
11831 | /* Yes - we are opening the file twice... */ | |
11832 | f = fopen (pathname, "rb"); | |
11833 | if (f == NULL) | |
11834 | { | |
11835 | /* Paranoia: This should never happen. */ | |
11836 | close_debug_file (sep_data); | |
11837 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
11838 | return false; | |
11839 | } | |
11840 | ||
11841 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
11842 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
11843 | ||
11844 | fclose (f); | |
11845 | close_debug_file (sep_data); | |
11846 | ||
11847 | if (crc != * (unsigned long *) crc_pointer) | |
11848 | { | |
11849 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
11850 | pathname); | |
11851 | return false; | |
11852 | } | |
11853 | ||
11854 | return true; | |
11855 | } | |
11856 | ||
11857 | static const char * | |
11858 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
11859 | { | |
11860 | const char * name; | |
11861 | unsigned int crc_offset; | |
11862 | unsigned long * crc32 = (unsigned long *) data; | |
11863 | ||
11864 | /* The name is first. | |
11865 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
11866 | name = (const char *) section->start; | |
11867 | ||
11868 | crc_offset = strnlen (name, section->size) + 1; | |
11869 | if (crc_offset == 1) | |
11870 | return NULL; | |
11871 | crc_offset = (crc_offset + 3) & ~3; | |
11872 | if (crc_offset + 4 > section->size) | |
11873 | return NULL; | |
11874 | ||
11875 | * crc32 = byte_get (section->start + crc_offset, 4); | |
11876 | return name; | |
11877 | } | |
11878 | ||
11879 | static bool | |
11880 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
11881 | { | |
11882 | void * sep_data = open_debug_file (filename); | |
11883 | ||
11884 | if (sep_data == NULL) | |
11885 | return false; | |
11886 | ||
11887 | /* FIXME: We should now extract the build-id in the separate file | |
11888 | and check it... */ | |
11889 | ||
11890 | close_debug_file (sep_data); | |
11891 | return true; | |
11892 | } | |
11893 | ||
11894 | typedef struct build_id_data | |
11895 | { | |
11896 | size_t len; | |
11897 | const unsigned char *data; | |
11898 | } Build_id_data; | |
11899 | ||
11900 | static const char * | |
11901 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
11902 | { | |
11903 | const char *name; | |
11904 | size_t namelen; | |
11905 | size_t id_len; | |
11906 | Build_id_data *build_id_data; | |
11907 | ||
11908 | /* The name is first. | |
11909 | The build-id follows immediately, with no padding, up to the section's end. */ | |
11910 | ||
11911 | name = (const char *) section->start; | |
11912 | namelen = strnlen (name, section->size) + 1; | |
11913 | if (namelen == 1) | |
11914 | return NULL; | |
11915 | if (namelen >= section->size) | |
11916 | return NULL; | |
11917 | ||
11918 | id_len = section->size - namelen; | |
11919 | if (id_len < 0x14) | |
11920 | return NULL; | |
11921 | ||
11922 | build_id_data = (Build_id_data *) data; | |
11923 | build_id_data->len = id_len; | |
11924 | build_id_data->data = section->start + namelen; | |
11925 | ||
11926 | return name; | |
11927 | } | |
11928 | ||
11929 | static void | |
11930 | add_separate_debug_file (const char * filename, void * handle) | |
11931 | { | |
11932 | separate_info * i = xmalloc (sizeof * i); | |
11933 | ||
11934 | i->filename = filename; | |
11935 | i->handle = handle; | |
11936 | i->next = first_separate_info; | |
11937 | first_separate_info = i; | |
11938 | } | |
11939 | ||
11940 | #if HAVE_LIBDEBUGINFOD | |
11941 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
11942 | file. If successful, store the path of the file in filename and | |
11943 | return TRUE, otherwise return FALSE. */ | |
11944 | ||
11945 | static bool | |
11946 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, | |
11947 | char ** filename, | |
11948 | void * file) | |
11949 | { | |
11950 | size_t build_id_len; | |
11951 | unsigned char * build_id; | |
11952 | ||
11953 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
11954 | { | |
11955 | /* Get the build-id of file. */ | |
11956 | build_id = get_build_id (file); | |
11957 | build_id_len = 0; | |
11958 | } | |
11959 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
11960 | { | |
11961 | /* Get the build-id of the debugaltlink file. */ | |
11962 | unsigned int filelen; | |
11963 | ||
11964 | filelen = strnlen ((const char *)section->start, section->size); | |
11965 | if (filelen == section->size) | |
11966 | /* Corrupt debugaltlink. */ | |
11967 | return false; | |
11968 | ||
11969 | build_id = section->start + filelen + 1; | |
11970 | build_id_len = section->size - (filelen + 1); | |
11971 | ||
11972 | if (build_id_len == 0) | |
11973 | return false; | |
11974 | } | |
11975 | else | |
11976 | return false; | |
11977 | ||
11978 | if (build_id) | |
11979 | { | |
11980 | int fd; | |
11981 | debuginfod_client * client; | |
11982 | ||
11983 | client = debuginfod_begin (); | |
11984 | if (client == NULL) | |
11985 | return false; | |
11986 | ||
11987 | /* Query debuginfod servers for the target file. If found its path | |
11988 | will be stored in filename. */ | |
11989 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); | |
11990 | debuginfod_end (client); | |
11991 | ||
11992 | /* Only free build_id if we allocated space for a hex string | |
11993 | in get_build_id (). */ | |
11994 | if (build_id_len == 0) | |
11995 | free (build_id); | |
11996 | ||
11997 | if (fd >= 0) | |
11998 | { | |
11999 | /* File successfully retrieved. Close fd since we want to | |
12000 | use open_debug_file () on filename instead. */ | |
12001 | close (fd); | |
12002 | return true; | |
12003 | } | |
12004 | } | |
12005 | ||
12006 | return false; | |
12007 | } | |
12008 | #endif /* HAVE_LIBDEBUGINFOD */ | |
12009 | ||
12010 | static void * | |
12011 | load_separate_debug_info (const char * main_filename, | |
12012 | struct dwarf_section * xlink, | |
12013 | parse_func_type parse_func, | |
12014 | check_func_type check_func, | |
12015 | void * func_data, | |
12016 | void * file ATTRIBUTE_UNUSED) | |
12017 | { | |
12018 | const char * separate_filename; | |
12019 | char * debug_filename; | |
12020 | char * canon_dir; | |
12021 | size_t canon_dirlen; | |
12022 | size_t dirlen; | |
12023 | char * canon_filename; | |
12024 | char * canon_debug_filename; | |
12025 | bool self; | |
12026 | ||
12027 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) | |
12028 | { | |
12029 | warn (_("Corrupt debuglink section: %s\n"), | |
12030 | xlink->name ? xlink->name : xlink->uncompressed_name); | |
12031 | return NULL; | |
12032 | } | |
12033 | ||
12034 | /* Attempt to locate the separate file. | |
12035 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
12036 | ||
12037 | canon_filename = lrealpath (main_filename); | |
12038 | canon_dir = xstrdup (canon_filename); | |
12039 | ||
12040 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) | |
12041 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
12042 | break; | |
12043 | canon_dir[canon_dirlen] = '\0'; | |
12044 | ||
12045 | #ifndef DEBUGDIR | |
12046 | #define DEBUGDIR "/lib/debug" | |
12047 | #endif | |
12048 | #ifndef EXTRA_DEBUG_ROOT1 | |
12049 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
12050 | #endif | |
12051 | #ifndef EXTRA_DEBUG_ROOT2 | |
12052 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
12053 | #endif | |
12054 | ||
12055 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 | |
12056 | + canon_dirlen | |
12057 | + strlen (".debug/") | |
12058 | #ifdef EXTRA_DEBUG_ROOT1 | |
12059 | + strlen (EXTRA_DEBUG_ROOT1) | |
12060 | #endif | |
12061 | #ifdef EXTRA_DEBUG_ROOT2 | |
12062 | + strlen (EXTRA_DEBUG_ROOT2) | |
12063 | #endif | |
12064 | + strlen (separate_filename) | |
12065 | + 1); | |
12066 | if (debug_filename == NULL) | |
12067 | { | |
12068 | warn (_("Out of memory\n")); | |
12069 | free (canon_dir); | |
12070 | free (canon_filename); | |
12071 | return NULL; | |
12072 | } | |
12073 | ||
12074 | /* First try in the current directory. */ | |
12075 | sprintf (debug_filename, "%s", separate_filename); | |
12076 | if (check_func (debug_filename, func_data)) | |
12077 | goto found; | |
12078 | ||
12079 | /* Then try in a subdirectory called .debug. */ | |
12080 | sprintf (debug_filename, ".debug/%s", separate_filename); | |
12081 | if (check_func (debug_filename, func_data)) | |
12082 | goto found; | |
12083 | ||
12084 | /* Then try in the same directory as the original file. */ | |
12085 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); | |
12086 | if (check_func (debug_filename, func_data)) | |
12087 | goto found; | |
12088 | ||
12089 | /* And the .debug subdirectory of that directory. */ | |
12090 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); | |
12091 | if (check_func (debug_filename, func_data)) | |
12092 | goto found; | |
12093 | ||
12094 | #ifdef EXTRA_DEBUG_ROOT1 | |
12095 | /* Try the first extra debug file root. */ | |
12096 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); | |
12097 | if (check_func (debug_filename, func_data)) | |
12098 | goto found; | |
12099 | ||
12100 | /* Try the first extra debug file root. */ | |
12101 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
12102 | if (check_func (debug_filename, func_data)) | |
12103 | goto found; | |
12104 | #endif | |
12105 | ||
12106 | #ifdef EXTRA_DEBUG_ROOT2 | |
12107 | /* Try the second extra debug file root. */ | |
12108 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); | |
12109 | if (check_func (debug_filename, func_data)) | |
12110 | goto found; | |
12111 | #endif | |
12112 | ||
12113 | /* Then try in the global debug_filename directory. */ | |
12114 | strcpy (debug_filename, DEBUGDIR); | |
12115 | dirlen = strlen (DEBUGDIR) - 1; | |
12116 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
12117 | strcat (debug_filename, "/"); | |
12118 | strcat (debug_filename, (const char *) separate_filename); | |
12119 | ||
12120 | if (check_func (debug_filename, func_data)) | |
12121 | goto found; | |
12122 | ||
12123 | #if HAVE_LIBDEBUGINFOD | |
12124 | { | |
12125 | char * tmp_filename; | |
12126 | ||
12127 | if (use_debuginfod | |
12128 | && debuginfod_fetch_separate_debug_info (xlink, | |
12129 | & tmp_filename, | |
12130 | file)) | |
12131 | { | |
12132 | /* File successfully downloaded from server, replace | |
12133 | debug_filename with the file's path. */ | |
12134 | free (debug_filename); | |
12135 | debug_filename = tmp_filename; | |
12136 | goto found; | |
12137 | } | |
12138 | } | |
12139 | #endif | |
12140 | ||
12141 | if (do_debug_links) | |
12142 | { | |
12143 | /* Failed to find the file. */ | |
12144 | warn (_("could not find separate debug file '%s'\n"), | |
12145 | separate_filename); | |
12146 | warn (_("tried: %s\n"), debug_filename); | |
12147 | ||
12148 | #ifdef EXTRA_DEBUG_ROOT2 | |
12149 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, | |
12150 | separate_filename); | |
12151 | warn (_("tried: %s\n"), debug_filename); | |
12152 | #endif | |
12153 | ||
12154 | #ifdef EXTRA_DEBUG_ROOT1 | |
12155 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, | |
12156 | canon_dir, separate_filename); | |
12157 | warn (_("tried: %s\n"), debug_filename); | |
12158 | ||
12159 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, | |
12160 | separate_filename); | |
12161 | warn (_("tried: %s\n"), debug_filename); | |
12162 | #endif | |
12163 | ||
12164 | sprintf (debug_filename, "%s.debug/%s", canon_dir, | |
12165 | separate_filename); | |
12166 | warn (_("tried: %s\n"), debug_filename); | |
12167 | ||
12168 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); | |
12169 | warn (_("tried: %s\n"), debug_filename); | |
12170 | ||
12171 | sprintf (debug_filename, ".debug/%s", separate_filename); | |
12172 | warn (_("tried: %s\n"), debug_filename); | |
12173 | ||
12174 | sprintf (debug_filename, "%s", separate_filename); | |
12175 | warn (_("tried: %s\n"), debug_filename); | |
12176 | ||
12177 | #if HAVE_LIBDEBUGINFOD | |
12178 | if (use_debuginfod) | |
12179 | { | |
12180 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
12181 | ||
12182 | if (urls == NULL) | |
12183 | urls = ""; | |
12184 | ||
12185 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); | |
12186 | } | |
12187 | #endif | |
12188 | } | |
12189 | ||
12190 | free (canon_dir); | |
12191 | free (debug_filename); | |
12192 | free (canon_filename); | |
12193 | return NULL; | |
12194 | ||
12195 | found: | |
12196 | free (canon_dir); | |
12197 | ||
12198 | canon_debug_filename = lrealpath (debug_filename); | |
12199 | self = strcmp (canon_debug_filename, canon_filename) == 0; | |
12200 | free (canon_filename); | |
12201 | free (canon_debug_filename); | |
12202 | if (self) | |
12203 | { | |
12204 | free (debug_filename); | |
12205 | return NULL; | |
12206 | } | |
12207 | ||
12208 | void * debug_handle; | |
12209 | ||
12210 | /* Now open the file.... */ | |
12211 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) | |
12212 | { | |
12213 | warn (_("failed to open separate debug file: %s\n"), debug_filename); | |
12214 | free (debug_filename); | |
12215 | return NULL; | |
12216 | } | |
12217 | ||
12218 | /* FIXME: We do not check to see if there are any other separate debug info | |
12219 | files that would also match. */ | |
12220 | ||
12221 | if (do_debug_links) | |
12222 | printf (_("\n%s: Found separate debug info file: %s\n"), main_filename, debug_filename); | |
12223 | add_separate_debug_file (debug_filename, debug_handle); | |
12224 | ||
12225 | /* Do not free debug_filename - it might be referenced inside | |
12226 | the structure returned by open_debug_file(). */ | |
12227 | return debug_handle; | |
12228 | } | |
12229 | ||
12230 | /* Attempt to load a separate dwarf object file. */ | |
12231 | ||
12232 | static void * | |
12233 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) | |
12234 | { | |
12235 | char * separate_filename; | |
12236 | void * separate_handle; | |
12237 | ||
12238 | if (IS_ABSOLUTE_PATH (name)) | |
12239 | separate_filename = strdup (name); | |
12240 | else | |
12241 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
12242 | separate_filename = concat (dir, "/", name, NULL); | |
12243 | if (separate_filename == NULL) | |
12244 | { | |
12245 | warn (_("Out of memory allocating dwo filename\n")); | |
12246 | return NULL; | |
12247 | } | |
12248 | ||
12249 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) | |
12250 | { | |
12251 | warn (_("Unable to load dwo file: %s\n"), separate_filename); | |
12252 | free (separate_filename); | |
12253 | return NULL; | |
12254 | } | |
12255 | ||
12256 | /* FIXME: We should check the dwo_id. */ | |
12257 | ||
12258 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); | |
12259 | ||
12260 | add_separate_debug_file (separate_filename, separate_handle); | |
12261 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
12262 | return separate_handle; | |
12263 | } | |
12264 | ||
12265 | static void * | |
12266 | try_build_id_prefix (const char * prefix, char * filename, const unsigned char * data, unsigned long id_len) | |
12267 | { | |
12268 | char * f = filename; | |
12269 | ||
12270 | f += sprintf (f, "%s.build-id/%02x/", prefix, (unsigned) *data++); | |
12271 | id_len --; | |
12272 | while (id_len --) | |
12273 | f += sprintf (f, "%02x", (unsigned) *data++); | |
12274 | strcpy (f, ".debug"); | |
12275 | ||
12276 | return open_debug_file (filename); | |
12277 | } | |
12278 | ||
12279 | /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */ | |
12280 | ||
12281 | static void | |
12282 | load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED, void * main_file) | |
12283 | { | |
12284 | if (! load_debug_section (note_gnu_build_id, main_file)) | |
12285 | return; /* No .note.gnu.build-id section. */ | |
12286 | ||
12287 | struct dwarf_section * section = & debug_displays [note_gnu_build_id].section; | |
12288 | if (section == NULL) | |
12289 | { | |
12290 | warn (_("Unable to load the .note.gnu.build-id section\n")); | |
12291 | return; | |
12292 | } | |
12293 | ||
12294 | if (section->start == NULL || section->size < 0x18) | |
12295 | { | |
12296 | warn (_(".note.gnu.build-id section is corrupt/empty\n")); | |
12297 | return; | |
12298 | } | |
12299 | ||
12300 | /* In theory we should extract the contents of the section into | |
12301 | a note structure and then check the fields. For now though | |
12302 | just use hard coded offsets instead: | |
12303 | ||
12304 | Field Bytes Contents | |
12305 | NSize 0...3 4 | |
12306 | DSize 4...7 8+ | |
12307 | Type 8..11 3 (NT_GNU_BUILD_ID) | |
12308 | Name 12.15 GNU\0 | |
12309 | Data 16.... */ | |
12310 | ||
12311 | /* FIXME: Check the name size, name and type fields. */ | |
12312 | ||
12313 | unsigned long build_id_size; | |
12314 | build_id_size = byte_get (section->start + 4, 4); | |
12315 | if (build_id_size < 8) | |
12316 | { | |
12317 | warn (_(".note.gnu.build-id data size is too small\n")); | |
12318 | return; | |
12319 | } | |
12320 | ||
12321 | if (build_id_size > (section->size - 16)) | |
12322 | { | |
12323 | warn (_(".note.gnu.build-id data size is too big\n")); | |
12324 | return; | |
12325 | } | |
12326 | ||
12327 | char * filename; | |
12328 | filename = xmalloc (strlen (".build-id/") | |
12329 | + build_id_size * 2 + 2 | |
12330 | + strlen (".debug") | |
12331 | /* The next string should be the same as the longest | |
12332 | name found in the prefixes[] array below. */ | |
12333 | + strlen ("/usr/lib64/debug/usr/") | |
12334 | + 1); | |
12335 | void * handle; | |
12336 | ||
12337 | static const char * prefixes[] = | |
12338 | { | |
12339 | "", | |
12340 | ".debug/", | |
12341 | "/usr/lib/debug/", | |
12342 | "/usr/lib/debug/usr/", | |
12343 | "/usr/lib64/debug/", | |
12344 | "/usr/lib64/debug/usr/" | |
12345 | }; | |
12346 | long unsigned int i; | |
12347 | ||
12348 | for (i = 0; i < ARRAY_SIZE (prefixes); i++) | |
12349 | { | |
12350 | handle = try_build_id_prefix (prefixes[i], filename, | |
12351 | section->start + 16, build_id_size); | |
12352 | if (handle != NULL) | |
12353 | break; | |
12354 | } | |
12355 | /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */ | |
12356 | if (handle == NULL) | |
12357 | { | |
12358 | /* Failed to find a debug file associated with the build-id. | |
12359 | This is not an error however, rather it just means that | |
12360 | the debug info has probably not been loaded on the system, | |
12361 | or that another method is being used to link to the debug | |
12362 | info. */ | |
12363 | free (filename); | |
12364 | return; | |
12365 | } | |
12366 | ||
12367 | add_separate_debug_file (filename, handle); | |
12368 | } | |
12369 | ||
12370 | /* Try to load a debug file pointed to by the .debug_sup section. */ | |
12371 | ||
12372 | static void | |
12373 | load_debug_sup_file (const char * main_filename, void * file) | |
12374 | { | |
12375 | if (! load_debug_section (debug_sup, file)) | |
12376 | return; /* No .debug_sup section. */ | |
12377 | ||
12378 | struct dwarf_section * section; | |
12379 | section = & debug_displays [debug_sup].section; | |
12380 | assert (section != NULL); | |
12381 | ||
12382 | if (section->start == NULL || section->size < 5) | |
12383 | { | |
12384 | warn (_(".debug_sup section is corrupt/empty\n")); | |
12385 | return; | |
12386 | } | |
12387 | ||
12388 | if (section->start[2] != 0) | |
12389 | return; /* This is a supplementary file. */ | |
12390 | ||
12391 | const char * filename = (const char *) section->start + 3; | |
12392 | if (strnlen (filename, section->size - 3) == section->size - 3) | |
12393 | { | |
12394 | warn (_("filename in .debug_sup section is corrupt\n")); | |
12395 | return; | |
12396 | } | |
12397 | ||
12398 | if (filename[0] != '/' && strchr (main_filename, '/')) | |
12399 | filename = xasprintf ("%.*s/%s", | |
12400 | (int) (strrchr (main_filename, '/') - main_filename), | |
12401 | main_filename, | |
12402 | filename); | |
12403 | else | |
12404 | /* PR 27796: Make sure that we pass a filename that can be free'd to | |
12405 | add_separate_debug_file(). */ | |
12406 | filename = xstrdup (filename); | |
12407 | ||
12408 | void * handle = open_debug_file (filename); | |
12409 | if (handle == NULL) | |
12410 | { | |
12411 | warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename); | |
12412 | free ((void *) filename); | |
12413 | return; | |
12414 | } | |
12415 | ||
12416 | printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename, filename); | |
12417 | ||
12418 | /* FIXME: Compare the checksums, if present. */ | |
12419 | add_separate_debug_file (filename, handle); | |
12420 | } | |
12421 | ||
12422 | /* Load a debuglink section and/or a debugaltlink section, if either are present. | |
12423 | Recursively check the loaded files for more of these sections. | |
12424 | Also follow any links in .debug_sup sections. | |
12425 | FIXME: Should also check for DWO_* entries in the newly loaded files. */ | |
12426 | ||
12427 | static void | |
12428 | check_for_and_load_links (void * file, const char * filename) | |
12429 | { | |
12430 | void * handle = NULL; | |
12431 | ||
12432 | if (load_debug_section (gnu_debugaltlink, file)) | |
12433 | { | |
12434 | Build_id_data build_id_data; | |
12435 | ||
12436 | handle = load_separate_debug_info (filename, | |
12437 | & debug_displays[gnu_debugaltlink].section, | |
12438 | parse_gnu_debugaltlink, | |
12439 | check_gnu_debugaltlink, | |
12440 | & build_id_data, | |
12441 | file); | |
12442 | if (handle) | |
12443 | { | |
12444 | assert (handle == first_separate_info->handle); | |
12445 | check_for_and_load_links (first_separate_info->handle, | |
12446 | first_separate_info->filename); | |
12447 | } | |
12448 | } | |
12449 | ||
12450 | if (load_debug_section (gnu_debuglink, file)) | |
12451 | { | |
12452 | unsigned long crc32; | |
12453 | ||
12454 | handle = load_separate_debug_info (filename, | |
12455 | & debug_displays[gnu_debuglink].section, | |
12456 | parse_gnu_debuglink, | |
12457 | check_gnu_debuglink, | |
12458 | & crc32, | |
12459 | file); | |
12460 | if (handle) | |
12461 | { | |
12462 | assert (handle == first_separate_info->handle); | |
12463 | check_for_and_load_links (first_separate_info->handle, | |
12464 | first_separate_info->filename); | |
12465 | } | |
12466 | } | |
12467 | ||
12468 | load_debug_sup_file (filename, file); | |
12469 | ||
12470 | load_build_id_debug_file (filename, file); | |
12471 | } | |
12472 | ||
12473 | /* Load the separate debug info file(s) attached to FILE, if any exist. | |
12474 | Returns TRUE if any were found, FALSE otherwise. | |
12475 | If TRUE is returned then the linked list starting at first_separate_info | |
12476 | will be populated with open file handles. */ | |
12477 | ||
12478 | bool | |
12479 | load_separate_debug_files (void * file, const char * filename) | |
12480 | { | |
12481 | /* Skip this operation if we are not interested in debug links. */ | |
12482 | if (! do_follow_links && ! do_debug_links) | |
12483 | return false; | |
12484 | ||
12485 | /* See if there are any dwo links. */ | |
12486 | if (load_debug_section (str, file) | |
12487 | && load_debug_section (abbrev, file) | |
12488 | && load_debug_section (info, file)) | |
12489 | { | |
12490 | /* Load the .debug_addr section, if it exists. */ | |
12491 | load_debug_section (debug_addr, file); | |
12492 | /* Load the .debug_str_offsets section, if it exists. */ | |
12493 | load_debug_section (str_index, file); | |
12494 | /* Load the .debug_loclists section, if it exists. */ | |
12495 | load_debug_section (loclists, file); | |
12496 | /* Load the .debug_rnglists section, if it exists. */ | |
12497 | load_debug_section (rnglists, file); | |
12498 | ||
12499 | free_dwo_info (); | |
12500 | ||
12501 | if (process_debug_info (& debug_displays[info].section, file, abbrev, | |
12502 | true, false)) | |
12503 | { | |
12504 | bool introduced = false; | |
12505 | dwo_info *dwinfo; | |
12506 | const char *dir = NULL; | |
12507 | const char *id = NULL; | |
12508 | const char *name = NULL; | |
12509 | ||
12510 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
12511 | { | |
12512 | /* Accumulate NAME, DIR and ID fields. */ | |
12513 | switch (dwinfo->type) | |
12514 | { | |
12515 | case DWO_NAME: | |
12516 | if (name != NULL) | |
12517 | warn (_("Multiple DWO_NAMEs encountered for the same CU\n")); | |
12518 | name = dwinfo->value; | |
12519 | break; | |
12520 | ||
12521 | case DWO_DIR: | |
12522 | /* There can be multiple DW_AT_comp_dir entries in a CU, | |
12523 | so do not complain. */ | |
12524 | dir = dwinfo->value; | |
12525 | break; | |
12526 | ||
12527 | case DWO_ID: | |
12528 | if (id != NULL) | |
12529 | warn (_("multiple DWO_IDs encountered for the same CU\n")); | |
12530 | id = dwinfo->value; | |
12531 | break; | |
12532 | ||
12533 | default: | |
12534 | error (_("Unexpected DWO INFO type")); | |
12535 | break; | |
12536 | } | |
12537 | ||
12538 | /* If we have reached the end of our list, or we are changing | |
12539 | CUs, then display the information that we have accumulated | |
12540 | so far. */ | |
12541 | if (name != NULL | |
12542 | && (dwinfo->next == NULL | |
12543 | || dwinfo->next->cu_offset != dwinfo->cu_offset)) | |
12544 | { | |
12545 | if (do_debug_links) | |
12546 | { | |
12547 | if (! introduced) | |
12548 | { | |
12549 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
12550 | debug_displays [info].section.uncompressed_name); | |
12551 | introduced = true; | |
12552 | } | |
12553 | ||
12554 | printf (_(" Name: %s\n"), name); | |
12555 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); | |
12556 | if (id != NULL) | |
12557 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
12558 | else if (debug_information[0].dwarf_version != 5) | |
12559 | printf (_(" ID: <not specified>\n")); | |
12560 | printf ("\n\n"); | |
12561 | } | |
12562 | ||
12563 | if (do_follow_links) | |
12564 | load_dwo_file (filename, name, dir, id); | |
12565 | ||
12566 | name = dir = id = NULL; | |
12567 | } | |
12568 | } | |
12569 | } | |
12570 | } | |
12571 | ||
12572 | if (! do_follow_links) | |
12573 | /* The other debug links will be displayed by display_debug_links() | |
12574 | so we do not need to do any further processing here. */ | |
12575 | return false; | |
12576 | ||
12577 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
12578 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ | |
12579 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ | |
12580 | ||
12581 | check_for_and_load_links (file, filename); | |
12582 | if (first_separate_info != NULL) | |
12583 | return true; | |
12584 | ||
12585 | do_follow_links = 0; | |
12586 | return false; | |
12587 | } | |
12588 | ||
12589 | void | |
12590 | free_debug_memory (void) | |
12591 | { | |
12592 | unsigned int i; | |
12593 | ||
12594 | free_all_abbrevs (); | |
12595 | ||
12596 | free (shndx_pool); | |
12597 | shndx_pool = NULL; | |
12598 | shndx_pool_size = 0; | |
12599 | shndx_pool_used = 0; | |
12600 | free (cu_sets); | |
12601 | cu_sets = NULL; | |
12602 | cu_count = 0; | |
12603 | free (tu_sets); | |
12604 | tu_sets = NULL; | |
12605 | tu_count = 0; | |
12606 | ||
12607 | memset (level_type_signed, 0, sizeof level_type_signed); | |
12608 | cu_tu_indexes_read = -1; | |
12609 | ||
12610 | for (i = 0; i < max; i++) | |
12611 | free_debug_section ((enum dwarf_section_display_enum) i); | |
12612 | ||
12613 | if (debug_information != NULL) | |
12614 | { | |
12615 | for (i = 0; i < alloc_num_debug_info_entries; i++) | |
12616 | free_debug_information (&debug_information[i]); | |
12617 | free (debug_information); | |
12618 | debug_information = NULL; | |
12619 | alloc_num_debug_info_entries = num_debug_info_entries = 0; | |
12620 | } | |
12621 | ||
12622 | separate_info * d; | |
12623 | separate_info * next; | |
12624 | ||
12625 | for (d = first_separate_info; d != NULL; d = next) | |
12626 | { | |
12627 | close_debug_file (d->handle); | |
12628 | free ((void *) d->filename); | |
12629 | next = d->next; | |
12630 | free ((void *) d); | |
12631 | } | |
12632 | first_separate_info = NULL; | |
12633 | ||
12634 | free_dwo_info (); | |
12635 | } | |
12636 | ||
12637 | typedef struct | |
12638 | { | |
12639 | const char letter; | |
12640 | const char *option; | |
12641 | int *variable; | |
12642 | int val; | |
12643 | } debug_dump_long_opts; | |
12644 | ||
12645 | static const debug_dump_long_opts debug_option_table[] = | |
12646 | { | |
12647 | { 'A', "addr", &do_debug_addr, 1 }, | |
12648 | { 'a', "abbrev", &do_debug_abbrevs, 1 }, | |
12649 | { 'c', "cu_index", &do_debug_cu_index, 1 }, | |
12650 | #ifdef HAVE_LIBDEBUGINFOD | |
12651 | { 'D', "use-debuginfod", &use_debuginfod, 1 }, | |
12652 | { 'E', "do-not-use-debuginfod", &use_debuginfod, 0 }, | |
12653 | #endif | |
12654 | { 'F', "frames-interp", &do_debug_frames_interp, 1 }, | |
12655 | { 'f', "frames", &do_debug_frames, 1 }, | |
12656 | { 'g', "gdb_index", &do_gdb_index, 1 }, | |
12657 | { 'i', "info", &do_debug_info, 1 }, | |
12658 | { 'K', "follow-links", &do_follow_links, 1 }, | |
12659 | { 'k', "links", &do_debug_links, 1 }, | |
12660 | { 'L', "decodedline", &do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
12661 | { 'l', "rawline", &do_debug_lines, FLAG_DEBUG_LINES_RAW }, | |
12662 | /* For compatibility with earlier versions of readelf. */ | |
12663 | { 'l', "line", &do_debug_lines, FLAG_DEBUG_LINES_RAW }, | |
12664 | { 'm', "macro", &do_debug_macinfo, 1 }, | |
12665 | { 'N', "no-follow-links", &do_follow_links, 0 }, | |
12666 | { 'O', "str-offsets", &do_debug_str_offsets, 1 }, | |
12667 | { 'o', "loc", &do_debug_loc, 1 }, | |
12668 | { 'p', "pubnames", &do_debug_pubnames, 1 }, | |
12669 | { 'R', "Ranges", &do_debug_ranges, 1 }, | |
12670 | { 'r', "aranges", &do_debug_aranges, 1 }, | |
12671 | /* For compatibility with earlier versions of readelf. */ | |
12672 | { 'r', "ranges", &do_debug_aranges, 1 }, | |
12673 | { 's', "str", &do_debug_str, 1 }, | |
12674 | { 'T', "trace_aranges", &do_trace_aranges, 1 }, | |
12675 | { 't', "pubtypes", &do_debug_pubtypes, 1 }, | |
12676 | { 'U', "trace_info", &do_trace_info, 1 }, | |
12677 | { 'u', "trace_abbrev", &do_trace_abbrevs, 1 }, | |
12678 | { 0, NULL, NULL, 0 } | |
12679 | }; | |
12680 | ||
12681 | /* Enable display of specific DWARF sections as determined by the comma | |
12682 | separated strings in NAMES. Returns non-zero if any displaying was | |
12683 | enabled. */ | |
12684 | ||
12685 | int | |
12686 | dwarf_select_sections_by_names (const char *names) | |
12687 | { | |
12688 | const char *p; | |
12689 | int result = 0; | |
12690 | ||
12691 | p = names; | |
12692 | while (*p) | |
12693 | { | |
12694 | const debug_dump_long_opts *entry; | |
12695 | ||
12696 | for (entry = debug_option_table; entry->option; entry++) | |
12697 | { | |
12698 | size_t len = strlen (entry->option); | |
12699 | ||
12700 | if (strncmp (p, entry->option, len) == 0 | |
12701 | && (p[len] == ',' || p[len] == '\0')) | |
12702 | { | |
12703 | if (entry->val == 0) | |
12704 | * entry->variable = 0; | |
12705 | else | |
12706 | * entry->variable = entry->val; | |
12707 | result |= entry->val; | |
12708 | ||
12709 | p += len; | |
12710 | break; | |
12711 | } | |
12712 | } | |
12713 | ||
12714 | if (entry->option == NULL) | |
12715 | { | |
12716 | warn (_("Unrecognized debug option '%s'\n"), p); | |
12717 | p = strchr (p, ','); | |
12718 | if (p == NULL) | |
12719 | break; | |
12720 | } | |
12721 | ||
12722 | if (*p == ',') | |
12723 | p++; | |
12724 | } | |
12725 | ||
12726 | /* The --debug-dump=frames-interp option also enables the | |
12727 | --debug-dump=frames option. */ | |
12728 | if (do_debug_frames_interp) | |
12729 | do_debug_frames = 1; | |
12730 | ||
12731 | return result; | |
12732 | } | |
12733 | ||
12734 | /* Enable display of specific DWARF sections as determined by the characters | |
12735 | in LETTERS. Returns non-zero if any displaying was enabled. */ | |
12736 | ||
12737 | int | |
12738 | dwarf_select_sections_by_letters (const char *letters) | |
12739 | { | |
12740 | int result = 0; | |
12741 | ||
12742 | while (* letters) | |
12743 | { | |
12744 | const debug_dump_long_opts *entry; | |
12745 | ||
12746 | for (entry = debug_option_table; entry->letter; entry++) | |
12747 | { | |
12748 | if (entry->letter == * letters) | |
12749 | { | |
12750 | if (entry->val == 0) | |
12751 | * entry->variable = 0; | |
12752 | else | |
12753 | * entry->variable |= entry->val; | |
12754 | result |= entry->val; | |
12755 | break; | |
12756 | } | |
12757 | } | |
12758 | ||
12759 | if (entry->letter == 0) | |
12760 | warn (_("Unrecognized debug letter option '%c'\n"), * letters); | |
12761 | ||
12762 | letters ++; | |
12763 | } | |
12764 | ||
12765 | /* The --debug-dump=frames-interp option also enables the | |
12766 | --debug-dump=frames option. */ | |
12767 | if (do_debug_frames_interp) | |
12768 | do_debug_frames = 1; | |
12769 | ||
12770 | return result; | |
12771 | } | |
12772 | ||
12773 | void | |
12774 | dwarf_select_sections_all (void) | |
12775 | { | |
12776 | do_debug_info = 1; | |
12777 | do_debug_abbrevs = 1; | |
12778 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
12779 | do_debug_pubnames = 1; | |
12780 | do_debug_pubtypes = 1; | |
12781 | do_debug_aranges = 1; | |
12782 | do_debug_ranges = 1; | |
12783 | do_debug_frames = 1; | |
12784 | do_debug_macinfo = 1; | |
12785 | do_debug_str = 1; | |
12786 | do_debug_loc = 1; | |
12787 | do_gdb_index = 1; | |
12788 | do_trace_info = 1; | |
12789 | do_trace_abbrevs = 1; | |
12790 | do_trace_aranges = 1; | |
12791 | do_debug_addr = 1; | |
12792 | do_debug_cu_index = 1; | |
12793 | do_follow_links = 1; | |
12794 | do_debug_links = 1; | |
12795 | do_debug_str_offsets = 1; | |
12796 | } | |
12797 | ||
12798 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0 | |
12799 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0 | |
12800 | ||
12801 | /* N.B. The order here must match the order in section_display_enum. */ | |
12802 | ||
12803 | struct dwarf_section_display debug_displays[] = | |
12804 | { | |
12805 | { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, | |
12806 | { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, true }, | |
12807 | { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, | |
12808 | { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev)}, display_debug_info, &do_debug_info, true }, | |
12809 | { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, | |
12810 | { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, false }, | |
12811 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, false }, | |
12812 | { { ".eh_frame", "", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, | |
12813 | { { ".eh_frame_hdr", "", "", NO_ABBREVS }, display_eh_frame_hdr, &do_debug_frames, true }, | |
12814 | { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, | |
12815 | { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, | |
12816 | { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
12817 | { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
12818 | { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
12819 | { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
12820 | { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
12821 | { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, false }, | |
12822 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, false }, | |
12823 | { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
12824 | { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
12825 | { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
12826 | { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
12827 | { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
12828 | { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev) }, display_debug_types, &do_debug_info, true }, | |
12829 | { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
12830 | { { ".gdb_index", "", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, false }, | |
12831 | { { ".debug_names", "", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, false }, | |
12832 | { { ".trace_info", "", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, true }, | |
12833 | { { ".trace_abbrev", "", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, false }, | |
12834 | { { ".trace_aranges", "", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, false }, | |
12835 | { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, true }, | |
12836 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, | |
12837 | { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, true }, | |
12838 | { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, | |
12839 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
12840 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, | |
12841 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, | |
12842 | { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS }, display_debug_str, &do_debug_str, true }, | |
12843 | { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, | |
12844 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, | |
12845 | { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS }, display_debug_addr, &do_debug_addr, true }, | |
12846 | { { ".debug_cu_index", "", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, | |
12847 | { { ".debug_tu_index", "", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, | |
12848 | { { ".gnu_debuglink", "", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, | |
12849 | { { ".gnu_debugaltlink", "", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, | |
12850 | { { ".debug_sup", "", "", NO_ABBREVS }, display_debug_sup, &do_debug_links, false }, | |
12851 | /* Separate debug info files can containt their own .debug_str section, | |
12852 | and this might be in *addition* to a .debug_str section already present | |
12853 | in the main file. Hence we need to have two entries for .debug_str. */ | |
12854 | { { ".debug_str", ".zdebug_str", "", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
12855 | { { ".note.gnu.build-id", "", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
12856 | }; | |
12857 | ||
12858 | /* A static assertion. */ | |
12859 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |