/src/binutils-gdb/binutils/dwarf.c
Line | Count | Source |
1 | | /* dwarf.c -- display DWARF contents of a BFD binary file |
2 | | Copyright (C) 2005-2026 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of GNU Binutils. |
5 | | |
6 | | This program is free software; you can redistribute it and/or modify |
7 | | it under the terms of the GNU General Public License as published by |
8 | | the Free Software Foundation; either version 3 of the License, or |
9 | | (at your option) any later version. |
10 | | |
11 | | This program is distributed in the hope that it will be useful, |
12 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | GNU General Public License for more details. |
15 | | |
16 | | You should have received a copy of the GNU General Public License |
17 | | along with this program; if not, write to the Free Software |
18 | | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
19 | | 02110-1301, USA. */ |
20 | | |
21 | | #include "sysdep.h" |
22 | | #include "libiberty.h" |
23 | | #include "bfd.h" |
24 | | #include <stdint.h> |
25 | | #include "bucomm.h" |
26 | | #include "elfcomm.h" |
27 | | #include "elf/common.h" |
28 | | #include "dwarf2.h" |
29 | | #include "dwarf.h" |
30 | | #include "gdb/gdb-index.h" |
31 | | #include "filenames.h" |
32 | | #include "safe-ctype.h" |
33 | | #include "sframe-api.h" |
34 | | #include <assert.h> |
35 | | |
36 | | #ifdef HAVE_LIBDEBUGINFOD |
37 | | #include <elfutils/debuginfod.h> |
38 | | #endif |
39 | | |
40 | | #include <limits.h> |
41 | | #ifndef CHAR_BIT |
42 | | #define CHAR_BIT 8 |
43 | | #endif |
44 | | |
45 | | #ifndef ENABLE_CHECKING |
46 | | #define ENABLE_CHECKING 0 |
47 | | #endif |
48 | | |
49 | | #undef MAX |
50 | | #undef MIN |
51 | 0 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
52 | | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
53 | | |
54 | | /* Flag values for the do_flags parameter passed |
55 | | to the process_debug_info() function. */ |
56 | 10.0k | #define DO_LOC 0x1 |
57 | 4.70k | #define DO_TYPES 0x2 |
58 | 14.0k | #define DO_GLOBAL_VARS 0x4 |
59 | | |
60 | 0 | #define PRINT_SPACE(n) do { \ |
61 | 0 | int _i; \ |
62 | 0 | for (_i = 0; _i < (n); ++_i) \ |
63 | 0 | putchar (' '); \ |
64 | 0 | } while (0) |
65 | | |
66 | 0 | #define PRINT_LBRACE(n) do { \ |
67 | 0 | PRINT_SPACE (n); \ |
68 | 0 | putchar ('{'); \ |
69 | 0 | putchar ('\n'); \ |
70 | 0 | } while (0) |
71 | | |
72 | 0 | #define PRINT_RBRACE(n) do { \ |
73 | 0 | PRINT_SPACE (n); \ |
74 | 0 | putchar ('}'); \ |
75 | 0 | putchar ('\n'); \ |
76 | 0 | } while (0) |
77 | | |
78 | | static const char *regname (unsigned int regno, int row); |
79 | | static const char *regname_internal_by_table_only (unsigned int regno); |
80 | | |
81 | | static int have_frame_base; |
82 | | static int frame_base_level = -1; /* To support nested DW_TAG_subprogram's. */ |
83 | | static int need_base_address; |
84 | | |
85 | | static unsigned int num_debug_info_entries = 0; |
86 | | static unsigned int alloc_num_debug_info_entries = 0; |
87 | | static debug_info *debug_information = NULL; |
88 | | |
89 | | static struct base_type_l base_type_list = {NULL, NULL}; |
90 | | static struct type_def_l type_def_list = {NULL, NULL}; |
91 | | static struct enum_type_l enum_type_list = {NULL, NULL}; |
92 | | static struct tab_type_l tab_type_list = {NULL, NULL}; |
93 | | static struct member_parent_l struct_type_list = {NULL, NULL}; |
94 | | static struct member_parent_l union_type_list = {NULL, NULL}; |
95 | | static struct type_ptr_l ptr_type_list = {NULL, NULL}; |
96 | | static struct type_ref_l const_type_list = {NULL, NULL}; |
97 | | static struct type_ref_l volatile_type_list = {NULL, NULL}; |
98 | | static struct variable_type_l variable_type_list = {NULL, NULL}; |
99 | | |
100 | | /* Special value for num_debug_info_entries to indicate |
101 | | that the .debug_info section could not be loaded/parsed. */ |
102 | 10.0k | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 |
103 | | |
104 | | /* A .debug_info section can contain multiple links to separate |
105 | | DWO object files. We use these structures to record these links. */ |
106 | | typedef enum dwo_type |
107 | | { |
108 | | DWO_NAME, |
109 | | DWO_DIR, |
110 | | DWO_ID |
111 | | } dwo_type; |
112 | | |
113 | | typedef struct dwo_info |
114 | | { |
115 | | dwo_type type; |
116 | | const char * value; |
117 | | uint64_t cu_offset; |
118 | | struct dwo_info * next; |
119 | | } dwo_info; |
120 | | |
121 | | static dwo_info *first_dwo_info = NULL; |
122 | | static bool need_dwo_info; |
123 | | |
124 | | separate_info * first_separate_info = NULL; |
125 | | |
126 | | unsigned int eh_addr_size; |
127 | | |
128 | | const char * separate_debug_info_dir = NULL; |
129 | | |
130 | | int do_debug_info; |
131 | | int do_debug_abbrevs; |
132 | | int do_debug_lines; |
133 | | int do_debug_pubnames; |
134 | | int do_debug_pubtypes; |
135 | | int do_debug_aranges; |
136 | | int do_debug_ranges; |
137 | | int do_debug_frames; |
138 | | int do_debug_frames_interp; |
139 | | int do_debug_macinfo; |
140 | | int do_debug_str; |
141 | | int do_debug_str_offsets; |
142 | | int do_debug_loc; |
143 | | int do_gdb_index; |
144 | | int do_sframe; |
145 | | int do_trace_info; |
146 | | int do_trace_abbrevs; |
147 | | int do_trace_aranges; |
148 | | int do_debug_addr; |
149 | | int do_debug_cu_index; |
150 | | int do_wide; |
151 | | int do_debug_links; |
152 | | int do_follow_links = DEFAULT_FOR_FOLLOW_LINKS; |
153 | | #ifdef HAVE_LIBDEBUGINFOD |
154 | | int use_debuginfod = 1; |
155 | | #endif |
156 | | bool do_checks; |
157 | | |
158 | | int dwarf_cutoff_level = -1; |
159 | | unsigned long dwarf_start_die; |
160 | | |
161 | | int dwarf_check = 0; |
162 | | |
163 | | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
164 | | sections. For version 1 package files, each set is stored in SHNDX_POOL |
165 | | as a zero-terminated list of section indexes comprising one set of debug |
166 | | sections from a .dwo file. */ |
167 | | |
168 | | static unsigned int *shndx_pool = NULL; |
169 | | static unsigned int shndx_pool_size = 0; |
170 | | static unsigned int shndx_pool_used = 0; |
171 | | |
172 | | /* For version 2 package files, each set contains an array of section offsets |
173 | | and an array of section sizes, giving the offset and size of the |
174 | | contribution from a CU or TU within one of the debug sections. |
175 | | When displaying debug info from a package file, we need to use these |
176 | | tables to locate the corresponding contributions to each section. */ |
177 | | |
178 | | struct cu_tu_set |
179 | | { |
180 | | uint64_t signature; |
181 | | uint64_t section_offsets[DW_SECT_MAX]; |
182 | | size_t section_sizes[DW_SECT_MAX]; |
183 | | }; |
184 | | |
185 | | static int cu_count = 0; |
186 | | static int tu_count = 0; |
187 | | static struct cu_tu_set *cu_sets = NULL; |
188 | | static struct cu_tu_set *tu_sets = NULL; |
189 | | |
190 | | static bool load_cu_tu_indexes (void *); |
191 | | |
192 | | /* An array that indicates for a given level of CU nesting whether |
193 | | the latest DW_AT_type seen for that level was a signed type or |
194 | | an unsigned type. */ |
195 | 678 | #define MAX_CU_NESTING (1 << 8) |
196 | | static bool level_type_signed[MAX_CU_NESTING]; |
197 | | |
198 | | /* Values for do_debug_lines. */ |
199 | 70.7k | #define FLAG_DEBUG_LINES_RAW 1 |
200 | 355 | #define FLAG_DEBUG_LINES_DECODED 2 |
201 | | |
202 | | static unsigned int |
203 | | size_of_encoded_value (int encoding) |
204 | 7.38k | { |
205 | 7.38k | switch (encoding & 0x7) |
206 | 7.38k | { |
207 | 61 | default: /* ??? */ |
208 | 5.02k | case 0: return eh_addr_size; |
209 | 53 | case 2: return 2; |
210 | 2.29k | case 3: return 4; |
211 | 4 | case 4: return 8; |
212 | 7.38k | } |
213 | 7.38k | } |
214 | | |
215 | | static uint64_t |
216 | | get_encoded_value (unsigned char **pdata, |
217 | | int encoding, |
218 | | struct dwarf_section *section, |
219 | | unsigned char * end) |
220 | 6.02k | { |
221 | 6.02k | unsigned char * data = * pdata; |
222 | 6.02k | unsigned int size = size_of_encoded_value (encoding); |
223 | 6.02k | uint64_t val; |
224 | | |
225 | 6.02k | if (data >= end || size > (size_t) (end - data)) |
226 | 133 | { |
227 | 133 | warn (_("Encoded value extends past end of section\n")); |
228 | 133 | * pdata = end; |
229 | 133 | return 0; |
230 | 133 | } |
231 | | |
232 | | /* PR 17512: file: 002-829853-0.004. */ |
233 | 5.89k | if (size > 8) |
234 | 0 | { |
235 | 0 | warn (_("Encoded size of %d is too large to read\n"), size); |
236 | 0 | * pdata = end; |
237 | 0 | return 0; |
238 | 0 | } |
239 | | |
240 | | /* PR 17512: file: 1085-5603-0.004. */ |
241 | 5.89k | if (size == 0) |
242 | 0 | { |
243 | 0 | warn (_("Encoded size of 0 is too small to read\n")); |
244 | 0 | * pdata = end; |
245 | 0 | return 0; |
246 | 0 | } |
247 | | |
248 | 5.89k | if (encoding & DW_EH_PE_signed) |
249 | 1.01k | val = byte_get_signed (data, size); |
250 | 4.87k | else |
251 | 4.87k | val = byte_get (data, size); |
252 | | |
253 | 5.89k | if ((encoding & 0x70) == DW_EH_PE_pcrel) |
254 | 1.00k | val += section->address + (data - section->start); |
255 | | |
256 | 5.89k | * pdata = data + size; |
257 | 5.89k | return val; |
258 | 5.89k | } |
259 | | |
260 | | /* Print a uint64_t value (typically an address, offset or length) in |
261 | | hexadecimal format, followed by a space. The precision displayed is |
262 | | determined by the NUM_BYTES parameter. */ |
263 | | |
264 | | static void |
265 | | print_hex (uint64_t value, unsigned num_bytes) |
266 | 11.0k | { |
267 | 11.0k | if (num_bytes == 0) |
268 | 0 | num_bytes = 2; |
269 | | |
270 | 11.0k | printf ("%0*" PRIx64 " ", num_bytes * 2, |
271 | 11.0k | value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); |
272 | 11.0k | } |
273 | | |
274 | | /* Like print_hex, but no trailing space. */ |
275 | | |
276 | | static void |
277 | | print_hex_ns (uint64_t value, unsigned num_bytes) |
278 | 66.4k | { |
279 | 66.4k | if (num_bytes == 0) |
280 | 0 | num_bytes = 2; |
281 | | |
282 | 66.4k | printf ("%0*" PRIx64, num_bytes * 2, |
283 | 66.4k | value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); |
284 | 66.4k | } |
285 | | |
286 | | /* Print a view number in hexadecimal value, with the same width as |
287 | | print_hex would have printed it. */ |
288 | | |
289 | | static void |
290 | | print_view (uint64_t value, unsigned num_bytes) |
291 | 0 | { |
292 | 0 | if (num_bytes == 0) |
293 | 0 | num_bytes = 2; |
294 | |
|
295 | 0 | printf ("v%0*" PRIx64 " ", num_bytes * 2 - 1, |
296 | 0 | value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); |
297 | 0 | } |
298 | | |
299 | | static const char * |
300 | | null_name (const char *p) |
301 | 63 | { |
302 | 63 | if (p == NULL) |
303 | 9 | p = _("unknown"); |
304 | 63 | return p; |
305 | 63 | } |
306 | | |
307 | | /* Read in a LEB128 encoded value starting at address DATA. |
308 | | If SIGN is true, return a signed LEB128 value. |
309 | | If LENGTH_RETURN is not NULL, return in it the number of bytes read. |
310 | | If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the |
311 | | terminating byte was not found and with bit 1 set if the value |
312 | | overflows a uint64_t. |
313 | | No bytes will be read at address END or beyond. */ |
314 | | |
315 | | uint64_t |
316 | | read_leb128 (const unsigned char *data, |
317 | | const unsigned char *const end, |
318 | | bool sign, |
319 | | unsigned int *length_return, |
320 | | int *status_return) |
321 | 5.79M | { |
322 | 5.79M | uint64_t result = 0; |
323 | 5.79M | unsigned int num_read = 0; |
324 | 5.79M | unsigned int shift = 0; |
325 | 5.79M | int status = 1; |
326 | | |
327 | 8.16M | while (data < end) |
328 | 8.16M | { |
329 | 8.16M | unsigned char byte = *data++; |
330 | 8.16M | unsigned char lost, mask; |
331 | | |
332 | 8.16M | num_read++; |
333 | | |
334 | 8.16M | if (shift < CHAR_BIT * sizeof (result)) |
335 | 7.47M | { |
336 | 7.47M | result |= ((uint64_t) (byte & 0x7f)) << shift; |
337 | | /* These bits overflowed. */ |
338 | 7.47M | lost = byte ^ (result >> shift); |
339 | | /* And this is the mask of possible overflow bits. */ |
340 | 7.47M | mask = 0x7f ^ ((uint64_t) 0x7f << shift >> shift); |
341 | 7.47M | shift += 7; |
342 | 7.47M | } |
343 | 688k | else |
344 | 688k | { |
345 | 688k | lost = byte; |
346 | 688k | mask = 0x7f; |
347 | 688k | } |
348 | 8.16M | if ((lost & mask) != (sign && (int64_t) result < 0 ? mask : 0)) |
349 | 709k | status |= 2; |
350 | | |
351 | 8.16M | if ((byte & 0x80) == 0) |
352 | 5.78M | { |
353 | 5.78M | status &= ~1; |
354 | 5.78M | if (sign && shift < CHAR_BIT * sizeof (result) && (byte & 0x40)) |
355 | 7.66k | result |= -((uint64_t) 1 << shift); |
356 | 5.78M | break; |
357 | 5.78M | } |
358 | 8.16M | } |
359 | | |
360 | 5.79M | if (length_return != NULL) |
361 | 5.79M | *length_return = num_read; |
362 | 5.79M | if (status_return != NULL) |
363 | 5.67M | *status_return = status; |
364 | | |
365 | 5.79M | return result; |
366 | 5.79M | } |
367 | | |
368 | | /* Read AMOUNT bytes from PTR and store them in VAL. |
369 | | Checks to make sure that the read will not reach or pass END. |
370 | | FUNC chooses whether the value read is unsigned or signed, and may |
371 | | be either byte_get or byte_get_signed. If INC is true, PTR is |
372 | | incremented after reading the value. |
373 | | This macro cannot protect against PTR values derived from user input. |
374 | | The C standard sections 6.5.6 and 6.5.8 say attempts to do so using |
375 | | pointers is undefined behaviour. */ |
376 | | #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \ |
377 | 54.4k | do \ |
378 | 54.4k | { \ |
379 | 54.4k | size_t amount = (AMOUNT); \ |
380 | 54.4k | if (sizeof (VAL) < amount) \ |
381 | 54.4k | { \ |
382 | 0 | error (ngettext ("internal error: attempt to read %d byte " \ |
383 | 0 | "of data in to %d sized variable", \ |
384 | 0 | "internal error: attempt to read %d bytes " \ |
385 | 0 | "of data in to %d sized variable", \ |
386 | 0 | amount), \ |
387 | 0 | (int) amount, (int) sizeof (VAL)); \ |
388 | 0 | amount = sizeof (VAL); \ |
389 | 0 | } \ |
390 | 54.4k | if (ENABLE_CHECKING) \ |
391 | 54.4k | assert ((PTR) <= (END)); \ |
392 | 54.4k | size_t avail = (END) - (PTR); \ |
393 | 54.4k | if ((PTR) > (END)) \ |
394 | 54.4k | avail = 0; \ |
395 | 54.4k | if (amount > avail) \ |
396 | 54.4k | amount = avail; \ |
397 | 54.4k | if (amount == 0) \ |
398 | 54.4k | (VAL) = 0; \ |
399 | 54.4k | else \ |
400 | 54.4k | (VAL) = (FUNC) ((PTR), amount); \ |
401 | 54.4k | if (INC) \ |
402 | 54.4k | (PTR) += amount; \ |
403 | 54.4k | } \ |
404 | 54.4k | while (0) |
405 | | |
406 | | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
407 | 536 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false) |
408 | | |
409 | | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
410 | 50.5k | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true) |
411 | | |
412 | | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
413 | | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false) |
414 | | |
415 | | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
416 | 3.45k | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true) |
417 | | |
418 | | typedef struct State_Machine_Registers |
419 | | { |
420 | | uint64_t address; |
421 | | unsigned int view; |
422 | | unsigned int file; |
423 | | unsigned int line; |
424 | | unsigned int column; |
425 | | int is_stmt; |
426 | | int basic_block; |
427 | | unsigned char op_index; |
428 | | unsigned char end_sequence; |
429 | | /* This variable hold the number of the last entry seen |
430 | | in the File Table. */ |
431 | | unsigned int last_file_entry; |
432 | | } SMR; |
433 | | |
434 | | static SMR state_machine_regs; |
435 | | |
436 | | static void |
437 | | reset_state_machine (int is_stmt) |
438 | 572 | { |
439 | 572 | state_machine_regs.address = 0; |
440 | 572 | state_machine_regs.view = 0; |
441 | 572 | state_machine_regs.op_index = 0; |
442 | 572 | state_machine_regs.file = 1; |
443 | 572 | state_machine_regs.line = 1; |
444 | 572 | state_machine_regs.column = 0; |
445 | 572 | state_machine_regs.is_stmt = is_stmt; |
446 | 572 | state_machine_regs.basic_block = 0; |
447 | 572 | state_machine_regs.end_sequence = 0; |
448 | 572 | state_machine_regs.last_file_entry = 0; |
449 | 572 | } |
450 | | |
451 | | /* Handled an extend line op. |
452 | | Returns the number of bytes read. */ |
453 | | |
454 | | static size_t |
455 | | process_extended_line_op (unsigned char * data, |
456 | | int is_stmt, |
457 | | unsigned char * end) |
458 | 881 | { |
459 | 881 | unsigned char op_code; |
460 | 881 | size_t len, header_len; |
461 | 881 | unsigned char *name; |
462 | 881 | unsigned char *orig_data = data; |
463 | 881 | uint64_t adr, val; |
464 | | |
465 | 881 | READ_ULEB (len, data, end); |
466 | 881 | header_len = data - orig_data; |
467 | | |
468 | 881 | if (len == 0 || data >= end || len > (size_t) (end - data)) |
469 | 237 | { |
470 | 237 | warn (_("Badly formed extended line op encountered!\n")); |
471 | 237 | return header_len; |
472 | 237 | } |
473 | | |
474 | 644 | op_code = *data++; |
475 | | |
476 | 644 | printf (_(" Extended opcode %d: "), op_code); |
477 | | |
478 | 644 | switch (op_code) |
479 | 644 | { |
480 | 289 | case DW_LNE_end_sequence: |
481 | 289 | printf (_("End of Sequence\n\n")); |
482 | 289 | reset_state_machine (is_stmt); |
483 | 289 | break; |
484 | | |
485 | 299 | case DW_LNE_set_address: |
486 | | /* PR 17512: file: 002-100480-0.004. */ |
487 | 299 | if (len - 1 > 8) |
488 | 1 | { |
489 | 1 | warn (_("Length (%zu) of DW_LNE_set_address op is too long\n"), |
490 | 1 | len - 1); |
491 | 1 | adr = 0; |
492 | 1 | } |
493 | 298 | else |
494 | 299 | SAFE_BYTE_GET (adr, data, len - 1, end); |
495 | 299 | printf (_("set Address to %#" PRIx64 "\n"), adr); |
496 | 299 | state_machine_regs.address = adr; |
497 | 299 | state_machine_regs.view = 0; |
498 | 299 | state_machine_regs.op_index = 0; |
499 | 299 | break; |
500 | | |
501 | 5 | case DW_LNE_define_file: |
502 | 5 | printf (_("define new File Table entry\n")); |
503 | 5 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
504 | 5 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
505 | | |
506 | 5 | { |
507 | 5 | size_t l; |
508 | | |
509 | 5 | name = data; |
510 | 5 | l = strnlen ((char *) data, end - data); |
511 | 5 | data += l; |
512 | 5 | if (data < end) |
513 | 5 | data++; |
514 | 5 | READ_ULEB (val, data, end); |
515 | 5 | printf ("%" PRIu64 "\t", val); |
516 | 5 | READ_ULEB (val, data, end); |
517 | 5 | printf ("%" PRIu64 "\t", val); |
518 | 5 | READ_ULEB (val, data, end); |
519 | 5 | printf ("%" PRIu64 "\t", val); |
520 | 5 | printf ("%.*s\n\n", (int) l, name); |
521 | 5 | } |
522 | | |
523 | 5 | if (((size_t) (data - orig_data) != len + header_len) || data >= end) |
524 | 1 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
525 | 5 | break; |
526 | | |
527 | 16 | case DW_LNE_set_discriminator: |
528 | 16 | READ_ULEB (val, data, end); |
529 | 16 | printf (_("set Discriminator to %" PRIu64 "\n"), val); |
530 | 16 | break; |
531 | | |
532 | | /* HP extensions. */ |
533 | 0 | case DW_LNE_HP_negate_is_UV_update: |
534 | 0 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
535 | 0 | break; |
536 | 2 | case DW_LNE_HP_push_context: |
537 | 2 | printf ("DW_LNE_HP_push_context\n"); |
538 | 2 | break; |
539 | 0 | case DW_LNE_HP_pop_context: |
540 | 0 | printf ("DW_LNE_HP_pop_context\n"); |
541 | 0 | break; |
542 | 0 | case DW_LNE_HP_set_file_line_column: |
543 | 0 | printf ("DW_LNE_HP_set_file_line_column\n"); |
544 | 0 | break; |
545 | 0 | case DW_LNE_HP_set_routine_name: |
546 | 0 | printf ("DW_LNE_HP_set_routine_name\n"); |
547 | 0 | break; |
548 | 0 | case DW_LNE_HP_set_sequence: |
549 | 0 | printf ("DW_LNE_HP_set_sequence\n"); |
550 | 0 | break; |
551 | 0 | case DW_LNE_HP_negate_post_semantics: |
552 | 0 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
553 | 0 | break; |
554 | 0 | case DW_LNE_HP_negate_function_exit: |
555 | 0 | printf ("DW_LNE_HP_negate_function_exit\n"); |
556 | 0 | break; |
557 | 0 | case DW_LNE_HP_negate_front_end_logical: |
558 | 0 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
559 | 0 | break; |
560 | 0 | case DW_LNE_HP_define_proc: |
561 | 0 | printf ("DW_LNE_HP_define_proc\n"); |
562 | 0 | break; |
563 | 0 | case DW_LNE_HP_source_file_correlation: |
564 | 0 | { |
565 | 0 | unsigned char *edata = data + len - 1; |
566 | |
|
567 | 0 | printf ("DW_LNE_HP_source_file_correlation\n"); |
568 | |
|
569 | 0 | while (data < edata) |
570 | 0 | { |
571 | 0 | unsigned int opc; |
572 | |
|
573 | 0 | READ_ULEB (opc, data, edata); |
574 | |
|
575 | 0 | switch (opc) |
576 | 0 | { |
577 | 0 | case DW_LNE_HP_SFC_formfeed: |
578 | 0 | printf (" DW_LNE_HP_SFC_formfeed\n"); |
579 | 0 | break; |
580 | 0 | case DW_LNE_HP_SFC_set_listing_line: |
581 | 0 | READ_ULEB (val, data, edata); |
582 | 0 | printf (" DW_LNE_HP_SFC_set_listing_line (%" PRIu64 ")\n", |
583 | 0 | val); |
584 | 0 | break; |
585 | 0 | case DW_LNE_HP_SFC_associate: |
586 | 0 | printf (" DW_LNE_HP_SFC_associate "); |
587 | 0 | READ_ULEB (val, data, edata); |
588 | 0 | printf ("(%" PRIu64 , val); |
589 | 0 | READ_ULEB (val, data, edata); |
590 | 0 | printf (",%" PRIu64, val); |
591 | 0 | READ_ULEB (val, data, edata); |
592 | 0 | printf (",%" PRIu64 ")\n", val); |
593 | 0 | break; |
594 | 0 | default: |
595 | 0 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); |
596 | 0 | data = edata; |
597 | 0 | break; |
598 | 0 | } |
599 | 0 | } |
600 | 0 | } |
601 | 0 | break; |
602 | | |
603 | 33 | default: |
604 | 33 | { |
605 | 33 | unsigned int rlen = len - 1; |
606 | | |
607 | 33 | if (op_code >= DW_LNE_lo_user |
608 | | /* The test against DW_LNW_hi_user is redundant due to |
609 | | the limited range of the unsigned char data type used |
610 | | for op_code. */ |
611 | 33 | /*&& op_code <= DW_LNE_hi_user*/) |
612 | 6 | printf (_("user defined: ")); |
613 | 27 | else |
614 | 27 | printf (_("UNKNOWN: ")); |
615 | 33 | printf (_("length %d ["), rlen); |
616 | 634 | for (; rlen; rlen--) |
617 | 601 | printf (" %02x", *data++); |
618 | 33 | printf ("]\n"); |
619 | 33 | } |
620 | 33 | break; |
621 | 644 | } |
622 | | |
623 | 644 | return len + header_len; |
624 | 644 | } |
625 | | |
626 | | static const char * |
627 | | fetch_indirect_string (uint64_t offset) |
628 | 1.80k | { |
629 | 1.80k | struct dwarf_section *section = &debug_displays [str].section; |
630 | 1.80k | const char *ret; |
631 | | |
632 | 1.80k | if (section->start == NULL) |
633 | 204 | return _("<no .debug_str section>"); |
634 | | |
635 | 1.60k | if (offset >= section->size) |
636 | 242 | { |
637 | 242 | warn (_("DW_FORM_strp offset too big: %#" PRIx64 "\n"), offset); |
638 | 242 | return _("<offset is too big>"); |
639 | 242 | } |
640 | | |
641 | 1.36k | ret = (const char *) (section->start + offset); |
642 | | /* Unfortunately we cannot rely upon the .debug_str section ending with a |
643 | | NUL byte. Since our caller is expecting to receive a well formed C |
644 | | string we test for the lack of a terminating byte here. */ |
645 | 1.36k | if (strnlen (ret, section->size - offset) |
646 | 1.36k | == section->size - offset) |
647 | 58 | ret = _("<no NUL byte at end of .debug_str section>"); |
648 | | |
649 | 1.36k | return ret; |
650 | 1.60k | } |
651 | | |
652 | | static const char * |
653 | | fetch_indirect_line_string (uint64_t offset) |
654 | 12 | { |
655 | 12 | struct dwarf_section *section = &debug_displays [line_str].section; |
656 | 12 | const char *ret; |
657 | | |
658 | 12 | if (section->start == NULL) |
659 | 0 | return _("<no .debug_line_str section>"); |
660 | | |
661 | 12 | if (offset >= section->size) |
662 | 2 | { |
663 | 2 | warn (_("DW_FORM_line_strp offset too big: %#" PRIx64 "\n"), offset); |
664 | 2 | return _("<offset is too big>"); |
665 | 2 | } |
666 | | |
667 | 10 | ret = (const char *) (section->start + offset); |
668 | | /* Unfortunately we cannot rely upon the .debug_line_str section ending |
669 | | with a NUL byte. Since our caller is expecting to receive a well formed |
670 | | C string we test for the lack of a terminating byte here. */ |
671 | 10 | if (strnlen (ret, section->size - offset) |
672 | 10 | == section->size - offset) |
673 | 0 | ret = _("<no NUL byte at end of .debug_line_str section>"); |
674 | | |
675 | 10 | return ret; |
676 | 12 | } |
677 | | |
678 | | static const char * |
679 | | fetch_indexed_string (uint64_t idx, |
680 | | struct cu_tu_set *this_set, |
681 | | uint64_t offset_size, |
682 | | bool dwo, |
683 | | uint64_t str_offsets_base) |
684 | 802 | { |
685 | 802 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; |
686 | 802 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; |
687 | 802 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; |
688 | 802 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; |
689 | 802 | uint64_t index_offset; |
690 | 802 | uint64_t str_offset; |
691 | 802 | const char * ret; |
692 | | |
693 | 802 | if (index_section->start == NULL) |
694 | 36 | return (dwo ? _("<no .debug_str_offsets.dwo section>") |
695 | 36 | : _("<no .debug_str_offsets section>")); |
696 | | |
697 | 766 | if (str_section->start == NULL) |
698 | 728 | return (dwo ? _("<no .debug_str.dwo section>") |
699 | 728 | : _("<no .debug_str section>")); |
700 | | |
701 | 38 | if (_mul_overflow (idx, offset_size, &index_offset) |
702 | 38 | || (this_set != NULL |
703 | 0 | && ((index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]) |
704 | 0 | < this_set->section_offsets [DW_SECT_STR_OFFSETS])) |
705 | 38 | || (index_offset += str_offsets_base) < str_offsets_base |
706 | 38 | || index_offset + offset_size < offset_size |
707 | 38 | || index_offset + offset_size > index_section->size) |
708 | 3 | { |
709 | 3 | warn (_("string index of %" PRIu64 " converts to an offset of %#" PRIx64 |
710 | 3 | " which is too big for section %s\n"), |
711 | 3 | idx, index_offset, str_section->name); |
712 | | |
713 | 3 | return _("<string index too big>"); |
714 | 3 | } |
715 | | |
716 | 35 | str_offset = byte_get (index_section->start + index_offset, offset_size); |
717 | | |
718 | 35 | if (str_offset >= str_section->size) |
719 | 1 | { |
720 | 1 | warn (_("indirect offset too big: %#" PRIx64 "\n"), str_offset); |
721 | 1 | return _("<indirect index offset is too big>"); |
722 | 1 | } |
723 | | |
724 | 34 | ret = (const char *) str_section->start + str_offset; |
725 | | |
726 | | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. |
727 | | Since our caller is expecting to receive a well formed C string we test |
728 | | for the lack of a terminating byte here. */ |
729 | 34 | if (strnlen (ret, str_section->size - str_offset) |
730 | 34 | == str_section->size - str_offset) |
731 | 0 | return _("<no NUL byte at end of section>"); |
732 | | |
733 | 34 | return ret; |
734 | 34 | } |
735 | | |
736 | | static uint64_t |
737 | | fetch_indexed_addr (uint64_t offset, uint32_t num_bytes) |
738 | 76 | { |
739 | 76 | struct dwarf_section *section = &debug_displays [debug_addr].section; |
740 | | |
741 | 76 | if (section->start == NULL) |
742 | 49 | { |
743 | 49 | warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n")); |
744 | 49 | return 0; |
745 | 49 | } |
746 | | |
747 | 27 | if (offset > section->size |
748 | 9 | || num_bytes > section->size - offset) |
749 | 18 | { |
750 | 18 | warn (_("Offset into section %s too big: %#" PRIx64 "\n"), |
751 | 18 | section->name, offset); |
752 | 18 | return 0; |
753 | 18 | } |
754 | | |
755 | 9 | return byte_get (section->start + offset, num_bytes); |
756 | 27 | } |
757 | | |
758 | | /* This is for resolving DW_FORM_rnglistx and DW_FORM_loclistx. |
759 | | |
760 | | The memory layout is: base_address (taken from the CU's top DIE) points at a table of offsets, |
761 | | relative to the section start. |
762 | | The table of offsets contains the offsets of objects of interest relative to the table of offsets. |
763 | | IDX is the index of the desired object in said table of offsets. |
764 | | |
765 | | This returns the offset of the desired object relative to the section start or -1 upon failure. */ |
766 | | |
767 | | static uint64_t |
768 | | fetch_indexed_offset (uint64_t idx, |
769 | | enum dwarf_section_display_enum sec_enum, |
770 | | uint64_t base_address, |
771 | | uint64_t offset_size) |
772 | 17 | { |
773 | 17 | uint64_t offset_of_offset; |
774 | 17 | struct dwarf_section *section = &debug_displays [sec_enum].section; |
775 | | |
776 | 17 | if (section->start == NULL) |
777 | 11 | { |
778 | 11 | warn (_("Unable to locate %s section\n"), section->uncompressed_name); |
779 | 11 | return -1; |
780 | 11 | } |
781 | | |
782 | 6 | if (_bfd_mul_overflow (idx, offset_size, &offset_of_offset) |
783 | 6 | || (offset_of_offset += base_address) < base_address |
784 | 6 | || offset_of_offset > section->size |
785 | 6 | || offset_size > section->size - offset_of_offset) |
786 | 0 | { |
787 | 0 | warn (_("Base %#" PRIx64 " with index %#" PRIx64 " is too big for section %s\n"), |
788 | 0 | base_address, idx, section->name); |
789 | 0 | return -1; |
790 | 0 | } |
791 | | |
792 | 6 | return base_address + byte_get (section->start + offset_of_offset, offset_size); |
793 | 6 | } |
794 | | |
795 | | /* FIXME: There are better and more efficient ways to handle |
796 | | these structures. For now though, I just want something that |
797 | | is simple to implement. */ |
798 | | /* Records a single attribute in an abbrev. */ |
799 | | typedef struct abbrev_attr |
800 | | { |
801 | | unsigned long attribute; |
802 | | unsigned long form; |
803 | | int64_t implicit_const; |
804 | | struct abbrev_attr *next; |
805 | | } |
806 | | abbrev_attr; |
807 | | |
808 | | /* Records a single abbrev. */ |
809 | | typedef struct abbrev_entry |
810 | | { |
811 | | unsigned long number; |
812 | | unsigned long tag; |
813 | | int children; |
814 | | struct abbrev_attr * first_attr; |
815 | | struct abbrev_attr * last_attr; |
816 | | struct abbrev_entry * next; |
817 | | } |
818 | | abbrev_entry; |
819 | | |
820 | | /* Records a set of abbreviations. */ |
821 | | typedef struct abbrev_list |
822 | | { |
823 | | abbrev_entry * first_abbrev; |
824 | | abbrev_entry * last_abbrev; |
825 | | unsigned char * raw; |
826 | | struct abbrev_list * next; |
827 | | unsigned char * start_of_next_abbrevs; |
828 | | } |
829 | | abbrev_list; |
830 | | |
831 | | /* Records all the abbrevs found so far. */ |
832 | | static struct abbrev_list * abbrev_lists = NULL; |
833 | | |
834 | | typedef struct abbrev_map |
835 | | { |
836 | | uint64_t start; |
837 | | uint64_t end; |
838 | | abbrev_list *list; |
839 | | } abbrev_map; |
840 | | |
841 | | /* Maps between CU offsets and abbrev sets. */ |
842 | | static abbrev_map * cu_abbrev_map = NULL; |
843 | | static unsigned long num_abbrev_map_entries = 0; |
844 | | static unsigned long next_free_abbrev_map_entry = 0; |
845 | | |
846 | 473 | #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8 |
847 | 9 | #define ABBREV_MAP_ENTRIES_INCREMENT 8 |
848 | | |
849 | | static void |
850 | | record_abbrev_list_for_cu (uint64_t start, uint64_t end, |
851 | | abbrev_list *list, abbrev_list *free_list) |
852 | 669 | { |
853 | 669 | if (free_list != NULL) |
854 | 545 | { |
855 | 545 | list->next = abbrev_lists; |
856 | 545 | abbrev_lists = list; |
857 | 545 | } |
858 | | |
859 | 669 | if (cu_abbrev_map == NULL) |
860 | 473 | { |
861 | 473 | num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES; |
862 | 473 | cu_abbrev_map = xmalloc (num_abbrev_map_entries * sizeof (* cu_abbrev_map)); |
863 | 473 | } |
864 | 196 | else if (next_free_abbrev_map_entry == num_abbrev_map_entries) |
865 | 9 | { |
866 | 9 | num_abbrev_map_entries += ABBREV_MAP_ENTRIES_INCREMENT; |
867 | 9 | cu_abbrev_map = xrealloc (cu_abbrev_map, num_abbrev_map_entries * sizeof (* cu_abbrev_map)); |
868 | 9 | } |
869 | | |
870 | 669 | cu_abbrev_map[next_free_abbrev_map_entry].start = start; |
871 | 669 | cu_abbrev_map[next_free_abbrev_map_entry].end = end; |
872 | 669 | cu_abbrev_map[next_free_abbrev_map_entry].list = list; |
873 | 669 | next_free_abbrev_map_entry ++; |
874 | 669 | } |
875 | | |
876 | | static abbrev_list * |
877 | | free_abbrev_list (abbrev_list *list) |
878 | 1.11M | { |
879 | 1.11M | abbrev_entry *abbrv = list->first_abbrev; |
880 | | |
881 | 1.44M | while (abbrv) |
882 | 336k | { |
883 | 336k | abbrev_attr *attr = abbrv->first_attr; |
884 | | |
885 | 1.73M | while (attr) |
886 | 1.39M | { |
887 | 1.39M | abbrev_attr *next_attr = attr->next; |
888 | 1.39M | free (attr); |
889 | 1.39M | attr = next_attr; |
890 | 1.39M | } |
891 | | |
892 | 336k | abbrev_entry *next_abbrev = abbrv->next; |
893 | 336k | free (abbrv); |
894 | 336k | abbrv = next_abbrev; |
895 | 336k | } |
896 | | |
897 | 1.11M | abbrev_list *next = list->next; |
898 | 1.11M | free (list); |
899 | 1.11M | return next; |
900 | 1.11M | } |
901 | | |
902 | | static void |
903 | | free_all_abbrevs (void) |
904 | 121k | { |
905 | 121k | while (abbrev_lists) |
906 | 545 | abbrev_lists = free_abbrev_list (abbrev_lists); |
907 | | |
908 | 121k | free (cu_abbrev_map); |
909 | 121k | cu_abbrev_map = NULL; |
910 | 121k | next_free_abbrev_map_entry = 0; |
911 | 121k | } |
912 | | |
913 | | static abbrev_list * |
914 | | find_abbrev_list_by_raw_abbrev (unsigned char *raw) |
915 | 1.05k | { |
916 | 1.05k | abbrev_list * list; |
917 | | |
918 | 1.23k | for (list = abbrev_lists; list != NULL; list = list->next) |
919 | 308 | if (list->raw == raw) |
920 | 124 | return list; |
921 | | |
922 | 929 | return NULL; |
923 | 1.05k | } |
924 | | |
925 | | /* Find the abbreviation map for the CU that includes OFFSET. |
926 | | OFFSET is an absolute offset from the start of the .debug_info section. */ |
927 | | /* FIXME: This function is going to slow down readelf & objdump. |
928 | | Not caching abbrevs is likely the answer. */ |
929 | | |
930 | | static abbrev_map * |
931 | | find_abbrev_map_by_offset (uint64_t offset) |
932 | 486 | { |
933 | 486 | unsigned long i; |
934 | | |
935 | 1.24k | for (i = 0; i < next_free_abbrev_map_entry; i++) |
936 | 1.24k | if (cu_abbrev_map[i].start <= offset |
937 | 1.24k | && cu_abbrev_map[i].end > offset) |
938 | 486 | return cu_abbrev_map + i; |
939 | | |
940 | 0 | return NULL; |
941 | 486 | } |
942 | | |
943 | | static void |
944 | | add_abbrev (unsigned long number, |
945 | | unsigned long tag, |
946 | | int children, |
947 | | abbrev_list * list) |
948 | 336k | { |
949 | 336k | abbrev_entry * entry; |
950 | | |
951 | 336k | entry = (abbrev_entry *) xmalloc (sizeof (*entry)); |
952 | | |
953 | 336k | entry->number = number; |
954 | 336k | entry->tag = tag; |
955 | 336k | entry->children = children; |
956 | 336k | entry->first_attr = NULL; |
957 | 336k | entry->last_attr = NULL; |
958 | 336k | entry->next = NULL; |
959 | | |
960 | 336k | assert (list != NULL); |
961 | | |
962 | 336k | if (list->first_abbrev == NULL) |
963 | 209k | list->first_abbrev = entry; |
964 | 127k | else |
965 | 127k | list->last_abbrev->next = entry; |
966 | | |
967 | 336k | list->last_abbrev = entry; |
968 | 336k | } |
969 | | |
970 | | static void |
971 | | add_abbrev_attr (unsigned long attribute, |
972 | | unsigned long form, |
973 | | int64_t implicit_const, |
974 | | abbrev_list *list) |
975 | 1.39M | { |
976 | 1.39M | abbrev_attr *attr; |
977 | | |
978 | 1.39M | attr = (abbrev_attr *) xmalloc (sizeof (*attr)); |
979 | | |
980 | 1.39M | attr->attribute = attribute; |
981 | 1.39M | attr->form = form; |
982 | 1.39M | attr->implicit_const = implicit_const; |
983 | 1.39M | attr->next = NULL; |
984 | | |
985 | 1.39M | assert (list != NULL && list->last_abbrev != NULL); |
986 | | |
987 | 1.39M | if (list->last_abbrev->first_attr == NULL) |
988 | 336k | list->last_abbrev->first_attr = attr; |
989 | 1.06M | else |
990 | 1.06M | list->last_abbrev->last_attr->next = attr; |
991 | | |
992 | 1.39M | list->last_abbrev->last_attr = attr; |
993 | 1.39M | } |
994 | | |
995 | | /* Return processed (partial) contents of a .debug_abbrev section. |
996 | | Returns NULL on errors. */ |
997 | | |
998 | | static abbrev_list * |
999 | | process_abbrev_set (struct dwarf_section *section, |
1000 | | unsigned char *start, |
1001 | | unsigned char *end) |
1002 | 1.11M | { |
1003 | 1.11M | abbrev_list *list = xmalloc (sizeof (*list)); |
1004 | 1.11M | list->first_abbrev = NULL; |
1005 | 1.11M | list->last_abbrev = NULL; |
1006 | 1.11M | list->raw = start; |
1007 | 1.11M | list->next = NULL; |
1008 | | |
1009 | 1.44M | while (start < end) |
1010 | 1.44M | { |
1011 | 1.44M | unsigned long entry; |
1012 | 1.44M | unsigned long tag; |
1013 | 1.44M | unsigned long attribute; |
1014 | 1.44M | int children; |
1015 | | |
1016 | 1.44M | READ_ULEB (entry, start, end); |
1017 | | |
1018 | | /* A single zero is supposed to end the set according |
1019 | | to the standard. If there's more, then signal that to |
1020 | | the caller. */ |
1021 | 1.44M | if (start == end || entry == 0) |
1022 | 1.10M | { |
1023 | 1.10M | list->start_of_next_abbrevs = start != end ? start : NULL; |
1024 | 1.10M | return list; |
1025 | 1.10M | } |
1026 | | |
1027 | 337k | READ_ULEB (tag, start, end); |
1028 | 337k | if (start == end) |
1029 | 160 | return free_abbrev_list (list); |
1030 | | |
1031 | 336k | children = *start++; |
1032 | | |
1033 | 336k | add_abbrev (entry, tag, children, list); |
1034 | | |
1035 | 336k | do |
1036 | 1.40M | { |
1037 | 1.40M | unsigned long form; |
1038 | | /* Initialize it due to a false compiler warning. */ |
1039 | 1.40M | int64_t implicit_const = -1; |
1040 | | |
1041 | 1.40M | READ_ULEB (attribute, start, end); |
1042 | 1.40M | if (start == end) |
1043 | 863 | break; |
1044 | | |
1045 | 1.40M | READ_ULEB (form, start, end); |
1046 | 1.40M | if (start == end) |
1047 | 796 | break; |
1048 | | |
1049 | 1.39M | if (form == DW_FORM_implicit_const) |
1050 | 4.22k | { |
1051 | 4.22k | READ_SLEB (implicit_const, start, end); |
1052 | 4.22k | if (start == end) |
1053 | 20 | break; |
1054 | 4.22k | } |
1055 | | |
1056 | 1.39M | add_abbrev_attr (attribute, form, implicit_const, list); |
1057 | 1.39M | } |
1058 | 1.39M | while (attribute != 0); |
1059 | 336k | } |
1060 | | |
1061 | | /* Report the missing single zero which ends the section. */ |
1062 | 1.67k | error (_("%s section not zero terminated\n"), section->name); |
1063 | | |
1064 | 1.67k | return free_abbrev_list (list); |
1065 | 1.11M | } |
1066 | | |
1067 | | /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE |
1068 | | plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE. |
1069 | | If FREE_LIST is non-NULL search the already decoded abbrevs on |
1070 | | abbrev_lists first and if found set *FREE_LIST to NULL. If |
1071 | | searching doesn't find a matching abbrev, set *FREE_LIST to the |
1072 | | newly allocated list. If FREE_LIST is NULL, no search is done and |
1073 | | the returned abbrev_list is always newly allocated. */ |
1074 | | |
1075 | | static abbrev_list * |
1076 | | find_and_process_abbrev_set (struct dwarf_section *section, |
1077 | | uint64_t abbrev_base, |
1078 | | uint64_t abbrev_size, |
1079 | | uint64_t abbrev_offset, |
1080 | | abbrev_list **free_list) |
1081 | 1.11M | { |
1082 | 1.11M | if (free_list) |
1083 | 1.13k | *free_list = NULL; |
1084 | | |
1085 | 1.11M | if (abbrev_base >= section->size |
1086 | 1.11M | || abbrev_size > section->size - abbrev_base) |
1087 | 72 | { |
1088 | | /* PR 17531: file:4bcd9ce9. */ |
1089 | 72 | warn (_("Debug info is corrupted, abbrev size (%#" PRIx64 ")" |
1090 | 72 | " is larger than abbrev section size (%#" PRIx64 ")\n"), |
1091 | 72 | abbrev_base + abbrev_size, section->size); |
1092 | 72 | return NULL; |
1093 | 72 | } |
1094 | 1.11M | if (abbrev_offset >= abbrev_size) |
1095 | 36 | { |
1096 | 36 | warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64 ")" |
1097 | 36 | " is larger than abbrev section size (%#" PRIx64 ")\n"), |
1098 | 36 | abbrev_offset, abbrev_size); |
1099 | 36 | return NULL; |
1100 | 36 | } |
1101 | | |
1102 | 1.11M | unsigned char *start = section->start + abbrev_base + abbrev_offset; |
1103 | 1.11M | unsigned char *end = section->start + abbrev_base + abbrev_size; |
1104 | 1.11M | abbrev_list *list = NULL; |
1105 | 1.11M | if (free_list) |
1106 | 1.05k | list = find_abbrev_list_by_raw_abbrev (start); |
1107 | 1.11M | if (list == NULL) |
1108 | 1.11M | { |
1109 | 1.11M | list = process_abbrev_set (section, start, end); |
1110 | 1.11M | if (free_list) |
1111 | 929 | *free_list = list; |
1112 | 1.11M | } |
1113 | 1.11M | return list; |
1114 | 1.11M | } |
1115 | | |
1116 | | static const char * |
1117 | | get_TAG_name (uint64_t tag) |
1118 | 330k | { |
1119 | 330k | const char *name = NULL; |
1120 | | |
1121 | 330k | if ((unsigned int) tag == tag) |
1122 | 323k | name = get_DW_TAG_name ((unsigned int) tag); |
1123 | 330k | if (name == NULL) |
1124 | 84.8k | { |
1125 | 84.8k | static char buffer[100]; |
1126 | | |
1127 | 84.8k | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1128 | 480 | snprintf (buffer, sizeof (buffer), |
1129 | 480 | _("User TAG value: %#" PRIx64), tag); |
1130 | 84.3k | else |
1131 | 84.3k | snprintf (buffer, sizeof (buffer), |
1132 | 84.3k | _("Unknown TAG value: %#" PRIx64), tag); |
1133 | 84.8k | return buffer; |
1134 | 84.8k | } |
1135 | | |
1136 | 245k | return name; |
1137 | 330k | } |
1138 | | |
1139 | | static const char * |
1140 | | get_FORM_name (unsigned long form) |
1141 | 1.32M | { |
1142 | 1.32M | const char *name = NULL; |
1143 | | |
1144 | 1.32M | if (form == 0) |
1145 | 381k | return "DW_FORM value: 0"; |
1146 | | |
1147 | 948k | if ((unsigned int) form == form) |
1148 | 926k | name = get_DW_FORM_name ((unsigned int) form); |
1149 | 948k | if (name == NULL) |
1150 | 707k | { |
1151 | 707k | static char buffer[100]; |
1152 | | |
1153 | 707k | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1154 | 707k | return buffer; |
1155 | 707k | } |
1156 | | |
1157 | 241k | return name; |
1158 | 948k | } |
1159 | | |
1160 | | static const char * |
1161 | | get_IDX_name (unsigned long idx) |
1162 | 0 | { |
1163 | 0 | const char *name = NULL; |
1164 | |
|
1165 | 0 | if ((unsigned int) idx == idx) |
1166 | 0 | name = get_DW_IDX_name ((unsigned int) idx); |
1167 | 0 | if (name == NULL) |
1168 | 0 | { |
1169 | 0 | static char buffer[100]; |
1170 | |
|
1171 | 0 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); |
1172 | 0 | return buffer; |
1173 | 0 | } |
1174 | | |
1175 | 0 | return name; |
1176 | 0 | } |
1177 | | |
1178 | | static unsigned char * |
1179 | | display_block (unsigned char *data, |
1180 | | uint64_t length, |
1181 | | const unsigned char * const end, char delimiter) |
1182 | 394 | { |
1183 | 394 | size_t maxlen; |
1184 | | |
1185 | 394 | printf (_("%c%" PRIu64 " byte block: "), delimiter, length); |
1186 | 394 | if (data > end) |
1187 | 0 | return (unsigned char *) end; |
1188 | | |
1189 | 394 | maxlen = end - data; |
1190 | 394 | length = length > maxlen ? maxlen : length; |
1191 | | |
1192 | 4.51k | while (length --) |
1193 | 4.12k | printf ("%" PRIx64 " ", byte_get (data++, 1)); |
1194 | | |
1195 | 394 | return data; |
1196 | 394 | } |
1197 | | |
1198 | | static int |
1199 | | get_location_expression (int die_tag, |
1200 | | unsigned long attribute, |
1201 | | unsigned char * data, |
1202 | | unsigned int pointer_size, |
1203 | | unsigned int offset_size, |
1204 | | int dwarf_version, |
1205 | | uint64_t length, |
1206 | | uint64_t die_offset, |
1207 | | uint64_t cu_offset, |
1208 | | struct dwarf_section * section) |
1209 | 0 | { |
1210 | 0 | unsigned op; |
1211 | 0 | uint64_t uvalue = 0; |
1212 | 0 | int64_t svalue; |
1213 | 0 | unsigned char *end = data + length; |
1214 | 0 | int need_frame_base = 0; |
1215 | |
|
1216 | 0 | while (data < end) |
1217 | 0 | { |
1218 | 0 | op = *data++; |
1219 | |
|
1220 | 0 | switch (op) |
1221 | 0 | { |
1222 | 0 | case DW_OP_addr: |
1223 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1224 | 0 | if (die_tag == DW_TAG_variable && attribute == DW_AT_location) |
1225 | 0 | { |
1226 | 0 | assert (variable_type_list.tail != NULL); |
1227 | 0 | if (!variable_type_list.tail->has_location_addr) |
1228 | 0 | { |
1229 | 0 | variable_type_list.tail->location_addr = uvalue; |
1230 | 0 | variable_type_list.tail->has_location_addr = true; |
1231 | 0 | } |
1232 | 0 | } |
1233 | 0 | break; |
1234 | 0 | case DW_OP_const1u: |
1235 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1236 | 0 | break; |
1237 | 0 | case DW_OP_const1s: |
1238 | 0 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1239 | 0 | break; |
1240 | 0 | case DW_OP_const2u: |
1241 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
1242 | 0 | break; |
1243 | 0 | case DW_OP_const2s: |
1244 | 0 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1245 | 0 | break; |
1246 | 0 | case DW_OP_const4u: |
1247 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1248 | 0 | break; |
1249 | 0 | case DW_OP_const4s: |
1250 | 0 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1251 | 0 | break; |
1252 | 0 | case DW_OP_const8u: |
1253 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
1254 | 0 | break; |
1255 | 0 | case DW_OP_const8s: |
1256 | 0 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 8, end); |
1257 | 0 | break; |
1258 | 0 | case DW_OP_bra: |
1259 | 0 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1260 | 0 | break; |
1261 | 0 | case DW_OP_skip: |
1262 | 0 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1263 | 0 | break; |
1264 | | |
1265 | 0 | case DW_OP_deref_size: |
1266 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1267 | 0 | break; |
1268 | 0 | case DW_OP_xderef_size: |
1269 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1270 | 0 | break; |
1271 | | |
1272 | 0 | case DW_OP_call2: |
1273 | 0 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1274 | 0 | break; |
1275 | 0 | case DW_OP_call4: |
1276 | 0 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1277 | 0 | break; |
1278 | 0 | case DW_OP_call_ref: |
1279 | 0 | if (dwarf_version == -1) |
1280 | | /* No way to tell where the next op is, so just bail. */ |
1281 | 0 | return need_frame_base; |
1282 | 0 | else if (dwarf_version == 2) |
1283 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1284 | 0 | else |
1285 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1286 | 0 | break; |
1287 | 0 | case DW_OP_implicit_value: |
1288 | 0 | READ_ULEB (uvalue, data, end); |
1289 | 0 | break; |
1290 | 0 | case DW_OP_implicit_pointer: |
1291 | 0 | case DW_OP_GNU_implicit_pointer: |
1292 | 0 | if (dwarf_version == -1) |
1293 | 0 | return need_frame_base; |
1294 | 0 | else if (dwarf_version == 2) |
1295 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1296 | 0 | else |
1297 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1298 | 0 | break; |
1299 | 0 | case DW_OP_entry_value: |
1300 | 0 | case DW_OP_GNU_entry_value: |
1301 | 0 | READ_ULEB (uvalue, data, end); |
1302 | | /* PR 17531: file: 0cc9cd00. */ |
1303 | 0 | if (uvalue > (size_t) (end - data)) |
1304 | 0 | uvalue = end - data; |
1305 | 0 | if (get_location_expression |
1306 | 0 | (die_tag, attribute, data, pointer_size, offset_size, |
1307 | 0 | dwarf_version, uvalue, die_offset, cu_offset, section)) |
1308 | 0 | need_frame_base = 1; |
1309 | 0 | data += uvalue; |
1310 | 0 | break; |
1311 | 0 | case DW_OP_const_type: |
1312 | 0 | case DW_OP_GNU_const_type: |
1313 | 0 | READ_ULEB (uvalue, data, end); |
1314 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1315 | 0 | break; |
1316 | 0 | case DW_OP_deref_type: |
1317 | 0 | case DW_OP_GNU_deref_type: |
1318 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1319 | 0 | break; |
1320 | 0 | case DW_OP_GNU_parameter_ref: |
1321 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1322 | 0 | break; |
1323 | 0 | case DW_OP_addrx: |
1324 | 0 | READ_ULEB (uvalue, data, end); |
1325 | 0 | break; |
1326 | 0 | case DW_OP_GNU_variable_value: |
1327 | 0 | if (dwarf_version == -1) |
1328 | 0 | return need_frame_base; |
1329 | 0 | else if (dwarf_version == 2) |
1330 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1331 | 0 | else |
1332 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1333 | 0 | break; |
1334 | | |
1335 | 0 | default: |
1336 | 0 | return need_frame_base; |
1337 | 0 | } |
1338 | 0 | } |
1339 | 0 | return need_frame_base; |
1340 | 0 | } |
1341 | | |
1342 | | static int |
1343 | | decode_location_expression (unsigned char * data, |
1344 | | unsigned int pointer_size, |
1345 | | unsigned int offset_size, |
1346 | | int dwarf_version, |
1347 | | uint64_t length, |
1348 | | uint64_t cu_offset, |
1349 | | struct dwarf_section * section) |
1350 | 9.34k | { |
1351 | 9.34k | unsigned op; |
1352 | 9.34k | uint64_t uvalue; |
1353 | 9.34k | int64_t svalue; |
1354 | 9.34k | unsigned char *end = data + length; |
1355 | 9.34k | int need_frame_base = 0; |
1356 | | |
1357 | 102k | while (data < end) |
1358 | 95.8k | { |
1359 | 95.8k | op = *data++; |
1360 | | |
1361 | 95.8k | switch (op) |
1362 | 95.8k | { |
1363 | 267 | case DW_OP_addr: |
1364 | 267 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1365 | 267 | printf ("DW_OP_addr: %" PRIx64, uvalue); |
1366 | 267 | break; |
1367 | 44 | case DW_OP_deref: |
1368 | 44 | printf ("DW_OP_deref"); |
1369 | 44 | break; |
1370 | 70 | case DW_OP_const1u: |
1371 | 70 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1372 | 70 | printf ("DW_OP_const1u: %" PRIu64, uvalue); |
1373 | 70 | break; |
1374 | 65 | case DW_OP_const1s: |
1375 | 65 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1376 | 65 | printf ("DW_OP_const1s: %" PRId64, svalue); |
1377 | 65 | break; |
1378 | 67 | case DW_OP_const2u: |
1379 | 67 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
1380 | 67 | printf ("DW_OP_const2u: %" PRIu64, uvalue); |
1381 | 67 | break; |
1382 | 41 | case DW_OP_const2s: |
1383 | 41 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1384 | 41 | printf ("DW_OP_const2s: %" PRId64, svalue); |
1385 | 41 | break; |
1386 | 67 | case DW_OP_const4u: |
1387 | 67 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1388 | 67 | printf ("DW_OP_const4u: %" PRIu64, uvalue); |
1389 | 67 | break; |
1390 | 21 | case DW_OP_const4s: |
1391 | 21 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1392 | 21 | printf ("DW_OP_const4s: %" PRId64, svalue); |
1393 | 21 | break; |
1394 | 63 | case DW_OP_const8u: |
1395 | 63 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
1396 | 63 | printf ("DW_OP_const8u: %" PRIu64, uvalue); |
1397 | 63 | break; |
1398 | 896 | case DW_OP_const8s: |
1399 | 896 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 8, end); |
1400 | 896 | printf ("DW_OP_const8s: %" PRId64, svalue); |
1401 | 896 | break; |
1402 | 17.9k | case DW_OP_constu: |
1403 | 17.9k | READ_ULEB (uvalue, data, end); |
1404 | 17.9k | printf ("DW_OP_constu: %" PRIu64, uvalue); |
1405 | 17.9k | break; |
1406 | 1.56k | case DW_OP_consts: |
1407 | 1.56k | READ_SLEB (svalue, data, end); |
1408 | 1.56k | printf ("DW_OP_consts: %" PRId64, svalue); |
1409 | 1.56k | break; |
1410 | 194 | case DW_OP_dup: |
1411 | 194 | printf ("DW_OP_dup"); |
1412 | 194 | break; |
1413 | 189 | case DW_OP_drop: |
1414 | 189 | printf ("DW_OP_drop"); |
1415 | 189 | break; |
1416 | 147 | case DW_OP_over: |
1417 | 147 | printf ("DW_OP_over"); |
1418 | 147 | break; |
1419 | 127 | case DW_OP_pick: |
1420 | 127 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1421 | 127 | printf ("DW_OP_pick: %" PRIu64, uvalue); |
1422 | 127 | break; |
1423 | 43.6k | case DW_OP_swap: |
1424 | 43.6k | printf ("DW_OP_swap"); |
1425 | 43.6k | break; |
1426 | 441 | case DW_OP_rot: |
1427 | 441 | printf ("DW_OP_rot"); |
1428 | 441 | break; |
1429 | 155 | case DW_OP_xderef: |
1430 | 155 | printf ("DW_OP_xderef"); |
1431 | 155 | break; |
1432 | 10 | case DW_OP_abs: |
1433 | 10 | printf ("DW_OP_abs"); |
1434 | 10 | break; |
1435 | 145 | case DW_OP_and: |
1436 | 145 | printf ("DW_OP_and"); |
1437 | 145 | break; |
1438 | 85 | case DW_OP_div: |
1439 | 85 | printf ("DW_OP_div"); |
1440 | 85 | break; |
1441 | 55 | case DW_OP_minus: |
1442 | 55 | printf ("DW_OP_minus"); |
1443 | 55 | break; |
1444 | 41 | case DW_OP_mod: |
1445 | 41 | printf ("DW_OP_mod"); |
1446 | 41 | break; |
1447 | 52 | case DW_OP_mul: |
1448 | 52 | printf ("DW_OP_mul"); |
1449 | 52 | break; |
1450 | 31 | case DW_OP_neg: |
1451 | 31 | printf ("DW_OP_neg"); |
1452 | 31 | break; |
1453 | 74 | case DW_OP_not: |
1454 | 74 | printf ("DW_OP_not"); |
1455 | 74 | break; |
1456 | 40 | case DW_OP_or: |
1457 | 40 | printf ("DW_OP_or"); |
1458 | 40 | break; |
1459 | 60 | case DW_OP_plus: |
1460 | 60 | printf ("DW_OP_plus"); |
1461 | 60 | break; |
1462 | 66 | case DW_OP_plus_uconst: |
1463 | 66 | READ_ULEB (uvalue, data, end); |
1464 | 66 | printf ("DW_OP_plus_uconst: %" PRIu64, uvalue); |
1465 | 66 | break; |
1466 | 81 | case DW_OP_shl: |
1467 | 81 | printf ("DW_OP_shl"); |
1468 | 81 | break; |
1469 | 119 | case DW_OP_shr: |
1470 | 119 | printf ("DW_OP_shr"); |
1471 | 119 | break; |
1472 | 122 | case DW_OP_shra: |
1473 | 122 | printf ("DW_OP_shra"); |
1474 | 122 | break; |
1475 | 22 | case DW_OP_xor: |
1476 | 22 | printf ("DW_OP_xor"); |
1477 | 22 | break; |
1478 | 148 | case DW_OP_bra: |
1479 | 148 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1480 | 148 | printf ("DW_OP_bra: %" PRId64, svalue); |
1481 | 148 | break; |
1482 | 89 | case DW_OP_eq: |
1483 | 89 | printf ("DW_OP_eq"); |
1484 | 89 | break; |
1485 | 82 | case DW_OP_ge: |
1486 | 82 | printf ("DW_OP_ge"); |
1487 | 82 | break; |
1488 | 156 | case DW_OP_gt: |
1489 | 156 | printf ("DW_OP_gt"); |
1490 | 156 | break; |
1491 | 93 | case DW_OP_le: |
1492 | 93 | printf ("DW_OP_le"); |
1493 | 93 | break; |
1494 | 126 | case DW_OP_lt: |
1495 | 126 | printf ("DW_OP_lt"); |
1496 | 126 | break; |
1497 | 378 | case DW_OP_ne: |
1498 | 378 | printf ("DW_OP_ne"); |
1499 | 378 | break; |
1500 | 371 | case DW_OP_skip: |
1501 | 371 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1502 | 371 | printf ("DW_OP_skip: %" PRId64, svalue); |
1503 | 371 | break; |
1504 | | |
1505 | 845 | case DW_OP_lit0: |
1506 | 1.03k | case DW_OP_lit1: |
1507 | 1.14k | case DW_OP_lit2: |
1508 | 1.34k | case DW_OP_lit3: |
1509 | 1.54k | case DW_OP_lit4: |
1510 | 1.63k | case DW_OP_lit5: |
1511 | 1.82k | case DW_OP_lit6: |
1512 | 2.09k | case DW_OP_lit7: |
1513 | 2.26k | case DW_OP_lit8: |
1514 | 2.38k | case DW_OP_lit9: |
1515 | 2.55k | case DW_OP_lit10: |
1516 | 2.62k | case DW_OP_lit11: |
1517 | 2.70k | case DW_OP_lit12: |
1518 | 2.77k | case DW_OP_lit13: |
1519 | 2.82k | case DW_OP_lit14: |
1520 | 2.92k | case DW_OP_lit15: |
1521 | 3.62k | case DW_OP_lit16: |
1522 | 3.79k | case DW_OP_lit17: |
1523 | 3.95k | case DW_OP_lit18: |
1524 | 4.23k | case DW_OP_lit19: |
1525 | 4.39k | case DW_OP_lit20: |
1526 | 4.47k | case DW_OP_lit21: |
1527 | 4.60k | case DW_OP_lit22: |
1528 | 4.77k | case DW_OP_lit23: |
1529 | 4.84k | case DW_OP_lit24: |
1530 | 4.88k | case DW_OP_lit25: |
1531 | 4.89k | case DW_OP_lit26: |
1532 | 5.19k | case DW_OP_lit27: |
1533 | 6.45k | case DW_OP_lit28: |
1534 | 6.79k | case DW_OP_lit29: |
1535 | 6.81k | case DW_OP_lit30: |
1536 | 6.81k | case DW_OP_lit31: |
1537 | 6.81k | printf ("DW_OP_lit%d", op - DW_OP_lit0); |
1538 | 6.81k | break; |
1539 | | |
1540 | 76 | case DW_OP_reg0: |
1541 | 142 | case DW_OP_reg1: |
1542 | 280 | case DW_OP_reg2: |
1543 | 389 | case DW_OP_reg3: |
1544 | 462 | case DW_OP_reg4: |
1545 | 842 | case DW_OP_reg5: |
1546 | 1.33k | case DW_OP_reg6: |
1547 | 2.26k | case DW_OP_reg7: |
1548 | 2.46k | case DW_OP_reg8: |
1549 | 2.54k | case DW_OP_reg9: |
1550 | 2.58k | case DW_OP_reg10: |
1551 | 2.75k | case DW_OP_reg11: |
1552 | 2.80k | case DW_OP_reg12: |
1553 | 2.83k | case DW_OP_reg13: |
1554 | 2.89k | case DW_OP_reg14: |
1555 | 3.00k | case DW_OP_reg15: |
1556 | 3.05k | case DW_OP_reg16: |
1557 | 3.61k | case DW_OP_reg17: |
1558 | 3.85k | case DW_OP_reg18: |
1559 | 4.47k | case DW_OP_reg19: |
1560 | 5.22k | case DW_OP_reg20: |
1561 | 5.33k | case DW_OP_reg21: |
1562 | 5.34k | case DW_OP_reg22: |
1563 | 5.51k | case DW_OP_reg23: |
1564 | 7.19k | case DW_OP_reg24: |
1565 | 7.28k | case DW_OP_reg25: |
1566 | 7.45k | case DW_OP_reg26: |
1567 | 7.54k | case DW_OP_reg27: |
1568 | 7.68k | case DW_OP_reg28: |
1569 | 7.75k | case DW_OP_reg29: |
1570 | 8.02k | case DW_OP_reg30: |
1571 | 8.23k | case DW_OP_reg31: |
1572 | 8.23k | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1573 | 8.23k | regname (op - DW_OP_reg0, 1)); |
1574 | 8.23k | break; |
1575 | | |
1576 | 198 | case DW_OP_breg0: |
1577 | 242 | case DW_OP_breg1: |
1578 | 344 | case DW_OP_breg2: |
1579 | 499 | case DW_OP_breg3: |
1580 | 737 | case DW_OP_breg4: |
1581 | 867 | case DW_OP_breg5: |
1582 | 885 | case DW_OP_breg6: |
1583 | 1.17k | case DW_OP_breg7: |
1584 | 1.27k | case DW_OP_breg8: |
1585 | 1.33k | case DW_OP_breg9: |
1586 | 1.38k | case DW_OP_breg10: |
1587 | 1.54k | case DW_OP_breg11: |
1588 | 1.60k | case DW_OP_breg12: |
1589 | 1.84k | case DW_OP_breg13: |
1590 | 1.84k | case DW_OP_breg14: |
1591 | 2.27k | case DW_OP_breg15: |
1592 | 2.33k | case DW_OP_breg16: |
1593 | 2.35k | case DW_OP_breg17: |
1594 | 2.36k | case DW_OP_breg18: |
1595 | 2.37k | case DW_OP_breg19: |
1596 | 2.41k | case DW_OP_breg20: |
1597 | 2.43k | case DW_OP_breg21: |
1598 | 2.45k | case DW_OP_breg22: |
1599 | 2.45k | case DW_OP_breg23: |
1600 | 2.47k | case DW_OP_breg24: |
1601 | 2.47k | case DW_OP_breg25: |
1602 | 2.52k | case DW_OP_breg26: |
1603 | 2.54k | case DW_OP_breg27: |
1604 | 2.54k | case DW_OP_breg28: |
1605 | 2.63k | case DW_OP_breg29: |
1606 | 2.65k | case DW_OP_breg30: |
1607 | 2.65k | case DW_OP_breg31: |
1608 | 2.65k | READ_SLEB (svalue, data, end); |
1609 | 2.65k | printf ("DW_OP_breg%d (%s): %" PRId64, |
1610 | 2.65k | op - DW_OP_breg0, regname (op - DW_OP_breg0, 1), svalue); |
1611 | 2.65k | break; |
1612 | | |
1613 | 193 | case DW_OP_regx: |
1614 | 193 | READ_ULEB (uvalue, data, end); |
1615 | 193 | printf ("DW_OP_regx: %" PRIu64 " (%s)", |
1616 | 193 | uvalue, regname (uvalue, 1)); |
1617 | 193 | break; |
1618 | 1.75k | case DW_OP_fbreg: |
1619 | 1.75k | need_frame_base = 1; |
1620 | 1.75k | READ_SLEB (svalue, data, end); |
1621 | 1.75k | printf ("DW_OP_fbreg: %" PRId64, svalue); |
1622 | 1.75k | break; |
1623 | 136 | case DW_OP_bregx: |
1624 | 136 | READ_ULEB (uvalue, data, end); |
1625 | 136 | READ_SLEB (svalue, data, end); |
1626 | 136 | printf ("DW_OP_bregx: %" PRIu64 " (%s) %" PRId64, |
1627 | 136 | uvalue, regname (uvalue, 1), svalue); |
1628 | 136 | break; |
1629 | 340 | case DW_OP_piece: |
1630 | 340 | READ_ULEB (uvalue, data, end); |
1631 | 340 | printf ("DW_OP_piece: %" PRIu64, uvalue); |
1632 | 340 | break; |
1633 | 200 | case DW_OP_deref_size: |
1634 | 200 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1635 | 200 | printf ("DW_OP_deref_size: %" PRIu64, uvalue); |
1636 | 200 | break; |
1637 | 32 | case DW_OP_xderef_size: |
1638 | 32 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1639 | 32 | printf ("DW_OP_xderef_size: %" PRIu64, uvalue); |
1640 | 32 | break; |
1641 | 113 | case DW_OP_nop: |
1642 | 113 | printf ("DW_OP_nop"); |
1643 | 113 | break; |
1644 | | |
1645 | | /* DWARF 3 extensions. */ |
1646 | 111 | case DW_OP_push_object_address: |
1647 | 111 | printf ("DW_OP_push_object_address"); |
1648 | 111 | break; |
1649 | 73 | case DW_OP_call2: |
1650 | | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
1651 | | this ought to be an 8-byte wide computation. */ |
1652 | 73 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1653 | 73 | printf ("DW_OP_call2: <%#" PRIx64 ">", svalue + cu_offset); |
1654 | 73 | break; |
1655 | 39 | case DW_OP_call4: |
1656 | | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
1657 | | this ought to be an 8-byte wide computation. */ |
1658 | 39 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1659 | 39 | printf ("DW_OP_call4: <%#" PRIx64 ">", svalue + cu_offset); |
1660 | 39 | break; |
1661 | 1 | case DW_OP_call_ref: |
1662 | | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
1663 | | this ought to be an 8-byte wide computation. */ |
1664 | 1 | if (dwarf_version == -1) |
1665 | 1 | { |
1666 | 1 | printf (_("(DW_OP_call_ref in frame info)")); |
1667 | | /* No way to tell where the next op is, so just bail. */ |
1668 | 1 | return need_frame_base; |
1669 | 1 | } |
1670 | 0 | if (dwarf_version == 2) |
1671 | 0 | { |
1672 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1673 | 0 | } |
1674 | 0 | else |
1675 | 0 | { |
1676 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1677 | 0 | } |
1678 | 0 | printf ("DW_OP_call_ref: <%#" PRIx64 ">", uvalue); |
1679 | 0 | break; |
1680 | 390 | case DW_OP_form_tls_address: |
1681 | 390 | printf ("DW_OP_form_tls_address"); |
1682 | 390 | break; |
1683 | 248 | case DW_OP_call_frame_cfa: |
1684 | 248 | printf ("DW_OP_call_frame_cfa"); |
1685 | 248 | break; |
1686 | 13 | case DW_OP_bit_piece: |
1687 | 13 | printf ("DW_OP_bit_piece: "); |
1688 | 13 | READ_ULEB (uvalue, data, end); |
1689 | 13 | printf (_("size: %" PRIu64 " "), uvalue); |
1690 | 13 | READ_ULEB (uvalue, data, end); |
1691 | 13 | printf (_("offset: %" PRIu64 " "), uvalue); |
1692 | 13 | break; |
1693 | | |
1694 | | /* DWARF 4 extensions. */ |
1695 | 10 | case DW_OP_stack_value: |
1696 | 10 | printf ("DW_OP_stack_value"); |
1697 | 10 | break; |
1698 | | |
1699 | 73 | case DW_OP_implicit_value: |
1700 | 73 | printf ("DW_OP_implicit_value"); |
1701 | 73 | READ_ULEB (uvalue, data, end); |
1702 | 73 | data = display_block (data, uvalue, end, ' '); |
1703 | 73 | break; |
1704 | | |
1705 | | /* GNU extensions. */ |
1706 | 30 | case DW_OP_GNU_push_tls_address: |
1707 | 30 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
1708 | 30 | break; |
1709 | 178 | case DW_OP_GNU_uninit: |
1710 | 178 | printf ("DW_OP_GNU_uninit"); |
1711 | | /* FIXME: Is there data associated with this OP ? */ |
1712 | 178 | break; |
1713 | 73 | case DW_OP_GNU_encoded_addr: |
1714 | 73 | { |
1715 | 73 | int encoding = 0; |
1716 | 73 | uint64_t addr; |
1717 | | |
1718 | 73 | if (data < end) |
1719 | 71 | encoding = *data++; |
1720 | 73 | addr = get_encoded_value (&data, encoding, section, end); |
1721 | | |
1722 | 73 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); |
1723 | 73 | print_hex_ns (addr, pointer_size); |
1724 | 73 | } |
1725 | 73 | break; |
1726 | 10 | case DW_OP_implicit_pointer: |
1727 | 43 | case DW_OP_GNU_implicit_pointer: |
1728 | | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
1729 | | this ought to be an 8-byte wide computation. */ |
1730 | 43 | if (dwarf_version == -1) |
1731 | 43 | { |
1732 | 43 | printf (_("(%s in frame info)"), |
1733 | 43 | (op == DW_OP_implicit_pointer |
1734 | 43 | ? "DW_OP_implicit_pointer" |
1735 | 43 | : "DW_OP_GNU_implicit_pointer")); |
1736 | | /* No way to tell where the next op is, so just bail. */ |
1737 | 43 | return need_frame_base; |
1738 | 43 | } |
1739 | 0 | if (dwarf_version == 2) |
1740 | 0 | { |
1741 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1742 | 0 | } |
1743 | 0 | else |
1744 | 0 | { |
1745 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1746 | 0 | } |
1747 | 0 | READ_SLEB (svalue, data, end); |
1748 | 0 | printf ("%s: <%#" PRIx64 "> %" PRId64, |
1749 | 0 | (op == DW_OP_implicit_pointer |
1750 | 0 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), |
1751 | 0 | uvalue, svalue); |
1752 | 0 | break; |
1753 | 5 | case DW_OP_entry_value: |
1754 | 95 | case DW_OP_GNU_entry_value: |
1755 | 95 | READ_ULEB (uvalue, data, end); |
1756 | | /* PR 17531: file: 0cc9cd00. */ |
1757 | 95 | if (uvalue > (size_t) (end - data)) |
1758 | 89 | uvalue = end - data; |
1759 | 95 | printf ("%s: (", (op == DW_OP_entry_value |
1760 | 95 | ? "DW_OP_entry_value" : "DW_OP_GNU_entry_value")); |
1761 | 95 | if (decode_location_expression (data, pointer_size, offset_size, |
1762 | 95 | dwarf_version, uvalue, |
1763 | 95 | cu_offset, section)) |
1764 | 0 | need_frame_base = 1; |
1765 | 95 | putchar (')'); |
1766 | 95 | data += uvalue; |
1767 | 95 | break; |
1768 | 13 | case DW_OP_const_type: |
1769 | 83 | case DW_OP_GNU_const_type: |
1770 | 83 | READ_ULEB (uvalue, data, end); |
1771 | 83 | printf ("%s: <%#" PRIx64 "> ", |
1772 | 83 | (op == DW_OP_const_type |
1773 | 83 | ? "DW_OP_const_type" : "DW_OP_GNU_const_type"), |
1774 | 83 | cu_offset + uvalue); |
1775 | 83 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1776 | 83 | data = display_block (data, uvalue, end, ' '); |
1777 | 83 | break; |
1778 | 251 | case DW_OP_regval_type: |
1779 | 268 | case DW_OP_GNU_regval_type: |
1780 | 268 | READ_ULEB (uvalue, data, end); |
1781 | 268 | printf ("%s: %" PRIu64 " (%s)", |
1782 | 268 | (op == DW_OP_regval_type |
1783 | 268 | ? "DW_OP_regval_type" : "DW_OP_GNU_regval_type"), |
1784 | 268 | uvalue, regname (uvalue, 1)); |
1785 | 268 | READ_ULEB (uvalue, data, end); |
1786 | 268 | printf (" <%#" PRIx64 ">", cu_offset + uvalue); |
1787 | 268 | break; |
1788 | 29 | case DW_OP_deref_type: |
1789 | 184 | case DW_OP_GNU_deref_type: |
1790 | 184 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1791 | 184 | printf ("%s: %" PRId64, |
1792 | 184 | (op == DW_OP_deref_type |
1793 | 184 | ? "DW_OP_deref_type" : "DW_OP_GNU_deref_type"), |
1794 | 184 | uvalue); |
1795 | 184 | READ_ULEB (uvalue, data, end); |
1796 | 184 | printf (" <%#" PRIx64 ">", cu_offset + uvalue); |
1797 | 184 | break; |
1798 | 54 | case DW_OP_convert: |
1799 | 91 | case DW_OP_GNU_convert: |
1800 | 91 | READ_ULEB (uvalue, data, end); |
1801 | 91 | printf ("%s <%#" PRIx64 ">", |
1802 | 91 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), |
1803 | 91 | uvalue ? cu_offset + uvalue : uvalue); |
1804 | 91 | break; |
1805 | 72 | case DW_OP_reinterpret: |
1806 | 80 | case DW_OP_GNU_reinterpret: |
1807 | 80 | READ_ULEB (uvalue, data, end); |
1808 | 80 | printf ("%s <%#" PRIx64 ">", |
1809 | 80 | (op == DW_OP_reinterpret |
1810 | 80 | ? "DW_OP_reinterpret" : "DW_OP_GNU_reinterpret"), |
1811 | 80 | uvalue ? cu_offset + uvalue : uvalue); |
1812 | 80 | break; |
1813 | 18 | case DW_OP_GNU_parameter_ref: |
1814 | 18 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1815 | 18 | printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64 ">", |
1816 | 18 | cu_offset + uvalue); |
1817 | 18 | break; |
1818 | 7 | case DW_OP_addrx: |
1819 | 7 | READ_ULEB (uvalue, data, end); |
1820 | 7 | printf ("DW_OP_addrx <%#" PRIx64 ">", uvalue); |
1821 | 7 | break; |
1822 | 502 | case DW_OP_GNU_addr_index: |
1823 | 502 | READ_ULEB (uvalue, data, end); |
1824 | 502 | printf ("DW_OP_GNU_addr_index <%#" PRIx64 ">", uvalue); |
1825 | 502 | break; |
1826 | 14 | case DW_OP_GNU_const_index: |
1827 | 14 | READ_ULEB (uvalue, data, end); |
1828 | 14 | printf ("DW_OP_GNU_const_index <%#" PRIx64 ">", uvalue); |
1829 | 14 | break; |
1830 | 27 | case DW_OP_GNU_variable_value: |
1831 | | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
1832 | | this ought to be an 8-byte wide computation. */ |
1833 | 27 | if (dwarf_version == -1) |
1834 | 27 | { |
1835 | 27 | printf (_("(DW_OP_GNU_variable_value in frame info)")); |
1836 | | /* No way to tell where the next op is, so just bail. */ |
1837 | 27 | return need_frame_base; |
1838 | 27 | } |
1839 | 0 | if (dwarf_version == 2) |
1840 | 0 | { |
1841 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1842 | 0 | } |
1843 | 0 | else |
1844 | 0 | { |
1845 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1846 | 0 | } |
1847 | 0 | printf ("DW_OP_GNU_variable_value: <%#" PRIx64 ">", uvalue); |
1848 | 0 | break; |
1849 | | |
1850 | | /* HP extensions. */ |
1851 | 1.06k | case DW_OP_HP_is_value: |
1852 | 1.06k | printf ("DW_OP_HP_is_value"); |
1853 | | /* FIXME: Is there data associated with this OP ? */ |
1854 | 1.06k | break; |
1855 | 74 | case DW_OP_HP_fltconst4: |
1856 | 74 | printf ("DW_OP_HP_fltconst4"); |
1857 | | /* FIXME: Is there data associated with this OP ? */ |
1858 | 74 | break; |
1859 | 62 | case DW_OP_HP_fltconst8: |
1860 | 62 | printf ("DW_OP_HP_fltconst8"); |
1861 | | /* FIXME: Is there data associated with this OP ? */ |
1862 | 62 | break; |
1863 | 80 | case DW_OP_HP_mod_range: |
1864 | 80 | printf ("DW_OP_HP_mod_range"); |
1865 | | /* FIXME: Is there data associated with this OP ? */ |
1866 | 80 | break; |
1867 | 45 | case DW_OP_HP_unmod_range: |
1868 | 45 | printf ("DW_OP_HP_unmod_range"); |
1869 | | /* FIXME: Is there data associated with this OP ? */ |
1870 | 45 | break; |
1871 | 135 | case DW_OP_HP_tls: |
1872 | 135 | printf ("DW_OP_HP_tls"); |
1873 | | /* FIXME: Is there data associated with this OP ? */ |
1874 | 135 | break; |
1875 | | |
1876 | | /* PGI (STMicroelectronics) extensions. */ |
1877 | 165 | case DW_OP_PGI_omp_thread_num: |
1878 | | /* Pushes the thread number for the current thread as it would be |
1879 | | returned by the standard OpenMP library function: |
1880 | | omp_get_thread_num(). The "current thread" is the thread for |
1881 | | which the expression is being evaluated. */ |
1882 | 165 | printf ("DW_OP_PGI_omp_thread_num"); |
1883 | 165 | break; |
1884 | | |
1885 | 2.67k | default: |
1886 | 2.67k | if (op >= DW_OP_lo_user |
1887 | 462 | && op <= DW_OP_hi_user) |
1888 | 462 | printf (_("(User defined location op %#x)"), op); |
1889 | 2.21k | else |
1890 | 2.21k | printf (_("(Unknown location op %#x)"), op); |
1891 | | /* No way to tell where the next op is, so just bail. */ |
1892 | 2.67k | return need_frame_base; |
1893 | 95.8k | } |
1894 | | |
1895 | | /* Separate the ops. */ |
1896 | 93.1k | if (data < end) |
1897 | 87.1k | printf ("; "); |
1898 | 93.1k | } |
1899 | | |
1900 | 6.59k | return need_frame_base; |
1901 | 9.34k | } |
1902 | | |
1903 | | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1904 | | This is used for DWARF package files. */ |
1905 | | |
1906 | | static struct cu_tu_set * |
1907 | | find_cu_tu_set_v2 (uint64_t cu_offset, bool do_types) |
1908 | 2.17k | { |
1909 | 2.17k | struct cu_tu_set *p; |
1910 | 2.17k | unsigned int nsets; |
1911 | 2.17k | unsigned int dw_sect; |
1912 | | |
1913 | 2.17k | if (do_types) |
1914 | 36 | { |
1915 | 36 | p = tu_sets; |
1916 | 36 | nsets = tu_count; |
1917 | 36 | dw_sect = DW_SECT_TYPES; |
1918 | 36 | } |
1919 | 2.13k | else |
1920 | 2.13k | { |
1921 | 2.13k | p = cu_sets; |
1922 | 2.13k | nsets = cu_count; |
1923 | 2.13k | dw_sect = DW_SECT_INFO; |
1924 | 2.13k | } |
1925 | 2.17k | while (nsets > 0) |
1926 | 0 | { |
1927 | 0 | if (p->section_offsets [dw_sect] == cu_offset) |
1928 | 0 | return p; |
1929 | 0 | p++; |
1930 | 0 | nsets--; |
1931 | 0 | } |
1932 | 2.17k | return NULL; |
1933 | 2.17k | } |
1934 | | |
1935 | | static const char * |
1936 | | fetch_alt_indirect_string (uint64_t offset) |
1937 | 0 | { |
1938 | 0 | separate_info * i; |
1939 | |
|
1940 | 0 | if (! do_follow_links) |
1941 | 0 | return ""; |
1942 | | |
1943 | 0 | if (first_separate_info == NULL) |
1944 | 0 | return _("<no links available>"); |
1945 | | |
1946 | 0 | for (i = first_separate_info; i != NULL; i = i->next) |
1947 | 0 | { |
1948 | 0 | struct dwarf_section * section; |
1949 | 0 | const char * ret; |
1950 | |
|
1951 | 0 | if (! load_debug_section (separate_debug_str, i->handle)) |
1952 | 0 | continue; |
1953 | | |
1954 | 0 | section = &debug_displays [separate_debug_str].section; |
1955 | |
|
1956 | 0 | if (section->start == NULL) |
1957 | 0 | continue; |
1958 | | |
1959 | 0 | if (offset >= section->size) |
1960 | 0 | continue; |
1961 | | |
1962 | 0 | ret = (const char *) (section->start + offset); |
1963 | | /* Unfortunately we cannot rely upon the .debug_str section ending with a |
1964 | | NUL byte. Since our caller is expecting to receive a well formed C |
1965 | | string we test for the lack of a terminating byte here. */ |
1966 | 0 | if (strnlen ((const char *) ret, section->size - offset) |
1967 | 0 | == section->size - offset) |
1968 | 0 | return _("<no NUL byte at end of alt .debug_str section>"); |
1969 | | |
1970 | 0 | return ret; |
1971 | 0 | } |
1972 | | |
1973 | 0 | warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64 ")" |
1974 | 0 | " too big or no string sections available\n"), offset); |
1975 | 0 | return _("<offset is too big>"); |
1976 | 0 | } |
1977 | | |
1978 | | static const char * |
1979 | | get_AT_name (unsigned long attribute) |
1980 | 1.33M | { |
1981 | 1.33M | const char *name; |
1982 | | |
1983 | 1.33M | if (attribute == 0) |
1984 | 328k | return "DW_AT value: 0"; |
1985 | | |
1986 | | /* One value is shared by the MIPS and HP extensions: */ |
1987 | 1.00M | if (attribute == DW_AT_MIPS_fde) |
1988 | 43 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; |
1989 | | |
1990 | 1.00M | name = get_DW_AT_name (attribute); |
1991 | | |
1992 | 1.00M | if (name == NULL) |
1993 | 243k | { |
1994 | 243k | static char buffer[100]; |
1995 | | |
1996 | 243k | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), |
1997 | 243k | attribute); |
1998 | 243k | return buffer; |
1999 | 243k | } |
2000 | | |
2001 | 763k | return name; |
2002 | 1.00M | } |
2003 | | |
2004 | | static const char * |
2005 | | get_AT_language_name (unsigned long value) |
2006 | 0 | { |
2007 | | /* Libiberty does not (yet) provide a get_DW_AT_language_name() |
2008 | | function so we define our own. */ |
2009 | |
|
2010 | 0 | switch (value) |
2011 | 0 | { |
2012 | 0 | case DW_LNAME_Ada: return "Ada"; |
2013 | 0 | case DW_LNAME_BLISS: return "BLISS"; |
2014 | 0 | case DW_LNAME_C: return "C"; |
2015 | 0 | case DW_LNAME_C_plus_plus: return "C_plus_plus"; |
2016 | 0 | case DW_LNAME_Cobol: return "Cobol"; |
2017 | 0 | case DW_LNAME_Crystal: return "Crystal"; |
2018 | 0 | case DW_LNAME_D: return "D"; |
2019 | 0 | case DW_LNAME_Dylan: return "Dylan"; |
2020 | 0 | case DW_LNAME_Fortran: return "Fortran"; |
2021 | 0 | case DW_LNAME_Go: return "Go"; |
2022 | 0 | case DW_LNAME_Haskell: return "Haskell"; |
2023 | 0 | case DW_LNAME_Java: return "Java"; |
2024 | 0 | case DW_LNAME_Julia: return "Julia"; |
2025 | 0 | case DW_LNAME_Kotlin: return "Kotlin"; |
2026 | 0 | case DW_LNAME_Modula2: return "Modula2"; |
2027 | 0 | case DW_LNAME_Modula3: return "Modula3"; |
2028 | 0 | case DW_LNAME_ObjC: return "ObjC"; |
2029 | 0 | case DW_LNAME_ObjC_plus_plus: return "ObjC_plus_plus"; |
2030 | 0 | case DW_LNAME_OCaml: return "OCaml"; |
2031 | 0 | case DW_LNAME_OpenCL_C: return "OpenCL_C"; |
2032 | 0 | case DW_LNAME_Pascal: return "Pascal"; |
2033 | 0 | case DW_LNAME_PLI: return "PLI"; |
2034 | 0 | case DW_LNAME_Python: return "Python"; |
2035 | 0 | case DW_LNAME_RenderScript: return "RenderScript"; |
2036 | 0 | case DW_LNAME_Rust: return "Rust"; |
2037 | 0 | case DW_LNAME_Swift: return "Swift"; |
2038 | 0 | case DW_LNAME_UPC: return "UPC"; |
2039 | 0 | case DW_LNAME_Zig: return "Zig"; |
2040 | 0 | case DW_LNAME_Assembly: return "Assembly"; |
2041 | 0 | case DW_LNAME_C_sharp: return "C_sharp"; |
2042 | 0 | case DW_LNAME_Mojo: return "Mojo"; |
2043 | 0 | case DW_LNAME_GLSL: return "GLSL"; |
2044 | 0 | case DW_LNAME_GLSL_ES: return "GLSL_ES"; |
2045 | 0 | case DW_LNAME_HLSL: return "HLSL"; |
2046 | 0 | case DW_LNAME_OpenCL_CPP: return "OpenCL_CPP"; |
2047 | 0 | case DW_LNAME_CPP_for_OpenCL: return "CPP_for_OpenCL"; |
2048 | 0 | case DW_LNAME_SYCL: return "SYCL"; |
2049 | 0 | case DW_LNAME_Ruby: return "Ruby"; |
2050 | 0 | case DW_LNAME_Move: return "Move"; |
2051 | 0 | case DW_LNAME_Hylo: return "Hylo"; |
2052 | 0 | case DW_LNAME_HIP: return "HIP"; |
2053 | 0 | case DW_LNAME_Odin: return "Odin"; |
2054 | 0 | case DW_LNAME_P4: return "P4"; |
2055 | 0 | case DW_LNAME_Metal: return "Metal"; |
2056 | 0 | case DW_LNAME_Algol68: return "Algol68"; |
2057 | 0 | default: break; |
2058 | 0 | } |
2059 | | |
2060 | 0 | static char buffer[100]; |
2061 | |
|
2062 | 0 | if (value >= DW_LNAME_lo_user && value <= DW_LNAME_hi_user) |
2063 | 0 | snprintf (buffer, sizeof (buffer), _("Implementation specific AT_language_name value: %lx"), |
2064 | 0 | value); |
2065 | 0 | else |
2066 | 0 | snprintf (buffer, sizeof (buffer), _("Unknown AT_language_name value: %lx"), |
2067 | 0 | value); |
2068 | |
|
2069 | 0 | return buffer; |
2070 | 0 | } |
2071 | | |
2072 | | static void |
2073 | | add_dwo_info (const char * value, uint64_t cu_offset, dwo_type type) |
2074 | 153 | { |
2075 | 153 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); |
2076 | | |
2077 | 153 | dwinfo->type = type; |
2078 | 153 | dwinfo->value = value; |
2079 | 153 | dwinfo->cu_offset = cu_offset; |
2080 | 153 | dwinfo->next = first_dwo_info; |
2081 | 153 | first_dwo_info = dwinfo; |
2082 | 153 | } |
2083 | | |
2084 | | static void |
2085 | | add_dwo_name (const char * name, uint64_t cu_offset) |
2086 | 0 | { |
2087 | 0 | add_dwo_info (name, cu_offset, DWO_NAME); |
2088 | 0 | } |
2089 | | |
2090 | | static void |
2091 | | add_dwo_dir (const char * dir, uint64_t cu_offset) |
2092 | 153 | { |
2093 | 153 | add_dwo_info (dir, cu_offset, DWO_DIR); |
2094 | 153 | } |
2095 | | |
2096 | | static void |
2097 | | add_dwo_id (const char * id, uint64_t cu_offset) |
2098 | 0 | { |
2099 | 0 | add_dwo_info (id, cu_offset, DWO_ID); |
2100 | 0 | } |
2101 | | |
2102 | | static void |
2103 | | free_dwo_info (void) |
2104 | 121k | { |
2105 | 121k | dwo_info * dwinfo; |
2106 | 121k | dwo_info * next; |
2107 | | |
2108 | 121k | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) |
2109 | 153 | { |
2110 | 153 | next = dwinfo->next; |
2111 | 153 | free (dwinfo); |
2112 | 153 | } |
2113 | 121k | first_dwo_info = NULL; |
2114 | 121k | } |
2115 | | |
2116 | | /* Ensure that START + UVALUE is less than END. |
2117 | | Return an adjusted UVALUE if necessary to ensure this relationship. */ |
2118 | | |
2119 | | static inline uint64_t |
2120 | | check_uvalue (const unsigned char *start, |
2121 | | uint64_t uvalue, |
2122 | | const unsigned char *end) |
2123 | 496 | { |
2124 | 496 | uint64_t max_uvalue = end - start; |
2125 | | |
2126 | | /* See PR 17512: file: 008-103549-0.001:0.1. |
2127 | | and PR 24829 for examples of where these tests are triggered. */ |
2128 | 496 | if (uvalue > max_uvalue) |
2129 | 31 | { |
2130 | 31 | warn (_("Corrupt attribute block length: %#" PRIx64 "\n"), uvalue); |
2131 | 31 | uvalue = max_uvalue; |
2132 | 31 | } |
2133 | | |
2134 | 496 | return uvalue; |
2135 | 496 | } |
2136 | | |
2137 | | static unsigned char * |
2138 | | skip_attr_bytes (unsigned long form, |
2139 | | unsigned char *data, |
2140 | | unsigned char *end, |
2141 | | uint64_t pointer_size, |
2142 | | uint64_t offset_size, |
2143 | | int dwarf_version, |
2144 | | uint64_t *value_return) |
2145 | 1.32k | { |
2146 | 1.32k | int64_t svalue; |
2147 | 1.32k | uint64_t uvalue = 0; |
2148 | 1.32k | uint64_t inc = 0; |
2149 | | |
2150 | 1.32k | * value_return = 0; |
2151 | | |
2152 | 1.32k | switch (form) |
2153 | 1.32k | { |
2154 | 0 | case DW_FORM_ref_addr: |
2155 | 0 | if (dwarf_version == 2) |
2156 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
2157 | 0 | else if (dwarf_version > 2) |
2158 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
2159 | 0 | else |
2160 | 0 | return NULL; |
2161 | 0 | break; |
2162 | | |
2163 | 0 | case DW_FORM_addr: |
2164 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
2165 | 0 | break; |
2166 | | |
2167 | 201 | case DW_FORM_strp: |
2168 | 201 | case DW_FORM_line_strp: |
2169 | 201 | case DW_FORM_sec_offset: |
2170 | 201 | case DW_FORM_GNU_ref_alt: |
2171 | 201 | case DW_FORM_GNU_strp_alt: |
2172 | 201 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
2173 | 201 | break; |
2174 | | |
2175 | 201 | case DW_FORM_flag_present: |
2176 | 40 | uvalue = 1; |
2177 | 40 | break; |
2178 | | |
2179 | 0 | case DW_FORM_ref1: |
2180 | 0 | case DW_FORM_flag: |
2181 | 708 | case DW_FORM_data1: |
2182 | 708 | case DW_FORM_strx1: |
2183 | 708 | case DW_FORM_addrx1: |
2184 | 708 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2185 | 708 | break; |
2186 | | |
2187 | 708 | case DW_FORM_strx3: |
2188 | 0 | case DW_FORM_addrx3: |
2189 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); |
2190 | 0 | break; |
2191 | | |
2192 | 0 | case DW_FORM_ref2: |
2193 | 0 | case DW_FORM_data2: |
2194 | 0 | case DW_FORM_strx2: |
2195 | 0 | case DW_FORM_addrx2: |
2196 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2197 | 0 | break; |
2198 | | |
2199 | 248 | case DW_FORM_ref4: |
2200 | 248 | case DW_FORM_data4: |
2201 | 248 | case DW_FORM_strx4: |
2202 | 248 | case DW_FORM_addrx4: |
2203 | 248 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2204 | 248 | break; |
2205 | | |
2206 | 248 | case DW_FORM_sdata: |
2207 | 0 | READ_SLEB (svalue, data, end); |
2208 | 0 | uvalue = svalue; |
2209 | 0 | break; |
2210 | | |
2211 | 0 | case DW_FORM_ref_udata: |
2212 | 0 | case DW_FORM_udata: |
2213 | 0 | case DW_FORM_GNU_str_index: |
2214 | 0 | case DW_FORM_strx: |
2215 | 0 | case DW_FORM_GNU_addr_index: |
2216 | 0 | case DW_FORM_addrx: |
2217 | 0 | case DW_FORM_loclistx: |
2218 | 0 | case DW_FORM_rnglistx: |
2219 | 0 | READ_ULEB (uvalue, data, end); |
2220 | 0 | break; |
2221 | | |
2222 | 0 | case DW_FORM_ref8: |
2223 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
2224 | 0 | break; |
2225 | | |
2226 | 0 | case DW_FORM_data8: |
2227 | 0 | case DW_FORM_ref_sig8: |
2228 | 0 | inc = 8; |
2229 | 0 | break; |
2230 | | |
2231 | 0 | case DW_FORM_data16: |
2232 | 0 | inc = 16; |
2233 | 0 | break; |
2234 | | |
2235 | 121 | case DW_FORM_string: |
2236 | 121 | inc = strnlen ((char *) data, end - data) + 1; |
2237 | 121 | break; |
2238 | | |
2239 | 0 | case DW_FORM_block: |
2240 | 1 | case DW_FORM_exprloc: |
2241 | 1 | READ_ULEB (uvalue, data, end); |
2242 | 1 | inc = uvalue; |
2243 | 1 | break; |
2244 | | |
2245 | 0 | case DW_FORM_block1: |
2246 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2247 | 0 | inc = uvalue; |
2248 | 0 | break; |
2249 | | |
2250 | 0 | case DW_FORM_block2: |
2251 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2252 | 0 | inc = uvalue; |
2253 | 0 | break; |
2254 | | |
2255 | 0 | case DW_FORM_block4: |
2256 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2257 | 0 | inc = uvalue; |
2258 | 0 | break; |
2259 | | |
2260 | 0 | case DW_FORM_indirect: |
2261 | 0 | READ_ULEB (form, data, end); |
2262 | 0 | if (form == DW_FORM_implicit_const) |
2263 | 0 | SKIP_ULEB (data, end); |
2264 | 0 | return skip_attr_bytes (form, data, end, pointer_size, offset_size, |
2265 | 0 | dwarf_version, value_return); |
2266 | | |
2267 | 1 | default: |
2268 | 1 | return NULL; |
2269 | 1.32k | } |
2270 | | |
2271 | 1.31k | * value_return = uvalue; |
2272 | 1.31k | if (inc <= (size_t) (end - data)) |
2273 | 1.31k | data += inc; |
2274 | 1 | else |
2275 | 1 | data = end; |
2276 | 1.31k | return data; |
2277 | 1.32k | } |
2278 | | |
2279 | | /* Given form FORM with value UVALUE, locate and return the abbreviation |
2280 | | associated with it. */ |
2281 | | |
2282 | | static abbrev_entry * |
2283 | | get_type_abbrev_from_form (unsigned long form, |
2284 | | uint64_t uvalue, |
2285 | | uint64_t cu_offset, |
2286 | | unsigned char *cu_end, |
2287 | | const struct dwarf_section *section, |
2288 | | unsigned long *abbrev_num_return, |
2289 | | unsigned char **data_return, |
2290 | | abbrev_map **map_return) |
2291 | 496 | { |
2292 | 496 | switch (form) |
2293 | 496 | { |
2294 | 0 | case DW_FORM_GNU_ref_alt: |
2295 | 0 | case DW_FORM_ref_sig8: |
2296 | | /* FIXME: We are unable to handle this form at the moment. */ |
2297 | 0 | return NULL; |
2298 | | |
2299 | 0 | case DW_FORM_ref_addr: |
2300 | 0 | if (uvalue >= section->size) |
2301 | 0 | { |
2302 | 0 | warn (_("Unable to resolve ref_addr form: uvalue %" PRIx64 |
2303 | 0 | " >= section size %" PRIx64 " (%s)\n"), |
2304 | 0 | uvalue, section->size, section->name); |
2305 | 0 | return NULL; |
2306 | 0 | } |
2307 | 0 | break; |
2308 | | |
2309 | 0 | case DW_FORM_ref_sup4: |
2310 | 0 | case DW_FORM_ref_sup8: |
2311 | 0 | break; |
2312 | | |
2313 | 0 | case DW_FORM_ref1: |
2314 | 0 | case DW_FORM_ref2: |
2315 | 486 | case DW_FORM_ref4: |
2316 | 486 | case DW_FORM_ref8: |
2317 | 486 | case DW_FORM_ref_udata: |
2318 | 486 | if (uvalue + cu_offset < uvalue |
2319 | 486 | || uvalue + cu_offset > (size_t) (cu_end - section->start)) |
2320 | 0 | { |
2321 | 0 | warn (_("Unable to resolve ref form: uvalue %" PRIx64 |
2322 | 0 | " + cu_offset %" PRIx64 " > CU size %tx\n"), |
2323 | 0 | uvalue, cu_offset, cu_end - section->start); |
2324 | 0 | return NULL; |
2325 | 0 | } |
2326 | 486 | uvalue += cu_offset; |
2327 | 486 | break; |
2328 | | |
2329 | | /* FIXME: Are there other DW_FORMs that can be used by types ? */ |
2330 | | |
2331 | 10 | default: |
2332 | 10 | warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form); |
2333 | 10 | return NULL; |
2334 | 496 | } |
2335 | | |
2336 | 486 | abbrev_map *map = find_abbrev_map_by_offset (uvalue); |
2337 | | |
2338 | 486 | if (map == NULL) |
2339 | 0 | { |
2340 | 0 | warn (_("Unable to find abbreviations for CU offset %" PRIx64 "\n"), |
2341 | 0 | uvalue); |
2342 | 0 | return NULL; |
2343 | 0 | } |
2344 | 486 | if (map->list == NULL) |
2345 | 0 | { |
2346 | 0 | warn (_("Empty abbreviation list encountered for CU offset %" PRIx64 "\n"), |
2347 | 0 | uvalue); |
2348 | 0 | return NULL; |
2349 | 0 | } |
2350 | | |
2351 | 486 | if (map_return != NULL) |
2352 | 486 | { |
2353 | 486 | if (form == DW_FORM_ref_addr) |
2354 | 0 | *map_return = map; |
2355 | 486 | else |
2356 | 486 | *map_return = NULL; |
2357 | 486 | } |
2358 | | |
2359 | 486 | unsigned char *data = section->start + uvalue; |
2360 | 486 | if (form == DW_FORM_ref_addr) |
2361 | 0 | cu_end = section->start + map->end; |
2362 | | |
2363 | 486 | unsigned long abbrev_number; |
2364 | 486 | READ_ULEB (abbrev_number, data, cu_end); |
2365 | | |
2366 | 486 | if (abbrev_num_return != NULL) |
2367 | 0 | *abbrev_num_return = abbrev_number; |
2368 | | |
2369 | 486 | if (data_return != NULL) |
2370 | 486 | *data_return = data; |
2371 | | |
2372 | 486 | abbrev_entry *entry; |
2373 | 2.23k | for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next) |
2374 | 2.22k | if (entry->number == abbrev_number) |
2375 | 479 | break; |
2376 | | |
2377 | 486 | if (entry == NULL) |
2378 | 7 | warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number); |
2379 | | |
2380 | 486 | return entry; |
2381 | 486 | } |
2382 | | |
2383 | | /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY |
2384 | | can be determined to be a signed type. The data for ENTRY can be |
2385 | | found starting at DATA. */ |
2386 | | |
2387 | | static void |
2388 | | get_type_signedness (abbrev_entry *entry, |
2389 | | const struct dwarf_section *section, |
2390 | | unsigned char *data, |
2391 | | unsigned char *end, |
2392 | | uint64_t cu_offset, |
2393 | | uint64_t pointer_size, |
2394 | | uint64_t offset_size, |
2395 | | int dwarf_version, |
2396 | | bool *is_signed, |
2397 | | unsigned int nesting) |
2398 | 479 | { |
2399 | 479 | abbrev_attr * attr; |
2400 | | |
2401 | 479 | * is_signed = false; |
2402 | | |
2403 | 479 | #define MAX_NESTING 20 |
2404 | 479 | if (nesting > MAX_NESTING) |
2405 | 0 | { |
2406 | | /* FIXME: Warn - or is this expected ? |
2407 | | NB/ We need to avoid infinite recursion. */ |
2408 | 0 | return; |
2409 | 0 | } |
2410 | | |
2411 | 479 | for (attr = entry->first_attr; |
2412 | 1.79k | attr != NULL && attr->attribute; |
2413 | 1.31k | attr = attr->next) |
2414 | 1.32k | { |
2415 | 1.32k | unsigned char * orig_data = data; |
2416 | 1.32k | uint64_t uvalue = 0; |
2417 | | |
2418 | 1.32k | data = skip_attr_bytes (attr->form, data, end, pointer_size, |
2419 | 1.32k | offset_size, dwarf_version, & uvalue); |
2420 | 1.32k | if (data == NULL) |
2421 | 1 | return; |
2422 | | |
2423 | 1.31k | switch (attr->attribute) |
2424 | 1.31k | { |
2425 | 0 | case DW_AT_linkage_name: |
2426 | 319 | case DW_AT_name: |
2427 | 319 | if (do_wide) |
2428 | 0 | { |
2429 | 0 | if (attr->form == DW_FORM_strp) |
2430 | 0 | printf (", %s", fetch_indirect_string (uvalue)); |
2431 | 0 | else if (attr->form == DW_FORM_string) |
2432 | 0 | printf (", %.*s", (int) (end - orig_data), orig_data); |
2433 | 0 | } |
2434 | 319 | break; |
2435 | | |
2436 | 175 | case DW_AT_type: |
2437 | | /* Recurse. */ |
2438 | 175 | { |
2439 | 175 | abbrev_entry *type_abbrev; |
2440 | 175 | unsigned char *type_data; |
2441 | 175 | abbrev_map *map; |
2442 | | |
2443 | 175 | type_abbrev = get_type_abbrev_from_form (attr->form, |
2444 | 175 | uvalue, |
2445 | 175 | cu_offset, |
2446 | 175 | end, |
2447 | 175 | section, |
2448 | 175 | NULL /* abbrev num return */, |
2449 | 175 | &type_data, |
2450 | 175 | &map); |
2451 | 175 | if (type_abbrev == NULL) |
2452 | 0 | break; |
2453 | | |
2454 | 175 | get_type_signedness (type_abbrev, section, type_data, |
2455 | 175 | map ? section->start + map->end : end, |
2456 | 175 | map ? map->start : cu_offset, |
2457 | 175 | pointer_size, offset_size, dwarf_version, |
2458 | 175 | is_signed, nesting + 1); |
2459 | 175 | } |
2460 | 0 | break; |
2461 | | |
2462 | 264 | case DW_AT_encoding: |
2463 | | /* Determine signness. */ |
2464 | 264 | switch (uvalue) |
2465 | 264 | { |
2466 | 0 | case DW_ATE_address: |
2467 | | /* FIXME - some architectures have signed addresses. */ |
2468 | 0 | case DW_ATE_boolean: |
2469 | 115 | case DW_ATE_unsigned: |
2470 | 115 | case DW_ATE_unsigned_char: |
2471 | 115 | case DW_ATE_unsigned_fixed: |
2472 | 115 | * is_signed = false; |
2473 | 115 | break; |
2474 | | |
2475 | 4 | default: |
2476 | 4 | case DW_ATE_complex_float: |
2477 | 4 | case DW_ATE_float: |
2478 | 129 | case DW_ATE_signed: |
2479 | 149 | case DW_ATE_signed_char: |
2480 | 149 | case DW_ATE_imaginary_float: |
2481 | 149 | case DW_ATE_decimal_float: |
2482 | 149 | case DW_ATE_signed_fixed: |
2483 | 149 | * is_signed = true; |
2484 | 149 | break; |
2485 | 264 | } |
2486 | 264 | break; |
2487 | 1.31k | } |
2488 | 1.31k | } |
2489 | 479 | } |
2490 | | |
2491 | | static void |
2492 | | read_and_print_leb128 (unsigned char *data, |
2493 | | unsigned int *bytes_read, |
2494 | | unsigned const char *end, |
2495 | | bool is_signed) |
2496 | 0 | { |
2497 | 0 | int status; |
2498 | 0 | uint64_t val = read_leb128 (data, end, is_signed, bytes_read, &status); |
2499 | 0 | if (status != 0) |
2500 | 0 | report_leb_status (status); |
2501 | 0 | else if (is_signed) |
2502 | 0 | printf ("%" PRId64, val); |
2503 | 0 | else |
2504 | 0 | printf ("%" PRIu64, val); |
2505 | 0 | } |
2506 | | |
2507 | | static void |
2508 | | display_discr_list (unsigned long form, |
2509 | | uint64_t uvalue, |
2510 | | unsigned char *data, |
2511 | | int level) |
2512 | 6 | { |
2513 | 6 | unsigned char *end = data; |
2514 | | |
2515 | 6 | if (uvalue == 0) |
2516 | 0 | { |
2517 | 0 | printf ("[default]"); |
2518 | 0 | return; |
2519 | 0 | } |
2520 | | |
2521 | 6 | switch (form) |
2522 | 6 | { |
2523 | 0 | case DW_FORM_block: |
2524 | 0 | case DW_FORM_block1: |
2525 | 0 | case DW_FORM_block2: |
2526 | 0 | case DW_FORM_block4: |
2527 | | /* Move data pointer back to the start of the byte array. */ |
2528 | 0 | data -= uvalue; |
2529 | 0 | break; |
2530 | 6 | default: |
2531 | 6 | printf ("<corrupt>\n"); |
2532 | 6 | warn (_("corrupt discr_list - not using a block form\n")); |
2533 | 6 | return; |
2534 | 6 | } |
2535 | | |
2536 | 0 | if (uvalue < 2) |
2537 | 0 | { |
2538 | 0 | printf ("<corrupt>\n"); |
2539 | 0 | warn (_("corrupt discr_list - block not long enough\n")); |
2540 | 0 | return; |
2541 | 0 | } |
2542 | | |
2543 | 0 | bool is_signed = (level > 0 && level <= MAX_CU_NESTING |
2544 | 0 | ? level_type_signed [level - 1] : false); |
2545 | |
|
2546 | 0 | printf ("("); |
2547 | 0 | while (data < end) |
2548 | 0 | { |
2549 | 0 | unsigned char discriminant; |
2550 | 0 | unsigned int bytes_read; |
2551 | |
|
2552 | 0 | SAFE_BYTE_GET_AND_INC (discriminant, data, 1, end); |
2553 | |
|
2554 | 0 | switch (discriminant) |
2555 | 0 | { |
2556 | 0 | case DW_DSC_label: |
2557 | 0 | printf ("label "); |
2558 | 0 | read_and_print_leb128 (data, & bytes_read, end, is_signed); |
2559 | 0 | data += bytes_read; |
2560 | 0 | break; |
2561 | | |
2562 | 0 | case DW_DSC_range: |
2563 | 0 | printf ("range "); |
2564 | 0 | read_and_print_leb128 (data, & bytes_read, end, is_signed); |
2565 | 0 | data += bytes_read; |
2566 | |
|
2567 | 0 | printf (".."); |
2568 | 0 | read_and_print_leb128 (data, & bytes_read, end, is_signed); |
2569 | 0 | data += bytes_read; |
2570 | 0 | break; |
2571 | | |
2572 | 0 | default: |
2573 | 0 | printf ("<corrupt>\n"); |
2574 | 0 | warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"), |
2575 | 0 | discriminant); |
2576 | 0 | return; |
2577 | 0 | } |
2578 | | |
2579 | 0 | if (data < end) |
2580 | 0 | printf (", "); |
2581 | 0 | } |
2582 | | |
2583 | 0 | if (is_signed) |
2584 | 0 | printf (")(signed)"); |
2585 | 0 | else |
2586 | 0 | printf (")(unsigned)"); |
2587 | 0 | } |
2588 | | |
2589 | | static void |
2590 | | display_lang (uint64_t uvalue) |
2591 | 242 | { |
2592 | 242 | switch (uvalue) |
2593 | 242 | { |
2594 | | /* Ordered by the numeric value of these constants. */ |
2595 | 48 | case DW_LANG_C89: printf ("ANSI C"); break; |
2596 | 0 | case DW_LANG_C: printf ("non-ANSI C"); break; |
2597 | 0 | case DW_LANG_Ada83: printf ("Ada"); break; |
2598 | 5 | case DW_LANG_C_plus_plus: printf ("C++"); break; |
2599 | 0 | case DW_LANG_Cobol74: printf ("Cobol 74"); break; |
2600 | 0 | case DW_LANG_Cobol85: printf ("Cobol 85"); break; |
2601 | 0 | case DW_LANG_Fortran77: printf ("FORTRAN 77"); break; |
2602 | 0 | case DW_LANG_Fortran90: printf ("Fortran 90"); break; |
2603 | 0 | case DW_LANG_Pascal83: printf ("ANSI Pascal"); break; |
2604 | 0 | case DW_LANG_Modula2: printf ("Modula 2"); break; |
2605 | | |
2606 | | /* DWARF 2.1 values. */ |
2607 | 2 | case DW_LANG_Java: printf ("Java"); break; |
2608 | 121 | case DW_LANG_C99: printf ("ANSI C99"); break; |
2609 | 1 | case DW_LANG_Ada95: printf ("ADA 95"); break; |
2610 | 0 | case DW_LANG_Fortran95: printf ("Fortran 95"); break; |
2611 | | |
2612 | | /* DWARF 3 values. */ |
2613 | 0 | case DW_LANG_PLI: printf ("PLI"); break; |
2614 | 0 | case DW_LANG_ObjC: printf ("Objective C"); break; |
2615 | 0 | case DW_LANG_ObjC_plus_plus: printf ("Objective C++"); break; |
2616 | 0 | case DW_LANG_UPC: printf ("Unified Parallel C"); break; |
2617 | 0 | case DW_LANG_D: printf ("D"); break; |
2618 | | |
2619 | | /* DWARF 4 values. */ |
2620 | 0 | case DW_LANG_Python: printf ("Python"); break; |
2621 | | |
2622 | | /* DWARF 5 values. */ |
2623 | 1 | case DW_LANG_OpenCL: printf ("OpenCL"); break; |
2624 | 0 | case DW_LANG_Go: printf ("Go"); break; |
2625 | 0 | case DW_LANG_Modula3: printf ("Modula 3"); break; |
2626 | 0 | case DW_LANG_Haskell: printf ("Haskell"); break; |
2627 | 0 | case DW_LANG_C_plus_plus_03: printf ("C++03"); break; |
2628 | 0 | case DW_LANG_C_plus_plus_11: printf ("C++11"); break; |
2629 | 0 | case DW_LANG_OCaml: printf ("OCaml"); break; |
2630 | 0 | case DW_LANG_Rust: printf ("Rust"); break; |
2631 | 0 | case DW_LANG_C11: printf ("C11"); break; |
2632 | 0 | case DW_LANG_Swift: printf ("Swift"); break; |
2633 | 0 | case DW_LANG_Julia: printf ("Julia"); break; |
2634 | 1 | case DW_LANG_Dylan: printf ("Dylan"); break; |
2635 | 0 | case DW_LANG_C_plus_plus_14: printf ("C++14"); break; |
2636 | 0 | case DW_LANG_Fortran03: printf ("Fortran 03"); break; |
2637 | 0 | case DW_LANG_Fortran08: printf ("Fortran 08"); break; |
2638 | 0 | case DW_LANG_RenderScript: printf ("RenderScript"); break; |
2639 | 0 | case DW_LANG_C17: printf ("C17"); break; |
2640 | 0 | case DW_LANG_Fortran18: printf ("Fortran 18"); break; |
2641 | 0 | case DW_LANG_Ada2005: printf ("Ada 2005"); break; |
2642 | 0 | case DW_LANG_Ada2012: printf ("Ada 2012"); break; |
2643 | 0 | case DW_LANG_HIP: printf ("Hip"); break; |
2644 | 0 | case DW_LANG_Assembly: printf ("Assembler"); break; |
2645 | 0 | case DW_LANG_C_sharp: printf ("C Sharp"); break; |
2646 | 0 | case DW_LANG_Mojo: printf ("Mojo"); break; |
2647 | 0 | case DW_LANG_GLSL: printf ("GLSL"); break; |
2648 | 0 | case DW_LANG_GLSL_ES: printf ("GLSL_ES"); break; |
2649 | 0 | case DW_LANG_HLSL: printf ("HLSL"); break; |
2650 | 0 | case DW_LANG_OpenCL_CPP: printf ("OpenCL C++"); break; |
2651 | 0 | case DW_LANG_CPP_for_OpenCL: printf ("C++ for OpenCL"); break; |
2652 | 0 | case DW_LANG_SYCL: printf ("SYCL"); break; |
2653 | 0 | case DW_LANG_C_plus_plus_17: printf ("C++17"); break; |
2654 | 0 | case DW_LANG_C_plus_plus_20: printf ("C++20"); break; |
2655 | 0 | case DW_LANG_C_plus_plus_23: printf ("C++23"); break; |
2656 | 0 | case DW_LANG_Odin: printf ("Odin"); break; |
2657 | 0 | case DW_LANG_P4: printf ("P4"); break; |
2658 | 0 | case DW_LANG_Metal: printf ("C23"); break; |
2659 | 0 | case DW_LANG_C23: printf ("C23"); break; |
2660 | 0 | case DW_LANG_Fortran23: printf ("Fortran 23"); break; |
2661 | 0 | case DW_LANG_Ruby: printf ("Ruby"); break; |
2662 | 0 | case DW_LANG_Move: printf ("Move"); break; |
2663 | 0 | case DW_LANG_Hylo: printf ("Hylo"); break; |
2664 | | |
2665 | | /* MIPS extension. */ |
2666 | 7 | case DW_LANG_Mips_Assembler: printf ("MIPS assembler"); break; |
2667 | | |
2668 | | /* UPC extension. */ |
2669 | 0 | case DW_LANG_Upc: printf ("Unified Parallel C"); break; |
2670 | | |
2671 | 56 | default: |
2672 | 56 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
2673 | 7 | printf (_("implementation defined: %#" PRIx64 ""), uvalue); |
2674 | 49 | else |
2675 | 49 | printf (_("unknown: %#" PRIx64 ""), uvalue); |
2676 | 56 | break; |
2677 | 242 | } |
2678 | 242 | } |
2679 | | |
2680 | | static void |
2681 | | display_base_type (const base_type bt) |
2682 | 0 | { |
2683 | 0 | printf ("type: %s", bt.name); |
2684 | 0 | if (bt.size_type == UNSIGNED_S) |
2685 | 0 | printf (", size: %#" PRIx64 "\n", bt.size.usize); |
2686 | 0 | else if (bt.size_type == SIGNED_S) |
2687 | 0 | printf (", size: %#" PRIx64 "\n", bt.size.ssize); |
2688 | 0 | } |
2689 | | |
2690 | | static base_type * |
2691 | | get_or_create_base_type (uint64_t die_offset) |
2692 | 0 | { |
2693 | 0 | if (base_type_list.tail == NULL |
2694 | 0 | || base_type_list.tail->die_offset != die_offset) |
2695 | 0 | { |
2696 | 0 | base_type *ret = xmalloc (sizeof (*ret)); |
2697 | 0 | ret->die_offset = die_offset; |
2698 | 0 | ret->name = NULL; |
2699 | 0 | ret->next = NULL; |
2700 | 0 | ret->field_type = BASE_TYPE; |
2701 | 0 | ret->size_type = UNSIGNED_S; |
2702 | 0 | ret->size.usize = 0; |
2703 | 0 | if (base_type_list.head == NULL) |
2704 | 0 | { |
2705 | 0 | base_type_list.head = ret; |
2706 | 0 | base_type_list.tail = ret; |
2707 | 0 | } |
2708 | 0 | else |
2709 | 0 | { |
2710 | 0 | base_type_list.tail->next = ret; |
2711 | 0 | base_type_list.tail = ret; |
2712 | 0 | } |
2713 | 0 | } |
2714 | 0 | return base_type_list.tail; |
2715 | 0 | } |
2716 | | |
2717 | | static void |
2718 | | display_type_def (const type_def td) |
2719 | 0 | { |
2720 | 0 | printf ("type: typedef %s\n", td.name); |
2721 | 0 | } |
2722 | | |
2723 | | static type_def* |
2724 | | get_or_create_type_def (uint64_t die_offset) |
2725 | 0 | { |
2726 | 0 | if (type_def_list.tail == NULL |
2727 | 0 | || type_def_list.tail->die_offset != die_offset) |
2728 | 0 | { |
2729 | 0 | generic_type gt = { { .base_type = NULL }, NO_TYPE }; |
2730 | 0 | type_def *ret = xmalloc (sizeof (*ret)); |
2731 | 0 | ret->ptr_type = gt; |
2732 | 0 | ret->die_offset = die_offset; |
2733 | 0 | ret->ptr_die_offset = 0; |
2734 | 0 | ret->name = NULL; |
2735 | 0 | ret->next = NULL; |
2736 | 0 | ret->field_type = TYPE_DEF; |
2737 | 0 | if (type_def_list.head == NULL) |
2738 | 0 | { |
2739 | 0 | type_def_list.head = ret; |
2740 | 0 | type_def_list.tail = ret; |
2741 | 0 | } |
2742 | 0 | else |
2743 | 0 | { |
2744 | 0 | type_def_list.tail->next = ret; |
2745 | 0 | type_def_list.tail = ret; |
2746 | 0 | } |
2747 | 0 | } |
2748 | 0 | return type_def_list.tail; |
2749 | 0 | } |
2750 | | |
2751 | | static void |
2752 | | display_enum (enum_constant *ec, int nb_tab) |
2753 | 0 | { |
2754 | 0 | enum_constant *head = ec; |
2755 | 0 | while (head != NULL) |
2756 | 0 | { |
2757 | 0 | PRINT_SPACE (nb_tab); |
2758 | 0 | printf ("value: %s = %" PRId64 "\n", head->name, head->value); |
2759 | 0 | head = head->next; |
2760 | 0 | } |
2761 | 0 | } |
2762 | | |
2763 | | static enum_constant * |
2764 | | get_or_create_enum_constant (enum_type *et, uint64_t die_offset) |
2765 | 0 | { |
2766 | 0 | assert (et != NULL); |
2767 | 0 | if (et->enum_const_tail == NULL |
2768 | 0 | || et->enum_const_tail->die_offset != die_offset) |
2769 | 0 | { |
2770 | 0 | enum_constant *enum_const = xmalloc (sizeof (*enum_const)); |
2771 | 0 | enum_const->die_offset = die_offset; |
2772 | 0 | enum_const->value = 0; |
2773 | 0 | enum_const->name = NULL; |
2774 | 0 | enum_const->next = NULL; |
2775 | 0 | if (et->enum_const_head == NULL) |
2776 | 0 | { |
2777 | 0 | et->enum_const_head = enum_const; |
2778 | 0 | et->enum_const_tail = enum_const; |
2779 | 0 | } |
2780 | 0 | else |
2781 | 0 | { |
2782 | 0 | et->enum_const_tail->next = enum_const; |
2783 | 0 | et->enum_const_tail = enum_const; |
2784 | 0 | } |
2785 | 0 | } |
2786 | 0 | return et->enum_const_tail; |
2787 | 0 | } |
2788 | | |
2789 | | static void |
2790 | | display_enum_type (const enum_type et, int nb_tab) |
2791 | 0 | { |
2792 | 0 | if (et.name == NULL) |
2793 | 0 | printf ("type: enum <anonymous>, size: %#" PRIx64 "\n", et.size.usize); |
2794 | 0 | else |
2795 | 0 | printf ("type: enum %s, size: %#" PRIx64 "\n", et.name, et.size.usize); |
2796 | 0 | PRINT_LBRACE (nb_tab); |
2797 | 0 | display_enum (et.enum_const_head, nb_tab + 1); |
2798 | 0 | PRINT_RBRACE (nb_tab); |
2799 | 0 | } |
2800 | | |
2801 | | static enum_type * |
2802 | | get_or_create_enum_type (uint64_t die_offset) |
2803 | 0 | { |
2804 | 0 | if (enum_type_list.tail == NULL |
2805 | 0 | || enum_type_list.tail->die_offset != die_offset) |
2806 | 0 | { |
2807 | 0 | enum_type *ret = xmalloc (sizeof (*ret)); |
2808 | |
|
2809 | 0 | ret->die_offset = die_offset; |
2810 | 0 | ret->size.usize = 0; |
2811 | 0 | ret->name = NULL; |
2812 | 0 | ret->enum_const_head = NULL; |
2813 | 0 | ret->enum_const_tail = NULL; |
2814 | 0 | ret->next = NULL; |
2815 | 0 | ret->field_type = ENUM_TYPE; |
2816 | 0 | ret->size_type = UNSIGNED_S; |
2817 | 0 | if (enum_type_list.head == NULL) |
2818 | 0 | { |
2819 | 0 | enum_type_list.head = ret; |
2820 | 0 | enum_type_list.tail = ret; |
2821 | 0 | } |
2822 | 0 | else |
2823 | 0 | { |
2824 | 0 | enum_type_list.tail->next = ret; |
2825 | 0 | enum_type_list.tail = ret; |
2826 | 0 | } |
2827 | 0 | } |
2828 | 0 | return enum_type_list.tail; |
2829 | 0 | } |
2830 | | |
2831 | | static void |
2832 | | display_subrange_type (subrange_type *st) |
2833 | 0 | { |
2834 | 0 | subrange_type *head = st; |
2835 | |
|
2836 | 0 | while (head != NULL) |
2837 | 0 | { |
2838 | 0 | if (head->size_type == UNSIGNED_S) |
2839 | 0 | printf ("[%" PRIu64 "]", head->size.usize); |
2840 | 0 | else if (head->size_type == SIGNED_S) |
2841 | 0 | printf ("[%" PRId64 "]", head->size.ssize); |
2842 | 0 | head = head->next; |
2843 | 0 | } |
2844 | 0 | } |
2845 | | |
2846 | | static subrange_type * |
2847 | | get_or_create_subrange_type (tab_type *tt, uint64_t die_offset) |
2848 | 0 | { |
2849 | 0 | assert (tt != NULL); |
2850 | 0 | if (tt->subrange_tail == NULL |
2851 | 0 | || tt->subrange_tail->die_offset != die_offset) |
2852 | 0 | { |
2853 | 0 | subrange_type *ret = xmalloc (sizeof (*ret)); |
2854 | |
|
2855 | 0 | ret->die_offset = die_offset; |
2856 | 0 | ret->size.usize = 0; |
2857 | 0 | ret->next = NULL; |
2858 | 0 | ret->size_type = UNSIGNED_S; |
2859 | 0 | if (tt->subrange_head == NULL) |
2860 | 0 | { |
2861 | 0 | tt->subrange_head = ret; |
2862 | 0 | tt->subrange_tail = ret; |
2863 | 0 | } |
2864 | 0 | else |
2865 | 0 | { |
2866 | 0 | tt->subrange_tail->next = ret; |
2867 | 0 | tt->subrange_tail = ret; |
2868 | 0 | } |
2869 | 0 | } |
2870 | 0 | return tt->subrange_tail; |
2871 | 0 | } |
2872 | | |
2873 | | static void |
2874 | | display_tab_type (const tab_type tt) |
2875 | 0 | { |
2876 | 0 | printf ("type: array"); |
2877 | 0 | display_subrange_type (tt.subrange_head); |
2878 | 0 | printf ("\n"); |
2879 | 0 | } |
2880 | | |
2881 | | static tab_type * |
2882 | | get_or_create_tab_type (uint64_t die_offset) |
2883 | 0 | { |
2884 | 0 | if (tab_type_list.tail == NULL |
2885 | 0 | || tab_type_list.tail->die_offset != die_offset) |
2886 | 0 | { |
2887 | 0 | generic_type gt = { { .base_type = NULL }, NO_TYPE }; |
2888 | 0 | tab_type *ret = xmalloc (sizeof (*ret)); |
2889 | 0 | ret->ptr_type = gt; |
2890 | 0 | ret->die_offset = die_offset; |
2891 | 0 | ret->ptr_die_offset = 0; |
2892 | 0 | ret->subrange_head = NULL; |
2893 | 0 | ret->subrange_tail = NULL; |
2894 | 0 | ret->next = NULL; |
2895 | 0 | ret->field_type = TAB_TYPE; |
2896 | 0 | if (tab_type_list.head == NULL) |
2897 | 0 | { |
2898 | 0 | tab_type_list.head = ret; |
2899 | 0 | tab_type_list.tail = ret; |
2900 | 0 | } |
2901 | 0 | else |
2902 | 0 | { |
2903 | 0 | tab_type_list.tail->next = ret; |
2904 | 0 | tab_type_list.tail = ret; |
2905 | 0 | } |
2906 | 0 | } |
2907 | 0 | return tab_type_list.tail; |
2908 | 0 | } |
2909 | | |
2910 | | static void |
2911 | | display_member_type (const member_type mt) |
2912 | 0 | { |
2913 | 0 | if (mt.name == NULL) |
2914 | 0 | printf ("member: (anonymous), offset: %#" PRIx64 "\n", mt.member_offset); |
2915 | 0 | else |
2916 | 0 | printf ("member: %s, offset: %#" PRIx64 "\n", mt.name, mt.member_offset); |
2917 | 0 | } |
2918 | | |
2919 | | static member_type * |
2920 | | get_or_create_member_type (member_parent *parent, uint64_t die_offset) |
2921 | 0 | { |
2922 | 0 | if (parent == NULL) |
2923 | 0 | return NULL; |
2924 | 0 | if (parent->member_tail == NULL |
2925 | 0 | || parent->member_tail->die_offset != die_offset) |
2926 | 0 | { |
2927 | 0 | generic_type gt = { { .base_type = NULL }, NO_TYPE }; |
2928 | 0 | member_type *ret = xmalloc (sizeof (*ret)); |
2929 | 0 | ret->ptr_type = gt; |
2930 | 0 | ret->die_offset = die_offset; |
2931 | 0 | ret->ptr_die_offset = 0; |
2932 | 0 | ret->member_offset = 0; |
2933 | 0 | ret->name = 0; |
2934 | 0 | ret->next = NULL; |
2935 | 0 | ret->field_type = MEMBER_TYPE; |
2936 | 0 | if (parent->member_head == NULL) |
2937 | 0 | { |
2938 | 0 | parent->member_head = ret; |
2939 | 0 | parent->member_tail = ret; |
2940 | 0 | } |
2941 | 0 | else |
2942 | 0 | { |
2943 | 0 | parent->member_tail->next = ret; |
2944 | 0 | parent->member_tail = ret; |
2945 | 0 | } |
2946 | 0 | } |
2947 | 0 | return parent->member_tail; |
2948 | 0 | } |
2949 | | |
2950 | | static bool |
2951 | | display_member_parent (const member_parent mp) |
2952 | 0 | { |
2953 | 0 | if (mp.displayed) |
2954 | 0 | { |
2955 | 0 | printf ("nested: struct %s\n", mp.name); |
2956 | 0 | return true; |
2957 | 0 | } |
2958 | 0 | else if (mp.type == UNION_TYPE) |
2959 | 0 | { |
2960 | 0 | if (mp.name == NULL) |
2961 | 0 | printf ("type: union <anonymous>"); |
2962 | 0 | else |
2963 | 0 | printf ("type: union %s", mp.name); |
2964 | 0 | } |
2965 | 0 | else if (mp.type == STRUCT_TYPE) |
2966 | 0 | { |
2967 | 0 | if (mp.name == NULL) |
2968 | 0 | printf ("type: struct <anonymous>"); |
2969 | 0 | else |
2970 | 0 | printf ("type: struct %s", mp.name); |
2971 | 0 | } |
2972 | | |
2973 | 0 | if (mp.is_declaration) |
2974 | 0 | printf (", incomplete or non-defining declaration\n"); |
2975 | 0 | else if (mp.size_type == UNSIGNED_S) |
2976 | 0 | printf (", size: %#" PRIx64 "\n", mp.size.usize); |
2977 | 0 | else if (mp.size_type == SIGNED_S) |
2978 | 0 | printf (", size: %#" PRIx64 "\n", mp.size.ssize); |
2979 | |
|
2980 | 0 | return false; |
2981 | 0 | } |
2982 | | |
2983 | | static member_parent * |
2984 | | get_or_create_member_parent (struct member_parent_l *mp_list, |
2985 | | uint64_t die_offset) |
2986 | 0 | { |
2987 | 0 | if (mp_list->tail == NULL |
2988 | 0 | || mp_list->tail->die_offset != die_offset) |
2989 | 0 | { |
2990 | 0 | member_parent *ret = xmalloc (sizeof (*ret)); |
2991 | 0 | ret->die_offset = die_offset; |
2992 | 0 | ret->size.usize = 0; |
2993 | 0 | ret->name = NULL; |
2994 | 0 | ret->member_head = NULL; |
2995 | 0 | ret->member_tail = NULL; |
2996 | 0 | ret->next = NULL; |
2997 | 0 | ret->size_type = UNSIGNED_S; |
2998 | 0 | ret->field_type = MEMBER_PARENT; |
2999 | 0 | ret->type = UNION_TYPE; |
3000 | 0 | ret->is_declaration = false; |
3001 | 0 | ret->linked = false; |
3002 | 0 | ret->displayed = false; |
3003 | 0 | if (mp_list->head == NULL) |
3004 | 0 | { |
3005 | 0 | mp_list->head = ret; |
3006 | 0 | mp_list->tail = ret; |
3007 | 0 | } |
3008 | 0 | else |
3009 | 0 | { |
3010 | 0 | mp_list->tail->next = ret; |
3011 | 0 | mp_list->tail = ret; |
3012 | 0 | } |
3013 | 0 | } |
3014 | 0 | return mp_list->tail; |
3015 | 0 | } |
3016 | | |
3017 | | static void |
3018 | | display_type_ptr (const type_ptr tp) |
3019 | 0 | { |
3020 | 0 | if (tp.size_type == UNSIGNED_S) |
3021 | 0 | printf ("type: ptr, size: %#" PRIx64 "\n", tp.size.usize); |
3022 | 0 | else if (tp.size_type == SIGNED_S) |
3023 | 0 | printf ("type: ptr, size: %#" PRIx64 "\n", tp.size.ssize); |
3024 | 0 | } |
3025 | | |
3026 | | static type_ptr * |
3027 | | get_or_create_type_ptr (uint64_t die_offset) |
3028 | 0 | { |
3029 | 0 | if (ptr_type_list.tail == NULL |
3030 | 0 | || ptr_type_list.tail->die_offset != die_offset) |
3031 | 0 | { |
3032 | 0 | generic_type gt = { { .base_type = NULL }, NO_TYPE }; |
3033 | |
|
3034 | 0 | type_ptr *ret = xmalloc (sizeof (*ret)); |
3035 | 0 | ret->ptr_type = gt; |
3036 | 0 | ret->die_offset = die_offset; |
3037 | 0 | ret->ptr_die_offset = 0; |
3038 | 0 | ret->size.usize = 0; |
3039 | 0 | ret->next = NULL; |
3040 | 0 | ret->field_type = TYPE_PTR; |
3041 | 0 | ret->size_type = UNSIGNED_S; |
3042 | 0 | if (ptr_type_list.head == NULL) |
3043 | 0 | { |
3044 | 0 | ptr_type_list.head = ret; |
3045 | 0 | ptr_type_list.tail = ret; |
3046 | 0 | } |
3047 | 0 | else |
3048 | 0 | { |
3049 | 0 | ptr_type_list.tail->next = ret; |
3050 | 0 | ptr_type_list.tail = ret; |
3051 | 0 | } |
3052 | 0 | } |
3053 | 0 | return ptr_type_list.tail; |
3054 | 0 | } |
3055 | | |
3056 | | static void |
3057 | | display_type_ref (const type_ref tr) |
3058 | 0 | { |
3059 | 0 | switch (tr.type) |
3060 | 0 | { |
3061 | 0 | case CONST_TYPE: |
3062 | 0 | printf ("type: const\n"); |
3063 | 0 | break; |
3064 | 0 | case VOLATILE_TYPE: |
3065 | 0 | printf ("type: volatile\n"); |
3066 | 0 | break; |
3067 | 0 | } |
3068 | 0 | } |
3069 | | |
3070 | | static type_ref * |
3071 | | get_or_create_type_ref (struct type_ref_l *tr_list, |
3072 | | uint64_t die_offset) |
3073 | 0 | { |
3074 | 0 | if (tr_list->tail == NULL |
3075 | 0 | || tr_list->tail->die_offset != die_offset) |
3076 | 0 | { |
3077 | 0 | generic_type gt = { { .base_type = NULL }, NO_TYPE }; |
3078 | 0 | type_ref *ret = xmalloc (sizeof (*ret)); |
3079 | |
|
3080 | 0 | ret->ptr_type = gt; |
3081 | 0 | ret->die_offset = die_offset; |
3082 | 0 | ret->ptr_die_offset = 0; |
3083 | 0 | ret->next = NULL; |
3084 | | /* Default to CONST_TYPE at initialization. */ |
3085 | 0 | ret->type = CONST_TYPE; |
3086 | 0 | ret->field_type = TYPE_REF; |
3087 | 0 | if (tr_list->head == NULL) |
3088 | 0 | { |
3089 | 0 | tr_list->head = ret; |
3090 | 0 | tr_list->tail = ret; |
3091 | 0 | } |
3092 | 0 | else |
3093 | 0 | { |
3094 | 0 | tr_list->tail->next = ret; |
3095 | 0 | tr_list->tail = ret; |
3096 | 0 | } |
3097 | 0 | } |
3098 | 0 | return tr_list->tail; |
3099 | 0 | } |
3100 | | |
3101 | | static void |
3102 | | display_variable_type (generic_type gt, |
3103 | | int nb_tab) |
3104 | 0 | { |
3105 | 0 | switch (gt.field_type) |
3106 | 0 | { |
3107 | 0 | case NO_TYPE: |
3108 | 0 | break; |
3109 | 0 | case BASE_TYPE: |
3110 | 0 | PRINT_SPACE (nb_tab); |
3111 | 0 | display_base_type (*gt.die_type.base_type); |
3112 | 0 | break; |
3113 | 0 | case TYPE_DEF: |
3114 | 0 | PRINT_SPACE (nb_tab); |
3115 | 0 | display_type_def (*gt.die_type.type_def); |
3116 | 0 | PRINT_LBRACE (nb_tab); |
3117 | 0 | display_variable_type (gt.die_type.type_def->ptr_type, nb_tab + 1); |
3118 | 0 | PRINT_RBRACE (nb_tab); |
3119 | 0 | break; |
3120 | 0 | case ENUM_TYPE: |
3121 | 0 | PRINT_SPACE (nb_tab); |
3122 | 0 | display_enum_type (*gt.die_type.enum_type, nb_tab); |
3123 | 0 | break; |
3124 | 0 | case TAB_TYPE: |
3125 | 0 | PRINT_SPACE (nb_tab); |
3126 | 0 | display_tab_type (*gt.die_type.tab_type); |
3127 | 0 | display_variable_type (gt.die_type.tab_type->ptr_type, nb_tab + 1); |
3128 | 0 | break; |
3129 | 0 | case MEMBER_PARENT: |
3130 | 0 | { |
3131 | 0 | PRINT_SPACE (nb_tab); |
3132 | 0 | if (display_member_parent (*gt.die_type.member_parent)) |
3133 | 0 | break; |
3134 | 0 | gt.die_type.member_parent->displayed = true; |
3135 | 0 | if (gt.die_type.member_parent->member_head != NULL) |
3136 | 0 | { |
3137 | 0 | PRINT_LBRACE (nb_tab); |
3138 | 0 | generic_type generic_mt |
3139 | 0 | = { { .member_type = gt.die_type.member_parent->member_head }, |
3140 | 0 | MEMBER_TYPE }; |
3141 | 0 | display_variable_type (generic_mt, nb_tab + 1); |
3142 | 0 | PRINT_RBRACE (nb_tab); |
3143 | 0 | } |
3144 | 0 | } |
3145 | 0 | break; |
3146 | 0 | case MEMBER_TYPE: |
3147 | 0 | { |
3148 | 0 | PRINT_SPACE (nb_tab + 1); |
3149 | 0 | display_member_type (*gt.die_type.member_type); |
3150 | 0 | display_variable_type (gt.die_type.member_type->ptr_type, nb_tab + 2); |
3151 | 0 | if (gt.die_type.member_type->next != NULL) |
3152 | 0 | { |
3153 | 0 | generic_type generic_mt |
3154 | 0 | = { { .member_type = gt.die_type.member_type->next }, |
3155 | 0 | MEMBER_TYPE }; |
3156 | 0 | display_variable_type (generic_mt, nb_tab); |
3157 | 0 | } |
3158 | 0 | } |
3159 | 0 | break; |
3160 | 0 | case TYPE_PTR: |
3161 | 0 | PRINT_SPACE (nb_tab); |
3162 | 0 | display_type_ptr (*gt.die_type.type_ptr); |
3163 | 0 | display_variable_type (gt.die_type.type_ptr->ptr_type, nb_tab + 1); |
3164 | 0 | break; |
3165 | 0 | case TYPE_REF: |
3166 | 0 | PRINT_SPACE (nb_tab); |
3167 | 0 | display_type_ref (*gt.die_type.type_ref); |
3168 | 0 | display_variable_type (gt.die_type.type_ref->ptr_type, nb_tab + 1); |
3169 | 0 | break; |
3170 | 0 | case VARIABLE_TYPE: |
3171 | 0 | if (gt.die_type.variable_type->is_specification) |
3172 | 0 | printf ("Incomplete, non-defining or separate declaration:\n"); |
3173 | 0 | else if (gt.die_type.variable_type->is_abstract_origin) |
3174 | 0 | printf ("Inlined instance:\n"); |
3175 | 0 | else |
3176 | 0 | { |
3177 | 0 | uint64_t origin = gt.die_type.variable_type->location_addr; |
3178 | 0 | uint64_t end = origin + gt.die_type.variable_type->total_size; |
3179 | 0 | printf ("%s @ 0x%08" PRIx64 " 0x%08" PRIx64 "\n", gt.die_type.variable_type->name, |
3180 | 0 | origin, end); |
3181 | 0 | } |
3182 | 0 | display_variable_type (gt.die_type.variable_type->ptr_type, nb_tab + 1); |
3183 | 0 | break; |
3184 | 0 | } |
3185 | 0 | } |
3186 | | |
3187 | | static variable_type * |
3188 | | get_or_create_variable_type (uint64_t die_offset) |
3189 | 0 | { |
3190 | 0 | if (variable_type_list.tail == NULL |
3191 | 0 | || variable_type_list.tail->die_offset != die_offset) |
3192 | 0 | { |
3193 | 0 | generic_type gt = { { .base_type = NULL }, NO_TYPE }; |
3194 | 0 | variable_type *ret = xmalloc (sizeof (*ret)); |
3195 | 0 | ret->field_type = VARIABLE_TYPE; |
3196 | 0 | ret->die_offset = die_offset; |
3197 | 0 | ret->ptr_die_offset = 0; |
3198 | 0 | ret->location_addr = 0; |
3199 | 0 | ret->total_size = 0; |
3200 | 0 | ret->has_location_addr = false; |
3201 | 0 | ret->is_specification = false; |
3202 | 0 | ret->is_abstract_origin = false; |
3203 | 0 | ret->name = NULL; |
3204 | 0 | ret->ptr_type = gt; |
3205 | 0 | ret->next = NULL; |
3206 | 0 | if (variable_type_list.head == NULL) |
3207 | 0 | { |
3208 | 0 | variable_type_list.head = ret; |
3209 | 0 | variable_type_list.tail = ret; |
3210 | 0 | } |
3211 | 0 | else |
3212 | 0 | { |
3213 | 0 | variable_type_list.tail->next = ret; |
3214 | 0 | variable_type_list.tail = ret; |
3215 | 0 | } |
3216 | 0 | } |
3217 | 0 | return variable_type_list.tail; |
3218 | 0 | } |
3219 | | |
3220 | | static void |
3221 | | insert_element_in_list (enum dwarf_tag dw_tag, |
3222 | | enum dwarf_attribute dw_attr, |
3223 | | uint64_t die_offset, |
3224 | | const uint64_t *uvalue, |
3225 | | const int64_t *svalue, |
3226 | | const char *data, |
3227 | | bool is_union) |
3228 | 0 | { |
3229 | 0 | switch (dw_tag) |
3230 | 0 | { |
3231 | 0 | case DW_TAG_base_type: |
3232 | 0 | { |
3233 | 0 | base_type *bt = get_or_create_base_type (die_offset); |
3234 | 0 | if (dw_attr == DW_AT_byte_size) |
3235 | 0 | { |
3236 | 0 | assert (uvalue != NULL || svalue != NULL); |
3237 | 0 | if (uvalue != NULL) |
3238 | 0 | { |
3239 | 0 | bt->size.usize = *uvalue; |
3240 | 0 | bt->size_type = UNSIGNED_S; |
3241 | 0 | } |
3242 | 0 | else |
3243 | 0 | { |
3244 | 0 | bt->size.ssize = *svalue; |
3245 | 0 | bt->size_type = SIGNED_S; |
3246 | 0 | } |
3247 | 0 | } |
3248 | 0 | else if (dw_attr == DW_AT_name) |
3249 | 0 | { |
3250 | 0 | assert (uvalue != NULL || data != NULL); |
3251 | 0 | if (data != NULL) |
3252 | 0 | bt->name = (const char *) data; |
3253 | 0 | else if (uvalue != NULL) |
3254 | 0 | bt->name = (const char *) fetch_indirect_string (*uvalue); |
3255 | 0 | } |
3256 | 0 | } |
3257 | 0 | break; |
3258 | 0 | case DW_TAG_typedef: |
3259 | 0 | { |
3260 | 0 | type_def *td = get_or_create_type_def (die_offset); |
3261 | 0 | if (dw_attr == DW_AT_type) |
3262 | 0 | { |
3263 | 0 | assert (uvalue != NULL); |
3264 | 0 | td->ptr_die_offset = *uvalue; |
3265 | 0 | } |
3266 | 0 | else if (dw_attr == DW_AT_name) |
3267 | 0 | { |
3268 | 0 | assert (uvalue != NULL || data != NULL); |
3269 | 0 | if (data != NULL) |
3270 | 0 | td->name = (const char *) data; |
3271 | 0 | else if (uvalue != NULL) |
3272 | 0 | td->name = (const char *) fetch_indirect_string (*uvalue); |
3273 | 0 | } |
3274 | 0 | } |
3275 | 0 | break; |
3276 | 0 | case DW_TAG_enumerator: |
3277 | 0 | { |
3278 | 0 | enum_constant *ec = get_or_create_enum_constant (enum_type_list.tail, |
3279 | 0 | die_offset); |
3280 | 0 | if (dw_attr == DW_AT_name) |
3281 | 0 | { |
3282 | 0 | assert (data != NULL || uvalue != NULL); |
3283 | 0 | if (data != NULL) |
3284 | 0 | ec->name = (const char *) data; |
3285 | 0 | else if (uvalue != NULL) |
3286 | 0 | ec->name = (const char *) fetch_indirect_string (*uvalue); |
3287 | 0 | } |
3288 | 0 | else if (dw_attr == DW_AT_const_value) |
3289 | 0 | { |
3290 | 0 | assert (uvalue != NULL); |
3291 | 0 | ec->value = *uvalue; |
3292 | 0 | } |
3293 | 0 | } |
3294 | 0 | break; |
3295 | 0 | case DW_TAG_enumeration_type: |
3296 | 0 | { |
3297 | 0 | enum_type *et = get_or_create_enum_type (die_offset); |
3298 | 0 | if (dw_attr == DW_AT_name) |
3299 | 0 | { |
3300 | 0 | assert (uvalue != NULL || data != NULL); |
3301 | 0 | if (data != NULL) |
3302 | 0 | et->name = (const char *) data; |
3303 | 0 | else if (uvalue != NULL) |
3304 | 0 | et->name = (const char *) fetch_indirect_string (*uvalue); |
3305 | 0 | } |
3306 | 0 | else if (dw_attr == DW_AT_byte_size) |
3307 | 0 | { |
3308 | 0 | assert (uvalue != NULL || svalue != NULL); |
3309 | 0 | if (uvalue != NULL) |
3310 | 0 | { |
3311 | 0 | et->size.usize = *uvalue; |
3312 | 0 | et->size_type = UNSIGNED_S; |
3313 | 0 | } |
3314 | 0 | else |
3315 | 0 | { |
3316 | 0 | et->size.ssize = *svalue; |
3317 | 0 | et->size_type = SIGNED_S; |
3318 | 0 | } |
3319 | 0 | } |
3320 | 0 | } |
3321 | 0 | break; |
3322 | 0 | case DW_TAG_subrange_type: |
3323 | 0 | { |
3324 | 0 | subrange_type *st = get_or_create_subrange_type (tab_type_list.tail, |
3325 | 0 | die_offset); |
3326 | 0 | if (dw_attr == DW_AT_upper_bound || dw_attr == DW_AT_count) |
3327 | 0 | { |
3328 | 0 | assert (uvalue != NULL || svalue != NULL); |
3329 | 0 | if (dw_attr == DW_AT_upper_bound) |
3330 | 0 | { |
3331 | 0 | if (uvalue != NULL) |
3332 | 0 | { |
3333 | 0 | st->size.usize = *uvalue + 1; |
3334 | 0 | st->size_type = UNSIGNED_S; |
3335 | 0 | } |
3336 | 0 | else |
3337 | 0 | { |
3338 | 0 | st->size.ssize = *svalue + 1; |
3339 | 0 | st->size_type = SIGNED_S; |
3340 | 0 | } |
3341 | 0 | } |
3342 | 0 | else if (dw_attr == DW_AT_count) |
3343 | 0 | { |
3344 | 0 | if (uvalue != NULL) |
3345 | 0 | { |
3346 | 0 | st->size.usize = *uvalue; |
3347 | 0 | st->size_type = UNSIGNED_S; |
3348 | 0 | } |
3349 | 0 | else |
3350 | 0 | { |
3351 | 0 | st->size.ssize = *svalue; |
3352 | 0 | st->size_type = SIGNED_S; |
3353 | 0 | } |
3354 | 0 | } |
3355 | 0 | } |
3356 | 0 | } |
3357 | 0 | break; |
3358 | 0 | case DW_TAG_array_type: |
3359 | 0 | { |
3360 | 0 | tab_type *tt = get_or_create_tab_type (die_offset); |
3361 | 0 | if (dw_attr == DW_AT_type) |
3362 | 0 | { |
3363 | 0 | assert (uvalue != NULL); |
3364 | 0 | tt->ptr_die_offset = *uvalue; |
3365 | 0 | } |
3366 | 0 | } |
3367 | 0 | break; |
3368 | 0 | case DW_TAG_member: |
3369 | 0 | { |
3370 | 0 | member_type *mt = NULL; |
3371 | 0 | if (is_union) |
3372 | 0 | mt = get_or_create_member_type (union_type_list.tail, die_offset); |
3373 | 0 | else |
3374 | 0 | mt = get_or_create_member_type (struct_type_list.tail, die_offset); |
3375 | 0 | if (mt == NULL) |
3376 | 0 | break; |
3377 | | |
3378 | 0 | if (dw_attr == DW_AT_name) |
3379 | 0 | { |
3380 | 0 | assert (uvalue != NULL || data != NULL); |
3381 | 0 | if (data != NULL) |
3382 | 0 | mt->name = (const char *) data; |
3383 | 0 | else if (uvalue != NULL) |
3384 | 0 | mt->name = (const char *) fetch_indirect_string (*uvalue); |
3385 | 0 | } |
3386 | 0 | else if (dw_attr == DW_AT_type) |
3387 | 0 | { |
3388 | 0 | assert (uvalue != NULL); |
3389 | 0 | mt->ptr_die_offset = *uvalue; |
3390 | 0 | } |
3391 | 0 | else if (dw_attr == DW_AT_data_member_location) |
3392 | 0 | { |
3393 | 0 | assert (svalue != NULL || uvalue != NULL); |
3394 | 0 | if (svalue != NULL) |
3395 | 0 | mt->member_offset = *svalue; |
3396 | 0 | else if (uvalue != NULL) |
3397 | 0 | mt->member_offset = *uvalue; |
3398 | 0 | } |
3399 | 0 | } |
3400 | 0 | break; |
3401 | 0 | case DW_TAG_structure_type: |
3402 | 0 | case DW_TAG_union_type: |
3403 | 0 | { |
3404 | 0 | member_parent *mp = NULL; |
3405 | 0 | if (dw_tag == DW_TAG_union_type) |
3406 | 0 | mp = get_or_create_member_parent (&union_type_list, die_offset); |
3407 | 0 | else if (dw_tag == DW_TAG_structure_type) |
3408 | 0 | { |
3409 | 0 | mp = get_or_create_member_parent (&struct_type_list, die_offset); |
3410 | 0 | mp->type = STRUCT_TYPE; |
3411 | 0 | } |
3412 | 0 | if (dw_attr == DW_AT_name) |
3413 | 0 | { |
3414 | 0 | assert (uvalue != NULL || data != NULL); |
3415 | 0 | if (data != NULL) |
3416 | 0 | mp->name = (const char *) data; |
3417 | 0 | else if (uvalue != NULL) |
3418 | 0 | mp->name = (const char *) fetch_indirect_string (*uvalue); |
3419 | 0 | } |
3420 | 0 | else if (dw_attr == DW_AT_byte_size) |
3421 | 0 | { |
3422 | 0 | assert (uvalue != NULL || svalue != NULL); |
3423 | 0 | if (uvalue != NULL) |
3424 | 0 | { |
3425 | 0 | mp->size.usize = *uvalue; |
3426 | 0 | mp->size_type = UNSIGNED_S; |
3427 | 0 | } |
3428 | 0 | else |
3429 | 0 | { |
3430 | 0 | mp->size.ssize = *svalue; |
3431 | 0 | mp->size_type = SIGNED_S; |
3432 | 0 | } |
3433 | 0 | } |
3434 | 0 | else if (dw_attr == DW_AT_declaration) |
3435 | 0 | mp->is_declaration = true; |
3436 | 0 | } |
3437 | 0 | break; |
3438 | 0 | case DW_TAG_pointer_type: |
3439 | 0 | { |
3440 | 0 | type_ptr* pt = get_or_create_type_ptr (die_offset); |
3441 | 0 | if (dw_attr == DW_AT_type) |
3442 | 0 | { |
3443 | 0 | assert (uvalue != NULL); |
3444 | 0 | pt->ptr_die_offset = *uvalue; |
3445 | 0 | } |
3446 | 0 | if (dw_attr == DW_AT_byte_size) |
3447 | 0 | { |
3448 | 0 | assert (uvalue != NULL || svalue != NULL); |
3449 | 0 | if (uvalue != NULL) |
3450 | 0 | { |
3451 | 0 | pt->size.usize = *uvalue; |
3452 | 0 | pt->size_type = UNSIGNED_S; |
3453 | 0 | } |
3454 | 0 | else |
3455 | 0 | { |
3456 | 0 | pt->size.ssize = *svalue; |
3457 | 0 | pt->size_type = SIGNED_S; |
3458 | 0 | } |
3459 | 0 | } |
3460 | 0 | } |
3461 | 0 | break; |
3462 | 0 | case DW_TAG_const_type: |
3463 | 0 | case DW_TAG_volatile_type: |
3464 | 0 | { |
3465 | 0 | type_ref *tr = NULL; |
3466 | 0 | if (dw_tag == DW_TAG_const_type) |
3467 | 0 | { |
3468 | 0 | tr = get_or_create_type_ref (&const_type_list, die_offset); |
3469 | 0 | tr->type = CONST_TYPE; |
3470 | 0 | } |
3471 | 0 | else if (dw_tag == DW_TAG_volatile_type) |
3472 | 0 | { |
3473 | 0 | tr = get_or_create_type_ref (&volatile_type_list, die_offset); |
3474 | 0 | tr->type = VOLATILE_TYPE; |
3475 | 0 | } |
3476 | 0 | if (dw_attr == DW_AT_type) |
3477 | 0 | { |
3478 | 0 | assert (uvalue != NULL); |
3479 | 0 | tr->ptr_die_offset = *uvalue; |
3480 | 0 | } |
3481 | 0 | } |
3482 | 0 | break; |
3483 | 0 | case DW_TAG_variable: |
3484 | 0 | { |
3485 | 0 | variable_type *vt = get_or_create_variable_type (die_offset); |
3486 | 0 | if (dw_attr == DW_AT_name) |
3487 | 0 | { |
3488 | 0 | assert (uvalue != NULL || data != NULL); |
3489 | 0 | if (data != NULL) |
3490 | 0 | vt->name = (const char *) data; |
3491 | 0 | else if (uvalue != NULL) |
3492 | 0 | vt->name = (const char *) fetch_indirect_string (*uvalue); |
3493 | 0 | } |
3494 | 0 | else if (dw_attr == DW_AT_type) |
3495 | 0 | { |
3496 | 0 | assert (uvalue != NULL); |
3497 | 0 | if (!vt->is_specification && !vt->is_abstract_origin) |
3498 | 0 | vt->ptr_die_offset = *uvalue; |
3499 | 0 | } |
3500 | 0 | else if (dw_attr == DW_AT_specification) |
3501 | 0 | { |
3502 | 0 | assert (uvalue != NULL); |
3503 | 0 | if (!vt->is_abstract_origin) |
3504 | 0 | { |
3505 | 0 | vt->ptr_die_offset = *uvalue; |
3506 | 0 | vt->is_specification = true; |
3507 | 0 | } |
3508 | 0 | } |
3509 | 0 | else if (dw_attr == DW_AT_abstract_origin) |
3510 | 0 | { |
3511 | 0 | assert (uvalue != NULL); |
3512 | 0 | if (!vt->is_specification) |
3513 | 0 | { |
3514 | 0 | vt->ptr_die_offset = *uvalue; |
3515 | 0 | vt->is_abstract_origin = true; |
3516 | 0 | } |
3517 | 0 | } |
3518 | 0 | } |
3519 | 0 | break; |
3520 | 0 | default: |
3521 | 0 | break; |
3522 | 0 | } |
3523 | 0 | } |
3524 | | |
3525 | | static unsigned char * |
3526 | | read_and_display_attr_value (unsigned long attribute, |
3527 | | unsigned long form, |
3528 | | int64_t implicit_const, |
3529 | | unsigned char *start, |
3530 | | unsigned char *data, |
3531 | | unsigned char *end, |
3532 | | uint64_t cu_offset, |
3533 | | uint64_t pointer_size, |
3534 | | uint64_t offset_size, |
3535 | | int dwarf_version, |
3536 | | debug_info *debug_info_p, |
3537 | | int do_loc, |
3538 | | struct dwarf_section *section, |
3539 | | struct cu_tu_set *this_set, |
3540 | | char delimiter, |
3541 | | int level, |
3542 | | bool do_var_map, |
3543 | | int die_tag, |
3544 | | unsigned long die_offset, |
3545 | | bool is_union) |
3546 | 13.9k | { |
3547 | 13.9k | int64_t svalue; |
3548 | 13.9k | uint64_t uvalue = 0; |
3549 | 13.9k | uint64_t uvalue_hi = 0; |
3550 | 13.9k | unsigned char *block_start = NULL; |
3551 | 13.9k | unsigned char *orig_data = data; |
3552 | | |
3553 | 13.9k | if (data > end || (data == end && form != DW_FORM_flag_present)) |
3554 | 132 | { |
3555 | 132 | warn (_("Corrupt attribute\n")); |
3556 | 132 | return data; |
3557 | 132 | } |
3558 | | |
3559 | 13.8k | if (do_wide && ! do_loc) |
3560 | 0 | { |
3561 | | /* PR 26847: Display the name of the form. */ |
3562 | 0 | const char * name = get_FORM_name (form); |
3563 | | |
3564 | | /* For convenience we skip the DW_FORM_ prefix to the name. */ |
3565 | 0 | if (name[0] == 'D') |
3566 | 0 | name += 8; /* strlen ("DW_FORM_") */ |
3567 | 0 | printf ("%c(%s)", delimiter, name); |
3568 | 0 | } |
3569 | | |
3570 | 13.8k | switch (form) |
3571 | 13.8k | { |
3572 | 8 | case DW_FORM_ref_addr: |
3573 | 8 | if (dwarf_version == 2) |
3574 | 8 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
3575 | 8 | else if (dwarf_version > 2) |
3576 | 8 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
3577 | 0 | else |
3578 | 0 | error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); |
3579 | 8 | break; |
3580 | | |
3581 | 1.29k | case DW_FORM_addr: |
3582 | 1.29k | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
3583 | 1.29k | break; |
3584 | | |
3585 | 1.29k | case DW_FORM_strp_sup: |
3586 | 2.63k | case DW_FORM_strp: |
3587 | 2.65k | case DW_FORM_line_strp: |
3588 | 3.31k | case DW_FORM_sec_offset: |
3589 | 3.31k | case DW_FORM_GNU_ref_alt: |
3590 | 3.31k | case DW_FORM_GNU_strp_alt: |
3591 | 3.31k | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
3592 | 3.31k | break; |
3593 | | |
3594 | 3.31k | case DW_FORM_flag_present: |
3595 | 1.67k | uvalue = 1; |
3596 | 1.67k | break; |
3597 | | |
3598 | 24 | case DW_FORM_ref1: |
3599 | 26 | case DW_FORM_flag: |
3600 | 3.36k | case DW_FORM_data1: |
3601 | 3.46k | case DW_FORM_strx1: |
3602 | 3.47k | case DW_FORM_addrx1: |
3603 | 3.47k | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
3604 | 3.47k | break; |
3605 | | |
3606 | 3.47k | case DW_FORM_ref2: |
3607 | 613 | case DW_FORM_data2: |
3608 | 613 | case DW_FORM_strx2: |
3609 | 614 | case DW_FORM_addrx2: |
3610 | 614 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
3611 | 614 | break; |
3612 | | |
3613 | 614 | case DW_FORM_strx3: |
3614 | 20 | case DW_FORM_addrx3: |
3615 | 20 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); |
3616 | 20 | break; |
3617 | | |
3618 | 20 | case DW_FORM_ref_sup4: |
3619 | 1.49k | case DW_FORM_ref4: |
3620 | 1.98k | case DW_FORM_data4: |
3621 | 1.99k | case DW_FORM_strx4: |
3622 | 1.99k | case DW_FORM_addrx4: |
3623 | 1.99k | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
3624 | 1.99k | break; |
3625 | | |
3626 | 1.99k | case DW_FORM_ref_sup8: |
3627 | 16 | case DW_FORM_ref8: |
3628 | 157 | case DW_FORM_data8: |
3629 | 161 | case DW_FORM_ref_sig8: |
3630 | 161 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
3631 | 161 | break; |
3632 | | |
3633 | 161 | case DW_FORM_data16: |
3634 | 12 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
3635 | 12 | SAFE_BYTE_GET_AND_INC (uvalue_hi, data, 8, end); |
3636 | 12 | if (byte_get != byte_get_little_endian) |
3637 | 0 | { |
3638 | 0 | uint64_t utmp = uvalue; |
3639 | 0 | uvalue = uvalue_hi; |
3640 | 0 | uvalue_hi = utmp; |
3641 | 0 | } |
3642 | 12 | break; |
3643 | | |
3644 | 8 | case DW_FORM_sdata: |
3645 | 8 | READ_SLEB (svalue, data, end); |
3646 | 8 | uvalue = svalue; |
3647 | 8 | break; |
3648 | | |
3649 | 0 | case DW_FORM_GNU_str_index: |
3650 | 3 | case DW_FORM_strx: |
3651 | 8 | case DW_FORM_ref_udata: |
3652 | 20 | case DW_FORM_udata: |
3653 | 20 | case DW_FORM_GNU_addr_index: |
3654 | 125 | case DW_FORM_addrx: |
3655 | 152 | case DW_FORM_loclistx: |
3656 | 180 | case DW_FORM_rnglistx: |
3657 | 180 | READ_ULEB (uvalue, data, end); |
3658 | 180 | break; |
3659 | | |
3660 | 12 | case DW_FORM_indirect: |
3661 | 12 | READ_ULEB (form, data, end); |
3662 | 12 | if (!do_loc) |
3663 | 6 | printf ("%c%s", delimiter, get_FORM_name (form)); |
3664 | 12 | if (form == DW_FORM_implicit_const) |
3665 | 0 | READ_SLEB (implicit_const, data, end); |
3666 | 12 | return read_and_display_attr_value (attribute, form, implicit_const, |
3667 | 12 | start, data, end, |
3668 | 12 | cu_offset, pointer_size, |
3669 | 12 | offset_size, dwarf_version, |
3670 | 12 | debug_info_p, do_loc, |
3671 | 12 | section, this_set, delimiter, level, |
3672 | 12 | do_var_map, die_tag, die_offset, |
3673 | 12 | is_union); |
3674 | | |
3675 | 0 | case DW_FORM_implicit_const: |
3676 | 0 | uvalue = implicit_const; |
3677 | 0 | break; |
3678 | | |
3679 | 1.05k | default: |
3680 | 1.05k | break; |
3681 | 13.8k | } |
3682 | | |
3683 | 13.8k | switch (form) |
3684 | 13.8k | { |
3685 | 8 | case DW_FORM_ref_addr: |
3686 | 8 | if (!do_loc) |
3687 | 5 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue); |
3688 | 8 | if (do_var_map) |
3689 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3690 | 0 | &uvalue, NULL, NULL, is_union); |
3691 | 8 | break; |
3692 | | |
3693 | 0 | case DW_FORM_GNU_ref_alt: |
3694 | 0 | if (!do_loc) |
3695 | 0 | { |
3696 | 0 | if (do_wide) |
3697 | | /* We have already printed the form name. */ |
3698 | 0 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue); |
3699 | 0 | else |
3700 | 0 | printf ("%c<alt %#" PRIx64 ">", delimiter, uvalue); |
3701 | 0 | } |
3702 | 0 | if (do_var_map) |
3703 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3704 | 0 | &uvalue, NULL, NULL, is_union); |
3705 | | /* FIXME: Follow the reference... */ |
3706 | 0 | break; |
3707 | | |
3708 | 24 | case DW_FORM_ref1: |
3709 | 33 | case DW_FORM_ref2: |
3710 | 1.53k | case DW_FORM_ref4: |
3711 | 1.53k | case DW_FORM_ref_sup4: |
3712 | 1.53k | case DW_FORM_ref_udata: |
3713 | 1.53k | { |
3714 | 1.53k | uint64_t utmp = uvalue + cu_offset; |
3715 | 1.53k | if (!do_loc) |
3716 | 748 | printf ("%c<%#" PRIx64 ">", delimiter, utmp); |
3717 | 1.53k | if (do_var_map) |
3718 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3719 | 0 | &utmp, NULL, NULL, is_union); |
3720 | 1.53k | } |
3721 | 1.53k | break; |
3722 | | |
3723 | 490 | case DW_FORM_data4: |
3724 | 1.78k | case DW_FORM_addr: |
3725 | 2.44k | case DW_FORM_sec_offset: |
3726 | 2.44k | if (!do_loc) |
3727 | 1.26k | printf ("%c%#" PRIx64, delimiter, uvalue); |
3728 | 2.44k | if (do_var_map) |
3729 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3730 | 0 | &uvalue, NULL, NULL, is_union); |
3731 | 2.44k | break; |
3732 | | |
3733 | 1.67k | case DW_FORM_flag_present: |
3734 | 1.67k | case DW_FORM_flag: |
3735 | 5.01k | case DW_FORM_data1: |
3736 | 5.61k | case DW_FORM_data2: |
3737 | 5.62k | case DW_FORM_sdata: |
3738 | 5.62k | if (!do_loc) |
3739 | 2.74k | printf ("%c%" PRId64, delimiter, uvalue); |
3740 | 5.62k | if (do_var_map) |
3741 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3742 | 0 | &uvalue, NULL, NULL, is_union); |
3743 | 5.62k | break; |
3744 | | |
3745 | 12 | case DW_FORM_udata: |
3746 | 12 | if (!do_loc) |
3747 | 6 | printf ("%c%" PRIu64, delimiter, uvalue); |
3748 | 12 | if (do_var_map) |
3749 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3750 | 0 | &uvalue, NULL, NULL, is_union); |
3751 | 12 | break; |
3752 | | |
3753 | 0 | case DW_FORM_implicit_const: |
3754 | 0 | if (!do_loc) |
3755 | 0 | printf ("%c%" PRId64, delimiter, implicit_const); |
3756 | 0 | if (do_var_map) |
3757 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3758 | 0 | NULL, &implicit_const, NULL, is_union); |
3759 | 0 | break; |
3760 | | |
3761 | 16 | case DW_FORM_ref_sup8: |
3762 | 16 | case DW_FORM_ref8: |
3763 | 157 | case DW_FORM_data8: |
3764 | 157 | if (!do_loc || do_var_map) |
3765 | 68 | { |
3766 | 68 | uint64_t utmp = uvalue; |
3767 | 68 | if (form == DW_FORM_ref8) |
3768 | 0 | utmp += cu_offset; |
3769 | 68 | if (do_var_map) |
3770 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3771 | 0 | &utmp, NULL, NULL, is_union); |
3772 | 68 | else |
3773 | 68 | printf ("%c%#" PRIx64, delimiter, utmp); |
3774 | 68 | } |
3775 | 157 | break; |
3776 | | |
3777 | 12 | case DW_FORM_data16: |
3778 | 12 | if (!do_loc) |
3779 | 6 | { |
3780 | 6 | if (uvalue_hi == 0) |
3781 | 1 | printf (" %#" PRIx64, uvalue); |
3782 | 5 | else |
3783 | 5 | printf (" %#" PRIx64 "%016" PRIx64, uvalue_hi, uvalue); |
3784 | 6 | } |
3785 | 12 | if (do_var_map) |
3786 | 0 | { |
3787 | 0 | if (uvalue_hi == 0) |
3788 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3789 | 0 | &uvalue, NULL, NULL, is_union); |
3790 | 0 | else |
3791 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3792 | 0 | &uvalue_hi, NULL, NULL, is_union); |
3793 | 0 | } |
3794 | 12 | break; |
3795 | | |
3796 | 252 | case DW_FORM_string: |
3797 | 252 | if (!do_loc) |
3798 | 115 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
3799 | 252 | if (do_var_map) |
3800 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3801 | 0 | NULL, NULL, (const char *) data, |
3802 | 0 | is_union); |
3803 | 252 | data += strnlen ((char *) data, end - data); |
3804 | 252 | if (data < end) |
3805 | 249 | data++; |
3806 | 252 | break; |
3807 | | |
3808 | 3 | case DW_FORM_block: |
3809 | 431 | case DW_FORM_exprloc: |
3810 | 431 | READ_ULEB (uvalue, data, end); |
3811 | 496 | do_block: |
3812 | 496 | block_start = data; |
3813 | 496 | if (block_start >= end) |
3814 | 0 | { |
3815 | 0 | warn (_("Block ends prematurely\n")); |
3816 | 0 | uvalue = 0; |
3817 | 0 | block_start = end; |
3818 | 0 | } |
3819 | | |
3820 | 496 | uvalue = check_uvalue (block_start, uvalue, end); |
3821 | | |
3822 | 496 | data = block_start + uvalue; |
3823 | 496 | if (!do_loc) |
3824 | 238 | { |
3825 | 238 | unsigned char op; |
3826 | | |
3827 | 238 | SAFE_BYTE_GET (op, block_start, sizeof (op), end); |
3828 | 238 | if (op != DW_OP_addrx) |
3829 | 238 | data = display_block (block_start, uvalue, end, delimiter); |
3830 | 238 | } |
3831 | 496 | break; |
3832 | | |
3833 | 496 | case DW_FORM_block1: |
3834 | 13 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
3835 | 13 | goto do_block; |
3836 | | |
3837 | 48 | case DW_FORM_block2: |
3838 | 48 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
3839 | 48 | goto do_block; |
3840 | | |
3841 | 48 | case DW_FORM_block4: |
3842 | 4 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
3843 | 4 | goto do_block; |
3844 | | |
3845 | 2.63k | case DW_FORM_strp: |
3846 | 2.63k | if (!do_loc) |
3847 | 1.31k | { |
3848 | 1.31k | if (do_wide) |
3849 | | /* We have already displayed the form name. */ |
3850 | 0 | printf (_("%c(offset: %#" PRIx64 "): %s"), |
3851 | 0 | delimiter, uvalue, fetch_indirect_string (uvalue)); |
3852 | 1.31k | else |
3853 | 1.31k | printf (_("%c(indirect string, offset: %#" PRIx64 "): %s"), |
3854 | 1.31k | delimiter, uvalue, fetch_indirect_string (uvalue)); |
3855 | 1.31k | } |
3856 | 2.63k | if (do_var_map) |
3857 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3858 | 0 | NULL, NULL, (const char *) |
3859 | 0 | fetch_indirect_string (uvalue), is_union); |
3860 | 2.63k | break; |
3861 | | |
3862 | 23 | case DW_FORM_line_strp: |
3863 | 23 | if (!do_loc) |
3864 | 12 | { |
3865 | 12 | if (do_wide) |
3866 | | /* We have already displayed the form name. */ |
3867 | 0 | printf (_("%c(offset: %#" PRIx64 "): %s"), |
3868 | 0 | delimiter, uvalue, fetch_indirect_line_string (uvalue)); |
3869 | 12 | else |
3870 | 12 | printf (_("%c(indirect line string, offset: %#" PRIx64 "): %s"), |
3871 | 12 | delimiter, uvalue, fetch_indirect_line_string (uvalue)); |
3872 | 12 | } |
3873 | 23 | if (do_var_map) |
3874 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3875 | 0 | NULL, NULL, (const char *) |
3876 | 0 | fetch_indirect_line_string (uvalue), is_union); |
3877 | 23 | break; |
3878 | | |
3879 | 0 | case DW_FORM_GNU_str_index: |
3880 | 3 | case DW_FORM_strx: |
3881 | 103 | case DW_FORM_strx1: |
3882 | 103 | case DW_FORM_strx2: |
3883 | 116 | case DW_FORM_strx3: |
3884 | 119 | case DW_FORM_strx4: |
3885 | 119 | if (!do_loc) |
3886 | 63 | { |
3887 | 63 | const char *suffix = section ? strrchr (section->name, '.') : NULL; |
3888 | 63 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
3889 | 63 | const char *strng; |
3890 | | |
3891 | 63 | strng = fetch_indexed_string (uvalue, this_set, offset_size, dwo, |
3892 | 63 | debug_info_p ? debug_info_p->str_offsets_base : 0); |
3893 | 63 | if (do_wide) |
3894 | | /* We have already displayed the form name. */ |
3895 | 0 | printf (_("%c(offset: %#" PRIx64 "): %s"), |
3896 | 0 | delimiter, uvalue, strng); |
3897 | 63 | else |
3898 | 63 | printf (_("%c(indexed string: %#" PRIx64 "): %s"), |
3899 | 63 | delimiter, uvalue, strng); |
3900 | 63 | if (do_var_map) |
3901 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3902 | 0 | NULL, NULL, strng, is_union); |
3903 | 63 | } |
3904 | 119 | break; |
3905 | | |
3906 | 0 | case DW_FORM_GNU_strp_alt: |
3907 | 0 | if (!do_loc) |
3908 | 0 | { |
3909 | 0 | if (do_wide) |
3910 | | /* We have already displayed the form name. */ |
3911 | 0 | printf (_("%c(offset: %#" PRIx64 ") %s"), |
3912 | 0 | delimiter, uvalue, fetch_alt_indirect_string (uvalue)); |
3913 | 0 | else |
3914 | 0 | printf (_("%c(alt indirect string, offset: %#" PRIx64 ") %s"), |
3915 | 0 | delimiter, uvalue, fetch_alt_indirect_string (uvalue)); |
3916 | 0 | } |
3917 | 0 | if (do_var_map) |
3918 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3919 | 0 | NULL, NULL, fetch_alt_indirect_string (uvalue), |
3920 | 0 | is_union); |
3921 | 0 | break; |
3922 | | |
3923 | 0 | case DW_FORM_indirect: |
3924 | | /* Handled above. */ |
3925 | 0 | break; |
3926 | | |
3927 | 4 | case DW_FORM_ref_sig8: |
3928 | 4 | if (!do_loc) |
3929 | 3 | printf ("%c%s: %#" PRIx64, delimiter, do_wide ? "" : "signature", |
3930 | 3 | uvalue); |
3931 | 4 | if (do_var_map) |
3932 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
3933 | 0 | &uvalue, NULL, NULL, is_union); |
3934 | 4 | break; |
3935 | | |
3936 | 0 | case DW_FORM_GNU_addr_index: |
3937 | 105 | case DW_FORM_addrx: |
3938 | 114 | case DW_FORM_addrx1: |
3939 | 115 | case DW_FORM_addrx2: |
3940 | 122 | case DW_FORM_addrx3: |
3941 | 129 | case DW_FORM_addrx4: |
3942 | 156 | case DW_FORM_loclistx: |
3943 | 184 | case DW_FORM_rnglistx: |
3944 | 184 | if (!do_loc) |
3945 | 94 | { |
3946 | 94 | uint64_t base, idx; |
3947 | 94 | const char *suffix = strrchr (section->name, '.'); |
3948 | 94 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
3949 | | |
3950 | 94 | if (form == DW_FORM_loclistx) |
3951 | 13 | { |
3952 | 13 | if (debug_info_p == NULL) |
3953 | 11 | idx = -1; |
3954 | 2 | else if (dwo) |
3955 | 0 | { |
3956 | 0 | idx = fetch_indexed_offset (uvalue, loclists_dwo, |
3957 | 0 | debug_info_p->loclists_base, |
3958 | 0 | debug_info_p->offset_size); |
3959 | 0 | if (idx != (uint64_t) -1) |
3960 | 0 | idx += (offset_size == 8) ? 20 : 12; |
3961 | 0 | } |
3962 | 2 | else if (dwarf_version > 4) |
3963 | 2 | { |
3964 | 2 | idx = fetch_indexed_offset (uvalue, loclists, |
3965 | 2 | debug_info_p->loclists_base, |
3966 | 2 | debug_info_p->offset_size); |
3967 | 2 | } |
3968 | 0 | else |
3969 | 0 | { |
3970 | | /* We want to compute: |
3971 | | idx = fetch_indexed_value (uvalue, loclists, |
3972 | | debug_info_p->loclists_base); |
3973 | | idx += debug_info_p->loclists_base; |
3974 | | Fortunately we already have that sum cached in the |
3975 | | loc_offsets array. */ |
3976 | 0 | if (uvalue < debug_info_p->num_loc_offsets) |
3977 | 0 | idx = debug_info_p->loc_offsets [uvalue]; |
3978 | 0 | else |
3979 | 0 | { |
3980 | 0 | warn (_("loc_offset %" PRIu64 " too big\n"), uvalue); |
3981 | 0 | idx = -1; |
3982 | 0 | } |
3983 | 0 | } |
3984 | 13 | } |
3985 | 81 | else if (form == DW_FORM_rnglistx) |
3986 | 17 | { |
3987 | 17 | if (debug_info_p == NULL) |
3988 | 2 | idx = -1; |
3989 | 15 | else |
3990 | 15 | idx = fetch_indexed_offset (uvalue, |
3991 | 15 | dwo ? rnglists_dwo : rnglists, |
3992 | 15 | debug_info_p->rnglists_base, |
3993 | 15 | debug_info_p->offset_size); |
3994 | 17 | } |
3995 | 64 | else |
3996 | 64 | { |
3997 | 64 | if (debug_info_p == NULL) |
3998 | 45 | base = 0; |
3999 | 19 | else if (debug_info_p->addr_base == DEBUG_INFO_UNAVAILABLE) |
4000 | 9 | base = 0; |
4001 | 10 | else |
4002 | 10 | base = debug_info_p->addr_base; |
4003 | | |
4004 | 64 | base += uvalue * pointer_size; |
4005 | 64 | idx = fetch_indexed_addr (base, pointer_size); |
4006 | 64 | } |
4007 | | |
4008 | | /* We have already displayed the form name. */ |
4009 | 94 | if (idx != (uint64_t) -1) |
4010 | 70 | { |
4011 | 70 | printf (_("%c(index: %#" PRIx64 "): %#" PRIx64), |
4012 | 70 | delimiter, uvalue, idx); |
4013 | 70 | if (do_var_map) |
4014 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
4015 | 0 | &uvalue, NULL, NULL, is_union); |
4016 | 70 | } |
4017 | 94 | } |
4018 | 184 | break; |
4019 | | |
4020 | 0 | case DW_FORM_strp_sup: |
4021 | 0 | { |
4022 | 0 | uint64_t utmp = uvalue + cu_offset; |
4023 | 0 | if (!do_loc) |
4024 | 0 | printf ("%c<%#" PRIx64 ">", delimiter, utmp); |
4025 | 0 | if (do_var_map) |
4026 | 0 | insert_element_in_list (die_tag, attribute, die_offset, |
4027 | 0 | &utmp, NULL, NULL, is_union); |
4028 | 0 | } |
4029 | 0 | break; |
4030 | | |
4031 | 310 | default: |
4032 | 310 | warn (_("Unrecognized form: %#lx\n"), form); |
4033 | | /* What to do? Consume a byte maybe? */ |
4034 | 310 | ++data; |
4035 | 310 | break; |
4036 | 13.8k | } |
4037 | | |
4038 | 13.8k | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) |
4039 | 13.8k | && num_debug_info_entries == 0 |
4040 | 6.52k | && debug_info_p != NULL) |
4041 | 6.48k | { |
4042 | 6.48k | switch (attribute) |
4043 | 6.48k | { |
4044 | 0 | case DW_AT_loclists_base: |
4045 | 0 | if (debug_info_p->loclists_base) |
4046 | 0 | warn (_("CU @ %#" PRIx64 " has multiple loclists_base values " |
4047 | 0 | "(%#" PRIx64 " and %#" PRIx64 ")\n"), |
4048 | 0 | debug_info_p->cu_offset, |
4049 | 0 | debug_info_p->loclists_base, uvalue); |
4050 | 0 | svalue = uvalue; |
4051 | 0 | if (svalue < 0) |
4052 | 0 | { |
4053 | 0 | warn (_("CU @ %#" PRIx64 " has has a negative loclists_base " |
4054 | 0 | "value of %#" PRIx64 " - treating as zero\n"), |
4055 | 0 | debug_info_p->cu_offset, svalue); |
4056 | 0 | uvalue = 0; |
4057 | 0 | } |
4058 | 0 | debug_info_p->loclists_base = uvalue; |
4059 | 0 | break; |
4060 | | |
4061 | 2 | case DW_AT_rnglists_base: |
4062 | | /* Assignment to debug_info_p->rnglists_base is now elsewhere. */ |
4063 | 2 | break; |
4064 | | |
4065 | 27 | case DW_AT_str_offsets_base: |
4066 | 27 | if (debug_info_p->str_offsets_base) |
4067 | 0 | warn (_("CU @ %#" PRIx64 " has multiple str_offsets_base values " |
4068 | 0 | "%#" PRIx64 " and %#" PRIx64 ")\n"), |
4069 | 0 | debug_info_p->cu_offset, |
4070 | 0 | debug_info_p->str_offsets_base, uvalue); |
4071 | 27 | svalue = uvalue; |
4072 | 27 | if (svalue < 0) |
4073 | 0 | { |
4074 | 0 | warn (_("CU @ %#" PRIx64 " has has a negative stroffsets_base " |
4075 | 0 | "value of %#" PRIx64 " - treating as zero\n"), |
4076 | 0 | debug_info_p->cu_offset, svalue); |
4077 | 0 | uvalue = 0; |
4078 | 0 | } |
4079 | 27 | debug_info_p->str_offsets_base = uvalue; |
4080 | 27 | break; |
4081 | | |
4082 | 74 | case DW_AT_frame_base: |
4083 | | /* This is crude; the have_frame_base is reset on the next |
4084 | | subprogram, not at the end of the current topmost one. */ |
4085 | 74 | have_frame_base = 1; |
4086 | 74 | frame_base_level = level; |
4087 | | /* Fall through. */ |
4088 | 215 | case DW_AT_location: |
4089 | 215 | case DW_AT_GNU_locviews: |
4090 | 218 | case DW_AT_string_length: |
4091 | 222 | case DW_AT_return_addr: |
4092 | 237 | case DW_AT_data_member_location: |
4093 | 240 | case DW_AT_vtable_elem_location: |
4094 | 240 | case DW_AT_segment: |
4095 | 245 | case DW_AT_static_link: |
4096 | 245 | case DW_AT_use_location: |
4097 | 255 | case DW_AT_call_value: |
4098 | 261 | case DW_AT_GNU_call_site_value: |
4099 | 261 | case DW_AT_call_data_value: |
4100 | 261 | case DW_AT_GNU_call_site_data_value: |
4101 | 261 | case DW_AT_call_target: |
4102 | 265 | case DW_AT_GNU_call_site_target: |
4103 | 265 | case DW_AT_call_target_clobbered: |
4104 | 265 | case DW_AT_GNU_call_site_target_clobbered: |
4105 | 265 | if ((dwarf_version < 4 |
4106 | 0 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
4107 | 265 | || form == DW_FORM_sec_offset |
4108 | 240 | || form == DW_FORM_loclistx) |
4109 | 25 | { |
4110 | | /* Process location list. */ |
4111 | 25 | unsigned int lmax = debug_info_p->max_loc_offsets; |
4112 | 25 | unsigned int num = debug_info_p->num_loc_offsets; |
4113 | | |
4114 | 25 | if (lmax == 0 || num >= lmax) |
4115 | 7 | { |
4116 | 7 | lmax += 1024; |
4117 | 7 | debug_info_p->loc_offsets = (uint64_t *) |
4118 | 7 | xcrealloc (debug_info_p->loc_offsets, |
4119 | 7 | lmax, sizeof (*debug_info_p->loc_offsets)); |
4120 | 7 | debug_info_p->loc_views = (uint64_t *) |
4121 | 7 | xcrealloc (debug_info_p->loc_views, |
4122 | 7 | lmax, sizeof (*debug_info_p->loc_views)); |
4123 | 7 | debug_info_p->have_frame_base = (int *) |
4124 | 7 | xcrealloc (debug_info_p->have_frame_base, |
4125 | 7 | lmax, sizeof (*debug_info_p->have_frame_base)); |
4126 | 7 | debug_info_p->max_loc_offsets = lmax; |
4127 | 7 | } |
4128 | 25 | if (form == DW_FORM_loclistx) |
4129 | 0 | uvalue = fetch_indexed_offset (num, loclists, |
4130 | 0 | debug_info_p->loclists_base, |
4131 | 0 | debug_info_p->offset_size); |
4132 | 25 | else if (this_set != NULL) |
4133 | 0 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
4134 | | |
4135 | 25 | debug_info_p->have_frame_base [num] = have_frame_base; |
4136 | 25 | if (attribute != DW_AT_GNU_locviews) |
4137 | 25 | { |
4138 | | /* Corrupt DWARF info can produce more offsets than views. |
4139 | | See PR 23062 for an example. */ |
4140 | 25 | if (debug_info_p->num_loc_offsets |
4141 | 25 | > debug_info_p->num_loc_views) |
4142 | 0 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); |
4143 | 25 | else |
4144 | 25 | { |
4145 | 25 | debug_info_p->loc_offsets [num] = uvalue; |
4146 | 25 | debug_info_p->num_loc_offsets++; |
4147 | 25 | } |
4148 | 25 | } |
4149 | 0 | else |
4150 | 0 | { |
4151 | 0 | if (debug_info_p->num_loc_views > num) |
4152 | 0 | { |
4153 | 0 | warn (_("The number of views (%u) is greater than the number of locations (%u)\n"), |
4154 | 0 | debug_info_p->num_loc_views, num); |
4155 | 0 | debug_info_p->num_loc_views = num; |
4156 | 0 | } |
4157 | 0 | else |
4158 | 0 | num = debug_info_p->num_loc_views; |
4159 | 0 | if (num > debug_info_p->num_loc_offsets) |
4160 | 0 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); |
4161 | 0 | else |
4162 | 0 | { |
4163 | 0 | debug_info_p->loc_views [num] = uvalue; |
4164 | 0 | debug_info_p->num_loc_views++; |
4165 | 0 | } |
4166 | 0 | } |
4167 | 25 | } |
4168 | 265 | break; |
4169 | | |
4170 | 561 | case DW_AT_low_pc: |
4171 | 561 | if (need_base_address) |
4172 | 229 | { |
4173 | 229 | if (form == DW_FORM_addrx) |
4174 | 12 | uvalue = fetch_indexed_addr (debug_info_p->addr_base |
4175 | 12 | + uvalue * pointer_size, |
4176 | 12 | pointer_size); |
4177 | | |
4178 | 229 | debug_info_p->base_address = uvalue; |
4179 | 229 | } |
4180 | 561 | break; |
4181 | | |
4182 | 0 | case DW_AT_GNU_addr_base: |
4183 | 15 | case DW_AT_addr_base: |
4184 | 15 | debug_info_p->addr_base = uvalue; |
4185 | | /* Retrieved elsewhere so that it is in |
4186 | | place by the time we read low_pc. */ |
4187 | 15 | break; |
4188 | | |
4189 | 0 | case DW_AT_GNU_ranges_base: |
4190 | 0 | debug_info_p->ranges_base = uvalue; |
4191 | 0 | break; |
4192 | | |
4193 | 73 | case DW_AT_ranges: |
4194 | 73 | if ((dwarf_version < 4 |
4195 | 4 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
4196 | 69 | || form == DW_FORM_sec_offset |
4197 | 0 | || form == DW_FORM_rnglistx) |
4198 | 73 | { |
4199 | | /* Process range list. */ |
4200 | 73 | unsigned int lmax = debug_info_p->max_range_lists; |
4201 | 73 | unsigned int num = debug_info_p->num_range_lists; |
4202 | | |
4203 | 73 | if (lmax == 0 || num >= lmax) |
4204 | 35 | { |
4205 | 35 | lmax += 1024; |
4206 | 35 | debug_info_p->range_lists = (uint64_t *) |
4207 | 35 | xcrealloc (debug_info_p->range_lists, |
4208 | 35 | lmax, sizeof (*debug_info_p->range_lists)); |
4209 | 35 | debug_info_p->max_range_lists = lmax; |
4210 | 35 | } |
4211 | | |
4212 | 73 | if (form == DW_FORM_rnglistx) |
4213 | 0 | uvalue = fetch_indexed_offset (uvalue, rnglists, |
4214 | 0 | debug_info_p->rnglists_base, |
4215 | 0 | debug_info_p->offset_size); |
4216 | | |
4217 | 73 | debug_info_p->range_lists [num] = uvalue; |
4218 | 73 | debug_info_p->num_range_lists++; |
4219 | 73 | } |
4220 | 73 | break; |
4221 | | |
4222 | 0 | case DW_AT_GNU_dwo_name: |
4223 | 0 | case DW_AT_dwo_name: |
4224 | 0 | if (need_dwo_info) |
4225 | 0 | switch (form) |
4226 | 0 | { |
4227 | 0 | case DW_FORM_strp: |
4228 | 0 | add_dwo_name (fetch_indirect_string (uvalue), |
4229 | 0 | cu_offset); |
4230 | 0 | break; |
4231 | 0 | case DW_FORM_GNU_strp_alt: |
4232 | 0 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset); |
4233 | 0 | break; |
4234 | 0 | case DW_FORM_GNU_str_index: |
4235 | 0 | case DW_FORM_strx: |
4236 | 0 | case DW_FORM_strx1: |
4237 | 0 | case DW_FORM_strx2: |
4238 | 0 | case DW_FORM_strx3: |
4239 | 0 | case DW_FORM_strx4: |
4240 | 0 | add_dwo_name (fetch_indexed_string (uvalue, this_set, |
4241 | 0 | offset_size, false, |
4242 | 0 | debug_info_p->str_offsets_base), |
4243 | 0 | cu_offset); |
4244 | 0 | break; |
4245 | 0 | case DW_FORM_string: |
4246 | 0 | add_dwo_name ((const char *) orig_data, cu_offset); |
4247 | 0 | break; |
4248 | 0 | default: |
4249 | 0 | warn (_("Unsupported form (%s) for attribute %s\n"), |
4250 | 0 | get_FORM_name (form), get_AT_name (attribute)); |
4251 | 0 | break; |
4252 | 0 | } |
4253 | 0 | break; |
4254 | | |
4255 | 228 | case DW_AT_comp_dir: |
4256 | | /* FIXME: Also extract a build-id in a CU/TU. */ |
4257 | 228 | if (need_dwo_info) |
4258 | 156 | switch (form) |
4259 | 156 | { |
4260 | 132 | case DW_FORM_strp: |
4261 | 132 | add_dwo_dir (fetch_indirect_string (uvalue), cu_offset); |
4262 | 132 | break; |
4263 | 0 | case DW_FORM_GNU_strp_alt: |
4264 | 0 | add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset); |
4265 | 0 | break; |
4266 | 0 | case DW_FORM_line_strp: |
4267 | 0 | add_dwo_dir (fetch_indirect_line_string (uvalue), cu_offset); |
4268 | 0 | break; |
4269 | 0 | case DW_FORM_GNU_str_index: |
4270 | 0 | case DW_FORM_strx: |
4271 | 13 | case DW_FORM_strx1: |
4272 | 13 | case DW_FORM_strx2: |
4273 | 13 | case DW_FORM_strx3: |
4274 | 13 | case DW_FORM_strx4: |
4275 | 13 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false, |
4276 | 13 | debug_info_p->str_offsets_base), |
4277 | 13 | cu_offset); |
4278 | 13 | break; |
4279 | 8 | case DW_FORM_string: |
4280 | 8 | add_dwo_dir ((const char *) orig_data, cu_offset); |
4281 | 8 | break; |
4282 | 3 | default: |
4283 | 3 | warn (_("Unsupported form (%s) for attribute %s\n"), |
4284 | 3 | get_FORM_name (form), get_AT_name (attribute)); |
4285 | 3 | break; |
4286 | 156 | } |
4287 | 228 | break; |
4288 | | |
4289 | 228 | case DW_AT_GNU_dwo_id: |
4290 | 0 | if (need_dwo_info) |
4291 | 0 | switch (form) |
4292 | 0 | { |
4293 | 0 | case DW_FORM_data8: |
4294 | | /* FIXME: Record the length of the ID as well ? */ |
4295 | 0 | add_dwo_id ((const char *) (data - 8), cu_offset); |
4296 | 0 | break; |
4297 | 0 | default: |
4298 | 0 | warn (_("Unsupported form (%s) for attribute %s\n"), |
4299 | 0 | get_FORM_name (form), get_AT_name (attribute)); |
4300 | 0 | break; |
4301 | 0 | } |
4302 | 0 | break; |
4303 | | |
4304 | 5.31k | default: |
4305 | 5.31k | break; |
4306 | 6.48k | } |
4307 | 6.48k | } |
4308 | | |
4309 | 13.8k | if (do_var_map) |
4310 | 0 | { |
4311 | 0 | switch (attribute) |
4312 | 0 | { |
4313 | 0 | case DW_AT_frame_base: |
4314 | 0 | case DW_AT_location: |
4315 | 0 | case DW_AT_loclists_base: |
4316 | 0 | case DW_AT_rnglists_base: |
4317 | 0 | case DW_AT_str_offsets_base: |
4318 | 0 | case DW_AT_string_length: |
4319 | 0 | case DW_AT_return_addr: |
4320 | 0 | case DW_AT_data_member_location: |
4321 | 0 | case DW_AT_vtable_elem_location: |
4322 | 0 | case DW_AT_segment: |
4323 | 0 | case DW_AT_static_link: |
4324 | 0 | case DW_AT_use_location: |
4325 | 0 | case DW_AT_call_value: |
4326 | 0 | case DW_AT_GNU_call_site_value: |
4327 | 0 | case DW_AT_call_data_value: |
4328 | 0 | case DW_AT_GNU_call_site_data_value: |
4329 | 0 | case DW_AT_call_target: |
4330 | 0 | case DW_AT_GNU_call_site_target: |
4331 | 0 | case DW_AT_call_target_clobbered: |
4332 | 0 | case DW_AT_GNU_call_site_target_clobbered: |
4333 | 0 | case DW_AT_allocated: |
4334 | 0 | case DW_AT_associated: |
4335 | 0 | case DW_AT_data_location: |
4336 | 0 | case DW_AT_stride: |
4337 | 0 | case DW_AT_upper_bound: |
4338 | 0 | case DW_AT_lower_bound: |
4339 | 0 | case DW_AT_rank: |
4340 | 0 | if (block_start) |
4341 | 0 | get_location_expression (die_tag, |
4342 | 0 | attribute, |
4343 | 0 | block_start, |
4344 | 0 | pointer_size, |
4345 | 0 | offset_size, |
4346 | 0 | dwarf_version, |
4347 | 0 | die_offset, |
4348 | 0 | uvalue, |
4349 | 0 | cu_offset, |
4350 | 0 | section); |
4351 | 0 | break; |
4352 | 0 | case DW_AT_data_bit_offset: |
4353 | 0 | case DW_AT_byte_size: |
4354 | 0 | case DW_AT_bit_size: |
4355 | 0 | case DW_AT_string_length_byte_size: |
4356 | 0 | case DW_AT_string_length_bit_size: |
4357 | 0 | case DW_AT_bit_stride: |
4358 | 0 | if (form == DW_FORM_exprloc) |
4359 | 0 | get_location_expression (die_tag, |
4360 | 0 | attribute, |
4361 | 0 | block_start, |
4362 | 0 | pointer_size, |
4363 | 0 | offset_size, |
4364 | 0 | dwarf_version, |
4365 | 0 | die_offset, |
4366 | 0 | uvalue, |
4367 | 0 | cu_offset, |
4368 | 0 | section); |
4369 | 0 | break; |
4370 | 0 | default: |
4371 | 0 | break; |
4372 | 0 | } |
4373 | 0 | } |
4374 | | |
4375 | 13.8k | if (do_loc || attribute == 0) |
4376 | 7.03k | return data; |
4377 | | |
4378 | | /* For some attributes we can display further information. */ |
4379 | 6.77k | switch (attribute) |
4380 | 6.77k | { |
4381 | 0 | case DW_AT_language_name: |
4382 | 0 | printf ("\t(%s)", get_AT_language_name (uvalue)); |
4383 | 0 | break; |
4384 | | |
4385 | 0 | case DW_AT_language_version: |
4386 | 0 | printf ("\t(%lu)", (unsigned long) uvalue); |
4387 | 0 | break; |
4388 | | |
4389 | 351 | case DW_AT_type: |
4390 | 351 | if (level >= 0 && level < MAX_CU_NESTING |
4391 | 327 | && uvalue < (size_t) (end - start)) |
4392 | 311 | { |
4393 | 311 | bool is_signed = false; |
4394 | 311 | abbrev_entry *type_abbrev; |
4395 | 311 | unsigned char *type_data; |
4396 | 311 | abbrev_map *map; |
4397 | | |
4398 | 311 | type_abbrev = get_type_abbrev_from_form (form, uvalue, |
4399 | 311 | cu_offset, end, |
4400 | 311 | section, NULL, |
4401 | 311 | &type_data, &map); |
4402 | 311 | if (type_abbrev != NULL) |
4403 | 304 | { |
4404 | 304 | get_type_signedness (type_abbrev, section, type_data, |
4405 | 304 | map ? section->start + map->end : end, |
4406 | 304 | map ? map->start : cu_offset, |
4407 | 304 | pointer_size, offset_size, dwarf_version, |
4408 | 304 | & is_signed, 0); |
4409 | 304 | } |
4410 | 311 | level_type_signed[level] = is_signed; |
4411 | 311 | } |
4412 | 351 | break; |
4413 | | |
4414 | 81 | case DW_AT_inline: |
4415 | 81 | printf ("\t"); |
4416 | 81 | switch (uvalue) |
4417 | 81 | { |
4418 | 9 | case DW_INL_not_inlined: |
4419 | 9 | printf (_("(not inlined)")); |
4420 | 9 | break; |
4421 | 64 | case DW_INL_inlined: |
4422 | 64 | printf (_("(inlined)")); |
4423 | 64 | break; |
4424 | 2 | case DW_INL_declared_not_inlined: |
4425 | 2 | printf (_("(declared as inline but ignored)")); |
4426 | 2 | break; |
4427 | 1 | case DW_INL_declared_inlined: |
4428 | 1 | printf (_("(declared as inline and inlined)")); |
4429 | 1 | break; |
4430 | 5 | default: |
4431 | 5 | printf (_(" (Unknown inline attribute value: %#" PRIx64 ")"), |
4432 | 5 | uvalue); |
4433 | 5 | break; |
4434 | 81 | } |
4435 | 81 | break; |
4436 | | |
4437 | 242 | case DW_AT_language: |
4438 | 242 | printf ("\t("); |
4439 | 242 | display_lang (uvalue); |
4440 | 242 | printf (")"); |
4441 | 242 | break; |
4442 | | |
4443 | 288 | case DW_AT_encoding: |
4444 | 288 | printf ("\t"); |
4445 | 288 | switch (uvalue) |
4446 | 288 | { |
4447 | 15 | case DW_ATE_void: printf ("(void)"); break; |
4448 | 0 | case DW_ATE_address: printf ("(machine address)"); break; |
4449 | 1 | case DW_ATE_boolean: printf ("(boolean)"); break; |
4450 | 1 | case DW_ATE_complex_float: printf ("(complex float)"); break; |
4451 | 4 | case DW_ATE_float: printf ("(float)"); break; |
4452 | 117 | case DW_ATE_signed: printf ("(signed)"); break; |
4453 | 26 | case DW_ATE_signed_char: printf ("(signed char)"); break; |
4454 | 91 | case DW_ATE_unsigned: printf ("(unsigned)"); break; |
4455 | 20 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; |
4456 | | /* DWARF 2.1 values: */ |
4457 | 1 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
4458 | 0 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; |
4459 | | /* DWARF 3 values: */ |
4460 | 0 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; |
4461 | 0 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; |
4462 | 0 | case DW_ATE_edited: printf ("(edited)"); break; |
4463 | 0 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; |
4464 | 0 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; |
4465 | | /* DWARF 4 values: */ |
4466 | 1 | case DW_ATE_UTF: printf ("(unicode string)"); break; |
4467 | | /* DWARF 5 values: */ |
4468 | 1 | case DW_ATE_UCS: printf ("(UCS)"); break; |
4469 | 0 | case DW_ATE_ASCII: printf ("(ASCII)"); break; |
4470 | | |
4471 | | /* HP extensions: */ |
4472 | 0 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; |
4473 | 0 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; |
4474 | 0 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; |
4475 | 0 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; |
4476 | 0 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; |
4477 | 0 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; |
4478 | 0 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; |
4479 | | |
4480 | 10 | default: |
4481 | 10 | if (uvalue >= DW_ATE_lo_user |
4482 | 4 | && uvalue <= DW_ATE_hi_user) |
4483 | 2 | printf (_("(user defined type)")); |
4484 | 8 | else |
4485 | 8 | printf (_("(unknown type)")); |
4486 | 10 | break; |
4487 | 288 | } |
4488 | 288 | break; |
4489 | | |
4490 | 288 | case DW_AT_accessibility: |
4491 | 28 | printf ("\t"); |
4492 | 28 | switch (uvalue) |
4493 | 28 | { |
4494 | 0 | case DW_ACCESS_public: printf ("(public)"); break; |
4495 | 0 | case DW_ACCESS_protected: printf ("(protected)"); break; |
4496 | 0 | case DW_ACCESS_private: printf ("(private)"); break; |
4497 | 28 | default: |
4498 | 28 | printf (_("(unknown accessibility)")); |
4499 | 28 | break; |
4500 | 28 | } |
4501 | 28 | break; |
4502 | | |
4503 | 28 | case DW_AT_visibility: |
4504 | 1 | printf ("\t"); |
4505 | 1 | switch (uvalue) |
4506 | 1 | { |
4507 | 0 | case DW_VIS_local: printf ("(local)"); break; |
4508 | 0 | case DW_VIS_exported: printf ("(exported)"); break; |
4509 | 0 | case DW_VIS_qualified: printf ("(qualified)"); break; |
4510 | 1 | default: printf (_("(unknown visibility)")); break; |
4511 | 1 | } |
4512 | 1 | break; |
4513 | | |
4514 | 2 | case DW_AT_endianity: |
4515 | 2 | printf ("\t"); |
4516 | 2 | switch (uvalue) |
4517 | 2 | { |
4518 | 2 | case DW_END_default: printf ("(default)"); break; |
4519 | 0 | case DW_END_big: printf ("(big)"); break; |
4520 | 0 | case DW_END_little: printf ("(little)"); break; |
4521 | 0 | default: |
4522 | 0 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) |
4523 | 0 | printf (_("(user specified)")); |
4524 | 0 | else |
4525 | 0 | printf (_("(unknown endianity)")); |
4526 | 0 | break; |
4527 | 2 | } |
4528 | 2 | break; |
4529 | | |
4530 | 2 | case DW_AT_virtuality: |
4531 | 0 | printf ("\t"); |
4532 | 0 | switch (uvalue) |
4533 | 0 | { |
4534 | 0 | case DW_VIRTUALITY_none: printf ("(none)"); break; |
4535 | 0 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; |
4536 | 0 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; |
4537 | 0 | default: printf (_("(unknown virtuality)")); break; |
4538 | 0 | } |
4539 | 0 | break; |
4540 | | |
4541 | 6 | case DW_AT_identifier_case: |
4542 | 6 | printf ("\t"); |
4543 | 6 | switch (uvalue) |
4544 | 6 | { |
4545 | 6 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; |
4546 | 0 | case DW_ID_up_case: printf ("(up_case)"); break; |
4547 | 0 | case DW_ID_down_case: printf ("(down_case)"); break; |
4548 | 0 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; |
4549 | 0 | default: printf (_("(unknown case)")); break; |
4550 | 6 | } |
4551 | 6 | break; |
4552 | | |
4553 | 6 | case DW_AT_calling_convention: |
4554 | 3 | printf ("\t"); |
4555 | 3 | switch (uvalue) |
4556 | 3 | { |
4557 | 0 | case DW_CC_normal: printf ("(normal)"); break; |
4558 | 0 | case DW_CC_program: printf ("(program)"); break; |
4559 | 0 | case DW_CC_nocall: printf ("(nocall)"); break; |
4560 | 0 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
4561 | 0 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; |
4562 | 0 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; |
4563 | 0 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; |
4564 | 3 | default: |
4565 | 3 | if (uvalue >= DW_CC_lo_user |
4566 | 0 | && uvalue <= DW_CC_hi_user) |
4567 | 0 | printf (_("(user defined)")); |
4568 | 3 | else |
4569 | 3 | printf (_("(unknown convention)")); |
4570 | 3 | } |
4571 | 3 | break; |
4572 | | |
4573 | 3 | case DW_AT_ordering: |
4574 | 0 | printf ("\t"); |
4575 | 0 | switch (uvalue) |
4576 | 0 | { |
4577 | 0 | case 255: |
4578 | 0 | case -1: printf (_("(undefined)")); break; |
4579 | 0 | case 0: printf ("(row major)"); break; |
4580 | 0 | case 1: printf ("(column major)"); break; |
4581 | 0 | } |
4582 | 0 | break; |
4583 | | |
4584 | 0 | case DW_AT_decimal_sign: |
4585 | 0 | printf ("\t"); |
4586 | 0 | switch (uvalue) |
4587 | 0 | { |
4588 | 0 | case DW_DS_unsigned: printf (_("(unsigned)")); break; |
4589 | 0 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; |
4590 | 0 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; |
4591 | 0 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; |
4592 | 0 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; |
4593 | 0 | default: printf (_("(unrecognised)")); break; |
4594 | 0 | } |
4595 | 0 | break; |
4596 | | |
4597 | 0 | case DW_AT_defaulted: |
4598 | 0 | printf ("\t"); |
4599 | 0 | switch (uvalue) |
4600 | 0 | { |
4601 | 0 | case DW_DEFAULTED_no: printf (_("(no)")); break; |
4602 | 0 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; |
4603 | 0 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; |
4604 | 0 | default: printf (_("(unrecognised)")); break; |
4605 | 0 | } |
4606 | 0 | break; |
4607 | | |
4608 | 6 | case DW_AT_discr_list: |
4609 | 6 | printf ("\t"); |
4610 | 6 | display_discr_list (form, uvalue, data, level); |
4611 | 6 | break; |
4612 | | |
4613 | 72 | case DW_AT_frame_base: |
4614 | 72 | have_frame_base = 1; |
4615 | | /* Fall through. */ |
4616 | 211 | case DW_AT_location: |
4617 | 211 | case DW_AT_loclists_base: |
4618 | 213 | case DW_AT_rnglists_base: |
4619 | 237 | case DW_AT_str_offsets_base: |
4620 | 238 | case DW_AT_string_length: |
4621 | 242 | case DW_AT_return_addr: |
4622 | 252 | case DW_AT_data_member_location: |
4623 | 253 | case DW_AT_vtable_elem_location: |
4624 | 253 | case DW_AT_segment: |
4625 | 256 | case DW_AT_static_link: |
4626 | 256 | case DW_AT_use_location: |
4627 | 264 | case DW_AT_call_value: |
4628 | 270 | case DW_AT_GNU_call_site_value: |
4629 | 270 | case DW_AT_call_data_value: |
4630 | 270 | case DW_AT_GNU_call_site_data_value: |
4631 | 270 | case DW_AT_call_target: |
4632 | 277 | case DW_AT_GNU_call_site_target: |
4633 | 277 | case DW_AT_call_target_clobbered: |
4634 | 277 | case DW_AT_GNU_call_site_target_clobbered: |
4635 | 277 | if ((dwarf_version < 4 |
4636 | 0 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
4637 | 277 | || form == DW_FORM_sec_offset |
4638 | 238 | || form == DW_FORM_loclistx) |
4639 | 39 | { |
4640 | 39 | if (attribute != DW_AT_rnglists_base |
4641 | 39 | && attribute != DW_AT_str_offsets_base) |
4642 | 24 | printf (_(" (location list)")); |
4643 | 39 | } |
4644 | | /* Fall through. */ |
4645 | 277 | case DW_AT_allocated: |
4646 | 278 | case DW_AT_associated: |
4647 | 283 | case DW_AT_data_location: |
4648 | 284 | case DW_AT_stride: |
4649 | 318 | case DW_AT_upper_bound: |
4650 | 319 | case DW_AT_lower_bound: |
4651 | 319 | case DW_AT_rank: |
4652 | 319 | if (block_start) |
4653 | 208 | { |
4654 | 208 | int need_frame_base; |
4655 | | |
4656 | 208 | printf ("\t("); |
4657 | 208 | need_frame_base = decode_location_expression (block_start, |
4658 | 208 | pointer_size, |
4659 | 208 | offset_size, |
4660 | 208 | dwarf_version, |
4661 | 208 | uvalue, |
4662 | 208 | cu_offset, section); |
4663 | 208 | printf (")"); |
4664 | 208 | if (need_frame_base && !have_frame_base) |
4665 | 0 | printf (_(" [without DW_AT_frame_base]")); |
4666 | 208 | } |
4667 | 319 | break; |
4668 | | |
4669 | 1 | case DW_AT_data_bit_offset: |
4670 | 288 | case DW_AT_byte_size: |
4671 | 288 | case DW_AT_bit_size: |
4672 | 292 | case DW_AT_string_length_byte_size: |
4673 | 296 | case DW_AT_string_length_bit_size: |
4674 | 309 | case DW_AT_bit_stride: |
4675 | 309 | if (form == DW_FORM_exprloc) |
4676 | 0 | { |
4677 | 0 | printf ("\t("); |
4678 | 0 | (void) decode_location_expression (block_start, pointer_size, |
4679 | 0 | offset_size, dwarf_version, |
4680 | 0 | uvalue, cu_offset, section); |
4681 | 0 | printf (")"); |
4682 | 0 | } |
4683 | 309 | break; |
4684 | | |
4685 | 10 | case DW_AT_import: |
4686 | 10 | { |
4687 | 10 | unsigned long abbrev_number; |
4688 | 10 | abbrev_entry *entry; |
4689 | | |
4690 | 10 | entry = get_type_abbrev_from_form (form, uvalue, cu_offset, end, |
4691 | 10 | section, & abbrev_number, NULL, NULL); |
4692 | 10 | if (entry == NULL) |
4693 | 10 | { |
4694 | 10 | if (form != DW_FORM_GNU_ref_alt) |
4695 | 10 | warn (_("Offset %#" PRIx64 " used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"), |
4696 | 10 | uvalue, |
4697 | 10 | orig_data - section->start); |
4698 | 10 | } |
4699 | 0 | else |
4700 | 0 | { |
4701 | 0 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
4702 | 0 | printf (" (%s)", get_TAG_name (entry->tag)); |
4703 | 0 | printf ("]"); |
4704 | 0 | } |
4705 | 10 | } |
4706 | 10 | break; |
4707 | | |
4708 | 5.12k | default: |
4709 | 5.12k | break; |
4710 | 6.77k | } |
4711 | | |
4712 | 6.77k | return data; |
4713 | 6.77k | } |
4714 | | |
4715 | | static unsigned char * |
4716 | | read_and_display_attr (unsigned long attribute, |
4717 | | unsigned long form, |
4718 | | int64_t implicit_const, |
4719 | | unsigned char *start, |
4720 | | unsigned char *data, |
4721 | | unsigned char *end, |
4722 | | uint64_t cu_offset, |
4723 | | uint64_t pointer_size, |
4724 | | uint64_t offset_size, |
4725 | | int dwarf_version, |
4726 | | debug_info *debug_info_p, |
4727 | | int do_loc, |
4728 | | struct dwarf_section *section, |
4729 | | struct cu_tu_set *this_set, |
4730 | | int level, |
4731 | | bool do_var_map, |
4732 | | int die_tag, |
4733 | | unsigned long die_offset, |
4734 | | bool is_union) |
4735 | 13.7k | { |
4736 | 13.7k | if (!do_loc) |
4737 | 6.84k | printf (" %-18s:", get_AT_name (attribute)); |
4738 | 13.7k | data = read_and_display_attr_value (attribute, form, implicit_const, |
4739 | 13.7k | start, data, end, |
4740 | 13.7k | cu_offset, pointer_size, offset_size, |
4741 | 13.7k | dwarf_version, debug_info_p, |
4742 | 13.7k | do_loc, section, this_set, ' ', level, |
4743 | 13.7k | do_var_map, die_tag, die_offset, |
4744 | 13.7k | is_union); |
4745 | 13.7k | if (!do_loc) |
4746 | 6.84k | printf ("\n"); |
4747 | 13.7k | return data; |
4748 | 13.7k | } |
4749 | | |
4750 | | /* Like load_debug_section, but if the ordinary call fails, and we are |
4751 | | following debug links, then attempt to load the requested section |
4752 | | from one of the separate debug info files. */ |
4753 | | |
4754 | | static bool |
4755 | | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, |
4756 | | void * handle) |
4757 | 5.51k | { |
4758 | 5.51k | if (load_debug_section (sec_enum, handle)) |
4759 | 1.50k | { |
4760 | 1.50k | if (debug_displays[sec_enum].section.filename == NULL) |
4761 | 0 | { |
4762 | | /* See if we can associate a filename with this section. */ |
4763 | 0 | separate_info * i; |
4764 | |
|
4765 | 0 | for (i = first_separate_info; i != NULL; i = i->next) |
4766 | 0 | if (i->handle == handle) |
4767 | 0 | { |
4768 | 0 | debug_displays[sec_enum].section.filename = i->filename; |
4769 | 0 | break; |
4770 | 0 | } |
4771 | 0 | } |
4772 | | |
4773 | 1.50k | return true; |
4774 | 1.50k | } |
4775 | | |
4776 | 4.01k | if (do_follow_links) |
4777 | 725 | { |
4778 | 725 | separate_info * i; |
4779 | | |
4780 | 725 | for (i = first_separate_info; i != NULL; i = i->next) |
4781 | 0 | { |
4782 | 0 | if (load_debug_section (sec_enum, i->handle)) |
4783 | 0 | { |
4784 | 0 | debug_displays[sec_enum].section.filename = i->filename; |
4785 | | |
4786 | | /* FIXME: We should check to see if any of the remaining debug info |
4787 | | files also contain this section, and, umm, do something about it. */ |
4788 | 0 | return true; |
4789 | 0 | } |
4790 | 0 | } |
4791 | 725 | } |
4792 | | |
4793 | 4.01k | return false; |
4794 | 4.01k | } |
4795 | | |
4796 | | static void |
4797 | | introduce (struct dwarf_section * section, bool raw) |
4798 | 7.99k | { |
4799 | 7.99k | if (raw) |
4800 | 355 | { |
4801 | 355 | if (do_follow_links && section->filename) |
4802 | 0 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), |
4803 | 0 | section->name, section->filename); |
4804 | 355 | else |
4805 | 355 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); |
4806 | 355 | } |
4807 | 7.63k | else |
4808 | 7.63k | { |
4809 | 7.63k | if (do_follow_links && section->filename) |
4810 | 0 | printf (_("Contents of the %s section (loaded from %s):\n\n"), |
4811 | 0 | section->name, section->filename); |
4812 | 7.63k | else |
4813 | 7.63k | printf (_("Contents of the %s section:\n\n"), section->name); |
4814 | 7.63k | } |
4815 | 7.99k | } |
4816 | | |
4817 | | /* Free memory allocated for one unit in debug_information. */ |
4818 | | |
4819 | | static void |
4820 | | free_debug_information (debug_info *ent) |
4821 | 1.07k | { |
4822 | 1.07k | if (ent->max_loc_offsets) |
4823 | 7 | { |
4824 | 7 | free (ent->loc_offsets); |
4825 | 7 | free (ent->loc_views); |
4826 | 7 | free (ent->have_frame_base); |
4827 | 7 | } |
4828 | 1.07k | if (ent->max_range_lists) |
4829 | 35 | { |
4830 | 35 | free (ent->range_lists); |
4831 | 35 | } |
4832 | 1.07k | } |
4833 | | |
4834 | | /* For look-ahead in attributes. When you want to scan a DIE for one specific |
4835 | | attribute and ignore the rest. */ |
4836 | | |
4837 | | static unsigned char * |
4838 | | skip_attribute (unsigned long form, |
4839 | | unsigned char * data, |
4840 | | unsigned char * end, |
4841 | | uint64_t pointer_size, |
4842 | | uint64_t offset_size, |
4843 | | int dwarf_version) |
4844 | 582 | { |
4845 | 582 | uint64_t temp; |
4846 | 582 | size_t inc; |
4847 | | |
4848 | 582 | switch (form) |
4849 | 582 | { |
4850 | 2 | case DW_FORM_ref_addr: |
4851 | 2 | inc = dwarf_version == 2 ? pointer_size : offset_size; |
4852 | 2 | break; |
4853 | 42 | case DW_FORM_addr: |
4854 | 42 | inc = pointer_size; |
4855 | 42 | break; |
4856 | 0 | case DW_FORM_strp_sup: |
4857 | 84 | case DW_FORM_strp: |
4858 | 87 | case DW_FORM_line_strp: |
4859 | 153 | case DW_FORM_sec_offset: |
4860 | 153 | case DW_FORM_GNU_ref_alt: |
4861 | 153 | case DW_FORM_GNU_strp_alt: |
4862 | 153 | inc = offset_size; |
4863 | 153 | break; |
4864 | 5 | case DW_FORM_ref1: |
4865 | 5 | case DW_FORM_flag: |
4866 | 23 | case DW_FORM_data1: |
4867 | 93 | case DW_FORM_strx1: |
4868 | 93 | case DW_FORM_addrx1: |
4869 | 93 | inc = 1; |
4870 | 93 | break; |
4871 | 2 | case DW_FORM_ref2: |
4872 | 65 | case DW_FORM_data2: |
4873 | 65 | case DW_FORM_strx2: |
4874 | 65 | case DW_FORM_addrx2: |
4875 | 65 | inc = 2; |
4876 | 65 | break; |
4877 | 10 | case DW_FORM_strx3: |
4878 | 10 | case DW_FORM_addrx3: |
4879 | 10 | inc = 3; |
4880 | 10 | break; |
4881 | 0 | case DW_FORM_ref_sup4: |
4882 | 0 | case DW_FORM_ref4: |
4883 | 65 | case DW_FORM_data4: |
4884 | 65 | case DW_FORM_strx4: |
4885 | 65 | case DW_FORM_addrx4: |
4886 | 65 | inc = 4; |
4887 | 65 | break; |
4888 | 10 | case DW_FORM_ref_sup8: |
4889 | 10 | case DW_FORM_ref8: |
4890 | 14 | case DW_FORM_data8: |
4891 | 14 | case DW_FORM_ref_sig8: |
4892 | 14 | inc = 8; |
4893 | 14 | break; |
4894 | 0 | case DW_FORM_data16: |
4895 | 0 | inc = 16; |
4896 | 0 | break; |
4897 | 5 | case DW_FORM_sdata: |
4898 | 5 | SKIP_SLEB (data, end); |
4899 | 5 | return data; |
4900 | 0 | case DW_FORM_GNU_str_index: |
4901 | 0 | case DW_FORM_strx: |
4902 | 0 | case DW_FORM_ref_udata: |
4903 | 0 | case DW_FORM_udata: |
4904 | 0 | case DW_FORM_GNU_addr_index: |
4905 | 29 | case DW_FORM_addrx: |
4906 | 34 | case DW_FORM_loclistx: |
4907 | 48 | case DW_FORM_rnglistx: |
4908 | 48 | SKIP_ULEB (data, end); |
4909 | 48 | return data; |
4910 | 10 | case DW_FORM_indirect: |
4911 | 20 | while (form == DW_FORM_indirect) |
4912 | 10 | READ_ULEB (form, data, end); |
4913 | 10 | return skip_attribute (form, data, end, pointer_size, offset_size, |
4914 | 10 | dwarf_version); |
4915 | | |
4916 | 10 | case DW_FORM_string: |
4917 | 10 | inc = strnlen ((char *) data, end - data) + 1; |
4918 | 10 | break; |
4919 | 0 | case DW_FORM_block: |
4920 | 0 | case DW_FORM_exprloc: |
4921 | 0 | READ_ULEB (temp, data, end); |
4922 | 0 | inc = temp; |
4923 | 0 | break; |
4924 | 2 | case DW_FORM_block1: |
4925 | 2 | SAFE_BYTE_GET_AND_INC (temp, data, 1, end); |
4926 | 2 | inc = temp; |
4927 | 2 | break; |
4928 | 5 | case DW_FORM_block2: |
4929 | 5 | SAFE_BYTE_GET_AND_INC (temp, data, 2, end); |
4930 | 5 | inc = temp; |
4931 | 5 | break; |
4932 | 2 | case DW_FORM_block4: |
4933 | 2 | SAFE_BYTE_GET_AND_INC (temp, data, 4, end); |
4934 | 2 | inc = temp; |
4935 | 2 | break; |
4936 | 0 | case DW_FORM_implicit_const: |
4937 | 0 | case DW_FORM_flag_present: |
4938 | 0 | return data; |
4939 | 56 | default: |
4940 | 56 | warn (_("Unexpected form in top DIE\n")); |
4941 | 56 | return data; |
4942 | 582 | } |
4943 | 463 | if (inc <= (size_t) (end - data)) |
4944 | 439 | data += inc; |
4945 | 24 | else |
4946 | 24 | data = end; |
4947 | 463 | return data; |
4948 | 582 | } |
4949 | | |
4950 | | static void |
4951 | | read_bases (abbrev_entry * entry, |
4952 | | unsigned char * data, |
4953 | | unsigned char * end, |
4954 | | int64_t pointer_size, |
4955 | | uint64_t offset_size, |
4956 | | int dwarf_version, |
4957 | | debug_info * debug_info_p) |
4958 | 79 | { |
4959 | 79 | abbrev_attr *attr; |
4960 | | |
4961 | 79 | for (attr = entry->first_attr; |
4962 | 678 | attr && attr->attribute; |
4963 | 599 | attr = attr->next) |
4964 | 599 | { |
4965 | 599 | uint64_t uvalue; |
4966 | | |
4967 | 599 | if (attr->attribute == DW_AT_rnglists_base) |
4968 | 0 | { |
4969 | 0 | if (attr->form == DW_FORM_sec_offset) |
4970 | 0 | { |
4971 | 0 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
4972 | 0 | debug_info_p->rnglists_base = uvalue; |
4973 | 0 | } |
4974 | 0 | else |
4975 | 0 | warn (_("Unexpected form of DW_AT_rnglists_base in the top DIE\n")); |
4976 | 0 | } |
4977 | 599 | else if (attr->attribute == DW_AT_addr_base |
4978 | 572 | || attr->attribute == DW_AT_GNU_addr_base) |
4979 | 27 | { |
4980 | 27 | if (attr->form == DW_FORM_sec_offset) |
4981 | 27 | { |
4982 | 27 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
4983 | 27 | debug_info_p->addr_base = uvalue; |
4984 | 27 | } |
4985 | 0 | else |
4986 | 0 | warn (_("Unexpected form of DW_AT_addr_base in the top DIE\n")); |
4987 | 27 | } |
4988 | 572 | else |
4989 | 572 | data = skip_attribute (attr->form, data, end, pointer_size, |
4990 | 572 | offset_size, dwarf_version); |
4991 | 599 | } |
4992 | 79 | } |
4993 | | |
4994 | | /* Process the contents of a .debug_info section. |
4995 | | If do_flags & DO_LOC then we are scanning for location lists and |
4996 | | dwo tags and we do not want to display anything to the user. |
4997 | | If do_flags & DO_TYPES, we are processing a .debug_types section |
4998 | | instead of a .debug_info section. |
4999 | | If do_var_map is TRUE, we are processing a .debug_types section without |
5000 | | displaying anything to the user yet. |
5001 | | The information displayed is restricted by the values in |
5002 | | DWARF_START_DIE and DWARF_CUTOFF_LEVEL. |
5003 | | Returns TRUE upon success. Otherwise an error or warning message |
5004 | | is printed and FALSE is returned. */ |
5005 | | |
5006 | | static bool |
5007 | | process_debug_info (struct dwarf_section * section, |
5008 | | void *file, |
5009 | | enum dwarf_section_display_enum abbrev_sec, |
5010 | | unsigned int do_flags) |
5011 | 677 | { |
5012 | 677 | unsigned char *start = section->start; |
5013 | 677 | unsigned char *end = start + section->size; |
5014 | 677 | unsigned char *section_begin; |
5015 | 677 | unsigned int unit; |
5016 | 677 | unsigned int num_units = 0; |
5017 | | |
5018 | | /* First scan the section to get the number of comp units. |
5019 | | Length sanity checks are done here. */ |
5020 | 2.10k | for (section_begin = start, num_units = 0; section_begin < end; |
5021 | 1.43k | num_units ++) |
5022 | 1.54k | { |
5023 | 1.54k | uint64_t length; |
5024 | | |
5025 | | /* Read the first 4 bytes. For a 32-bit DWARF section, this |
5026 | | will be the length. For a 64-bit DWARF section, it'll be |
5027 | | the escape code 0xffffffff followed by an 8 byte length. */ |
5028 | 1.54k | SAFE_BYTE_GET_AND_INC (length, section_begin, 4, end); |
5029 | | |
5030 | 1.54k | if (length == 0xffffffff) |
5031 | 1.54k | SAFE_BYTE_GET_AND_INC (length, section_begin, 8, end); |
5032 | 1.52k | else if (length >= 0xfffffff0 && length < 0xffffffff) |
5033 | 5 | { |
5034 | 5 | warn (_("Reserved length value (%#" PRIx64 ") found in section %s\n"), |
5035 | 5 | length, section->name); |
5036 | 5 | return false; |
5037 | 5 | } |
5038 | | |
5039 | | /* Negative values are illegal, they may even cause infinite |
5040 | | looping. This can happen if we can't accurately apply |
5041 | | relocations to an object file, or if the file is corrupt. */ |
5042 | 1.53k | if (length > (size_t) (end - section_begin)) |
5043 | 108 | { |
5044 | 108 | warn (_("Corrupt unit length (got %#" PRIx64 |
5045 | 108 | " expected at most %#tx) in section %s\n"), |
5046 | 108 | length, end - section_begin, section->name); |
5047 | 108 | return false; |
5048 | 108 | } |
5049 | 1.43k | section_begin += length; |
5050 | 1.43k | } |
5051 | | |
5052 | 564 | if (num_units == 0) |
5053 | 0 | { |
5054 | 0 | error (_("No comp units in %s section ?\n"), section->name); |
5055 | 0 | return false; |
5056 | 0 | } |
5057 | | |
5058 | 564 | if (((do_flags & DO_LOC) || do_debug_loc || do_debug_ranges || do_debug_info) |
5059 | 564 | && alloc_num_debug_info_entries == 0 |
5060 | 268 | && !(do_flags & DO_TYPES)) |
5061 | 267 | { |
5062 | | /* Then allocate an array to hold the information. */ |
5063 | 267 | debug_information = cmalloc (num_units, sizeof (*debug_information)); |
5064 | 267 | if (debug_information == NULL) |
5065 | 0 | { |
5066 | 0 | error (_("Not enough memory for a debug info array of %u entries\n"), |
5067 | 0 | num_units); |
5068 | 0 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
5069 | 0 | return false; |
5070 | 0 | } |
5071 | | |
5072 | | /* PR 17531: file: 92ca3797. |
5073 | | We cannot rely upon the debug_information array being initialised |
5074 | | before it is used. A corrupt file could easily contain references |
5075 | | to a unit for which information has not been made available. So |
5076 | | we ensure that the array is zeroed here. */ |
5077 | 267 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
5078 | | |
5079 | 267 | alloc_num_debug_info_entries = num_units; |
5080 | 267 | } |
5081 | | |
5082 | 564 | if (!(do_flags & DO_LOC) || (do_flags & DO_GLOBAL_VARS)) |
5083 | 315 | { |
5084 | 315 | load_debug_section_with_follow (str, file); |
5085 | 315 | load_debug_section_with_follow (line_str, file); |
5086 | 315 | load_debug_section_with_follow (str_dwo, file); |
5087 | 315 | load_debug_section_with_follow (str_index, file); |
5088 | 315 | load_debug_section_with_follow (str_index_dwo, file); |
5089 | 315 | load_debug_section_with_follow (debug_addr, file); |
5090 | 315 | } |
5091 | | |
5092 | 564 | load_debug_section_with_follow (abbrev_sec, file); |
5093 | 564 | load_debug_section_with_follow (loclists, file); |
5094 | 564 | load_debug_section_with_follow (rnglists, file); |
5095 | 564 | load_debug_section_with_follow (loclists_dwo, file); |
5096 | 564 | load_debug_section_with_follow (rnglists_dwo, file); |
5097 | | |
5098 | 564 | if (debug_displays [abbrev_sec].section.start == NULL) |
5099 | 14 | { |
5100 | 14 | warn (_("Unable to locate %s section!\n"), |
5101 | 14 | debug_displays [abbrev_sec].section.uncompressed_name); |
5102 | 14 | return false; |
5103 | 14 | } |
5104 | | |
5105 | 550 | if (!(do_flags & DO_LOC) && dwarf_start_die == 0) |
5106 | 305 | introduce (section, false); |
5107 | | |
5108 | 550 | free_all_abbrevs (); |
5109 | | |
5110 | | /* In order to be able to resolve DW_FORM_ref_addr forms we need |
5111 | | to load *all* of the abbrevs for all CUs in this .debug_info |
5112 | | section. This does effectively mean that we (partially) read |
5113 | | every CU header twice. */ |
5114 | 1.68k | for (section_begin = start; start < end;) |
5115 | 1.13k | { |
5116 | 1.13k | DWARF2_Internal_CompUnit compunit; |
5117 | 1.13k | unsigned char *hdrptr; |
5118 | 1.13k | uint64_t abbrev_base; |
5119 | 1.13k | size_t abbrev_size; |
5120 | 1.13k | uint64_t cu_offset; |
5121 | 1.13k | unsigned int offset_size; |
5122 | 1.13k | struct cu_tu_set *this_set; |
5123 | 1.13k | unsigned char *end_cu; |
5124 | | |
5125 | 1.13k | hdrptr = start; |
5126 | 1.13k | cu_offset = start - section_begin; |
5127 | | |
5128 | 1.13k | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
5129 | | |
5130 | 1.13k | if (compunit.cu_length == 0xffffffff) |
5131 | 0 | { |
5132 | 0 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
5133 | 0 | offset_size = 8; |
5134 | 0 | } |
5135 | 1.13k | else |
5136 | 1.13k | offset_size = 4; |
5137 | 1.13k | end_cu = hdrptr + compunit.cu_length; |
5138 | | |
5139 | 1.13k | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu); |
5140 | | |
5141 | 1.13k | if (compunit.cu_version < 5) |
5142 | 1.00k | { |
5143 | 1.00k | compunit.cu_unit_type = DW_UT_compile; |
5144 | | /* Initialize it due to a false compiler warning. */ |
5145 | 1.00k | compunit.cu_pointer_size = -1; |
5146 | 1.00k | } |
5147 | 130 | else |
5148 | 130 | { |
5149 | 130 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu); |
5150 | 130 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
5151 | 130 | } |
5152 | | |
5153 | 1.13k | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, |
5154 | 1.13k | end_cu); |
5155 | | |
5156 | 1.13k | if (compunit.cu_unit_type == DW_UT_split_compile |
5157 | 1.13k | || compunit.cu_unit_type == DW_UT_skeleton) |
5158 | 4 | { |
5159 | 4 | uint64_t dwo_id; |
5160 | 4 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu); |
5161 | 4 | } |
5162 | | |
5163 | 1.13k | this_set = find_cu_tu_set_v2 (cu_offset, (do_flags & DO_TYPES)); |
5164 | 1.13k | if (this_set == NULL) |
5165 | 1.13k | { |
5166 | 1.13k | abbrev_base = 0; |
5167 | 1.13k | abbrev_size = debug_displays [abbrev_sec].section.size; |
5168 | 1.13k | } |
5169 | 0 | else |
5170 | 0 | { |
5171 | 0 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; |
5172 | 0 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; |
5173 | 0 | } |
5174 | | |
5175 | 1.13k | abbrev_list *list; |
5176 | 1.13k | abbrev_list *free_list; |
5177 | 1.13k | list = find_and_process_abbrev_set (&debug_displays[abbrev_sec].section, |
5178 | 1.13k | abbrev_base, abbrev_size, |
5179 | 1.13k | compunit.cu_abbrev_offset, |
5180 | 1.13k | &free_list); |
5181 | 1.13k | start = end_cu; |
5182 | 1.13k | if (list != NULL && list->first_abbrev != NULL) |
5183 | 669 | record_abbrev_list_for_cu (cu_offset, start - section_begin, |
5184 | 669 | list, free_list); |
5185 | 469 | else if (free_list != NULL) |
5186 | 348 | free_abbrev_list (free_list); |
5187 | 1.13k | } |
5188 | | |
5189 | 1.33k | for (start = section_begin, unit = 0; start < end; unit++) |
5190 | 1.03k | { |
5191 | 1.03k | DWARF2_Internal_CompUnit compunit; |
5192 | 1.03k | unsigned char *hdrptr; |
5193 | 1.03k | unsigned char *tags; |
5194 | 1.03k | int level, last_level, saved_level; |
5195 | 1.03k | uint64_t cu_offset; |
5196 | 1.03k | unsigned int offset_size; |
5197 | 1.03k | uint64_t signature = 0; |
5198 | 1.03k | uint64_t type_offset = 0; |
5199 | 1.03k | struct cu_tu_set *this_set; |
5200 | 1.03k | uint64_t abbrev_base; |
5201 | 1.03k | size_t abbrev_size; |
5202 | 1.03k | unsigned char *end_cu; |
5203 | 1.03k | bool is_union; |
5204 | | |
5205 | 1.03k | hdrptr = start; |
5206 | 1.03k | cu_offset = start - section_begin; |
5207 | | |
5208 | 1.03k | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
5209 | | |
5210 | 1.03k | if (compunit.cu_length == 0xffffffff) |
5211 | 0 | { |
5212 | 0 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
5213 | 0 | offset_size = 8; |
5214 | 0 | } |
5215 | 1.03k | else |
5216 | 1.03k | offset_size = 4; |
5217 | 1.03k | end_cu = hdrptr + compunit.cu_length; |
5218 | | |
5219 | 1.03k | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu); |
5220 | | |
5221 | 1.03k | if (compunit.cu_version < 5) |
5222 | 902 | { |
5223 | 902 | compunit.cu_unit_type = DW_UT_compile; |
5224 | | /* Initialize it due to a false compiler warning. */ |
5225 | 902 | compunit.cu_pointer_size = -1; |
5226 | 902 | } |
5227 | 130 | else |
5228 | 130 | { |
5229 | 130 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu); |
5230 | 130 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
5231 | 130 | } |
5232 | | |
5233 | 1.03k | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end_cu); |
5234 | | |
5235 | 1.03k | this_set = find_cu_tu_set_v2 (cu_offset, (do_flags & DO_TYPES)); |
5236 | 1.03k | if (this_set == NULL) |
5237 | 1.03k | { |
5238 | 1.03k | abbrev_base = 0; |
5239 | 1.03k | abbrev_size = debug_displays [abbrev_sec].section.size; |
5240 | 1.03k | } |
5241 | 0 | else |
5242 | 0 | { |
5243 | 0 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; |
5244 | 0 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; |
5245 | 0 | } |
5246 | | |
5247 | 1.03k | if (compunit.cu_version < 5) |
5248 | 1.03k | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
5249 | | |
5250 | 1.03k | bool do_dwo_id = false; |
5251 | 1.03k | uint64_t dwo_id = 0; |
5252 | 1.03k | if (compunit.cu_unit_type == DW_UT_split_compile |
5253 | 1.02k | || compunit.cu_unit_type == DW_UT_skeleton) |
5254 | 4 | { |
5255 | 4 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu); |
5256 | 4 | do_dwo_id = true; |
5257 | 4 | } |
5258 | | |
5259 | | /* PR 17512: file: 001-108546-0.001:0.1. */ |
5260 | 1.03k | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) |
5261 | 483 | { |
5262 | 483 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), |
5263 | 483 | compunit.cu_pointer_size, offset_size); |
5264 | 483 | compunit.cu_pointer_size = offset_size; |
5265 | 483 | } |
5266 | | |
5267 | 1.03k | if ((do_flags & DO_TYPES) || compunit.cu_unit_type == DW_UT_type) |
5268 | 18 | { |
5269 | 18 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, end_cu); |
5270 | 18 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end_cu); |
5271 | 18 | } |
5272 | | |
5273 | 1.03k | if (dwarf_start_die >= (size_t) (end_cu - section_begin)) |
5274 | 0 | { |
5275 | 0 | start = end_cu; |
5276 | 0 | continue; |
5277 | 0 | } |
5278 | | |
5279 | 1.03k | if (((do_flags & DO_LOC) || do_debug_loc |
5280 | 0 | || do_debug_ranges || do_debug_info) |
5281 | 1.03k | && num_debug_info_entries == 0 |
5282 | 530 | && alloc_num_debug_info_entries > unit |
5283 | 530 | && !(do_flags & DO_TYPES)) |
5284 | 530 | { |
5285 | 530 | free_debug_information (&debug_information[unit]); |
5286 | 530 | memset (&debug_information[unit], 0, sizeof (*debug_information)); |
5287 | 530 | debug_information[unit].pointer_size = compunit.cu_pointer_size; |
5288 | 530 | debug_information[unit].offset_size = offset_size; |
5289 | 530 | debug_information[unit].dwarf_version = compunit.cu_version; |
5290 | 530 | debug_information[unit].cu_offset = cu_offset; |
5291 | 530 | debug_information[unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
5292 | 530 | debug_information[unit].ranges_base = DEBUG_INFO_UNAVAILABLE; |
5293 | 530 | } |
5294 | | |
5295 | 1.03k | if (!(do_flags & DO_LOC) && dwarf_start_die == 0) |
5296 | 569 | { |
5297 | 569 | printf (_(" Compilation Unit @ offset %#" PRIx64 ":\n"), |
5298 | 569 | cu_offset); |
5299 | 569 | printf (_(" Length: %#" PRIx64 " (%s)\n"), |
5300 | 569 | compunit.cu_length, |
5301 | 569 | offset_size == 8 ? "64-bit" : "32-bit"); |
5302 | 569 | printf (_(" Version: %d\n"), compunit.cu_version); |
5303 | 569 | if (compunit.cu_version >= 5) |
5304 | 63 | { |
5305 | 63 | const char *name = get_DW_UT_name (compunit.cu_unit_type); |
5306 | | |
5307 | 63 | printf (_(" Unit Type: %s (%x)\n"), |
5308 | 63 | null_name (name), |
5309 | 63 | compunit.cu_unit_type); |
5310 | 63 | } |
5311 | 569 | printf (_(" Abbrev Offset: %#" PRIx64 "\n"), |
5312 | 569 | compunit.cu_abbrev_offset); |
5313 | 569 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
5314 | 569 | if ((do_flags & DO_TYPES) || compunit.cu_unit_type == DW_UT_type) |
5315 | 18 | { |
5316 | 18 | printf (_(" Signature: %#" PRIx64 "\n"), signature); |
5317 | 18 | printf (_(" Type Offset: %#" PRIx64 "\n"), type_offset); |
5318 | 18 | } |
5319 | 569 | if (do_dwo_id) |
5320 | 2 | printf (_(" DWO ID: %#" PRIx64 "\n"), dwo_id); |
5321 | 569 | if (this_set != NULL) |
5322 | 0 | { |
5323 | 0 | uint64_t *offsets = this_set->section_offsets; |
5324 | 0 | size_t *sizes = this_set->section_sizes; |
5325 | |
|
5326 | 0 | printf (_(" Section contributions:\n")); |
5327 | 0 | printf (_(" .debug_abbrev.dwo: %#" PRIx64 " %#zx\n"), |
5328 | 0 | offsets[DW_SECT_ABBREV], sizes[DW_SECT_ABBREV]); |
5329 | 0 | printf (_(" .debug_line.dwo: %#" PRIx64 " %#zx\n"), |
5330 | 0 | offsets[DW_SECT_LINE], sizes[DW_SECT_LINE]); |
5331 | 0 | printf (_(" .debug_loc.dwo: %#" PRIx64 " %#zx\n"), |
5332 | 0 | offsets[DW_SECT_LOC], sizes[DW_SECT_LOC]); |
5333 | 0 | printf (_(" .debug_str_offsets.dwo: %#" PRIx64 " %#zx\n"), |
5334 | 0 | offsets[DW_SECT_STR_OFFSETS], sizes[DW_SECT_STR_OFFSETS]); |
5335 | 0 | } |
5336 | 569 | } |
5337 | | |
5338 | 1.03k | tags = hdrptr; |
5339 | 1.03k | start = end_cu; |
5340 | | |
5341 | 1.03k | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
5342 | 475 | { |
5343 | 475 | warn (_("CU at offset %#" PRIx64 " contains corrupt or " |
5344 | 475 | "unsupported version number: %d.\n"), |
5345 | 475 | cu_offset, compunit.cu_version); |
5346 | 475 | continue; |
5347 | 475 | } |
5348 | | |
5349 | 557 | if (compunit.cu_unit_type != DW_UT_compile |
5350 | 3 | && compunit.cu_unit_type != DW_UT_partial |
5351 | 3 | && compunit.cu_unit_type != DW_UT_type |
5352 | 3 | && compunit.cu_unit_type != DW_UT_split_compile |
5353 | 0 | && compunit.cu_unit_type != DW_UT_skeleton) |
5354 | 0 | { |
5355 | 0 | warn (_("CU at offset %#" PRIx64 " contains corrupt or " |
5356 | 0 | "unsupported unit type: %d.\n"), |
5357 | 0 | cu_offset, compunit.cu_unit_type); |
5358 | 0 | continue; |
5359 | 0 | } |
5360 | | |
5361 | | /* Process the abbrevs used by this compilation unit. */ |
5362 | 557 | abbrev_list *list; |
5363 | 557 | list = find_and_process_abbrev_set (&debug_displays[abbrev_sec].section, |
5364 | 557 | abbrev_base, abbrev_size, |
5365 | 557 | compunit.cu_abbrev_offset, NULL); |
5366 | 557 | level = 0; |
5367 | 557 | last_level = level; |
5368 | 557 | saved_level = -1; |
5369 | 557 | is_union = false; |
5370 | 5.18k | while (tags < start) |
5371 | 4.91k | { |
5372 | 4.91k | unsigned long abbrev_number; |
5373 | 4.91k | unsigned long die_offset; |
5374 | 4.91k | abbrev_entry *entry; |
5375 | 4.91k | abbrev_attr *attr; |
5376 | 4.91k | bool do_printing; |
5377 | | |
5378 | 4.91k | die_offset = tags - section_begin; |
5379 | | |
5380 | 4.91k | READ_ULEB (abbrev_number, tags, start); |
5381 | | |
5382 | | /* A null DIE marks the end of a list of siblings or it may also be |
5383 | | a section padding. */ |
5384 | 4.91k | if (abbrev_number == 0) |
5385 | 1.51k | { |
5386 | | /* Check if it can be a section padding for the last CU. */ |
5387 | 1.51k | if (level == 0 && start == end) |
5388 | 190 | { |
5389 | 190 | unsigned char *chk; |
5390 | | |
5391 | 739 | for (chk = tags; chk < start; chk++) |
5392 | 696 | if (*chk != 0) |
5393 | 147 | break; |
5394 | 190 | if (chk == start) |
5395 | 43 | break; |
5396 | 190 | } |
5397 | | |
5398 | 1.47k | if (!(do_flags & DO_LOC) && die_offset >= dwarf_start_die |
5399 | 764 | && (dwarf_cutoff_level == -1 |
5400 | 0 | || level < dwarf_cutoff_level)) |
5401 | 764 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
5402 | 764 | level, die_offset); |
5403 | | |
5404 | 1.47k | --level; |
5405 | 1.47k | if (level < 0) |
5406 | 1.06k | { |
5407 | 1.06k | static unsigned num_bogus_warns = 0; |
5408 | | |
5409 | 1.06k | if (num_bogus_warns < 3) |
5410 | 6 | { |
5411 | 6 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
5412 | 6 | die_offset, section->name); |
5413 | 6 | num_bogus_warns ++; |
5414 | 6 | if (num_bogus_warns == 3) |
5415 | 2 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); |
5416 | 6 | } |
5417 | 1.06k | } |
5418 | 1.47k | if (dwarf_start_die != 0 && level < saved_level) |
5419 | 0 | { |
5420 | 0 | if (list != NULL) |
5421 | 0 | free_abbrev_list (list); |
5422 | 0 | return true; |
5423 | 0 | } |
5424 | 1.47k | continue; |
5425 | 1.47k | } |
5426 | | |
5427 | 3.39k | if ((do_flags & DO_LOC) |
5428 | 1.68k | || (dwarf_start_die != 0 && die_offset < dwarf_start_die)) |
5429 | 1.71k | do_printing = false; |
5430 | 1.68k | else |
5431 | 1.68k | { |
5432 | 1.68k | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) |
5433 | 0 | saved_level = level; |
5434 | 1.68k | do_printing = (dwarf_cutoff_level == -1 |
5435 | 0 | || level < dwarf_cutoff_level); |
5436 | 1.68k | if (do_printing) |
5437 | 1.68k | printf (_(" <%d><%lx>: Abbrev Number: %lu"), |
5438 | 1.68k | level, die_offset, abbrev_number); |
5439 | 0 | else if (dwarf_cutoff_level == -1 |
5440 | 0 | || last_level < dwarf_cutoff_level) |
5441 | 0 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); |
5442 | 1.68k | last_level = level; |
5443 | 1.68k | } |
5444 | | |
5445 | | /* Scan through the abbreviation list until we reach the |
5446 | | correct entry. */ |
5447 | 3.39k | entry = NULL; |
5448 | 3.39k | if (list != NULL) |
5449 | 14.8k | for (entry = list->first_abbrev; entry != NULL; entry = entry->next) |
5450 | 14.6k | if (entry->number == abbrev_number) |
5451 | 3.15k | break; |
5452 | | |
5453 | 3.39k | if (entry == NULL) |
5454 | 246 | { |
5455 | 246 | if (do_printing) |
5456 | 127 | { |
5457 | 127 | printf ("\n"); |
5458 | 127 | fflush (stdout); |
5459 | 127 | } |
5460 | 246 | warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"), |
5461 | 246 | die_offset, abbrev_number); |
5462 | 246 | if (list != NULL) |
5463 | 219 | free_abbrev_list (list); |
5464 | 246 | return false; |
5465 | 246 | } |
5466 | | |
5467 | 3.15k | if (do_printing) |
5468 | 1.55k | printf (" (%s)\n", get_TAG_name (entry->tag)); |
5469 | | |
5470 | 3.15k | switch (entry->tag) |
5471 | 3.15k | { |
5472 | 1.98k | default: |
5473 | 1.98k | need_base_address = 0; |
5474 | 1.98k | break; |
5475 | 502 | case DW_TAG_compile_unit: |
5476 | 502 | case DW_TAG_skeleton_unit: |
5477 | 502 | need_base_address = 1; |
5478 | 502 | need_dwo_info = do_flags & DO_LOC; |
5479 | 502 | break; |
5480 | 5 | case DW_TAG_entry_point: |
5481 | 5 | need_base_address = 0; |
5482 | | /* Assuming that there is no DW_AT_frame_base. */ |
5483 | 5 | have_frame_base = 0; |
5484 | 5 | break; |
5485 | 661 | case DW_TAG_subprogram: |
5486 | 661 | need_base_address = 0; |
5487 | 661 | if (level <= frame_base_level) |
5488 | | /* Don't reset that for nested subprogram. */ |
5489 | 345 | have_frame_base = 0; |
5490 | 661 | break; |
5491 | 0 | case DW_TAG_structure_type: |
5492 | 0 | is_union = false; |
5493 | 0 | break; |
5494 | 0 | case DW_TAG_union_type: |
5495 | 0 | is_union = true; |
5496 | 0 | break; |
5497 | 3.15k | } |
5498 | | |
5499 | 3.15k | debug_info *debug_info_p = NULL; |
5500 | 3.15k | if (debug_information |
5501 | 3.15k | && num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
5502 | 2.08k | && unit < alloc_num_debug_info_entries) |
5503 | 2.08k | debug_info_p = debug_information + unit; |
5504 | | |
5505 | 3.15k | assert (!debug_info_p |
5506 | 3.15k | || (debug_info_p->num_loc_offsets |
5507 | 3.15k | == debug_info_p->num_loc_views)); |
5508 | | |
5509 | | /* Look ahead so that the values of DW_AT_rnglists_base, |
5510 | | DW_AT_[GNU_]addr_base are available before attributes that |
5511 | | reference them are parsed in the same DIE. |
5512 | | Only needed for the top DIE on DWARFv5+. |
5513 | | No simiar treatment for loclists_base because there should |
5514 | | be no loclist attributes in top DIE. */ |
5515 | 3.15k | if (debug_info_p && compunit.cu_version >= 5 && level == 0) |
5516 | 79 | { |
5517 | 79 | int64_t stemp; |
5518 | | |
5519 | 79 | read_bases (entry, |
5520 | 79 | tags, |
5521 | 79 | start, |
5522 | 79 | compunit.cu_pointer_size, |
5523 | 79 | offset_size, |
5524 | 79 | compunit.cu_version, |
5525 | 79 | debug_info_p); |
5526 | | |
5527 | | /* This check was in place before, keep it. */ |
5528 | 79 | stemp = debug_info_p->rnglists_base; |
5529 | 79 | if (stemp < 0) |
5530 | 0 | { |
5531 | 0 | warn (_("CU @ %#" PRIx64 " has has a negative rnglists_base " |
5532 | 0 | "value of %#" PRIx64 " - treating as zero\n"), |
5533 | 0 | debug_info_p->cu_offset, stemp); |
5534 | 0 | debug_info_p->rnglists_base = 0; |
5535 | 0 | } |
5536 | 79 | } |
5537 | | |
5538 | 3.15k | for (attr = entry->first_attr; |
5539 | 16.9k | attr && attr->attribute; |
5540 | 13.7k | attr = attr->next) |
5541 | 13.7k | { |
5542 | 13.7k | if (do_printing) |
5543 | | /* Show the offset from where the tag was extracted. */ |
5544 | 6.84k | printf (" <%tx>", tags - section_begin); |
5545 | 13.7k | tags = read_and_display_attr (attr->attribute, |
5546 | 13.7k | attr->form, |
5547 | 13.7k | attr->implicit_const, |
5548 | 13.7k | section_begin, |
5549 | 13.7k | tags, |
5550 | 13.7k | start, |
5551 | 13.7k | cu_offset, |
5552 | 13.7k | compunit.cu_pointer_size, |
5553 | 13.7k | offset_size, |
5554 | 13.7k | compunit.cu_version, |
5555 | 13.7k | debug_info_p, |
5556 | 13.7k | !do_printing, |
5557 | 13.7k | section, |
5558 | 13.7k | this_set, |
5559 | 13.7k | level, |
5560 | 13.7k | do_flags & DO_GLOBAL_VARS, |
5561 | 13.7k | entry->tag, |
5562 | 13.7k | die_offset, |
5563 | 13.7k | is_union); |
5564 | 13.7k | } |
5565 | | |
5566 | | /* If a locview attribute appears before a location one, |
5567 | | make sure we don't associate it with an earlier |
5568 | | loclist. */ |
5569 | 3.15k | if (debug_info_p) |
5570 | 2.08k | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) |
5571 | 2.08k | { |
5572 | 25 | case 1: |
5573 | 25 | debug_info_p->loc_views [debug_info_p->num_loc_views] = -1; |
5574 | 25 | debug_info_p->num_loc_views++; |
5575 | 25 | assert (debug_info_p->num_loc_views |
5576 | 25 | == debug_info_p->num_loc_offsets); |
5577 | 25 | break; |
5578 | | |
5579 | 2.05k | case 0: |
5580 | 2.05k | break; |
5581 | | |
5582 | 0 | case -1: |
5583 | 0 | warn (_("DIE has locviews without loclist\n")); |
5584 | 0 | debug_info_p->num_loc_views--; |
5585 | 0 | break; |
5586 | | |
5587 | 0 | default: |
5588 | 0 | assert (0); |
5589 | 2.08k | } |
5590 | | |
5591 | 3.15k | if (entry->children) |
5592 | 618 | ++level; |
5593 | 3.15k | } |
5594 | 311 | if (list != NULL) |
5595 | 308 | free_abbrev_list (list); |
5596 | 311 | } |
5597 | | |
5598 | | /* Set num_debug_info_entries here so that it can be used to check if |
5599 | | we need to process .debug_loc and .debug_ranges sections. */ |
5600 | 304 | if (((do_flags & DO_LOC) || do_debug_loc || do_debug_ranges || do_debug_info) |
5601 | 304 | && num_debug_info_entries == 0 |
5602 | 117 | && !(do_flags & DO_TYPES)) |
5603 | 117 | { |
5604 | 117 | if (num_units > alloc_num_debug_info_entries) |
5605 | 0 | num_debug_info_entries = alloc_num_debug_info_entries; |
5606 | 117 | else |
5607 | 117 | num_debug_info_entries = num_units; |
5608 | 117 | } |
5609 | | |
5610 | 304 | if (!(do_flags & DO_LOC)) |
5611 | 178 | printf ("\n"); |
5612 | | |
5613 | 304 | return true; |
5614 | 550 | } |
5615 | | |
5616 | | /* Locate and scan the .debug_info section in the file and record the pointer |
5617 | | sizes and offsets for the compilation units in it. Usually an executable |
5618 | | will have just one pointer size, but this is not guaranteed, and so we try |
5619 | | not to make any assumptions. Returns zero upon failure, or the number of |
5620 | | compilation units upon success. */ |
5621 | | |
5622 | | static unsigned int |
5623 | | load_debug_info (void * file) |
5624 | 675 | { |
5625 | | /* If we have already tried and failed to load the .debug_info |
5626 | | section then do not bother to repeat the task. */ |
5627 | 675 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
5628 | 368 | return 0; |
5629 | | |
5630 | | /* If we already have the information there is nothing else to do. */ |
5631 | 307 | if (num_debug_info_entries > 0) |
5632 | 202 | return num_debug_info_entries; |
5633 | | |
5634 | | /* If this is a DWARF package file, load the CU and TU indexes. */ |
5635 | 105 | (void) load_cu_tu_indexes (file); |
5636 | | |
5637 | 105 | if (load_debug_section_with_follow (info, file) |
5638 | 60 | && process_debug_info (&debug_displays [info].section, file, |
5639 | 60 | abbrev, DO_LOC)) |
5640 | 0 | return num_debug_info_entries; |
5641 | | |
5642 | 105 | if (load_debug_section_with_follow (info_dwo, file) |
5643 | 0 | && process_debug_info (&debug_displays [info_dwo].section, file, |
5644 | 0 | abbrev_dwo, DO_LOC)) |
5645 | 0 | return num_debug_info_entries; |
5646 | | |
5647 | 105 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
5648 | 105 | return 0; |
5649 | 105 | } |
5650 | | |
5651 | | static bool |
5652 | | address_size_ok (const char *sec_name, unsigned addr_size, unsigned seg_size) |
5653 | 170 | { |
5654 | 170 | if (seg_size != 0) |
5655 | 8 | { |
5656 | 8 | warn (_("Unsupported segment selector size (%u) in %s section.\n"), |
5657 | 8 | seg_size, sec_name); |
5658 | 8 | return false; |
5659 | 8 | } |
5660 | 162 | if (addr_size == 0 || addr_size > 8) |
5661 | 7 | { |
5662 | 7 | warn (_("Unsupported address size (%u) in %s section.\n"), |
5663 | 7 | addr_size, sec_name); |
5664 | 7 | return false; |
5665 | 7 | } |
5666 | 155 | return true; |
5667 | 162 | } |
5668 | | |
5669 | | /* Read a DWARF .debug_line section header starting at DATA. |
5670 | | Upon success returns an updated DATA pointer and the LINFO |
5671 | | structure and the END_OF_SEQUENCE pointer will be filled in. |
5672 | | Otherwise returns NULL. */ |
5673 | | |
5674 | | static unsigned char * |
5675 | | read_debug_line_header (struct dwarf_section * section, |
5676 | | unsigned char * data, |
5677 | | unsigned char * end, |
5678 | | DWARF2_Internal_LineInfo * linfo, |
5679 | | unsigned char ** end_of_sequence) |
5680 | 394 | { |
5681 | 394 | unsigned char *hdrptr; |
5682 | | |
5683 | | /* Extract information from the Line Number Program Header. |
5684 | | (section 6.2.4 in the Dwarf3 doc). */ |
5685 | 394 | hdrptr = data; |
5686 | | |
5687 | | /* Get and check the length of the block. */ |
5688 | 394 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); |
5689 | | |
5690 | 394 | if (linfo->li_length == 0xffffffff) |
5691 | 0 | { |
5692 | | /* This section is 64-bit DWARF 3. */ |
5693 | 0 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
5694 | 0 | linfo->li_offset_size = 8; |
5695 | 0 | } |
5696 | 394 | else |
5697 | 394 | linfo->li_offset_size = 4; |
5698 | | |
5699 | 394 | if (linfo->li_length > (size_t) (end - hdrptr)) |
5700 | 68 | { |
5701 | | /* If the length field has a relocation against it, then we should |
5702 | | not complain if it is inaccurate (and probably negative). This |
5703 | | happens in object files when the .debug_line section is actually |
5704 | | comprised of several different .debug_line.* sections, (some of |
5705 | | which may be removed by linker garbage collection), and a relocation |
5706 | | is used to compute the correct length once that is done. */ |
5707 | 68 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
5708 | 5 | { |
5709 | 5 | linfo->li_length = end - hdrptr; |
5710 | 5 | } |
5711 | 63 | else |
5712 | 63 | { |
5713 | 63 | warn (_("The length field (%#" PRIx64 ")" |
5714 | 63 | " in the debug_line header is wrong" |
5715 | 63 | " - the section is too small\n"), |
5716 | 63 | linfo->li_length); |
5717 | 63 | return NULL; |
5718 | 63 | } |
5719 | 68 | } |
5720 | 331 | end = hdrptr + linfo->li_length; |
5721 | | |
5722 | | /* Get and check the version number. */ |
5723 | 331 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); |
5724 | | |
5725 | 331 | if (linfo->li_version != 2 |
5726 | 206 | && linfo->li_version != 3 |
5727 | 206 | && linfo->li_version != 4 |
5728 | 70 | && linfo->li_version != 5) |
5729 | 38 | { |
5730 | 38 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
5731 | 38 | "is currently supported.\n")); |
5732 | 38 | return NULL; |
5733 | 38 | } |
5734 | | |
5735 | 293 | if (linfo->li_version >= 5) |
5736 | 32 | { |
5737 | 32 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
5738 | | |
5739 | 32 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
5740 | 32 | if (!address_size_ok (section->name, linfo->li_address_size, |
5741 | 32 | linfo->li_segment_size)) |
5742 | 8 | return NULL; |
5743 | 32 | } |
5744 | | |
5745 | 285 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, |
5746 | 285 | linfo->li_offset_size, end); |
5747 | 285 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
5748 | | |
5749 | 285 | if (linfo->li_version >= 4) |
5750 | 160 | { |
5751 | 160 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
5752 | | |
5753 | 160 | if (linfo->li_max_ops_per_insn == 0) |
5754 | 2 | { |
5755 | 2 | warn (_("Invalid maximum operations per insn.\n")); |
5756 | 2 | return NULL; |
5757 | 2 | } |
5758 | 160 | } |
5759 | 125 | else |
5760 | 125 | linfo->li_max_ops_per_insn = 1; |
5761 | | |
5762 | 283 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
5763 | 283 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
5764 | 283 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
5765 | 283 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); |
5766 | | |
5767 | 283 | *end_of_sequence = end; |
5768 | 283 | return hdrptr; |
5769 | 283 | } |
5770 | | |
5771 | | static unsigned char * |
5772 | | display_formatted_table (unsigned char *data, |
5773 | | unsigned char *start, |
5774 | | unsigned char *end, |
5775 | | const DWARF2_Internal_LineInfo *linfo, |
5776 | | struct dwarf_section *section, |
5777 | | bool is_dir) |
5778 | 48 | { |
5779 | 48 | unsigned char *format_start, format_count, *format, formati; |
5780 | 48 | uint64_t data_count, datai; |
5781 | 48 | unsigned int namepass, last_entry = 0; |
5782 | 48 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
5783 | | |
5784 | 48 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
5785 | 48 | if (do_checks && format_count > 5) |
5786 | 0 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), |
5787 | 0 | table_name, format_count); |
5788 | | |
5789 | 48 | format_start = data; |
5790 | 163 | for (formati = 0; formati < format_count; formati++) |
5791 | 115 | { |
5792 | 115 | SKIP_ULEB (data, end); |
5793 | 115 | SKIP_ULEB (data, end); |
5794 | 115 | if (data >= end) |
5795 | 0 | { |
5796 | 0 | warn (_("%s: Corrupt format description entry\n"), table_name); |
5797 | 0 | return data; |
5798 | 0 | } |
5799 | 115 | } |
5800 | | |
5801 | 48 | READ_ULEB (data_count, data, end); |
5802 | 48 | if (data_count == 0) |
5803 | 12 | { |
5804 | 12 | printf (_("\n The %s is empty.\n"), table_name); |
5805 | 12 | return data; |
5806 | 12 | } |
5807 | 36 | else if (data >= end |
5808 | 36 | || data_count > (size_t) (end - data)) |
5809 | 9 | { |
5810 | 9 | warn (_("%s: Corrupt entry count %#" PRIx64 "\n"), table_name, data_count); |
5811 | 9 | return data; |
5812 | 9 | } |
5813 | | |
5814 | 27 | else if (format_count == 0) |
5815 | 1 | { |
5816 | 1 | warn (_("%s: format count is zero, but the table is not empty\n"), |
5817 | 1 | table_name); |
5818 | 1 | return end; |
5819 | 1 | } |
5820 | | |
5821 | 26 | printf (_("\n The %s (offset %#tx, lines %" PRIu64 ", columns %u):\n"), |
5822 | 26 | table_name, data - start, data_count, format_count); |
5823 | | |
5824 | 26 | printf (_(" Entry")); |
5825 | | /* Delay displaying name as the last entry for better screen layout. */ |
5826 | 78 | for (namepass = 0; namepass < 2; namepass++) |
5827 | 52 | { |
5828 | 52 | format = format_start; |
5829 | 134 | for (formati = 0; formati < format_count; formati++) |
5830 | 82 | { |
5831 | 82 | uint64_t content_type; |
5832 | | |
5833 | 82 | READ_ULEB (content_type, format, end); |
5834 | 82 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
5835 | 41 | switch (content_type) |
5836 | 41 | { |
5837 | 25 | case DW_LNCT_path: |
5838 | 25 | printf (_("\tName")); |
5839 | 25 | break; |
5840 | 10 | case DW_LNCT_directory_index: |
5841 | 10 | printf (_("\tDir")); |
5842 | 10 | break; |
5843 | 0 | case DW_LNCT_timestamp: |
5844 | 0 | printf (_("\tTime")); |
5845 | 0 | break; |
5846 | 0 | case DW_LNCT_size: |
5847 | 0 | printf (_("\tSize")); |
5848 | 0 | break; |
5849 | 5 | case DW_LNCT_MD5: |
5850 | 5 | printf (_("\tMD5\t\t\t")); |
5851 | 5 | break; |
5852 | 1 | default: |
5853 | 1 | printf (_("\t(Unknown format content type %" PRIu64 ")"), |
5854 | 1 | content_type); |
5855 | 41 | } |
5856 | 82 | SKIP_ULEB (format, end); |
5857 | 82 | } |
5858 | 52 | } |
5859 | 26 | putchar ('\n'); |
5860 | | |
5861 | 81 | for (datai = 0; datai < data_count; datai++) |
5862 | 59 | { |
5863 | 59 | unsigned char *datapass = data; |
5864 | | |
5865 | 59 | printf (" %d", last_entry++); |
5866 | | /* Delay displaying name as the last entry for better screen layout. */ |
5867 | 177 | for (namepass = 0; namepass < 2; namepass++) |
5868 | 118 | { |
5869 | 118 | format = format_start; |
5870 | 118 | data = datapass; |
5871 | 266 | for (formati = 0; formati < format_count; formati++) |
5872 | 148 | { |
5873 | 148 | uint64_t content_type, form; |
5874 | | |
5875 | 148 | READ_ULEB (content_type, format, end); |
5876 | 148 | READ_ULEB (form, format, end); |
5877 | 148 | bool do_loc = (content_type == DW_LNCT_path) != (namepass == 1); |
5878 | 148 | data = read_and_display_attr_value (0, form, 0, start, data, end, |
5879 | 148 | 0, linfo->li_address_size, |
5880 | 148 | linfo->li_offset_size, |
5881 | 148 | linfo->li_version, NULL, |
5882 | 148 | do_loc, section, NULL, '\t', |
5883 | 148 | -1, false, 0, 0, false); |
5884 | 148 | } |
5885 | 118 | } |
5886 | | |
5887 | 59 | if (data >= end && (datai < data_count - 1)) |
5888 | 4 | { |
5889 | 4 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
5890 | 4 | return data; |
5891 | 4 | } |
5892 | 55 | putchar ('\n'); |
5893 | 55 | } |
5894 | 22 | return data; |
5895 | 26 | } |
5896 | | |
5897 | | static int |
5898 | | display_debug_sup (struct dwarf_section * section, |
5899 | | void * file ATTRIBUTE_UNUSED) |
5900 | 0 | { |
5901 | 0 | unsigned char * start = section->start; |
5902 | 0 | unsigned char * end = section->start + section->size; |
5903 | 0 | unsigned int version; |
5904 | 0 | char is_supplementary; |
5905 | 0 | const unsigned char * sup_filename; |
5906 | 0 | size_t sup_filename_len; |
5907 | 0 | unsigned int num_read; |
5908 | 0 | int status; |
5909 | 0 | uint64_t checksum_len; |
5910 | | |
5911 | |
|
5912 | 0 | introduce (section, true); |
5913 | 0 | if (section->size < 4) |
5914 | 0 | { |
5915 | 0 | error (_("corrupt .debug_sup section: size is too small\n")); |
5916 | 0 | return 0; |
5917 | 0 | } |
5918 | | |
5919 | | /* Read the data. */ |
5920 | 0 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); |
5921 | 0 | if (version < 5) |
5922 | 0 | warn (_("corrupt .debug_sup section: version < 5\n")); |
5923 | |
|
5924 | 0 | SAFE_BYTE_GET_AND_INC (is_supplementary, start, 1, end); |
5925 | 0 | if (is_supplementary != 0 && is_supplementary != 1) |
5926 | 0 | warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n")); |
5927 | |
|
5928 | 0 | sup_filename = start; |
5929 | 0 | if (is_supplementary && sup_filename[0] != 0) |
5930 | 0 | warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n")); |
5931 | |
|
5932 | 0 | sup_filename_len = strnlen ((const char *) start, end - start); |
5933 | 0 | if (sup_filename_len == (size_t) (end - start)) |
5934 | 0 | { |
5935 | 0 | error (_("corrupt .debug_sup section: filename is not NUL terminated\n")); |
5936 | 0 | return 0; |
5937 | 0 | } |
5938 | 0 | start += sup_filename_len + 1; |
5939 | |
|
5940 | 0 | checksum_len = read_leb128 (start, end, false /* unsigned */, & num_read, & status); |
5941 | 0 | if (status) |
5942 | 0 | { |
5943 | 0 | error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n")); |
5944 | 0 | checksum_len = 0; |
5945 | 0 | } |
5946 | 0 | start += num_read; |
5947 | 0 | if (checksum_len > (size_t) (end - start)) |
5948 | 0 | { |
5949 | 0 | error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n")); |
5950 | 0 | checksum_len = end - start; |
5951 | 0 | } |
5952 | 0 | else if (checksum_len < (size_t) (end - start)) |
5953 | 0 | { |
5954 | 0 | warn (_("corrupt .debug_sup section: there are %#" PRIx64 |
5955 | 0 | " extra, unused bytes at the end of the section\n"), |
5956 | 0 | (end - start) - checksum_len); |
5957 | 0 | } |
5958 | |
|
5959 | 0 | printf (_(" Version: %u\n"), version); |
5960 | 0 | printf (_(" Is Supp: %u\n"), is_supplementary); |
5961 | 0 | printf (_(" Filename: %s\n"), sup_filename); |
5962 | 0 | printf (_(" Checksum Len: %" PRIu64 "\n"), checksum_len); |
5963 | 0 | if (checksum_len > 0) |
5964 | 0 | { |
5965 | 0 | printf (_(" Checksum: ")); |
5966 | 0 | while (checksum_len--) |
5967 | 0 | printf ("0x%x ", * start++ ); |
5968 | 0 | printf ("\n"); |
5969 | 0 | } |
5970 | 0 | return 1; |
5971 | 0 | } |
5972 | | |
5973 | | static int |
5974 | | display_debug_lines_raw (struct dwarf_section * section, |
5975 | | unsigned char * data, |
5976 | | unsigned char * end, |
5977 | | void * file) |
5978 | 355 | { |
5979 | 355 | unsigned char *start = section->start; |
5980 | 355 | int verbose_view = 0; |
5981 | | |
5982 | 355 | introduce (section, true); |
5983 | | |
5984 | 637 | while (data < end) |
5985 | 394 | { |
5986 | 394 | static DWARF2_Internal_LineInfo saved_linfo; |
5987 | 394 | DWARF2_Internal_LineInfo linfo; |
5988 | 394 | unsigned char *standard_opcodes; |
5989 | 394 | unsigned char *end_of_sequence; |
5990 | 394 | int i; |
5991 | | |
5992 | 394 | if (startswith (section->name, ".debug_line.") |
5993 | | /* Note: the following does not apply to .debug_line.dwo sections. |
5994 | | These are full debug_line sections. */ |
5995 | 0 | && strcmp (section->name, ".debug_line.dwo") != 0) |
5996 | 0 | { |
5997 | | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
5998 | | section containing just the Line Number Statements. They are |
5999 | | created by the assembler and intended to be used alongside gcc's |
6000 | | -ffunction-sections command line option. When the linker's |
6001 | | garbage collection decides to discard a .text.<foo> section it |
6002 | | can then also discard the line number information in .debug_line.<foo>. |
6003 | | |
6004 | | Since the section is a fragment it does not have the details |
6005 | | needed to fill out a LineInfo structure, so instead we use the |
6006 | | details from the last full debug_line section that we processed. */ |
6007 | 0 | end_of_sequence = end; |
6008 | 0 | standard_opcodes = NULL; |
6009 | 0 | linfo = saved_linfo; |
6010 | | /* PR 17531: file: 0522b371. */ |
6011 | 0 | if (linfo.li_line_range == 0) |
6012 | 0 | { |
6013 | 0 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
6014 | 0 | return 0; |
6015 | 0 | } |
6016 | 0 | reset_state_machine (linfo.li_default_is_stmt); |
6017 | 0 | } |
6018 | 394 | else |
6019 | 394 | { |
6020 | 394 | unsigned char * hdrptr; |
6021 | | |
6022 | 394 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
6023 | 394 | & end_of_sequence)) == NULL) |
6024 | 111 | return 0; |
6025 | | |
6026 | 283 | printf (_(" Offset: %#tx\n"), data - start); |
6027 | 283 | printf (_(" Length: %" PRId64 "\n"), linfo.li_length); |
6028 | 283 | printf (_(" DWARF Version: %d\n"), linfo.li_version); |
6029 | 283 | if (linfo.li_version >= 5) |
6030 | 24 | { |
6031 | 24 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); |
6032 | 24 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); |
6033 | 24 | } |
6034 | 283 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
6035 | 283 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
6036 | 283 | if (linfo.li_version >= 4) |
6037 | 158 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); |
6038 | 283 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); |
6039 | 283 | printf (_(" Line Base: %d\n"), linfo.li_line_base); |
6040 | 283 | printf (_(" Line Range: %d\n"), linfo.li_line_range); |
6041 | 283 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); |
6042 | | |
6043 | | /* PR 17512: file: 1665-6428-0.004. */ |
6044 | 283 | if (linfo.li_line_range == 0) |
6045 | 3 | { |
6046 | 3 | warn (_("Line range of 0 is invalid, using 1 instead\n")); |
6047 | 3 | linfo.li_line_range = 1; |
6048 | 3 | } |
6049 | | |
6050 | 283 | reset_state_machine (linfo.li_default_is_stmt); |
6051 | | |
6052 | | /* Display the contents of the Opcodes table. */ |
6053 | 283 | standard_opcodes = hdrptr; |
6054 | | |
6055 | | /* PR 17512: file: 002-417945-0.004. */ |
6056 | 283 | if (standard_opcodes + linfo.li_opcode_base >= end) |
6057 | 0 | { |
6058 | 0 | warn (_("Line Base extends beyond end of section\n")); |
6059 | 0 | return 0; |
6060 | 0 | } |
6061 | | |
6062 | 283 | printf (_("\n Opcodes:\n")); |
6063 | | |
6064 | 4.44k | for (i = 1; i < linfo.li_opcode_base; i++) |
6065 | 4.16k | printf (ngettext (" Opcode %d has %d arg\n", |
6066 | 4.16k | " Opcode %d has %d args\n", |
6067 | 4.16k | standard_opcodes[i - 1]), |
6068 | 4.16k | i, standard_opcodes[i - 1]); |
6069 | | |
6070 | | /* Display the contents of the Directory table. */ |
6071 | 283 | data = standard_opcodes + linfo.li_opcode_base - 1; |
6072 | | |
6073 | 283 | if (linfo.li_version >= 5) |
6074 | 24 | { |
6075 | 24 | load_debug_section_with_follow (line_str, file); |
6076 | | |
6077 | 24 | data = display_formatted_table (data, start, end, &linfo, section, |
6078 | 24 | true); |
6079 | 24 | data = display_formatted_table (data, start, end, &linfo, section, |
6080 | 24 | false); |
6081 | 24 | } |
6082 | 259 | else |
6083 | 259 | { |
6084 | 259 | if (*data == 0) |
6085 | 111 | printf (_("\n The Directory Table is empty.\n")); |
6086 | 148 | else |
6087 | 148 | { |
6088 | 148 | unsigned int last_dir_entry = 0; |
6089 | | |
6090 | 148 | printf (_("\n The Directory Table (offset %#tx):\n"), |
6091 | 148 | data - start); |
6092 | | |
6093 | 422 | while (data < end && *data != 0) |
6094 | 274 | { |
6095 | 274 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); |
6096 | | |
6097 | 274 | data += strnlen ((char *) data, end - data); |
6098 | 274 | if (data < end) |
6099 | 273 | data++; |
6100 | 274 | } |
6101 | | |
6102 | | /* PR 17512: file: 002-132094-0.004. */ |
6103 | 148 | if (data >= end - 1) |
6104 | 1 | break; |
6105 | 148 | } |
6106 | | |
6107 | | /* Skip the NUL at the end of the table. */ |
6108 | 258 | if (data < end) |
6109 | 258 | data++; |
6110 | | |
6111 | | /* Display the contents of the File Name table. */ |
6112 | 258 | if (data >= end || *data == 0) |
6113 | 5 | printf (_("\n The File Name Table is empty.\n")); |
6114 | 253 | else |
6115 | 253 | { |
6116 | 253 | printf (_("\n The File Name Table (offset %#tx):\n"), |
6117 | 253 | data - start); |
6118 | 253 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
6119 | | |
6120 | 897 | while (data < end && *data != 0) |
6121 | 646 | { |
6122 | 646 | unsigned char *name; |
6123 | 646 | uint64_t val; |
6124 | | |
6125 | 646 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
6126 | 646 | name = data; |
6127 | 646 | data += strnlen ((char *) data, end - data); |
6128 | 646 | if (data < end) |
6129 | 644 | data++; |
6130 | | |
6131 | 646 | READ_ULEB (val, data, end); |
6132 | 646 | printf ("%" PRIu64 "\t", val); |
6133 | 646 | READ_ULEB (val, data, end); |
6134 | 646 | printf ("%" PRIu64 "\t", val); |
6135 | 646 | READ_ULEB (val, data, end); |
6136 | 646 | printf ("%" PRIu64 "\t", val); |
6137 | 646 | printf ("%.*s\n", (int)(end - name), name); |
6138 | | |
6139 | 646 | if (data >= end) |
6140 | 2 | { |
6141 | 2 | warn (_("Corrupt file name table entry\n")); |
6142 | 2 | break; |
6143 | 2 | } |
6144 | 646 | } |
6145 | 253 | } |
6146 | | |
6147 | | /* Skip the NUL at the end of the table. */ |
6148 | 258 | if (data < end) |
6149 | 256 | data++; |
6150 | 258 | } |
6151 | | |
6152 | 282 | putchar ('\n'); |
6153 | 282 | saved_linfo = linfo; |
6154 | 282 | } |
6155 | | |
6156 | | /* Now display the statements. */ |
6157 | 282 | if (data >= end_of_sequence) |
6158 | 19 | printf (_(" No Line Number Statements.\n")); |
6159 | 263 | else |
6160 | 263 | { |
6161 | 263 | printf (_(" Line Number Statements:\n")); |
6162 | | |
6163 | 25.6k | while (data < end_of_sequence) |
6164 | 25.3k | { |
6165 | 25.3k | unsigned char op_code; |
6166 | 25.3k | int adv; |
6167 | 25.3k | uint64_t uladv; |
6168 | | |
6169 | 25.3k | printf (" [0x%08tx]", data - start); |
6170 | | |
6171 | 25.3k | op_code = *data++; |
6172 | | |
6173 | 25.3k | if (op_code >= linfo.li_opcode_base) |
6174 | 7.92k | { |
6175 | 7.92k | op_code -= linfo.li_opcode_base; |
6176 | 7.92k | uladv = (op_code / linfo.li_line_range); |
6177 | 7.92k | if (linfo.li_max_ops_per_insn == 1) |
6178 | 7.44k | { |
6179 | 7.44k | uladv *= linfo.li_min_insn_length; |
6180 | 7.44k | state_machine_regs.address += uladv; |
6181 | 7.44k | if (uladv) |
6182 | 6.50k | state_machine_regs.view = 0; |
6183 | 7.44k | printf (_(" Special opcode %d: " |
6184 | 7.44k | "advance Address by %" PRIu64 |
6185 | 7.44k | " to %#" PRIx64 "%s"), |
6186 | 7.44k | op_code, uladv, state_machine_regs.address, |
6187 | 7.44k | verbose_view && uladv |
6188 | 7.44k | ? _(" (reset view)") : ""); |
6189 | 7.44k | } |
6190 | 472 | else |
6191 | 472 | { |
6192 | 472 | unsigned addrdelta |
6193 | 472 | = ((state_machine_regs.op_index + uladv) |
6194 | 472 | / linfo.li_max_ops_per_insn) |
6195 | 472 | * linfo.li_min_insn_length; |
6196 | | |
6197 | 472 | state_machine_regs.address += addrdelta; |
6198 | 472 | state_machine_regs.op_index |
6199 | 472 | = (state_machine_regs.op_index + uladv) |
6200 | 472 | % linfo.li_max_ops_per_insn; |
6201 | 472 | if (addrdelta) |
6202 | 172 | state_machine_regs.view = 0; |
6203 | 472 | printf (_(" Special opcode %d: " |
6204 | 472 | "advance Address by %" PRIu64 |
6205 | 472 | " to %#" PRIx64 "[%d]%s"), |
6206 | 472 | op_code, uladv, state_machine_regs.address, |
6207 | 472 | state_machine_regs.op_index, |
6208 | 472 | verbose_view && addrdelta |
6209 | 472 | ? _(" (reset view)") : ""); |
6210 | 472 | } |
6211 | 7.92k | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
6212 | 7.92k | state_machine_regs.line += adv; |
6213 | 7.92k | printf (_(" and Line by %d to %d"), |
6214 | 7.92k | adv, state_machine_regs.line); |
6215 | 7.92k | if (verbose_view || state_machine_regs.view) |
6216 | 325 | printf (_(" (view %u)\n"), state_machine_regs.view); |
6217 | 7.59k | else |
6218 | 7.59k | putchar ('\n'); |
6219 | 7.92k | state_machine_regs.view++; |
6220 | 7.92k | } |
6221 | 17.4k | else |
6222 | 17.4k | switch (op_code) |
6223 | 17.4k | { |
6224 | 881 | case DW_LNS_extended_op: |
6225 | 881 | data += process_extended_line_op (data, |
6226 | 881 | linfo.li_default_is_stmt, |
6227 | 881 | end); |
6228 | 881 | break; |
6229 | | |
6230 | 396 | case DW_LNS_copy: |
6231 | 396 | printf (_(" Copy")); |
6232 | 396 | if (verbose_view || state_machine_regs.view) |
6233 | 26 | printf (_(" (view %u)\n"), state_machine_regs.view); |
6234 | 370 | else |
6235 | 370 | putchar ('\n'); |
6236 | 396 | state_machine_regs.view++; |
6237 | 396 | break; |
6238 | | |
6239 | 815 | case DW_LNS_advance_pc: |
6240 | 815 | READ_ULEB (uladv, data, end); |
6241 | 815 | if (linfo.li_max_ops_per_insn == 1) |
6242 | 777 | { |
6243 | 777 | uladv *= linfo.li_min_insn_length; |
6244 | 777 | state_machine_regs.address += uladv; |
6245 | 777 | if (uladv) |
6246 | 773 | state_machine_regs.view = 0; |
6247 | 777 | printf (_(" Advance PC by %" PRIu64 |
6248 | 777 | " to %#" PRIx64 "%s\n"), |
6249 | 777 | uladv, state_machine_regs.address, |
6250 | 777 | verbose_view && uladv |
6251 | 777 | ? _(" (reset view)") : ""); |
6252 | 777 | } |
6253 | 38 | else |
6254 | 38 | { |
6255 | 38 | unsigned addrdelta |
6256 | 38 | = ((state_machine_regs.op_index + uladv) |
6257 | 38 | / linfo.li_max_ops_per_insn) |
6258 | 38 | * linfo.li_min_insn_length; |
6259 | 38 | state_machine_regs.address |
6260 | 38 | += addrdelta; |
6261 | 38 | state_machine_regs.op_index |
6262 | 38 | = (state_machine_regs.op_index + uladv) |
6263 | 38 | % linfo.li_max_ops_per_insn; |
6264 | 38 | if (addrdelta) |
6265 | 21 | state_machine_regs.view = 0; |
6266 | 38 | printf (_(" Advance PC by %" PRIu64 |
6267 | 38 | " to %#" PRIx64 "[%d]%s\n"), |
6268 | 38 | uladv, state_machine_regs.address, |
6269 | 38 | state_machine_regs.op_index, |
6270 | 38 | verbose_view && addrdelta |
6271 | 38 | ? _(" (reset view)") : ""); |
6272 | 38 | } |
6273 | 815 | break; |
6274 | | |
6275 | 3.92k | case DW_LNS_advance_line: |
6276 | 3.92k | READ_SLEB (adv, data, end); |
6277 | 3.92k | state_machine_regs.line += adv; |
6278 | 3.92k | printf (_(" Advance Line by %d to %d\n"), |
6279 | 3.92k | adv, state_machine_regs.line); |
6280 | 3.92k | break; |
6281 | | |
6282 | 69 | case DW_LNS_set_file: |
6283 | 69 | READ_ULEB (uladv, data, end); |
6284 | 69 | printf (_(" Set File Name to entry %" PRIu64 |
6285 | 69 | " in the File Name Table\n"), uladv); |
6286 | 69 | state_machine_regs.file = uladv; |
6287 | 69 | break; |
6288 | | |
6289 | 5.21k | case DW_LNS_set_column: |
6290 | 5.21k | READ_ULEB (uladv, data, end); |
6291 | 5.21k | printf (_(" Set column to %" PRIu64 "\n"), uladv); |
6292 | 5.21k | state_machine_regs.column = uladv; |
6293 | 5.21k | break; |
6294 | | |
6295 | 3.46k | case DW_LNS_negate_stmt: |
6296 | 3.46k | adv = state_machine_regs.is_stmt; |
6297 | 3.46k | adv = ! adv; |
6298 | 3.46k | printf (_(" Set is_stmt to %d\n"), adv); |
6299 | 3.46k | state_machine_regs.is_stmt = adv; |
6300 | 3.46k | break; |
6301 | | |
6302 | 2 | case DW_LNS_set_basic_block: |
6303 | 2 | printf (_(" Set basic block\n")); |
6304 | 2 | state_machine_regs.basic_block = 1; |
6305 | 2 | break; |
6306 | | |
6307 | 2.41k | case DW_LNS_const_add_pc: |
6308 | 2.41k | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); |
6309 | 2.41k | if (linfo.li_max_ops_per_insn) |
6310 | 2.41k | { |
6311 | 2.41k | uladv *= linfo.li_min_insn_length; |
6312 | 2.41k | state_machine_regs.address += uladv; |
6313 | 2.41k | if (uladv) |
6314 | 2.40k | state_machine_regs.view = 0; |
6315 | 2.41k | printf (_(" Advance PC by constant %" PRIu64 |
6316 | 2.41k | " to %#" PRIx64 "%s\n"), |
6317 | 2.41k | uladv, state_machine_regs.address, |
6318 | 2.41k | verbose_view && uladv |
6319 | 2.41k | ? _(" (reset view)") : ""); |
6320 | 2.41k | } |
6321 | 0 | else |
6322 | 0 | { |
6323 | 0 | unsigned addrdelta |
6324 | 0 | = ((state_machine_regs.op_index + uladv) |
6325 | 0 | / linfo.li_max_ops_per_insn) |
6326 | 0 | * linfo.li_min_insn_length; |
6327 | 0 | state_machine_regs.address |
6328 | 0 | += addrdelta; |
6329 | 0 | state_machine_regs.op_index |
6330 | 0 | = (state_machine_regs.op_index + uladv) |
6331 | 0 | % linfo.li_max_ops_per_insn; |
6332 | 0 | if (addrdelta) |
6333 | 0 | state_machine_regs.view = 0; |
6334 | 0 | printf (_(" Advance PC by constant %" PRIu64 |
6335 | 0 | " to %#" PRIx64 "[%d]%s\n"), |
6336 | 0 | uladv, state_machine_regs.address, |
6337 | 0 | state_machine_regs.op_index, |
6338 | 0 | verbose_view && addrdelta |
6339 | 0 | ? _(" (reset view)") : ""); |
6340 | 0 | } |
6341 | 2.41k | break; |
6342 | | |
6343 | 3 | case DW_LNS_fixed_advance_pc: |
6344 | 3 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); |
6345 | 3 | state_machine_regs.address += uladv; |
6346 | 3 | state_machine_regs.op_index = 0; |
6347 | 3 | printf (_(" Advance PC by fixed size amount %" PRIu64 |
6348 | 3 | " to %#" PRIx64 "\n"), |
6349 | 3 | uladv, state_machine_regs.address); |
6350 | | /* Do NOT reset view. */ |
6351 | 3 | break; |
6352 | | |
6353 | 166 | case DW_LNS_set_prologue_end: |
6354 | 166 | printf (_(" Set prologue_end to true\n")); |
6355 | 166 | break; |
6356 | | |
6357 | 3 | case DW_LNS_set_epilogue_begin: |
6358 | 3 | printf (_(" Set epilogue_begin to true\n")); |
6359 | 3 | break; |
6360 | | |
6361 | 2 | case DW_LNS_set_isa: |
6362 | 2 | READ_ULEB (uladv, data, end); |
6363 | 2 | printf (_(" Set ISA to %" PRIu64 "\n"), uladv); |
6364 | 2 | break; |
6365 | | |
6366 | 63 | default: |
6367 | 63 | printf (_(" Unknown opcode %d with operands: "), op_code); |
6368 | | |
6369 | 63 | if (standard_opcodes != NULL) |
6370 | 4.73k | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) |
6371 | 4.67k | { |
6372 | 4.67k | READ_ULEB (uladv, data, end); |
6373 | 4.67k | printf ("%#" PRIx64 "%s", uladv, i == 1 ? "" : ", "); |
6374 | 4.67k | } |
6375 | 63 | putchar ('\n'); |
6376 | 63 | break; |
6377 | 17.4k | } |
6378 | 25.3k | } |
6379 | 263 | putchar ('\n'); |
6380 | 263 | } |
6381 | 282 | } |
6382 | | |
6383 | 244 | return 1; |
6384 | 355 | } |
6385 | | |
6386 | | typedef struct |
6387 | | { |
6388 | | const char *name; |
6389 | | unsigned int directory_index; |
6390 | | unsigned int modification_date; |
6391 | | unsigned int length; |
6392 | | } File_Entry; |
6393 | | |
6394 | | /* Output a decoded representation of the .debug_line section. */ |
6395 | | |
6396 | | static int |
6397 | | display_debug_lines_decoded (struct dwarf_section * section, |
6398 | | unsigned char * start, |
6399 | | unsigned char * data, |
6400 | | unsigned char * end, |
6401 | | void * fileptr) |
6402 | 0 | { |
6403 | 0 | static DWARF2_Internal_LineInfo saved_linfo; |
6404 | |
|
6405 | 0 | introduce (section, false); |
6406 | |
|
6407 | 0 | while (data < end) |
6408 | 0 | { |
6409 | | /* This loop amounts to one iteration per compilation unit. */ |
6410 | 0 | DWARF2_Internal_LineInfo linfo; |
6411 | 0 | unsigned char *standard_opcodes; |
6412 | 0 | unsigned char *end_of_sequence; |
6413 | 0 | int i; |
6414 | 0 | File_Entry *file_table = NULL; |
6415 | 0 | unsigned int n_files = 0; |
6416 | 0 | const char **directory_table = NULL; |
6417 | 0 | unsigned int n_directories = 0; |
6418 | |
|
6419 | 0 | if (startswith (section->name, ".debug_line.") |
6420 | | /* Note: the following does not apply to .debug_line.dwo sections. |
6421 | | These are full debug_line sections. */ |
6422 | 0 | && strcmp (section->name, ".debug_line.dwo") != 0) |
6423 | 0 | { |
6424 | | /* See comment in display_debug_lines_raw(). */ |
6425 | 0 | end_of_sequence = end; |
6426 | 0 | standard_opcodes = NULL; |
6427 | 0 | linfo = saved_linfo; |
6428 | | /* PR 17531: file: 0522b371. */ |
6429 | 0 | if (linfo.li_line_range == 0) |
6430 | 0 | { |
6431 | 0 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
6432 | 0 | return 0; |
6433 | 0 | } |
6434 | 0 | reset_state_machine (linfo.li_default_is_stmt); |
6435 | 0 | } |
6436 | 0 | else |
6437 | 0 | { |
6438 | 0 | unsigned char *hdrptr; |
6439 | |
|
6440 | 0 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
6441 | 0 | & end_of_sequence)) == NULL) |
6442 | 0 | return 0; |
6443 | | |
6444 | | /* PR 17531: file: 0522b371. */ |
6445 | 0 | if (linfo.li_line_range == 0) |
6446 | 0 | { |
6447 | 0 | warn (_("Line range of 0 is invalid, using 1 instead\n")); |
6448 | 0 | linfo.li_line_range = 1; |
6449 | 0 | } |
6450 | 0 | reset_state_machine (linfo.li_default_is_stmt); |
6451 | | |
6452 | | /* Save a pointer to the contents of the Opcodes table. */ |
6453 | 0 | standard_opcodes = hdrptr; |
6454 | | |
6455 | | /* Traverse the Directory table just to count entries. */ |
6456 | 0 | data = standard_opcodes + linfo.li_opcode_base - 1; |
6457 | | /* PR 20440 */ |
6458 | 0 | if (data >= end) |
6459 | 0 | { |
6460 | 0 | warn (_("opcode base of %d extends beyond end of section\n"), |
6461 | 0 | linfo.li_opcode_base); |
6462 | 0 | return 0; |
6463 | 0 | } |
6464 | | |
6465 | 0 | if (linfo.li_version >= 5) |
6466 | 0 | { |
6467 | 0 | unsigned char *format_start, *format; |
6468 | 0 | unsigned int format_count, formati, entryi; |
6469 | |
|
6470 | 0 | load_debug_section_with_follow (line_str, fileptr); |
6471 | | |
6472 | | /* Skip directories format. */ |
6473 | 0 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
6474 | 0 | if (do_checks && format_count > 1) |
6475 | 0 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), |
6476 | 0 | format_count); |
6477 | 0 | format_start = data; |
6478 | 0 | for (formati = 0; formati < format_count; formati++) |
6479 | 0 | { |
6480 | 0 | SKIP_ULEB (data, end); |
6481 | 0 | SKIP_ULEB (data, end); |
6482 | 0 | } |
6483 | |
|
6484 | 0 | READ_ULEB (n_directories, data, end); |
6485 | 0 | if (data >= end) |
6486 | 0 | { |
6487 | 0 | warn (_("Corrupt directories list\n")); |
6488 | 0 | break; |
6489 | 0 | } |
6490 | | |
6491 | 0 | if (n_directories == 0) |
6492 | 0 | directory_table = NULL; |
6493 | 0 | else if (n_directories > section->size) |
6494 | 0 | { |
6495 | 0 | warn (_("number of directories (0x%x) exceeds size of section %s\n"), |
6496 | 0 | n_directories, section->name); |
6497 | 0 | return 0; |
6498 | 0 | } |
6499 | 0 | else |
6500 | 0 | directory_table = (const char **) |
6501 | 0 | xcalloc (n_directories, sizeof (const char *)); |
6502 | | |
6503 | 0 | for (entryi = 0; entryi < n_directories; entryi++) |
6504 | 0 | { |
6505 | 0 | const char **pathp = &directory_table[entryi]; |
6506 | |
|
6507 | 0 | format = format_start; |
6508 | 0 | for (formati = 0; formati < format_count; formati++) |
6509 | 0 | { |
6510 | 0 | uint64_t content_type, form; |
6511 | 0 | uint64_t uvalue; |
6512 | |
|
6513 | 0 | READ_ULEB (content_type, format, end); |
6514 | 0 | READ_ULEB (form, format, end); |
6515 | 0 | if (data >= end) |
6516 | 0 | { |
6517 | 0 | warn (_("Corrupt directories list\n")); |
6518 | 0 | break; |
6519 | 0 | } |
6520 | 0 | switch (content_type) |
6521 | 0 | { |
6522 | 0 | case DW_LNCT_path: |
6523 | 0 | switch (form) |
6524 | 0 | { |
6525 | 0 | case DW_FORM_string: |
6526 | 0 | *pathp = (char *) data; |
6527 | 0 | break; |
6528 | 0 | case DW_FORM_line_strp: |
6529 | 0 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, |
6530 | 0 | end); |
6531 | | /* Remove const by the cast. */ |
6532 | 0 | *pathp = fetch_indirect_line_string (uvalue); |
6533 | 0 | break; |
6534 | 0 | } |
6535 | 0 | break; |
6536 | 0 | } |
6537 | 0 | data = read_and_display_attr_value (0, form, 0, |
6538 | 0 | start, data, end, 0, |
6539 | 0 | linfo.li_address_size, |
6540 | 0 | linfo.li_offset_size, |
6541 | 0 | linfo.li_version, |
6542 | 0 | NULL, 1, section, |
6543 | 0 | NULL, '\t', -1, |
6544 | 0 | false, 0, 0, false); |
6545 | 0 | } |
6546 | 0 | if (data >= end) |
6547 | 0 | { |
6548 | 0 | warn (_("Corrupt directories list\n")); |
6549 | 0 | break; |
6550 | 0 | } |
6551 | 0 | } |
6552 | | |
6553 | | /* Skip files format. */ |
6554 | 0 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
6555 | 0 | if (do_checks && format_count > 5) |
6556 | 0 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), |
6557 | 0 | format_count); |
6558 | |
|
6559 | 0 | format_start = data; |
6560 | 0 | for (formati = 0; formati < format_count; formati++) |
6561 | 0 | { |
6562 | 0 | SKIP_ULEB (data, end); |
6563 | 0 | SKIP_ULEB (data, end); |
6564 | 0 | } |
6565 | |
|
6566 | 0 | READ_ULEB (n_files, data, end); |
6567 | 0 | if (data >= end && n_files > 0) |
6568 | 0 | { |
6569 | 0 | warn (_("Corrupt file name list\n")); |
6570 | 0 | break; |
6571 | 0 | } |
6572 | | |
6573 | 0 | if (n_files == 0) |
6574 | 0 | file_table = NULL; |
6575 | 0 | else if (n_files > section->size) |
6576 | 0 | { |
6577 | 0 | warn (_("number of files (0x%x) exceeds size of section %s\n"), |
6578 | 0 | n_files, section->name); |
6579 | 0 | return 0; |
6580 | 0 | } |
6581 | 0 | else |
6582 | 0 | file_table = (File_Entry *) xcalloc (n_files, |
6583 | 0 | sizeof (File_Entry)); |
6584 | | |
6585 | 0 | for (entryi = 0; entryi < n_files; entryi++) |
6586 | 0 | { |
6587 | 0 | File_Entry *file = &file_table[entryi]; |
6588 | |
|
6589 | 0 | format = format_start; |
6590 | 0 | for (formati = 0; formati < format_count; formati++) |
6591 | 0 | { |
6592 | 0 | uint64_t content_type, form; |
6593 | 0 | uint64_t uvalue; |
6594 | 0 | unsigned char *tmp; |
6595 | |
|
6596 | 0 | READ_ULEB (content_type, format, end); |
6597 | 0 | READ_ULEB (form, format, end); |
6598 | 0 | if (data >= end) |
6599 | 0 | { |
6600 | 0 | warn (_("Corrupt file name list\n")); |
6601 | 0 | break; |
6602 | 0 | } |
6603 | 0 | switch (content_type) |
6604 | 0 | { |
6605 | 0 | case DW_LNCT_path: |
6606 | 0 | switch (form) |
6607 | 0 | { |
6608 | 0 | case DW_FORM_string: |
6609 | 0 | file->name = (char *) data; |
6610 | 0 | break; |
6611 | 0 | case DW_FORM_line_strp: |
6612 | 0 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, |
6613 | 0 | end); |
6614 | | /* Remove const by the cast. */ |
6615 | 0 | file->name = fetch_indirect_line_string (uvalue); |
6616 | 0 | break; |
6617 | 0 | } |
6618 | 0 | break; |
6619 | 0 | case DW_LNCT_directory_index: |
6620 | 0 | switch (form) |
6621 | 0 | { |
6622 | 0 | case DW_FORM_data1: |
6623 | 0 | SAFE_BYTE_GET (file->directory_index, data, 1, |
6624 | 0 | end); |
6625 | 0 | break; |
6626 | 0 | case DW_FORM_data2: |
6627 | 0 | SAFE_BYTE_GET (file->directory_index, data, 2, |
6628 | 0 | end); |
6629 | 0 | break; |
6630 | 0 | case DW_FORM_udata: |
6631 | 0 | tmp = data; |
6632 | 0 | READ_ULEB (file->directory_index, tmp, end); |
6633 | 0 | break; |
6634 | 0 | } |
6635 | 0 | break; |
6636 | 0 | } |
6637 | 0 | data = read_and_display_attr_value (0, form, 0, |
6638 | 0 | start, data, end, 0, |
6639 | 0 | linfo.li_address_size, |
6640 | 0 | linfo.li_offset_size, |
6641 | 0 | linfo.li_version, |
6642 | 0 | NULL, 1, section, |
6643 | 0 | NULL, '\t', -1, |
6644 | 0 | false, 0, 0, false); |
6645 | 0 | } |
6646 | 0 | if (data >= end) |
6647 | 0 | { |
6648 | 0 | warn (_("Corrupt file name list\n")); |
6649 | 0 | break; |
6650 | 0 | } |
6651 | 0 | } |
6652 | 0 | } |
6653 | 0 | else |
6654 | 0 | { |
6655 | 0 | if (*data != 0) |
6656 | 0 | { |
6657 | 0 | char *ptr_directory_table = (char *) data; |
6658 | |
|
6659 | 0 | while (data < end && *data != 0) |
6660 | 0 | { |
6661 | 0 | data += strnlen ((char *) data, end - data); |
6662 | 0 | if (data < end) |
6663 | 0 | data++; |
6664 | 0 | n_directories++; |
6665 | 0 | } |
6666 | | |
6667 | | /* PR 20440 */ |
6668 | 0 | if (data >= end) |
6669 | 0 | { |
6670 | 0 | warn (_("directory table ends unexpectedly\n")); |
6671 | 0 | n_directories = 0; |
6672 | 0 | break; |
6673 | 0 | } |
6674 | | |
6675 | | /* Go through the directory table again to save the directories. */ |
6676 | 0 | directory_table = (const char **) |
6677 | 0 | xmalloc (n_directories * sizeof (const char *)); |
6678 | |
|
6679 | 0 | i = 0; |
6680 | 0 | while (*ptr_directory_table != 0) |
6681 | 0 | { |
6682 | 0 | directory_table[i] = ptr_directory_table; |
6683 | 0 | ptr_directory_table += strlen (ptr_directory_table) + 1; |
6684 | 0 | i++; |
6685 | 0 | } |
6686 | 0 | } |
6687 | | /* Skip the NUL at the end of the table. */ |
6688 | 0 | data++; |
6689 | | |
6690 | | /* Traverse the File Name table just to count the entries. */ |
6691 | 0 | if (data < end && *data != 0) |
6692 | 0 | { |
6693 | 0 | unsigned char *ptr_file_name_table = data; |
6694 | |
|
6695 | 0 | while (data < end && *data != 0) |
6696 | 0 | { |
6697 | | /* Skip Name, directory index, last modification |
6698 | | time and length of file. */ |
6699 | 0 | data += strnlen ((char *) data, end - data); |
6700 | 0 | if (data < end) |
6701 | 0 | data++; |
6702 | 0 | SKIP_ULEB (data, end); |
6703 | 0 | SKIP_ULEB (data, end); |
6704 | 0 | SKIP_ULEB (data, end); |
6705 | 0 | n_files++; |
6706 | 0 | } |
6707 | |
|
6708 | 0 | if (data >= end) |
6709 | 0 | { |
6710 | 0 | warn (_("file table ends unexpectedly\n")); |
6711 | 0 | n_files = 0; |
6712 | 0 | break; |
6713 | 0 | } |
6714 | | |
6715 | | /* Go through the file table again to save the strings. */ |
6716 | 0 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); |
6717 | |
|
6718 | 0 | i = 0; |
6719 | 0 | while (*ptr_file_name_table != 0) |
6720 | 0 | { |
6721 | 0 | file_table[i].name = (char *) ptr_file_name_table; |
6722 | 0 | ptr_file_name_table |
6723 | 0 | += strlen ((char *) ptr_file_name_table) + 1; |
6724 | | |
6725 | | /* We are not interested in directory, time or size. */ |
6726 | 0 | READ_ULEB (file_table[i].directory_index, |
6727 | 0 | ptr_file_name_table, end); |
6728 | 0 | READ_ULEB (file_table[i].modification_date, |
6729 | 0 | ptr_file_name_table, end); |
6730 | 0 | READ_ULEB (file_table[i].length, |
6731 | 0 | ptr_file_name_table, end); |
6732 | 0 | i++; |
6733 | 0 | } |
6734 | 0 | i = 0; |
6735 | 0 | } |
6736 | | |
6737 | | /* Skip the NUL at the end of the table. */ |
6738 | 0 | data++; |
6739 | 0 | } |
6740 | | |
6741 | | /* Print the Compilation Unit's name and a header. */ |
6742 | 0 | if (file_table == NULL) |
6743 | 0 | printf (_("CU: No directory table\n")); |
6744 | 0 | else if (directory_table == NULL) |
6745 | 0 | printf (_("CU: %s:\n"), null_name (file_table[0].name)); |
6746 | 0 | else |
6747 | 0 | { |
6748 | 0 | unsigned int ix = file_table[0].directory_index; |
6749 | 0 | const char *directory; |
6750 | |
|
6751 | 0 | if (ix == 0 && linfo.li_version < 5) |
6752 | 0 | directory = "."; |
6753 | | /* PR 20439 */ |
6754 | 0 | else if (n_directories == 0) |
6755 | 0 | directory = _("<unknown>"); |
6756 | 0 | else |
6757 | 0 | { |
6758 | 0 | if (linfo.li_version < 5) |
6759 | 0 | --ix; |
6760 | 0 | if (ix >= n_directories) |
6761 | 0 | { |
6762 | 0 | warn (_("directory index %u " |
6763 | 0 | ">= number of directories %u\n"), |
6764 | 0 | ix, n_directories); |
6765 | 0 | directory = _("<corrupt>"); |
6766 | 0 | } |
6767 | 0 | else |
6768 | 0 | directory = directory_table[ix]; |
6769 | 0 | } |
6770 | 0 | if (do_wide) |
6771 | 0 | printf (_("CU: %s/%s:\n"), |
6772 | 0 | null_name (directory), |
6773 | 0 | null_name (file_table[0].name)); |
6774 | 0 | else |
6775 | 0 | printf ("%s:\n", null_name (file_table[0].name)); |
6776 | 0 | } |
6777 | |
|
6778 | 0 | if (n_files > 0) |
6779 | 0 | { |
6780 | 0 | if (do_wide) |
6781 | 0 | printf (_("File name Line number Starting address View Stmt\n")); |
6782 | 0 | else |
6783 | 0 | printf (_("File name Line number Starting address View Stmt\n")); |
6784 | 0 | } |
6785 | 0 | else |
6786 | 0 | printf (_("CU: Empty file name table\n")); |
6787 | 0 | saved_linfo = linfo; |
6788 | 0 | } |
6789 | | |
6790 | | /* This loop iterates through the Dwarf Line Number Program. */ |
6791 | 0 | while (data < end_of_sequence) |
6792 | 0 | { |
6793 | 0 | unsigned char op_code; |
6794 | 0 | int xop; |
6795 | 0 | int adv; |
6796 | 0 | unsigned long int uladv; |
6797 | 0 | int is_special_opcode = 0; |
6798 | |
|
6799 | 0 | op_code = *data++; |
6800 | 0 | xop = op_code; |
6801 | |
|
6802 | 0 | if (op_code >= linfo.li_opcode_base) |
6803 | 0 | { |
6804 | 0 | op_code -= linfo.li_opcode_base; |
6805 | 0 | uladv = (op_code / linfo.li_line_range); |
6806 | 0 | if (linfo.li_max_ops_per_insn == 1) |
6807 | 0 | { |
6808 | 0 | uladv *= linfo.li_min_insn_length; |
6809 | 0 | state_machine_regs.address += uladv; |
6810 | 0 | if (uladv) |
6811 | 0 | state_machine_regs.view = 0; |
6812 | 0 | } |
6813 | 0 | else |
6814 | 0 | { |
6815 | 0 | unsigned addrdelta |
6816 | 0 | = ((state_machine_regs.op_index + uladv) |
6817 | 0 | / linfo.li_max_ops_per_insn) |
6818 | 0 | * linfo.li_min_insn_length; |
6819 | 0 | state_machine_regs.address |
6820 | 0 | += addrdelta; |
6821 | 0 | state_machine_regs.op_index |
6822 | 0 | = (state_machine_regs.op_index + uladv) |
6823 | 0 | % linfo.li_max_ops_per_insn; |
6824 | 0 | if (addrdelta) |
6825 | 0 | state_machine_regs.view = 0; |
6826 | 0 | } |
6827 | |
|
6828 | 0 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
6829 | 0 | state_machine_regs.line += adv; |
6830 | 0 | is_special_opcode = 1; |
6831 | | /* Increment view after printing this row. */ |
6832 | 0 | } |
6833 | 0 | else |
6834 | 0 | switch (op_code) |
6835 | 0 | { |
6836 | 0 | case DW_LNS_extended_op: |
6837 | 0 | { |
6838 | 0 | unsigned int ext_op_code_len; |
6839 | 0 | unsigned char ext_op_code; |
6840 | 0 | unsigned char *op_code_end; |
6841 | 0 | unsigned char *op_code_data = data; |
6842 | |
|
6843 | 0 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); |
6844 | 0 | op_code_end = op_code_data + ext_op_code_len; |
6845 | 0 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) |
6846 | 0 | { |
6847 | 0 | warn (_("Badly formed extended line op encountered!\n")); |
6848 | 0 | break; |
6849 | 0 | } |
6850 | 0 | ext_op_code = *op_code_data++; |
6851 | 0 | xop = ext_op_code; |
6852 | 0 | xop = -xop; |
6853 | |
|
6854 | 0 | switch (ext_op_code) |
6855 | 0 | { |
6856 | 0 | case DW_LNE_end_sequence: |
6857 | | /* Reset stuff after printing this row. */ |
6858 | 0 | break; |
6859 | 0 | case DW_LNE_set_address: |
6860 | 0 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, |
6861 | 0 | op_code_data, |
6862 | 0 | op_code_end - op_code_data, |
6863 | 0 | op_code_end); |
6864 | 0 | state_machine_regs.op_index = 0; |
6865 | 0 | state_machine_regs.view = 0; |
6866 | 0 | break; |
6867 | 0 | case DW_LNE_define_file: |
6868 | 0 | file_table = (File_Entry *) xrealloc |
6869 | 0 | (file_table, (n_files + 1) * sizeof (File_Entry)); |
6870 | |
|
6871 | 0 | ++state_machine_regs.last_file_entry; |
6872 | | /* Source file name. */ |
6873 | 0 | file_table[n_files].name = (char *) op_code_data; |
6874 | 0 | op_code_data += strlen ((char *) op_code_data) + 1; |
6875 | | /* Directory index. */ |
6876 | 0 | READ_ULEB (file_table[n_files].directory_index, |
6877 | 0 | op_code_data, op_code_end); |
6878 | | /* Last modification time. */ |
6879 | 0 | READ_ULEB (file_table[n_files].modification_date, |
6880 | 0 | op_code_data, op_code_end); |
6881 | | /* File length. */ |
6882 | 0 | READ_ULEB (file_table[n_files].length, |
6883 | 0 | op_code_data, op_code_end); |
6884 | 0 | n_files++; |
6885 | 0 | break; |
6886 | | |
6887 | 0 | case DW_LNE_set_discriminator: |
6888 | 0 | case DW_LNE_HP_set_sequence: |
6889 | | /* Simply ignored. */ |
6890 | 0 | break; |
6891 | | |
6892 | 0 | default: |
6893 | 0 | printf (_("UNKNOWN (%u): length %ld\n"), |
6894 | 0 | ext_op_code, (long int) (op_code_data - data)); |
6895 | 0 | break; |
6896 | 0 | } |
6897 | 0 | data = op_code_end; |
6898 | 0 | break; |
6899 | 0 | } |
6900 | 0 | case DW_LNS_copy: |
6901 | | /* Increment view after printing this row. */ |
6902 | 0 | break; |
6903 | | |
6904 | 0 | case DW_LNS_advance_pc: |
6905 | 0 | READ_ULEB (uladv, data, end); |
6906 | 0 | if (linfo.li_max_ops_per_insn == 1) |
6907 | 0 | { |
6908 | 0 | uladv *= linfo.li_min_insn_length; |
6909 | 0 | state_machine_regs.address += uladv; |
6910 | 0 | if (uladv) |
6911 | 0 | state_machine_regs.view = 0; |
6912 | 0 | } |
6913 | 0 | else |
6914 | 0 | { |
6915 | 0 | unsigned addrdelta |
6916 | 0 | = ((state_machine_regs.op_index + uladv) |
6917 | 0 | / linfo.li_max_ops_per_insn) |
6918 | 0 | * linfo.li_min_insn_length; |
6919 | 0 | state_machine_regs.address |
6920 | 0 | += addrdelta; |
6921 | 0 | state_machine_regs.op_index |
6922 | 0 | = (state_machine_regs.op_index + uladv) |
6923 | 0 | % linfo.li_max_ops_per_insn; |
6924 | 0 | if (addrdelta) |
6925 | 0 | state_machine_regs.view = 0; |
6926 | 0 | } |
6927 | 0 | break; |
6928 | | |
6929 | 0 | case DW_LNS_advance_line: |
6930 | 0 | READ_SLEB (adv, data, end); |
6931 | 0 | state_machine_regs.line += adv; |
6932 | 0 | break; |
6933 | | |
6934 | 0 | case DW_LNS_set_file: |
6935 | 0 | READ_ULEB (uladv, data, end); |
6936 | 0 | state_machine_regs.file = uladv; |
6937 | |
|
6938 | 0 | unsigned file = state_machine_regs.file; |
6939 | 0 | if (linfo.li_version < 5) |
6940 | 0 | --file; |
6941 | |
|
6942 | 0 | if (file_table == NULL || n_files == 0) |
6943 | 0 | printf (_("\n [Use file table entry %d]\n"), file); |
6944 | | /* PR 20439 */ |
6945 | 0 | else if (file >= n_files) |
6946 | 0 | { |
6947 | 0 | warn (_("file index %u >= number of files %u\n"), |
6948 | 0 | file, n_files); |
6949 | 0 | printf (_("\n <over large file table index %u>"), file); |
6950 | 0 | } |
6951 | 0 | else |
6952 | 0 | { |
6953 | 0 | unsigned dir = file_table[file].directory_index; |
6954 | 0 | if (dir == 0 && linfo.li_version < 5) |
6955 | | /* If directory index is 0, that means compilation |
6956 | | current directory. bfd/dwarf2.c shows |
6957 | | DW_AT_comp_dir here but in keeping with the |
6958 | | readelf practice of minimal interpretation of |
6959 | | file data, we show "./". */ |
6960 | 0 | printf ("\n./%s:[++]\n", |
6961 | 0 | null_name (file_table[file].name)); |
6962 | 0 | else if (directory_table == NULL || n_directories == 0) |
6963 | 0 | printf (_("\n [Use file %s " |
6964 | 0 | "in directory table entry %d]\n"), |
6965 | 0 | null_name (file_table[file].name), dir); |
6966 | 0 | else |
6967 | 0 | { |
6968 | 0 | if (linfo.li_version < 5) |
6969 | 0 | --dir; |
6970 | | /* PR 20439 */ |
6971 | 0 | if (dir >= n_directories) |
6972 | 0 | { |
6973 | 0 | warn (_("directory index %u " |
6974 | 0 | ">= number of directories %u\n"), |
6975 | 0 | dir, n_directories); |
6976 | 0 | printf (_("\n <over large directory table entry " |
6977 | 0 | "%u>\n"), dir); |
6978 | 0 | } |
6979 | 0 | else |
6980 | 0 | printf ("\n%s/%s:\n", |
6981 | 0 | null_name (directory_table[dir]), |
6982 | 0 | null_name (file_table[file].name)); |
6983 | 0 | } |
6984 | 0 | } |
6985 | 0 | break; |
6986 | | |
6987 | 0 | case DW_LNS_set_column: |
6988 | 0 | READ_ULEB (uladv, data, end); |
6989 | 0 | state_machine_regs.column = uladv; |
6990 | 0 | break; |
6991 | | |
6992 | 0 | case DW_LNS_negate_stmt: |
6993 | 0 | adv = state_machine_regs.is_stmt; |
6994 | 0 | adv = ! adv; |
6995 | 0 | state_machine_regs.is_stmt = adv; |
6996 | 0 | break; |
6997 | | |
6998 | 0 | case DW_LNS_set_basic_block: |
6999 | 0 | state_machine_regs.basic_block = 1; |
7000 | 0 | break; |
7001 | | |
7002 | 0 | case DW_LNS_const_add_pc: |
7003 | 0 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); |
7004 | 0 | if (linfo.li_max_ops_per_insn == 1) |
7005 | 0 | { |
7006 | 0 | uladv *= linfo.li_min_insn_length; |
7007 | 0 | state_machine_regs.address += uladv; |
7008 | 0 | if (uladv) |
7009 | 0 | state_machine_regs.view = 0; |
7010 | 0 | } |
7011 | 0 | else |
7012 | 0 | { |
7013 | 0 | unsigned addrdelta |
7014 | 0 | = ((state_machine_regs.op_index + uladv) |
7015 | 0 | / linfo.li_max_ops_per_insn) |
7016 | 0 | * linfo.li_min_insn_length; |
7017 | 0 | state_machine_regs.address |
7018 | 0 | += addrdelta; |
7019 | 0 | state_machine_regs.op_index |
7020 | 0 | = (state_machine_regs.op_index + uladv) |
7021 | 0 | % linfo.li_max_ops_per_insn; |
7022 | 0 | if (addrdelta) |
7023 | 0 | state_machine_regs.view = 0; |
7024 | 0 | } |
7025 | 0 | break; |
7026 | | |
7027 | 0 | case DW_LNS_fixed_advance_pc: |
7028 | 0 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); |
7029 | 0 | state_machine_regs.address += uladv; |
7030 | 0 | state_machine_regs.op_index = 0; |
7031 | | /* Do NOT reset view. */ |
7032 | 0 | break; |
7033 | | |
7034 | 0 | case DW_LNS_set_prologue_end: |
7035 | 0 | break; |
7036 | | |
7037 | 0 | case DW_LNS_set_epilogue_begin: |
7038 | 0 | break; |
7039 | | |
7040 | 0 | case DW_LNS_set_isa: |
7041 | 0 | READ_ULEB (uladv, data, end); |
7042 | 0 | printf (_(" Set ISA to %lu\n"), uladv); |
7043 | 0 | break; |
7044 | | |
7045 | 0 | default: |
7046 | 0 | printf (_(" Unknown opcode %d with operands: "), op_code); |
7047 | |
|
7048 | 0 | if (standard_opcodes != NULL) |
7049 | 0 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) |
7050 | 0 | { |
7051 | 0 | uint64_t val; |
7052 | |
|
7053 | 0 | READ_ULEB (val, data, end); |
7054 | 0 | printf ("%#" PRIx64 "%s", val, i == 1 ? "" : ", "); |
7055 | 0 | } |
7056 | 0 | putchar ('\n'); |
7057 | 0 | break; |
7058 | 0 | } |
7059 | | |
7060 | | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
7061 | | to the DWARF address/line matrix. */ |
7062 | 0 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
7063 | 0 | || (xop == DW_LNS_copy)) |
7064 | 0 | { |
7065 | 0 | const unsigned int MAX_FILENAME_LENGTH = 35; |
7066 | 0 | char *fileName = NULL; |
7067 | 0 | char *newFileName = NULL; |
7068 | 0 | size_t fileNameLength; |
7069 | |
|
7070 | 0 | if (file_table) |
7071 | 0 | { |
7072 | 0 | unsigned indx = state_machine_regs.file; |
7073 | |
|
7074 | 0 | if (linfo.li_version < 5) |
7075 | 0 | --indx; |
7076 | | /* PR 20439 */ |
7077 | 0 | if (indx >= n_files) |
7078 | 0 | { |
7079 | 0 | warn (_("file index %u >= number of files %u\n"), |
7080 | 0 | indx, n_files); |
7081 | 0 | fileName = _("<corrupt>"); |
7082 | 0 | } |
7083 | 0 | else |
7084 | 0 | fileName = (char *) file_table[indx].name; |
7085 | 0 | } |
7086 | 0 | if (!fileName) |
7087 | 0 | fileName = _("<unknown>"); |
7088 | |
|
7089 | 0 | fileNameLength = strlen (fileName); |
7090 | 0 | newFileName = fileName; |
7091 | 0 | if (fileNameLength > MAX_FILENAME_LENGTH && !do_wide) |
7092 | 0 | { |
7093 | 0 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); |
7094 | | /* Truncate file name */ |
7095 | 0 | memcpy (newFileName, |
7096 | 0 | fileName + fileNameLength - MAX_FILENAME_LENGTH, |
7097 | 0 | MAX_FILENAME_LENGTH); |
7098 | 0 | newFileName[MAX_FILENAME_LENGTH] = 0; |
7099 | 0 | } |
7100 | | |
7101 | | /* A row with end_seq set to true has a meaningful address, but |
7102 | | the other information in the same row is not significant. |
7103 | | In such a row, print line as "-", and don't print |
7104 | | view/is_stmt. */ |
7105 | 0 | if (!do_wide || fileNameLength <= MAX_FILENAME_LENGTH) |
7106 | 0 | { |
7107 | 0 | if (linfo.li_max_ops_per_insn == 1) |
7108 | 0 | { |
7109 | 0 | if (xop == -DW_LNE_end_sequence) |
7110 | 0 | printf ("%-31s %11s %#18" PRIx64, |
7111 | 0 | newFileName, "-", |
7112 | 0 | state_machine_regs.address); |
7113 | 0 | else |
7114 | 0 | printf ("%-31s %11d %#18" PRIx64, |
7115 | 0 | newFileName, state_machine_regs.line, |
7116 | 0 | state_machine_regs.address); |
7117 | 0 | } |
7118 | 0 | else |
7119 | 0 | { |
7120 | 0 | if (xop == -DW_LNE_end_sequence) |
7121 | 0 | printf ("%-31s %11s %#18" PRIx64 "[%d]", |
7122 | 0 | newFileName, "-", |
7123 | 0 | state_machine_regs.address, |
7124 | 0 | state_machine_regs.op_index); |
7125 | 0 | else |
7126 | 0 | printf ("%-31s %11d %#18" PRIx64 "[%d]", |
7127 | 0 | newFileName, state_machine_regs.line, |
7128 | 0 | state_machine_regs.address, |
7129 | 0 | state_machine_regs.op_index); |
7130 | 0 | } |
7131 | 0 | } |
7132 | 0 | else |
7133 | 0 | { |
7134 | 0 | if (linfo.li_max_ops_per_insn == 1) |
7135 | 0 | { |
7136 | 0 | if (xop == -DW_LNE_end_sequence) |
7137 | 0 | printf ("%s %11s %#18" PRIx64, |
7138 | 0 | newFileName, "-", |
7139 | 0 | state_machine_regs.address); |
7140 | 0 | else |
7141 | 0 | printf ("%s %11d %#18" PRIx64, |
7142 | 0 | newFileName, state_machine_regs.line, |
7143 | 0 | state_machine_regs.address); |
7144 | 0 | } |
7145 | 0 | else |
7146 | 0 | { |
7147 | 0 | if (xop == -DW_LNE_end_sequence) |
7148 | 0 | printf ("%s %11s %#18" PRIx64 "[%d]", |
7149 | 0 | newFileName, "-", |
7150 | 0 | state_machine_regs.address, |
7151 | 0 | state_machine_regs.op_index); |
7152 | 0 | else |
7153 | 0 | printf ("%s %11d %#18" PRIx64 "[%d]", |
7154 | 0 | newFileName, state_machine_regs.line, |
7155 | 0 | state_machine_regs.address, |
7156 | 0 | state_machine_regs.op_index); |
7157 | 0 | } |
7158 | 0 | } |
7159 | |
|
7160 | 0 | if (xop != -DW_LNE_end_sequence) |
7161 | 0 | { |
7162 | 0 | if (state_machine_regs.view) |
7163 | 0 | printf (" %6u", state_machine_regs.view); |
7164 | 0 | else |
7165 | 0 | printf (" "); |
7166 | |
|
7167 | 0 | if (state_machine_regs.is_stmt) |
7168 | 0 | printf (" x"); |
7169 | 0 | } |
7170 | |
|
7171 | 0 | putchar ('\n'); |
7172 | 0 | state_machine_regs.view++; |
7173 | |
|
7174 | 0 | if (xop == -DW_LNE_end_sequence) |
7175 | 0 | { |
7176 | 0 | reset_state_machine (linfo.li_default_is_stmt); |
7177 | 0 | putchar ('\n'); |
7178 | 0 | } |
7179 | |
|
7180 | 0 | if (newFileName != fileName) |
7181 | 0 | free (newFileName); |
7182 | 0 | } |
7183 | 0 | } |
7184 | | |
7185 | 0 | if (file_table) |
7186 | 0 | { |
7187 | 0 | free (file_table); |
7188 | 0 | file_table = NULL; |
7189 | 0 | n_files = 0; |
7190 | 0 | } |
7191 | |
|
7192 | 0 | if (directory_table) |
7193 | 0 | { |
7194 | 0 | free (directory_table); |
7195 | 0 | directory_table = NULL; |
7196 | 0 | n_directories = 0; |
7197 | 0 | } |
7198 | |
|
7199 | 0 | putchar ('\n'); |
7200 | 0 | } |
7201 | | |
7202 | 0 | return 1; |
7203 | 0 | } |
7204 | | |
7205 | | static int |
7206 | | display_debug_lines (struct dwarf_section *section, void *file) |
7207 | 355 | { |
7208 | 355 | unsigned char *data = section->start; |
7209 | 355 | unsigned char *end = data + section->size; |
7210 | 355 | int retValRaw = 1; |
7211 | 355 | int retValDecoded = 1; |
7212 | | |
7213 | 355 | if (do_debug_lines == 0) |
7214 | 0 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; |
7215 | | |
7216 | 355 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
7217 | 355 | retValRaw = display_debug_lines_raw (section, data, end, file); |
7218 | | |
7219 | 355 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
7220 | 0 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
7221 | | |
7222 | 355 | if (!retValRaw || !retValDecoded) |
7223 | 111 | return 0; |
7224 | | |
7225 | 244 | return 1; |
7226 | 355 | } |
7227 | | |
7228 | | static debug_info * |
7229 | | find_debug_info_for_offset (uint64_t offset) |
7230 | 224 | { |
7231 | 224 | unsigned int i; |
7232 | | |
7233 | 224 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
7234 | 0 | return NULL; |
7235 | | |
7236 | 238 | for (i = 0; i < num_debug_info_entries; i++) |
7237 | 231 | if (debug_information[i].cu_offset == offset) |
7238 | 217 | return debug_information + i; |
7239 | | |
7240 | 7 | return NULL; |
7241 | 224 | } |
7242 | | |
7243 | | static const char * |
7244 | | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) |
7245 | 55 | { |
7246 | | /* See gdb/gdb-index.h. */ |
7247 | 55 | static const char * const kinds[] = |
7248 | 55 | { |
7249 | 55 | N_ ("no info"), |
7250 | 55 | N_ ("type"), |
7251 | 55 | N_ ("variable"), |
7252 | 55 | N_ ("function"), |
7253 | 55 | N_ ("other"), |
7254 | 55 | N_ ("unused5"), |
7255 | 55 | N_ ("unused6"), |
7256 | 55 | N_ ("unused7") |
7257 | 55 | }; |
7258 | | |
7259 | 55 | return _ (kinds[kind]); |
7260 | 55 | } |
7261 | | |
7262 | | static int |
7263 | | display_debug_pubnames_worker (struct dwarf_section *section, |
7264 | | void *file ATTRIBUTE_UNUSED, |
7265 | | int is_gnu) |
7266 | 210 | { |
7267 | 210 | DWARF2_Internal_PubNames names; |
7268 | 210 | unsigned char *start = section->start; |
7269 | 210 | unsigned char *end = start + section->size; |
7270 | | |
7271 | | /* It does not matter if this load fails, |
7272 | | we test for that later on. */ |
7273 | 210 | load_debug_info (file); |
7274 | | |
7275 | 210 | introduce (section, false); |
7276 | | |
7277 | 872 | while (start < end) |
7278 | 761 | { |
7279 | 761 | unsigned char *data; |
7280 | 761 | unsigned long sec_off = start - section->start; |
7281 | 761 | unsigned int offset_size; |
7282 | | |
7283 | 761 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
7284 | 761 | if (names.pn_length == 0xffffffff) |
7285 | 8 | { |
7286 | 8 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
7287 | 8 | offset_size = 8; |
7288 | 8 | } |
7289 | 753 | else |
7290 | 753 | offset_size = 4; |
7291 | | |
7292 | 761 | if (names.pn_length > (size_t) (end - start)) |
7293 | 99 | { |
7294 | 99 | warn (_("Debug info is corrupted, " |
7295 | 99 | "%s header at %#lx has length %#" PRIx64 "\n"), |
7296 | 99 | section->name, sec_off, names.pn_length); |
7297 | 99 | break; |
7298 | 99 | } |
7299 | | |
7300 | 662 | data = start; |
7301 | 662 | start += names.pn_length; |
7302 | | |
7303 | 662 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, start); |
7304 | 662 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, start); |
7305 | | |
7306 | 662 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
7307 | 196 | && num_debug_info_entries > 0 |
7308 | 196 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
7309 | 4 | warn (_(".debug_info offset of %#" PRIx64 |
7310 | 4 | " in %s section does not point to a CU header.\n"), |
7311 | 4 | names.pn_offset, section->name); |
7312 | | |
7313 | 662 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, start); |
7314 | | |
7315 | 662 | printf (_(" Length: %" PRId64 "\n"), |
7316 | 662 | names.pn_length); |
7317 | 662 | printf (_(" Version: %d\n"), |
7318 | 662 | names.pn_version); |
7319 | 662 | printf (_(" Offset into .debug_info section: %#" PRIx64 "\n"), |
7320 | 662 | names.pn_offset); |
7321 | 662 | printf (_(" Size of area in .debug_info section: %" PRId64 "\n"), |
7322 | 662 | names.pn_size); |
7323 | | |
7324 | 662 | if (names.pn_version != 2 && names.pn_version != 3) |
7325 | 606 | { |
7326 | 606 | static int warned = 0; |
7327 | | |
7328 | 606 | if (! warned) |
7329 | 1 | { |
7330 | 1 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); |
7331 | 1 | warned = 1; |
7332 | 1 | } |
7333 | | |
7334 | 606 | continue; |
7335 | 606 | } |
7336 | | |
7337 | 56 | if (is_gnu) |
7338 | 28 | printf (_("\n Offset Kind Name\n")); |
7339 | 28 | else |
7340 | 28 | printf (_("\n Offset\tName\n")); |
7341 | | |
7342 | 162 | while (1) |
7343 | 162 | { |
7344 | 162 | size_t maxprint; |
7345 | 162 | uint64_t offset; |
7346 | | |
7347 | 162 | SAFE_BYTE_GET_AND_INC (offset, data, offset_size, start); |
7348 | | |
7349 | 162 | if (offset == 0) |
7350 | 52 | break; |
7351 | | |
7352 | 110 | if (data >= start) |
7353 | 2 | break; |
7354 | 108 | maxprint = (start - data) - 1; |
7355 | | |
7356 | 108 | if (is_gnu) |
7357 | 55 | { |
7358 | 55 | unsigned int kind_data; |
7359 | 55 | gdb_index_symbol_kind kind; |
7360 | 55 | const char *kind_name; |
7361 | 55 | int is_static; |
7362 | | |
7363 | 55 | SAFE_BYTE_GET_AND_INC (kind_data, data, 1, start); |
7364 | 55 | maxprint --; |
7365 | | /* GCC computes the kind as the upper byte in the CU index |
7366 | | word, and then right shifts it by the CU index size. |
7367 | | Left shift KIND to where the gdb-index.h accessor macros |
7368 | | can use it. */ |
7369 | 55 | kind_data <<= GDB_INDEX_CU_BITSIZE; |
7370 | 55 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); |
7371 | 55 | kind_name = get_gdb_index_symbol_kind_name (kind); |
7372 | 55 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); |
7373 | 55 | printf (" %-6" PRIx64 " %s,%-10s %.*s\n", |
7374 | 55 | offset, is_static ? _("s") : _("g"), |
7375 | 55 | kind_name, (int) maxprint, data); |
7376 | 55 | } |
7377 | 53 | else |
7378 | 53 | printf (" %-6" PRIx64 "\t%.*s\n", |
7379 | 53 | offset, (int) maxprint, data); |
7380 | | |
7381 | 108 | data += strnlen ((char *) data, maxprint); |
7382 | 108 | if (data < start) |
7383 | 108 | data++; |
7384 | 108 | if (data >= start) |
7385 | 2 | break; |
7386 | 108 | } |
7387 | 56 | } |
7388 | | |
7389 | 210 | printf ("\n"); |
7390 | 210 | return 1; |
7391 | 210 | } |
7392 | | |
7393 | | static int |
7394 | | display_debug_pubnames (struct dwarf_section *section, void *file) |
7395 | 103 | { |
7396 | 103 | return display_debug_pubnames_worker (section, file, 0); |
7397 | 103 | } |
7398 | | |
7399 | | static int |
7400 | | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) |
7401 | 107 | { |
7402 | 107 | return display_debug_pubnames_worker (section, file, 1); |
7403 | 107 | } |
7404 | | |
7405 | | static int |
7406 | | display_debug_macinfo (struct dwarf_section *section, |
7407 | | void *file ATTRIBUTE_UNUSED) |
7408 | 56 | { |
7409 | 56 | unsigned char *start = section->start; |
7410 | 56 | unsigned char *end = start + section->size; |
7411 | 56 | unsigned char *curr = start; |
7412 | 56 | enum dwarf_macinfo_record_type op; |
7413 | | |
7414 | 56 | introduce (section, false); |
7415 | | |
7416 | 409 | while (curr < end) |
7417 | 353 | { |
7418 | 353 | unsigned int lineno; |
7419 | 353 | const unsigned char *string; |
7420 | | |
7421 | 353 | op = (enum dwarf_macinfo_record_type) *curr; |
7422 | 353 | curr++; |
7423 | | |
7424 | 353 | switch (op) |
7425 | 353 | { |
7426 | 7 | case DW_MACINFO_start_file: |
7427 | 7 | { |
7428 | 7 | unsigned int filenum; |
7429 | | |
7430 | 7 | READ_ULEB (lineno, curr, end); |
7431 | 7 | READ_ULEB (filenum, curr, end); |
7432 | 7 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
7433 | 7 | lineno, filenum); |
7434 | 7 | } |
7435 | 7 | break; |
7436 | | |
7437 | 7 | case DW_MACINFO_end_file: |
7438 | 7 | printf (_(" DW_MACINFO_end_file\n")); |
7439 | 7 | break; |
7440 | | |
7441 | 47 | case DW_MACINFO_define: |
7442 | 47 | READ_ULEB (lineno, curr, end); |
7443 | 47 | string = curr; |
7444 | 47 | curr += strnlen ((char *) string, end - string); |
7445 | 47 | printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"), |
7446 | 47 | lineno, (int) (curr - string), string); |
7447 | 47 | if (curr < end) |
7448 | 37 | curr++; |
7449 | 47 | break; |
7450 | | |
7451 | 33 | case DW_MACINFO_undef: |
7452 | 33 | READ_ULEB (lineno, curr, end); |
7453 | 33 | string = curr; |
7454 | 33 | curr += strnlen ((char *) string, end - string); |
7455 | 33 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"), |
7456 | 33 | lineno, (int) (curr - string), string); |
7457 | 33 | if (curr < end) |
7458 | 33 | curr++; |
7459 | 33 | break; |
7460 | | |
7461 | 8 | case DW_MACINFO_vendor_ext: |
7462 | 8 | { |
7463 | 8 | unsigned int constant; |
7464 | | |
7465 | 8 | READ_ULEB (constant, curr, end); |
7466 | 8 | string = curr; |
7467 | 8 | curr += strnlen ((char *) string, end - string); |
7468 | 8 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"), |
7469 | 8 | constant, (int) (curr - string), string); |
7470 | 8 | if (curr < end) |
7471 | 7 | curr++; |
7472 | 8 | } |
7473 | 8 | break; |
7474 | 353 | } |
7475 | 353 | } |
7476 | | |
7477 | 56 | return 1; |
7478 | 56 | } |
7479 | | |
7480 | | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
7481 | | filename and dirname corresponding to file name table entry with index |
7482 | | FILEIDX. Return NULL on failure. */ |
7483 | | |
7484 | | static unsigned char * |
7485 | | get_line_filename_and_dirname (uint64_t line_offset, |
7486 | | uint64_t fileidx, |
7487 | | unsigned char **dir_name) |
7488 | 5 | { |
7489 | 5 | struct dwarf_section *section = &debug_displays [line].section; |
7490 | 5 | unsigned char *hdrptr, *dirtable, *file_name; |
7491 | 5 | unsigned int offset_size; |
7492 | 5 | unsigned int version, opcode_base; |
7493 | 5 | uint64_t length, diridx; |
7494 | 5 | const unsigned char * end; |
7495 | | |
7496 | 5 | *dir_name = NULL; |
7497 | 5 | if (section->start == NULL |
7498 | 0 | || line_offset >= section->size |
7499 | 0 | || fileidx == 0) |
7500 | 5 | return NULL; |
7501 | | |
7502 | 0 | hdrptr = section->start + line_offset; |
7503 | 0 | end = section->start + section->size; |
7504 | |
|
7505 | 0 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); |
7506 | 0 | if (length == 0xffffffff) |
7507 | 0 | { |
7508 | | /* This section is 64-bit DWARF 3. */ |
7509 | 0 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
7510 | 0 | offset_size = 8; |
7511 | 0 | } |
7512 | 0 | else |
7513 | 0 | offset_size = 4; |
7514 | |
|
7515 | 0 | if (length > (size_t) (end - hdrptr) |
7516 | 0 | || length < 2 + offset_size + 1 + 3 + 1) |
7517 | 0 | return NULL; |
7518 | 0 | end = hdrptr + length; |
7519 | |
|
7520 | 0 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); |
7521 | 0 | if (version != 2 && version != 3 && version != 4) |
7522 | 0 | return NULL; |
7523 | 0 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ |
7524 | 0 | if (version >= 4) |
7525 | 0 | hdrptr++; /* Skip max_ops_per_insn. */ |
7526 | 0 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ |
7527 | |
|
7528 | 0 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); |
7529 | 0 | if (opcode_base == 0 |
7530 | 0 | || opcode_base - 1 >= (size_t) (end - hdrptr)) |
7531 | 0 | return NULL; |
7532 | | |
7533 | 0 | hdrptr += opcode_base - 1; |
7534 | |
|
7535 | 0 | dirtable = hdrptr; |
7536 | | /* Skip over dirname table. */ |
7537 | 0 | while (*hdrptr != '\0') |
7538 | 0 | { |
7539 | 0 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
7540 | 0 | if (hdrptr < end) |
7541 | 0 | hdrptr++; |
7542 | 0 | if (hdrptr >= end) |
7543 | 0 | return NULL; |
7544 | 0 | } |
7545 | 0 | hdrptr++; /* Skip the NUL at the end of the table. */ |
7546 | | |
7547 | | /* Now skip over preceding filename table entries. */ |
7548 | 0 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
7549 | 0 | { |
7550 | 0 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
7551 | 0 | if (hdrptr < end) |
7552 | 0 | hdrptr++; |
7553 | 0 | SKIP_ULEB (hdrptr, end); |
7554 | 0 | SKIP_ULEB (hdrptr, end); |
7555 | 0 | SKIP_ULEB (hdrptr, end); |
7556 | 0 | } |
7557 | 0 | if (hdrptr >= end || *hdrptr == '\0') |
7558 | 0 | return NULL; |
7559 | | |
7560 | 0 | file_name = hdrptr; |
7561 | 0 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
7562 | 0 | if (hdrptr < end) |
7563 | 0 | hdrptr++; |
7564 | 0 | if (hdrptr >= end) |
7565 | 0 | return NULL; |
7566 | 0 | READ_ULEB (diridx, hdrptr, end); |
7567 | 0 | if (diridx == 0) |
7568 | 0 | return file_name; |
7569 | 0 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
7570 | 0 | { |
7571 | 0 | dirtable += strnlen ((char *) dirtable, end - dirtable); |
7572 | 0 | if (dirtable < end) |
7573 | 0 | dirtable++; |
7574 | 0 | } |
7575 | 0 | if (dirtable >= end || *dirtable == '\0') |
7576 | 0 | return NULL; |
7577 | 0 | *dir_name = dirtable; |
7578 | 0 | return file_name; |
7579 | 0 | } |
7580 | | |
7581 | | static int |
7582 | | display_debug_macro (struct dwarf_section *section, |
7583 | | void *file) |
7584 | 96 | { |
7585 | 96 | unsigned char *start = section->start; |
7586 | 96 | unsigned char *end = start + section->size; |
7587 | 96 | unsigned char *curr = start; |
7588 | 96 | unsigned char *extended_op_buf[256]; |
7589 | 96 | bool is_dwo = false; |
7590 | 96 | const char *suffix = strrchr (section->name, '.'); |
7591 | | |
7592 | 96 | if (suffix && strcmp (suffix, ".dwo") == 0) |
7593 | 0 | is_dwo = true; |
7594 | | |
7595 | 96 | if (is_dwo) |
7596 | 0 | { |
7597 | 0 | load_debug_section_with_follow (str_dwo, file); |
7598 | 0 | load_debug_section_with_follow (str_index_dwo, file); |
7599 | 0 | } |
7600 | 96 | else |
7601 | 96 | { |
7602 | 96 | load_debug_section_with_follow (str, file); |
7603 | 96 | load_debug_section_with_follow (str_index, file); |
7604 | 96 | } |
7605 | 96 | load_debug_section_with_follow (line, file); |
7606 | | |
7607 | 96 | introduce (section, false); |
7608 | | |
7609 | 130 | while (curr < end) |
7610 | 101 | { |
7611 | 101 | unsigned int lineno, version, flags; |
7612 | 101 | unsigned int offset_size; |
7613 | 101 | uint64_t line_offset = 0, sec_offset = curr - start, offset; |
7614 | 101 | unsigned char **extended_ops = NULL; |
7615 | | |
7616 | 101 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7617 | 101 | if (version != 4 && version != 5) |
7618 | 36 | { |
7619 | 36 | error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"), |
7620 | 36 | section->name, version); |
7621 | 36 | return 0; |
7622 | 36 | } |
7623 | | |
7624 | 65 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
7625 | 65 | offset_size = (flags & 1) ? 8 : 4; |
7626 | 65 | printf (_(" Offset: %#" PRIx64 "\n"), sec_offset); |
7627 | 65 | printf (_(" Version: %d\n"), version); |
7628 | 65 | printf (_(" Offset size: %d\n"), offset_size); |
7629 | 65 | if (flags & 2) |
7630 | 5 | { |
7631 | 5 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
7632 | 5 | printf (_(" Offset into .debug_line: %#" PRIx64 "\n"), |
7633 | 5 | line_offset); |
7634 | 5 | } |
7635 | 65 | if (flags & 4) |
7636 | 7 | { |
7637 | 7 | unsigned int i, count, op; |
7638 | 7 | uint64_t nargs, n; |
7639 | | |
7640 | 7 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); |
7641 | | |
7642 | 7 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
7643 | 7 | extended_ops = extended_op_buf; |
7644 | 7 | if (count) |
7645 | 5 | { |
7646 | 5 | printf (_(" Extension opcode arguments:\n")); |
7647 | 16 | for (i = 0; i < count; i++) |
7648 | 16 | { |
7649 | 16 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
7650 | 16 | extended_ops[op] = curr; |
7651 | 16 | READ_ULEB (nargs, curr, end); |
7652 | 16 | if (nargs == 0) |
7653 | 9 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
7654 | 7 | else |
7655 | 7 | { |
7656 | 7 | printf (_(" DW_MACRO_%02x arguments: "), op); |
7657 | 18 | for (n = 0; n < nargs; n++) |
7658 | 16 | { |
7659 | 16 | unsigned int form; |
7660 | | |
7661 | 16 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); |
7662 | 16 | printf ("%s%s", get_FORM_name (form), |
7663 | 16 | n == nargs - 1 ? "\n" : ", "); |
7664 | 16 | switch (form) |
7665 | 16 | { |
7666 | 1 | case DW_FORM_data1: |
7667 | 1 | case DW_FORM_data2: |
7668 | 1 | case DW_FORM_data4: |
7669 | 1 | case DW_FORM_data8: |
7670 | 1 | case DW_FORM_sdata: |
7671 | 1 | case DW_FORM_udata: |
7672 | 1 | case DW_FORM_block: |
7673 | 1 | case DW_FORM_block1: |
7674 | 11 | case DW_FORM_block2: |
7675 | 11 | case DW_FORM_block4: |
7676 | 11 | case DW_FORM_flag: |
7677 | 11 | case DW_FORM_string: |
7678 | 11 | case DW_FORM_strp: |
7679 | 11 | case DW_FORM_sec_offset: |
7680 | 11 | break; |
7681 | 5 | default: |
7682 | 5 | error (_("Invalid extension opcode form %s\n"), |
7683 | 5 | get_FORM_name (form)); |
7684 | 5 | return 0; |
7685 | 16 | } |
7686 | 16 | } |
7687 | 7 | } |
7688 | 16 | } |
7689 | 5 | } |
7690 | 7 | } |
7691 | 60 | printf ("\n"); |
7692 | | |
7693 | 177 | while (1) |
7694 | 177 | { |
7695 | 177 | unsigned int op; |
7696 | 177 | const char *string; |
7697 | | |
7698 | 177 | if (curr >= end) |
7699 | 2 | { |
7700 | 2 | error (_(".debug_macro section not zero terminated\n")); |
7701 | 2 | return 0; |
7702 | 2 | } |
7703 | | |
7704 | 175 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
7705 | 175 | if (op == 0) |
7706 | 34 | break; |
7707 | | |
7708 | 141 | switch (op) |
7709 | 141 | { |
7710 | 38 | case DW_MACRO_define: |
7711 | 38 | READ_ULEB (lineno, curr, end); |
7712 | 38 | string = (const char *) curr; |
7713 | 38 | op = strnlen (string, end - curr); |
7714 | 38 | curr += op; |
7715 | 38 | printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"), |
7716 | 38 | lineno, (int) op, string); |
7717 | 38 | if (curr < end) |
7718 | 38 | curr++; |
7719 | 38 | break; |
7720 | | |
7721 | 34 | case DW_MACRO_undef: |
7722 | 34 | READ_ULEB (lineno, curr, end); |
7723 | 34 | string = (const char *) curr; |
7724 | 34 | op = strnlen (string, end - curr); |
7725 | 34 | curr += op; |
7726 | 34 | printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"), |
7727 | 34 | lineno, (int) op, string); |
7728 | 34 | if (curr < end) |
7729 | 32 | curr++; |
7730 | 34 | break; |
7731 | | |
7732 | 12 | case DW_MACRO_start_file: |
7733 | 12 | { |
7734 | 12 | unsigned int filenum; |
7735 | 12 | unsigned char *file_name = NULL, *dir_name = NULL; |
7736 | | |
7737 | 12 | READ_ULEB (lineno, curr, end); |
7738 | 12 | READ_ULEB (filenum, curr, end); |
7739 | | |
7740 | 12 | if ((flags & 2) == 0) |
7741 | 7 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
7742 | 5 | else |
7743 | 5 | file_name |
7744 | 5 | = get_line_filename_and_dirname (line_offset, filenum, |
7745 | 5 | &dir_name); |
7746 | 12 | if (file_name == NULL) |
7747 | 12 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
7748 | 12 | lineno, filenum); |
7749 | 0 | else |
7750 | 0 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
7751 | 0 | lineno, filenum, |
7752 | 0 | dir_name != NULL ? (const char *) dir_name : "", |
7753 | 0 | dir_name != NULL ? "/" : "", file_name); |
7754 | 12 | } |
7755 | 12 | break; |
7756 | | |
7757 | 0 | case DW_MACRO_end_file: |
7758 | 0 | printf (_(" DW_MACRO_end_file\n")); |
7759 | 0 | break; |
7760 | | |
7761 | 1 | case DW_MACRO_define_strp: |
7762 | 1 | READ_ULEB (lineno, curr, end); |
7763 | 1 | if (version == 4 && is_dwo) |
7764 | 0 | READ_ULEB (offset, curr, end); |
7765 | 1 | else |
7766 | 1 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7767 | 1 | string = fetch_indirect_string (offset); |
7768 | 1 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
7769 | 1 | lineno, string); |
7770 | 1 | break; |
7771 | | |
7772 | 16 | case DW_MACRO_undef_strp: |
7773 | 16 | READ_ULEB (lineno, curr, end); |
7774 | 16 | if (version == 4 && is_dwo) |
7775 | 0 | READ_ULEB (offset, curr, end); |
7776 | 16 | else |
7777 | 16 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7778 | 16 | string = fetch_indirect_string (offset); |
7779 | 16 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
7780 | 16 | lineno, string); |
7781 | 16 | break; |
7782 | | |
7783 | 1 | case DW_MACRO_import: |
7784 | 1 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7785 | 1 | printf (_(" DW_MACRO_import - offset : %#" PRIx64 "\n"), |
7786 | 1 | offset); |
7787 | 1 | break; |
7788 | | |
7789 | 1 | case DW_MACRO_define_sup: |
7790 | 1 | READ_ULEB (lineno, curr, end); |
7791 | 1 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7792 | 1 | printf (_(" DW_MACRO_define_sup - lineno : %d" |
7793 | 1 | " macro offset : %#" PRIx64 "\n"), |
7794 | 1 | lineno, offset); |
7795 | 1 | break; |
7796 | | |
7797 | 4 | case DW_MACRO_undef_sup: |
7798 | 4 | READ_ULEB (lineno, curr, end); |
7799 | 4 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7800 | 4 | printf (_(" DW_MACRO_undef_sup - lineno : %d" |
7801 | 4 | " macro offset : %#" PRIx64 "\n"), |
7802 | 4 | lineno, offset); |
7803 | 4 | break; |
7804 | | |
7805 | 0 | case DW_MACRO_import_sup: |
7806 | 0 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7807 | 0 | printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64 "\n"), |
7808 | 0 | offset); |
7809 | 0 | break; |
7810 | | |
7811 | 1 | case DW_MACRO_define_strx: |
7812 | 1 | case DW_MACRO_undef_strx: |
7813 | 1 | READ_ULEB (lineno, curr, end); |
7814 | 1 | READ_ULEB (offset, curr, end); |
7815 | 1 | string = fetch_indexed_string (offset, NULL, offset_size, |
7816 | 1 | is_dwo, 0); |
7817 | 1 | if (op == DW_MACRO_define_strx) |
7818 | 1 | printf (" DW_MACRO_define_strx "); |
7819 | 0 | else |
7820 | 0 | printf (" DW_MACRO_undef_strx "); |
7821 | 1 | if (do_wide) |
7822 | 0 | printf (_("(with offset %#" PRIx64 ") "), offset); |
7823 | 1 | printf (_("lineno : %d macro : %s\n"), |
7824 | 1 | lineno, string); |
7825 | 1 | break; |
7826 | | |
7827 | 33 | default: |
7828 | 33 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) |
7829 | 9 | { |
7830 | 9 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); |
7831 | 9 | break; |
7832 | 9 | } |
7833 | | |
7834 | 24 | if (extended_ops == NULL || extended_ops[op] == NULL) |
7835 | 24 | { |
7836 | 24 | error (_(" Unknown macro opcode %02x seen\n"), op); |
7837 | 24 | return 0; |
7838 | 24 | } |
7839 | 0 | else |
7840 | 0 | { |
7841 | | /* Skip over unhandled opcodes. */ |
7842 | 0 | uint64_t nargs, n; |
7843 | 0 | unsigned char *desc = extended_ops[op]; |
7844 | 0 | READ_ULEB (nargs, desc, end); |
7845 | 0 | if (nargs == 0) |
7846 | 0 | { |
7847 | 0 | printf (_(" DW_MACRO_%02x\n"), op); |
7848 | 0 | break; |
7849 | 0 | } |
7850 | 0 | printf (_(" DW_MACRO_%02x -"), op); |
7851 | 0 | for (n = 0; n < nargs; n++) |
7852 | 0 | { |
7853 | 0 | int val; |
7854 | | |
7855 | | /* DW_FORM_implicit_const is not expected here. */ |
7856 | 0 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
7857 | 0 | curr |
7858 | 0 | = read_and_display_attr_value (0, val, 0, |
7859 | 0 | start, curr, end, 0, |
7860 | 0 | offset_size, |
7861 | 0 | offset_size, version, |
7862 | 0 | NULL, 0, section, |
7863 | 0 | NULL, ' ', -1, |
7864 | 0 | false, 0, 0, false); |
7865 | 0 | if (n != nargs - 1) |
7866 | 0 | printf (","); |
7867 | 0 | } |
7868 | 0 | printf ("\n"); |
7869 | 0 | } |
7870 | 0 | break; |
7871 | 141 | } |
7872 | 141 | } |
7873 | | |
7874 | 34 | printf ("\n"); |
7875 | 34 | } |
7876 | | |
7877 | 29 | return 1; |
7878 | 96 | } |
7879 | | |
7880 | | static int |
7881 | | display_debug_abbrev (struct dwarf_section *section, |
7882 | | void *file ATTRIBUTE_UNUSED) |
7883 | 2.73k | { |
7884 | 2.73k | abbrev_entry *entry; |
7885 | 2.73k | unsigned char *start = section->start; |
7886 | | |
7887 | 2.73k | introduce (section, false); |
7888 | | |
7889 | 2.73k | do |
7890 | 1.10M | { |
7891 | 1.10M | uint64_t offset = start - section->start; |
7892 | 1.10M | abbrev_list *list = find_and_process_abbrev_set (section, 0, |
7893 | 1.10M | section->size, offset, |
7894 | 1.10M | NULL); |
7895 | 1.10M | if (list == NULL) |
7896 | 1.79k | break; |
7897 | | |
7898 | 1.10M | if (list->first_abbrev) |
7899 | 206k | printf (_(" Number TAG (%#" PRIx64 ")\n"), offset); |
7900 | | |
7901 | 1.43M | for (entry = list->first_abbrev; entry; entry = entry->next) |
7902 | 328k | { |
7903 | 328k | abbrev_attr *attr; |
7904 | | |
7905 | 328k | printf (" %ld %s [%s]\n", |
7906 | 328k | entry->number, |
7907 | 328k | get_TAG_name (entry->tag), |
7908 | 328k | entry->children ? _("has children") : _("no children")); |
7909 | | |
7910 | 1.65M | for (attr = entry->first_attr; attr; attr = attr->next) |
7911 | 1.32M | { |
7912 | 1.32M | printf (" %-18s %s", |
7913 | 1.32M | get_AT_name (attr->attribute), |
7914 | 1.32M | get_FORM_name (attr->form)); |
7915 | 1.32M | if (attr->form == DW_FORM_implicit_const) |
7916 | 3.95k | printf (": %" PRId64, attr->implicit_const); |
7917 | 1.32M | putchar ('\n'); |
7918 | 1.32M | } |
7919 | 328k | } |
7920 | 1.10M | start = list->start_of_next_abbrevs; |
7921 | 1.10M | free_abbrev_list (list); |
7922 | 1.10M | } |
7923 | 1.10M | while (start); |
7924 | | |
7925 | 2.73k | printf ("\n"); |
7926 | | |
7927 | 2.73k | return 1; |
7928 | 2.73k | } |
7929 | | |
7930 | | /* Return true when ADDR is the maximum address, when addresses are |
7931 | | POINTER_SIZE bytes long. */ |
7932 | | |
7933 | | static bool |
7934 | | is_max_address (uint64_t addr, unsigned int pointer_size) |
7935 | 299 | { |
7936 | 299 | uint64_t mask = ~(~(uint64_t) 0 << 1 << (pointer_size * 8 - 1)); |
7937 | 299 | return ((addr & mask) == mask); |
7938 | 299 | } |
7939 | | |
7940 | | /* Display a view pair list starting at *VSTART_PTR and ending at |
7941 | | VLISTEND within SECTION. */ |
7942 | | |
7943 | | static void |
7944 | | display_view_pair_list (struct dwarf_section *section, |
7945 | | unsigned char **vstart_ptr, |
7946 | | unsigned int debug_info_entry, |
7947 | | unsigned char *vlistend) |
7948 | 0 | { |
7949 | 0 | unsigned char *vstart = *vstart_ptr; |
7950 | 0 | unsigned char *section_end = section->start + section->size; |
7951 | 0 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; |
7952 | |
|
7953 | 0 | if (vlistend < section_end) |
7954 | 0 | section_end = vlistend; |
7955 | |
|
7956 | 0 | putchar ('\n'); |
7957 | |
|
7958 | 0 | while (vstart < section_end) |
7959 | 0 | { |
7960 | 0 | uint64_t off = vstart - section->start; |
7961 | 0 | uint64_t vbegin, vend; |
7962 | |
|
7963 | 0 | READ_ULEB (vbegin, vstart, section_end); |
7964 | 0 | if (vstart == section_end) |
7965 | 0 | break; |
7966 | | |
7967 | 0 | READ_ULEB (vend, vstart, section_end); |
7968 | 0 | printf (" %8.8" PRIx64 " ", off); |
7969 | |
|
7970 | 0 | print_view (vbegin, pointer_size); |
7971 | 0 | print_view (vend, pointer_size); |
7972 | 0 | printf (_("location view pair\n")); |
7973 | 0 | } |
7974 | |
|
7975 | 0 | putchar ('\n'); |
7976 | 0 | *vstart_ptr = vstart; |
7977 | 0 | } |
7978 | | |
7979 | | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
7980 | | |
7981 | | static void |
7982 | | display_loc_list (struct dwarf_section *section, |
7983 | | unsigned char **start_ptr, |
7984 | | unsigned int debug_info_entry, |
7985 | | uint64_t offset, |
7986 | | uint64_t base_address, |
7987 | | unsigned char **vstart_ptr, |
7988 | | int has_frame_base) |
7989 | 0 | { |
7990 | 0 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
7991 | 0 | unsigned char *section_end = section->start + section->size; |
7992 | 0 | uint64_t cu_offset; |
7993 | 0 | unsigned int pointer_size; |
7994 | 0 | unsigned int offset_size; |
7995 | 0 | int dwarf_version; |
7996 | 0 | uint64_t begin; |
7997 | 0 | uint64_t end; |
7998 | 0 | unsigned short length; |
7999 | 0 | int need_frame_base; |
8000 | |
|
8001 | 0 | if (debug_info_entry >= num_debug_info_entries) |
8002 | 0 | { |
8003 | 0 | warn (_("No debug information available for loc lists of entry: %u\n"), |
8004 | 0 | debug_info_entry); |
8005 | 0 | return; |
8006 | 0 | } |
8007 | | |
8008 | 0 | cu_offset = debug_information [debug_info_entry].cu_offset; |
8009 | 0 | pointer_size = debug_information [debug_info_entry].pointer_size; |
8010 | 0 | offset_size = debug_information [debug_info_entry].offset_size; |
8011 | 0 | dwarf_version = debug_information [debug_info_entry].dwarf_version; |
8012 | |
|
8013 | 0 | if (pointer_size < 2 || pointer_size > 8) |
8014 | 0 | { |
8015 | 0 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), |
8016 | 0 | pointer_size, debug_info_entry); |
8017 | 0 | return; |
8018 | 0 | } |
8019 | | |
8020 | 0 | while (1) |
8021 | 0 | { |
8022 | 0 | uint64_t off = offset + (start - *start_ptr); |
8023 | 0 | uint64_t vbegin = -1, vend = -1; |
8024 | |
|
8025 | 0 | if (2 * pointer_size > (size_t) (section_end - start)) |
8026 | 0 | { |
8027 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
8028 | 0 | " is not terminated.\n"), offset); |
8029 | 0 | break; |
8030 | 0 | } |
8031 | | |
8032 | 0 | printf (" "); |
8033 | 0 | print_hex (off, 4); |
8034 | |
|
8035 | 0 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
8036 | 0 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); |
8037 | |
|
8038 | 0 | if (begin == 0 && end == 0) |
8039 | 0 | { |
8040 | | /* PR 18374: In a object file we can have a location list that |
8041 | | starts with a begin and end of 0 because there are relocations |
8042 | | that need to be applied to the addresses. Actually applying |
8043 | | the relocations now does not help as they will probably resolve |
8044 | | to 0, since the object file has not been fully linked. Real |
8045 | | end of list markers will not have any relocations against them. */ |
8046 | 0 | if (! reloc_at (section, off) |
8047 | 0 | && ! reloc_at (section, off + pointer_size)) |
8048 | 0 | { |
8049 | 0 | printf (_("<End of list>\n")); |
8050 | 0 | break; |
8051 | 0 | } |
8052 | 0 | } |
8053 | | |
8054 | | /* Check base address specifiers. */ |
8055 | 0 | if (is_max_address (begin, pointer_size) |
8056 | 0 | && !is_max_address (end, pointer_size)) |
8057 | 0 | { |
8058 | 0 | base_address = end; |
8059 | 0 | print_hex (begin, pointer_size); |
8060 | 0 | print_hex (end, pointer_size); |
8061 | 0 | printf (_("(base address)\n")); |
8062 | 0 | continue; |
8063 | 0 | } |
8064 | | |
8065 | 0 | if (vstart) |
8066 | 0 | { |
8067 | 0 | off = offset + (vstart - *start_ptr); |
8068 | |
|
8069 | 0 | READ_ULEB (vbegin, vstart, section_end); |
8070 | 0 | print_view (vbegin, pointer_size); |
8071 | |
|
8072 | 0 | READ_ULEB (vend, vstart, section_end); |
8073 | 0 | print_view (vend, pointer_size); |
8074 | |
|
8075 | 0 | printf (_("views at %8.8" PRIx64 " for:\n %*s "), off, 8, ""); |
8076 | 0 | } |
8077 | |
|
8078 | 0 | if (2 > (size_t) (section_end - start)) |
8079 | 0 | { |
8080 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
8081 | 0 | " is not terminated.\n"), offset); |
8082 | 0 | break; |
8083 | 0 | } |
8084 | | |
8085 | 0 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
8086 | |
|
8087 | 0 | if (length > (size_t) (section_end - start)) |
8088 | 0 | { |
8089 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
8090 | 0 | " is not terminated.\n"), offset); |
8091 | 0 | break; |
8092 | 0 | } |
8093 | | |
8094 | 0 | print_hex (begin + base_address, pointer_size); |
8095 | 0 | print_hex (end + base_address, pointer_size); |
8096 | |
|
8097 | 0 | putchar ('('); |
8098 | 0 | need_frame_base = decode_location_expression (start, |
8099 | 0 | pointer_size, |
8100 | 0 | offset_size, |
8101 | 0 | dwarf_version, |
8102 | 0 | length, |
8103 | 0 | cu_offset, section); |
8104 | 0 | putchar (')'); |
8105 | |
|
8106 | 0 | if (need_frame_base && !has_frame_base) |
8107 | 0 | printf (_(" [without DW_AT_frame_base]")); |
8108 | |
|
8109 | 0 | if (begin == end && vbegin == vend) |
8110 | 0 | fputs (_(" (start == end)"), stdout); |
8111 | 0 | else if (begin > end || (begin == end && vbegin > vend)) |
8112 | 0 | fputs (_(" (start > end)"), stdout); |
8113 | |
|
8114 | 0 | putchar ('\n'); |
8115 | |
|
8116 | 0 | start += length; |
8117 | 0 | } |
8118 | | |
8119 | 0 | *start_ptr = start; |
8120 | 0 | *vstart_ptr = vstart; |
8121 | 0 | } |
8122 | | |
8123 | | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
8124 | | |
8125 | | static void |
8126 | | display_loclists_list (struct dwarf_section * section, |
8127 | | unsigned char ** start_ptr, |
8128 | | debug_info * debug_info_p, |
8129 | | uint64_t offset, |
8130 | | uint64_t base_address, |
8131 | | unsigned char ** vstart_ptr, |
8132 | | int has_frame_base) |
8133 | 0 | { |
8134 | 0 | unsigned char *start = *start_ptr; |
8135 | 0 | unsigned char *vstart = *vstart_ptr; |
8136 | 0 | unsigned char *section_end = section->start + section->size; |
8137 | 0 | uint64_t cu_offset; |
8138 | 0 | unsigned int pointer_size; |
8139 | 0 | unsigned int offset_size; |
8140 | 0 | unsigned int dwarf_version; |
8141 | 0 | uint64_t idx; |
8142 | | |
8143 | | /* Initialize it due to a false compiler warning. */ |
8144 | 0 | uint64_t begin = -1, vbegin = -1; |
8145 | 0 | uint64_t end = -1, vend = -1; |
8146 | 0 | uint64_t length; |
8147 | 0 | int need_frame_base; |
8148 | |
|
8149 | 0 | cu_offset = debug_info_p->cu_offset; |
8150 | 0 | pointer_size = debug_info_p->pointer_size; |
8151 | 0 | offset_size = debug_info_p->offset_size; |
8152 | 0 | dwarf_version = debug_info_p->dwarf_version; |
8153 | |
|
8154 | 0 | if (pointer_size < 2 || pointer_size > 8) |
8155 | 0 | { |
8156 | 0 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), |
8157 | 0 | pointer_size, (int)(debug_info_p - debug_information)); |
8158 | 0 | return; |
8159 | 0 | } |
8160 | | |
8161 | 0 | while (1) |
8162 | 0 | { |
8163 | 0 | uint64_t off = offset + (start - *start_ptr); |
8164 | 0 | enum dwarf_location_list_entry_type llet; |
8165 | |
|
8166 | 0 | if (start + 1 > section_end) |
8167 | 0 | { |
8168 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
8169 | 0 | " is not terminated.\n"), offset); |
8170 | 0 | break; |
8171 | 0 | } |
8172 | | |
8173 | 0 | printf (" "); |
8174 | 0 | print_hex (off, 4); |
8175 | |
|
8176 | 0 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); |
8177 | |
|
8178 | 0 | if (vstart && (llet == DW_LLE_offset_pair |
8179 | 0 | || llet == DW_LLE_start_end |
8180 | 0 | || llet == DW_LLE_start_length)) |
8181 | 0 | { |
8182 | 0 | off = offset + (vstart - *start_ptr); |
8183 | |
|
8184 | 0 | READ_ULEB (vbegin, vstart, section_end); |
8185 | 0 | print_view (vbegin, pointer_size); |
8186 | |
|
8187 | 0 | READ_ULEB (vend, vstart, section_end); |
8188 | 0 | print_view (vend, pointer_size); |
8189 | |
|
8190 | 0 | printf (_("views at %8.8" PRIx64 " for:\n %*s "), off, 8, ""); |
8191 | 0 | } |
8192 | |
|
8193 | 0 | switch (llet) |
8194 | 0 | { |
8195 | 0 | case DW_LLE_end_of_list: |
8196 | 0 | printf (_("<End of list>\n")); |
8197 | 0 | break; |
8198 | | |
8199 | 0 | case DW_LLE_base_addressx: |
8200 | 0 | READ_ULEB (idx, start, section_end); |
8201 | 0 | print_hex (idx, pointer_size); |
8202 | 0 | printf (_("(index into .debug_addr) ")); |
8203 | 0 | base_address = fetch_indexed_addr |
8204 | 0 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); |
8205 | 0 | print_hex (base_address, pointer_size); |
8206 | 0 | printf (_("(base address)\n")); |
8207 | 0 | break; |
8208 | | |
8209 | 0 | case DW_LLE_startx_endx: |
8210 | 0 | READ_ULEB (idx, start, section_end); |
8211 | 0 | begin = fetch_indexed_addr |
8212 | 0 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); |
8213 | 0 | READ_ULEB (idx, start, section_end); |
8214 | 0 | end = fetch_indexed_addr |
8215 | 0 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); |
8216 | 0 | break; |
8217 | | |
8218 | 0 | case DW_LLE_startx_length: |
8219 | 0 | READ_ULEB (idx, start, section_end); |
8220 | 0 | begin = fetch_indexed_addr |
8221 | 0 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); |
8222 | 0 | READ_ULEB (end, start, section_end); |
8223 | 0 | end += begin; |
8224 | 0 | break; |
8225 | | |
8226 | 0 | case DW_LLE_default_location: |
8227 | 0 | begin = end = 0; |
8228 | 0 | break; |
8229 | | |
8230 | 0 | case DW_LLE_offset_pair: |
8231 | 0 | READ_ULEB (begin, start, section_end); |
8232 | 0 | begin += base_address; |
8233 | 0 | READ_ULEB (end, start, section_end); |
8234 | 0 | end += base_address; |
8235 | 0 | break; |
8236 | | |
8237 | 0 | case DW_LLE_base_address: |
8238 | 0 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, |
8239 | 0 | section_end); |
8240 | 0 | print_hex (base_address, pointer_size); |
8241 | 0 | printf (_("(base address)\n")); |
8242 | 0 | break; |
8243 | | |
8244 | 0 | case DW_LLE_start_end: |
8245 | 0 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
8246 | 0 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); |
8247 | 0 | break; |
8248 | | |
8249 | 0 | case DW_LLE_start_length: |
8250 | 0 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
8251 | 0 | READ_ULEB (end, start, section_end); |
8252 | 0 | end += begin; |
8253 | 0 | break; |
8254 | | |
8255 | 0 | #ifdef DW_LLE_view_pair |
8256 | 0 | case DW_LLE_view_pair: |
8257 | 0 | if (vstart) |
8258 | 0 | printf (_("View pair entry in loclist with locviews attribute\n")); |
8259 | 0 | READ_ULEB (vbegin, start, section_end); |
8260 | 0 | print_view (vbegin, pointer_size); |
8261 | |
|
8262 | 0 | READ_ULEB (vend, start, section_end); |
8263 | 0 | print_view (vend, pointer_size); |
8264 | |
|
8265 | 0 | printf (_("views for:\n")); |
8266 | 0 | continue; |
8267 | 0 | #endif |
8268 | | |
8269 | 0 | default: |
8270 | 0 | error (_("Invalid location list entry type %d\n"), llet); |
8271 | 0 | return; |
8272 | 0 | } |
8273 | | |
8274 | 0 | if (llet == DW_LLE_end_of_list) |
8275 | 0 | break; |
8276 | | |
8277 | 0 | if (llet == DW_LLE_base_address |
8278 | 0 | || llet == DW_LLE_base_addressx) |
8279 | 0 | continue; |
8280 | | |
8281 | 0 | if (start == section_end) |
8282 | 0 | { |
8283 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
8284 | 0 | " is not terminated.\n"), offset); |
8285 | 0 | break; |
8286 | 0 | } |
8287 | 0 | READ_ULEB (length, start, section_end); |
8288 | |
|
8289 | 0 | if (length > (size_t) (section_end - start)) |
8290 | 0 | { |
8291 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
8292 | 0 | " is not terminated.\n"), offset); |
8293 | 0 | break; |
8294 | 0 | } |
8295 | | |
8296 | 0 | print_hex (begin, pointer_size); |
8297 | 0 | print_hex (end, pointer_size); |
8298 | |
|
8299 | 0 | putchar ('('); |
8300 | 0 | need_frame_base = decode_location_expression (start, |
8301 | 0 | pointer_size, |
8302 | 0 | offset_size, |
8303 | 0 | dwarf_version, |
8304 | 0 | length, |
8305 | 0 | cu_offset, section); |
8306 | 0 | putchar (')'); |
8307 | |
|
8308 | 0 | if (need_frame_base && !has_frame_base) |
8309 | 0 | printf (_(" [without DW_AT_frame_base]")); |
8310 | |
|
8311 | 0 | if (begin == end && vbegin == vend) |
8312 | 0 | fputs (_(" (start == end)"), stdout); |
8313 | 0 | else if (begin > end || (begin == end && vbegin > vend)) |
8314 | 0 | fputs (_(" (start > end)"), stdout); |
8315 | |
|
8316 | 0 | putchar ('\n'); |
8317 | |
|
8318 | 0 | start += length; |
8319 | 0 | vbegin = vend = -1; |
8320 | 0 | } |
8321 | | |
8322 | 0 | if (vbegin != (uint64_t) -1 || vend != (uint64_t) -1) |
8323 | 0 | printf (_("Trailing view pair not used in a range")); |
8324 | |
|
8325 | 0 | *start_ptr = start; |
8326 | 0 | *vstart_ptr = vstart; |
8327 | 0 | } |
8328 | | |
8329 | | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
8330 | | right-adjusted in a field of length LEN, and followed by a space. */ |
8331 | | |
8332 | | static void |
8333 | | print_addr_index (unsigned int idx, unsigned int len) |
8334 | 0 | { |
8335 | 0 | static char buf[15]; |
8336 | 0 | snprintf (buf, sizeof (buf), "[%d]", idx); |
8337 | 0 | printf ("%*s ", len, buf); |
8338 | 0 | } |
8339 | | |
8340 | | /* Display a location list from a .dwo section. It uses address indexes rather |
8341 | | than embedded addresses. This code closely follows display_loc_list, but the |
8342 | | two are sufficiently different that combining things is very ugly. */ |
8343 | | |
8344 | | static void |
8345 | | display_loc_list_dwo (struct dwarf_section *section, |
8346 | | unsigned char **start_ptr, |
8347 | | unsigned int debug_info_entry, |
8348 | | uint64_t offset, |
8349 | | unsigned char **vstart_ptr, |
8350 | | int has_frame_base) |
8351 | 0 | { |
8352 | 0 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
8353 | 0 | unsigned char *section_end = section->start + section->size; |
8354 | 0 | uint64_t cu_offset; |
8355 | 0 | unsigned int pointer_size; |
8356 | 0 | unsigned int offset_size; |
8357 | 0 | int dwarf_version; |
8358 | 0 | int entry_type; |
8359 | 0 | unsigned short length; |
8360 | 0 | int need_frame_base; |
8361 | 0 | unsigned int idx; |
8362 | |
|
8363 | 0 | if (debug_info_entry >= num_debug_info_entries) |
8364 | 0 | { |
8365 | 0 | warn (_("No debug information for loc lists of entry: %u\n"), |
8366 | 0 | debug_info_entry); |
8367 | 0 | return; |
8368 | 0 | } |
8369 | | |
8370 | 0 | cu_offset = debug_information [debug_info_entry].cu_offset; |
8371 | 0 | pointer_size = debug_information [debug_info_entry].pointer_size; |
8372 | 0 | offset_size = debug_information [debug_info_entry].offset_size; |
8373 | 0 | dwarf_version = debug_information [debug_info_entry].dwarf_version; |
8374 | |
|
8375 | 0 | if (pointer_size < 2 || pointer_size > 8) |
8376 | 0 | { |
8377 | 0 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), |
8378 | 0 | pointer_size, debug_info_entry); |
8379 | 0 | return; |
8380 | 0 | } |
8381 | | |
8382 | 0 | while (1) |
8383 | 0 | { |
8384 | 0 | printf (" "); |
8385 | 0 | print_hex (offset + (start - *start_ptr), 4); |
8386 | |
|
8387 | 0 | if (start >= section_end) |
8388 | 0 | { |
8389 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
8390 | 0 | " is not terminated.\n"), offset); |
8391 | 0 | break; |
8392 | 0 | } |
8393 | | |
8394 | 0 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
8395 | |
|
8396 | 0 | if (vstart) |
8397 | 0 | switch (entry_type) |
8398 | 0 | { |
8399 | 0 | default: |
8400 | 0 | break; |
8401 | | |
8402 | 0 | case 2: |
8403 | 0 | case 3: |
8404 | 0 | case 4: |
8405 | 0 | { |
8406 | 0 | uint64_t view; |
8407 | 0 | uint64_t off = offset + (vstart - *start_ptr); |
8408 | |
|
8409 | 0 | READ_ULEB (view, vstart, section_end); |
8410 | 0 | print_view (view, 8); |
8411 | |
|
8412 | 0 | READ_ULEB (view, vstart, section_end); |
8413 | 0 | print_view (view, 8); |
8414 | |
|
8415 | 0 | printf (_("views at %8.8" PRIx64 " for:\n %*s "), off, 8, ""); |
8416 | |
|
8417 | 0 | } |
8418 | 0 | break; |
8419 | 0 | } |
8420 | | |
8421 | 0 | switch (entry_type) |
8422 | 0 | { |
8423 | 0 | case 0: /* A terminating entry. */ |
8424 | 0 | *start_ptr = start; |
8425 | 0 | *vstart_ptr = vstart; |
8426 | 0 | printf (_("<End of list>\n")); |
8427 | 0 | return; |
8428 | 0 | case 1: /* A base-address entry. */ |
8429 | 0 | READ_ULEB (idx, start, section_end); |
8430 | 0 | print_addr_index (idx, 8); |
8431 | 0 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
8432 | 0 | printf (_("(base address selection entry)\n")); |
8433 | 0 | continue; |
8434 | 0 | case 2: /* A start/end entry. */ |
8435 | 0 | READ_ULEB (idx, start, section_end); |
8436 | 0 | print_addr_index (idx, 8); |
8437 | 0 | READ_ULEB (idx, start, section_end); |
8438 | 0 | print_addr_index (idx, 8); |
8439 | 0 | break; |
8440 | 0 | case 3: /* A start/length entry. */ |
8441 | 0 | READ_ULEB (idx, start, section_end); |
8442 | 0 | print_addr_index (idx, 8); |
8443 | 0 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); |
8444 | 0 | printf ("%08x ", idx); |
8445 | 0 | break; |
8446 | 0 | case 4: /* An offset pair entry. */ |
8447 | 0 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); |
8448 | 0 | printf ("%08x ", idx); |
8449 | 0 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); |
8450 | 0 | printf ("%08x ", idx); |
8451 | 0 | break; |
8452 | 0 | default: |
8453 | 0 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); |
8454 | 0 | *start_ptr = start; |
8455 | 0 | *vstart_ptr = vstart; |
8456 | 0 | return; |
8457 | 0 | } |
8458 | | |
8459 | 0 | if (2 > (size_t) (section_end - start)) |
8460 | 0 | { |
8461 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
8462 | 0 | " is not terminated.\n"), offset); |
8463 | 0 | break; |
8464 | 0 | } |
8465 | | |
8466 | 0 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
8467 | 0 | if (length > (size_t) (section_end - start)) |
8468 | 0 | { |
8469 | 0 | warn (_("Location list starting at offset %#" PRIx64 |
8470 | 0 | " is not terminated.\n"), offset); |
8471 | 0 | break; |
8472 | 0 | } |
8473 | | |
8474 | 0 | putchar ('('); |
8475 | 0 | need_frame_base = decode_location_expression (start, |
8476 | 0 | pointer_size, |
8477 | 0 | offset_size, |
8478 | 0 | dwarf_version, |
8479 | 0 | length, |
8480 | 0 | cu_offset, section); |
8481 | 0 | putchar (')'); |
8482 | |
|
8483 | 0 | if (need_frame_base && !has_frame_base) |
8484 | 0 | printf (_(" [without DW_AT_frame_base]")); |
8485 | |
|
8486 | 0 | putchar ('\n'); |
8487 | |
|
8488 | 0 | start += length; |
8489 | 0 | } |
8490 | | |
8491 | 0 | *start_ptr = start; |
8492 | 0 | *vstart_ptr = vstart; |
8493 | 0 | } |
8494 | | |
8495 | | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
8496 | | loc_views. */ |
8497 | | |
8498 | | static uint64_t *loc_offsets, *loc_views; |
8499 | | |
8500 | | static int |
8501 | | loc_offsets_compar (const void *ap, const void *bp) |
8502 | 0 | { |
8503 | 0 | uint64_t a = loc_offsets[*(const unsigned int *) ap]; |
8504 | 0 | uint64_t b = loc_offsets[*(const unsigned int *) bp]; |
8505 | |
|
8506 | 0 | int ret = (a > b) - (b > a); |
8507 | 0 | if (ret) |
8508 | 0 | return ret; |
8509 | | |
8510 | 0 | a = loc_views[*(const unsigned int *) ap]; |
8511 | 0 | b = loc_views[*(const unsigned int *) bp]; |
8512 | |
|
8513 | 0 | ret = (a > b) - (b > a); |
8514 | |
|
8515 | 0 | return ret; |
8516 | 0 | } |
8517 | | |
8518 | | /* Reads and dumps the DWARFv5 loclists compiler unit header, |
8519 | | including the offset table. |
8520 | | Returns the offset of the next compile unit header. */ |
8521 | | |
8522 | | static uint64_t |
8523 | | display_loclists_unit_header (struct dwarf_section * section, |
8524 | | uint64_t header_offset, |
8525 | | uint32_t * offset_count, |
8526 | | unsigned char ** loclists_start) |
8527 | 0 | { |
8528 | 0 | uint64_t length; |
8529 | 0 | unsigned char *start = section->start + header_offset; |
8530 | 0 | unsigned char *end = section->start + section->size; |
8531 | 0 | unsigned short version; |
8532 | 0 | unsigned char address_size; |
8533 | 0 | unsigned char segment_selector_size; |
8534 | 0 | bool is_64bit; |
8535 | 0 | uint32_t i; |
8536 | |
|
8537 | 0 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
8538 | 0 | if (length == 0xffffffff) |
8539 | 0 | { |
8540 | 0 | is_64bit = true; |
8541 | 0 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
8542 | 0 | } |
8543 | 0 | else |
8544 | 0 | is_64bit = false; |
8545 | 0 | if (length < 8) |
8546 | 0 | return (uint64_t) -1; |
8547 | | |
8548 | 0 | printf (_("Table at Offset %#" PRIx64 "\n"), header_offset); |
8549 | 0 | header_offset = start - section->start; |
8550 | |
|
8551 | 0 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); |
8552 | 0 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, end); |
8553 | 0 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, end); |
8554 | 0 | SAFE_BYTE_GET_AND_INC (*offset_count, start, 4, end); |
8555 | |
|
8556 | 0 | printf (_(" Length: %#" PRIx64 "\n"), length); |
8557 | 0 | printf (_(" DWARF version: %u\n"), version); |
8558 | 0 | printf (_(" Address size: %u\n"), address_size); |
8559 | 0 | printf (_(" Segment size: %u\n"), segment_selector_size); |
8560 | 0 | printf (_(" Offset entries: %u\n"), *offset_count); |
8561 | |
|
8562 | 0 | if (length > section->size - header_offset) |
8563 | 0 | length = section->size - header_offset; |
8564 | |
|
8565 | 0 | if (!address_size_ok (section->name, address_size, segment_selector_size)) |
8566 | 0 | return (uint64_t) -1; |
8567 | | |
8568 | 0 | uint64_t max_off_count = length >> (is_64bit ? 3 : 2); |
8569 | 0 | if (*offset_count > max_off_count) |
8570 | 0 | *offset_count = max_off_count; |
8571 | 0 | if (*offset_count) |
8572 | 0 | { |
8573 | 0 | printf (_("\n Offset Entries starting at %#tx:\n"), |
8574 | 0 | start - section->start); |
8575 | |
|
8576 | 0 | for (i = 0; i < *offset_count; i++) |
8577 | 0 | { |
8578 | 0 | uint64_t entry; |
8579 | |
|
8580 | 0 | SAFE_BYTE_GET_AND_INC (entry, start, is_64bit ? 8 : 4, end); |
8581 | 0 | printf (_(" [%6u] %#" PRIx64 "\n"), i, entry); |
8582 | 0 | } |
8583 | 0 | } |
8584 | |
|
8585 | 0 | putchar ('\n'); |
8586 | 0 | *loclists_start = start; |
8587 | |
|
8588 | 0 | return header_offset + length; |
8589 | 0 | } |
8590 | | |
8591 | | static int |
8592 | | display_debug_loc (struct dwarf_section *section, void *file) |
8593 | 107 | { |
8594 | 107 | unsigned char *start = section->start, *vstart = NULL; |
8595 | 107 | uint64_t bytes; |
8596 | 107 | unsigned char *section_begin = start; |
8597 | 107 | unsigned int num_loc_list = 0; |
8598 | 107 | uint64_t last_offset = 0; |
8599 | 107 | uint64_t last_view = 0; |
8600 | 107 | unsigned int first = 0; |
8601 | 107 | unsigned int i; |
8602 | 107 | unsigned int j; |
8603 | 107 | int seen_first_offset = 0; |
8604 | 107 | int locs_sorted = 1; |
8605 | 107 | unsigned char *next = start, *vnext = vstart; |
8606 | 107 | unsigned int *array = NULL; |
8607 | 107 | const char *suffix = strrchr (section->name, '.'); |
8608 | 107 | bool is_dwo = false; |
8609 | 107 | bool is_loclists = strstr (section->name, "debug_loclists") != NULL; |
8610 | 107 | uint64_t next_header_offset = 0; |
8611 | | |
8612 | 107 | if (suffix && strcmp (suffix, ".dwo") == 0) |
8613 | 0 | is_dwo = true; |
8614 | | |
8615 | 107 | bytes = section->size; |
8616 | | |
8617 | 107 | if (bytes == 0) |
8618 | 0 | { |
8619 | 0 | printf (_("\nThe %s section is empty.\n"), section->name); |
8620 | 0 | return 0; |
8621 | 0 | } |
8622 | | |
8623 | 107 | if (is_loclists) |
8624 | 42 | { |
8625 | 42 | unsigned char *hdrptr = section_begin; |
8626 | 42 | uint64_t ll_length; |
8627 | 42 | unsigned short ll_version; |
8628 | 42 | unsigned char *end = section_begin + section->size; |
8629 | 42 | unsigned char address_size, segment_selector_size; |
8630 | 42 | uint32_t offset_entry_count; |
8631 | | |
8632 | 42 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); |
8633 | 42 | if (ll_length == 0xffffffff) |
8634 | 42 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); |
8635 | | |
8636 | 42 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); |
8637 | 42 | if (ll_version != 5) |
8638 | 22 | { |
8639 | 22 | warn (_("The %s section contains corrupt or " |
8640 | 22 | "unsupported version number: %d.\n"), |
8641 | 22 | section->name, ll_version); |
8642 | 22 | return 0; |
8643 | 22 | } |
8644 | | |
8645 | 20 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); |
8646 | 20 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); |
8647 | 20 | if (!address_size_ok (section->name, address_size, segment_selector_size)) |
8648 | 0 | return 0; |
8649 | | |
8650 | 20 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); |
8651 | | |
8652 | | /*if (offset_entry_count != 0) |
8653 | | return display_offset_entry_loclists (section);*/ |
8654 | | |
8655 | | //header_size = hdrptr - section_begin; |
8656 | 20 | } |
8657 | | |
8658 | 85 | if (load_debug_info (file) == 0) |
8659 | 58 | { |
8660 | 58 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), |
8661 | 58 | section->name); |
8662 | 58 | return 0; |
8663 | 58 | } |
8664 | | |
8665 | | /* Check the order of location list in .debug_info section. If |
8666 | | offsets of location lists are in the ascending order, we can |
8667 | | use `debug_information' directly. */ |
8668 | 83 | for (i = 0; i < num_debug_info_entries; i++) |
8669 | 56 | { |
8670 | 56 | unsigned int num; |
8671 | | |
8672 | 56 | num = debug_information [i].num_loc_offsets; |
8673 | 56 | if (num > num_loc_list) |
8674 | 0 | num_loc_list = num; |
8675 | | |
8676 | | /* Check if we can use `debug_information' directly. */ |
8677 | 56 | if (locs_sorted && num != 0) |
8678 | 0 | { |
8679 | 0 | if (!seen_first_offset) |
8680 | 0 | { |
8681 | | /* This is the first location list. */ |
8682 | 0 | last_offset = debug_information [i].loc_offsets [0]; |
8683 | 0 | last_view = debug_information [i].loc_views [0]; |
8684 | 0 | first = i; |
8685 | 0 | seen_first_offset = 1; |
8686 | 0 | j = 1; |
8687 | 0 | } |
8688 | 0 | else |
8689 | 0 | j = 0; |
8690 | |
|
8691 | 0 | for (; j < num; j++) |
8692 | 0 | { |
8693 | 0 | if (last_offset > debug_information [i].loc_offsets [j] |
8694 | 0 | || (last_offset == debug_information [i].loc_offsets [j] |
8695 | 0 | && last_view > debug_information [i].loc_views [j])) |
8696 | 0 | { |
8697 | 0 | locs_sorted = 0; |
8698 | 0 | break; |
8699 | 0 | } |
8700 | 0 | last_offset = debug_information [i].loc_offsets [j]; |
8701 | 0 | last_view = debug_information [i].loc_views [j]; |
8702 | 0 | } |
8703 | 0 | } |
8704 | 56 | } |
8705 | | |
8706 | 27 | if (!seen_first_offset) |
8707 | 27 | error (_("No location lists in .debug_info section!\n")); |
8708 | | |
8709 | 27 | if (!locs_sorted) |
8710 | 0 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); |
8711 | | |
8712 | 27 | introduce (section, false); |
8713 | | |
8714 | 27 | if (reloc_at (section, 0)) |
8715 | 0 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); |
8716 | | |
8717 | 27 | if (!is_loclists) |
8718 | 18 | printf (_(" Offset Begin End Expression\n")); |
8719 | | |
8720 | 83 | for (i = first; i < num_debug_info_entries; i++) |
8721 | 56 | { |
8722 | 56 | uint64_t offset = 0, voffset = 0; |
8723 | 56 | uint64_t base_address; |
8724 | 56 | unsigned int k; |
8725 | 56 | int has_frame_base; |
8726 | 56 | debug_info *debug_info_p = debug_information + i; |
8727 | 56 | uint32_t offset_count; |
8728 | | |
8729 | | /* .debug_loclists section is loaded into debug_information as |
8730 | | DWARF-5 debug info and .debug_loc section is loaded into |
8731 | | debug_information as pre-DWARF-5 debug info. When dumping |
8732 | | .debug_loc section, we should only process pre-DWARF-5 debug |
8733 | | info in debug_information. When dumping .debug_loclists |
8734 | | section, we should only process DWARF-5 info in |
8735 | | debug_information. */ |
8736 | 56 | if ((debug_info_p->dwarf_version >= 5) != is_loclists) |
8737 | 13 | continue; |
8738 | | |
8739 | 43 | if (!locs_sorted) |
8740 | 0 | { |
8741 | 0 | for (k = 0; k < debug_info_p->num_loc_offsets; k++) |
8742 | 0 | array[k] = k; |
8743 | 0 | loc_offsets = debug_info_p->loc_offsets; |
8744 | 0 | loc_views = debug_info_p->loc_views; |
8745 | 0 | qsort (array, debug_info_p->num_loc_offsets, |
8746 | 0 | sizeof (*array), loc_offsets_compar); |
8747 | 0 | } |
8748 | | |
8749 | | /* .debug_loclists has a per-unit header. |
8750 | | Update start if we are detecting it. */ |
8751 | 43 | if (debug_info_p->dwarf_version >= 5) |
8752 | 6 | { |
8753 | 6 | j = locs_sorted ? 0 : array [0]; |
8754 | | |
8755 | 6 | if (debug_info_p->num_loc_offsets) |
8756 | 0 | offset = debug_info_p->loc_offsets [j]; |
8757 | | |
8758 | 6 | if (debug_info_p->num_loc_views) |
8759 | 0 | voffset = debug_info_p->loc_views [j]; |
8760 | | |
8761 | | /* Parse and dump unit headers in loclists. |
8762 | | This will misbehave if the order of CUs in debug_info |
8763 | | doesn't match the one in loclists. */ |
8764 | 6 | if (next_header_offset < offset) |
8765 | 0 | { |
8766 | 0 | while (next_header_offset < offset) |
8767 | 0 | { |
8768 | 0 | next_header_offset = display_loclists_unit_header |
8769 | 0 | (section, next_header_offset, &offset_count, &start); |
8770 | |
|
8771 | 0 | if (next_header_offset == (uint64_t)-1) |
8772 | | /* Header parsing error. */ |
8773 | 0 | return 0; |
8774 | 0 | } |
8775 | | |
8776 | 0 | printf (_("\ |
8777 | 0 | Offset Begin End Expression\n")); |
8778 | 0 | } |
8779 | 6 | } |
8780 | | |
8781 | 43 | int adjacent_view_loclists = 1; |
8782 | | |
8783 | 43 | for (k = 0; k < debug_info_p->num_loc_offsets; k++) |
8784 | 0 | { |
8785 | 0 | j = locs_sorted ? k : array[k]; |
8786 | 0 | if (k |
8787 | 0 | && (debug_info_p->loc_offsets [locs_sorted |
8788 | 0 | ? k - 1 : array [k - 1]] |
8789 | 0 | == debug_info_p->loc_offsets [j]) |
8790 | 0 | && (debug_info_p->loc_views [locs_sorted |
8791 | 0 | ? k - 1 : array [k - 1]] |
8792 | 0 | == debug_info_p->loc_views [j])) |
8793 | 0 | continue; |
8794 | 0 | has_frame_base = debug_info_p->have_frame_base [j]; |
8795 | 0 | offset = debug_info_p->loc_offsets [j]; |
8796 | 0 | next = section_begin + offset; |
8797 | 0 | voffset = debug_info_p->loc_views [j]; |
8798 | 0 | if (voffset != (uint64_t) -1) |
8799 | 0 | vnext = section_begin + voffset; |
8800 | 0 | else |
8801 | 0 | vnext = NULL; |
8802 | 0 | base_address = debug_info_p->base_address; |
8803 | |
|
8804 | 0 | if (vnext && vnext < next) |
8805 | 0 | { |
8806 | 0 | vstart = vnext; |
8807 | 0 | display_view_pair_list (section, &vstart, i, next); |
8808 | 0 | if (start == vnext) |
8809 | 0 | start = vstart; |
8810 | 0 | } |
8811 | |
|
8812 | 0 | if (start < next) |
8813 | 0 | { |
8814 | 0 | if (vnext && vnext < next) |
8815 | 0 | warn (_("There is a hole [%#tx - %#" PRIx64 "]" |
8816 | 0 | " in %s section.\n"), |
8817 | 0 | start - section_begin, voffset, section->name); |
8818 | 0 | else |
8819 | 0 | warn (_("There is a hole [%#tx - %#" PRIx64 "]" |
8820 | 0 | " in %s section.\n"), |
8821 | 0 | start - section_begin, offset, section->name); |
8822 | 0 | } |
8823 | 0 | else if (start > next) |
8824 | 0 | warn (_("There is an overlap [%#tx - %#" PRIx64 "]" |
8825 | 0 | " in %s section.\n"), |
8826 | 0 | start - section_begin, offset, section->name); |
8827 | 0 | start = next; |
8828 | 0 | vstart = vnext; |
8829 | |
|
8830 | 0 | if (offset >= bytes) |
8831 | 0 | { |
8832 | 0 | warn (_("Offset %#" PRIx64 " is bigger than %s section size.\n"), |
8833 | 0 | offset, section->name); |
8834 | 0 | continue; |
8835 | 0 | } |
8836 | | |
8837 | 0 | if (vnext && voffset >= bytes) |
8838 | 0 | { |
8839 | 0 | warn (_("View Offset %#" PRIx64 " is bigger than %s section size.\n"), |
8840 | 0 | voffset, section->name); |
8841 | 0 | continue; |
8842 | 0 | } |
8843 | | |
8844 | 0 | if (!is_loclists) |
8845 | 0 | { |
8846 | 0 | if (is_dwo) |
8847 | 0 | display_loc_list_dwo (section, &start, i, offset, |
8848 | 0 | &vstart, has_frame_base); |
8849 | 0 | else |
8850 | 0 | display_loc_list (section, &start, i, offset, base_address, |
8851 | 0 | &vstart, has_frame_base); |
8852 | 0 | } |
8853 | 0 | else |
8854 | 0 | { |
8855 | 0 | if (is_dwo) |
8856 | 0 | warn (_("DWO is not yet supported.\n")); |
8857 | 0 | else |
8858 | 0 | display_loclists_list (section, &start, debug_info_p, offset, |
8859 | 0 | base_address, &vstart, has_frame_base); |
8860 | 0 | } |
8861 | | |
8862 | | /* FIXME: this arrangement is quite simplistic. Nothing |
8863 | | requires locview lists to be adjacent to corresponding |
8864 | | loclists, and a single loclist could be augmented by |
8865 | | different locview lists, and vice-versa, unlikely as it |
8866 | | is that it would make sense to do so. Hopefully we'll |
8867 | | have view pair support built into loclists before we ever |
8868 | | need to address all these possibilities. */ |
8869 | 0 | if (adjacent_view_loclists && vnext |
8870 | 0 | && vnext != start && vstart != next) |
8871 | 0 | { |
8872 | 0 | adjacent_view_loclists = 0; |
8873 | 0 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); |
8874 | 0 | } |
8875 | |
|
8876 | 0 | if (vnext && vnext == start) |
8877 | 0 | display_view_pair_list (section, &start, i, vstart); |
8878 | 0 | } |
8879 | 43 | } |
8880 | | |
8881 | 27 | if (start < section->start + section->size) |
8882 | 27 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
8883 | 27 | "There are %ld unused bytes at the end of section %s\n", |
8884 | 27 | (long) (section->start + section->size - start)), |
8885 | 27 | (long) (section->start + section->size - start), section->name); |
8886 | 27 | putchar ('\n'); |
8887 | 27 | free (array); |
8888 | 27 | return 1; |
8889 | 27 | } |
8890 | | |
8891 | | static int |
8892 | | display_debug_str (struct dwarf_section *section, |
8893 | | void *file ATTRIBUTE_UNUSED) |
8894 | 623 | { |
8895 | 623 | unsigned char *start = section->start; |
8896 | 623 | uint64_t bytes = section->size; |
8897 | 623 | uint64_t addr = section->address; |
8898 | | |
8899 | 623 | if (bytes == 0) |
8900 | 9 | { |
8901 | 9 | printf (_("\nThe %s section is empty.\n"), section->name); |
8902 | 9 | return 0; |
8903 | 9 | } |
8904 | | |
8905 | 614 | introduce (section, false); |
8906 | | |
8907 | 9.63k | while (bytes) |
8908 | 9.01k | { |
8909 | 9.01k | int j; |
8910 | 9.01k | int k; |
8911 | 9.01k | int lbytes; |
8912 | | |
8913 | 9.01k | lbytes = (bytes > 16 ? 16 : bytes); |
8914 | | |
8915 | 9.01k | printf (" 0x%8.8" PRIx64 " ", addr); |
8916 | | |
8917 | 153k | for (j = 0; j < 16; j++) |
8918 | 144k | { |
8919 | 144k | if (j < lbytes) |
8920 | 141k | printf ("%2.2x", start[j]); |
8921 | 3.01k | else |
8922 | 3.01k | printf (" "); |
8923 | | |
8924 | 144k | if ((j & 3) == 3) |
8925 | 36.0k | printf (" "); |
8926 | 144k | } |
8927 | | |
8928 | 150k | for (j = 0; j < lbytes; j++) |
8929 | 141k | { |
8930 | 141k | k = start[j]; |
8931 | 141k | if (k >= ' ' && k < 0x80) |
8932 | 90.4k | printf ("%c", k); |
8933 | 50.8k | else |
8934 | 50.8k | printf ("."); |
8935 | 141k | } |
8936 | | |
8937 | 9.01k | putchar ('\n'); |
8938 | | |
8939 | 9.01k | start += lbytes; |
8940 | 9.01k | addr += lbytes; |
8941 | 9.01k | bytes -= lbytes; |
8942 | 9.01k | } |
8943 | | |
8944 | 614 | putchar ('\n'); |
8945 | | |
8946 | 614 | return 1; |
8947 | 623 | } |
8948 | | |
8949 | | static int |
8950 | | display_variable_mapping_info (struct dwarf_section *section, void *file) |
8951 | 0 | { |
8952 | 0 | return process_debug_info (section, file, section->abbrev_sec, |
8953 | 0 | DO_LOC | DO_GLOBAL_VARS); |
8954 | 0 | } |
8955 | | |
8956 | | static int |
8957 | | display_debug_info (struct dwarf_section *section, void *file) |
8958 | 366 | { |
8959 | 366 | return process_debug_info (section, file, section->abbrev_sec, 0); |
8960 | 366 | } |
8961 | | |
8962 | | static int |
8963 | | display_debug_types (struct dwarf_section *section, void *file) |
8964 | 20 | { |
8965 | 20 | return process_debug_info (section, file, section->abbrev_sec, DO_TYPES); |
8966 | 20 | } |
8967 | | |
8968 | | static int |
8969 | | display_trace_info (struct dwarf_section *section, void *file) |
8970 | 0 | { |
8971 | 0 | return process_debug_info (section, file, section->abbrev_sec, DO_TYPES); |
8972 | 0 | } |
8973 | | |
8974 | | static int |
8975 | | display_sframe (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) |
8976 | 0 | { |
8977 | 0 | sframe_decoder_ctx *sfd_ctx = NULL; |
8978 | 0 | unsigned char *data = section->start; |
8979 | 0 | size_t sf_size = section->size; |
8980 | 0 | int err = 0; |
8981 | |
|
8982 | 0 | if (strcmp (section->name, "") == 0) |
8983 | 0 | { |
8984 | 0 | error (_("Section name must be provided \n")); |
8985 | 0 | return false; |
8986 | 0 | } |
8987 | | |
8988 | | /* Decode the contents of the section. */ |
8989 | 0 | sfd_ctx = sframe_decode ((const char*)data, sf_size, &err); |
8990 | 0 | if (!sfd_ctx || err) |
8991 | 0 | { |
8992 | 0 | error (_("SFrame decode failure: %s\n"), sframe_errmsg (err)); |
8993 | 0 | return false; |
8994 | 0 | } |
8995 | | |
8996 | 0 | printf (_("Contents of the SFrame section %s:"), section->name); |
8997 | | /* Dump the contents as text. */ |
8998 | 0 | dump_sframe (sfd_ctx, section->address); |
8999 | |
|
9000 | 0 | sframe_decoder_free (&sfd_ctx); |
9001 | |
|
9002 | 0 | return true; |
9003 | 0 | } |
9004 | | |
9005 | | static int |
9006 | | display_debug_aranges (struct dwarf_section *section, |
9007 | | void *file ATTRIBUTE_UNUSED) |
9008 | 115 | { |
9009 | 115 | unsigned char *start = section->start; |
9010 | 115 | unsigned char *end = start + section->size; |
9011 | | |
9012 | 115 | introduce (section, false); |
9013 | | |
9014 | | /* It does not matter if this load fails, |
9015 | | we test for that later on. */ |
9016 | 115 | load_debug_info (file); |
9017 | | |
9018 | 223 | while (start < end) |
9019 | 148 | { |
9020 | 148 | unsigned char *hdrptr; |
9021 | 148 | DWARF2_Internal_ARange arange; |
9022 | 148 | unsigned char *addr_ranges; |
9023 | 148 | uint64_t length; |
9024 | 148 | uint64_t address; |
9025 | 148 | uint64_t sec_off; |
9026 | 148 | unsigned char tuple_size; |
9027 | 148 | unsigned int offset_size; |
9028 | 148 | unsigned char *end_ranges; |
9029 | | |
9030 | 148 | hdrptr = start; |
9031 | 148 | sec_off = hdrptr - section->start; |
9032 | | |
9033 | 148 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
9034 | 148 | if (arange.ar_length == 0xffffffff) |
9035 | 1 | { |
9036 | 1 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
9037 | 1 | offset_size = 8; |
9038 | 1 | } |
9039 | 147 | else |
9040 | 147 | offset_size = 4; |
9041 | | |
9042 | 148 | if (arange.ar_length > (size_t) (end - hdrptr)) |
9043 | 22 | { |
9044 | 22 | warn (_("Debug info is corrupted, %s header at %#" PRIx64 |
9045 | 22 | " has length %#" PRIx64 "\n"), |
9046 | 22 | section->name, sec_off, arange.ar_length); |
9047 | 22 | break; |
9048 | 22 | } |
9049 | 126 | end_ranges = hdrptr + arange.ar_length; |
9050 | | |
9051 | 126 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end_ranges); |
9052 | 126 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, |
9053 | 126 | end_ranges); |
9054 | | |
9055 | 126 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
9056 | 28 | && num_debug_info_entries > 0 |
9057 | 28 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) |
9058 | 3 | warn (_(".debug_info offset of %#" PRIx64 |
9059 | 3 | " in %s section does not point to a CU header.\n"), |
9060 | 3 | arange.ar_info_offset, section->name); |
9061 | | |
9062 | 126 | SAFE_BYTE_GET_AND_INC (arange.ar_address_size, hdrptr, 1, end_ranges); |
9063 | 126 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end_ranges); |
9064 | | |
9065 | 126 | if (arange.ar_version != 2 && arange.ar_version != 3) |
9066 | 11 | { |
9067 | | /* PR 19872: A version number of 0 probably means that there is |
9068 | | padding at the end of the .debug_aranges section. Gold puts |
9069 | | it there when performing an incremental link, for example. |
9070 | | So do not generate a warning in this case. */ |
9071 | 11 | if (arange.ar_version) |
9072 | 0 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); |
9073 | 11 | break; |
9074 | 11 | } |
9075 | | |
9076 | 115 | printf (_(" Length: %" PRId64 "\n"), arange.ar_length); |
9077 | 115 | printf (_(" Version: %d\n"), arange.ar_version); |
9078 | 115 | printf (_(" Offset into .debug_info: %#" PRIx64 "\n"), |
9079 | 115 | arange.ar_info_offset); |
9080 | 115 | printf (_(" Address size: %d\n"), arange.ar_address_size); |
9081 | 115 | printf (_(" Segment size: %d\n"), arange.ar_segment_size); |
9082 | | |
9083 | 115 | if (!address_size_ok (section->name, arange.ar_address_size, |
9084 | 115 | arange.ar_segment_size)) |
9085 | 7 | break; |
9086 | | |
9087 | 108 | tuple_size = 2 * arange.ar_address_size + arange.ar_segment_size; |
9088 | | |
9089 | 108 | if (tuple_size > 8) |
9090 | 66 | printf (_("\n Address Length\n")); |
9091 | 42 | else |
9092 | 42 | printf (_("\n Address Length\n")); |
9093 | | |
9094 | 108 | addr_ranges = hdrptr; |
9095 | | |
9096 | | /* Pad to a multiple of the tuple size. */ |
9097 | 108 | addr_ranges += tuple_size - 1 - (addr_ranges - start - 1) % tuple_size; |
9098 | | |
9099 | 325 | while (tuple_size <= end_ranges - addr_ranges) |
9100 | 217 | { |
9101 | 217 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, arange.ar_address_size, |
9102 | 217 | end_ranges); |
9103 | 217 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, arange.ar_address_size, |
9104 | 217 | end_ranges); |
9105 | 217 | printf (" "); |
9106 | 217 | print_hex (address, arange.ar_address_size); |
9107 | 217 | print_hex_ns (length, arange.ar_address_size); |
9108 | 217 | putchar ('\n'); |
9109 | 217 | } |
9110 | | |
9111 | 108 | start = end_ranges; |
9112 | 108 | } |
9113 | | |
9114 | 115 | printf ("\n"); |
9115 | | |
9116 | 115 | return 1; |
9117 | 115 | } |
9118 | | |
9119 | | /* Comparison function for qsort. */ |
9120 | | static int |
9121 | | comp_addr_base (const void * v0, const void * v1) |
9122 | 0 | { |
9123 | 0 | debug_info *info0 = *(debug_info **) v0; |
9124 | 0 | debug_info *info1 = *(debug_info **) v1; |
9125 | 0 | return info0->addr_base - info1->addr_base; |
9126 | 0 | } |
9127 | | |
9128 | | /* Display the debug_addr section. */ |
9129 | | static int |
9130 | | display_debug_addr (struct dwarf_section *section, |
9131 | | void *file) |
9132 | 63 | { |
9133 | 63 | debug_info **debug_addr_info; |
9134 | 63 | unsigned char *entry; |
9135 | 63 | unsigned char *end; |
9136 | 63 | unsigned int i; |
9137 | 63 | unsigned int count; |
9138 | 63 | unsigned char * header; |
9139 | | |
9140 | 63 | if (section->size == 0) |
9141 | 0 | { |
9142 | 0 | printf (_("\nThe %s section is empty.\n"), section->name); |
9143 | 0 | return 0; |
9144 | 0 | } |
9145 | | |
9146 | 63 | if (load_debug_info (file) == 0) |
9147 | 33 | { |
9148 | 33 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), |
9149 | 33 | section->name); |
9150 | 33 | return 0; |
9151 | 33 | } |
9152 | | |
9153 | 30 | introduce (section, false); |
9154 | | |
9155 | | /* PR 17531: file: cf38d01b. |
9156 | | We use xcalloc because a corrupt file may not have initialised all of the |
9157 | | fields in the debug_info structure, which means that the sort below might |
9158 | | try to move uninitialised data. */ |
9159 | 30 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), |
9160 | 30 | sizeof (debug_info *)); |
9161 | | |
9162 | 30 | count = 0; |
9163 | 78 | for (i = 0; i < num_debug_info_entries; i++) |
9164 | 48 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
9165 | 15 | { |
9166 | | /* PR 17531: file: cf38d01b. */ |
9167 | 15 | if (debug_information[i].addr_base >= section->size) |
9168 | 4 | warn (_("Corrupt address base (%#" PRIx64 ")" |
9169 | 4 | " found in debug section %u\n"), |
9170 | 4 | debug_information[i].addr_base, i); |
9171 | 11 | else |
9172 | 11 | debug_addr_info [count++] = debug_information + i; |
9173 | 15 | } |
9174 | | |
9175 | | /* Add a sentinel to make iteration convenient. */ |
9176 | 30 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); |
9177 | 30 | debug_addr_info [count]->addr_base = section->size; |
9178 | 30 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
9179 | | |
9180 | 30 | header = section->start; |
9181 | 33 | for (i = 0; i < count; i++) |
9182 | 11 | { |
9183 | 11 | unsigned int idx; |
9184 | 11 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
9185 | 11 | unsigned int segment_selector_size = 0; |
9186 | | |
9187 | 11 | printf (_(" For compilation unit at offset %#" PRIx64 ":\n"), |
9188 | 11 | debug_addr_info [i]->cu_offset); |
9189 | | |
9190 | 11 | printf (_("\tIndex\tAddress\n")); |
9191 | 11 | entry = section->start + debug_addr_info [i]->addr_base; |
9192 | 11 | if (debug_addr_info [i]->dwarf_version >= 5) |
9193 | 10 | { |
9194 | 10 | size_t header_size = entry - header; |
9195 | 10 | unsigned char *curr_header = header; |
9196 | 10 | uint64_t length; |
9197 | 10 | int version; |
9198 | | |
9199 | 10 | if (header_size != 8 && header_size != 16) |
9200 | 7 | { |
9201 | 7 | warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"), |
9202 | 7 | section->name, header_size); |
9203 | 7 | break; |
9204 | 7 | } |
9205 | | |
9206 | 3 | SAFE_BYTE_GET_AND_INC (length, curr_header, 4, entry); |
9207 | 3 | if (length == 0xffffffff) |
9208 | 3 | SAFE_BYTE_GET_AND_INC (length, curr_header, 8, entry); |
9209 | 3 | if (length > (size_t) (section->start + section->size - curr_header) |
9210 | 2 | || length < (size_t) (entry - curr_header)) |
9211 | 1 | { |
9212 | 1 | warn (_("Corrupt %s section: unit_length field of %#" PRIx64 |
9213 | 1 | " is invalid\n"), section->name, length); |
9214 | 1 | break; |
9215 | 1 | } |
9216 | 2 | end = curr_header + length; |
9217 | 2 | SAFE_BYTE_GET_AND_INC (version, curr_header, 2, entry); |
9218 | 2 | if (version != 5) |
9219 | 0 | warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"), |
9220 | 0 | section->name, version); |
9221 | | |
9222 | 2 | SAFE_BYTE_GET_AND_INC (address_size, curr_header, 1, entry); |
9223 | 2 | SAFE_BYTE_GET_AND_INC (segment_selector_size, curr_header, 1, entry); |
9224 | 2 | } |
9225 | 1 | else |
9226 | 1 | end = section->start + debug_addr_info [i + 1]->addr_base; |
9227 | | |
9228 | 3 | header = end; |
9229 | 3 | idx = 0; |
9230 | | |
9231 | 3 | if (!address_size_ok (section->name, address_size, segment_selector_size)) |
9232 | 0 | break; |
9233 | | |
9234 | 9 | while ((size_t) (end - entry) >= address_size) |
9235 | 6 | { |
9236 | 6 | uint64_t base = byte_get (entry, address_size); |
9237 | 6 | printf (_("\t%d:\t"), idx); |
9238 | 6 | print_hex_ns (base, address_size); |
9239 | 6 | printf ("\n"); |
9240 | 6 | entry += address_size; |
9241 | 6 | idx++; |
9242 | 6 | } |
9243 | 3 | } |
9244 | 30 | printf ("\n"); |
9245 | | |
9246 | 30 | free (debug_addr_info[count]); |
9247 | 30 | free (debug_addr_info); |
9248 | 30 | return i == count; |
9249 | 30 | } |
9250 | | |
9251 | | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ |
9252 | | |
9253 | | static int |
9254 | | display_debug_str_offsets (struct dwarf_section *section, |
9255 | | void *file ATTRIBUTE_UNUSED) |
9256 | 72 | { |
9257 | 72 | unsigned long idx; |
9258 | | |
9259 | 72 | if (section->size == 0) |
9260 | 0 | { |
9261 | 0 | printf (_("\nThe %s section is empty.\n"), section->name); |
9262 | 0 | return 0; |
9263 | 0 | } |
9264 | | |
9265 | 72 | unsigned char *start = section->start; |
9266 | 72 | unsigned char *end = start + section->size; |
9267 | 72 | unsigned char *curr = start; |
9268 | 72 | uint64_t debug_str_offsets_hdr_len; |
9269 | | |
9270 | 72 | const char *suffix = strrchr (section->name, '.'); |
9271 | 72 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
9272 | | |
9273 | 72 | if (dwo) |
9274 | 2 | load_debug_section_with_follow (str_dwo, file); |
9275 | 70 | else |
9276 | 70 | load_debug_section_with_follow (str, file); |
9277 | | |
9278 | 72 | introduce (section, false); |
9279 | | |
9280 | 141 | while (curr < end) |
9281 | 74 | { |
9282 | 74 | uint64_t length; |
9283 | 74 | uint64_t entry_length; |
9284 | | |
9285 | 74 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); |
9286 | | /* FIXME: We assume that this means 64-bit DWARF is being used. */ |
9287 | 74 | if (length == 0xffffffff) |
9288 | 3 | { |
9289 | 3 | SAFE_BYTE_GET_AND_INC (length, curr, 8, end); |
9290 | 3 | entry_length = 8; |
9291 | 3 | debug_str_offsets_hdr_len = 16; |
9292 | 3 | } |
9293 | 71 | else |
9294 | 71 | { |
9295 | 71 | entry_length = 4; |
9296 | 71 | debug_str_offsets_hdr_len = 8; |
9297 | 71 | } |
9298 | | |
9299 | 74 | unsigned char *entries_end; |
9300 | 74 | if (length == 0) |
9301 | 17 | { |
9302 | | /* This is probably an old style .debug_str_offset section which |
9303 | | just contains offsets and no header (and the first offset is 0). */ |
9304 | 17 | length = section->size; |
9305 | 17 | curr = section->start; |
9306 | 17 | entries_end = end; |
9307 | 17 | debug_str_offsets_hdr_len = 0; |
9308 | | |
9309 | 17 | printf (_(" Length: %#" PRIx64 "\n"), length); |
9310 | 17 | printf (_(" Index Offset [String]\n")); |
9311 | 17 | } |
9312 | 57 | else |
9313 | 57 | { |
9314 | 57 | if (length <= (size_t) (end - curr)) |
9315 | 38 | entries_end = curr + length; |
9316 | 19 | else |
9317 | 19 | { |
9318 | 19 | warn (_("Section %s is too small %#" PRIx64 "\n"), |
9319 | 19 | section->name, section->size); |
9320 | 19 | entries_end = end; |
9321 | 19 | } |
9322 | | |
9323 | 57 | int version; |
9324 | 57 | SAFE_BYTE_GET_AND_INC (version, curr, 2, entries_end); |
9325 | 57 | if (version != 5) |
9326 | 18 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); |
9327 | | |
9328 | 57 | int padding; |
9329 | 57 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, entries_end); |
9330 | 57 | if (padding != 0) |
9331 | 15 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); |
9332 | | |
9333 | 57 | printf (_(" Length: %#" PRIx64 "\n"), length); |
9334 | 57 | printf (_(" Version: %#x\n"), version); |
9335 | 57 | printf (_(" Index Offset [String]\n")); |
9336 | 57 | } |
9337 | | |
9338 | 1.14k | for (idx = 0; curr < entries_end; idx++) |
9339 | 1.07k | { |
9340 | 1.07k | uint64_t offset; |
9341 | 1.07k | const char *string; |
9342 | | |
9343 | 1.07k | if ((size_t) (entries_end - curr) < entry_length) |
9344 | | /* Not enough space to read one entry_length, give up. */ |
9345 | 5 | return 0; |
9346 | | |
9347 | 1.06k | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, entries_end); |
9348 | 1.06k | if (dwo) |
9349 | 725 | string = fetch_indexed_string (idx, NULL, entry_length, dwo, |
9350 | 725 | debug_str_offsets_hdr_len); |
9351 | 342 | else |
9352 | 342 | string = fetch_indirect_string (offset); |
9353 | | |
9354 | 1.06k | printf (" %8lu ", idx); |
9355 | 1.06k | print_hex (offset, entry_length); |
9356 | 1.06k | printf (" %s\n", string); |
9357 | 1.06k | } |
9358 | 74 | } |
9359 | | |
9360 | 67 | return 1; |
9361 | 72 | } |
9362 | | |
9363 | | /* Each debug_information[x].range_lists[y] gets this representation for |
9364 | | sorting purposes. */ |
9365 | | |
9366 | | struct range_entry |
9367 | | { |
9368 | | /* The debug_information[x].range_lists[y] value. */ |
9369 | | uint64_t ranges_offset; |
9370 | | |
9371 | | /* Original debug_information to find parameters of the data. */ |
9372 | | debug_info *debug_info_p; |
9373 | | }; |
9374 | | |
9375 | | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ |
9376 | | |
9377 | | static int |
9378 | | range_entry_compar (const void *ap, const void *bp) |
9379 | 30 | { |
9380 | 30 | const struct range_entry *a_re = (const struct range_entry *) ap; |
9381 | 30 | const struct range_entry *b_re = (const struct range_entry *) bp; |
9382 | 30 | const uint64_t a = a_re->ranges_offset; |
9383 | 30 | const uint64_t b = b_re->ranges_offset; |
9384 | | |
9385 | 30 | return (a > b) - (b > a); |
9386 | 30 | } |
9387 | | |
9388 | | static unsigned char * |
9389 | | display_debug_ranges_list (unsigned char * start, |
9390 | | unsigned char * finish, |
9391 | | unsigned int pointer_size, |
9392 | | uint64_t offset, |
9393 | | uint64_t base_address) |
9394 | 31 | { |
9395 | 330 | while (start < finish) |
9396 | 317 | { |
9397 | 317 | uint64_t begin; |
9398 | 317 | uint64_t end; |
9399 | | |
9400 | 317 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); |
9401 | 317 | if (start >= finish) |
9402 | 0 | break; |
9403 | 317 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); |
9404 | | |
9405 | 317 | printf (" "); |
9406 | 317 | print_hex (offset, 4); |
9407 | | |
9408 | 317 | if (begin == 0 && end == 0) |
9409 | 18 | { |
9410 | 18 | printf (_("<End of list>\n")); |
9411 | 18 | break; |
9412 | 18 | } |
9413 | | |
9414 | | /* Check base address specifiers. */ |
9415 | 299 | if (is_max_address (begin, pointer_size) |
9416 | 0 | && !is_max_address (end, pointer_size)) |
9417 | 0 | { |
9418 | 0 | base_address = end; |
9419 | 0 | print_hex (begin, pointer_size); |
9420 | 0 | print_hex (end, pointer_size); |
9421 | 0 | printf ("(base address)\n"); |
9422 | 0 | continue; |
9423 | 0 | } |
9424 | | |
9425 | 299 | print_hex (begin + base_address, pointer_size); |
9426 | 299 | print_hex_ns (end + base_address, pointer_size); |
9427 | | |
9428 | 299 | if (begin == end) |
9429 | 0 | fputs (_(" (start == end)"), stdout); |
9430 | 299 | else if (begin > end) |
9431 | 88 | fputs (_(" (start > end)"), stdout); |
9432 | | |
9433 | 299 | putchar ('\n'); |
9434 | 299 | } |
9435 | | |
9436 | 31 | return start; |
9437 | 31 | } |
9438 | | |
9439 | | static unsigned char * |
9440 | | display_debug_rnglists_list (unsigned char * start, |
9441 | | unsigned char * finish, |
9442 | | unsigned int pointer_size, |
9443 | | uint64_t offset, |
9444 | | uint64_t base_address, |
9445 | | uint64_t addr_base) |
9446 | 0 | { |
9447 | 0 | unsigned char *next = start; |
9448 | |
|
9449 | 0 | while (1) |
9450 | 0 | { |
9451 | 0 | uint64_t off = offset + (start - next); |
9452 | 0 | enum dwarf_range_list_entry rlet; |
9453 | | /* Initialize it due to a false compiler warning. */ |
9454 | 0 | uint64_t begin = -1, length, end = -1; |
9455 | |
|
9456 | 0 | if (start >= finish) |
9457 | 0 | { |
9458 | 0 | warn (_("Range list starting at offset %#" PRIx64 |
9459 | 0 | " is not terminated.\n"), offset); |
9460 | 0 | break; |
9461 | 0 | } |
9462 | | |
9463 | 0 | printf (" "); |
9464 | 0 | print_hex (off, 4); |
9465 | |
|
9466 | 0 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); |
9467 | |
|
9468 | 0 | switch (rlet) |
9469 | 0 | { |
9470 | 0 | case DW_RLE_end_of_list: |
9471 | 0 | printf (_("<End of list>\n")); |
9472 | 0 | break; |
9473 | 0 | case DW_RLE_base_addressx: |
9474 | 0 | READ_ULEB (base_address, start, finish); |
9475 | 0 | print_hex (base_address, pointer_size); |
9476 | 0 | printf (_("(base address index) ")); |
9477 | 0 | base_address = fetch_indexed_addr (base_address * pointer_size + addr_base, |
9478 | 0 | pointer_size); |
9479 | 0 | print_hex (base_address, pointer_size); |
9480 | 0 | printf (_("(base address)\n")); |
9481 | 0 | break; |
9482 | 0 | case DW_RLE_startx_endx: |
9483 | 0 | READ_ULEB (begin, start, finish); |
9484 | 0 | READ_ULEB (end, start, finish); |
9485 | 0 | begin = fetch_indexed_addr (begin * pointer_size + addr_base, |
9486 | 0 | pointer_size); |
9487 | 0 | end = fetch_indexed_addr (end * pointer_size + addr_base, |
9488 | 0 | pointer_size); |
9489 | 0 | break; |
9490 | 0 | case DW_RLE_startx_length: |
9491 | 0 | READ_ULEB (begin, start, finish); |
9492 | 0 | READ_ULEB (length, start, finish); |
9493 | 0 | begin = fetch_indexed_addr (begin * pointer_size + addr_base, |
9494 | 0 | pointer_size); |
9495 | 0 | end = begin + length; |
9496 | 0 | break; |
9497 | 0 | case DW_RLE_offset_pair: |
9498 | 0 | READ_ULEB (begin, start, finish); |
9499 | 0 | READ_ULEB (end, start, finish); |
9500 | 0 | break; |
9501 | 0 | case DW_RLE_base_address: |
9502 | 0 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); |
9503 | 0 | print_hex (base_address, pointer_size); |
9504 | 0 | printf (_("(base address)\n")); |
9505 | 0 | break; |
9506 | 0 | case DW_RLE_start_end: |
9507 | 0 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); |
9508 | 0 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); |
9509 | 0 | break; |
9510 | 0 | case DW_RLE_start_length: |
9511 | 0 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); |
9512 | 0 | READ_ULEB (length, start, finish); |
9513 | 0 | end = begin + length; |
9514 | 0 | break; |
9515 | 0 | default: |
9516 | 0 | error (_("Invalid range list entry type %d\n"), rlet); |
9517 | 0 | rlet = DW_RLE_end_of_list; |
9518 | 0 | break; |
9519 | 0 | } |
9520 | | |
9521 | 0 | if (rlet == DW_RLE_end_of_list) |
9522 | 0 | break; |
9523 | 0 | if (rlet == DW_RLE_base_address || rlet == DW_RLE_base_addressx) |
9524 | 0 | continue; |
9525 | | |
9526 | | /* Only a DW_RLE_offset_pair needs the base address added. */ |
9527 | 0 | if (rlet == DW_RLE_offset_pair) |
9528 | 0 | { |
9529 | 0 | begin += base_address; |
9530 | 0 | end += base_address; |
9531 | 0 | } |
9532 | |
|
9533 | 0 | print_hex (begin, pointer_size); |
9534 | 0 | print_hex (end, pointer_size); |
9535 | |
|
9536 | 0 | if (begin == end) |
9537 | 0 | fputs (_(" (start == end)"), stdout); |
9538 | 0 | else if (begin > end) |
9539 | 0 | fputs (_(" (start > end)"), stdout); |
9540 | |
|
9541 | 0 | putchar ('\n'); |
9542 | 0 | } |
9543 | | |
9544 | 0 | return start; |
9545 | 0 | } |
9546 | | |
9547 | | static bool |
9548 | | display_debug_rnglists_unit_header (struct dwarf_section * section, |
9549 | | uint64_t * unit_offset, |
9550 | | unsigned char * poffset_size) |
9551 | 0 | { |
9552 | 0 | uint64_t start_offset = *unit_offset; |
9553 | 0 | unsigned char * p = section->start + start_offset; |
9554 | 0 | unsigned char * finish = section->start + section->size; |
9555 | 0 | unsigned char * hdr; |
9556 | 0 | uint64_t length; |
9557 | 0 | unsigned char segment_selector_size; |
9558 | 0 | unsigned int offset_entry_count; |
9559 | 0 | unsigned int i; |
9560 | 0 | unsigned short version; |
9561 | 0 | unsigned char address_size = 0; |
9562 | 0 | unsigned char offset_size; |
9563 | | |
9564 | | /* Get and check the length of the block. */ |
9565 | 0 | SAFE_BYTE_GET_AND_INC (length, p, 4, finish); |
9566 | |
|
9567 | 0 | if (length == 0xffffffff) |
9568 | 0 | { |
9569 | | /* This section is 64-bit DWARF 3. */ |
9570 | 0 | SAFE_BYTE_GET_AND_INC (length, p, 8, finish); |
9571 | 0 | *poffset_size = offset_size = 8; |
9572 | 0 | } |
9573 | 0 | else |
9574 | 0 | *poffset_size = offset_size = 4; |
9575 | |
|
9576 | 0 | if (length < 8) |
9577 | 0 | return false; |
9578 | | |
9579 | | /* Get the other fields in the header. */ |
9580 | 0 | hdr = p; |
9581 | 0 | SAFE_BYTE_GET_AND_INC (version, p, 2, finish); |
9582 | 0 | SAFE_BYTE_GET_AND_INC (address_size, p, 1, finish); |
9583 | 0 | SAFE_BYTE_GET_AND_INC (segment_selector_size, p, 1, finish); |
9584 | 0 | SAFE_BYTE_GET_AND_INC (offset_entry_count, p, 4, finish); |
9585 | |
|
9586 | 0 | printf (_(" Table at Offset: %#" PRIx64 ":\n"), start_offset); |
9587 | 0 | printf (_(" Length: %#" PRIx64 "\n"), length); |
9588 | 0 | printf (_(" DWARF version: %u\n"), version); |
9589 | 0 | printf (_(" Address size: %u\n"), address_size); |
9590 | 0 | printf (_(" Segment size: %u\n"), segment_selector_size); |
9591 | 0 | printf (_(" Offset entries: %u\n"), offset_entry_count); |
9592 | |
|
9593 | 0 | if (length > (size_t) (finish - hdr)) |
9594 | 0 | length = finish - hdr; |
9595 | | |
9596 | | /* Report the next unit offset to the caller. */ |
9597 | 0 | *unit_offset = (hdr - section->start) + length; |
9598 | | |
9599 | | /* Check the fields. */ |
9600 | 0 | if (segment_selector_size != 0) |
9601 | 0 | { |
9602 | 0 | warn (_("The %s section contains " |
9603 | 0 | "unsupported segment selector size: %d.\n"), |
9604 | 0 | section->name, segment_selector_size); |
9605 | 0 | return false; |
9606 | 0 | } |
9607 | | |
9608 | 0 | if (version < 5) |
9609 | 0 | { |
9610 | 0 | warn (_("Only DWARF version 5+ debug_rnglists info " |
9611 | 0 | "is currently supported.\n")); |
9612 | 0 | return false; |
9613 | 0 | } |
9614 | | |
9615 | 0 | uint64_t max_off_count = (length - 8) / offset_size; |
9616 | 0 | if (offset_entry_count > max_off_count) |
9617 | 0 | offset_entry_count = max_off_count; |
9618 | 0 | if (offset_entry_count != 0) |
9619 | 0 | { |
9620 | 0 | printf (_("\n Offsets starting at %#tx:\n"), p - section->start); |
9621 | |
|
9622 | 0 | for (i = 0; i < offset_entry_count; i++) |
9623 | 0 | { |
9624 | 0 | uint64_t entry; |
9625 | |
|
9626 | 0 | SAFE_BYTE_GET_AND_INC (entry, p, offset_size, finish); |
9627 | 0 | printf (_(" [%6u] %#" PRIx64 "\n"), i, entry); |
9628 | 0 | } |
9629 | 0 | } |
9630 | |
|
9631 | 0 | return true; |
9632 | 0 | } |
9633 | | |
9634 | | static bool |
9635 | | is_range_list_for_this_section (bool is_rnglists, unsigned int version) |
9636 | 144 | { |
9637 | 144 | if (is_rnglists && version > 4) |
9638 | 11 | return true; |
9639 | | |
9640 | 133 | if (! is_rnglists && version < 5) |
9641 | 87 | return true; |
9642 | | |
9643 | 46 | return false; |
9644 | 133 | } |
9645 | | |
9646 | | static int |
9647 | | display_debug_ranges (struct dwarf_section *section, |
9648 | | void *file ATTRIBUTE_UNUSED) |
9649 | 203 | { |
9650 | 203 | unsigned char *start = section->start; |
9651 | 203 | unsigned char *last_start = start; |
9652 | 203 | unsigned char *last_end; |
9653 | 203 | uint64_t bytes = section->size; |
9654 | 203 | unsigned char *section_begin = start; |
9655 | 203 | unsigned char *finish = start + bytes; |
9656 | 203 | unsigned int num_range_list, i; |
9657 | 203 | struct range_entry *range_entries; |
9658 | 203 | struct range_entry *range_entry_fill; |
9659 | 203 | bool is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
9660 | 203 | uint64_t last_offset = 0; |
9661 | 203 | uint64_t next_rnglists_cu_offset = 0; |
9662 | 203 | unsigned char offset_size; |
9663 | 203 | bool ok_header = true; |
9664 | | |
9665 | 203 | if (bytes == 0) |
9666 | 1 | { |
9667 | 1 | printf (_("\nThe %s section is empty.\n"), section->name); |
9668 | 1 | return 0; |
9669 | 1 | } |
9670 | | |
9671 | 202 | introduce (section, false); |
9672 | | |
9673 | 202 | if (load_debug_info (file) == 0) |
9674 | 151 | { |
9675 | 151 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), |
9676 | 151 | section->name); |
9677 | 151 | return 0; |
9678 | 151 | } |
9679 | | |
9680 | 51 | num_range_list = 0; |
9681 | 162 | for (i = 0; i < num_debug_info_entries; i++) |
9682 | 111 | if (is_range_list_for_this_section (is_rnglists, debug_information [i].dwarf_version)) |
9683 | 65 | num_range_list += debug_information [i].num_range_lists; |
9684 | | |
9685 | 51 | if (num_range_list == 0) |
9686 | 36 | { |
9687 | | /* This can happen when the file was compiled with -gsplit-debug |
9688 | | which removes references to range lists from the primary .o file. */ |
9689 | 36 | printf (_("No range lists referenced by .debug_info section.\n")); |
9690 | 36 | return 1; |
9691 | 36 | } |
9692 | | |
9693 | 15 | range_entry_fill = range_entries = XNEWVEC (struct range_entry, num_range_list); |
9694 | | |
9695 | 32 | for (i = 0; i < num_debug_info_entries; i++) |
9696 | 17 | { |
9697 | 17 | debug_info *debug_info_p = &debug_information[i]; |
9698 | 17 | unsigned int j; |
9699 | | |
9700 | 50 | for (j = 0; j < debug_info_p->num_range_lists; j++) |
9701 | 33 | { |
9702 | 33 | if (is_range_list_for_this_section (is_rnglists, debug_info_p->dwarf_version)) |
9703 | 33 | { |
9704 | 33 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; |
9705 | 33 | range_entry_fill->debug_info_p = debug_info_p; |
9706 | 33 | range_entry_fill++; |
9707 | 33 | } |
9708 | 33 | } |
9709 | 17 | } |
9710 | | |
9711 | 15 | assert (range_entry_fill >= range_entries); |
9712 | 15 | assert (num_range_list >= (unsigned int)(range_entry_fill - range_entries)); |
9713 | 15 | num_range_list = range_entry_fill - range_entries; |
9714 | 15 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
9715 | 15 | range_entry_compar); |
9716 | | |
9717 | 15 | putchar ('\n'); |
9718 | 15 | if (!is_rnglists) |
9719 | 15 | printf (_(" Offset Begin End\n")); |
9720 | | |
9721 | 15 | last_end = NULL; |
9722 | 48 | for (i = 0; i < num_range_list; i++) |
9723 | 33 | { |
9724 | 33 | struct range_entry *range_entry = &range_entries[i]; |
9725 | 33 | debug_info *debug_info_p = range_entry->debug_info_p; |
9726 | 33 | unsigned int pointer_size; |
9727 | 33 | uint64_t offset; |
9728 | 33 | unsigned char *next; |
9729 | 33 | uint64_t base_address; |
9730 | | |
9731 | 33 | pointer_size = debug_info_p->pointer_size; |
9732 | 33 | offset = range_entry->ranges_offset; |
9733 | 33 | base_address = debug_info_p->base_address; |
9734 | | |
9735 | | /* PR 17512: file: 001-101485-0.001:0.1. */ |
9736 | 33 | if (pointer_size < 2 || pointer_size > 8) |
9737 | 0 | { |
9738 | 0 | warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64 "\n"), |
9739 | 0 | pointer_size, offset); |
9740 | 0 | continue; |
9741 | 0 | } |
9742 | | |
9743 | 33 | if (offset > (size_t) (finish - section_begin)) |
9744 | 2 | { |
9745 | 2 | warn (_("Corrupt offset (%#" PRIx64 ") in range entry %u\n"), |
9746 | 2 | offset, i); |
9747 | 2 | continue; |
9748 | 2 | } |
9749 | | |
9750 | | /* If we've moved on to the next compile unit in the rnglists section - dump the unit header(s). */ |
9751 | 31 | if (is_rnglists && next_rnglists_cu_offset < offset) |
9752 | 0 | { |
9753 | 0 | while (ok_header && next_rnglists_cu_offset < offset) |
9754 | 0 | ok_header = display_debug_rnglists_unit_header (section, |
9755 | 0 | &next_rnglists_cu_offset, |
9756 | 0 | &offset_size); |
9757 | 0 | if (!ok_header) |
9758 | 0 | break; |
9759 | 0 | printf (_(" Offset Begin End\n")); |
9760 | 0 | } |
9761 | | |
9762 | 31 | next = section_begin + offset; /* Offset is from the section start, the base has already been added. */ |
9763 | | |
9764 | 31 | if (i == 0) |
9765 | 14 | { |
9766 | 14 | last_end = section_begin; |
9767 | 14 | if (is_rnglists) |
9768 | 0 | last_end += 2 * offset_size - 4 + 2 + 1 + 1 + 4; |
9769 | 14 | } |
9770 | | /* If multiple DWARF entities reference the same range then we will |
9771 | | have multiple entries in the `range_entries' list for the same |
9772 | | offset. Thanks to the sort above these will all be consecutive in |
9773 | | the `range_entries' list, so we can easily ignore duplicates |
9774 | | here. */ |
9775 | 31 | if (i > 0 && last_offset == offset) |
9776 | 0 | continue; |
9777 | 31 | last_offset = offset; |
9778 | | |
9779 | 31 | if (dwarf_check != 0) |
9780 | 0 | { |
9781 | 0 | if (start < next) |
9782 | 0 | { |
9783 | 0 | if (last_end != next) |
9784 | 0 | warn (_("There is a hole [%#tx - %#tx] in %s section.\n"), |
9785 | 0 | last_end - section_begin, next - section_begin, |
9786 | 0 | section->name); |
9787 | 0 | } |
9788 | 0 | else if (start > next) |
9789 | 0 | { |
9790 | 0 | if (next == last_start) |
9791 | 0 | continue; |
9792 | 0 | warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"), |
9793 | 0 | start - section_begin, next - section_begin, section->name); |
9794 | 0 | } |
9795 | 0 | } |
9796 | | |
9797 | 31 | start = next; |
9798 | 31 | last_start = next; |
9799 | | |
9800 | 31 | if (is_rnglists) |
9801 | 0 | last_end |
9802 | 0 | = display_debug_rnglists_list |
9803 | 0 | (start, finish, pointer_size, offset, base_address, |
9804 | 0 | debug_info_p->addr_base); |
9805 | 31 | else |
9806 | 31 | last_end |
9807 | 31 | = display_debug_ranges_list |
9808 | 31 | (start, finish, pointer_size, offset, base_address); |
9809 | 31 | } |
9810 | | |
9811 | | /* Display trailing empty (or unreferenced) compile units, if any. */ |
9812 | 15 | if (is_rnglists && ok_header) |
9813 | 0 | while (next_rnglists_cu_offset < section->size) |
9814 | 0 | if (!display_debug_rnglists_unit_header (section, |
9815 | 0 | &next_rnglists_cu_offset, |
9816 | 0 | &offset_size)) |
9817 | 0 | break; |
9818 | 15 | putchar ('\n'); |
9819 | | |
9820 | 15 | free (range_entries); |
9821 | | |
9822 | 15 | return 1; |
9823 | 15 | } |
9824 | | |
9825 | | typedef struct Frame_Chunk |
9826 | | { |
9827 | | struct Frame_Chunk *next; |
9828 | | unsigned char *chunk_start; |
9829 | | unsigned int ncols; |
9830 | | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
9831 | | short int *col_type; |
9832 | | int64_t *col_offset; |
9833 | | char *augmentation; |
9834 | | unsigned int code_factor; |
9835 | | int data_factor; |
9836 | | uint64_t pc_begin; |
9837 | | uint64_t pc_range; |
9838 | | unsigned int cfa_reg; |
9839 | | uint64_t cfa_offset; |
9840 | | bool cfa_ofs_signed_p; |
9841 | | unsigned int ra; |
9842 | | unsigned char fde_encoding; |
9843 | | unsigned char cfa_exp; |
9844 | | unsigned char ptr_size; |
9845 | | unsigned char segment_size; |
9846 | | } |
9847 | | Frame_Chunk; |
9848 | | |
9849 | | typedef bool (*is_mach_augmentation_ftype) (char c); |
9850 | | static is_mach_augmentation_ftype is_mach_augmentation; |
9851 | | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
9852 | | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; |
9853 | | static const char *const *dwarf_regnames; |
9854 | | static unsigned int dwarf_regnames_count; |
9855 | | static bool is_aarch64; |
9856 | | |
9857 | | /* A marker for a col_type that means this column was never referenced |
9858 | | in the frame info. */ |
9859 | 589k | #define DW_CFA_unreferenced (-1) |
9860 | | |
9861 | | /* Return 0 if no more space is needed, 1 if more space is needed, |
9862 | | -1 for invalid reg. */ |
9863 | | |
9864 | | static int |
9865 | | frame_need_space (Frame_Chunk *fc, unsigned int reg) |
9866 | 301k | { |
9867 | 301k | unsigned int prev = fc->ncols; |
9868 | | |
9869 | 301k | if (reg < (unsigned int) fc->ncols) |
9870 | 283k | return 0; |
9871 | | |
9872 | 17.9k | if (dwarf_regnames_count > 0 |
9873 | 17.9k | && reg > dwarf_regnames_count) |
9874 | 5.52k | return -1; |
9875 | | |
9876 | 12.3k | fc->ncols = reg + 1; |
9877 | | /* PR 17512: file: 10450-2643-0.004. |
9878 | | If reg == -1 then this can happen... */ |
9879 | 12.3k | if (fc->ncols == 0) |
9880 | 0 | return -1; |
9881 | | |
9882 | | /* PR 17512: file: 2844a11d. */ |
9883 | 12.3k | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
9884 | 0 | { |
9885 | 0 | error (_("Unfeasibly large register number: %u\n"), reg); |
9886 | 0 | fc->ncols = 0; |
9887 | | /* FIXME: 1024 is an arbitrary limit. Increase it if |
9888 | | we ever encounter a valid binary that exceeds it. */ |
9889 | 0 | return -1; |
9890 | 0 | } |
9891 | | |
9892 | 12.3k | fc->col_type = xcrealloc (fc->col_type, fc->ncols, |
9893 | 12.3k | sizeof (*fc->col_type)); |
9894 | 12.3k | fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, |
9895 | 12.3k | sizeof (*fc->col_offset)); |
9896 | | /* PR 17512: file:002-10025-0.005. */ |
9897 | 12.3k | if (fc->col_type == NULL || fc->col_offset == NULL) |
9898 | 0 | { |
9899 | 0 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), |
9900 | 0 | fc->ncols); |
9901 | 0 | fc->ncols = 0; |
9902 | 0 | return -1; |
9903 | 0 | } |
9904 | | |
9905 | 257k | while (prev < fc->ncols) |
9906 | 244k | { |
9907 | 244k | fc->col_type[prev] = DW_CFA_unreferenced; |
9908 | 244k | fc->col_offset[prev] = 0; |
9909 | 244k | prev++; |
9910 | 244k | } |
9911 | 12.3k | return 1; |
9912 | 12.3k | } |
9913 | | |
9914 | | static const char *const dwarf_regnames_i386[] = |
9915 | | { |
9916 | | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
9917 | | "esp", "ebp", "esi", "edi", /* 4 - 7 */ |
9918 | | "eip", "eflags", NULL, /* 8 - 10 */ |
9919 | | "st0", "st1", "st2", "st3", /* 11 - 14 */ |
9920 | | "st4", "st5", "st6", "st7", /* 15 - 18 */ |
9921 | | NULL, NULL, /* 19 - 20 */ |
9922 | | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ |
9923 | | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ |
9924 | | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ |
9925 | | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ |
9926 | | "fcw", "fsw", "mxcsr", /* 37 - 39 */ |
9927 | | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ |
9928 | | "tr", "ldtr", /* 48 - 49 */ |
9929 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ |
9930 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ |
9931 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ |
9932 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ |
9933 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ |
9934 | | NULL, NULL, NULL, /* 90 - 92 */ |
9935 | | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ |
9936 | | }; |
9937 | | |
9938 | | static const char *const dwarf_regnames_iamcu[] = |
9939 | | { |
9940 | | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
9941 | | "esp", "ebp", "esi", "edi", /* 4 - 7 */ |
9942 | | "eip", "eflags", NULL, /* 8 - 10 */ |
9943 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ |
9944 | | NULL, NULL, /* 19 - 20 */ |
9945 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ |
9946 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ |
9947 | | NULL, NULL, NULL, /* 37 - 39 */ |
9948 | | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ |
9949 | | "tr", "ldtr", /* 48 - 49 */ |
9950 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ |
9951 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ |
9952 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ |
9953 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ |
9954 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ |
9955 | | NULL, NULL, NULL, /* 90 - 92 */ |
9956 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ |
9957 | | }; |
9958 | | |
9959 | | static void |
9960 | | init_dwarf_regnames_i386 (void) |
9961 | 944 | { |
9962 | 944 | dwarf_regnames = dwarf_regnames_i386; |
9963 | 944 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); |
9964 | 944 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
9965 | 944 | } |
9966 | | |
9967 | | static void |
9968 | | init_dwarf_regnames_iamcu (void) |
9969 | 1.88k | { |
9970 | 1.88k | dwarf_regnames = dwarf_regnames_iamcu; |
9971 | 1.88k | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); |
9972 | 1.88k | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
9973 | 1.88k | } |
9974 | | |
9975 | | static const char *const DW_CFA_GNU_window_save_name[] = |
9976 | | { |
9977 | | "DW_CFA_GNU_window_save", |
9978 | | "DW_CFA_AARCH64_negate_ra_state" |
9979 | | }; |
9980 | | |
9981 | | static const char *const dwarf_regnames_x86_64[] = |
9982 | | { |
9983 | | "rax", "rdx", "rcx", "rbx", |
9984 | | "rsi", "rdi", "rbp", "rsp", |
9985 | | "r8", "r9", "r10", "r11", |
9986 | | "r12", "r13", "r14", "r15", |
9987 | | "rip", |
9988 | | "xmm0", "xmm1", "xmm2", "xmm3", |
9989 | | "xmm4", "xmm5", "xmm6", "xmm7", |
9990 | | "xmm8", "xmm9", "xmm10", "xmm11", |
9991 | | "xmm12", "xmm13", "xmm14", "xmm15", |
9992 | | "st0", "st1", "st2", "st3", |
9993 | | "st4", "st5", "st6", "st7", |
9994 | | "mm0", "mm1", "mm2", "mm3", |
9995 | | "mm4", "mm5", "mm6", "mm7", |
9996 | | "rflags", |
9997 | | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, |
9998 | | "fs.base", "gs.base", NULL, NULL, |
9999 | | "tr", "ldtr", |
10000 | | "mxcsr", "fcw", "fsw", |
10001 | | "xmm16", "xmm17", "xmm18", "xmm19", |
10002 | | "xmm20", "xmm21", "xmm22", "xmm23", |
10003 | | "xmm24", "xmm25", "xmm26", "xmm27", |
10004 | | "xmm28", "xmm29", "xmm30", "xmm31", |
10005 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ |
10006 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ |
10007 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ |
10008 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ |
10009 | | NULL, NULL, NULL, /* 115 - 117 */ |
10010 | | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7", |
10011 | | "bnd0", "bnd1", "bnd2", "bnd3", |
10012 | | }; |
10013 | | |
10014 | | static void |
10015 | | init_dwarf_regnames_x86_64 (void) |
10016 | 2.89k | { |
10017 | 2.89k | dwarf_regnames = dwarf_regnames_x86_64; |
10018 | 2.89k | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); |
10019 | 2.89k | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
10020 | 2.89k | } |
10021 | | |
10022 | | static const char *const dwarf_regnames_aarch64[] = |
10023 | | { |
10024 | | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
10025 | | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", |
10026 | | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
10027 | | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", |
10028 | | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, |
10029 | | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
10030 | | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", |
10031 | | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", |
10032 | | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
10033 | | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", |
10034 | | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
10035 | | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", |
10036 | | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
10037 | | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", |
10038 | | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", |
10039 | | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", |
10040 | | }; |
10041 | | |
10042 | | static void |
10043 | | init_dwarf_regnames_aarch64 (void) |
10044 | 10.4k | { |
10045 | 10.4k | dwarf_regnames = dwarf_regnames_aarch64; |
10046 | 10.4k | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); |
10047 | 10.4k | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
10048 | 10.4k | is_aarch64 = true; |
10049 | 10.4k | } |
10050 | | |
10051 | | static const char *const dwarf_regnames_s390[] = |
10052 | | { |
10053 | | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ |
10054 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
10055 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
10056 | | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", |
10057 | | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", |
10058 | | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", |
10059 | | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", |
10060 | | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", |
10061 | | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", |
10062 | | "pswm", "pswa", |
10063 | | NULL, NULL, |
10064 | | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", |
10065 | | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", |
10066 | | }; |
10067 | | |
10068 | | static void |
10069 | | init_dwarf_regnames_s390 (void) |
10070 | 980 | { |
10071 | 980 | dwarf_regnames = dwarf_regnames_s390; |
10072 | 980 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); |
10073 | 980 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
10074 | 980 | } |
10075 | | |
10076 | | static const char *const dwarf_regnames_riscv[] = |
10077 | | { |
10078 | | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ |
10079 | | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ |
10080 | | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ |
10081 | | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ |
10082 | | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ |
10083 | | "fs0", "fs1", /* 40 - 41 */ |
10084 | | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ |
10085 | | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ |
10086 | | "fs10", "fs11", /* 58 - 59 */ |
10087 | | "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */ |
10088 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 64 - 71 */ |
10089 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 72 - 79 */ |
10090 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 80 - 87 */ |
10091 | | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 88 - 95 */ |
10092 | | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */ |
10093 | | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */ |
10094 | | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */ |
10095 | | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */ |
10096 | | }; |
10097 | | |
10098 | | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
10099 | | the large number of CSRs. */ |
10100 | | |
10101 | | static const char * |
10102 | | regname_internal_riscv (unsigned int regno) |
10103 | 32 | { |
10104 | 32 | const char *name = NULL; |
10105 | | |
10106 | | /* Lookup in the table first, this covers GPR and FPR. */ |
10107 | 32 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) |
10108 | 31 | name = dwarf_regnames_riscv [regno]; |
10109 | 1 | else if (regno >= 4096 && regno <= 8191) |
10110 | 0 | { |
10111 | | /* This might be a CSR, these live in a sparse number space from 4096 |
10112 | | to 8191 These numbers are defined in the RISC-V ELF ABI |
10113 | | document. */ |
10114 | 0 | switch (regno) |
10115 | 0 | { |
10116 | 0 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
10117 | 0 | case VALUE + 4096: name = #NAME; break; |
10118 | 0 | #include "opcode/riscv-opc.h" |
10119 | 0 | #undef DECLARE_CSR |
10120 | | |
10121 | 0 | default: |
10122 | 0 | { |
10123 | 0 | static char csr_name[10]; |
10124 | 0 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); |
10125 | 0 | name = csr_name; |
10126 | 0 | } |
10127 | 0 | break; |
10128 | 0 | } |
10129 | 0 | } |
10130 | | |
10131 | 32 | return name; |
10132 | 32 | } |
10133 | | |
10134 | | static void |
10135 | | init_dwarf_regnames_riscv (void) |
10136 | 1.16k | { |
10137 | 1.16k | dwarf_regnames = NULL; |
10138 | 1.16k | dwarf_regnames_count = 8192; |
10139 | 1.16k | dwarf_regnames_lookup_func = regname_internal_riscv; |
10140 | 1.16k | } |
10141 | | |
10142 | | static const char *const dwarf_regnames_loongarch[] = |
10143 | | { |
10144 | | "$zero", "$ra", "$tp", "$sp", "$a0", "$a1", "$a2", "$a3", /* 0-7 */ |
10145 | | "$a4", "$a5", "$a6", "$a7", "$t0", "$t1", "$t2", "$t3", /* 8-15 */ |
10146 | | "$t4", "$t5", "$t6", "$t7", "$t8", "$r21","$fp", "$s0", /* 16-23 */ |
10147 | | "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7", "$s8", /* 24-31 */ |
10148 | | "$fa0", "$fa1", "$fa2", "$fa3", "$fa4", "$fa5", "$fa6", /* 32-38 */ |
10149 | | "$fa7", "$ft0", "$ft1", "$ft2", "$ft3", "$ft4", "$ft5", /* 39-45 */ |
10150 | | "$ft6", "$ft7", "$ft8", "$ft9", "$ft10", "$ft11", "$ft12", /* 46-52 */ |
10151 | | "$ft13", "$ft14", "$ft15", "$fs0", "$fs1", "$fs2", "$fs3", /* 53-59 */ |
10152 | | "$fs4", "$fs5", "$fs6", "$fs7", /* 60-63 */ |
10153 | | }; |
10154 | | |
10155 | | static void |
10156 | | init_dwarf_regnames_loongarch (void) |
10157 | 673 | { |
10158 | 673 | dwarf_regnames = dwarf_regnames_loongarch; |
10159 | 673 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_loongarch); |
10160 | 673 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
10161 | 673 | } |
10162 | | |
10163 | | static bool |
10164 | | is_nomach_augmentation (char c ATTRIBUTE_UNUSED) |
10165 | 3 | { |
10166 | 3 | return false; |
10167 | 3 | } |
10168 | | |
10169 | | static bool |
10170 | | is_aarch64_augmentation (char c) |
10171 | 0 | { |
10172 | 0 | return (c == 'B' || c == 'G'); |
10173 | 0 | } |
10174 | | |
10175 | | void |
10176 | | init_dwarf_by_elf_machine_code (unsigned int e_machine) |
10177 | 80.7k | { |
10178 | 80.7k | is_mach_augmentation = is_nomach_augmentation; |
10179 | 80.7k | dwarf_regnames_lookup_func = NULL; |
10180 | 80.7k | is_aarch64 = false; |
10181 | | |
10182 | 80.7k | switch (e_machine) |
10183 | 80.7k | { |
10184 | 360 | case EM_386: |
10185 | 360 | init_dwarf_regnames_i386 (); |
10186 | 360 | break; |
10187 | | |
10188 | 1.88k | case EM_IAMCU: |
10189 | 1.88k | init_dwarf_regnames_iamcu (); |
10190 | 1.88k | break; |
10191 | | |
10192 | 604 | case EM_X86_64: |
10193 | 1.10k | case EM_L1OM: |
10194 | 1.45k | case EM_K1OM: |
10195 | 1.45k | init_dwarf_regnames_x86_64 (); |
10196 | 1.45k | break; |
10197 | | |
10198 | 2.15k | case EM_AARCH64: |
10199 | 2.15k | init_dwarf_regnames_aarch64 (); |
10200 | 2.15k | is_mach_augmentation = is_aarch64_augmentation; |
10201 | 2.15k | break; |
10202 | | |
10203 | 887 | case EM_S390: |
10204 | 887 | init_dwarf_regnames_s390 (); |
10205 | 887 | break; |
10206 | | |
10207 | 420 | case EM_RISCV: |
10208 | 420 | init_dwarf_regnames_riscv (); |
10209 | 420 | break; |
10210 | | |
10211 | 463 | case EM_LOONGARCH: |
10212 | 463 | init_dwarf_regnames_loongarch (); |
10213 | 463 | break; |
10214 | | |
10215 | 73.1k | default: |
10216 | 73.1k | break; |
10217 | 80.7k | } |
10218 | 80.7k | } |
10219 | | |
10220 | | /* Initialize the DWARF register name lookup state based on the |
10221 | | architecture and specific machine type of a BFD. */ |
10222 | | |
10223 | | void |
10224 | | init_dwarf_by_bfd_arch_and_mach (enum bfd_architecture arch, |
10225 | | unsigned long mach) |
10226 | 32.0k | { |
10227 | 32.0k | is_mach_augmentation = is_nomach_augmentation; |
10228 | 32.0k | dwarf_regnames_lookup_func = NULL; |
10229 | 32.0k | is_aarch64 = false; |
10230 | | |
10231 | 32.0k | switch (arch) |
10232 | 32.0k | { |
10233 | 2.02k | case bfd_arch_i386: |
10234 | 2.02k | switch (mach) |
10235 | 2.02k | { |
10236 | 1.43k | case bfd_mach_x86_64: |
10237 | 1.43k | case bfd_mach_x86_64_intel_syntax: |
10238 | 1.43k | case bfd_mach_x64_32: |
10239 | 1.43k | case bfd_mach_x64_32_intel_syntax: |
10240 | 1.43k | init_dwarf_regnames_x86_64 (); |
10241 | 1.43k | break; |
10242 | | |
10243 | 584 | default: |
10244 | 584 | init_dwarf_regnames_i386 (); |
10245 | 584 | break; |
10246 | 2.02k | } |
10247 | 2.02k | break; |
10248 | | |
10249 | 2.02k | case bfd_arch_iamcu: |
10250 | 0 | init_dwarf_regnames_iamcu (); |
10251 | 0 | break; |
10252 | | |
10253 | 8.33k | case bfd_arch_aarch64: |
10254 | 8.33k | init_dwarf_regnames_aarch64(); |
10255 | 8.33k | is_mach_augmentation = is_aarch64_augmentation; |
10256 | 8.33k | break; |
10257 | | |
10258 | 93 | case bfd_arch_s390: |
10259 | 93 | init_dwarf_regnames_s390 (); |
10260 | 93 | break; |
10261 | | |
10262 | 742 | case bfd_arch_riscv: |
10263 | 742 | init_dwarf_regnames_riscv (); |
10264 | 742 | break; |
10265 | | |
10266 | 210 | case bfd_arch_loongarch: |
10267 | 210 | init_dwarf_regnames_loongarch (); |
10268 | 210 | break; |
10269 | | |
10270 | 20.6k | default: |
10271 | 20.6k | break; |
10272 | 32.0k | } |
10273 | 32.0k | } |
10274 | | |
10275 | | static const char * |
10276 | | regname_internal_by_table_only (unsigned int regno) |
10277 | 97.2k | { |
10278 | 97.2k | if (dwarf_regnames != NULL |
10279 | 97.2k | && regno < dwarf_regnames_count |
10280 | 95.4k | && dwarf_regnames [regno] != NULL) |
10281 | 91.1k | return dwarf_regnames [regno]; |
10282 | | |
10283 | 6.16k | return NULL; |
10284 | 97.2k | } |
10285 | | |
10286 | | static const char * |
10287 | | regname (unsigned int regno, int name_only_p) |
10288 | 108k | { |
10289 | 108k | static char reg[64]; |
10290 | | |
10291 | 108k | const char *name = NULL; |
10292 | | |
10293 | 108k | if (dwarf_regnames_lookup_func != NULL) |
10294 | 97.2k | name = dwarf_regnames_lookup_func (regno); |
10295 | | |
10296 | 108k | if (name != NULL) |
10297 | 91.1k | { |
10298 | 91.1k | if (name_only_p) |
10299 | 10.2k | return name; |
10300 | 80.8k | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); |
10301 | 80.8k | } |
10302 | 17.7k | else |
10303 | 17.7k | snprintf (reg, sizeof (reg), "r%d", regno); |
10304 | 98.5k | return reg; |
10305 | 108k | } |
10306 | | |
10307 | | static void |
10308 | | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
10309 | 0 | { |
10310 | 0 | unsigned int r; |
10311 | 0 | char tmp[100]; |
10312 | |
|
10313 | 0 | if (*max_regs != fc->ncols) |
10314 | 0 | *max_regs = fc->ncols; |
10315 | |
|
10316 | 0 | if (*need_col_headers) |
10317 | 0 | { |
10318 | 0 | *need_col_headers = 0; |
10319 | |
|
10320 | 0 | printf ("%-*s CFA ", eh_addr_size * 2, " LOC"); |
10321 | |
|
10322 | 0 | for (r = 0; r < *max_regs; r++) |
10323 | 0 | if (fc->col_type[r] != DW_CFA_unreferenced) |
10324 | 0 | { |
10325 | 0 | if (r == fc->ra) |
10326 | 0 | printf ("ra "); |
10327 | 0 | else |
10328 | 0 | printf ("%-5s ", regname (r, 1)); |
10329 | 0 | } |
10330 | |
|
10331 | 0 | printf ("\n"); |
10332 | 0 | } |
10333 | |
|
10334 | 0 | print_hex (fc->pc_begin, eh_addr_size); |
10335 | 0 | if (fc->cfa_exp) |
10336 | 0 | strcpy (tmp, "exp"); |
10337 | 0 | else |
10338 | 0 | sprintf (tmp, (fc->cfa_ofs_signed_p ? "%s%+" PRId64 : "%s+%" PRIu64), |
10339 | 0 | regname (fc->cfa_reg, 1), fc->cfa_offset); |
10340 | 0 | printf ("%-8s ", tmp); |
10341 | |
|
10342 | 0 | for (r = 0; r < fc->ncols; r++) |
10343 | 0 | { |
10344 | 0 | if (fc->col_type[r] != DW_CFA_unreferenced) |
10345 | 0 | { |
10346 | 0 | switch (fc->col_type[r]) |
10347 | 0 | { |
10348 | 0 | case DW_CFA_undefined: |
10349 | 0 | strcpy (tmp, "u"); |
10350 | 0 | break; |
10351 | 0 | case DW_CFA_same_value: |
10352 | 0 | strcpy (tmp, "s"); |
10353 | 0 | break; |
10354 | 0 | case DW_CFA_offset: |
10355 | 0 | sprintf (tmp, "c%+" PRId64, fc->col_offset[r]); |
10356 | 0 | break; |
10357 | 0 | case DW_CFA_val_offset: |
10358 | 0 | sprintf (tmp, "v%+" PRId64, fc->col_offset[r]); |
10359 | 0 | break; |
10360 | 0 | case DW_CFA_register: |
10361 | 0 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
10362 | 0 | break; |
10363 | 0 | case DW_CFA_expression: |
10364 | 0 | strcpy (tmp, "exp"); |
10365 | 0 | break; |
10366 | 0 | case DW_CFA_val_expression: |
10367 | 0 | strcpy (tmp, "vexp"); |
10368 | 0 | break; |
10369 | 0 | default: |
10370 | 0 | strcpy (tmp, "n/a"); |
10371 | 0 | break; |
10372 | 0 | } |
10373 | 0 | printf ("%-5s ", tmp); |
10374 | 0 | } |
10375 | 0 | } |
10376 | 0 | printf ("\n"); |
10377 | 0 | } |
10378 | | |
10379 | 492 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
10380 | | |
10381 | | static unsigned char * |
10382 | | read_cie (unsigned char *start, unsigned char *end, |
10383 | | Frame_Chunk **p_cie, int *p_version, |
10384 | | uint64_t *p_aug_len, unsigned char **p_aug) |
10385 | 554 | { |
10386 | 554 | int version; |
10387 | 554 | Frame_Chunk *fc; |
10388 | 554 | unsigned char *augmentation_data = NULL; |
10389 | 554 | uint64_t augmentation_data_len = 0; |
10390 | | |
10391 | 554 | * p_cie = NULL; |
10392 | | /* PR 17512: file: 001-228113-0.004. */ |
10393 | 554 | if (start >= end) |
10394 | 11 | return end; |
10395 | | |
10396 | 543 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
10397 | 543 | memset (fc, 0, sizeof (Frame_Chunk)); |
10398 | | |
10399 | 543 | fc->col_type = xmalloc (sizeof (*fc->col_type)); |
10400 | 543 | fc->col_offset = xmalloc (sizeof (*fc->col_offset)); |
10401 | | |
10402 | 543 | version = *start++; |
10403 | | |
10404 | 543 | fc->augmentation = (char *) start; |
10405 | | /* PR 17512: file: 001-228113-0.004. |
10406 | | Skip past augmentation name, but avoid running off the end of the data. */ |
10407 | 4.23k | while (start < end) |
10408 | 4.23k | if (* start ++ == '\0') |
10409 | 539 | break; |
10410 | 543 | if (start == end) |
10411 | 4 | { |
10412 | 4 | warn (_("No terminator for augmentation name\n")); |
10413 | 4 | goto fail; |
10414 | 4 | } |
10415 | | |
10416 | 539 | if (strcmp (fc->augmentation, "eh") == 0) |
10417 | 1 | { |
10418 | 1 | if (eh_addr_size > (size_t) (end - start)) |
10419 | 0 | goto fail; |
10420 | 1 | start += eh_addr_size; |
10421 | 1 | } |
10422 | | |
10423 | 539 | if (version >= 4) |
10424 | 94 | { |
10425 | 94 | if (2 > (size_t) (end - start)) |
10426 | 0 | goto fail; |
10427 | 94 | GET (fc->ptr_size, 1); |
10428 | 94 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
10429 | 57 | { |
10430 | 57 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); |
10431 | 57 | goto fail; |
10432 | 57 | } |
10433 | | |
10434 | 37 | GET (fc->segment_size, 1); |
10435 | | /* PR 17512: file: e99d2804. */ |
10436 | 37 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) |
10437 | 4 | { |
10438 | 4 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); |
10439 | 4 | goto fail; |
10440 | 4 | } |
10441 | | |
10442 | 33 | eh_addr_size = fc->ptr_size; |
10443 | 33 | } |
10444 | 445 | else |
10445 | 445 | { |
10446 | 445 | fc->ptr_size = eh_addr_size; |
10447 | 445 | fc->segment_size = 0; |
10448 | 445 | } |
10449 | | |
10450 | 478 | READ_ULEB (fc->code_factor, start, end); |
10451 | 478 | READ_SLEB (fc->data_factor, start, end); |
10452 | | |
10453 | 478 | if (start >= end) |
10454 | 7 | goto fail; |
10455 | | |
10456 | 471 | if (version == 1) |
10457 | 361 | { |
10458 | 361 | GET (fc->ra, 1); |
10459 | 361 | } |
10460 | 110 | else |
10461 | 110 | { |
10462 | 110 | READ_ULEB (fc->ra, start, end); |
10463 | 110 | } |
10464 | | |
10465 | 471 | if (fc->augmentation[0] == 'z') |
10466 | 356 | { |
10467 | 356 | if (start >= end) |
10468 | 0 | goto fail; |
10469 | 356 | READ_ULEB (augmentation_data_len, start, end); |
10470 | 356 | augmentation_data = start; |
10471 | | /* PR 17512: file: 11042-2589-0.004. */ |
10472 | 356 | if (augmentation_data_len > (size_t) (end - start)) |
10473 | 5 | { |
10474 | 5 | warn (_("Augmentation data too long: %#" PRIx64 |
10475 | 5 | ", expected at most %#tx\n"), |
10476 | 5 | augmentation_data_len, end - start); |
10477 | 5 | goto fail; |
10478 | 5 | } |
10479 | 351 | start += augmentation_data_len; |
10480 | 351 | } |
10481 | | |
10482 | 466 | if (augmentation_data_len) |
10483 | 344 | { |
10484 | 344 | unsigned char *p; |
10485 | 344 | unsigned char *q; |
10486 | 344 | unsigned char *qend; |
10487 | | |
10488 | 344 | p = (unsigned char *) fc->augmentation + 1; |
10489 | 344 | q = augmentation_data; |
10490 | 344 | qend = q + augmentation_data_len; |
10491 | | |
10492 | 688 | while (p < end && q < qend) |
10493 | 347 | { |
10494 | 347 | if (*p == 'L') |
10495 | 0 | q++; |
10496 | 347 | else if (*p == 'P') |
10497 | 0 | q += 1 + size_of_encoded_value (*q); |
10498 | 347 | else if (*p == 'R') |
10499 | 343 | fc->fde_encoding = *q++; |
10500 | 4 | else if (*p == 'S') |
10501 | 1 | ; |
10502 | 3 | else if (is_mach_augmentation (*p)) |
10503 | 0 | ; |
10504 | 3 | else |
10505 | 3 | break; |
10506 | 344 | p++; |
10507 | 344 | } |
10508 | | /* Note - it is OK if this loop terminates with q < qend. |
10509 | | Padding may have been inserted to align the end of the CIE. */ |
10510 | 344 | } |
10511 | | |
10512 | 466 | *p_cie = fc; |
10513 | 466 | if (p_version) |
10514 | 466 | *p_version = version; |
10515 | 466 | if (p_aug_len) |
10516 | 466 | { |
10517 | 466 | *p_aug_len = augmentation_data_len; |
10518 | 466 | *p_aug = augmentation_data; |
10519 | 466 | } |
10520 | 466 | return start; |
10521 | | |
10522 | 77 | fail: |
10523 | 77 | free (fc->col_offset); |
10524 | 77 | free (fc->col_type); |
10525 | 77 | free (fc); |
10526 | 77 | return end; |
10527 | 471 | } |
10528 | | |
10529 | | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
10530 | | If do_wide is not enabled, then formats the output to fit into 80 columns. |
10531 | | PRINTED contains the number of characters already written to the current |
10532 | | output line. */ |
10533 | | |
10534 | | static void |
10535 | | display_data (size_t printed, const unsigned char *data, size_t len) |
10536 | 374 | { |
10537 | 374 | if (do_wide || len < ((80 - printed) / 3)) |
10538 | 857 | for (printed = 0; printed < len; ++printed) |
10539 | 490 | printf (" %02x", data[printed]); |
10540 | 7 | else |
10541 | 7 | { |
10542 | 2.30k | for (printed = 0; printed < len; ++printed) |
10543 | 2.29k | { |
10544 | 2.29k | if (printed % (80 / 3) == 0) |
10545 | 91 | putchar ('\n'); |
10546 | 2.29k | printf (" %02x", data[printed]); |
10547 | 2.29k | } |
10548 | 7 | } |
10549 | 374 | } |
10550 | | |
10551 | | /* Prints out the contents on the augmentation data array. |
10552 | | If do_wide is not enabled, then formats the output to fit into 80 columns. */ |
10553 | | |
10554 | | static void |
10555 | | display_augmentation_data (const unsigned char * data, uint64_t len) |
10556 | 371 | { |
10557 | 371 | size_t i; |
10558 | | |
10559 | 371 | i = printf (_(" Augmentation data: ")); |
10560 | 371 | display_data (i, data, len); |
10561 | 371 | } |
10562 | | |
10563 | | static const char * |
10564 | | decode_eh_encoding (unsigned int value) |
10565 | 240 | { |
10566 | 240 | if (value == DW_EH_PE_omit) |
10567 | 3 | return "omit"; |
10568 | | |
10569 | 237 | char * format; |
10570 | 237 | switch (value & 0x0f) |
10571 | 237 | { |
10572 | 3 | case DW_EH_PE_uleb128: format = "uleb128"; break; |
10573 | 2 | case DW_EH_PE_udata2: format = "udata2"; break; |
10574 | 73 | case DW_EH_PE_udata4: format = "udata4"; break; |
10575 | 9 | case DW_EH_PE_udata8: format = "udata8"; break; |
10576 | 0 | case DW_EH_PE_sleb128: format = "sleb128"; break; |
10577 | 2 | case DW_EH_PE_sdata2: format = "sdata2"; break; |
10578 | 136 | case DW_EH_PE_sdata4: format = "sdata4"; break; |
10579 | 4 | case DW_EH_PE_sdata8: format = "sdata8"; break; |
10580 | | |
10581 | 8 | default: format = "<unknown format>"; break; /* FIXME: Generate a warning ? */ |
10582 | 237 | } |
10583 | | |
10584 | 237 | char * application; |
10585 | 237 | switch (value & 0xf0) |
10586 | 237 | { |
10587 | 82 | case DW_EH_PE_absptr: application = "absolute"; break; |
10588 | 70 | case DW_EH_PE_pcrel: application = "pcrel"; break; |
10589 | 3 | case DW_EH_PE_textrel: application = "textrel"; break; /* FIXME: Is this allowed ? */ |
10590 | 69 | case DW_EH_PE_datarel: application = "datarel"; break; |
10591 | 0 | case DW_EH_PE_funcrel: application = "funcrel"; break; /* FIXME: Is this allowed ? */ |
10592 | 1 | case DW_EH_PE_aligned: application = "aligned"; break; /* FIXME: Is this allowed ? */ |
10593 | 0 | case DW_EH_PE_indirect: application = "indirect"; break; /* FIXME: Is this allowed ? */ |
10594 | | |
10595 | 12 | default: application = "<unknown application method>"; break; /* FIXME: Generate a warning ? */ |
10596 | 237 | } |
10597 | | |
10598 | 237 | static char buffer[128]; |
10599 | 237 | sprintf (buffer, "%s, %s", format, application); |
10600 | 237 | return buffer; |
10601 | 237 | } |
10602 | | |
10603 | | /* Reads a value stored at START encoded according to ENCODING. |
10604 | | Does not read from, or past, END. |
10605 | | Upon success, returns the read value and sets * RETURN_LEN to |
10606 | | the number of bytes read. |
10607 | | Upon failure returns zero and sets * RETURN_LEN to 0. |
10608 | | |
10609 | | Note: does not perform any application transformations to the value. */ |
10610 | | |
10611 | | static uint64_t |
10612 | | get_encoded_eh_value (unsigned int encoding, |
10613 | | unsigned char * start, |
10614 | | unsigned char * end, |
10615 | | unsigned int * return_len) |
10616 | 1.43k | { |
10617 | 1.43k | uint64_t val; |
10618 | 1.43k | unsigned int len; |
10619 | 1.43k | int status; |
10620 | 1.43k | unsigned char * old_start; |
10621 | | |
10622 | 1.43k | switch (encoding & 0x0f) |
10623 | 1.43k | { |
10624 | 2 | case DW_EH_PE_uleb128: |
10625 | 2 | val = read_leb128 (start, end, false, & len, & status); |
10626 | 2 | if (status != 0) |
10627 | 0 | len = 0; |
10628 | 2 | break; |
10629 | | |
10630 | 0 | case DW_EH_PE_sleb128: |
10631 | 0 | val = read_leb128 (start, end, true, & len, & status); |
10632 | 0 | if (status != 0) |
10633 | 0 | len = 0; |
10634 | 0 | break; |
10635 | | |
10636 | 13 | case DW_EH_PE_udata2: |
10637 | 13 | old_start = start; |
10638 | 13 | SAFE_BYTE_GET_AND_INC (val, start, 2, end); |
10639 | 13 | len = start - old_start == 2 ? 2 : 0; |
10640 | 13 | break; |
10641 | | |
10642 | 71 | case DW_EH_PE_udata4: |
10643 | 71 | old_start = start; |
10644 | 71 | SAFE_BYTE_GET_AND_INC (val, start, 4, end); |
10645 | 71 | len = start - old_start == 4 ? 4 : 0; |
10646 | 71 | break; |
10647 | | |
10648 | 138 | case DW_EH_PE_udata8: |
10649 | 138 | old_start = start; |
10650 | 138 | SAFE_BYTE_GET_AND_INC (val, start, 8, end); |
10651 | 138 | len = start - old_start == 8 ? 8 : 0; |
10652 | 138 | break; |
10653 | | |
10654 | 2 | case DW_EH_PE_sdata2: |
10655 | 2 | old_start = start; |
10656 | 2 | SAFE_SIGNED_BYTE_GET_AND_INC (val, start, 2, end); |
10657 | 2 | len = start - old_start == 2 ? 2 : 0; |
10658 | 2 | break; |
10659 | | |
10660 | 1.19k | case DW_EH_PE_sdata4: |
10661 | 1.19k | old_start = start; |
10662 | 1.19k | SAFE_SIGNED_BYTE_GET_AND_INC (val, start, 4, end); |
10663 | 1.19k | len = start - old_start == 4 ? 4 : 0; |
10664 | 1.19k | break; |
10665 | | |
10666 | 6 | case DW_EH_PE_sdata8: |
10667 | 6 | old_start = start; |
10668 | 6 | SAFE_SIGNED_BYTE_GET_AND_INC (val, start, 8, end); |
10669 | 6 | len = start - old_start == 8 ? 8 : 0; |
10670 | 6 | break; |
10671 | | |
10672 | 6 | default: |
10673 | 6 | goto fail; |
10674 | 1.43k | } |
10675 | | |
10676 | 1.42k | * return_len = len; |
10677 | 1.42k | return val; |
10678 | | |
10679 | 6 | fail: |
10680 | 6 | * return_len = 0; |
10681 | 6 | return 0; |
10682 | 1.43k | } |
10683 | | |
10684 | | static uint64_t |
10685 | | encoded_eh_offset (unsigned int encoding, |
10686 | | struct dwarf_section * section, |
10687 | | uint64_t section_offset, |
10688 | | uint64_t value) |
10689 | 1.34k | { |
10690 | 1.34k | switch (encoding & 0xf0) |
10691 | 1.34k | { |
10692 | 136 | default: |
10693 | | /* This should not happen. FIXME: warn ? */ |
10694 | 138 | case DW_EH_PE_absptr: |
10695 | 138 | return value; |
10696 | | |
10697 | 69 | case DW_EH_PE_pcrel: |
10698 | 69 | return value + (uint64_t)(section->address + section_offset); |
10699 | | |
10700 | 1.13k | case DW_EH_PE_datarel: |
10701 | 1.13k | return value + (uint64_t)section->address; |
10702 | 1.34k | } |
10703 | 1.34k | } |
10704 | | |
10705 | | static int |
10706 | | display_eh_frame_hdr (struct dwarf_section *section, |
10707 | | void *file ATTRIBUTE_UNUSED) |
10708 | 133 | { |
10709 | 133 | unsigned char *start = section->start; |
10710 | 133 | unsigned char *end = start + section->size; |
10711 | | |
10712 | 133 | introduce (section, false); |
10713 | | |
10714 | 133 | if (section->size < 6) |
10715 | 1 | { |
10716 | 1 | warn (_(".eh_frame_hdr section is too small\n")); |
10717 | 1 | return 0; |
10718 | 1 | } |
10719 | | |
10720 | 132 | unsigned int version = start[0]; |
10721 | 132 | if (version != 1) |
10722 | 52 | { |
10723 | 52 | warn (_("Unsupported .eh_frame_hdr version %u\n"), version); |
10724 | 52 | return 0; |
10725 | 52 | } |
10726 | | |
10727 | 80 | printf (_(" Version: %u\n"), version); |
10728 | | |
10729 | 80 | unsigned int ptr_enc = start[1]; |
10730 | | /* Strictly speaking this is the encoding format of the eh_frame_ptr field below. */ |
10731 | 80 | printf (_(" Pointer Encoding Format: %#x (%s)\n"), ptr_enc, decode_eh_encoding (ptr_enc)); |
10732 | | |
10733 | 80 | unsigned int count_enc = start[2]; |
10734 | 80 | printf (_(" Count Encoding Format: %#x (%s)\n"), count_enc, decode_eh_encoding (count_enc)); |
10735 | | |
10736 | 80 | unsigned int table_enc = start[3]; |
10737 | 80 | printf (_(" Table Encoding Format: %#x (%s)\n"), table_enc, decode_eh_encoding (table_enc)); |
10738 | | |
10739 | 80 | start += 4; |
10740 | | |
10741 | 80 | unsigned int len; |
10742 | | |
10743 | 80 | uint64_t eh_frame_ptr = get_encoded_eh_value (ptr_enc, start, end, & len); |
10744 | 80 | if (len == 0) |
10745 | 3 | { |
10746 | 3 | warn (_("unable to read eh_frame_ptr field in .eh_frame_hdr section\n")); |
10747 | 3 | return 0; |
10748 | 3 | } |
10749 | 77 | printf (_(" Start of frame section: %#" PRIx64), eh_frame_ptr); |
10750 | | |
10751 | 77 | uint64_t offset_eh_frame_ptr = encoded_eh_offset (ptr_enc, section, 4, eh_frame_ptr); |
10752 | 77 | if (offset_eh_frame_ptr != eh_frame_ptr) |
10753 | 69 | printf (_(" (offset: %#" PRIx64 ")"), offset_eh_frame_ptr); |
10754 | | |
10755 | 77 | printf ("\n"); |
10756 | 77 | start += len; |
10757 | | |
10758 | 77 | if (count_enc == DW_EH_PE_omit) |
10759 | 1 | { |
10760 | 1 | warn (_("It is suspicious to have a .eh_frame_hdr section with an empty search table\n")); |
10761 | 1 | return 0; |
10762 | 1 | } |
10763 | | |
10764 | 76 | if (count_enc & 0xf0) |
10765 | 2 | { |
10766 | 2 | warn (_("The count field format should be absolute, not relative to an address\n")); |
10767 | 2 | return 0; |
10768 | 2 | } |
10769 | | |
10770 | 74 | uint64_t fde_count = get_encoded_eh_value (count_enc, start, end, & len); |
10771 | 74 | if (len == 0) |
10772 | 2 | { |
10773 | 2 | warn (_("unable to read fde_count field in .eh_frame_hdr section\n")); |
10774 | 2 | return 0; |
10775 | 2 | } |
10776 | 72 | printf (_(" Entries in search table: %#" PRIx64), fde_count); |
10777 | 72 | printf ("\n"); |
10778 | 72 | start += len; |
10779 | | |
10780 | 72 | if (fde_count != 0 && table_enc == DW_EH_PE_omit) |
10781 | 0 | { |
10782 | 0 | warn (_("It is suspicious to have a .eh_frame_hdr section an empty table but a non empty count field\n")); |
10783 | 0 | return 0; |
10784 | 0 | } |
10785 | | |
10786 | 72 | uint64_t i; |
10787 | | /* Read and display the search table. */ |
10788 | 705 | for (i = 0; i < fde_count; i++) |
10789 | 645 | { |
10790 | 645 | uint64_t location, address; |
10791 | 645 | unsigned char * row_start = start; |
10792 | | |
10793 | 645 | location = get_encoded_eh_value (table_enc, start, end, & len); |
10794 | 645 | if (len == 0) |
10795 | 9 | { |
10796 | 9 | warn (_("Failed to read location field for entry %#" PRIx64 " in the .eh_frame_hdr's search table\n"), i); |
10797 | 9 | return 0; |
10798 | 9 | } |
10799 | 636 | start += len; |
10800 | | |
10801 | 636 | address = get_encoded_eh_value (table_enc, start, end, & len); |
10802 | 636 | if (len == 0) |
10803 | 3 | { |
10804 | 3 | warn (_("Failed to read address field for entry %#" PRIx64 " in the .eh_frame_hdr's search table\n"), i); |
10805 | 3 | return 0; |
10806 | 3 | } |
10807 | 633 | start += len; |
10808 | | |
10809 | | /* This format is intended to be compatible with the output of eu-readelf's -e option. */ |
10810 | 633 | printf (" %#" PRIx64 " (offset: %#" PRIx64 ") -> %#" PRIx64 " fde=[ %5" PRIx64 "]\n", |
10811 | 633 | location, |
10812 | 633 | encoded_eh_offset (table_enc, section, row_start - section->start, location), |
10813 | 633 | address, |
10814 | 633 | encoded_eh_offset (table_enc, section, row_start - section->start, address) - offset_eh_frame_ptr); |
10815 | 633 | } |
10816 | | |
10817 | 60 | printf ("\n"); |
10818 | 60 | return 1; |
10819 | 72 | } |
10820 | | |
10821 | | static int |
10822 | | display_debug_frames (struct dwarf_section *section, |
10823 | | void *file ATTRIBUTE_UNUSED) |
10824 | 2.99k | { |
10825 | 2.99k | unsigned char *start = section->start; |
10826 | 2.99k | unsigned char *end = start + section->size; |
10827 | 2.99k | unsigned char *section_start = start; |
10828 | 2.99k | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
10829 | 2.99k | Frame_Chunk *remembered_state = NULL; |
10830 | 2.99k | Frame_Chunk *rs; |
10831 | 2.99k | bool is_eh = strcmp (section->name, ".eh_frame") == 0; |
10832 | 2.99k | unsigned int max_regs = 0; |
10833 | 2.99k | const char *bad_reg = _("bad register: "); |
10834 | 2.99k | unsigned int saved_eh_addr_size = eh_addr_size; |
10835 | | |
10836 | 2.99k | introduce (section, false); |
10837 | | |
10838 | 8.33k | while (start < end) |
10839 | 5.42k | { |
10840 | 5.42k | unsigned char *saved_start; |
10841 | 5.42k | unsigned char *block_end; |
10842 | 5.42k | uint64_t length; |
10843 | 5.42k | uint64_t cie_id; |
10844 | 5.42k | Frame_Chunk *fc; |
10845 | 5.42k | Frame_Chunk *cie; |
10846 | 5.42k | int need_col_headers = 1; |
10847 | 5.42k | unsigned char *augmentation_data = NULL; |
10848 | 5.42k | uint64_t augmentation_data_len = 0; |
10849 | 5.42k | unsigned int encoded_ptr_size = saved_eh_addr_size; |
10850 | 5.42k | unsigned int offset_size; |
10851 | 5.42k | bool all_nops; |
10852 | 5.42k | static Frame_Chunk fde_fc; |
10853 | | |
10854 | 5.42k | saved_start = start; |
10855 | | |
10856 | 5.42k | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
10857 | | |
10858 | 5.42k | if (length == 0) |
10859 | 768 | { |
10860 | 768 | printf ("\n%08tx ZERO terminator\n\n", |
10861 | 768 | saved_start - section_start); |
10862 | | /* Skip any zero terminators that directly follow. |
10863 | | A corrupt section size could have loaded a whole |
10864 | | slew of zero filled memory bytes. eg |
10865 | | PR 17512: file: 070-19381-0.004. */ |
10866 | 15.2k | while (start < end && * start == 0) |
10867 | 14.4k | ++ start; |
10868 | 768 | continue; |
10869 | 768 | } |
10870 | | |
10871 | 4.66k | if (length == 0xffffffff) |
10872 | 186 | { |
10873 | 186 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
10874 | 186 | offset_size = 8; |
10875 | 186 | } |
10876 | 4.47k | else |
10877 | 4.47k | offset_size = 4; |
10878 | | |
10879 | 4.66k | if (length > (size_t) (end - start)) |
10880 | 2.66k | { |
10881 | 2.66k | warn ("Invalid length %#" PRIx64 " in FDE at %#tx\n", |
10882 | 2.66k | length, saved_start - section_start); |
10883 | 2.66k | block_end = end; |
10884 | 2.66k | } |
10885 | 1.99k | else |
10886 | 1.99k | block_end = start + length; |
10887 | | |
10888 | 4.66k | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, block_end); |
10889 | | |
10890 | 4.66k | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
10891 | 2.88k | || (offset_size == 8 && cie_id == DW64_CIE_ID))) |
10892 | 543 | { |
10893 | 543 | int version; |
10894 | 543 | unsigned int mreg; |
10895 | | |
10896 | 543 | start = read_cie (start, block_end, &cie, &version, |
10897 | 543 | &augmentation_data_len, &augmentation_data); |
10898 | | /* PR 17512: file: 027-135133-0.005. */ |
10899 | 543 | if (cie == NULL) |
10900 | 86 | break; |
10901 | | |
10902 | 457 | fc = cie; |
10903 | 457 | fc->next = chunks; |
10904 | 457 | chunks = fc; |
10905 | 457 | fc->chunk_start = saved_start; |
10906 | 457 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
10907 | 457 | if (mreg < fc->ra) |
10908 | 372 | mreg = fc->ra; |
10909 | 457 | if (frame_need_space (fc, mreg) < 0) |
10910 | 5 | break; |
10911 | 452 | if (fc->fde_encoding) |
10912 | 343 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); |
10913 | | |
10914 | 452 | printf ("\n%08tx ", saved_start - section_start); |
10915 | 452 | print_hex (length, fc->ptr_size); |
10916 | 452 | print_hex (cie_id, offset_size); |
10917 | | |
10918 | 452 | if (do_debug_frames_interp) |
10919 | 0 | { |
10920 | 0 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, |
10921 | 0 | fc->code_factor, fc->data_factor, fc->ra); |
10922 | 0 | } |
10923 | 452 | else |
10924 | 452 | { |
10925 | 452 | printf ("CIE\n"); |
10926 | 452 | printf (" Version: %d\n", version); |
10927 | 452 | printf (" Augmentation: \"%s\"\n", fc->augmentation); |
10928 | 452 | if (version >= 4) |
10929 | 31 | { |
10930 | 31 | printf (" Pointer Size: %u\n", fc->ptr_size); |
10931 | 31 | printf (" Segment Size: %u\n", fc->segment_size); |
10932 | 31 | } |
10933 | 452 | printf (" Code alignment factor: %u\n", fc->code_factor); |
10934 | 452 | printf (" Data alignment factor: %d\n", fc->data_factor); |
10935 | 452 | printf (" Return address column: %d\n", fc->ra); |
10936 | | |
10937 | 452 | if (augmentation_data_len) |
10938 | 344 | display_augmentation_data (augmentation_data, augmentation_data_len); |
10939 | | |
10940 | 452 | putchar ('\n'); |
10941 | 452 | } |
10942 | 452 | } |
10943 | 4.11k | else |
10944 | 4.11k | { |
10945 | 4.11k | unsigned long segment_selector; |
10946 | 4.11k | uint64_t cie_off; |
10947 | | |
10948 | 4.11k | cie_off = cie_id; |
10949 | 4.11k | if (is_eh) |
10950 | 1.28k | { |
10951 | 1.28k | uint64_t sign = (uint64_t) 1 << (offset_size * 8 - 1); |
10952 | 1.28k | cie_off = (cie_off ^ sign) - sign; |
10953 | 1.28k | cie_off = start - 4 - section_start - cie_off; |
10954 | 1.28k | } |
10955 | | |
10956 | 4.11k | if (cie_off >= section->size) |
10957 | 2.45k | cie = NULL; |
10958 | 1.66k | else |
10959 | 1.66k | { |
10960 | 1.66k | unsigned char *look_for = section_start + cie_off; |
10961 | 1.66k | if (cie_off <= (size_t) (saved_start - section_start)) |
10962 | 1.54k | { |
10963 | 1.58k | for (cie = chunks; cie ; cie = cie->next) |
10964 | 1.10k | if (cie->chunk_start == look_for) |
10965 | 1.06k | break; |
10966 | 1.54k | } |
10967 | 118 | else |
10968 | 118 | { |
10969 | 118 | for (cie = forward_refs; cie ; cie = cie->next) |
10970 | 0 | if (cie->chunk_start == look_for) |
10971 | 0 | break; |
10972 | 118 | if (!cie) |
10973 | 118 | { |
10974 | 118 | unsigned int off_size; |
10975 | 118 | unsigned char *cie_scan; |
10976 | | |
10977 | 118 | cie_scan = look_for; |
10978 | 118 | off_size = 4; |
10979 | 118 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); |
10980 | 118 | if (length == 0xffffffff) |
10981 | 14 | { |
10982 | 14 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); |
10983 | 14 | off_size = 8; |
10984 | 14 | } |
10985 | 118 | if (length != 0 && length <= (size_t) (end - cie_scan)) |
10986 | 16 | { |
10987 | 16 | uint64_t c_id; |
10988 | 16 | unsigned char *cie_end = cie_scan + length; |
10989 | | |
10990 | 16 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, |
10991 | 16 | cie_end); |
10992 | 16 | if (is_eh |
10993 | 16 | ? c_id == 0 |
10994 | 16 | : ((off_size == 4 && c_id == DW_CIE_ID) |
10995 | 5 | || (off_size == 8 && c_id == DW64_CIE_ID))) |
10996 | 11 | { |
10997 | 11 | int version; |
10998 | 11 | unsigned int mreg; |
10999 | | |
11000 | 11 | read_cie (cie_scan, cie_end, &cie, &version, |
11001 | 11 | &augmentation_data_len, |
11002 | 11 | &augmentation_data); |
11003 | | /* PR 17512: file: 3450-2098-0.004. */ |
11004 | 11 | if (cie == NULL) |
11005 | 2 | { |
11006 | 2 | warn (_("Failed to read CIE information\n")); |
11007 | 2 | break; |
11008 | 2 | } |
11009 | 9 | cie->next = forward_refs; |
11010 | 9 | forward_refs = cie; |
11011 | 9 | cie->chunk_start = look_for; |
11012 | 9 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
11013 | 9 | if (mreg < cie->ra) |
11014 | 3 | mreg = cie->ra; |
11015 | 9 | if (frame_need_space (cie, mreg) < 0) |
11016 | 0 | { |
11017 | 0 | warn (_("Invalid max register\n")); |
11018 | 0 | break; |
11019 | 0 | } |
11020 | 9 | if (cie->fde_encoding) |
11021 | 0 | encoded_ptr_size |
11022 | 0 | = size_of_encoded_value (cie->fde_encoding); |
11023 | 9 | } |
11024 | 16 | } |
11025 | 118 | } |
11026 | 118 | } |
11027 | 1.66k | } |
11028 | | |
11029 | 4.11k | fc = &fde_fc; |
11030 | 4.11k | memset (fc, 0, sizeof (Frame_Chunk)); |
11031 | | |
11032 | 4.11k | if (!cie) |
11033 | 3.04k | { |
11034 | 3.04k | fc->ncols = 0; |
11035 | 3.04k | fc->col_type = xmalloc (sizeof (*fc->col_type)); |
11036 | 3.04k | fc->col_offset = xmalloc (sizeof (*fc->col_offset)); |
11037 | 3.04k | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
11038 | 0 | { |
11039 | 0 | warn (_("Invalid max register\n")); |
11040 | 0 | break; |
11041 | 0 | } |
11042 | 3.04k | cie = fc; |
11043 | 3.04k | fc->augmentation = ""; |
11044 | 3.04k | fc->fde_encoding = 0; |
11045 | 3.04k | fc->ptr_size = eh_addr_size; |
11046 | 3.04k | fc->segment_size = 0; |
11047 | 3.04k | } |
11048 | 1.07k | else |
11049 | 1.07k | { |
11050 | 1.07k | fc->ncols = cie->ncols; |
11051 | 1.07k | fc->col_type = xcmalloc (fc->ncols, sizeof (*fc->col_type)); |
11052 | 1.07k | fc->col_offset = xcmalloc (fc->ncols, sizeof (*fc->col_offset)); |
11053 | 1.07k | memcpy (fc->col_type, cie->col_type, |
11054 | 1.07k | fc->ncols * sizeof (*fc->col_type)); |
11055 | 1.07k | memcpy (fc->col_offset, cie->col_offset, |
11056 | 1.07k | fc->ncols * sizeof (*fc->col_offset)); |
11057 | 1.07k | fc->augmentation = cie->augmentation; |
11058 | 1.07k | fc->ptr_size = cie->ptr_size; |
11059 | 1.07k | eh_addr_size = cie->ptr_size; |
11060 | 1.07k | fc->segment_size = cie->segment_size; |
11061 | 1.07k | fc->code_factor = cie->code_factor; |
11062 | 1.07k | fc->data_factor = cie->data_factor; |
11063 | 1.07k | fc->cfa_reg = cie->cfa_reg; |
11064 | 1.07k | fc->cfa_offset = cie->cfa_offset; |
11065 | 1.07k | fc->cfa_ofs_signed_p = cie->cfa_ofs_signed_p; |
11066 | 1.07k | fc->ra = cie->ra; |
11067 | 1.07k | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
11068 | 0 | { |
11069 | 0 | warn (_("Invalid max register\n")); |
11070 | 0 | break; |
11071 | 0 | } |
11072 | 1.07k | fc->fde_encoding = cie->fde_encoding; |
11073 | 1.07k | } |
11074 | | |
11075 | 4.11k | if (fc->fde_encoding) |
11076 | 1.01k | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); |
11077 | | |
11078 | 4.11k | segment_selector = 0; |
11079 | 4.11k | if (fc->segment_size) |
11080 | 0 | { |
11081 | 0 | if (fc->segment_size > sizeof (segment_selector)) |
11082 | 0 | { |
11083 | | /* PR 17512: file: 9e196b3e. */ |
11084 | 0 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); |
11085 | 0 | fc->segment_size = 4; |
11086 | 0 | } |
11087 | 0 | SAFE_BYTE_GET_AND_INC (segment_selector, start, |
11088 | 0 | fc->segment_size, block_end); |
11089 | 0 | } |
11090 | | |
11091 | 4.11k | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, |
11092 | 4.11k | block_end); |
11093 | | |
11094 | | /* FIXME: It appears that sometimes the final pc_range value is |
11095 | | encoded in less than encoded_ptr_size bytes. See the x86_64 |
11096 | | run of the "objcopy on compressed debug sections" test for an |
11097 | | example of this. */ |
11098 | 4.11k | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, |
11099 | 4.11k | block_end); |
11100 | | |
11101 | 4.11k | if (cie->augmentation[0] == 'z') |
11102 | 1.03k | { |
11103 | 1.03k | READ_ULEB (augmentation_data_len, start, block_end); |
11104 | 1.03k | augmentation_data = start; |
11105 | | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
11106 | 1.03k | if (augmentation_data_len > (size_t) (block_end - start)) |
11107 | 46 | { |
11108 | 46 | warn (_("Augmentation data too long: %#" PRIx64 ", " |
11109 | 46 | "expected at most %#tx\n"), |
11110 | 46 | augmentation_data_len, block_end - start); |
11111 | 46 | start = block_end; |
11112 | 46 | augmentation_data = NULL; |
11113 | 46 | augmentation_data_len = 0; |
11114 | 46 | } |
11115 | 1.03k | start += augmentation_data_len; |
11116 | 1.03k | } |
11117 | | |
11118 | 4.11k | printf ("\n%08tx ", saved_start - section_start); |
11119 | 4.11k | print_hex (length, fc->ptr_size); |
11120 | 4.11k | print_hex (cie_id, offset_size); |
11121 | 4.11k | printf ("FDE "); |
11122 | | |
11123 | 4.11k | if (cie->chunk_start) |
11124 | 1.07k | printf ("cie=%08tx", cie->chunk_start - section_start); |
11125 | 3.04k | else |
11126 | | /* Ideally translate "invalid " to 8 chars, trailing space |
11127 | | is optional. */ |
11128 | 3.04k | printf (_("cie=invalid ")); |
11129 | | |
11130 | 4.11k | printf (" pc="); |
11131 | 4.11k | if (fc->segment_size) |
11132 | 0 | printf ("%04lx:", segment_selector); |
11133 | | |
11134 | 4.11k | print_hex_ns (fc->pc_begin, fc->ptr_size); |
11135 | 4.11k | printf (".."); |
11136 | 4.11k | print_hex_ns (fc->pc_begin + fc->pc_range, fc->ptr_size); |
11137 | 4.11k | printf ("\n"); |
11138 | | |
11139 | 4.11k | if (! do_debug_frames_interp && augmentation_data_len) |
11140 | 27 | { |
11141 | 27 | display_augmentation_data (augmentation_data, augmentation_data_len); |
11142 | 27 | putchar ('\n'); |
11143 | 27 | } |
11144 | 4.11k | } |
11145 | | |
11146 | | /* At this point, fc is the current chunk, cie (if any) is set, and |
11147 | | we're about to interpret instructions for the chunk. */ |
11148 | | /* ??? At present we need to do this always, since this sizes the |
11149 | | fc->col_type and fc->col_offset arrays, which we write into always. |
11150 | | We should probably split the interpreted and non-interpreted bits |
11151 | | into two different routines, since there's so much that doesn't |
11152 | | really overlap between them. */ |
11153 | 4.56k | if (1 || do_debug_frames_interp) |
11154 | 4.56k | { |
11155 | | /* Start by making a pass over the chunk, allocating storage |
11156 | | and taking note of what registers are used. */ |
11157 | 4.56k | unsigned char *tmp = start; |
11158 | | |
11159 | 974k | while (start < block_end) |
11160 | 969k | { |
11161 | 969k | unsigned int reg, op, opa; |
11162 | 969k | unsigned long temp; |
11163 | | |
11164 | 969k | op = *start++; |
11165 | 969k | opa = op & 0x3f; |
11166 | 969k | if (op & 0xc0) |
11167 | 448k | op &= 0xc0; |
11168 | | |
11169 | | /* Warning: if you add any more cases to this switch, be |
11170 | | sure to add them to the corresponding switch below. */ |
11171 | 969k | reg = -1u; |
11172 | 969k | switch (op) |
11173 | 969k | { |
11174 | 199k | case DW_CFA_advance_loc: |
11175 | 199k | break; |
11176 | 60.1k | case DW_CFA_offset: |
11177 | 60.1k | SKIP_ULEB (start, block_end); |
11178 | 60.1k | reg = opa; |
11179 | 60.1k | break; |
11180 | 188k | case DW_CFA_restore: |
11181 | 188k | reg = opa; |
11182 | 188k | break; |
11183 | 11.6k | case DW_CFA_set_loc: |
11184 | 11.6k | if ((size_t) (block_end - start) < encoded_ptr_size) |
11185 | 114 | start = block_end; |
11186 | 11.5k | else |
11187 | 11.5k | start += encoded_ptr_size; |
11188 | 11.6k | break; |
11189 | 7.51k | case DW_CFA_advance_loc1: |
11190 | 7.51k | if ((size_t) (block_end - start) < 1) |
11191 | 8 | start = block_end; |
11192 | 7.50k | else |
11193 | 7.50k | start += 1; |
11194 | 7.51k | break; |
11195 | 5.13k | case DW_CFA_advance_loc2: |
11196 | 5.13k | if ((size_t) (block_end - start) < 2) |
11197 | 8 | start = block_end; |
11198 | 5.12k | else |
11199 | 5.12k | start += 2; |
11200 | 5.13k | break; |
11201 | 6.22k | case DW_CFA_advance_loc4: |
11202 | 6.22k | if ((size_t) (block_end - start) < 4) |
11203 | 35 | start = block_end; |
11204 | 6.18k | else |
11205 | 6.18k | start += 4; |
11206 | 6.22k | break; |
11207 | 5.51k | case DW_CFA_offset_extended: |
11208 | 7.44k | case DW_CFA_val_offset: |
11209 | 7.44k | READ_ULEB (reg, start, block_end); |
11210 | 7.44k | SKIP_ULEB (start, block_end); |
11211 | 7.44k | break; |
11212 | 6.55k | case DW_CFA_restore_extended: |
11213 | 6.55k | READ_ULEB (reg, start, block_end); |
11214 | 6.55k | break; |
11215 | 3.09k | case DW_CFA_undefined: |
11216 | 3.09k | READ_ULEB (reg, start, block_end); |
11217 | 3.09k | break; |
11218 | 5.70k | case DW_CFA_same_value: |
11219 | 5.70k | READ_ULEB (reg, start, block_end); |
11220 | 5.70k | break; |
11221 | 4.25k | case DW_CFA_register: |
11222 | 4.25k | READ_ULEB (reg, start, block_end); |
11223 | 4.25k | SKIP_ULEB (start, block_end); |
11224 | 4.25k | break; |
11225 | 5.51k | case DW_CFA_def_cfa: |
11226 | 5.51k | SKIP_ULEB (start, block_end); |
11227 | 5.51k | SKIP_ULEB (start, block_end); |
11228 | 5.51k | break; |
11229 | 3.54k | case DW_CFA_def_cfa_register: |
11230 | 3.54k | SKIP_ULEB (start, block_end); |
11231 | 3.54k | break; |
11232 | 4.27k | case DW_CFA_def_cfa_offset: |
11233 | 4.27k | SKIP_ULEB (start, block_end); |
11234 | 4.27k | break; |
11235 | 2.08k | case DW_CFA_def_cfa_expression: |
11236 | 2.08k | READ_ULEB (temp, start, block_end); |
11237 | 2.08k | if ((size_t) (block_end - start) < temp) |
11238 | 462 | start = block_end; |
11239 | 1.62k | else |
11240 | 1.62k | start += temp; |
11241 | 2.08k | break; |
11242 | 6.33k | case DW_CFA_expression: |
11243 | 11.5k | case DW_CFA_val_expression: |
11244 | 11.5k | READ_ULEB (reg, start, block_end); |
11245 | 11.5k | READ_ULEB (temp, start, block_end); |
11246 | 11.5k | if ((size_t) (block_end - start) < temp) |
11247 | 930 | start = block_end; |
11248 | 10.6k | else |
11249 | 10.6k | start += temp; |
11250 | 11.5k | break; |
11251 | 4.83k | case DW_CFA_offset_extended_sf: |
11252 | 6.40k | case DW_CFA_val_offset_sf: |
11253 | 6.40k | READ_ULEB (reg, start, block_end); |
11254 | 6.40k | SKIP_SLEB (start, block_end); |
11255 | 6.40k | break; |
11256 | 1.88k | case DW_CFA_def_cfa_sf: |
11257 | 1.88k | SKIP_ULEB (start, block_end); |
11258 | 1.88k | SKIP_SLEB (start, block_end); |
11259 | 1.88k | break; |
11260 | 3.13k | case DW_CFA_def_cfa_offset_sf: |
11261 | 3.13k | SKIP_SLEB (start, block_end); |
11262 | 3.13k | break; |
11263 | 1.01k | case DW_CFA_MIPS_advance_loc8: |
11264 | 1.01k | if ((size_t) (block_end - start) < 8) |
11265 | 15 | start = block_end; |
11266 | 1.00k | else |
11267 | 1.00k | start += 8; |
11268 | 1.01k | break; |
11269 | 9.99k | case DW_CFA_GNU_args_size: |
11270 | 9.99k | SKIP_ULEB (start, block_end); |
11271 | 9.99k | break; |
11272 | 3.50k | case DW_CFA_GNU_negative_offset_extended: |
11273 | 3.50k | READ_ULEB (reg, start, block_end); |
11274 | 3.50k | SKIP_ULEB (start, block_end); |
11275 | 3.50k | break; |
11276 | 410k | default: |
11277 | 410k | break; |
11278 | 969k | } |
11279 | 969k | if (reg != -1u && frame_need_space (fc, reg) >= 0) |
11280 | 291k | { |
11281 | | /* Don't leave any reg as DW_CFA_unreferenced so |
11282 | | that frame_display_row prints name of regs in |
11283 | | header, and all referenced regs in each line. */ |
11284 | 291k | if (reg >= cie->ncols |
11285 | 289k | || cie->col_type[reg] == DW_CFA_unreferenced) |
11286 | 60.2k | fc->col_type[reg] = DW_CFA_undefined; |
11287 | 230k | else |
11288 | 230k | fc->col_type[reg] = cie->col_type[reg]; |
11289 | 291k | } |
11290 | 969k | } |
11291 | 4.56k | start = tmp; |
11292 | 4.56k | } |
11293 | | |
11294 | 4.56k | all_nops = true; |
11295 | | |
11296 | | /* Now we know what registers are used, make a second pass over |
11297 | | the chunk, this time actually printing out the info. */ |
11298 | | |
11299 | 240k | while (start < block_end) |
11300 | 236k | { |
11301 | 236k | unsigned op, opa; |
11302 | | /* Note: It is tempting to use an unsigned long for 'reg' but there |
11303 | | are various functions, notably frame_space_needed() that assume that |
11304 | | reg is an unsigned int. */ |
11305 | 236k | unsigned int reg; |
11306 | 236k | int64_t sofs; |
11307 | 236k | uint64_t ofs; |
11308 | 236k | const char *reg_prefix = ""; |
11309 | | |
11310 | 236k | op = *start++; |
11311 | 236k | opa = op & 0x3f; |
11312 | 236k | if (op & 0xc0) |
11313 | 120k | op &= 0xc0; |
11314 | | |
11315 | | /* Make a note if something other than DW_CFA_nop happens. */ |
11316 | 236k | if (op != DW_CFA_nop) |
11317 | 167k | all_nops = false; |
11318 | | |
11319 | | /* Warning: if you add any more cases to this switch, be |
11320 | | sure to add them to the corresponding switch above. */ |
11321 | 236k | switch (op) |
11322 | 236k | { |
11323 | 52.0k | case DW_CFA_advance_loc: |
11324 | 52.0k | opa *= fc->code_factor; |
11325 | 52.0k | if (do_debug_frames_interp) |
11326 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
11327 | 52.0k | else |
11328 | 52.0k | { |
11329 | 52.0k | printf (" DW_CFA_advance_loc: %d to ", opa); |
11330 | 52.0k | print_hex_ns (fc->pc_begin + opa, fc->ptr_size); |
11331 | 52.0k | printf ("\n"); |
11332 | 52.0k | } |
11333 | 52.0k | fc->pc_begin += opa; |
11334 | 52.0k | break; |
11335 | | |
11336 | 11.6k | case DW_CFA_offset: |
11337 | 11.6k | READ_ULEB (ofs, start, block_end); |
11338 | 11.6k | ofs *= fc->data_factor; |
11339 | 11.6k | if (opa >= fc->ncols) |
11340 | 147 | reg_prefix = bad_reg; |
11341 | 11.6k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11342 | 11.6k | printf (" DW_CFA_offset: %s%s at cfa%+" PRId64 "\n", |
11343 | 11.6k | reg_prefix, regname (opa, 0), ofs); |
11344 | 11.6k | if (*reg_prefix == '\0') |
11345 | 11.5k | { |
11346 | 11.5k | fc->col_type[opa] = DW_CFA_offset; |
11347 | 11.5k | fc->col_offset[opa] = ofs; |
11348 | 11.5k | } |
11349 | 11.6k | break; |
11350 | | |
11351 | 56.6k | case DW_CFA_restore: |
11352 | 56.6k | if (opa >= fc->ncols) |
11353 | 2.58k | reg_prefix = bad_reg; |
11354 | 56.6k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11355 | 56.6k | printf (" DW_CFA_restore: %s%s\n", |
11356 | 56.6k | reg_prefix, regname (opa, 0)); |
11357 | 56.6k | if (*reg_prefix != '\0') |
11358 | 2.58k | break; |
11359 | | |
11360 | 54.0k | if (opa >= cie->ncols |
11361 | 53.8k | || cie->col_type[opa] == DW_CFA_unreferenced) |
11362 | 565 | { |
11363 | 565 | fc->col_type[opa] = DW_CFA_undefined; |
11364 | 565 | fc->col_offset[opa] = 0; |
11365 | 565 | } |
11366 | 53.4k | else |
11367 | 53.4k | { |
11368 | 53.4k | fc->col_type[opa] = cie->col_type[opa]; |
11369 | 53.4k | fc->col_offset[opa] = cie->col_offset[opa]; |
11370 | 53.4k | } |
11371 | 54.0k | break; |
11372 | | |
11373 | 1.83k | case DW_CFA_set_loc: |
11374 | 1.83k | ofs = get_encoded_value (&start, fc->fde_encoding, section, |
11375 | 1.83k | block_end); |
11376 | 1.83k | if (do_debug_frames_interp) |
11377 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
11378 | 1.83k | else |
11379 | 1.83k | { |
11380 | 1.83k | printf (" DW_CFA_set_loc: "); |
11381 | 1.83k | print_hex_ns (ofs, fc->ptr_size); |
11382 | 1.83k | printf ("\n"); |
11383 | 1.83k | } |
11384 | 1.83k | fc->pc_begin = ofs; |
11385 | 1.83k | break; |
11386 | | |
11387 | 1.13k | case DW_CFA_advance_loc1: |
11388 | 1.13k | SAFE_BYTE_GET_AND_INC (ofs, start, 1, block_end); |
11389 | 1.13k | ofs *= fc->code_factor; |
11390 | 1.13k | if (do_debug_frames_interp) |
11391 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
11392 | 1.13k | else |
11393 | 1.13k | { |
11394 | 1.13k | printf (" DW_CFA_advance_loc1: %" PRId64 " to ", ofs); |
11395 | 1.13k | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); |
11396 | 1.13k | printf ("\n"); |
11397 | 1.13k | } |
11398 | 1.13k | fc->pc_begin += ofs; |
11399 | 1.13k | break; |
11400 | | |
11401 | 1.05k | case DW_CFA_advance_loc2: |
11402 | 1.05k | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
11403 | 1.05k | ofs *= fc->code_factor; |
11404 | 1.05k | if (do_debug_frames_interp) |
11405 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
11406 | 1.05k | else |
11407 | 1.05k | { |
11408 | 1.05k | printf (" DW_CFA_advance_loc2: %" PRId64 " to ", ofs); |
11409 | 1.05k | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); |
11410 | 1.05k | printf ("\n"); |
11411 | 1.05k | } |
11412 | 1.05k | fc->pc_begin += ofs; |
11413 | 1.05k | break; |
11414 | | |
11415 | 1.26k | case DW_CFA_advance_loc4: |
11416 | 1.26k | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
11417 | 1.26k | ofs *= fc->code_factor; |
11418 | 1.26k | if (do_debug_frames_interp) |
11419 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
11420 | 1.26k | else |
11421 | 1.26k | { |
11422 | 1.26k | printf (" DW_CFA_advance_loc4: %" PRId64 " to ", ofs); |
11423 | 1.26k | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); |
11424 | 1.26k | printf ("\n"); |
11425 | 1.26k | } |
11426 | 1.26k | fc->pc_begin += ofs; |
11427 | 1.26k | break; |
11428 | | |
11429 | 1.96k | case DW_CFA_offset_extended: |
11430 | 1.96k | READ_ULEB (reg, start, block_end); |
11431 | 1.96k | READ_ULEB (ofs, start, block_end); |
11432 | 1.96k | ofs *= fc->data_factor; |
11433 | 1.96k | if (reg >= fc->ncols) |
11434 | 115 | reg_prefix = bad_reg; |
11435 | 1.96k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11436 | 1.96k | printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64 "\n", |
11437 | 1.96k | reg_prefix, regname (reg, 0), ofs); |
11438 | 1.96k | if (*reg_prefix == '\0') |
11439 | 1.85k | { |
11440 | 1.85k | fc->col_type[reg] = DW_CFA_offset; |
11441 | 1.85k | fc->col_offset[reg] = ofs; |
11442 | 1.85k | } |
11443 | 1.96k | break; |
11444 | | |
11445 | 405 | case DW_CFA_val_offset: |
11446 | 405 | READ_ULEB (reg, start, block_end); |
11447 | 405 | READ_ULEB (ofs, start, block_end); |
11448 | 405 | ofs *= fc->data_factor; |
11449 | 405 | if (reg >= fc->ncols) |
11450 | 44 | reg_prefix = bad_reg; |
11451 | 405 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11452 | 405 | printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64 "\n", |
11453 | 405 | reg_prefix, regname (reg, 0), ofs); |
11454 | 405 | if (*reg_prefix == '\0') |
11455 | 361 | { |
11456 | 361 | fc->col_type[reg] = DW_CFA_val_offset; |
11457 | 361 | fc->col_offset[reg] = ofs; |
11458 | 361 | } |
11459 | 405 | break; |
11460 | | |
11461 | 1.76k | case DW_CFA_restore_extended: |
11462 | 1.76k | READ_ULEB (reg, start, block_end); |
11463 | 1.76k | if (reg >= fc->ncols) |
11464 | 159 | reg_prefix = bad_reg; |
11465 | 1.76k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11466 | 1.76k | printf (" DW_CFA_restore_extended: %s%s\n", |
11467 | 1.76k | reg_prefix, regname (reg, 0)); |
11468 | 1.76k | if (*reg_prefix != '\0') |
11469 | 159 | break; |
11470 | | |
11471 | 1.60k | if (reg >= cie->ncols |
11472 | 1.60k | || cie->col_type[reg] == DW_CFA_unreferenced) |
11473 | 11 | { |
11474 | 11 | fc->col_type[reg] = DW_CFA_undefined; |
11475 | 11 | fc->col_offset[reg] = 0; |
11476 | 11 | } |
11477 | 1.59k | else |
11478 | 1.59k | { |
11479 | 1.59k | fc->col_type[reg] = cie->col_type[reg]; |
11480 | 1.59k | fc->col_offset[reg] = cie->col_offset[reg]; |
11481 | 1.59k | } |
11482 | 1.60k | break; |
11483 | | |
11484 | 1.48k | case DW_CFA_undefined: |
11485 | 1.48k | READ_ULEB (reg, start, block_end); |
11486 | 1.48k | if (reg >= fc->ncols) |
11487 | 105 | reg_prefix = bad_reg; |
11488 | 1.48k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11489 | 1.48k | printf (" DW_CFA_undefined: %s%s\n", |
11490 | 1.48k | reg_prefix, regname (reg, 0)); |
11491 | 1.48k | if (*reg_prefix == '\0') |
11492 | 1.37k | { |
11493 | 1.37k | fc->col_type[reg] = DW_CFA_undefined; |
11494 | 1.37k | fc->col_offset[reg] = 0; |
11495 | 1.37k | } |
11496 | 1.48k | break; |
11497 | | |
11498 | 1.49k | case DW_CFA_same_value: |
11499 | 1.49k | READ_ULEB (reg, start, block_end); |
11500 | 1.49k | if (reg >= fc->ncols) |
11501 | 121 | reg_prefix = bad_reg; |
11502 | 1.49k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11503 | 1.49k | printf (" DW_CFA_same_value: %s%s\n", |
11504 | 1.49k | reg_prefix, regname (reg, 0)); |
11505 | 1.49k | if (*reg_prefix == '\0') |
11506 | 1.36k | { |
11507 | 1.36k | fc->col_type[reg] = DW_CFA_same_value; |
11508 | 1.36k | fc->col_offset[reg] = 0; |
11509 | 1.36k | } |
11510 | 1.49k | break; |
11511 | | |
11512 | 1.94k | case DW_CFA_register: |
11513 | 1.94k | READ_ULEB (reg, start, block_end); |
11514 | 1.94k | READ_ULEB (ofs, start, block_end); |
11515 | 1.94k | if (reg >= fc->ncols) |
11516 | 210 | reg_prefix = bad_reg; |
11517 | 1.94k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11518 | 1.94k | { |
11519 | 1.94k | printf (" DW_CFA_register: %s%s in ", |
11520 | 1.94k | reg_prefix, regname (reg, 0)); |
11521 | 1.94k | puts (regname (ofs, 0)); |
11522 | 1.94k | } |
11523 | 1.94k | if (*reg_prefix == '\0') |
11524 | 1.73k | { |
11525 | 1.73k | fc->col_type[reg] = DW_CFA_register; |
11526 | 1.73k | fc->col_offset[reg] = ofs; |
11527 | 1.73k | } |
11528 | 1.94k | break; |
11529 | | |
11530 | 2.82k | case DW_CFA_remember_state: |
11531 | 2.82k | if (! do_debug_frames_interp) |
11532 | 2.82k | printf (" DW_CFA_remember_state\n"); |
11533 | 2.82k | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
11534 | 2.82k | rs->cfa_offset = fc->cfa_offset; |
11535 | 2.82k | rs->cfa_ofs_signed_p = fc->cfa_ofs_signed_p; |
11536 | 2.82k | rs->cfa_reg = fc->cfa_reg; |
11537 | 2.82k | rs->ra = fc->ra; |
11538 | 2.82k | rs->cfa_exp = fc->cfa_exp; |
11539 | 2.82k | rs->ncols = fc->ncols; |
11540 | 2.82k | rs->col_type = xcmalloc (rs->ncols, sizeof (*rs->col_type)); |
11541 | 2.82k | rs->col_offset = xcmalloc (rs->ncols, sizeof (*rs->col_offset)); |
11542 | 2.82k | memcpy (rs->col_type, fc->col_type, |
11543 | 2.82k | rs->ncols * sizeof (*fc->col_type)); |
11544 | 2.82k | memcpy (rs->col_offset, fc->col_offset, |
11545 | 2.82k | rs->ncols * sizeof (*fc->col_offset)); |
11546 | 2.82k | rs->next = remembered_state; |
11547 | 2.82k | remembered_state = rs; |
11548 | 2.82k | break; |
11549 | | |
11550 | 1.31k | case DW_CFA_restore_state: |
11551 | 1.31k | if (! do_debug_frames_interp) |
11552 | 1.31k | printf (" DW_CFA_restore_state\n"); |
11553 | 1.31k | rs = remembered_state; |
11554 | 1.31k | if (rs) |
11555 | 36 | { |
11556 | 36 | remembered_state = rs->next; |
11557 | 36 | fc->cfa_offset = rs->cfa_offset; |
11558 | 36 | fc->cfa_ofs_signed_p = rs->cfa_ofs_signed_p; |
11559 | 36 | fc->cfa_reg = rs->cfa_reg; |
11560 | 36 | fc->ra = rs->ra; |
11561 | 36 | fc->cfa_exp = rs->cfa_exp; |
11562 | 36 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
11563 | 0 | { |
11564 | 0 | warn (_("Invalid column number in saved frame state\n")); |
11565 | 0 | fc->ncols = 0; |
11566 | 0 | } |
11567 | 36 | else |
11568 | 36 | { |
11569 | 36 | memcpy (fc->col_type, rs->col_type, |
11570 | 36 | rs->ncols * sizeof (*rs->col_type)); |
11571 | 36 | memcpy (fc->col_offset, rs->col_offset, |
11572 | 36 | rs->ncols * sizeof (*rs->col_offset)); |
11573 | 36 | } |
11574 | 36 | free (rs->col_type); |
11575 | 36 | free (rs->col_offset); |
11576 | 36 | free (rs); |
11577 | 36 | } |
11578 | 1.27k | else if (do_debug_frames_interp) |
11579 | 0 | printf ("Mismatched DW_CFA_restore_state\n"); |
11580 | 1.31k | break; |
11581 | | |
11582 | 2.38k | case DW_CFA_def_cfa: |
11583 | 2.38k | READ_ULEB (fc->cfa_reg, start, block_end); |
11584 | 2.38k | READ_ULEB (fc->cfa_offset, start, block_end); |
11585 | 2.38k | fc->cfa_ofs_signed_p = false; |
11586 | 2.38k | fc->cfa_exp = 0; |
11587 | 2.38k | if (! do_debug_frames_interp) |
11588 | 2.38k | printf (" DW_CFA_def_cfa: %s ofs %" PRIu64 "\n", |
11589 | 2.38k | regname (fc->cfa_reg, 0), fc->cfa_offset); |
11590 | 2.38k | break; |
11591 | | |
11592 | 1.74k | case DW_CFA_def_cfa_register: |
11593 | 1.74k | READ_ULEB (fc->cfa_reg, start, block_end); |
11594 | 1.74k | fc->cfa_exp = 0; |
11595 | 1.74k | if (! do_debug_frames_interp) |
11596 | 1.74k | printf (" DW_CFA_def_cfa_register: %s\n", |
11597 | 1.74k | regname (fc->cfa_reg, 0)); |
11598 | 1.74k | break; |
11599 | | |
11600 | 2.22k | case DW_CFA_def_cfa_offset: |
11601 | 2.22k | READ_ULEB (fc->cfa_offset, start, block_end); |
11602 | 2.22k | fc->cfa_ofs_signed_p = false; |
11603 | 2.22k | if (! do_debug_frames_interp) |
11604 | 2.22k | printf (" DW_CFA_def_cfa_offset: %" PRIu64 "\n", fc->cfa_offset); |
11605 | 2.22k | break; |
11606 | | |
11607 | 68.7k | case DW_CFA_nop: |
11608 | 68.7k | if (! do_debug_frames_interp) |
11609 | 68.7k | printf (" DW_CFA_nop\n"); |
11610 | 68.7k | break; |
11611 | | |
11612 | 861 | case DW_CFA_def_cfa_expression: |
11613 | 861 | READ_ULEB (ofs, start, block_end); |
11614 | 861 | if (ofs > (size_t) (block_end - start)) |
11615 | 114 | { |
11616 | 114 | printf (_(" %s: <corrupt len %" PRIu64 ">\n"), |
11617 | 114 | "DW_CFA_def_cfa_expression", ofs); |
11618 | 114 | break; |
11619 | 114 | } |
11620 | 747 | if (! do_debug_frames_interp) |
11621 | 747 | { |
11622 | 747 | printf (" DW_CFA_def_cfa_expression ("); |
11623 | 747 | decode_location_expression (start, eh_addr_size, 0, -1, |
11624 | 747 | ofs, 0, section); |
11625 | 747 | printf (")\n"); |
11626 | 747 | } |
11627 | 747 | fc->cfa_exp = 1; |
11628 | 747 | start += ofs; |
11629 | 747 | break; |
11630 | | |
11631 | 4.08k | case DW_CFA_expression: |
11632 | 4.08k | READ_ULEB (reg, start, block_end); |
11633 | 4.08k | READ_ULEB (ofs, start, block_end); |
11634 | 4.08k | if (reg >= fc->ncols) |
11635 | 277 | reg_prefix = bad_reg; |
11636 | | /* PR 17512: file: 069-133014-0.006. */ |
11637 | | /* PR 17512: file: 98c02eb4. */ |
11638 | 4.08k | if (ofs > (size_t) (block_end - start)) |
11639 | 244 | { |
11640 | 244 | printf (_(" %s: <corrupt len %" PRIu64 ">\n"), |
11641 | 244 | "DW_CFA_expression", ofs); |
11642 | 244 | break; |
11643 | 244 | } |
11644 | 3.83k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11645 | 3.83k | { |
11646 | 3.83k | printf (" DW_CFA_expression: %s%s (", |
11647 | 3.83k | reg_prefix, regname (reg, 0)); |
11648 | 3.83k | decode_location_expression (start, eh_addr_size, 0, -1, |
11649 | 3.83k | ofs, 0, section); |
11650 | 3.83k | printf (")\n"); |
11651 | 3.83k | } |
11652 | 3.83k | if (*reg_prefix == '\0') |
11653 | 3.57k | fc->col_type[reg] = DW_CFA_expression; |
11654 | 3.83k | start += ofs; |
11655 | 3.83k | break; |
11656 | | |
11657 | 5.00k | case DW_CFA_val_expression: |
11658 | 5.00k | READ_ULEB (reg, start, block_end); |
11659 | 5.00k | READ_ULEB (ofs, start, block_end); |
11660 | 5.00k | if (reg >= fc->ncols) |
11661 | 537 | reg_prefix = bad_reg; |
11662 | 5.00k | if (ofs > (size_t) (block_end - start)) |
11663 | 542 | { |
11664 | 542 | printf (" %s: <corrupt len %" PRIu64 ">\n", |
11665 | 542 | "DW_CFA_val_expression", ofs); |
11666 | 542 | break; |
11667 | 542 | } |
11668 | 4.46k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11669 | 4.46k | { |
11670 | 4.46k | printf (" DW_CFA_val_expression: %s%s (", |
11671 | 4.46k | reg_prefix, regname (reg, 0)); |
11672 | 4.46k | decode_location_expression (start, eh_addr_size, 0, -1, |
11673 | 4.46k | ofs, 0, section); |
11674 | 4.46k | printf (")\n"); |
11675 | 4.46k | } |
11676 | 4.46k | if (*reg_prefix == '\0') |
11677 | 4.02k | fc->col_type[reg] = DW_CFA_val_expression; |
11678 | 4.46k | start += ofs; |
11679 | 4.46k | break; |
11680 | | |
11681 | 2.82k | case DW_CFA_offset_extended_sf: |
11682 | 2.82k | READ_ULEB (reg, start, block_end); |
11683 | 2.82k | READ_SLEB (sofs, start, block_end); |
11684 | | /* data_factor multiplicaton done here as unsigned to |
11685 | | avoid integer overflow warnings from asan on fuzzed |
11686 | | objects. */ |
11687 | 2.82k | ofs = sofs; |
11688 | 2.82k | ofs *= fc->data_factor; |
11689 | 2.82k | if (reg >= fc->ncols) |
11690 | 196 | reg_prefix = bad_reg; |
11691 | 2.82k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11692 | 2.82k | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64 "\n", |
11693 | 2.82k | reg_prefix, regname (reg, 0), ofs); |
11694 | 2.82k | if (*reg_prefix == '\0') |
11695 | 2.62k | { |
11696 | 2.62k | fc->col_type[reg] = DW_CFA_offset; |
11697 | 2.62k | fc->col_offset[reg] = ofs; |
11698 | 2.62k | } |
11699 | 2.82k | break; |
11700 | | |
11701 | 591 | case DW_CFA_val_offset_sf: |
11702 | 591 | READ_ULEB (reg, start, block_end); |
11703 | 591 | READ_SLEB (sofs, start, block_end); |
11704 | 591 | ofs = sofs; |
11705 | 591 | ofs *= fc->data_factor; |
11706 | 591 | if (reg >= fc->ncols) |
11707 | 230 | reg_prefix = bad_reg; |
11708 | 591 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11709 | 591 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64 "\n", |
11710 | 591 | reg_prefix, regname (reg, 0), ofs); |
11711 | 591 | if (*reg_prefix == '\0') |
11712 | 361 | { |
11713 | 361 | fc->col_type[reg] = DW_CFA_val_offset; |
11714 | 361 | fc->col_offset[reg] = ofs; |
11715 | 361 | } |
11716 | 591 | break; |
11717 | | |
11718 | 532 | case DW_CFA_def_cfa_sf: |
11719 | 532 | READ_ULEB (fc->cfa_reg, start, block_end); |
11720 | 532 | READ_SLEB (sofs, start, block_end); |
11721 | 532 | ofs = sofs; |
11722 | 532 | ofs *= fc->data_factor; |
11723 | 532 | fc->cfa_offset = ofs; |
11724 | 532 | fc->cfa_ofs_signed_p = true; |
11725 | 532 | fc->cfa_exp = 0; |
11726 | 532 | if (! do_debug_frames_interp) |
11727 | 532 | printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64 "\n", |
11728 | 532 | regname (fc->cfa_reg, 0), ofs); |
11729 | 532 | break; |
11730 | | |
11731 | 800 | case DW_CFA_def_cfa_offset_sf: |
11732 | 800 | READ_SLEB (sofs, start, block_end); |
11733 | 800 | ofs = sofs; |
11734 | 800 | ofs *= fc->data_factor; |
11735 | 800 | fc->cfa_offset = ofs; |
11736 | 800 | fc->cfa_ofs_signed_p = true; |
11737 | 800 | if (! do_debug_frames_interp) |
11738 | 800 | printf (" DW_CFA_def_cfa_offset_sf: %" PRId64 "\n", ofs); |
11739 | 800 | break; |
11740 | | |
11741 | 296 | case DW_CFA_MIPS_advance_loc8: |
11742 | 296 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
11743 | 296 | ofs *= fc->code_factor; |
11744 | 296 | if (do_debug_frames_interp) |
11745 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
11746 | 296 | else |
11747 | 296 | { |
11748 | 296 | printf (" DW_CFA_MIPS_advance_loc8: %" PRId64 " to ", ofs); |
11749 | 296 | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); |
11750 | 296 | printf ("\n"); |
11751 | 296 | } |
11752 | 296 | fc->pc_begin += ofs; |
11753 | 296 | break; |
11754 | | |
11755 | 637 | case DW_CFA_AARCH64_negate_ra_state_with_pc: |
11756 | 637 | if (! do_debug_frames_interp) |
11757 | 637 | printf (" DW_CFA_AARCH64_negate_ra_state_with_pc\n"); |
11758 | 637 | break; |
11759 | | |
11760 | 358 | case DW_CFA_GNU_window_save: |
11761 | 358 | if (! do_debug_frames_interp) |
11762 | 358 | printf (" %s\n", DW_CFA_GNU_window_save_name[is_aarch64]); |
11763 | 358 | break; |
11764 | | |
11765 | 2.17k | case DW_CFA_GNU_args_size: |
11766 | 2.17k | READ_ULEB (ofs, start, block_end); |
11767 | 2.17k | if (! do_debug_frames_interp) |
11768 | 2.17k | printf (" DW_CFA_GNU_args_size: %" PRIu64 "\n", ofs); |
11769 | 2.17k | break; |
11770 | | |
11771 | 1.67k | case DW_CFA_GNU_negative_offset_extended: |
11772 | 1.67k | READ_ULEB (reg, start, block_end); |
11773 | 1.67k | READ_SLEB (sofs, start, block_end); |
11774 | 1.67k | ofs = sofs; |
11775 | 1.67k | ofs = -ofs * fc->data_factor; |
11776 | 1.67k | if (reg >= fc->ncols) |
11777 | 216 | reg_prefix = bad_reg; |
11778 | 1.67k | if (! do_debug_frames_interp || *reg_prefix != '\0') |
11779 | 1.67k | printf (" DW_CFA_GNU_negative_offset_extended: %s%s " |
11780 | 1.67k | "at cfa%+" PRId64 "\n", |
11781 | 1.67k | reg_prefix, regname (reg, 0), ofs); |
11782 | 1.67k | if (*reg_prefix == '\0') |
11783 | 1.45k | { |
11784 | 1.45k | fc->col_type[reg] = DW_CFA_offset; |
11785 | 1.45k | fc->col_offset[reg] = ofs; |
11786 | 1.45k | } |
11787 | 1.67k | break; |
11788 | | |
11789 | 2.53k | default: |
11790 | 2.53k | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
11791 | 2.24k | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); |
11792 | 290 | else |
11793 | 290 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
11794 | 2.53k | start = block_end; |
11795 | 236k | } |
11796 | 236k | } |
11797 | | |
11798 | | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
11799 | 4.56k | if (do_debug_frames_interp && ! all_nops) |
11800 | 0 | frame_display_row (fc, &need_col_headers, &max_regs); |
11801 | | |
11802 | 4.56k | if (fde_fc.col_type != NULL) |
11803 | 4.11k | { |
11804 | 4.11k | free (fde_fc.col_type); |
11805 | 4.11k | fde_fc.col_type = NULL; |
11806 | 4.11k | } |
11807 | 4.56k | if (fde_fc.col_offset != NULL) |
11808 | 4.11k | { |
11809 | 4.11k | free (fde_fc.col_offset); |
11810 | 4.11k | fde_fc.col_offset = NULL; |
11811 | 4.11k | } |
11812 | | |
11813 | 4.56k | start = block_end; |
11814 | 4.56k | eh_addr_size = saved_eh_addr_size; |
11815 | 4.56k | } |
11816 | | |
11817 | 2.99k | printf ("\n"); |
11818 | | |
11819 | 5.78k | while (remembered_state != NULL) |
11820 | 2.79k | { |
11821 | 2.79k | rs = remembered_state; |
11822 | 2.79k | remembered_state = rs->next; |
11823 | 2.79k | free (rs->col_type); |
11824 | 2.79k | free (rs->col_offset); |
11825 | 2.79k | rs->next = NULL; /* Paranoia. */ |
11826 | 2.79k | free (rs); |
11827 | 2.79k | } |
11828 | | |
11829 | 3.45k | while (chunks != NULL) |
11830 | 457 | { |
11831 | 457 | rs = chunks; |
11832 | 457 | chunks = rs->next; |
11833 | 457 | free (rs->col_type); |
11834 | 457 | free (rs->col_offset); |
11835 | 457 | rs->next = NULL; /* Paranoia. */ |
11836 | 457 | free (rs); |
11837 | 457 | } |
11838 | | |
11839 | 3.00k | while (forward_refs != NULL) |
11840 | 9 | { |
11841 | 9 | rs = forward_refs; |
11842 | 9 | forward_refs = rs->next; |
11843 | 9 | free (rs->col_type); |
11844 | 9 | free (rs->col_offset); |
11845 | 9 | rs->next = NULL; /* Paranoia. */ |
11846 | 9 | free (rs); |
11847 | 9 | } |
11848 | | |
11849 | 2.99k | return 1; |
11850 | 2.99k | } |
11851 | | |
11852 | | #undef GET |
11853 | | |
11854 | | static int |
11855 | | display_debug_names (struct dwarf_section *section, void *file) |
11856 | 0 | { |
11857 | 0 | unsigned char *hdrptr = section->start; |
11858 | 0 | uint64_t unit_length; |
11859 | 0 | unsigned char *unit_start; |
11860 | 0 | const unsigned char *const section_end = section->start + section->size; |
11861 | 0 | unsigned char *unit_end; |
11862 | |
|
11863 | 0 | introduce (section, false); |
11864 | |
|
11865 | 0 | load_debug_section_with_follow (str, file); |
11866 | |
|
11867 | 0 | for (; hdrptr < section_end; hdrptr = unit_end) |
11868 | 0 | { |
11869 | 0 | unsigned int offset_size; |
11870 | 0 | uint16_t dwarf_version, padding; |
11871 | 0 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; |
11872 | 0 | uint64_t bucket_count, name_count, abbrev_table_size; |
11873 | 0 | uint32_t augmentation_string_size; |
11874 | 0 | unsigned int i; |
11875 | 0 | bool augmentation_printable; |
11876 | 0 | const char *augmentation_string; |
11877 | 0 | size_t total; |
11878 | |
|
11879 | 0 | unit_start = hdrptr; |
11880 | | |
11881 | | /* Get and check the length of the block. */ |
11882 | 0 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); |
11883 | |
|
11884 | 0 | if (unit_length == 0xffffffff) |
11885 | 0 | { |
11886 | | /* This section is 64-bit DWARF. */ |
11887 | 0 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); |
11888 | 0 | offset_size = 8; |
11889 | 0 | } |
11890 | 0 | else |
11891 | 0 | offset_size = 4; |
11892 | |
|
11893 | 0 | if (unit_length > (size_t) (section_end - hdrptr) |
11894 | 0 | || unit_length < 2 + 2 + 4 * 7) |
11895 | 0 | { |
11896 | 0 | too_short: |
11897 | 0 | warn (_("Debug info is corrupted, %s header at %#tx" |
11898 | 0 | " has length %#" PRIx64 "\n"), |
11899 | 0 | section->name, unit_start - section->start, unit_length); |
11900 | 0 | return 0; |
11901 | 0 | } |
11902 | 0 | unit_end = hdrptr + unit_length; |
11903 | | |
11904 | | /* Get and check the version number. */ |
11905 | 0 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); |
11906 | 0 | printf (_("Version %d\n"), (int) dwarf_version); |
11907 | | |
11908 | | /* Prior versions did not exist, and future versions may not be |
11909 | | backwards compatible. */ |
11910 | 0 | if (dwarf_version != 5) |
11911 | 0 | { |
11912 | 0 | warn (_("Only DWARF version 5 .debug_names " |
11913 | 0 | "is currently supported.\n")); |
11914 | 0 | return 0; |
11915 | 0 | } |
11916 | | |
11917 | 0 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); |
11918 | 0 | if (padding != 0) |
11919 | 0 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), |
11920 | 0 | padding); |
11921 | |
|
11922 | 0 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); |
11923 | 0 | if (comp_unit_count == 0) |
11924 | 0 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); |
11925 | |
|
11926 | 0 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); |
11927 | 0 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); |
11928 | 0 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); |
11929 | 0 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); |
11930 | 0 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); |
11931 | |
|
11932 | 0 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); |
11933 | 0 | if (augmentation_string_size % 4 != 0) |
11934 | 0 | { |
11935 | 0 | warn (_("Augmentation string length %u must be rounded up " |
11936 | 0 | "to a multiple of 4 in .debug_names.\n"), |
11937 | 0 | augmentation_string_size); |
11938 | 0 | augmentation_string_size += (-augmentation_string_size) & 3; |
11939 | 0 | } |
11940 | 0 | if (augmentation_string_size > (size_t) (unit_end - hdrptr)) |
11941 | 0 | goto too_short; |
11942 | | |
11943 | 0 | printf (_("Augmentation string:")); |
11944 | |
|
11945 | 0 | augmentation_printable = true; |
11946 | 0 | augmentation_string = (const char *) hdrptr; |
11947 | |
|
11948 | 0 | for (i = 0; i < augmentation_string_size; i++) |
11949 | 0 | { |
11950 | 0 | unsigned char uc; |
11951 | |
|
11952 | 0 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); |
11953 | 0 | printf (" %02x", uc); |
11954 | |
|
11955 | 0 | if (uc != 0 && !ISPRINT (uc)) |
11956 | 0 | augmentation_printable = false; |
11957 | 0 | } |
11958 | |
|
11959 | 0 | if (augmentation_printable) |
11960 | 0 | { |
11961 | 0 | printf (" (\""); |
11962 | 0 | for (i = 0; |
11963 | 0 | i < augmentation_string_size && augmentation_string[i]; |
11964 | 0 | ++i) |
11965 | 0 | putchar (augmentation_string[i]); |
11966 | 0 | printf ("\")"); |
11967 | 0 | } |
11968 | 0 | putchar ('\n'); |
11969 | |
|
11970 | 0 | printf (_("CU table:\n")); |
11971 | 0 | if (_mul_overflow (comp_unit_count, offset_size, &total) |
11972 | 0 | || total > (size_t) (unit_end - hdrptr)) |
11973 | 0 | goto too_short; |
11974 | 0 | for (i = 0; i < comp_unit_count; i++) |
11975 | 0 | { |
11976 | 0 | uint64_t cu_offset; |
11977 | |
|
11978 | 0 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); |
11979 | 0 | printf ("[%3u] %#" PRIx64 "\n", i, cu_offset); |
11980 | 0 | } |
11981 | 0 | putchar ('\n'); |
11982 | |
|
11983 | 0 | printf (_("TU table:\n")); |
11984 | 0 | if (_mul_overflow (local_type_unit_count, offset_size, &total) |
11985 | 0 | || total > (size_t) (unit_end - hdrptr)) |
11986 | 0 | goto too_short; |
11987 | 0 | for (i = 0; i < local_type_unit_count; i++) |
11988 | 0 | { |
11989 | 0 | uint64_t tu_offset; |
11990 | |
|
11991 | 0 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); |
11992 | 0 | printf ("[%3u] %#" PRIx64 "\n", i, tu_offset); |
11993 | 0 | } |
11994 | 0 | putchar ('\n'); |
11995 | |
|
11996 | 0 | printf (_("Foreign TU table:\n")); |
11997 | 0 | if (_mul_overflow (foreign_type_unit_count, 8, &total) |
11998 | 0 | || total > (size_t) (unit_end - hdrptr)) |
11999 | 0 | goto too_short; |
12000 | 0 | for (i = 0; i < foreign_type_unit_count; i++) |
12001 | 0 | { |
12002 | 0 | uint64_t signature; |
12003 | |
|
12004 | 0 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); |
12005 | 0 | printf (_("[%3u] "), i); |
12006 | 0 | print_hex_ns (signature, 8); |
12007 | 0 | putchar ('\n'); |
12008 | 0 | } |
12009 | 0 | putchar ('\n'); |
12010 | |
|
12011 | 0 | uint64_t xtra = (bucket_count * sizeof (uint32_t) |
12012 | 0 | + name_count * (sizeof (uint32_t) + 2 * offset_size) |
12013 | 0 | + abbrev_table_size); |
12014 | 0 | if (xtra > (size_t) (unit_end - hdrptr)) |
12015 | 0 | { |
12016 | 0 | warn (_("Entry pool offset (%#" PRIx64 ") exceeds unit size %#tx " |
12017 | 0 | "for unit %#tx in the debug_names\n"), |
12018 | 0 | xtra, unit_end - unit_start, unit_start - section->start); |
12019 | 0 | return 0; |
12020 | 0 | } |
12021 | 0 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; |
12022 | 0 | hdrptr += bucket_count * sizeof (uint32_t); |
12023 | 0 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; |
12024 | 0 | if (bucket_count != 0) |
12025 | 0 | hdrptr += name_count * sizeof (uint32_t); |
12026 | 0 | unsigned char *const name_table_string_offsets = hdrptr; |
12027 | 0 | hdrptr += name_count * offset_size; |
12028 | 0 | unsigned char *const name_table_entry_offsets = hdrptr; |
12029 | 0 | hdrptr += name_count * offset_size; |
12030 | 0 | unsigned char *const abbrev_table = hdrptr; |
12031 | 0 | hdrptr += abbrev_table_size; |
12032 | 0 | const unsigned char *const abbrev_table_end = hdrptr; |
12033 | 0 | unsigned char *const entry_pool = hdrptr; |
12034 | |
|
12035 | 0 | size_t buckets_filled = 0; |
12036 | 0 | size_t bucketi; |
12037 | 0 | for (bucketi = 0; bucketi < bucket_count; bucketi++) |
12038 | 0 | { |
12039 | 0 | const uint32_t bucket = hash_table_buckets[bucketi]; |
12040 | |
|
12041 | 0 | if (bucket != 0) |
12042 | 0 | ++buckets_filled; |
12043 | 0 | } |
12044 | 0 | printf (ngettext ("Used %zu of %lu bucket.\n", |
12045 | 0 | "Used %zu of %lu buckets.\n", |
12046 | 0 | (unsigned long) bucket_count), |
12047 | 0 | buckets_filled, (unsigned long) bucket_count); |
12048 | |
|
12049 | 0 | if (bucket_count != 0) |
12050 | 0 | { |
12051 | 0 | uint32_t hash_prev = 0; |
12052 | 0 | size_t hash_clash_count = 0; |
12053 | 0 | size_t longest_clash = 0; |
12054 | 0 | size_t this_length = 0; |
12055 | 0 | size_t hashi; |
12056 | 0 | for (hashi = 0; hashi < name_count; hashi++) |
12057 | 0 | { |
12058 | 0 | const uint32_t hash_this = hash_table_hashes[hashi]; |
12059 | |
|
12060 | 0 | if (hashi > 0) |
12061 | 0 | { |
12062 | 0 | if (hash_prev % bucket_count == hash_this % bucket_count) |
12063 | 0 | { |
12064 | 0 | ++hash_clash_count; |
12065 | 0 | ++this_length; |
12066 | 0 | longest_clash = MAX (longest_clash, this_length); |
12067 | 0 | } |
12068 | 0 | else |
12069 | 0 | this_length = 0; |
12070 | 0 | } |
12071 | 0 | hash_prev = hash_this; |
12072 | 0 | } |
12073 | 0 | printf (_("Out of %" PRIu64 " items there are %zu bucket clashes" |
12074 | 0 | " (longest of %zu entries).\n"), |
12075 | 0 | name_count, hash_clash_count, longest_clash); |
12076 | |
|
12077 | 0 | if (name_count != buckets_filled + hash_clash_count) |
12078 | 0 | warn (_("The name_count (%" PRIu64 ")" |
12079 | 0 | " is not the same as the used bucket_count" |
12080 | 0 | " (%zu) + the hash clash count (%zu)\n"), |
12081 | 0 | name_count, buckets_filled, hash_clash_count); |
12082 | 0 | } |
12083 | |
|
12084 | 0 | struct abbrev_lookup_entry |
12085 | 0 | { |
12086 | 0 | uint64_t abbrev_tag; |
12087 | 0 | unsigned char *abbrev_lookup_ptr; |
12088 | 0 | }; |
12089 | 0 | struct abbrev_lookup_entry *abbrev_lookup = NULL; |
12090 | 0 | size_t abbrev_lookup_used = 0; |
12091 | 0 | size_t abbrev_lookup_allocated = 0; |
12092 | |
|
12093 | 0 | unsigned char *abbrevptr = abbrev_table; |
12094 | 0 | for (;;) |
12095 | 0 | { |
12096 | 0 | uint64_t abbrev_tag; |
12097 | |
|
12098 | 0 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); |
12099 | 0 | if (abbrev_tag == 0) |
12100 | 0 | break; |
12101 | 0 | if (abbrev_lookup_used == abbrev_lookup_allocated) |
12102 | 0 | { |
12103 | 0 | abbrev_lookup_allocated = MAX (0x100, |
12104 | 0 | abbrev_lookup_allocated * 2); |
12105 | 0 | abbrev_lookup = xrealloc (abbrev_lookup, |
12106 | 0 | (abbrev_lookup_allocated |
12107 | 0 | * sizeof (*abbrev_lookup))); |
12108 | 0 | } |
12109 | 0 | assert (abbrev_lookup_used < abbrev_lookup_allocated); |
12110 | 0 | struct abbrev_lookup_entry *entry; |
12111 | 0 | for (entry = abbrev_lookup; |
12112 | 0 | entry < abbrev_lookup + abbrev_lookup_used; |
12113 | 0 | entry++) |
12114 | 0 | if (entry->abbrev_tag == abbrev_tag) |
12115 | 0 | { |
12116 | 0 | warn (_("Duplicate abbreviation tag %" PRIu64 |
12117 | 0 | " in unit %#tx in the debug_names section\n"), |
12118 | 0 | abbrev_tag, unit_start - section->start); |
12119 | 0 | break; |
12120 | 0 | } |
12121 | 0 | entry = &abbrev_lookup[abbrev_lookup_used++]; |
12122 | 0 | entry->abbrev_tag = abbrev_tag; |
12123 | 0 | entry->abbrev_lookup_ptr = abbrevptr; |
12124 | | |
12125 | | /* Skip DWARF tag. */ |
12126 | 0 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
12127 | 0 | for (;;) |
12128 | 0 | { |
12129 | 0 | uint64_t xindex, form; |
12130 | |
|
12131 | 0 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); |
12132 | 0 | READ_ULEB (form, abbrevptr, abbrev_table_end); |
12133 | 0 | if (xindex == 0 && form == 0) |
12134 | 0 | break; |
12135 | | |
12136 | 0 | if (form == DW_FORM_implicit_const) |
12137 | 0 | { |
12138 | 0 | int64_t implicit_const; |
12139 | 0 | READ_SLEB (implicit_const, abbrevptr, abbrev_table_end); |
12140 | 0 | } |
12141 | 0 | } |
12142 | 0 | } |
12143 | | |
12144 | 0 | printf (_("\nSymbol table:\n")); |
12145 | 0 | uint32_t namei; |
12146 | 0 | for (namei = 0; namei < name_count; ++namei) |
12147 | 0 | { |
12148 | 0 | uint64_t string_offset, entry_offset; |
12149 | 0 | unsigned char *p; |
12150 | | /* We need to scan first whether there is a single or multiple |
12151 | | entries. TAGNO is -2 for the first entry, it is -1 for the |
12152 | | initial tag read of the second entry, then it becomes 0 for the |
12153 | | first entry for real printing etc. */ |
12154 | 0 | int tagno = -2; |
12155 | | /* Initialize it due to a false compiler warning. */ |
12156 | 0 | uint64_t second_abbrev_tag = -1; |
12157 | 0 | unsigned char *entryptr; |
12158 | |
|
12159 | 0 | p = name_table_string_offsets + namei * offset_size; |
12160 | 0 | SAFE_BYTE_GET (string_offset, p, offset_size, unit_end); |
12161 | |
|
12162 | 0 | p = name_table_entry_offsets + namei * offset_size; |
12163 | 0 | SAFE_BYTE_GET (entry_offset, p, offset_size, unit_end); |
12164 | | |
12165 | | /* The name table is indexed starting at 1 according to |
12166 | | DWARF, so be sure to use the DWARF numbering here. */ |
12167 | 0 | printf ("[%3u] ", namei + 1); |
12168 | 0 | if (bucket_count != 0) |
12169 | 0 | printf ("#%08x ", hash_table_hashes[namei]); |
12170 | |
|
12171 | 0 | printf ("%s:", fetch_indirect_string (string_offset)); |
12172 | |
|
12173 | 0 | entryptr = entry_pool + entry_offset; |
12174 | | /* PR 31456: Check for invalid entry offset. */ |
12175 | 0 | if (entryptr < entry_pool || entryptr >= unit_end) |
12176 | 0 | { |
12177 | 0 | warn (_("Invalid entry offset value: %" PRIx64 "\n"), entry_offset); |
12178 | 0 | break; |
12179 | 0 | } |
12180 | | |
12181 | 0 | for (;;) |
12182 | 0 | { |
12183 | 0 | uint64_t abbrev_tag; |
12184 | 0 | uint64_t dwarf_tag; |
12185 | 0 | const struct abbrev_lookup_entry *entry; |
12186 | 0 | uint64_t this_entry = entryptr - entry_pool; |
12187 | |
|
12188 | 0 | READ_ULEB (abbrev_tag, entryptr, unit_end); |
12189 | 0 | if (tagno == -1) |
12190 | 0 | { |
12191 | 0 | second_abbrev_tag = abbrev_tag; |
12192 | 0 | tagno = 0; |
12193 | 0 | entryptr = entry_pool + entry_offset; |
12194 | 0 | continue; |
12195 | 0 | } |
12196 | 0 | if (abbrev_tag == 0) |
12197 | 0 | break; |
12198 | 0 | if (tagno >= 0) |
12199 | 0 | printf ("%s<%#" PRIx64 "><%" PRIu64 ">", |
12200 | 0 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), |
12201 | 0 | this_entry, abbrev_tag); |
12202 | |
|
12203 | 0 | for (entry = abbrev_lookup; |
12204 | 0 | entry < abbrev_lookup + abbrev_lookup_used; |
12205 | 0 | entry++) |
12206 | 0 | if (entry->abbrev_tag == abbrev_tag) |
12207 | 0 | break; |
12208 | 0 | if (entry >= abbrev_lookup + abbrev_lookup_used) |
12209 | 0 | { |
12210 | 0 | warn (_("Undefined abbreviation tag %" PRId64 |
12211 | 0 | " in unit %#tx in the debug_names section\n"), |
12212 | 0 | abbrev_tag, |
12213 | 0 | unit_start - section->start); |
12214 | 0 | break; |
12215 | 0 | } |
12216 | 0 | abbrevptr = entry->abbrev_lookup_ptr; |
12217 | 0 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
12218 | 0 | if (tagno >= 0) |
12219 | 0 | printf (" %s", get_TAG_name (dwarf_tag)); |
12220 | 0 | for (;;) |
12221 | 0 | { |
12222 | 0 | uint64_t xindex, form; |
12223 | |
|
12224 | 0 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); |
12225 | 0 | READ_ULEB (form, abbrevptr, abbrev_table_end); |
12226 | 0 | if (xindex == 0 && form == 0) |
12227 | 0 | break; |
12228 | | |
12229 | 0 | if (tagno >= 0) |
12230 | 0 | printf (" %s", get_IDX_name (xindex)); |
12231 | |
|
12232 | 0 | int64_t implicit_const = 0; |
12233 | 0 | if (form == DW_FORM_implicit_const) |
12234 | 0 | READ_SLEB (implicit_const, abbrevptr, abbrev_table_end); |
12235 | |
|
12236 | 0 | entryptr = read_and_display_attr_value (0, form, implicit_const, |
12237 | 0 | unit_start, entryptr, |
12238 | 0 | unit_end, 0, |
12239 | 0 | offset_size, |
12240 | 0 | offset_size, |
12241 | 0 | dwarf_version, NULL, |
12242 | 0 | (tagno < 0), section, |
12243 | 0 | NULL, '=', -1, |
12244 | 0 | false, 0, 0, false); |
12245 | 0 | } |
12246 | 0 | ++tagno; |
12247 | 0 | } |
12248 | 0 | if (tagno <= 0) |
12249 | 0 | printf (_(" <no entries>")); |
12250 | 0 | putchar ('\n'); |
12251 | 0 | } |
12252 | | |
12253 | 0 | free (abbrev_lookup); |
12254 | 0 | } |
12255 | | |
12256 | 0 | return 1; |
12257 | 0 | } |
12258 | | |
12259 | | static int |
12260 | | display_debug_links (struct dwarf_section * section, |
12261 | | void * file ATTRIBUTE_UNUSED) |
12262 | 50 | { |
12263 | 50 | const unsigned char * filename; |
12264 | 50 | unsigned int filelen; |
12265 | | |
12266 | 50 | introduce (section, false); |
12267 | | |
12268 | | /* The .gnu_debuglink section is formatted as: |
12269 | | (c-string) Filename. |
12270 | | (padding) If needed to reach a 4 byte boundary. |
12271 | | (uint32_t) CRC32 value. |
12272 | | |
12273 | | The .gnu_debugaltlink section is formatted as: |
12274 | | (c-string) Filename. |
12275 | | (binary) Build-ID. */ |
12276 | | |
12277 | 50 | filename = section->start; |
12278 | 50 | filelen = strnlen ((const char *) filename, section->size); |
12279 | 50 | if (filelen == section->size) |
12280 | 3 | { |
12281 | 3 | warn (_("The debuglink filename is corrupt/missing\n")); |
12282 | 3 | return 0; |
12283 | 3 | } |
12284 | | |
12285 | 47 | printf (_(" Separate debug info file: %s\n"), filename); |
12286 | | |
12287 | 47 | if (startswith (section->name, ".gnu_debuglink")) |
12288 | 44 | { |
12289 | 44 | unsigned int crc32; |
12290 | 44 | unsigned int crc_offset; |
12291 | | |
12292 | 44 | crc_offset = filelen + 1; |
12293 | 44 | crc_offset = (crc_offset + 3) & ~3; |
12294 | 44 | if (crc_offset + 4 > section->size) |
12295 | 2 | { |
12296 | 2 | warn (_("CRC offset missing/truncated\n")); |
12297 | 2 | return 0; |
12298 | 2 | } |
12299 | | |
12300 | 42 | crc32 = byte_get (filename + crc_offset, 4); |
12301 | | |
12302 | 42 | printf (_(" CRC value: %#x\n"), crc32); |
12303 | | |
12304 | 42 | if (crc_offset + 4 < section->size) |
12305 | 8 | { |
12306 | 8 | warn (_("There are %#" PRIx64 |
12307 | 8 | " extraneous bytes at the end of the section\n"), |
12308 | 8 | section->size - (crc_offset + 4)); |
12309 | 8 | return 0; |
12310 | 8 | } |
12311 | 42 | } |
12312 | 3 | else /* startswith (section->name, ".gnu_debugaltlink") */ |
12313 | 3 | { |
12314 | 3 | const unsigned char *build_id = section->start + filelen + 1; |
12315 | 3 | size_t build_id_len = section->size - (filelen + 1); |
12316 | 3 | size_t printed; |
12317 | | |
12318 | | /* FIXME: Should we support smaller build-id notes ? */ |
12319 | 3 | if (build_id_len < 0x14) |
12320 | 0 | { |
12321 | 0 | warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len); |
12322 | 0 | return 0; |
12323 | 0 | } |
12324 | | |
12325 | 3 | printed = printf (_(" Build-ID (%#zx bytes):"), build_id_len); |
12326 | 3 | display_data (printed, build_id, build_id_len); |
12327 | 3 | putchar ('\n'); |
12328 | 3 | } |
12329 | | |
12330 | 37 | putchar ('\n'); |
12331 | 37 | return 1; |
12332 | 47 | } |
12333 | | |
12334 | | static int |
12335 | | display_gdb_index (struct dwarf_section *section, |
12336 | | void *file ATTRIBUTE_UNUSED) |
12337 | 0 | { |
12338 | 0 | unsigned char *start = section->start; |
12339 | 0 | uint32_t version; |
12340 | 0 | uint32_t cu_list_offset, tu_list_offset; |
12341 | 0 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset, |
12342 | 0 | shortcut_table_offset; |
12343 | 0 | unsigned int cu_list_elements, tu_list_elements; |
12344 | 0 | unsigned int address_table_elements, symbol_table_slots; |
12345 | 0 | unsigned char *cu_list, *tu_list; |
12346 | 0 | unsigned char *address_table, *symbol_table, *shortcut_table, *constant_pool; |
12347 | 0 | unsigned int i; |
12348 | | |
12349 | | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ |
12350 | |
|
12351 | 0 | introduce (section, false); |
12352 | |
|
12353 | 0 | version = section->size < 4 ? 0 : byte_get_little_endian (start, 4); |
12354 | 0 | size_t header_size = (version < 9 ? 6 : 7) * sizeof (uint32_t); |
12355 | 0 | if (section->size < header_size) |
12356 | 0 | { |
12357 | 0 | warn (_("Truncated header in the %s section.\n"), section->name); |
12358 | 0 | return 0; |
12359 | 0 | } |
12360 | | |
12361 | 0 | printf (_("Version %lu\n"), (unsigned long) version); |
12362 | | |
12363 | | /* Prior versions are obsolete, and future versions may not be |
12364 | | backwards compatible. */ |
12365 | 0 | if (version < 3 || version > 9) |
12366 | 0 | { |
12367 | 0 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
12368 | 0 | return 0; |
12369 | 0 | } |
12370 | 0 | if (version < 4) |
12371 | 0 | warn (_("The address table data in version 3 may be wrong.\n")); |
12372 | 0 | if (version < 5) |
12373 | 0 | warn (_("Version 4 does not support case insensitive lookups.\n")); |
12374 | 0 | if (version < 6) |
12375 | 0 | warn (_("Version 5 does not include inlined functions.\n")); |
12376 | 0 | if (version < 7) |
12377 | 0 | warn (_("Version 6 does not include symbol attributes.\n")); |
12378 | | /* Version 7 indices generated by Gold have bad type unit references, |
12379 | | PR binutils/15021. But we don't know if the index was generated by |
12380 | | Gold or not, so to avoid worrying users with gdb-generated indices |
12381 | | we say nothing for version 7 here. */ |
12382 | |
|
12383 | 0 | cu_list_offset = byte_get_little_endian (start + 4, 4); |
12384 | 0 | tu_list_offset = byte_get_little_endian (start + 8, 4); |
12385 | 0 | address_table_offset = byte_get_little_endian (start + 12, 4); |
12386 | 0 | symbol_table_offset = byte_get_little_endian (start + 16, 4); |
12387 | 0 | shortcut_table_offset = byte_get_little_endian (start + 20, 4); |
12388 | 0 | if (version < 9) |
12389 | 0 | constant_pool_offset = shortcut_table_offset; |
12390 | 0 | else |
12391 | 0 | constant_pool_offset = byte_get_little_endian (start + 24, 4); |
12392 | |
|
12393 | 0 | if (cu_list_offset > section->size |
12394 | 0 | || tu_list_offset > section->size |
12395 | 0 | || address_table_offset > section->size |
12396 | 0 | || symbol_table_offset > section->size |
12397 | 0 | || shortcut_table_offset > section->size |
12398 | 0 | || constant_pool_offset > section->size |
12399 | 0 | || tu_list_offset < cu_list_offset |
12400 | 0 | || address_table_offset < tu_list_offset |
12401 | 0 | || symbol_table_offset < address_table_offset |
12402 | 0 | || shortcut_table_offset < symbol_table_offset |
12403 | 0 | || constant_pool_offset < shortcut_table_offset) |
12404 | 0 | { |
12405 | 0 | warn (_("Corrupt header in the %s section.\n"), section->name); |
12406 | 0 | return 0; |
12407 | 0 | } |
12408 | | |
12409 | 0 | cu_list_elements = (tu_list_offset - cu_list_offset) / 16; |
12410 | 0 | tu_list_elements = (address_table_offset - tu_list_offset) / 24; |
12411 | 0 | address_table_elements = (symbol_table_offset - address_table_offset) / 20; |
12412 | 0 | symbol_table_slots = (shortcut_table_offset - symbol_table_offset) / 8; |
12413 | |
|
12414 | 0 | cu_list = start + cu_list_offset; |
12415 | 0 | tu_list = start + tu_list_offset; |
12416 | 0 | address_table = start + address_table_offset; |
12417 | 0 | symbol_table = start + symbol_table_offset; |
12418 | 0 | shortcut_table = start + shortcut_table_offset; |
12419 | 0 | constant_pool = start + constant_pool_offset; |
12420 | |
|
12421 | 0 | printf (_("\nCU table:\n")); |
12422 | 0 | for (i = 0; i < cu_list_elements; i++) |
12423 | 0 | { |
12424 | 0 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 16, 8); |
12425 | 0 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 16 + 8, 8); |
12426 | |
|
12427 | 0 | printf ("[%3u] %#" PRIx64 " - %#" PRIx64 "\n", |
12428 | 0 | i, cu_offset, cu_offset + cu_length - 1); |
12429 | 0 | } |
12430 | |
|
12431 | 0 | printf (_("\nTU table:\n")); |
12432 | 0 | for (i = 0; i < tu_list_elements; i++) |
12433 | 0 | { |
12434 | 0 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 24, 8); |
12435 | 0 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 24 + 8, 8); |
12436 | 0 | uint64_t signature = byte_get_little_endian (tu_list + i * 24 + 16, 8); |
12437 | |
|
12438 | 0 | printf ("[%3u] %#" PRIx64 " %#" PRIx64 " ", |
12439 | 0 | i, tu_offset, type_offset); |
12440 | 0 | print_hex_ns (signature, 8); |
12441 | 0 | printf ("\n"); |
12442 | 0 | } |
12443 | |
|
12444 | 0 | printf (_("\nAddress table:\n")); |
12445 | 0 | for (i = 0; i < address_table_elements; i++) |
12446 | 0 | { |
12447 | 0 | uint64_t low = byte_get_little_endian (address_table + i * 20, 8); |
12448 | 0 | uint64_t high = byte_get_little_endian (address_table + i * 20 + 8, 8); |
12449 | 0 | uint32_t cu_index = byte_get_little_endian (address_table + i * 20 + 16, 4); |
12450 | |
|
12451 | 0 | print_hex (low, 8); |
12452 | 0 | print_hex (high, 8); |
12453 | 0 | printf ("%" PRIu32 "\n", cu_index); |
12454 | 0 | } |
12455 | |
|
12456 | 0 | printf (_("\nSymbol table:\n")); |
12457 | 0 | for (i = 0; i < symbol_table_slots; ++i) |
12458 | 0 | { |
12459 | 0 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); |
12460 | 0 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); |
12461 | 0 | uint32_t num_cus, cu; |
12462 | |
|
12463 | 0 | if (name_offset != 0 |
12464 | 0 | || cu_vector_offset != 0) |
12465 | 0 | { |
12466 | 0 | unsigned int j; |
12467 | | |
12468 | | /* PR 17531: file: 5b7b07ad. */ |
12469 | 0 | if (name_offset >= section->size - constant_pool_offset) |
12470 | 0 | { |
12471 | 0 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); |
12472 | 0 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), |
12473 | 0 | name_offset, i); |
12474 | 0 | } |
12475 | 0 | else |
12476 | 0 | printf ("[%3u] %.*s:", i, |
12477 | 0 | (int) (section->size - (constant_pool_offset + name_offset)), |
12478 | 0 | constant_pool + name_offset); |
12479 | |
|
12480 | 0 | if (section->size - constant_pool_offset < 4 |
12481 | 0 | || cu_vector_offset > section->size - constant_pool_offset - 4) |
12482 | 0 | { |
12483 | 0 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); |
12484 | 0 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), |
12485 | 0 | cu_vector_offset, i); |
12486 | 0 | continue; |
12487 | 0 | } |
12488 | | |
12489 | 0 | num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4); |
12490 | |
|
12491 | 0 | if ((uint64_t) num_cus * 4 > section->size - (constant_pool_offset |
12492 | 0 | + cu_vector_offset + 4)) |
12493 | 0 | { |
12494 | 0 | printf ("<invalid number of CUs: %d>\n", num_cus); |
12495 | 0 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
12496 | 0 | num_cus, i); |
12497 | 0 | continue; |
12498 | 0 | } |
12499 | | |
12500 | 0 | if (num_cus > 1) |
12501 | 0 | printf ("\n"); |
12502 | |
|
12503 | 0 | for (j = 0; j < num_cus; ++j) |
12504 | 0 | { |
12505 | 0 | int is_static; |
12506 | 0 | gdb_index_symbol_kind kind; |
12507 | |
|
12508 | 0 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
12509 | 0 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
12510 | 0 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
12511 | 0 | cu = GDB_INDEX_CU_VALUE (cu); |
12512 | | /* Convert to TU number if it's for a type unit. */ |
12513 | 0 | if (cu >= cu_list_elements) |
12514 | 0 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
12515 | 0 | (unsigned long) cu - cu_list_elements); |
12516 | 0 | else |
12517 | 0 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
12518 | |
|
12519 | 0 | printf (" [%s, %s]", |
12520 | 0 | is_static ? _("static") : _("global"), |
12521 | 0 | get_gdb_index_symbol_kind_name (kind)); |
12522 | 0 | if (num_cus > 1) |
12523 | 0 | printf ("\n"); |
12524 | 0 | } |
12525 | 0 | if (num_cus <= 1) |
12526 | 0 | printf ("\n"); |
12527 | 0 | } |
12528 | 0 | } |
12529 | |
|
12530 | 0 | if (version >= 9) |
12531 | 0 | { |
12532 | 0 | printf (_("\nShortcut table:\n")); |
12533 | |
|
12534 | 0 | if (shortcut_table_offset + 8 > constant_pool_offset) |
12535 | 0 | { |
12536 | 0 | warn (_("Corrupt shortcut table in the %s section.\n"), section->name); |
12537 | 0 | return 0; |
12538 | 0 | } |
12539 | | |
12540 | 0 | uint32_t lang = byte_get_little_endian (shortcut_table, 4); |
12541 | 0 | printf (_("Language of main: ")); |
12542 | 0 | display_lang (lang); |
12543 | 0 | printf ("\n"); |
12544 | |
|
12545 | 0 | printf (_("Name of main: ")); |
12546 | 0 | if (lang == 0) |
12547 | 0 | printf (_("<unknown>\n")); |
12548 | 0 | else |
12549 | 0 | { |
12550 | 0 | uint32_t name_offset = byte_get_little_endian (shortcut_table + 4, 4); |
12551 | 0 | if (name_offset >= section->size - constant_pool_offset) |
12552 | 0 | { |
12553 | 0 | printf (_("<corrupt offset: %x>\n"), name_offset); |
12554 | 0 | warn (_("Corrupt name offset of 0x%x found for name of main\n"), |
12555 | 0 | name_offset); |
12556 | 0 | } |
12557 | 0 | else |
12558 | 0 | printf ("%s\n", constant_pool + name_offset); |
12559 | 0 | } |
12560 | 0 | } |
12561 | | |
12562 | 0 | return 1; |
12563 | 0 | } |
12564 | | |
12565 | | /* Pre-allocate enough space for the CU/TU sets needed. */ |
12566 | | |
12567 | | static void |
12568 | | prealloc_cu_tu_list (unsigned int nshndx) |
12569 | 0 | { |
12570 | 0 | if (nshndx == 0) |
12571 | | /* Always allocate at least one entry for the end-marker. */ |
12572 | 0 | nshndx = 1; |
12573 | |
|
12574 | 0 | if (shndx_pool == NULL) |
12575 | 0 | { |
12576 | 0 | shndx_pool_size = nshndx; |
12577 | 0 | shndx_pool_used = 0; |
12578 | 0 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, |
12579 | 0 | sizeof (unsigned int)); |
12580 | 0 | } |
12581 | 0 | else |
12582 | 0 | { |
12583 | 0 | shndx_pool_size = shndx_pool_used + nshndx; |
12584 | 0 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, |
12585 | 0 | sizeof (unsigned int)); |
12586 | 0 | } |
12587 | 0 | } |
12588 | | |
12589 | | static void |
12590 | | add_shndx_to_cu_tu_entry (unsigned int shndx) |
12591 | 0 | { |
12592 | 0 | shndx_pool [shndx_pool_used++] = shndx; |
12593 | 0 | } |
12594 | | |
12595 | | static void |
12596 | | end_cu_tu_entry (void) |
12597 | 0 | { |
12598 | 0 | shndx_pool [shndx_pool_used++] = 0; |
12599 | 0 | } |
12600 | | |
12601 | | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
12602 | | |
12603 | | static const char * |
12604 | | get_DW_SECT_short_name (unsigned int dw_sect) |
12605 | 0 | { |
12606 | 0 | static char buf[16]; |
12607 | |
|
12608 | 0 | switch (dw_sect) |
12609 | 0 | { |
12610 | 0 | case DW_SECT_INFO: |
12611 | 0 | return "info"; |
12612 | 0 | case DW_SECT_TYPES: |
12613 | 0 | return "types"; |
12614 | 0 | case DW_SECT_ABBREV: |
12615 | 0 | return "abbrev"; |
12616 | 0 | case DW_SECT_LINE: |
12617 | 0 | return "line"; |
12618 | 0 | case DW_SECT_LOC: |
12619 | 0 | return "loc"; |
12620 | 0 | case DW_SECT_STR_OFFSETS: |
12621 | 0 | return "str_off"; |
12622 | 0 | case DW_SECT_MACINFO: |
12623 | 0 | return "macinfo"; |
12624 | 0 | case DW_SECT_MACRO: |
12625 | 0 | return "macro"; |
12626 | 0 | default: |
12627 | 0 | break; |
12628 | 0 | } |
12629 | | |
12630 | 0 | snprintf (buf, sizeof (buf), "%d", dw_sect); |
12631 | 0 | return buf; |
12632 | 0 | } |
12633 | | |
12634 | | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. |
12635 | | These sections are extensions for Fission. |
12636 | | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ |
12637 | | |
12638 | | static bool |
12639 | | process_cu_tu_index (struct dwarf_section *section, int do_display) |
12640 | 0 | { |
12641 | 0 | unsigned char *phdr = section->start; |
12642 | 0 | unsigned char *limit = phdr + section->size; |
12643 | 0 | unsigned char *phash; |
12644 | 0 | unsigned char *pindex; |
12645 | 0 | unsigned char *ppool; |
12646 | 0 | unsigned int version; |
12647 | 0 | unsigned int ncols = 0; |
12648 | 0 | unsigned int nused; |
12649 | 0 | unsigned int nslots; |
12650 | 0 | unsigned int i; |
12651 | 0 | unsigned int j; |
12652 | 0 | uint64_t signature; |
12653 | 0 | size_t total; |
12654 | | |
12655 | | /* PR 17512: file: 002-168123-0.004. */ |
12656 | 0 | if (phdr == NULL) |
12657 | 0 | { |
12658 | 0 | warn (_("Section %s is empty\n"), section->name); |
12659 | 0 | return false; |
12660 | 0 | } |
12661 | | /* PR 17512: file: 002-376-0.004. */ |
12662 | 0 | if (section->size < 24) |
12663 | 0 | { |
12664 | 0 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
12665 | 0 | section->name); |
12666 | 0 | return false; |
12667 | 0 | } |
12668 | | |
12669 | 0 | phash = phdr; |
12670 | 0 | SAFE_BYTE_GET_AND_INC (version, phash, 4, limit); |
12671 | 0 | if (version >= 2) |
12672 | 0 | SAFE_BYTE_GET_AND_INC (ncols, phash, 4, limit); |
12673 | 0 | SAFE_BYTE_GET_AND_INC (nused, phash, 4, limit); |
12674 | 0 | SAFE_BYTE_GET_AND_INC (nslots, phash, 4, limit); |
12675 | |
|
12676 | 0 | pindex = phash + (size_t) nslots * 8; |
12677 | 0 | ppool = pindex + (size_t) nslots * 4; |
12678 | |
|
12679 | 0 | if (do_display) |
12680 | 0 | { |
12681 | 0 | introduce (section, false); |
12682 | |
|
12683 | 0 | printf (_(" Version: %u\n"), version); |
12684 | 0 | if (version >= 2) |
12685 | 0 | printf (_(" Number of columns: %u\n"), ncols); |
12686 | 0 | printf (_(" Number of used entries: %u\n"), nused); |
12687 | 0 | printf (_(" Number of slots: %u\n\n"), nslots); |
12688 | 0 | } |
12689 | | |
12690 | | /* PR 17531: file: 45d69832. */ |
12691 | 0 | if (_mul_overflow ((size_t) nslots, 12, &total) |
12692 | 0 | || total > (size_t) (limit - phash)) |
12693 | 0 | { |
12694 | 0 | warn (ngettext ("Section %s is too small for %u slot\n", |
12695 | 0 | "Section %s is too small for %u slots\n", |
12696 | 0 | nslots), |
12697 | 0 | section->name, nslots); |
12698 | 0 | return false; |
12699 | 0 | } |
12700 | | |
12701 | 0 | if (version == 1) |
12702 | 0 | { |
12703 | 0 | unsigned char *shndx_list; |
12704 | 0 | unsigned int shndx; |
12705 | |
|
12706 | 0 | if (!do_display) |
12707 | 0 | { |
12708 | 0 | prealloc_cu_tu_list ((limit - ppool) / 4); |
12709 | 0 | for (shndx_list = ppool + 4; shndx_list <= limit - 4; shndx_list += 4) |
12710 | 0 | { |
12711 | 0 | shndx = byte_get (shndx_list, 4); |
12712 | 0 | add_shndx_to_cu_tu_entry (shndx); |
12713 | 0 | } |
12714 | 0 | end_cu_tu_entry (); |
12715 | 0 | } |
12716 | 0 | else |
12717 | 0 | for (i = 0; i < nslots; i++) |
12718 | 0 | { |
12719 | 0 | SAFE_BYTE_GET (signature, phash, 8, limit); |
12720 | 0 | if (signature != 0) |
12721 | 0 | { |
12722 | 0 | SAFE_BYTE_GET (j, pindex, 4, limit); |
12723 | 0 | shndx_list = ppool + j * 4; |
12724 | | /* PR 17531: file: 705e010d. */ |
12725 | 0 | if (shndx_list < ppool) |
12726 | 0 | { |
12727 | 0 | warn (_("Section index pool located before start of section\n")); |
12728 | 0 | return false; |
12729 | 0 | } |
12730 | | |
12731 | 0 | printf (_(" [%3d] Signature: %#" PRIx64 " Sections: "), |
12732 | 0 | i, signature); |
12733 | 0 | for (;;) |
12734 | 0 | { |
12735 | 0 | if (shndx_list >= limit) |
12736 | 0 | { |
12737 | 0 | warn (_("Section %s too small for shndx pool\n"), |
12738 | 0 | section->name); |
12739 | 0 | return false; |
12740 | 0 | } |
12741 | 0 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
12742 | 0 | if (shndx == 0) |
12743 | 0 | break; |
12744 | 0 | printf (" %d", shndx); |
12745 | 0 | shndx_list += 4; |
12746 | 0 | } |
12747 | 0 | printf ("\n"); |
12748 | 0 | } |
12749 | 0 | phash += 8; |
12750 | 0 | pindex += 4; |
12751 | 0 | } |
12752 | 0 | } |
12753 | 0 | else if (version == 2) |
12754 | 0 | { |
12755 | 0 | unsigned int val; |
12756 | 0 | unsigned int dw_sect; |
12757 | 0 | unsigned char *ph = phash; |
12758 | 0 | unsigned char *pi = pindex; |
12759 | 0 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
12760 | 0 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; |
12761 | 0 | bool is_tu_index; |
12762 | 0 | struct cu_tu_set *this_set = NULL; |
12763 | 0 | unsigned int row; |
12764 | 0 | unsigned char *prow; |
12765 | 0 | size_t temp; |
12766 | |
|
12767 | 0 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; |
12768 | | |
12769 | | /* PR 17531: file: 0dd159bf. |
12770 | | Check for integer overflow (can occur when size_t is 32-bit) |
12771 | | with overlarge ncols or nused values. */ |
12772 | 0 | if (nused == -1u |
12773 | 0 | || _mul_overflow ((size_t) ncols, 4, &temp) |
12774 | 0 | || _mul_overflow ((size_t) nused + 1, temp, &total) |
12775 | 0 | || total > (size_t) (limit - ppool) |
12776 | | /* PR 30227: ncols could be 0. */ |
12777 | 0 | || _mul_overflow ((size_t) nused + 1, 4, &total) |
12778 | 0 | || total > (size_t) (limit - ppool)) |
12779 | 0 | { |
12780 | 0 | warn (_("Section %s too small for offset and size tables\n"), |
12781 | 0 | section->name); |
12782 | 0 | return false; |
12783 | 0 | } |
12784 | | |
12785 | 0 | if (do_display) |
12786 | 0 | { |
12787 | 0 | printf (_(" Offset table\n")); |
12788 | 0 | printf (" slot %-16s ", |
12789 | 0 | is_tu_index ? _("signature") : _("dwo_id")); |
12790 | 0 | } |
12791 | 0 | else |
12792 | 0 | { |
12793 | 0 | if (is_tu_index) |
12794 | 0 | { |
12795 | 0 | tu_count = nused; |
12796 | 0 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
12797 | 0 | this_set = tu_sets; |
12798 | 0 | } |
12799 | 0 | else |
12800 | 0 | { |
12801 | 0 | cu_count = nused; |
12802 | 0 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
12803 | 0 | this_set = cu_sets; |
12804 | 0 | } |
12805 | 0 | } |
12806 | |
|
12807 | 0 | if (do_display) |
12808 | 0 | { |
12809 | 0 | for (j = 0; j < ncols; j++) |
12810 | 0 | { |
12811 | 0 | unsigned char *p = ppool + j * 4; |
12812 | 0 | SAFE_BYTE_GET (dw_sect, p, 4, limit); |
12813 | 0 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
12814 | 0 | } |
12815 | 0 | printf ("\n"); |
12816 | 0 | } |
12817 | |
|
12818 | 0 | for (i = 0; i < nslots; i++) |
12819 | 0 | { |
12820 | 0 | SAFE_BYTE_GET (signature, ph, 8, limit); |
12821 | |
|
12822 | 0 | SAFE_BYTE_GET (row, pi, 4, limit); |
12823 | 0 | if (row != 0) |
12824 | 0 | { |
12825 | | /* PR 17531: file: a05f6ab3. */ |
12826 | 0 | if (row > nused) |
12827 | 0 | { |
12828 | 0 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), |
12829 | 0 | row, nused); |
12830 | 0 | return false; |
12831 | 0 | } |
12832 | | |
12833 | 0 | if (!do_display) |
12834 | 0 | { |
12835 | 0 | size_t num_copy = sizeof (uint64_t); |
12836 | |
|
12837 | 0 | memcpy (&this_set[row - 1].signature, ph, num_copy); |
12838 | 0 | } |
12839 | |
|
12840 | 0 | prow = poffsets + (row - 1) * ncols * 4; |
12841 | 0 | if (do_display) |
12842 | 0 | printf (" [%3d] %#" PRIx64, i, signature); |
12843 | 0 | for (j = 0; j < ncols; j++) |
12844 | 0 | { |
12845 | 0 | unsigned char *p = prow + j * 4; |
12846 | 0 | SAFE_BYTE_GET (val, p, 4, limit); |
12847 | 0 | if (do_display) |
12848 | 0 | printf (" %8d", val); |
12849 | 0 | else |
12850 | 0 | { |
12851 | 0 | p = ppool + j * 4; |
12852 | 0 | SAFE_BYTE_GET (dw_sect, p, 4, limit); |
12853 | | |
12854 | | /* PR 17531: file: 10796eb3. */ |
12855 | 0 | if (dw_sect >= DW_SECT_MAX) |
12856 | 0 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); |
12857 | 0 | else |
12858 | 0 | this_set [row - 1].section_offsets [dw_sect] = val; |
12859 | 0 | } |
12860 | 0 | } |
12861 | |
|
12862 | 0 | if (do_display) |
12863 | 0 | printf ("\n"); |
12864 | 0 | } |
12865 | 0 | ph += 8; |
12866 | 0 | pi += 4; |
12867 | 0 | } |
12868 | | |
12869 | 0 | ph = phash; |
12870 | 0 | pi = pindex; |
12871 | 0 | if (do_display) |
12872 | 0 | { |
12873 | 0 | printf ("\n"); |
12874 | 0 | printf (_(" Size table\n")); |
12875 | 0 | printf (" slot %-16s ", |
12876 | 0 | is_tu_index ? _("signature") : _("dwo_id")); |
12877 | 0 | } |
12878 | |
|
12879 | 0 | for (j = 0; j < ncols; j++) |
12880 | 0 | { |
12881 | 0 | unsigned char *p = ppool + j * 4; |
12882 | 0 | SAFE_BYTE_GET (val, p, 4, limit); |
12883 | 0 | if (do_display) |
12884 | 0 | printf (" %8s", get_DW_SECT_short_name (val)); |
12885 | 0 | } |
12886 | |
|
12887 | 0 | if (do_display) |
12888 | 0 | printf ("\n"); |
12889 | |
|
12890 | 0 | for (i = 0; i < nslots; i++) |
12891 | 0 | { |
12892 | 0 | SAFE_BYTE_GET (signature, ph, 8, limit); |
12893 | |
|
12894 | 0 | SAFE_BYTE_GET (row, pi, 4, limit); |
12895 | 0 | if (row != 0) |
12896 | 0 | { |
12897 | 0 | prow = psizes + (row - 1) * ncols * 4; |
12898 | |
|
12899 | 0 | if (do_display) |
12900 | 0 | printf (" [%3d] %#" PRIx64, i, signature); |
12901 | |
|
12902 | 0 | for (j = 0; j < ncols; j++) |
12903 | 0 | { |
12904 | 0 | unsigned char *p = prow + j * 4; |
12905 | | |
12906 | | /* PR 28645: Check for overflow. Since we do not know how |
12907 | | many populated rows there will be, we cannot just |
12908 | | perform a single check at the start of this function. */ |
12909 | 0 | if (p > (limit - 4)) |
12910 | 0 | { |
12911 | 0 | if (do_display) |
12912 | 0 | printf ("\n"); |
12913 | 0 | warn (_("Too many rows/columns in DWARF index section %s\n"), |
12914 | 0 | section->name); |
12915 | 0 | return false; |
12916 | 0 | } |
12917 | | |
12918 | 0 | SAFE_BYTE_GET (val, p, 4, limit); |
12919 | |
|
12920 | 0 | if (do_display) |
12921 | 0 | printf (" %8d", val); |
12922 | 0 | else |
12923 | 0 | { |
12924 | 0 | p = ppool + j * 4; |
12925 | 0 | SAFE_BYTE_GET (dw_sect, p, 4, limit); |
12926 | 0 | if (dw_sect >= DW_SECT_MAX) |
12927 | 0 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); |
12928 | 0 | else |
12929 | 0 | this_set [row - 1].section_sizes [dw_sect] = val; |
12930 | 0 | } |
12931 | 0 | } |
12932 | | |
12933 | 0 | if (do_display) |
12934 | 0 | printf ("\n"); |
12935 | 0 | } |
12936 | | |
12937 | 0 | ph += 8; |
12938 | 0 | pi += 4; |
12939 | 0 | } |
12940 | 0 | } |
12941 | 0 | else if (do_display) |
12942 | 0 | printf (_(" Unsupported version (%d)\n"), version); |
12943 | | |
12944 | 0 | if (do_display) |
12945 | 0 | printf ("\n"); |
12946 | |
|
12947 | 0 | return true; |
12948 | 0 | } |
12949 | | |
12950 | | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
12951 | | |
12952 | | /* Load the CU and TU indexes if present. This will build a list of |
12953 | | section sets that we can use to associate a .debug_info.dwo section |
12954 | | with its associated .debug_abbrev.dwo section in a .dwp file. */ |
12955 | | |
12956 | | static bool |
12957 | | load_cu_tu_indexes (void *file) |
12958 | 105 | { |
12959 | | /* If we have already loaded (or tried to load) the CU and TU indexes |
12960 | | then do not bother to repeat the task. */ |
12961 | 105 | if (cu_tu_indexes_read == -1) |
12962 | 105 | { |
12963 | 105 | cu_tu_indexes_read = true; |
12964 | | |
12965 | 105 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
12966 | 0 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
12967 | 0 | cu_tu_indexes_read = false; |
12968 | | |
12969 | 105 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
12970 | 0 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
12971 | 0 | cu_tu_indexes_read = false; |
12972 | 105 | } |
12973 | | |
12974 | 105 | return (bool) cu_tu_indexes_read; |
12975 | 105 | } |
12976 | | |
12977 | | /* Find the set of sections that includes section SHNDX. */ |
12978 | | |
12979 | | unsigned int * |
12980 | | find_cu_tu_set (void *file, unsigned int shndx) |
12981 | 0 | { |
12982 | 0 | unsigned int i; |
12983 | |
|
12984 | 0 | if (! load_cu_tu_indexes (file)) |
12985 | 0 | return NULL; |
12986 | | |
12987 | | /* Find SHNDX in the shndx pool. */ |
12988 | 0 | for (i = 0; i < shndx_pool_used; i++) |
12989 | 0 | if (shndx_pool [i] == shndx) |
12990 | 0 | break; |
12991 | |
|
12992 | 0 | if (i >= shndx_pool_used) |
12993 | 0 | return NULL; |
12994 | | |
12995 | | /* Now backup to find the first entry in the set. */ |
12996 | 0 | while (i > 0 && shndx_pool [i - 1] != 0) |
12997 | 0 | i--; |
12998 | |
|
12999 | 0 | return shndx_pool + i; |
13000 | 0 | } |
13001 | | |
13002 | | /* Display a .debug_cu_index or .debug_tu_index section. */ |
13003 | | |
13004 | | static int |
13005 | | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) |
13006 | 0 | { |
13007 | 0 | return process_cu_tu_index (section, 1); |
13008 | 0 | } |
13009 | | |
13010 | | static int |
13011 | | display_debug_not_supported (struct dwarf_section *section, |
13012 | | void *file ATTRIBUTE_UNUSED) |
13013 | 0 | { |
13014 | 0 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), |
13015 | 0 | section->name); |
13016 | |
|
13017 | 0 | return 1; |
13018 | 0 | } |
13019 | | |
13020 | | /* Like malloc, but takes two parameters like calloc. |
13021 | | Verifies that the first parameter is not too large. |
13022 | | Note: does *not* initialise the allocated memory to zero. */ |
13023 | | |
13024 | | void * |
13025 | | cmalloc (uint64_t nmemb, size_t size) |
13026 | 218k | { |
13027 | | /* Check for overflow. */ |
13028 | 218k | if (nmemb >= ~(size_t) 0 / size) |
13029 | 0 | return NULL; |
13030 | | |
13031 | 218k | return xmalloc (nmemb * size); |
13032 | 218k | } |
13033 | | |
13034 | | /* Like xmalloc, but takes two parameters like calloc. |
13035 | | Verifies that the first parameter is not too large. |
13036 | | Note: does *not* initialise the allocated memory to zero. */ |
13037 | | |
13038 | | void * |
13039 | | xcmalloc (uint64_t nmemb, size_t size) |
13040 | 10.9k | { |
13041 | | /* Check for overflow. */ |
13042 | 10.9k | if (nmemb >= ~(size_t) 0 / size) |
13043 | 0 | { |
13044 | 0 | fprintf (stderr, |
13045 | 0 | _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64 "\n"), |
13046 | 0 | nmemb); |
13047 | 0 | xexit (1); |
13048 | 0 | } |
13049 | | |
13050 | 10.9k | return xmalloc (nmemb * size); |
13051 | 10.9k | } |
13052 | | |
13053 | | /* Like xrealloc, but takes three parameters. |
13054 | | Verifies that the second parameter is not too large. |
13055 | | Note: does *not* initialise any new memory to zero. */ |
13056 | | |
13057 | | void * |
13058 | | xcrealloc (void *ptr, uint64_t nmemb, size_t size) |
13059 | 24.8k | { |
13060 | | /* Check for overflow. */ |
13061 | 24.8k | if (nmemb >= ~(size_t) 0 / size) |
13062 | 0 | { |
13063 | 0 | error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64 "\n"), |
13064 | 0 | nmemb); |
13065 | 0 | xexit (1); |
13066 | 0 | } |
13067 | | |
13068 | 24.8k | return xrealloc (ptr, nmemb * size); |
13069 | 24.8k | } |
13070 | | |
13071 | | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
13072 | | |
13073 | | void * |
13074 | | xcalloc2 (uint64_t nmemb, size_t size) |
13075 | 52.1k | { |
13076 | | /* Check for overflow. */ |
13077 | 52.1k | if (nmemb >= ~(size_t) 0 / size) |
13078 | 0 | { |
13079 | 0 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64 "\n"), |
13080 | 0 | nmemb); |
13081 | 0 | xexit (1); |
13082 | 0 | } |
13083 | | |
13084 | 52.1k | return xcalloc (nmemb, size); |
13085 | 52.1k | } |
13086 | | |
13087 | | static unsigned long |
13088 | | calc_gnu_debuglink_crc32 (unsigned long crc, |
13089 | | const unsigned char *buf, |
13090 | | size_t len) |
13091 | 0 | { |
13092 | 0 | static const unsigned long crc32_table[256] = |
13093 | 0 | { |
13094 | 0 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, |
13095 | 0 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, |
13096 | 0 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, |
13097 | 0 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, |
13098 | 0 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, |
13099 | 0 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, |
13100 | 0 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, |
13101 | 0 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, |
13102 | 0 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, |
13103 | 0 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, |
13104 | 0 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, |
13105 | 0 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, |
13106 | 0 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, |
13107 | 0 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, |
13108 | 0 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, |
13109 | 0 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, |
13110 | 0 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, |
13111 | 0 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, |
13112 | 0 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, |
13113 | 0 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, |
13114 | 0 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, |
13115 | 0 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, |
13116 | 0 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, |
13117 | 0 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, |
13118 | 0 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, |
13119 | 0 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, |
13120 | 0 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, |
13121 | 0 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, |
13122 | 0 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, |
13123 | 0 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, |
13124 | 0 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, |
13125 | 0 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, |
13126 | 0 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, |
13127 | 0 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, |
13128 | 0 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, |
13129 | 0 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, |
13130 | 0 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, |
13131 | 0 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, |
13132 | 0 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, |
13133 | 0 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, |
13134 | 0 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, |
13135 | 0 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, |
13136 | 0 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, |
13137 | 0 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, |
13138 | 0 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, |
13139 | 0 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, |
13140 | 0 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, |
13141 | 0 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, |
13142 | 0 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, |
13143 | 0 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, |
13144 | 0 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, |
13145 | 0 | 0x2d02ef8d |
13146 | 0 | }; |
13147 | 0 | const unsigned char *end; |
13148 | |
|
13149 | 0 | crc = ~crc & 0xffffffff; |
13150 | 0 | for (end = buf + len; buf < end; ++ buf) |
13151 | 0 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); |
13152 | 0 | return ~crc & 0xffffffff; |
13153 | 0 | } |
13154 | | |
13155 | | typedef bool (*check_func_type) (const char *, void *); |
13156 | | typedef const char *(* parse_func_type) (struct dwarf_section *, void *); |
13157 | | |
13158 | | static bool |
13159 | | check_gnu_debuglink (const char * pathname, void * crc_pointer) |
13160 | 288 | { |
13161 | 288 | static unsigned char buffer[8 * 1024]; |
13162 | 288 | FILE *f; |
13163 | 288 | size_t count; |
13164 | 288 | unsigned long crc = 0; |
13165 | 288 | void *sep_data; |
13166 | | |
13167 | 288 | sep_data = open_debug_file (pathname); |
13168 | 288 | if (sep_data == NULL) |
13169 | 288 | return false; |
13170 | | |
13171 | | /* Yes - we are opening the file twice... */ |
13172 | 0 | f = fopen (pathname, "rb"); |
13173 | 0 | if (f == NULL) |
13174 | 0 | { |
13175 | | /* Paranoia: This should never happen. */ |
13176 | 0 | close_debug_file (sep_data); |
13177 | 0 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); |
13178 | 0 | return false; |
13179 | 0 | } |
13180 | | |
13181 | 0 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) |
13182 | 0 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); |
13183 | |
|
13184 | 0 | fclose (f); |
13185 | 0 | close_debug_file (sep_data); |
13186 | |
|
13187 | 0 | if (crc != * (unsigned long *) crc_pointer) |
13188 | 0 | { |
13189 | 0 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), |
13190 | 0 | pathname); |
13191 | 0 | return false; |
13192 | 0 | } |
13193 | | |
13194 | 0 | return true; |
13195 | 0 | } |
13196 | | |
13197 | | static const char * |
13198 | | parse_gnu_debuglink (struct dwarf_section * section, void * data) |
13199 | 47 | { |
13200 | 47 | const char * name; |
13201 | 47 | unsigned int crc_offset; |
13202 | 47 | unsigned long * crc32 = (unsigned long *) data; |
13203 | | |
13204 | | /* The name is first. |
13205 | | The CRC value is stored after the filename, aligned up to 4 bytes. */ |
13206 | 47 | name = (const char *) section->start; |
13207 | | |
13208 | 47 | crc_offset = strnlen (name, section->size) + 1; |
13209 | 47 | if (crc_offset == 1) |
13210 | 6 | return NULL; |
13211 | 41 | crc_offset = (crc_offset + 3) & ~3; |
13212 | 41 | if (crc_offset + 4 > section->size) |
13213 | 5 | return NULL; |
13214 | | |
13215 | 36 | * crc32 = byte_get (section->start + crc_offset, 4); |
13216 | 36 | return name; |
13217 | 41 | } |
13218 | | |
13219 | | static bool |
13220 | | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) |
13221 | 16 | { |
13222 | 16 | void * sep_data = open_debug_file (filename); |
13223 | | |
13224 | 16 | if (sep_data == NULL) |
13225 | 16 | return false; |
13226 | | |
13227 | | /* FIXME: We should now extract the build-id in the separate file |
13228 | | and check it... */ |
13229 | | |
13230 | 0 | close_debug_file (sep_data); |
13231 | 0 | return true; |
13232 | 16 | } |
13233 | | |
13234 | | typedef struct build_id_data |
13235 | | { |
13236 | | size_t len; |
13237 | | const unsigned char *data; |
13238 | | } Build_id_data; |
13239 | | |
13240 | | static const char * |
13241 | | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) |
13242 | 3 | { |
13243 | 3 | const char *name; |
13244 | 3 | size_t namelen; |
13245 | 3 | size_t id_len; |
13246 | 3 | Build_id_data *build_id_data; |
13247 | | |
13248 | | /* The name is first. |
13249 | | The build-id follows immediately, with no padding, up to the section's end. */ |
13250 | | |
13251 | 3 | name = (const char *) section->start; |
13252 | 3 | namelen = strnlen (name, section->size) + 1; |
13253 | 3 | if (namelen == 1) |
13254 | 1 | return NULL; |
13255 | 2 | if (namelen >= section->size) |
13256 | 0 | return NULL; |
13257 | | |
13258 | 2 | id_len = section->size - namelen; |
13259 | 2 | if (id_len < 0x14) |
13260 | 0 | return NULL; |
13261 | | |
13262 | 2 | build_id_data = (Build_id_data *) data; |
13263 | 2 | build_id_data->len = id_len; |
13264 | 2 | build_id_data->data = section->start + namelen; |
13265 | | |
13266 | 2 | return name; |
13267 | 2 | } |
13268 | | |
13269 | | static void |
13270 | | add_separate_debug_file (const char * filename, void * handle) |
13271 | 0 | { |
13272 | 0 | separate_info * i = xmalloc (sizeof * i); |
13273 | |
|
13274 | 0 | i->filename = filename; |
13275 | 0 | i->handle = handle; |
13276 | 0 | i->next = first_separate_info; |
13277 | 0 | first_separate_info = i; |
13278 | 0 | } |
13279 | | |
13280 | | #if HAVE_LIBDEBUGINFOD |
13281 | | /* Query debuginfod servers for the target debuglink or debugaltlink |
13282 | | file. If successful, store the path of the file in filename and |
13283 | | return TRUE, otherwise return FALSE. */ |
13284 | | |
13285 | | static bool |
13286 | | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, |
13287 | | char ** filename, |
13288 | | void * file) |
13289 | | { |
13290 | | size_t build_id_len; |
13291 | | unsigned char * build_id; |
13292 | | |
13293 | | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) |
13294 | | { |
13295 | | /* Get the build-id of file. */ |
13296 | | build_id = get_build_id (file); |
13297 | | build_id_len = 0; |
13298 | | } |
13299 | | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) |
13300 | | { |
13301 | | /* Get the build-id of the debugaltlink file. */ |
13302 | | unsigned int filelen; |
13303 | | |
13304 | | filelen = strnlen ((const char *)section->start, section->size); |
13305 | | if (filelen == section->size) |
13306 | | /* Corrupt debugaltlink. */ |
13307 | | return false; |
13308 | | |
13309 | | build_id = section->start + filelen + 1; |
13310 | | build_id_len = section->size - (filelen + 1); |
13311 | | |
13312 | | if (build_id_len == 0) |
13313 | | return false; |
13314 | | } |
13315 | | else |
13316 | | return false; |
13317 | | |
13318 | | if (build_id) |
13319 | | { |
13320 | | int fd; |
13321 | | debuginfod_client * client; |
13322 | | |
13323 | | client = debuginfod_begin (); |
13324 | | if (client == NULL) |
13325 | | return false; |
13326 | | |
13327 | | /* Query debuginfod servers for the target file. If found its path |
13328 | | will be stored in filename. */ |
13329 | | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); |
13330 | | debuginfod_end (client); |
13331 | | |
13332 | | /* Only free build_id if we allocated space for a hex string |
13333 | | in get_build_id (). */ |
13334 | | if (build_id_len == 0) |
13335 | | free (build_id); |
13336 | | |
13337 | | if (fd >= 0) |
13338 | | { |
13339 | | /* File successfully retrieved. Close fd since we want to |
13340 | | use open_debug_file () on filename instead. */ |
13341 | | close (fd); |
13342 | | return true; |
13343 | | } |
13344 | | } |
13345 | | |
13346 | | return false; |
13347 | | } |
13348 | | #endif /* HAVE_LIBDEBUGINFOD */ |
13349 | | |
13350 | | static void * |
13351 | | load_separate_debug_info (const char * main_filename, |
13352 | | struct dwarf_section * xlink, |
13353 | | parse_func_type parse_func, |
13354 | | check_func_type check_func, |
13355 | | void * func_data, |
13356 | | void * file ATTRIBUTE_UNUSED) |
13357 | 50 | { |
13358 | 50 | const char * separate_filename; |
13359 | 50 | char * debug_filename; |
13360 | 50 | char * canon_dir; |
13361 | 50 | size_t canon_dirlen; |
13362 | 50 | size_t dirlen; |
13363 | 50 | char * canon_filename; |
13364 | 50 | char * canon_debug_filename; |
13365 | 50 | bool self; |
13366 | | |
13367 | 50 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
13368 | 12 | { |
13369 | 12 | warn (_("Corrupt debuglink section: %s\n"), |
13370 | 12 | xlink->name ? xlink->name : xlink->uncompressed_name); |
13371 | 12 | return NULL; |
13372 | 12 | } |
13373 | | |
13374 | | /* Attempt to locate the separate file. |
13375 | | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ |
13376 | | |
13377 | 38 | canon_filename = lrealpath (main_filename); |
13378 | 38 | canon_dir = xstrdup (canon_filename); |
13379 | | |
13380 | 538 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) |
13381 | 538 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) |
13382 | 38 | break; |
13383 | 38 | canon_dir[canon_dirlen] = '\0'; |
13384 | | |
13385 | 38 | #ifndef DEBUGDIR |
13386 | 152 | #define DEBUGDIR "/lib/debug" |
13387 | 38 | #endif |
13388 | 38 | #ifndef EXTRA_DEBUG_ROOT1 |
13389 | 190 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" |
13390 | 38 | #endif |
13391 | 38 | #ifndef EXTRA_DEBUG_ROOT2 |
13392 | 114 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" |
13393 | 38 | #endif |
13394 | | |
13395 | 38 | unsigned long len = strlen (DEBUGDIR) + 1 |
13396 | 38 | + canon_dirlen |
13397 | 38 | + strlen (".debug/") |
13398 | 38 | #ifdef EXTRA_DEBUG_ROOT1 |
13399 | 38 | + strlen (EXTRA_DEBUG_ROOT1) |
13400 | 38 | #endif |
13401 | 38 | #ifdef EXTRA_DEBUG_ROOT2 |
13402 | 38 | + strlen (EXTRA_DEBUG_ROOT2) |
13403 | 38 | #endif |
13404 | 38 | + strlen (separate_filename) |
13405 | 38 | + 1; |
13406 | | |
13407 | 38 | if (separate_debug_info_dir) |
13408 | 0 | len += strlen (separate_debug_info_dir); |
13409 | | |
13410 | 38 | debug_filename = (char *) malloc (len); |
13411 | 38 | if (debug_filename == NULL) |
13412 | 0 | { |
13413 | 0 | warn (_("Out of memory\n")); |
13414 | 0 | free (canon_dir); |
13415 | 0 | free (canon_filename); |
13416 | 0 | return NULL; |
13417 | 0 | } |
13418 | | |
13419 | | /* If the user has supplied a debug info directory then try that first. */ |
13420 | 38 | if (separate_debug_info_dir != NULL) |
13421 | 0 | { |
13422 | 0 | sprintf (debug_filename, "%s/%s", separate_debug_info_dir, separate_filename); |
13423 | 0 | if (check_func (debug_filename, func_data)) |
13424 | 0 | goto found; |
13425 | 0 | } |
13426 | | |
13427 | | /* Next try in the current directory. */ |
13428 | 38 | sprintf (debug_filename, "%s", separate_filename); |
13429 | 38 | if (check_func (debug_filename, func_data)) |
13430 | 0 | goto found; |
13431 | | |
13432 | | /* Then try in a subdirectory called .debug. */ |
13433 | 38 | sprintf (debug_filename, ".debug/%s", separate_filename); |
13434 | 38 | if (check_func (debug_filename, func_data)) |
13435 | 0 | goto found; |
13436 | | |
13437 | | /* Then try in the same directory as the original file. */ |
13438 | 38 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
13439 | 38 | if (check_func (debug_filename, func_data)) |
13440 | 0 | goto found; |
13441 | | |
13442 | | /* And the .debug subdirectory of that directory. */ |
13443 | 38 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
13444 | 38 | if (check_func (debug_filename, func_data)) |
13445 | 0 | goto found; |
13446 | | |
13447 | 38 | #ifdef EXTRA_DEBUG_ROOT1 |
13448 | | /* Try the first extra debug file root. */ |
13449 | 38 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
13450 | 38 | if (check_func (debug_filename, func_data)) |
13451 | 0 | goto found; |
13452 | | |
13453 | | /* Try the first extra debug file root. */ |
13454 | 38 | sprintf (debug_filename, "%s/%s%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
13455 | 38 | if (check_func (debug_filename, func_data)) |
13456 | 0 | goto found; |
13457 | 38 | #endif |
13458 | | |
13459 | 38 | #ifdef EXTRA_DEBUG_ROOT2 |
13460 | | /* Try the second extra debug file root. */ |
13461 | 38 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
13462 | 38 | if (check_func (debug_filename, func_data)) |
13463 | 0 | goto found; |
13464 | 38 | #endif |
13465 | | |
13466 | | /* Then try in the global debug_filename directory. */ |
13467 | 38 | strcpy (debug_filename, DEBUGDIR); |
13468 | 38 | dirlen = strlen (DEBUGDIR) - 1; |
13469 | 38 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') |
13470 | 38 | strcat (debug_filename, "/"); |
13471 | 38 | strcat (debug_filename, (const char *) separate_filename); |
13472 | | |
13473 | 38 | if (check_func (debug_filename, func_data)) |
13474 | 0 | goto found; |
13475 | | |
13476 | | #if HAVE_LIBDEBUGINFOD |
13477 | | { |
13478 | | char * tmp_filename; |
13479 | | |
13480 | | if (use_debuginfod |
13481 | | && debuginfod_fetch_separate_debug_info (xlink, |
13482 | | & tmp_filename, |
13483 | | file)) |
13484 | | { |
13485 | | /* File successfully downloaded from server, replace |
13486 | | debug_filename with the file's path. */ |
13487 | | free (debug_filename); |
13488 | | debug_filename = tmp_filename; |
13489 | | goto found; |
13490 | | } |
13491 | | } |
13492 | | #endif |
13493 | | |
13494 | 38 | if (do_debug_links) |
13495 | 38 | { |
13496 | | /* Failed to find the file. */ |
13497 | 38 | warn (_("could not find separate debug file '%s'\n"), separate_filename); |
13498 | 38 | if (separate_debug_info_dir != NULL) |
13499 | 0 | warn (_("tried: %s/%s\n"), separate_debug_info_dir, separate_filename); |
13500 | 38 | warn (_("tried: %s\n"), separate_filename); |
13501 | 38 | warn (_("tried: .debug/%s\n"), separate_filename); |
13502 | 38 | warn (_("tried: %s%s\n"), canon_dir, separate_filename); |
13503 | 38 | #ifdef EXTRA_DEBUG_ROOT1 |
13504 | 38 | warn (_("tried: %s/%s\n"), EXTRA_DEBUG_ROOT1, separate_filename); |
13505 | 38 | warn (_("tried: %s/%s%s\n"), EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
13506 | 38 | #endif |
13507 | 38 | #ifdef EXTRA_DEBUG_ROOT2 |
13508 | 38 | warn (_("tried: %s/%s\n"), EXTRA_DEBUG_ROOT2, separate_filename); |
13509 | 38 | #endif |
13510 | 38 | warn (_("tried: %s\n"), debug_filename); |
13511 | | |
13512 | | #if HAVE_LIBDEBUGINFOD |
13513 | | if (use_debuginfod) |
13514 | | { |
13515 | | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); |
13516 | | |
13517 | | if (urls == NULL) |
13518 | | urls = ""; |
13519 | | |
13520 | | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); |
13521 | | } |
13522 | | #endif |
13523 | 38 | } |
13524 | | |
13525 | 38 | free (canon_dir); |
13526 | 38 | free (debug_filename); |
13527 | 38 | free (canon_filename); |
13528 | 38 | return NULL; |
13529 | | |
13530 | 0 | found: |
13531 | 0 | free (canon_dir); |
13532 | |
|
13533 | 0 | canon_debug_filename = lrealpath (debug_filename); |
13534 | 0 | self = strcmp (canon_debug_filename, canon_filename) == 0; |
13535 | 0 | free (canon_filename); |
13536 | 0 | free (canon_debug_filename); |
13537 | 0 | if (self) |
13538 | 0 | { |
13539 | 0 | free (debug_filename); |
13540 | 0 | return NULL; |
13541 | 0 | } |
13542 | | |
13543 | 0 | void * debug_handle; |
13544 | | |
13545 | | /* Now open the file.... */ |
13546 | 0 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
13547 | 0 | { |
13548 | 0 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
13549 | 0 | free (debug_filename); |
13550 | 0 | return NULL; |
13551 | 0 | } |
13552 | | |
13553 | | /* FIXME: We do not check to see if there are any other separate debug info |
13554 | | files that would also match. */ |
13555 | | |
13556 | 0 | if (do_debug_links) |
13557 | 0 | printf (_("\n%s: Found separate debug info file: %s\n"), main_filename, debug_filename); |
13558 | |
|
13559 | 0 | add_separate_debug_file (debug_filename, debug_handle); |
13560 | | |
13561 | | /* Do not free debug_filename - it might be referenced inside |
13562 | | the structure returned by open_debug_file(). */ |
13563 | 0 | return debug_handle; |
13564 | 0 | } |
13565 | | |
13566 | | /* Attempt to load a separate dwarf object file. */ |
13567 | | |
13568 | | static void * |
13569 | | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
13570 | 0 | { |
13571 | 0 | char * separate_filename; |
13572 | 0 | void * separate_handle; |
13573 | |
|
13574 | 0 | if (IS_ABSOLUTE_PATH (name)) |
13575 | 0 | separate_filename = strdup (name); |
13576 | 0 | else |
13577 | | /* FIXME: Skip adding / if dwo_dir ends in /. */ |
13578 | 0 | separate_filename = concat (dir, "/", name, NULL); |
13579 | 0 | if (separate_filename == NULL) |
13580 | 0 | { |
13581 | 0 | warn (_("Out of memory allocating dwo filename\n")); |
13582 | 0 | return NULL; |
13583 | 0 | } |
13584 | | |
13585 | 0 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
13586 | 0 | { |
13587 | 0 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
13588 | 0 | free (separate_filename); |
13589 | 0 | return NULL; |
13590 | 0 | } |
13591 | | |
13592 | | /* FIXME: We should check the dwo_id. */ |
13593 | | |
13594 | 0 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
13595 | |
|
13596 | 0 | add_separate_debug_file (separate_filename, separate_handle); |
13597 | | /* Note - separate_filename will be freed in free_debug_memory(). */ |
13598 | 0 | return separate_handle; |
13599 | 0 | } |
13600 | | |
13601 | | static void * |
13602 | | try_build_id_prefix (const char * prefix, char * filename, const unsigned char * data, unsigned long id_len) |
13603 | 294 | { |
13604 | 294 | char * f = filename; |
13605 | | |
13606 | 294 | f += sprintf (f, "%s.build-id/%02x/", prefix, (unsigned) *data++); |
13607 | 294 | id_len --; |
13608 | 5.88k | while (id_len --) |
13609 | 5.58k | f += sprintf (f, "%02x", (unsigned) *data++); |
13610 | 294 | strcpy (f, ".debug"); |
13611 | | |
13612 | 294 | return open_debug_file (filename); |
13613 | 294 | } |
13614 | | |
13615 | | /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */ |
13616 | | |
13617 | | static void |
13618 | | load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED, void * main_file) |
13619 | 40.2k | { |
13620 | 40.2k | if (! load_debug_section (note_gnu_build_id, main_file)) |
13621 | 40.1k | return; /* No .note.gnu.build-id section. */ |
13622 | | |
13623 | 58 | struct dwarf_section * section = & debug_displays [note_gnu_build_id].section; |
13624 | 58 | if (section == NULL) |
13625 | 0 | { |
13626 | 0 | warn (_("Unable to load the .note.gnu.build-id section\n")); |
13627 | 0 | return; |
13628 | 0 | } |
13629 | | |
13630 | 58 | if (section->start == NULL || section->size < 0x18) |
13631 | 0 | { |
13632 | 0 | warn (_(".note.gnu.build-id section is corrupt/empty\n")); |
13633 | 0 | return; |
13634 | 0 | } |
13635 | | |
13636 | | /* In theory we should extract the contents of the section into |
13637 | | a note structure and then check the fields. For now though |
13638 | | just use hard coded offsets instead: |
13639 | | |
13640 | | Field Bytes Contents |
13641 | | NSize 0...3 4 |
13642 | | DSize 4...7 8+ |
13643 | | Type 8..11 3 (NT_GNU_BUILD_ID) |
13644 | | Name 12.15 GNU\0 |
13645 | | Data 16.... */ |
13646 | | |
13647 | | /* FIXME: Check the name size, name and type fields. */ |
13648 | | |
13649 | 58 | unsigned long build_id_size; |
13650 | 58 | build_id_size = byte_get (section->start + 4, 4); |
13651 | 58 | if (build_id_size < 8) |
13652 | 3 | { |
13653 | 3 | warn (_(".note.gnu.build-id data size is too small\n")); |
13654 | 3 | return; |
13655 | 3 | } |
13656 | | |
13657 | 55 | if (build_id_size > (section->size - 16)) |
13658 | 6 | { |
13659 | 6 | warn (_(".note.gnu.build-id data size is too big\n")); |
13660 | 6 | return; |
13661 | 6 | } |
13662 | | |
13663 | 49 | char * filename; |
13664 | 49 | filename = xmalloc (strlen (".build-id/") |
13665 | 49 | + build_id_size * 2 + 2 |
13666 | 49 | + strlen (".debug") |
13667 | | /* The next string should be the same as the longest |
13668 | | name found in the prefixes[] array below. */ |
13669 | 49 | + strlen ("/usr/lib64/debug/usr/") |
13670 | 49 | + 1); |
13671 | 49 | void * handle; |
13672 | | |
13673 | 49 | static const char * prefixes[] = |
13674 | 49 | { |
13675 | 49 | "", |
13676 | 49 | ".debug/", |
13677 | 49 | "/usr/lib/debug/", |
13678 | 49 | "/usr/lib/debug/usr/", |
13679 | 49 | "/usr/lib64/debug/", |
13680 | 49 | "/usr/lib64/debug/usr/" |
13681 | 49 | }; |
13682 | 49 | long unsigned int i; |
13683 | | |
13684 | 343 | for (i = 0; i < ARRAY_SIZE (prefixes); i++) |
13685 | 294 | { |
13686 | 294 | handle = try_build_id_prefix (prefixes[i], filename, |
13687 | 294 | section->start + 16, build_id_size); |
13688 | 294 | if (handle != NULL) |
13689 | 0 | break; |
13690 | 294 | } |
13691 | | /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */ |
13692 | 49 | if (handle == NULL) |
13693 | 49 | { |
13694 | | /* Failed to find a debug file associated with the build-id. |
13695 | | This is not an error however, rather it just means that |
13696 | | the debug info has probably not been loaded on the system, |
13697 | | or that another method is being used to link to the debug |
13698 | | info. */ |
13699 | 49 | free (filename); |
13700 | 49 | return; |
13701 | 49 | } |
13702 | | |
13703 | 0 | add_separate_debug_file (filename, handle); |
13704 | 0 | } |
13705 | | |
13706 | | /* Try to load a debug file pointed to by the .debug_sup section. */ |
13707 | | |
13708 | | static void |
13709 | | load_debug_sup_file (const char * main_filename, void * file) |
13710 | 40.2k | { |
13711 | 40.2k | if (! load_debug_section (debug_sup, file)) |
13712 | 40.2k | return; /* No .debug_sup section. */ |
13713 | | |
13714 | 0 | struct dwarf_section * section; |
13715 | 0 | section = & debug_displays [debug_sup].section; |
13716 | 0 | assert (section != NULL); |
13717 | |
|
13718 | 0 | if (section->start == NULL || section->size < 5) |
13719 | 0 | { |
13720 | 0 | warn (_(".debug_sup section is corrupt/empty\n")); |
13721 | 0 | return; |
13722 | 0 | } |
13723 | | |
13724 | 0 | if (section->start[2] != 0) |
13725 | 0 | return; /* This is a supplementary file. */ |
13726 | | |
13727 | 0 | const char * filename = (const char *) section->start + 3; |
13728 | 0 | if (strnlen (filename, section->size - 3) == section->size - 3) |
13729 | 0 | { |
13730 | 0 | warn (_("filename in .debug_sup section is corrupt\n")); |
13731 | 0 | return; |
13732 | 0 | } |
13733 | | |
13734 | 0 | if (filename[0] != '/' && strchr (main_filename, '/')) |
13735 | 0 | filename = xasprintf ("%.*s/%s", |
13736 | 0 | (int) (strrchr (main_filename, '/') - main_filename), |
13737 | 0 | main_filename, |
13738 | 0 | filename); |
13739 | 0 | else |
13740 | | /* PR 27796: Make sure that we pass a filename that can be free'd to |
13741 | | add_separate_debug_file(). */ |
13742 | 0 | filename = xstrdup (filename); |
13743 | |
|
13744 | 0 | void * handle = open_debug_file (filename); |
13745 | 0 | if (handle == NULL) |
13746 | 0 | { |
13747 | 0 | warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename); |
13748 | 0 | free ((void *) filename); |
13749 | 0 | return; |
13750 | 0 | } |
13751 | | |
13752 | 0 | printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename, filename); |
13753 | | |
13754 | | /* FIXME: Compare the checksums, if present. */ |
13755 | 0 | add_separate_debug_file (filename, handle); |
13756 | 0 | } |
13757 | | |
13758 | | /* Load a debuglink section and/or a debugaltlink section, if either are present. |
13759 | | Recursively check the loaded files for more of these sections. |
13760 | | Also follow any links in .debug_sup sections. |
13761 | | FIXME: Should also check for DWO_* entries in the newly loaded files. */ |
13762 | | |
13763 | | static void |
13764 | | check_for_and_load_links (void * file, const char * filename) |
13765 | 40.2k | { |
13766 | 40.2k | void * handle = NULL; |
13767 | | |
13768 | 40.2k | if (load_debug_section (gnu_debugaltlink, file)) |
13769 | 3 | { |
13770 | 3 | Build_id_data build_id_data; |
13771 | | |
13772 | 3 | handle = load_separate_debug_info (filename, |
13773 | 3 | & debug_displays[gnu_debugaltlink].section, |
13774 | 3 | parse_gnu_debugaltlink, |
13775 | 3 | check_gnu_debugaltlink, |
13776 | 3 | & build_id_data, |
13777 | 3 | file); |
13778 | 3 | if (handle) |
13779 | 0 | { |
13780 | 0 | assert (handle == first_separate_info->handle); |
13781 | 0 | check_for_and_load_links (first_separate_info->handle, |
13782 | 0 | first_separate_info->filename); |
13783 | 0 | } |
13784 | 3 | } |
13785 | | |
13786 | 40.2k | if (load_debug_section (gnu_debuglink, file)) |
13787 | 47 | { |
13788 | 47 | unsigned long crc32; |
13789 | | |
13790 | 47 | handle = load_separate_debug_info (filename, |
13791 | 47 | & debug_displays[gnu_debuglink].section, |
13792 | 47 | parse_gnu_debuglink, |
13793 | 47 | check_gnu_debuglink, |
13794 | 47 | & crc32, |
13795 | 47 | file); |
13796 | 47 | if (handle) |
13797 | 0 | { |
13798 | 0 | assert (handle == first_separate_info->handle); |
13799 | 0 | check_for_and_load_links (first_separate_info->handle, |
13800 | 0 | first_separate_info->filename); |
13801 | 0 | } |
13802 | 47 | } |
13803 | | |
13804 | 40.2k | load_debug_sup_file (filename, file); |
13805 | | |
13806 | 40.2k | load_build_id_debug_file (filename, file); |
13807 | 40.2k | } |
13808 | | |
13809 | | /* Load the separate debug info file(s) attached to FILE, if any exist. |
13810 | | Returns TRUE if any were found, FALSE otherwise. |
13811 | | If TRUE is returned then the linked list starting at first_separate_info |
13812 | | will be populated with open file handles. */ |
13813 | | |
13814 | | bool |
13815 | | load_separate_debug_files (void * file, const char * filename) |
13816 | 48.9k | { |
13817 | | /* Skip this operation if we are not interested in debug links. */ |
13818 | 48.9k | if (! do_follow_links && ! do_debug_links) |
13819 | 136 | return false; |
13820 | | |
13821 | | /* See if there are any dwo links. */ |
13822 | 48.7k | if (load_debug_section (str, file) |
13823 | 522 | && load_debug_section (abbrev, file) |
13824 | 423 | && load_debug_section (info, file)) |
13825 | 231 | { |
13826 | | /* Load the .debug_addr section, if it exists. */ |
13827 | 231 | load_debug_section (debug_addr, file); |
13828 | | /* Load the .debug_str_offsets section, if it exists. */ |
13829 | 231 | load_debug_section (str_index, file); |
13830 | | /* Load the .debug_loclists section, if it exists. */ |
13831 | 231 | load_debug_section (loclists, file); |
13832 | | /* Load the .debug_rnglists section, if it exists. */ |
13833 | 231 | load_debug_section (rnglists, file); |
13834 | | |
13835 | 231 | free_dwo_info (); |
13836 | | |
13837 | 231 | if (process_debug_info (& debug_displays[info].section, file, abbrev, |
13838 | 231 | DO_LOC)) |
13839 | 126 | { |
13840 | 126 | bool introduced = false; |
13841 | 126 | dwo_info *dwinfo; |
13842 | 126 | const char *dir = NULL; |
13843 | 126 | const char *id = NULL; |
13844 | 126 | const char *name = NULL; |
13845 | | |
13846 | 201 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) |
13847 | 75 | { |
13848 | | /* Accumulate NAME, DIR and ID fields. */ |
13849 | 75 | switch (dwinfo->type) |
13850 | 75 | { |
13851 | 0 | case DWO_NAME: |
13852 | 0 | if (name != NULL) |
13853 | 0 | warn (_("Multiple DWO_NAMEs encountered for the same CU\n")); |
13854 | 0 | name = dwinfo->value; |
13855 | 0 | break; |
13856 | | |
13857 | 75 | case DWO_DIR: |
13858 | | /* There can be multiple DW_AT_comp_dir entries in a CU, |
13859 | | so do not complain. */ |
13860 | 75 | dir = dwinfo->value; |
13861 | 75 | break; |
13862 | | |
13863 | 0 | case DWO_ID: |
13864 | 0 | if (id != NULL) |
13865 | 0 | warn (_("multiple DWO_IDs encountered for the same CU\n")); |
13866 | 0 | id = dwinfo->value; |
13867 | 0 | break; |
13868 | | |
13869 | 0 | default: |
13870 | 0 | error (_("Unexpected DWO INFO type")); |
13871 | 0 | break; |
13872 | 75 | } |
13873 | | |
13874 | | /* If we have reached the end of our list, or we are changing |
13875 | | CUs, then display the information that we have accumulated |
13876 | | so far. */ |
13877 | 75 | if (name != NULL |
13878 | 0 | && (dwinfo->next == NULL |
13879 | 0 | || dwinfo->next->cu_offset != dwinfo->cu_offset)) |
13880 | 0 | { |
13881 | 0 | if (do_debug_links) |
13882 | 0 | { |
13883 | 0 | if (! introduced) |
13884 | 0 | { |
13885 | 0 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), |
13886 | 0 | debug_displays [info].section.uncompressed_name); |
13887 | 0 | introduced = true; |
13888 | 0 | } |
13889 | |
|
13890 | 0 | printf (_(" Name: %s\n"), name); |
13891 | 0 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); |
13892 | 0 | if (id != NULL) |
13893 | 0 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); |
13894 | 0 | else if (debug_information[0].dwarf_version != 5) |
13895 | 0 | printf (_(" ID: <not specified>\n")); |
13896 | 0 | printf ("\n\n"); |
13897 | 0 | } |
13898 | |
|
13899 | 0 | if (do_follow_links) |
13900 | 0 | load_dwo_file (filename, name, dir, id); |
13901 | |
|
13902 | 0 | name = dir = id = NULL; |
13903 | 0 | } |
13904 | 75 | } |
13905 | 126 | } |
13906 | 231 | } |
13907 | | |
13908 | 48.7k | if (! do_follow_links) |
13909 | | /* The other debug links will be displayed by display_debug_links() |
13910 | | so we do not need to do any further processing here. */ |
13911 | 8.54k | return false; |
13912 | | |
13913 | | /* FIXME: We do not check for the presence of both link sections in the same file. */ |
13914 | | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
13915 | | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
13916 | | |
13917 | 40.2k | check_for_and_load_links (file, filename); |
13918 | | |
13919 | 40.2k | if (first_separate_info != NULL) |
13920 | 0 | return true; |
13921 | | |
13922 | 40.2k | do_follow_links = 0; |
13923 | 40.2k | return false; |
13924 | 40.2k | } |
13925 | | |
13926 | | void |
13927 | | free_debug_memory (void) |
13928 | 120k | { |
13929 | 120k | unsigned int i; |
13930 | | |
13931 | 120k | free_all_abbrevs (); |
13932 | | |
13933 | 120k | free (shndx_pool); |
13934 | 120k | shndx_pool = NULL; |
13935 | 120k | shndx_pool_size = 0; |
13936 | 120k | shndx_pool_used = 0; |
13937 | 120k | free (cu_sets); |
13938 | 120k | cu_sets = NULL; |
13939 | 120k | cu_count = 0; |
13940 | 120k | free (tu_sets); |
13941 | 120k | tu_sets = NULL; |
13942 | 120k | tu_count = 0; |
13943 | | |
13944 | 120k | memset (level_type_signed, 0, sizeof level_type_signed); |
13945 | 120k | cu_tu_indexes_read = -1; |
13946 | | |
13947 | 6.15M | for (i = 0; i < max; i++) |
13948 | 6.03M | free_debug_section ((enum dwarf_section_display_enum) i); |
13949 | | |
13950 | 120k | if (debug_information != NULL) |
13951 | 267 | { |
13952 | 814 | for (i = 0; i < alloc_num_debug_info_entries; i++) |
13953 | 547 | free_debug_information (&debug_information[i]); |
13954 | 267 | free (debug_information); |
13955 | 267 | debug_information = NULL; |
13956 | 267 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
13957 | 267 | } |
13958 | | |
13959 | 120k | separate_info * d; |
13960 | 120k | separate_info * next; |
13961 | | |
13962 | 120k | for (d = first_separate_info; d != NULL; d = next) |
13963 | 0 | { |
13964 | 0 | close_debug_file (d->handle); |
13965 | 0 | free ((void *) d->filename); |
13966 | 0 | next = d->next; |
13967 | 0 | free ((void *) d); |
13968 | 0 | } |
13969 | 120k | first_separate_info = NULL; |
13970 | | |
13971 | 120k | free_dwo_info (); |
13972 | 120k | } |
13973 | | |
13974 | | typedef struct |
13975 | | { |
13976 | | const char letter; |
13977 | | const char *option; |
13978 | | int *variable; |
13979 | | int val; |
13980 | | } debug_dump_long_opts; |
13981 | | |
13982 | | static const debug_dump_long_opts debug_option_table[] = |
13983 | | { |
13984 | | { 'A', "addr", &do_debug_addr, 1 }, |
13985 | | { 'a', "abbrev", &do_debug_abbrevs, 1 }, |
13986 | | { 'c', "cu_index", &do_debug_cu_index, 1 }, |
13987 | | #ifdef HAVE_LIBDEBUGINFOD |
13988 | | { 'D', "use-debuginfod", &use_debuginfod, 1 }, |
13989 | | { 'E', "do-not-use-debuginfod", &use_debuginfod, 0 }, |
13990 | | #endif |
13991 | | { 'F', "frames-interp", &do_debug_frames_interp, 1 }, |
13992 | | { 'f', "frames", &do_debug_frames, 1 }, |
13993 | | { 'g', "gdb_index", &do_gdb_index, 1 }, |
13994 | | { 'i', "info", &do_debug_info, 1 }, |
13995 | | { 'K', "follow-links", &do_follow_links, 1 }, |
13996 | | { 'k', "links", &do_debug_links, 1 }, |
13997 | | { 'L', "decodedline", &do_debug_lines, FLAG_DEBUG_LINES_DECODED }, |
13998 | | { 'l', "rawline", &do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
13999 | | /* For compatibility with earlier versions of readelf. */ |
14000 | | { 'l', "line", &do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
14001 | | { 'm', "macro", &do_debug_macinfo, 1 }, |
14002 | | { 'N', "no-follow-links", &do_follow_links, 0 }, |
14003 | | { 'O', "str-offsets", &do_debug_str_offsets, 1 }, |
14004 | | { 'o', "loc", &do_debug_loc, 1 }, |
14005 | | { 'p', "pubnames", &do_debug_pubnames, 1 }, |
14006 | | { 'R', "Ranges", &do_debug_ranges, 1 }, |
14007 | | { 'r', "aranges", &do_debug_aranges, 1 }, |
14008 | | /* For compatibility with earlier versions of readelf. */ |
14009 | | { 'r', "ranges", &do_debug_aranges, 1 }, |
14010 | | { 's', "str", &do_debug_str, 1 }, |
14011 | | { 'T', "trace_aranges", &do_trace_aranges, 1 }, |
14012 | | { 't', "pubtypes", &do_debug_pubtypes, 1 }, |
14013 | | { 'U', "trace_info", &do_trace_info, 1 }, |
14014 | | { 'u', "trace_abbrev", &do_trace_abbrevs, 1 }, |
14015 | | { 0, NULL, NULL, 0 } |
14016 | | }; |
14017 | | |
14018 | | /* Enable display of specific DWARF sections as determined by the comma |
14019 | | separated strings in NAMES. Returns non-zero if any displaying was |
14020 | | enabled. */ |
14021 | | |
14022 | | int |
14023 | | dwarf_select_sections_by_names (const char *names) |
14024 | 0 | { |
14025 | 0 | const char *p; |
14026 | 0 | int result = 0; |
14027 | |
|
14028 | 0 | p = names; |
14029 | 0 | while (*p) |
14030 | 0 | { |
14031 | 0 | const debug_dump_long_opts *entry; |
14032 | |
|
14033 | 0 | for (entry = debug_option_table; entry->option; entry++) |
14034 | 0 | { |
14035 | 0 | size_t len = strlen (entry->option); |
14036 | |
|
14037 | 0 | if (strncmp (p, entry->option, len) == 0 |
14038 | 0 | && (p[len] == ',' || p[len] == '\0')) |
14039 | 0 | { |
14040 | 0 | if (entry->val == 0) |
14041 | 0 | * entry->variable = 0; |
14042 | 0 | else |
14043 | 0 | * entry->variable = entry->val; |
14044 | 0 | result |= entry->val; |
14045 | |
|
14046 | 0 | p += len; |
14047 | 0 | break; |
14048 | 0 | } |
14049 | 0 | } |
14050 | |
|
14051 | 0 | if (entry->option == NULL) |
14052 | 0 | { |
14053 | 0 | warn (_("Unrecognized debug option '%s'\n"), p); |
14054 | 0 | p = strchr (p, ','); |
14055 | 0 | if (p == NULL) |
14056 | 0 | break; |
14057 | 0 | } |
14058 | | |
14059 | 0 | if (*p == ',') |
14060 | 0 | p++; |
14061 | 0 | } |
14062 | | |
14063 | | /* The --debug-dump=frames-interp option also enables the |
14064 | | --debug-dump=frames option. */ |
14065 | 0 | if (do_debug_frames_interp) |
14066 | 0 | do_debug_frames = 1; |
14067 | |
|
14068 | 0 | return result; |
14069 | 0 | } |
14070 | | |
14071 | | /* Enable display of specific DWARF sections as determined by the characters |
14072 | | in LETTERS. Returns non-zero if any displaying was enabled. */ |
14073 | | |
14074 | | int |
14075 | | dwarf_select_sections_by_letters (const char *letters) |
14076 | 70.3k | { |
14077 | 70.3k | int result = 0; |
14078 | | |
14079 | 140k | while (* letters) |
14080 | 70.3k | { |
14081 | 70.3k | const debug_dump_long_opts *entry; |
14082 | | |
14083 | 703k | for (entry = debug_option_table; entry->letter; entry++) |
14084 | 703k | { |
14085 | 703k | if (entry->letter == * letters) |
14086 | 70.3k | { |
14087 | 70.3k | if (entry->val == 0) |
14088 | 0 | * entry->variable = 0; |
14089 | 70.3k | else |
14090 | 70.3k | * entry->variable |= entry->val; |
14091 | 70.3k | result |= entry->val; |
14092 | 70.3k | break; |
14093 | 70.3k | } |
14094 | 703k | } |
14095 | | |
14096 | 70.3k | if (entry->letter == 0) |
14097 | 0 | warn (_("Unrecognized debug letter option '%c'\n"), * letters); |
14098 | | |
14099 | 70.3k | letters ++; |
14100 | 70.3k | } |
14101 | | |
14102 | | /* The --debug-dump=frames-interp option also enables the |
14103 | | --debug-dump=frames option. */ |
14104 | 70.3k | if (do_debug_frames_interp) |
14105 | 0 | do_debug_frames = 1; |
14106 | | |
14107 | 70.3k | return result; |
14108 | 70.3k | } |
14109 | | |
14110 | | void |
14111 | | dwarf_select_sections_all (void) |
14112 | 70.3k | { |
14113 | 70.3k | do_debug_info = 1; |
14114 | 70.3k | do_debug_abbrevs = 1; |
14115 | 70.3k | do_debug_lines = FLAG_DEBUG_LINES_RAW; |
14116 | 70.3k | do_debug_pubnames = 1; |
14117 | 70.3k | do_debug_pubtypes = 1; |
14118 | 70.3k | do_debug_aranges = 1; |
14119 | 70.3k | do_debug_ranges = 1; |
14120 | 70.3k | do_debug_frames = 1; |
14121 | 70.3k | do_debug_macinfo = 1; |
14122 | 70.3k | do_debug_str = 1; |
14123 | 70.3k | do_debug_loc = 1; |
14124 | 70.3k | do_gdb_index = 1; |
14125 | 70.3k | do_trace_info = 1; |
14126 | 70.3k | do_trace_abbrevs = 1; |
14127 | 70.3k | do_trace_aranges = 1; |
14128 | 70.3k | do_debug_addr = 1; |
14129 | 70.3k | do_debug_cu_index = 1; |
14130 | 70.3k | do_follow_links = 1; |
14131 | 70.3k | do_debug_links = 1; |
14132 | 70.3k | do_debug_str_offsets = 1; |
14133 | 70.3k | } |
14134 | | |
14135 | | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0 |
14136 | | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0 |
14137 | | |
14138 | | /* N.B. The order here must match the order in section_display_enum. */ |
14139 | | |
14140 | | struct dwarf_section_display debug_displays[] = |
14141 | | { |
14142 | | { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, |
14143 | | { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, true }, |
14144 | | { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, |
14145 | | { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev)}, display_debug_info, &do_debug_info, true }, |
14146 | | { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, |
14147 | | { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, false }, |
14148 | | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, false }, |
14149 | | { { ".eh_frame", "", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, |
14150 | | { { ".eh_frame_hdr", "", "", NO_ABBREVS }, display_eh_frame_hdr, &do_debug_frames, true }, |
14151 | | { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, |
14152 | | { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, |
14153 | | { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, |
14154 | | { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, |
14155 | | { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, |
14156 | | { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, |
14157 | | { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, |
14158 | | { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, false }, |
14159 | | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, false }, |
14160 | | { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, |
14161 | | { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, |
14162 | | { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, |
14163 | | { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, |
14164 | | { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, |
14165 | | { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev) }, display_debug_types, &do_debug_info, true }, |
14166 | | { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, |
14167 | | { { ".gdb_index", "", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, false }, |
14168 | | { { ".debug_names", "", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, false }, |
14169 | | { { ".sframe", "", "", NO_ABBREVS }, display_sframe, &do_sframe, true }, |
14170 | | { { ".trace_info", "", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, true }, |
14171 | | { { ".trace_abbrev", "", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, false }, |
14172 | | { { ".trace_aranges", "", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, false }, |
14173 | | { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, true }, |
14174 | | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, |
14175 | | { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, true }, |
14176 | | { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, |
14177 | | { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, |
14178 | | { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, |
14179 | | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, |
14180 | | { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS }, display_debug_str, &do_debug_str, true }, |
14181 | | { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, |
14182 | | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, |
14183 | | { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS }, display_debug_addr, &do_debug_addr, true }, |
14184 | | { { ".debug_cu_index", "", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, |
14185 | | { { ".debug_tu_index", "", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, |
14186 | | { { ".gnu_debuglink", "", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, |
14187 | | { { ".gnu_debugaltlink", "", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, |
14188 | | { { ".debug_sup", "", "", NO_ABBREVS }, display_debug_sup, &do_debug_links, false }, |
14189 | | /* Separate debug info files can containt their own .debug_str section, |
14190 | | and this might be in *addition* to a .debug_str section already present |
14191 | | in the main file. Hence we need to have two entries for .debug_str. */ |
14192 | | { { ".debug_str", ".zdebug_str", "", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, |
14193 | | { { ".note.gnu.build-id", "", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, |
14194 | | { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev)}, display_variable_mapping_info, &do_debug_info, true } |
14195 | | }; |
14196 | | |
14197 | | /* A static assertion. */ |
14198 | | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |
14199 | | |
14200 | | static generic_type |
14201 | | do_link_variable_information (generic_type src_die, |
14202 | | generic_type target_die) |
14203 | 0 | { |
14204 | 0 | assert (src_die.field_type != NO_TYPE); |
14205 | |
|
14206 | 0 | generic_type res = { { .base_type = NULL }, NO_TYPE }; |
14207 | |
|
14208 | 0 | switch (src_die.field_type) |
14209 | 0 | { |
14210 | 0 | case NO_TYPE: |
14211 | 0 | case BASE_TYPE: |
14212 | 0 | case ENUM_TYPE: |
14213 | 0 | case MEMBER_PARENT: |
14214 | 0 | break; |
14215 | 0 | case MEMBER_TYPE: |
14216 | 0 | src_die.die_type.member_type->ptr_type = target_die; |
14217 | 0 | res = target_die; |
14218 | 0 | break; |
14219 | 0 | case TYPE_DEF: |
14220 | 0 | src_die.die_type.type_def->ptr_type = target_die; |
14221 | 0 | res = target_die; |
14222 | 0 | break; |
14223 | 0 | case TAB_TYPE: |
14224 | 0 | src_die.die_type.tab_type->ptr_type = target_die; |
14225 | 0 | res = target_die; |
14226 | 0 | break; |
14227 | 0 | case TYPE_PTR: |
14228 | 0 | src_die.die_type.type_ptr->ptr_type = target_die; |
14229 | 0 | res = target_die; |
14230 | 0 | break; |
14231 | 0 | case TYPE_REF: |
14232 | 0 | src_die.die_type.type_ref->ptr_type = target_die; |
14233 | 0 | res = target_die; |
14234 | 0 | break; |
14235 | 0 | case VARIABLE_TYPE: |
14236 | 0 | src_die.die_type.variable_type->ptr_type = target_die; |
14237 | | /* If the variable_type of src_die has either DW_AT_specification or |
14238 | | DW_AT_abstract_origin present then src_die's variable_type could |
14239 | | have missing attributes such as DW_AT_name. Hence move the attribute |
14240 | | DW_AT_location held by src_die to target_die which have complete |
14241 | | attributes. */ |
14242 | 0 | if (src_die.die_type.variable_type->is_specification |
14243 | 0 | || src_die.die_type.variable_type->is_abstract_origin) |
14244 | 0 | { |
14245 | 0 | assert (target_die.die_type.variable_type != NULL |
14246 | 0 | && target_die.field_type == VARIABLE_TYPE); |
14247 | 0 | target_die.die_type.variable_type->location_addr |
14248 | 0 | = src_die.die_type.variable_type->location_addr; |
14249 | 0 | } |
14250 | 0 | res = target_die; |
14251 | 0 | break; |
14252 | 0 | } |
14253 | | |
14254 | 0 | return res; |
14255 | 0 | } |
14256 | | |
14257 | | static bool |
14258 | | link_variable_information (generic_type src_die, uint64_t ptr_die_offset) |
14259 | 0 | { |
14260 | 0 | assert (src_die.field_type != NO_TYPE |
14261 | 0 | && src_die.die_type.base_type != NULL); |
14262 | |
|
14263 | 0 | base_type *i_base_type = base_type_list.head; |
14264 | 0 | while (i_base_type != NULL) |
14265 | 0 | { |
14266 | 0 | if (i_base_type->die_offset == ptr_die_offset) |
14267 | 0 | { |
14268 | 0 | generic_type generic_bt = { { .base_type = i_base_type }, BASE_TYPE }; |
14269 | 0 | do_link_variable_information (src_die, generic_bt); |
14270 | 0 | return true; |
14271 | 0 | } |
14272 | 0 | i_base_type = i_base_type->next; |
14273 | 0 | } |
14274 | | |
14275 | 0 | type_def *i_type_def = type_def_list.head; |
14276 | 0 | while (i_type_def != NULL) |
14277 | 0 | { |
14278 | 0 | if (i_type_def->die_offset == ptr_die_offset) |
14279 | 0 | { |
14280 | 0 | generic_type generic_td = { { .type_def = i_type_def }, TYPE_DEF }; |
14281 | 0 | generic_td = do_link_variable_information (src_die, generic_td); |
14282 | 0 | return link_variable_information (generic_td, |
14283 | 0 | i_type_def->ptr_die_offset); |
14284 | 0 | } |
14285 | 0 | i_type_def = i_type_def->next; |
14286 | 0 | } |
14287 | | |
14288 | 0 | enum_type *i_enum_type = enum_type_list.head; |
14289 | 0 | while (i_enum_type != NULL) |
14290 | 0 | { |
14291 | 0 | if (i_enum_type->die_offset == ptr_die_offset) |
14292 | 0 | { |
14293 | 0 | generic_type generic_et = { { .enum_type = i_enum_type }, ENUM_TYPE }; |
14294 | 0 | do_link_variable_information (src_die, generic_et); |
14295 | 0 | return true; |
14296 | 0 | } |
14297 | 0 | i_enum_type = i_enum_type->next; |
14298 | 0 | } |
14299 | | |
14300 | 0 | tab_type *i_tab_type = tab_type_list.head; |
14301 | 0 | while (i_tab_type != NULL) |
14302 | 0 | { |
14303 | 0 | if (i_tab_type->die_offset == ptr_die_offset) |
14304 | 0 | { |
14305 | 0 | generic_type generic_tt = { { .tab_type = i_tab_type }, TAB_TYPE }; |
14306 | 0 | generic_tt = do_link_variable_information (src_die, generic_tt); |
14307 | 0 | return link_variable_information (generic_tt, |
14308 | 0 | i_tab_type->ptr_die_offset); |
14309 | 0 | } |
14310 | 0 | i_tab_type = i_tab_type->next; |
14311 | 0 | } |
14312 | | |
14313 | 0 | member_parent *i_struct_type = struct_type_list.head; |
14314 | 0 | while (i_struct_type != NULL) |
14315 | 0 | { |
14316 | 0 | if (i_struct_type->die_offset == ptr_die_offset) |
14317 | 0 | { |
14318 | 0 | generic_type generic_mp = { { .member_parent = i_struct_type }, |
14319 | 0 | MEMBER_PARENT }; |
14320 | 0 | do_link_variable_information (src_die, generic_mp); |
14321 | |
|
14322 | 0 | if (i_struct_type->linked) |
14323 | 0 | return true; |
14324 | | |
14325 | 0 | i_struct_type->linked = true; |
14326 | 0 | member_type *i_member_type = i_struct_type->member_head; |
14327 | 0 | while (i_member_type != NULL) |
14328 | 0 | { |
14329 | 0 | generic_type generic_mt = { { .member_type = i_member_type }, |
14330 | 0 | MEMBER_TYPE }; |
14331 | 0 | link_variable_information (generic_mt, |
14332 | 0 | i_member_type->ptr_die_offset); |
14333 | 0 | i_member_type = i_member_type->next; |
14334 | 0 | } |
14335 | 0 | return true; |
14336 | 0 | } |
14337 | 0 | i_struct_type = i_struct_type->next; |
14338 | 0 | } |
14339 | | |
14340 | 0 | member_parent *i_union_type = union_type_list.head; |
14341 | 0 | while (i_union_type != NULL) |
14342 | 0 | { |
14343 | 0 | if (i_union_type->die_offset == ptr_die_offset) |
14344 | 0 | { |
14345 | 0 | generic_type generic_mp = { { .member_parent = i_union_type }, |
14346 | 0 | MEMBER_PARENT }; |
14347 | 0 | do_link_variable_information (src_die, generic_mp); |
14348 | |
|
14349 | 0 | if (i_union_type->linked) |
14350 | 0 | return true; |
14351 | | |
14352 | 0 | i_union_type->linked = true; |
14353 | 0 | member_type *i_member_type = i_union_type->member_head; |
14354 | 0 | while (i_member_type != NULL) |
14355 | 0 | { |
14356 | 0 | generic_type generic_mt = { { .member_type = i_member_type }, |
14357 | 0 | MEMBER_TYPE }; |
14358 | 0 | link_variable_information (generic_mt, |
14359 | 0 | i_member_type->ptr_die_offset); |
14360 | 0 | i_member_type = i_member_type->next; |
14361 | 0 | } |
14362 | 0 | return true; |
14363 | 0 | } |
14364 | 0 | i_union_type = i_union_type->next; |
14365 | 0 | } |
14366 | | |
14367 | 0 | type_ptr *i_ptr_type = ptr_type_list.head; |
14368 | 0 | while (i_ptr_type != NULL) |
14369 | 0 | { |
14370 | 0 | if (i_ptr_type->die_offset == ptr_die_offset) |
14371 | 0 | { |
14372 | 0 | generic_type generic_pt = { { .type_ptr = i_ptr_type }, TYPE_PTR }; |
14373 | 0 | generic_pt = do_link_variable_information (src_die, generic_pt); |
14374 | 0 | return link_variable_information (generic_pt, |
14375 | 0 | i_ptr_type->ptr_die_offset); |
14376 | 0 | } |
14377 | 0 | i_ptr_type = i_ptr_type->next; |
14378 | 0 | } |
14379 | | |
14380 | 0 | type_ref *i_const_type = const_type_list.head; |
14381 | 0 | while (i_const_type != NULL) |
14382 | 0 | { |
14383 | 0 | if (i_const_type->die_offset == ptr_die_offset) |
14384 | 0 | { |
14385 | 0 | generic_type generic_ref = { { .type_ref = i_const_type }, TYPE_REF }; |
14386 | 0 | generic_ref = do_link_variable_information (src_die, generic_ref); |
14387 | 0 | return link_variable_information (generic_ref, |
14388 | 0 | i_const_type->ptr_die_offset); |
14389 | 0 | } |
14390 | 0 | i_const_type = i_const_type->next; |
14391 | 0 | } |
14392 | | |
14393 | 0 | type_ref *i_volatile_type = volatile_type_list.head; |
14394 | 0 | while (i_volatile_type != NULL) |
14395 | 0 | { |
14396 | 0 | if (i_volatile_type->die_offset == ptr_die_offset) |
14397 | 0 | { |
14398 | 0 | generic_type generic_ref = { { .type_ref = i_volatile_type }, |
14399 | 0 | TYPE_REF }; |
14400 | 0 | generic_ref = do_link_variable_information (src_die, generic_ref); |
14401 | 0 | return link_variable_information (generic_ref, |
14402 | 0 | i_volatile_type->ptr_die_offset); |
14403 | 0 | } |
14404 | 0 | i_volatile_type = i_volatile_type->next; |
14405 | 0 | } |
14406 | | |
14407 | 0 | variable_type *i_variable_type = variable_type_list.head; |
14408 | 0 | while (i_variable_type != NULL) |
14409 | 0 | { |
14410 | 0 | if (i_variable_type->die_offset == ptr_die_offset) |
14411 | 0 | { |
14412 | 0 | generic_type generic_vt = { { .variable_type = i_variable_type }, |
14413 | 0 | VARIABLE_TYPE }; |
14414 | 0 | generic_vt = do_link_variable_information (src_die, generic_vt); |
14415 | 0 | return link_variable_information (generic_vt, |
14416 | 0 | i_variable_type->ptr_die_offset); |
14417 | 0 | } |
14418 | 0 | i_variable_type = i_variable_type->next;; |
14419 | 0 | } |
14420 | | |
14421 | 0 | if (i_base_type == NULL && i_type_def == NULL |
14422 | 0 | && i_enum_type == NULL && i_tab_type == NULL |
14423 | 0 | && i_struct_type == NULL && i_union_type == NULL |
14424 | 0 | && i_union_type == NULL && i_ptr_type == NULL |
14425 | 0 | && i_const_type == NULL && i_volatile_type == NULL |
14426 | 0 | && i_variable_type == NULL) |
14427 | 0 | return false; |
14428 | | |
14429 | 0 | return true; |
14430 | 0 | } |
14431 | | |
14432 | | static uint64_t |
14433 | | compute_variable_total_size (generic_type src_die) |
14434 | 0 | { |
14435 | 0 | uint64_t size = 0; |
14436 | |
|
14437 | 0 | switch (src_die.field_type) |
14438 | 0 | { |
14439 | 0 | case NO_TYPE: |
14440 | 0 | break; |
14441 | 0 | case BASE_TYPE: |
14442 | 0 | if (src_die.die_type.base_type->size_type == UNSIGNED_S) |
14443 | 0 | size = src_die.die_type.base_type->size.usize; |
14444 | 0 | else if (src_die.die_type.base_type->size_type == SIGNED_S) |
14445 | 0 | size = src_die.die_type.base_type->size.ssize; |
14446 | 0 | return size; |
14447 | 0 | case TYPE_DEF: |
14448 | 0 | return compute_variable_total_size (src_die.die_type.type_def->ptr_type); |
14449 | 0 | case ENUM_TYPE: |
14450 | 0 | if (src_die.die_type.enum_type->size_type == UNSIGNED_S) |
14451 | 0 | size = src_die.die_type.enum_type->size.usize; |
14452 | 0 | else if (src_die.die_type.enum_type->size_type == SIGNED_S) |
14453 | 0 | size = src_die.die_type.enum_type->size.ssize; |
14454 | 0 | return size; |
14455 | 0 | case TAB_TYPE: |
14456 | 0 | { |
14457 | 0 | size = (size == 0) ? 1 : size; |
14458 | 0 | subrange_type *i_subrange = src_die.die_type.tab_type->subrange_head; |
14459 | 0 | while (i_subrange != NULL) |
14460 | 0 | { |
14461 | 0 | if (i_subrange->size_type == UNSIGNED_S) |
14462 | 0 | size = i_subrange->size.usize * size; |
14463 | 0 | else if (i_subrange->size_type == SIGNED_S) |
14464 | 0 | size = i_subrange->size.ssize * size; |
14465 | 0 | i_subrange = i_subrange->next; |
14466 | 0 | } |
14467 | 0 | return size |
14468 | 0 | * compute_variable_total_size (src_die.die_type.tab_type->ptr_type); |
14469 | 0 | } |
14470 | 0 | case MEMBER_TYPE: |
14471 | 0 | return 0; |
14472 | 0 | case MEMBER_PARENT: |
14473 | 0 | if (src_die.die_type.member_parent->size_type == UNSIGNED_S) |
14474 | 0 | size = src_die.die_type.member_parent->size.usize; |
14475 | 0 | else if (src_die.die_type.member_parent->size_type == SIGNED_S) |
14476 | 0 | size = src_die.die_type.member_parent->size.ssize; |
14477 | 0 | return size; |
14478 | 0 | case TYPE_PTR: |
14479 | 0 | if (src_die.die_type.type_ptr->size_type == UNSIGNED_S) |
14480 | 0 | size = src_die.die_type.type_ptr->size.usize; |
14481 | 0 | else if (src_die.die_type.type_ptr->size_type == SIGNED_S) |
14482 | 0 | size = src_die.die_type.type_ptr->size.ssize; |
14483 | 0 | return size; |
14484 | 0 | case TYPE_REF: |
14485 | 0 | return compute_variable_total_size (src_die.die_type.type_ref->ptr_type); |
14486 | 0 | case VARIABLE_TYPE: |
14487 | 0 | return compute_variable_total_size ( |
14488 | 0 | src_die.die_type.variable_type->ptr_type); |
14489 | 0 | } |
14490 | 0 | return size; |
14491 | 0 | } |
14492 | | |
14493 | | static void |
14494 | | reset_displayed_field (member_parent *mp_type) |
14495 | 0 | { |
14496 | 0 | member_parent *i_mp = mp_type; |
14497 | 0 | while (i_mp != NULL) |
14498 | 0 | { |
14499 | 0 | i_mp->displayed = false; |
14500 | 0 | i_mp = i_mp->next; |
14501 | 0 | } |
14502 | 0 | } |
14503 | | |
14504 | | void |
14505 | | resolve_and_display_variable_info (void) |
14506 | 0 | { |
14507 | 0 | variable_type *i_vt = variable_type_list.head; |
14508 | 0 | while (i_vt != NULL) |
14509 | 0 | { |
14510 | 0 | generic_type generic_vt = { { .variable_type = i_vt }, VARIABLE_TYPE }; |
14511 | 0 | if (i_vt->has_location_addr |
14512 | 0 | && link_variable_information (generic_vt, i_vt->ptr_die_offset)) |
14513 | 0 | { |
14514 | 0 | uint64_t vt_size = compute_variable_total_size (generic_vt); |
14515 | | /* When is_specification or is_abstract_origin is true. The current |
14516 | | variable_type i_vt only holds DW_AT_location value and could be |
14517 | | missing DW_AT_name for example. Hence the move the size value to |
14518 | | the underlying DW_TAG_variable and display the underlying |
14519 | | DW_TAG_variable. */ |
14520 | 0 | if (i_vt->is_specification || i_vt->is_abstract_origin) |
14521 | 0 | { |
14522 | 0 | assert (i_vt->ptr_type.field_type == VARIABLE_TYPE |
14523 | 0 | && i_vt->ptr_type.die_type.variable_type != NULL); |
14524 | 0 | i_vt->ptr_type.die_type.variable_type->total_size = vt_size; |
14525 | 0 | } |
14526 | 0 | else |
14527 | 0 | i_vt->total_size = vt_size; |
14528 | 0 | display_variable_type (generic_vt, 0); |
14529 | 0 | reset_displayed_field (struct_type_list.head); |
14530 | 0 | reset_displayed_field (union_type_list.head); |
14531 | 0 | printf ("\n"); |
14532 | 0 | } |
14533 | 0 | i_vt = i_vt->next; |
14534 | 0 | } |
14535 | 0 | } |
14536 | | |
14537 | | static void |
14538 | | free_base_type (base_type *bt) |
14539 | 0 | { |
14540 | 0 | base_type *head = bt; |
14541 | 0 | while (head != NULL) |
14542 | 0 | { |
14543 | 0 | base_type *next = head->next; |
14544 | 0 | free (head); |
14545 | 0 | head = next; |
14546 | 0 | } |
14547 | 0 | } |
14548 | | |
14549 | | static void |
14550 | | free_type_def (type_def *td) |
14551 | 0 | { |
14552 | 0 | type_def *head = td; |
14553 | 0 | while (head != NULL) |
14554 | 0 | { |
14555 | 0 | type_def *next = head->next; |
14556 | 0 | free (head); |
14557 | 0 | head = next; |
14558 | 0 | } |
14559 | 0 | } |
14560 | | |
14561 | | static void |
14562 | | free_enum_constant (enum_constant *ec) |
14563 | 0 | { |
14564 | 0 | enum_constant *head = ec; |
14565 | 0 | while (head != NULL) |
14566 | 0 | { |
14567 | 0 | enum_constant *next = head->next; |
14568 | 0 | free (head); |
14569 | 0 | head = next; |
14570 | 0 | } |
14571 | 0 | } |
14572 | | |
14573 | | static void |
14574 | | free_enum_type (enum_type *et) |
14575 | 0 | { |
14576 | 0 | enum_type *head = et; |
14577 | 0 | while (head != NULL) |
14578 | 0 | { |
14579 | 0 | enum_type *next = head->next; |
14580 | 0 | free_enum_constant (head->enum_const_head); |
14581 | 0 | free (head); |
14582 | 0 | head = next; |
14583 | 0 | } |
14584 | 0 | } |
14585 | | |
14586 | | static void |
14587 | | free_subrange_type (subrange_type *st) |
14588 | 0 | { |
14589 | 0 | subrange_type * head = st; |
14590 | 0 | while (head != NULL) |
14591 | 0 | { |
14592 | 0 | subrange_type *next = head->next; |
14593 | 0 | free (head); |
14594 | 0 | head = next; |
14595 | 0 | } |
14596 | 0 | } |
14597 | | |
14598 | | static void |
14599 | | free_tab_type (tab_type *tt) |
14600 | 0 | { |
14601 | 0 | tab_type *head = tt; |
14602 | 0 | while (head != NULL) |
14603 | 0 | { |
14604 | 0 | tab_type *next = head->next; |
14605 | 0 | free_subrange_type (head->subrange_head); |
14606 | 0 | free (head); |
14607 | 0 | head = next; |
14608 | 0 | } |
14609 | 0 | } |
14610 | | |
14611 | | static void |
14612 | | free_member_type (member_type *mt) |
14613 | 0 | { |
14614 | 0 | member_type *head = mt; |
14615 | 0 | while (head != NULL) |
14616 | 0 | { |
14617 | 0 | member_type *next = head->next; |
14618 | 0 | free (head); |
14619 | 0 | head = next; |
14620 | 0 | } |
14621 | 0 | } |
14622 | | |
14623 | | static void |
14624 | | free_member_parent (member_parent *mp) |
14625 | 0 | { |
14626 | 0 | member_parent *head = mp; |
14627 | 0 | while (head != NULL) |
14628 | 0 | { |
14629 | 0 | member_parent *next = head->next; |
14630 | 0 | free_member_type (head->member_head); |
14631 | 0 | free (head); |
14632 | 0 | head = next; |
14633 | 0 | } |
14634 | 0 | } |
14635 | | |
14636 | | static void |
14637 | | free_type_ptr (type_ptr *tp) |
14638 | 0 | { |
14639 | 0 | type_ptr *head = tp; |
14640 | 0 | while (head != NULL) |
14641 | 0 | { |
14642 | 0 | type_ptr *next = head->next; |
14643 | 0 | free (head); |
14644 | 0 | head = next; |
14645 | 0 | } |
14646 | 0 | } |
14647 | | |
14648 | | static void |
14649 | | free_type_ref (type_ref *tr) |
14650 | 0 | { |
14651 | 0 | type_ref *head = tr; |
14652 | 0 | while (head != NULL) |
14653 | 0 | { |
14654 | 0 | type_ref *next = head->next; |
14655 | 0 | free (head); |
14656 | 0 | head = next; |
14657 | 0 | } |
14658 | 0 | } |
14659 | | |
14660 | | static void |
14661 | | free_variable_type (variable_type *vt) |
14662 | 0 | { |
14663 | 0 | variable_type *head = vt; |
14664 | 0 | while (head != NULL) |
14665 | 0 | { |
14666 | 0 | variable_type *next = head->next; |
14667 | 0 | free (head); |
14668 | 0 | head = next; |
14669 | 0 | } |
14670 | 0 | } |
14671 | | |
14672 | | void |
14673 | | free_mapping_info_struct (void) |
14674 | 0 | { |
14675 | 0 | free_base_type (base_type_list.head); |
14676 | 0 | free_type_def (type_def_list.head); |
14677 | 0 | free_enum_type (enum_type_list.head); |
14678 | 0 | free_tab_type (tab_type_list.head); |
14679 | 0 | free_member_parent (struct_type_list.head); |
14680 | 0 | free_member_parent (union_type_list.head); |
14681 | 0 | free_type_ptr (ptr_type_list.head); |
14682 | 0 | free_type_ref (const_type_list.head); |
14683 | 0 | free_type_ref (volatile_type_list.head); |
14684 | 0 | free_variable_type (variable_type_list.head); |
14685 | 0 | } |