]>
Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
e8e7cf2a | 2 | Copyright (C) 2005-2025 Free Software Foundation, Inc. |
19e6b90e L |
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 | |
32866df7 | 8 | the Free Software Foundation; either version 3 of the License, or |
19e6b90e L |
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 | ||
3db64b00 | 21 | #include "sysdep.h" |
19e6b90e | 22 | #include "libiberty.h" |
3db64b00 | 23 | #include "bfd.h" |
3dfb1b6d | 24 | #include <stdint.h> |
3db64b00 | 25 | #include "bucomm.h" |
3284fe0c | 26 | #include "elfcomm.h" |
2dc4cec1 | 27 | #include "elf/common.h" |
fa8f86ff | 28 | #include "dwarf2.h" |
3db64b00 | 29 | #include "dwarf.h" |
8d6eee87 | 30 | #include "gdb/gdb-index.h" |
dda8d76d | 31 | #include "filenames.h" |
48467cb9 | 32 | #include "safe-ctype.h" |
61364358 JK |
33 | #include <assert.h> |
34 | ||
301a9420 AM |
35 | #ifdef HAVE_LIBDEBUGINFOD |
36 | #include <elfutils/debuginfod.h> | |
37 | #endif | |
38 | ||
b9b204b3 | 39 | #include <limits.h> |
b9b204b3 AM |
40 | #ifndef CHAR_BIT |
41 | #define CHAR_BIT 8 | |
42 | #endif | |
43 | ||
c485e475 ES |
44 | #ifndef ENABLE_CHECKING |
45 | #define ENABLE_CHECKING 0 | |
46 | #endif | |
47 | ||
61364358 JK |
48 | #undef MAX |
49 | #undef MIN | |
50 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
51 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
19e6b90e | 52 | |
18464d4d | 53 | static const char *regname (unsigned int regno, int row); |
1296bc99 | 54 | static const char *regname_internal_by_table_only (unsigned int regno); |
18464d4d | 55 | |
19e6b90e | 56 | static int have_frame_base; |
b05efa39 | 57 | static int frame_base_level = -1; /* To support nested DW_TAG_subprogram's. */ |
19e6b90e L |
58 | static int need_base_address; |
59 | ||
19e6b90e | 60 | static unsigned int num_debug_info_entries = 0; |
82b1b41b | 61 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 62 | static debug_info *debug_information = NULL; |
cc86f28f NC |
63 | /* Special value for num_debug_info_entries to indicate |
64 | that the .debug_info section could not be loaded/parsed. */ | |
65 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 66 | |
24841daa NC |
67 | /* A .debug_info section can contain multiple links to separate |
68 | DWO object files. We use these structures to record these links. */ | |
69 | typedef enum dwo_type | |
70 | { | |
84102ebc VA |
71 | DWO_NAME, |
72 | DWO_DIR, | |
73 | DWO_ID | |
24841daa NC |
74 | } dwo_type; |
75 | ||
76 | typedef struct dwo_info | |
77 | { | |
78 | dwo_type type; | |
79 | const char * value; | |
31e5a3a3 | 80 | uint64_t cu_offset; |
24841daa NC |
81 | struct dwo_info * next; |
82 | } dwo_info; | |
83 | ||
015dc7e1 AM |
84 | static dwo_info *first_dwo_info = NULL; |
85 | static bool need_dwo_info; | |
24841daa NC |
86 | |
87 | separate_info * first_separate_info = NULL; | |
d85bf2ba | 88 | |
77ef8654 | 89 | unsigned int eh_addr_size; |
19e6b90e L |
90 | |
91 | int do_debug_info; | |
92 | int do_debug_abbrevs; | |
93 | int do_debug_lines; | |
94 | int do_debug_pubnames; | |
f9f0e732 | 95 | int do_debug_pubtypes; |
19e6b90e L |
96 | int do_debug_aranges; |
97 | int do_debug_ranges; | |
98 | int do_debug_frames; | |
99 | int do_debug_frames_interp; | |
100 | int do_debug_macinfo; | |
101 | int do_debug_str; | |
e4b7104b | 102 | int do_debug_str_offsets; |
19e6b90e | 103 | int do_debug_loc; |
5bbdf3d5 | 104 | int do_gdb_index; |
6f875884 TG |
105 | int do_trace_info; |
106 | int do_trace_abbrevs; | |
107 | int do_trace_aranges; | |
657d0d47 CC |
108 | int do_debug_addr; |
109 | int do_debug_cu_index; | |
a262ae96 | 110 | int do_wide; |
dda8d76d | 111 | int do_debug_links; |
c46b7066 | 112 | int do_follow_links = DEFAULT_FOR_FOLLOW_LINKS; |
bed566bb NC |
113 | #ifdef HAVE_LIBDEBUGINFOD |
114 | int use_debuginfod = 1; | |
115 | #endif | |
015dc7e1 | 116 | bool do_checks; |
19e6b90e | 117 | |
fd2f0033 TT |
118 | int dwarf_cutoff_level = -1; |
119 | unsigned long dwarf_start_die; | |
120 | ||
4723351a CC |
121 | int dwarf_check = 0; |
122 | ||
341f9135 CC |
123 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
124 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
125 | as a zero-terminated list of section indexes comprising one set of debug | |
126 | sections from a .dwo file. */ | |
127 | ||
341f9135 CC |
128 | static unsigned int *shndx_pool = NULL; |
129 | static unsigned int shndx_pool_size = 0; | |
130 | static unsigned int shndx_pool_used = 0; | |
131 | ||
132 | /* For version 2 package files, each set contains an array of section offsets | |
133 | and an array of section sizes, giving the offset and size of the | |
134 | contribution from a CU or TU within one of the debug sections. | |
135 | When displaying debug info from a package file, we need to use these | |
136 | tables to locate the corresponding contributions to each section. */ | |
137 | ||
138 | struct cu_tu_set | |
139 | { | |
31e5a3a3 AM |
140 | uint64_t signature; |
141 | uint64_t section_offsets[DW_SECT_MAX]; | |
142 | size_t section_sizes[DW_SECT_MAX]; | |
341f9135 CC |
143 | }; |
144 | ||
145 | static int cu_count = 0; | |
146 | static int tu_count = 0; | |
147 | static struct cu_tu_set *cu_sets = NULL; | |
148 | static struct cu_tu_set *tu_sets = NULL; | |
149 | ||
015dc7e1 | 150 | static bool load_cu_tu_indexes (void *); |
341f9135 | 151 | |
ec1b0fbb NC |
152 | /* An array that indicates for a given level of CU nesting whether |
153 | the latest DW_AT_type seen for that level was a signed type or | |
154 | an unsigned type. */ | |
155 | #define MAX_CU_NESTING (1 << 8) | |
015dc7e1 | 156 | static bool level_type_signed[MAX_CU_NESTING]; |
ec1b0fbb | 157 | |
4cb93e3b TG |
158 | /* Values for do_debug_lines. */ |
159 | #define FLAG_DEBUG_LINES_RAW 1 | |
160 | #define FLAG_DEBUG_LINES_DECODED 2 | |
161 | ||
77ef8654 | 162 | static unsigned int |
f1c4cc75 RH |
163 | size_of_encoded_value (int encoding) |
164 | { | |
165 | switch (encoding & 0x7) | |
166 | { | |
167 | default: /* ??? */ | |
168 | case 0: return eh_addr_size; | |
169 | case 2: return 2; | |
170 | case 3: return 4; | |
171 | case 4: return 8; | |
172 | } | |
173 | } | |
174 | ||
31e5a3a3 | 175 | static uint64_t |
041830e0 | 176 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 177 | int encoding, |
041830e0 NC |
178 | struct dwarf_section *section, |
179 | unsigned char * end) | |
f1c4cc75 | 180 | { |
041830e0 | 181 | unsigned char * data = * pdata; |
6937bb54 | 182 | unsigned int size = size_of_encoded_value (encoding); |
31e5a3a3 | 183 | uint64_t val; |
f1c4cc75 | 184 | |
fc5e0925 | 185 | if (data >= end || size > (size_t) (end - data)) |
041830e0 NC |
186 | { |
187 | warn (_("Encoded value extends past end of section\n")); | |
188 | * pdata = end; | |
189 | return 0; | |
190 | } | |
191 | ||
6937bb54 NC |
192 | /* PR 17512: file: 002-829853-0.004. */ |
193 | if (size > 8) | |
194 | { | |
195 | warn (_("Encoded size of %d is too large to read\n"), size); | |
196 | * pdata = end; | |
197 | return 0; | |
198 | } | |
199 | ||
0a9d414a NC |
200 | /* PR 17512: file: 1085-5603-0.004. */ |
201 | if (size == 0) | |
202 | { | |
203 | warn (_("Encoded size of 0 is too small to read\n")); | |
204 | * pdata = end; | |
205 | return 0; | |
206 | } | |
207 | ||
f1c4cc75 | 208 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 209 | val = byte_get_signed (data, size); |
f1c4cc75 | 210 | else |
bad62cf5 AM |
211 | val = byte_get (data, size); |
212 | ||
213 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
214 | val += section->address + (data - section->start); | |
041830e0 NC |
215 | |
216 | * pdata = data + size; | |
bad62cf5 | 217 | return val; |
f1c4cc75 RH |
218 | } |
219 | ||
31e5a3a3 AM |
220 | /* Print a uint64_t value (typically an address, offset or length) in |
221 | hexadecimal format, followed by a space. The precision displayed is | |
222 | determined by the NUM_BYTES parameter. */ | |
467c65bc | 223 | |
31e5a3a3 AM |
224 | static void |
225 | print_hex (uint64_t value, unsigned num_bytes) | |
47704ddf | 226 | { |
31e5a3a3 AM |
227 | if (num_bytes == 0) |
228 | num_bytes = 2; | |
bf5117e3 | 229 | |
31e5a3a3 AM |
230 | printf ("%0*" PRIx64 " ", num_bytes * 2, |
231 | value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); | |
bf5117e3 NC |
232 | } |
233 | ||
31e5a3a3 | 234 | /* Like print_hex, but no trailing space. */ |
bf5117e3 NC |
235 | |
236 | static void | |
31e5a3a3 | 237 | print_hex_ns (uint64_t value, unsigned num_bytes) |
bf5117e3 | 238 | { |
31e5a3a3 AM |
239 | if (num_bytes == 0) |
240 | num_bytes = 2; | |
241 | ||
242 | printf ("%0*" PRIx64, num_bytes * 2, | |
243 | value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); | |
47704ddf KT |
244 | } |
245 | ||
31e5a3a3 AM |
246 | /* Print a view number in hexadecimal value, with the same width as |
247 | print_hex would have printed it. */ | |
9f272209 AO |
248 | |
249 | static void | |
31e5a3a3 | 250 | print_view (uint64_t value, unsigned num_bytes) |
9f272209 | 251 | { |
31e5a3a3 AM |
252 | if (num_bytes == 0) |
253 | num_bytes = 2; | |
9f272209 | 254 | |
31e5a3a3 AM |
255 | printf ("v%0*" PRIx64 " ", num_bytes * 2 - 1, |
256 | value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); | |
9f272209 AO |
257 | } |
258 | ||
b1f1cefd AM |
259 | static const char * |
260 | null_name (const char *p) | |
261 | { | |
262 | if (p == NULL) | |
263 | p = _("unknown"); | |
264 | return p; | |
265 | } | |
266 | ||
f6f0e17b NC |
267 | /* Read in a LEB128 encoded value starting at address DATA. |
268 | If SIGN is true, return a signed LEB128 value. | |
269 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
b9b204b3 | 270 | If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the |
cd30bcef | 271 | terminating byte was not found and with bit 1 set if the value |
31e5a3a3 | 272 | overflows a uint64_t. |
f6f0e17b NC |
273 | No bytes will be read at address END or beyond. */ |
274 | ||
31e5a3a3 | 275 | uint64_t |
f6f0e17b | 276 | read_leb128 (unsigned char *data, |
cd30bcef | 277 | const unsigned char *const end, |
015dc7e1 | 278 | bool sign, |
cd30bcef AM |
279 | unsigned int *length_return, |
280 | int *status_return) | |
19e6b90e | 281 | { |
31e5a3a3 | 282 | uint64_t result = 0; |
19e6b90e L |
283 | unsigned int num_read = 0; |
284 | unsigned int shift = 0; | |
cd30bcef | 285 | int status = 1; |
19e6b90e | 286 | |
f6f0e17b | 287 | while (data < end) |
19e6b90e | 288 | { |
cd30bcef | 289 | unsigned char byte = *data++; |
b9b204b3 | 290 | unsigned char lost, mask; |
08d7da7d | 291 | |
19e6b90e L |
292 | num_read++; |
293 | ||
b9b204b3 | 294 | if (shift < CHAR_BIT * sizeof (result)) |
cd30bcef | 295 | { |
31e5a3a3 | 296 | result |= ((uint64_t) (byte & 0x7f)) << shift; |
b9b204b3 AM |
297 | /* These bits overflowed. */ |
298 | lost = byte ^ (result >> shift); | |
299 | /* And this is the mask of possible overflow bits. */ | |
31e5a3a3 | 300 | mask = 0x7f ^ ((uint64_t) 0x7f << shift >> shift); |
cd30bcef AM |
301 | shift += 7; |
302 | } | |
b9b204b3 | 303 | else |
08d7da7d | 304 | { |
b9b204b3 AM |
305 | lost = byte; |
306 | mask = 0x7f; | |
08d7da7d | 307 | } |
31e5a3a3 | 308 | if ((lost & mask) != (sign && (int64_t) result < 0 ? mask : 0)) |
b9b204b3 | 309 | status |= 2; |
19e6b90e | 310 | |
b9b204b3 | 311 | if ((byte & 0x80) == 0) |
cd30bcef AM |
312 | { |
313 | status &= ~1; | |
b9b204b3 | 314 | if (sign && shift < CHAR_BIT * sizeof (result) && (byte & 0x40)) |
31e5a3a3 | 315 | result |= -((uint64_t) 1 << shift); |
cd30bcef AM |
316 | break; |
317 | } | |
19e6b90e | 318 | } |
19e6b90e L |
319 | |
320 | if (length_return != NULL) | |
321 | *length_return = num_read; | |
cd30bcef AM |
322 | if (status_return != NULL) |
323 | *status_return = status; | |
19e6b90e L |
324 | |
325 | return result; | |
326 | } | |
327 | ||
6d1ad6f7 AM |
328 | /* Read AMOUNT bytes from PTR and store them in VAL. |
329 | Checks to make sure that the read will not reach or pass END. | |
330 | FUNC chooses whether the value read is unsigned or signed, and may | |
331 | be either byte_get or byte_get_signed. If INC is true, PTR is | |
332 | incremented after reading the value. | |
333 | This macro cannot protect against PTR values derived from user input. | |
334 | The C standard sections 6.5.6 and 6.5.8 say attempts to do so using | |
335 | pointers is undefined behaviour. */ | |
336 | #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \ | |
337 | do \ | |
338 | { \ | |
339 | size_t amount = (AMOUNT); \ | |
340 | if (sizeof (VAL) < amount) \ | |
341 | { \ | |
d3a49aa8 AM |
342 | error (ngettext ("internal error: attempt to read %d byte " \ |
343 | "of data in to %d sized variable", \ | |
344 | "internal error: attempt to read %d bytes " \ | |
345 | "of data in to %d sized variable", \ | |
346 | amount), \ | |
6d1ad6f7 AM |
347 | (int) amount, (int) sizeof (VAL)); \ |
348 | amount = sizeof (VAL); \ | |
349 | } \ | |
ebb17864 AM |
350 | if (ENABLE_CHECKING) \ |
351 | assert ((PTR) <= (END)); \ | |
6d1ad6f7 | 352 | size_t avail = (END) - (PTR); \ |
ebb17864 AM |
353 | if ((PTR) > (END)) \ |
354 | avail = 0; \ | |
6d1ad6f7 AM |
355 | if (amount > avail) \ |
356 | amount = avail; \ | |
357 | if (amount == 0) \ | |
358 | (VAL) = 0; \ | |
359 | else \ | |
360 | (VAL) = (FUNC) ((PTR), amount); \ | |
361 | if (INC) \ | |
362 | (PTR) += amount; \ | |
363 | } \ | |
0c588247 NC |
364 | while (0) |
365 | ||
6d1ad6f7 AM |
366 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
367 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false) | |
368 | ||
0c588247 | 369 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
6d1ad6f7 | 370 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true) |
0c588247 NC |
371 | |
372 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ | |
6d1ad6f7 | 373 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false) |
0c588247 NC |
374 | |
375 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ | |
6d1ad6f7 | 376 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true) |
0c588247 | 377 | |
19e6b90e L |
378 | typedef struct State_Machine_Registers |
379 | { | |
31e5a3a3 | 380 | uint64_t address; |
ba8826a8 | 381 | unsigned int view; |
19e6b90e L |
382 | unsigned int file; |
383 | unsigned int line; | |
384 | unsigned int column; | |
385 | int is_stmt; | |
386 | int basic_block; | |
a233b20c JJ |
387 | unsigned char op_index; |
388 | unsigned char end_sequence; | |
ba8826a8 AO |
389 | /* This variable hold the number of the last entry seen |
390 | in the File Table. */ | |
19e6b90e L |
391 | unsigned int last_file_entry; |
392 | } SMR; | |
393 | ||
394 | static SMR state_machine_regs; | |
395 | ||
396 | static void | |
397 | reset_state_machine (int is_stmt) | |
398 | { | |
399 | state_machine_regs.address = 0; | |
ba8826a8 | 400 | state_machine_regs.view = 0; |
a233b20c | 401 | state_machine_regs.op_index = 0; |
19e6b90e L |
402 | state_machine_regs.file = 1; |
403 | state_machine_regs.line = 1; | |
404 | state_machine_regs.column = 0; | |
405 | state_machine_regs.is_stmt = is_stmt; | |
406 | state_machine_regs.basic_block = 0; | |
407 | state_machine_regs.end_sequence = 0; | |
408 | state_machine_regs.last_file_entry = 0; | |
409 | } | |
410 | ||
411 | /* Handled an extend line op. | |
412 | Returns the number of bytes read. */ | |
413 | ||
cd30bcef | 414 | static size_t |
f6f0e17b NC |
415 | process_extended_line_op (unsigned char * data, |
416 | int is_stmt, | |
417 | unsigned char * end) | |
19e6b90e L |
418 | { |
419 | unsigned char op_code; | |
cd30bcef | 420 | size_t len, header_len; |
19e6b90e | 421 | unsigned char *name; |
143a3db0 | 422 | unsigned char *orig_data = data; |
31e5a3a3 | 423 | uint64_t adr, val; |
19e6b90e | 424 | |
cd30bcef AM |
425 | READ_ULEB (len, data, end); |
426 | header_len = data - orig_data; | |
19e6b90e | 427 | |
55b26492 | 428 | if (len == 0 || data >= end || len > (size_t) (end - data)) |
19e6b90e | 429 | { |
f41e4712 | 430 | warn (_("Badly formed extended line op encountered!\n")); |
cd30bcef | 431 | return header_len; |
19e6b90e L |
432 | } |
433 | ||
19e6b90e L |
434 | op_code = *data++; |
435 | ||
436 | printf (_(" Extended opcode %d: "), op_code); | |
437 | ||
438 | switch (op_code) | |
439 | { | |
440 | case DW_LNE_end_sequence: | |
441 | printf (_("End of Sequence\n\n")); | |
442 | reset_state_machine (is_stmt); | |
443 | break; | |
444 | ||
445 | case DW_LNE_set_address: | |
6937bb54 | 446 | /* PR 17512: file: 002-100480-0.004. */ |
cd30bcef | 447 | if (len - 1 > 8) |
77ef8654 | 448 | { |
31e5a3a3 AM |
449 | warn (_("Length (%zu) of DW_LNE_set_address op is too long\n"), |
450 | len - 1); | |
77ef8654 NC |
451 | adr = 0; |
452 | } | |
453 | else | |
cd30bcef | 454 | SAFE_BYTE_GET (adr, data, len - 1, end); |
cc443420 | 455 | printf (_("set Address to %#" PRIx64 "\n"), adr); |
19e6b90e | 456 | state_machine_regs.address = adr; |
ba8826a8 | 457 | state_machine_regs.view = 0; |
a233b20c | 458 | state_machine_regs.op_index = 0; |
19e6b90e L |
459 | break; |
460 | ||
461 | case DW_LNE_define_file: | |
143a3db0 | 462 | printf (_("define new File Table entry\n")); |
19e6b90e | 463 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 464 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 465 | |
d949ff56 NC |
466 | { |
467 | size_t l; | |
468 | ||
469 | name = data; | |
470 | l = strnlen ((char *) data, end - data); | |
a7077ce7 AM |
471 | data += l; |
472 | if (data < end) | |
473 | data++; | |
cd30bcef | 474 | READ_ULEB (val, data, end); |
31e5a3a3 | 475 | printf ("%" PRIu64 "\t", val); |
cd30bcef | 476 | READ_ULEB (val, data, end); |
31e5a3a3 | 477 | printf ("%" PRIu64 "\t", val); |
cd30bcef | 478 | READ_ULEB (val, data, end); |
31e5a3a3 | 479 | printf ("%" PRIu64 "\t", val); |
d949ff56 NC |
480 | printf ("%.*s\n\n", (int) l, name); |
481 | } | |
f6f0e17b | 482 | |
55b26492 | 483 | if (((size_t) (data - orig_data) != len + header_len) || data >= end) |
b4eb7656 | 484 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
485 | break; |
486 | ||
ed4a4bdf | 487 | case DW_LNE_set_discriminator: |
cd30bcef | 488 | READ_ULEB (val, data, end); |
31e5a3a3 | 489 | printf (_("set Discriminator to %" PRIu64 "\n"), val); |
ed4a4bdf CC |
490 | break; |
491 | ||
cb1861cb | 492 | /* HP extensions. */ |
e2a0d921 | 493 | case DW_LNE_HP_negate_is_UV_update: |
ed4a4bdf | 494 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
495 | break; |
496 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 497 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
498 | break; |
499 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 500 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
501 | break; |
502 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 503 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
504 | break; |
505 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 506 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
507 | break; |
508 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 509 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
510 | break; |
511 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 512 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
513 | break; |
514 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 515 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
516 | break; |
517 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 518 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
519 | break; |
520 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 521 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 522 | break; |
43294ab7 TG |
523 | case DW_LNE_HP_source_file_correlation: |
524 | { | |
cd30bcef | 525 | unsigned char *edata = data + len - 1; |
b4eb7656 AM |
526 | |
527 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
528 | ||
529 | while (data < edata) | |
530 | { | |
531 | unsigned int opc; | |
532 | ||
cd30bcef | 533 | READ_ULEB (opc, data, edata); |
b4eb7656 AM |
534 | |
535 | switch (opc) | |
536 | { | |
537 | case DW_LNE_HP_SFC_formfeed: | |
538 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
539 | break; | |
540 | case DW_LNE_HP_SFC_set_listing_line: | |
cd30bcef | 541 | READ_ULEB (val, data, edata); |
31e5a3a3 AM |
542 | printf (" DW_LNE_HP_SFC_set_listing_line (%" PRIu64 ")\n", |
543 | val); | |
b4eb7656 AM |
544 | break; |
545 | case DW_LNE_HP_SFC_associate: | |
546 | printf (" DW_LNE_HP_SFC_associate "); | |
cd30bcef | 547 | READ_ULEB (val, data, edata); |
31e5a3a3 | 548 | printf ("(%" PRIu64 , val); |
cd30bcef | 549 | READ_ULEB (val, data, edata); |
31e5a3a3 | 550 | printf (",%" PRIu64, val); |
cd30bcef | 551 | READ_ULEB (val, data, edata); |
31e5a3a3 | 552 | printf (",%" PRIu64 ")\n", val); |
b4eb7656 AM |
553 | break; |
554 | default: | |
555 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
556 | data = edata; | |
557 | break; | |
558 | } | |
559 | } | |
43294ab7 TG |
560 | } |
561 | break; | |
cecf136e | 562 | |
19e6b90e | 563 | default: |
7e665af3 | 564 | { |
cd30bcef | 565 | unsigned int rlen = len - 1; |
b4eb7656 AM |
566 | |
567 | if (op_code >= DW_LNE_lo_user | |
568 | /* The test against DW_LNW_hi_user is redundant due to | |
569 | the limited range of the unsigned char data type used | |
570 | for op_code. */ | |
571 | /*&& op_code <= DW_LNE_hi_user*/) | |
572 | printf (_("user defined: ")); | |
573 | else | |
574 | printf (_("UNKNOWN: ")); | |
575 | printf (_("length %d ["), rlen); | |
576 | for (; rlen; rlen--) | |
577 | printf (" %02x", *data++); | |
578 | printf ("]\n"); | |
7e665af3 | 579 | } |
19e6b90e L |
580 | break; |
581 | } | |
582 | ||
cd30bcef | 583 | return len + header_len; |
19e6b90e L |
584 | } |
585 | ||
0c588247 | 586 | static const unsigned char * |
31e5a3a3 | 587 | fetch_indirect_string (uint64_t offset) |
19e6b90e L |
588 | { |
589 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 590 | const unsigned char * ret; |
19e6b90e L |
591 | |
592 | if (section->start == NULL) | |
0c588247 | 593 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 594 | |
d949ff56 | 595 | if (offset >= section->size) |
19e6b90e | 596 | { |
31e5a3a3 | 597 | warn (_("DW_FORM_strp offset too big: %#" PRIx64 "\n"), offset); |
0c588247 | 598 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
599 | } |
600 | ||
d949ff56 NC |
601 | ret = section->start + offset; |
602 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
603 | NUL byte. Since our caller is expecting to receive a well formed C | |
604 | string we test for the lack of a terminating byte here. */ | |
605 | if (strnlen ((const char *) ret, section->size - offset) | |
606 | == section->size - offset) | |
607 | ret = (const unsigned char *) | |
608 | _("<no NUL byte at end of .debug_str section>"); | |
609 | ||
521d4b19 | 610 | return ret; |
19e6b90e L |
611 | } |
612 | ||
77145576 | 613 | static const unsigned char * |
31e5a3a3 | 614 | fetch_indirect_line_string (uint64_t offset) |
77145576 JK |
615 | { |
616 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 617 | const unsigned char * ret; |
77145576 JK |
618 | |
619 | if (section->start == NULL) | |
620 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
621 | ||
d949ff56 | 622 | if (offset >= section->size) |
77145576 | 623 | { |
31e5a3a3 | 624 | warn (_("DW_FORM_line_strp offset too big: %#" PRIx64 "\n"), offset); |
77145576 JK |
625 | return (const unsigned char *) _("<offset is too big>"); |
626 | } | |
627 | ||
d949ff56 NC |
628 | ret = section->start + offset; |
629 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
630 | with a NUL byte. Since our caller is expecting to receive a well formed | |
631 | C string we test for the lack of a terminating byte here. */ | |
632 | if (strnlen ((const char *) ret, section->size - offset) | |
633 | == section->size - offset) | |
634 | ret = (const unsigned char *) | |
635 | _("<no NUL byte at end of .debug_line_str section>"); | |
636 | ||
637 | return ret; | |
77145576 JK |
638 | } |
639 | ||
4723351a | 640 | static const char * |
31e5a3a3 AM |
641 | fetch_indexed_string (uint64_t idx, |
642 | struct cu_tu_set *this_set, | |
643 | uint64_t offset_size, | |
644 | bool dwo, | |
645 | uint64_t str_offsets_base) | |
4723351a CC |
646 | { |
647 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
648 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
649 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
650 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
31e5a3a3 AM |
651 | uint64_t index_offset; |
652 | uint64_t str_offset; | |
d949ff56 | 653 | const char * ret; |
4723351a CC |
654 | |
655 | if (index_section->start == NULL) | |
656 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
657 | : _("<no .debug_str_offsets section>")); | |
658 | ||
e4b7104b NC |
659 | if (str_section->start == NULL) |
660 | return (dwo ? _("<no .debug_str.dwo section>") | |
661 | : _("<no .debug_str section>")); | |
662 | ||
34d63622 AM |
663 | if (_mul_overflow (idx, offset_size, &index_offset) |
664 | || (this_set != NULL | |
665 | && ((index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]) | |
666 | < this_set->section_offsets [DW_SECT_STR_OFFSETS])) | |
667 | || (index_offset += str_offsets_base) < str_offsets_base | |
668 | || index_offset + offset_size < offset_size | |
669 | || index_offset + offset_size > index_section->size) | |
4723351a | 670 | { |
31e5a3a3 | 671 | warn (_("string index of %" PRIu64 " converts to an offset of %#" PRIx64 |
2b34e067 | 672 | " which is too big for section %s\n"), |
31e5a3a3 | 673 | idx, index_offset, str_section->name); |
4723351a | 674 | |
a3f1431a | 675 | return _("<string index too big>"); |
f18acc9c KB |
676 | } |
677 | ||
a3f1431a NC |
678 | str_offset = byte_get (index_section->start + index_offset, offset_size); |
679 | ||
d949ff56 | 680 | if (str_offset >= str_section->size) |
4723351a | 681 | { |
31e5a3a3 | 682 | warn (_("indirect offset too big: %#" PRIx64 "\n"), str_offset); |
4723351a CC |
683 | return _("<indirect index offset is too big>"); |
684 | } | |
685 | ||
d949ff56 | 686 | ret = (const char *) str_section->start + str_offset; |
a3f1431a | 687 | |
d949ff56 NC |
688 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. |
689 | Since our caller is expecting to receive a well formed C string we test | |
690 | for the lack of a terminating byte here. */ | |
691 | if (strnlen (ret, str_section->size - str_offset) | |
692 | == str_section->size - str_offset) | |
a3f1431a | 693 | return _("<no NUL byte at end of section>"); |
d949ff56 NC |
694 | |
695 | return ret; | |
4723351a CC |
696 | } |
697 | ||
31e5a3a3 AM |
698 | static uint64_t |
699 | fetch_indexed_addr (uint64_t offset, uint32_t num_bytes) | |
4723351a CC |
700 | { |
701 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
702 | ||
703 | if (section->start == NULL) | |
19c26da6 | 704 | { |
dbcbf67c | 705 | warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n")); |
19c26da6 NC |
706 | return 0; |
707 | } | |
4723351a | 708 | |
19c26da6 | 709 | if (offset + num_bytes > section->size) |
4723351a | 710 | { |
31e5a3a3 AM |
711 | warn (_("Offset into section %s too big: %#" PRIx64 "\n"), |
712 | section->name, offset); | |
19c26da6 | 713 | return 0; |
4723351a CC |
714 | } |
715 | ||
19c26da6 | 716 | return byte_get (section->start + offset, num_bytes); |
4723351a CC |
717 | } |
718 | ||
8c7125fe | 719 | /* This is for resolving DW_FORM_rnglistx and DW_FORM_loclistx. |
19c26da6 | 720 | |
8c7125fe VA |
721 | The memory layout is: base_address (taken from the CU's top DIE) points at a table of offsets, |
722 | relative to the section start. | |
84102ebc VA |
723 | The table of offsets contains the offsets of objects of interest relative to the table of offsets. |
724 | IDX is the index of the desired object in said table of offsets. | |
725 | ||
726 | This returns the offset of the desired object relative to the section start or -1 upon failure. */ | |
727 | ||
728 | static uint64_t | |
729 | fetch_indexed_offset (uint64_t idx, | |
730 | enum dwarf_section_display_enum sec_enum, | |
731 | uint64_t base_address, | |
732 | uint64_t offset_size) | |
733 | { | |
8c7125fe | 734 | uint64_t offset_of_offset = base_address + idx * offset_size; |
84102ebc VA |
735 | struct dwarf_section *section = &debug_displays [sec_enum].section; |
736 | ||
737 | if (section->start == NULL) | |
738 | { | |
739 | warn (_("Unable to locate %s section\n"), section->uncompressed_name); | |
740 | return -1; | |
741 | } | |
742 | ||
743 | if (section->size < 4) | |
744 | { | |
745 | warn (_("Section %s is too small to contain an value indexed from another section!\n"), | |
746 | section->name); | |
747 | return -1; | |
748 | } | |
749 | ||
8c7125fe | 750 | if (offset_of_offset + offset_size >= section->size) |
84102ebc VA |
751 | { |
752 | warn (_("Offset of %#" PRIx64 " is too big for section %s\n"), | |
8c7125fe | 753 | offset_of_offset, section->name); |
84102ebc VA |
754 | return -1; |
755 | } | |
cb1861cb | 756 | |
8c7125fe | 757 | return base_address + byte_get (section->start + offset_of_offset, offset_size); |
84102ebc VA |
758 | } |
759 | ||
19e6b90e L |
760 | /* FIXME: There are better and more efficient ways to handle |
761 | these structures. For now though, I just want something that | |
762 | is simple to implement. */ | |
bcd213b2 | 763 | /* Records a single attribute in an abbrev. */ |
19e6b90e L |
764 | typedef struct abbrev_attr |
765 | { | |
31e5a3a3 AM |
766 | unsigned long attribute; |
767 | unsigned long form; | |
768 | int64_t implicit_const; | |
769 | struct abbrev_attr *next; | |
19e6b90e L |
770 | } |
771 | abbrev_attr; | |
772 | ||
bcd213b2 | 773 | /* Records a single abbrev. */ |
19e6b90e L |
774 | typedef struct abbrev_entry |
775 | { | |
bcd213b2 NC |
776 | unsigned long number; |
777 | unsigned long tag; | |
778 | int children; | |
779 | struct abbrev_attr * first_attr; | |
780 | struct abbrev_attr * last_attr; | |
781 | struct abbrev_entry * next; | |
19e6b90e L |
782 | } |
783 | abbrev_entry; | |
784 | ||
bcd213b2 NC |
785 | /* Records a set of abbreviations. */ |
786 | typedef struct abbrev_list | |
787 | { | |
788 | abbrev_entry * first_abbrev; | |
789 | abbrev_entry * last_abbrev; | |
695c6dfe | 790 | unsigned char * raw; |
bcd213b2 NC |
791 | struct abbrev_list * next; |
792 | unsigned char * start_of_next_abbrevs; | |
793 | } | |
794 | abbrev_list; | |
795 | ||
796 | /* Records all the abbrevs found so far. */ | |
797 | static struct abbrev_list * abbrev_lists = NULL; | |
798 | ||
799 | typedef struct abbrev_map | |
800 | { | |
31e5a3a3 AM |
801 | uint64_t start; |
802 | uint64_t end; | |
803 | abbrev_list *list; | |
bcd213b2 NC |
804 | } abbrev_map; |
805 | ||
806 | /* Maps between CU offsets and abbrev sets. */ | |
807 | static abbrev_map * cu_abbrev_map = NULL; | |
808 | static unsigned long num_abbrev_map_entries = 0; | |
809 | static unsigned long next_free_abbrev_map_entry = 0; | |
810 | ||
811 | #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8 | |
812 | #define ABBREV_MAP_ENTRIES_INCREMENT 8 | |
813 | ||
814 | static void | |
31e5a3a3 | 815 | record_abbrev_list_for_cu (uint64_t start, uint64_t end, |
f07c08e1 | 816 | abbrev_list *list, abbrev_list *free_list) |
bcd213b2 | 817 | { |
f07c08e1 AM |
818 | if (free_list != NULL) |
819 | { | |
820 | list->next = abbrev_lists; | |
821 | abbrev_lists = list; | |
822 | } | |
823 | ||
bcd213b2 NC |
824 | if (cu_abbrev_map == NULL) |
825 | { | |
826 | num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES; | |
827 | cu_abbrev_map = xmalloc (num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
828 | } | |
829 | else if (next_free_abbrev_map_entry == num_abbrev_map_entries) | |
830 | { | |
831 | num_abbrev_map_entries += ABBREV_MAP_ENTRIES_INCREMENT; | |
832 | cu_abbrev_map = xrealloc (cu_abbrev_map, num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
833 | } | |
834 | ||
835 | cu_abbrev_map[next_free_abbrev_map_entry].start = start; | |
836 | cu_abbrev_map[next_free_abbrev_map_entry].end = end; | |
837 | cu_abbrev_map[next_free_abbrev_map_entry].list = list; | |
838 | next_free_abbrev_map_entry ++; | |
839 | } | |
19e6b90e | 840 | |
175b9150 AM |
841 | static abbrev_list * |
842 | free_abbrev_list (abbrev_list *list) | |
19e6b90e | 843 | { |
175b9150 | 844 | abbrev_entry *abbrv = list->first_abbrev; |
19e6b90e | 845 | |
175b9150 | 846 | while (abbrv) |
19e6b90e | 847 | { |
175b9150 | 848 | abbrev_attr *attr = abbrv->first_attr; |
19e6b90e | 849 | |
175b9150 | 850 | while (attr) |
19e6b90e | 851 | { |
175b9150 AM |
852 | abbrev_attr *next_attr = attr->next; |
853 | free (attr); | |
854 | attr = next_attr; | |
19e6b90e L |
855 | } |
856 | ||
175b9150 AM |
857 | abbrev_entry *next_abbrev = abbrv->next; |
858 | free (abbrv); | |
859 | abbrv = next_abbrev; | |
19e6b90e L |
860 | } |
861 | ||
175b9150 AM |
862 | abbrev_list *next = list->next; |
863 | free (list); | |
864 | return next; | |
865 | } | |
866 | ||
867 | static void | |
868 | free_all_abbrevs (void) | |
869 | { | |
870 | while (abbrev_lists) | |
871 | abbrev_lists = free_abbrev_list (abbrev_lists); | |
872 | ||
873 | free (cu_abbrev_map); | |
874 | cu_abbrev_map = NULL; | |
875 | next_free_abbrev_map_entry = 0; | |
bcd213b2 NC |
876 | } |
877 | ||
bcd213b2 | 878 | static abbrev_list * |
695c6dfe | 879 | find_abbrev_list_by_raw_abbrev (unsigned char *raw) |
bcd213b2 NC |
880 | { |
881 | abbrev_list * list; | |
882 | ||
883 | for (list = abbrev_lists; list != NULL; list = list->next) | |
695c6dfe | 884 | if (list->raw == raw) |
bcd213b2 NC |
885 | return list; |
886 | ||
887 | return NULL; | |
888 | } | |
889 | ||
890 | /* Find the abbreviation map for the CU that includes OFFSET. | |
891 | OFFSET is an absolute offset from the start of the .debug_info section. */ | |
892 | /* FIXME: This function is going to slow down readelf & objdump. | |
f07c08e1 | 893 | Not caching abbrevs is likely the answer. */ |
bcd213b2 NC |
894 | |
895 | static abbrev_map * | |
31e5a3a3 | 896 | find_abbrev_map_by_offset (uint64_t offset) |
bcd213b2 NC |
897 | { |
898 | unsigned long i; | |
899 | ||
900 | for (i = 0; i < next_free_abbrev_map_entry; i++) | |
901 | if (cu_abbrev_map[i].start <= offset | |
902 | && cu_abbrev_map[i].end > offset) | |
903 | return cu_abbrev_map + i; | |
904 | ||
175b9150 | 905 | return NULL; |
19e6b90e L |
906 | } |
907 | ||
908 | static void | |
bcd213b2 NC |
909 | add_abbrev (unsigned long number, |
910 | unsigned long tag, | |
911 | int children, | |
912 | abbrev_list * list) | |
19e6b90e | 913 | { |
bcd213b2 | 914 | abbrev_entry * entry; |
19e6b90e | 915 | |
bcd213b2 | 916 | entry = (abbrev_entry *) xmalloc (sizeof (*entry)); |
19e6b90e | 917 | |
bcd213b2 | 918 | entry->number = number; |
19e6b90e L |
919 | entry->tag = tag; |
920 | entry->children = children; | |
921 | entry->first_attr = NULL; | |
922 | entry->last_attr = NULL; | |
923 | entry->next = NULL; | |
924 | ||
bcd213b2 NC |
925 | assert (list != NULL); |
926 | ||
927 | if (list->first_abbrev == NULL) | |
928 | list->first_abbrev = entry; | |
19e6b90e | 929 | else |
bcd213b2 | 930 | list->last_abbrev->next = entry; |
19e6b90e | 931 | |
bcd213b2 | 932 | list->last_abbrev = entry; |
19e6b90e L |
933 | } |
934 | ||
935 | static void | |
31e5a3a3 AM |
936 | add_abbrev_attr (unsigned long attribute, |
937 | unsigned long form, | |
938 | int64_t implicit_const, | |
939 | abbrev_list *list) | |
19e6b90e L |
940 | { |
941 | abbrev_attr *attr; | |
942 | ||
bcd213b2 | 943 | attr = (abbrev_attr *) xmalloc (sizeof (*attr)); |
19e6b90e | 944 | |
0121f438 EB |
945 | attr->attribute = attribute; |
946 | attr->form = form; | |
77145576 | 947 | attr->implicit_const = implicit_const; |
0121f438 | 948 | attr->next = NULL; |
19e6b90e | 949 | |
bcd213b2 NC |
950 | assert (list != NULL && list->last_abbrev != NULL); |
951 | ||
952 | if (list->last_abbrev->first_attr == NULL) | |
953 | list->last_abbrev->first_attr = attr; | |
19e6b90e | 954 | else |
bcd213b2 | 955 | list->last_abbrev->last_attr->next = attr; |
19e6b90e | 956 | |
bcd213b2 | 957 | list->last_abbrev->last_attr = attr; |
19e6b90e L |
958 | } |
959 | ||
f07c08e1 AM |
960 | /* Return processed (partial) contents of a .debug_abbrev section. |
961 | Returns NULL on errors. */ | |
19e6b90e | 962 | |
f07c08e1 | 963 | static abbrev_list * |
f2f9554b | 964 | process_abbrev_set (struct dwarf_section *section, |
f07c08e1 AM |
965 | unsigned char *start, |
966 | unsigned char *end) | |
19e6b90e | 967 | { |
f07c08e1 AM |
968 | abbrev_list *list = xmalloc (sizeof (*list)); |
969 | list->first_abbrev = NULL; | |
970 | list->last_abbrev = NULL; | |
695c6dfe | 971 | list->raw = start; |
31991eaa | 972 | list->next = NULL; |
f2f9554b | 973 | |
19e6b90e L |
974 | while (start < end) |
975 | { | |
19e6b90e L |
976 | unsigned long entry; |
977 | unsigned long tag; | |
978 | unsigned long attribute; | |
979 | int children; | |
980 | ||
cd30bcef | 981 | READ_ULEB (entry, start, end); |
19e6b90e | 982 | |
bcd213b2 | 983 | /* A single zero is supposed to end the set according |
19e6b90e L |
984 | to the standard. If there's more, then signal that to |
985 | the caller. */ | |
f07c08e1 AM |
986 | if (start == end || entry == 0) |
987 | { | |
988 | list->start_of_next_abbrevs = start != end ? start : NULL; | |
989 | return list; | |
990 | } | |
19e6b90e | 991 | |
cd30bcef | 992 | READ_ULEB (tag, start, end); |
f6f0e17b | 993 | if (start == end) |
31991eaa | 994 | return free_abbrev_list (list); |
19e6b90e L |
995 | |
996 | children = *start++; | |
997 | ||
bcd213b2 | 998 | add_abbrev (entry, tag, children, list); |
19e6b90e L |
999 | |
1000 | do | |
1001 | { | |
1002 | unsigned long form; | |
77145576 | 1003 | /* Initialize it due to a false compiler warning. */ |
31e5a3a3 | 1004 | int64_t implicit_const = -1; |
19e6b90e | 1005 | |
cd30bcef | 1006 | READ_ULEB (attribute, start, end); |
f6f0e17b NC |
1007 | if (start == end) |
1008 | break; | |
19e6b90e | 1009 | |
cd30bcef | 1010 | READ_ULEB (form, start, end); |
f6f0e17b NC |
1011 | if (start == end) |
1012 | break; | |
19e6b90e | 1013 | |
77145576 JK |
1014 | if (form == DW_FORM_implicit_const) |
1015 | { | |
cd30bcef | 1016 | READ_SLEB (implicit_const, start, end); |
77145576 JK |
1017 | if (start == end) |
1018 | break; | |
1019 | } | |
1020 | ||
bcd213b2 | 1021 | add_abbrev_attr (attribute, form, implicit_const, list); |
19e6b90e L |
1022 | } |
1023 | while (attribute != 0); | |
1024 | } | |
1025 | ||
399c99f7 | 1026 | /* Report the missing single zero which ends the section. */ |
175b9150 | 1027 | error (_("%s section not zero terminated\n"), section->name); |
399c99f7 | 1028 | |
31991eaa | 1029 | return free_abbrev_list (list); |
19e6b90e L |
1030 | } |
1031 | ||
f07c08e1 AM |
1032 | /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE |
1033 | plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE. | |
1034 | If FREE_LIST is non-NULL search the already decoded abbrevs on | |
1035 | abbrev_lists first and if found set *FREE_LIST to NULL. If | |
1036 | searching doesn't find a matching abbrev, set *FREE_LIST to the | |
1037 | newly allocated list. If FREE_LIST is NULL, no search is done and | |
1038 | the returned abbrev_list is always newly allocated. */ | |
1039 | ||
1040 | static abbrev_list * | |
1041 | find_and_process_abbrev_set (struct dwarf_section *section, | |
31e5a3a3 AM |
1042 | uint64_t abbrev_base, |
1043 | uint64_t abbrev_size, | |
1044 | uint64_t abbrev_offset, | |
f07c08e1 AM |
1045 | abbrev_list **free_list) |
1046 | { | |
1047 | if (free_list) | |
1048 | *free_list = NULL; | |
1049 | ||
1050 | if (abbrev_base >= section->size | |
1051 | || abbrev_size > section->size - abbrev_base) | |
1052 | { | |
1053 | /* PR 17531: file:4bcd9ce9. */ | |
31e5a3a3 AM |
1054 | warn (_("Debug info is corrupted, abbrev size (%#" PRIx64 ")" |
1055 | " is larger than abbrev section size (%#" PRIx64 ")\n"), | |
cb1861cb | 1056 | abbrev_base + abbrev_size, section->size); |
f07c08e1 AM |
1057 | return NULL; |
1058 | } | |
1059 | if (abbrev_offset >= abbrev_size) | |
1060 | { | |
31e5a3a3 AM |
1061 | warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64 ")" |
1062 | " is larger than abbrev section size (%#" PRIx64 ")\n"), | |
1063 | abbrev_offset, abbrev_size); | |
f07c08e1 AM |
1064 | return NULL; |
1065 | } | |
1066 | ||
1067 | unsigned char *start = section->start + abbrev_base + abbrev_offset; | |
1068 | unsigned char *end = section->start + abbrev_base + abbrev_size; | |
1069 | abbrev_list *list = NULL; | |
1070 | if (free_list) | |
695c6dfe | 1071 | list = find_abbrev_list_by_raw_abbrev (start); |
f07c08e1 AM |
1072 | if (list == NULL) |
1073 | { | |
1074 | list = process_abbrev_set (section, start, end); | |
f07c08e1 AM |
1075 | if (free_list) |
1076 | *free_list = list; | |
1077 | } | |
1078 | return list; | |
1079 | } | |
1080 | ||
a19c41a7 | 1081 | static const char * |
31e5a3a3 | 1082 | get_TAG_name (uint64_t tag) |
19e6b90e | 1083 | { |
31e5a3a3 | 1084 | const char *name = NULL; |
a19c41a7 | 1085 | |
31e5a3a3 AM |
1086 | if ((unsigned int) tag == tag) |
1087 | name = get_DW_TAG_name ((unsigned int) tag); | |
a19c41a7 | 1088 | if (name == NULL) |
19e6b90e | 1089 | { |
a19c41a7 | 1090 | static char buffer[100]; |
19e6b90e | 1091 | |
04914e37 | 1092 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
31e5a3a3 AM |
1093 | snprintf (buffer, sizeof (buffer), |
1094 | _("User TAG value: %#" PRIx64), tag); | |
04914e37 | 1095 | else |
31e5a3a3 AM |
1096 | snprintf (buffer, sizeof (buffer), |
1097 | _("Unknown TAG value: %#" PRIx64), tag); | |
a19c41a7 | 1098 | return buffer; |
19e6b90e | 1099 | } |
a19c41a7 TT |
1100 | |
1101 | return name; | |
19e6b90e L |
1102 | } |
1103 | ||
a19c41a7 | 1104 | static const char * |
19e6b90e L |
1105 | get_FORM_name (unsigned long form) |
1106 | { | |
31e5a3a3 | 1107 | const char *name = NULL; |
bf5117e3 | 1108 | |
399c99f7 L |
1109 | if (form == 0) |
1110 | return "DW_FORM value: 0"; | |
a19c41a7 | 1111 | |
31e5a3a3 AM |
1112 | if ((unsigned int) form == form) |
1113 | name = get_DW_FORM_name ((unsigned int) form); | |
a19c41a7 | 1114 | if (name == NULL) |
19e6b90e | 1115 | { |
a19c41a7 | 1116 | static char buffer[100]; |
19e6b90e | 1117 | |
a19c41a7 TT |
1118 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1119 | return buffer; | |
19e6b90e | 1120 | } |
a19c41a7 TT |
1121 | |
1122 | return name; | |
19e6b90e L |
1123 | } |
1124 | ||
61364358 JK |
1125 | static const char * |
1126 | get_IDX_name (unsigned long idx) | |
1127 | { | |
31e5a3a3 | 1128 | const char *name = NULL; |
61364358 | 1129 | |
31e5a3a3 AM |
1130 | if ((unsigned int) idx == idx) |
1131 | name = get_DW_IDX_name ((unsigned int) idx); | |
61364358 JK |
1132 | if (name == NULL) |
1133 | { | |
1134 | static char buffer[100]; | |
1135 | ||
1136 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1137 | return buffer; | |
1138 | } | |
1139 | ||
1140 | return name; | |
1141 | } | |
1142 | ||
19e6b90e | 1143 | static unsigned char * |
0c588247 | 1144 | display_block (unsigned char *data, |
31e5a3a3 | 1145 | uint64_t length, |
ef0b5f1c | 1146 | const unsigned char * const end, char delimiter) |
19e6b90e | 1147 | { |
31e5a3a3 | 1148 | size_t maxlen; |
0c588247 | 1149 | |
31e5a3a3 | 1150 | printf (_("%c%" PRIu64 " byte block: "), delimiter, length); |
a1165289 NC |
1151 | if (data > end) |
1152 | return (unsigned char *) end; | |
19e6b90e | 1153 | |
31e5a3a3 | 1154 | maxlen = end - data; |
0c588247 NC |
1155 | length = length > maxlen ? maxlen : length; |
1156 | ||
19e6b90e | 1157 | while (length --) |
31e5a3a3 | 1158 | printf ("%" PRIx64 " ", byte_get (data++, 1)); |
19e6b90e L |
1159 | |
1160 | return data; | |
1161 | } | |
1162 | ||
1163 | static int | |
1164 | decode_location_expression (unsigned char * data, | |
1165 | unsigned int pointer_size, | |
b7807392 JJ |
1166 | unsigned int offset_size, |
1167 | int dwarf_version, | |
31e5a3a3 AM |
1168 | uint64_t length, |
1169 | uint64_t cu_offset, | |
f1c4cc75 | 1170 | struct dwarf_section * section) |
19e6b90e L |
1171 | { |
1172 | unsigned op; | |
31e5a3a3 AM |
1173 | uint64_t uvalue; |
1174 | int64_t svalue; | |
19e6b90e L |
1175 | unsigned char *end = data + length; |
1176 | int need_frame_base = 0; | |
1177 | ||
1178 | while (data < end) | |
1179 | { | |
1180 | op = *data++; | |
1181 | ||
1182 | switch (op) | |
1183 | { | |
1184 | case DW_OP_addr: | |
0c588247 | 1185 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
31e5a3a3 | 1186 | printf ("DW_OP_addr: %" PRIx64, uvalue); |
19e6b90e L |
1187 | break; |
1188 | case DW_OP_deref: | |
1189 | printf ("DW_OP_deref"); | |
1190 | break; | |
1191 | case DW_OP_const1u: | |
0c588247 | 1192 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
31e5a3a3 | 1193 | printf ("DW_OP_const1u: %" PRIu64, uvalue); |
19e6b90e L |
1194 | break; |
1195 | case DW_OP_const1s: | |
0c588247 | 1196 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
31e5a3a3 | 1197 | printf ("DW_OP_const1s: %" PRId64, svalue); |
19e6b90e L |
1198 | break; |
1199 | case DW_OP_const2u: | |
87bc83b3 | 1200 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
31e5a3a3 | 1201 | printf ("DW_OP_const2u: %" PRIu64, uvalue); |
19e6b90e L |
1202 | break; |
1203 | case DW_OP_const2s: | |
0c588247 | 1204 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
31e5a3a3 | 1205 | printf ("DW_OP_const2s: %" PRId64, svalue); |
19e6b90e L |
1206 | break; |
1207 | case DW_OP_const4u: | |
0c588247 | 1208 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
31e5a3a3 | 1209 | printf ("DW_OP_const4u: %" PRIu64, uvalue); |
19e6b90e L |
1210 | break; |
1211 | case DW_OP_const4s: | |
0c588247 | 1212 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
31e5a3a3 | 1213 | printf ("DW_OP_const4s: %" PRId64, svalue); |
19e6b90e L |
1214 | break; |
1215 | case DW_OP_const8u: | |
31e5a3a3 AM |
1216 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
1217 | printf ("DW_OP_const8u: %" PRIu64, uvalue); | |
19e6b90e L |
1218 | break; |
1219 | case DW_OP_const8s: | |
31e5a3a3 AM |
1220 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 8, end); |
1221 | printf ("DW_OP_const8s: %" PRId64, svalue); | |
19e6b90e L |
1222 | break; |
1223 | case DW_OP_constu: | |
cd30bcef | 1224 | READ_ULEB (uvalue, data, end); |
31e5a3a3 | 1225 | printf ("DW_OP_constu: %" PRIu64, uvalue); |
19e6b90e L |
1226 | break; |
1227 | case DW_OP_consts: | |
cd30bcef | 1228 | READ_SLEB (svalue, data, end); |
31e5a3a3 | 1229 | printf ("DW_OP_consts: %" PRId64, svalue); |
19e6b90e L |
1230 | break; |
1231 | case DW_OP_dup: | |
1232 | printf ("DW_OP_dup"); | |
1233 | break; | |
1234 | case DW_OP_drop: | |
1235 | printf ("DW_OP_drop"); | |
1236 | break; | |
1237 | case DW_OP_over: | |
1238 | printf ("DW_OP_over"); | |
1239 | break; | |
1240 | case DW_OP_pick: | |
0c588247 | 1241 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
31e5a3a3 | 1242 | printf ("DW_OP_pick: %" PRIu64, uvalue); |
19e6b90e L |
1243 | break; |
1244 | case DW_OP_swap: | |
1245 | printf ("DW_OP_swap"); | |
1246 | break; | |
1247 | case DW_OP_rot: | |
1248 | printf ("DW_OP_rot"); | |
1249 | break; | |
1250 | case DW_OP_xderef: | |
1251 | printf ("DW_OP_xderef"); | |
1252 | break; | |
1253 | case DW_OP_abs: | |
1254 | printf ("DW_OP_abs"); | |
1255 | break; | |
1256 | case DW_OP_and: | |
1257 | printf ("DW_OP_and"); | |
1258 | break; | |
1259 | case DW_OP_div: | |
1260 | printf ("DW_OP_div"); | |
1261 | break; | |
1262 | case DW_OP_minus: | |
1263 | printf ("DW_OP_minus"); | |
1264 | break; | |
1265 | case DW_OP_mod: | |
1266 | printf ("DW_OP_mod"); | |
1267 | break; | |
1268 | case DW_OP_mul: | |
1269 | printf ("DW_OP_mul"); | |
1270 | break; | |
1271 | case DW_OP_neg: | |
1272 | printf ("DW_OP_neg"); | |
1273 | break; | |
1274 | case DW_OP_not: | |
1275 | printf ("DW_OP_not"); | |
1276 | break; | |
1277 | case DW_OP_or: | |
1278 | printf ("DW_OP_or"); | |
1279 | break; | |
1280 | case DW_OP_plus: | |
1281 | printf ("DW_OP_plus"); | |
1282 | break; | |
1283 | case DW_OP_plus_uconst: | |
cd30bcef | 1284 | READ_ULEB (uvalue, data, end); |
31e5a3a3 | 1285 | printf ("DW_OP_plus_uconst: %" PRIu64, uvalue); |
19e6b90e L |
1286 | break; |
1287 | case DW_OP_shl: | |
1288 | printf ("DW_OP_shl"); | |
1289 | break; | |
1290 | case DW_OP_shr: | |
1291 | printf ("DW_OP_shr"); | |
1292 | break; | |
1293 | case DW_OP_shra: | |
1294 | printf ("DW_OP_shra"); | |
1295 | break; | |
1296 | case DW_OP_xor: | |
1297 | printf ("DW_OP_xor"); | |
1298 | break; | |
1299 | case DW_OP_bra: | |
0c588247 | 1300 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
31e5a3a3 | 1301 | printf ("DW_OP_bra: %" PRId64, svalue); |
19e6b90e L |
1302 | break; |
1303 | case DW_OP_eq: | |
1304 | printf ("DW_OP_eq"); | |
1305 | break; | |
1306 | case DW_OP_ge: | |
1307 | printf ("DW_OP_ge"); | |
1308 | break; | |
1309 | case DW_OP_gt: | |
1310 | printf ("DW_OP_gt"); | |
1311 | break; | |
1312 | case DW_OP_le: | |
1313 | printf ("DW_OP_le"); | |
1314 | break; | |
1315 | case DW_OP_lt: | |
1316 | printf ("DW_OP_lt"); | |
1317 | break; | |
1318 | case DW_OP_ne: | |
1319 | printf ("DW_OP_ne"); | |
1320 | break; | |
1321 | case DW_OP_skip: | |
0c588247 | 1322 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
31e5a3a3 | 1323 | printf ("DW_OP_skip: %" PRId64, svalue); |
19e6b90e L |
1324 | break; |
1325 | ||
1326 | case DW_OP_lit0: | |
1327 | case DW_OP_lit1: | |
1328 | case DW_OP_lit2: | |
1329 | case DW_OP_lit3: | |
1330 | case DW_OP_lit4: | |
1331 | case DW_OP_lit5: | |
1332 | case DW_OP_lit6: | |
1333 | case DW_OP_lit7: | |
1334 | case DW_OP_lit8: | |
1335 | case DW_OP_lit9: | |
1336 | case DW_OP_lit10: | |
1337 | case DW_OP_lit11: | |
1338 | case DW_OP_lit12: | |
1339 | case DW_OP_lit13: | |
1340 | case DW_OP_lit14: | |
1341 | case DW_OP_lit15: | |
1342 | case DW_OP_lit16: | |
1343 | case DW_OP_lit17: | |
1344 | case DW_OP_lit18: | |
1345 | case DW_OP_lit19: | |
1346 | case DW_OP_lit20: | |
1347 | case DW_OP_lit21: | |
1348 | case DW_OP_lit22: | |
1349 | case DW_OP_lit23: | |
1350 | case DW_OP_lit24: | |
1351 | case DW_OP_lit25: | |
1352 | case DW_OP_lit26: | |
1353 | case DW_OP_lit27: | |
1354 | case DW_OP_lit28: | |
1355 | case DW_OP_lit29: | |
1356 | case DW_OP_lit30: | |
1357 | case DW_OP_lit31: | |
1358 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1359 | break; | |
1360 | ||
1361 | case DW_OP_reg0: | |
1362 | case DW_OP_reg1: | |
1363 | case DW_OP_reg2: | |
1364 | case DW_OP_reg3: | |
1365 | case DW_OP_reg4: | |
1366 | case DW_OP_reg5: | |
1367 | case DW_OP_reg6: | |
1368 | case DW_OP_reg7: | |
1369 | case DW_OP_reg8: | |
1370 | case DW_OP_reg9: | |
1371 | case DW_OP_reg10: | |
1372 | case DW_OP_reg11: | |
1373 | case DW_OP_reg12: | |
1374 | case DW_OP_reg13: | |
1375 | case DW_OP_reg14: | |
1376 | case DW_OP_reg15: | |
1377 | case DW_OP_reg16: | |
1378 | case DW_OP_reg17: | |
1379 | case DW_OP_reg18: | |
1380 | case DW_OP_reg19: | |
1381 | case DW_OP_reg20: | |
1382 | case DW_OP_reg21: | |
1383 | case DW_OP_reg22: | |
1384 | case DW_OP_reg23: | |
1385 | case DW_OP_reg24: | |
1386 | case DW_OP_reg25: | |
1387 | case DW_OP_reg26: | |
1388 | case DW_OP_reg27: | |
1389 | case DW_OP_reg28: | |
1390 | case DW_OP_reg29: | |
1391 | case DW_OP_reg30: | |
1392 | case DW_OP_reg31: | |
18464d4d JK |
1393 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1394 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1395 | break; |
1396 | ||
1397 | case DW_OP_breg0: | |
1398 | case DW_OP_breg1: | |
1399 | case DW_OP_breg2: | |
1400 | case DW_OP_breg3: | |
1401 | case DW_OP_breg4: | |
1402 | case DW_OP_breg5: | |
1403 | case DW_OP_breg6: | |
1404 | case DW_OP_breg7: | |
1405 | case DW_OP_breg8: | |
1406 | case DW_OP_breg9: | |
1407 | case DW_OP_breg10: | |
1408 | case DW_OP_breg11: | |
1409 | case DW_OP_breg12: | |
1410 | case DW_OP_breg13: | |
1411 | case DW_OP_breg14: | |
1412 | case DW_OP_breg15: | |
1413 | case DW_OP_breg16: | |
1414 | case DW_OP_breg17: | |
1415 | case DW_OP_breg18: | |
1416 | case DW_OP_breg19: | |
1417 | case DW_OP_breg20: | |
1418 | case DW_OP_breg21: | |
1419 | case DW_OP_breg22: | |
1420 | case DW_OP_breg23: | |
1421 | case DW_OP_breg24: | |
1422 | case DW_OP_breg25: | |
1423 | case DW_OP_breg26: | |
1424 | case DW_OP_breg27: | |
1425 | case DW_OP_breg28: | |
1426 | case DW_OP_breg29: | |
1427 | case DW_OP_breg30: | |
1428 | case DW_OP_breg31: | |
cd30bcef | 1429 | READ_SLEB (svalue, data, end); |
31e5a3a3 AM |
1430 | printf ("DW_OP_breg%d (%s): %" PRId64, |
1431 | op - DW_OP_breg0, regname (op - DW_OP_breg0, 1), svalue); | |
19e6b90e L |
1432 | break; |
1433 | ||
1434 | case DW_OP_regx: | |
cd30bcef | 1435 | READ_ULEB (uvalue, data, end); |
31e5a3a3 AM |
1436 | printf ("DW_OP_regx: %" PRIu64 " (%s)", |
1437 | uvalue, regname (uvalue, 1)); | |
19e6b90e L |
1438 | break; |
1439 | case DW_OP_fbreg: | |
1440 | need_frame_base = 1; | |
cd30bcef | 1441 | READ_SLEB (svalue, data, end); |
31e5a3a3 | 1442 | printf ("DW_OP_fbreg: %" PRId64, svalue); |
19e6b90e L |
1443 | break; |
1444 | case DW_OP_bregx: | |
cd30bcef AM |
1445 | READ_ULEB (uvalue, data, end); |
1446 | READ_SLEB (svalue, data, end); | |
31e5a3a3 AM |
1447 | printf ("DW_OP_bregx: %" PRIu64 " (%s) %" PRId64, |
1448 | uvalue, regname (uvalue, 1), svalue); | |
19e6b90e L |
1449 | break; |
1450 | case DW_OP_piece: | |
cd30bcef | 1451 | READ_ULEB (uvalue, data, end); |
31e5a3a3 | 1452 | printf ("DW_OP_piece: %" PRIu64, uvalue); |
19e6b90e L |
1453 | break; |
1454 | case DW_OP_deref_size: | |
0c588247 | 1455 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
31e5a3a3 | 1456 | printf ("DW_OP_deref_size: %" PRIu64, uvalue); |
19e6b90e L |
1457 | break; |
1458 | case DW_OP_xderef_size: | |
0c588247 | 1459 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
31e5a3a3 | 1460 | printf ("DW_OP_xderef_size: %" PRIu64, uvalue); |
19e6b90e L |
1461 | break; |
1462 | case DW_OP_nop: | |
1463 | printf ("DW_OP_nop"); | |
1464 | break; | |
1465 | ||
1466 | /* DWARF 3 extensions. */ | |
1467 | case DW_OP_push_object_address: | |
1468 | printf ("DW_OP_push_object_address"); | |
1469 | break; | |
1470 | case DW_OP_call2: | |
d85bf2ba | 1471 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1472 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1473 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
cc443420 | 1474 | printf ("DW_OP_call2: <%#" PRIx64 ">", svalue + cu_offset); |
19e6b90e L |
1475 | break; |
1476 | case DW_OP_call4: | |
d85bf2ba | 1477 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1478 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1479 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
cc443420 | 1480 | printf ("DW_OP_call4: <%#" PRIx64 ">", svalue + cu_offset); |
19e6b90e L |
1481 | break; |
1482 | case DW_OP_call_ref: | |
d85bf2ba | 1483 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1484 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1485 | if (dwarf_version == -1) |
1486 | { | |
1487 | printf (_("(DW_OP_call_ref in frame info)")); | |
1488 | /* No way to tell where the next op is, so just bail. */ | |
1489 | return need_frame_base; | |
1490 | } | |
1491 | if (dwarf_version == 2) | |
1492 | { | |
0c588247 | 1493 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1494 | } |
1495 | else | |
1496 | { | |
0c588247 | 1497 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1498 | } |
cc443420 | 1499 | printf ("DW_OP_call_ref: <%#" PRIx64 ">", uvalue); |
19e6b90e | 1500 | break; |
a87b0a59 NS |
1501 | case DW_OP_form_tls_address: |
1502 | printf ("DW_OP_form_tls_address"); | |
1503 | break; | |
e2a0d921 NC |
1504 | case DW_OP_call_frame_cfa: |
1505 | printf ("DW_OP_call_frame_cfa"); | |
1506 | break; | |
1507 | case DW_OP_bit_piece: | |
1508 | printf ("DW_OP_bit_piece: "); | |
cd30bcef | 1509 | READ_ULEB (uvalue, data, end); |
31e5a3a3 | 1510 | printf (_("size: %" PRIu64 " "), uvalue); |
cd30bcef | 1511 | READ_ULEB (uvalue, data, end); |
31e5a3a3 | 1512 | printf (_("offset: %" PRIu64 " "), uvalue); |
e2a0d921 | 1513 | break; |
19e6b90e | 1514 | |
3244e8f5 JJ |
1515 | /* DWARF 4 extensions. */ |
1516 | case DW_OP_stack_value: | |
1517 | printf ("DW_OP_stack_value"); | |
1518 | break; | |
1519 | ||
1520 | case DW_OP_implicit_value: | |
1521 | printf ("DW_OP_implicit_value"); | |
cd30bcef | 1522 | READ_ULEB (uvalue, data, end); |
ef0b5f1c | 1523 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1524 | break; |
1525 | ||
19e6b90e L |
1526 | /* GNU extensions. */ |
1527 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1528 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1529 | break; |
1530 | case DW_OP_GNU_uninit: | |
1531 | printf ("DW_OP_GNU_uninit"); | |
1532 | /* FIXME: Is there data associated with this OP ? */ | |
1533 | break; | |
f1c4cc75 RH |
1534 | case DW_OP_GNU_encoded_addr: |
1535 | { | |
6937bb54 | 1536 | int encoding = 0; |
31e5a3a3 | 1537 | uint64_t addr; |
467c65bc | 1538 | |
6937bb54 NC |
1539 | if (data < end) |
1540 | encoding = *data++; | |
041830e0 | 1541 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1542 | |
1543 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
cc443420 | 1544 | print_hex_ns (addr, pointer_size); |
f1c4cc75 RH |
1545 | } |
1546 | break; | |
bc0a77d2 | 1547 | case DW_OP_implicit_pointer: |
b7807392 | 1548 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1549 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1550 | this ought to be an 8-byte wide computation. */ |
1551 | if (dwarf_version == -1) | |
1552 | { | |
bc0a77d2 JK |
1553 | printf (_("(%s in frame info)"), |
1554 | (op == DW_OP_implicit_pointer | |
1555 | ? "DW_OP_implicit_pointer" | |
1556 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1557 | /* No way to tell where the next op is, so just bail. */ |
1558 | return need_frame_base; | |
1559 | } | |
1560 | if (dwarf_version == 2) | |
1561 | { | |
0c588247 | 1562 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1563 | } |
1564 | else | |
1565 | { | |
0c588247 | 1566 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1567 | } |
cd30bcef | 1568 | READ_SLEB (svalue, data, end); |
cc443420 | 1569 | printf ("%s: <%#" PRIx64 "> %" PRId64, |
bc0a77d2 JK |
1570 | (op == DW_OP_implicit_pointer |
1571 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
31e5a3a3 | 1572 | uvalue, svalue); |
b7807392 | 1573 | break; |
77145576 | 1574 | case DW_OP_entry_value: |
0892011d | 1575 | case DW_OP_GNU_entry_value: |
cd30bcef | 1576 | READ_ULEB (uvalue, data, end); |
058037d3 | 1577 | /* PR 17531: file: 0cc9cd00. */ |
31e5a3a3 | 1578 | if (uvalue > (size_t) (end - data)) |
058037d3 | 1579 | uvalue = end - data; |
cb1861cb AM |
1580 | printf ("%s: (", (op == DW_OP_entry_value |
1581 | ? "DW_OP_entry_value" : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1582 | if (decode_location_expression (data, pointer_size, offset_size, |
1583 | dwarf_version, uvalue, | |
1584 | cu_offset, section)) | |
1585 | need_frame_base = 1; | |
1586 | putchar (')'); | |
1587 | data += uvalue; | |
1588 | break; | |
bc0a77d2 | 1589 | case DW_OP_const_type: |
0892011d | 1590 | case DW_OP_GNU_const_type: |
cd30bcef | 1591 | READ_ULEB (uvalue, data, end); |
cc443420 | 1592 | printf ("%s: <%#" PRIx64 "> ", |
cb1861cb AM |
1593 | (op == DW_OP_const_type |
1594 | ? "DW_OP_const_type" : "DW_OP_GNU_const_type"), | |
31e5a3a3 | 1595 | cu_offset + uvalue); |
0c588247 | 1596 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1597 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1598 | break; |
bc0a77d2 | 1599 | case DW_OP_regval_type: |
0892011d | 1600 | case DW_OP_GNU_regval_type: |
cd30bcef | 1601 | READ_ULEB (uvalue, data, end); |
31e5a3a3 | 1602 | printf ("%s: %" PRIu64 " (%s)", |
cb1861cb AM |
1603 | (op == DW_OP_regval_type |
1604 | ? "DW_OP_regval_type" : "DW_OP_GNU_regval_type"), | |
31e5a3a3 | 1605 | uvalue, regname (uvalue, 1)); |
cd30bcef | 1606 | READ_ULEB (uvalue, data, end); |
cc443420 | 1607 | printf (" <%#" PRIx64 ">", cu_offset + uvalue); |
0892011d | 1608 | break; |
bc0a77d2 | 1609 | case DW_OP_deref_type: |
0892011d | 1610 | case DW_OP_GNU_deref_type: |
0c588247 | 1611 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
31e5a3a3 | 1612 | printf ("%s: %" PRId64, |
cb1861cb AM |
1613 | (op == DW_OP_deref_type |
1614 | ? "DW_OP_deref_type" : "DW_OP_GNU_deref_type"), | |
31e5a3a3 | 1615 | uvalue); |
cd30bcef | 1616 | READ_ULEB (uvalue, data, end); |
cc443420 | 1617 | printf (" <%#" PRIx64 ">", cu_offset + uvalue); |
0892011d | 1618 | break; |
bc0a77d2 | 1619 | case DW_OP_convert: |
0892011d | 1620 | case DW_OP_GNU_convert: |
cd30bcef | 1621 | READ_ULEB (uvalue, data, end); |
cc443420 | 1622 | printf ("%s <%#" PRIx64 ">", |
bc0a77d2 | 1623 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), |
31e5a3a3 | 1624 | uvalue ? cu_offset + uvalue : uvalue); |
0892011d | 1625 | break; |
bc0a77d2 | 1626 | case DW_OP_reinterpret: |
0892011d | 1627 | case DW_OP_GNU_reinterpret: |
cd30bcef | 1628 | READ_ULEB (uvalue, data, end); |
cc443420 | 1629 | printf ("%s <%#" PRIx64 ">", |
cb1861cb AM |
1630 | (op == DW_OP_reinterpret |
1631 | ? "DW_OP_reinterpret" : "DW_OP_GNU_reinterpret"), | |
31e5a3a3 | 1632 | uvalue ? cu_offset + uvalue : uvalue); |
f8b999f9 JJ |
1633 | break; |
1634 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1635 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
cc443420 | 1636 | printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64 ">", |
31e5a3a3 | 1637 | cu_offset + uvalue); |
0892011d | 1638 | break; |
3ac9da49 NK |
1639 | case DW_OP_addrx: |
1640 | READ_ULEB (uvalue, data, end); | |
cc443420 | 1641 | printf ("DW_OP_addrx <%#" PRIx64 ">", uvalue); |
3ac9da49 | 1642 | break; |
b4eb7656 | 1643 | case DW_OP_GNU_addr_index: |
cd30bcef | 1644 | READ_ULEB (uvalue, data, end); |
cc443420 | 1645 | printf ("DW_OP_GNU_addr_index <%#" PRIx64 ">", uvalue); |
b4eb7656 AM |
1646 | break; |
1647 | case DW_OP_GNU_const_index: | |
cd30bcef | 1648 | READ_ULEB (uvalue, data, end); |
cc443420 | 1649 | printf ("DW_OP_GNU_const_index <%#" PRIx64 ">", uvalue); |
b4eb7656 | 1650 | break; |
f384a1f0 KB |
1651 | case DW_OP_GNU_variable_value: |
1652 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1653 | this ought to be an 8-byte wide computation. */ | |
1654 | if (dwarf_version == -1) | |
1655 | { | |
1656 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1657 | /* No way to tell where the next op is, so just bail. */ | |
1658 | return need_frame_base; | |
1659 | } | |
1660 | if (dwarf_version == 2) | |
1661 | { | |
1662 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1663 | } | |
1664 | else | |
1665 | { | |
1666 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1667 | } | |
cc443420 | 1668 | printf ("DW_OP_GNU_variable_value: <%#" PRIx64 ">", uvalue); |
f384a1f0 | 1669 | break; |
e2a0d921 NC |
1670 | |
1671 | /* HP extensions. */ | |
1672 | case DW_OP_HP_is_value: | |
1673 | printf ("DW_OP_HP_is_value"); | |
1674 | /* FIXME: Is there data associated with this OP ? */ | |
1675 | break; | |
1676 | case DW_OP_HP_fltconst4: | |
1677 | printf ("DW_OP_HP_fltconst4"); | |
1678 | /* FIXME: Is there data associated with this OP ? */ | |
1679 | break; | |
1680 | case DW_OP_HP_fltconst8: | |
1681 | printf ("DW_OP_HP_fltconst8"); | |
1682 | /* FIXME: Is there data associated with this OP ? */ | |
1683 | break; | |
1684 | case DW_OP_HP_mod_range: | |
1685 | printf ("DW_OP_HP_mod_range"); | |
1686 | /* FIXME: Is there data associated with this OP ? */ | |
1687 | break; | |
1688 | case DW_OP_HP_unmod_range: | |
1689 | printf ("DW_OP_HP_unmod_range"); | |
1690 | /* FIXME: Is there data associated with this OP ? */ | |
1691 | break; | |
1692 | case DW_OP_HP_tls: | |
1693 | printf ("DW_OP_HP_tls"); | |
1694 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1695 | break; |
1696 | ||
35d60fe4 NC |
1697 | /* PGI (STMicroelectronics) extensions. */ |
1698 | case DW_OP_PGI_omp_thread_num: | |
1699 | /* Pushes the thread number for the current thread as it would be | |
1700 | returned by the standard OpenMP library function: | |
1701 | omp_get_thread_num(). The "current thread" is the thread for | |
1702 | which the expression is being evaluated. */ | |
1703 | printf ("DW_OP_PGI_omp_thread_num"); | |
1704 | break; | |
1705 | ||
19e6b90e L |
1706 | default: |
1707 | if (op >= DW_OP_lo_user | |
1708 | && op <= DW_OP_hi_user) | |
cc443420 | 1709 | printf (_("(User defined location op %#x)"), op); |
19e6b90e | 1710 | else |
cc443420 | 1711 | printf (_("(Unknown location op %#x)"), op); |
19e6b90e L |
1712 | /* No way to tell where the next op is, so just bail. */ |
1713 | return need_frame_base; | |
1714 | } | |
1715 | ||
1716 | /* Separate the ops. */ | |
1717 | if (data < end) | |
1718 | printf ("; "); | |
1719 | } | |
1720 | ||
1721 | return need_frame_base; | |
1722 | } | |
1723 | ||
341f9135 CC |
1724 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1725 | This is used for DWARF package files. */ | |
1726 | ||
1727 | static struct cu_tu_set * | |
31e5a3a3 | 1728 | find_cu_tu_set_v2 (uint64_t cu_offset, int do_types) |
341f9135 CC |
1729 | { |
1730 | struct cu_tu_set *p; | |
1731 | unsigned int nsets; | |
1732 | unsigned int dw_sect; | |
1733 | ||
1734 | if (do_types) | |
1735 | { | |
1736 | p = tu_sets; | |
1737 | nsets = tu_count; | |
1738 | dw_sect = DW_SECT_TYPES; | |
1739 | } | |
1740 | else | |
1741 | { | |
1742 | p = cu_sets; | |
1743 | nsets = cu_count; | |
1744 | dw_sect = DW_SECT_INFO; | |
1745 | } | |
1746 | while (nsets > 0) | |
1747 | { | |
1748 | if (p->section_offsets [dw_sect] == cu_offset) | |
1749 | return p; | |
1750 | p++; | |
1751 | nsets--; | |
1752 | } | |
1753 | return NULL; | |
1754 | } | |
1755 | ||
dda8d76d | 1756 | static const char * |
31e5a3a3 | 1757 | fetch_alt_indirect_string (uint64_t offset) |
dda8d76d | 1758 | { |
24841daa | 1759 | separate_info * i; |
dda8d76d NC |
1760 | |
1761 | if (! do_follow_links) | |
1762 | return ""; | |
1763 | ||
24841daa NC |
1764 | if (first_separate_info == NULL) |
1765 | return _("<no links available>"); | |
dda8d76d | 1766 | |
24841daa NC |
1767 | for (i = first_separate_info; i != NULL; i = i->next) |
1768 | { | |
1769 | struct dwarf_section * section; | |
1770 | const char * ret; | |
dda8d76d | 1771 | |
24841daa NC |
1772 | if (! load_debug_section (separate_debug_str, i->handle)) |
1773 | continue; | |
dda8d76d | 1774 | |
24841daa | 1775 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1776 | |
24841daa NC |
1777 | if (section->start == NULL) |
1778 | continue; | |
dda8d76d | 1779 | |
24841daa NC |
1780 | if (offset >= section->size) |
1781 | continue; | |
1782 | ||
1783 | ret = (const char *) (section->start + offset); | |
1784 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1785 | NUL byte. Since our caller is expecting to receive a well formed C | |
1786 | string we test for the lack of a terminating byte here. */ | |
1787 | if (strnlen ((const char *) ret, section->size - offset) | |
1788 | == section->size - offset) | |
1789 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1790 | ||
1791 | return ret; | |
1792 | } | |
521d4b19 | 1793 | |
31e5a3a3 AM |
1794 | warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64 ")" |
1795 | " too big or no string sections available\n"), offset); | |
24841daa | 1796 | return _("<offset is too big>"); |
dda8d76d | 1797 | } |
175b9150 | 1798 | |
d85bf2ba NC |
1799 | static const char * |
1800 | get_AT_name (unsigned long attribute) | |
1801 | { | |
1802 | const char *name; | |
1803 | ||
1804 | if (attribute == 0) | |
1805 | return "DW_AT value: 0"; | |
1806 | ||
1807 | /* One value is shared by the MIPS and HP extensions: */ | |
1808 | if (attribute == DW_AT_MIPS_fde) | |
1809 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1810 | ||
1811 | name = get_DW_AT_name (attribute); | |
1812 | ||
1813 | if (name == NULL) | |
1814 | { | |
1815 | static char buffer[100]; | |
1816 | ||
1817 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1818 | attribute); | |
1819 | return buffer; | |
1820 | } | |
1821 | ||
1822 | return name; | |
1823 | } | |
1824 | ||
24841daa | 1825 | static void |
31e5a3a3 | 1826 | add_dwo_info (const char * value, uint64_t cu_offset, dwo_type type) |
24841daa NC |
1827 | { |
1828 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1829 | ||
50ea0877 NC |
1830 | dwinfo->type = type; |
1831 | dwinfo->value = value; | |
1832 | dwinfo->cu_offset = cu_offset; | |
1833 | dwinfo->next = first_dwo_info; | |
24841daa NC |
1834 | first_dwo_info = dwinfo; |
1835 | } | |
1836 | ||
1837 | static void | |
31e5a3a3 | 1838 | add_dwo_name (const char * name, uint64_t cu_offset) |
24841daa | 1839 | { |
50ea0877 | 1840 | add_dwo_info (name, cu_offset, DWO_NAME); |
24841daa NC |
1841 | } |
1842 | ||
1843 | static void | |
31e5a3a3 | 1844 | add_dwo_dir (const char * dir, uint64_t cu_offset) |
24841daa | 1845 | { |
50ea0877 | 1846 | add_dwo_info (dir, cu_offset, DWO_DIR); |
24841daa NC |
1847 | } |
1848 | ||
1849 | static void | |
31e5a3a3 | 1850 | add_dwo_id (const char * id, uint64_t cu_offset) |
24841daa | 1851 | { |
50ea0877 | 1852 | add_dwo_info (id, cu_offset, DWO_ID); |
24841daa NC |
1853 | } |
1854 | ||
1855 | static void | |
1856 | free_dwo_info (void) | |
1857 | { | |
1858 | dwo_info * dwinfo; | |
1859 | dwo_info * next; | |
1860 | ||
1861 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1862 | { | |
1863 | next = dwinfo->next; | |
1864 | free (dwinfo); | |
1865 | } | |
1866 | first_dwo_info = NULL; | |
1867 | } | |
1868 | ||
afc72f15 NC |
1869 | /* Ensure that START + UVALUE is less than END. |
1870 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1871 | ||
31e5a3a3 AM |
1872 | static inline uint64_t |
1873 | check_uvalue (const unsigned char *start, | |
1874 | uint64_t uvalue, | |
1875 | const unsigned char *end) | |
afc72f15 | 1876 | { |
31e5a3a3 | 1877 | uint64_t max_uvalue = end - start; |
afc72f15 | 1878 | |
afc72f15 NC |
1879 | /* See PR 17512: file: 008-103549-0.001:0.1. |
1880 | and PR 24829 for examples of where these tests are triggered. */ | |
a85eba51 | 1881 | if (uvalue > max_uvalue) |
afc72f15 | 1882 | { |
31e5a3a3 | 1883 | warn (_("Corrupt attribute block length: %#" PRIx64 "\n"), uvalue); |
afc72f15 NC |
1884 | uvalue = max_uvalue; |
1885 | } | |
1886 | ||
1887 | return uvalue; | |
1888 | } | |
1889 | ||
ec1b0fbb | 1890 | static unsigned char * |
a7077ce7 AM |
1891 | skip_attr_bytes (unsigned long form, |
1892 | unsigned char *data, | |
1893 | unsigned char *end, | |
31e5a3a3 AM |
1894 | uint64_t pointer_size, |
1895 | uint64_t offset_size, | |
a7077ce7 | 1896 | int dwarf_version, |
31e5a3a3 | 1897 | uint64_t *value_return) |
ec1b0fbb | 1898 | { |
31e5a3a3 AM |
1899 | int64_t svalue; |
1900 | uint64_t uvalue = 0; | |
1901 | uint64_t inc = 0; | |
ec1b0fbb NC |
1902 | |
1903 | * value_return = 0; | |
1904 | ||
1905 | switch (form) | |
1906 | { | |
1907 | case DW_FORM_ref_addr: | |
1908 | if (dwarf_version == 2) | |
1909 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
59624513 | 1910 | else if (dwarf_version > 2) |
ec1b0fbb NC |
1911 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1912 | else | |
1913 | return NULL; | |
1914 | break; | |
1915 | ||
1916 | case DW_FORM_addr: | |
1917 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1918 | break; | |
1919 | ||
1920 | case DW_FORM_strp: | |
1921 | case DW_FORM_line_strp: | |
1922 | case DW_FORM_sec_offset: | |
1923 | case DW_FORM_GNU_ref_alt: | |
1924 | case DW_FORM_GNU_strp_alt: | |
1925 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1926 | break; | |
1927 | ||
1928 | case DW_FORM_flag_present: | |
1929 | uvalue = 1; | |
1930 | break; | |
1931 | ||
1932 | case DW_FORM_ref1: | |
1933 | case DW_FORM_flag: | |
1934 | case DW_FORM_data1: | |
32e4f96c TV |
1935 | case DW_FORM_strx1: |
1936 | case DW_FORM_addrx1: | |
ec1b0fbb NC |
1937 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1938 | break; | |
1939 | ||
32e4f96c TV |
1940 | case DW_FORM_strx3: |
1941 | case DW_FORM_addrx3: | |
1942 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); | |
1943 | break; | |
1944 | ||
ec1b0fbb NC |
1945 | case DW_FORM_ref2: |
1946 | case DW_FORM_data2: | |
32e4f96c TV |
1947 | case DW_FORM_strx2: |
1948 | case DW_FORM_addrx2: | |
ec1b0fbb NC |
1949 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
1950 | break; | |
1951 | ||
1952 | case DW_FORM_ref4: | |
1953 | case DW_FORM_data4: | |
32e4f96c TV |
1954 | case DW_FORM_strx4: |
1955 | case DW_FORM_addrx4: | |
ec1b0fbb NC |
1956 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1957 | break; | |
1958 | ||
1959 | case DW_FORM_sdata: | |
cd30bcef AM |
1960 | READ_SLEB (svalue, data, end); |
1961 | uvalue = svalue; | |
ec1b0fbb NC |
1962 | break; |
1963 | ||
1964 | case DW_FORM_ref_udata: | |
1965 | case DW_FORM_udata: | |
1966 | case DW_FORM_GNU_str_index: | |
32e4f96c | 1967 | case DW_FORM_strx: |
ec1b0fbb | 1968 | case DW_FORM_GNU_addr_index: |
32e4f96c | 1969 | case DW_FORM_addrx: |
19c26da6 NC |
1970 | case DW_FORM_loclistx: |
1971 | case DW_FORM_rnglistx: | |
cd30bcef | 1972 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
1973 | break; |
1974 | ||
1975 | case DW_FORM_ref8: | |
af2ddf69 AM |
1976 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
1977 | break; | |
1f573141 | 1978 | |
ec1b0fbb | 1979 | case DW_FORM_data8: |
59624513 | 1980 | case DW_FORM_ref_sig8: |
a7077ce7 | 1981 | inc = 8; |
ec1b0fbb NC |
1982 | break; |
1983 | ||
1984 | case DW_FORM_data16: | |
a7077ce7 | 1985 | inc = 16; |
ec1b0fbb NC |
1986 | break; |
1987 | ||
1988 | case DW_FORM_string: | |
a7077ce7 | 1989 | inc = strnlen ((char *) data, end - data) + 1; |
ec1b0fbb NC |
1990 | break; |
1991 | ||
1992 | case DW_FORM_block: | |
1993 | case DW_FORM_exprloc: | |
cd30bcef | 1994 | READ_ULEB (uvalue, data, end); |
a7077ce7 | 1995 | inc = uvalue; |
ec1b0fbb NC |
1996 | break; |
1997 | ||
1998 | case DW_FORM_block1: | |
a7077ce7 AM |
1999 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2000 | inc = uvalue; | |
ec1b0fbb NC |
2001 | break; |
2002 | ||
2003 | case DW_FORM_block2: | |
a7077ce7 AM |
2004 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2005 | inc = uvalue; | |
ec1b0fbb NC |
2006 | break; |
2007 | ||
2008 | case DW_FORM_block4: | |
a7077ce7 AM |
2009 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2010 | inc = uvalue; | |
ec1b0fbb NC |
2011 | break; |
2012 | ||
ec1b0fbb | 2013 | case DW_FORM_indirect: |
59624513 NC |
2014 | READ_ULEB (form, data, end); |
2015 | if (form == DW_FORM_implicit_const) | |
2016 | SKIP_ULEB (data, end); | |
a7077ce7 AM |
2017 | return skip_attr_bytes (form, data, end, pointer_size, offset_size, |
2018 | dwarf_version, value_return); | |
59624513 | 2019 | |
ec1b0fbb NC |
2020 | default: |
2021 | return NULL; | |
2022 | } | |
2023 | ||
2024 | * value_return = uvalue; | |
31e5a3a3 | 2025 | if (inc <= (size_t) (end - data)) |
a7077ce7 AM |
2026 | data += inc; |
2027 | else | |
2028 | data = end; | |
ec1b0fbb NC |
2029 | return data; |
2030 | } | |
2031 | ||
bcd213b2 NC |
2032 | /* Given form FORM with value UVALUE, locate and return the abbreviation |
2033 | associated with it. */ | |
2034 | ||
2035 | static abbrev_entry * | |
1b3892be | 2036 | get_type_abbrev_from_form (unsigned long form, |
f2a15e7c | 2037 | uint64_t uvalue, |
31e5a3a3 | 2038 | uint64_t cu_offset, |
40e1d303 | 2039 | unsigned char *cu_end, |
1b3892be AM |
2040 | const struct dwarf_section *section, |
2041 | unsigned long *abbrev_num_return, | |
2042 | unsigned char **data_return, | |
2043 | abbrev_map **map_return) | |
bcd213b2 | 2044 | { |
bcd213b2 NC |
2045 | switch (form) |
2046 | { | |
2047 | case DW_FORM_GNU_ref_alt: | |
5f128a25 | 2048 | case DW_FORM_ref_sig8: |
bcd213b2 NC |
2049 | /* FIXME: We are unable to handle this form at the moment. */ |
2050 | return NULL; | |
2051 | ||
2052 | case DW_FORM_ref_addr: | |
2053 | if (uvalue >= section->size) | |
2054 | { | |
f2a15e7c AM |
2055 | warn (_("Unable to resolve ref_addr form: uvalue %" PRIx64 |
2056 | " >= section size %" PRIx64 " (%s)\n"), | |
31e5a3a3 | 2057 | uvalue, section->size, section->name); |
bcd213b2 NC |
2058 | return NULL; |
2059 | } | |
2060 | break; | |
2061 | ||
e38332c2 NC |
2062 | case DW_FORM_ref_sup4: |
2063 | case DW_FORM_ref_sup8: | |
2064 | break; | |
2065 | ||
bcd213b2 NC |
2066 | case DW_FORM_ref1: |
2067 | case DW_FORM_ref2: | |
2068 | case DW_FORM_ref4: | |
1f573141 | 2069 | case DW_FORM_ref8: |
bcd213b2 | 2070 | case DW_FORM_ref_udata: |
175b9150 AM |
2071 | if (uvalue + cu_offset < uvalue |
2072 | || uvalue + cu_offset > (size_t) (cu_end - section->start)) | |
bcd213b2 | 2073 | { |
f2a15e7c AM |
2074 | warn (_("Unable to resolve ref form: uvalue %" PRIx64 |
2075 | " + cu_offset %" PRIx64 " > CU size %tx\n"), | |
31e5a3a3 | 2076 | uvalue, cu_offset, cu_end - section->start); |
bcd213b2 NC |
2077 | return NULL; |
2078 | } | |
2079 | uvalue += cu_offset; | |
2080 | break; | |
2081 | ||
2082 | /* FIXME: Are there other DW_FORMs that can be used by types ? */ | |
2083 | ||
2084 | default: | |
2085 | warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form); | |
2086 | return NULL; | |
2087 | } | |
2088 | ||
f2a15e7c | 2089 | abbrev_map *map = find_abbrev_map_by_offset (uvalue); |
521d4b19 | 2090 | |
bcd213b2 NC |
2091 | if (map == NULL) |
2092 | { | |
f2a15e7c AM |
2093 | warn (_("Unable to find abbreviations for CU offset %" PRIx64 "\n"), |
2094 | uvalue); | |
bcd213b2 NC |
2095 | return NULL; |
2096 | } | |
2097 | if (map->list == NULL) | |
2098 | { | |
f2a15e7c AM |
2099 | warn (_("Empty abbreviation list encountered for CU offset %" PRIx64 "\n"), |
2100 | uvalue); | |
bcd213b2 NC |
2101 | return NULL; |
2102 | } | |
2103 | ||
1b3892be | 2104 | if (map_return != NULL) |
bcd213b2 NC |
2105 | { |
2106 | if (form == DW_FORM_ref_addr) | |
1b3892be | 2107 | *map_return = map; |
bcd213b2 | 2108 | else |
1b3892be | 2109 | *map_return = NULL; |
bcd213b2 | 2110 | } |
175b9150 | 2111 | |
f2a15e7c | 2112 | unsigned char *data = section->start + uvalue; |
479c6116 AM |
2113 | if (form == DW_FORM_ref_addr) |
2114 | cu_end = section->start + map->end; | |
2115 | ||
f2a15e7c | 2116 | unsigned long abbrev_number; |
479c6116 | 2117 | READ_ULEB (abbrev_number, data, cu_end); |
bcd213b2 | 2118 | |
bcd213b2 | 2119 | if (abbrev_num_return != NULL) |
f2a15e7c | 2120 | *abbrev_num_return = abbrev_number; |
bcd213b2 NC |
2121 | |
2122 | if (data_return != NULL) | |
f2a15e7c AM |
2123 | *data_return = data; |
2124 | ||
2125 | abbrev_entry *entry; | |
2126 | for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next) | |
2127 | if (entry->number == abbrev_number) | |
2128 | break; | |
bcd213b2 NC |
2129 | |
2130 | if (entry == NULL) | |
2131 | warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number); | |
2132 | ||
2133 | return entry; | |
2134 | } | |
2135 | ||
2136 | /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY | |
2137 | can be determined to be a signed type. The data for ENTRY can be | |
2138 | found starting at DATA. */ | |
ec1b0fbb NC |
2139 | |
2140 | static void | |
015dc7e1 AM |
2141 | get_type_signedness (abbrev_entry *entry, |
2142 | const struct dwarf_section *section, | |
2143 | unsigned char *data, | |
a7077ce7 | 2144 | unsigned char *end, |
31e5a3a3 AM |
2145 | uint64_t cu_offset, |
2146 | uint64_t pointer_size, | |
2147 | uint64_t offset_size, | |
015dc7e1 AM |
2148 | int dwarf_version, |
2149 | bool *is_signed, | |
2150 | unsigned int nesting) | |
ec1b0fbb | 2151 | { |
ec1b0fbb NC |
2152 | abbrev_attr * attr; |
2153 | ||
015dc7e1 | 2154 | * is_signed = false; |
ec1b0fbb | 2155 | |
59624513 NC |
2156 | #define MAX_NESTING 20 |
2157 | if (nesting > MAX_NESTING) | |
2158 | { | |
2159 | /* FIXME: Warn - or is this expected ? | |
2160 | NB/ We need to avoid infinite recursion. */ | |
2161 | return; | |
2162 | } | |
2163 | ||
ec1b0fbb NC |
2164 | for (attr = entry->first_attr; |
2165 | attr != NULL && attr->attribute; | |
2166 | attr = attr->next) | |
2167 | { | |
bcd213b2 | 2168 | unsigned char * orig_data = data; |
31e5a3a3 | 2169 | uint64_t uvalue = 0; |
ec1b0fbb NC |
2170 | |
2171 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
2172 | offset_size, dwarf_version, & uvalue); | |
2173 | if (data == NULL) | |
2174 | return; | |
2175 | ||
2176 | switch (attr->attribute) | |
2177 | { | |
bcd213b2 | 2178 | case DW_AT_linkage_name: |
ec1b0fbb | 2179 | case DW_AT_name: |
bcd213b2 NC |
2180 | if (do_wide) |
2181 | { | |
2182 | if (attr->form == DW_FORM_strp) | |
2183 | printf (", %s", fetch_indirect_string (uvalue)); | |
2184 | else if (attr->form == DW_FORM_string) | |
4ff0bb2d | 2185 | printf (", %.*s", (int) (end - orig_data), orig_data); |
bcd213b2 | 2186 | } |
ec1b0fbb | 2187 | break; |
bcd213b2 | 2188 | |
ec1b0fbb NC |
2189 | case DW_AT_type: |
2190 | /* Recurse. */ | |
bcd213b2 | 2191 | { |
1b3892be AM |
2192 | abbrev_entry *type_abbrev; |
2193 | unsigned char *type_data; | |
2194 | abbrev_map *map; | |
bcd213b2 NC |
2195 | |
2196 | type_abbrev = get_type_abbrev_from_form (attr->form, | |
2197 | uvalue, | |
2198 | cu_offset, | |
40e1d303 | 2199 | end, |
bcd213b2 NC |
2200 | section, |
2201 | NULL /* abbrev num return */, | |
1b3892be AM |
2202 | &type_data, |
2203 | &map); | |
bcd213b2 NC |
2204 | if (type_abbrev == NULL) |
2205 | break; | |
2206 | ||
1b3892be AM |
2207 | get_type_signedness (type_abbrev, section, type_data, |
2208 | map ? section->start + map->end : end, | |
2209 | map ? map->start : cu_offset, | |
bcd213b2 NC |
2210 | pointer_size, offset_size, dwarf_version, |
2211 | is_signed, nesting + 1); | |
2212 | } | |
ec1b0fbb NC |
2213 | break; |
2214 | ||
2215 | case DW_AT_encoding: | |
2216 | /* Determine signness. */ | |
2217 | switch (uvalue) | |
2218 | { | |
2219 | case DW_ATE_address: | |
2220 | /* FIXME - some architectures have signed addresses. */ | |
2221 | case DW_ATE_boolean: | |
2222 | case DW_ATE_unsigned: | |
2223 | case DW_ATE_unsigned_char: | |
2224 | case DW_ATE_unsigned_fixed: | |
015dc7e1 | 2225 | * is_signed = false; |
ec1b0fbb NC |
2226 | break; |
2227 | ||
2228 | default: | |
2229 | case DW_ATE_complex_float: | |
2230 | case DW_ATE_float: | |
2231 | case DW_ATE_signed: | |
2232 | case DW_ATE_signed_char: | |
2233 | case DW_ATE_imaginary_float: | |
2234 | case DW_ATE_decimal_float: | |
2235 | case DW_ATE_signed_fixed: | |
015dc7e1 | 2236 | * is_signed = true; |
ec1b0fbb NC |
2237 | break; |
2238 | } | |
2239 | break; | |
2240 | } | |
2241 | } | |
2242 | } | |
2243 | ||
2244 | static void | |
015dc7e1 AM |
2245 | read_and_print_leb128 (unsigned char *data, |
2246 | unsigned int *bytes_read, | |
2247 | unsigned const char *end, | |
2248 | bool is_signed) | |
ec1b0fbb | 2249 | { |
cd30bcef | 2250 | int status; |
31e5a3a3 | 2251 | uint64_t val = read_leb128 (data, end, is_signed, bytes_read, &status); |
cd30bcef | 2252 | if (status != 0) |
9039747f | 2253 | report_leb_status (status); |
31e5a3a3 AM |
2254 | else if (is_signed) |
2255 | printf ("%" PRId64, val); | |
ec1b0fbb | 2256 | else |
31e5a3a3 | 2257 | printf ("%" PRIu64, val); |
ec1b0fbb NC |
2258 | } |
2259 | ||
2260 | static void | |
31e5a3a3 AM |
2261 | display_discr_list (unsigned long form, |
2262 | uint64_t uvalue, | |
2263 | unsigned char *data, | |
2264 | int level) | |
ec1b0fbb | 2265 | { |
9039747f AM |
2266 | unsigned char *end = data; |
2267 | ||
ec1b0fbb NC |
2268 | if (uvalue == 0) |
2269 | { | |
2270 | printf ("[default]"); | |
2271 | return; | |
2272 | } | |
521d4b19 | 2273 | |
ec1b0fbb NC |
2274 | switch (form) |
2275 | { | |
2276 | case DW_FORM_block: | |
2277 | case DW_FORM_block1: | |
2278 | case DW_FORM_block2: | |
2279 | case DW_FORM_block4: | |
2280 | /* Move data pointer back to the start of the byte array. */ | |
2281 | data -= uvalue; | |
2282 | break; | |
2283 | default: | |
2284 | printf ("<corrupt>\n"); | |
2285 | warn (_("corrupt discr_list - not using a block form\n")); | |
2286 | return; | |
2287 | } | |
2288 | ||
2289 | if (uvalue < 2) | |
2290 | { | |
2291 | printf ("<corrupt>\n"); | |
2292 | warn (_("corrupt discr_list - block not long enough\n")); | |
2293 | return; | |
2294 | } | |
2295 | ||
9039747f AM |
2296 | bool is_signed = (level > 0 && level <= MAX_CU_NESTING |
2297 | ? level_type_signed [level - 1] : false); | |
521d4b19 | 2298 | |
ec1b0fbb | 2299 | printf ("("); |
9039747f | 2300 | while (data < end) |
ec1b0fbb NC |
2301 | { |
2302 | unsigned char discriminant; | |
2303 | unsigned int bytes_read; | |
2304 | ||
6d1ad6f7 | 2305 | SAFE_BYTE_GET_AND_INC (discriminant, data, 1, end); |
ec1b0fbb | 2306 | |
ec1b0fbb NC |
2307 | switch (discriminant) |
2308 | { | |
2309 | case DW_DSC_label: | |
2310 | printf ("label "); | |
2311 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
ec1b0fbb NC |
2312 | data += bytes_read; |
2313 | break; | |
2314 | ||
2315 | case DW_DSC_range: | |
2316 | printf ("range "); | |
2317 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
ec1b0fbb NC |
2318 | data += bytes_read; |
2319 | ||
2320 | printf (".."); | |
2321 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
ec1b0fbb NC |
2322 | data += bytes_read; |
2323 | break; | |
2324 | ||
2325 | default: | |
2326 | printf ("<corrupt>\n"); | |
e38332c2 | 2327 | warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"), |
ec1b0fbb NC |
2328 | discriminant); |
2329 | return; | |
2330 | } | |
2331 | ||
9039747f | 2332 | if (data < end) |
ec1b0fbb NC |
2333 | printf (", "); |
2334 | } | |
2335 | ||
2336 | if (is_signed) | |
2337 | printf (")(signed)"); | |
2338 | else | |
2339 | printf (")(unsigned)"); | |
2340 | } | |
2341 | ||
9847ba8f TV |
2342 | static void |
2343 | display_lang (uint64_t uvalue) | |
2344 | { | |
2345 | switch (uvalue) | |
2346 | { | |
2347 | /* Ordered by the numeric value of these constants. */ | |
2348 | case DW_LANG_C89: printf ("ANSI C"); break; | |
2349 | case DW_LANG_C: printf ("non-ANSI C"); break; | |
2350 | case DW_LANG_Ada83: printf ("Ada"); break; | |
2351 | case DW_LANG_C_plus_plus: printf ("C++"); break; | |
2352 | case DW_LANG_Cobol74: printf ("Cobol 74"); break; | |
2353 | case DW_LANG_Cobol85: printf ("Cobol 85"); break; | |
2354 | case DW_LANG_Fortran77: printf ("FORTRAN 77"); break; | |
2355 | case DW_LANG_Fortran90: printf ("Fortran 90"); break; | |
2356 | case DW_LANG_Pascal83: printf ("ANSI Pascal"); break; | |
2357 | case DW_LANG_Modula2: printf ("Modula 2"); break; | |
2358 | ||
2359 | /* DWARF 2.1 values. */ | |
2360 | case DW_LANG_Java: printf ("Java"); break; | |
2361 | case DW_LANG_C99: printf ("ANSI C99"); break; | |
2362 | case DW_LANG_Ada95: printf ("ADA 95"); break; | |
2363 | case DW_LANG_Fortran95: printf ("Fortran 95"); break; | |
2364 | ||
2365 | /* DWARF 3 values. */ | |
2366 | case DW_LANG_PLI: printf ("PLI"); break; | |
2367 | case DW_LANG_ObjC: printf ("Objective C"); break; | |
2368 | case DW_LANG_ObjC_plus_plus: printf ("Objective C++"); break; | |
2369 | case DW_LANG_UPC: printf ("Unified Parallel C"); break; | |
2370 | case DW_LANG_D: printf ("D"); break; | |
2371 | ||
2372 | /* DWARF 4 values. */ | |
2373 | case DW_LANG_Python: printf ("Python"); break; | |
2374 | ||
2375 | /* DWARF 5 values. */ | |
2376 | case DW_LANG_OpenCL: printf ("OpenCL"); break; | |
2377 | case DW_LANG_Go: printf ("Go"); break; | |
2378 | case DW_LANG_Modula3: printf ("Modula 3"); break; | |
2379 | case DW_LANG_Haskell: printf ("Haskell"); break; | |
2380 | case DW_LANG_C_plus_plus_03: printf ("C++03"); break; | |
2381 | case DW_LANG_C_plus_plus_11: printf ("C++11"); break; | |
2382 | case DW_LANG_OCaml: printf ("OCaml"); break; | |
2383 | case DW_LANG_Rust: printf ("Rust"); break; | |
2384 | case DW_LANG_C11: printf ("C11"); break; | |
2385 | case DW_LANG_Swift: printf ("Swift"); break; | |
2386 | case DW_LANG_Julia: printf ("Julia"); break; | |
2387 | case DW_LANG_Dylan: printf ("Dylan"); break; | |
2388 | case DW_LANG_C_plus_plus_14: printf ("C++14"); break; | |
2389 | case DW_LANG_Fortran03: printf ("Fortran 03"); break; | |
2390 | case DW_LANG_Fortran08: printf ("Fortran 08"); break; | |
2391 | case DW_LANG_RenderScript: printf ("RenderScript"); break; | |
d05b8f01 AH |
2392 | case DW_LANG_C17: printf ("C17"); break; |
2393 | case DW_LANG_Fortran18: printf ("Fortran 18"); break; | |
2394 | case DW_LANG_Ada2005: printf ("Ada 2005"); break; | |
2395 | case DW_LANG_Ada2012: printf ("Ada 2012"); break; | |
2396 | case DW_LANG_HIP: printf ("Hip"); break; | |
2397 | case DW_LANG_Assembly: printf ("Assembler"); break; | |
2398 | case DW_LANG_C_sharp: printf ("C Sharp"); break; | |
2399 | case DW_LANG_Mojo: printf ("Mojo"); break; | |
2400 | case DW_LANG_GLSL: printf ("GLSL"); break; | |
2401 | case DW_LANG_GLSL_ES: printf ("GLSL_ES"); break; | |
2402 | case DW_LANG_HLSL: printf ("HLSL"); break; | |
2403 | case DW_LANG_OpenCL_CPP: printf ("OpenCL C++"); break; | |
2404 | case DW_LANG_CPP_for_OpenCL: printf ("C++ for OpenCL"); break; | |
2405 | case DW_LANG_SYCL: printf ("SYCL"); break; | |
2406 | case DW_LANG_C_plus_plus_17: printf ("C++17"); break; | |
2407 | case DW_LANG_C_plus_plus_20: printf ("C++20"); break; | |
2408 | case DW_LANG_C_plus_plus_23: printf ("C++23"); break; | |
2409 | case DW_LANG_Odin: printf ("Odin"); break; | |
2410 | case DW_LANG_P4: printf ("P4"); break; | |
2411 | case DW_LANG_Metal: printf ("C23"); break; | |
2412 | case DW_LANG_C23: printf ("C23"); break; | |
2413 | case DW_LANG_Fortran23: printf ("Fortran 23"); break; | |
2414 | case DW_LANG_Ruby: printf ("Ruby"); break; | |
2415 | case DW_LANG_Move: printf ("Move"); break; | |
2416 | case DW_LANG_Hylo: printf ("Hylo"); break; | |
9847ba8f TV |
2417 | |
2418 | /* MIPS extension. */ | |
2419 | case DW_LANG_Mips_Assembler: printf ("MIPS assembler"); break; | |
2420 | ||
2421 | /* UPC extension. */ | |
2422 | case DW_LANG_Upc: printf ("Unified Parallel C"); break; | |
2423 | ||
2424 | default: | |
2425 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) | |
2426 | printf (_("implementation defined: %#" PRIx64 ""), uvalue); | |
2427 | else | |
2428 | printf (_("unknown: %#" PRIx64 ""), uvalue); | |
2429 | break; | |
2430 | } | |
2431 | } | |
2432 | ||
19e6b90e | 2433 | static unsigned char * |
31e5a3a3 AM |
2434 | read_and_display_attr_value (unsigned long attribute, |
2435 | unsigned long form, | |
2436 | int64_t implicit_const, | |
2437 | unsigned char *start, | |
2438 | unsigned char *data, | |
2439 | unsigned char *end, | |
2440 | uint64_t cu_offset, | |
2441 | uint64_t pointer_size, | |
2442 | uint64_t offset_size, | |
2443 | int dwarf_version, | |
2444 | debug_info *debug_info_p, | |
2445 | int do_loc, | |
2446 | struct dwarf_section *section, | |
2447 | struct cu_tu_set *this_set, | |
2448 | char delimiter, | |
2449 | int level) | |
2450 | { | |
2451 | int64_t svalue; | |
2452 | uint64_t uvalue = 0; | |
2453 | uint64_t uvalue_hi = 0; | |
af2ddf69 AM |
2454 | unsigned char *block_start = NULL; |
2455 | unsigned char *orig_data = data; | |
19e6b90e | 2456 | |
f41e4712 | 2457 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2458 | { |
f41e4712 | 2459 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2460 | return data; |
2461 | } | |
2462 | ||
521d4b19 NC |
2463 | if (do_wide && ! do_loc) |
2464 | { | |
2465 | /* PR 26847: Display the name of the form. */ | |
2466 | const char * name = get_FORM_name (form); | |
2467 | ||
2468 | /* For convenience we skip the DW_FORM_ prefix to the name. */ | |
2469 | if (name[0] == 'D') | |
2470 | name += 8; /* strlen ("DW_FORM_") */ | |
2471 | printf ("%c(%s)", delimiter, name); | |
2472 | } | |
2473 | ||
19e6b90e L |
2474 | switch (form) |
2475 | { | |
19e6b90e L |
2476 | case DW_FORM_ref_addr: |
2477 | if (dwarf_version == 2) | |
0c588247 | 2478 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
ec47b32a | 2479 | else if (dwarf_version > 2) |
0c588247 | 2480 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2481 | else |
ec47b32a | 2482 | error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); |
19e6b90e L |
2483 | break; |
2484 | ||
2485 | case DW_FORM_addr: | |
0c588247 | 2486 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2487 | break; |
2488 | ||
e38332c2 | 2489 | case DW_FORM_strp_sup: |
19e6b90e | 2490 | case DW_FORM_strp: |
77145576 | 2491 | case DW_FORM_line_strp: |
932fd279 | 2492 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2493 | case DW_FORM_GNU_ref_alt: |
2494 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2495 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2496 | break; |
2497 | ||
932fd279 JJ |
2498 | case DW_FORM_flag_present: |
2499 | uvalue = 1; | |
2500 | break; | |
2501 | ||
19e6b90e L |
2502 | case DW_FORM_ref1: |
2503 | case DW_FORM_flag: | |
2504 | case DW_FORM_data1: | |
32e4f96c TV |
2505 | case DW_FORM_strx1: |
2506 | case DW_FORM_addrx1: | |
0c588247 | 2507 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2508 | break; |
2509 | ||
2510 | case DW_FORM_ref2: | |
2511 | case DW_FORM_data2: | |
32e4f96c TV |
2512 | case DW_FORM_strx2: |
2513 | case DW_FORM_addrx2: | |
0c588247 | 2514 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2515 | break; |
2516 | ||
32e4f96c TV |
2517 | case DW_FORM_strx3: |
2518 | case DW_FORM_addrx3: | |
2519 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); | |
2520 | break; | |
2521 | ||
e38332c2 | 2522 | case DW_FORM_ref_sup4: |
19e6b90e L |
2523 | case DW_FORM_ref4: |
2524 | case DW_FORM_data4: | |
32e4f96c TV |
2525 | case DW_FORM_strx4: |
2526 | case DW_FORM_addrx4: | |
0c588247 | 2527 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2528 | break; |
2529 | ||
af2ddf69 AM |
2530 | case DW_FORM_ref_sup8: |
2531 | case DW_FORM_ref8: | |
2532 | case DW_FORM_data8: | |
2533 | case DW_FORM_ref_sig8: | |
2534 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); | |
2535 | break; | |
2536 | ||
2537 | case DW_FORM_data16: | |
2538 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); | |
2539 | SAFE_BYTE_GET_AND_INC (uvalue_hi, data, 8, end); | |
2540 | if (byte_get != byte_get_little_endian) | |
2541 | { | |
31e5a3a3 | 2542 | uint64_t utmp = uvalue; |
af2ddf69 AM |
2543 | uvalue = uvalue_hi; |
2544 | uvalue_hi = utmp; | |
2545 | } | |
2546 | break; | |
2547 | ||
19e6b90e | 2548 | case DW_FORM_sdata: |
cd30bcef AM |
2549 | READ_SLEB (svalue, data, end); |
2550 | uvalue = svalue; | |
19e6b90e L |
2551 | break; |
2552 | ||
4723351a | 2553 | case DW_FORM_GNU_str_index: |
32e4f96c | 2554 | case DW_FORM_strx: |
19e6b90e L |
2555 | case DW_FORM_ref_udata: |
2556 | case DW_FORM_udata: | |
cd30bcef | 2557 | case DW_FORM_GNU_addr_index: |
32e4f96c | 2558 | case DW_FORM_addrx: |
19c26da6 NC |
2559 | case DW_FORM_loclistx: |
2560 | case DW_FORM_rnglistx: | |
cd30bcef | 2561 | READ_ULEB (uvalue, data, end); |
19e6b90e L |
2562 | break; |
2563 | ||
2564 | case DW_FORM_indirect: | |
cd30bcef | 2565 | READ_ULEB (form, data, end); |
19e6b90e | 2566 | if (!do_loc) |
ef0b5f1c | 2567 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 | 2568 | if (form == DW_FORM_implicit_const) |
cd30bcef | 2569 | READ_SLEB (implicit_const, data, end); |
ec1b0fbb NC |
2570 | return read_and_display_attr_value (attribute, form, implicit_const, |
2571 | start, data, end, | |
2572 | cu_offset, pointer_size, | |
19e6b90e | 2573 | offset_size, dwarf_version, |
ec4d4525 | 2574 | debug_info_p, do_loc, |
ec1b0fbb | 2575 | section, this_set, delimiter, level); |
c63fc368 NC |
2576 | |
2577 | case DW_FORM_implicit_const: | |
2578 | uvalue = implicit_const; | |
2579 | break; | |
19c26da6 NC |
2580 | |
2581 | default: | |
2582 | break; | |
19e6b90e L |
2583 | } |
2584 | ||
2585 | switch (form) | |
2586 | { | |
2587 | case DW_FORM_ref_addr: | |
2588 | if (!do_loc) | |
cc443420 | 2589 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue); |
19e6b90e L |
2590 | break; |
2591 | ||
a081f3cd JJ |
2592 | case DW_FORM_GNU_ref_alt: |
2593 | if (!do_loc) | |
521d4b19 NC |
2594 | { |
2595 | if (do_wide) | |
2596 | /* We have already printed the form name. */ | |
cc443420 | 2597 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue); |
521d4b19 | 2598 | else |
cc443420 | 2599 | printf ("%c<alt %#" PRIx64 ">", delimiter, uvalue); |
521d4b19 | 2600 | } |
dda8d76d | 2601 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2602 | break; |
2603 | ||
19e6b90e L |
2604 | case DW_FORM_ref1: |
2605 | case DW_FORM_ref2: | |
2606 | case DW_FORM_ref4: | |
e38332c2 | 2607 | case DW_FORM_ref_sup4: |
19e6b90e L |
2608 | case DW_FORM_ref_udata: |
2609 | if (!do_loc) | |
cc443420 | 2610 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue + cu_offset); |
19e6b90e L |
2611 | break; |
2612 | ||
2613 | case DW_FORM_data4: | |
2614 | case DW_FORM_addr: | |
932fd279 | 2615 | case DW_FORM_sec_offset: |
19e6b90e | 2616 | if (!do_loc) |
cc443420 | 2617 | printf ("%c%#" PRIx64, delimiter, uvalue); |
19e6b90e L |
2618 | break; |
2619 | ||
932fd279 | 2620 | case DW_FORM_flag_present: |
19e6b90e L |
2621 | case DW_FORM_flag: |
2622 | case DW_FORM_data1: | |
2623 | case DW_FORM_data2: | |
2624 | case DW_FORM_sdata: | |
19e6b90e | 2625 | if (!do_loc) |
31e5a3a3 | 2626 | printf ("%c%" PRId64, delimiter, uvalue); |
19e6b90e L |
2627 | break; |
2628 | ||
581db2a2 AM |
2629 | case DW_FORM_udata: |
2630 | if (!do_loc) | |
31e5a3a3 | 2631 | printf ("%c%" PRIu64, delimiter, uvalue); |
581db2a2 AM |
2632 | break; |
2633 | ||
77145576 JK |
2634 | case DW_FORM_implicit_const: |
2635 | if (!do_loc) | |
31e5a3a3 | 2636 | printf ("%c%" PRId64, delimiter, implicit_const); |
77145576 JK |
2637 | break; |
2638 | ||
e38332c2 | 2639 | case DW_FORM_ref_sup8: |
19e6b90e L |
2640 | case DW_FORM_ref8: |
2641 | case DW_FORM_data8: | |
2bc8690c | 2642 | if (!do_loc) |
19e6b90e | 2643 | { |
31e5a3a3 | 2644 | uint64_t utmp = uvalue; |
a69c4772 | 2645 | if (form == DW_FORM_ref8) |
af2ddf69 | 2646 | utmp += cu_offset; |
cc443420 | 2647 | printf ("%c%#" PRIx64, delimiter, utmp); |
19e6b90e | 2648 | } |
19e6b90e L |
2649 | break; |
2650 | ||
2f6cd591 JK |
2651 | case DW_FORM_data16: |
2652 | if (!do_loc) | |
31e5a3a3 AM |
2653 | { |
2654 | if (uvalue_hi == 0) | |
cc443420 | 2655 | printf (" %#" PRIx64, uvalue); |
31e5a3a3 | 2656 | else |
cc443420 | 2657 | printf (" %#" PRIx64 "%016" PRIx64, uvalue_hi, uvalue); |
31e5a3a3 | 2658 | } |
2f6cd591 JK |
2659 | break; |
2660 | ||
19e6b90e L |
2661 | case DW_FORM_string: |
2662 | if (!do_loc) | |
ef0b5f1c | 2663 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
a7077ce7 AM |
2664 | data += strnlen ((char *) data, end - data); |
2665 | if (data < end) | |
2666 | data++; | |
19e6b90e L |
2667 | break; |
2668 | ||
2669 | case DW_FORM_block: | |
932fd279 | 2670 | case DW_FORM_exprloc: |
cd30bcef AM |
2671 | READ_ULEB (uvalue, data, end); |
2672 | do_block: | |
2673 | block_start = data; | |
a1165289 NC |
2674 | if (block_start >= end) |
2675 | { | |
2676 | warn (_("Block ends prematurely\n")); | |
2677 | uvalue = 0; | |
2678 | block_start = end; | |
2679 | } | |
afc72f15 NC |
2680 | |
2681 | uvalue = check_uvalue (block_start, uvalue, end); | |
2682 | ||
3ac9da49 NK |
2683 | data = block_start + uvalue; |
2684 | if (!do_loc) | |
2685 | { | |
2686 | unsigned char op; | |
2687 | ||
2688 | SAFE_BYTE_GET (op, block_start, sizeof (op), end); | |
2689 | if (op != DW_OP_addrx) | |
2690 | data = display_block (block_start, uvalue, end, delimiter); | |
2691 | } | |
19e6b90e L |
2692 | break; |
2693 | ||
2694 | case DW_FORM_block1: | |
cd30bcef AM |
2695 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2696 | goto do_block; | |
19e6b90e L |
2697 | |
2698 | case DW_FORM_block2: | |
cd30bcef AM |
2699 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2700 | goto do_block; | |
19e6b90e L |
2701 | |
2702 | case DW_FORM_block4: | |
cd30bcef AM |
2703 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2704 | goto do_block; | |
19e6b90e L |
2705 | |
2706 | case DW_FORM_strp: | |
2707 | if (!do_loc) | |
521d4b19 NC |
2708 | { |
2709 | if (do_wide) | |
2710 | /* We have already displayed the form name. */ | |
cc443420 | 2711 | printf (_("%c(offset: %#" PRIx64 "): %s"), |
31e5a3a3 | 2712 | delimiter, uvalue, fetch_indirect_string (uvalue)); |
521d4b19 | 2713 | else |
cc443420 | 2714 | printf (_("%c(indirect string, offset: %#" PRIx64 "): %s"), |
31e5a3a3 | 2715 | delimiter, uvalue, fetch_indirect_string (uvalue)); |
521d4b19 | 2716 | } |
19e6b90e L |
2717 | break; |
2718 | ||
77145576 JK |
2719 | case DW_FORM_line_strp: |
2720 | if (!do_loc) | |
521d4b19 NC |
2721 | { |
2722 | if (do_wide) | |
2723 | /* We have already displayed the form name. */ | |
cc443420 | 2724 | printf (_("%c(offset: %#" PRIx64 "): %s"), |
31e5a3a3 | 2725 | delimiter, uvalue, fetch_indirect_line_string (uvalue)); |
521d4b19 | 2726 | else |
cc443420 | 2727 | printf (_("%c(indirect line string, offset: %#" PRIx64 "): %s"), |
31e5a3a3 | 2728 | delimiter, uvalue, fetch_indirect_line_string (uvalue)); |
521d4b19 | 2729 | } |
77145576 JK |
2730 | break; |
2731 | ||
4723351a | 2732 | case DW_FORM_GNU_str_index: |
32e4f96c TV |
2733 | case DW_FORM_strx: |
2734 | case DW_FORM_strx1: | |
2735 | case DW_FORM_strx2: | |
2736 | case DW_FORM_strx3: | |
2737 | case DW_FORM_strx4: | |
4723351a | 2738 | if (!do_loc) |
b4eb7656 | 2739 | { |
be38442d | 2740 | const char *suffix = section ? strrchr (section->name, '.') : NULL; |
015dc7e1 | 2741 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
e98e7d9a | 2742 | const char *strng; |
b4eb7656 | 2743 | |
e98e7d9a NC |
2744 | strng = fetch_indexed_string (uvalue, this_set, offset_size, dwo, |
2745 | debug_info_p ? debug_info_p->str_offsets_base : 0); | |
521d4b19 NC |
2746 | if (do_wide) |
2747 | /* We have already displayed the form name. */ | |
cc443420 | 2748 | printf (_("%c(offset: %#" PRIx64 "): %s"), |
31e5a3a3 | 2749 | delimiter, uvalue, strng); |
521d4b19 | 2750 | else |
cc443420 | 2751 | printf (_("%c(indexed string: %#" PRIx64 "): %s"), |
31e5a3a3 | 2752 | delimiter, uvalue, strng); |
b4eb7656 | 2753 | } |
4723351a CC |
2754 | break; |
2755 | ||
a081f3cd JJ |
2756 | case DW_FORM_GNU_strp_alt: |
2757 | if (!do_loc) | |
dda8d76d | 2758 | { |
521d4b19 NC |
2759 | if (do_wide) |
2760 | /* We have already displayed the form name. */ | |
cc443420 | 2761 | printf (_("%c(offset: %#" PRIx64 ") %s"), |
31e5a3a3 | 2762 | delimiter, uvalue, fetch_alt_indirect_string (uvalue)); |
521d4b19 | 2763 | else |
cc443420 | 2764 | printf (_("%c(alt indirect string, offset: %#" PRIx64 ") %s"), |
31e5a3a3 | 2765 | delimiter, uvalue, fetch_alt_indirect_string (uvalue)); |
dda8d76d | 2766 | } |
a081f3cd JJ |
2767 | break; |
2768 | ||
19e6b90e L |
2769 | case DW_FORM_indirect: |
2770 | /* Handled above. */ | |
2771 | break; | |
2772 | ||
2b6f5997 CC |
2773 | case DW_FORM_ref_sig8: |
2774 | if (!do_loc) | |
cc443420 | 2775 | printf ("%c%s: %#" PRIx64, delimiter, do_wide ? "" : "signature", |
31e5a3a3 | 2776 | uvalue); |
2b6f5997 CC |
2777 | break; |
2778 | ||
4723351a | 2779 | case DW_FORM_GNU_addr_index: |
32e4f96c TV |
2780 | case DW_FORM_addrx: |
2781 | case DW_FORM_addrx1: | |
2782 | case DW_FORM_addrx2: | |
2783 | case DW_FORM_addrx3: | |
2784 | case DW_FORM_addrx4: | |
19c26da6 NC |
2785 | case DW_FORM_loclistx: |
2786 | case DW_FORM_rnglistx: | |
4723351a | 2787 | if (!do_loc) |
521d4b19 | 2788 | { |
31e5a3a3 | 2789 | uint64_t base, idx; |
4694a0e5 BK |
2790 | const char *suffix = strrchr (section->name, '.'); |
2791 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; | |
32e4f96c | 2792 | |
dbcbf67c NC |
2793 | if (form == DW_FORM_loclistx) |
2794 | { | |
e838a672 AM |
2795 | if (debug_info_p == NULL) |
2796 | idx = -1; | |
2797 | else if (dwo) | |
175b9150 | 2798 | { |
8c7125fe VA |
2799 | idx = fetch_indexed_offset (uvalue, loclists_dwo, |
2800 | debug_info_p->loclists_base, | |
2801 | debug_info_p->offset_size); | |
31e5a3a3 | 2802 | if (idx != (uint64_t) -1) |
dfbc689c | 2803 | idx += (offset_size == 8) ? 20 : 12; |
175b9150 | 2804 | } |
e838a672 | 2805 | else if (dwarf_version > 4) |
dbcbf67c | 2806 | { |
8c7125fe VA |
2807 | idx = fetch_indexed_offset (uvalue, loclists, |
2808 | debug_info_p->loclists_base, | |
2809 | debug_info_p->offset_size); | |
dbcbf67c NC |
2810 | } |
2811 | else | |
2812 | { | |
2813 | /* We want to compute: | |
8c7125fe VA |
2814 | idx = fetch_indexed_value (uvalue, loclists, |
2815 | debug_info_p->loclists_base); | |
188bc854 | 2816 | idx += debug_info_p->loclists_base; |
dbcbf67c NC |
2817 | Fortunately we already have that sum cached in the |
2818 | loc_offsets array. */ | |
dfbc689c AM |
2819 | if (uvalue < debug_info_p->num_loc_offsets) |
2820 | idx = debug_info_p->loc_offsets [uvalue]; | |
2821 | else | |
2822 | { | |
2823 | warn (_("loc_offset %" PRIu64 " too big\n"), uvalue); | |
2824 | idx = -1; | |
2825 | } | |
dbcbf67c NC |
2826 | } |
2827 | } | |
2828 | else if (form == DW_FORM_rnglistx) | |
2829 | { | |
e838a672 AM |
2830 | if (debug_info_p == NULL) |
2831 | idx = -1; | |
dbcbf67c | 2832 | else |
e838a672 AM |
2833 | idx = fetch_indexed_offset (uvalue, |
2834 | dwo ? rnglists_dwo : rnglists, | |
2835 | debug_info_p->rnglists_base, | |
2836 | debug_info_p->offset_size); | |
dbcbf67c | 2837 | } |
32e4f96c | 2838 | else |
dbcbf67c NC |
2839 | { |
2840 | if (debug_info_p == NULL) | |
2841 | base = 0; | |
2842 | else if (debug_info_p->addr_base == DEBUG_INFO_UNAVAILABLE) | |
2843 | base = 0; | |
2844 | else | |
2845 | base = debug_info_p->addr_base; | |
32e4f96c | 2846 | |
dbcbf67c | 2847 | base += uvalue * pointer_size; |
188bc854 | 2848 | idx = fetch_indexed_addr (base, pointer_size); |
dbcbf67c | 2849 | } |
32e4f96c | 2850 | |
dbcbf67c | 2851 | /* We have already displayed the form name. */ |
31e5a3a3 | 2852 | if (idx != (uint64_t) -1) |
cc443420 | 2853 | printf (_("%c(index: %#" PRIx64 "): %#" PRIx64), |
31e5a3a3 | 2854 | delimiter, uvalue, idx); |
521d4b19 | 2855 | } |
4723351a CC |
2856 | break; |
2857 | ||
e38332c2 NC |
2858 | case DW_FORM_strp_sup: |
2859 | if (!do_loc) | |
cc443420 | 2860 | printf ("%c<%#" PRIx64 ">", delimiter, uvalue + cu_offset); |
e38332c2 | 2861 | break; |
175b9150 | 2862 | |
19e6b90e | 2863 | default: |
2b34e067 | 2864 | warn (_("Unrecognized form: %#lx\n"), form); |
84f82c95 AM |
2865 | /* What to do? Consume a byte maybe? */ |
2866 | ++data; | |
19e6b90e L |
2867 | break; |
2868 | } | |
2869 | ||
f18acc9c | 2870 | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) |
fd2f0033 TT |
2871 | && num_debug_info_entries == 0 |
2872 | && debug_info_p != NULL) | |
19e6b90e L |
2873 | { |
2874 | switch (attribute) | |
2875 | { | |
19c26da6 NC |
2876 | case DW_AT_loclists_base: |
2877 | if (debug_info_p->loclists_base) | |
31e5a3a3 | 2878 | warn (_("CU @ %#" PRIx64 " has multiple loclists_base values " |
2b34e067 | 2879 | "(%#" PRIx64 " and %#" PRIx64 ")\n"), |
31e5a3a3 AM |
2880 | debug_info_p->cu_offset, |
2881 | debug_info_p->loclists_base, uvalue); | |
8d17c53b NC |
2882 | svalue = uvalue; |
2883 | if (svalue < 0) | |
2884 | { | |
2885 | warn (_("CU @ %#" PRIx64 " has has a negative loclists_base " | |
2b34e067 | 2886 | "value of %#" PRIx64 " - treating as zero\n"), |
8d17c53b NC |
2887 | debug_info_p->cu_offset, svalue); |
2888 | uvalue = 0; | |
2889 | } | |
19c26da6 NC |
2890 | debug_info_p->loclists_base = uvalue; |
2891 | break; | |
8d17c53b | 2892 | |
84102ebc VA |
2893 | case DW_AT_rnglists_base: |
2894 | /* Assignment to debug_info_p->rnglists_base is now elsewhere. */ | |
2895 | break; | |
8d17c53b | 2896 | |
f18acc9c KB |
2897 | case DW_AT_str_offsets_base: |
2898 | if (debug_info_p->str_offsets_base) | |
31e5a3a3 | 2899 | warn (_("CU @ %#" PRIx64 " has multiple str_offsets_base values " |
2b34e067 | 2900 | "%#" PRIx64 " and %#" PRIx64 ")\n"), |
31e5a3a3 AM |
2901 | debug_info_p->cu_offset, |
2902 | debug_info_p->str_offsets_base, uvalue); | |
8d17c53b NC |
2903 | svalue = uvalue; |
2904 | if (svalue < 0) | |
2905 | { | |
2906 | warn (_("CU @ %#" PRIx64 " has has a negative stroffsets_base " | |
2b34e067 | 2907 | "value of %#" PRIx64 " - treating as zero\n"), |
8d17c53b NC |
2908 | debug_info_p->cu_offset, svalue); |
2909 | uvalue = 0; | |
2910 | } | |
f18acc9c KB |
2911 | debug_info_p->str_offsets_base = uvalue; |
2912 | break; | |
2913 | ||
19e6b90e | 2914 | case DW_AT_frame_base: |
b05efa39 VA |
2915 | /* This is crude; the have_frame_base is reset on the next |
2916 | subprogram, not at the end of the current topmost one. */ | |
19e6b90e | 2917 | have_frame_base = 1; |
b05efa39 | 2918 | frame_base_level = level; |
1a0670f3 | 2919 | /* Fall through. */ |
19e6b90e | 2920 | case DW_AT_location: |
9f272209 | 2921 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2922 | case DW_AT_string_length: |
2923 | case DW_AT_return_addr: | |
19e6b90e L |
2924 | case DW_AT_data_member_location: |
2925 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2926 | case DW_AT_segment: |
2927 | case DW_AT_static_link: | |
2928 | case DW_AT_use_location: | |
bc0a77d2 | 2929 | case DW_AT_call_value: |
629e7ca8 | 2930 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2931 | case DW_AT_call_data_value: |
629e7ca8 | 2932 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2933 | case DW_AT_call_target: |
629e7ca8 | 2934 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2935 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2936 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2937 | if ((dwarf_version < 4 |
212b6063 | 2938 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
19c26da6 NC |
2939 | || form == DW_FORM_sec_offset |
2940 | || form == DW_FORM_loclistx) | |
19e6b90e L |
2941 | { |
2942 | /* Process location list. */ | |
91d6fa6a | 2943 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2944 | unsigned int num = debug_info_p->num_loc_offsets; |
2945 | ||
91d6fa6a | 2946 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2947 | { |
91d6fa6a | 2948 | lmax += 1024; |
31e5a3a3 | 2949 | debug_info_p->loc_offsets = (uint64_t *) |
b4eb7656 AM |
2950 | xcrealloc (debug_info_p->loc_offsets, |
2951 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
31e5a3a3 | 2952 | debug_info_p->loc_views = (uint64_t *) |
9f272209 AO |
2953 | xcrealloc (debug_info_p->loc_views, |
2954 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2955 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2956 | xcrealloc (debug_info_p->have_frame_base, |
2957 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2958 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2959 | } |
19c26da6 | 2960 | if (form == DW_FORM_loclistx) |
8c7125fe VA |
2961 | uvalue = fetch_indexed_offset (num, loclists, |
2962 | debug_info_p->loclists_base, | |
2963 | debug_info_p->offset_size); | |
19c26da6 | 2964 | else if (this_set != NULL) |
b4eb7656 | 2965 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19c26da6 | 2966 | |
19e6b90e | 2967 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2968 | if (attribute != DW_AT_GNU_locviews) |
2969 | { | |
a7504f87 NC |
2970 | /* Corrupt DWARF info can produce more offsets than views. |
2971 | See PR 23062 for an example. */ | |
2972 | if (debug_info_p->num_loc_offsets | |
2973 | > debug_info_p->num_loc_views) | |
2974 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2975 | else | |
2976 | { | |
2977 | debug_info_p->loc_offsets [num] = uvalue; | |
2978 | debug_info_p->num_loc_offsets++; | |
2979 | } | |
9f272209 AO |
2980 | } |
2981 | else | |
2982 | { | |
7bb9e56c NC |
2983 | if (debug_info_p->num_loc_views > num) |
2984 | { | |
2985 | warn (_("The number of views (%u) is greater than the number of locations (%u)\n"), | |
2986 | debug_info_p->num_loc_views, num); | |
2987 | debug_info_p->num_loc_views = num; | |
2988 | } | |
2989 | else | |
2990 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2991 | if (num > debug_info_p->num_loc_offsets) |
2992 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2993 | else | |
2994 | { | |
2995 | debug_info_p->loc_views [num] = uvalue; | |
2996 | debug_info_p->num_loc_views++; | |
2997 | } | |
9f272209 | 2998 | } |
19e6b90e L |
2999 | } |
3000 | break; | |
e2a0d921 | 3001 | |
19e6b90e L |
3002 | case DW_AT_low_pc: |
3003 | if (need_base_address) | |
84102ebc VA |
3004 | { |
3005 | if (form == DW_FORM_addrx) | |
8c7125fe VA |
3006 | uvalue = fetch_indexed_addr (debug_info_p->addr_base |
3007 | + uvalue * pointer_size, | |
84102ebc VA |
3008 | pointer_size); |
3009 | ||
3010 | debug_info_p->base_address = uvalue; | |
3011 | } | |
19e6b90e L |
3012 | break; |
3013 | ||
4723351a | 3014 | case DW_AT_GNU_addr_base: |
32e4f96c | 3015 | case DW_AT_addr_base: |
b4eb7656 | 3016 | debug_info_p->addr_base = uvalue; |
8c7125fe VA |
3017 | /* Retrieved elsewhere so that it is in |
3018 | place by the time we read low_pc. */ | |
4723351a CC |
3019 | break; |
3020 | ||
3021 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 3022 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
3023 | break; |
3024 | ||
19e6b90e | 3025 | case DW_AT_ranges: |
b4eb7656 | 3026 | if ((dwarf_version < 4 |
212b6063 | 3027 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
19c26da6 NC |
3028 | || form == DW_FORM_sec_offset |
3029 | || form == DW_FORM_rnglistx) | |
19e6b90e L |
3030 | { |
3031 | /* Process range list. */ | |
91d6fa6a | 3032 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
3033 | unsigned int num = debug_info_p->num_range_lists; |
3034 | ||
91d6fa6a | 3035 | if (lmax == 0 || num >= lmax) |
19e6b90e | 3036 | { |
91d6fa6a | 3037 | lmax += 1024; |
31e5a3a3 | 3038 | debug_info_p->range_lists = (uint64_t *) |
b4eb7656 AM |
3039 | xcrealloc (debug_info_p->range_lists, |
3040 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 3041 | debug_info_p->max_range_lists = lmax; |
19e6b90e | 3042 | } |
19c26da6 NC |
3043 | |
3044 | if (form == DW_FORM_rnglistx) | |
84102ebc VA |
3045 | uvalue = fetch_indexed_offset (uvalue, rnglists, |
3046 | debug_info_p->rnglists_base, | |
3047 | debug_info_p->offset_size); | |
19c26da6 | 3048 | |
19e6b90e L |
3049 | debug_info_p->range_lists [num] = uvalue; |
3050 | debug_info_p->num_range_lists++; | |
3051 | } | |
3052 | break; | |
3053 | ||
d85bf2ba NC |
3054 | case DW_AT_GNU_dwo_name: |
3055 | case DW_AT_dwo_name: | |
3056 | if (need_dwo_info) | |
3057 | switch (form) | |
3058 | { | |
3059 | case DW_FORM_strp: | |
8c7125fe VA |
3060 | add_dwo_name ((const char *) fetch_indirect_string (uvalue), |
3061 | cu_offset); | |
d85bf2ba | 3062 | break; |
5568cc9e | 3063 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 3064 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 3065 | break; |
d85bf2ba | 3066 | case DW_FORM_GNU_str_index: |
32e4f96c TV |
3067 | case DW_FORM_strx: |
3068 | case DW_FORM_strx1: | |
3069 | case DW_FORM_strx2: | |
3070 | case DW_FORM_strx3: | |
3071 | case DW_FORM_strx4: | |
8c7125fe VA |
3072 | add_dwo_name (fetch_indexed_string (uvalue, this_set, |
3073 | offset_size, false, | |
175b9150 | 3074 | debug_info_p->str_offsets_base), |
f18acc9c | 3075 | cu_offset); |
d85bf2ba NC |
3076 | break; |
3077 | case DW_FORM_string: | |
50ea0877 | 3078 | add_dwo_name ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
3079 | break; |
3080 | default: | |
3081 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
3082 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
3083 | break; |
3084 | } | |
3085 | break; | |
521d4b19 | 3086 | |
d85bf2ba NC |
3087 | case DW_AT_comp_dir: |
3088 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
3089 | if (need_dwo_info) | |
3090 | switch (form) | |
3091 | { | |
3092 | case DW_FORM_strp: | |
50ea0877 | 3093 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 3094 | break; |
5568cc9e | 3095 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 3096 | add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 3097 | break; |
d85bf2ba | 3098 | case DW_FORM_line_strp: |
50ea0877 | 3099 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue), cu_offset); |
d85bf2ba NC |
3100 | break; |
3101 | case DW_FORM_GNU_str_index: | |
32e4f96c TV |
3102 | case DW_FORM_strx: |
3103 | case DW_FORM_strx1: | |
3104 | case DW_FORM_strx2: | |
3105 | case DW_FORM_strx3: | |
3106 | case DW_FORM_strx4: | |
f18acc9c | 3107 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false, |
175b9150 | 3108 | debug_info_p->str_offsets_base), |
f18acc9c | 3109 | cu_offset); |
d85bf2ba NC |
3110 | break; |
3111 | case DW_FORM_string: | |
50ea0877 | 3112 | add_dwo_dir ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
3113 | break; |
3114 | default: | |
3115 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
3116 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
3117 | break; |
3118 | } | |
3119 | break; | |
521d4b19 | 3120 | |
d85bf2ba NC |
3121 | case DW_AT_GNU_dwo_id: |
3122 | if (need_dwo_info) | |
3123 | switch (form) | |
3124 | { | |
3125 | case DW_FORM_data8: | |
24841daa | 3126 | /* FIXME: Record the length of the ID as well ? */ |
50ea0877 | 3127 | add_dwo_id ((const char *) (data - 8), cu_offset); |
d85bf2ba NC |
3128 | break; |
3129 | default: | |
3130 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
3131 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
3132 | break; |
3133 | } | |
3134 | break; | |
521d4b19 | 3135 | |
19e6b90e L |
3136 | default: |
3137 | break; | |
3138 | } | |
3139 | } | |
3140 | ||
4ccf1e31 | 3141 | if (do_loc || attribute == 0) |
19e6b90e L |
3142 | return data; |
3143 | ||
ec4d4525 | 3144 | /* For some attributes we can display further information. */ |
19e6b90e L |
3145 | switch (attribute) |
3146 | { | |
ec1b0fbb | 3147 | case DW_AT_type: |
b3fe587e AM |
3148 | if (level >= 0 && level < MAX_CU_NESTING |
3149 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb | 3150 | { |
015dc7e1 AM |
3151 | bool is_signed = false; |
3152 | abbrev_entry *type_abbrev; | |
3153 | unsigned char *type_data; | |
1b3892be | 3154 | abbrev_map *map; |
521d4b19 | 3155 | |
40e1d303 AM |
3156 | type_abbrev = get_type_abbrev_from_form (form, uvalue, |
3157 | cu_offset, end, | |
3158 | section, NULL, | |
3159 | &type_data, &map); | |
bcd213b2 NC |
3160 | if (type_abbrev != NULL) |
3161 | { | |
1b3892be AM |
3162 | get_type_signedness (type_abbrev, section, type_data, |
3163 | map ? section->start + map->end : end, | |
3164 | map ? map->start : cu_offset, | |
bcd213b2 NC |
3165 | pointer_size, offset_size, dwarf_version, |
3166 | & is_signed, 0); | |
3167 | } | |
ec1b0fbb NC |
3168 | level_type_signed[level] = is_signed; |
3169 | } | |
3170 | break; | |
521d4b19 | 3171 | |
19e6b90e | 3172 | case DW_AT_inline: |
2e9e81a8 | 3173 | printf ("\t"); |
19e6b90e L |
3174 | switch (uvalue) |
3175 | { | |
3176 | case DW_INL_not_inlined: | |
3177 | printf (_("(not inlined)")); | |
3178 | break; | |
3179 | case DW_INL_inlined: | |
3180 | printf (_("(inlined)")); | |
3181 | break; | |
3182 | case DW_INL_declared_not_inlined: | |
3183 | printf (_("(declared as inline but ignored)")); | |
3184 | break; | |
3185 | case DW_INL_declared_inlined: | |
3186 | printf (_("(declared as inline and inlined)")); | |
3187 | break; | |
3188 | default: | |
31e5a3a3 AM |
3189 | printf (_(" (Unknown inline attribute value: %#" PRIx64 ")"), |
3190 | uvalue); | |
19e6b90e L |
3191 | break; |
3192 | } | |
3193 | break; | |
3194 | ||
3195 | case DW_AT_language: | |
9847ba8f TV |
3196 | printf ("\t("); |
3197 | display_lang (uvalue); | |
3198 | printf (")"); | |
19e6b90e L |
3199 | break; |
3200 | ||
3201 | case DW_AT_encoding: | |
2e9e81a8 | 3202 | printf ("\t"); |
19e6b90e L |
3203 | switch (uvalue) |
3204 | { | |
3205 | case DW_ATE_void: printf ("(void)"); break; | |
3206 | case DW_ATE_address: printf ("(machine address)"); break; | |
3207 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
3208 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
3209 | case DW_ATE_float: printf ("(float)"); break; | |
3210 | case DW_ATE_signed: printf ("(signed)"); break; | |
3211 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
3212 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
3213 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 3214 | /* DWARF 2.1 values: */ |
19e6b90e L |
3215 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
3216 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
3217 | /* DWARF 3 values: */ |
3218 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
3219 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
3220 | case DW_ATE_edited: printf ("(edited)"); break; | |
3221 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
3222 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
3223 | /* DWARF 4 values: */ |
3224 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
3225 | /* DWARF 5 values: */ | |
3226 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
3227 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
3228 | ||
e2a0d921 NC |
3229 | /* HP extensions: */ |
3230 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
3231 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
3232 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
3233 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
3234 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
3235 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
3236 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
3237 | ||
19e6b90e L |
3238 | default: |
3239 | if (uvalue >= DW_ATE_lo_user | |
3240 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 3241 | printf (_("(user defined type)")); |
19e6b90e | 3242 | else |
9cf03b7e | 3243 | printf (_("(unknown type)")); |
19e6b90e L |
3244 | break; |
3245 | } | |
3246 | break; | |
3247 | ||
3248 | case DW_AT_accessibility: | |
2e9e81a8 | 3249 | printf ("\t"); |
19e6b90e L |
3250 | switch (uvalue) |
3251 | { | |
3252 | case DW_ACCESS_public: printf ("(public)"); break; | |
3253 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
3254 | case DW_ACCESS_private: printf ("(private)"); break; | |
3255 | default: | |
9cf03b7e | 3256 | printf (_("(unknown accessibility)")); |
19e6b90e L |
3257 | break; |
3258 | } | |
3259 | break; | |
3260 | ||
3261 | case DW_AT_visibility: | |
2e9e81a8 | 3262 | printf ("\t"); |
19e6b90e L |
3263 | switch (uvalue) |
3264 | { | |
3265 | case DW_VIS_local: printf ("(local)"); break; | |
3266 | case DW_VIS_exported: printf ("(exported)"); break; | |
3267 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 3268 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
3269 | } |
3270 | break; | |
3271 | ||
04914e37 NC |
3272 | case DW_AT_endianity: |
3273 | printf ("\t"); | |
3274 | switch (uvalue) | |
3275 | { | |
3276 | case DW_END_default: printf ("(default)"); break; | |
3277 | case DW_END_big: printf ("(big)"); break; | |
3278 | case DW_END_little: printf ("(little)"); break; | |
3279 | default: | |
3280 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
3281 | printf (_("(user specified)")); | |
3282 | else | |
3283 | printf (_("(unknown endianity)")); | |
3284 | break; | |
3285 | } | |
3286 | break; | |
3287 | ||
19e6b90e | 3288 | case DW_AT_virtuality: |
2e9e81a8 | 3289 | printf ("\t"); |
19e6b90e L |
3290 | switch (uvalue) |
3291 | { | |
3292 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
3293 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
3294 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 3295 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
3296 | } |
3297 | break; | |
3298 | ||
3299 | case DW_AT_identifier_case: | |
2e9e81a8 | 3300 | printf ("\t"); |
19e6b90e L |
3301 | switch (uvalue) |
3302 | { | |
3303 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
3304 | case DW_ID_up_case: printf ("(up_case)"); break; | |
3305 | case DW_ID_down_case: printf ("(down_case)"); break; | |
3306 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 3307 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
3308 | } |
3309 | break; | |
3310 | ||
3311 | case DW_AT_calling_convention: | |
2e9e81a8 | 3312 | printf ("\t"); |
19e6b90e L |
3313 | switch (uvalue) |
3314 | { | |
3315 | case DW_CC_normal: printf ("(normal)"); break; | |
3316 | case DW_CC_program: printf ("(program)"); break; | |
3317 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
3318 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
3319 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
3320 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
3321 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
3322 | default: |
3323 | if (uvalue >= DW_CC_lo_user | |
3324 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 3325 | printf (_("(user defined)")); |
19e6b90e | 3326 | else |
9cf03b7e | 3327 | printf (_("(unknown convention)")); |
19e6b90e L |
3328 | } |
3329 | break; | |
3330 | ||
3331 | case DW_AT_ordering: | |
2e9e81a8 | 3332 | printf ("\t"); |
19e6b90e L |
3333 | switch (uvalue) |
3334 | { | |
04914e37 | 3335 | case 255: |
9cf03b7e | 3336 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
3337 | case 0: printf ("(row major)"); break; |
3338 | case 1: printf ("(column major)"); break; | |
3339 | } | |
3340 | break; | |
3341 | ||
04914e37 NC |
3342 | case DW_AT_decimal_sign: |
3343 | printf ("\t"); | |
3344 | switch (uvalue) | |
3345 | { | |
3346 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
3347 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
3348 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
3349 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
3350 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
3351 | default: printf (_("(unrecognised)")); break; | |
3352 | } | |
3353 | break; | |
3354 | ||
3355 | case DW_AT_defaulted: | |
3356 | printf ("\t"); | |
3357 | switch (uvalue) | |
3358 | { | |
3359 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
3360 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
3361 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
3362 | default: printf (_("(unrecognised)")); break; | |
3363 | } | |
3364 | break; | |
3365 | ||
3366 | case DW_AT_discr_list: | |
3367 | printf ("\t"); | |
9039747f | 3368 | display_discr_list (form, uvalue, data, level); |
04914e37 | 3369 | break; |
521d4b19 | 3370 | |
19e6b90e L |
3371 | case DW_AT_frame_base: |
3372 | have_frame_base = 1; | |
1a0670f3 | 3373 | /* Fall through. */ |
19e6b90e | 3374 | case DW_AT_location: |
19c26da6 | 3375 | case DW_AT_loclists_base: |
ec41dd75 | 3376 | case DW_AT_rnglists_base: |
f18acc9c | 3377 | case DW_AT_str_offsets_base: |
e2a0d921 NC |
3378 | case DW_AT_string_length: |
3379 | case DW_AT_return_addr: | |
19e6b90e L |
3380 | case DW_AT_data_member_location: |
3381 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
3382 | case DW_AT_segment: |
3383 | case DW_AT_static_link: | |
3384 | case DW_AT_use_location: | |
bc0a77d2 | 3385 | case DW_AT_call_value: |
629e7ca8 | 3386 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 3387 | case DW_AT_call_data_value: |
629e7ca8 | 3388 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 3389 | case DW_AT_call_target: |
629e7ca8 | 3390 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 3391 | case DW_AT_call_target_clobbered: |
629e7ca8 | 3392 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 3393 | if ((dwarf_version < 4 |
b4eb7656 | 3394 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
19c26da6 NC |
3395 | || form == DW_FORM_sec_offset |
3396 | || form == DW_FORM_loclistx) | |
ec41dd75 | 3397 | { |
f18acc9c KB |
3398 | if (attribute != DW_AT_rnglists_base |
3399 | && attribute != DW_AT_str_offsets_base) | |
ec41dd75 NC |
3400 | printf (_(" (location list)")); |
3401 | } | |
e2a0d921 | 3402 | /* Fall through. */ |
19e6b90e L |
3403 | case DW_AT_allocated: |
3404 | case DW_AT_associated: | |
3405 | case DW_AT_data_location: | |
3406 | case DW_AT_stride: | |
3407 | case DW_AT_upper_bound: | |
cecf136e | 3408 | case DW_AT_lower_bound: |
ad349f24 | 3409 | case DW_AT_rank: |
19e6b90e L |
3410 | if (block_start) |
3411 | { | |
3412 | int need_frame_base; | |
3413 | ||
2e9e81a8 | 3414 | printf ("\t("); |
19e6b90e L |
3415 | need_frame_base = decode_location_expression (block_start, |
3416 | pointer_size, | |
b7807392 JJ |
3417 | offset_size, |
3418 | dwarf_version, | |
19e6b90e | 3419 | uvalue, |
f1c4cc75 | 3420 | cu_offset, section); |
19e6b90e L |
3421 | printf (")"); |
3422 | if (need_frame_base && !have_frame_base) | |
3423 | printf (_(" [without DW_AT_frame_base]")); | |
3424 | } | |
19e6b90e L |
3425 | break; |
3426 | ||
c54207d3 NC |
3427 | case DW_AT_data_bit_offset: |
3428 | case DW_AT_byte_size: | |
3429 | case DW_AT_bit_size: | |
3430 | case DW_AT_string_length_byte_size: | |
3431 | case DW_AT_string_length_bit_size: | |
3432 | case DW_AT_bit_stride: | |
3433 | if (form == DW_FORM_exprloc) | |
3434 | { | |
3435 | printf ("\t("); | |
3436 | (void) decode_location_expression (block_start, pointer_size, | |
3437 | offset_size, dwarf_version, | |
3438 | uvalue, cu_offset, section); | |
3439 | printf (")"); | |
3440 | } | |
3441 | break; | |
3442 | ||
ec4d4525 NC |
3443 | case DW_AT_import: |
3444 | { | |
bcd213b2 NC |
3445 | unsigned long abbrev_number; |
3446 | abbrev_entry *entry; | |
2b6f5997 | 3447 | |
40e1d303 | 3448 | entry = get_type_abbrev_from_form (form, uvalue, cu_offset, end, |
bcd213b2 NC |
3449 | section, & abbrev_number, NULL, NULL); |
3450 | if (entry == NULL) | |
3451 | { | |
3452 | if (form != DW_FORM_GNU_ref_alt) | |
31e5a3a3 AM |
3453 | warn (_("Offset %#" PRIx64 " used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"), |
3454 | uvalue, | |
3455 | orig_data - section->start); | |
bcd213b2 | 3456 | } |
6e3d6dc1 NC |
3457 | else |
3458 | { | |
2e9e81a8 | 3459 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
bcd213b2 | 3460 | printf (" (%s)", get_TAG_name (entry->tag)); |
6e3d6dc1 NC |
3461 | printf ("]"); |
3462 | } | |
ec4d4525 NC |
3463 | } |
3464 | break; | |
3465 | ||
19e6b90e L |
3466 | default: |
3467 | break; | |
3468 | } | |
3469 | ||
3470 | return data; | |
3471 | } | |
3472 | ||
19e6b90e | 3473 | static unsigned char * |
31e5a3a3 AM |
3474 | read_and_display_attr (unsigned long attribute, |
3475 | unsigned long form, | |
3476 | int64_t implicit_const, | |
3477 | unsigned char *start, | |
3478 | unsigned char *data, | |
3479 | unsigned char *end, | |
3480 | uint64_t cu_offset, | |
3481 | uint64_t pointer_size, | |
3482 | uint64_t offset_size, | |
3483 | int dwarf_version, | |
3484 | debug_info *debug_info_p, | |
3485 | int do_loc, | |
3486 | struct dwarf_section *section, | |
3487 | struct cu_tu_set *this_set, | |
3488 | int level) | |
19e6b90e L |
3489 | { |
3490 | if (!do_loc) | |
750f03b7 | 3491 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
3492 | data = read_and_display_attr_value (attribute, form, implicit_const, |
3493 | start, data, end, | |
f6f0e17b | 3494 | cu_offset, pointer_size, offset_size, |
19e6b90e | 3495 | dwarf_version, debug_info_p, |
ec1b0fbb | 3496 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
3497 | if (!do_loc) |
3498 | printf ("\n"); | |
3499 | return data; | |
3500 | } | |
3501 | ||
dda8d76d | 3502 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
3503 | following debug links, then attempt to load the requested section |
3504 | from one of the separate debug info files. */ | |
dda8d76d | 3505 | |
015dc7e1 | 3506 | static bool |
dda8d76d | 3507 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, |
24841daa | 3508 | void * handle) |
dda8d76d | 3509 | { |
24841daa | 3510 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3511 | { |
24841daa NC |
3512 | if (debug_displays[sec_enum].section.filename == NULL) |
3513 | { | |
3514 | /* See if we can associate a filename with this section. */ | |
3515 | separate_info * i; | |
3516 | ||
3517 | for (i = first_separate_info; i != NULL; i = i->next) | |
3518 | if (i->handle == handle) | |
3519 | { | |
3520 | debug_displays[sec_enum].section.filename = i->filename; | |
3521 | break; | |
3522 | } | |
3523 | } | |
3524 | ||
015dc7e1 | 3525 | return true; |
dda8d76d NC |
3526 | } |
3527 | ||
24841daa NC |
3528 | if (do_follow_links) |
3529 | { | |
3530 | separate_info * i; | |
3531 | ||
3532 | for (i = first_separate_info; i != NULL; i = i->next) | |
3533 | { | |
3534 | if (load_debug_section (sec_enum, i->handle)) | |
3535 | { | |
3536 | debug_displays[sec_enum].section.filename = i->filename; | |
3537 | ||
3538 | /* FIXME: We should check to see if any of the remaining debug info | |
3539 | files also contain this section, and, umm, do something about it. */ | |
015dc7e1 | 3540 | return true; |
24841daa NC |
3541 | } |
3542 | } | |
3543 | } | |
dda8d76d | 3544 | |
015dc7e1 | 3545 | return false; |
dda8d76d NC |
3546 | } |
3547 | ||
3548 | static void | |
015dc7e1 | 3549 | introduce (struct dwarf_section * section, bool raw) |
dda8d76d NC |
3550 | { |
3551 | if (raw) | |
3552 | { | |
3553 | if (do_follow_links && section->filename) | |
3554 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3555 | section->name, section->filename); | |
3556 | else | |
3557 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3558 | } | |
3559 | else | |
3560 | { | |
3561 | if (do_follow_links && section->filename) | |
3562 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3563 | section->name, section->filename); | |
3564 | else | |
3565 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3566 | } | |
3567 | } | |
521d4b19 | 3568 | |
450da4bd AM |
3569 | /* Free memory allocated for one unit in debug_information. */ |
3570 | ||
3571 | static void | |
3572 | free_debug_information (debug_info *ent) | |
3573 | { | |
3574 | if (ent->max_loc_offsets) | |
3575 | { | |
3576 | free (ent->loc_offsets); | |
3577 | free (ent->loc_views); | |
3578 | free (ent->have_frame_base); | |
3579 | } | |
3580 | if (ent->max_range_lists) | |
a422bb9d | 3581 | { |
a422bb9d AM |
3582 | free (ent->range_lists); |
3583 | } | |
450da4bd AM |
3584 | } |
3585 | ||
84102ebc VA |
3586 | /* For look-ahead in attributes. When you want to scan a DIE for one specific |
3587 | attribute and ignore the rest. */ | |
3588 | ||
3589 | static unsigned char * | |
3590 | skip_attribute (unsigned long form, | |
3591 | unsigned char * data, | |
3592 | unsigned char * end, | |
3593 | uint64_t pointer_size, | |
3594 | uint64_t offset_size, | |
3595 | int dwarf_version) | |
3596 | { | |
3597 | uint64_t temp; | |
4b8c2aaf | 3598 | size_t inc; |
84102ebc VA |
3599 | |
3600 | switch (form) | |
3601 | { | |
3602 | case DW_FORM_ref_addr: | |
4b8c2aaf | 3603 | inc = dwarf_version == 2 ? pointer_size : offset_size; |
84102ebc VA |
3604 | break; |
3605 | case DW_FORM_addr: | |
4b8c2aaf | 3606 | inc = pointer_size; |
84102ebc VA |
3607 | break; |
3608 | case DW_FORM_strp_sup: | |
3609 | case DW_FORM_strp: | |
3610 | case DW_FORM_line_strp: | |
3611 | case DW_FORM_sec_offset: | |
3612 | case DW_FORM_GNU_ref_alt: | |
3613 | case DW_FORM_GNU_strp_alt: | |
4b8c2aaf | 3614 | inc = offset_size; |
84102ebc VA |
3615 | break; |
3616 | case DW_FORM_ref1: | |
3617 | case DW_FORM_flag: | |
3618 | case DW_FORM_data1: | |
3619 | case DW_FORM_strx1: | |
cb1861cb | 3620 | case DW_FORM_addrx1: |
4b8c2aaf | 3621 | inc = 1; |
84102ebc VA |
3622 | break; |
3623 | case DW_FORM_ref2: | |
3624 | case DW_FORM_data2: | |
3625 | case DW_FORM_strx2: | |
cb1861cb | 3626 | case DW_FORM_addrx2: |
4b8c2aaf | 3627 | inc = 2; |
84102ebc VA |
3628 | break; |
3629 | case DW_FORM_strx3: | |
cb1861cb | 3630 | case DW_FORM_addrx3: |
4b8c2aaf | 3631 | inc = 3; |
84102ebc VA |
3632 | break; |
3633 | case DW_FORM_ref_sup4: | |
3634 | case DW_FORM_ref4: | |
3635 | case DW_FORM_data4: | |
3636 | case DW_FORM_strx4: | |
3637 | case DW_FORM_addrx4: | |
4b8c2aaf | 3638 | inc = 4; |
84102ebc VA |
3639 | break; |
3640 | case DW_FORM_ref_sup8: | |
3641 | case DW_FORM_ref8: | |
3642 | case DW_FORM_data8: | |
3643 | case DW_FORM_ref_sig8: | |
4b8c2aaf | 3644 | inc = 8; |
84102ebc | 3645 | break; |
cb1861cb | 3646 | case DW_FORM_data16: |
4b8c2aaf | 3647 | inc = 16; |
84102ebc VA |
3648 | break; |
3649 | case DW_FORM_sdata: | |
4b8c2aaf AM |
3650 | SKIP_SLEB (data, end); |
3651 | return data; | |
84102ebc VA |
3652 | case DW_FORM_GNU_str_index: |
3653 | case DW_FORM_strx: | |
3654 | case DW_FORM_ref_udata: | |
3655 | case DW_FORM_udata: | |
3656 | case DW_FORM_GNU_addr_index: | |
3657 | case DW_FORM_addrx: | |
3658 | case DW_FORM_loclistx: | |
3659 | case DW_FORM_rnglistx: | |
4b8c2aaf AM |
3660 | SKIP_ULEB (data, end); |
3661 | return data; | |
84102ebc VA |
3662 | case DW_FORM_indirect: |
3663 | while (form == DW_FORM_indirect) | |
3664 | READ_ULEB (form, data, end); | |
4b8c2aaf AM |
3665 | return skip_attribute (form, data, end, pointer_size, offset_size, |
3666 | dwarf_version); | |
84102ebc VA |
3667 | |
3668 | case DW_FORM_string: | |
4b8c2aaf | 3669 | inc = strnlen ((char *) data, end - data); |
84102ebc VA |
3670 | break; |
3671 | case DW_FORM_block: | |
3672 | case DW_FORM_exprloc: | |
3673 | READ_ULEB (temp, data, end); | |
4b8c2aaf | 3674 | inc = temp; |
84102ebc VA |
3675 | break; |
3676 | case DW_FORM_block1: | |
3677 | SAFE_BYTE_GET_AND_INC (temp, data, 1, end); | |
4b8c2aaf | 3678 | inc = temp; |
84102ebc VA |
3679 | break; |
3680 | case DW_FORM_block2: | |
3681 | SAFE_BYTE_GET_AND_INC (temp, data, 2, end); | |
4b8c2aaf | 3682 | inc = temp; |
84102ebc VA |
3683 | break; |
3684 | case DW_FORM_block4: | |
3685 | SAFE_BYTE_GET_AND_INC (temp, data, 4, end); | |
4b8c2aaf | 3686 | inc = temp; |
84102ebc VA |
3687 | break; |
3688 | case DW_FORM_implicit_const: | |
3689 | case DW_FORM_flag_present: | |
4b8c2aaf | 3690 | return data; |
84102ebc VA |
3691 | default: |
3692 | warn (_("Unexpected form in top DIE\n")); | |
4b8c2aaf | 3693 | return data; |
84102ebc | 3694 | } |
4b8c2aaf AM |
3695 | if (inc <= (size_t) (end - data)) |
3696 | data += inc; | |
3697 | else | |
3698 | data = end; | |
84102ebc VA |
3699 | return data; |
3700 | } | |
3701 | ||
3702 | static void | |
3703 | read_bases (abbrev_entry * entry, | |
3704 | unsigned char * data, | |
3705 | unsigned char * end, | |
3706 | int64_t pointer_size, | |
3707 | uint64_t offset_size, | |
3708 | int dwarf_version, | |
3709 | debug_info * debug_info_p) | |
3710 | { | |
3711 | abbrev_attr *attr; | |
3712 | ||
3713 | for (attr = entry->first_attr; | |
3714 | attr && attr->attribute; | |
3715 | attr = attr->next) | |
3716 | { | |
3717 | uint64_t uvalue; | |
3718 | ||
3719 | if (attr->attribute == DW_AT_rnglists_base) | |
3720 | { | |
3721 | if (attr->form == DW_FORM_sec_offset) | |
3722 | { | |
3723 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
3724 | debug_info_p->rnglists_base = uvalue; | |
3725 | } | |
3726 | else | |
3727 | warn (_("Unexpected form of DW_AT_rnglists_base in the top DIE\n")); | |
3728 | } | |
4b8c2aaf AM |
3729 | else if (attr->attribute == DW_AT_addr_base |
3730 | || attr->attribute == DW_AT_GNU_addr_base) | |
84102ebc VA |
3731 | { |
3732 | if (attr->form == DW_FORM_sec_offset) | |
3733 | { | |
3734 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
3735 | debug_info_p->addr_base = uvalue; | |
3736 | } | |
3737 | else | |
3738 | warn (_("Unexpected form of DW_AT_addr_base in the top DIE\n")); | |
3739 | } | |
3740 | else | |
b05efa39 VA |
3741 | data = skip_attribute (attr->form, data, end, pointer_size, |
3742 | offset_size, dwarf_version); | |
84102ebc VA |
3743 | } |
3744 | } | |
3745 | ||
d85bf2ba NC |
3746 | /* Process the contents of a .debug_info section. |
3747 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3748 | and we do not want to display anything to the user. | |
3749 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3750 | a .debug_info section. | |
3751 | The information displayed is restricted by the values in DWARF_START_DIE | |
3752 | and DWARF_CUTOFF_LEVEL. | |
3753 | Returns TRUE upon success. Otherwise an error or warning message is | |
3754 | printed and FALSE is returned. */ | |
19e6b90e | 3755 | |
015dc7e1 AM |
3756 | static bool |
3757 | process_debug_info (struct dwarf_section * section, | |
3758 | void *file, | |
3759 | enum dwarf_section_display_enum abbrev_sec, | |
3760 | bool do_loc, | |
3761 | bool do_types) | |
19e6b90e L |
3762 | { |
3763 | unsigned char *start = section->start; | |
3764 | unsigned char *end = start + section->size; | |
3765 | unsigned char *section_begin; | |
3766 | unsigned int unit; | |
3767 | unsigned int num_units = 0; | |
3768 | ||
edba4e4a AM |
3769 | /* First scan the section to get the number of comp units. |
3770 | Length sanity checks are done here. */ | |
3771 | for (section_begin = start, num_units = 0; section_begin < end; | |
3772 | num_units ++) | |
19e6b90e | 3773 | { |
31e5a3a3 | 3774 | uint64_t length; |
19e6b90e | 3775 | |
edba4e4a AM |
3776 | /* Read the first 4 bytes. For a 32-bit DWARF section, this |
3777 | will be the length. For a 64-bit DWARF section, it'll be | |
3778 | the escape code 0xffffffff followed by an 8 byte length. */ | |
3779 | SAFE_BYTE_GET_AND_INC (length, section_begin, 4, end); | |
aca88567 | 3780 | |
edba4e4a AM |
3781 | if (length == 0xffffffff) |
3782 | SAFE_BYTE_GET_AND_INC (length, section_begin, 8, end); | |
3783 | else if (length >= 0xfffffff0 && length < 0xffffffff) | |
3784 | { | |
31e5a3a3 AM |
3785 | warn (_("Reserved length value (%#" PRIx64 ") found in section %s\n"), |
3786 | length, section->name); | |
edba4e4a | 3787 | return false; |
19e6b90e L |
3788 | } |
3789 | ||
edba4e4a AM |
3790 | /* Negative values are illegal, they may even cause infinite |
3791 | looping. This can happen if we can't accurately apply | |
3792 | relocations to an object file, or if the file is corrupt. */ | |
3793 | if (length > (size_t) (end - section_begin)) | |
19e6b90e | 3794 | { |
31e5a3a3 AM |
3795 | warn (_("Corrupt unit length (got %#" PRIx64 |
3796 | " expected at most %#tx) in section %s\n"), | |
3797 | length, end - section_begin, section->name); | |
015dc7e1 | 3798 | return false; |
19e6b90e | 3799 | } |
edba4e4a AM |
3800 | section_begin += length; |
3801 | } | |
3802 | ||
3803 | if (num_units == 0) | |
3804 | { | |
3805 | error (_("No comp units in %s section ?\n"), section->name); | |
3806 | return false; | |
3807 | } | |
3808 | ||
f18acc9c | 3809 | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) |
e51fdff7 AM |
3810 | && alloc_num_debug_info_entries == 0 |
3811 | && !do_types) | |
edba4e4a | 3812 | { |
19e6b90e | 3813 | /* Then allocate an array to hold the information. */ |
e51fdff7 | 3814 | debug_information = cmalloc (num_units, sizeof (*debug_information)); |
19e6b90e L |
3815 | if (debug_information == NULL) |
3816 | { | |
f41e4712 | 3817 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3818 | num_units); |
82b1b41b | 3819 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
015dc7e1 | 3820 | return false; |
19e6b90e | 3821 | } |
d85bf2ba | 3822 | |
03a91817 NC |
3823 | /* PR 17531: file: 92ca3797. |
3824 | We cannot rely upon the debug_information array being initialised | |
3825 | before it is used. A corrupt file could easily contain references | |
3826 | to a unit for which information has not been made available. So | |
3827 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3828 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3829 | ||
82b1b41b | 3830 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3831 | } |
3832 | ||
3833 | if (!do_loc) | |
3834 | { | |
dda8d76d NC |
3835 | load_debug_section_with_follow (str, file); |
3836 | load_debug_section_with_follow (line_str, file); | |
3837 | load_debug_section_with_follow (str_dwo, file); | |
3838 | load_debug_section_with_follow (str_index, file); | |
3839 | load_debug_section_with_follow (str_index_dwo, file); | |
3840 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e | 3841 | } |
521d4b19 | 3842 | |
dda8d76d | 3843 | load_debug_section_with_follow (abbrev_sec, file); |
19c26da6 NC |
3844 | load_debug_section_with_follow (loclists, file); |
3845 | load_debug_section_with_follow (rnglists, file); | |
4694a0e5 BK |
3846 | load_debug_section_with_follow (loclists_dwo, file); |
3847 | load_debug_section_with_follow (rnglists_dwo, file); | |
3848 | ||
6f875884 | 3849 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3850 | { |
3851 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3852 | debug_displays [abbrev_sec].section.uncompressed_name); |
015dc7e1 | 3853 | return false; |
19e6b90e L |
3854 | } |
3855 | ||
dda8d76d | 3856 | if (!do_loc && dwarf_start_die == 0) |
015dc7e1 | 3857 | introduce (section, false); |
bcd213b2 NC |
3858 | |
3859 | free_all_abbrevs (); | |
521d4b19 | 3860 | |
175b9150 | 3861 | /* In order to be able to resolve DW_FORM_ref_addr forms we need |
bcd213b2 NC |
3862 | to load *all* of the abbrevs for all CUs in this .debug_info |
3863 | section. This does effectively mean that we (partially) read | |
3864 | every CU header twice. */ | |
3865 | for (section_begin = start; start < end;) | |
3866 | { | |
31e5a3a3 AM |
3867 | DWARF2_Internal_CompUnit compunit; |
3868 | unsigned char *hdrptr; | |
3869 | uint64_t abbrev_base; | |
3870 | size_t abbrev_size; | |
3871 | uint64_t cu_offset; | |
3872 | unsigned int offset_size; | |
3873 | struct cu_tu_set *this_set; | |
edba4e4a | 3874 | unsigned char *end_cu; |
bcd213b2 NC |
3875 | |
3876 | hdrptr = start; | |
edba4e4a | 3877 | cu_offset = start - section_begin; |
bcd213b2 NC |
3878 | |
3879 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); | |
3880 | ||
3881 | if (compunit.cu_length == 0xffffffff) | |
3882 | { | |
3883 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); | |
3884 | offset_size = 8; | |
bcd213b2 NC |
3885 | } |
3886 | else | |
edba4e4a AM |
3887 | offset_size = 4; |
3888 | end_cu = hdrptr + compunit.cu_length; | |
bcd213b2 | 3889 | |
edba4e4a | 3890 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu); |
bcd213b2 NC |
3891 | |
3892 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); | |
3893 | ||
3894 | if (compunit.cu_version < 5) | |
3895 | { | |
3896 | compunit.cu_unit_type = DW_UT_compile; | |
3897 | /* Initialize it due to a false compiler warning. */ | |
3898 | compunit.cu_pointer_size = -1; | |
3899 | } | |
3900 | else | |
3901 | { | |
edba4e4a | 3902 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu); |
bcd213b2 NC |
3903 | do_types = (compunit.cu_unit_type == DW_UT_type); |
3904 | ||
edba4e4a | 3905 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
bcd213b2 NC |
3906 | } |
3907 | ||
edba4e4a AM |
3908 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, |
3909 | end_cu); | |
bcd213b2 | 3910 | |
9b87f84a TV |
3911 | if (compunit.cu_unit_type == DW_UT_split_compile |
3912 | || compunit.cu_unit_type == DW_UT_skeleton) | |
3913 | { | |
3914 | uint64_t dwo_id; | |
edba4e4a | 3915 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu); |
9b87f84a TV |
3916 | } |
3917 | ||
76868f36 L |
3918 | if (this_set == NULL) |
3919 | { | |
3920 | abbrev_base = 0; | |
3921 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3922 | } | |
3923 | else | |
3924 | { | |
3925 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3926 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3927 | } | |
3928 | ||
f07c08e1 AM |
3929 | abbrev_list *list; |
3930 | abbrev_list *free_list; | |
3931 | list = find_and_process_abbrev_set (&debug_displays[abbrev_sec].section, | |
3932 | abbrev_base, abbrev_size, | |
3933 | compunit.cu_abbrev_offset, | |
3934 | &free_list); | |
edba4e4a | 3935 | start = end_cu; |
f07c08e1 AM |
3936 | if (list != NULL && list->first_abbrev != NULL) |
3937 | record_abbrev_list_for_cu (cu_offset, start - section_begin, | |
3938 | list, free_list); | |
3939 | else if (free_list != NULL) | |
3940 | free_abbrev_list (free_list); | |
bcd213b2 NC |
3941 | } |
3942 | ||
3943 | for (start = section_begin, unit = 0; start < end; unit++) | |
19e6b90e L |
3944 | { |
3945 | DWARF2_Internal_CompUnit compunit; | |
3946 | unsigned char *hdrptr; | |
19e6b90e | 3947 | unsigned char *tags; |
fd2f0033 | 3948 | int level, last_level, saved_level; |
31e5a3a3 | 3949 | uint64_t cu_offset; |
bf5117e3 | 3950 | unsigned int offset_size; |
31e5a3a3 AM |
3951 | uint64_t signature = 0; |
3952 | uint64_t type_offset = 0; | |
341f9135 | 3953 | struct cu_tu_set *this_set; |
31e5a3a3 | 3954 | uint64_t abbrev_base; |
341f9135 | 3955 | size_t abbrev_size; |
edba4e4a | 3956 | unsigned char *end_cu; |
19e6b90e L |
3957 | |
3958 | hdrptr = start; | |
edba4e4a | 3959 | cu_offset = start - section_begin; |
19e6b90e | 3960 | |
0c588247 | 3961 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3962 | |
3963 | if (compunit.cu_length == 0xffffffff) | |
3964 | { | |
0c588247 | 3965 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e | 3966 | offset_size = 8; |
19e6b90e L |
3967 | } |
3968 | else | |
edba4e4a AM |
3969 | offset_size = 4; |
3970 | end_cu = hdrptr + compunit.cu_length; | |
19e6b90e | 3971 | |
edba4e4a | 3972 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu); |
19e6b90e | 3973 | |
341f9135 CC |
3974 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3975 | ||
77145576 JK |
3976 | if (compunit.cu_version < 5) |
3977 | { | |
3978 | compunit.cu_unit_type = DW_UT_compile; | |
3979 | /* Initialize it due to a false compiler warning. */ | |
3980 | compunit.cu_pointer_size = -1; | |
3981 | } | |
3982 | else | |
3983 | { | |
edba4e4a | 3984 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu); |
77145576 JK |
3985 | do_types = (compunit.cu_unit_type == DW_UT_type); |
3986 | ||
edba4e4a | 3987 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
77145576 JK |
3988 | } |
3989 | ||
edba4e4a | 3990 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end_cu); |
19e6b90e | 3991 | |
341f9135 CC |
3992 | if (this_set == NULL) |
3993 | { | |
3994 | abbrev_base = 0; | |
3995 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3996 | } | |
3997 | else | |
3998 | { | |
3999 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
4000 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
4001 | } | |
4002 | ||
77145576 | 4003 | if (compunit.cu_version < 5) |
edba4e4a | 4004 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
77145576 | 4005 | |
015dc7e1 | 4006 | bool do_dwo_id = false; |
e6ca1878 | 4007 | uint64_t dwo_id = 0; |
9b87f84a TV |
4008 | if (compunit.cu_unit_type == DW_UT_split_compile |
4009 | || compunit.cu_unit_type == DW_UT_skeleton) | |
4010 | { | |
edba4e4a | 4011 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu); |
015dc7e1 | 4012 | do_dwo_id = true; |
9b87f84a TV |
4013 | } |
4014 | ||
f41e4712 NC |
4015 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
4016 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
4017 | { | |
4018 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
4019 | compunit.cu_pointer_size, offset_size); | |
4020 | compunit.cu_pointer_size = offset_size; | |
4021 | } | |
2b6f5997 CC |
4022 | |
4023 | if (do_types) | |
b4eb7656 | 4024 | { |
edba4e4a AM |
4025 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, end_cu); |
4026 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end_cu); | |
b4eb7656 | 4027 | } |
2b6f5997 | 4028 | |
edba4e4a | 4029 | if (dwarf_start_die >= (size_t) (end_cu - section_begin)) |
ae7e7825 | 4030 | { |
edba4e4a | 4031 | start = end_cu; |
ae7e7825 NC |
4032 | continue; |
4033 | } | |
4034 | ||
f18acc9c | 4035 | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) |
2b6f5997 | 4036 | && num_debug_info_entries == 0 |
c4b2f181 | 4037 | && alloc_num_debug_info_entries > unit |
2b6f5997 | 4038 | && ! do_types) |
19e6b90e | 4039 | { |
450da4bd AM |
4040 | free_debug_information (&debug_information[unit]); |
4041 | memset (&debug_information[unit], 0, sizeof (*debug_information)); | |
4042 | debug_information[unit].pointer_size = compunit.cu_pointer_size; | |
4043 | debug_information[unit].offset_size = offset_size; | |
4044 | debug_information[unit].dwarf_version = compunit.cu_version; | |
4045 | debug_information[unit].cu_offset = cu_offset; | |
4046 | debug_information[unit].addr_base = DEBUG_INFO_UNAVAILABLE; | |
4047 | debug_information[unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
4048 | } |
4049 | ||
fd2f0033 | 4050 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 4051 | { |
cc443420 | 4052 | printf (_(" Compilation Unit @ offset %#" PRIx64 ":\n"), |
31e5a3a3 | 4053 | cu_offset); |
cc443420 | 4054 | printf (_(" Length: %#" PRIx64 " (%s)\n"), |
31e5a3a3 | 4055 | compunit.cu_length, |
49e7b350 | 4056 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 4057 | printf (_(" Version: %d\n"), compunit.cu_version); |
debd1a62 | 4058 | if (compunit.cu_version >= 5) |
4896932e MF |
4059 | { |
4060 | const char *name = get_DW_UT_name (compunit.cu_unit_type); | |
4061 | ||
4062 | printf (_(" Unit Type: %s (%x)\n"), | |
b1f1cefd | 4063 | null_name (name), |
4896932e MF |
4064 | compunit.cu_unit_type); |
4065 | } | |
cc443420 | 4066 | printf (_(" Abbrev Offset: %#" PRIx64 "\n"), |
31e5a3a3 | 4067 | compunit.cu_abbrev_offset); |
19e6b90e | 4068 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
4069 | if (do_types) |
4070 | { | |
cc443420 AM |
4071 | printf (_(" Signature: %#" PRIx64 "\n"), signature); |
4072 | printf (_(" Type Offset: %#" PRIx64 "\n"), type_offset); | |
2b6f5997 | 4073 | } |
d60f7998 | 4074 | if (do_dwo_id) |
cc443420 | 4075 | printf (_(" DWO ID: %#" PRIx64 "\n"), dwo_id); |
341f9135 CC |
4076 | if (this_set != NULL) |
4077 | { | |
31e5a3a3 | 4078 | uint64_t *offsets = this_set->section_offsets; |
341f9135 CC |
4079 | size_t *sizes = this_set->section_sizes; |
4080 | ||
4081 | printf (_(" Section contributions:\n")); | |
cc443420 | 4082 | printf (_(" .debug_abbrev.dwo: %#" PRIx64 " %#zx\n"), |
31e5a3a3 | 4083 | offsets[DW_SECT_ABBREV], sizes[DW_SECT_ABBREV]); |
cc443420 | 4084 | printf (_(" .debug_line.dwo: %#" PRIx64 " %#zx\n"), |
31e5a3a3 | 4085 | offsets[DW_SECT_LINE], sizes[DW_SECT_LINE]); |
cc443420 | 4086 | printf (_(" .debug_loc.dwo: %#" PRIx64 " %#zx\n"), |
31e5a3a3 | 4087 | offsets[DW_SECT_LOC], sizes[DW_SECT_LOC]); |
cc443420 | 4088 | printf (_(" .debug_str_offsets.dwo: %#" PRIx64 " %#zx\n"), |
31e5a3a3 | 4089 | offsets[DW_SECT_STR_OFFSETS], sizes[DW_SECT_STR_OFFSETS]); |
341f9135 | 4090 | } |
19e6b90e L |
4091 | } |
4092 | ||
460c89ff | 4093 | tags = hdrptr; |
edba4e4a | 4094 | start = end_cu; |
460c89ff | 4095 | |
77145576 | 4096 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 4097 | { |
31e5a3a3 | 4098 | warn (_("CU at offset %#" PRIx64 " contains corrupt or " |
47704ddf | 4099 | "unsupported version number: %d.\n"), |
31e5a3a3 | 4100 | cu_offset, compunit.cu_version); |
19e6b90e L |
4101 | continue; |
4102 | } | |
4103 | ||
77145576 | 4104 | if (compunit.cu_unit_type != DW_UT_compile |
ec47b32a | 4105 | && compunit.cu_unit_type != DW_UT_partial |
9b87f84a TV |
4106 | && compunit.cu_unit_type != DW_UT_type |
4107 | && compunit.cu_unit_type != DW_UT_split_compile | |
4108 | && compunit.cu_unit_type != DW_UT_skeleton) | |
77145576 | 4109 | { |
31e5a3a3 | 4110 | warn (_("CU at offset %#" PRIx64 " contains corrupt or " |
77145576 | 4111 | "unsupported unit type: %d.\n"), |
31e5a3a3 | 4112 | cu_offset, compunit.cu_unit_type); |
77145576 JK |
4113 | continue; |
4114 | } | |
4115 | ||
d493b283 | 4116 | /* Process the abbrevs used by this compilation unit. */ |
f07c08e1 AM |
4117 | abbrev_list *list; |
4118 | list = find_and_process_abbrev_set (&debug_displays[abbrev_sec].section, | |
4119 | abbrev_base, abbrev_size, | |
4120 | compunit.cu_abbrev_offset, NULL); | |
19e6b90e | 4121 | level = 0; |
fd2f0033 TT |
4122 | last_level = level; |
4123 | saved_level = -1; | |
19e6b90e L |
4124 | while (tags < start) |
4125 | { | |
19e6b90e | 4126 | unsigned long abbrev_number; |
ec4d4525 | 4127 | unsigned long die_offset; |
19e6b90e L |
4128 | abbrev_entry *entry; |
4129 | abbrev_attr *attr; | |
fd2f0033 | 4130 | int do_printing = 1; |
19e6b90e | 4131 | |
ec4d4525 NC |
4132 | die_offset = tags - section_begin; |
4133 | ||
cd30bcef | 4134 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 4135 | |
eb7cc021 JK |
4136 | /* A null DIE marks the end of a list of siblings or it may also be |
4137 | a section padding. */ | |
19e6b90e L |
4138 | if (abbrev_number == 0) |
4139 | { | |
eb7cc021 JK |
4140 | /* Check if it can be a section padding for the last CU. */ |
4141 | if (level == 0 && start == end) | |
4142 | { | |
4143 | unsigned char *chk; | |
4144 | ||
4145 | for (chk = tags; chk < start; chk++) | |
4146 | if (*chk != 0) | |
4147 | break; | |
4148 | if (chk == start) | |
4149 | break; | |
4150 | } | |
4151 | ||
4337774f TT |
4152 | if (!do_loc && die_offset >= dwarf_start_die |
4153 | && (dwarf_cutoff_level == -1 | |
4154 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
4155 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
4156 | level, die_offset); | |
4157 | ||
19e6b90e | 4158 | --level; |
ec4d4525 NC |
4159 | if (level < 0) |
4160 | { | |
4161 | static unsigned num_bogus_warns = 0; | |
4162 | ||
4163 | if (num_bogus_warns < 3) | |
4164 | { | |
4723351a CC |
4165 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
4166 | die_offset, section->name); | |
ec4d4525 NC |
4167 | num_bogus_warns ++; |
4168 | if (num_bogus_warns == 3) | |
4169 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
4170 | } | |
4171 | } | |
fd2f0033 | 4172 | if (dwarf_start_die != 0 && level < saved_level) |
02838630 AM |
4173 | { |
4174 | if (list != NULL) | |
4175 | free_abbrev_list (list); | |
4176 | return true; | |
4177 | } | |
19e6b90e L |
4178 | continue; |
4179 | } | |
4180 | ||
4b78141a | 4181 | if (!do_loc) |
fd2f0033 TT |
4182 | { |
4183 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
4184 | do_printing = 0; | |
4185 | else | |
4186 | { | |
4187 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
4188 | saved_level = level; | |
4189 | do_printing = (dwarf_cutoff_level == -1 | |
4190 | || level < dwarf_cutoff_level); | |
4191 | if (do_printing) | |
4192 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
4193 | level, die_offset, abbrev_number); | |
4194 | else if (dwarf_cutoff_level == -1 | |
4195 | || last_level < dwarf_cutoff_level) | |
4196 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
4197 | last_level = level; | |
4198 | } | |
4199 | } | |
cecf136e | 4200 | |
19e6b90e L |
4201 | /* Scan through the abbreviation list until we reach the |
4202 | correct entry. */ | |
175b9150 AM |
4203 | entry = NULL; |
4204 | if (list != NULL) | |
4205 | for (entry = list->first_abbrev; entry != NULL; entry = entry->next) | |
4206 | if (entry->number == abbrev_number) | |
4207 | break; | |
bcd213b2 | 4208 | |
19e6b90e L |
4209 | if (entry == NULL) |
4210 | { | |
fd2f0033 | 4211 | if (!do_loc && do_printing) |
4b78141a NC |
4212 | { |
4213 | printf ("\n"); | |
4214 | fflush (stdout); | |
4215 | } | |
31e5a3a3 | 4216 | warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 4217 | die_offset, abbrev_number); |
02838630 AM |
4218 | if (list != NULL) |
4219 | free_abbrev_list (list); | |
015dc7e1 | 4220 | return false; |
19e6b90e L |
4221 | } |
4222 | ||
fd2f0033 | 4223 | if (!do_loc && do_printing) |
cc5914eb | 4224 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 4225 | |
19e6b90e L |
4226 | switch (entry->tag) |
4227 | { | |
4228 | default: | |
4229 | need_base_address = 0; | |
4230 | break; | |
4231 | case DW_TAG_compile_unit: | |
40711542 | 4232 | case DW_TAG_skeleton_unit: |
175b9150 | 4233 | need_base_address = 1; |
d85bf2ba | 4234 | need_dwo_info = do_loc; |
19e6b90e L |
4235 | break; |
4236 | case DW_TAG_entry_point: | |
19e6b90e L |
4237 | need_base_address = 0; |
4238 | /* Assuming that there is no DW_AT_frame_base. */ | |
4239 | have_frame_base = 0; | |
4240 | break; | |
b05efa39 VA |
4241 | case DW_TAG_subprogram: |
4242 | need_base_address = 0; | |
cb1861cb AM |
4243 | if (level <= frame_base_level) |
4244 | /* Don't reset that for nested subprogram. */ | |
4245 | have_frame_base = 0; | |
b05efa39 | 4246 | break; |
19e6b90e L |
4247 | } |
4248 | ||
cb1861cb AM |
4249 | debug_info *debug_info_p = ((debug_information |
4250 | && unit < alloc_num_debug_info_entries) | |
4251 | ? debug_information + unit : NULL); | |
9f272209 AO |
4252 | |
4253 | assert (!debug_info_p | |
4254 | || (debug_info_p->num_loc_offsets | |
4255 | == debug_info_p->num_loc_views)); | |
4256 | ||
b05efa39 VA |
4257 | /* Look ahead so that the values of DW_AT_rnglists_base, |
4258 | DW_AT_[GNU_]addr_base are available before attributes that | |
4259 | reference them are parsed in the same DIE. | |
84102ebc | 4260 | Only needed for the top DIE on DWARFv5+. |
b05efa39 VA |
4261 | No simiar treatment for loclists_base because there should |
4262 | be no loclist attributes in top DIE. */ | |
0f8adbf7 | 4263 | if (debug_info_p && compunit.cu_version >= 5 && level == 0) |
84102ebc VA |
4264 | { |
4265 | int64_t stemp; | |
4266 | ||
4267 | read_bases (entry, | |
4268 | tags, | |
4269 | start, | |
4270 | compunit.cu_pointer_size, | |
4271 | offset_size, | |
4272 | compunit.cu_version, | |
4273 | debug_info_p); | |
4274 | ||
0f8adbf7 AM |
4275 | /* This check was in place before, keep it. */ |
4276 | stemp = debug_info_p->rnglists_base; | |
4277 | if (stemp < 0) | |
84102ebc | 4278 | { |
0f8adbf7 | 4279 | warn (_("CU @ %#" PRIx64 " has has a negative rnglists_base " |
2b34e067 | 4280 | "value of %#" PRIx64 " - treating as zero\n"), |
0f8adbf7 AM |
4281 | debug_info_p->cu_offset, stemp); |
4282 | debug_info_p->rnglists_base = 0; | |
84102ebc VA |
4283 | } |
4284 | } | |
4285 | ||
399c99f7 L |
4286 | for (attr = entry->first_attr; |
4287 | attr && attr->attribute; | |
4288 | attr = attr->next) | |
4b78141a | 4289 | { |
fd2f0033 | 4290 | if (! do_loc && do_printing) |
4b78141a | 4291 | /* Show the offset from where the tag was extracted. */ |
31e5a3a3 | 4292 | printf (" <%tx>", tags - section_begin); |
4b78141a NC |
4293 | tags = read_and_display_attr (attr->attribute, |
4294 | attr->form, | |
77145576 | 4295 | attr->implicit_const, |
ec1b0fbb | 4296 | section_begin, |
341f9135 | 4297 | tags, |
edba4e4a | 4298 | start, |
341f9135 | 4299 | cu_offset, |
4b78141a NC |
4300 | compunit.cu_pointer_size, |
4301 | offset_size, | |
4302 | compunit.cu_version, | |
9f272209 | 4303 | debug_info_p, |
341f9135 CC |
4304 | do_loc || ! do_printing, |
4305 | section, | |
ec1b0fbb NC |
4306 | this_set, |
4307 | level); | |
4b78141a | 4308 | } |
cecf136e | 4309 | |
9f272209 AO |
4310 | /* If a locview attribute appears before a location one, |
4311 | make sure we don't associate it with an earlier | |
4312 | loclist. */ | |
4313 | if (debug_info_p) | |
4314 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
4315 | { | |
4316 | case 1: | |
31e5a3a3 | 4317 | debug_info_p->loc_views [debug_info_p->num_loc_views] = -1; |
9f272209 AO |
4318 | debug_info_p->num_loc_views++; |
4319 | assert (debug_info_p->num_loc_views | |
4320 | == debug_info_p->num_loc_offsets); | |
4321 | break; | |
4322 | ||
4323 | case 0: | |
4324 | break; | |
4325 | ||
4326 | case -1: | |
b05efa39 | 4327 | warn (_("DIE has locviews without loclist\n")); |
9f272209 AO |
4328 | debug_info_p->num_loc_views--; |
4329 | break; | |
4330 | ||
4331 | default: | |
4332 | assert (0); | |
cb1861cb | 4333 | } |
9f272209 | 4334 | |
b4eb7656 AM |
4335 | if (entry->children) |
4336 | ++level; | |
4337 | } | |
f07c08e1 AM |
4338 | if (list != NULL) |
4339 | free_abbrev_list (list); | |
19e6b90e | 4340 | } |
cecf136e | 4341 | |
19e6b90e L |
4342 | /* Set num_debug_info_entries here so that it can be used to check if |
4343 | we need to process .debug_loc and .debug_ranges sections. */ | |
f18acc9c | 4344 | if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) |
2b6f5997 CC |
4345 | && num_debug_info_entries == 0 |
4346 | && ! do_types) | |
82b1b41b | 4347 | { |
b4eb7656 | 4348 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
4349 | num_debug_info_entries = alloc_num_debug_info_entries; |
4350 | else | |
4351 | num_debug_info_entries = num_units; | |
4352 | } | |
cecf136e | 4353 | |
19e6b90e | 4354 | if (!do_loc) |
467c65bc | 4355 | printf ("\n"); |
cecf136e | 4356 | |
015dc7e1 | 4357 | return true; |
19e6b90e L |
4358 | } |
4359 | ||
4360 | /* Locate and scan the .debug_info section in the file and record the pointer | |
4361 | sizes and offsets for the compilation units in it. Usually an executable | |
4362 | will have just one pointer size, but this is not guaranteed, and so we try | |
4363 | not to make any assumptions. Returns zero upon failure, or the number of | |
4364 | compilation units upon success. */ | |
4365 | ||
4366 | static unsigned int | |
4367 | load_debug_info (void * file) | |
4368 | { | |
1febe64d | 4369 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 4370 | section then do not bother to repeat the task. */ |
cc86f28f | 4371 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
4372 | return 0; |
4373 | ||
19e6b90e L |
4374 | /* If we already have the information there is nothing else to do. */ |
4375 | if (num_debug_info_entries > 0) | |
4376 | return num_debug_info_entries; | |
4377 | ||
341f9135 | 4378 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 4379 | (void) load_cu_tu_indexes (file); |
341f9135 | 4380 | |
dda8d76d | 4381 | if (load_debug_section_with_follow (info, file) |
015dc7e1 | 4382 | && process_debug_info (&debug_displays [info].section, file, abbrev, true, false)) |
19e6b90e | 4383 | return num_debug_info_entries; |
82b1b41b | 4384 | |
dda8d76d | 4385 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 4386 | && process_debug_info (&debug_displays [info_dwo].section, file, |
015dc7e1 | 4387 | abbrev_dwo, true, false)) |
4723351a | 4388 | return num_debug_info_entries; |
1febe64d | 4389 | |
cc86f28f | 4390 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 4391 | return 0; |
19e6b90e L |
4392 | } |
4393 | ||
b40bf0a2 NC |
4394 | /* Read a DWARF .debug_line section header starting at DATA. |
4395 | Upon success returns an updated DATA pointer and the LINFO | |
4396 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
4397 | Otherwise returns NULL. */ | |
19e6b90e | 4398 | |
b40bf0a2 NC |
4399 | static unsigned char * |
4400 | read_debug_line_header (struct dwarf_section * section, | |
4401 | unsigned char * data, | |
4402 | unsigned char * end, | |
4403 | DWARF2_Internal_LineInfo * linfo, | |
4404 | unsigned char ** end_of_sequence) | |
4405 | { | |
4406 | unsigned char *hdrptr; | |
19e6b90e | 4407 | |
b40bf0a2 NC |
4408 | /* Extract information from the Line Number Program Header. |
4409 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 4410 | hdrptr = data; |
19e6b90e | 4411 | |
b40bf0a2 NC |
4412 | /* Get and check the length of the block. */ |
4413 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 4414 | |
b40bf0a2 | 4415 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
4416 | { |
4417 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 4418 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 4419 | linfo->li_offset_size = 8; |
f41e4712 NC |
4420 | } |
4421 | else | |
37195e23 | 4422 | linfo->li_offset_size = 4; |
19e6b90e | 4423 | |
37195e23 | 4424 | if (linfo->li_length > (size_t) (end - hdrptr)) |
f41e4712 | 4425 | { |
8fcc61b4 NC |
4426 | /* If the length field has a relocation against it, then we should |
4427 | not complain if it is inaccurate (and probably negative). This | |
4428 | happens in object files when the .debug_line section is actually | |
4429 | comprised of several different .debug_line.* sections, (some of | |
4430 | which may be removed by linker garbage collection), and a relocation | |
4431 | is used to compute the correct length once that is done. */ | |
77145576 | 4432 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 4433 | { |
37195e23 | 4434 | linfo->li_length = end - hdrptr; |
b40bf0a2 NC |
4435 | } |
4436 | else | |
4437 | { | |
31e5a3a3 AM |
4438 | warn (_("The length field (%#" PRIx64 ")" |
4439 | " in the debug_line header is wrong" | |
4440 | " - the section is too small\n"), | |
4441 | linfo->li_length); | |
b40bf0a2 NC |
4442 | return NULL; |
4443 | } | |
f41e4712 | 4444 | } |
37195e23 | 4445 | end = hdrptr + linfo->li_length; |
19e6b90e | 4446 | |
b40bf0a2 NC |
4447 | /* Get and check the version number. */ |
4448 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
4449 | ||
4450 | if (linfo->li_version != 2 | |
4451 | && linfo->li_version != 3 | |
77145576 JK |
4452 | && linfo->li_version != 4 |
4453 | && linfo->li_version != 5) | |
f41e4712 | 4454 | { |
77145576 JK |
4455 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
4456 | "is currently supported.\n")); | |
b40bf0a2 | 4457 | return NULL; |
f41e4712 | 4458 | } |
19e6b90e | 4459 | |
77145576 JK |
4460 | if (linfo->li_version >= 5) |
4461 | { | |
5496f3c6 | 4462 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
77145576 | 4463 | |
5496f3c6 NC |
4464 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
4465 | if (linfo->li_segment_size != 0) | |
77145576 JK |
4466 | { |
4467 | warn (_("The %s section contains " | |
4468 | "unsupported segment selector size: %d.\n"), | |
5496f3c6 NC |
4469 | section->name, linfo->li_segment_size); |
4470 | return NULL; | |
77145576 JK |
4471 | } |
4472 | } | |
4473 | ||
4474 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
4475 | linfo->li_offset_size, end); | |
b40bf0a2 | 4476 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 4477 | |
b40bf0a2 | 4478 | if (linfo->li_version >= 4) |
f41e4712 | 4479 | { |
b40bf0a2 | 4480 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 4481 | |
b40bf0a2 | 4482 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
4483 | { |
4484 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 4485 | return NULL; |
a233b20c | 4486 | } |
f41e4712 NC |
4487 | } |
4488 | else | |
b40bf0a2 | 4489 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 4490 | |
b40bf0a2 | 4491 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 4492 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
4493 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
4494 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 4495 | |
37195e23 | 4496 | *end_of_sequence = end; |
b40bf0a2 NC |
4497 | return hdrptr; |
4498 | } | |
19e6b90e | 4499 | |
77145576 | 4500 | static unsigned char * |
015dc7e1 AM |
4501 | display_formatted_table (unsigned char *data, |
4502 | unsigned char *start, | |
4503 | unsigned char *end, | |
4504 | const DWARF2_Internal_LineInfo *linfo, | |
4505 | struct dwarf_section *section, | |
4506 | bool is_dir) | |
77145576 JK |
4507 | { |
4508 | unsigned char *format_start, format_count, *format, formati; | |
31e5a3a3 | 4509 | uint64_t data_count, datai; |
cd30bcef | 4510 | unsigned int namepass, last_entry = 0; |
5496f3c6 | 4511 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
521d4b19 | 4512 | |
77145576 | 4513 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
546cb2d8 NC |
4514 | if (do_checks && format_count > 5) |
4515 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), | |
4516 | table_name, format_count); | |
4517 | ||
77145576 JK |
4518 | format_start = data; |
4519 | for (formati = 0; formati < format_count; formati++) | |
4520 | { | |
cd30bcef AM |
4521 | SKIP_ULEB (data, end); |
4522 | SKIP_ULEB (data, end); | |
55b26492 | 4523 | if (data >= end) |
77145576 | 4524 | { |
5496f3c6 | 4525 | warn (_("%s: Corrupt format description entry\n"), table_name); |
77145576 JK |
4526 | return data; |
4527 | } | |
4528 | } | |
4529 | ||
cd30bcef | 4530 | READ_ULEB (data_count, data, end); |
546cb2d8 | 4531 | if (data_count == 0) |
77145576 | 4532 | { |
546cb2d8 | 4533 | printf (_("\n The %s is empty.\n"), table_name); |
77145576 JK |
4534 | return data; |
4535 | } | |
8032f75b AM |
4536 | else if (data >= end |
4537 | || data_count > (size_t) (end - data)) | |
77145576 | 4538 | { |
8032f75b | 4539 | warn (_("%s: Corrupt entry count %#" PRIx64 "\n"), table_name, data_count); |
77145576 JK |
4540 | return data; |
4541 | } | |
546cb2d8 | 4542 | |
5496f3c6 NC |
4543 | else if (format_count == 0) |
4544 | { | |
4545 | warn (_("%s: format count is zero, but the table is not empty\n"), | |
4546 | table_name); | |
4547 | return end; | |
4548 | } | |
77145576 | 4549 | |
cc443420 | 4550 | printf (_("\n The %s (offset %#tx, lines %" PRIu64 ", columns %u):\n"), |
31e5a3a3 | 4551 | table_name, data - start, data_count, format_count); |
77145576 JK |
4552 | |
4553 | printf (_(" Entry")); | |
521d4b19 | 4554 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4555 | for (namepass = 0; namepass < 2; namepass++) |
4556 | { | |
4557 | format = format_start; | |
4558 | for (formati = 0; formati < format_count; formati++) | |
4559 | { | |
31e5a3a3 | 4560 | uint64_t content_type; |
77145576 | 4561 | |
cd30bcef | 4562 | READ_ULEB (content_type, format, end); |
77145576 JK |
4563 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
4564 | switch (content_type) | |
4565 | { | |
4566 | case DW_LNCT_path: | |
4567 | printf (_("\tName")); | |
4568 | break; | |
4569 | case DW_LNCT_directory_index: | |
4570 | printf (_("\tDir")); | |
4571 | break; | |
4572 | case DW_LNCT_timestamp: | |
4573 | printf (_("\tTime")); | |
4574 | break; | |
4575 | case DW_LNCT_size: | |
4576 | printf (_("\tSize")); | |
4577 | break; | |
4578 | case DW_LNCT_MD5: | |
5496f3c6 | 4579 | printf (_("\tMD5\t\t\t")); |
77145576 JK |
4580 | break; |
4581 | default: | |
31e5a3a3 AM |
4582 | printf (_("\t(Unknown format content type %" PRIu64 ")"), |
4583 | content_type); | |
77145576 | 4584 | } |
cd30bcef | 4585 | SKIP_ULEB (format, end); |
77145576 JK |
4586 | } |
4587 | } | |
4588 | putchar ('\n'); | |
4589 | ||
4590 | for (datai = 0; datai < data_count; datai++) | |
4591 | { | |
4592 | unsigned char *datapass = data; | |
4593 | ||
4594 | printf (" %d", last_entry++); | |
521d4b19 | 4595 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4596 | for (namepass = 0; namepass < 2; namepass++) |
4597 | { | |
4598 | format = format_start; | |
4599 | data = datapass; | |
4600 | for (formati = 0; formati < format_count; formati++) | |
4601 | { | |
31e5a3a3 | 4602 | uint64_t content_type, form; |
77145576 | 4603 | |
cd30bcef AM |
4604 | READ_ULEB (content_type, format, end); |
4605 | READ_ULEB (form, format, end); | |
4606 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
4607 | 0, 0, linfo->li_offset_size, | |
77145576 JK |
4608 | linfo->li_version, NULL, |
4609 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 4610 | section, NULL, '\t', -1); |
77145576 JK |
4611 | } |
4612 | } | |
5496f3c6 | 4613 | |
55b26492 | 4614 | if (data >= end && (datai < data_count - 1)) |
77145576 | 4615 | { |
5496f3c6 | 4616 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
77145576 JK |
4617 | return data; |
4618 | } | |
4619 | putchar ('\n'); | |
4620 | } | |
4621 | return data; | |
4622 | } | |
4623 | ||
e38332c2 NC |
4624 | static int |
4625 | display_debug_sup (struct dwarf_section * section, | |
4626 | void * file ATTRIBUTE_UNUSED) | |
4627 | { | |
4628 | unsigned char * start = section->start; | |
4629 | unsigned char * end = section->start + section->size; | |
4630 | unsigned int version; | |
4631 | char is_supplementary; | |
4632 | const unsigned char * sup_filename; | |
4633 | size_t sup_filename_len; | |
4634 | unsigned int num_read; | |
4635 | int status; | |
31e5a3a3 | 4636 | uint64_t checksum_len; |
e38332c2 NC |
4637 | |
4638 | ||
015dc7e1 | 4639 | introduce (section, true); |
e38332c2 NC |
4640 | if (section->size < 4) |
4641 | { | |
4642 | error (_("corrupt .debug_sup section: size is too small\n")); | |
4643 | return 0; | |
4644 | } | |
4645 | ||
4646 | /* Read the data. */ | |
4647 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); | |
4648 | if (version < 5) | |
2b34e067 | 4649 | warn (_("corrupt .debug_sup section: version < 5\n")); |
e38332c2 NC |
4650 | |
4651 | SAFE_BYTE_GET_AND_INC (is_supplementary, start, 1, end); | |
4652 | if (is_supplementary != 0 && is_supplementary != 1) | |
175b9150 | 4653 | warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n")); |
e38332c2 NC |
4654 | |
4655 | sup_filename = start; | |
4656 | if (is_supplementary && sup_filename[0] != 0) | |
4657 | warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n")); | |
4658 | ||
4659 | sup_filename_len = strnlen ((const char *) start, end - start); | |
4660 | if (sup_filename_len == (size_t) (end - start)) | |
4661 | { | |
4662 | error (_("corrupt .debug_sup section: filename is not NUL terminated\n")); | |
4663 | return 0; | |
4664 | } | |
4665 | start += sup_filename_len + 1; | |
4666 | ||
015dc7e1 | 4667 | checksum_len = read_leb128 (start, end, false /* unsigned */, & num_read, & status); |
e38332c2 NC |
4668 | if (status) |
4669 | { | |
4670 | error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n")); | |
4671 | checksum_len = 0; | |
4672 | } | |
4673 | start += num_read; | |
31e5a3a3 | 4674 | if (checksum_len > (size_t) (end - start)) |
e38332c2 NC |
4675 | { |
4676 | error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n")); | |
4677 | checksum_len = end - start; | |
4678 | } | |
31e5a3a3 | 4679 | else if (checksum_len < (size_t) (end - start)) |
e38332c2 | 4680 | { |
31e5a3a3 AM |
4681 | warn (_("corrupt .debug_sup section: there are %#" PRIx64 |
4682 | " extra, unused bytes at the end of the section\n"), | |
4683 | (end - start) - checksum_len); | |
e38332c2 NC |
4684 | } |
4685 | ||
4686 | printf (_(" Version: %u\n"), version); | |
4687 | printf (_(" Is Supp: %u\n"), is_supplementary); | |
4688 | printf (_(" Filename: %s\n"), sup_filename); | |
31e5a3a3 | 4689 | printf (_(" Checksum Len: %" PRIu64 "\n"), checksum_len); |
e38332c2 NC |
4690 | if (checksum_len > 0) |
4691 | { | |
4692 | printf (_(" Checksum: ")); | |
4693 | while (checksum_len--) | |
4694 | printf ("0x%x ", * start++ ); | |
4695 | printf ("\n"); | |
4696 | } | |
4697 | return 1; | |
4698 | } | |
4699 | ||
b40bf0a2 | 4700 | static int |
dda8d76d NC |
4701 | display_debug_lines_raw (struct dwarf_section * section, |
4702 | unsigned char * data, | |
4703 | unsigned char * end, | |
4704 | void * file) | |
b40bf0a2 NC |
4705 | { |
4706 | unsigned char *start = section->start; | |
ba8826a8 | 4707 | int verbose_view = 0; |
19e6b90e | 4708 | |
015dc7e1 | 4709 | introduce (section, true); |
19e6b90e | 4710 | |
b40bf0a2 NC |
4711 | while (data < end) |
4712 | { | |
4713 | static DWARF2_Internal_LineInfo saved_linfo; | |
4714 | DWARF2_Internal_LineInfo linfo; | |
4715 | unsigned char *standard_opcodes; | |
4716 | unsigned char *end_of_sequence; | |
fe59e83d | 4717 | int i; |
19e6b90e | 4718 | |
24d127aa | 4719 | if (startswith (section->name, ".debug_line.") |
4925cdd7 NC |
4720 | /* Note: the following does not apply to .debug_line.dwo sections. |
4721 | These are full debug_line sections. */ | |
4722 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 4723 | { |
b40bf0a2 NC |
4724 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
4725 | section containing just the Line Number Statements. They are | |
4726 | created by the assembler and intended to be used alongside gcc's | |
4727 | -ffunction-sections command line option. When the linker's | |
4728 | garbage collection decides to discard a .text.<foo> section it | |
4729 | can then also discard the line number information in .debug_line.<foo>. | |
4730 | ||
4925cdd7 | 4731 | Since the section is a fragment it does not have the details |
b40bf0a2 | 4732 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 4733 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
4734 | end_of_sequence = end; |
4735 | standard_opcodes = NULL; | |
4736 | linfo = saved_linfo; | |
058037d3 NC |
4737 | /* PR 17531: file: 0522b371. */ |
4738 | if (linfo.li_line_range == 0) | |
4739 | { | |
1306a742 | 4740 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4741 | return 0; |
4742 | } | |
b40bf0a2 | 4743 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4744 | } |
19e6b90e L |
4745 | else |
4746 | { | |
b40bf0a2 | 4747 | unsigned char * hdrptr; |
19e6b90e | 4748 | |
b40bf0a2 NC |
4749 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4750 | & end_of_sequence)) == NULL) | |
4751 | return 0; | |
19e6b90e | 4752 | |
cc443420 | 4753 | printf (_(" Offset: %#tx\n"), data - start); |
31e5a3a3 | 4754 | printf (_(" Length: %" PRId64 "\n"), linfo.li_length); |
b40bf0a2 | 4755 | printf (_(" DWARF Version: %d\n"), linfo.li_version); |
5496f3c6 NC |
4756 | if (linfo.li_version >= 5) |
4757 | { | |
4758 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); | |
4759 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); | |
4760 | } | |
77ef8654 | 4761 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
4762 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
4763 | if (linfo.li_version >= 4) | |
4764 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
4765 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
4766 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4767 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4768 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 4769 | |
0a9d414a NC |
4770 | /* PR 17512: file: 1665-6428-0.004. */ |
4771 | if (linfo.li_line_range == 0) | |
4772 | { | |
4773 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4774 | linfo.li_line_range = 1; | |
4775 | } | |
77ef8654 | 4776 | |
b40bf0a2 | 4777 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4778 | |
b40bf0a2 NC |
4779 | /* Display the contents of the Opcodes table. */ |
4780 | standard_opcodes = hdrptr; | |
19e6b90e | 4781 | |
6937bb54 NC |
4782 | /* PR 17512: file: 002-417945-0.004. */ |
4783 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4784 | { | |
4785 | warn (_("Line Base extends beyond end of section\n")); | |
4786 | return 0; | |
4787 | } | |
4788 | ||
b40bf0a2 | 4789 | printf (_("\n Opcodes:\n")); |
19e6b90e | 4790 | |
b40bf0a2 | 4791 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
4792 | printf (ngettext (" Opcode %d has %d arg\n", |
4793 | " Opcode %d has %d args\n", | |
4794 | standard_opcodes[i - 1]), | |
4795 | i, standard_opcodes[i - 1]); | |
19e6b90e | 4796 | |
b40bf0a2 NC |
4797 | /* Display the contents of the Directory table. */ |
4798 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 4799 | |
77145576 | 4800 | if (linfo.li_version >= 5) |
b40bf0a2 | 4801 | { |
dda8d76d | 4802 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 4803 | |
77145576 | 4804 | data = display_formatted_table (data, start, end, &linfo, section, |
015dc7e1 | 4805 | true); |
77145576 | 4806 | data = display_formatted_table (data, start, end, &linfo, section, |
015dc7e1 | 4807 | false); |
77145576 JK |
4808 | } |
4809 | else | |
4810 | { | |
4811 | if (*data == 0) | |
4812 | printf (_("\n The Directory Table is empty.\n")); | |
4813 | else | |
a233b20c | 4814 | { |
77145576 | 4815 | unsigned int last_dir_entry = 0; |
6937bb54 | 4816 | |
cc443420 | 4817 | printf (_("\n The Directory Table (offset %#tx):\n"), |
31e5a3a3 | 4818 | data - start); |
19e6b90e | 4819 | |
77145576 JK |
4820 | while (data < end && *data != 0) |
4821 | { | |
4822 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 4823 | |
a7077ce7 AM |
4824 | data += strnlen ((char *) data, end - data); |
4825 | if (data < end) | |
4826 | data++; | |
77145576 | 4827 | } |
19e6b90e | 4828 | |
77145576 JK |
4829 | /* PR 17512: file: 002-132094-0.004. */ |
4830 | if (data >= end - 1) | |
4831 | break; | |
4832 | } | |
19e6b90e | 4833 | |
77145576 | 4834 | /* Skip the NUL at the end of the table. */ |
a7077ce7 AM |
4835 | if (data < end) |
4836 | data++; | |
19e6b90e | 4837 | |
77145576 | 4838 | /* Display the contents of the File Name table. */ |
a7077ce7 | 4839 | if (data >= end || *data == 0) |
77145576 JK |
4840 | printf (_("\n The File Name Table is empty.\n")); |
4841 | else | |
4842 | { | |
cc443420 | 4843 | printf (_("\n The File Name Table (offset %#tx):\n"), |
31e5a3a3 | 4844 | data - start); |
77145576 | 4845 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
19e6b90e | 4846 | |
77145576 | 4847 | while (data < end && *data != 0) |
b40bf0a2 | 4848 | { |
77145576 | 4849 | unsigned char *name; |
31e5a3a3 | 4850 | uint64_t val; |
77145576 JK |
4851 | |
4852 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4853 | name = data; | |
a7077ce7 AM |
4854 | data += strnlen ((char *) data, end - data); |
4855 | if (data < end) | |
4856 | data++; | |
77145576 | 4857 | |
cd30bcef | 4858 | READ_ULEB (val, data, end); |
31e5a3a3 | 4859 | printf ("%" PRIu64 "\t", val); |
cd30bcef | 4860 | READ_ULEB (val, data, end); |
31e5a3a3 | 4861 | printf ("%" PRIu64 "\t", val); |
cd30bcef | 4862 | READ_ULEB (val, data, end); |
31e5a3a3 | 4863 | printf ("%" PRIu64 "\t", val); |
77145576 JK |
4864 | printf ("%.*s\n", (int)(end - name), name); |
4865 | ||
55b26492 | 4866 | if (data >= end) |
77145576 JK |
4867 | { |
4868 | warn (_("Corrupt file name table entry\n")); | |
4869 | break; | |
4870 | } | |
b40bf0a2 | 4871 | } |
a233b20c | 4872 | } |
77145576 JK |
4873 | |
4874 | /* Skip the NUL at the end of the table. */ | |
a7077ce7 AM |
4875 | if (data < end) |
4876 | data++; | |
b40bf0a2 | 4877 | } |
19e6b90e | 4878 | |
b40bf0a2 NC |
4879 | putchar ('\n'); |
4880 | saved_linfo = linfo; | |
4881 | } | |
19e6b90e | 4882 | |
b40bf0a2 NC |
4883 | /* Now display the statements. */ |
4884 | if (data >= end_of_sequence) | |
4885 | printf (_(" No Line Number Statements.\n")); | |
4886 | else | |
4887 | { | |
4888 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4889 | |
b40bf0a2 NC |
4890 | while (data < end_of_sequence) |
4891 | { | |
4892 | unsigned char op_code; | |
329dd2b6 | 4893 | int adv; |
31e5a3a3 | 4894 | uint64_t uladv; |
19e6b90e | 4895 | |
31e5a3a3 | 4896 | printf (" [0x%08tx]", data - start); |
fe59e83d | 4897 | |
b40bf0a2 | 4898 | op_code = *data++; |
19e6b90e | 4899 | |
b40bf0a2 | 4900 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4901 | { |
b40bf0a2 NC |
4902 | op_code -= linfo.li_opcode_base; |
4903 | uladv = (op_code / linfo.li_line_range); | |
4904 | if (linfo.li_max_ops_per_insn == 1) | |
4905 | { | |
4906 | uladv *= linfo.li_min_insn_length; | |
4907 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4908 | if (uladv) |
4909 | state_machine_regs.view = 0; | |
b40bf0a2 | 4910 | printf (_(" Special opcode %d: " |
31e5a3a3 | 4911 | "advance Address by %" PRIu64 |
cc443420 | 4912 | " to %#" PRIx64 "%s"), |
31e5a3a3 | 4913 | op_code, uladv, state_machine_regs.address, |
ba8826a8 AO |
4914 | verbose_view && uladv |
4915 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4916 | } |
4917 | else | |
4918 | { | |
ba8826a8 AO |
4919 | unsigned addrdelta |
4920 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4921 | / linfo.li_max_ops_per_insn) |
4922 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4923 | |
4924 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4925 | state_machine_regs.op_index |
4926 | = (state_machine_regs.op_index + uladv) | |
4927 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4928 | if (addrdelta) |
4929 | state_machine_regs.view = 0; | |
b40bf0a2 | 4930 | printf (_(" Special opcode %d: " |
31e5a3a3 | 4931 | "advance Address by %" PRIu64 |
cc443420 | 4932 | " to %#" PRIx64 "[%d]%s"), |
31e5a3a3 | 4933 | op_code, uladv, state_machine_regs.address, |
ba8826a8 AO |
4934 | state_machine_regs.op_index, |
4935 | verbose_view && addrdelta | |
4936 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4937 | } |
4938 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4939 | state_machine_regs.line += adv; | |
329dd2b6 | 4940 | printf (_(" and Line by %d to %d"), |
31e5a3a3 | 4941 | adv, state_machine_regs.line); |
ba8826a8 AO |
4942 | if (verbose_view || state_machine_regs.view) |
4943 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4944 | else | |
4945 | putchar ('\n'); | |
4946 | state_machine_regs.view++; | |
19e6b90e | 4947 | } |
cd30bcef AM |
4948 | else |
4949 | switch (op_code) | |
4950 | { | |
4951 | case DW_LNS_extended_op: | |
4952 | data += process_extended_line_op (data, | |
4953 | linfo.li_default_is_stmt, | |
4954 | end); | |
4955 | break; | |
4956 | ||
4957 | case DW_LNS_copy: | |
4958 | printf (_(" Copy")); | |
4959 | if (verbose_view || state_machine_regs.view) | |
4960 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4961 | else | |
4962 | putchar ('\n'); | |
4963 | state_machine_regs.view++; | |
4964 | break; | |
4965 | ||
4966 | case DW_LNS_advance_pc: | |
4967 | READ_ULEB (uladv, data, end); | |
4968 | if (linfo.li_max_ops_per_insn == 1) | |
4969 | { | |
4970 | uladv *= linfo.li_min_insn_length; | |
4971 | state_machine_regs.address += uladv; | |
4972 | if (uladv) | |
4973 | state_machine_regs.view = 0; | |
31e5a3a3 | 4974 | printf (_(" Advance PC by %" PRIu64 |
cc443420 | 4975 | " to %#" PRIx64 "%s\n"), |
31e5a3a3 | 4976 | uladv, state_machine_regs.address, |
cd30bcef AM |
4977 | verbose_view && uladv |
4978 | ? _(" (reset view)") : ""); | |
4979 | } | |
4980 | else | |
4981 | { | |
4982 | unsigned addrdelta | |
4983 | = ((state_machine_regs.op_index + uladv) | |
4984 | / linfo.li_max_ops_per_insn) | |
4985 | * linfo.li_min_insn_length; | |
4986 | state_machine_regs.address | |
4987 | += addrdelta; | |
4988 | state_machine_regs.op_index | |
4989 | = (state_machine_regs.op_index + uladv) | |
4990 | % linfo.li_max_ops_per_insn; | |
4991 | if (addrdelta) | |
4992 | state_machine_regs.view = 0; | |
31e5a3a3 | 4993 | printf (_(" Advance PC by %" PRIu64 |
cc443420 | 4994 | " to %#" PRIx64 "[%d]%s\n"), |
31e5a3a3 | 4995 | uladv, state_machine_regs.address, |
cd30bcef AM |
4996 | state_machine_regs.op_index, |
4997 | verbose_view && addrdelta | |
4998 | ? _(" (reset view)") : ""); | |
4999 | } | |
5000 | break; | |
5001 | ||
5002 | case DW_LNS_advance_line: | |
5003 | READ_SLEB (adv, data, end); | |
5004 | state_machine_regs.line += adv; | |
329dd2b6 | 5005 | printf (_(" Advance Line by %d to %d\n"), |
31e5a3a3 | 5006 | adv, state_machine_regs.line); |
cd30bcef AM |
5007 | break; |
5008 | ||
5009 | case DW_LNS_set_file: | |
5010 | READ_ULEB (uladv, data, end); | |
31e5a3a3 AM |
5011 | printf (_(" Set File Name to entry %" PRIu64 |
5012 | " in the File Name Table\n"), uladv); | |
cd30bcef AM |
5013 | state_machine_regs.file = uladv; |
5014 | break; | |
5015 | ||
5016 | case DW_LNS_set_column: | |
5017 | READ_ULEB (uladv, data, end); | |
31e5a3a3 | 5018 | printf (_(" Set column to %" PRIu64 "\n"), uladv); |
cd30bcef AM |
5019 | state_machine_regs.column = uladv; |
5020 | break; | |
5021 | ||
5022 | case DW_LNS_negate_stmt: | |
5023 | adv = state_machine_regs.is_stmt; | |
5024 | adv = ! adv; | |
329dd2b6 | 5025 | printf (_(" Set is_stmt to %d\n"), adv); |
cd30bcef AM |
5026 | state_machine_regs.is_stmt = adv; |
5027 | break; | |
5028 | ||
5029 | case DW_LNS_set_basic_block: | |
5030 | printf (_(" Set basic block\n")); | |
5031 | state_machine_regs.basic_block = 1; | |
5032 | break; | |
5033 | ||
5034 | case DW_LNS_const_add_pc: | |
5035 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
5036 | if (linfo.li_max_ops_per_insn) | |
5037 | { | |
5038 | uladv *= linfo.li_min_insn_length; | |
5039 | state_machine_regs.address += uladv; | |
5040 | if (uladv) | |
5041 | state_machine_regs.view = 0; | |
31e5a3a3 | 5042 | printf (_(" Advance PC by constant %" PRIu64 |
cc443420 | 5043 | " to %#" PRIx64 "%s\n"), |
31e5a3a3 | 5044 | uladv, state_machine_regs.address, |
cd30bcef AM |
5045 | verbose_view && uladv |
5046 | ? _(" (reset view)") : ""); | |
5047 | } | |
5048 | else | |
5049 | { | |
5050 | unsigned addrdelta | |
5051 | = ((state_machine_regs.op_index + uladv) | |
5052 | / linfo.li_max_ops_per_insn) | |
5053 | * linfo.li_min_insn_length; | |
5054 | state_machine_regs.address | |
5055 | += addrdelta; | |
5056 | state_machine_regs.op_index | |
5057 | = (state_machine_regs.op_index + uladv) | |
5058 | % linfo.li_max_ops_per_insn; | |
5059 | if (addrdelta) | |
5060 | state_machine_regs.view = 0; | |
31e5a3a3 | 5061 | printf (_(" Advance PC by constant %" PRIu64 |
cc443420 | 5062 | " to %#" PRIx64 "[%d]%s\n"), |
31e5a3a3 | 5063 | uladv, state_machine_regs.address, |
cd30bcef AM |
5064 | state_machine_regs.op_index, |
5065 | verbose_view && addrdelta | |
5066 | ? _(" (reset view)") : ""); | |
5067 | } | |
5068 | break; | |
5069 | ||
5070 | case DW_LNS_fixed_advance_pc: | |
5071 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5072 | state_machine_regs.address += uladv; | |
5073 | state_machine_regs.op_index = 0; | |
31e5a3a3 | 5074 | printf (_(" Advance PC by fixed size amount %" PRIu64 |
cc443420 | 5075 | " to %#" PRIx64 "\n"), |
31e5a3a3 | 5076 | uladv, state_machine_regs.address); |
cd30bcef AM |
5077 | /* Do NOT reset view. */ |
5078 | break; | |
5079 | ||
5080 | case DW_LNS_set_prologue_end: | |
5081 | printf (_(" Set prologue_end to true\n")); | |
5082 | break; | |
5083 | ||
5084 | case DW_LNS_set_epilogue_begin: | |
5085 | printf (_(" Set epilogue_begin to true\n")); | |
5086 | break; | |
5087 | ||
5088 | case DW_LNS_set_isa: | |
5089 | READ_ULEB (uladv, data, end); | |
31e5a3a3 | 5090 | printf (_(" Set ISA to %" PRIu64 "\n"), uladv); |
cd30bcef AM |
5091 | break; |
5092 | ||
5093 | default: | |
5094 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5095 | ||
5096 | if (standard_opcodes != NULL) | |
5097 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5098 | { | |
5099 | READ_ULEB (uladv, data, end); | |
cc443420 | 5100 | printf ("%#" PRIx64 "%s", uladv, i == 1 ? "" : ", "); |
cd30bcef AM |
5101 | } |
5102 | putchar ('\n'); | |
5103 | break; | |
5104 | } | |
19e6b90e | 5105 | } |
b40bf0a2 | 5106 | putchar ('\n'); |
19e6b90e | 5107 | } |
19e6b90e L |
5108 | } |
5109 | ||
5110 | return 1; | |
5111 | } | |
5112 | ||
a262ae96 NC |
5113 | typedef struct |
5114 | { | |
b1f1cefd | 5115 | char *name; |
467c65bc NC |
5116 | unsigned int directory_index; |
5117 | unsigned int modification_date; | |
5118 | unsigned int length; | |
a262ae96 NC |
5119 | } File_Entry; |
5120 | ||
5121 | /* Output a decoded representation of the .debug_line section. */ | |
5122 | ||
5123 | static int | |
dda8d76d | 5124 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 5125 | unsigned char * start, |
dda8d76d NC |
5126 | unsigned char * data, |
5127 | unsigned char * end, | |
5128 | void * fileptr) | |
a262ae96 | 5129 | { |
b40bf0a2 NC |
5130 | static DWARF2_Internal_LineInfo saved_linfo; |
5131 | ||
015dc7e1 | 5132 | introduce (section, false); |
a262ae96 NC |
5133 | |
5134 | while (data < end) | |
5135 | { | |
5136 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 5137 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
5138 | unsigned char *standard_opcodes; |
5139 | unsigned char *end_of_sequence; | |
a262ae96 NC |
5140 | int i; |
5141 | File_Entry *file_table = NULL; | |
143a3db0 | 5142 | unsigned int n_files = 0; |
b1f1cefd | 5143 | char **directory_table = NULL; |
a984f112 | 5144 | unsigned int n_directories = 0; |
a262ae96 | 5145 | |
24d127aa | 5146 | if (startswith (section->name, ".debug_line.") |
4925cdd7 NC |
5147 | /* Note: the following does not apply to .debug_line.dwo sections. |
5148 | These are full debug_line sections. */ | |
5149 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 5150 | { |
4925cdd7 | 5151 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
5152 | end_of_sequence = end; |
5153 | standard_opcodes = NULL; | |
5154 | linfo = saved_linfo; | |
058037d3 NC |
5155 | /* PR 17531: file: 0522b371. */ |
5156 | if (linfo.li_line_range == 0) | |
5157 | { | |
1306a742 | 5158 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
5159 | return 0; |
5160 | } | |
b40bf0a2 | 5161 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 5162 | } |
a262ae96 | 5163 | else |
b4eb7656 | 5164 | { |
b40bf0a2 | 5165 | unsigned char *hdrptr; |
a262ae96 | 5166 | |
b40bf0a2 NC |
5167 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
5168 | & end_of_sequence)) == NULL) | |
a233b20c | 5169 | return 0; |
0c588247 | 5170 | |
058037d3 NC |
5171 | /* PR 17531: file: 0522b371. */ |
5172 | if (linfo.li_line_range == 0) | |
5173 | { | |
5174 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
5175 | linfo.li_line_range = 1; | |
5176 | } | |
b40bf0a2 | 5177 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 5178 | |
b40bf0a2 NC |
5179 | /* Save a pointer to the contents of the Opcodes table. */ |
5180 | standard_opcodes = hdrptr; | |
a262ae96 | 5181 | |
b40bf0a2 NC |
5182 | /* Traverse the Directory table just to count entries. */ |
5183 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
5184 | /* PR 20440 */ |
5185 | if (data >= end) | |
5186 | { | |
5187 | warn (_("opcode base of %d extends beyond end of section\n"), | |
5188 | linfo.li_opcode_base); | |
5189 | return 0; | |
5190 | } | |
5191 | ||
77145576 | 5192 | if (linfo.li_version >= 5) |
b40bf0a2 | 5193 | { |
a984f112 AM |
5194 | unsigned char *format_start, *format; |
5195 | unsigned int format_count, formati, entryi; | |
a262ae96 | 5196 | |
dda8d76d | 5197 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
5198 | |
5199 | /* Skip directories format. */ | |
5200 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
5201 | if (do_checks && format_count > 1) |
5202 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), | |
5203 | format_count); | |
77145576 JK |
5204 | format_start = data; |
5205 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 5206 | { |
cd30bcef AM |
5207 | SKIP_ULEB (data, end); |
5208 | SKIP_ULEB (data, end); | |
b40bf0a2 | 5209 | } |
a262ae96 | 5210 | |
cd30bcef | 5211 | READ_ULEB (n_directories, data, end); |
55b26492 | 5212 | if (data >= end) |
d8024a91 | 5213 | { |
77145576 | 5214 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
5215 | break; |
5216 | } | |
5217 | ||
070b775f NC |
5218 | if (n_directories == 0) |
5219 | directory_table = NULL; | |
9f1c612b NC |
5220 | else if (n_directories > section->size) |
5221 | { | |
5222 | warn (_("number of directories (0x%x) exceeds size of section %s\n"), | |
5223 | n_directories, section->name); | |
5224 | return 0; | |
5225 | } | |
070b775f | 5226 | else |
b1f1cefd AM |
5227 | directory_table = (char **) |
5228 | xcalloc (n_directories, sizeof (unsigned char *)); | |
a262ae96 | 5229 | |
77145576 | 5230 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 5231 | { |
b1f1cefd | 5232 | char **pathp = &directory_table[entryi]; |
a262ae96 | 5233 | |
77145576 JK |
5234 | format = format_start; |
5235 | for (formati = 0; formati < format_count; formati++) | |
5236 | { | |
31e5a3a3 AM |
5237 | uint64_t content_type, form; |
5238 | uint64_t uvalue; | |
77145576 | 5239 | |
cd30bcef AM |
5240 | READ_ULEB (content_type, format, end); |
5241 | READ_ULEB (form, format, end); | |
55b26492 | 5242 | if (data >= end) |
77145576 JK |
5243 | { |
5244 | warn (_("Corrupt directories list\n")); | |
5245 | break; | |
5246 | } | |
5247 | switch (content_type) | |
5248 | { | |
5249 | case DW_LNCT_path: | |
5250 | switch (form) | |
5251 | { | |
5252 | case DW_FORM_string: | |
b1f1cefd | 5253 | *pathp = (char *) data; |
77145576 JK |
5254 | break; |
5255 | case DW_FORM_line_strp: | |
5256 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
5257 | end); | |
5258 | /* Remove const by the cast. */ | |
b1f1cefd | 5259 | *pathp = (char *) |
77145576 JK |
5260 | fetch_indirect_line_string (uvalue); |
5261 | break; | |
5262 | } | |
5263 | break; | |
5264 | } | |
cd30bcef AM |
5265 | data = read_and_display_attr_value (0, form, 0, start, |
5266 | data, end, 0, 0, | |
77145576 JK |
5267 | linfo.li_offset_size, |
5268 | linfo.li_version, | |
5269 | NULL, 1, section, | |
ec1b0fbb | 5270 | NULL, '\t', -1); |
77145576 | 5271 | } |
55b26492 | 5272 | if (data >= end) |
77145576 JK |
5273 | { |
5274 | warn (_("Corrupt directories list\n")); | |
5275 | break; | |
5276 | } | |
5277 | } | |
a262ae96 | 5278 | |
77145576 JK |
5279 | /* Skip files format. */ |
5280 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
5281 | if (do_checks && format_count > 5) |
5282 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), | |
5283 | format_count); | |
9f1c612b | 5284 | |
77145576 JK |
5285 | format_start = data; |
5286 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 5287 | { |
cd30bcef AM |
5288 | SKIP_ULEB (data, end); |
5289 | SKIP_ULEB (data, end); | |
b40bf0a2 | 5290 | } |
a262ae96 | 5291 | |
cd30bcef | 5292 | READ_ULEB (n_files, data, end); |
55b26492 | 5293 | if (data >= end && n_files > 0) |
d8024a91 | 5294 | { |
77145576 | 5295 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
5296 | break; |
5297 | } | |
5298 | ||
070b775f NC |
5299 | if (n_files == 0) |
5300 | file_table = NULL; | |
9f1c612b NC |
5301 | else if (n_files > section->size) |
5302 | { | |
5303 | warn (_("number of files (0x%x) exceeds size of section %s\n"), | |
5304 | n_files, section->name); | |
5305 | return 0; | |
5306 | } | |
070b775f | 5307 | else |
b1f1cefd AM |
5308 | file_table = (File_Entry *) xcalloc (n_files, |
5309 | sizeof (File_Entry)); | |
a262ae96 | 5310 | |
77145576 | 5311 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 5312 | { |
77145576 | 5313 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 5314 | |
77145576 JK |
5315 | format = format_start; |
5316 | for (formati = 0; formati < format_count; formati++) | |
5317 | { | |
31e5a3a3 AM |
5318 | uint64_t content_type, form; |
5319 | uint64_t uvalue; | |
cd30bcef | 5320 | unsigned char *tmp; |
77145576 | 5321 | |
cd30bcef AM |
5322 | READ_ULEB (content_type, format, end); |
5323 | READ_ULEB (form, format, end); | |
55b26492 | 5324 | if (data >= end) |
77145576 JK |
5325 | { |
5326 | warn (_("Corrupt file name list\n")); | |
5327 | break; | |
5328 | } | |
5329 | switch (content_type) | |
5330 | { | |
5331 | case DW_LNCT_path: | |
5332 | switch (form) | |
5333 | { | |
5334 | case DW_FORM_string: | |
b1f1cefd | 5335 | file->name = (char *) data; |
77145576 JK |
5336 | break; |
5337 | case DW_FORM_line_strp: | |
5338 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
5339 | end); | |
5340 | /* Remove const by the cast. */ | |
b1f1cefd | 5341 | file->name = (char *) |
77145576 JK |
5342 | fetch_indirect_line_string (uvalue); |
5343 | break; | |
5344 | } | |
5345 | break; | |
5346 | case DW_LNCT_directory_index: | |
5347 | switch (form) | |
5348 | { | |
5349 | case DW_FORM_data1: | |
5350 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
5351 | end); | |
5352 | break; | |
5353 | case DW_FORM_data2: | |
5354 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
5355 | end); | |
5356 | break; | |
5357 | case DW_FORM_udata: | |
cd30bcef AM |
5358 | tmp = data; |
5359 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
5360 | break; |
5361 | } | |
5362 | break; | |
5363 | } | |
cd30bcef AM |
5364 | data = read_and_display_attr_value (0, form, 0, start, |
5365 | data, end, 0, 0, | |
77145576 JK |
5366 | linfo.li_offset_size, |
5367 | linfo.li_version, | |
5368 | NULL, 1, section, | |
ec1b0fbb | 5369 | NULL, '\t', -1); |
77145576 | 5370 | } |
55b26492 | 5371 | if (data >= end) |
77145576 JK |
5372 | { |
5373 | warn (_("Corrupt file name list\n")); | |
5374 | break; | |
5375 | } | |
5376 | } | |
5377 | } | |
5378 | else | |
5379 | { | |
5380 | if (*data != 0) | |
b40bf0a2 | 5381 | { |
b1f1cefd | 5382 | char *ptr_directory_table = (char *) data; |
77145576 JK |
5383 | |
5384 | while (data < end && *data != 0) | |
5385 | { | |
a7077ce7 AM |
5386 | data += strnlen ((char *) data, end - data); |
5387 | if (data < end) | |
5388 | data++; | |
77145576 JK |
5389 | n_directories++; |
5390 | } | |
5391 | ||
5392 | /* PR 20440 */ | |
5393 | if (data >= end) | |
5394 | { | |
5395 | warn (_("directory table ends unexpectedly\n")); | |
5396 | n_directories = 0; | |
5397 | break; | |
5398 | } | |
5399 | ||
5400 | /* Go through the directory table again to save the directories. */ | |
b1f1cefd | 5401 | directory_table = (char **) |
77145576 JK |
5402 | xmalloc (n_directories * sizeof (unsigned char *)); |
5403 | ||
5404 | i = 0; | |
5405 | while (*ptr_directory_table != 0) | |
5406 | { | |
5407 | directory_table[i] = ptr_directory_table; | |
b1f1cefd | 5408 | ptr_directory_table += strlen (ptr_directory_table) + 1; |
77145576 JK |
5409 | i++; |
5410 | } | |
b40bf0a2 | 5411 | } |
77145576 JK |
5412 | /* Skip the NUL at the end of the table. */ |
5413 | data++; | |
5414 | ||
5415 | /* Traverse the File Name table just to count the entries. */ | |
5416 | if (data < end && *data != 0) | |
b40bf0a2 | 5417 | { |
77145576 JK |
5418 | unsigned char *ptr_file_name_table = data; |
5419 | ||
5420 | while (data < end && *data != 0) | |
db9537d2 | 5421 | { |
cd30bcef AM |
5422 | /* Skip Name, directory index, last modification |
5423 | time and length of file. */ | |
a7077ce7 AM |
5424 | data += strnlen ((char *) data, end - data); |
5425 | if (data < end) | |
5426 | data++; | |
cd30bcef AM |
5427 | SKIP_ULEB (data, end); |
5428 | SKIP_ULEB (data, end); | |
5429 | SKIP_ULEB (data, end); | |
77145576 | 5430 | n_files++; |
db9537d2 | 5431 | } |
a262ae96 | 5432 | |
77145576 JK |
5433 | if (data >= end) |
5434 | { | |
5435 | warn (_("file table ends unexpectedly\n")); | |
5436 | n_files = 0; | |
5437 | break; | |
5438 | } | |
5439 | ||
5440 | /* Go through the file table again to save the strings. */ | |
5441 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 5442 | |
77145576 JK |
5443 | i = 0; |
5444 | while (*ptr_file_name_table != 0) | |
5445 | { | |
b1f1cefd | 5446 | file_table[i].name = (char *) ptr_file_name_table; |
56051e28 AM |
5447 | ptr_file_name_table |
5448 | += strlen ((char *) ptr_file_name_table) + 1; | |
77145576 JK |
5449 | |
5450 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
5451 | READ_ULEB (file_table[i].directory_index, |
5452 | ptr_file_name_table, end); | |
5453 | READ_ULEB (file_table[i].modification_date, | |
5454 | ptr_file_name_table, end); | |
5455 | READ_ULEB (file_table[i].length, | |
5456 | ptr_file_name_table, end); | |
77145576 JK |
5457 | i++; |
5458 | } | |
5459 | i = 0; | |
b40bf0a2 | 5460 | } |
77145576 JK |
5461 | |
5462 | /* Skip the NUL at the end of the table. */ | |
5463 | data++; | |
b40bf0a2 | 5464 | } |
cc5914eb | 5465 | |
77145576 | 5466 | /* Print the Compilation Unit's name and a header. */ |
f082820d | 5467 | if (file_table == NULL) |
070b775f | 5468 | printf (_("CU: No directory table\n")); |
f082820d | 5469 | else if (directory_table == NULL) |
b1f1cefd | 5470 | printf (_("CU: %s:\n"), null_name (file_table[0].name)); |
77145576 JK |
5471 | else |
5472 | { | |
5473 | unsigned int ix = file_table[0].directory_index; | |
5474 | const char *directory; | |
5475 | ||
a984f112 | 5476 | if (ix == 0 && linfo.li_version < 5) |
77145576 JK |
5477 | directory = "."; |
5478 | /* PR 20439 */ | |
5479 | else if (n_directories == 0) | |
5480 | directory = _("<unknown>"); | |
a984f112 | 5481 | else |
77145576 | 5482 | { |
a984f112 AM |
5483 | if (linfo.li_version < 5) |
5484 | --ix; | |
5485 | if (ix >= n_directories) | |
5486 | { | |
5487 | warn (_("directory index %u " | |
5488 | ">= number of directories %u\n"), | |
5489 | ix, n_directories); | |
5490 | directory = _("<corrupt>"); | |
5491 | } | |
5492 | else | |
5493 | directory = directory_table[ix]; | |
77145576 | 5494 | } |
c4f58714 | 5495 | if (do_wide) |
b1f1cefd AM |
5496 | printf (_("CU: %s/%s:\n"), |
5497 | null_name (directory), | |
5498 | null_name (file_table[0].name)); | |
77145576 | 5499 | else |
b1f1cefd | 5500 | printf ("%s:\n", null_name (file_table[0].name)); |
77145576 | 5501 | } |
a262ae96 | 5502 | |
070b775f | 5503 | if (n_files > 0) |
7506fc9b NC |
5504 | { |
5505 | if (do_wide) | |
5506 | printf (_("File name Line number Starting address View Stmt\n")); | |
5507 | else | |
5508 | printf (_("File name Line number Starting address View Stmt\n")); | |
5509 | } | |
070b775f NC |
5510 | else |
5511 | printf (_("CU: Empty file name table\n")); | |
b40bf0a2 NC |
5512 | saved_linfo = linfo; |
5513 | } | |
a262ae96 NC |
5514 | |
5515 | /* This loop iterates through the Dwarf Line Number Program. */ | |
5516 | while (data < end_of_sequence) | |
b4eb7656 | 5517 | { |
a262ae96 | 5518 | unsigned char op_code; |
ba8826a8 | 5519 | int xop; |
b4eb7656 AM |
5520 | int adv; |
5521 | unsigned long int uladv; | |
b4eb7656 | 5522 | int is_special_opcode = 0; |
a262ae96 | 5523 | |
b4eb7656 | 5524 | op_code = *data++; |
ba8826a8 | 5525 | xop = op_code; |
a262ae96 | 5526 | |
b4eb7656 | 5527 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 5528 | { |
91d6fa6a | 5529 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
5530 | uladv = (op_code / linfo.li_line_range); |
5531 | if (linfo.li_max_ops_per_insn == 1) | |
5532 | { | |
5533 | uladv *= linfo.li_min_insn_length; | |
5534 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
5535 | if (uladv) |
5536 | state_machine_regs.view = 0; | |
a233b20c JJ |
5537 | } |
5538 | else | |
5539 | { | |
ba8826a8 AO |
5540 | unsigned addrdelta |
5541 | = ((state_machine_regs.op_index + uladv) | |
5542 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 5543 | * linfo.li_min_insn_length; |
ba8826a8 AO |
5544 | state_machine_regs.address |
5545 | += addrdelta; | |
a233b20c JJ |
5546 | state_machine_regs.op_index |
5547 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 5548 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
5549 | if (addrdelta) |
5550 | state_machine_regs.view = 0; | |
a233b20c | 5551 | } |
a262ae96 | 5552 | |
b4eb7656 AM |
5553 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
5554 | state_machine_regs.line += adv; | |
5555 | is_special_opcode = 1; | |
ba8826a8 | 5556 | /* Increment view after printing this row. */ |
b4eb7656 | 5557 | } |
cd30bcef AM |
5558 | else |
5559 | switch (op_code) | |
5560 | { | |
5561 | case DW_LNS_extended_op: | |
5562 | { | |
5563 | unsigned int ext_op_code_len; | |
5564 | unsigned char ext_op_code; | |
5565 | unsigned char *op_code_end; | |
5566 | unsigned char *op_code_data = data; | |
5567 | ||
5568 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
5569 | op_code_end = op_code_data + ext_op_code_len; | |
5570 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
5571 | { | |
5572 | warn (_("Badly formed extended line op encountered!\n")); | |
5573 | break; | |
5574 | } | |
5575 | ext_op_code = *op_code_data++; | |
5576 | xop = ext_op_code; | |
5577 | xop = -xop; | |
5578 | ||
5579 | switch (ext_op_code) | |
5580 | { | |
5581 | case DW_LNE_end_sequence: | |
5582 | /* Reset stuff after printing this row. */ | |
5583 | break; | |
5584 | case DW_LNE_set_address: | |
5585 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
5586 | op_code_data, | |
5587 | op_code_end - op_code_data, | |
5588 | op_code_end); | |
5589 | state_machine_regs.op_index = 0; | |
5590 | state_machine_regs.view = 0; | |
5591 | break; | |
5592 | case DW_LNE_define_file: | |
5593 | file_table = (File_Entry *) xrealloc | |
5594 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
5595 | ||
5596 | ++state_machine_regs.last_file_entry; | |
5597 | /* Source file name. */ | |
b1f1cefd | 5598 | file_table[n_files].name = (char *) op_code_data; |
cd30bcef AM |
5599 | op_code_data += strlen ((char *) op_code_data) + 1; |
5600 | /* Directory index. */ | |
5601 | READ_ULEB (file_table[n_files].directory_index, | |
5602 | op_code_data, op_code_end); | |
5603 | /* Last modification time. */ | |
5604 | READ_ULEB (file_table[n_files].modification_date, | |
5605 | op_code_data, op_code_end); | |
5606 | /* File length. */ | |
5607 | READ_ULEB (file_table[n_files].length, | |
5608 | op_code_data, op_code_end); | |
5609 | n_files++; | |
5610 | break; | |
5611 | ||
5612 | case DW_LNE_set_discriminator: | |
5613 | case DW_LNE_HP_set_sequence: | |
5614 | /* Simply ignored. */ | |
5615 | break; | |
5616 | ||
5617 | default: | |
5618 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 5619 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
5620 | break; |
5621 | } | |
5622 | data = op_code_end; | |
5623 | break; | |
5624 | } | |
5625 | case DW_LNS_copy: | |
5626 | /* Increment view after printing this row. */ | |
5627 | break; | |
5628 | ||
5629 | case DW_LNS_advance_pc: | |
5630 | READ_ULEB (uladv, data, end); | |
5631 | if (linfo.li_max_ops_per_insn == 1) | |
5632 | { | |
5633 | uladv *= linfo.li_min_insn_length; | |
5634 | state_machine_regs.address += uladv; | |
5635 | if (uladv) | |
5636 | state_machine_regs.view = 0; | |
5637 | } | |
5638 | else | |
5639 | { | |
5640 | unsigned addrdelta | |
5641 | = ((state_machine_regs.op_index + uladv) | |
5642 | / linfo.li_max_ops_per_insn) | |
5643 | * linfo.li_min_insn_length; | |
5644 | state_machine_regs.address | |
5645 | += addrdelta; | |
5646 | state_machine_regs.op_index | |
5647 | = (state_machine_regs.op_index + uladv) | |
5648 | % linfo.li_max_ops_per_insn; | |
5649 | if (addrdelta) | |
5650 | state_machine_regs.view = 0; | |
5651 | } | |
5652 | break; | |
5653 | ||
5654 | case DW_LNS_advance_line: | |
5655 | READ_SLEB (adv, data, end); | |
5656 | state_machine_regs.line += adv; | |
5657 | break; | |
5658 | ||
5659 | case DW_LNS_set_file: | |
5660 | READ_ULEB (uladv, data, end); | |
5661 | state_machine_regs.file = uladv; | |
5662 | ||
a984f112 AM |
5663 | unsigned file = state_machine_regs.file; |
5664 | if (linfo.li_version < 5) | |
5665 | --file; | |
2caffd34 | 5666 | |
a984f112 AM |
5667 | if (file_table == NULL || n_files == 0) |
5668 | printf (_("\n [Use file table entry %d]\n"), file); | |
5669 | /* PR 20439 */ | |
5670 | else if (file >= n_files) | |
5671 | { | |
5672 | warn (_("file index %u >= number of files %u\n"), | |
5673 | file, n_files); | |
5674 | printf (_("\n <over large file table index %u>"), file); | |
5675 | } | |
5676 | else | |
5677 | { | |
5678 | unsigned dir = file_table[file].directory_index; | |
5679 | if (dir == 0 && linfo.li_version < 5) | |
5680 | /* If directory index is 0, that means compilation | |
5681 | current directory. bfd/dwarf2.c shows | |
5682 | DW_AT_comp_dir here but in keeping with the | |
5683 | readelf practice of minimal interpretation of | |
5684 | file data, we show "./". */ | |
5685 | printf ("\n./%s:[++]\n", | |
5686 | null_name (file_table[file].name)); | |
5687 | else if (directory_table == NULL || n_directories == 0) | |
5688 | printf (_("\n [Use file %s " | |
5689 | "in directory table entry %d]\n"), | |
5690 | null_name (file_table[file].name), dir); | |
5691 | else | |
5692 | { | |
5693 | if (linfo.li_version < 5) | |
5694 | --dir; | |
5695 | /* PR 20439 */ | |
5696 | if (dir >= n_directories) | |
5697 | { | |
5698 | warn (_("directory index %u " | |
5699 | ">= number of directories %u\n"), | |
5700 | dir, n_directories); | |
5701 | printf (_("\n <over large directory table entry " | |
5702 | "%u>\n"), dir); | |
5703 | } | |
5704 | else | |
5705 | printf ("\n%s/%s:\n", | |
5706 | null_name (directory_table[dir]), | |
5707 | null_name (file_table[file].name)); | |
5708 | } | |
5709 | } | |
cd30bcef AM |
5710 | break; |
5711 | ||
5712 | case DW_LNS_set_column: | |
5713 | READ_ULEB (uladv, data, end); | |
5714 | state_machine_regs.column = uladv; | |
5715 | break; | |
5716 | ||
5717 | case DW_LNS_negate_stmt: | |
5718 | adv = state_machine_regs.is_stmt; | |
5719 | adv = ! adv; | |
5720 | state_machine_regs.is_stmt = adv; | |
5721 | break; | |
5722 | ||
5723 | case DW_LNS_set_basic_block: | |
5724 | state_machine_regs.basic_block = 1; | |
5725 | break; | |
5726 | ||
5727 | case DW_LNS_const_add_pc: | |
5728 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
5729 | if (linfo.li_max_ops_per_insn == 1) | |
5730 | { | |
5731 | uladv *= linfo.li_min_insn_length; | |
5732 | state_machine_regs.address += uladv; | |
5733 | if (uladv) | |
5734 | state_machine_regs.view = 0; | |
5735 | } | |
5736 | else | |
5737 | { | |
5738 | unsigned addrdelta | |
5739 | = ((state_machine_regs.op_index + uladv) | |
5740 | / linfo.li_max_ops_per_insn) | |
5741 | * linfo.li_min_insn_length; | |
5742 | state_machine_regs.address | |
5743 | += addrdelta; | |
5744 | state_machine_regs.op_index | |
5745 | = (state_machine_regs.op_index + uladv) | |
5746 | % linfo.li_max_ops_per_insn; | |
5747 | if (addrdelta) | |
5748 | state_machine_regs.view = 0; | |
5749 | } | |
5750 | break; | |
5751 | ||
5752 | case DW_LNS_fixed_advance_pc: | |
5753 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5754 | state_machine_regs.address += uladv; | |
5755 | state_machine_regs.op_index = 0; | |
5756 | /* Do NOT reset view. */ | |
5757 | break; | |
5758 | ||
5759 | case DW_LNS_set_prologue_end: | |
5760 | break; | |
5761 | ||
5762 | case DW_LNS_set_epilogue_begin: | |
5763 | break; | |
5764 | ||
5765 | case DW_LNS_set_isa: | |
5766 | READ_ULEB (uladv, data, end); | |
5767 | printf (_(" Set ISA to %lu\n"), uladv); | |
5768 | break; | |
5769 | ||
5770 | default: | |
5771 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5772 | ||
5773 | if (standard_opcodes != NULL) | |
5774 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5775 | { | |
31e5a3a3 | 5776 | uint64_t val; |
cd30bcef AM |
5777 | |
5778 | READ_ULEB (val, data, end); | |
cc443420 | 5779 | printf ("%#" PRIx64 "%s", val, i == 1 ? "" : ", "); |
cd30bcef AM |
5780 | } |
5781 | putchar ('\n'); | |
5782 | break; | |
5783 | } | |
a262ae96 | 5784 | |
b4eb7656 AM |
5785 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
5786 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
5787 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
5788 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
5789 | { |
5790 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
f2f58a39 | 5791 | char *fileName = NULL; |
b4eb7656 AM |
5792 | char *newFileName = NULL; |
5793 | size_t fileNameLength; | |
b40bf0a2 NC |
5794 | |
5795 | if (file_table) | |
db9537d2 | 5796 | { |
fba9460f AM |
5797 | unsigned indx = state_machine_regs.file; |
5798 | ||
5799 | if (linfo.li_version < 5) | |
5800 | --indx; | |
db9537d2 NC |
5801 | /* PR 20439 */ |
5802 | if (indx >= n_files) | |
5803 | { | |
a984f112 AM |
5804 | warn (_("file index %u >= number of files %u\n"), |
5805 | indx, n_files); | |
db9537d2 NC |
5806 | fileName = _("<corrupt>"); |
5807 | } | |
5808 | else | |
5809 | fileName = (char *) file_table[indx].name; | |
5810 | } | |
f2f58a39 | 5811 | if (!fileName) |
db9537d2 | 5812 | fileName = _("<unknown>"); |
b40bf0a2 NC |
5813 | |
5814 | fileNameLength = strlen (fileName); | |
539b54f0 AM |
5815 | newFileName = fileName; |
5816 | if (fileNameLength > MAX_FILENAME_LENGTH && !do_wide) | |
b4eb7656 AM |
5817 | { |
5818 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5819 | /* Truncate file name */ | |
539b54f0 AM |
5820 | memcpy (newFileName, |
5821 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5822 | MAX_FILENAME_LENGTH); | |
e1104d08 | 5823 | newFileName[MAX_FILENAME_LENGTH] = 0; |
b4eb7656 | 5824 | } |
b4eb7656 | 5825 | |
af2b3186 TV |
5826 | /* A row with end_seq set to true has a meaningful address, but |
5827 | the other information in the same row is not significant. | |
5828 | In such a row, print line as "-", and don't print | |
5829 | view/is_stmt. */ | |
539b54f0 | 5830 | if (!do_wide || fileNameLength <= MAX_FILENAME_LENGTH) |
b4eb7656 | 5831 | { |
a233b20c | 5832 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5833 | { |
5834 | if (xop == -DW_LNE_end_sequence) | |
7506fc9b | 5835 | printf ("%-31s %11s %#18" PRIx64, |
af2b3186 TV |
5836 | newFileName, "-", |
5837 | state_machine_regs.address); | |
5838 | else | |
7506fc9b | 5839 | printf ("%-31s %11d %#18" PRIx64, |
af2b3186 TV |
5840 | newFileName, state_machine_regs.line, |
5841 | state_machine_regs.address); | |
5842 | } | |
a233b20c | 5843 | else |
af2b3186 TV |
5844 | { |
5845 | if (xop == -DW_LNE_end_sequence) | |
7506fc9b | 5846 | printf ("%-31s %11s %#18" PRIx64 "[%d]", |
af2b3186 TV |
5847 | newFileName, "-", |
5848 | state_machine_regs.address, | |
5849 | state_machine_regs.op_index); | |
5850 | else | |
7506fc9b | 5851 | printf ("%-31s %11d %#18" PRIx64 "[%d]", |
af2b3186 TV |
5852 | newFileName, state_machine_regs.line, |
5853 | state_machine_regs.address, | |
5854 | state_machine_regs.op_index); | |
5855 | } | |
b4eb7656 AM |
5856 | } |
5857 | else | |
5858 | { | |
a233b20c | 5859 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5860 | { |
5861 | if (xop == -DW_LNE_end_sequence) | |
31e5a3a3 | 5862 | printf ("%s %11s %#18" PRIx64, |
af2b3186 TV |
5863 | newFileName, "-", |
5864 | state_machine_regs.address); | |
5865 | else | |
31e5a3a3 | 5866 | printf ("%s %11d %#18" PRIx64, |
af2b3186 TV |
5867 | newFileName, state_machine_regs.line, |
5868 | state_machine_regs.address); | |
175b9150 | 5869 | } |
a233b20c | 5870 | else |
af2b3186 TV |
5871 | { |
5872 | if (xop == -DW_LNE_end_sequence) | |
31e5a3a3 | 5873 | printf ("%s %11s %#18" PRIx64 "[%d]", |
af2b3186 TV |
5874 | newFileName, "-", |
5875 | state_machine_regs.address, | |
5876 | state_machine_regs.op_index); | |
5877 | else | |
31e5a3a3 | 5878 | printf ("%s %11d %#18" PRIx64 "[%d]", |
af2b3186 TV |
5879 | newFileName, state_machine_regs.line, |
5880 | state_machine_regs.address, | |
5881 | state_machine_regs.op_index); | |
5882 | } | |
b4eb7656 | 5883 | } |
a262ae96 | 5884 | |
af2b3186 TV |
5885 | if (xop != -DW_LNE_end_sequence) |
5886 | { | |
5887 | if (state_machine_regs.view) | |
5888 | printf (" %6u", state_machine_regs.view); | |
5889 | else | |
5890 | printf (" "); | |
17f6ade2 | 5891 | |
af2b3186 TV |
5892 | if (state_machine_regs.is_stmt) |
5893 | printf (" x"); | |
5894 | } | |
17f6ade2 JD |
5895 | |
5896 | putchar ('\n'); | |
ba8826a8 AO |
5897 | state_machine_regs.view++; |
5898 | ||
5899 | if (xop == -DW_LNE_end_sequence) | |
5900 | { | |
5901 | reset_state_machine (linfo.li_default_is_stmt); | |
5902 | putchar ('\n'); | |
5903 | } | |
a262ae96 | 5904 | |
539b54f0 AM |
5905 | if (newFileName != fileName) |
5906 | free (newFileName); | |
b4eb7656 AM |
5907 | } |
5908 | } | |
b40bf0a2 NC |
5909 | |
5910 | if (file_table) | |
5911 | { | |
5912 | free (file_table); | |
5913 | file_table = NULL; | |
5914 | n_files = 0; | |
5915 | } | |
5916 | ||
5917 | if (directory_table) | |
5918 | { | |
5919 | free (directory_table); | |
5920 | directory_table = NULL; | |
5921 | n_directories = 0; | |
5922 | } | |
5923 | ||
a262ae96 NC |
5924 | putchar ('\n'); |
5925 | } | |
5926 | ||
5927 | return 1; | |
5928 | } | |
5929 | ||
5930 | static int | |
77145576 | 5931 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5932 | { |
5933 | unsigned char *data = section->start; | |
5934 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5935 | int retValRaw = 1; |
5936 | int retValDecoded = 1; | |
a262ae96 | 5937 | |
008f4c78 NC |
5938 | if (do_debug_lines == 0) |
5939 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5940 | ||
4cb93e3b | 5941 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5942 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5943 | |
4cb93e3b | 5944 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5945 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5946 | |
4cb93e3b | 5947 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5948 | return 0; |
5949 | ||
5950 | return 1; | |
5951 | } | |
5952 | ||
6e3d6dc1 | 5953 | static debug_info * |
31e5a3a3 | 5954 | find_debug_info_for_offset (uint64_t offset) |
6e3d6dc1 NC |
5955 | { |
5956 | unsigned int i; | |
5957 | ||
5958 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5959 | return NULL; | |
5960 | ||
5961 | for (i = 0; i < num_debug_info_entries; i++) | |
5962 | if (debug_information[i].cu_offset == offset) | |
5963 | return debug_information + i; | |
5964 | ||
5965 | return NULL; | |
5966 | } | |
5967 | ||
459d52c8 DE |
5968 | static const char * |
5969 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5970 | { | |
5971 | /* See gdb/gdb-index.h. */ | |
5972 | static const char * const kinds[] = | |
5973 | { | |
5974 | N_ ("no info"), | |
5975 | N_ ("type"), | |
5976 | N_ ("variable"), | |
5977 | N_ ("function"), | |
5978 | N_ ("other"), | |
5979 | N_ ("unused5"), | |
5980 | N_ ("unused6"), | |
5981 | N_ ("unused7") | |
5982 | }; | |
5983 | ||
5984 | return _ (kinds[kind]); | |
5985 | } | |
5986 | ||
19e6b90e | 5987 | static int |
459d52c8 DE |
5988 | display_debug_pubnames_worker (struct dwarf_section *section, |
5989 | void *file ATTRIBUTE_UNUSED, | |
5990 | int is_gnu) | |
19e6b90e | 5991 | { |
91d6fa6a | 5992 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5993 | unsigned char *start = section->start; |
5994 | unsigned char *end = start + section->size; | |
5995 | ||
6e3d6dc1 NC |
5996 | /* It does not matter if this load fails, |
5997 | we test for that later on. */ | |
5998 | load_debug_info (file); | |
5999 | ||
015dc7e1 | 6000 | introduce (section, false); |
19e6b90e L |
6001 | |
6002 | while (start < end) | |
6003 | { | |
6004 | unsigned char *data; | |
35b2c89e AM |
6005 | unsigned long sec_off = start - section->start; |
6006 | unsigned int offset_size; | |
19e6b90e | 6007 | |
e98fdf1a | 6008 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 6009 | if (names.pn_length == 0xffffffff) |
19e6b90e | 6010 | { |
e98fdf1a | 6011 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e | 6012 | offset_size = 8; |
19e6b90e L |
6013 | } |
6014 | else | |
35b2c89e | 6015 | offset_size = 4; |
19e6b90e | 6016 | |
35b2c89e | 6017 | if (names.pn_length > (size_t) (end - start)) |
e98fdf1a | 6018 | { |
31e5a3a3 AM |
6019 | warn (_("Debug info is corrupted, " |
6020 | "%s header at %#lx has length %#" PRIx64 "\n"), | |
6021 | section->name, sec_off, names.pn_length); | |
e98fdf1a AM |
6022 | break; |
6023 | } | |
6024 | ||
6025 | data = start; | |
6026 | start += names.pn_length; | |
6027 | ||
35b2c89e AM |
6028 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, start); |
6029 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, start); | |
6e3d6dc1 NC |
6030 | |
6031 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
6032 | && num_debug_info_entries > 0 | |
91d6fa6a | 6033 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
31e5a3a3 AM |
6034 | warn (_(".debug_info offset of %#" PRIx64 |
6035 | " in %s section does not point to a CU header.\n"), | |
6036 | names.pn_offset, section->name); | |
cecf136e | 6037 | |
35b2c89e | 6038 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, start); |
19e6b90e | 6039 | |
31e5a3a3 AM |
6040 | printf (_(" Length: %" PRId64 "\n"), |
6041 | names.pn_length); | |
058037d3 NC |
6042 | printf (_(" Version: %d\n"), |
6043 | names.pn_version); | |
cc443420 | 6044 | printf (_(" Offset into .debug_info section: %#" PRIx64 "\n"), |
31e5a3a3 AM |
6045 | names.pn_offset); |
6046 | printf (_(" Size of area in .debug_info section: %" PRId64 "\n"), | |
6047 | names.pn_size); | |
19e6b90e | 6048 | |
91d6fa6a | 6049 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
6050 | { |
6051 | static int warned = 0; | |
6052 | ||
6053 | if (! warned) | |
6054 | { | |
6055 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
6056 | warned = 1; | |
6057 | } | |
6058 | ||
6059 | continue; | |
6060 | } | |
6061 | ||
459d52c8 DE |
6062 | if (is_gnu) |
6063 | printf (_("\n Offset Kind Name\n")); | |
6064 | else | |
6065 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 6066 | |
e98fdf1a | 6067 | while (1) |
19e6b90e | 6068 | { |
be7d229a | 6069 | size_t maxprint; |
31e5a3a3 | 6070 | uint64_t offset; |
f41e4712 | 6071 | |
35b2c89e | 6072 | SAFE_BYTE_GET_AND_INC (offset, data, offset_size, start); |
19e6b90e | 6073 | |
e98fdf1a AM |
6074 | if (offset == 0) |
6075 | break; | |
b4eb7656 | 6076 | |
35b2c89e | 6077 | if (data >= start) |
e98fdf1a | 6078 | break; |
35b2c89e | 6079 | maxprint = (start - data) - 1; |
f41e4712 | 6080 | |
e98fdf1a AM |
6081 | if (is_gnu) |
6082 | { | |
6083 | unsigned int kind_data; | |
6084 | gdb_index_symbol_kind kind; | |
6085 | const char *kind_name; | |
6086 | int is_static; | |
6087 | ||
35b2c89e | 6088 | SAFE_BYTE_GET_AND_INC (kind_data, data, 1, start); |
e98fdf1a AM |
6089 | maxprint --; |
6090 | /* GCC computes the kind as the upper byte in the CU index | |
6091 | word, and then right shifts it by the CU index size. | |
6092 | Left shift KIND to where the gdb-index.h accessor macros | |
6093 | can use it. */ | |
6094 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
6095 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
6096 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
6097 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
31e5a3a3 AM |
6098 | printf (" %-6" PRIx64 " %s,%-10s %.*s\n", |
6099 | offset, is_static ? _("s") : _("g"), | |
e98fdf1a | 6100 | kind_name, (int) maxprint, data); |
19e6b90e | 6101 | } |
e98fdf1a | 6102 | else |
31e5a3a3 AM |
6103 | printf (" %-6" PRIx64 "\t%.*s\n", |
6104 | offset, (int) maxprint, data); | |
e98fdf1a | 6105 | |
a7077ce7 | 6106 | data += strnlen ((char *) data, maxprint); |
35b2c89e | 6107 | if (data < start) |
a7077ce7 | 6108 | data++; |
35b2c89e | 6109 | if (data >= start) |
e98fdf1a | 6110 | break; |
19e6b90e | 6111 | } |
19e6b90e L |
6112 | } |
6113 | ||
6114 | printf ("\n"); | |
6115 | return 1; | |
6116 | } | |
6117 | ||
459d52c8 DE |
6118 | static int |
6119 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
6120 | { | |
6121 | return display_debug_pubnames_worker (section, file, 0); | |
6122 | } | |
6123 | ||
6124 | static int | |
6125 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
6126 | { | |
6127 | return display_debug_pubnames_worker (section, file, 1); | |
6128 | } | |
6129 | ||
19e6b90e L |
6130 | static int |
6131 | display_debug_macinfo (struct dwarf_section *section, | |
6132 | void *file ATTRIBUTE_UNUSED) | |
6133 | { | |
6134 | unsigned char *start = section->start; | |
6135 | unsigned char *end = start + section->size; | |
6136 | unsigned char *curr = start; | |
19e6b90e L |
6137 | enum dwarf_macinfo_record_type op; |
6138 | ||
015dc7e1 | 6139 | introduce (section, false); |
19e6b90e L |
6140 | |
6141 | while (curr < end) | |
6142 | { | |
6143 | unsigned int lineno; | |
0c588247 | 6144 | const unsigned char *string; |
19e6b90e | 6145 | |
3f5e193b | 6146 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
6147 | curr++; |
6148 | ||
6149 | switch (op) | |
6150 | { | |
6151 | case DW_MACINFO_start_file: | |
6152 | { | |
6153 | unsigned int filenum; | |
6154 | ||
cd30bcef AM |
6155 | READ_ULEB (lineno, curr, end); |
6156 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
6157 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
6158 | lineno, filenum); | |
6159 | } | |
6160 | break; | |
6161 | ||
6162 | case DW_MACINFO_end_file: | |
6163 | printf (_(" DW_MACINFO_end_file\n")); | |
6164 | break; | |
6165 | ||
6166 | case DW_MACINFO_define: | |
cd30bcef | 6167 | READ_ULEB (lineno, curr, end); |
0c588247 | 6168 | string = curr; |
c03df922 AM |
6169 | curr += strnlen ((char *) string, end - string); |
6170 | printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"), | |
6171 | lineno, (int) (curr - string), string); | |
6172 | if (curr < end) | |
6173 | curr++; | |
19e6b90e L |
6174 | break; |
6175 | ||
6176 | case DW_MACINFO_undef: | |
cd30bcef | 6177 | READ_ULEB (lineno, curr, end); |
0c588247 | 6178 | string = curr; |
c03df922 AM |
6179 | curr += strnlen ((char *) string, end - string); |
6180 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"), | |
6181 | lineno, (int) (curr - string), string); | |
6182 | if (curr < end) | |
6183 | curr++; | |
19e6b90e L |
6184 | break; |
6185 | ||
6186 | case DW_MACINFO_vendor_ext: | |
6187 | { | |
6188 | unsigned int constant; | |
6189 | ||
cd30bcef | 6190 | READ_ULEB (constant, curr, end); |
0c588247 | 6191 | string = curr; |
c03df922 AM |
6192 | curr += strnlen ((char *) string, end - string); |
6193 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"), | |
6194 | constant, (int) (curr - string), string); | |
6195 | if (curr < end) | |
6196 | curr++; | |
19e6b90e L |
6197 | } |
6198 | break; | |
6199 | } | |
6200 | } | |
6201 | ||
6202 | return 1; | |
6203 | } | |
6204 | ||
4ccf1e31 JJ |
6205 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
6206 | filename and dirname corresponding to file name table entry with index | |
6207 | FILEIDX. Return NULL on failure. */ | |
6208 | ||
6209 | static unsigned char * | |
31e5a3a3 AM |
6210 | get_line_filename_and_dirname (uint64_t line_offset, |
6211 | uint64_t fileidx, | |
4ccf1e31 JJ |
6212 | unsigned char **dir_name) |
6213 | { | |
6214 | struct dwarf_section *section = &debug_displays [line].section; | |
6215 | unsigned char *hdrptr, *dirtable, *file_name; | |
46d1214d | 6216 | unsigned int offset_size; |
cd30bcef | 6217 | unsigned int version, opcode_base; |
31e5a3a3 | 6218 | uint64_t length, diridx; |
f6f0e17b | 6219 | const unsigned char * end; |
4ccf1e31 JJ |
6220 | |
6221 | *dir_name = NULL; | |
6222 | if (section->start == NULL | |
6223 | || line_offset >= section->size | |
6224 | || fileidx == 0) | |
6225 | return NULL; | |
6226 | ||
6227 | hdrptr = section->start + line_offset; | |
f6f0e17b | 6228 | end = section->start + section->size; |
0c588247 NC |
6229 | |
6230 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
6231 | if (length == 0xffffffff) |
6232 | { | |
6233 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 6234 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 | 6235 | offset_size = 8; |
4ccf1e31 JJ |
6236 | } |
6237 | else | |
46d1214d AM |
6238 | offset_size = 4; |
6239 | ||
6240 | if (length > (size_t) (end - hdrptr) | |
6241 | || length < 2 + offset_size + 1 + 3 + 1) | |
4ccf1e31 | 6242 | return NULL; |
46d1214d | 6243 | end = hdrptr + length; |
0c588247 NC |
6244 | |
6245 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
6246 | if (version != 2 && version != 3 && version != 4) |
6247 | return NULL; | |
6248 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
6249 | if (version >= 4) | |
6250 | hdrptr++; /* Skip max_ops_per_insn. */ | |
6251 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
6252 | |
6253 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
46d1214d AM |
6254 | if (opcode_base == 0 |
6255 | || opcode_base - 1 >= (size_t) (end - hdrptr)) | |
4ccf1e31 | 6256 | return NULL; |
0c588247 | 6257 | |
4ccf1e31 | 6258 | hdrptr += opcode_base - 1; |
5c1c468d | 6259 | |
4ccf1e31 JJ |
6260 | dirtable = hdrptr; |
6261 | /* Skip over dirname table. */ | |
6262 | while (*hdrptr != '\0') | |
5c1c468d | 6263 | { |
46d1214d AM |
6264 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
6265 | if (hdrptr < end) | |
6266 | hdrptr++; | |
5c1c468d NC |
6267 | if (hdrptr >= end) |
6268 | return NULL; | |
6269 | } | |
4ccf1e31 | 6270 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 6271 | |
4ccf1e31 | 6272 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 6273 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 6274 | { |
46d1214d AM |
6275 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
6276 | if (hdrptr < end) | |
6277 | hdrptr++; | |
cd30bcef AM |
6278 | SKIP_ULEB (hdrptr, end); |
6279 | SKIP_ULEB (hdrptr, end); | |
6280 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 6281 | } |
5c1c468d | 6282 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 6283 | return NULL; |
5c1c468d | 6284 | |
4ccf1e31 | 6285 | file_name = hdrptr; |
46d1214d AM |
6286 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
6287 | if (hdrptr < end) | |
6288 | hdrptr++; | |
5c1c468d NC |
6289 | if (hdrptr >= end) |
6290 | return NULL; | |
cd30bcef | 6291 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
6292 | if (diridx == 0) |
6293 | return file_name; | |
5c1c468d | 6294 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
46d1214d AM |
6295 | { |
6296 | dirtable += strnlen ((char *) dirtable, end - dirtable); | |
6297 | if (dirtable < end) | |
6298 | dirtable++; | |
6299 | } | |
5c1c468d | 6300 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
6301 | return NULL; |
6302 | *dir_name = dirtable; | |
6303 | return file_name; | |
6304 | } | |
6305 | ||
6306 | static int | |
6307 | display_debug_macro (struct dwarf_section *section, | |
6308 | void *file) | |
6309 | { | |
6310 | unsigned char *start = section->start; | |
6311 | unsigned char *end = start + section->size; | |
6312 | unsigned char *curr = start; | |
6313 | unsigned char *extended_op_buf[256]; | |
015dc7e1 | 6314 | bool is_dwo = false; |
d296b736 NC |
6315 | const char *suffix = strrchr (section->name, '.'); |
6316 | ||
6317 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
015dc7e1 | 6318 | is_dwo = true; |
4ccf1e31 | 6319 | |
e548840a TV |
6320 | if (is_dwo) |
6321 | { | |
6322 | load_debug_section_with_follow (str_dwo, file); | |
6323 | load_debug_section_with_follow (str_index_dwo, file); | |
6324 | } | |
6325 | else | |
6326 | { | |
6327 | load_debug_section_with_follow (str, file); | |
6328 | load_debug_section_with_follow (str_index, file); | |
6329 | } | |
dda8d76d | 6330 | load_debug_section_with_follow (line, file); |
175b9150 | 6331 | |
015dc7e1 | 6332 | introduce (section, false); |
4ccf1e31 JJ |
6333 | |
6334 | while (curr < end) | |
6335 | { | |
6336 | unsigned int lineno, version, flags; | |
d296b736 | 6337 | unsigned int offset_size; |
0c588247 | 6338 | const unsigned char *string; |
31e5a3a3 | 6339 | uint64_t line_offset = 0, sec_offset = curr - start, offset; |
4ccf1e31 JJ |
6340 | unsigned char **extended_ops = NULL; |
6341 | ||
0c588247 | 6342 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 6343 | if (version != 4 && version != 5) |
4ccf1e31 | 6344 | { |
0e12f6c8 TV |
6345 | error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"), |
6346 | section->name, version); | |
4ccf1e31 JJ |
6347 | return 0; |
6348 | } | |
6349 | ||
0c588247 | 6350 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
d296b736 | 6351 | offset_size = (flags & 1) ? 8 : 4; |
cc443420 | 6352 | printf (_(" Offset: %#" PRIx64 "\n"), sec_offset); |
4ccf1e31 JJ |
6353 | printf (_(" Version: %d\n"), version); |
6354 | printf (_(" Offset size: %d\n"), offset_size); | |
6355 | if (flags & 2) | |
6356 | { | |
0c588247 | 6357 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
cc443420 | 6358 | printf (_(" Offset into .debug_line: %#" PRIx64 "\n"), |
31e5a3a3 | 6359 | line_offset); |
4ccf1e31 JJ |
6360 | } |
6361 | if (flags & 4) | |
6362 | { | |
0c588247 | 6363 | unsigned int i, count, op; |
31e5a3a3 | 6364 | uint64_t nargs, n; |
0c588247 NC |
6365 | |
6366 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 6367 | |
4ccf1e31 JJ |
6368 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
6369 | extended_ops = extended_op_buf; | |
6370 | if (count) | |
6371 | { | |
6372 | printf (_(" Extension opcode arguments:\n")); | |
6373 | for (i = 0; i < count; i++) | |
6374 | { | |
0c588247 | 6375 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 6376 | extended_ops[op] = curr; |
cd30bcef | 6377 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 6378 | if (nargs == 0) |
7a7e1061 | 6379 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
6380 | else |
6381 | { | |
7a7e1061 | 6382 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
6383 | for (n = 0; n < nargs; n++) |
6384 | { | |
0c588247 NC |
6385 | unsigned int form; |
6386 | ||
6387 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
6388 | printf ("%s%s", get_FORM_name (form), |
6389 | n == nargs - 1 ? "\n" : ", "); | |
6390 | switch (form) | |
6391 | { | |
6392 | case DW_FORM_data1: | |
6393 | case DW_FORM_data2: | |
6394 | case DW_FORM_data4: | |
6395 | case DW_FORM_data8: | |
6396 | case DW_FORM_sdata: | |
6397 | case DW_FORM_udata: | |
6398 | case DW_FORM_block: | |
6399 | case DW_FORM_block1: | |
6400 | case DW_FORM_block2: | |
6401 | case DW_FORM_block4: | |
6402 | case DW_FORM_flag: | |
6403 | case DW_FORM_string: | |
6404 | case DW_FORM_strp: | |
6405 | case DW_FORM_sec_offset: | |
6406 | break; | |
6407 | default: | |
6408 | error (_("Invalid extension opcode form %s\n"), | |
6409 | get_FORM_name (form)); | |
6410 | return 0; | |
6411 | } | |
6412 | } | |
6413 | } | |
6414 | } | |
6415 | } | |
6416 | } | |
6417 | printf ("\n"); | |
6418 | ||
6419 | while (1) | |
6420 | { | |
6421 | unsigned int op; | |
6422 | ||
6423 | if (curr >= end) | |
6424 | { | |
6425 | error (_(".debug_macro section not zero terminated\n")); | |
6426 | return 0; | |
6427 | } | |
6428 | ||
0c588247 | 6429 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
6430 | if (op == 0) |
6431 | break; | |
6432 | ||
6433 | switch (op) | |
6434 | { | |
e4b7104b NC |
6435 | case DW_MACRO_define: |
6436 | READ_ULEB (lineno, curr, end); | |
6437 | string = curr; | |
b0d461ec AM |
6438 | curr += strnlen ((char *) string, end - string); |
6439 | printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"), | |
6440 | lineno, (int) (curr - string), string); | |
6441 | if (curr < end) | |
6442 | curr++; | |
e4b7104b NC |
6443 | break; |
6444 | ||
6445 | case DW_MACRO_undef: | |
6446 | READ_ULEB (lineno, curr, end); | |
6447 | string = curr; | |
b0d461ec AM |
6448 | curr += strnlen ((char *) string, end - string); |
6449 | printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"), | |
6450 | lineno, (int) (curr - string), string); | |
6451 | if (curr < end) | |
6452 | curr++; | |
e4b7104b NC |
6453 | break; |
6454 | ||
7a7e1061 | 6455 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
6456 | { |
6457 | unsigned int filenum; | |
6458 | unsigned char *file_name = NULL, *dir_name = NULL; | |
6459 | ||
cd30bcef AM |
6460 | READ_ULEB (lineno, curr, end); |
6461 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
6462 | |
6463 | if ((flags & 2) == 0) | |
7a7e1061 | 6464 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
6465 | else |
6466 | file_name | |
6467 | = get_line_filename_and_dirname (line_offset, filenum, | |
6468 | &dir_name); | |
6469 | if (file_name == NULL) | |
7a7e1061 | 6470 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
6471 | lineno, filenum); |
6472 | else | |
7a7e1061 | 6473 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
6474 | lineno, filenum, |
6475 | dir_name != NULL ? (const char *) dir_name : "", | |
6476 | dir_name != NULL ? "/" : "", file_name); | |
6477 | } | |
6478 | break; | |
6479 | ||
7a7e1061 JK |
6480 | case DW_MACRO_end_file: |
6481 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
6482 | break; |
6483 | ||
7a7e1061 | 6484 | case DW_MACRO_define_strp: |
cd30bcef | 6485 | READ_ULEB (lineno, curr, end); |
d296b736 NC |
6486 | if (version == 4 && is_dwo) |
6487 | READ_ULEB (offset, curr, end); | |
6488 | else | |
6489 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
4ccf1e31 | 6490 | string = fetch_indirect_string (offset); |
7a7e1061 | 6491 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6492 | lineno, string); |
6493 | break; | |
6494 | ||
7a7e1061 | 6495 | case DW_MACRO_undef_strp: |
cd30bcef | 6496 | READ_ULEB (lineno, curr, end); |
d296b736 NC |
6497 | if (version == 4 && is_dwo) |
6498 | READ_ULEB (offset, curr, end); | |
6499 | else | |
6500 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
4ccf1e31 | 6501 | string = fetch_indirect_string (offset); |
7a7e1061 | 6502 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6503 | lineno, string); |
6504 | break; | |
6505 | ||
7a7e1061 | 6506 | case DW_MACRO_import: |
0c588247 | 6507 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
cc443420 | 6508 | printf (_(" DW_MACRO_import - offset : %#" PRIx64 "\n"), |
31e5a3a3 | 6509 | offset); |
4ccf1e31 JJ |
6510 | break; |
6511 | ||
7a7e1061 | 6512 | case DW_MACRO_define_sup: |
cd30bcef | 6513 | READ_ULEB (lineno, curr, end); |
0c588247 | 6514 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
31e5a3a3 | 6515 | printf (_(" DW_MACRO_define_sup - lineno : %d" |
cc443420 | 6516 | " macro offset : %#" PRIx64 "\n"), |
31e5a3a3 | 6517 | lineno, offset); |
a081f3cd JJ |
6518 | break; |
6519 | ||
7a7e1061 | 6520 | case DW_MACRO_undef_sup: |
cd30bcef | 6521 | READ_ULEB (lineno, curr, end); |
0c588247 | 6522 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
31e5a3a3 | 6523 | printf (_(" DW_MACRO_undef_sup - lineno : %d" |
cc443420 | 6524 | " macro offset : %#" PRIx64 "\n"), |
31e5a3a3 | 6525 | lineno, offset); |
a081f3cd JJ |
6526 | break; |
6527 | ||
7a7e1061 | 6528 | case DW_MACRO_import_sup: |
0c588247 | 6529 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
cc443420 | 6530 | printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64 "\n"), |
31e5a3a3 | 6531 | offset); |
a081f3cd JJ |
6532 | break; |
6533 | ||
e4b7104b NC |
6534 | case DW_MACRO_define_strx: |
6535 | case DW_MACRO_undef_strx: | |
6536 | READ_ULEB (lineno, curr, end); | |
6537 | READ_ULEB (offset, curr, end); | |
6538 | string = (const unsigned char *) | |
e548840a | 6539 | fetch_indexed_string (offset, NULL, offset_size, is_dwo, 0); |
e4b7104b NC |
6540 | if (op == DW_MACRO_define_strx) |
6541 | printf (" DW_MACRO_define_strx "); | |
6542 | else | |
6543 | printf (" DW_MACRO_undef_strx "); | |
6544 | if (do_wide) | |
cc443420 | 6545 | printf (_("(with offset %#" PRIx64 ") "), offset); |
e4b7104b NC |
6546 | printf (_("lineno : %d macro : %s\n"), |
6547 | lineno, string); | |
6548 | break; | |
6549 | ||
4ccf1e31 | 6550 | default: |
e4b7104b NC |
6551 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) |
6552 | { | |
6553 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); | |
6554 | break; | |
6555 | } | |
6556 | ||
4ccf1e31 JJ |
6557 | if (extended_ops == NULL || extended_ops[op] == NULL) |
6558 | { | |
6559 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
6560 | return 0; | |
6561 | } | |
6562 | else | |
6563 | { | |
6564 | /* Skip over unhandled opcodes. */ | |
31e5a3a3 | 6565 | uint64_t nargs, n; |
4ccf1e31 | 6566 | unsigned char *desc = extended_ops[op]; |
cd30bcef | 6567 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
6568 | if (nargs == 0) |
6569 | { | |
7a7e1061 | 6570 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
6571 | break; |
6572 | } | |
7a7e1061 | 6573 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
6574 | for (n = 0; n < nargs; n++) |
6575 | { | |
0c588247 NC |
6576 | int val; |
6577 | ||
77145576 | 6578 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 6579 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 6580 | curr |
77145576 | 6581 | = read_and_display_attr_value (0, val, 0, |
be38442d AM |
6582 | start, curr, end, 0, 0, |
6583 | offset_size, version, | |
6584 | NULL, 0, section, | |
ec1b0fbb | 6585 | NULL, ' ', -1); |
4ccf1e31 JJ |
6586 | if (n != nargs - 1) |
6587 | printf (","); | |
6588 | } | |
6589 | printf ("\n"); | |
6590 | } | |
6591 | break; | |
6592 | } | |
6593 | } | |
6594 | ||
6595 | printf ("\n"); | |
b4eb7656 | 6596 | } |
4ccf1e31 JJ |
6597 | |
6598 | return 1; | |
6599 | } | |
6600 | ||
19e6b90e L |
6601 | static int |
6602 | display_debug_abbrev (struct dwarf_section *section, | |
6603 | void *file ATTRIBUTE_UNUSED) | |
6604 | { | |
6605 | abbrev_entry *entry; | |
6606 | unsigned char *start = section->start; | |
19e6b90e | 6607 | |
015dc7e1 | 6608 | introduce (section, false); |
19e6b90e L |
6609 | |
6610 | do | |
6611 | { | |
31e5a3a3 | 6612 | uint64_t offset = start - section->start; |
f07c08e1 AM |
6613 | abbrev_list *list = find_and_process_abbrev_set (section, 0, |
6614 | section->size, offset, | |
6615 | NULL); | |
bcd213b2 | 6616 | if (list == NULL) |
f07c08e1 | 6617 | break; |
19e6b90e | 6618 | |
f07c08e1 | 6619 | if (list->first_abbrev) |
cc443420 | 6620 | printf (_(" Number TAG (%#" PRIx64 ")\n"), offset); |
19e6b90e | 6621 | |
bcd213b2 | 6622 | for (entry = list->first_abbrev; entry; entry = entry->next) |
19e6b90e L |
6623 | { |
6624 | abbrev_attr *attr; | |
6625 | ||
cc5914eb | 6626 | printf (" %ld %s [%s]\n", |
bcd213b2 | 6627 | entry->number, |
19e6b90e L |
6628 | get_TAG_name (entry->tag), |
6629 | entry->children ? _("has children") : _("no children")); | |
6630 | ||
6631 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
6632 | { |
6633 | printf (" %-18s %s", | |
6634 | get_AT_name (attr->attribute), | |
6635 | get_FORM_name (attr->form)); | |
6636 | if (attr->form == DW_FORM_implicit_const) | |
31e5a3a3 | 6637 | printf (": %" PRId64, attr->implicit_const); |
77145576 JK |
6638 | putchar ('\n'); |
6639 | } | |
19e6b90e | 6640 | } |
f07c08e1 AM |
6641 | start = list->start_of_next_abbrevs; |
6642 | free_abbrev_list (list); | |
19e6b90e L |
6643 | } |
6644 | while (start); | |
6645 | ||
6646 | printf ("\n"); | |
6647 | ||
6648 | return 1; | |
6649 | } | |
6650 | ||
42bcef4a AB |
6651 | /* Return true when ADDR is the maximum address, when addresses are |
6652 | POINTER_SIZE bytes long. */ | |
6653 | ||
015dc7e1 | 6654 | static bool |
31e5a3a3 | 6655 | is_max_address (uint64_t addr, unsigned int pointer_size) |
42bcef4a | 6656 | { |
31e5a3a3 | 6657 | uint64_t mask = ~(~(uint64_t) 0 << 1 << (pointer_size * 8 - 1)); |
42bcef4a AB |
6658 | return ((addr & mask) == mask); |
6659 | } | |
6660 | ||
9f272209 AO |
6661 | /* Display a view pair list starting at *VSTART_PTR and ending at |
6662 | VLISTEND within SECTION. */ | |
6663 | ||
6664 | static void | |
6665 | display_view_pair_list (struct dwarf_section *section, | |
6666 | unsigned char **vstart_ptr, | |
6667 | unsigned int debug_info_entry, | |
6668 | unsigned char *vlistend) | |
6669 | { | |
6670 | unsigned char *vstart = *vstart_ptr; | |
6671 | unsigned char *section_end = section->start + section->size; | |
6672 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
6673 | ||
6674 | if (vlistend < section_end) | |
6675 | section_end = vlistend; | |
6676 | ||
6677 | putchar ('\n'); | |
6678 | ||
6679 | while (vstart < section_end) | |
6680 | { | |
31e5a3a3 AM |
6681 | uint64_t off = vstart - section->start; |
6682 | uint64_t vbegin, vend; | |
9f272209 | 6683 | |
cd30bcef | 6684 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 6685 | if (vstart == section_end) |
cd30bcef | 6686 | break; |
9f272209 | 6687 | |
cd30bcef | 6688 | READ_ULEB (vend, vstart, section_end); |
31e5a3a3 | 6689 | printf (" %8.8" PRIx64 " ", off); |
9f272209 | 6690 | |
31e5a3a3 AM |
6691 | print_view (vbegin, pointer_size); |
6692 | print_view (vend, pointer_size); | |
9f272209 AO |
6693 | printf (_("location view pair\n")); |
6694 | } | |
6695 | ||
6696 | putchar ('\n'); | |
6697 | *vstart_ptr = vstart; | |
6698 | } | |
6699 | ||
4723351a CC |
6700 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
6701 | ||
6702 | static void | |
6703 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
6704 | unsigned char **start_ptr, |
6705 | unsigned int debug_info_entry, | |
31e5a3a3 AM |
6706 | uint64_t offset, |
6707 | uint64_t base_address, | |
9f272209 | 6708 | unsigned char **vstart_ptr, |
b4eb7656 | 6709 | int has_frame_base) |
4723351a | 6710 | { |
9f272209 | 6711 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6712 | unsigned char *section_end = section->start + section->size; |
31e5a3a3 | 6713 | uint64_t cu_offset; |
82b1b41b NC |
6714 | unsigned int pointer_size; |
6715 | unsigned int offset_size; | |
6716 | int dwarf_version; | |
31e5a3a3 AM |
6717 | uint64_t begin; |
6718 | uint64_t end; | |
4723351a CC |
6719 | unsigned short length; |
6720 | int need_frame_base; | |
6721 | ||
82b1b41b NC |
6722 | if (debug_info_entry >= num_debug_info_entries) |
6723 | { | |
6724 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
6725 | debug_info_entry); | |
6726 | return; | |
6727 | } | |
b4eb7656 | 6728 | |
82b1b41b NC |
6729 | cu_offset = debug_information [debug_info_entry].cu_offset; |
6730 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6731 | offset_size = debug_information [debug_info_entry].offset_size; | |
6732 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 6733 | |
f41e4712 NC |
6734 | if (pointer_size < 2 || pointer_size > 8) |
6735 | { | |
6736 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6737 | pointer_size, debug_info_entry); | |
6738 | return; | |
6739 | } | |
6740 | ||
4723351a CC |
6741 | while (1) |
6742 | { | |
31e5a3a3 AM |
6743 | uint64_t off = offset + (start - *start_ptr); |
6744 | uint64_t vbegin = -1, vend = -1; | |
d1c4b12b | 6745 | |
78480097 | 6746 | if (2 * pointer_size > (size_t) (section_end - start)) |
b4eb7656 | 6747 | { |
31e5a3a3 AM |
6748 | warn (_("Location list starting at offset %#" PRIx64 |
6749 | " is not terminated.\n"), offset); | |
b4eb7656 AM |
6750 | break; |
6751 | } | |
4723351a | 6752 | |
9745b5a7 | 6753 | printf (" "); |
31e5a3a3 | 6754 | print_hex (off, 4); |
fab128ef | 6755 | |
0c588247 NC |
6756 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
6757 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 6758 | |
4723351a | 6759 | if (begin == 0 && end == 0) |
b4eb7656 | 6760 | { |
d1c4b12b NC |
6761 | /* PR 18374: In a object file we can have a location list that |
6762 | starts with a begin and end of 0 because there are relocations | |
6763 | that need to be applied to the addresses. Actually applying | |
6764 | the relocations now does not help as they will probably resolve | |
6765 | to 0, since the object file has not been fully linked. Real | |
6766 | end of list markers will not have any relocations against them. */ | |
6767 | if (! reloc_at (section, off) | |
6768 | && ! reloc_at (section, off + pointer_size)) | |
6769 | { | |
6770 | printf (_("<End of list>\n")); | |
6771 | break; | |
6772 | } | |
b4eb7656 | 6773 | } |
4723351a CC |
6774 | |
6775 | /* Check base address specifiers. */ | |
42bcef4a | 6776 | if (is_max_address (begin, pointer_size) |
175b9150 | 6777 | && !is_max_address (end, pointer_size)) |
b4eb7656 AM |
6778 | { |
6779 | base_address = end; | |
31e5a3a3 AM |
6780 | print_hex (begin, pointer_size); |
6781 | print_hex (end, pointer_size); | |
b4eb7656 AM |
6782 | printf (_("(base address)\n")); |
6783 | continue; | |
6784 | } | |
4723351a | 6785 | |
9f272209 AO |
6786 | if (vstart) |
6787 | { | |
9f272209 AO |
6788 | off = offset + (vstart - *start_ptr); |
6789 | ||
cd30bcef | 6790 | READ_ULEB (vbegin, vstart, section_end); |
31e5a3a3 | 6791 | print_view (vbegin, pointer_size); |
9f272209 | 6792 | |
cd30bcef | 6793 | READ_ULEB (vend, vstart, section_end); |
31e5a3a3 | 6794 | print_view (vend, pointer_size); |
9f272209 | 6795 | |
31e5a3a3 | 6796 | printf (_("views at %8.8" PRIx64 " for:\n %*s "), off, 8, ""); |
9f272209 AO |
6797 | } |
6798 | ||
78480097 | 6799 | if (2 > (size_t) (section_end - start)) |
b4eb7656 | 6800 | { |
31e5a3a3 AM |
6801 | warn (_("Location list starting at offset %#" PRIx64 |
6802 | " is not terminated.\n"), offset); | |
b4eb7656 AM |
6803 | break; |
6804 | } | |
4723351a | 6805 | |
0c588247 | 6806 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6807 | |
78480097 | 6808 | if (length > (size_t) (section_end - start)) |
b4eb7656 | 6809 | { |
31e5a3a3 AM |
6810 | warn (_("Location list starting at offset %#" PRIx64 |
6811 | " is not terminated.\n"), offset); | |
b4eb7656 AM |
6812 | break; |
6813 | } | |
4723351a | 6814 | |
31e5a3a3 AM |
6815 | print_hex (begin + base_address, pointer_size); |
6816 | print_hex (end + base_address, pointer_size); | |
4723351a CC |
6817 | |
6818 | putchar ('('); | |
6819 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6820 | pointer_size, |
6821 | offset_size, | |
6822 | dwarf_version, | |
6823 | length, | |
6824 | cu_offset, section); | |
4723351a CC |
6825 | putchar (')'); |
6826 | ||
6827 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6828 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 6829 | |
9f272209 | 6830 | if (begin == end && vbegin == vend) |
b4eb7656 | 6831 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6832 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 6833 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
6834 | |
6835 | putchar ('\n'); | |
6836 | ||
6837 | start += length; | |
6838 | } | |
6839 | ||
6840 | *start_ptr = start; | |
9f272209 | 6841 | *vstart_ptr = vstart; |
4723351a CC |
6842 | } |
6843 | ||
77145576 JK |
6844 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6845 | ||
6846 | static void | |
19c26da6 NC |
6847 | display_loclists_list (struct dwarf_section * section, |
6848 | unsigned char ** start_ptr, | |
b05efa39 | 6849 | debug_info * debug_info_p, |
31e5a3a3 AM |
6850 | uint64_t offset, |
6851 | uint64_t base_address, | |
19c26da6 NC |
6852 | unsigned char ** vstart_ptr, |
6853 | int has_frame_base) | |
77145576 | 6854 | { |
31e5a3a3 AM |
6855 | unsigned char *start = *start_ptr; |
6856 | unsigned char *vstart = *vstart_ptr; | |
6857 | unsigned char *section_end = section->start + section->size; | |
6858 | uint64_t cu_offset; | |
6859 | unsigned int pointer_size; | |
6860 | unsigned int offset_size; | |
6861 | unsigned int dwarf_version; | |
236b4847 | 6862 | uint64_t idx; |
77145576 | 6863 | |
9dfd0db9 | 6864 | /* Initialize it due to a false compiler warning. */ |
31e5a3a3 AM |
6865 | uint64_t begin = -1, vbegin = -1; |
6866 | uint64_t end = -1, vend = -1; | |
6867 | uint64_t length; | |
77145576 JK |
6868 | int need_frame_base; |
6869 | ||
b05efa39 VA |
6870 | cu_offset = debug_info_p->cu_offset; |
6871 | pointer_size = debug_info_p->pointer_size; | |
6872 | offset_size = debug_info_p->offset_size; | |
6873 | dwarf_version = debug_info_p->dwarf_version; | |
77145576 JK |
6874 | |
6875 | if (pointer_size < 2 || pointer_size > 8) | |
6876 | { | |
6877 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
b05efa39 | 6878 | pointer_size, (int)(debug_info_p - debug_information)); |
77145576 JK |
6879 | return; |
6880 | } | |
6881 | ||
6882 | while (1) | |
6883 | { | |
31e5a3a3 | 6884 | uint64_t off = offset + (start - *start_ptr); |
77145576 JK |
6885 | enum dwarf_location_list_entry_type llet; |
6886 | ||
6887 | if (start + 1 > section_end) | |
6888 | { | |
31e5a3a3 AM |
6889 | warn (_("Location list starting at offset %#" PRIx64 |
6890 | " is not terminated.\n"), offset); | |
77145576 JK |
6891 | break; |
6892 | } | |
6893 | ||
9745b5a7 | 6894 | printf (" "); |
31e5a3a3 | 6895 | print_hex (off, 4); |
77145576 JK |
6896 | |
6897 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6898 | ||
1c9f770d MW |
6899 | if (vstart && (llet == DW_LLE_offset_pair |
6900 | || llet == DW_LLE_start_end | |
6901 | || llet == DW_LLE_start_length)) | |
9f272209 AO |
6902 | { |
6903 | off = offset + (vstart - *start_ptr); | |
6904 | ||
cd30bcef | 6905 | READ_ULEB (vbegin, vstart, section_end); |
31e5a3a3 | 6906 | print_view (vbegin, pointer_size); |
9f272209 | 6907 | |
cd30bcef | 6908 | READ_ULEB (vend, vstart, section_end); |
31e5a3a3 | 6909 | print_view (vend, pointer_size); |
9f272209 | 6910 | |
31e5a3a3 | 6911 | printf (_("views at %8.8" PRIx64 " for:\n %*s "), off, 8, ""); |
9f272209 AO |
6912 | } |
6913 | ||
77145576 JK |
6914 | switch (llet) |
6915 | { | |
6916 | case DW_LLE_end_of_list: | |
6917 | printf (_("<End of list>\n")); | |
6918 | break; | |
19c26da6 NC |
6919 | |
6920 | case DW_LLE_base_addressx: | |
236b4847 JB |
6921 | READ_ULEB (idx, start, section_end); |
6922 | print_hex (idx, pointer_size); | |
19c26da6 | 6923 | printf (_("(index into .debug_addr) ")); |
b05efa39 | 6924 | base_address = fetch_indexed_addr |
236b4847 | 6925 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); |
31e5a3a3 | 6926 | print_hex (base_address, pointer_size); |
19c26da6 NC |
6927 | printf (_("(base address)\n")); |
6928 | break; | |
6929 | ||
6930 | case DW_LLE_startx_endx: | |
236b4847 | 6931 | READ_ULEB (idx, start, section_end); |
b05efa39 | 6932 | begin = fetch_indexed_addr |
236b4847 JB |
6933 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); |
6934 | READ_ULEB (idx, start, section_end); | |
b05efa39 | 6935 | end = fetch_indexed_addr |
236b4847 | 6936 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); |
19c26da6 NC |
6937 | break; |
6938 | ||
6939 | case DW_LLE_startx_length: | |
236b4847 | 6940 | READ_ULEB (idx, start, section_end); |
b05efa39 | 6941 | begin = fetch_indexed_addr |
236b4847 | 6942 | (debug_info_p->addr_base + idx * pointer_size, pointer_size); |
19c26da6 NC |
6943 | READ_ULEB (end, start, section_end); |
6944 | end += begin; | |
6945 | break; | |
6946 | ||
6947 | case DW_LLE_default_location: | |
6948 | begin = end = 0; | |
6949 | break; | |
175b9150 | 6950 | |
77145576 | 6951 | case DW_LLE_offset_pair: |
cd30bcef | 6952 | READ_ULEB (begin, start, section_end); |
1c9f770d | 6953 | begin += base_address; |
cd30bcef | 6954 | READ_ULEB (end, start, section_end); |
1c9f770d MW |
6955 | end += base_address; |
6956 | break; | |
19c26da6 NC |
6957 | |
6958 | case DW_LLE_base_address: | |
6959 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6960 | section_end); | |
31e5a3a3 | 6961 | print_hex (base_address, pointer_size); |
19c26da6 NC |
6962 | printf (_("(base address)\n")); |
6963 | break; | |
6964 | ||
1c9f770d MW |
6965 | case DW_LLE_start_end: |
6966 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6967 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
6968 | break; | |
19c26da6 | 6969 | |
1c9f770d MW |
6970 | case DW_LLE_start_length: |
6971 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6972 | READ_ULEB (end, start, section_end); | |
6973 | end += begin; | |
77145576 | 6974 | break; |
19c26da6 | 6975 | |
9f272209 AO |
6976 | #ifdef DW_LLE_view_pair |
6977 | case DW_LLE_view_pair: | |
6978 | if (vstart) | |
6979 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 6980 | READ_ULEB (vbegin, start, section_end); |
31e5a3a3 | 6981 | print_view (vbegin, pointer_size); |
9f272209 | 6982 | |
cd30bcef | 6983 | READ_ULEB (vend, start, section_end); |
31e5a3a3 | 6984 | print_view (vend, pointer_size); |
9f272209 AO |
6985 | |
6986 | printf (_("views for:\n")); | |
6987 | continue; | |
6988 | #endif | |
19c26da6 | 6989 | |
77145576 JK |
6990 | default: |
6991 | error (_("Invalid location list entry type %d\n"), llet); | |
6992 | return; | |
6993 | } | |
19c26da6 | 6994 | |
77145576 JK |
6995 | if (llet == DW_LLE_end_of_list) |
6996 | break; | |
19c26da6 NC |
6997 | |
6998 | if (llet == DW_LLE_base_address | |
6999 | || llet == DW_LLE_base_addressx) | |
77145576 JK |
7000 | continue; |
7001 | ||
78480097 | 7002 | if (start == section_end) |
77145576 | 7003 | { |
31e5a3a3 AM |
7004 | warn (_("Location list starting at offset %#" PRIx64 |
7005 | " is not terminated.\n"), offset); | |
77145576 JK |
7006 | break; |
7007 | } | |
cd30bcef | 7008 | READ_ULEB (length, start, section_end); |
77145576 | 7009 | |
78480097 AM |
7010 | if (length > (size_t) (section_end - start)) |
7011 | { | |
31e5a3a3 AM |
7012 | warn (_("Location list starting at offset %#" PRIx64 |
7013 | " is not terminated.\n"), offset); | |
78480097 AM |
7014 | break; |
7015 | } | |
7016 | ||
31e5a3a3 AM |
7017 | print_hex (begin, pointer_size); |
7018 | print_hex (end, pointer_size); | |
77145576 JK |
7019 | |
7020 | putchar ('('); | |
7021 | need_frame_base = decode_location_expression (start, | |
7022 | pointer_size, | |
7023 | offset_size, | |
7024 | dwarf_version, | |
7025 | length, | |
7026 | cu_offset, section); | |
7027 | putchar (')'); | |
7028 | ||
7029 | if (need_frame_base && !has_frame_base) | |
7030 | printf (_(" [without DW_AT_frame_base]")); | |
7031 | ||
9f272209 | 7032 | if (begin == end && vbegin == vend) |
77145576 | 7033 | fputs (_(" (start == end)"), stdout); |
9f272209 | 7034 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
7035 | fputs (_(" (start > end)"), stdout); |
7036 | ||
7037 | putchar ('\n'); | |
7038 | ||
7039 | start += length; | |
9f272209 | 7040 | vbegin = vend = -1; |
77145576 JK |
7041 | } |
7042 | ||
31e5a3a3 | 7043 | if (vbegin != (uint64_t) -1 || vend != (uint64_t) -1) |
9f272209 AO |
7044 | printf (_("Trailing view pair not used in a range")); |
7045 | ||
77145576 | 7046 | *start_ptr = start; |
9f272209 | 7047 | *vstart_ptr = vstart; |
77145576 JK |
7048 | } |
7049 | ||
fab128ef CC |
7050 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
7051 | right-adjusted in a field of length LEN, and followed by a space. */ | |
7052 | ||
7053 | static void | |
7054 | print_addr_index (unsigned int idx, unsigned int len) | |
7055 | { | |
7056 | static char buf[15]; | |
7057 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 7058 | printf ("%*s ", len, buf); |
fab128ef CC |
7059 | } |
7060 | ||
4723351a CC |
7061 | /* Display a location list from a .dwo section. It uses address indexes rather |
7062 | than embedded addresses. This code closely follows display_loc_list, but the | |
7063 | two are sufficiently different that combining things is very ugly. */ | |
7064 | ||
7065 | static void | |
7066 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
7067 | unsigned char **start_ptr, |
7068 | unsigned int debug_info_entry, | |
31e5a3a3 | 7069 | uint64_t offset, |
9f272209 | 7070 | unsigned char **vstart_ptr, |
b4eb7656 | 7071 | int has_frame_base) |
4723351a | 7072 | { |
9f272209 | 7073 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 7074 | unsigned char *section_end = section->start + section->size; |
31e5a3a3 | 7075 | uint64_t cu_offset; |
82b1b41b NC |
7076 | unsigned int pointer_size; |
7077 | unsigned int offset_size; | |
7078 | int dwarf_version; | |
4723351a CC |
7079 | int entry_type; |
7080 | unsigned short length; | |
7081 | int need_frame_base; | |
fab128ef | 7082 | unsigned int idx; |
4723351a | 7083 | |
82b1b41b NC |
7084 | if (debug_info_entry >= num_debug_info_entries) |
7085 | { | |
7086 | warn (_("No debug information for loc lists of entry: %u\n"), | |
7087 | debug_info_entry); | |
7088 | return; | |
7089 | } | |
7090 | ||
7091 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
7092 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
7093 | offset_size = debug_information [debug_info_entry].offset_size; | |
7094 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
7095 | ||
f41e4712 NC |
7096 | if (pointer_size < 2 || pointer_size > 8) |
7097 | { | |
7098 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
7099 | pointer_size, debug_info_entry); | |
7100 | return; | |
7101 | } | |
7102 | ||
4723351a CC |
7103 | while (1) |
7104 | { | |
9745b5a7 | 7105 | printf (" "); |
31e5a3a3 | 7106 | print_hex (offset + (start - *start_ptr), 4); |
4723351a | 7107 | |
fab128ef | 7108 | if (start >= section_end) |
b4eb7656 | 7109 | { |
31e5a3a3 AM |
7110 | warn (_("Location list starting at offset %#" PRIx64 |
7111 | " is not terminated.\n"), offset); | |
b4eb7656 AM |
7112 | break; |
7113 | } | |
4723351a | 7114 | |
0c588247 | 7115 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
7116 | |
7117 | if (vstart) | |
7118 | switch (entry_type) | |
7119 | { | |
7120 | default: | |
7121 | break; | |
7122 | ||
7123 | case 2: | |
7124 | case 3: | |
7125 | case 4: | |
7126 | { | |
31e5a3a3 AM |
7127 | uint64_t view; |
7128 | uint64_t off = offset + (vstart - *start_ptr); | |
9f272209 | 7129 | |
cd30bcef | 7130 | READ_ULEB (view, vstart, section_end); |
31e5a3a3 | 7131 | print_view (view, 8); |
9f272209 | 7132 | |
cd30bcef | 7133 | READ_ULEB (view, vstart, section_end); |
31e5a3a3 | 7134 | print_view (view, 8); |
9f272209 | 7135 | |
31e5a3a3 | 7136 | printf (_("views at %8.8" PRIx64 " for:\n %*s "), off, 8, ""); |
9f272209 AO |
7137 | |
7138 | } | |
7139 | break; | |
7140 | } | |
7141 | ||
4723351a | 7142 | switch (entry_type) |
b4eb7656 AM |
7143 | { |
7144 | case 0: /* A terminating entry. */ | |
7145 | *start_ptr = start; | |
9f272209 | 7146 | *vstart_ptr = vstart; |
b4eb7656 AM |
7147 | printf (_("<End of list>\n")); |
7148 | return; | |
7149 | case 1: /* A base-address entry. */ | |
cd30bcef | 7150 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 7151 | print_addr_index (idx, 8); |
9f272209 | 7152 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
7153 | printf (_("(base address selection entry)\n")); |
7154 | continue; | |
7155 | case 2: /* A start/end entry. */ | |
cd30bcef | 7156 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 7157 | print_addr_index (idx, 8); |
cd30bcef | 7158 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
7159 | print_addr_index (idx, 8); |
7160 | break; | |
7161 | case 3: /* A start/length entry. */ | |
cd30bcef | 7162 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
7163 | print_addr_index (idx, 8); |
7164 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
7165 | printf ("%08x ", idx); | |
7166 | break; | |
7167 | case 4: /* An offset pair entry. */ | |
7168 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
7169 | printf ("%08x ", idx); | |
7170 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
7171 | printf ("%08x ", idx); | |
7172 | break; | |
7173 | default: | |
7174 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
7175 | *start_ptr = start; | |
9f272209 | 7176 | *vstart_ptr = vstart; |
b4eb7656 AM |
7177 | return; |
7178 | } | |
4723351a | 7179 | |
78480097 | 7180 | if (2 > (size_t) (section_end - start)) |
b4eb7656 | 7181 | { |
31e5a3a3 AM |
7182 | warn (_("Location list starting at offset %#" PRIx64 |
7183 | " is not terminated.\n"), offset); | |
b4eb7656 AM |
7184 | break; |
7185 | } | |
4723351a | 7186 | |
0c588247 | 7187 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
78480097 | 7188 | if (length > (size_t) (section_end - start)) |
b4eb7656 | 7189 | { |
31e5a3a3 AM |
7190 | warn (_("Location list starting at offset %#" PRIx64 |
7191 | " is not terminated.\n"), offset); | |
b4eb7656 AM |
7192 | break; |
7193 | } | |
4723351a CC |
7194 | |
7195 | putchar ('('); | |
7196 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
7197 | pointer_size, |
7198 | offset_size, | |
7199 | dwarf_version, | |
7200 | length, | |
7201 | cu_offset, section); | |
4723351a CC |
7202 | putchar (')'); |
7203 | ||
7204 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 7205 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
7206 | |
7207 | putchar ('\n'); | |
7208 | ||
7209 | start += length; | |
7210 | } | |
7211 | ||
7212 | *start_ptr = start; | |
9f272209 | 7213 | *vstart_ptr = vstart; |
4723351a CC |
7214 | } |
7215 | ||
9f272209 AO |
7216 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
7217 | loc_views. */ | |
51d0d03f | 7218 | |
31e5a3a3 | 7219 | static uint64_t *loc_offsets, *loc_views; |
51d0d03f JJ |
7220 | |
7221 | static int | |
7222 | loc_offsets_compar (const void *ap, const void *bp) | |
7223 | { | |
31e5a3a3 AM |
7224 | uint64_t a = loc_offsets[*(const unsigned int *) ap]; |
7225 | uint64_t b = loc_offsets[*(const unsigned int *) bp]; | |
51d0d03f | 7226 | |
9f272209 AO |
7227 | int ret = (a > b) - (b > a); |
7228 | if (ret) | |
7229 | return ret; | |
7230 | ||
7231 | a = loc_views[*(const unsigned int *) ap]; | |
7232 | b = loc_views[*(const unsigned int *) bp]; | |
7233 | ||
7234 | ret = (a > b) - (b > a); | |
7235 | ||
7236 | return ret; | |
51d0d03f JJ |
7237 | } |
7238 | ||
b05efa39 VA |
7239 | /* Reads and dumps the DWARFv5 loclists compiler unit header, |
7240 | including the offset table. | |
7241 | Returns the offset of the next compile unit header. */ | |
7242 | ||
7243 | static uint64_t | |
7244 | display_loclists_unit_header (struct dwarf_section * section, | |
7245 | uint64_t header_offset, | |
7246 | uint32_t * offset_count, | |
7247 | unsigned char ** loclists_start) | |
19c26da6 | 7248 | { |
b05efa39 VA |
7249 | uint64_t length; |
7250 | unsigned char *start = section->start + header_offset; | |
7251 | unsigned char *end = section->start + section->size; | |
7252 | unsigned short version; | |
7253 | unsigned char address_size; | |
7254 | unsigned char segment_selector_size; | |
7255 | bool is_64bit; | |
7256 | uint32_t i; | |
19c26da6 | 7257 | |
b05efa39 | 7258 | printf (_("Table at Offset %#" PRIx64 "\n"), header_offset); |
19c26da6 | 7259 | |
b05efa39 VA |
7260 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
7261 | if (length == 0xffffffff) | |
19c26da6 | 7262 | { |
b05efa39 VA |
7263 | is_64bit = true; |
7264 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); | |
7265 | } | |
7266 | else | |
7267 | is_64bit = false; | |
19c26da6 | 7268 | |
b05efa39 VA |
7269 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); |
7270 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, end); | |
7271 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, end); | |
7272 | SAFE_BYTE_GET_AND_INC (*offset_count, start, 4, end); | |
19c26da6 | 7273 | |
b05efa39 VA |
7274 | printf (_(" Length: %#" PRIx64 "\n"), length); |
7275 | printf (_(" DWARF version: %u\n"), version); | |
7276 | printf (_(" Address size: %u\n"), address_size); | |
7277 | printf (_(" Segment size: %u\n"), segment_selector_size); | |
7278 | printf (_(" Offset entries: %u\n"), *offset_count); | |
175b9150 | 7279 | |
b05efa39 VA |
7280 | if (segment_selector_size != 0) |
7281 | { | |
7282 | warn (_("The %s section contains an " | |
7283 | "unsupported segment selector size: %d.\n"), | |
7284 | section->name, segment_selector_size); | |
7285 | return (uint64_t)-1; | |
7286 | } | |
175b9150 | 7287 | |
b05efa39 VA |
7288 | if ( *offset_count) |
7289 | { | |
cc443420 | 7290 | printf (_("\n Offset Entries starting at %#tx:\n"), |
31e5a3a3 | 7291 | start - section->start); |
19c26da6 | 7292 | |
b05efa39 | 7293 | for (i = 0; i < *offset_count; i++) |
19c26da6 | 7294 | { |
31e5a3a3 | 7295 | uint64_t entry; |
19c26da6 | 7296 | |
31e5a3a3 | 7297 | SAFE_BYTE_GET_AND_INC (entry, start, is_64bit ? 8 : 4, end); |
cc443420 | 7298 | printf (_(" [%6u] %#" PRIx64 "\n"), i, entry); |
19c26da6 | 7299 | } |
19c26da6 | 7300 | } |
19c26da6 | 7301 | |
b05efa39 VA |
7302 | putchar ('\n'); |
7303 | *loclists_start = start; | |
7304 | ||
7305 | /* The length field doesn't include the length field itself. */ | |
7306 | return header_offset + length + (is_64bit ? 12 : 4); | |
19c26da6 NC |
7307 | } |
7308 | ||
19e6b90e L |
7309 | static int |
7310 | display_debug_loc (struct dwarf_section *section, void *file) | |
7311 | { | |
9f272209 | 7312 | unsigned char *start = section->start, *vstart = NULL; |
31e5a3a3 | 7313 | uint64_t bytes; |
19e6b90e L |
7314 | unsigned char *section_begin = start; |
7315 | unsigned int num_loc_list = 0; | |
31e5a3a3 AM |
7316 | uint64_t last_offset = 0; |
7317 | uint64_t last_view = 0; | |
19e6b90e L |
7318 | unsigned int first = 0; |
7319 | unsigned int i; | |
7320 | unsigned int j; | |
7321 | int seen_first_offset = 0; | |
51d0d03f | 7322 | int locs_sorted = 1; |
9f272209 | 7323 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 7324 | unsigned int *array = NULL; |
4723351a | 7325 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 7326 | bool is_dwo = false; |
82bdc396 | 7327 | bool is_loclists = strstr (section->name, "debug_loclists") != NULL; |
b05efa39 | 7328 | uint64_t next_header_offset = 0; |
4723351a CC |
7329 | |
7330 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
015dc7e1 | 7331 | is_dwo = true; |
19e6b90e L |
7332 | |
7333 | bytes = section->size; | |
19e6b90e L |
7334 | |
7335 | if (bytes == 0) | |
7336 | { | |
7337 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7338 | return 0; | |
7339 | } | |
7340 | ||
77145576 JK |
7341 | if (is_loclists) |
7342 | { | |
7343 | unsigned char *hdrptr = section_begin; | |
31e5a3a3 | 7344 | uint64_t ll_length; |
77145576 JK |
7345 | unsigned short ll_version; |
7346 | unsigned char *end = section_begin + section->size; | |
7347 | unsigned char address_size, segment_selector_size; | |
7348 | uint32_t offset_entry_count; | |
7349 | ||
7350 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
7351 | if (ll_length == 0xffffffff) | |
7352 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
7353 | ||
7354 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
7355 | if (ll_version != 5) | |
7356 | { | |
7357 | warn (_("The %s section contains corrupt or " | |
7358 | "unsupported version number: %d.\n"), | |
7359 | section->name, ll_version); | |
7360 | return 0; | |
7361 | } | |
7362 | ||
7363 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
7364 | ||
7365 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
7366 | if (segment_selector_size != 0) | |
7367 | { | |
7368 | warn (_("The %s section contains " | |
7369 | "unsupported segment selector size: %d.\n"), | |
7370 | section->name, segment_selector_size); | |
7371 | return 0; | |
7372 | } | |
7373 | ||
7374 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
19c26da6 | 7375 | |
b05efa39 VA |
7376 | /*if (offset_entry_count != 0) |
7377 | return display_offset_entry_loclists (section);*/ | |
77145576 | 7378 | |
b05efa39 | 7379 | //header_size = hdrptr - section_begin; |
77145576 JK |
7380 | } |
7381 | ||
1febe64d NC |
7382 | if (load_debug_info (file) == 0) |
7383 | { | |
7384 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7385 | section->name); | |
7386 | return 0; | |
7387 | } | |
19e6b90e L |
7388 | |
7389 | /* Check the order of location list in .debug_info section. If | |
7390 | offsets of location lists are in the ascending order, we can | |
7391 | use `debug_information' directly. */ | |
7392 | for (i = 0; i < num_debug_info_entries; i++) | |
7393 | { | |
7394 | unsigned int num; | |
7395 | ||
7396 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
7397 | if (num > num_loc_list) |
7398 | num_loc_list = num; | |
19e6b90e L |
7399 | |
7400 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 7401 | if (locs_sorted && num != 0) |
19e6b90e L |
7402 | { |
7403 | if (!seen_first_offset) | |
7404 | { | |
7405 | /* This is the first location list. */ | |
7406 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 7407 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
7408 | first = i; |
7409 | seen_first_offset = 1; | |
7410 | j = 1; | |
7411 | } | |
7412 | else | |
7413 | j = 0; | |
7414 | ||
7415 | for (; j < num; j++) | |
7416 | { | |
cb1861cb | 7417 | if (last_offset > debug_information [i].loc_offsets [j] |
9f272209 AO |
7418 | || (last_offset == debug_information [i].loc_offsets [j] |
7419 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 7420 | { |
51d0d03f | 7421 | locs_sorted = 0; |
19e6b90e L |
7422 | break; |
7423 | } | |
7424 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 7425 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
7426 | } |
7427 | } | |
7428 | } | |
7429 | ||
19e6b90e L |
7430 | if (!seen_first_offset) |
7431 | error (_("No location lists in .debug_info section!\n")); | |
7432 | ||
51d0d03f JJ |
7433 | if (!locs_sorted) |
7434 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d | 7435 | |
015dc7e1 | 7436 | introduce (section, false); |
dda8d76d | 7437 | |
d1c4b12b NC |
7438 | if (reloc_at (section, 0)) |
7439 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 7440 | |
b05efa39 VA |
7441 | if (!is_loclists) |
7442 | printf (_(" Offset Begin End Expression\n")); | |
19e6b90e | 7443 | |
19e6b90e L |
7444 | for (i = first; i < num_debug_info_entries; i++) |
7445 | { | |
de3b4032 | 7446 | uint64_t offset = 0, voffset = 0; |
31e5a3a3 | 7447 | uint64_t base_address; |
d1c4b12b | 7448 | unsigned int k; |
19e6b90e | 7449 | int has_frame_base; |
cb1861cb AM |
7450 | debug_info *debug_info_p = debug_information + i; |
7451 | uint32_t offset_count; | |
19e6b90e | 7452 | |
82bdc396 L |
7453 | /* .debug_loclists section is loaded into debug_information as |
7454 | DWARF-5 debug info and .debug_loc section is loaded into | |
7455 | debug_information as pre-DWARF-5 debug info. When dumping | |
7456 | .debug_loc section, we should only process pre-DWARF-5 debug | |
7457 | info in debug_information. When dumping .debug_loclists | |
7458 | section, we should only process DWARF-5 info in | |
7459 | debug_information. */ | |
7460 | if ((debug_info_p->dwarf_version >= 5) != is_loclists) | |
7461 | continue; | |
7462 | ||
51d0d03f JJ |
7463 | if (!locs_sorted) |
7464 | { | |
b05efa39 | 7465 | for (k = 0; k < debug_info_p->num_loc_offsets; k++) |
51d0d03f | 7466 | array[k] = k; |
b05efa39 VA |
7467 | loc_offsets = debug_info_p->loc_offsets; |
7468 | loc_views = debug_info_p->loc_views; | |
7469 | qsort (array, debug_info_p->num_loc_offsets, | |
51d0d03f JJ |
7470 | sizeof (*array), loc_offsets_compar); |
7471 | } | |
19e6b90e | 7472 | |
de3b4032 CC |
7473 | /* .debug_loclists has a per-unit header. |
7474 | Update start if we are detecting it. */ | |
82bdc396 | 7475 | if (debug_info_p->dwarf_version >= 5) |
de3b4032 CC |
7476 | { |
7477 | j = locs_sorted ? 0 : array [0]; | |
7478 | ||
b05efa39 VA |
7479 | if (debug_info_p->num_loc_offsets) |
7480 | offset = debug_info_p->loc_offsets [j]; | |
de3b4032 | 7481 | |
b05efa39 VA |
7482 | if (debug_info_p->num_loc_views) |
7483 | voffset = debug_info_p->loc_views [j]; | |
de3b4032 | 7484 | |
b05efa39 VA |
7485 | /* Parse and dump unit headers in loclists. |
7486 | This will misbehave if the order of CUs in debug_info | |
7487 | doesn't match the one in loclists. */ | |
7488 | if (next_header_offset < offset) | |
7489 | { | |
7490 | while (next_header_offset < offset) | |
7491 | { | |
7492 | next_header_offset = display_loclists_unit_header | |
7493 | (section, next_header_offset, &offset_count, &start); | |
7494 | ||
7495 | if (next_header_offset == (uint64_t)-1) | |
7496 | /* Header parsing error. */ | |
7497 | return 0; | |
7498 | } | |
7499 | ||
7500 | printf (_("\ | |
7501 | Offset Begin End Expression\n")); | |
7502 | } | |
de3b4032 CC |
7503 | } |
7504 | ||
9f272209 | 7505 | int adjacent_view_loclists = 1; |
b05efa39 VA |
7506 | |
7507 | for (k = 0; k < debug_info_p->num_loc_offsets; k++) | |
19e6b90e | 7508 | { |
51d0d03f JJ |
7509 | j = locs_sorted ? k : array[k]; |
7510 | if (k | |
b05efa39 | 7511 | && (debug_info_p->loc_offsets [locs_sorted |
cb1861cb | 7512 | ? k - 1 : array [k - 1]] |
b05efa39 VA |
7513 | == debug_info_p->loc_offsets [j]) |
7514 | && (debug_info_p->loc_views [locs_sorted | |
cb1861cb | 7515 | ? k - 1 : array [k - 1]] |
b05efa39 | 7516 | == debug_info_p->loc_views [j])) |
51d0d03f | 7517 | continue; |
b05efa39 VA |
7518 | has_frame_base = debug_info_p->have_frame_base [j]; |
7519 | offset = debug_info_p->loc_offsets [j]; | |
19e6b90e | 7520 | next = section_begin + offset; |
b05efa39 | 7521 | voffset = debug_info_p->loc_views [j]; |
31e5a3a3 | 7522 | if (voffset != (uint64_t) -1) |
9f272209 AO |
7523 | vnext = section_begin + voffset; |
7524 | else | |
7525 | vnext = NULL; | |
b05efa39 | 7526 | base_address = debug_info_p->base_address; |
19e6b90e | 7527 | |
9f272209 AO |
7528 | if (vnext && vnext < next) |
7529 | { | |
7530 | vstart = vnext; | |
7531 | display_view_pair_list (section, &vstart, i, next); | |
7532 | if (start == vnext) | |
7533 | start = vstart; | |
7534 | } | |
7535 | ||
de3b4032 | 7536 | if (start < next) |
19e6b90e | 7537 | { |
de3b4032 | 7538 | if (vnext && vnext < next) |
31e5a3a3 AM |
7539 | warn (_("There is a hole [%#tx - %#" PRIx64 "]" |
7540 | " in %s section.\n"), | |
de3b4032 CC |
7541 | start - section_begin, voffset, section->name); |
7542 | else | |
7543 | warn (_("There is a hole [%#tx - %#" PRIx64 "]" | |
31e5a3a3 AM |
7544 | " in %s section.\n"), |
7545 | start - section_begin, offset, section->name); | |
19e6b90e | 7546 | } |
de3b4032 CC |
7547 | else if (start > next) |
7548 | warn (_("There is an overlap [%#tx - %#" PRIx64 "]" | |
7549 | " in %s section.\n"), | |
7550 | start - section_begin, offset, section->name); | |
19e6b90e | 7551 | start = next; |
9f272209 | 7552 | vstart = vnext; |
19e6b90e L |
7553 | |
7554 | if (offset >= bytes) | |
7555 | { | |
31e5a3a3 AM |
7556 | warn (_("Offset %#" PRIx64 " is bigger than %s section size.\n"), |
7557 | offset, section->name); | |
19e6b90e L |
7558 | continue; |
7559 | } | |
7560 | ||
9f272209 AO |
7561 | if (vnext && voffset >= bytes) |
7562 | { | |
31e5a3a3 AM |
7563 | warn (_("View Offset %#" PRIx64 " is bigger than %s section size.\n"), |
7564 | voffset, section->name); | |
9f272209 AO |
7565 | continue; |
7566 | } | |
7567 | ||
77145576 JK |
7568 | if (!is_loclists) |
7569 | { | |
7570 | if (is_dwo) | |
7571 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 7572 | &vstart, has_frame_base); |
77145576 JK |
7573 | else |
7574 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 7575 | &vstart, has_frame_base); |
77145576 | 7576 | } |
b4eb7656 | 7577 | else |
77145576 JK |
7578 | { |
7579 | if (is_dwo) | |
7580 | warn (_("DWO is not yet supported.\n")); | |
7581 | else | |
b05efa39 VA |
7582 | display_loclists_list (section, &start, debug_info_p, offset, |
7583 | base_address, &vstart, has_frame_base); | |
9f272209 AO |
7584 | } |
7585 | ||
7586 | /* FIXME: this arrangement is quite simplistic. Nothing | |
7587 | requires locview lists to be adjacent to corresponding | |
7588 | loclists, and a single loclist could be augmented by | |
7589 | different locview lists, and vice-versa, unlikely as it | |
7590 | is that it would make sense to do so. Hopefully we'll | |
7591 | have view pair support built into loclists before we ever | |
7592 | need to address all these possibilities. */ | |
7593 | if (adjacent_view_loclists && vnext | |
7594 | && vnext != start && vstart != next) | |
7595 | { | |
7596 | adjacent_view_loclists = 0; | |
7597 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 7598 | } |
9f272209 AO |
7599 | |
7600 | if (vnext && vnext == start) | |
7601 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
7602 | } |
7603 | } | |
031cd65f | 7604 | |
4723351a | 7605 | if (start < section->start + section->size) |
d3a49aa8 AM |
7606 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
7607 | "There are %ld unused bytes at the end of section %s\n", | |
7608 | (long) (section->start + section->size - start)), | |
4723351a | 7609 | (long) (section->start + section->size - start), section->name); |
98fb390a | 7610 | putchar ('\n'); |
51d0d03f | 7611 | free (array); |
19e6b90e L |
7612 | return 1; |
7613 | } | |
7614 | ||
7615 | static int | |
7616 | display_debug_str (struct dwarf_section *section, | |
7617 | void *file ATTRIBUTE_UNUSED) | |
7618 | { | |
7619 | unsigned char *start = section->start; | |
31e5a3a3 AM |
7620 | uint64_t bytes = section->size; |
7621 | uint64_t addr = section->address; | |
19e6b90e L |
7622 | |
7623 | if (bytes == 0) | |
7624 | { | |
7625 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7626 | return 0; | |
7627 | } | |
7628 | ||
015dc7e1 | 7629 | introduce (section, false); |
19e6b90e L |
7630 | |
7631 | while (bytes) | |
7632 | { | |
7633 | int j; | |
7634 | int k; | |
7635 | int lbytes; | |
7636 | ||
7637 | lbytes = (bytes > 16 ? 16 : bytes); | |
7638 | ||
31e5a3a3 | 7639 | printf (" 0x%8.8" PRIx64 " ", addr); |
19e6b90e L |
7640 | |
7641 | for (j = 0; j < 16; j++) | |
7642 | { | |
7643 | if (j < lbytes) | |
7644 | printf ("%2.2x", start[j]); | |
7645 | else | |
7646 | printf (" "); | |
7647 | ||
7648 | if ((j & 3) == 3) | |
7649 | printf (" "); | |
7650 | } | |
7651 | ||
7652 | for (j = 0; j < lbytes; j++) | |
7653 | { | |
7654 | k = start[j]; | |
7655 | if (k >= ' ' && k < 0x80) | |
7656 | printf ("%c", k); | |
7657 | else | |
7658 | printf ("."); | |
7659 | } | |
7660 | ||
7661 | putchar ('\n'); | |
7662 | ||
7663 | start += lbytes; | |
7664 | addr += lbytes; | |
7665 | bytes -= lbytes; | |
7666 | } | |
7667 | ||
7668 | putchar ('\n'); | |
7669 | ||
7670 | return 1; | |
7671 | } | |
7672 | ||
19e6b90e L |
7673 | static int |
7674 | display_debug_info (struct dwarf_section *section, void *file) | |
7675 | { | |
015dc7e1 | 7676 | return process_debug_info (section, file, section->abbrev_sec, false, false); |
19e6b90e L |
7677 | } |
7678 | ||
2b6f5997 CC |
7679 | static int |
7680 | display_debug_types (struct dwarf_section *section, void *file) | |
7681 | { | |
015dc7e1 | 7682 | return process_debug_info (section, file, section->abbrev_sec, false, true); |
6f875884 TG |
7683 | } |
7684 | ||
7685 | static int | |
7686 | display_trace_info (struct dwarf_section *section, void *file) | |
7687 | { | |
015dc7e1 | 7688 | return process_debug_info (section, file, section->abbrev_sec, false, true); |
2b6f5997 | 7689 | } |
19e6b90e L |
7690 | |
7691 | static int | |
7692 | display_debug_aranges (struct dwarf_section *section, | |
7693 | void *file ATTRIBUTE_UNUSED) | |
7694 | { | |
7695 | unsigned char *start = section->start; | |
7696 | unsigned char *end = start + section->size; | |
7697 | ||
015dc7e1 | 7698 | introduce (section, false); |
19e6b90e | 7699 | |
6e3d6dc1 NC |
7700 | /* It does not matter if this load fails, |
7701 | we test for that later on. */ | |
7702 | load_debug_info (file); | |
7703 | ||
19e6b90e L |
7704 | while (start < end) |
7705 | { | |
7706 | unsigned char *hdrptr; | |
7707 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 7708 | unsigned char *addr_ranges; |
31e5a3a3 AM |
7709 | uint64_t length; |
7710 | uint64_t address; | |
7711 | uint64_t sec_off; | |
53b8873b | 7712 | unsigned char address_size; |
31e5a3a3 | 7713 | unsigned int offset_size; |
6ca07350 | 7714 | unsigned char *end_ranges; |
19e6b90e L |
7715 | |
7716 | hdrptr = start; | |
6ca07350 | 7717 | sec_off = hdrptr - section->start; |
19e6b90e | 7718 | |
0c588247 | 7719 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
7720 | if (arange.ar_length == 0xffffffff) |
7721 | { | |
0c588247 | 7722 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e | 7723 | offset_size = 8; |
19e6b90e L |
7724 | } |
7725 | else | |
6ca07350 | 7726 | offset_size = 4; |
19e6b90e | 7727 | |
6ca07350 | 7728 | if (arange.ar_length > (size_t) (end - hdrptr)) |
e98fdf1a | 7729 | { |
31e5a3a3 AM |
7730 | warn (_("Debug info is corrupted, %s header at %#" PRIx64 |
7731 | " has length %#" PRIx64 "\n"), | |
7732 | section->name, sec_off, arange.ar_length); | |
e98fdf1a AM |
7733 | break; |
7734 | } | |
6ca07350 | 7735 | end_ranges = hdrptr + arange.ar_length; |
e98fdf1a | 7736 | |
6ca07350 AM |
7737 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end_ranges); |
7738 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, | |
7739 | end_ranges); | |
19e6b90e | 7740 | |
6e3d6dc1 NC |
7741 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
7742 | && num_debug_info_entries > 0 | |
7743 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
31e5a3a3 AM |
7744 | warn (_(".debug_info offset of %#" PRIx64 |
7745 | " in %s section does not point to a CU header.\n"), | |
7746 | arange.ar_info_offset, section->name); | |
6e3d6dc1 | 7747 | |
6ca07350 AM |
7748 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end_ranges); |
7749 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end_ranges); | |
19e6b90e L |
7750 | |
7751 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
7752 | { | |
67f101ee NC |
7753 | /* PR 19872: A version number of 0 probably means that there is |
7754 | padding at the end of the .debug_aranges section. Gold puts | |
7755 | it there when performing an incremental link, for example. | |
7756 | So do not generate a warning in this case. */ | |
7757 | if (arange.ar_version) | |
7758 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
7759 | break; |
7760 | } | |
7761 | ||
31e5a3a3 | 7762 | printf (_(" Length: %" PRId64 "\n"), arange.ar_length); |
19e6b90e | 7763 | printf (_(" Version: %d\n"), arange.ar_version); |
cc443420 | 7764 | printf (_(" Offset into .debug_info: %#" PRIx64 "\n"), |
31e5a3a3 | 7765 | arange.ar_info_offset); |
19e6b90e L |
7766 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
7767 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
7768 | ||
53b8873b NC |
7769 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
7770 | ||
f41e4712 NC |
7771 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
7772 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
7773 | { |
7774 | error (_("Invalid address size in %s section!\n"), | |
7775 | section->name); | |
7776 | break; | |
7777 | } | |
7778 | ||
53b8873b NC |
7779 | /* The DWARF spec does not require that the address size be a power |
7780 | of two, but we do. This will have to change if we ever encounter | |
7781 | an uneven architecture. */ | |
7782 | if ((address_size & (address_size - 1)) != 0) | |
7783 | { | |
7784 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
7785 | break; | |
7786 | } | |
cecf136e | 7787 | |
209c9a13 NC |
7788 | if (address_size > 4) |
7789 | printf (_("\n Address Length\n")); | |
7790 | else | |
7791 | printf (_("\n Address Length\n")); | |
19e6b90e | 7792 | |
91d6fa6a | 7793 | addr_ranges = hdrptr; |
19e6b90e | 7794 | |
53b8873b | 7795 | /* Must pad to an alignment boundary that is twice the address size. */ |
359c7441 AM |
7796 | addr_ranges += (2 * address_size - 1 |
7797 | - (hdrptr - start - 1) % (2 * address_size)); | |
19e6b90e | 7798 | |
359c7441 | 7799 | while (2 * address_size <= end_ranges - addr_ranges) |
19e6b90e | 7800 | { |
359c7441 AM |
7801 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, |
7802 | end_ranges); | |
7803 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, | |
7804 | end_ranges); | |
80c35038 | 7805 | printf (" "); |
31e5a3a3 | 7806 | print_hex (address, address_size); |
cc443420 | 7807 | print_hex_ns (length, address_size); |
2d9472a2 | 7808 | putchar ('\n'); |
19e6b90e | 7809 | } |
359c7441 AM |
7810 | |
7811 | start = end_ranges; | |
19e6b90e L |
7812 | } |
7813 | ||
7814 | printf ("\n"); | |
7815 | ||
7816 | return 1; | |
7817 | } | |
7818 | ||
4723351a CC |
7819 | /* Comparison function for qsort. */ |
7820 | static int | |
7821 | comp_addr_base (const void * v0, const void * v1) | |
7822 | { | |
d367307b AM |
7823 | debug_info *info0 = *(debug_info **) v0; |
7824 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
7825 | return info0->addr_base - info1->addr_base; |
7826 | } | |
7827 | ||
7828 | /* Display the debug_addr section. */ | |
7829 | static int | |
7830 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 7831 | void *file) |
4723351a CC |
7832 | { |
7833 | debug_info **debug_addr_info; | |
7834 | unsigned char *entry; | |
7835 | unsigned char *end; | |
7836 | unsigned int i; | |
7837 | unsigned int count; | |
0e12f6c8 | 7838 | unsigned char * header; |
4723351a CC |
7839 | |
7840 | if (section->size == 0) | |
7841 | { | |
7842 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7843 | return 0; | |
7844 | } | |
7845 | ||
7846 | if (load_debug_info (file) == 0) | |
7847 | { | |
7848 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7849 | section->name); | |
7850 | return 0; | |
7851 | } | |
7852 | ||
015dc7e1 | 7853 | introduce (section, false); |
4723351a | 7854 | |
1306a742 NC |
7855 | /* PR 17531: file: cf38d01b. |
7856 | We use xcalloc because a corrupt file may not have initialised all of the | |
7857 | fields in the debug_info structure, which means that the sort below might | |
7858 | try to move uninitialised data. */ | |
7859 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 7860 | sizeof (debug_info *)); |
4723351a CC |
7861 | |
7862 | count = 0; | |
7863 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 7864 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
7865 | { |
7866 | /* PR 17531: file: cf38d01b. */ | |
7867 | if (debug_information[i].addr_base >= section->size) | |
31e5a3a3 AM |
7868 | warn (_("Corrupt address base (%#" PRIx64 ")" |
7869 | " found in debug section %u\n"), | |
7870 | debug_information[i].addr_base, i); | |
1306a742 NC |
7871 | else |
7872 | debug_addr_info [count++] = debug_information + i; | |
7873 | } | |
4723351a CC |
7874 | |
7875 | /* Add a sentinel to make iteration convenient. */ | |
7876 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
7877 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 7878 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 7879 | |
0e12f6c8 | 7880 | header = section->start; |
4723351a CC |
7881 | for (i = 0; i < count; i++) |
7882 | { | |
7883 | unsigned int idx; | |
fab128ef | 7884 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a | 7885 | |
cc443420 | 7886 | printf (_(" For compilation unit at offset %#" PRIx64 ":\n"), |
31e5a3a3 | 7887 | debug_addr_info [i]->cu_offset); |
4723351a | 7888 | |
fab128ef | 7889 | printf (_("\tIndex\tAddress\n")); |
4723351a | 7890 | entry = section->start + debug_addr_info [i]->addr_base; |
0e12f6c8 TV |
7891 | if (debug_addr_info [i]->dwarf_version >= 5) |
7892 | { | |
31e5a3a3 AM |
7893 | size_t header_size = entry - header; |
7894 | unsigned char *curr_header = header; | |
7895 | uint64_t length; | |
7896 | int version; | |
7897 | int segment_selector_size; | |
0e12f6c8 TV |
7898 | |
7899 | if (header_size != 8 && header_size != 16) | |
7900 | { | |
2b34e067 | 7901 | warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"), |
31e5a3a3 | 7902 | section->name, header_size); |
1024d59c | 7903 | break; |
0e12f6c8 TV |
7904 | } |
7905 | ||
7906 | SAFE_BYTE_GET_AND_INC (length, curr_header, 4, entry); | |
7907 | if (length == 0xffffffff) | |
a7077ce7 | 7908 | SAFE_BYTE_GET_AND_INC (length, curr_header, 8, entry); |
956bc7a2 AM |
7909 | if (length > (size_t) (section->start + section->size - curr_header) |
7910 | || length < (size_t) (entry - curr_header)) | |
c8628c77 AM |
7911 | { |
7912 | warn (_("Corrupt %s section: unit_length field of %#" PRIx64 | |
2b34e067 | 7913 | " is invalid\n"), section->name, length); |
1024d59c | 7914 | break; |
c8628c77 | 7915 | } |
0e12f6c8 | 7916 | end = curr_header + length; |
0e12f6c8 TV |
7917 | SAFE_BYTE_GET_AND_INC (version, curr_header, 2, entry); |
7918 | if (version != 5) | |
7919 | warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"), | |
7920 | section->name, version); | |
7921 | ||
7922 | SAFE_BYTE_GET_AND_INC (address_size, curr_header, 1, entry); | |
7923 | SAFE_BYTE_GET_AND_INC (segment_selector_size, curr_header, 1, entry); | |
7924 | address_size += segment_selector_size; | |
7925 | } | |
7926 | else | |
956bc7a2 | 7927 | end = section->start + debug_addr_info [i + 1]->addr_base; |
fa501b69 | 7928 | |
0e12f6c8 | 7929 | header = end; |
4723351a | 7930 | idx = 0; |
fa501b69 | 7931 | |
42f39fde NC |
7932 | if (address_size < 1 || address_size > sizeof (uint64_t)) |
7933 | { | |
2b34e067 | 7934 | warn (_("Corrupt %s section: address size (%x) is wrong\n"), |
42f39fde | 7935 | section->name, address_size); |
1024d59c | 7936 | break; |
42f39fde NC |
7937 | } |
7938 | ||
c8628c77 | 7939 | while ((size_t) (end - entry) >= address_size) |
b4eb7656 | 7940 | { |
31e5a3a3 | 7941 | uint64_t base = byte_get (entry, address_size); |
b4eb7656 | 7942 | printf (_("\t%d:\t"), idx); |
cc443420 | 7943 | print_hex_ns (base, address_size); |
b4eb7656 AM |
7944 | printf ("\n"); |
7945 | entry += address_size; | |
7946 | idx++; | |
7947 | } | |
4723351a CC |
7948 | } |
7949 | printf ("\n"); | |
7950 | ||
1024d59c | 7951 | free (debug_addr_info[count]); |
4723351a | 7952 | free (debug_addr_info); |
1024d59c | 7953 | return i == count; |
4723351a CC |
7954 | } |
7955 | ||
7956 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 7957 | |
4723351a CC |
7958 | static int |
7959 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 7960 | void *file ATTRIBUTE_UNUSED) |
4723351a | 7961 | { |
9f27c364 HPN |
7962 | unsigned long idx; |
7963 | ||
4723351a CC |
7964 | if (section->size == 0) |
7965 | { | |
7966 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7967 | return 0; | |
7968 | } | |
e4b7104b NC |
7969 | |
7970 | unsigned char *start = section->start; | |
7971 | unsigned char *end = start + section->size; | |
7972 | unsigned char *curr = start; | |
31e5a3a3 | 7973 | uint64_t debug_str_offsets_hdr_len; |
e4b7104b | 7974 | |
63b4cc53 | 7975 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 7976 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
39f381cb NC |
7977 | |
7978 | if (dwo) | |
7979 | load_debug_section_with_follow (str_dwo, file); | |
7980 | else | |
7981 | load_debug_section_with_follow (str, file); | |
e4b7104b | 7982 | |
015dc7e1 | 7983 | introduce (section, false); |
e4b7104b NC |
7984 | |
7985 | while (curr < end) | |
7986 | { | |
31e5a3a3 AM |
7987 | uint64_t length; |
7988 | uint64_t entry_length; | |
e4b7104b NC |
7989 | |
7990 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
7991 | /* FIXME: We assume that this means 64-bit DWARF is being used. */ | |
7992 | if (length == 0xffffffff) | |
7993 | { | |
a7077ce7 | 7994 | SAFE_BYTE_GET_AND_INC (length, curr, 8, end); |
e4b7104b | 7995 | entry_length = 8; |
40711542 | 7996 | debug_str_offsets_hdr_len = 16; |
e4b7104b NC |
7997 | } |
7998 | else | |
40711542 BK |
7999 | { |
8000 | entry_length = 4; | |
8001 | debug_str_offsets_hdr_len = 8; | |
8002 | } | |
e4b7104b | 8003 | |
95abb394 | 8004 | unsigned char *entries_end; |
39f381cb NC |
8005 | if (length == 0) |
8006 | { | |
8007 | /* This is probably an old style .debug_str_offset section which | |
8008 | just contains offsets and no header (and the first offset is 0). */ | |
8009 | length = section->size; | |
8010 | curr = section->start; | |
95abb394 | 8011 | entries_end = end; |
7e4f1f4b | 8012 | debug_str_offsets_hdr_len = 0; |
e4b7104b | 8013 | |
31e5a3a3 | 8014 | printf (_(" Length: %#" PRIx64 "\n"), length); |
39f381cb NC |
8015 | printf (_(" Index Offset [String]\n")); |
8016 | } | |
8017 | else | |
8018 | { | |
31e5a3a3 | 8019 | if (length <= (size_t) (end - curr)) |
b96a1bcb AM |
8020 | entries_end = curr + length; |
8021 | else | |
8022 | { | |
31e5a3a3 AM |
8023 | warn (_("Section %s is too small %#" PRIx64 "\n"), |
8024 | section->name, section->size); | |
b96a1bcb AM |
8025 | entries_end = end; |
8026 | } | |
95abb394 | 8027 | |
39f381cb | 8028 | int version; |
5250d2f0 | 8029 | SAFE_BYTE_GET_AND_INC (version, curr, 2, entries_end); |
39f381cb NC |
8030 | if (version != 5) |
8031 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); | |
8032 | ||
8033 | int padding; | |
5250d2f0 | 8034 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, entries_end); |
39f381cb NC |
8035 | if (padding != 0) |
8036 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); | |
8037 | ||
31e5a3a3 AM |
8038 | printf (_(" Length: %#" PRIx64 "\n"), length); |
8039 | printf (_(" Version: %#x\n"), version); | |
39f381cb NC |
8040 | printf (_(" Index Offset [String]\n")); |
8041 | } | |
e4b7104b | 8042 | |
95abb394 | 8043 | for (idx = 0; curr < entries_end; idx++) |
e4b7104b | 8044 | { |
31e5a3a3 | 8045 | uint64_t offset; |
e4b7104b NC |
8046 | const unsigned char * string; |
8047 | ||
31e5a3a3 | 8048 | if ((size_t) (entries_end - curr) < entry_length) |
95abb394 TV |
8049 | /* Not enough space to read one entry_length, give up. */ |
8050 | return 0; | |
8051 | ||
c4375dd7 | 8052 | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, entries_end); |
39f381cb NC |
8053 | if (dwo) |
8054 | string = (const unsigned char *) | |
40711542 | 8055 | fetch_indexed_string (idx, NULL, entry_length, dwo, debug_str_offsets_hdr_len); |
39f381cb NC |
8056 | else |
8057 | string = fetch_indirect_string (offset); | |
8058 | ||
31e5a3a3 AM |
8059 | printf (" %8lu ", idx); |
8060 | print_hex (offset, entry_length); | |
8061 | printf (" %s\n", string); | |
e4b7104b NC |
8062 | } |
8063 | } | |
39f381cb | 8064 | |
4723351a CC |
8065 | return 1; |
8066 | } | |
8067 | ||
01a8f077 JK |
8068 | /* Each debug_information[x].range_lists[y] gets this representation for |
8069 | sorting purposes. */ | |
8070 | ||
8071 | struct range_entry | |
467c65bc NC |
8072 | { |
8073 | /* The debug_information[x].range_lists[y] value. */ | |
31e5a3a3 | 8074 | uint64_t ranges_offset; |
01a8f077 | 8075 | |
467c65bc NC |
8076 | /* Original debug_information to find parameters of the data. */ |
8077 | debug_info *debug_info_p; | |
8078 | }; | |
01a8f077 JK |
8079 | |
8080 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
8081 | ||
8082 | static int | |
8083 | range_entry_compar (const void *ap, const void *bp) | |
8084 | { | |
3f5e193b NC |
8085 | const struct range_entry *a_re = (const struct range_entry *) ap; |
8086 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
31e5a3a3 AM |
8087 | const uint64_t a = a_re->ranges_offset; |
8088 | const uint64_t b = b_re->ranges_offset; | |
01a8f077 JK |
8089 | |
8090 | return (a > b) - (b > a); | |
8091 | } | |
8092 | ||
f72c4fa3 | 8093 | static unsigned char * |
9745b5a7 NC |
8094 | display_debug_ranges_list (unsigned char * start, |
8095 | unsigned char * finish, | |
8096 | unsigned int pointer_size, | |
31e5a3a3 AM |
8097 | uint64_t offset, |
8098 | uint64_t base_address) | |
77145576 JK |
8099 | { |
8100 | while (start < finish) | |
8101 | { | |
31e5a3a3 AM |
8102 | uint64_t begin; |
8103 | uint64_t end; | |
77145576 JK |
8104 | |
8105 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
8106 | if (start >= finish) | |
8107 | break; | |
8108 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
8109 | ||
9745b5a7 | 8110 | printf (" "); |
31e5a3a3 | 8111 | print_hex (offset, 4); |
77145576 JK |
8112 | |
8113 | if (begin == 0 && end == 0) | |
8114 | { | |
8115 | printf (_("<End of list>\n")); | |
8116 | break; | |
8117 | } | |
8118 | ||
8119 | /* Check base address specifiers. */ | |
8120 | if (is_max_address (begin, pointer_size) | |
8121 | && !is_max_address (end, pointer_size)) | |
8122 | { | |
8123 | base_address = end; | |
31e5a3a3 AM |
8124 | print_hex (begin, pointer_size); |
8125 | print_hex (end, pointer_size); | |
77145576 JK |
8126 | printf ("(base address)\n"); |
8127 | continue; | |
8128 | } | |
8129 | ||
31e5a3a3 | 8130 | print_hex (begin + base_address, pointer_size); |
cc443420 | 8131 | print_hex_ns (end + base_address, pointer_size); |
77145576 JK |
8132 | |
8133 | if (begin == end) | |
cc443420 | 8134 | fputs (_(" (start == end)"), stdout); |
77145576 | 8135 | else if (begin > end) |
cc443420 | 8136 | fputs (_(" (start > end)"), stdout); |
77145576 JK |
8137 | |
8138 | putchar ('\n'); | |
8139 | } | |
f72c4fa3 L |
8140 | |
8141 | return start; | |
77145576 JK |
8142 | } |
8143 | ||
dbcbf67c | 8144 | static unsigned char * |
9745b5a7 NC |
8145 | display_debug_rnglists_list (unsigned char * start, |
8146 | unsigned char * finish, | |
8147 | unsigned int pointer_size, | |
31e5a3a3 AM |
8148 | uint64_t offset, |
8149 | uint64_t base_address, | |
84102ebc | 8150 | uint64_t addr_base) |
77145576 JK |
8151 | { |
8152 | unsigned char *next = start; | |
8153 | ||
8154 | while (1) | |
8155 | { | |
31e5a3a3 | 8156 | uint64_t off = offset + (start - next); |
77145576 | 8157 | enum dwarf_range_list_entry rlet; |
9dfd0db9 | 8158 | /* Initialize it due to a false compiler warning. */ |
31e5a3a3 | 8159 | uint64_t begin = -1, length, end = -1; |
77145576 | 8160 | |
669f463d | 8161 | if (start >= finish) |
77145576 | 8162 | { |
31e5a3a3 AM |
8163 | warn (_("Range list starting at offset %#" PRIx64 |
8164 | " is not terminated.\n"), offset); | |
77145576 JK |
8165 | break; |
8166 | } | |
8167 | ||
9745b5a7 | 8168 | printf (" "); |
31e5a3a3 | 8169 | print_hex (off, 4); |
77145576 JK |
8170 | |
8171 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
8172 | ||
8173 | switch (rlet) | |
8174 | { | |
8175 | case DW_RLE_end_of_list: | |
8176 | printf (_("<End of list>\n")); | |
8177 | break; | |
19c26da6 NC |
8178 | case DW_RLE_base_addressx: |
8179 | READ_ULEB (base_address, start, finish); | |
31e5a3a3 | 8180 | print_hex (base_address, pointer_size); |
19c26da6 | 8181 | printf (_("(base address index) ")); |
1b19566b | 8182 | base_address = fetch_indexed_addr (base_address * pointer_size + addr_base, |
84102ebc | 8183 | pointer_size); |
31e5a3a3 | 8184 | print_hex (base_address, pointer_size); |
77145576 JK |
8185 | printf (_("(base address)\n")); |
8186 | break; | |
19c26da6 NC |
8187 | case DW_RLE_startx_endx: |
8188 | READ_ULEB (begin, start, finish); | |
8189 | READ_ULEB (end, start, finish); | |
1b19566b | 8190 | begin = fetch_indexed_addr (begin * pointer_size + addr_base, |
84102ebc | 8191 | pointer_size); |
1b19566b | 8192 | end = fetch_indexed_addr (end * pointer_size + addr_base, |
84102ebc | 8193 | pointer_size); |
19c26da6 NC |
8194 | break; |
8195 | case DW_RLE_startx_length: | |
8196 | READ_ULEB (begin, start, finish); | |
cd30bcef | 8197 | READ_ULEB (length, start, finish); |
1b19566b | 8198 | begin = fetch_indexed_addr (begin * pointer_size + addr_base, |
84102ebc | 8199 | pointer_size); |
77145576 JK |
8200 | end = begin + length; |
8201 | break; | |
8202 | case DW_RLE_offset_pair: | |
cd30bcef AM |
8203 | READ_ULEB (begin, start, finish); |
8204 | READ_ULEB (end, start, finish); | |
77145576 | 8205 | break; |
19c26da6 NC |
8206 | case DW_RLE_base_address: |
8207 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
31e5a3a3 | 8208 | print_hex (base_address, pointer_size); |
19c26da6 NC |
8209 | printf (_("(base address)\n")); |
8210 | break; | |
77145576 JK |
8211 | case DW_RLE_start_end: |
8212 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
8213 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
8214 | break; | |
19c26da6 NC |
8215 | case DW_RLE_start_length: |
8216 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
8217 | READ_ULEB (length, start, finish); | |
8218 | end = begin + length; | |
8219 | break; | |
77145576 JK |
8220 | default: |
8221 | error (_("Invalid range list entry type %d\n"), rlet); | |
8222 | rlet = DW_RLE_end_of_list; | |
8223 | break; | |
8224 | } | |
ec41dd75 | 8225 | |
77145576 JK |
8226 | if (rlet == DW_RLE_end_of_list) |
8227 | break; | |
19c26da6 | 8228 | if (rlet == DW_RLE_base_address || rlet == DW_RLE_base_addressx) |
77145576 JK |
8229 | continue; |
8230 | ||
4d932715 BE |
8231 | /* Only a DW_RLE_offset_pair needs the base address added. */ |
8232 | if (rlet == DW_RLE_offset_pair) | |
8233 | { | |
8234 | begin += base_address; | |
8235 | end += base_address; | |
8236 | } | |
8237 | ||
31e5a3a3 AM |
8238 | print_hex (begin, pointer_size); |
8239 | print_hex (end, pointer_size); | |
77145576 JK |
8240 | |
8241 | if (begin == end) | |
31e5a3a3 | 8242 | fputs (_(" (start == end)"), stdout); |
77145576 | 8243 | else if (begin > end) |
31e5a3a3 | 8244 | fputs (_(" (start > end)"), stdout); |
77145576 JK |
8245 | |
8246 | putchar ('\n'); | |
8247 | } | |
dbcbf67c NC |
8248 | |
8249 | return start; | |
77145576 JK |
8250 | } |
8251 | ||
19e6b90e | 8252 | static int |
84102ebc VA |
8253 | display_debug_rnglists_unit_header (struct dwarf_section * section, |
8254 | uint64_t * unit_offset, | |
8255 | unsigned char * poffset_size) | |
19e6b90e | 8256 | { |
84102ebc VA |
8257 | uint64_t start_offset = *unit_offset; |
8258 | unsigned char * p = section->start + start_offset; | |
8259 | unsigned char * finish = section->start + section->size; | |
8260 | uint64_t initial_length; | |
8261 | unsigned char segment_selector_size; | |
8262 | unsigned int offset_entry_count; | |
8263 | unsigned int i; | |
8264 | unsigned short version; | |
8265 | unsigned char address_size = 0; | |
8266 | unsigned char offset_size; | |
19e6b90e | 8267 | |
84102ebc VA |
8268 | /* Get and check the length of the block. */ |
8269 | SAFE_BYTE_GET_AND_INC (initial_length, p, 4, finish); | |
77145576 | 8270 | |
84102ebc VA |
8271 | if (initial_length == 0xffffffff) |
8272 | { | |
8273 | /* This section is 64-bit DWARF 3. */ | |
8274 | SAFE_BYTE_GET_AND_INC (initial_length, p, 8, finish); | |
8275 | *poffset_size = offset_size = 8; | |
8276 | } | |
8277 | else | |
8278 | *poffset_size = offset_size = 4; | |
77145576 | 8279 | |
84102ebc VA |
8280 | if (initial_length > (size_t) (finish - p)) |
8281 | { | |
8282 | /* If the length field has a relocation against it, then we should | |
8283 | not complain if it is inaccurate (and probably negative). | |
8284 | It is copied from .debug_line handling code. */ | |
8285 | if (reloc_at (section, (p - section->start) - offset_size)) | |
8286 | initial_length = finish - p; | |
77145576 | 8287 | else |
77145576 | 8288 | { |
84102ebc VA |
8289 | warn (_("The length field (%#" PRIx64 |
8290 | ") in the debug_rnglists header is wrong" | |
8291 | " - the section is too small\n"), | |
8292 | initial_length); | |
77145576 JK |
8293 | return 0; |
8294 | } | |
84102ebc | 8295 | } |
77145576 | 8296 | |
84102ebc VA |
8297 | /* Report the next unit offset to the caller. */ |
8298 | *unit_offset = (p - section->start) + initial_length; | |
77145576 | 8299 | |
84102ebc VA |
8300 | /* Get the other fields in the header. */ |
8301 | SAFE_BYTE_GET_AND_INC (version, p, 2, finish); | |
8302 | SAFE_BYTE_GET_AND_INC (address_size, p, 1, finish); | |
8303 | SAFE_BYTE_GET_AND_INC (segment_selector_size, p, 1, finish); | |
8304 | SAFE_BYTE_GET_AND_INC (offset_entry_count, p, 4, finish); | |
dbcbf67c | 8305 | |
84102ebc VA |
8306 | printf (_(" Table at Offset: %#" PRIx64 ":\n"), start_offset); |
8307 | printf (_(" Length: %#" PRIx64 "\n"), initial_length); | |
8308 | printf (_(" DWARF version: %u\n"), version); | |
8309 | printf (_(" Address size: %u\n"), address_size); | |
8310 | printf (_(" Segment size: %u\n"), segment_selector_size); | |
8311 | printf (_(" Offset entries: %u\n"), offset_entry_count); | |
19c26da6 | 8312 | |
84102ebc VA |
8313 | /* Check the fields. */ |
8314 | if (segment_selector_size != 0) | |
8315 | { | |
8316 | warn (_("The %s section contains " | |
8317 | "unsupported segment selector size: %d.\n"), | |
8318 | section->name, segment_selector_size); | |
8319 | return 0; | |
8320 | } | |
19c26da6 | 8321 | |
84102ebc VA |
8322 | if (version < 5) |
8323 | { | |
8324 | warn (_("Only DWARF version 5+ debug_rnglists info " | |
8325 | "is currently supported.\n")); | |
8326 | return 0; | |
8327 | } | |
8328 | ||
8329 | if (offset_entry_count != 0) | |
8330 | { | |
8331 | printf (_("\n Offsets starting at %#tx:\n"), p - section->start); | |
dbcbf67c NC |
8332 | |
8333 | for (i = 0; i < offset_entry_count; i++) | |
8334 | { | |
84102ebc | 8335 | uint64_t entry; |
dbcbf67c | 8336 | |
84102ebc VA |
8337 | SAFE_BYTE_GET_AND_INC (entry, p, offset_size, finish); |
8338 | printf (_(" [%6u] %#" PRIx64 "\n"), i, entry); | |
dbcbf67c | 8339 | } |
19c26da6 | 8340 | } |
dbcbf67c NC |
8341 | |
8342 | return 1; | |
8343 | } | |
8344 | ||
589d38af NC |
8345 | static bool |
8346 | is_range_list_for_this_section (bool is_rnglists, unsigned int version) | |
8347 | { | |
8348 | if (is_rnglists && version > 4) | |
8349 | return true; | |
8350 | ||
8351 | if (! is_rnglists && version < 5) | |
8352 | return true; | |
8353 | ||
8354 | return false; | |
8355 | } | |
8356 | ||
dbcbf67c NC |
8357 | static int |
8358 | display_debug_ranges (struct dwarf_section *section, | |
8359 | void *file ATTRIBUTE_UNUSED) | |
8360 | { | |
31e5a3a3 AM |
8361 | unsigned char *start = section->start; |
8362 | unsigned char *last_start = start; | |
f72c4fa3 | 8363 | unsigned char *last_end; |
31e5a3a3 AM |
8364 | uint64_t bytes = section->size; |
8365 | unsigned char *section_begin = start; | |
8366 | unsigned char *finish = start + bytes; | |
8367 | unsigned int num_range_list, i; | |
8368 | struct range_entry *range_entries; | |
8369 | struct range_entry *range_entry_fill; | |
589d38af | 8370 | bool is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
31e5a3a3 | 8371 | uint64_t last_offset = 0; |
84102ebc VA |
8372 | uint64_t next_rnglists_cu_offset = 0; |
8373 | unsigned char offset_size; | |
dbcbf67c NC |
8374 | |
8375 | if (bytes == 0) | |
8376 | { | |
8377 | printf (_("\nThe %s section is empty.\n"), section->name); | |
8378 | return 0; | |
8379 | } | |
8380 | ||
8381 | introduce (section, false); | |
cb1861cb | 8382 | |
1febe64d NC |
8383 | if (load_debug_info (file) == 0) |
8384 | { | |
8385 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
8386 | section->name); | |
8387 | return 0; | |
8388 | } | |
19e6b90e | 8389 | |
01a8f077 | 8390 | num_range_list = 0; |
19e6b90e | 8391 | for (i = 0; i < num_debug_info_entries; i++) |
84102ebc VA |
8392 | if (is_range_list_for_this_section (is_rnglists, debug_information [i].dwarf_version)) |
8393 | num_range_list += debug_information [i].num_range_lists; | |
19e6b90e | 8394 | |
01a8f077 | 8395 | if (num_range_list == 0) |
4723351a CC |
8396 | { |
8397 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 8398 | which removes references to range lists from the primary .o file. */ |
589d38af | 8399 | printf (_("No range lists referenced by .debug_info section.\n")); |
4723351a CC |
8400 | return 1; |
8401 | } | |
19e6b90e | 8402 | |
84102ebc | 8403 | range_entry_fill = range_entries = XNEWVEC (struct range_entry, num_range_list); |
19e6b90e | 8404 | |
01a8f077 JK |
8405 | for (i = 0; i < num_debug_info_entries; i++) |
8406 | { | |
8407 | debug_info *debug_info_p = &debug_information[i]; | |
8408 | unsigned int j; | |
8409 | ||
8410 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
8411 | { | |
84102ebc | 8412 | if (is_range_list_for_this_section (is_rnglists, debug_info_p->dwarf_version)) |
589d38af NC |
8413 | { |
8414 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
8415 | range_entry_fill->debug_info_p = debug_info_p; | |
8416 | range_entry_fill++; | |
8417 | } | |
19e6b90e L |
8418 | } |
8419 | } | |
8420 | ||
84102ebc VA |
8421 | assert (range_entry_fill >= range_entries); |
8422 | assert (num_range_list >= (unsigned int)(range_entry_fill - range_entries)); | |
589d38af | 8423 | num_range_list = range_entry_fill - range_entries; |
01a8f077 JK |
8424 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
8425 | range_entry_compar); | |
19e6b90e | 8426 | |
19c26da6 | 8427 | putchar ('\n'); |
84102ebc VA |
8428 | if (!is_rnglists) |
8429 | printf (_(" Offset Begin End\n")); | |
19e6b90e | 8430 | |
f72c4fa3 | 8431 | last_end = NULL; |
01a8f077 | 8432 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 8433 | { |
01a8f077 JK |
8434 | struct range_entry *range_entry = &range_entries[i]; |
8435 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 8436 | unsigned int pointer_size; |
31e5a3a3 | 8437 | uint64_t offset; |
01a8f077 | 8438 | unsigned char *next; |
31e5a3a3 | 8439 | uint64_t base_address; |
19e6b90e | 8440 | |
84102ebc | 8441 | pointer_size = debug_info_p->pointer_size; |
d493b283 | 8442 | offset = range_entry->ranges_offset; |
01a8f077 | 8443 | base_address = debug_info_p->base_address; |
cecf136e | 8444 | |
f41e4712 NC |
8445 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
8446 | if (pointer_size < 2 || pointer_size > 8) | |
8447 | { | |
31e5a3a3 AM |
8448 | warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64 "\n"), |
8449 | pointer_size, offset); | |
f41e4712 NC |
8450 | continue; |
8451 | } | |
b4eb7656 | 8452 | |
b4951546 | 8453 | if (offset > (size_t) (finish - section_begin)) |
d11ae95e | 8454 | { |
31e5a3a3 AM |
8455 | warn (_("Corrupt offset (%#" PRIx64 ") in range entry %u\n"), |
8456 | offset, i); | |
d11ae95e NC |
8457 | continue; |
8458 | } | |
ec41dd75 | 8459 | |
84102ebc VA |
8460 | /* If we've moved on to the next compile unit in the rnglists section - dump the unit header(s). */ |
8461 | if (is_rnglists && next_rnglists_cu_offset < offset) | |
8462 | { | |
8463 | while (next_rnglists_cu_offset < offset) | |
8464 | display_debug_rnglists_unit_header (section, &next_rnglists_cu_offset, &offset_size); | |
8465 | printf (_(" Offset Begin End\n")); | |
8466 | } | |
8467 | ||
8468 | next = section_begin + offset; /* Offset is from the section start, the base has already been added. */ | |
cb1861cb | 8469 | |
f72c4fa3 L |
8470 | if (i == 0) |
8471 | { | |
8472 | last_end = section_begin; | |
8473 | if (is_rnglists) | |
8474 | last_end += 2 * offset_size - 4 + 2 + 1 + 1 + 4; | |
8475 | } | |
cb4c35cf | 8476 | /* If multiple DWARF entities reference the same range then we will |
175b9150 AM |
8477 | have multiple entries in the `range_entries' list for the same |
8478 | offset. Thanks to the sort above these will all be consecutive in | |
8479 | the `range_entries' list, so we can easily ignore duplicates | |
8480 | here. */ | |
cb4c35cf | 8481 | if (i > 0 && last_offset == offset) |
175b9150 | 8482 | continue; |
cb4c35cf AB |
8483 | last_offset = offset; |
8484 | ||
f72c4fa3 | 8485 | if (dwarf_check != 0) |
19e6b90e | 8486 | { |
01a8f077 | 8487 | if (start < next) |
f72c4fa3 L |
8488 | { |
8489 | if (last_end != next) | |
8490 | warn (_("There is a hole [%#tx - %#tx] in %s section.\n"), | |
8491 | last_end - section_begin, next - section_begin, | |
8492 | section->name); | |
8493 | } | |
01a8f077 | 8494 | else if (start > next) |
a2ff7a4b AM |
8495 | { |
8496 | if (next == last_start) | |
8497 | continue; | |
31e5a3a3 AM |
8498 | warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"), |
8499 | start - section_begin, next - section_begin, section->name); | |
a2ff7a4b | 8500 | } |
01a8f077 | 8501 | } |
d11ae95e | 8502 | |
01a8f077 | 8503 | start = next; |
a2ff7a4b | 8504 | last_start = next; |
19e6b90e | 8505 | |
84102ebc | 8506 | if (is_rnglists) |
f72c4fa3 L |
8507 | last_end |
8508 | = display_debug_rnglists_list | |
8509 | (start, finish, pointer_size, offset, base_address, | |
8510 | debug_info_p->addr_base); | |
84102ebc | 8511 | else |
f72c4fa3 L |
8512 | last_end |
8513 | = display_debug_ranges_list | |
8514 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e | 8515 | } |
84102ebc VA |
8516 | |
8517 | /* Display trailing empty (or unreferenced) compile units, if any. */ | |
8518 | if (is_rnglists) | |
8519 | while (next_rnglists_cu_offset < section->size) | |
8520 | display_debug_rnglists_unit_header (section, &next_rnglists_cu_offset, &offset_size); | |
8521 | ||
19e6b90e | 8522 | putchar ('\n'); |
01a8f077 JK |
8523 | |
8524 | free (range_entries); | |
8525 | ||
19e6b90e L |
8526 | return 1; |
8527 | } | |
8528 | ||
8529 | typedef struct Frame_Chunk | |
8530 | { | |
8531 | struct Frame_Chunk *next; | |
8532 | unsigned char *chunk_start; | |
a1165289 | 8533 | unsigned int ncols; |
19e6b90e L |
8534 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
8535 | short int *col_type; | |
d0517d6e | 8536 | int64_t *col_offset; |
19e6b90e L |
8537 | char *augmentation; |
8538 | unsigned int code_factor; | |
8539 | int data_factor; | |
31e5a3a3 AM |
8540 | uint64_t pc_begin; |
8541 | uint64_t pc_range; | |
32ef3000 | 8542 | unsigned int cfa_reg; |
31e5a3a3 | 8543 | uint64_t cfa_offset; |
a1165289 | 8544 | unsigned int ra; |
19e6b90e L |
8545 | unsigned char fde_encoding; |
8546 | unsigned char cfa_exp; | |
604282a7 JJ |
8547 | unsigned char ptr_size; |
8548 | unsigned char segment_size; | |
19e6b90e L |
8549 | } |
8550 | Frame_Chunk; | |
8551 | ||
1296bc99 AB |
8552 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
8553 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
8554 | static const char *const *dwarf_regnames; |
8555 | static unsigned int dwarf_regnames_count; | |
e4e340a3 | 8556 | static bool is_aarch64; |
1296bc99 | 8557 | |
19e6b90e L |
8558 | /* A marker for a col_type that means this column was never referenced |
8559 | in the frame info. */ | |
8560 | #define DW_CFA_unreferenced (-1) | |
8561 | ||
a1165289 | 8562 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
8563 | -1 for invalid reg. */ |
8564 | ||
8565 | static int | |
8566 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 8567 | { |
a1165289 | 8568 | unsigned int prev = fc->ncols; |
19e6b90e | 8569 | |
665ce1f6 L |
8570 | if (reg < (unsigned int) fc->ncols) |
8571 | return 0; | |
8572 | ||
d9acf707 | 8573 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
8574 | && reg > dwarf_regnames_count) |
8575 | return -1; | |
19e6b90e L |
8576 | |
8577 | fc->ncols = reg + 1; | |
a1165289 NC |
8578 | /* PR 17512: file: 10450-2643-0.004. |
8579 | If reg == -1 then this can happen... */ | |
8580 | if (fc->ncols == 0) | |
8581 | return -1; | |
8582 | ||
06614111 | 8583 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 8584 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
8585 | { |
8586 | error (_("Unfeasibly large register number: %u\n"), reg); | |
8587 | fc->ncols = 0; | |
8588 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
8589 | we ever encounter a valid binary that exceeds it. */ | |
8590 | return -1; | |
8591 | } | |
8592 | ||
d0517d6e AM |
8593 | fc->col_type = xcrealloc (fc->col_type, fc->ncols, |
8594 | sizeof (*fc->col_type)); | |
8595 | fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, | |
8596 | sizeof (*fc->col_offset)); | |
b4eb7656 | 8597 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
8598 | if (fc->col_type == NULL || fc->col_offset == NULL) |
8599 | { | |
8600 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
8601 | fc->ncols); | |
8602 | fc->ncols = 0; | |
8603 | return -1; | |
8604 | } | |
19e6b90e L |
8605 | |
8606 | while (prev < fc->ncols) | |
8607 | { | |
8608 | fc->col_type[prev] = DW_CFA_unreferenced; | |
8609 | fc->col_offset[prev] = 0; | |
8610 | prev++; | |
8611 | } | |
665ce1f6 | 8612 | return 1; |
19e6b90e L |
8613 | } |
8614 | ||
2dc4cec1 L |
8615 | static const char *const dwarf_regnames_i386[] = |
8616 | { | |
43234a1e L |
8617 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
8618 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
8619 | "eip", "eflags", NULL, /* 8 - 10 */ | |
8620 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
8621 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
8622 | NULL, NULL, /* 19 - 20 */ | |
8623 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
8624 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
8625 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
8626 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
8627 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
8628 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
8629 | "tr", "ldtr", /* 48 - 49 */ | |
8630 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
8631 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
8632 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
8633 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
8634 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
8635 | NULL, NULL, NULL, /* 90 - 92 */ | |
8636 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
8637 | }; |
8638 | ||
3d875af5 L |
8639 | static const char *const dwarf_regnames_iamcu[] = |
8640 | { | |
8641 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
8642 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
8643 | "eip", "eflags", NULL, /* 8 - 10 */ | |
8644 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
8645 | NULL, NULL, /* 19 - 20 */ | |
8646 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
8647 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
8648 | NULL, NULL, NULL, /* 37 - 39 */ | |
8649 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
8650 | "tr", "ldtr", /* 48 - 49 */ | |
8651 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
8652 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
8653 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
8654 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
8655 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
8656 | NULL, NULL, NULL, /* 90 - 92 */ | |
8657 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
8658 | }; | |
8659 | ||
99f6fdd9 | 8660 | static void |
b129eb0e RH |
8661 | init_dwarf_regnames_i386 (void) |
8662 | { | |
8663 | dwarf_regnames = dwarf_regnames_i386; | |
8664 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 8665 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
8666 | } |
8667 | ||
99f6fdd9 | 8668 | static void |
3d875af5 L |
8669 | init_dwarf_regnames_iamcu (void) |
8670 | { | |
8671 | dwarf_regnames = dwarf_regnames_iamcu; | |
8672 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 8673 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
8674 | } |
8675 | ||
e4e340a3 AM |
8676 | static const char *const DW_CFA_GNU_window_save_name[] = |
8677 | { | |
8678 | "DW_CFA_GNU_window_save", | |
8679 | "DW_CFA_AARCH64_negate_ra_state" | |
8680 | }; | |
8681 | ||
2dc4cec1 L |
8682 | static const char *const dwarf_regnames_x86_64[] = |
8683 | { | |
8684 | "rax", "rdx", "rcx", "rbx", | |
8685 | "rsi", "rdi", "rbp", "rsp", | |
8686 | "r8", "r9", "r10", "r11", | |
8687 | "r12", "r13", "r14", "r15", | |
8688 | "rip", | |
8689 | "xmm0", "xmm1", "xmm2", "xmm3", | |
8690 | "xmm4", "xmm5", "xmm6", "xmm7", | |
8691 | "xmm8", "xmm9", "xmm10", "xmm11", | |
8692 | "xmm12", "xmm13", "xmm14", "xmm15", | |
8693 | "st0", "st1", "st2", "st3", | |
8694 | "st4", "st5", "st6", "st7", | |
8695 | "mm0", "mm1", "mm2", "mm3", | |
8696 | "mm4", "mm5", "mm6", "mm7", | |
8697 | "rflags", | |
8698 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
8699 | "fs.base", "gs.base", NULL, NULL, | |
8700 | "tr", "ldtr", | |
43234a1e L |
8701 | "mxcsr", "fcw", "fsw", |
8702 | "xmm16", "xmm17", "xmm18", "xmm19", | |
8703 | "xmm20", "xmm21", "xmm22", "xmm23", | |
8704 | "xmm24", "xmm25", "xmm26", "xmm27", | |
8705 | "xmm28", "xmm29", "xmm30", "xmm31", | |
8706 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
8707 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
8708 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
8709 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
8710 | NULL, NULL, NULL, /* 115 - 117 */ | |
a40a0460 JB |
8711 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7", |
8712 | "bnd0", "bnd1", "bnd2", "bnd3", | |
2dc4cec1 L |
8713 | }; |
8714 | ||
99f6fdd9 | 8715 | static void |
b129eb0e RH |
8716 | init_dwarf_regnames_x86_64 (void) |
8717 | { | |
8718 | dwarf_regnames = dwarf_regnames_x86_64; | |
8719 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 8720 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
8721 | } |
8722 | ||
4ee22035 RH |
8723 | static const char *const dwarf_regnames_aarch64[] = |
8724 | { | |
b4eb7656 AM |
8725 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
8726 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
8727 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
8728 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
8729 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
8730 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
8731 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
8732 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
8733 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
8734 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
8735 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
8736 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
8737 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
8738 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
8739 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
8740 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
8741 | }; |
8742 | ||
99f6fdd9 | 8743 | static void |
4ee22035 RH |
8744 | init_dwarf_regnames_aarch64 (void) |
8745 | { | |
8746 | dwarf_regnames = dwarf_regnames_aarch64; | |
8747 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 8748 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
e4e340a3 | 8749 | is_aarch64 = true; |
4ee22035 RH |
8750 | } |
8751 | ||
d6bb17b0 AA |
8752 | static const char *const dwarf_regnames_s390[] = |
8753 | { | |
8754 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
8755 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8756 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8757 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
8758 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
8759 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
8760 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
8761 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
8762 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
8763 | "pswm", "pswa", | |
8764 | NULL, NULL, | |
8765 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
8766 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
8767 | }; | |
8768 | ||
99f6fdd9 | 8769 | static void |
d6bb17b0 AA |
8770 | init_dwarf_regnames_s390 (void) |
8771 | { | |
8772 | dwarf_regnames = dwarf_regnames_s390; | |
8773 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 8774 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
8775 | } |
8776 | ||
5bb0830d AB |
8777 | static const char *const dwarf_regnames_riscv[] = |
8778 | { | |
7b4f2407 TO |
8779 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ |
8780 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
8781 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
8782 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
8783 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
8784 | "fs0", "fs1", /* 40 - 41 */ | |
8785 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
8786 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
8787 | "fs10", "fs11", /* 58 - 59 */ | |
8788 | "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */ | |
8789 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 64 - 71 */ | |
8790 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 72 - 79 */ | |
8791 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 80 - 87 */ | |
8792 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 88 - 95 */ | |
8793 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */ | |
8794 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */ | |
8795 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */ | |
8796 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */ | |
5bb0830d AB |
8797 | }; |
8798 | ||
4762fe62 AB |
8799 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
8800 | the large number of CSRs. */ | |
8801 | ||
8802 | static const char * | |
8803 | regname_internal_riscv (unsigned int regno) | |
8804 | { | |
8805 | const char *name = NULL; | |
8806 | ||
8807 | /* Lookup in the table first, this covers GPR and FPR. */ | |
8808 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
8809 | name = dwarf_regnames_riscv [regno]; | |
8810 | else if (regno >= 4096 && regno <= 8191) | |
8811 | { | |
8812 | /* This might be a CSR, these live in a sparse number space from 4096 | |
8813 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
8814 | document. */ | |
8815 | switch (regno) | |
8816 | { | |
8f595e9b NC |
8817 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
8818 | case VALUE + 4096: name = #NAME; break; | |
4762fe62 AB |
8819 | #include "opcode/riscv-opc.h" |
8820 | #undef DECLARE_CSR | |
8821 | ||
8822 | default: | |
8823 | { | |
8824 | static char csr_name[10]; | |
8825 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
8826 | name = csr_name; | |
8827 | } | |
8828 | break; | |
8829 | } | |
8830 | } | |
8831 | ||
8832 | return name; | |
8833 | } | |
8834 | ||
99f6fdd9 | 8835 | static void |
5bb0830d AB |
8836 | init_dwarf_regnames_riscv (void) |
8837 | { | |
4762fe62 AB |
8838 | dwarf_regnames = NULL; |
8839 | dwarf_regnames_count = 8192; | |
8840 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
8841 | } |
8842 | ||
3d75969b LC |
8843 | static const char *const dwarf_regnames_loongarch[] = |
8844 | { | |
8845 | "$zero", "$ra", "$tp", "$sp", "$a0", "$a1", "$a2", "$a3", /* 0-7 */ | |
8846 | "$a4", "$a5", "$a6", "$a7", "$t0", "$t1", "$t2", "$t3", /* 8-15 */ | |
8847 | "$t4", "$t5", "$t6", "$t7", "$t8", "$r21","$fp", "$s0", /* 16-23 */ | |
8848 | "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7", "$s8", /* 24-31 */ | |
8849 | "$fa0", "$fa1", "$fa2", "$fa3", "$fa4", "$fa5", "$fa6", /* 32-38 */ | |
8850 | "$fa7", "$ft0", "$ft1", "$ft2", "$ft3", "$ft4", "$ft5", /* 39-45 */ | |
8851 | "$ft6", "$ft7", "$ft8", "$ft9", "$ft10", "$ft11", "$ft12", /* 46-52 */ | |
8852 | "$ft13", "$ft14", "$ft15", "$fs0", "$fs1", "$fs2", "$fs3", /* 53-59 */ | |
8853 | "$fs4", "$fs5", "$fs6", "$fs7", /* 60-63 */ | |
8854 | }; | |
8855 | ||
8856 | static void | |
8857 | init_dwarf_regnames_loongarch (void) | |
8858 | { | |
8859 | dwarf_regnames = dwarf_regnames_loongarch; | |
8860 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_loongarch); | |
8861 | dwarf_regnames_lookup_func = regname_internal_by_table_only; | |
8862 | } | |
8863 | ||
2dc4cec1 | 8864 | void |
955ff7fc | 8865 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 8866 | { |
1296bc99 | 8867 | dwarf_regnames_lookup_func = NULL; |
e4e340a3 | 8868 | is_aarch64 = false; |
1296bc99 | 8869 | |
2dc4cec1 L |
8870 | switch (e_machine) |
8871 | { | |
8872 | case EM_386: | |
b129eb0e | 8873 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
8874 | break; |
8875 | ||
3d875af5 L |
8876 | case EM_IAMCU: |
8877 | init_dwarf_regnames_iamcu (); | |
8878 | break; | |
8879 | ||
2dc4cec1 | 8880 | case EM_X86_64: |
7f502d6c | 8881 | case EM_L1OM: |
7a9068fe | 8882 | case EM_K1OM: |
b129eb0e | 8883 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
8884 | break; |
8885 | ||
4ee22035 RH |
8886 | case EM_AARCH64: |
8887 | init_dwarf_regnames_aarch64 (); | |
8888 | break; | |
8889 | ||
d6bb17b0 AA |
8890 | case EM_S390: |
8891 | init_dwarf_regnames_s390 (); | |
8892 | break; | |
8893 | ||
5bb0830d AB |
8894 | case EM_RISCV: |
8895 | init_dwarf_regnames_riscv (); | |
8896 | break; | |
8897 | ||
3d75969b LC |
8898 | case EM_LOONGARCH: |
8899 | init_dwarf_regnames_loongarch (); | |
8900 | break; | |
8901 | ||
2dc4cec1 L |
8902 | default: |
8903 | break; | |
8904 | } | |
8905 | } | |
8906 | ||
229a22cf AB |
8907 | /* Initialize the DWARF register name lookup state based on the |
8908 | architecture and specific machine type of a BFD. */ | |
8909 | ||
8910 | void | |
8911 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
8912 | unsigned long mach) | |
8913 | { | |
1296bc99 | 8914 | dwarf_regnames_lookup_func = NULL; |
e4e340a3 | 8915 | is_aarch64 = false; |
1296bc99 | 8916 | |
229a22cf AB |
8917 | switch (arch) |
8918 | { | |
8919 | case bfd_arch_i386: | |
8920 | switch (mach) | |
8921 | { | |
8922 | case bfd_mach_x86_64: | |
8923 | case bfd_mach_x86_64_intel_syntax: | |
229a22cf AB |
8924 | case bfd_mach_x64_32: |
8925 | case bfd_mach_x64_32_intel_syntax: | |
229a22cf AB |
8926 | init_dwarf_regnames_x86_64 (); |
8927 | break; | |
8928 | ||
8929 | default: | |
8930 | init_dwarf_regnames_i386 (); | |
8931 | break; | |
8932 | } | |
8933 | break; | |
8934 | ||
8935 | case bfd_arch_iamcu: | |
8936 | init_dwarf_regnames_iamcu (); | |
8937 | break; | |
8938 | ||
8939 | case bfd_arch_aarch64: | |
8940 | init_dwarf_regnames_aarch64(); | |
8941 | break; | |
8942 | ||
8943 | case bfd_arch_s390: | |
8944 | init_dwarf_regnames_s390 (); | |
8945 | break; | |
8946 | ||
8947 | case bfd_arch_riscv: | |
8948 | init_dwarf_regnames_riscv (); | |
8949 | break; | |
8950 | ||
3d75969b LC |
8951 | case bfd_arch_loongarch: |
8952 | init_dwarf_regnames_loongarch (); | |
8953 | break; | |
8954 | ||
229a22cf AB |
8955 | default: |
8956 | break; | |
8957 | } | |
8958 | } | |
8959 | ||
2dc4cec1 | 8960 | static const char * |
1296bc99 | 8961 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 8962 | { |
1296bc99 | 8963 | if (dwarf_regnames != NULL |
2dc4cec1 L |
8964 | && regno < dwarf_regnames_count |
8965 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
8966 | return dwarf_regnames [regno]; |
8967 | ||
8968 | return NULL; | |
8969 | } | |
8970 | ||
8971 | static const char * | |
8972 | regname (unsigned int regno, int name_only_p) | |
8973 | { | |
8974 | static char reg[64]; | |
8975 | ||
8976 | const char *name = NULL; | |
8977 | ||
8978 | if (dwarf_regnames_lookup_func != NULL) | |
8979 | name = dwarf_regnames_lookup_func (regno); | |
8980 | ||
8981 | if (name != NULL) | |
2dc4cec1 | 8982 | { |
1296bc99 AB |
8983 | if (name_only_p) |
8984 | return name; | |
8985 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
8986 | } |
8987 | else | |
8988 | snprintf (reg, sizeof (reg), "r%d", regno); | |
8989 | return reg; | |
8990 | } | |
8991 | ||
19e6b90e | 8992 | static void |
a1165289 | 8993 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 8994 | { |
a1165289 | 8995 | unsigned int r; |
19e6b90e L |
8996 | char tmp[100]; |
8997 | ||
d8024a91 | 8998 | if (*max_regs != fc->ncols) |
19e6b90e L |
8999 | *max_regs = fc->ncols; |
9000 | ||
9001 | if (*need_col_headers) | |
9002 | { | |
9003 | *need_col_headers = 0; | |
9004 | ||
288f0ba2 | 9005 | printf ("%-*s CFA ", eh_addr_size * 2, " LOC"); |
19e6b90e L |
9006 | |
9007 | for (r = 0; r < *max_regs; r++) | |
9008 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
9009 | { | |
9010 | if (r == fc->ra) | |
50751e18 | 9011 | printf ("ra "); |
19e6b90e | 9012 | else |
2dc4cec1 | 9013 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
9014 | } |
9015 | ||
9016 | printf ("\n"); | |
9017 | } | |
9018 | ||
31e5a3a3 | 9019 | print_hex (fc->pc_begin, eh_addr_size); |
19e6b90e L |
9020 | if (fc->cfa_exp) |
9021 | strcpy (tmp, "exp"); | |
9022 | else | |
c8071705 | 9023 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
9024 | printf ("%-8s ", tmp); |
9025 | ||
9026 | for (r = 0; r < fc->ncols; r++) | |
9027 | { | |
9028 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
9029 | { | |
9030 | switch (fc->col_type[r]) | |
9031 | { | |
9032 | case DW_CFA_undefined: | |
9033 | strcpy (tmp, "u"); | |
9034 | break; | |
9035 | case DW_CFA_same_value: | |
9036 | strcpy (tmp, "s"); | |
9037 | break; | |
9038 | case DW_CFA_offset: | |
d0517d6e | 9039 | sprintf (tmp, "c%+" PRId64, fc->col_offset[r]); |
19e6b90e | 9040 | break; |
12eae2d3 | 9041 | case DW_CFA_val_offset: |
d0517d6e | 9042 | sprintf (tmp, "v%+" PRId64, fc->col_offset[r]); |
12eae2d3 | 9043 | break; |
19e6b90e | 9044 | case DW_CFA_register: |
2dc4cec1 | 9045 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
9046 | break; |
9047 | case DW_CFA_expression: | |
9048 | strcpy (tmp, "exp"); | |
9049 | break; | |
12eae2d3 JJ |
9050 | case DW_CFA_val_expression: |
9051 | strcpy (tmp, "vexp"); | |
9052 | break; | |
19e6b90e L |
9053 | default: |
9054 | strcpy (tmp, "n/a"); | |
9055 | break; | |
9056 | } | |
2dc4cec1 | 9057 | printf ("%-5s ", tmp); |
19e6b90e L |
9058 | } |
9059 | } | |
9060 | printf ("\n"); | |
9061 | } | |
9062 | ||
49727e46 | 9063 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 9064 | |
49727e46 AM |
9065 | static unsigned char * |
9066 | read_cie (unsigned char *start, unsigned char *end, | |
9067 | Frame_Chunk **p_cie, int *p_version, | |
31e5a3a3 | 9068 | uint64_t *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
9069 | { |
9070 | int version; | |
9071 | Frame_Chunk *fc; | |
49727e46 | 9072 | unsigned char *augmentation_data = NULL; |
31e5a3a3 | 9073 | uint64_t augmentation_data_len = 0; |
49727e46 | 9074 | |
041830e0 | 9075 | * p_cie = NULL; |
f41e4712 NC |
9076 | /* PR 17512: file: 001-228113-0.004. */ |
9077 | if (start >= end) | |
9078 | return end; | |
9079 | ||
49727e46 AM |
9080 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
9081 | memset (fc, 0, sizeof (Frame_Chunk)); | |
9082 | ||
d0517d6e AM |
9083 | fc->col_type = xmalloc (sizeof (*fc->col_type)); |
9084 | fc->col_offset = xmalloc (sizeof (*fc->col_offset)); | |
49727e46 AM |
9085 | |
9086 | version = *start++; | |
9087 | ||
9088 | fc->augmentation = (char *) start; | |
f41e4712 NC |
9089 | /* PR 17512: file: 001-228113-0.004. |
9090 | Skip past augmentation name, but avoid running off the end of the data. */ | |
9091 | while (start < end) | |
9092 | if (* start ++ == '\0') | |
9093 | break; | |
9094 | if (start == end) | |
9095 | { | |
9096 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 9097 | goto fail; |
f41e4712 | 9098 | } |
49727e46 AM |
9099 | |
9100 | if (strcmp (fc->augmentation, "eh") == 0) | |
c93c4a85 AM |
9101 | { |
9102 | if (eh_addr_size > (size_t) (end - start)) | |
9103 | goto fail; | |
9104 | start += eh_addr_size; | |
9105 | } | |
49727e46 AM |
9106 | |
9107 | if (version >= 4) | |
9108 | { | |
c93c4a85 AM |
9109 | if (2 > (size_t) (end - start)) |
9110 | goto fail; | |
49727e46 | 9111 | GET (fc->ptr_size, 1); |
77ef8654 NC |
9112 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
9113 | { | |
9114 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 9115 | goto fail; |
77ef8654 NC |
9116 | } |
9117 | ||
49727e46 | 9118 | GET (fc->segment_size, 1); |
77ef8654 NC |
9119 | /* PR 17512: file: e99d2804. */ |
9120 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
9121 | { | |
9122 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 9123 | goto fail; |
77ef8654 NC |
9124 | } |
9125 | ||
49727e46 AM |
9126 | eh_addr_size = fc->ptr_size; |
9127 | } | |
9128 | else | |
9129 | { | |
9130 | fc->ptr_size = eh_addr_size; | |
9131 | fc->segment_size = 0; | |
9132 | } | |
442a6ce8 | 9133 | |
cd30bcef AM |
9134 | READ_ULEB (fc->code_factor, start, end); |
9135 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 9136 | |
c93c4a85 AM |
9137 | if (start >= end) |
9138 | goto fail; | |
9139 | ||
49727e46 AM |
9140 | if (version == 1) |
9141 | { | |
9142 | GET (fc->ra, 1); | |
9143 | } | |
9144 | else | |
9145 | { | |
cd30bcef | 9146 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
9147 | } |
9148 | ||
9149 | if (fc->augmentation[0] == 'z') | |
9150 | { | |
c93c4a85 AM |
9151 | if (start >= end) |
9152 | goto fail; | |
cd30bcef | 9153 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 9154 | augmentation_data = start; |
a1165289 | 9155 | /* PR 17512: file: 11042-2589-0.004. */ |
be7d229a | 9156 | if (augmentation_data_len > (size_t) (end - start)) |
a1165289 | 9157 | { |
31e5a3a3 AM |
9158 | warn (_("Augmentation data too long: %#" PRIx64 |
9159 | ", expected at most %#tx\n"), | |
9160 | augmentation_data_len, end - start); | |
442a6ce8 | 9161 | goto fail; |
a1165289 | 9162 | } |
9c0f3d3f | 9163 | start += augmentation_data_len; |
49727e46 AM |
9164 | } |
9165 | ||
9166 | if (augmentation_data_len) | |
9167 | { | |
058037d3 NC |
9168 | unsigned char *p; |
9169 | unsigned char *q; | |
9170 | unsigned char *qend; | |
b4eb7656 | 9171 | |
49727e46 AM |
9172 | p = (unsigned char *) fc->augmentation + 1; |
9173 | q = augmentation_data; | |
058037d3 NC |
9174 | qend = q + augmentation_data_len; |
9175 | ||
9c0f3d3f | 9176 | while (p < end && q < qend) |
49727e46 AM |
9177 | { |
9178 | if (*p == 'L') | |
9179 | q++; | |
9180 | else if (*p == 'P') | |
9181 | q += 1 + size_of_encoded_value (*q); | |
9182 | else if (*p == 'R') | |
9183 | fc->fde_encoding = *q++; | |
9184 | else if (*p == 'S') | |
9185 | ; | |
09038062 ST |
9186 | else if (*p == 'B') |
9187 | ; | |
49727e46 AM |
9188 | else |
9189 | break; | |
9190 | p++; | |
9191 | } | |
c361b9ac NC |
9192 | /* Note - it is OK if this loop terminates with q < qend. |
9193 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
9194 | } |
9195 | ||
9196 | *p_cie = fc; | |
9197 | if (p_version) | |
9198 | *p_version = version; | |
9199 | if (p_aug_len) | |
9200 | { | |
9201 | *p_aug_len = augmentation_data_len; | |
9202 | *p_aug = augmentation_data; | |
9203 | } | |
9204 | return start; | |
442a6ce8 NC |
9205 | |
9206 | fail: | |
9207 | free (fc->col_offset); | |
9208 | free (fc->col_type); | |
9209 | free (fc); | |
9210 | return end; | |
49727e46 AM |
9211 | } |
9212 | ||
d85bf2ba NC |
9213 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
9214 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
9215 | PRINTED contains the number of characters already written to the current | |
9216 | output line. */ | |
bf59c5d5 NC |
9217 | |
9218 | static void | |
be7d229a | 9219 | display_data (size_t printed, const unsigned char *data, size_t len) |
bf59c5d5 | 9220 | { |
d85bf2ba NC |
9221 | if (do_wide || len < ((80 - printed) / 3)) |
9222 | for (printed = 0; printed < len; ++printed) | |
9223 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
9224 | else |
9225 | { | |
d85bf2ba | 9226 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 9227 | { |
d85bf2ba | 9228 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 9229 | putchar ('\n'); |
d85bf2ba | 9230 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
9231 | } |
9232 | } | |
d85bf2ba NC |
9233 | } |
9234 | ||
9235 | /* Prints out the contents on the augmentation data array. | |
9236 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
9237 | ||
9238 | static void | |
31e5a3a3 | 9239 | display_augmentation_data (const unsigned char * data, uint64_t len) |
d85bf2ba | 9240 | { |
be7d229a | 9241 | size_t i; |
d85bf2ba NC |
9242 | |
9243 | i = printf (_(" Augmentation data: ")); | |
9244 | display_data (i, data, len); | |
bf59c5d5 NC |
9245 | } |
9246 | ||
1878f44b NC |
9247 | static const char * |
9248 | decode_eh_encoding (unsigned int value) | |
9249 | { | |
9250 | if (value == DW_EH_PE_omit) | |
9251 | return "omit"; | |
9252 | ||
9253 | char * format; | |
9254 | switch (value & 0x0f) | |
9255 | { | |
9256 | case DW_EH_PE_uleb128: format = "uleb128"; break; | |
9257 | case DW_EH_PE_udata2: format = "udata2"; break; | |
9258 | case DW_EH_PE_udata4: format = "udata4"; break; | |
9259 | case DW_EH_PE_udata8: format = "udata8"; break; | |
9260 | case DW_EH_PE_sleb128: format = "sleb128"; break; | |
9261 | case DW_EH_PE_sdata2: format = "sdata2"; break; | |
9262 | case DW_EH_PE_sdata4: format = "sdata4"; break; | |
9263 | case DW_EH_PE_sdata8: format = "sdata8"; break; | |
9264 | ||
9265 | default: format = "<unknown format>"; break; /* FIXME: Generate a warning ? */ | |
9266 | } | |
9267 | ||
9268 | char * application; | |
9269 | switch (value & 0xf0) | |
9270 | { | |
9271 | case DW_EH_PE_absptr: application = "absolute"; break; | |
9272 | case DW_EH_PE_pcrel: application = "pcrel"; break; | |
9273 | case DW_EH_PE_textrel: application = "textrel"; break; /* FIXME: Is this allowed ? */ | |
9274 | case DW_EH_PE_datarel: application = "datarel"; break; | |
9275 | case DW_EH_PE_funcrel: application = "funcrel"; break; /* FIXME: Is this allowed ? */ | |
9276 | case DW_EH_PE_aligned: application = "aligned"; break; /* FIXME: Is this allowed ? */ | |
9277 | case DW_EH_PE_indirect: application = "indirect"; break; /* FIXME: Is this allowed ? */ | |
9278 | ||
9279 | default: application = "<unknown application method>"; break; /* FIXME: Generate a warning ? */ | |
9280 | } | |
9281 | ||
9282 | static char buffer[128]; | |
9283 | sprintf (buffer, "%s, %s", format, application); | |
9284 | return buffer; | |
9285 | } | |
9286 | ||
9287 | /* Reads a value stored at START encoded according to ENCODING. | |
9288 | Does not read from, or past, END. | |
9289 | Upon success, returns the read value and sets * RETURN_LEN to | |
9290 | the number of bytes read. | |
9291 | Upon failure returns zero and sets * RETURN_LEN to 0. | |
cb1861cb | 9292 | |
1878f44b NC |
9293 | Note: does not perform any application transformations to the value. */ |
9294 | ||
9295 | static uint64_t | |
9296 | get_encoded_eh_value (unsigned int encoding, | |
9297 | unsigned char * start, | |
9298 | unsigned char * end, | |
9299 | unsigned int * return_len) | |
9300 | { | |
9301 | uint64_t val; | |
9302 | unsigned int len; | |
9303 | int status; | |
9304 | unsigned char * old_start; | |
9305 | ||
9306 | switch (encoding & 0x0f) | |
9307 | { | |
9308 | case DW_EH_PE_uleb128: | |
9309 | val = read_leb128 (start, end, false, & len, & status); | |
9310 | if (status != 0) | |
9311 | len = 0; | |
9312 | break; | |
9313 | ||
9314 | case DW_EH_PE_sleb128: | |
9315 | val = read_leb128 (start, end, true, & len, & status); | |
9316 | if (status != 0) | |
9317 | len = 0; | |
9318 | break; | |
9319 | ||
9320 | case DW_EH_PE_udata2: | |
9321 | old_start = start; | |
9322 | SAFE_BYTE_GET_AND_INC (val, start, 2, end); | |
e14f7aba | 9323 | len = start - old_start == 2 ? 2 : 0; |
1878f44b NC |
9324 | break; |
9325 | ||
9326 | case DW_EH_PE_udata4: | |
9327 | old_start = start; | |
9328 | SAFE_BYTE_GET_AND_INC (val, start, 4, end); | |
e14f7aba | 9329 | len = start - old_start == 4 ? 4 : 0; |
1878f44b NC |
9330 | break; |
9331 | ||
9332 | case DW_EH_PE_udata8: | |
9333 | old_start = start; | |
9334 | SAFE_BYTE_GET_AND_INC (val, start, 8, end); | |
e14f7aba | 9335 | len = start - old_start == 8 ? 8 : 0; |
1878f44b NC |
9336 | break; |
9337 | ||
9338 | case DW_EH_PE_sdata2: | |
9339 | old_start = start; | |
9340 | SAFE_SIGNED_BYTE_GET_AND_INC (val, start, 2, end); | |
e14f7aba | 9341 | len = start - old_start == 2 ? 2 : 0; |
1878f44b NC |
9342 | break; |
9343 | ||
9344 | case DW_EH_PE_sdata4: | |
9345 | old_start = start; | |
9346 | SAFE_SIGNED_BYTE_GET_AND_INC (val, start, 4, end); | |
e14f7aba | 9347 | len = start - old_start == 4 ? 4 : 0; |
1878f44b NC |
9348 | break; |
9349 | ||
9350 | case DW_EH_PE_sdata8: | |
9351 | old_start = start; | |
9352 | SAFE_SIGNED_BYTE_GET_AND_INC (val, start, 8, end); | |
e14f7aba | 9353 | len = start - old_start == 8 ? 8 : 0; |
1878f44b NC |
9354 | break; |
9355 | ||
9356 | default: | |
9357 | goto fail; | |
9358 | } | |
9359 | ||
9360 | * return_len = len; | |
9361 | return val; | |
9362 | ||
9363 | fail: | |
9364 | * return_len = 0; | |
9365 | return 0; | |
1878f44b NC |
9366 | } |
9367 | ||
9368 | static uint64_t | |
9369 | encoded_eh_offset (unsigned int encoding, | |
9370 | struct dwarf_section * section, | |
9371 | uint64_t section_offset, | |
9372 | uint64_t value) | |
9373 | { | |
9374 | switch (encoding & 0xf0) | |
9375 | { | |
9376 | default: | |
9377 | /* This should not happen. FIXME: warn ? */ | |
9378 | case DW_EH_PE_absptr: | |
9379 | return value; | |
9380 | ||
9381 | case DW_EH_PE_pcrel: | |
9382 | return value + (uint64_t)(section->address + section_offset); | |
9383 | ||
9384 | case DW_EH_PE_datarel: | |
9385 | return value + (uint64_t)section->address; | |
9386 | } | |
9387 | } | |
9388 | ||
9389 | static int | |
9390 | display_eh_frame_hdr (struct dwarf_section *section, | |
9391 | void *file ATTRIBUTE_UNUSED) | |
9392 | { | |
9393 | unsigned char *start = section->start; | |
9394 | unsigned char *end = start + section->size; | |
9395 | ||
9396 | introduce (section, false); | |
9397 | ||
9398 | if (section->size < 6) | |
9399 | { | |
9400 | warn (_(".eh_frame_hdr section is too small\n")); | |
9401 | return 0; | |
9402 | } | |
9403 | ||
9404 | unsigned int version = start[0]; | |
9405 | if (version != 1) | |
9406 | { | |
9407 | warn (_("Unsupported .eh_frame_hdr version %u\n"), version); | |
9408 | return 0; | |
9409 | } | |
9410 | ||
9411 | printf (_(" Version: %u\n"), version); | |
9412 | ||
9413 | unsigned int ptr_enc = start[1]; | |
9414 | /* Strictly speaking this is the encoding format of the eh_frame_ptr field below. */ | |
9415 | printf (_(" Pointer Encoding Format: %#x (%s)\n"), ptr_enc, decode_eh_encoding (ptr_enc)); | |
9416 | ||
9417 | unsigned int count_enc = start[2]; | |
9418 | printf (_(" Count Encoding Format: %#x (%s)\n"), count_enc, decode_eh_encoding (count_enc)); | |
9419 | ||
9420 | unsigned int table_enc = start[3]; | |
9421 | printf (_(" Table Encoding Format: %#x (%s)\n"), table_enc, decode_eh_encoding (table_enc)); | |
9422 | ||
9423 | start += 4; | |
9424 | ||
9425 | unsigned int len; | |
9426 | ||
9427 | uint64_t eh_frame_ptr = get_encoded_eh_value (ptr_enc, start, end, & len); | |
9428 | if (len == 0) | |
9429 | { | |
9430 | warn (_("unable to read eh_frame_ptr field in .eh_frame_hdr section\n")); | |
9431 | return 0; | |
9432 | } | |
9433 | printf (_(" Start of frame section: %#" PRIx64), eh_frame_ptr); | |
9434 | ||
9435 | uint64_t offset_eh_frame_ptr = encoded_eh_offset (ptr_enc, section, 4, eh_frame_ptr); | |
9436 | if (offset_eh_frame_ptr != eh_frame_ptr) | |
9437 | printf (_(" (offset: %#" PRIx64 ")"), offset_eh_frame_ptr); | |
cb1861cb | 9438 | |
1878f44b NC |
9439 | printf ("\n"); |
9440 | start += len; | |
9441 | ||
9442 | if (count_enc == DW_EH_PE_omit) | |
9443 | { | |
9444 | warn (_("It is suspicious to have a .eh_frame_hdr section with an empty search table\n")); | |
9445 | return 0; | |
9446 | } | |
9447 | ||
9448 | if (count_enc & 0xf0) | |
9449 | { | |
9450 | warn (_("The count field format should be absolute, not relative to an address\n")); | |
9451 | return 0; | |
9452 | } | |
cb1861cb | 9453 | |
1878f44b NC |
9454 | uint64_t fde_count = get_encoded_eh_value (count_enc, start, end, & len); |
9455 | if (len == 0) | |
9456 | { | |
9457 | warn (_("unable to read fde_count field in .eh_frame_hdr section\n")); | |
9458 | return 0; | |
9459 | } | |
9460 | printf (_(" Entries in search table: %#" PRIx64), fde_count); | |
9461 | printf ("\n"); | |
9462 | start += len; | |
9463 | ||
9464 | if (fde_count != 0 && table_enc == DW_EH_PE_omit) | |
9465 | { | |
9466 | warn (_("It is suspicious to have a .eh_frame_hdr section an empty table but a non empty count field\n")); | |
9467 | return 0; | |
9468 | } | |
9469 | ||
9470 | uint64_t i; | |
9471 | /* Read and display the search table. */ | |
9472 | for (i = 0; i < fde_count; i++) | |
9473 | { | |
9474 | uint64_t location, address; | |
9475 | unsigned char * row_start = start; | |
9476 | ||
9477 | location = get_encoded_eh_value (table_enc, start, end, & len); | |
9478 | if (len == 0) | |
9479 | { | |
9480 | warn (_("Failed to read location field for entry %#" PRIx64 " in the .eh_frame_hdr's search table\n"), i); | |
9481 | return 0; | |
9482 | } | |
9483 | start += len; | |
9484 | ||
9485 | address = get_encoded_eh_value (table_enc, start, end, & len); | |
9486 | if (len == 0) | |
9487 | { | |
9488 | warn (_("Failed to read address field for entry %#" PRIx64 " in the .eh_frame_hdr's search table\n"), i); | |
9489 | return 0; | |
9490 | } | |
9491 | start += len; | |
9492 | ||
9493 | /* This format is intended to be compatible with the output of eu-readelf's -e option. */ | |
9494 | printf (" %#" PRIx64 " (offset: %#" PRIx64 ") -> %#" PRIx64 " fde=[ %5" PRIx64 "]\n", | |
9495 | location, | |
9496 | encoded_eh_offset (table_enc, section, row_start - section->start, location), | |
9497 | address, | |
9498 | encoded_eh_offset (table_enc, section, row_start - section->start, address) - offset_eh_frame_ptr); | |
9499 | } | |
9500 | ||
9501 | printf ("\n"); | |
9502 | return 1; | |
9503 | } | |
9504 | ||
19e6b90e L |
9505 | static int |
9506 | display_debug_frames (struct dwarf_section *section, | |
9507 | void *file ATTRIBUTE_UNUSED) | |
9508 | { | |
9509 | unsigned char *start = section->start; | |
9510 | unsigned char *end = start + section->size; | |
9511 | unsigned char *section_start = start; | |
3391569f NC |
9512 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
9513 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 9514 | Frame_Chunk *rs; |
015dc7e1 | 9515 | bool is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 9516 | unsigned int max_regs = 0; |
665ce1f6 | 9517 | const char *bad_reg = _("bad register: "); |
77ef8654 | 9518 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 9519 | |
015dc7e1 | 9520 | introduce (section, false); |
19e6b90e L |
9521 | |
9522 | while (start < end) | |
9523 | { | |
9524 | unsigned char *saved_start; | |
9525 | unsigned char *block_end; | |
31e5a3a3 AM |
9526 | uint64_t length; |
9527 | uint64_t cie_id; | |
19e6b90e L |
9528 | Frame_Chunk *fc; |
9529 | Frame_Chunk *cie; | |
9530 | int need_col_headers = 1; | |
9531 | unsigned char *augmentation_data = NULL; | |
31e5a3a3 | 9532 | uint64_t augmentation_data_len = 0; |
bf5117e3 NC |
9533 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
9534 | unsigned int offset_size; | |
015dc7e1 | 9535 | bool all_nops; |
a788aedd | 9536 | static Frame_Chunk fde_fc; |
19e6b90e L |
9537 | |
9538 | saved_start = start; | |
19e6b90e | 9539 | |
0c588247 | 9540 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 9541 | |
19e6b90e L |
9542 | if (length == 0) |
9543 | { | |
31e5a3a3 | 9544 | printf ("\n%08tx ZERO terminator\n\n", |
cb1861cb | 9545 | saved_start - section_start); |
6937bb54 NC |
9546 | /* Skip any zero terminators that directly follow. |
9547 | A corrupt section size could have loaded a whole | |
9548 | slew of zero filled memory bytes. eg | |
9549 | PR 17512: file: 070-19381-0.004. */ | |
9550 | while (start < end && * start == 0) | |
9551 | ++ start; | |
b758e50f | 9552 | continue; |
19e6b90e L |
9553 | } |
9554 | ||
9555 | if (length == 0xffffffff) | |
9556 | { | |
0c588247 | 9557 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e | 9558 | offset_size = 8; |
19e6b90e L |
9559 | } |
9560 | else | |
5897a389 | 9561 | offset_size = 4; |
19e6b90e | 9562 | |
5897a389 | 9563 | if (length > (size_t) (end - start)) |
53b8873b | 9564 | { |
31e5a3a3 AM |
9565 | warn ("Invalid length %#" PRIx64 " in FDE at %#tx\n", |
9566 | length, saved_start - section_start); | |
53b8873b NC |
9567 | block_end = end; |
9568 | } | |
5897a389 AM |
9569 | else |
9570 | block_end = start + length; | |
0c588247 | 9571 | |
5897a389 | 9572 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, block_end); |
19e6b90e | 9573 | |
846a11e4 NC |
9574 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
9575 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
9576 | { |
9577 | int version; | |
a1165289 | 9578 | unsigned int mreg; |
19e6b90e | 9579 | |
5897a389 | 9580 | start = read_cie (start, block_end, &cie, &version, |
49727e46 | 9581 | &augmentation_data_len, &augmentation_data); |
041830e0 NC |
9582 | /* PR 17512: file: 027-135133-0.005. */ |
9583 | if (cie == NULL) | |
9584 | break; | |
a1165289 | 9585 | |
49727e46 | 9586 | fc = cie; |
19e6b90e L |
9587 | fc->next = chunks; |
9588 | chunks = fc; | |
9589 | fc->chunk_start = saved_start; | |
a1165289 | 9590 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
9591 | if (mreg < fc->ra) |
9592 | mreg = fc->ra; | |
06614111 NC |
9593 | if (frame_need_space (fc, mreg) < 0) |
9594 | break; | |
49727e46 AM |
9595 | if (fc->fde_encoding) |
9596 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 9597 | |
31e5a3a3 AM |
9598 | printf ("\n%08tx ", saved_start - section_start); |
9599 | print_hex (length, fc->ptr_size); | |
9600 | print_hex (cie_id, offset_size); | |
bf5117e3 | 9601 | |
19e6b90e | 9602 | if (do_debug_frames_interp) |
bf5117e3 NC |
9603 | { |
9604 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
9605 | fc->code_factor, fc->data_factor, fc->ra); | |
9606 | } | |
19e6b90e L |
9607 | else |
9608 | { | |
bf5117e3 | 9609 | printf ("CIE\n"); |
19e6b90e L |
9610 | printf (" Version: %d\n", version); |
9611 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
9612 | if (version >= 4) |
9613 | { | |
9614 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
9615 | printf (" Segment Size: %u\n", fc->segment_size); | |
9616 | } | |
19e6b90e L |
9617 | printf (" Code alignment factor: %u\n", fc->code_factor); |
9618 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
9619 | printf (" Return address column: %d\n", fc->ra); | |
9620 | ||
9621 | if (augmentation_data_len) | |
bf59c5d5 | 9622 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 9623 | |
19e6b90e L |
9624 | putchar ('\n'); |
9625 | } | |
19e6b90e L |
9626 | } |
9627 | else | |
9628 | { | |
9629 | unsigned char *look_for; | |
604282a7 | 9630 | unsigned long segment_selector; |
31e5a3a3 | 9631 | uint64_t cie_off; |
19e6b90e | 9632 | |
0d872fca | 9633 | cie_off = cie_id; |
49727e46 AM |
9634 | if (is_eh) |
9635 | { | |
31e5a3a3 | 9636 | uint64_t sign = (uint64_t) 1 << (offset_size * 8 - 1); |
0d872fca AM |
9637 | cie_off = (cie_off ^ sign) - sign; |
9638 | cie_off = start - 4 - section_start - cie_off; | |
49727e46 | 9639 | } |
19e6b90e | 9640 | |
0d872fca | 9641 | look_for = section_start + cie_off; |
31e5a3a3 | 9642 | if (cie_off <= (size_t) (saved_start - section_start)) |
49727e46 AM |
9643 | { |
9644 | for (cie = chunks; cie ; cie = cie->next) | |
9645 | if (cie->chunk_start == look_for) | |
9646 | break; | |
9647 | } | |
d21f875d AM |
9648 | else if (cie_off >= section->size) |
9649 | cie = NULL; | |
49727e46 AM |
9650 | else |
9651 | { | |
9652 | for (cie = forward_refs; cie ; cie = cie->next) | |
9653 | if (cie->chunk_start == look_for) | |
9654 | break; | |
9655 | if (!cie) | |
9656 | { | |
9657 | unsigned int off_size; | |
9658 | unsigned char *cie_scan; | |
19e6b90e | 9659 | |
49727e46 AM |
9660 | cie_scan = look_for; |
9661 | off_size = 4; | |
9662 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
9663 | if (length == 0xffffffff) | |
9664 | { | |
9665 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
9666 | off_size = 8; | |
9667 | } | |
5897a389 | 9668 | if (length != 0 && length <= (size_t) (end - cie_scan)) |
49727e46 | 9669 | { |
31e5a3a3 | 9670 | uint64_t c_id; |
5897a389 | 9671 | unsigned char *cie_end = cie_scan + length; |
49727e46 | 9672 | |
5897a389 AM |
9673 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, |
9674 | cie_end); | |
49727e46 AM |
9675 | if (is_eh |
9676 | ? c_id == 0 | |
9677 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
9678 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
9679 | { | |
9680 | int version; | |
a1165289 | 9681 | unsigned int mreg; |
49727e46 | 9682 | |
5897a389 | 9683 | read_cie (cie_scan, cie_end, &cie, &version, |
49727e46 | 9684 | &augmentation_data_len, &augmentation_data); |
a1165289 NC |
9685 | /* PR 17512: file: 3450-2098-0.004. */ |
9686 | if (cie == NULL) | |
9687 | { | |
9688 | warn (_("Failed to read CIE information\n")); | |
9689 | break; | |
9690 | } | |
49727e46 AM |
9691 | cie->next = forward_refs; |
9692 | forward_refs = cie; | |
9693 | cie->chunk_start = look_for; | |
a1165289 | 9694 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
9695 | if (mreg < cie->ra) |
9696 | mreg = cie->ra; | |
06614111 NC |
9697 | if (frame_need_space (cie, mreg) < 0) |
9698 | { | |
9699 | warn (_("Invalid max register\n")); | |
9700 | break; | |
9701 | } | |
49727e46 AM |
9702 | if (cie->fde_encoding) |
9703 | encoded_ptr_size | |
9704 | = size_of_encoded_value (cie->fde_encoding); | |
9705 | } | |
9706 | } | |
9707 | } | |
9708 | } | |
9709 | ||
9710 | fc = &fde_fc; | |
9711 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
9712 | |
9713 | if (!cie) | |
9714 | { | |
19e6b90e | 9715 | fc->ncols = 0; |
d0517d6e AM |
9716 | fc->col_type = xmalloc (sizeof (*fc->col_type)); |
9717 | fc->col_offset = xmalloc (sizeof (*fc->col_offset)); | |
06614111 NC |
9718 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
9719 | { | |
9720 | warn (_("Invalid max register\n")); | |
9721 | break; | |
9722 | } | |
19e6b90e L |
9723 | cie = fc; |
9724 | fc->augmentation = ""; | |
9725 | fc->fde_encoding = 0; | |
604282a7 JJ |
9726 | fc->ptr_size = eh_addr_size; |
9727 | fc->segment_size = 0; | |
19e6b90e L |
9728 | } |
9729 | else | |
9730 | { | |
9731 | fc->ncols = cie->ncols; | |
d0517d6e AM |
9732 | fc->col_type = xcmalloc (fc->ncols, sizeof (*fc->col_type)); |
9733 | fc->col_offset = xcmalloc (fc->ncols, sizeof (*fc->col_offset)); | |
9734 | memcpy (fc->col_type, cie->col_type, | |
9735 | fc->ncols * sizeof (*fc->col_type)); | |
9736 | memcpy (fc->col_offset, cie->col_offset, | |
9737 | fc->ncols * sizeof (*fc->col_offset)); | |
19e6b90e | 9738 | fc->augmentation = cie->augmentation; |
604282a7 JJ |
9739 | fc->ptr_size = cie->ptr_size; |
9740 | eh_addr_size = cie->ptr_size; | |
9741 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
9742 | fc->code_factor = cie->code_factor; |
9743 | fc->data_factor = cie->data_factor; | |
9744 | fc->cfa_reg = cie->cfa_reg; | |
9745 | fc->cfa_offset = cie->cfa_offset; | |
9746 | fc->ra = cie->ra; | |
06614111 NC |
9747 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
9748 | { | |
9749 | warn (_("Invalid max register\n")); | |
9750 | break; | |
9751 | } | |
19e6b90e L |
9752 | fc->fde_encoding = cie->fde_encoding; |
9753 | } | |
9754 | ||
9755 | if (fc->fde_encoding) | |
9756 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
9757 | ||
604282a7 JJ |
9758 | segment_selector = 0; |
9759 | if (fc->segment_size) | |
c8071705 NC |
9760 | { |
9761 | if (fc->segment_size > sizeof (segment_selector)) | |
9762 | { | |
9763 | /* PR 17512: file: 9e196b3e. */ | |
9764 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
9765 | fc->segment_size = 4; | |
9766 | } | |
5897a389 AM |
9767 | SAFE_BYTE_GET_AND_INC (segment_selector, start, |
9768 | fc->segment_size, block_end); | |
c8071705 | 9769 | } |
041830e0 | 9770 | |
5897a389 AM |
9771 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, |
9772 | block_end); | |
19e6b90e | 9773 | |
0c588247 NC |
9774 | /* FIXME: It appears that sometimes the final pc_range value is |
9775 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
9776 | run of the "objcopy on compressed debug sections" test for an | |
9777 | example of this. */ | |
5897a389 AM |
9778 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, |
9779 | block_end); | |
bf5117e3 | 9780 | |
19e6b90e L |
9781 | if (cie->augmentation[0] == 'z') |
9782 | { | |
5897a389 | 9783 | READ_ULEB (augmentation_data_len, start, block_end); |
19e6b90e | 9784 | augmentation_data = start; |
bf59c5d5 | 9785 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
be7d229a | 9786 | if (augmentation_data_len > (size_t) (block_end - start)) |
0a9d414a | 9787 | { |
31e5a3a3 AM |
9788 | warn (_("Augmentation data too long: %#" PRIx64 ", " |
9789 | "expected at most %#tx\n"), | |
9790 | augmentation_data_len, block_end - start); | |
5897a389 | 9791 | start = block_end; |
0a9d414a NC |
9792 | augmentation_data = NULL; |
9793 | augmentation_data_len = 0; | |
9794 | } | |
d292364e | 9795 | start += augmentation_data_len; |
19e6b90e L |
9796 | } |
9797 | ||
31e5a3a3 AM |
9798 | printf ("\n%08tx ", saved_start - section_start); |
9799 | print_hex (length, fc->ptr_size); | |
9800 | print_hex (cie_id, offset_size); | |
9801 | printf ("FDE "); | |
bf5117e3 | 9802 | |
ca877583 | 9803 | if (cie->chunk_start) |
31e5a3a3 | 9804 | printf ("cie=%08tx", cie->chunk_start - section_start); |
ca877583 AM |
9805 | else |
9806 | /* Ideally translate "invalid " to 8 chars, trailing space | |
9807 | is optional. */ | |
9808 | printf (_("cie=invalid ")); | |
9809 | ||
9810 | printf (" pc="); | |
604282a7 JJ |
9811 | if (fc->segment_size) |
9812 | printf ("%04lx:", segment_selector); | |
bf5117e3 | 9813 | |
31e5a3a3 AM |
9814 | print_hex_ns (fc->pc_begin, fc->ptr_size); |
9815 | printf (".."); | |
9816 | print_hex_ns (fc->pc_begin + fc->pc_range, fc->ptr_size); | |
9817 | printf ("\n"); | |
bf5117e3 | 9818 | |
19e6b90e L |
9819 | if (! do_debug_frames_interp && augmentation_data_len) |
9820 | { | |
bf59c5d5 | 9821 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
9822 | putchar ('\n'); |
9823 | } | |
9824 | } | |
9825 | ||
9826 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
9827 | we're about to interpret instructions for the chunk. */ | |
9828 | /* ??? At present we need to do this always, since this sizes the | |
9829 | fc->col_type and fc->col_offset arrays, which we write into always. | |
9830 | We should probably split the interpreted and non-interpreted bits | |
9831 | into two different routines, since there's so much that doesn't | |
9832 | really overlap between them. */ | |
9833 | if (1 || do_debug_frames_interp) | |
9834 | { | |
9835 | /* Start by making a pass over the chunk, allocating storage | |
9836 | and taking note of what registers are used. */ | |
9837 | unsigned char *tmp = start; | |
9838 | ||
9839 | while (start < block_end) | |
9840 | { | |
041830e0 NC |
9841 | unsigned int reg, op, opa; |
9842 | unsigned long temp; | |
19e6b90e L |
9843 | |
9844 | op = *start++; | |
9845 | opa = op & 0x3f; | |
9846 | if (op & 0xc0) | |
9847 | op &= 0xc0; | |
9848 | ||
9849 | /* Warning: if you add any more cases to this switch, be | |
9850 | sure to add them to the corresponding switch below. */ | |
45bf072b | 9851 | reg = -1u; |
19e6b90e L |
9852 | switch (op) |
9853 | { | |
9854 | case DW_CFA_advance_loc: | |
9855 | break; | |
9856 | case DW_CFA_offset: | |
5897a389 | 9857 | SKIP_ULEB (start, block_end); |
45bf072b | 9858 | reg = opa; |
19e6b90e L |
9859 | break; |
9860 | case DW_CFA_restore: | |
45bf072b | 9861 | reg = opa; |
19e6b90e L |
9862 | break; |
9863 | case DW_CFA_set_loc: | |
5897a389 AM |
9864 | if ((size_t) (block_end - start) < encoded_ptr_size) |
9865 | start = block_end; | |
9866 | else | |
9867 | start += encoded_ptr_size; | |
19e6b90e L |
9868 | break; |
9869 | case DW_CFA_advance_loc1: | |
5897a389 AM |
9870 | if ((size_t) (block_end - start) < 1) |
9871 | start = block_end; | |
9872 | else | |
9873 | start += 1; | |
19e6b90e L |
9874 | break; |
9875 | case DW_CFA_advance_loc2: | |
5897a389 AM |
9876 | if ((size_t) (block_end - start) < 2) |
9877 | start = block_end; | |
9878 | else | |
9879 | start += 2; | |
19e6b90e L |
9880 | break; |
9881 | case DW_CFA_advance_loc4: | |
5897a389 AM |
9882 | if ((size_t) (block_end - start) < 4) |
9883 | start = block_end; | |
9884 | else | |
9885 | start += 4; | |
19e6b90e L |
9886 | break; |
9887 | case DW_CFA_offset_extended: | |
12eae2d3 | 9888 | case DW_CFA_val_offset: |
5897a389 AM |
9889 | READ_ULEB (reg, start, block_end); |
9890 | SKIP_ULEB (start, block_end); | |
19e6b90e L |
9891 | break; |
9892 | case DW_CFA_restore_extended: | |
5897a389 | 9893 | READ_ULEB (reg, start, block_end); |
19e6b90e L |
9894 | break; |
9895 | case DW_CFA_undefined: | |
5897a389 | 9896 | READ_ULEB (reg, start, block_end); |
19e6b90e L |
9897 | break; |
9898 | case DW_CFA_same_value: | |
5897a389 | 9899 | READ_ULEB (reg, start, block_end); |
19e6b90e L |
9900 | break; |
9901 | case DW_CFA_register: | |
5897a389 AM |
9902 | READ_ULEB (reg, start, block_end); |
9903 | SKIP_ULEB (start, block_end); | |
19e6b90e L |
9904 | break; |
9905 | case DW_CFA_def_cfa: | |
5897a389 AM |
9906 | SKIP_ULEB (start, block_end); |
9907 | SKIP_ULEB (start, block_end); | |
19e6b90e L |
9908 | break; |
9909 | case DW_CFA_def_cfa_register: | |
5897a389 | 9910 | SKIP_ULEB (start, block_end); |
19e6b90e L |
9911 | break; |
9912 | case DW_CFA_def_cfa_offset: | |
5897a389 | 9913 | SKIP_ULEB (start, block_end); |
19e6b90e L |
9914 | break; |
9915 | case DW_CFA_def_cfa_expression: | |
5897a389 AM |
9916 | READ_ULEB (temp, start, block_end); |
9917 | if ((size_t) (block_end - start) < temp) | |
9918 | start = block_end; | |
041830e0 | 9919 | else |
5897a389 | 9920 | start += temp; |
19e6b90e L |
9921 | break; |
9922 | case DW_CFA_expression: | |
12eae2d3 | 9923 | case DW_CFA_val_expression: |
5897a389 AM |
9924 | READ_ULEB (reg, start, block_end); |
9925 | READ_ULEB (temp, start, block_end); | |
9926 | if ((size_t) (block_end - start) < temp) | |
9927 | start = block_end; | |
041830e0 | 9928 | else |
5897a389 | 9929 | start += temp; |
19e6b90e L |
9930 | break; |
9931 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 9932 | case DW_CFA_val_offset_sf: |
5897a389 AM |
9933 | READ_ULEB (reg, start, block_end); |
9934 | SKIP_SLEB (start, block_end); | |
19e6b90e L |
9935 | break; |
9936 | case DW_CFA_def_cfa_sf: | |
5897a389 AM |
9937 | SKIP_ULEB (start, block_end); |
9938 | SKIP_SLEB (start, block_end); | |
19e6b90e L |
9939 | break; |
9940 | case DW_CFA_def_cfa_offset_sf: | |
5897a389 | 9941 | SKIP_SLEB (start, block_end); |
19e6b90e L |
9942 | break; |
9943 | case DW_CFA_MIPS_advance_loc8: | |
5897a389 AM |
9944 | if ((size_t) (block_end - start) < 8) |
9945 | start = block_end; | |
9946 | else | |
9947 | start += 8; | |
19e6b90e L |
9948 | break; |
9949 | case DW_CFA_GNU_args_size: | |
5897a389 | 9950 | SKIP_ULEB (start, block_end); |
19e6b90e L |
9951 | break; |
9952 | case DW_CFA_GNU_negative_offset_extended: | |
5897a389 AM |
9953 | READ_ULEB (reg, start, block_end); |
9954 | SKIP_ULEB (start, block_end); | |
665ce1f6 | 9955 | break; |
19e6b90e L |
9956 | default: |
9957 | break; | |
9958 | } | |
45bf072b AM |
9959 | if (reg != -1u && frame_need_space (fc, reg) >= 0) |
9960 | { | |
9961 | /* Don't leave any reg as DW_CFA_unreferenced so | |
9962 | that frame_display_row prints name of regs in | |
9963 | header, and all referenced regs in each line. */ | |
9964 | if (reg >= cie->ncols | |
9965 | || cie->col_type[reg] == DW_CFA_unreferenced) | |
9966 | fc->col_type[reg] = DW_CFA_undefined; | |
9967 | else | |
9968 | fc->col_type[reg] = cie->col_type[reg]; | |
9969 | } | |
19e6b90e L |
9970 | } |
9971 | start = tmp; | |
9972 | } | |
9973 | ||
015dc7e1 | 9974 | all_nops = true; |
5b6312fd | 9975 | |
19e6b90e L |
9976 | /* Now we know what registers are used, make a second pass over |
9977 | the chunk, this time actually printing out the info. */ | |
9978 | ||
9979 | while (start < block_end) | |
9980 | { | |
9981 | unsigned op, opa; | |
7f2c8a1d NC |
9982 | /* Note: It is tempting to use an unsigned long for 'reg' but there |
9983 | are various functions, notably frame_space_needed() that assume that | |
9984 | reg is an unsigned int. */ | |
9985 | unsigned int reg; | |
d0517d6e | 9986 | int64_t sofs; |
31e5a3a3 | 9987 | uint64_t ofs; |
665ce1f6 | 9988 | const char *reg_prefix = ""; |
19e6b90e L |
9989 | |
9990 | op = *start++; | |
9991 | opa = op & 0x3f; | |
9992 | if (op & 0xc0) | |
9993 | op &= 0xc0; | |
9994 | ||
5b6312fd NC |
9995 | /* Make a note if something other than DW_CFA_nop happens. */ |
9996 | if (op != DW_CFA_nop) | |
015dc7e1 | 9997 | all_nops = false; |
5b6312fd | 9998 | |
19e6b90e L |
9999 | /* Warning: if you add any more cases to this switch, be |
10000 | sure to add them to the corresponding switch above. */ | |
10001 | switch (op) | |
10002 | { | |
10003 | case DW_CFA_advance_loc: | |
d0517d6e | 10004 | opa *= fc->code_factor; |
19e6b90e L |
10005 | if (do_debug_frames_interp) |
10006 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10007 | else | |
31e5a3a3 | 10008 | { |
d0517d6e AM |
10009 | printf (" DW_CFA_advance_loc: %d to ", opa); |
10010 | print_hex_ns (fc->pc_begin + opa, fc->ptr_size); | |
31e5a3a3 AM |
10011 | printf ("\n"); |
10012 | } | |
d0517d6e | 10013 | fc->pc_begin += opa; |
19e6b90e L |
10014 | break; |
10015 | ||
10016 | case DW_CFA_offset: | |
d0517d6e AM |
10017 | READ_ULEB (ofs, start, block_end); |
10018 | ofs *= fc->data_factor; | |
45bf072b | 10019 | if (opa >= fc->ncols) |
665ce1f6 L |
10020 | reg_prefix = bad_reg; |
10021 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
d0517d6e AM |
10022 | printf (" DW_CFA_offset: %s%s at cfa%+" PRId64 "\n", |
10023 | reg_prefix, regname (opa, 0), ofs); | |
665ce1f6 L |
10024 | if (*reg_prefix == '\0') |
10025 | { | |
10026 | fc->col_type[opa] = DW_CFA_offset; | |
d0517d6e | 10027 | fc->col_offset[opa] = ofs; |
665ce1f6 | 10028 | } |
19e6b90e L |
10029 | break; |
10030 | ||
10031 | case DW_CFA_restore: | |
45bf072b | 10032 | if (opa >= fc->ncols) |
665ce1f6 L |
10033 | reg_prefix = bad_reg; |
10034 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10035 | printf (" DW_CFA_restore: %s%s\n", | |
10036 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
10037 | if (*reg_prefix != '\0') |
10038 | break; | |
10039 | ||
45bf072b AM |
10040 | if (opa >= cie->ncols |
10041 | || cie->col_type[opa] == DW_CFA_unreferenced) | |
50751e18 AK |
10042 | { |
10043 | fc->col_type[opa] = DW_CFA_undefined; | |
10044 | fc->col_offset[opa] = 0; | |
10045 | } | |
10046 | else | |
665ce1f6 L |
10047 | { |
10048 | fc->col_type[opa] = cie->col_type[opa]; | |
10049 | fc->col_offset[opa] = cie->col_offset[opa]; | |
10050 | } | |
19e6b90e L |
10051 | break; |
10052 | ||
10053 | case DW_CFA_set_loc: | |
d0517d6e | 10054 | ofs = get_encoded_value (&start, fc->fde_encoding, section, |
5897a389 | 10055 | block_end); |
19e6b90e L |
10056 | if (do_debug_frames_interp) |
10057 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10058 | else | |
31e5a3a3 AM |
10059 | { |
10060 | printf (" DW_CFA_set_loc: "); | |
d0517d6e | 10061 | print_hex_ns (ofs, fc->ptr_size); |
31e5a3a3 AM |
10062 | printf ("\n"); |
10063 | } | |
d0517d6e | 10064 | fc->pc_begin = ofs; |
19e6b90e L |
10065 | break; |
10066 | ||
10067 | case DW_CFA_advance_loc1: | |
5897a389 | 10068 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, block_end); |
d0517d6e | 10069 | ofs *= fc->code_factor; |
19e6b90e L |
10070 | if (do_debug_frames_interp) |
10071 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10072 | else | |
31e5a3a3 | 10073 | { |
d0517d6e AM |
10074 | printf (" DW_CFA_advance_loc1: %" PRId64 " to ", ofs); |
10075 | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); | |
31e5a3a3 AM |
10076 | printf ("\n"); |
10077 | } | |
d0517d6e | 10078 | fc->pc_begin += ofs; |
19e6b90e L |
10079 | break; |
10080 | ||
10081 | case DW_CFA_advance_loc2: | |
6937bb54 | 10082 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
d0517d6e | 10083 | ofs *= fc->code_factor; |
19e6b90e L |
10084 | if (do_debug_frames_interp) |
10085 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10086 | else | |
31e5a3a3 | 10087 | { |
d0517d6e AM |
10088 | printf (" DW_CFA_advance_loc2: %" PRId64 " to ", ofs); |
10089 | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); | |
31e5a3a3 AM |
10090 | printf ("\n"); |
10091 | } | |
d0517d6e | 10092 | fc->pc_begin += ofs; |
19e6b90e L |
10093 | break; |
10094 | ||
10095 | case DW_CFA_advance_loc4: | |
6937bb54 | 10096 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
d0517d6e | 10097 | ofs *= fc->code_factor; |
19e6b90e L |
10098 | if (do_debug_frames_interp) |
10099 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10100 | else | |
31e5a3a3 | 10101 | { |
d0517d6e AM |
10102 | printf (" DW_CFA_advance_loc4: %" PRId64 " to ", ofs); |
10103 | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); | |
31e5a3a3 AM |
10104 | printf ("\n"); |
10105 | } | |
d0517d6e | 10106 | fc->pc_begin += ofs; |
19e6b90e L |
10107 | break; |
10108 | ||
10109 | case DW_CFA_offset_extended: | |
5897a389 | 10110 | READ_ULEB (reg, start, block_end); |
d0517d6e AM |
10111 | READ_ULEB (ofs, start, block_end); |
10112 | ofs *= fc->data_factor; | |
45bf072b | 10113 | if (reg >= fc->ncols) |
665ce1f6 L |
10114 | reg_prefix = bad_reg; |
10115 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
d0517d6e AM |
10116 | printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64 "\n", |
10117 | reg_prefix, regname (reg, 0), ofs); | |
665ce1f6 L |
10118 | if (*reg_prefix == '\0') |
10119 | { | |
10120 | fc->col_type[reg] = DW_CFA_offset; | |
d0517d6e | 10121 | fc->col_offset[reg] = ofs; |
665ce1f6 | 10122 | } |
19e6b90e L |
10123 | break; |
10124 | ||
12eae2d3 | 10125 | case DW_CFA_val_offset: |
5897a389 | 10126 | READ_ULEB (reg, start, block_end); |
d0517d6e AM |
10127 | READ_ULEB (ofs, start, block_end); |
10128 | ofs *= fc->data_factor; | |
45bf072b | 10129 | if (reg >= fc->ncols) |
665ce1f6 L |
10130 | reg_prefix = bad_reg; |
10131 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
d0517d6e AM |
10132 | printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64 "\n", |
10133 | reg_prefix, regname (reg, 0), ofs); | |
665ce1f6 L |
10134 | if (*reg_prefix == '\0') |
10135 | { | |
10136 | fc->col_type[reg] = DW_CFA_val_offset; | |
d0517d6e | 10137 | fc->col_offset[reg] = ofs; |
665ce1f6 | 10138 | } |
12eae2d3 JJ |
10139 | break; |
10140 | ||
19e6b90e | 10141 | case DW_CFA_restore_extended: |
5897a389 | 10142 | READ_ULEB (reg, start, block_end); |
45bf072b | 10143 | if (reg >= fc->ncols) |
665ce1f6 L |
10144 | reg_prefix = bad_reg; |
10145 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10146 | printf (" DW_CFA_restore_extended: %s%s\n", | |
10147 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
10148 | if (*reg_prefix != '\0') |
10149 | break; | |
10150 | ||
45bf072b AM |
10151 | if (reg >= cie->ncols |
10152 | || cie->col_type[reg] == DW_CFA_unreferenced) | |
50751e18 AK |
10153 | { |
10154 | fc->col_type[reg] = DW_CFA_undefined; | |
10155 | fc->col_offset[reg] = 0; | |
10156 | } | |
10157 | else | |
665ce1f6 L |
10158 | { |
10159 | fc->col_type[reg] = cie->col_type[reg]; | |
10160 | fc->col_offset[reg] = cie->col_offset[reg]; | |
10161 | } | |
19e6b90e L |
10162 | break; |
10163 | ||
10164 | case DW_CFA_undefined: | |
5897a389 | 10165 | READ_ULEB (reg, start, block_end); |
45bf072b | 10166 | if (reg >= fc->ncols) |
665ce1f6 L |
10167 | reg_prefix = bad_reg; |
10168 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10169 | printf (" DW_CFA_undefined: %s%s\n", | |
10170 | reg_prefix, regname (reg, 0)); | |
10171 | if (*reg_prefix == '\0') | |
10172 | { | |
10173 | fc->col_type[reg] = DW_CFA_undefined; | |
10174 | fc->col_offset[reg] = 0; | |
10175 | } | |
19e6b90e L |
10176 | break; |
10177 | ||
10178 | case DW_CFA_same_value: | |
5897a389 | 10179 | READ_ULEB (reg, start, block_end); |
45bf072b | 10180 | if (reg >= fc->ncols) |
665ce1f6 L |
10181 | reg_prefix = bad_reg; |
10182 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
10183 | printf (" DW_CFA_same_value: %s%s\n", | |
10184 | reg_prefix, regname (reg, 0)); | |
10185 | if (*reg_prefix == '\0') | |
10186 | { | |
10187 | fc->col_type[reg] = DW_CFA_same_value; | |
10188 | fc->col_offset[reg] = 0; | |
10189 | } | |
19e6b90e L |
10190 | break; |
10191 | ||
10192 | case DW_CFA_register: | |
5897a389 | 10193 | READ_ULEB (reg, start, block_end); |
d0517d6e | 10194 | READ_ULEB (ofs, start, block_end); |
45bf072b | 10195 | if (reg >= fc->ncols) |
665ce1f6 L |
10196 | reg_prefix = bad_reg; |
10197 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 10198 | { |
665ce1f6 L |
10199 | printf (" DW_CFA_register: %s%s in ", |
10200 | reg_prefix, regname (reg, 0)); | |
d0517d6e | 10201 | puts (regname (ofs, 0)); |
2dc4cec1 | 10202 | } |
665ce1f6 L |
10203 | if (*reg_prefix == '\0') |
10204 | { | |
10205 | fc->col_type[reg] = DW_CFA_register; | |
d0517d6e | 10206 | fc->col_offset[reg] = ofs; |
665ce1f6 | 10207 | } |
19e6b90e L |
10208 | break; |
10209 | ||
10210 | case DW_CFA_remember_state: | |
10211 | if (! do_debug_frames_interp) | |
10212 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 10213 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 10214 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
10215 | rs->cfa_reg = fc->cfa_reg; |
10216 | rs->ra = fc->ra; | |
10217 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 10218 | rs->ncols = fc->ncols; |
d0517d6e AM |
10219 | rs->col_type = xcmalloc (rs->ncols, sizeof (*rs->col_type)); |
10220 | rs->col_offset = xcmalloc (rs->ncols, sizeof (*rs->col_offset)); | |
10221 | memcpy (rs->col_type, fc->col_type, | |
10222 | rs->ncols * sizeof (*fc->col_type)); | |
10223 | memcpy (rs->col_offset, fc->col_offset, | |
10224 | rs->ncols * sizeof (*fc->col_offset)); | |
19e6b90e L |
10225 | rs->next = remembered_state; |
10226 | remembered_state = rs; | |
10227 | break; | |
10228 | ||
10229 | case DW_CFA_restore_state: | |
10230 | if (! do_debug_frames_interp) | |
10231 | printf (" DW_CFA_restore_state\n"); | |
10232 | rs = remembered_state; | |
10233 | if (rs) | |
10234 | { | |
10235 | remembered_state = rs->next; | |
d71ad7fc RC |
10236 | fc->cfa_offset = rs->cfa_offset; |
10237 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
10238 | fc->ra = rs->ra; |
10239 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
10240 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
10241 | { | |
1306a742 | 10242 | warn (_("Invalid column number in saved frame state\n")); |
06614111 | 10243 | fc->ncols = 0; |
06614111 | 10244 | } |
ca5321d4 AM |
10245 | else |
10246 | { | |
10247 | memcpy (fc->col_type, rs->col_type, | |
10248 | rs->ncols * sizeof (*rs->col_type)); | |
10249 | memcpy (fc->col_offset, rs->col_offset, | |
10250 | rs->ncols * sizeof (*rs->col_offset)); | |
10251 | } | |
19e6b90e L |
10252 | free (rs->col_type); |
10253 | free (rs->col_offset); | |
10254 | free (rs); | |
10255 | } | |
10256 | else if (do_debug_frames_interp) | |
10257 | printf ("Mismatched DW_CFA_restore_state\n"); | |
10258 | break; | |
10259 | ||
10260 | case DW_CFA_def_cfa: | |
5897a389 AM |
10261 | READ_ULEB (fc->cfa_reg, start, block_end); |
10262 | READ_ULEB (fc->cfa_offset, start, block_end); | |
19e6b90e L |
10263 | fc->cfa_exp = 0; |
10264 | if (! do_debug_frames_interp) | |
2dc4cec1 | 10265 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 10266 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
10267 | break; |
10268 | ||
10269 | case DW_CFA_def_cfa_register: | |
5897a389 | 10270 | READ_ULEB (fc->cfa_reg, start, block_end); |
19e6b90e L |
10271 | fc->cfa_exp = 0; |
10272 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
10273 | printf (" DW_CFA_def_cfa_register: %s\n", |
10274 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
10275 | break; |
10276 | ||
10277 | case DW_CFA_def_cfa_offset: | |
5897a389 | 10278 | READ_ULEB (fc->cfa_offset, start, block_end); |
19e6b90e | 10279 | if (! do_debug_frames_interp) |
c8071705 | 10280 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
10281 | break; |
10282 | ||
10283 | case DW_CFA_nop: | |
10284 | if (! do_debug_frames_interp) | |
10285 | printf (" DW_CFA_nop\n"); | |
10286 | break; | |
10287 | ||
10288 | case DW_CFA_def_cfa_expression: | |
d0517d6e AM |
10289 | READ_ULEB (ofs, start, block_end); |
10290 | if (ofs > (size_t) (block_end - start)) | |
6937bb54 | 10291 | { |
d0517d6e AM |
10292 | printf (_(" %s: <corrupt len %" PRIu64 ">\n"), |
10293 | "DW_CFA_def_cfa_expression", ofs); | |
6937bb54 NC |
10294 | break; |
10295 | } | |
19e6b90e L |
10296 | if (! do_debug_frames_interp) |
10297 | { | |
10298 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 | 10299 | decode_location_expression (start, eh_addr_size, 0, -1, |
d0517d6e | 10300 | ofs, 0, section); |
19e6b90e L |
10301 | printf (")\n"); |
10302 | } | |
10303 | fc->cfa_exp = 1; | |
d0517d6e | 10304 | start += ofs; |
19e6b90e L |
10305 | break; |
10306 | ||
10307 | case DW_CFA_expression: | |
5897a389 | 10308 | READ_ULEB (reg, start, block_end); |
d0517d6e | 10309 | READ_ULEB (ofs, start, block_end); |
45bf072b | 10310 | if (reg >= fc->ncols) |
665ce1f6 | 10311 | reg_prefix = bad_reg; |
6937bb54 | 10312 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 10313 | /* PR 17512: file: 98c02eb4. */ |
d0517d6e | 10314 | if (ofs > (size_t) (block_end - start)) |
6937bb54 | 10315 | { |
d0517d6e AM |
10316 | printf (_(" %s: <corrupt len %" PRIu64 ">\n"), |
10317 | "DW_CFA_expression", ofs); | |
6937bb54 NC |
10318 | break; |
10319 | } | |
665ce1f6 | 10320 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 10321 | { |
665ce1f6 L |
10322 | printf (" DW_CFA_expression: %s%s (", |
10323 | reg_prefix, regname (reg, 0)); | |
b7807392 | 10324 | decode_location_expression (start, eh_addr_size, 0, -1, |
d0517d6e | 10325 | ofs, 0, section); |
19e6b90e L |
10326 | printf (")\n"); |
10327 | } | |
665ce1f6 L |
10328 | if (*reg_prefix == '\0') |
10329 | fc->col_type[reg] = DW_CFA_expression; | |
d0517d6e | 10330 | start += ofs; |
19e6b90e L |
10331 | break; |
10332 | ||
12eae2d3 | 10333 | case DW_CFA_val_expression: |
5897a389 | 10334 | READ_ULEB (reg, start, block_end); |
d0517d6e | 10335 | READ_ULEB (ofs, start, block_end); |
45bf072b | 10336 | if (reg >= fc->ncols) |
665ce1f6 | 10337 | reg_prefix = bad_reg; |
d0517d6e | 10338 | if (ofs > (size_t) (block_end - start)) |
6937bb54 | 10339 | { |
d0517d6e AM |
10340 | printf (" %s: <corrupt len %" PRIu64 ">\n", |
10341 | "DW_CFA_val_expression", ofs); | |
6937bb54 NC |
10342 | break; |
10343 | } | |
665ce1f6 | 10344 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 10345 | { |
665ce1f6 L |
10346 | printf (" DW_CFA_val_expression: %s%s (", |
10347 | reg_prefix, regname (reg, 0)); | |
b7807392 | 10348 | decode_location_expression (start, eh_addr_size, 0, -1, |
d0517d6e | 10349 | ofs, 0, section); |
12eae2d3 JJ |
10350 | printf (")\n"); |
10351 | } | |
665ce1f6 L |
10352 | if (*reg_prefix == '\0') |
10353 | fc->col_type[reg] = DW_CFA_val_expression; | |
d0517d6e | 10354 | start += ofs; |
12eae2d3 JJ |
10355 | break; |
10356 | ||
19e6b90e | 10357 | case DW_CFA_offset_extended_sf: |
5897a389 | 10358 | READ_ULEB (reg, start, block_end); |
d0517d6e AM |
10359 | READ_SLEB (sofs, start, block_end); |
10360 | /* data_factor multiplicaton done here as unsigned to | |
10361 | avoid integer overflow warnings from asan on fuzzed | |
10362 | objects. */ | |
10363 | ofs = sofs; | |
10364 | ofs *= fc->data_factor; | |
45bf072b | 10365 | if (reg >= fc->ncols) |
665ce1f6 L |
10366 | reg_prefix = bad_reg; |
10367 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
31e5a3a3 | 10368 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64 "\n", |
d0517d6e | 10369 | reg_prefix, regname (reg, 0), ofs); |
665ce1f6 L |
10370 | if (*reg_prefix == '\0') |
10371 | { | |
10372 | fc->col_type[reg] = DW_CFA_offset; | |
d0517d6e | 10373 | fc->col_offset[reg] = ofs; |
665ce1f6 | 10374 | } |
19e6b90e L |
10375 | break; |
10376 | ||
12eae2d3 | 10377 | case DW_CFA_val_offset_sf: |
5897a389 | 10378 | READ_ULEB (reg, start, block_end); |
d0517d6e AM |
10379 | READ_SLEB (sofs, start, block_end); |
10380 | ofs = sofs; | |
10381 | ofs *= fc->data_factor; | |
45bf072b | 10382 | if (reg >= fc->ncols) |
665ce1f6 L |
10383 | reg_prefix = bad_reg; |
10384 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
31e5a3a3 | 10385 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64 "\n", |
d0517d6e | 10386 | reg_prefix, regname (reg, 0), ofs); |
665ce1f6 L |
10387 | if (*reg_prefix == '\0') |
10388 | { | |
10389 | fc->col_type[reg] = DW_CFA_val_offset; | |
d0517d6e | 10390 | fc->col_offset[reg] = ofs; |
665ce1f6 | 10391 | } |
12eae2d3 JJ |
10392 | break; |
10393 | ||
19e6b90e | 10394 | case DW_CFA_def_cfa_sf: |
5897a389 | 10395 | READ_ULEB (fc->cfa_reg, start, block_end); |
d0517d6e AM |
10396 | READ_SLEB (sofs, start, block_end); |
10397 | ofs = sofs; | |
10398 | ofs *= fc->data_factor; | |
10399 | fc->cfa_offset = ofs; | |
19e6b90e L |
10400 | fc->cfa_exp = 0; |
10401 | if (! do_debug_frames_interp) | |
31e5a3a3 | 10402 | printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64 "\n", |
d0517d6e | 10403 | regname (fc->cfa_reg, 0), ofs); |
19e6b90e L |
10404 | break; |
10405 | ||
10406 | case DW_CFA_def_cfa_offset_sf: | |
d0517d6e AM |
10407 | READ_SLEB (sofs, start, block_end); |
10408 | ofs = sofs; | |
10409 | ofs *= fc->data_factor; | |
10410 | fc->cfa_offset = ofs; | |
19e6b90e | 10411 | if (! do_debug_frames_interp) |
d0517d6e | 10412 | printf (" DW_CFA_def_cfa_offset_sf: %" PRId64 "\n", ofs); |
19e6b90e L |
10413 | break; |
10414 | ||
10415 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 10416 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
d0517d6e | 10417 | ofs *= fc->code_factor; |
19e6b90e L |
10418 | if (do_debug_frames_interp) |
10419 | frame_display_row (fc, &need_col_headers, &max_regs); | |
10420 | else | |
31e5a3a3 | 10421 | { |
d0517d6e AM |
10422 | printf (" DW_CFA_MIPS_advance_loc8: %" PRId64 " to ", ofs); |
10423 | print_hex_ns (fc->pc_begin + ofs, fc->ptr_size); | |
31e5a3a3 AM |
10424 | printf ("\n"); |
10425 | } | |
d0517d6e | 10426 | fc->pc_begin += ofs; |
19e6b90e L |
10427 | break; |
10428 | ||
c4ab4dd7 ML |
10429 | case DW_CFA_AARCH64_negate_ra_state_with_pc: |
10430 | if (! do_debug_frames_interp) | |
10431 | printf (" DW_CFA_AARCH64_negate_ra_state_with_pc\n"); | |
10432 | break; | |
10433 | ||
19e6b90e L |
10434 | case DW_CFA_GNU_window_save: |
10435 | if (! do_debug_frames_interp) | |
e4e340a3 | 10436 | printf (" %s\n", DW_CFA_GNU_window_save_name[is_aarch64]); |
19e6b90e L |
10437 | break; |
10438 | ||
10439 | case DW_CFA_GNU_args_size: | |
d0517d6e | 10440 | READ_ULEB (ofs, start, block_end); |
19e6b90e | 10441 | if (! do_debug_frames_interp) |
d0517d6e | 10442 | printf (" DW_CFA_GNU_args_size: %" PRIu64 "\n", ofs); |
19e6b90e L |
10443 | break; |
10444 | ||
10445 | case DW_CFA_GNU_negative_offset_extended: | |
5897a389 | 10446 | READ_ULEB (reg, start, block_end); |
d0517d6e AM |
10447 | READ_SLEB (sofs, start, block_end); |
10448 | ofs = sofs; | |
10449 | ofs = -ofs * fc->data_factor; | |
45bf072b | 10450 | if (reg >= fc->ncols) |
665ce1f6 L |
10451 | reg_prefix = bad_reg; |
10452 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
31e5a3a3 AM |
10453 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s " |
10454 | "at cfa%+" PRId64 "\n", | |
d0517d6e | 10455 | reg_prefix, regname (reg, 0), ofs); |
665ce1f6 L |
10456 | if (*reg_prefix == '\0') |
10457 | { | |
10458 | fc->col_type[reg] = DW_CFA_offset; | |
d0517d6e | 10459 | fc->col_offset[reg] = ofs; |
665ce1f6 | 10460 | } |
19e6b90e L |
10461 | break; |
10462 | ||
10463 | default: | |
53b8873b NC |
10464 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
10465 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
10466 | else | |
f41e4712 | 10467 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
10468 | start = block_end; |
10469 | } | |
10470 | } | |
10471 | ||
5b6312fd NC |
10472 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
10473 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
10474 | frame_display_row (fc, &need_col_headers, &max_regs); |
10475 | ||
a788aedd AM |
10476 | if (fde_fc.col_type != NULL) |
10477 | { | |
10478 | free (fde_fc.col_type); | |
10479 | fde_fc.col_type = NULL; | |
10480 | } | |
10481 | if (fde_fc.col_offset != NULL) | |
10482 | { | |
10483 | free (fde_fc.col_offset); | |
10484 | fde_fc.col_offset = NULL; | |
10485 | } | |
10486 | ||
19e6b90e | 10487 | start = block_end; |
604282a7 | 10488 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
10489 | } |
10490 | ||
10491 | printf ("\n"); | |
10492 | ||
3391569f NC |
10493 | while (remembered_state != NULL) |
10494 | { | |
10495 | rs = remembered_state; | |
10496 | remembered_state = rs->next; | |
10497 | free (rs->col_type); | |
10498 | free (rs->col_offset); | |
10499 | rs->next = NULL; /* Paranoia. */ | |
10500 | free (rs); | |
10501 | } | |
10502 | ||
10503 | while (chunks != NULL) | |
10504 | { | |
10505 | rs = chunks; | |
10506 | chunks = rs->next; | |
10507 | free (rs->col_type); | |
10508 | free (rs->col_offset); | |
10509 | rs->next = NULL; /* Paranoia. */ | |
10510 | free (rs); | |
10511 | } | |
10512 | ||
10513 | while (forward_refs != NULL) | |
10514 | { | |
10515 | rs = forward_refs; | |
10516 | forward_refs = rs->next; | |
10517 | free (rs->col_type); | |
10518 | free (rs->col_offset); | |
10519 | rs->next = NULL; /* Paranoia. */ | |
10520 | free (rs); | |
10521 | } | |
10522 | ||
19e6b90e L |
10523 | return 1; |
10524 | } | |
10525 | ||
10526 | #undef GET | |
19e6b90e | 10527 | |
61364358 JK |
10528 | static int |
10529 | display_debug_names (struct dwarf_section *section, void *file) | |
10530 | { | |
10531 | unsigned char *hdrptr = section->start; | |
31e5a3a3 | 10532 | uint64_t unit_length; |
61364358 JK |
10533 | unsigned char *unit_start; |
10534 | const unsigned char *const section_end = section->start + section->size; | |
10535 | unsigned char *unit_end; | |
10536 | ||
015dc7e1 | 10537 | introduce (section, false); |
61364358 | 10538 | |
dda8d76d | 10539 | load_debug_section_with_follow (str, file); |
61364358 JK |
10540 | |
10541 | for (; hdrptr < section_end; hdrptr = unit_end) | |
10542 | { | |
10543 | unsigned int offset_size; | |
10544 | uint16_t dwarf_version, padding; | |
10545 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
d7870f63 | 10546 | uint64_t bucket_count, name_count, abbrev_table_size; |
61364358 JK |
10547 | uint32_t augmentation_string_size; |
10548 | unsigned int i; | |
015dc7e1 | 10549 | bool augmentation_printable; |
48467cb9 | 10550 | const char *augmentation_string; |
d7870f63 | 10551 | size_t total; |
61364358 JK |
10552 | |
10553 | unit_start = hdrptr; | |
10554 | ||
10555 | /* Get and check the length of the block. */ | |
10556 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
10557 | ||
10558 | if (unit_length == 0xffffffff) | |
10559 | { | |
10560 | /* This section is 64-bit DWARF. */ | |
10561 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
10562 | offset_size = 8; | |
10563 | } | |
10564 | else | |
10565 | offset_size = 4; | |
61364358 | 10566 | |
d7870f63 AM |
10567 | if (unit_length > (size_t) (section_end - hdrptr) |
10568 | || unit_length < 2 + 2 + 4 * 7) | |
61364358 | 10569 | { |
d7870f63 | 10570 | too_short: |
31e5a3a3 AM |
10571 | warn (_("Debug info is corrupted, %s header at %#tx" |
10572 | " has length %#" PRIx64 "\n"), | |
10573 | section->name, unit_start - section->start, unit_length); | |
61364358 JK |
10574 | return 0; |
10575 | } | |
d7870f63 | 10576 | unit_end = hdrptr + unit_length; |
61364358 JK |
10577 | |
10578 | /* Get and check the version number. */ | |
10579 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
31e5a3a3 | 10580 | printf (_("Version %d\n"), (int) dwarf_version); |
61364358 JK |
10581 | |
10582 | /* Prior versions did not exist, and future versions may not be | |
10583 | backwards compatible. */ | |
10584 | if (dwarf_version != 5) | |
10585 | { | |
10586 | warn (_("Only DWARF version 5 .debug_names " | |
10587 | "is currently supported.\n")); | |
10588 | return 0; | |
10589 | } | |
10590 | ||
10591 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
10592 | if (padding != 0) | |
10593 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
10594 | padding); | |
10595 | ||
10596 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
10597 | if (comp_unit_count == 0) | |
10598 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
10599 | ||
10600 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
10601 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
10602 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
10603 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
10604 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
10605 | ||
10606 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
10607 | if (augmentation_string_size % 4 != 0) | |
10608 | { | |
10609 | warn (_("Augmentation string length %u must be rounded up " | |
10610 | "to a multiple of 4 in .debug_names.\n"), | |
10611 | augmentation_string_size); | |
10612 | augmentation_string_size += (-augmentation_string_size) & 3; | |
10613 | } | |
d7870f63 AM |
10614 | if (augmentation_string_size > (size_t) (unit_end - hdrptr)) |
10615 | goto too_short; | |
48467cb9 | 10616 | |
61364358 | 10617 | printf (_("Augmentation string:")); |
48467cb9 | 10618 | |
015dc7e1 | 10619 | augmentation_printable = true; |
48467cb9 TV |
10620 | augmentation_string = (const char *) hdrptr; |
10621 | ||
61364358 JK |
10622 | for (i = 0; i < augmentation_string_size; i++) |
10623 | { | |
10624 | unsigned char uc; | |
10625 | ||
10626 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
10627 | printf (" %02x", uc); | |
48467cb9 TV |
10628 | |
10629 | if (uc != 0 && !ISPRINT (uc)) | |
015dc7e1 | 10630 | augmentation_printable = false; |
48467cb9 TV |
10631 | } |
10632 | ||
10633 | if (augmentation_printable) | |
10634 | { | |
10635 | printf (" (\""); | |
10636 | for (i = 0; | |
10637 | i < augmentation_string_size && augmentation_string[i]; | |
10638 | ++i) | |
10639 | putchar (augmentation_string[i]); | |
10640 | printf ("\")"); | |
61364358 | 10641 | } |
61364358 JK |
10642 | putchar ('\n'); |
10643 | ||
10644 | printf (_("CU table:\n")); | |
d7870f63 AM |
10645 | if (_mul_overflow (comp_unit_count, offset_size, &total) |
10646 | || total > (size_t) (unit_end - hdrptr)) | |
10647 | goto too_short; | |
61364358 JK |
10648 | for (i = 0; i < comp_unit_count; i++) |
10649 | { | |
10650 | uint64_t cu_offset; | |
10651 | ||
10652 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
cc443420 | 10653 | printf ("[%3u] %#" PRIx64 "\n", i, cu_offset); |
61364358 JK |
10654 | } |
10655 | putchar ('\n'); | |
10656 | ||
10657 | printf (_("TU table:\n")); | |
d7870f63 AM |
10658 | if (_mul_overflow (local_type_unit_count, offset_size, &total) |
10659 | || total > (size_t) (unit_end - hdrptr)) | |
10660 | goto too_short; | |
61364358 JK |
10661 | for (i = 0; i < local_type_unit_count; i++) |
10662 | { | |
10663 | uint64_t tu_offset; | |
10664 | ||
10665 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
cc443420 | 10666 | printf ("[%3u] %#" PRIx64 "\n", i, tu_offset); |
61364358 JK |
10667 | } |
10668 | putchar ('\n'); | |
10669 | ||
10670 | printf (_("Foreign TU table:\n")); | |
d7870f63 AM |
10671 | if (_mul_overflow (foreign_type_unit_count, 8, &total) |
10672 | || total > (size_t) (unit_end - hdrptr)) | |
10673 | goto too_short; | |
61364358 JK |
10674 | for (i = 0; i < foreign_type_unit_count; i++) |
10675 | { | |
10676 | uint64_t signature; | |
10677 | ||
10678 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
10679 | printf (_("[%3u] "), i); | |
cc443420 | 10680 | print_hex_ns (signature, 8); |
61364358 JK |
10681 | putchar ('\n'); |
10682 | } | |
10683 | putchar ('\n'); | |
10684 | ||
d7870f63 AM |
10685 | uint64_t xtra = (bucket_count * sizeof (uint32_t) |
10686 | + name_count * (sizeof (uint32_t) + 2 * offset_size) | |
10687 | + abbrev_table_size); | |
10688 | if (xtra > (size_t) (unit_end - hdrptr)) | |
10689 | { | |
31e5a3a3 AM |
10690 | warn (_("Entry pool offset (%#" PRIx64 ") exceeds unit size %#tx " |
10691 | "for unit %#tx in the debug_names\n"), | |
10692 | xtra, unit_end - unit_start, unit_start - section->start); | |
d7870f63 AM |
10693 | return 0; |
10694 | } | |
61364358 JK |
10695 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; |
10696 | hdrptr += bucket_count * sizeof (uint32_t); | |
10697 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
e0a87412 TT |
10698 | if (bucket_count != 0) |
10699 | hdrptr += name_count * sizeof (uint32_t); | |
61364358 JK |
10700 | unsigned char *const name_table_string_offsets = hdrptr; |
10701 | hdrptr += name_count * offset_size; | |
10702 | unsigned char *const name_table_entry_offsets = hdrptr; | |
10703 | hdrptr += name_count * offset_size; | |
10704 | unsigned char *const abbrev_table = hdrptr; | |
10705 | hdrptr += abbrev_table_size; | |
10706 | const unsigned char *const abbrev_table_end = hdrptr; | |
10707 | unsigned char *const entry_pool = hdrptr; | |
61364358 JK |
10708 | |
10709 | size_t buckets_filled = 0; | |
10710 | size_t bucketi; | |
10711 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
10712 | { | |
10713 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
10714 | ||
10715 | if (bucket != 0) | |
10716 | ++buckets_filled; | |
10717 | } | |
d3a49aa8 AM |
10718 | printf (ngettext ("Used %zu of %lu bucket.\n", |
10719 | "Used %zu of %lu buckets.\n", | |
31e5a3a3 | 10720 | (unsigned long) bucket_count), |
d3a49aa8 | 10721 | buckets_filled, (unsigned long) bucket_count); |
61364358 | 10722 | |
5fbb38fc AM |
10723 | if (bucket_count != 0) |
10724 | { | |
10725 | uint32_t hash_prev = 0; | |
10726 | size_t hash_clash_count = 0; | |
10727 | size_t longest_clash = 0; | |
10728 | size_t this_length = 0; | |
10729 | size_t hashi; | |
10730 | for (hashi = 0; hashi < name_count; hashi++) | |
61364358 | 10731 | { |
5fbb38fc AM |
10732 | const uint32_t hash_this = hash_table_hashes[hashi]; |
10733 | ||
10734 | if (hashi > 0) | |
61364358 | 10735 | { |
5fbb38fc AM |
10736 | if (hash_prev % bucket_count == hash_this % bucket_count) |
10737 | { | |
10738 | ++hash_clash_count; | |
10739 | ++this_length; | |
10740 | longest_clash = MAX (longest_clash, this_length); | |
10741 | } | |
10742 | else | |
10743 | this_length = 0; | |
61364358 | 10744 | } |
5fbb38fc | 10745 | hash_prev = hash_this; |
61364358 | 10746 | } |
31e5a3a3 | 10747 | printf (_("Out of %" PRIu64 " items there are %zu bucket clashes" |
5fbb38fc | 10748 | " (longest of %zu entries).\n"), |
31e5a3a3 | 10749 | name_count, hash_clash_count, longest_clash); |
175b9150 | 10750 | |
e3e5ae04 | 10751 | if (name_count != buckets_filled + hash_clash_count) |
31e5a3a3 AM |
10752 | warn (_("The name_count (%" PRIu64 ")" |
10753 | " is not the same as the used bucket_count" | |
2b34e067 | 10754 | " (%zu) + the hash clash count (%zu)\n"), |
31e5a3a3 | 10755 | name_count, buckets_filled, hash_clash_count); |
61364358 | 10756 | } |
61364358 JK |
10757 | |
10758 | struct abbrev_lookup_entry | |
10759 | { | |
31e5a3a3 | 10760 | uint64_t abbrev_tag; |
61364358 JK |
10761 | unsigned char *abbrev_lookup_ptr; |
10762 | }; | |
10763 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
10764 | size_t abbrev_lookup_used = 0; | |
10765 | size_t abbrev_lookup_allocated = 0; | |
10766 | ||
10767 | unsigned char *abbrevptr = abbrev_table; | |
10768 | for (;;) | |
10769 | { | |
31e5a3a3 | 10770 | uint64_t abbrev_tag; |
cd30bcef AM |
10771 | |
10772 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
10773 | if (abbrev_tag == 0) |
10774 | break; | |
10775 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
10776 | { | |
10777 | abbrev_lookup_allocated = MAX (0x100, | |
10778 | abbrev_lookup_allocated * 2); | |
10779 | abbrev_lookup = xrealloc (abbrev_lookup, | |
10780 | (abbrev_lookup_allocated | |
10781 | * sizeof (*abbrev_lookup))); | |
10782 | } | |
10783 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
10784 | struct abbrev_lookup_entry *entry; | |
10785 | for (entry = abbrev_lookup; | |
10786 | entry < abbrev_lookup + abbrev_lookup_used; | |
10787 | entry++) | |
10788 | if (entry->abbrev_tag == abbrev_tag) | |
10789 | { | |
31e5a3a3 AM |
10790 | warn (_("Duplicate abbreviation tag %" PRIu64 |
10791 | " in unit %#tx in the debug_names section\n"), | |
10792 | abbrev_tag, unit_start - section->start); | |
61364358 JK |
10793 | break; |
10794 | } | |
10795 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
10796 | entry->abbrev_tag = abbrev_tag; | |
10797 | entry->abbrev_lookup_ptr = abbrevptr; | |
10798 | ||
10799 | /* Skip DWARF tag. */ | |
cd30bcef | 10800 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
10801 | for (;;) |
10802 | { | |
31e5a3a3 | 10803 | uint64_t xindex, form; |
cd30bcef AM |
10804 | |
10805 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
10806 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 10807 | if (xindex == 0 && form == 0) |
61364358 JK |
10808 | break; |
10809 | } | |
10810 | } | |
10811 | ||
10812 | printf (_("\nSymbol table:\n")); | |
10813 | uint32_t namei; | |
10814 | for (namei = 0; namei < name_count; ++namei) | |
10815 | { | |
10816 | uint64_t string_offset, entry_offset; | |
6d1ad6f7 | 10817 | unsigned char *p; |
709b8d14 NC |
10818 | /* We need to scan first whether there is a single or multiple |
10819 | entries. TAGNO is -2 for the first entry, it is -1 for the | |
10820 | initial tag read of the second entry, then it becomes 0 for the | |
10821 | first entry for real printing etc. */ | |
10822 | int tagno = -2; | |
10823 | /* Initialize it due to a false compiler warning. */ | |
10824 | uint64_t second_abbrev_tag = -1; | |
10825 | unsigned char *entryptr; | |
61364358 | 10826 | |
6d1ad6f7 AM |
10827 | p = name_table_string_offsets + namei * offset_size; |
10828 | SAFE_BYTE_GET (string_offset, p, offset_size, unit_end); | |
709b8d14 | 10829 | |
6d1ad6f7 AM |
10830 | p = name_table_entry_offsets + namei * offset_size; |
10831 | SAFE_BYTE_GET (entry_offset, p, offset_size, unit_end); | |
61364358 | 10832 | |
e0a87412 TT |
10833 | /* The name table is indexed starting at 1 according to |
10834 | DWARF, so be sure to use the DWARF numbering here. */ | |
10835 | printf ("[%3u] ", namei + 1); | |
10836 | if (bucket_count != 0) | |
10837 | printf ("#%08x ", hash_table_hashes[namei]); | |
709b8d14 | 10838 | |
e0a87412 | 10839 | printf ("%s:", fetch_indirect_string (string_offset)); |
61364358 | 10840 | |
709b8d14 NC |
10841 | entryptr = entry_pool + entry_offset; |
10842 | /* PR 31456: Check for invalid entry offset. */ | |
10843 | if (entryptr < entry_pool || entryptr >= unit_end) | |
10844 | { | |
10845 | warn (_("Invalid entry offset value: %" PRIx64 "\n"), entry_offset); | |
10846 | break; | |
10847 | } | |
61364358 | 10848 | |
61364358 JK |
10849 | for (;;) |
10850 | { | |
31e5a3a3 AM |
10851 | uint64_t abbrev_tag; |
10852 | uint64_t dwarf_tag; | |
cd30bcef | 10853 | const struct abbrev_lookup_entry *entry; |
ef8975b4 | 10854 | uint64_t this_entry = entryptr - entry_pool; |
cd30bcef AM |
10855 | |
10856 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
10857 | if (tagno == -1) |
10858 | { | |
10859 | second_abbrev_tag = abbrev_tag; | |
10860 | tagno = 0; | |
10861 | entryptr = entry_pool + entry_offset; | |
10862 | continue; | |
10863 | } | |
10864 | if (abbrev_tag == 0) | |
10865 | break; | |
10866 | if (tagno >= 0) | |
ef8975b4 | 10867 | printf ("%s<%#" PRIx64 "><%" PRIu64 ">", |
175b9150 | 10868 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), |
ef8975b4 | 10869 | this_entry, abbrev_tag); |
61364358 | 10870 | |
61364358 JK |
10871 | for (entry = abbrev_lookup; |
10872 | entry < abbrev_lookup + abbrev_lookup_used; | |
10873 | entry++) | |
10874 | if (entry->abbrev_tag == abbrev_tag) | |
10875 | break; | |
10876 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
10877 | { | |
31e5a3a3 AM |
10878 | warn (_("Undefined abbreviation tag %" PRId64 |
10879 | " in unit %#tx in the debug_names section\n"), | |
10880 | abbrev_tag, | |
10881 | unit_start - section->start); | |
61364358 JK |
10882 | break; |
10883 | } | |
10884 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 10885 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
10886 | if (tagno >= 0) |
10887 | printf (" %s", get_TAG_name (dwarf_tag)); | |
10888 | for (;;) | |
10889 | { | |
31e5a3a3 | 10890 | uint64_t xindex, form; |
cd30bcef AM |
10891 | |
10892 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
10893 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 10894 | if (xindex == 0 && form == 0) |
61364358 JK |
10895 | break; |
10896 | ||
10897 | if (tagno >= 0) | |
1d827a72 | 10898 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
10899 | entryptr = read_and_display_attr_value (0, form, 0, |
10900 | unit_start, entryptr, unit_end, | |
10901 | 0, 0, offset_size, | |
61364358 | 10902 | dwarf_version, NULL, |
be38442d | 10903 | (tagno < 0), section, |
ec1b0fbb | 10904 | NULL, '=', -1); |
61364358 JK |
10905 | } |
10906 | ++tagno; | |
10907 | } | |
10908 | if (tagno <= 0) | |
10909 | printf (_(" <no entries>")); | |
10910 | putchar ('\n'); | |
10911 | } | |
10912 | ||
10913 | free (abbrev_lookup); | |
10914 | } | |
10915 | ||
10916 | return 1; | |
10917 | } | |
10918 | ||
dda8d76d | 10919 | static int |
d85bf2ba NC |
10920 | display_debug_links (struct dwarf_section * section, |
10921 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
10922 | { |
10923 | const unsigned char * filename; | |
10924 | unsigned int filelen; | |
10925 | ||
015dc7e1 | 10926 | introduce (section, false); |
dda8d76d NC |
10927 | |
10928 | /* The .gnu_debuglink section is formatted as: | |
10929 | (c-string) Filename. | |
10930 | (padding) If needed to reach a 4 byte boundary. | |
10931 | (uint32_t) CRC32 value. | |
10932 | ||
88c66eca | 10933 | The .gnu_debugaltlink section is formatted as: |
dda8d76d NC |
10934 | (c-string) Filename. |
10935 | (binary) Build-ID. */ | |
521d4b19 | 10936 | |
dda8d76d NC |
10937 | filename = section->start; |
10938 | filelen = strnlen ((const char *) filename, section->size); | |
10939 | if (filelen == section->size) | |
10940 | { | |
10941 | warn (_("The debuglink filename is corrupt/missing\n")); | |
10942 | return 0; | |
10943 | } | |
10944 | ||
10945 | printf (_(" Separate debug info file: %s\n"), filename); | |
10946 | ||
24d127aa | 10947 | if (startswith (section->name, ".gnu_debuglink")) |
dda8d76d NC |
10948 | { |
10949 | unsigned int crc32; | |
10950 | unsigned int crc_offset; | |
10951 | ||
10952 | crc_offset = filelen + 1; | |
10953 | crc_offset = (crc_offset + 3) & ~3; | |
10954 | if (crc_offset + 4 > section->size) | |
10955 | { | |
10956 | warn (_("CRC offset missing/truncated\n")); | |
10957 | return 0; | |
10958 | } | |
10959 | ||
10960 | crc32 = byte_get (filename + crc_offset, 4); | |
10961 | ||
10962 | printf (_(" CRC value: %#x\n"), crc32); | |
10963 | ||
10964 | if (crc_offset + 4 < section->size) | |
10965 | { | |
31e5a3a3 AM |
10966 | warn (_("There are %#" PRIx64 |
10967 | " extraneous bytes at the end of the section\n"), | |
10968 | section->size - (crc_offset + 4)); | |
dda8d76d NC |
10969 | return 0; |
10970 | } | |
10971 | } | |
24d127aa | 10972 | else /* startswith (section->name, ".gnu_debugaltlink") */ |
dda8d76d | 10973 | { |
be7d229a AM |
10974 | const unsigned char *build_id = section->start + filelen + 1; |
10975 | size_t build_id_len = section->size - (filelen + 1); | |
10976 | size_t printed; | |
dda8d76d NC |
10977 | |
10978 | /* FIXME: Should we support smaller build-id notes ? */ | |
10979 | if (build_id_len < 0x14) | |
10980 | { | |
be7d229a | 10981 | warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len); |
dda8d76d NC |
10982 | return 0; |
10983 | } | |
10984 | ||
be7d229a | 10985 | printed = printf (_(" Build-ID (%#zx bytes):"), build_id_len); |
d85bf2ba | 10986 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
10987 | putchar ('\n'); |
10988 | } | |
10989 | ||
10990 | putchar ('\n'); | |
10991 | return 1; | |
10992 | } | |
10993 | ||
5bbdf3d5 DE |
10994 | static int |
10995 | display_gdb_index (struct dwarf_section *section, | |
10996 | void *file ATTRIBUTE_UNUSED) | |
10997 | { | |
10998 | unsigned char *start = section->start; | |
10999 | uint32_t version; | |
11000 | uint32_t cu_list_offset, tu_list_offset; | |
81161696 TT |
11001 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset, |
11002 | shortcut_table_offset; | |
5bbdf3d5 | 11003 | unsigned int cu_list_elements, tu_list_elements; |
244e19c7 | 11004 | unsigned int address_table_elements, symbol_table_slots; |
5bbdf3d5 | 11005 | unsigned char *cu_list, *tu_list; |
81161696 | 11006 | unsigned char *address_table, *symbol_table, *shortcut_table, *constant_pool; |
5bbdf3d5 DE |
11007 | unsigned int i; |
11008 | ||
11009 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
11010 | ||
015dc7e1 | 11011 | introduce (section, false); |
5bbdf3d5 | 11012 | |
81161696 TT |
11013 | version = section->size < 4 ? 0 : byte_get_little_endian (start, 4); |
11014 | size_t header_size = (version < 9 ? 6 : 7) * sizeof (uint32_t); | |
11015 | if (section->size < header_size) | |
5bbdf3d5 DE |
11016 | { |
11017 | warn (_("Truncated header in the %s section.\n"), section->name); | |
11018 | return 0; | |
11019 | } | |
11020 | ||
31e5a3a3 | 11021 | printf (_("Version %lu\n"), (unsigned long) version); |
5bbdf3d5 DE |
11022 | |
11023 | /* Prior versions are obsolete, and future versions may not be | |
11024 | backwards compatible. */ | |
81161696 | 11025 | if (version < 3 || version > 9) |
5bbdf3d5 | 11026 | { |
da88a764 | 11027 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
11028 | return 0; |
11029 | } | |
8d6eee87 TT |
11030 | if (version < 4) |
11031 | warn (_("The address table data in version 3 may be wrong.\n")); | |
11032 | if (version < 5) | |
11033 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
11034 | if (version < 6) | |
11035 | warn (_("Version 5 does not include inlined functions.\n")); | |
11036 | if (version < 7) | |
cb1861cb | 11037 | warn (_("Version 6 does not include symbol attributes.\n")); |
aa170720 DE |
11038 | /* Version 7 indices generated by Gold have bad type unit references, |
11039 | PR binutils/15021. But we don't know if the index was generated by | |
11040 | Gold or not, so to avoid worrying users with gdb-generated indices | |
11041 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
11042 | |
11043 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
11044 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
11045 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
11046 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
81161696 TT |
11047 | shortcut_table_offset = byte_get_little_endian (start + 20, 4); |
11048 | if (version < 9) | |
11049 | constant_pool_offset = shortcut_table_offset; | |
11050 | else | |
11051 | constant_pool_offset = byte_get_little_endian (start + 24, 4); | |
5bbdf3d5 DE |
11052 | |
11053 | if (cu_list_offset > section->size | |
11054 | || tu_list_offset > section->size | |
11055 | || address_table_offset > section->size | |
11056 | || symbol_table_offset > section->size | |
81161696 | 11057 | || shortcut_table_offset > section->size |
244e19c7 AM |
11058 | || constant_pool_offset > section->size |
11059 | || tu_list_offset < cu_list_offset | |
11060 | || address_table_offset < tu_list_offset | |
11061 | || symbol_table_offset < address_table_offset | |
81161696 TT |
11062 | || shortcut_table_offset < symbol_table_offset |
11063 | || constant_pool_offset < shortcut_table_offset) | |
5bbdf3d5 DE |
11064 | { |
11065 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
11066 | return 0; | |
11067 | } | |
11068 | ||
244e19c7 AM |
11069 | cu_list_elements = (tu_list_offset - cu_list_offset) / 16; |
11070 | tu_list_elements = (address_table_offset - tu_list_offset) / 24; | |
11071 | address_table_elements = (symbol_table_offset - address_table_offset) / 20; | |
81161696 | 11072 | symbol_table_slots = (shortcut_table_offset - symbol_table_offset) / 8; |
5bbdf3d5 DE |
11073 | |
11074 | cu_list = start + cu_list_offset; | |
11075 | tu_list = start + tu_list_offset; | |
11076 | address_table = start + address_table_offset; | |
11077 | symbol_table = start + symbol_table_offset; | |
81161696 | 11078 | shortcut_table = start + shortcut_table_offset; |
5bbdf3d5 DE |
11079 | constant_pool = start + constant_pool_offset; |
11080 | ||
11081 | printf (_("\nCU table:\n")); | |
244e19c7 | 11082 | for (i = 0; i < cu_list_elements; i++) |
5bbdf3d5 | 11083 | { |
244e19c7 AM |
11084 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 16, 8); |
11085 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 16 + 8, 8); | |
5bbdf3d5 | 11086 | |
cc443420 | 11087 | printf ("[%3u] %#" PRIx64 " - %#" PRIx64 "\n", |
31e5a3a3 | 11088 | i, cu_offset, cu_offset + cu_length - 1); |
5bbdf3d5 DE |
11089 | } |
11090 | ||
11091 | printf (_("\nTU table:\n")); | |
244e19c7 | 11092 | for (i = 0; i < tu_list_elements; i++) |
5bbdf3d5 | 11093 | { |
244e19c7 AM |
11094 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 24, 8); |
11095 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 24 + 8, 8); | |
11096 | uint64_t signature = byte_get_little_endian (tu_list + i * 24 + 16, 8); | |
5bbdf3d5 | 11097 | |
cc443420 | 11098 | printf ("[%3u] %#" PRIx64 " %#" PRIx64 " ", |
31e5a3a3 | 11099 | i, tu_offset, type_offset); |
cc443420 | 11100 | print_hex_ns (signature, 8); |
5bbdf3d5 DE |
11101 | printf ("\n"); |
11102 | } | |
11103 | ||
11104 | printf (_("\nAddress table:\n")); | |
244e19c7 | 11105 | for (i = 0; i < address_table_elements; i++) |
5bbdf3d5 | 11106 | { |
244e19c7 AM |
11107 | uint64_t low = byte_get_little_endian (address_table + i * 20, 8); |
11108 | uint64_t high = byte_get_little_endian (address_table + i * 20 + 8, 8); | |
69bfd175 | 11109 | uint32_t cu_index = byte_get_little_endian (address_table + i * 20 + 16, 4); |
5bbdf3d5 | 11110 | |
31e5a3a3 AM |
11111 | print_hex (low, 8); |
11112 | print_hex (high, 8); | |
11113 | printf ("%" PRIu32 "\n", cu_index); | |
5bbdf3d5 DE |
11114 | } |
11115 | ||
11116 | printf (_("\nSymbol table:\n")); | |
11117 | for (i = 0; i < symbol_table_slots; ++i) | |
11118 | { | |
11119 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
11120 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
11121 | uint32_t num_cus, cu; | |
11122 | ||
11123 | if (name_offset != 0 | |
11124 | || cu_vector_offset != 0) | |
11125 | { | |
11126 | unsigned int j; | |
11127 | ||
53774b7e | 11128 | /* PR 17531: file: 5b7b07ad. */ |
bb19bf12 | 11129 | if (name_offset >= section->size - constant_pool_offset) |
53774b7e NC |
11130 | { |
11131 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
11132 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
11133 | name_offset, i); | |
11134 | } | |
11135 | else | |
acff9664 NC |
11136 | printf ("[%3u] %.*s:", i, |
11137 | (int) (section->size - (constant_pool_offset + name_offset)), | |
11138 | constant_pool + name_offset); | |
53774b7e | 11139 | |
bb19bf12 AM |
11140 | if (section->size - constant_pool_offset < 4 |
11141 | || cu_vector_offset > section->size - constant_pool_offset - 4) | |
53774b7e NC |
11142 | { |
11143 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
11144 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
11145 | cu_vector_offset, i); | |
11146 | continue; | |
11147 | } | |
57028622 | 11148 | |
bb19bf12 | 11149 | num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4); |
53774b7e | 11150 | |
bb19bf12 AM |
11151 | if ((uint64_t) num_cus * 4 > section->size - (constant_pool_offset |
11152 | + cu_vector_offset + 4)) | |
53774b7e NC |
11153 | { |
11154 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 11155 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
11156 | num_cus, i); |
11157 | continue; | |
11158 | } | |
11159 | ||
8d6eee87 TT |
11160 | if (num_cus > 1) |
11161 | printf ("\n"); | |
f3853b34 | 11162 | |
5bbdf3d5 DE |
11163 | for (j = 0; j < num_cus; ++j) |
11164 | { | |
7c1cef97 | 11165 | int is_static; |
8d6eee87 TT |
11166 | gdb_index_symbol_kind kind; |
11167 | ||
5bbdf3d5 | 11168 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 11169 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
11170 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
11171 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 11172 | /* Convert to TU number if it's for a type unit. */ |
e82295b2 | 11173 | if (cu >= cu_list_elements) |
8d6eee87 | 11174 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
31e5a3a3 | 11175 | (unsigned long) cu - cu_list_elements); |
5bbdf3d5 | 11176 | else |
8d6eee87 TT |
11177 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
11178 | ||
459d52c8 DE |
11179 | printf (" [%s, %s]", |
11180 | is_static ? _("static") : _("global"), | |
11181 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
11182 | if (num_cus > 1) |
11183 | printf ("\n"); | |
5bbdf3d5 | 11184 | } |
8d6eee87 TT |
11185 | if (num_cus <= 1) |
11186 | printf ("\n"); | |
5bbdf3d5 DE |
11187 | } |
11188 | } | |
11189 | ||
81161696 TT |
11190 | if (version >= 9) |
11191 | { | |
11192 | printf (_("\nShortcut table:\n")); | |
11193 | ||
11194 | if (shortcut_table_offset + 8 > constant_pool_offset) | |
11195 | { | |
11196 | warn (_("Corrupt shortcut table in the %s section.\n"), section->name); | |
11197 | return 0; | |
11198 | } | |
11199 | ||
11200 | uint32_t lang = byte_get_little_endian (shortcut_table, 4); | |
11201 | printf (_("Language of main: ")); | |
11202 | display_lang (lang); | |
11203 | printf ("\n"); | |
11204 | ||
11205 | printf (_("Name of main: ")); | |
11206 | if (lang == 0) | |
11207 | printf (_("<unknown>\n")); | |
11208 | else | |
11209 | { | |
11210 | uint32_t name_offset = byte_get_little_endian (shortcut_table + 4, 4); | |
11211 | if (name_offset >= section->size - constant_pool_offset) | |
11212 | { | |
11213 | printf (_("<corrupt offset: %x>\n"), name_offset); | |
11214 | warn (_("Corrupt name offset of 0x%x found for name of main\n"), | |
11215 | name_offset); | |
11216 | } | |
11217 | else | |
11218 | printf ("%s\n", constant_pool + name_offset); | |
11219 | } | |
11220 | } | |
11221 | ||
5bbdf3d5 DE |
11222 | return 1; |
11223 | } | |
11224 | ||
657d0d47 CC |
11225 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
11226 | ||
11227 | static void | |
11228 | prealloc_cu_tu_list (unsigned int nshndx) | |
11229 | { | |
688fe114 NC |
11230 | if (nshndx == 0) |
11231 | /* Always allocate at least one entry for the end-marker. */ | |
11232 | nshndx = 1; | |
11233 | ||
657d0d47 CC |
11234 | if (shndx_pool == NULL) |
11235 | { | |
11236 | shndx_pool_size = nshndx; | |
11237 | shndx_pool_used = 0; | |
11238 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
11239 | sizeof (unsigned int)); | |
11240 | } | |
11241 | else | |
11242 | { | |
11243 | shndx_pool_size = shndx_pool_used + nshndx; | |
11244 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
11245 | sizeof (unsigned int)); | |
11246 | } | |
11247 | } | |
11248 | ||
11249 | static void | |
11250 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
11251 | { | |
657d0d47 CC |
11252 | shndx_pool [shndx_pool_used++] = shndx; |
11253 | } | |
11254 | ||
11255 | static void | |
11256 | end_cu_tu_entry (void) | |
11257 | { | |
657d0d47 CC |
11258 | shndx_pool [shndx_pool_used++] = 0; |
11259 | } | |
11260 | ||
341f9135 CC |
11261 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
11262 | ||
11263 | static const char * | |
11264 | get_DW_SECT_short_name (unsigned int dw_sect) | |
11265 | { | |
11266 | static char buf[16]; | |
11267 | ||
11268 | switch (dw_sect) | |
11269 | { | |
cb1861cb AM |
11270 | case DW_SECT_INFO: |
11271 | return "info"; | |
11272 | case DW_SECT_TYPES: | |
11273 | return "types"; | |
11274 | case DW_SECT_ABBREV: | |
11275 | return "abbrev"; | |
11276 | case DW_SECT_LINE: | |
11277 | return "line"; | |
11278 | case DW_SECT_LOC: | |
11279 | return "loc"; | |
11280 | case DW_SECT_STR_OFFSETS: | |
11281 | return "str_off"; | |
11282 | case DW_SECT_MACINFO: | |
11283 | return "macinfo"; | |
11284 | case DW_SECT_MACRO: | |
11285 | return "macro"; | |
11286 | default: | |
11287 | break; | |
341f9135 CC |
11288 | } |
11289 | ||
11290 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
11291 | return buf; | |
11292 | } | |
11293 | ||
11294 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
11295 | These sections are extensions for Fission. | |
11296 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 | 11297 | |
688fe114 | 11298 | static bool |
657d0d47 CC |
11299 | process_cu_tu_index (struct dwarf_section *section, int do_display) |
11300 | { | |
11301 | unsigned char *phdr = section->start; | |
11302 | unsigned char *limit = phdr + section->size; | |
11303 | unsigned char *phash; | |
11304 | unsigned char *pindex; | |
11305 | unsigned char *ppool; | |
11306 | unsigned int version; | |
341f9135 | 11307 | unsigned int ncols = 0; |
657d0d47 CC |
11308 | unsigned int nused; |
11309 | unsigned int nslots; | |
11310 | unsigned int i; | |
341f9135 | 11311 | unsigned int j; |
31e5a3a3 | 11312 | uint64_t signature; |
b9c0d703 | 11313 | size_t total; |
657d0d47 | 11314 | |
6937bb54 NC |
11315 | /* PR 17512: file: 002-168123-0.004. */ |
11316 | if (phdr == NULL) | |
11317 | { | |
11318 | warn (_("Section %s is empty\n"), section->name); | |
688fe114 | 11319 | return false; |
6937bb54 NC |
11320 | } |
11321 | /* PR 17512: file: 002-376-0.004. */ | |
11322 | if (section->size < 24) | |
11323 | { | |
72c61a0d | 11324 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 | 11325 | section->name); |
688fe114 | 11326 | return false; |
6937bb54 NC |
11327 | } |
11328 | ||
6d1ad6f7 AM |
11329 | phash = phdr; |
11330 | SAFE_BYTE_GET_AND_INC (version, phash, 4, limit); | |
341f9135 | 11331 | if (version >= 2) |
6d1ad6f7 AM |
11332 | SAFE_BYTE_GET_AND_INC (ncols, phash, 4, limit); |
11333 | SAFE_BYTE_GET_AND_INC (nused, phash, 4, limit); | |
11334 | SAFE_BYTE_GET_AND_INC (nslots, phash, 4, limit); | |
6937bb54 | 11335 | |
8e2e3c6c AM |
11336 | pindex = phash + (size_t) nslots * 8; |
11337 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 11338 | |
657d0d47 CC |
11339 | if (do_display) |
11340 | { | |
015dc7e1 | 11341 | introduce (section, false); |
dda8d76d | 11342 | |
8e2e3c6c | 11343 | printf (_(" Version: %u\n"), version); |
341f9135 | 11344 | if (version >= 2) |
8e2e3c6c AM |
11345 | printf (_(" Number of columns: %u\n"), ncols); |
11346 | printf (_(" Number of used entries: %u\n"), nused); | |
11347 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
11348 | } |
11349 | ||
8e2e3c6c | 11350 | /* PR 17531: file: 45d69832. */ |
b9c0d703 AM |
11351 | if (_mul_overflow ((size_t) nslots, 12, &total) |
11352 | || total > (size_t) (limit - phash)) | |
657d0d47 | 11353 | { |
8e2e3c6c AM |
11354 | warn (ngettext ("Section %s is too small for %u slot\n", |
11355 | "Section %s is too small for %u slots\n", | |
11356 | nslots), | |
657d0d47 | 11357 | section->name, nslots); |
688fe114 | 11358 | return false; |
657d0d47 CC |
11359 | } |
11360 | ||
341f9135 | 11361 | if (version == 1) |
657d0d47 | 11362 | { |
28750e3b AM |
11363 | unsigned char *shndx_list; |
11364 | unsigned int shndx; | |
11365 | ||
341f9135 | 11366 | if (!do_display) |
657d0d47 | 11367 | { |
28750e3b AM |
11368 | prealloc_cu_tu_list ((limit - ppool) / 4); |
11369 | for (shndx_list = ppool + 4; shndx_list <= limit - 4; shndx_list += 4) | |
657d0d47 | 11370 | { |
28750e3b AM |
11371 | shndx = byte_get (shndx_list, 4); |
11372 | add_shndx_to_cu_tu_entry (shndx); | |
11373 | } | |
11374 | end_cu_tu_entry (); | |
11375 | } | |
11376 | else | |
11377 | for (i = 0; i < nslots; i++) | |
11378 | { | |
11379 | SAFE_BYTE_GET (signature, phash, 8, limit); | |
11380 | if (signature != 0) | |
11381 | { | |
11382 | SAFE_BYTE_GET (j, pindex, 4, limit); | |
11383 | shndx_list = ppool + j * 4; | |
11384 | /* PR 17531: file: 705e010d. */ | |
11385 | if (shndx_list < ppool) | |
11386 | { | |
11387 | warn (_("Section index pool located before start of section\n")); | |
688fe114 | 11388 | return false; |
28750e3b | 11389 | } |
f3853b34 | 11390 | |
cc443420 | 11391 | printf (_(" [%3d] Signature: %#" PRIx64 " Sections: "), |
31e5a3a3 | 11392 | i, signature); |
28750e3b AM |
11393 | for (;;) |
11394 | { | |
11395 | if (shndx_list >= limit) | |
11396 | { | |
11397 | warn (_("Section %s too small for shndx pool\n"), | |
11398 | section->name); | |
688fe114 | 11399 | return false; |
28750e3b AM |
11400 | } |
11401 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); | |
11402 | if (shndx == 0) | |
11403 | break; | |
341f9135 | 11404 | printf (" %d", shndx); |
28750e3b AM |
11405 | shndx_list += 4; |
11406 | } | |
341f9135 | 11407 | printf ("\n"); |
28750e3b AM |
11408 | } |
11409 | phash += 8; | |
11410 | pindex += 4; | |
11411 | } | |
341f9135 CC |
11412 | } |
11413 | else if (version == 2) | |
11414 | { | |
11415 | unsigned int val; | |
11416 | unsigned int dw_sect; | |
11417 | unsigned char *ph = phash; | |
11418 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
11419 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
11420 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
015dc7e1 | 11421 | bool is_tu_index; |
341f9135 CC |
11422 | struct cu_tu_set *this_set = NULL; |
11423 | unsigned int row; | |
11424 | unsigned char *prow; | |
b9c0d703 | 11425 | size_t temp; |
341f9135 CC |
11426 | |
11427 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
11428 | ||
362beea4 | 11429 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
11430 | Check for integer overflow (can occur when size_t is 32-bit) |
11431 | with overlarge ncols or nused values. */ | |
b9c0d703 | 11432 | if (nused == -1u |
175b9150 | 11433 | || _mul_overflow ((size_t) ncols, 4, &temp) |
b9c0d703 | 11434 | || _mul_overflow ((size_t) nused + 1, temp, &total) |
97b75c42 NC |
11435 | || total > (size_t) (limit - ppool) |
11436 | /* PR 30227: ncols could be 0. */ | |
11437 | || _mul_overflow ((size_t) nused + 1, 4, &total) | |
b9c0d703 | 11438 | || total > (size_t) (limit - ppool)) |
341f9135 CC |
11439 | { |
11440 | warn (_("Section %s too small for offset and size tables\n"), | |
11441 | section->name); | |
688fe114 | 11442 | return false; |
341f9135 | 11443 | } |
175b9150 | 11444 | |
341f9135 CC |
11445 | if (do_display) |
11446 | { | |
11447 | printf (_(" Offset table\n")); | |
11448 | printf (" slot %-16s ", | |
cb1861cb | 11449 | is_tu_index ? _("signature") : _("dwo_id")); |
341f9135 CC |
11450 | } |
11451 | else | |
11452 | { | |
11453 | if (is_tu_index) | |
11454 | { | |
11455 | tu_count = nused; | |
72c61a0d | 11456 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 11457 | this_set = tu_sets; |
657d0d47 | 11458 | } |
657d0d47 | 11459 | else |
341f9135 CC |
11460 | { |
11461 | cu_count = nused; | |
72c61a0d | 11462 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
11463 | this_set = cu_sets; |
11464 | } | |
11465 | } | |
6937bb54 | 11466 | |
341f9135 CC |
11467 | if (do_display) |
11468 | { | |
11469 | for (j = 0; j < ncols; j++) | |
11470 | { | |
6d1ad6f7 AM |
11471 | unsigned char *p = ppool + j * 4; |
11472 | SAFE_BYTE_GET (dw_sect, p, 4, limit); | |
341f9135 CC |
11473 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
11474 | } | |
11475 | printf ("\n"); | |
11476 | } | |
6937bb54 | 11477 | |
341f9135 CC |
11478 | for (i = 0; i < nslots; i++) |
11479 | { | |
af2ddf69 | 11480 | SAFE_BYTE_GET (signature, ph, 8, limit); |
6937bb54 NC |
11481 | |
11482 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
11483 | if (row != 0) |
11484 | { | |
591f7597 | 11485 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 11486 | if (row > nused) |
591f7597 NC |
11487 | { |
11488 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
11489 | row, nused); | |
688fe114 | 11490 | return false; |
591f7597 NC |
11491 | } |
11492 | ||
341f9135 | 11493 | if (!do_display) |
6aea08d9 NC |
11494 | { |
11495 | size_t num_copy = sizeof (uint64_t); | |
11496 | ||
b9c0d703 | 11497 | memcpy (&this_set[row - 1].signature, ph, num_copy); |
6aea08d9 | 11498 | } |
6937bb54 | 11499 | |
341f9135 CC |
11500 | prow = poffsets + (row - 1) * ncols * 4; |
11501 | if (do_display) | |
cc443420 | 11502 | printf (" [%3d] %#" PRIx64, i, signature); |
341f9135 CC |
11503 | for (j = 0; j < ncols; j++) |
11504 | { | |
6d1ad6f7 AM |
11505 | unsigned char *p = prow + j * 4; |
11506 | SAFE_BYTE_GET (val, p, 4, limit); | |
341f9135 CC |
11507 | if (do_display) |
11508 | printf (" %8d", val); | |
11509 | else | |
11510 | { | |
6d1ad6f7 AM |
11511 | p = ppool + j * 4; |
11512 | SAFE_BYTE_GET (dw_sect, p, 4, limit); | |
82b1b41b NC |
11513 | |
11514 | /* PR 17531: file: 10796eb3. */ | |
11515 | if (dw_sect >= DW_SECT_MAX) | |
11516 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
11517 | else | |
11518 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
11519 | } |
11520 | } | |
6937bb54 | 11521 | |
341f9135 CC |
11522 | if (do_display) |
11523 | printf ("\n"); | |
11524 | } | |
11525 | ph += 8; | |
11526 | pi += 4; | |
11527 | } | |
11528 | ||
11529 | ph = phash; | |
11530 | pi = pindex; | |
11531 | if (do_display) | |
b4eb7656 | 11532 | { |
341f9135 CC |
11533 | printf ("\n"); |
11534 | printf (_(" Size table\n")); | |
11535 | printf (" slot %-16s ", | |
cb1861cb | 11536 | is_tu_index ? _("signature") : _("dwo_id")); |
b4eb7656 | 11537 | } |
6937bb54 | 11538 | |
341f9135 CC |
11539 | for (j = 0; j < ncols; j++) |
11540 | { | |
6d1ad6f7 AM |
11541 | unsigned char *p = ppool + j * 4; |
11542 | SAFE_BYTE_GET (val, p, 4, limit); | |
341f9135 CC |
11543 | if (do_display) |
11544 | printf (" %8s", get_DW_SECT_short_name (val)); | |
11545 | } | |
6937bb54 | 11546 | |
341f9135 CC |
11547 | if (do_display) |
11548 | printf ("\n"); | |
6937bb54 | 11549 | |
341f9135 CC |
11550 | for (i = 0; i < nslots; i++) |
11551 | { | |
af2ddf69 | 11552 | SAFE_BYTE_GET (signature, ph, 8, limit); |
6937bb54 NC |
11553 | |
11554 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
11555 | if (row != 0) |
11556 | { | |
11557 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 11558 | |
341f9135 | 11559 | if (do_display) |
cc443420 | 11560 | printf (" [%3d] %#" PRIx64, i, signature); |
6937bb54 | 11561 | |
341f9135 CC |
11562 | for (j = 0; j < ncols; j++) |
11563 | { | |
6d1ad6f7 | 11564 | unsigned char *p = prow + j * 4; |
117e35f5 NC |
11565 | |
11566 | /* PR 28645: Check for overflow. Since we do not know how | |
11567 | many populated rows there will be, we cannot just | |
11568 | perform a single check at the start of this function. */ | |
11569 | if (p > (limit - 4)) | |
11570 | { | |
11571 | if (do_display) | |
11572 | printf ("\n"); | |
11573 | warn (_("Too many rows/columns in DWARF index section %s\n"), | |
11574 | section->name); | |
688fe114 | 11575 | return false; |
117e35f5 NC |
11576 | } |
11577 | ||
6d1ad6f7 | 11578 | SAFE_BYTE_GET (val, p, 4, limit); |
117e35f5 | 11579 | |
341f9135 CC |
11580 | if (do_display) |
11581 | printf (" %8d", val); | |
11582 | else | |
11583 | { | |
6d1ad6f7 AM |
11584 | p = ppool + j * 4; |
11585 | SAFE_BYTE_GET (dw_sect, p, 4, limit); | |
82b1b41b NC |
11586 | if (dw_sect >= DW_SECT_MAX) |
11587 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
11588 | else | |
cb1861cb | 11589 | this_set [row - 1].section_sizes [dw_sect] = val; |
341f9135 CC |
11590 | } |
11591 | } | |
6937bb54 | 11592 | |
341f9135 CC |
11593 | if (do_display) |
11594 | printf ("\n"); | |
11595 | } | |
6937bb54 | 11596 | |
341f9135 CC |
11597 | ph += 8; |
11598 | pi += 4; | |
657d0d47 | 11599 | } |
657d0d47 | 11600 | } |
341f9135 | 11601 | else if (do_display) |
6937bb54 | 11602 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
11603 | |
11604 | if (do_display) | |
cb1861cb | 11605 | printf ("\n"); |
657d0d47 | 11606 | |
688fe114 | 11607 | return true; |
657d0d47 CC |
11608 | } |
11609 | ||
288f0ba2 AM |
11610 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
11611 | ||
657d0d47 CC |
11612 | /* Load the CU and TU indexes if present. This will build a list of |
11613 | section sets that we can use to associate a .debug_info.dwo section | |
11614 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
11615 | ||
015dc7e1 | 11616 | static bool |
657d0d47 CC |
11617 | load_cu_tu_indexes (void *file) |
11618 | { | |
11619 | /* If we have already loaded (or tried to load) the CU and TU indexes | |
11620 | then do not bother to repeat the task. */ | |
43a444f9 NC |
11621 | if (cu_tu_indexes_read == -1) |
11622 | { | |
015dc7e1 | 11623 | cu_tu_indexes_read = true; |
521d4b19 | 11624 | |
dda8d76d | 11625 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 | 11626 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
015dc7e1 | 11627 | cu_tu_indexes_read = false; |
43a444f9 | 11628 | |
dda8d76d | 11629 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 | 11630 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
015dc7e1 | 11631 | cu_tu_indexes_read = false; |
43a444f9 | 11632 | } |
657d0d47 | 11633 | |
015dc7e1 | 11634 | return (bool) cu_tu_indexes_read; |
657d0d47 CC |
11635 | } |
11636 | ||
11637 | /* Find the set of sections that includes section SHNDX. */ | |
11638 | ||
11639 | unsigned int * | |
11640 | find_cu_tu_set (void *file, unsigned int shndx) | |
11641 | { | |
11642 | unsigned int i; | |
11643 | ||
43a444f9 NC |
11644 | if (! load_cu_tu_indexes (file)) |
11645 | return NULL; | |
657d0d47 CC |
11646 | |
11647 | /* Find SHNDX in the shndx pool. */ | |
11648 | for (i = 0; i < shndx_pool_used; i++) | |
11649 | if (shndx_pool [i] == shndx) | |
11650 | break; | |
11651 | ||
11652 | if (i >= shndx_pool_used) | |
11653 | return NULL; | |
11654 | ||
11655 | /* Now backup to find the first entry in the set. */ | |
11656 | while (i > 0 && shndx_pool [i - 1] != 0) | |
11657 | i--; | |
11658 | ||
11659 | return shndx_pool + i; | |
11660 | } | |
11661 | ||
11662 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
11663 | ||
11664 | static int | |
11665 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
11666 | { | |
11667 | return process_cu_tu_index (section, 1); | |
11668 | } | |
11669 | ||
19e6b90e L |
11670 | static int |
11671 | display_debug_not_supported (struct dwarf_section *section, | |
11672 | void *file ATTRIBUTE_UNUSED) | |
11673 | { | |
11674 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
cb1861cb | 11675 | section->name); |
19e6b90e L |
11676 | |
11677 | return 1; | |
11678 | } | |
11679 | ||
1306a742 NC |
11680 | /* Like malloc, but takes two parameters like calloc. |
11681 | Verifies that the first parameter is not too large. | |
82b1b41b | 11682 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 11683 | |
19e6b90e | 11684 | void * |
26c527e6 | 11685 | cmalloc (uint64_t nmemb, size_t size) |
19e6b90e L |
11686 | { |
11687 | /* Check for overflow. */ | |
11688 | if (nmemb >= ~(size_t) 0 / size) | |
11689 | return NULL; | |
82b1b41b NC |
11690 | |
11691 | return xmalloc (nmemb * size); | |
19e6b90e L |
11692 | } |
11693 | ||
1306a742 NC |
11694 | /* Like xmalloc, but takes two parameters like calloc. |
11695 | Verifies that the first parameter is not too large. | |
11696 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 11697 | |
72c61a0d | 11698 | void * |
26c527e6 | 11699 | xcmalloc (uint64_t nmemb, size_t size) |
72c61a0d NC |
11700 | { |
11701 | /* Check for overflow. */ | |
11702 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
11703 | { |
11704 | fprintf (stderr, | |
26c527e6 | 11705 | _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64 "\n"), |
31e5a3a3 | 11706 | nmemb); |
8490fb40 NC |
11707 | xexit (1); |
11708 | } | |
72c61a0d | 11709 | |
1306a742 | 11710 | return xmalloc (nmemb * size); |
72c61a0d NC |
11711 | } |
11712 | ||
1306a742 NC |
11713 | /* Like xrealloc, but takes three parameters. |
11714 | Verifies that the second parameter is not too large. | |
11715 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 11716 | |
19e6b90e | 11717 | void * |
26c527e6 | 11718 | xcrealloc (void *ptr, uint64_t nmemb, size_t size) |
19e6b90e L |
11719 | { |
11720 | /* Check for overflow. */ | |
11721 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 11722 | { |
26c527e6 | 11723 | error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64 "\n"), |
31e5a3a3 | 11724 | nmemb); |
8490fb40 NC |
11725 | xexit (1); |
11726 | } | |
82b1b41b | 11727 | |
1306a742 | 11728 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
11729 | } |
11730 | ||
1306a742 | 11731 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 11732 | |
19e6b90e | 11733 | void * |
26c527e6 | 11734 | xcalloc2 (uint64_t nmemb, size_t size) |
19e6b90e L |
11735 | { |
11736 | /* Check for overflow. */ | |
11737 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 11738 | { |
26c527e6 | 11739 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64 "\n"), |
31e5a3a3 | 11740 | nmemb); |
8490fb40 NC |
11741 | xexit (1); |
11742 | } | |
82b1b41b | 11743 | |
1306a742 | 11744 | return xcalloc (nmemb, size); |
19e6b90e L |
11745 | } |
11746 | ||
dda8d76d | 11747 | static unsigned long |
be7d229a AM |
11748 | calc_gnu_debuglink_crc32 (unsigned long crc, |
11749 | const unsigned char *buf, | |
11750 | size_t len) | |
dda8d76d NC |
11751 | { |
11752 | static const unsigned long crc32_table[256] = | |
11753 | { | |
11754 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
11755 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
11756 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
11757 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
11758 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
11759 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
11760 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
11761 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
11762 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
11763 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
11764 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
11765 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
11766 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
11767 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
11768 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
11769 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
11770 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
11771 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
11772 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
11773 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
11774 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
11775 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
11776 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
11777 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
11778 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
11779 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
11780 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
11781 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
11782 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
11783 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
11784 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
11785 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
11786 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
11787 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
11788 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
11789 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
11790 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
11791 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
11792 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
11793 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
11794 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
11795 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
11796 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
11797 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
11798 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
11799 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
11800 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
11801 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
11802 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
11803 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
11804 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
11805 | 0x2d02ef8d | |
11806 | }; | |
11807 | const unsigned char *end; | |
11808 | ||
11809 | crc = ~crc & 0xffffffff; | |
11810 | for (end = buf + len; buf < end; ++ buf) | |
11811 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
11812 | return ~crc & 0xffffffff; | |
11813 | } | |
11814 | ||
015dc7e1 AM |
11815 | typedef bool (*check_func_type) (const char *, void *); |
11816 | typedef const char *(* parse_func_type) (struct dwarf_section *, void *); | |
dda8d76d | 11817 | |
015dc7e1 | 11818 | static bool |
dda8d76d NC |
11819 | check_gnu_debuglink (const char * pathname, void * crc_pointer) |
11820 | { | |
be7d229a AM |
11821 | static unsigned char buffer[8 * 1024]; |
11822 | FILE *f; | |
11823 | size_t count; | |
11824 | unsigned long crc = 0; | |
11825 | void *sep_data; | |
dda8d76d NC |
11826 | |
11827 | sep_data = open_debug_file (pathname); | |
11828 | if (sep_data == NULL) | |
015dc7e1 | 11829 | return false; |
dda8d76d NC |
11830 | |
11831 | /* Yes - we are opening the file twice... */ | |
11832 | f = fopen (pathname, "rb"); | |
11833 | if (f == NULL) | |
11834 | { | |
11835 | /* Paranoia: This should never happen. */ | |
11836 | close_debug_file (sep_data); | |
11837 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
015dc7e1 | 11838 | return false; |
dda8d76d NC |
11839 | } |
11840 | ||
11841 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
11842 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
11843 | ||
11844 | fclose (f); | |
94e2b2a7 | 11845 | close_debug_file (sep_data); |
dda8d76d NC |
11846 | |
11847 | if (crc != * (unsigned long *) crc_pointer) | |
11848 | { | |
dda8d76d NC |
11849 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), |
11850 | pathname); | |
015dc7e1 | 11851 | return false; |
dda8d76d NC |
11852 | } |
11853 | ||
015dc7e1 | 11854 | return true; |
dda8d76d NC |
11855 | } |
11856 | ||
11857 | static const char * | |
11858 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
11859 | { | |
11860 | const char * name; | |
11861 | unsigned int crc_offset; | |
11862 | unsigned long * crc32 = (unsigned long *) data; | |
11863 | ||
11864 | /* The name is first. | |
11865 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
11866 | name = (const char *) section->start; | |
11867 | ||
11868 | crc_offset = strnlen (name, section->size) + 1; | |
3d64c987 NC |
11869 | if (crc_offset == 1) |
11870 | return NULL; | |
dda8d76d NC |
11871 | crc_offset = (crc_offset + 3) & ~3; |
11872 | if (crc_offset + 4 > section->size) | |
11873 | return NULL; | |
11874 | ||
11875 | * crc32 = byte_get (section->start + crc_offset, 4); | |
11876 | return name; | |
11877 | } | |
11878 | ||
015dc7e1 | 11879 | static bool |
dda8d76d NC |
11880 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) |
11881 | { | |
11882 | void * sep_data = open_debug_file (filename); | |
11883 | ||
11884 | if (sep_data == NULL) | |
015dc7e1 | 11885 | return false; |
dda8d76d NC |
11886 | |
11887 | /* FIXME: We should now extract the build-id in the separate file | |
11888 | and check it... */ | |
11889 | ||
94e2b2a7 | 11890 | close_debug_file (sep_data); |
015dc7e1 | 11891 | return true; |
dda8d76d NC |
11892 | } |
11893 | ||
11894 | typedef struct build_id_data | |
11895 | { | |
be7d229a AM |
11896 | size_t len; |
11897 | const unsigned char *data; | |
dda8d76d NC |
11898 | } Build_id_data; |
11899 | ||
11900 | static const char * | |
11901 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
11902 | { | |
be7d229a AM |
11903 | const char *name; |
11904 | size_t namelen; | |
11905 | size_t id_len; | |
11906 | Build_id_data *build_id_data; | |
dda8d76d NC |
11907 | |
11908 | /* The name is first. | |
11909 | The build-id follows immediately, with no padding, up to the section's end. */ | |
11910 | ||
11911 | name = (const char *) section->start; | |
11912 | namelen = strnlen (name, section->size) + 1; | |
3d64c987 NC |
11913 | if (namelen == 1) |
11914 | return NULL; | |
dda8d76d NC |
11915 | if (namelen >= section->size) |
11916 | return NULL; | |
11917 | ||
11918 | id_len = section->size - namelen; | |
11919 | if (id_len < 0x14) | |
11920 | return NULL; | |
11921 | ||
dfbee680 | 11922 | build_id_data = (Build_id_data *) data; |
dda8d76d NC |
11923 | build_id_data->len = id_len; |
11924 | build_id_data->data = section->start + namelen; | |
11925 | ||
dda8d76d NC |
11926 | return name; |
11927 | } | |
11928 | ||
24841daa NC |
11929 | static void |
11930 | add_separate_debug_file (const char * filename, void * handle) | |
11931 | { | |
11932 | separate_info * i = xmalloc (sizeof * i); | |
11933 | ||
11934 | i->filename = filename; | |
11935 | i->handle = handle; | |
11936 | i->next = first_separate_info; | |
11937 | first_separate_info = i; | |
11938 | } | |
11939 | ||
301a9420 AM |
11940 | #if HAVE_LIBDEBUGINFOD |
11941 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
11942 | file. If successful, store the path of the file in filename and | |
11943 | return TRUE, otherwise return FALSE. */ | |
11944 | ||
015dc7e1 | 11945 | static bool |
301a9420 | 11946 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, |
175b9150 AM |
11947 | char ** filename, |
11948 | void * file) | |
301a9420 AM |
11949 | { |
11950 | size_t build_id_len; | |
11951 | unsigned char * build_id; | |
11952 | ||
11953 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
11954 | { | |
11955 | /* Get the build-id of file. */ | |
11956 | build_id = get_build_id (file); | |
11957 | build_id_len = 0; | |
11958 | } | |
11959 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
11960 | { | |
11961 | /* Get the build-id of the debugaltlink file. */ | |
11962 | unsigned int filelen; | |
11963 | ||
11964 | filelen = strnlen ((const char *)section->start, section->size); | |
11965 | if (filelen == section->size) | |
175b9150 AM |
11966 | /* Corrupt debugaltlink. */ |
11967 | return false; | |
301a9420 AM |
11968 | |
11969 | build_id = section->start + filelen + 1; | |
11970 | build_id_len = section->size - (filelen + 1); | |
11971 | ||
11972 | if (build_id_len == 0) | |
175b9150 | 11973 | return false; |
301a9420 AM |
11974 | } |
11975 | else | |
015dc7e1 | 11976 | return false; |
301a9420 AM |
11977 | |
11978 | if (build_id) | |
11979 | { | |
11980 | int fd; | |
11981 | debuginfod_client * client; | |
11982 | ||
11983 | client = debuginfod_begin (); | |
11984 | if (client == NULL) | |
175b9150 | 11985 | return false; |
301a9420 AM |
11986 | |
11987 | /* Query debuginfod servers for the target file. If found its path | |
175b9150 | 11988 | will be stored in filename. */ |
301a9420 AM |
11989 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); |
11990 | debuginfod_end (client); | |
11991 | ||
11992 | /* Only free build_id if we allocated space for a hex string | |
175b9150 | 11993 | in get_build_id (). */ |
301a9420 | 11994 | if (build_id_len == 0) |
175b9150 | 11995 | free (build_id); |
301a9420 AM |
11996 | |
11997 | if (fd >= 0) | |
175b9150 AM |
11998 | { |
11999 | /* File successfully retrieved. Close fd since we want to | |
12000 | use open_debug_file () on filename instead. */ | |
12001 | close (fd); | |
12002 | return true; | |
12003 | } | |
301a9420 AM |
12004 | } |
12005 | ||
015dc7e1 | 12006 | return false; |
301a9420 | 12007 | } |
bed566bb | 12008 | #endif /* HAVE_LIBDEBUGINFOD */ |
301a9420 | 12009 | |
dda8d76d NC |
12010 | static void * |
12011 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 12012 | struct dwarf_section * xlink, |
dda8d76d NC |
12013 | parse_func_type parse_func, |
12014 | check_func_type check_func, | |
301a9420 | 12015 | void * func_data, |
175b9150 | 12016 | void * file ATTRIBUTE_UNUSED) |
dda8d76d NC |
12017 | { |
12018 | const char * separate_filename; | |
24841daa | 12019 | char * debug_filename; |
dda8d76d NC |
12020 | char * canon_dir; |
12021 | size_t canon_dirlen; | |
12022 | size_t dirlen; | |
40eb8b92 L |
12023 | char * canon_filename; |
12024 | char * canon_debug_filename; | |
12025 | bool self; | |
dda8d76d | 12026 | |
2b63c337 | 12027 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
12028 | { |
12029 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 12030 | xlink->name ? xlink->name : xlink->uncompressed_name); |
ce139cd5 | 12031 | return NULL; |
dda8d76d | 12032 | } |
521d4b19 | 12033 | |
dda8d76d NC |
12034 | /* Attempt to locate the separate file. |
12035 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
12036 | ||
40eb8b92 L |
12037 | canon_filename = lrealpath (main_filename); |
12038 | canon_dir = xstrdup (canon_filename); | |
521d4b19 | 12039 | |
dda8d76d NC |
12040 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) |
12041 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
12042 | break; | |
12043 | canon_dir[canon_dirlen] = '\0'; | |
12044 | ||
12045 | #ifndef DEBUGDIR | |
12046 | #define DEBUGDIR "/lib/debug" | |
12047 | #endif | |
12048 | #ifndef EXTRA_DEBUG_ROOT1 | |
12049 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
12050 | #endif | |
12051 | #ifndef EXTRA_DEBUG_ROOT2 | |
12052 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
12053 | #endif | |
12054 | ||
24841daa NC |
12055 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
12056 | + canon_dirlen | |
12057 | + strlen (".debug/") | |
dda8d76d | 12058 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 12059 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
12060 | #endif |
12061 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 12062 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 12063 | #endif |
24841daa NC |
12064 | + strlen (separate_filename) |
12065 | + 1); | |
12066 | if (debug_filename == NULL) | |
dda8d76d | 12067 | { |
2b34e067 | 12068 | warn (_("Out of memory\n")); |
3391569f | 12069 | free (canon_dir); |
40eb8b92 | 12070 | free (canon_filename); |
dda8d76d NC |
12071 | return NULL; |
12072 | } | |
12073 | ||
12074 | /* First try in the current directory. */ | |
24841daa NC |
12075 | sprintf (debug_filename, "%s", separate_filename); |
12076 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
12077 | goto found; |
12078 | ||
12079 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
12080 | sprintf (debug_filename, ".debug/%s", separate_filename); |
12081 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
12082 | goto found; |
12083 | ||
12084 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
12085 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
12086 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
12087 | goto found; |
12088 | ||
12089 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
12090 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
12091 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
12092 | goto found; |
12093 | ||
12094 | #ifdef EXTRA_DEBUG_ROOT1 | |
12095 | /* Try the first extra debug file root. */ | |
24841daa NC |
12096 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
12097 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 12098 | goto found; |
39f0547e NC |
12099 | |
12100 | /* Try the first extra debug file root. */ | |
12101 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
12102 | if (check_func (debug_filename, func_data)) | |
12103 | goto found; | |
dda8d76d NC |
12104 | #endif |
12105 | ||
12106 | #ifdef EXTRA_DEBUG_ROOT2 | |
12107 | /* Try the second extra debug file root. */ | |
24841daa NC |
12108 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
12109 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
12110 | goto found; |
12111 | #endif | |
12112 | ||
24841daa NC |
12113 | /* Then try in the global debug_filename directory. */ |
12114 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
12115 | dirlen = strlen (DEBUGDIR) - 1; |
12116 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
12117 | strcat (debug_filename, "/"); |
12118 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 12119 | |
24841daa | 12120 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
12121 | goto found; |
12122 | ||
301a9420 AM |
12123 | #if HAVE_LIBDEBUGINFOD |
12124 | { | |
12125 | char * tmp_filename; | |
12126 | ||
bed566bb NC |
12127 | if (use_debuginfod |
12128 | && debuginfod_fetch_separate_debug_info (xlink, | |
12129 | & tmp_filename, | |
12130 | file)) | |
301a9420 | 12131 | { |
175b9150 AM |
12132 | /* File successfully downloaded from server, replace |
12133 | debug_filename with the file's path. */ | |
12134 | free (debug_filename); | |
12135 | debug_filename = tmp_filename; | |
12136 | goto found; | |
301a9420 AM |
12137 | } |
12138 | } | |
12139 | #endif | |
12140 | ||
ecd65684 L |
12141 | if (do_debug_links) |
12142 | { | |
12143 | /* Failed to find the file. */ | |
12144 | warn (_("could not find separate debug file '%s'\n"), | |
12145 | separate_filename); | |
12146 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
12147 | |
12148 | #ifdef EXTRA_DEBUG_ROOT2 | |
ecd65684 L |
12149 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, |
12150 | separate_filename); | |
12151 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
12152 | #endif |
12153 | ||
12154 | #ifdef EXTRA_DEBUG_ROOT1 | |
ecd65684 L |
12155 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, |
12156 | canon_dir, separate_filename); | |
12157 | warn (_("tried: %s\n"), debug_filename); | |
39f0547e | 12158 | |
ecd65684 L |
12159 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, |
12160 | separate_filename); | |
12161 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
12162 | #endif |
12163 | ||
ecd65684 L |
12164 | sprintf (debug_filename, "%s.debug/%s", canon_dir, |
12165 | separate_filename); | |
12166 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 12167 | |
ecd65684 L |
12168 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
12169 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 12170 | |
ecd65684 L |
12171 | sprintf (debug_filename, ".debug/%s", separate_filename); |
12172 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 12173 | |
ecd65684 L |
12174 | sprintf (debug_filename, "%s", separate_filename); |
12175 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 12176 | |
301a9420 | 12177 | #if HAVE_LIBDEBUGINFOD |
bed566bb NC |
12178 | if (use_debuginfod) |
12179 | { | |
12180 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
301a9420 | 12181 | |
bed566bb NC |
12182 | if (urls == NULL) |
12183 | urls = ""; | |
12184 | ||
12185 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); | |
12186 | } | |
301a9420 | 12187 | #endif |
ecd65684 | 12188 | } |
301a9420 | 12189 | |
dda8d76d | 12190 | free (canon_dir); |
24841daa | 12191 | free (debug_filename); |
40eb8b92 | 12192 | free (canon_filename); |
dda8d76d NC |
12193 | return NULL; |
12194 | ||
12195 | found: | |
12196 | free (canon_dir); | |
12197 | ||
40eb8b92 L |
12198 | canon_debug_filename = lrealpath (debug_filename); |
12199 | self = strcmp (canon_debug_filename, canon_filename) == 0; | |
12200 | free (canon_filename); | |
12201 | free (canon_debug_filename); | |
12202 | if (self) | |
12203 | { | |
12204 | free (debug_filename); | |
12205 | return NULL; | |
12206 | } | |
12207 | ||
24841daa NC |
12208 | void * debug_handle; |
12209 | ||
dda8d76d | 12210 | /* Now open the file.... */ |
24841daa | 12211 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 12212 | { |
24841daa NC |
12213 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
12214 | free (debug_filename); | |
ce139cd5 | 12215 | return NULL; |
dda8d76d NC |
12216 | } |
12217 | ||
12218 | /* FIXME: We do not check to see if there are any other separate debug info | |
12219 | files that would also match. */ | |
12220 | ||
ca0e11aa NC |
12221 | if (do_debug_links) |
12222 | printf (_("\n%s: Found separate debug info file: %s\n"), main_filename, debug_filename); | |
24841daa | 12223 | add_separate_debug_file (debug_filename, debug_handle); |
dda8d76d | 12224 | |
24841daa | 12225 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 12226 | the structure returned by open_debug_file(). */ |
24841daa | 12227 | return debug_handle; |
dda8d76d NC |
12228 | } |
12229 | ||
d85bf2ba NC |
12230 | /* Attempt to load a separate dwarf object file. */ |
12231 | ||
12232 | static void * | |
24841daa | 12233 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 12234 | { |
24841daa NC |
12235 | char * separate_filename; |
12236 | void * separate_handle; | |
d85bf2ba | 12237 | |
d9d9d8ef TV |
12238 | if (IS_ABSOLUTE_PATH (name)) |
12239 | separate_filename = strdup (name); | |
12240 | else | |
12241 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
12242 | separate_filename = concat (dir, "/", name, NULL); | |
24841daa | 12243 | if (separate_filename == NULL) |
d85bf2ba NC |
12244 | { |
12245 | warn (_("Out of memory allocating dwo filename\n")); | |
12246 | return NULL; | |
12247 | } | |
12248 | ||
24841daa | 12249 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 12250 | { |
24841daa NC |
12251 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
12252 | free (separate_filename); | |
d85bf2ba NC |
12253 | return NULL; |
12254 | } | |
12255 | ||
12256 | /* FIXME: We should check the dwo_id. */ | |
12257 | ||
24841daa | 12258 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
bfbfa6e7 | 12259 | |
24841daa NC |
12260 | add_separate_debug_file (separate_filename, separate_handle); |
12261 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
12262 | return separate_handle; | |
d85bf2ba NC |
12263 | } |
12264 | ||
61ab1364 NC |
12265 | static void * |
12266 | try_build_id_prefix (const char * prefix, char * filename, const unsigned char * data, unsigned long id_len) | |
12267 | { | |
12268 | char * f = filename; | |
12269 | ||
dbc6a0e2 | 12270 | f += sprintf (f, "%s.build-id/%02x/", prefix, (unsigned) *data++); |
61ab1364 NC |
12271 | id_len --; |
12272 | while (id_len --) | |
12273 | f += sprintf (f, "%02x", (unsigned) *data++); | |
dbc6a0e2 | 12274 | strcpy (f, ".debug"); |
61ab1364 NC |
12275 | |
12276 | return open_debug_file (filename); | |
12277 | } | |
12278 | ||
12279 | /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */ | |
12280 | ||
12281 | static void | |
40c01d1b | 12282 | load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED, void * main_file) |
61ab1364 NC |
12283 | { |
12284 | if (! load_debug_section (note_gnu_build_id, main_file)) | |
12285 | return; /* No .note.gnu.build-id section. */ | |
12286 | ||
12287 | struct dwarf_section * section = & debug_displays [note_gnu_build_id].section; | |
12288 | if (section == NULL) | |
12289 | { | |
12290 | warn (_("Unable to load the .note.gnu.build-id section\n")); | |
12291 | return; | |
12292 | } | |
12293 | ||
12294 | if (section->start == NULL || section->size < 0x18) | |
12295 | { | |
12296 | warn (_(".note.gnu.build-id section is corrupt/empty\n")); | |
12297 | return; | |
12298 | } | |
12299 | ||
12300 | /* In theory we should extract the contents of the section into | |
12301 | a note structure and then check the fields. For now though | |
12302 | just use hard coded offsets instead: | |
175b9150 | 12303 | |
61ab1364 NC |
12304 | Field Bytes Contents |
12305 | NSize 0...3 4 | |
12306 | DSize 4...7 8+ | |
12307 | Type 8..11 3 (NT_GNU_BUILD_ID) | |
175b9150 | 12308 | Name 12.15 GNU\0 |
61ab1364 NC |
12309 | Data 16.... */ |
12310 | ||
12311 | /* FIXME: Check the name size, name and type fields. */ | |
12312 | ||
12313 | unsigned long build_id_size; | |
12314 | build_id_size = byte_get (section->start + 4, 4); | |
12315 | if (build_id_size < 8) | |
12316 | { | |
12317 | warn (_(".note.gnu.build-id data size is too small\n")); | |
12318 | return; | |
12319 | } | |
175b9150 | 12320 | |
61ab1364 NC |
12321 | if (build_id_size > (section->size - 16)) |
12322 | { | |
6af41860 | 12323 | warn (_(".note.gnu.build-id data size is too big\n")); |
61ab1364 NC |
12324 | return; |
12325 | } | |
12326 | ||
12327 | char * filename; | |
12328 | filename = xmalloc (strlen (".build-id/") | |
12329 | + build_id_size * 2 + 2 | |
12330 | + strlen (".debug") | |
12331 | /* The next string should be the same as the longest | |
12332 | name found in the prefixes[] array below. */ | |
88c66eca | 12333 | + strlen ("/usr/lib64/debug/usr/") |
61ab1364 NC |
12334 | + 1); |
12335 | void * handle; | |
12336 | ||
12337 | static const char * prefixes[] = | |
12338 | { | |
12339 | "", | |
12340 | ".debug/", | |
12341 | "/usr/lib/debug/", | |
12342 | "/usr/lib/debug/usr/", | |
12343 | "/usr/lib64/debug/", | |
88c66eca | 12344 | "/usr/lib64/debug/usr/" |
61ab1364 NC |
12345 | }; |
12346 | long unsigned int i; | |
12347 | ||
12348 | for (i = 0; i < ARRAY_SIZE (prefixes); i++) | |
12349 | { | |
12350 | handle = try_build_id_prefix (prefixes[i], filename, | |
12351 | section->start + 16, build_id_size); | |
12352 | if (handle != NULL) | |
12353 | break; | |
12354 | } | |
12355 | /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */ | |
12356 | if (handle == NULL) | |
12357 | { | |
12358 | /* Failed to find a debug file associated with the build-id. | |
12359 | This is not an error however, rather it just means that | |
12360 | the debug info has probably not been loaded on the system, | |
12361 | or that another method is being used to link to the debug | |
12362 | info. */ | |
12363 | free (filename); | |
12364 | return; | |
12365 | } | |
12366 | ||
61ab1364 NC |
12367 | add_separate_debug_file (filename, handle); |
12368 | } | |
12369 | ||
12370 | /* Try to load a debug file pointed to by the .debug_sup section. */ | |
12371 | ||
e38332c2 NC |
12372 | static void |
12373 | load_debug_sup_file (const char * main_filename, void * file) | |
12374 | { | |
12375 | if (! load_debug_section (debug_sup, file)) | |
12376 | return; /* No .debug_sup section. */ | |
12377 | ||
12378 | struct dwarf_section * section; | |
12379 | section = & debug_displays [debug_sup].section; | |
12380 | assert (section != NULL); | |
12381 | ||
12382 | if (section->start == NULL || section->size < 5) | |
12383 | { | |
12384 | warn (_(".debug_sup section is corrupt/empty\n")); | |
12385 | return; | |
12386 | } | |
12387 | ||
12388 | if (section->start[2] != 0) | |
12389 | return; /* This is a supplementary file. */ | |
12390 | ||
12391 | const char * filename = (const char *) section->start + 3; | |
12392 | if (strnlen (filename, section->size - 3) == section->size - 3) | |
12393 | { | |
12394 | warn (_("filename in .debug_sup section is corrupt\n")); | |
12395 | return; | |
12396 | } | |
12397 | ||
12398 | if (filename[0] != '/' && strchr (main_filename, '/')) | |
86b26b45 | 12399 | filename = xasprintf ("%.*s/%s", |
bfbfa6e7 NC |
12400 | (int) (strrchr (main_filename, '/') - main_filename), |
12401 | main_filename, | |
12402 | filename); | |
bfbfa6e7 | 12403 | else |
86b26b45 AM |
12404 | /* PR 27796: Make sure that we pass a filename that can be free'd to |
12405 | add_separate_debug_file(). */ | |
12406 | filename = xstrdup (filename); | |
e38332c2 | 12407 | |
bfbfa6e7 | 12408 | void * handle = open_debug_file (filename); |
e38332c2 NC |
12409 | if (handle == NULL) |
12410 | { | |
12411 | warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename); | |
bfbfa6e7 | 12412 | free ((void *) filename); |
e38332c2 NC |
12413 | return; |
12414 | } | |
12415 | ||
12416 | printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename, filename); | |
12417 | ||
12418 | /* FIXME: Compare the checksums, if present. */ | |
12419 | add_separate_debug_file (filename, handle); | |
12420 | } | |
12421 | ||
ce139cd5 NC |
12422 | /* Load a debuglink section and/or a debugaltlink section, if either are present. |
12423 | Recursively check the loaded files for more of these sections. | |
e38332c2 NC |
12424 | Also follow any links in .debug_sup sections. |
12425 | FIXME: Should also check for DWO_* entries in the newly loaded files. */ | |
ce139cd5 NC |
12426 | |
12427 | static void | |
12428 | check_for_and_load_links (void * file, const char * filename) | |
12429 | { | |
12430 | void * handle = NULL; | |
12431 | ||
12432 | if (load_debug_section (gnu_debugaltlink, file)) | |
12433 | { | |
12434 | Build_id_data build_id_data; | |
12435 | ||
12436 | handle = load_separate_debug_info (filename, | |
12437 | & debug_displays[gnu_debugaltlink].section, | |
12438 | parse_gnu_debugaltlink, | |
12439 | check_gnu_debugaltlink, | |
12440 | & build_id_data, | |
12441 | file); | |
12442 | if (handle) | |
12443 | { | |
12444 | assert (handle == first_separate_info->handle); | |
12445 | check_for_and_load_links (first_separate_info->handle, | |
12446 | first_separate_info->filename); | |
12447 | } | |
12448 | } | |
12449 | ||
12450 | if (load_debug_section (gnu_debuglink, file)) | |
12451 | { | |
12452 | unsigned long crc32; | |
12453 | ||
12454 | handle = load_separate_debug_info (filename, | |
12455 | & debug_displays[gnu_debuglink].section, | |
12456 | parse_gnu_debuglink, | |
12457 | check_gnu_debuglink, | |
12458 | & crc32, | |
12459 | file); | |
12460 | if (handle) | |
12461 | { | |
12462 | assert (handle == first_separate_info->handle); | |
12463 | check_for_and_load_links (first_separate_info->handle, | |
12464 | first_separate_info->filename); | |
12465 | } | |
12466 | } | |
e38332c2 NC |
12467 | |
12468 | load_debug_sup_file (filename, file); | |
61ab1364 NC |
12469 | |
12470 | load_build_id_debug_file (filename, file); | |
ce139cd5 NC |
12471 | } |
12472 | ||
24841daa NC |
12473 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
12474 | Returns TRUE if any were found, FALSE otherwise. | |
12475 | If TRUE is returned then the linked list starting at first_separate_info | |
12476 | will be populated with open file handles. */ | |
dda8d76d | 12477 | |
015dc7e1 | 12478 | bool |
24841daa | 12479 | load_separate_debug_files (void * file, const char * filename) |
dda8d76d | 12480 | { |
8de3a6e2 NC |
12481 | /* Skip this operation if we are not interested in debug links. */ |
12482 | if (! do_follow_links && ! do_debug_links) | |
015dc7e1 | 12483 | return false; |
8de3a6e2 | 12484 | |
24841daa | 12485 | /* See if there are any dwo links. */ |
d85bf2ba NC |
12486 | if (load_debug_section (str, file) |
12487 | && load_debug_section (abbrev, file) | |
12488 | && load_debug_section (info, file)) | |
12489 | { | |
ec41dd75 NC |
12490 | /* Load the .debug_addr section, if it exists. */ |
12491 | load_debug_section (debug_addr, file); | |
f18acc9c KB |
12492 | /* Load the .debug_str_offsets section, if it exists. */ |
12493 | load_debug_section (str_index, file); | |
4694a0e5 BK |
12494 | /* Load the .debug_loclists section, if it exists. */ |
12495 | load_debug_section (loclists, file); | |
12496 | /* Load the .debug_rnglists section, if it exists. */ | |
12497 | load_debug_section (rnglists, file); | |
ec41dd75 | 12498 | |
24841daa | 12499 | free_dwo_info (); |
d85bf2ba | 12500 | |
50ea0877 | 12501 | if (process_debug_info (& debug_displays[info].section, file, abbrev, |
015dc7e1 | 12502 | true, false)) |
d85bf2ba | 12503 | { |
015dc7e1 AM |
12504 | bool introduced = false; |
12505 | dwo_info *dwinfo; | |
12506 | const char *dir = NULL; | |
12507 | const char *id = NULL; | |
12508 | const char *name = NULL; | |
24841daa NC |
12509 | |
12510 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 12511 | { |
50ea0877 | 12512 | /* Accumulate NAME, DIR and ID fields. */ |
24841daa | 12513 | switch (dwinfo->type) |
d85bf2ba | 12514 | { |
24841daa | 12515 | case DWO_NAME: |
50ea0877 NC |
12516 | if (name != NULL) |
12517 | warn (_("Multiple DWO_NAMEs encountered for the same CU\n")); | |
12518 | name = dwinfo->value; | |
12519 | break; | |
12520 | ||
12521 | case DWO_DIR: | |
12522 | /* There can be multiple DW_AT_comp_dir entries in a CU, | |
12523 | so do not complain. */ | |
12524 | dir = dwinfo->value; | |
12525 | break; | |
12526 | ||
12527 | case DWO_ID: | |
12528 | if (id != NULL) | |
12529 | warn (_("multiple DWO_IDs encountered for the same CU\n")); | |
12530 | id = dwinfo->value; | |
12531 | break; | |
12532 | ||
12533 | default: | |
12534 | error (_("Unexpected DWO INFO type")); | |
12535 | break; | |
12536 | } | |
12537 | ||
12538 | /* If we have reached the end of our list, or we are changing | |
12539 | CUs, then display the information that we have accumulated | |
12540 | so far. */ | |
12541 | if (name != NULL | |
12542 | && (dwinfo->next == NULL | |
12543 | || dwinfo->next->cu_offset != dwinfo->cu_offset)) | |
12544 | { | |
24841daa NC |
12545 | if (do_debug_links) |
12546 | { | |
12547 | if (! introduced) | |
12548 | { | |
12549 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
12550 | debug_displays [info].section.uncompressed_name); | |
015dc7e1 | 12551 | introduced = true; |
24841daa | 12552 | } |
d85bf2ba | 12553 | |
50ea0877 | 12554 | printf (_(" Name: %s\n"), name); |
24841daa NC |
12555 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); |
12556 | if (id != NULL) | |
12557 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
40711542 | 12558 | else if (debug_information[0].dwarf_version != 5) |
50ea0877 | 12559 | printf (_(" ID: <not specified>\n")); |
24841daa NC |
12560 | printf ("\n\n"); |
12561 | } | |
12562 | ||
12563 | if (do_follow_links) | |
50ea0877 | 12564 | load_dwo_file (filename, name, dir, id); |
24841daa | 12565 | |
50ea0877 | 12566 | name = dir = id = NULL; |
24841daa | 12567 | } |
d85bf2ba NC |
12568 | } |
12569 | } | |
12570 | } | |
12571 | ||
dda8d76d | 12572 | if (! do_follow_links) |
8de3a6e2 NC |
12573 | /* The other debug links will be displayed by display_debug_links() |
12574 | so we do not need to do any further processing here. */ | |
015dc7e1 | 12575 | return false; |
dda8d76d NC |
12576 | |
12577 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
dda8d76d | 12578 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
d85bf2ba | 12579 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 12580 | |
ce139cd5 | 12581 | check_for_and_load_links (file, filename); |
24841daa | 12582 | if (first_separate_info != NULL) |
015dc7e1 | 12583 | return true; |
24841daa | 12584 | |
dda8d76d | 12585 | do_follow_links = 0; |
015dc7e1 | 12586 | return false; |
521d4b19 | 12587 | } |
dda8d76d | 12588 | |
19e6b90e L |
12589 | void |
12590 | free_debug_memory (void) | |
12591 | { | |
3f5e193b | 12592 | unsigned int i; |
19e6b90e | 12593 | |
bcd213b2 | 12594 | free_all_abbrevs (); |
19e6b90e | 12595 | |
288f0ba2 AM |
12596 | free (shndx_pool); |
12597 | shndx_pool = NULL; | |
12598 | shndx_pool_size = 0; | |
12599 | shndx_pool_used = 0; | |
12600 | free (cu_sets); | |
12601 | cu_sets = NULL; | |
12602 | cu_count = 0; | |
12603 | free (tu_sets); | |
12604 | tu_sets = NULL; | |
12605 | tu_count = 0; | |
12606 | ||
12607 | memset (level_type_signed, 0, sizeof level_type_signed); | |
12608 | cu_tu_indexes_read = -1; | |
12609 | ||
19e6b90e | 12610 | for (i = 0; i < max; i++) |
3f5e193b | 12611 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 12612 | |
cc86f28f | 12613 | if (debug_information != NULL) |
19e6b90e | 12614 | { |
82fcdb39 | 12615 | for (i = 0; i < alloc_num_debug_info_entries; i++) |
450da4bd | 12616 | free_debug_information (&debug_information[i]); |
19e6b90e L |
12617 | free (debug_information); |
12618 | debug_information = NULL; | |
82b1b41b | 12619 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 12620 | } |
dda8d76d | 12621 | |
24841daa NC |
12622 | separate_info * d; |
12623 | separate_info * next; | |
dda8d76d | 12624 | |
24841daa NC |
12625 | for (d = first_separate_info; d != NULL; d = next) |
12626 | { | |
12627 | close_debug_file (d->handle); | |
12628 | free ((void *) d->filename); | |
12629 | next = d->next; | |
12630 | free ((void *) d); | |
dda8d76d | 12631 | } |
24841daa | 12632 | first_separate_info = NULL; |
521d4b19 | 12633 | |
24841daa | 12634 | free_dwo_info (); |
19e6b90e L |
12635 | } |
12636 | ||
68f7e451 AM |
12637 | typedef struct |
12638 | { | |
12639 | const char letter; | |
12640 | const char *option; | |
12641 | int *variable; | |
12642 | int val; | |
12643 | } debug_dump_long_opts; | |
12644 | ||
12645 | static const debug_dump_long_opts debug_option_table[] = | |
12646 | { | |
12647 | { 'A', "addr", &do_debug_addr, 1 }, | |
12648 | { 'a', "abbrev", &do_debug_abbrevs, 1 }, | |
12649 | { 'c', "cu_index", &do_debug_cu_index, 1 }, | |
12650 | #ifdef HAVE_LIBDEBUGINFOD | |
12651 | { 'D', "use-debuginfod", &use_debuginfod, 1 }, | |
12652 | { 'E', "do-not-use-debuginfod", &use_debuginfod, 0 }, | |
12653 | #endif | |
12654 | { 'F', "frames-interp", &do_debug_frames_interp, 1 }, | |
12655 | { 'f', "frames", &do_debug_frames, 1 }, | |
12656 | { 'g', "gdb_index", &do_gdb_index, 1 }, | |
12657 | { 'i', "info", &do_debug_info, 1 }, | |
12658 | { 'K', "follow-links", &do_follow_links, 1 }, | |
12659 | { 'k', "links", &do_debug_links, 1 }, | |
12660 | { 'L', "decodedline", &do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
12661 | { 'l', "rawline", &do_debug_lines, FLAG_DEBUG_LINES_RAW }, | |
12662 | /* For compatibility with earlier versions of readelf. */ | |
12663 | { 'l', "line", &do_debug_lines, FLAG_DEBUG_LINES_RAW }, | |
12664 | { 'm', "macro", &do_debug_macinfo, 1 }, | |
12665 | { 'N', "no-follow-links", &do_follow_links, 0 }, | |
12666 | { 'O', "str-offsets", &do_debug_str_offsets, 1 }, | |
12667 | { 'o', "loc", &do_debug_loc, 1 }, | |
12668 | { 'p', "pubnames", &do_debug_pubnames, 1 }, | |
12669 | { 'R', "Ranges", &do_debug_ranges, 1 }, | |
12670 | { 'r', "aranges", &do_debug_aranges, 1 }, | |
12671 | /* For compatibility with earlier versions of readelf. */ | |
12672 | { 'r', "ranges", &do_debug_aranges, 1 }, | |
12673 | { 's', "str", &do_debug_str, 1 }, | |
12674 | { 'T', "trace_aranges", &do_trace_aranges, 1 }, | |
12675 | { 't', "pubtypes", &do_debug_pubtypes, 1 }, | |
12676 | { 'U', "trace_info", &do_trace_info, 1 }, | |
12677 | { 'u', "trace_abbrev", &do_trace_abbrevs, 1 }, | |
12678 | { 0, NULL, NULL, 0 } | |
12679 | }; | |
12680 | ||
94585d6d NC |
12681 | /* Enable display of specific DWARF sections as determined by the comma |
12682 | separated strings in NAMES. Returns non-zero if any displaying was | |
12683 | enabled. */ | |
12684 | ||
12685 | int | |
4cb93e3b TG |
12686 | dwarf_select_sections_by_names (const char *names) |
12687 | { | |
4cb93e3b | 12688 | const char *p; |
94585d6d | 12689 | int result = 0; |
467c65bc | 12690 | |
4cb93e3b TG |
12691 | p = names; |
12692 | while (*p) | |
12693 | { | |
68f7e451 | 12694 | const debug_dump_long_opts *entry; |
467c65bc | 12695 | |
68f7e451 | 12696 | for (entry = debug_option_table; entry->option; entry++) |
4cb93e3b TG |
12697 | { |
12698 | size_t len = strlen (entry->option); | |
467c65bc | 12699 | |
4cb93e3b TG |
12700 | if (strncmp (p, entry->option, len) == 0 |
12701 | && (p[len] == ',' || p[len] == '\0')) | |
12702 | { | |
aa40d66b NC |
12703 | if (entry->val == 0) |
12704 | * entry->variable = 0; | |
12705 | else | |
12706 | * entry->variable = entry->val; | |
94585d6d | 12707 | result |= entry->val; |
467c65bc | 12708 | |
4cb93e3b TG |
12709 | p += len; |
12710 | break; | |
12711 | } | |
12712 | } | |
467c65bc | 12713 | |
4cb93e3b TG |
12714 | if (entry->option == NULL) |
12715 | { | |
12716 | warn (_("Unrecognized debug option '%s'\n"), p); | |
12717 | p = strchr (p, ','); | |
12718 | if (p == NULL) | |
12719 | break; | |
12720 | } | |
467c65bc | 12721 | |
4cb93e3b TG |
12722 | if (*p == ',') |
12723 | p++; | |
12724 | } | |
94585d6d | 12725 | |
68f7e451 AM |
12726 | /* The --debug-dump=frames-interp option also enables the |
12727 | --debug-dump=frames option. */ | |
12728 | if (do_debug_frames_interp) | |
12729 | do_debug_frames = 1; | |
12730 | ||
94585d6d | 12731 | return result; |
4cb93e3b TG |
12732 | } |
12733 | ||
94585d6d NC |
12734 | /* Enable display of specific DWARF sections as determined by the characters |
12735 | in LETTERS. Returns non-zero if any displaying was enabled. */ | |
12736 | ||
12737 | int | |
4cb93e3b TG |
12738 | dwarf_select_sections_by_letters (const char *letters) |
12739 | { | |
94585d6d NC |
12740 | int result = 0; |
12741 | ||
12742 | while (* letters) | |
12743 | { | |
68f7e451 | 12744 | const debug_dump_long_opts *entry; |
94585d6d | 12745 | |
68f7e451 | 12746 | for (entry = debug_option_table; entry->letter; entry++) |
94585d6d NC |
12747 | { |
12748 | if (entry->letter == * letters) | |
12749 | { | |
aa40d66b NC |
12750 | if (entry->val == 0) |
12751 | * entry->variable = 0; | |
12752 | else | |
12753 | * entry->variable |= entry->val; | |
94585d6d | 12754 | result |= entry->val; |
68f7e451 | 12755 | break; |
94585d6d NC |
12756 | } |
12757 | } | |
12758 | ||
12759 | if (entry->letter == 0) | |
12760 | warn (_("Unrecognized debug letter option '%c'\n"), * letters); | |
12761 | ||
12762 | letters ++; | |
12763 | } | |
12764 | ||
68f7e451 AM |
12765 | /* The --debug-dump=frames-interp option also enables the |
12766 | --debug-dump=frames option. */ | |
12767 | if (do_debug_frames_interp) | |
12768 | do_debug_frames = 1; | |
12769 | ||
94585d6d | 12770 | return result; |
4cb93e3b TG |
12771 | } |
12772 | ||
12773 | void | |
12774 | dwarf_select_sections_all (void) | |
12775 | { | |
12776 | do_debug_info = 1; | |
12777 | do_debug_abbrevs = 1; | |
12778 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
12779 | do_debug_pubnames = 1; | |
f9f0e732 | 12780 | do_debug_pubtypes = 1; |
4cb93e3b TG |
12781 | do_debug_aranges = 1; |
12782 | do_debug_ranges = 1; | |
12783 | do_debug_frames = 1; | |
12784 | do_debug_macinfo = 1; | |
12785 | do_debug_str = 1; | |
12786 | do_debug_loc = 1; | |
5bbdf3d5 | 12787 | do_gdb_index = 1; |
6f875884 TG |
12788 | do_trace_info = 1; |
12789 | do_trace_abbrevs = 1; | |
12790 | do_trace_aranges = 1; | |
657d0d47 CC |
12791 | do_debug_addr = 1; |
12792 | do_debug_cu_index = 1; | |
dda8d76d NC |
12793 | do_follow_links = 1; |
12794 | do_debug_links = 1; | |
e4b7104b | 12795 | do_debug_str_offsets = 1; |
4cb93e3b TG |
12796 | } |
12797 | ||
208599d9 AM |
12798 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0 |
12799 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0 | |
dda8d76d NC |
12800 | |
12801 | /* N.B. The order here must match the order in section_display_enum. */ | |
12802 | ||
19e6b90e L |
12803 | struct dwarf_section_display debug_displays[] = |
12804 | { | |
51d29b8c CC |
12805 | { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, |
12806 | { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, true }, | |
12807 | { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, | |
12808 | { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev)}, display_debug_info, &do_debug_info, true }, | |
12809 | { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, | |
12810 | { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, false }, | |
12811 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, false }, | |
12812 | { { ".eh_frame", "", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, | |
1878f44b | 12813 | { { ".eh_frame_hdr", "", "", NO_ABBREVS }, display_eh_frame_hdr, &do_debug_frames, true }, |
51d29b8c CC |
12814 | { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, |
12815 | { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, | |
12816 | { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
12817 | { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
12818 | { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
12819 | { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
4694a0e5 | 12820 | { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, |
51d29b8c CC |
12821 | { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, false }, |
12822 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, false }, | |
12823 | { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
12824 | { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
4694a0e5 | 12825 | { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, |
51d29b8c CC |
12826 | { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, |
12827 | { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
12828 | { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev) }, display_debug_types, &do_debug_info, true }, | |
12829 | { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
12830 | { { ".gdb_index", "", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, false }, | |
12831 | { { ".debug_names", "", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, false }, | |
12832 | { { ".trace_info", "", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, true }, | |
12833 | { { ".trace_abbrev", "", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, false }, | |
12834 | { { ".trace_aranges", "", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, false }, | |
12835 | { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, true }, | |
12836 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, | |
12837 | { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, true }, | |
12838 | { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, | |
12839 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
12840 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, | |
12841 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, | |
12842 | { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS }, display_debug_str, &do_debug_str, true }, | |
12843 | { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, | |
12844 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, | |
12845 | { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS }, display_debug_addr, &do_debug_addr, true }, | |
12846 | { { ".debug_cu_index", "", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, | |
12847 | { { ".debug_tu_index", "", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, | |
12848 | { { ".gnu_debuglink", "", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, | |
12849 | { { ".gnu_debugaltlink", "", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, | |
12850 | { { ".debug_sup", "", "", NO_ABBREVS }, display_debug_sup, &do_debug_links, false }, | |
dda8d76d NC |
12851 | /* Separate debug info files can containt their own .debug_str section, |
12852 | and this might be in *addition* to a .debug_str section already present | |
51d29b8c | 12853 | in the main file. Hence we need to have two entries for .debug_str. */ |
61ab1364 NC |
12854 | { { ".debug_str", ".zdebug_str", "", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, |
12855 | { { ".note.gnu.build-id", "", "", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
19e6b90e | 12856 | }; |
b451e98a JK |
12857 | |
12858 | /* A static assertion. */ | |
12859 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |