Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
250d07de | 2 | Copyright (C) 2005-2021 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 L |
56 | static int have_frame_base; |
57 | static int need_base_address; | |
58 | ||
19e6b90e | 59 | static unsigned int num_debug_info_entries = 0; |
82b1b41b | 60 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 61 | static debug_info *debug_information = NULL; |
cc86f28f NC |
62 | /* Special value for num_debug_info_entries to indicate |
63 | that the .debug_info section could not be loaded/parsed. */ | |
64 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 65 | |
24841daa NC |
66 | /* A .debug_info section can contain multiple links to separate |
67 | DWO object files. We use these structures to record these links. */ | |
68 | typedef enum dwo_type | |
69 | { | |
70 | DWO_NAME, | |
71 | DWO_DIR, | |
72 | DWO_ID | |
73 | } dwo_type; | |
74 | ||
75 | typedef struct dwo_info | |
76 | { | |
77 | dwo_type type; | |
78 | const char * value; | |
50ea0877 | 79 | dwarf_vma cu_offset; |
24841daa NC |
80 | struct dwo_info * next; |
81 | } dwo_info; | |
82 | ||
015dc7e1 AM |
83 | static dwo_info *first_dwo_info = NULL; |
84 | static bool need_dwo_info; | |
24841daa NC |
85 | |
86 | separate_info * first_separate_info = NULL; | |
d85bf2ba | 87 | |
77ef8654 | 88 | unsigned int eh_addr_size; |
19e6b90e L |
89 | |
90 | int do_debug_info; | |
91 | int do_debug_abbrevs; | |
92 | int do_debug_lines; | |
93 | int do_debug_pubnames; | |
f9f0e732 | 94 | int do_debug_pubtypes; |
19e6b90e L |
95 | int do_debug_aranges; |
96 | int do_debug_ranges; | |
97 | int do_debug_frames; | |
98 | int do_debug_frames_interp; | |
99 | int do_debug_macinfo; | |
100 | int do_debug_str; | |
e4b7104b | 101 | int do_debug_str_offsets; |
19e6b90e | 102 | int do_debug_loc; |
5bbdf3d5 | 103 | int do_gdb_index; |
6f875884 TG |
104 | int do_trace_info; |
105 | int do_trace_abbrevs; | |
106 | int do_trace_aranges; | |
657d0d47 CC |
107 | int do_debug_addr; |
108 | int do_debug_cu_index; | |
a262ae96 | 109 | int do_wide; |
dda8d76d | 110 | int do_debug_links; |
c46b7066 | 111 | int do_follow_links = DEFAULT_FOR_FOLLOW_LINKS; |
015dc7e1 | 112 | bool do_checks; |
19e6b90e | 113 | |
fd2f0033 TT |
114 | int dwarf_cutoff_level = -1; |
115 | unsigned long dwarf_start_die; | |
116 | ||
4723351a CC |
117 | int dwarf_check = 0; |
118 | ||
9f272209 AO |
119 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
120 | testing whether e.g. a locview list is present. */ | |
121 | static const dwarf_vma vm1 = -1; | |
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 | { | |
ec1b0fbb NC |
140 | uint64_t signature; |
141 | dwarf_vma 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 | ||
175 | static dwarf_vma | |
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); |
bad62cf5 | 183 | dwarf_vma 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 | ||
87b9f255 | 220 | #if SIZEOF_LONG_LONG > SIZEOF_LONG |
4c219c2e AM |
221 | # ifndef __MINGW32__ |
222 | # define DWARF_VMA_FMT "ll" | |
223 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
224 | # else | |
225 | # define DWARF_VMA_FMT "I64" | |
226 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
227 | # endif | |
2e14fae2 | 228 | #else |
4c219c2e AM |
229 | # define DWARF_VMA_FMT "l" |
230 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
231 | #endif |
232 | ||
bf5117e3 NC |
233 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
234 | buffer containing the converted VALUE. The value is converted according | |
235 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
236 | it specifies the maximum number of bytes to be displayed in the converted | |
237 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 238 | |
47704ddf | 239 | static const char * |
bf5117e3 | 240 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
241 | { |
242 | /* As dwarf_vmatoa is used more then once in a printf call | |
243 | for output, we are cycling through an fixed array of pointers | |
244 | for return address. */ | |
245 | static int buf_pos = 0; | |
467c65bc NC |
246 | static struct dwarf_vmatoa_buf |
247 | { | |
47704ddf KT |
248 | char place[64]; |
249 | } buf[16]; | |
47704ddf KT |
250 | char *ret; |
251 | ||
47704ddf | 252 | ret = buf[buf_pos++].place; |
467c65bc | 253 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 254 | |
bf5117e3 NC |
255 | if (num_bytes) |
256 | { | |
222c2bf0 | 257 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
258 | integer value, so we print the full value into a buffer and then select |
259 | the precision we need. */ | |
260 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
261 | if (num_bytes > 8) | |
262 | num_bytes = 8; | |
263 | return ret + (16 - 2 * num_bytes); | |
264 | } | |
265 | else | |
266 | { | |
267 | char fmt[32]; | |
268 | ||
0bae9e9e NC |
269 | if (fmtch) |
270 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
271 | else | |
272 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
273 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
274 | return ret; | |
275 | } | |
276 | } | |
47704ddf | 277 | |
bf5117e3 NC |
278 | static inline const char * |
279 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
280 | { | |
281 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
282 | } | |
283 | ||
284 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
285 | hexadecimal format, followed by a space. The length of the VALUE (and | |
286 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
287 | ||
288 | static void | |
289 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
290 | { | |
291 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
292 | } |
293 | ||
9f272209 AO |
294 | /* Print a view number in hexadecimal value, with the same width |
295 | print_dwarf_vma would have printed it with the same num_bytes. | |
296 | Print blanks for zero view, unless force is nonzero. */ | |
297 | ||
298 | static void | |
299 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
300 | { | |
301 | int len; | |
302 | if (!num_bytes) | |
303 | len = 4; | |
304 | else | |
305 | len = num_bytes * 2; | |
306 | ||
307 | assert (value == (unsigned long) value); | |
308 | if (value || force) | |
309 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
310 | else | |
311 | printf ("%*s", len + 1, ""); | |
312 | } | |
313 | ||
f6f0e17b NC |
314 | /* Read in a LEB128 encoded value starting at address DATA. |
315 | If SIGN is true, return a signed LEB128 value. | |
316 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
b9b204b3 | 317 | If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the |
cd30bcef AM |
318 | terminating byte was not found and with bit 1 set if the value |
319 | overflows a dwarf_vma. | |
f6f0e17b NC |
320 | No bytes will be read at address END or beyond. */ |
321 | ||
467c65bc | 322 | dwarf_vma |
f6f0e17b | 323 | read_leb128 (unsigned char *data, |
cd30bcef | 324 | const unsigned char *const end, |
015dc7e1 | 325 | bool sign, |
cd30bcef AM |
326 | unsigned int *length_return, |
327 | int *status_return) | |
19e6b90e | 328 | { |
467c65bc | 329 | dwarf_vma result = 0; |
19e6b90e L |
330 | unsigned int num_read = 0; |
331 | unsigned int shift = 0; | |
cd30bcef | 332 | int status = 1; |
19e6b90e | 333 | |
f6f0e17b | 334 | while (data < end) |
19e6b90e | 335 | { |
cd30bcef | 336 | unsigned char byte = *data++; |
b9b204b3 | 337 | unsigned char lost, mask; |
08d7da7d | 338 | |
19e6b90e L |
339 | num_read++; |
340 | ||
b9b204b3 | 341 | if (shift < CHAR_BIT * sizeof (result)) |
cd30bcef | 342 | { |
b9b204b3 AM |
343 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
344 | /* These bits overflowed. */ | |
345 | lost = byte ^ (result >> shift); | |
346 | /* And this is the mask of possible overflow bits. */ | |
347 | mask = 0x7f ^ ((dwarf_vma) 0x7f << shift >> shift); | |
cd30bcef AM |
348 | shift += 7; |
349 | } | |
b9b204b3 | 350 | else |
08d7da7d | 351 | { |
b9b204b3 AM |
352 | lost = byte; |
353 | mask = 0x7f; | |
08d7da7d | 354 | } |
b9b204b3 AM |
355 | if ((lost & mask) != (sign && (dwarf_signed_vma) result < 0 ? mask : 0)) |
356 | status |= 2; | |
19e6b90e | 357 | |
b9b204b3 | 358 | if ((byte & 0x80) == 0) |
cd30bcef AM |
359 | { |
360 | status &= ~1; | |
b9b204b3 | 361 | if (sign && shift < CHAR_BIT * sizeof (result) && (byte & 0x40)) |
cd30bcef AM |
362 | result |= -((dwarf_vma) 1 << shift); |
363 | break; | |
364 | } | |
19e6b90e | 365 | } |
19e6b90e L |
366 | |
367 | if (length_return != NULL) | |
368 | *length_return = num_read; | |
cd30bcef AM |
369 | if (status_return != NULL) |
370 | *status_return = status; | |
19e6b90e L |
371 | |
372 | return result; | |
373 | } | |
374 | ||
6d1ad6f7 AM |
375 | /* Read AMOUNT bytes from PTR and store them in VAL. |
376 | Checks to make sure that the read will not reach or pass END. | |
377 | FUNC chooses whether the value read is unsigned or signed, and may | |
378 | be either byte_get or byte_get_signed. If INC is true, PTR is | |
379 | incremented after reading the value. | |
380 | This macro cannot protect against PTR values derived from user input. | |
381 | The C standard sections 6.5.6 and 6.5.8 say attempts to do so using | |
382 | pointers is undefined behaviour. */ | |
383 | #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \ | |
384 | do \ | |
385 | { \ | |
386 | size_t amount = (AMOUNT); \ | |
387 | if (sizeof (VAL) < amount) \ | |
388 | { \ | |
d3a49aa8 AM |
389 | error (ngettext ("internal error: attempt to read %d byte " \ |
390 | "of data in to %d sized variable", \ | |
391 | "internal error: attempt to read %d bytes " \ | |
392 | "of data in to %d sized variable", \ | |
393 | amount), \ | |
6d1ad6f7 AM |
394 | (int) amount, (int) sizeof (VAL)); \ |
395 | amount = sizeof (VAL); \ | |
396 | } \ | |
ebb17864 AM |
397 | if (ENABLE_CHECKING) \ |
398 | assert ((PTR) <= (END)); \ | |
6d1ad6f7 | 399 | size_t avail = (END) - (PTR); \ |
ebb17864 AM |
400 | if ((PTR) > (END)) \ |
401 | avail = 0; \ | |
6d1ad6f7 AM |
402 | if (amount > avail) \ |
403 | amount = avail; \ | |
404 | if (amount == 0) \ | |
405 | (VAL) = 0; \ | |
406 | else \ | |
407 | (VAL) = (FUNC) ((PTR), amount); \ | |
408 | if (INC) \ | |
409 | (PTR) += amount; \ | |
410 | } \ | |
0c588247 NC |
411 | while (0) |
412 | ||
6d1ad6f7 AM |
413 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
414 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false) | |
415 | ||
0c588247 | 416 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
6d1ad6f7 | 417 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true) |
0c588247 NC |
418 | |
419 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ | |
6d1ad6f7 | 420 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false) |
0c588247 NC |
421 | |
422 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ | |
6d1ad6f7 | 423 | SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true) |
0c588247 | 424 | |
19e6b90e L |
425 | typedef struct State_Machine_Registers |
426 | { | |
467c65bc | 427 | dwarf_vma address; |
ba8826a8 | 428 | unsigned int view; |
19e6b90e L |
429 | unsigned int file; |
430 | unsigned int line; | |
431 | unsigned int column; | |
432 | int is_stmt; | |
433 | int basic_block; | |
a233b20c JJ |
434 | unsigned char op_index; |
435 | unsigned char end_sequence; | |
ba8826a8 AO |
436 | /* This variable hold the number of the last entry seen |
437 | in the File Table. */ | |
19e6b90e L |
438 | unsigned int last_file_entry; |
439 | } SMR; | |
440 | ||
441 | static SMR state_machine_regs; | |
442 | ||
443 | static void | |
444 | reset_state_machine (int is_stmt) | |
445 | { | |
446 | state_machine_regs.address = 0; | |
ba8826a8 | 447 | state_machine_regs.view = 0; |
a233b20c | 448 | state_machine_regs.op_index = 0; |
19e6b90e L |
449 | state_machine_regs.file = 1; |
450 | state_machine_regs.line = 1; | |
451 | state_machine_regs.column = 0; | |
452 | state_machine_regs.is_stmt = is_stmt; | |
453 | state_machine_regs.basic_block = 0; | |
454 | state_machine_regs.end_sequence = 0; | |
455 | state_machine_regs.last_file_entry = 0; | |
456 | } | |
457 | ||
458 | /* Handled an extend line op. | |
459 | Returns the number of bytes read. */ | |
460 | ||
cd30bcef | 461 | static size_t |
f6f0e17b NC |
462 | process_extended_line_op (unsigned char * data, |
463 | int is_stmt, | |
464 | unsigned char * end) | |
19e6b90e L |
465 | { |
466 | unsigned char op_code; | |
cd30bcef | 467 | size_t len, header_len; |
19e6b90e | 468 | unsigned char *name; |
143a3db0 | 469 | unsigned char *orig_data = data; |
cd30bcef | 470 | dwarf_vma adr, val; |
19e6b90e | 471 | |
cd30bcef AM |
472 | READ_ULEB (len, data, end); |
473 | header_len = data - orig_data; | |
19e6b90e | 474 | |
55b26492 | 475 | if (len == 0 || data >= end || len > (size_t) (end - data)) |
19e6b90e | 476 | { |
f41e4712 | 477 | warn (_("Badly formed extended line op encountered!\n")); |
cd30bcef | 478 | return header_len; |
19e6b90e L |
479 | } |
480 | ||
19e6b90e L |
481 | op_code = *data++; |
482 | ||
483 | printf (_(" Extended opcode %d: "), op_code); | |
484 | ||
485 | switch (op_code) | |
486 | { | |
487 | case DW_LNE_end_sequence: | |
488 | printf (_("End of Sequence\n\n")); | |
489 | reset_state_machine (is_stmt); | |
490 | break; | |
491 | ||
492 | case DW_LNE_set_address: | |
6937bb54 | 493 | /* PR 17512: file: 002-100480-0.004. */ |
cd30bcef | 494 | if (len - 1 > 8) |
77ef8654 | 495 | { |
cd30bcef AM |
496 | warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"), |
497 | (unsigned long) len - 1); | |
77ef8654 NC |
498 | adr = 0; |
499 | } | |
500 | else | |
cd30bcef | 501 | SAFE_BYTE_GET (adr, data, len - 1, end); |
47704ddf | 502 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 503 | state_machine_regs.address = adr; |
ba8826a8 | 504 | state_machine_regs.view = 0; |
a233b20c | 505 | state_machine_regs.op_index = 0; |
19e6b90e L |
506 | break; |
507 | ||
508 | case DW_LNE_define_file: | |
143a3db0 | 509 | printf (_("define new File Table entry\n")); |
19e6b90e | 510 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 511 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 512 | |
d949ff56 NC |
513 | { |
514 | size_t l; | |
515 | ||
516 | name = data; | |
517 | l = strnlen ((char *) data, end - data); | |
a7077ce7 AM |
518 | data += l; |
519 | if (data < end) | |
520 | data++; | |
cd30bcef AM |
521 | READ_ULEB (val, data, end); |
522 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
523 | READ_ULEB (val, data, end); | |
524 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
525 | READ_ULEB (val, data, end); | |
526 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
d949ff56 NC |
527 | printf ("%.*s\n\n", (int) l, name); |
528 | } | |
f6f0e17b | 529 | |
55b26492 | 530 | if (((size_t) (data - orig_data) != len + header_len) || data >= end) |
b4eb7656 | 531 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
532 | break; |
533 | ||
ed4a4bdf | 534 | case DW_LNE_set_discriminator: |
cd30bcef AM |
535 | READ_ULEB (val, data, end); |
536 | printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val)); | |
ed4a4bdf CC |
537 | break; |
538 | ||
e2a0d921 NC |
539 | /* HP extensions. */ |
540 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 541 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
542 | break; |
543 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 544 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
545 | break; |
546 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 547 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
548 | break; |
549 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 550 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
551 | break; |
552 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 553 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
554 | break; |
555 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 556 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
557 | break; |
558 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 559 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
560 | break; |
561 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 562 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
563 | break; |
564 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 565 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
566 | break; |
567 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 568 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 569 | break; |
43294ab7 TG |
570 | case DW_LNE_HP_source_file_correlation: |
571 | { | |
cd30bcef | 572 | unsigned char *edata = data + len - 1; |
b4eb7656 AM |
573 | |
574 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
575 | ||
576 | while (data < edata) | |
577 | { | |
578 | unsigned int opc; | |
579 | ||
cd30bcef | 580 | READ_ULEB (opc, data, edata); |
b4eb7656 AM |
581 | |
582 | switch (opc) | |
583 | { | |
584 | case DW_LNE_HP_SFC_formfeed: | |
585 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
586 | break; | |
587 | case DW_LNE_HP_SFC_set_listing_line: | |
cd30bcef | 588 | READ_ULEB (val, data, edata); |
b4eb7656 | 589 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", |
cd30bcef | 590 | dwarf_vmatoa ("u", val)); |
b4eb7656 AM |
591 | break; |
592 | case DW_LNE_HP_SFC_associate: | |
593 | printf (" DW_LNE_HP_SFC_associate "); | |
cd30bcef AM |
594 | READ_ULEB (val, data, edata); |
595 | printf ("(%s", dwarf_vmatoa ("u", val)); | |
596 | READ_ULEB (val, data, edata); | |
597 | printf (",%s", dwarf_vmatoa ("u", val)); | |
598 | READ_ULEB (val, data, edata); | |
599 | printf (",%s)\n", dwarf_vmatoa ("u", val)); | |
b4eb7656 AM |
600 | break; |
601 | default: | |
602 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
603 | data = edata; | |
604 | break; | |
605 | } | |
606 | } | |
43294ab7 TG |
607 | } |
608 | break; | |
cecf136e | 609 | |
19e6b90e | 610 | default: |
7e665af3 | 611 | { |
cd30bcef | 612 | unsigned int rlen = len - 1; |
b4eb7656 AM |
613 | |
614 | if (op_code >= DW_LNE_lo_user | |
615 | /* The test against DW_LNW_hi_user is redundant due to | |
616 | the limited range of the unsigned char data type used | |
617 | for op_code. */ | |
618 | /*&& op_code <= DW_LNE_hi_user*/) | |
619 | printf (_("user defined: ")); | |
620 | else | |
621 | printf (_("UNKNOWN: ")); | |
622 | printf (_("length %d ["), rlen); | |
623 | for (; rlen; rlen--) | |
624 | printf (" %02x", *data++); | |
625 | printf ("]\n"); | |
7e665af3 | 626 | } |
19e6b90e L |
627 | break; |
628 | } | |
629 | ||
cd30bcef | 630 | return len + header_len; |
19e6b90e L |
631 | } |
632 | ||
0c588247 | 633 | static const unsigned char * |
467c65bc | 634 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
635 | { |
636 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 637 | const unsigned char * ret; |
19e6b90e L |
638 | |
639 | if (section->start == NULL) | |
0c588247 | 640 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 641 | |
d949ff56 | 642 | if (offset >= section->size) |
19e6b90e | 643 | { |
d296b736 | 644 | warn (_("DW_FORM_strp offset too big: 0x%s\n"), |
467c65bc | 645 | dwarf_vmatoa ("x", offset)); |
0c588247 | 646 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
647 | } |
648 | ||
d949ff56 NC |
649 | ret = section->start + offset; |
650 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
651 | NUL byte. Since our caller is expecting to receive a well formed C | |
652 | string we test for the lack of a terminating byte here. */ | |
653 | if (strnlen ((const char *) ret, section->size - offset) | |
654 | == section->size - offset) | |
655 | ret = (const unsigned char *) | |
656 | _("<no NUL byte at end of .debug_str section>"); | |
657 | ||
521d4b19 | 658 | return ret; |
19e6b90e L |
659 | } |
660 | ||
77145576 JK |
661 | static const unsigned char * |
662 | fetch_indirect_line_string (dwarf_vma offset) | |
663 | { | |
664 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 665 | const unsigned char * ret; |
77145576 JK |
666 | |
667 | if (section->start == NULL) | |
668 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
669 | ||
d949ff56 | 670 | if (offset >= section->size) |
77145576 | 671 | { |
d296b736 | 672 | warn (_("DW_FORM_line_strp offset too big: 0x%s\n"), |
77145576 JK |
673 | dwarf_vmatoa ("x", offset)); |
674 | return (const unsigned char *) _("<offset is too big>"); | |
675 | } | |
676 | ||
d949ff56 NC |
677 | ret = section->start + offset; |
678 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
679 | with a NUL byte. Since our caller is expecting to receive a well formed | |
680 | C string we test for the lack of a terminating byte here. */ | |
681 | if (strnlen ((const char *) ret, section->size - offset) | |
682 | == section->size - offset) | |
683 | ret = (const unsigned char *) | |
684 | _("<no NUL byte at end of .debug_line_str section>"); | |
685 | ||
686 | return ret; | |
77145576 JK |
687 | } |
688 | ||
4723351a | 689 | static const char * |
341f9135 | 690 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
015dc7e1 | 691 | dwarf_vma offset_size, bool dwo) |
4723351a CC |
692 | { |
693 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
694 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
695 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
696 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
e4b7104b | 697 | dwarf_vma index_offset; |
4723351a | 698 | dwarf_vma str_offset; |
d949ff56 | 699 | const char * ret; |
e4b7104b | 700 | unsigned char *curr = index_section->start; |
5ab39075 | 701 | unsigned char *end = curr + index_section->size; |
e4b7104b | 702 | dwarf_vma length; |
4723351a CC |
703 | |
704 | if (index_section->start == NULL) | |
705 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
706 | : _("<no .debug_str_offsets section>")); | |
707 | ||
e4b7104b NC |
708 | if (str_section->start == NULL) |
709 | return (dwo ? _("<no .debug_str.dwo section>") | |
710 | : _("<no .debug_str section>")); | |
711 | ||
712 | /* FIXME: We should cache the length... */ | |
713 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
714 | if (length == 0xffffffff) | |
715 | { | |
716 | if (offset_size != 8) | |
39f381cb | 717 | warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size)); |
e4b7104b NC |
718 | SAFE_BYTE_GET_AND_INC (length, curr, 8, end); |
719 | } | |
720 | else if (offset_size != 4) | |
721 | { | |
39f381cb | 722 | warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size)); |
e4b7104b NC |
723 | } |
724 | ||
39f381cb | 725 | if (length == 0) |
e4b7104b | 726 | { |
39f381cb NC |
727 | /* This is probably an old style .debug_str_offset section which |
728 | just contains offsets and no header (and the first offset is 0). */ | |
729 | curr = index_section->start; | |
730 | length = index_section->size; | |
731 | } | |
732 | else | |
733 | { | |
734 | /* Skip the version and padding bytes. | |
735 | We assume that they are correct. */ | |
5ab39075 AM |
736 | if (end - curr >= 4) |
737 | curr += 4; | |
738 | else | |
739 | curr = end; | |
740 | if (length >= 4) | |
741 | length -= 4; | |
742 | else | |
743 | length = 0; | |
744 | ||
745 | if (this_set != NULL | |
746 | && this_set->section_sizes[DW_SECT_STR_OFFSETS] < length) | |
747 | length = this_set->section_sizes[DW_SECT_STR_OFFSETS]; | |
39f381cb | 748 | |
5ab39075 | 749 | if (length > (dwarf_vma) (end - curr)) |
39f381cb | 750 | { |
5ab39075 | 751 | warn (_("index table size too large for section %s vs %s\n"), |
39f381cb NC |
752 | dwarf_vmatoa ("x", length), |
753 | dwarf_vmatoa ("x", index_section->size)); | |
5ab39075 AM |
754 | length = end - curr; |
755 | } | |
756 | ||
757 | if (length < offset_size) | |
758 | { | |
759 | warn (_("index table size %s is too small\n"), | |
760 | dwarf_vmatoa ("x", length)); | |
39f381cb NC |
761 | return _("<table too small>"); |
762 | } | |
e4b7104b NC |
763 | } |
764 | ||
765 | index_offset = idx * offset_size; | |
521d4b19 | 766 | |
341f9135 CC |
767 | if (this_set != NULL) |
768 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
e4b7104b | 769 | |
5ab39075 AM |
770 | if (index_offset >= length |
771 | || length - index_offset < offset_size) | |
4723351a | 772 | { |
d296b736 | 773 | warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"), |
e4b7104b NC |
774 | dwarf_vmatoa ("x", index_offset), |
775 | dwarf_vmatoa ("x", length)); | |
4723351a CC |
776 | return _("<index offset is too big>"); |
777 | } | |
778 | ||
e4b7104b | 779 | str_offset = byte_get (curr + index_offset, offset_size); |
4723351a | 780 | str_offset -= str_section->address; |
d949ff56 | 781 | if (str_offset >= str_section->size) |
4723351a | 782 | { |
d296b736 | 783 | warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"), |
4723351a CC |
784 | dwarf_vmatoa ("x", str_offset)); |
785 | return _("<indirect index offset is too big>"); | |
786 | } | |
787 | ||
d949ff56 NC |
788 | ret = (const char *) str_section->start + str_offset; |
789 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
790 | Since our caller is expecting to receive a well formed C string we test | |
791 | for the lack of a terminating byte here. */ | |
792 | if (strnlen (ret, str_section->size - str_offset) | |
793 | == str_section->size - str_offset) | |
794 | ret = (const char *) _("<no NUL byte at end of section>"); | |
795 | ||
796 | return ret; | |
4723351a CC |
797 | } |
798 | ||
799 | static const char * | |
800 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
801 | { | |
802 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
803 | ||
804 | if (section->start == NULL) | |
805 | return (_("<no .debug_addr section>")); | |
806 | ||
807 | if (offset + bytes > section->size) | |
808 | { | |
d296b736 | 809 | warn (_("Offset into section %s too big: 0x%s\n"), |
b4eb7656 | 810 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
811 | return "<offset too big>"; |
812 | } | |
813 | ||
814 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
815 | } | |
816 | ||
817 | ||
19e6b90e L |
818 | /* FIXME: There are better and more efficient ways to handle |
819 | these structures. For now though, I just want something that | |
820 | is simple to implement. */ | |
bcd213b2 | 821 | /* Records a single attribute in an abbrev. */ |
19e6b90e L |
822 | typedef struct abbrev_attr |
823 | { | |
bcd213b2 NC |
824 | unsigned long attribute; |
825 | unsigned long form; | |
0121f438 | 826 | dwarf_signed_vma implicit_const; |
bcd213b2 | 827 | struct abbrev_attr * next; |
19e6b90e L |
828 | } |
829 | abbrev_attr; | |
830 | ||
bcd213b2 | 831 | /* Records a single abbrev. */ |
19e6b90e L |
832 | typedef struct abbrev_entry |
833 | { | |
bcd213b2 NC |
834 | unsigned long number; |
835 | unsigned long tag; | |
836 | int children; | |
837 | struct abbrev_attr * first_attr; | |
838 | struct abbrev_attr * last_attr; | |
839 | struct abbrev_entry * next; | |
19e6b90e L |
840 | } |
841 | abbrev_entry; | |
842 | ||
bcd213b2 NC |
843 | /* Records a set of abbreviations. */ |
844 | typedef struct abbrev_list | |
845 | { | |
846 | abbrev_entry * first_abbrev; | |
847 | abbrev_entry * last_abbrev; | |
76868f36 | 848 | dwarf_vma abbrev_base; |
bcd213b2 NC |
849 | dwarf_vma abbrev_offset; |
850 | struct abbrev_list * next; | |
851 | unsigned char * start_of_next_abbrevs; | |
852 | } | |
853 | abbrev_list; | |
854 | ||
855 | /* Records all the abbrevs found so far. */ | |
856 | static struct abbrev_list * abbrev_lists = NULL; | |
857 | ||
858 | typedef struct abbrev_map | |
859 | { | |
860 | dwarf_vma start; | |
861 | dwarf_vma end; | |
862 | abbrev_list * list; | |
863 | } abbrev_map; | |
864 | ||
865 | /* Maps between CU offsets and abbrev sets. */ | |
866 | static abbrev_map * cu_abbrev_map = NULL; | |
867 | static unsigned long num_abbrev_map_entries = 0; | |
868 | static unsigned long next_free_abbrev_map_entry = 0; | |
869 | ||
870 | #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8 | |
871 | #define ABBREV_MAP_ENTRIES_INCREMENT 8 | |
872 | ||
873 | static void | |
874 | record_abbrev_list_for_cu (dwarf_vma start, dwarf_vma end, abbrev_list * list) | |
875 | { | |
876 | if (cu_abbrev_map == NULL) | |
877 | { | |
878 | num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES; | |
879 | cu_abbrev_map = xmalloc (num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
880 | } | |
881 | else if (next_free_abbrev_map_entry == num_abbrev_map_entries) | |
882 | { | |
883 | num_abbrev_map_entries += ABBREV_MAP_ENTRIES_INCREMENT; | |
884 | cu_abbrev_map = xrealloc (cu_abbrev_map, num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
885 | } | |
886 | ||
887 | cu_abbrev_map[next_free_abbrev_map_entry].start = start; | |
888 | cu_abbrev_map[next_free_abbrev_map_entry].end = end; | |
889 | cu_abbrev_map[next_free_abbrev_map_entry].list = list; | |
890 | next_free_abbrev_map_entry ++; | |
891 | } | |
19e6b90e L |
892 | |
893 | static void | |
bcd213b2 | 894 | free_all_abbrevs (void) |
19e6b90e | 895 | { |
bcd213b2 | 896 | abbrev_list * list; |
19e6b90e | 897 | |
bcd213b2 | 898 | for (list = abbrev_lists; list != NULL;) |
19e6b90e | 899 | { |
bcd213b2 NC |
900 | abbrev_list * next = list->next; |
901 | abbrev_entry * abbrv; | |
19e6b90e | 902 | |
bcd213b2 | 903 | for (abbrv = list->first_abbrev; abbrv != NULL;) |
19e6b90e | 904 | { |
bcd213b2 NC |
905 | abbrev_entry * next_abbrev = abbrv->next; |
906 | abbrev_attr * attr; | |
907 | ||
908 | for (attr = abbrv->first_attr; attr;) | |
909 | { | |
910 | abbrev_attr *next_attr = attr->next; | |
19e6b90e | 911 | |
bcd213b2 NC |
912 | free (attr); |
913 | attr = next_attr; | |
914 | } | |
915 | ||
916 | free (abbrv); | |
917 | abbrv = next_abbrev; | |
19e6b90e L |
918 | } |
919 | ||
bcd213b2 NC |
920 | free (list); |
921 | list = next; | |
19e6b90e L |
922 | } |
923 | ||
bcd213b2 NC |
924 | abbrev_lists = NULL; |
925 | } | |
926 | ||
927 | static abbrev_list * | |
76868f36 | 928 | new_abbrev_list (dwarf_vma abbrev_base, dwarf_vma abbrev_offset) |
bcd213b2 NC |
929 | { |
930 | abbrev_list * list = (abbrev_list *) xcalloc (sizeof * list, 1); | |
931 | ||
76868f36 | 932 | list->abbrev_base = abbrev_base; |
bcd213b2 NC |
933 | list->abbrev_offset = abbrev_offset; |
934 | ||
935 | list->next = abbrev_lists; | |
936 | abbrev_lists = list; | |
937 | ||
938 | return list; | |
939 | } | |
940 | ||
941 | static abbrev_list * | |
76868f36 L |
942 | find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base, |
943 | dwarf_vma abbrev_offset) | |
bcd213b2 NC |
944 | { |
945 | abbrev_list * list; | |
946 | ||
947 | for (list = abbrev_lists; list != NULL; list = list->next) | |
76868f36 L |
948 | if (list->abbrev_base == abbrev_base |
949 | && list->abbrev_offset == abbrev_offset) | |
bcd213b2 NC |
950 | return list; |
951 | ||
952 | return NULL; | |
953 | } | |
954 | ||
955 | /* Find the abbreviation map for the CU that includes OFFSET. | |
956 | OFFSET is an absolute offset from the start of the .debug_info section. */ | |
957 | /* FIXME: This function is going to slow down readelf & objdump. | |
958 | Consider using a better algorithm to mitigate this effect. */ | |
959 | ||
960 | static abbrev_map * | |
961 | find_abbrev_map_by_offset (dwarf_vma offset) | |
962 | { | |
963 | unsigned long i; | |
964 | ||
965 | for (i = 0; i < next_free_abbrev_map_entry; i++) | |
966 | if (cu_abbrev_map[i].start <= offset | |
967 | && cu_abbrev_map[i].end > offset) | |
968 | return cu_abbrev_map + i; | |
969 | ||
970 | return NULL; | |
19e6b90e L |
971 | } |
972 | ||
973 | static void | |
bcd213b2 NC |
974 | add_abbrev (unsigned long number, |
975 | unsigned long tag, | |
976 | int children, | |
977 | abbrev_list * list) | |
19e6b90e | 978 | { |
bcd213b2 | 979 | abbrev_entry * entry; |
19e6b90e | 980 | |
bcd213b2 | 981 | entry = (abbrev_entry *) xmalloc (sizeof (*entry)); |
19e6b90e | 982 | |
bcd213b2 | 983 | entry->number = number; |
19e6b90e L |
984 | entry->tag = tag; |
985 | entry->children = children; | |
986 | entry->first_attr = NULL; | |
987 | entry->last_attr = NULL; | |
988 | entry->next = NULL; | |
989 | ||
bcd213b2 NC |
990 | assert (list != NULL); |
991 | ||
992 | if (list->first_abbrev == NULL) | |
993 | list->first_abbrev = entry; | |
19e6b90e | 994 | else |
bcd213b2 | 995 | list->last_abbrev->next = entry; |
19e6b90e | 996 | |
bcd213b2 | 997 | list->last_abbrev = entry; |
19e6b90e L |
998 | } |
999 | ||
1000 | static void | |
0121f438 EB |
1001 | add_abbrev_attr (unsigned long attribute, |
1002 | unsigned long form, | |
1003 | dwarf_signed_vma implicit_const, | |
1004 | abbrev_list * list) | |
19e6b90e L |
1005 | { |
1006 | abbrev_attr *attr; | |
1007 | ||
bcd213b2 | 1008 | attr = (abbrev_attr *) xmalloc (sizeof (*attr)); |
19e6b90e | 1009 | |
0121f438 EB |
1010 | attr->attribute = attribute; |
1011 | attr->form = form; | |
77145576 | 1012 | attr->implicit_const = implicit_const; |
0121f438 | 1013 | attr->next = NULL; |
19e6b90e | 1014 | |
bcd213b2 NC |
1015 | assert (list != NULL && list->last_abbrev != NULL); |
1016 | ||
1017 | if (list->last_abbrev->first_attr == NULL) | |
1018 | list->last_abbrev->first_attr = attr; | |
19e6b90e | 1019 | else |
bcd213b2 | 1020 | list->last_abbrev->last_attr->next = attr; |
19e6b90e | 1021 | |
bcd213b2 | 1022 | list->last_abbrev->last_attr = attr; |
19e6b90e L |
1023 | } |
1024 | ||
1025 | /* Processes the (partial) contents of a .debug_abbrev section. | |
1026 | Returns NULL if the end of the section was encountered. | |
1027 | Returns the address after the last byte read if the end of | |
1028 | an abbreviation set was found. */ | |
1029 | ||
1030 | static unsigned char * | |
f2f9554b AM |
1031 | process_abbrev_set (struct dwarf_section *section, |
1032 | dwarf_vma abbrev_base, | |
1033 | dwarf_vma abbrev_size, | |
1034 | dwarf_vma abbrev_offset, | |
1035 | abbrev_list *list) | |
19e6b90e | 1036 | { |
f2f9554b AM |
1037 | if (abbrev_base >= section->size |
1038 | || abbrev_size > section->size - abbrev_base) | |
1039 | { | |
1040 | /* PR 17531: file:4bcd9ce9. */ | |
1041 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than " | |
1042 | "abbrev section size (%lx)\n"), | |
d30182b5 | 1043 | (unsigned long) (abbrev_base + abbrev_size), |
f2f9554b AM |
1044 | (unsigned long) section->size); |
1045 | return NULL; | |
1046 | } | |
1047 | if (abbrev_offset >= abbrev_size) | |
1048 | { | |
1049 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than " | |
1050 | "abbrev section size (%lx)\n"), | |
1051 | (unsigned long) abbrev_offset, | |
1052 | (unsigned long) abbrev_size); | |
1053 | return NULL; | |
1054 | } | |
1055 | ||
1056 | unsigned char *start = section->start + abbrev_base; | |
1057 | unsigned char *end = start + abbrev_size; | |
1058 | start += abbrev_offset; | |
19e6b90e L |
1059 | while (start < end) |
1060 | { | |
19e6b90e L |
1061 | unsigned long entry; |
1062 | unsigned long tag; | |
1063 | unsigned long attribute; | |
1064 | int children; | |
1065 | ||
cd30bcef | 1066 | READ_ULEB (entry, start, end); |
19e6b90e | 1067 | |
bcd213b2 | 1068 | /* A single zero is supposed to end the set according |
19e6b90e L |
1069 | to the standard. If there's more, then signal that to |
1070 | the caller. */ | |
f6f0e17b NC |
1071 | if (start == end) |
1072 | return NULL; | |
19e6b90e | 1073 | if (entry == 0) |
f6f0e17b | 1074 | return start; |
19e6b90e | 1075 | |
cd30bcef | 1076 | READ_ULEB (tag, start, end); |
f6f0e17b NC |
1077 | if (start == end) |
1078 | return NULL; | |
19e6b90e L |
1079 | |
1080 | children = *start++; | |
1081 | ||
bcd213b2 | 1082 | add_abbrev (entry, tag, children, list); |
19e6b90e L |
1083 | |
1084 | do | |
1085 | { | |
1086 | unsigned long form; | |
77145576 | 1087 | /* Initialize it due to a false compiler warning. */ |
0121f438 | 1088 | dwarf_signed_vma implicit_const = -1; |
19e6b90e | 1089 | |
cd30bcef | 1090 | READ_ULEB (attribute, start, end); |
f6f0e17b NC |
1091 | if (start == end) |
1092 | break; | |
19e6b90e | 1093 | |
cd30bcef | 1094 | READ_ULEB (form, start, end); |
f6f0e17b NC |
1095 | if (start == end) |
1096 | break; | |
19e6b90e | 1097 | |
77145576 JK |
1098 | if (form == DW_FORM_implicit_const) |
1099 | { | |
cd30bcef | 1100 | READ_SLEB (implicit_const, start, end); |
77145576 JK |
1101 | if (start == end) |
1102 | break; | |
1103 | } | |
1104 | ||
bcd213b2 | 1105 | add_abbrev_attr (attribute, form, implicit_const, list); |
19e6b90e L |
1106 | } |
1107 | while (attribute != 0); | |
1108 | } | |
1109 | ||
399c99f7 L |
1110 | /* Report the missing single zero which ends the section. */ |
1111 | error (_(".debug_abbrev section not zero terminated\n")); | |
1112 | ||
19e6b90e L |
1113 | return NULL; |
1114 | } | |
1115 | ||
a19c41a7 | 1116 | static const char * |
19e6b90e L |
1117 | get_TAG_name (unsigned long tag) |
1118 | { | |
04914e37 | 1119 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
1120 | |
1121 | if (name == NULL) | |
19e6b90e | 1122 | { |
a19c41a7 | 1123 | static char buffer[100]; |
19e6b90e | 1124 | |
04914e37 NC |
1125 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1126 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
1127 | else | |
1128 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 1129 | return buffer; |
19e6b90e | 1130 | } |
a19c41a7 TT |
1131 | |
1132 | return name; | |
19e6b90e L |
1133 | } |
1134 | ||
a19c41a7 | 1135 | static const char * |
19e6b90e L |
1136 | get_FORM_name (unsigned long form) |
1137 | { | |
399c99f7 | 1138 | const char *name; |
bf5117e3 | 1139 | |
399c99f7 L |
1140 | if (form == 0) |
1141 | return "DW_FORM value: 0"; | |
a19c41a7 | 1142 | |
399c99f7 | 1143 | name = get_DW_FORM_name (form); |
a19c41a7 | 1144 | if (name == NULL) |
19e6b90e | 1145 | { |
a19c41a7 | 1146 | static char buffer[100]; |
19e6b90e | 1147 | |
a19c41a7 TT |
1148 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1149 | return buffer; | |
19e6b90e | 1150 | } |
a19c41a7 TT |
1151 | |
1152 | return name; | |
19e6b90e L |
1153 | } |
1154 | ||
61364358 JK |
1155 | static const char * |
1156 | get_IDX_name (unsigned long idx) | |
1157 | { | |
1158 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1159 | ||
1160 | if (name == NULL) | |
1161 | { | |
1162 | static char buffer[100]; | |
1163 | ||
1164 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1165 | return buffer; | |
1166 | } | |
1167 | ||
1168 | return name; | |
1169 | } | |
1170 | ||
19e6b90e | 1171 | static unsigned char * |
0c588247 NC |
1172 | display_block (unsigned char *data, |
1173 | dwarf_vma length, | |
ef0b5f1c | 1174 | const unsigned char * const end, char delimiter) |
19e6b90e | 1175 | { |
0c588247 NC |
1176 | dwarf_vma maxlen; |
1177 | ||
ef0b5f1c | 1178 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1179 | if (data > end) |
1180 | return (unsigned char *) end; | |
19e6b90e | 1181 | |
0c588247 NC |
1182 | maxlen = (dwarf_vma) (end - data); |
1183 | length = length > maxlen ? maxlen : length; | |
1184 | ||
19e6b90e L |
1185 | while (length --) |
1186 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1187 | ||
1188 | return data; | |
1189 | } | |
1190 | ||
1191 | static int | |
1192 | decode_location_expression (unsigned char * data, | |
1193 | unsigned int pointer_size, | |
b7807392 JJ |
1194 | unsigned int offset_size, |
1195 | int dwarf_version, | |
467c65bc NC |
1196 | dwarf_vma length, |
1197 | dwarf_vma cu_offset, | |
f1c4cc75 | 1198 | struct dwarf_section * section) |
19e6b90e L |
1199 | { |
1200 | unsigned op; | |
467c65bc | 1201 | dwarf_vma uvalue; |
0c588247 | 1202 | dwarf_signed_vma svalue; |
19e6b90e L |
1203 | unsigned char *end = data + length; |
1204 | int need_frame_base = 0; | |
1205 | ||
1206 | while (data < end) | |
1207 | { | |
1208 | op = *data++; | |
1209 | ||
1210 | switch (op) | |
1211 | { | |
1212 | case DW_OP_addr: | |
0c588247 NC |
1213 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1214 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1215 | break; |
1216 | case DW_OP_deref: | |
1217 | printf ("DW_OP_deref"); | |
1218 | break; | |
1219 | case DW_OP_const1u: | |
0c588247 NC |
1220 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1221 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1222 | break; |
1223 | case DW_OP_const1s: | |
0c588247 NC |
1224 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1225 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1226 | break; |
1227 | case DW_OP_const2u: | |
87bc83b3 | 1228 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1229 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1230 | break; |
1231 | case DW_OP_const2s: | |
0c588247 NC |
1232 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1233 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1234 | break; |
1235 | case DW_OP_const4u: | |
0c588247 NC |
1236 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1237 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1238 | break; |
1239 | case DW_OP_const4s: | |
0c588247 NC |
1240 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1241 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1242 | break; |
1243 | case DW_OP_const8u: | |
0c588247 NC |
1244 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1245 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1246 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1247 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1248 | break; |
1249 | case DW_OP_const8s: | |
0c588247 NC |
1250 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1251 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1252 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1253 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1254 | break; |
1255 | case DW_OP_constu: | |
cd30bcef AM |
1256 | READ_ULEB (uvalue, data, end); |
1257 | printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1258 | break; |
1259 | case DW_OP_consts: | |
cd30bcef AM |
1260 | READ_SLEB (svalue, data, end); |
1261 | printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1262 | break; |
1263 | case DW_OP_dup: | |
1264 | printf ("DW_OP_dup"); | |
1265 | break; | |
1266 | case DW_OP_drop: | |
1267 | printf ("DW_OP_drop"); | |
1268 | break; | |
1269 | case DW_OP_over: | |
1270 | printf ("DW_OP_over"); | |
1271 | break; | |
1272 | case DW_OP_pick: | |
0c588247 NC |
1273 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1274 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1275 | break; |
1276 | case DW_OP_swap: | |
1277 | printf ("DW_OP_swap"); | |
1278 | break; | |
1279 | case DW_OP_rot: | |
1280 | printf ("DW_OP_rot"); | |
1281 | break; | |
1282 | case DW_OP_xderef: | |
1283 | printf ("DW_OP_xderef"); | |
1284 | break; | |
1285 | case DW_OP_abs: | |
1286 | printf ("DW_OP_abs"); | |
1287 | break; | |
1288 | case DW_OP_and: | |
1289 | printf ("DW_OP_and"); | |
1290 | break; | |
1291 | case DW_OP_div: | |
1292 | printf ("DW_OP_div"); | |
1293 | break; | |
1294 | case DW_OP_minus: | |
1295 | printf ("DW_OP_minus"); | |
1296 | break; | |
1297 | case DW_OP_mod: | |
1298 | printf ("DW_OP_mod"); | |
1299 | break; | |
1300 | case DW_OP_mul: | |
1301 | printf ("DW_OP_mul"); | |
1302 | break; | |
1303 | case DW_OP_neg: | |
1304 | printf ("DW_OP_neg"); | |
1305 | break; | |
1306 | case DW_OP_not: | |
1307 | printf ("DW_OP_not"); | |
1308 | break; | |
1309 | case DW_OP_or: | |
1310 | printf ("DW_OP_or"); | |
1311 | break; | |
1312 | case DW_OP_plus: | |
1313 | printf ("DW_OP_plus"); | |
1314 | break; | |
1315 | case DW_OP_plus_uconst: | |
cd30bcef AM |
1316 | READ_ULEB (uvalue, data, end); |
1317 | printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1318 | break; |
1319 | case DW_OP_shl: | |
1320 | printf ("DW_OP_shl"); | |
1321 | break; | |
1322 | case DW_OP_shr: | |
1323 | printf ("DW_OP_shr"); | |
1324 | break; | |
1325 | case DW_OP_shra: | |
1326 | printf ("DW_OP_shra"); | |
1327 | break; | |
1328 | case DW_OP_xor: | |
1329 | printf ("DW_OP_xor"); | |
1330 | break; | |
1331 | case DW_OP_bra: | |
0c588247 NC |
1332 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1333 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1334 | break; |
1335 | case DW_OP_eq: | |
1336 | printf ("DW_OP_eq"); | |
1337 | break; | |
1338 | case DW_OP_ge: | |
1339 | printf ("DW_OP_ge"); | |
1340 | break; | |
1341 | case DW_OP_gt: | |
1342 | printf ("DW_OP_gt"); | |
1343 | break; | |
1344 | case DW_OP_le: | |
1345 | printf ("DW_OP_le"); | |
1346 | break; | |
1347 | case DW_OP_lt: | |
1348 | printf ("DW_OP_lt"); | |
1349 | break; | |
1350 | case DW_OP_ne: | |
1351 | printf ("DW_OP_ne"); | |
1352 | break; | |
1353 | case DW_OP_skip: | |
0c588247 NC |
1354 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1355 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1356 | break; |
1357 | ||
1358 | case DW_OP_lit0: | |
1359 | case DW_OP_lit1: | |
1360 | case DW_OP_lit2: | |
1361 | case DW_OP_lit3: | |
1362 | case DW_OP_lit4: | |
1363 | case DW_OP_lit5: | |
1364 | case DW_OP_lit6: | |
1365 | case DW_OP_lit7: | |
1366 | case DW_OP_lit8: | |
1367 | case DW_OP_lit9: | |
1368 | case DW_OP_lit10: | |
1369 | case DW_OP_lit11: | |
1370 | case DW_OP_lit12: | |
1371 | case DW_OP_lit13: | |
1372 | case DW_OP_lit14: | |
1373 | case DW_OP_lit15: | |
1374 | case DW_OP_lit16: | |
1375 | case DW_OP_lit17: | |
1376 | case DW_OP_lit18: | |
1377 | case DW_OP_lit19: | |
1378 | case DW_OP_lit20: | |
1379 | case DW_OP_lit21: | |
1380 | case DW_OP_lit22: | |
1381 | case DW_OP_lit23: | |
1382 | case DW_OP_lit24: | |
1383 | case DW_OP_lit25: | |
1384 | case DW_OP_lit26: | |
1385 | case DW_OP_lit27: | |
1386 | case DW_OP_lit28: | |
1387 | case DW_OP_lit29: | |
1388 | case DW_OP_lit30: | |
1389 | case DW_OP_lit31: | |
1390 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1391 | break; | |
1392 | ||
1393 | case DW_OP_reg0: | |
1394 | case DW_OP_reg1: | |
1395 | case DW_OP_reg2: | |
1396 | case DW_OP_reg3: | |
1397 | case DW_OP_reg4: | |
1398 | case DW_OP_reg5: | |
1399 | case DW_OP_reg6: | |
1400 | case DW_OP_reg7: | |
1401 | case DW_OP_reg8: | |
1402 | case DW_OP_reg9: | |
1403 | case DW_OP_reg10: | |
1404 | case DW_OP_reg11: | |
1405 | case DW_OP_reg12: | |
1406 | case DW_OP_reg13: | |
1407 | case DW_OP_reg14: | |
1408 | case DW_OP_reg15: | |
1409 | case DW_OP_reg16: | |
1410 | case DW_OP_reg17: | |
1411 | case DW_OP_reg18: | |
1412 | case DW_OP_reg19: | |
1413 | case DW_OP_reg20: | |
1414 | case DW_OP_reg21: | |
1415 | case DW_OP_reg22: | |
1416 | case DW_OP_reg23: | |
1417 | case DW_OP_reg24: | |
1418 | case DW_OP_reg25: | |
1419 | case DW_OP_reg26: | |
1420 | case DW_OP_reg27: | |
1421 | case DW_OP_reg28: | |
1422 | case DW_OP_reg29: | |
1423 | case DW_OP_reg30: | |
1424 | case DW_OP_reg31: | |
18464d4d JK |
1425 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1426 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1427 | break; |
1428 | ||
1429 | case DW_OP_breg0: | |
1430 | case DW_OP_breg1: | |
1431 | case DW_OP_breg2: | |
1432 | case DW_OP_breg3: | |
1433 | case DW_OP_breg4: | |
1434 | case DW_OP_breg5: | |
1435 | case DW_OP_breg6: | |
1436 | case DW_OP_breg7: | |
1437 | case DW_OP_breg8: | |
1438 | case DW_OP_breg9: | |
1439 | case DW_OP_breg10: | |
1440 | case DW_OP_breg11: | |
1441 | case DW_OP_breg12: | |
1442 | case DW_OP_breg13: | |
1443 | case DW_OP_breg14: | |
1444 | case DW_OP_breg15: | |
1445 | case DW_OP_breg16: | |
1446 | case DW_OP_breg17: | |
1447 | case DW_OP_breg18: | |
1448 | case DW_OP_breg19: | |
1449 | case DW_OP_breg20: | |
1450 | case DW_OP_breg21: | |
1451 | case DW_OP_breg22: | |
1452 | case DW_OP_breg23: | |
1453 | case DW_OP_breg24: | |
1454 | case DW_OP_breg25: | |
1455 | case DW_OP_breg26: | |
1456 | case DW_OP_breg27: | |
1457 | case DW_OP_breg28: | |
1458 | case DW_OP_breg29: | |
1459 | case DW_OP_breg30: | |
1460 | case DW_OP_breg31: | |
cd30bcef AM |
1461 | READ_SLEB (svalue, data, end); |
1462 | printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0, | |
1463 | regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1464 | break; |
1465 | ||
1466 | case DW_OP_regx: | |
cd30bcef | 1467 | READ_ULEB (uvalue, data, end); |
467c65bc NC |
1468 | printf ("DW_OP_regx: %s (%s)", |
1469 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1470 | break; |
1471 | case DW_OP_fbreg: | |
1472 | need_frame_base = 1; | |
cd30bcef AM |
1473 | READ_SLEB (svalue, data, end); |
1474 | printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1475 | break; |
1476 | case DW_OP_bregx: | |
cd30bcef AM |
1477 | READ_ULEB (uvalue, data, end); |
1478 | READ_SLEB (svalue, data, end); | |
467c65bc NC |
1479 | printf ("DW_OP_bregx: %s (%s) %s", |
1480 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
cd30bcef | 1481 | dwarf_vmatoa ("d", svalue)); |
19e6b90e L |
1482 | break; |
1483 | case DW_OP_piece: | |
cd30bcef AM |
1484 | READ_ULEB (uvalue, data, end); |
1485 | printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1486 | break; |
1487 | case DW_OP_deref_size: | |
0c588247 NC |
1488 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1489 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1490 | break; |
1491 | case DW_OP_xderef_size: | |
0c588247 NC |
1492 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1493 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1494 | break; |
1495 | case DW_OP_nop: | |
1496 | printf ("DW_OP_nop"); | |
1497 | break; | |
1498 | ||
1499 | /* DWARF 3 extensions. */ | |
1500 | case DW_OP_push_object_address: | |
1501 | printf ("DW_OP_push_object_address"); | |
1502 | break; | |
1503 | case DW_OP_call2: | |
d85bf2ba | 1504 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1505 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1506 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1507 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1508 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1509 | break; |
1510 | case DW_OP_call4: | |
d85bf2ba | 1511 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1512 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1513 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1514 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1515 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1516 | break; |
1517 | case DW_OP_call_ref: | |
d85bf2ba | 1518 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1519 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1520 | if (dwarf_version == -1) |
1521 | { | |
1522 | printf (_("(DW_OP_call_ref in frame info)")); | |
1523 | /* No way to tell where the next op is, so just bail. */ | |
1524 | return need_frame_base; | |
1525 | } | |
1526 | if (dwarf_version == 2) | |
1527 | { | |
0c588247 | 1528 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1529 | } |
1530 | else | |
1531 | { | |
0c588247 | 1532 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1533 | } |
0c588247 | 1534 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1535 | break; |
a87b0a59 NS |
1536 | case DW_OP_form_tls_address: |
1537 | printf ("DW_OP_form_tls_address"); | |
1538 | break; | |
e2a0d921 NC |
1539 | case DW_OP_call_frame_cfa: |
1540 | printf ("DW_OP_call_frame_cfa"); | |
1541 | break; | |
1542 | case DW_OP_bit_piece: | |
1543 | printf ("DW_OP_bit_piece: "); | |
cd30bcef AM |
1544 | READ_ULEB (uvalue, data, end); |
1545 | printf (_("size: %s "), dwarf_vmatoa ("u", uvalue)); | |
1546 | READ_ULEB (uvalue, data, end); | |
1547 | printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue)); | |
e2a0d921 | 1548 | break; |
19e6b90e | 1549 | |
3244e8f5 JJ |
1550 | /* DWARF 4 extensions. */ |
1551 | case DW_OP_stack_value: | |
1552 | printf ("DW_OP_stack_value"); | |
1553 | break; | |
1554 | ||
1555 | case DW_OP_implicit_value: | |
1556 | printf ("DW_OP_implicit_value"); | |
cd30bcef | 1557 | READ_ULEB (uvalue, data, end); |
ef0b5f1c | 1558 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1559 | break; |
1560 | ||
19e6b90e L |
1561 | /* GNU extensions. */ |
1562 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1563 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1564 | break; |
1565 | case DW_OP_GNU_uninit: | |
1566 | printf ("DW_OP_GNU_uninit"); | |
1567 | /* FIXME: Is there data associated with this OP ? */ | |
1568 | break; | |
f1c4cc75 RH |
1569 | case DW_OP_GNU_encoded_addr: |
1570 | { | |
6937bb54 | 1571 | int encoding = 0; |
f1c4cc75 | 1572 | dwarf_vma addr; |
467c65bc | 1573 | |
6937bb54 NC |
1574 | if (data < end) |
1575 | encoding = *data++; | |
041830e0 | 1576 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1577 | |
1578 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1579 | print_dwarf_vma (addr, pointer_size); | |
1580 | } | |
1581 | break; | |
bc0a77d2 | 1582 | case DW_OP_implicit_pointer: |
b7807392 | 1583 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1584 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1585 | this ought to be an 8-byte wide computation. */ |
1586 | if (dwarf_version == -1) | |
1587 | { | |
bc0a77d2 JK |
1588 | printf (_("(%s in frame info)"), |
1589 | (op == DW_OP_implicit_pointer | |
1590 | ? "DW_OP_implicit_pointer" | |
1591 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1592 | /* No way to tell where the next op is, so just bail. */ |
1593 | return need_frame_base; | |
1594 | } | |
1595 | if (dwarf_version == 2) | |
1596 | { | |
0c588247 | 1597 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1598 | } |
1599 | else | |
1600 | { | |
0c588247 | 1601 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1602 | } |
cd30bcef | 1603 | READ_SLEB (svalue, data, end); |
bc0a77d2 JK |
1604 | printf ("%s: <0x%s> %s", |
1605 | (op == DW_OP_implicit_pointer | |
1606 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 | 1607 | dwarf_vmatoa ("x", uvalue), |
cd30bcef | 1608 | dwarf_vmatoa ("d", svalue)); |
b7807392 | 1609 | break; |
77145576 | 1610 | case DW_OP_entry_value: |
0892011d | 1611 | case DW_OP_GNU_entry_value: |
cd30bcef | 1612 | READ_ULEB (uvalue, data, end); |
058037d3 NC |
1613 | /* PR 17531: file: 0cc9cd00. */ |
1614 | if (uvalue > (dwarf_vma) (end - data)) | |
1615 | uvalue = end - data; | |
77145576 JK |
1616 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1617 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1618 | if (decode_location_expression (data, pointer_size, offset_size, |
1619 | dwarf_version, uvalue, | |
1620 | cu_offset, section)) | |
1621 | need_frame_base = 1; | |
1622 | putchar (')'); | |
1623 | data += uvalue; | |
1624 | break; | |
bc0a77d2 | 1625 | case DW_OP_const_type: |
0892011d | 1626 | case DW_OP_GNU_const_type: |
cd30bcef | 1627 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1628 | printf ("%s: <0x%s> ", |
1629 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1630 | : "DW_OP_GNU_const_type"), | |
0892011d | 1631 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1632 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1633 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1634 | break; |
bc0a77d2 | 1635 | case DW_OP_regval_type: |
0892011d | 1636 | case DW_OP_GNU_regval_type: |
cd30bcef | 1637 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1638 | printf ("%s: %s (%s)", |
1639 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1640 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1641 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
cd30bcef | 1642 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1643 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1644 | break; | |
bc0a77d2 | 1645 | case DW_OP_deref_type: |
0892011d | 1646 | case DW_OP_GNU_deref_type: |
0c588247 | 1647 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1648 | printf ("%s: %ld", |
1649 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1650 | : "DW_OP_GNU_deref_type"), | |
1651 | (long) uvalue); | |
cd30bcef | 1652 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1653 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1654 | break; | |
bc0a77d2 | 1655 | case DW_OP_convert: |
0892011d | 1656 | case DW_OP_GNU_convert: |
cd30bcef | 1657 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1658 | printf ("%s <0x%s>", |
1659 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1660 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1661 | break; |
bc0a77d2 | 1662 | case DW_OP_reinterpret: |
0892011d | 1663 | case DW_OP_GNU_reinterpret: |
cd30bcef | 1664 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1665 | printf ("%s <0x%s>", |
1666 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1667 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1668 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1669 | break; | |
1670 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1671 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1672 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1673 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1674 | break; |
b4eb7656 | 1675 | case DW_OP_GNU_addr_index: |
cd30bcef | 1676 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1677 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1678 | break; | |
1679 | case DW_OP_GNU_const_index: | |
cd30bcef | 1680 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1681 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1682 | break; | |
f384a1f0 KB |
1683 | case DW_OP_GNU_variable_value: |
1684 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1685 | this ought to be an 8-byte wide computation. */ | |
1686 | if (dwarf_version == -1) | |
1687 | { | |
1688 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1689 | /* No way to tell where the next op is, so just bail. */ | |
1690 | return need_frame_base; | |
1691 | } | |
1692 | if (dwarf_version == 2) | |
1693 | { | |
1694 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1695 | } | |
1696 | else | |
1697 | { | |
1698 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1699 | } | |
1700 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1701 | break; | |
e2a0d921 NC |
1702 | |
1703 | /* HP extensions. */ | |
1704 | case DW_OP_HP_is_value: | |
1705 | printf ("DW_OP_HP_is_value"); | |
1706 | /* FIXME: Is there data associated with this OP ? */ | |
1707 | break; | |
1708 | case DW_OP_HP_fltconst4: | |
1709 | printf ("DW_OP_HP_fltconst4"); | |
1710 | /* FIXME: Is there data associated with this OP ? */ | |
1711 | break; | |
1712 | case DW_OP_HP_fltconst8: | |
1713 | printf ("DW_OP_HP_fltconst8"); | |
1714 | /* FIXME: Is there data associated with this OP ? */ | |
1715 | break; | |
1716 | case DW_OP_HP_mod_range: | |
1717 | printf ("DW_OP_HP_mod_range"); | |
1718 | /* FIXME: Is there data associated with this OP ? */ | |
1719 | break; | |
1720 | case DW_OP_HP_unmod_range: | |
1721 | printf ("DW_OP_HP_unmod_range"); | |
1722 | /* FIXME: Is there data associated with this OP ? */ | |
1723 | break; | |
1724 | case DW_OP_HP_tls: | |
1725 | printf ("DW_OP_HP_tls"); | |
1726 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1727 | break; |
1728 | ||
35d60fe4 NC |
1729 | /* PGI (STMicroelectronics) extensions. */ |
1730 | case DW_OP_PGI_omp_thread_num: | |
1731 | /* Pushes the thread number for the current thread as it would be | |
1732 | returned by the standard OpenMP library function: | |
1733 | omp_get_thread_num(). The "current thread" is the thread for | |
1734 | which the expression is being evaluated. */ | |
1735 | printf ("DW_OP_PGI_omp_thread_num"); | |
1736 | break; | |
1737 | ||
19e6b90e L |
1738 | default: |
1739 | if (op >= DW_OP_lo_user | |
1740 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1741 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1742 | else |
0502a2b4 | 1743 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1744 | /* No way to tell where the next op is, so just bail. */ |
1745 | return need_frame_base; | |
1746 | } | |
1747 | ||
1748 | /* Separate the ops. */ | |
1749 | if (data < end) | |
1750 | printf ("; "); | |
1751 | } | |
1752 | ||
1753 | return need_frame_base; | |
1754 | } | |
1755 | ||
341f9135 CC |
1756 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1757 | This is used for DWARF package files. */ | |
1758 | ||
1759 | static struct cu_tu_set * | |
1760 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1761 | { | |
1762 | struct cu_tu_set *p; | |
1763 | unsigned int nsets; | |
1764 | unsigned int dw_sect; | |
1765 | ||
1766 | if (do_types) | |
1767 | { | |
1768 | p = tu_sets; | |
1769 | nsets = tu_count; | |
1770 | dw_sect = DW_SECT_TYPES; | |
1771 | } | |
1772 | else | |
1773 | { | |
1774 | p = cu_sets; | |
1775 | nsets = cu_count; | |
1776 | dw_sect = DW_SECT_INFO; | |
1777 | } | |
1778 | while (nsets > 0) | |
1779 | { | |
1780 | if (p->section_offsets [dw_sect] == cu_offset) | |
1781 | return p; | |
1782 | p++; | |
1783 | nsets--; | |
1784 | } | |
1785 | return NULL; | |
1786 | } | |
1787 | ||
dda8d76d NC |
1788 | static const char * |
1789 | fetch_alt_indirect_string (dwarf_vma offset) | |
1790 | { | |
24841daa | 1791 | separate_info * i; |
dda8d76d NC |
1792 | |
1793 | if (! do_follow_links) | |
1794 | return ""; | |
1795 | ||
24841daa NC |
1796 | if (first_separate_info == NULL) |
1797 | return _("<no links available>"); | |
dda8d76d | 1798 | |
24841daa NC |
1799 | for (i = first_separate_info; i != NULL; i = i->next) |
1800 | { | |
1801 | struct dwarf_section * section; | |
1802 | const char * ret; | |
dda8d76d | 1803 | |
24841daa NC |
1804 | if (! load_debug_section (separate_debug_str, i->handle)) |
1805 | continue; | |
dda8d76d | 1806 | |
24841daa | 1807 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1808 | |
24841daa NC |
1809 | if (section->start == NULL) |
1810 | continue; | |
dda8d76d | 1811 | |
24841daa NC |
1812 | if (offset >= section->size) |
1813 | continue; | |
1814 | ||
1815 | ret = (const char *) (section->start + offset); | |
1816 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1817 | NUL byte. Since our caller is expecting to receive a well formed C | |
1818 | string we test for the lack of a terminating byte here. */ | |
1819 | if (strnlen ((const char *) ret, section->size - offset) | |
1820 | == section->size - offset) | |
1821 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1822 | ||
1823 | return ret; | |
1824 | } | |
521d4b19 | 1825 | |
24841daa NC |
1826 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), |
1827 | dwarf_vmatoa ("x", offset)); | |
1828 | return _("<offset is too big>"); | |
dda8d76d NC |
1829 | } |
1830 | ||
d85bf2ba NC |
1831 | static const char * |
1832 | get_AT_name (unsigned long attribute) | |
1833 | { | |
1834 | const char *name; | |
1835 | ||
1836 | if (attribute == 0) | |
1837 | return "DW_AT value: 0"; | |
1838 | ||
1839 | /* One value is shared by the MIPS and HP extensions: */ | |
1840 | if (attribute == DW_AT_MIPS_fde) | |
1841 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1842 | ||
1843 | name = get_DW_AT_name (attribute); | |
1844 | ||
1845 | if (name == NULL) | |
1846 | { | |
1847 | static char buffer[100]; | |
1848 | ||
1849 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1850 | attribute); | |
1851 | return buffer; | |
1852 | } | |
1853 | ||
1854 | return name; | |
1855 | } | |
1856 | ||
24841daa | 1857 | static void |
50ea0877 | 1858 | add_dwo_info (const char * value, dwarf_vma cu_offset, dwo_type type) |
24841daa NC |
1859 | { |
1860 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1861 | ||
50ea0877 NC |
1862 | dwinfo->type = type; |
1863 | dwinfo->value = value; | |
1864 | dwinfo->cu_offset = cu_offset; | |
1865 | dwinfo->next = first_dwo_info; | |
24841daa NC |
1866 | first_dwo_info = dwinfo; |
1867 | } | |
1868 | ||
1869 | static void | |
50ea0877 | 1870 | add_dwo_name (const char * name, dwarf_vma cu_offset) |
24841daa | 1871 | { |
50ea0877 | 1872 | add_dwo_info (name, cu_offset, DWO_NAME); |
24841daa NC |
1873 | } |
1874 | ||
1875 | static void | |
50ea0877 | 1876 | add_dwo_dir (const char * dir, dwarf_vma cu_offset) |
24841daa | 1877 | { |
50ea0877 | 1878 | add_dwo_info (dir, cu_offset, DWO_DIR); |
24841daa NC |
1879 | } |
1880 | ||
1881 | static void | |
50ea0877 | 1882 | add_dwo_id (const char * id, dwarf_vma cu_offset) |
24841daa | 1883 | { |
50ea0877 | 1884 | add_dwo_info (id, cu_offset, DWO_ID); |
24841daa NC |
1885 | } |
1886 | ||
1887 | static void | |
1888 | free_dwo_info (void) | |
1889 | { | |
1890 | dwo_info * dwinfo; | |
1891 | dwo_info * next; | |
1892 | ||
1893 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1894 | { | |
1895 | next = dwinfo->next; | |
1896 | free (dwinfo); | |
1897 | } | |
1898 | first_dwo_info = NULL; | |
1899 | } | |
1900 | ||
afc72f15 NC |
1901 | /* Ensure that START + UVALUE is less than END. |
1902 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1903 | ||
1904 | static inline dwarf_vma | |
1905 | check_uvalue (const unsigned char * start, | |
1906 | dwarf_vma uvalue, | |
1907 | const unsigned char * end) | |
1908 | { | |
1909 | dwarf_vma max_uvalue = end - start; | |
1910 | ||
afc72f15 NC |
1911 | /* See PR 17512: file: 008-103549-0.001:0.1. |
1912 | and PR 24829 for examples of where these tests are triggered. */ | |
a85eba51 | 1913 | if (uvalue > max_uvalue) |
afc72f15 NC |
1914 | { |
1915 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1916 | uvalue = max_uvalue; | |
1917 | } | |
1918 | ||
1919 | return uvalue; | |
1920 | } | |
1921 | ||
ec1b0fbb | 1922 | static unsigned char * |
a7077ce7 AM |
1923 | skip_attr_bytes (unsigned long form, |
1924 | unsigned char *data, | |
1925 | unsigned char *end, | |
1926 | dwarf_vma pointer_size, | |
1927 | dwarf_vma offset_size, | |
1928 | int dwarf_version, | |
1929 | dwarf_vma *value_return) | |
ec1b0fbb | 1930 | { |
cd30bcef AM |
1931 | dwarf_signed_vma svalue; |
1932 | dwarf_vma uvalue = 0; | |
a7077ce7 | 1933 | dwarf_vma inc = 0; |
ec1b0fbb NC |
1934 | |
1935 | * value_return = 0; | |
1936 | ||
1937 | switch (form) | |
1938 | { | |
1939 | case DW_FORM_ref_addr: | |
1940 | if (dwarf_version == 2) | |
1941 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
59624513 | 1942 | else if (dwarf_version > 2) |
ec1b0fbb NC |
1943 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1944 | else | |
1945 | return NULL; | |
1946 | break; | |
1947 | ||
1948 | case DW_FORM_addr: | |
1949 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1950 | break; | |
1951 | ||
1952 | case DW_FORM_strp: | |
1953 | case DW_FORM_line_strp: | |
1954 | case DW_FORM_sec_offset: | |
1955 | case DW_FORM_GNU_ref_alt: | |
1956 | case DW_FORM_GNU_strp_alt: | |
1957 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1958 | break; | |
1959 | ||
1960 | case DW_FORM_flag_present: | |
1961 | uvalue = 1; | |
1962 | break; | |
1963 | ||
1964 | case DW_FORM_ref1: | |
1965 | case DW_FORM_flag: | |
1966 | case DW_FORM_data1: | |
32e4f96c TV |
1967 | case DW_FORM_strx1: |
1968 | case DW_FORM_addrx1: | |
ec1b0fbb NC |
1969 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1970 | break; | |
1971 | ||
32e4f96c TV |
1972 | case DW_FORM_strx3: |
1973 | case DW_FORM_addrx3: | |
1974 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); | |
1975 | break; | |
1976 | ||
ec1b0fbb NC |
1977 | case DW_FORM_ref2: |
1978 | case DW_FORM_data2: | |
32e4f96c TV |
1979 | case DW_FORM_strx2: |
1980 | case DW_FORM_addrx2: | |
ec1b0fbb NC |
1981 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
1982 | break; | |
1983 | ||
1984 | case DW_FORM_ref4: | |
1985 | case DW_FORM_data4: | |
32e4f96c TV |
1986 | case DW_FORM_strx4: |
1987 | case DW_FORM_addrx4: | |
ec1b0fbb NC |
1988 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1989 | break; | |
1990 | ||
1991 | case DW_FORM_sdata: | |
cd30bcef AM |
1992 | READ_SLEB (svalue, data, end); |
1993 | uvalue = svalue; | |
ec1b0fbb NC |
1994 | break; |
1995 | ||
1996 | case DW_FORM_ref_udata: | |
1997 | case DW_FORM_udata: | |
1998 | case DW_FORM_GNU_str_index: | |
32e4f96c | 1999 | case DW_FORM_strx: |
ec1b0fbb | 2000 | case DW_FORM_GNU_addr_index: |
32e4f96c | 2001 | case DW_FORM_addrx: |
cd30bcef | 2002 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
2003 | break; |
2004 | ||
2005 | case DW_FORM_ref8: | |
af2ddf69 AM |
2006 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
2007 | break; | |
1f573141 | 2008 | |
ec1b0fbb | 2009 | case DW_FORM_data8: |
59624513 | 2010 | case DW_FORM_ref_sig8: |
a7077ce7 | 2011 | inc = 8; |
ec1b0fbb NC |
2012 | break; |
2013 | ||
2014 | case DW_FORM_data16: | |
a7077ce7 | 2015 | inc = 16; |
ec1b0fbb NC |
2016 | break; |
2017 | ||
2018 | case DW_FORM_string: | |
a7077ce7 | 2019 | inc = strnlen ((char *) data, end - data) + 1; |
ec1b0fbb NC |
2020 | break; |
2021 | ||
2022 | case DW_FORM_block: | |
2023 | case DW_FORM_exprloc: | |
cd30bcef | 2024 | READ_ULEB (uvalue, data, end); |
a7077ce7 | 2025 | inc = uvalue; |
ec1b0fbb NC |
2026 | break; |
2027 | ||
2028 | case DW_FORM_block1: | |
a7077ce7 AM |
2029 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2030 | inc = uvalue; | |
ec1b0fbb NC |
2031 | break; |
2032 | ||
2033 | case DW_FORM_block2: | |
a7077ce7 AM |
2034 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2035 | inc = uvalue; | |
ec1b0fbb NC |
2036 | break; |
2037 | ||
2038 | case DW_FORM_block4: | |
a7077ce7 AM |
2039 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2040 | inc = uvalue; | |
ec1b0fbb NC |
2041 | break; |
2042 | ||
ec1b0fbb | 2043 | case DW_FORM_indirect: |
59624513 NC |
2044 | READ_ULEB (form, data, end); |
2045 | if (form == DW_FORM_implicit_const) | |
2046 | SKIP_ULEB (data, end); | |
a7077ce7 AM |
2047 | return skip_attr_bytes (form, data, end, pointer_size, offset_size, |
2048 | dwarf_version, value_return); | |
59624513 | 2049 | |
ec1b0fbb NC |
2050 | default: |
2051 | return NULL; | |
2052 | } | |
2053 | ||
2054 | * value_return = uvalue; | |
a7077ce7 AM |
2055 | if (inc <= (dwarf_vma) (end - data)) |
2056 | data += inc; | |
2057 | else | |
2058 | data = end; | |
ec1b0fbb NC |
2059 | return data; |
2060 | } | |
2061 | ||
bcd213b2 NC |
2062 | /* Given form FORM with value UVALUE, locate and return the abbreviation |
2063 | associated with it. */ | |
2064 | ||
2065 | static abbrev_entry * | |
1b3892be AM |
2066 | get_type_abbrev_from_form (unsigned long form, |
2067 | unsigned long uvalue, | |
2068 | dwarf_vma cu_offset, | |
2069 | const struct dwarf_section *section, | |
2070 | unsigned long *abbrev_num_return, | |
2071 | unsigned char **data_return, | |
2072 | abbrev_map **map_return) | |
bcd213b2 NC |
2073 | { |
2074 | unsigned long abbrev_number; | |
2075 | abbrev_map * map; | |
2076 | abbrev_entry * entry; | |
2077 | unsigned char * data; | |
2078 | ||
2079 | if (abbrev_num_return != NULL) | |
2080 | * abbrev_num_return = 0; | |
2081 | if (data_return != NULL) | |
2082 | * data_return = NULL; | |
2083 | ||
2084 | switch (form) | |
2085 | { | |
2086 | case DW_FORM_GNU_ref_alt: | |
5f128a25 | 2087 | case DW_FORM_ref_sig8: |
bcd213b2 NC |
2088 | /* FIXME: We are unable to handle this form at the moment. */ |
2089 | return NULL; | |
2090 | ||
2091 | case DW_FORM_ref_addr: | |
2092 | if (uvalue >= section->size) | |
2093 | { | |
2094 | warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"), | |
2095 | uvalue, (long) section->size, section->name); | |
2096 | return NULL; | |
2097 | } | |
2098 | break; | |
2099 | ||
e38332c2 NC |
2100 | case DW_FORM_ref_sup4: |
2101 | case DW_FORM_ref_sup8: | |
2102 | break; | |
2103 | ||
bcd213b2 NC |
2104 | case DW_FORM_ref1: |
2105 | case DW_FORM_ref2: | |
2106 | case DW_FORM_ref4: | |
1f573141 | 2107 | case DW_FORM_ref8: |
bcd213b2 NC |
2108 | case DW_FORM_ref_udata: |
2109 | if (uvalue + cu_offset > section->size) | |
2110 | { | |
2111 | warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"), | |
2112 | uvalue, (long) cu_offset, (long) section->size); | |
2113 | return NULL; | |
2114 | } | |
2115 | uvalue += cu_offset; | |
2116 | break; | |
2117 | ||
2118 | /* FIXME: Are there other DW_FORMs that can be used by types ? */ | |
2119 | ||
2120 | default: | |
2121 | warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form); | |
2122 | return NULL; | |
2123 | } | |
2124 | ||
2125 | data = (unsigned char *) section->start + uvalue; | |
2126 | map = find_abbrev_map_by_offset (uvalue); | |
521d4b19 | 2127 | |
bcd213b2 NC |
2128 | if (map == NULL) |
2129 | { | |
2130 | warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue); | |
2131 | return NULL; | |
2132 | } | |
2133 | if (map->list == NULL) | |
2134 | { | |
2135 | warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue); | |
2136 | return NULL; | |
2137 | } | |
2138 | ||
1b3892be | 2139 | if (map_return != NULL) |
bcd213b2 NC |
2140 | { |
2141 | if (form == DW_FORM_ref_addr) | |
1b3892be | 2142 | *map_return = map; |
bcd213b2 | 2143 | else |
1b3892be | 2144 | *map_return = NULL; |
bcd213b2 NC |
2145 | } |
2146 | ||
2147 | READ_ULEB (abbrev_number, data, section->start + section->size); | |
2148 | ||
2149 | for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next) | |
2150 | if (entry->number == abbrev_number) | |
2151 | break; | |
521d4b19 | 2152 | |
bcd213b2 NC |
2153 | if (abbrev_num_return != NULL) |
2154 | * abbrev_num_return = abbrev_number; | |
2155 | ||
2156 | if (data_return != NULL) | |
2157 | * data_return = data; | |
2158 | ||
2159 | if (entry == NULL) | |
2160 | warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number); | |
2161 | ||
2162 | return entry; | |
2163 | } | |
2164 | ||
2165 | /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY | |
2166 | can be determined to be a signed type. The data for ENTRY can be | |
2167 | found starting at DATA. */ | |
ec1b0fbb NC |
2168 | |
2169 | static void | |
015dc7e1 AM |
2170 | get_type_signedness (abbrev_entry *entry, |
2171 | const struct dwarf_section *section, | |
2172 | unsigned char *data, | |
a7077ce7 | 2173 | unsigned char *end, |
015dc7e1 AM |
2174 | dwarf_vma cu_offset, |
2175 | dwarf_vma pointer_size, | |
2176 | dwarf_vma offset_size, | |
2177 | int dwarf_version, | |
2178 | bool *is_signed, | |
2179 | unsigned int nesting) | |
ec1b0fbb | 2180 | { |
ec1b0fbb NC |
2181 | abbrev_attr * attr; |
2182 | ||
015dc7e1 | 2183 | * is_signed = false; |
ec1b0fbb | 2184 | |
59624513 NC |
2185 | #define MAX_NESTING 20 |
2186 | if (nesting > MAX_NESTING) | |
2187 | { | |
2188 | /* FIXME: Warn - or is this expected ? | |
2189 | NB/ We need to avoid infinite recursion. */ | |
2190 | return; | |
2191 | } | |
2192 | ||
ec1b0fbb NC |
2193 | for (attr = entry->first_attr; |
2194 | attr != NULL && attr->attribute; | |
2195 | attr = attr->next) | |
2196 | { | |
bcd213b2 | 2197 | unsigned char * orig_data = data; |
ec1b0fbb NC |
2198 | dwarf_vma uvalue = 0; |
2199 | ||
2200 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
2201 | offset_size, dwarf_version, & uvalue); | |
2202 | if (data == NULL) | |
2203 | return; | |
2204 | ||
2205 | switch (attr->attribute) | |
2206 | { | |
bcd213b2 | 2207 | case DW_AT_linkage_name: |
ec1b0fbb | 2208 | case DW_AT_name: |
bcd213b2 NC |
2209 | if (do_wide) |
2210 | { | |
2211 | if (attr->form == DW_FORM_strp) | |
2212 | printf (", %s", fetch_indirect_string (uvalue)); | |
2213 | else if (attr->form == DW_FORM_string) | |
4ff0bb2d | 2214 | printf (", %.*s", (int) (end - orig_data), orig_data); |
bcd213b2 | 2215 | } |
ec1b0fbb | 2216 | break; |
bcd213b2 | 2217 | |
ec1b0fbb NC |
2218 | case DW_AT_type: |
2219 | /* Recurse. */ | |
bcd213b2 | 2220 | { |
1b3892be AM |
2221 | abbrev_entry *type_abbrev; |
2222 | unsigned char *type_data; | |
2223 | abbrev_map *map; | |
bcd213b2 NC |
2224 | |
2225 | type_abbrev = get_type_abbrev_from_form (attr->form, | |
2226 | uvalue, | |
2227 | cu_offset, | |
2228 | section, | |
2229 | NULL /* abbrev num return */, | |
1b3892be AM |
2230 | &type_data, |
2231 | &map); | |
bcd213b2 NC |
2232 | if (type_abbrev == NULL) |
2233 | break; | |
2234 | ||
1b3892be AM |
2235 | get_type_signedness (type_abbrev, section, type_data, |
2236 | map ? section->start + map->end : end, | |
2237 | map ? map->start : cu_offset, | |
bcd213b2 NC |
2238 | pointer_size, offset_size, dwarf_version, |
2239 | is_signed, nesting + 1); | |
2240 | } | |
ec1b0fbb NC |
2241 | break; |
2242 | ||
2243 | case DW_AT_encoding: | |
2244 | /* Determine signness. */ | |
2245 | switch (uvalue) | |
2246 | { | |
2247 | case DW_ATE_address: | |
2248 | /* FIXME - some architectures have signed addresses. */ | |
2249 | case DW_ATE_boolean: | |
2250 | case DW_ATE_unsigned: | |
2251 | case DW_ATE_unsigned_char: | |
2252 | case DW_ATE_unsigned_fixed: | |
015dc7e1 | 2253 | * is_signed = false; |
ec1b0fbb NC |
2254 | break; |
2255 | ||
2256 | default: | |
2257 | case DW_ATE_complex_float: | |
2258 | case DW_ATE_float: | |
2259 | case DW_ATE_signed: | |
2260 | case DW_ATE_signed_char: | |
2261 | case DW_ATE_imaginary_float: | |
2262 | case DW_ATE_decimal_float: | |
2263 | case DW_ATE_signed_fixed: | |
015dc7e1 | 2264 | * is_signed = true; |
ec1b0fbb NC |
2265 | break; |
2266 | } | |
2267 | break; | |
2268 | } | |
2269 | } | |
2270 | } | |
2271 | ||
2272 | static void | |
015dc7e1 AM |
2273 | read_and_print_leb128 (unsigned char *data, |
2274 | unsigned int *bytes_read, | |
2275 | unsigned const char *end, | |
2276 | bool is_signed) | |
ec1b0fbb | 2277 | { |
cd30bcef AM |
2278 | int status; |
2279 | dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status); | |
2280 | if (status != 0) | |
1b513401 | 2281 | report_leb_status (status, __FILE__, __LINE__); |
ec1b0fbb | 2282 | else |
cd30bcef | 2283 | printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val)); |
ec1b0fbb NC |
2284 | } |
2285 | ||
2286 | static void | |
2287 | display_discr_list (unsigned long form, | |
2288 | dwarf_vma uvalue, | |
2289 | unsigned char * data, | |
2290 | unsigned const char * end, | |
2291 | int level) | |
2292 | { | |
2293 | if (uvalue == 0) | |
2294 | { | |
2295 | printf ("[default]"); | |
2296 | return; | |
2297 | } | |
521d4b19 | 2298 | |
ec1b0fbb NC |
2299 | switch (form) |
2300 | { | |
2301 | case DW_FORM_block: | |
2302 | case DW_FORM_block1: | |
2303 | case DW_FORM_block2: | |
2304 | case DW_FORM_block4: | |
2305 | /* Move data pointer back to the start of the byte array. */ | |
2306 | data -= uvalue; | |
2307 | break; | |
2308 | default: | |
2309 | printf ("<corrupt>\n"); | |
2310 | warn (_("corrupt discr_list - not using a block form\n")); | |
2311 | return; | |
2312 | } | |
2313 | ||
2314 | if (uvalue < 2) | |
2315 | { | |
2316 | printf ("<corrupt>\n"); | |
2317 | warn (_("corrupt discr_list - block not long enough\n")); | |
2318 | return; | |
2319 | } | |
2320 | ||
015dc7e1 | 2321 | bool is_signed = |
ec1b0fbb | 2322 | (level > 0 && level <= MAX_CU_NESTING) |
015dc7e1 | 2323 | ? level_type_signed [level - 1] : false; |
521d4b19 | 2324 | |
ec1b0fbb NC |
2325 | printf ("("); |
2326 | while (uvalue) | |
2327 | { | |
2328 | unsigned char discriminant; | |
2329 | unsigned int bytes_read; | |
2330 | ||
6d1ad6f7 | 2331 | SAFE_BYTE_GET_AND_INC (discriminant, data, 1, end); |
ec1b0fbb | 2332 | -- uvalue; |
ec1b0fbb NC |
2333 | |
2334 | assert (uvalue > 0); | |
2335 | switch (discriminant) | |
2336 | { | |
2337 | case DW_DSC_label: | |
2338 | printf ("label "); | |
2339 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2340 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2341 | uvalue -= bytes_read; | |
2342 | data += bytes_read; | |
2343 | break; | |
2344 | ||
2345 | case DW_DSC_range: | |
2346 | printf ("range "); | |
2347 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2348 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2349 | uvalue -= bytes_read; | |
2350 | data += bytes_read; | |
2351 | ||
2352 | printf (".."); | |
2353 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2354 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2355 | uvalue -= bytes_read; | |
2356 | data += bytes_read; | |
2357 | break; | |
2358 | ||
2359 | default: | |
2360 | printf ("<corrupt>\n"); | |
e38332c2 | 2361 | warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"), |
ec1b0fbb NC |
2362 | discriminant); |
2363 | return; | |
2364 | } | |
2365 | ||
2366 | if (uvalue) | |
2367 | printf (", "); | |
2368 | } | |
2369 | ||
2370 | if (is_signed) | |
2371 | printf (")(signed)"); | |
2372 | else | |
2373 | printf (")(unsigned)"); | |
2374 | } | |
2375 | ||
19e6b90e | 2376 | static unsigned char * |
dda8d76d NC |
2377 | read_and_display_attr_value (unsigned long attribute, |
2378 | unsigned long form, | |
2379 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2380 | unsigned char * start, |
dda8d76d NC |
2381 | unsigned char * data, |
2382 | unsigned char * end, | |
2383 | dwarf_vma cu_offset, | |
2384 | dwarf_vma pointer_size, | |
2385 | dwarf_vma offset_size, | |
2386 | int dwarf_version, | |
2387 | debug_info * debug_info_p, | |
2388 | int do_loc, | |
2389 | struct dwarf_section * section, | |
2390 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2391 | char delimiter, |
2392 | int level) | |
19e6b90e | 2393 | { |
cd30bcef | 2394 | dwarf_signed_vma svalue; |
af2ddf69 AM |
2395 | dwarf_vma uvalue = 0; |
2396 | dwarf_vma uvalue_hi = 0; | |
2397 | unsigned char *block_start = NULL; | |
2398 | unsigned char *orig_data = data; | |
19e6b90e | 2399 | |
f41e4712 | 2400 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2401 | { |
f41e4712 | 2402 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2403 | return data; |
2404 | } | |
2405 | ||
521d4b19 NC |
2406 | if (do_wide && ! do_loc) |
2407 | { | |
2408 | /* PR 26847: Display the name of the form. */ | |
2409 | const char * name = get_FORM_name (form); | |
2410 | ||
2411 | /* For convenience we skip the DW_FORM_ prefix to the name. */ | |
2412 | if (name[0] == 'D') | |
2413 | name += 8; /* strlen ("DW_FORM_") */ | |
2414 | printf ("%c(%s)", delimiter, name); | |
2415 | } | |
2416 | ||
19e6b90e L |
2417 | switch (form) |
2418 | { | |
2419 | default: | |
2420 | break; | |
2421 | ||
2422 | case DW_FORM_ref_addr: | |
2423 | if (dwarf_version == 2) | |
0c588247 | 2424 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
ec47b32a | 2425 | else if (dwarf_version > 2) |
0c588247 | 2426 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2427 | else |
ec47b32a | 2428 | error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); |
19e6b90e L |
2429 | break; |
2430 | ||
2431 | case DW_FORM_addr: | |
0c588247 | 2432 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2433 | break; |
2434 | ||
e38332c2 | 2435 | case DW_FORM_strp_sup: |
19e6b90e | 2436 | case DW_FORM_strp: |
77145576 | 2437 | case DW_FORM_line_strp: |
932fd279 | 2438 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2439 | case DW_FORM_GNU_ref_alt: |
2440 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2441 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2442 | break; |
2443 | ||
932fd279 JJ |
2444 | case DW_FORM_flag_present: |
2445 | uvalue = 1; | |
2446 | break; | |
2447 | ||
19e6b90e L |
2448 | case DW_FORM_ref1: |
2449 | case DW_FORM_flag: | |
2450 | case DW_FORM_data1: | |
32e4f96c TV |
2451 | case DW_FORM_strx1: |
2452 | case DW_FORM_addrx1: | |
0c588247 | 2453 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2454 | break; |
2455 | ||
2456 | case DW_FORM_ref2: | |
2457 | case DW_FORM_data2: | |
32e4f96c TV |
2458 | case DW_FORM_strx2: |
2459 | case DW_FORM_addrx2: | |
0c588247 | 2460 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2461 | break; |
2462 | ||
32e4f96c TV |
2463 | case DW_FORM_strx3: |
2464 | case DW_FORM_addrx3: | |
2465 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); | |
2466 | break; | |
2467 | ||
e38332c2 | 2468 | case DW_FORM_ref_sup4: |
19e6b90e L |
2469 | case DW_FORM_ref4: |
2470 | case DW_FORM_data4: | |
32e4f96c TV |
2471 | case DW_FORM_strx4: |
2472 | case DW_FORM_addrx4: | |
0c588247 | 2473 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2474 | break; |
2475 | ||
af2ddf69 AM |
2476 | case DW_FORM_ref_sup8: |
2477 | case DW_FORM_ref8: | |
2478 | case DW_FORM_data8: | |
2479 | case DW_FORM_ref_sig8: | |
2480 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); | |
2481 | break; | |
2482 | ||
2483 | case DW_FORM_data16: | |
2484 | SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); | |
2485 | SAFE_BYTE_GET_AND_INC (uvalue_hi, data, 8, end); | |
2486 | if (byte_get != byte_get_little_endian) | |
2487 | { | |
2488 | dwarf_vma utmp = uvalue; | |
2489 | uvalue = uvalue_hi; | |
2490 | uvalue_hi = utmp; | |
2491 | } | |
2492 | break; | |
2493 | ||
19e6b90e | 2494 | case DW_FORM_sdata: |
cd30bcef AM |
2495 | READ_SLEB (svalue, data, end); |
2496 | uvalue = svalue; | |
19e6b90e L |
2497 | break; |
2498 | ||
4723351a | 2499 | case DW_FORM_GNU_str_index: |
32e4f96c | 2500 | case DW_FORM_strx: |
19e6b90e L |
2501 | case DW_FORM_ref_udata: |
2502 | case DW_FORM_udata: | |
cd30bcef | 2503 | case DW_FORM_GNU_addr_index: |
32e4f96c | 2504 | case DW_FORM_addrx: |
cd30bcef | 2505 | READ_ULEB (uvalue, data, end); |
19e6b90e L |
2506 | break; |
2507 | ||
2508 | case DW_FORM_indirect: | |
cd30bcef | 2509 | READ_ULEB (form, data, end); |
19e6b90e | 2510 | if (!do_loc) |
ef0b5f1c | 2511 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 | 2512 | if (form == DW_FORM_implicit_const) |
cd30bcef | 2513 | READ_SLEB (implicit_const, data, end); |
ec1b0fbb NC |
2514 | return read_and_display_attr_value (attribute, form, implicit_const, |
2515 | start, data, end, | |
2516 | cu_offset, pointer_size, | |
19e6b90e | 2517 | offset_size, dwarf_version, |
ec4d4525 | 2518 | debug_info_p, do_loc, |
ec1b0fbb | 2519 | section, this_set, delimiter, level); |
c63fc368 NC |
2520 | |
2521 | case DW_FORM_implicit_const: | |
2522 | uvalue = implicit_const; | |
2523 | break; | |
19e6b90e L |
2524 | } |
2525 | ||
2526 | switch (form) | |
2527 | { | |
2528 | case DW_FORM_ref_addr: | |
2529 | if (!do_loc) | |
bcd213b2 | 2530 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2531 | break; |
2532 | ||
a081f3cd JJ |
2533 | case DW_FORM_GNU_ref_alt: |
2534 | if (!do_loc) | |
521d4b19 NC |
2535 | { |
2536 | if (do_wide) | |
2537 | /* We have already printed the form name. */ | |
2538 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); | |
2539 | else | |
2540 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); | |
2541 | } | |
dda8d76d | 2542 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2543 | break; |
2544 | ||
19e6b90e L |
2545 | case DW_FORM_ref1: |
2546 | case DW_FORM_ref2: | |
2547 | case DW_FORM_ref4: | |
e38332c2 | 2548 | case DW_FORM_ref_sup4: |
19e6b90e L |
2549 | case DW_FORM_ref_udata: |
2550 | if (!do_loc) | |
ef0b5f1c | 2551 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2552 | break; |
2553 | ||
2554 | case DW_FORM_data4: | |
2555 | case DW_FORM_addr: | |
932fd279 | 2556 | case DW_FORM_sec_offset: |
19e6b90e | 2557 | if (!do_loc) |
ef0b5f1c | 2558 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2559 | break; |
2560 | ||
932fd279 | 2561 | case DW_FORM_flag_present: |
19e6b90e L |
2562 | case DW_FORM_flag: |
2563 | case DW_FORM_data1: | |
2564 | case DW_FORM_data2: | |
2565 | case DW_FORM_sdata: | |
2566 | case DW_FORM_udata: | |
2567 | if (!do_loc) | |
ef0b5f1c | 2568 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2569 | break; |
2570 | ||
77145576 JK |
2571 | case DW_FORM_implicit_const: |
2572 | if (!do_loc) | |
2573 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2574 | break; | |
2575 | ||
e38332c2 | 2576 | case DW_FORM_ref_sup8: |
19e6b90e L |
2577 | case DW_FORM_ref8: |
2578 | case DW_FORM_data8: | |
2bc8690c | 2579 | if (!do_loc) |
19e6b90e | 2580 | { |
af2ddf69 | 2581 | dwarf_vma utmp = uvalue; |
a69c4772 | 2582 | if (form == DW_FORM_ref8) |
af2ddf69 AM |
2583 | utmp += cu_offset; |
2584 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", utmp)); | |
19e6b90e | 2585 | } |
19e6b90e L |
2586 | break; |
2587 | ||
2f6cd591 JK |
2588 | case DW_FORM_data16: |
2589 | if (!do_loc) | |
af2ddf69 AM |
2590 | printf (" 0x%s%s", |
2591 | uvalue_hi == 0 ? "" : dwarf_vmatoa ("x", uvalue_hi), | |
2592 | dwarf_vmatoa_1 ("x", uvalue, uvalue_hi == 0 ? 0 : 8)); | |
2f6cd591 JK |
2593 | break; |
2594 | ||
19e6b90e L |
2595 | case DW_FORM_string: |
2596 | if (!do_loc) | |
ef0b5f1c | 2597 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
a7077ce7 AM |
2598 | data += strnlen ((char *) data, end - data); |
2599 | if (data < end) | |
2600 | data++; | |
19e6b90e L |
2601 | break; |
2602 | ||
2603 | case DW_FORM_block: | |
932fd279 | 2604 | case DW_FORM_exprloc: |
cd30bcef AM |
2605 | READ_ULEB (uvalue, data, end); |
2606 | do_block: | |
2607 | block_start = data; | |
a1165289 NC |
2608 | if (block_start >= end) |
2609 | { | |
2610 | warn (_("Block ends prematurely\n")); | |
2611 | uvalue = 0; | |
2612 | block_start = end; | |
2613 | } | |
afc72f15 NC |
2614 | |
2615 | uvalue = check_uvalue (block_start, uvalue, end); | |
2616 | ||
19e6b90e L |
2617 | if (do_loc) |
2618 | data = block_start + uvalue; | |
2619 | else | |
ef0b5f1c | 2620 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2621 | break; |
2622 | ||
2623 | case DW_FORM_block1: | |
cd30bcef AM |
2624 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2625 | goto do_block; | |
19e6b90e L |
2626 | |
2627 | case DW_FORM_block2: | |
cd30bcef AM |
2628 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2629 | goto do_block; | |
19e6b90e L |
2630 | |
2631 | case DW_FORM_block4: | |
cd30bcef AM |
2632 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2633 | goto do_block; | |
19e6b90e L |
2634 | |
2635 | case DW_FORM_strp: | |
2636 | if (!do_loc) | |
521d4b19 NC |
2637 | { |
2638 | if (do_wide) | |
2639 | /* We have already displayed the form name. */ | |
2640 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2641 | dwarf_vmatoa ("x", uvalue), | |
2642 | fetch_indirect_string (uvalue)); | |
2643 | else | |
2644 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, | |
2645 | dwarf_vmatoa ("x", uvalue), | |
2646 | fetch_indirect_string (uvalue)); | |
2647 | } | |
19e6b90e L |
2648 | break; |
2649 | ||
77145576 JK |
2650 | case DW_FORM_line_strp: |
2651 | if (!do_loc) | |
521d4b19 NC |
2652 | { |
2653 | if (do_wide) | |
2654 | /* We have already displayed the form name. */ | |
2655 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2656 | dwarf_vmatoa ("x", uvalue), | |
2657 | fetch_indirect_line_string (uvalue)); | |
2658 | else | |
2659 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2660 | dwarf_vmatoa ("x", uvalue), | |
2661 | fetch_indirect_line_string (uvalue)); | |
2662 | } | |
77145576 JK |
2663 | break; |
2664 | ||
4723351a | 2665 | case DW_FORM_GNU_str_index: |
32e4f96c TV |
2666 | case DW_FORM_strx: |
2667 | case DW_FORM_strx1: | |
2668 | case DW_FORM_strx2: | |
2669 | case DW_FORM_strx3: | |
2670 | case DW_FORM_strx4: | |
4723351a | 2671 | if (!do_loc) |
b4eb7656 | 2672 | { |
63b4cc53 | 2673 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 2674 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
b4eb7656 | 2675 | |
521d4b19 NC |
2676 | if (do_wide) |
2677 | /* We have already displayed the form name. */ | |
2678 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2679 | dwarf_vmatoa ("x", uvalue), | |
2680 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2681 | else | |
2682 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, | |
2683 | dwarf_vmatoa ("x", uvalue), | |
2684 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
b4eb7656 | 2685 | } |
4723351a CC |
2686 | break; |
2687 | ||
a081f3cd JJ |
2688 | case DW_FORM_GNU_strp_alt: |
2689 | if (!do_loc) | |
dda8d76d | 2690 | { |
521d4b19 NC |
2691 | if (do_wide) |
2692 | /* We have already displayed the form name. */ | |
2693 | printf (_("%c(offset: 0x%s) %s"), delimiter, | |
2694 | dwarf_vmatoa ("x", uvalue), | |
2695 | fetch_alt_indirect_string (uvalue)); | |
2696 | else | |
2697 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2698 | dwarf_vmatoa ("x", uvalue), | |
2699 | fetch_alt_indirect_string (uvalue)); | |
dda8d76d | 2700 | } |
a081f3cd JJ |
2701 | break; |
2702 | ||
19e6b90e L |
2703 | case DW_FORM_indirect: |
2704 | /* Handled above. */ | |
2705 | break; | |
2706 | ||
2b6f5997 CC |
2707 | case DW_FORM_ref_sig8: |
2708 | if (!do_loc) | |
af2ddf69 AM |
2709 | printf ("%c%s: 0x%s", delimiter, do_wide ? "" : "signature", |
2710 | dwarf_vmatoa ("x", uvalue)); | |
2b6f5997 CC |
2711 | break; |
2712 | ||
4723351a | 2713 | case DW_FORM_GNU_addr_index: |
32e4f96c TV |
2714 | case DW_FORM_addrx: |
2715 | case DW_FORM_addrx1: | |
2716 | case DW_FORM_addrx2: | |
2717 | case DW_FORM_addrx3: | |
2718 | case DW_FORM_addrx4: | |
4723351a | 2719 | if (!do_loc) |
521d4b19 | 2720 | { |
32e4f96c TV |
2721 | dwarf_vma base; |
2722 | dwarf_vma offset; | |
2723 | ||
2724 | if (debug_info_p == NULL) | |
2725 | base = 0; | |
2726 | else if (debug_info_p->addr_base == DEBUG_INFO_UNAVAILABLE) | |
2727 | base = 0; | |
2728 | else | |
2729 | base = debug_info_p->addr_base; | |
2730 | ||
2731 | offset = base + uvalue * pointer_size; | |
2732 | ||
521d4b19 NC |
2733 | if (do_wide) |
2734 | /* We have already displayed the form name. */ | |
2735 | printf (_("%c(index: 0x%s): %s"), delimiter, | |
2736 | dwarf_vmatoa ("x", uvalue), | |
32e4f96c | 2737 | fetch_indexed_value (offset, pointer_size)); |
521d4b19 NC |
2738 | else |
2739 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, | |
2740 | dwarf_vmatoa ("x", uvalue), | |
32e4f96c | 2741 | fetch_indexed_value (offset, pointer_size)); |
521d4b19 | 2742 | } |
4723351a CC |
2743 | break; |
2744 | ||
e38332c2 NC |
2745 | case DW_FORM_strp_sup: |
2746 | if (!do_loc) | |
2747 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); | |
2748 | break; | |
2749 | ||
19e6b90e | 2750 | default: |
e38332c2 | 2751 | warn (_("Unrecognized form: 0x%lx\n"), form); |
19e6b90e L |
2752 | break; |
2753 | } | |
2754 | ||
19e6b90e | 2755 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2756 | && num_debug_info_entries == 0 |
2757 | && debug_info_p != NULL) | |
19e6b90e L |
2758 | { |
2759 | switch (attribute) | |
2760 | { | |
2761 | case DW_AT_frame_base: | |
2762 | have_frame_base = 1; | |
1a0670f3 | 2763 | /* Fall through. */ |
19e6b90e | 2764 | case DW_AT_location: |
9f272209 | 2765 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2766 | case DW_AT_string_length: |
2767 | case DW_AT_return_addr: | |
19e6b90e L |
2768 | case DW_AT_data_member_location: |
2769 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2770 | case DW_AT_segment: |
2771 | case DW_AT_static_link: | |
2772 | case DW_AT_use_location: | |
bc0a77d2 | 2773 | case DW_AT_call_value: |
629e7ca8 | 2774 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2775 | case DW_AT_call_data_value: |
629e7ca8 | 2776 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2777 | case DW_AT_call_target: |
629e7ca8 | 2778 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2779 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2780 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2781 | if ((dwarf_version < 4 |
212b6063 | 2782 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2783 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2784 | { |
2785 | /* Process location list. */ | |
91d6fa6a | 2786 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2787 | unsigned int num = debug_info_p->num_loc_offsets; |
2788 | ||
91d6fa6a | 2789 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2790 | { |
91d6fa6a | 2791 | lmax += 1024; |
467c65bc | 2792 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2793 | xcrealloc (debug_info_p->loc_offsets, |
2794 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2795 | debug_info_p->loc_views = (dwarf_vma *) |
2796 | xcrealloc (debug_info_p->loc_views, | |
2797 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2798 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2799 | xcrealloc (debug_info_p->have_frame_base, |
2800 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2801 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2802 | } |
341f9135 | 2803 | if (this_set != NULL) |
b4eb7656 | 2804 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2805 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2806 | if (attribute != DW_AT_GNU_locviews) |
2807 | { | |
a7504f87 NC |
2808 | /* Corrupt DWARF info can produce more offsets than views. |
2809 | See PR 23062 for an example. */ | |
2810 | if (debug_info_p->num_loc_offsets | |
2811 | > debug_info_p->num_loc_views) | |
2812 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2813 | else | |
2814 | { | |
2815 | debug_info_p->loc_offsets [num] = uvalue; | |
2816 | debug_info_p->num_loc_offsets++; | |
2817 | } | |
9f272209 AO |
2818 | } |
2819 | else | |
2820 | { | |
2821 | assert (debug_info_p->num_loc_views <= num); | |
2822 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2823 | if (num > debug_info_p->num_loc_offsets) |
2824 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2825 | else | |
2826 | { | |
2827 | debug_info_p->loc_views [num] = uvalue; | |
2828 | debug_info_p->num_loc_views++; | |
2829 | } | |
9f272209 | 2830 | } |
19e6b90e L |
2831 | } |
2832 | break; | |
e2a0d921 | 2833 | |
19e6b90e L |
2834 | case DW_AT_low_pc: |
2835 | if (need_base_address) | |
2836 | debug_info_p->base_address = uvalue; | |
2837 | break; | |
2838 | ||
4723351a | 2839 | case DW_AT_GNU_addr_base: |
32e4f96c | 2840 | case DW_AT_addr_base: |
b4eb7656 | 2841 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2842 | break; |
2843 | ||
2844 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2845 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2846 | break; |
2847 | ||
19e6b90e | 2848 | case DW_AT_ranges: |
b4eb7656 | 2849 | if ((dwarf_version < 4 |
212b6063 | 2850 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2851 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2852 | { |
2853 | /* Process range list. */ | |
91d6fa6a | 2854 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2855 | unsigned int num = debug_info_p->num_range_lists; |
2856 | ||
91d6fa6a | 2857 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2858 | { |
91d6fa6a | 2859 | lmax += 1024; |
467c65bc | 2860 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2861 | xcrealloc (debug_info_p->range_lists, |
2862 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2863 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2864 | } |
2865 | debug_info_p->range_lists [num] = uvalue; | |
2866 | debug_info_p->num_range_lists++; | |
2867 | } | |
2868 | break; | |
2869 | ||
d85bf2ba NC |
2870 | case DW_AT_GNU_dwo_name: |
2871 | case DW_AT_dwo_name: | |
2872 | if (need_dwo_info) | |
2873 | switch (form) | |
2874 | { | |
2875 | case DW_FORM_strp: | |
50ea0877 | 2876 | add_dwo_name ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 2877 | break; |
5568cc9e | 2878 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 2879 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 2880 | break; |
d85bf2ba | 2881 | case DW_FORM_GNU_str_index: |
32e4f96c TV |
2882 | case DW_FORM_strx: |
2883 | case DW_FORM_strx1: | |
2884 | case DW_FORM_strx2: | |
2885 | case DW_FORM_strx3: | |
2886 | case DW_FORM_strx4: | |
015dc7e1 | 2887 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset); |
d85bf2ba NC |
2888 | break; |
2889 | case DW_FORM_string: | |
50ea0877 | 2890 | add_dwo_name ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
2891 | break; |
2892 | default: | |
2893 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2894 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2895 | break; |
2896 | } | |
2897 | break; | |
521d4b19 | 2898 | |
d85bf2ba NC |
2899 | case DW_AT_comp_dir: |
2900 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2901 | if (need_dwo_info) | |
2902 | switch (form) | |
2903 | { | |
2904 | case DW_FORM_strp: | |
50ea0877 | 2905 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 2906 | break; |
5568cc9e | 2907 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 2908 | add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 2909 | break; |
d85bf2ba | 2910 | case DW_FORM_line_strp: |
50ea0877 | 2911 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue), cu_offset); |
d85bf2ba NC |
2912 | break; |
2913 | case DW_FORM_GNU_str_index: | |
32e4f96c TV |
2914 | case DW_FORM_strx: |
2915 | case DW_FORM_strx1: | |
2916 | case DW_FORM_strx2: | |
2917 | case DW_FORM_strx3: | |
2918 | case DW_FORM_strx4: | |
015dc7e1 | 2919 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset); |
d85bf2ba NC |
2920 | break; |
2921 | case DW_FORM_string: | |
50ea0877 | 2922 | add_dwo_dir ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
2923 | break; |
2924 | default: | |
2925 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2926 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2927 | break; |
2928 | } | |
2929 | break; | |
521d4b19 | 2930 | |
d85bf2ba NC |
2931 | case DW_AT_GNU_dwo_id: |
2932 | if (need_dwo_info) | |
2933 | switch (form) | |
2934 | { | |
2935 | case DW_FORM_data8: | |
24841daa | 2936 | /* FIXME: Record the length of the ID as well ? */ |
50ea0877 | 2937 | add_dwo_id ((const char *) (data - 8), cu_offset); |
d85bf2ba NC |
2938 | break; |
2939 | default: | |
2940 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2941 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2942 | break; |
2943 | } | |
2944 | break; | |
521d4b19 | 2945 | |
19e6b90e L |
2946 | default: |
2947 | break; | |
2948 | } | |
2949 | } | |
2950 | ||
4ccf1e31 | 2951 | if (do_loc || attribute == 0) |
19e6b90e L |
2952 | return data; |
2953 | ||
ec4d4525 | 2954 | /* For some attributes we can display further information. */ |
19e6b90e L |
2955 | switch (attribute) |
2956 | { | |
ec1b0fbb | 2957 | case DW_AT_type: |
b3fe587e AM |
2958 | if (level >= 0 && level < MAX_CU_NESTING |
2959 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb | 2960 | { |
015dc7e1 AM |
2961 | bool is_signed = false; |
2962 | abbrev_entry *type_abbrev; | |
2963 | unsigned char *type_data; | |
1b3892be | 2964 | abbrev_map *map; |
521d4b19 | 2965 | |
bcd213b2 | 2966 | type_abbrev = get_type_abbrev_from_form (form, uvalue, cu_offset, |
1b3892be | 2967 | section, NULL, &type_data, &map); |
bcd213b2 NC |
2968 | if (type_abbrev != NULL) |
2969 | { | |
1b3892be AM |
2970 | get_type_signedness (type_abbrev, section, type_data, |
2971 | map ? section->start + map->end : end, | |
2972 | map ? map->start : cu_offset, | |
bcd213b2 NC |
2973 | pointer_size, offset_size, dwarf_version, |
2974 | & is_signed, 0); | |
2975 | } | |
ec1b0fbb NC |
2976 | level_type_signed[level] = is_signed; |
2977 | } | |
2978 | break; | |
521d4b19 | 2979 | |
19e6b90e | 2980 | case DW_AT_inline: |
2e9e81a8 | 2981 | printf ("\t"); |
19e6b90e L |
2982 | switch (uvalue) |
2983 | { | |
2984 | case DW_INL_not_inlined: | |
2985 | printf (_("(not inlined)")); | |
2986 | break; | |
2987 | case DW_INL_inlined: | |
2988 | printf (_("(inlined)")); | |
2989 | break; | |
2990 | case DW_INL_declared_not_inlined: | |
2991 | printf (_("(declared as inline but ignored)")); | |
2992 | break; | |
2993 | case DW_INL_declared_inlined: | |
2994 | printf (_("(declared as inline and inlined)")); | |
2995 | break; | |
2996 | default: | |
47704ddf KT |
2997 | printf (_(" (Unknown inline attribute value: %s)"), |
2998 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2999 | break; |
3000 | } | |
3001 | break; | |
3002 | ||
3003 | case DW_AT_language: | |
2e9e81a8 | 3004 | printf ("\t"); |
19e6b90e L |
3005 | switch (uvalue) |
3006 | { | |
4b78141a | 3007 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 3008 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
3009 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
3010 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 3011 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
3012 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
3013 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
3014 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
3015 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 3016 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 3017 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 3018 | /* DWARF 2.1 values. */ |
4b78141a | 3019 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
3020 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
3021 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
3022 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
3023 | /* DWARF 3 values. */ |
3024 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
3025 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
3026 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
3027 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
3028 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
3029 | /* DWARF 4 values. */ |
3030 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 3031 | /* DWARF 5 values. */ |
2008a0db | 3032 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 3033 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
3034 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
3035 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
3036 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 3037 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
3038 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
3039 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 3040 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
3041 | case DW_LANG_Swift: printf ("(Swift)"); break; |
3042 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
3043 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 3044 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
3045 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
3046 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 3047 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
3048 | /* MIPS extension. */ |
3049 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
3050 | /* UPC extension. */ | |
3051 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
3052 | default: | |
4b78141a | 3053 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 3054 | printf (_("(implementation defined: %s)"), |
467c65bc | 3055 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 3056 | else |
9cf03b7e | 3057 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
3058 | break; |
3059 | } | |
3060 | break; | |
3061 | ||
3062 | case DW_AT_encoding: | |
2e9e81a8 | 3063 | printf ("\t"); |
19e6b90e L |
3064 | switch (uvalue) |
3065 | { | |
3066 | case DW_ATE_void: printf ("(void)"); break; | |
3067 | case DW_ATE_address: printf ("(machine address)"); break; | |
3068 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
3069 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
3070 | case DW_ATE_float: printf ("(float)"); break; | |
3071 | case DW_ATE_signed: printf ("(signed)"); break; | |
3072 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
3073 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
3074 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 3075 | /* DWARF 2.1 values: */ |
19e6b90e L |
3076 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
3077 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
3078 | /* DWARF 3 values: */ |
3079 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
3080 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
3081 | case DW_ATE_edited: printf ("(edited)"); break; | |
3082 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
3083 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
3084 | /* DWARF 4 values: */ |
3085 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
3086 | /* DWARF 5 values: */ | |
3087 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
3088 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
3089 | ||
e2a0d921 NC |
3090 | /* HP extensions: */ |
3091 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
3092 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
3093 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
3094 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
3095 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
3096 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
3097 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
3098 | ||
19e6b90e L |
3099 | default: |
3100 | if (uvalue >= DW_ATE_lo_user | |
3101 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 3102 | printf (_("(user defined type)")); |
19e6b90e | 3103 | else |
9cf03b7e | 3104 | printf (_("(unknown type)")); |
19e6b90e L |
3105 | break; |
3106 | } | |
3107 | break; | |
3108 | ||
3109 | case DW_AT_accessibility: | |
2e9e81a8 | 3110 | printf ("\t"); |
19e6b90e L |
3111 | switch (uvalue) |
3112 | { | |
3113 | case DW_ACCESS_public: printf ("(public)"); break; | |
3114 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
3115 | case DW_ACCESS_private: printf ("(private)"); break; | |
3116 | default: | |
9cf03b7e | 3117 | printf (_("(unknown accessibility)")); |
19e6b90e L |
3118 | break; |
3119 | } | |
3120 | break; | |
3121 | ||
3122 | case DW_AT_visibility: | |
2e9e81a8 | 3123 | printf ("\t"); |
19e6b90e L |
3124 | switch (uvalue) |
3125 | { | |
3126 | case DW_VIS_local: printf ("(local)"); break; | |
3127 | case DW_VIS_exported: printf ("(exported)"); break; | |
3128 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 3129 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
3130 | } |
3131 | break; | |
3132 | ||
04914e37 NC |
3133 | case DW_AT_endianity: |
3134 | printf ("\t"); | |
3135 | switch (uvalue) | |
3136 | { | |
3137 | case DW_END_default: printf ("(default)"); break; | |
3138 | case DW_END_big: printf ("(big)"); break; | |
3139 | case DW_END_little: printf ("(little)"); break; | |
3140 | default: | |
3141 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
3142 | printf (_("(user specified)")); | |
3143 | else | |
3144 | printf (_("(unknown endianity)")); | |
3145 | break; | |
3146 | } | |
3147 | break; | |
3148 | ||
19e6b90e | 3149 | case DW_AT_virtuality: |
2e9e81a8 | 3150 | printf ("\t"); |
19e6b90e L |
3151 | switch (uvalue) |
3152 | { | |
3153 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
3154 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
3155 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 3156 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
3157 | } |
3158 | break; | |
3159 | ||
3160 | case DW_AT_identifier_case: | |
2e9e81a8 | 3161 | printf ("\t"); |
19e6b90e L |
3162 | switch (uvalue) |
3163 | { | |
3164 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
3165 | case DW_ID_up_case: printf ("(up_case)"); break; | |
3166 | case DW_ID_down_case: printf ("(down_case)"); break; | |
3167 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 3168 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
3169 | } |
3170 | break; | |
3171 | ||
3172 | case DW_AT_calling_convention: | |
2e9e81a8 | 3173 | printf ("\t"); |
19e6b90e L |
3174 | switch (uvalue) |
3175 | { | |
3176 | case DW_CC_normal: printf ("(normal)"); break; | |
3177 | case DW_CC_program: printf ("(program)"); break; | |
3178 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
3179 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
3180 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
3181 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
3182 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
3183 | default: |
3184 | if (uvalue >= DW_CC_lo_user | |
3185 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 3186 | printf (_("(user defined)")); |
19e6b90e | 3187 | else |
9cf03b7e | 3188 | printf (_("(unknown convention)")); |
19e6b90e L |
3189 | } |
3190 | break; | |
3191 | ||
3192 | case DW_AT_ordering: | |
2e9e81a8 | 3193 | printf ("\t"); |
19e6b90e L |
3194 | switch (uvalue) |
3195 | { | |
04914e37 | 3196 | case 255: |
9cf03b7e | 3197 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
3198 | case 0: printf ("(row major)"); break; |
3199 | case 1: printf ("(column major)"); break; | |
3200 | } | |
3201 | break; | |
3202 | ||
04914e37 NC |
3203 | case DW_AT_decimal_sign: |
3204 | printf ("\t"); | |
3205 | switch (uvalue) | |
3206 | { | |
3207 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
3208 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
3209 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
3210 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
3211 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
3212 | default: printf (_("(unrecognised)")); break; | |
3213 | } | |
3214 | break; | |
3215 | ||
3216 | case DW_AT_defaulted: | |
3217 | printf ("\t"); | |
3218 | switch (uvalue) | |
3219 | { | |
3220 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
3221 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
3222 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
3223 | default: printf (_("(unrecognised)")); break; | |
3224 | } | |
3225 | break; | |
3226 | ||
3227 | case DW_AT_discr_list: | |
3228 | printf ("\t"); | |
ec1b0fbb | 3229 | display_discr_list (form, uvalue, data, end, level); |
04914e37 | 3230 | break; |
521d4b19 | 3231 | |
19e6b90e L |
3232 | case DW_AT_frame_base: |
3233 | have_frame_base = 1; | |
1a0670f3 | 3234 | /* Fall through. */ |
19e6b90e | 3235 | case DW_AT_location: |
e2a0d921 NC |
3236 | case DW_AT_string_length: |
3237 | case DW_AT_return_addr: | |
19e6b90e L |
3238 | case DW_AT_data_member_location: |
3239 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
3240 | case DW_AT_segment: |
3241 | case DW_AT_static_link: | |
3242 | case DW_AT_use_location: | |
bc0a77d2 | 3243 | case DW_AT_call_value: |
629e7ca8 | 3244 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 3245 | case DW_AT_call_data_value: |
629e7ca8 | 3246 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 3247 | case DW_AT_call_target: |
629e7ca8 | 3248 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 3249 | case DW_AT_call_target_clobbered: |
629e7ca8 | 3250 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 3251 | if ((dwarf_version < 4 |
b4eb7656 | 3252 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 3253 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 3254 | printf (_(" (location list)")); |
e2a0d921 | 3255 | /* Fall through. */ |
19e6b90e L |
3256 | case DW_AT_allocated: |
3257 | case DW_AT_associated: | |
3258 | case DW_AT_data_location: | |
3259 | case DW_AT_stride: | |
3260 | case DW_AT_upper_bound: | |
cecf136e | 3261 | case DW_AT_lower_bound: |
19e6b90e L |
3262 | if (block_start) |
3263 | { | |
3264 | int need_frame_base; | |
3265 | ||
2e9e81a8 | 3266 | printf ("\t("); |
19e6b90e L |
3267 | need_frame_base = decode_location_expression (block_start, |
3268 | pointer_size, | |
b7807392 JJ |
3269 | offset_size, |
3270 | dwarf_version, | |
19e6b90e | 3271 | uvalue, |
f1c4cc75 | 3272 | cu_offset, section); |
19e6b90e L |
3273 | printf (")"); |
3274 | if (need_frame_base && !have_frame_base) | |
3275 | printf (_(" [without DW_AT_frame_base]")); | |
3276 | } | |
19e6b90e L |
3277 | break; |
3278 | ||
c54207d3 NC |
3279 | case DW_AT_data_bit_offset: |
3280 | case DW_AT_byte_size: | |
3281 | case DW_AT_bit_size: | |
3282 | case DW_AT_string_length_byte_size: | |
3283 | case DW_AT_string_length_bit_size: | |
3284 | case DW_AT_bit_stride: | |
3285 | if (form == DW_FORM_exprloc) | |
3286 | { | |
3287 | printf ("\t("); | |
3288 | (void) decode_location_expression (block_start, pointer_size, | |
3289 | offset_size, dwarf_version, | |
3290 | uvalue, cu_offset, section); | |
3291 | printf (")"); | |
3292 | } | |
3293 | break; | |
3294 | ||
ec4d4525 NC |
3295 | case DW_AT_import: |
3296 | { | |
bcd213b2 NC |
3297 | unsigned long abbrev_number; |
3298 | abbrev_entry *entry; | |
2b6f5997 | 3299 | |
bcd213b2 NC |
3300 | entry = get_type_abbrev_from_form (form, uvalue, cu_offset, |
3301 | section, & abbrev_number, NULL, NULL); | |
3302 | if (entry == NULL) | |
3303 | { | |
3304 | if (form != DW_FORM_GNU_ref_alt) | |
3305 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), | |
3306 | dwarf_vmatoa ("x", uvalue), | |
3307 | (unsigned long) (orig_data - section->start)); | |
3308 | } | |
6e3d6dc1 NC |
3309 | else |
3310 | { | |
2e9e81a8 | 3311 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
bcd213b2 | 3312 | printf (" (%s)", get_TAG_name (entry->tag)); |
6e3d6dc1 NC |
3313 | printf ("]"); |
3314 | } | |
ec4d4525 NC |
3315 | } |
3316 | break; | |
3317 | ||
19e6b90e L |
3318 | default: |
3319 | break; | |
3320 | } | |
3321 | ||
3322 | return data; | |
3323 | } | |
3324 | ||
19e6b90e | 3325 | static unsigned char * |
dda8d76d NC |
3326 | read_and_display_attr (unsigned long attribute, |
3327 | unsigned long form, | |
3328 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 3329 | unsigned char * start, |
dda8d76d NC |
3330 | unsigned char * data, |
3331 | unsigned char * end, | |
3332 | dwarf_vma cu_offset, | |
3333 | dwarf_vma pointer_size, | |
3334 | dwarf_vma offset_size, | |
3335 | int dwarf_version, | |
3336 | debug_info * debug_info_p, | |
3337 | int do_loc, | |
3338 | struct dwarf_section * section, | |
ec1b0fbb NC |
3339 | struct cu_tu_set * this_set, |
3340 | int level) | |
19e6b90e L |
3341 | { |
3342 | if (!do_loc) | |
750f03b7 | 3343 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
3344 | data = read_and_display_attr_value (attribute, form, implicit_const, |
3345 | start, data, end, | |
f6f0e17b | 3346 | cu_offset, pointer_size, offset_size, |
19e6b90e | 3347 | dwarf_version, debug_info_p, |
ec1b0fbb | 3348 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
3349 | if (!do_loc) |
3350 | printf ("\n"); | |
3351 | return data; | |
3352 | } | |
3353 | ||
dda8d76d | 3354 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
3355 | following debug links, then attempt to load the requested section |
3356 | from one of the separate debug info files. */ | |
dda8d76d | 3357 | |
015dc7e1 | 3358 | static bool |
dda8d76d | 3359 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, |
24841daa | 3360 | void * handle) |
dda8d76d | 3361 | { |
24841daa | 3362 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3363 | { |
24841daa NC |
3364 | if (debug_displays[sec_enum].section.filename == NULL) |
3365 | { | |
3366 | /* See if we can associate a filename with this section. */ | |
3367 | separate_info * i; | |
3368 | ||
3369 | for (i = first_separate_info; i != NULL; i = i->next) | |
3370 | if (i->handle == handle) | |
3371 | { | |
3372 | debug_displays[sec_enum].section.filename = i->filename; | |
3373 | break; | |
3374 | } | |
3375 | } | |
3376 | ||
015dc7e1 | 3377 | return true; |
dda8d76d NC |
3378 | } |
3379 | ||
24841daa NC |
3380 | if (do_follow_links) |
3381 | { | |
3382 | separate_info * i; | |
3383 | ||
3384 | for (i = first_separate_info; i != NULL; i = i->next) | |
3385 | { | |
3386 | if (load_debug_section (sec_enum, i->handle)) | |
3387 | { | |
3388 | debug_displays[sec_enum].section.filename = i->filename; | |
3389 | ||
3390 | /* FIXME: We should check to see if any of the remaining debug info | |
3391 | files also contain this section, and, umm, do something about it. */ | |
015dc7e1 | 3392 | return true; |
24841daa NC |
3393 | } |
3394 | } | |
3395 | } | |
dda8d76d | 3396 | |
015dc7e1 | 3397 | return false; |
dda8d76d NC |
3398 | } |
3399 | ||
3400 | static void | |
015dc7e1 | 3401 | introduce (struct dwarf_section * section, bool raw) |
dda8d76d NC |
3402 | { |
3403 | if (raw) | |
3404 | { | |
3405 | if (do_follow_links && section->filename) | |
3406 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3407 | section->name, section->filename); | |
3408 | else | |
3409 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3410 | } | |
3411 | else | |
3412 | { | |
3413 | if (do_follow_links && section->filename) | |
3414 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3415 | section->name, section->filename); | |
3416 | else | |
3417 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3418 | } | |
3419 | } | |
521d4b19 | 3420 | |
d85bf2ba NC |
3421 | /* Process the contents of a .debug_info section. |
3422 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3423 | and we do not want to display anything to the user. | |
3424 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3425 | a .debug_info section. | |
3426 | The information displayed is restricted by the values in DWARF_START_DIE | |
3427 | and DWARF_CUTOFF_LEVEL. | |
3428 | Returns TRUE upon success. Otherwise an error or warning message is | |
3429 | printed and FALSE is returned. */ | |
19e6b90e | 3430 | |
015dc7e1 AM |
3431 | static bool |
3432 | process_debug_info (struct dwarf_section * section, | |
3433 | void *file, | |
3434 | enum dwarf_section_display_enum abbrev_sec, | |
3435 | bool do_loc, | |
3436 | bool do_types) | |
19e6b90e L |
3437 | { |
3438 | unsigned char *start = section->start; | |
3439 | unsigned char *end = start + section->size; | |
3440 | unsigned char *section_begin; | |
3441 | unsigned int unit; | |
3442 | unsigned int num_units = 0; | |
3443 | ||
edba4e4a AM |
3444 | /* First scan the section to get the number of comp units. |
3445 | Length sanity checks are done here. */ | |
3446 | for (section_begin = start, num_units = 0; section_begin < end; | |
3447 | num_units ++) | |
19e6b90e | 3448 | { |
767221a9 | 3449 | dwarf_vma length; |
19e6b90e | 3450 | |
edba4e4a AM |
3451 | /* Read the first 4 bytes. For a 32-bit DWARF section, this |
3452 | will be the length. For a 64-bit DWARF section, it'll be | |
3453 | the escape code 0xffffffff followed by an 8 byte length. */ | |
3454 | SAFE_BYTE_GET_AND_INC (length, section_begin, 4, end); | |
aca88567 | 3455 | |
edba4e4a AM |
3456 | if (length == 0xffffffff) |
3457 | SAFE_BYTE_GET_AND_INC (length, section_begin, 8, end); | |
3458 | else if (length >= 0xfffffff0 && length < 0xffffffff) | |
3459 | { | |
3460 | warn (_("Reserved length value (0x%s) found in section %s\n"), | |
3461 | dwarf_vmatoa ("x", length), section->name); | |
3462 | return false; | |
19e6b90e L |
3463 | } |
3464 | ||
edba4e4a AM |
3465 | /* Negative values are illegal, they may even cause infinite |
3466 | looping. This can happen if we can't accurately apply | |
3467 | relocations to an object file, or if the file is corrupt. */ | |
3468 | if (length > (size_t) (end - section_begin)) | |
19e6b90e | 3469 | { |
edba4e4a AM |
3470 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3471 | dwarf_vmatoa ("x", length), section->name); | |
015dc7e1 | 3472 | return false; |
19e6b90e | 3473 | } |
edba4e4a AM |
3474 | section_begin += length; |
3475 | } | |
3476 | ||
3477 | if (num_units == 0) | |
3478 | { | |
3479 | error (_("No comp units in %s section ?\n"), section->name); | |
3480 | return false; | |
3481 | } | |
3482 | ||
3483 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
3484 | && num_debug_info_entries == 0 | |
3485 | && ! do_types) | |
3486 | { | |
19e6b90e L |
3487 | |
3488 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3489 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3490 | sizeof (* debug_information)); |
19e6b90e L |
3491 | if (debug_information == NULL) |
3492 | { | |
f41e4712 | 3493 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3494 | num_units); |
82b1b41b | 3495 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
015dc7e1 | 3496 | return false; |
19e6b90e | 3497 | } |
d85bf2ba | 3498 | |
03a91817 NC |
3499 | /* PR 17531: file: 92ca3797. |
3500 | We cannot rely upon the debug_information array being initialised | |
3501 | before it is used. A corrupt file could easily contain references | |
3502 | to a unit for which information has not been made available. So | |
3503 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3504 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3505 | ||
82b1b41b | 3506 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3507 | } |
3508 | ||
3509 | if (!do_loc) | |
3510 | { | |
dda8d76d NC |
3511 | load_debug_section_with_follow (str, file); |
3512 | load_debug_section_with_follow (line_str, file); | |
3513 | load_debug_section_with_follow (str_dwo, file); | |
3514 | load_debug_section_with_follow (str_index, file); | |
3515 | load_debug_section_with_follow (str_index_dwo, file); | |
3516 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e | 3517 | } |
521d4b19 | 3518 | |
dda8d76d | 3519 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3520 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3521 | { |
3522 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3523 | debug_displays [abbrev_sec].section.uncompressed_name); |
015dc7e1 | 3524 | return false; |
19e6b90e L |
3525 | } |
3526 | ||
dda8d76d | 3527 | if (!do_loc && dwarf_start_die == 0) |
015dc7e1 | 3528 | introduce (section, false); |
bcd213b2 NC |
3529 | |
3530 | free_all_abbrevs (); | |
3531 | free (cu_abbrev_map); | |
3532 | cu_abbrev_map = NULL; | |
3533 | next_free_abbrev_map_entry = 0; | |
521d4b19 | 3534 | |
bcd213b2 NC |
3535 | /* In order to be able to resolve DW_FORM_ref_attr forms we need |
3536 | to load *all* of the abbrevs for all CUs in this .debug_info | |
3537 | section. This does effectively mean that we (partially) read | |
3538 | every CU header twice. */ | |
3539 | for (section_begin = start; start < end;) | |
3540 | { | |
3541 | DWARF2_Internal_CompUnit compunit; | |
3542 | unsigned char * hdrptr; | |
76868f36 L |
3543 | dwarf_vma abbrev_base; |
3544 | size_t abbrev_size; | |
bcd213b2 NC |
3545 | dwarf_vma cu_offset; |
3546 | unsigned int offset_size; | |
bcd213b2 NC |
3547 | struct cu_tu_set * this_set; |
3548 | abbrev_list * list; | |
edba4e4a | 3549 | unsigned char *end_cu; |
bcd213b2 NC |
3550 | |
3551 | hdrptr = start; | |
edba4e4a | 3552 | cu_offset = start - section_begin; |
bcd213b2 NC |
3553 | |
3554 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); | |
3555 | ||
3556 | if (compunit.cu_length == 0xffffffff) | |
3557 | { | |
3558 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); | |
3559 | offset_size = 8; | |
bcd213b2 NC |
3560 | } |
3561 | else | |
edba4e4a AM |
3562 | offset_size = 4; |
3563 | end_cu = hdrptr + compunit.cu_length; | |
bcd213b2 | 3564 | |
edba4e4a | 3565 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu); |
bcd213b2 NC |
3566 | |
3567 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); | |
3568 | ||
3569 | if (compunit.cu_version < 5) | |
3570 | { | |
3571 | compunit.cu_unit_type = DW_UT_compile; | |
3572 | /* Initialize it due to a false compiler warning. */ | |
3573 | compunit.cu_pointer_size = -1; | |
3574 | } | |
3575 | else | |
3576 | { | |
edba4e4a | 3577 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu); |
bcd213b2 NC |
3578 | do_types = (compunit.cu_unit_type == DW_UT_type); |
3579 | ||
edba4e4a | 3580 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
bcd213b2 NC |
3581 | } |
3582 | ||
edba4e4a AM |
3583 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, |
3584 | end_cu); | |
bcd213b2 | 3585 | |
9b87f84a TV |
3586 | if (compunit.cu_unit_type == DW_UT_split_compile |
3587 | || compunit.cu_unit_type == DW_UT_skeleton) | |
3588 | { | |
3589 | uint64_t dwo_id; | |
edba4e4a | 3590 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu); |
9b87f84a TV |
3591 | } |
3592 | ||
76868f36 L |
3593 | if (this_set == NULL) |
3594 | { | |
3595 | abbrev_base = 0; | |
3596 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3597 | } | |
3598 | else | |
3599 | { | |
3600 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3601 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3602 | } | |
3603 | ||
3604 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, | |
3605 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3606 | if (list == NULL) |
3607 | { | |
bcd213b2 NC |
3608 | unsigned char * next; |
3609 | ||
76868f36 L |
3610 | list = new_abbrev_list (abbrev_base, |
3611 | compunit.cu_abbrev_offset); | |
f2f9554b AM |
3612 | next = process_abbrev_set (&debug_displays[abbrev_sec].section, |
3613 | abbrev_base, abbrev_size, | |
3614 | compunit.cu_abbrev_offset, list); | |
bcd213b2 NC |
3615 | list->start_of_next_abbrevs = next; |
3616 | } | |
521d4b19 | 3617 | |
edba4e4a | 3618 | start = end_cu; |
bcd213b2 NC |
3619 | record_abbrev_list_for_cu (cu_offset, start - section_begin, list); |
3620 | } | |
3621 | ||
3622 | for (start = section_begin, unit = 0; start < end; unit++) | |
19e6b90e L |
3623 | { |
3624 | DWARF2_Internal_CompUnit compunit; | |
3625 | unsigned char *hdrptr; | |
19e6b90e | 3626 | unsigned char *tags; |
fd2f0033 | 3627 | int level, last_level, saved_level; |
467c65bc | 3628 | dwarf_vma cu_offset; |
bf5117e3 | 3629 | unsigned int offset_size; |
af2ddf69 | 3630 | dwarf_vma signature = 0; |
767221a9 | 3631 | dwarf_vma type_offset = 0; |
341f9135 CC |
3632 | struct cu_tu_set *this_set; |
3633 | dwarf_vma abbrev_base; | |
3634 | size_t abbrev_size; | |
bcd213b2 | 3635 | abbrev_list * list = NULL; |
edba4e4a | 3636 | unsigned char *end_cu; |
19e6b90e L |
3637 | |
3638 | hdrptr = start; | |
edba4e4a | 3639 | cu_offset = start - section_begin; |
19e6b90e | 3640 | |
0c588247 | 3641 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3642 | |
3643 | if (compunit.cu_length == 0xffffffff) | |
3644 | { | |
0c588247 | 3645 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e | 3646 | offset_size = 8; |
19e6b90e L |
3647 | } |
3648 | else | |
edba4e4a AM |
3649 | offset_size = 4; |
3650 | end_cu = hdrptr + compunit.cu_length; | |
19e6b90e | 3651 | |
edba4e4a | 3652 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu); |
19e6b90e | 3653 | |
341f9135 CC |
3654 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3655 | ||
77145576 JK |
3656 | if (compunit.cu_version < 5) |
3657 | { | |
3658 | compunit.cu_unit_type = DW_UT_compile; | |
3659 | /* Initialize it due to a false compiler warning. */ | |
3660 | compunit.cu_pointer_size = -1; | |
3661 | } | |
3662 | else | |
3663 | { | |
edba4e4a | 3664 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu); |
77145576 JK |
3665 | do_types = (compunit.cu_unit_type == DW_UT_type); |
3666 | ||
edba4e4a | 3667 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
77145576 JK |
3668 | } |
3669 | ||
edba4e4a | 3670 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end_cu); |
19e6b90e | 3671 | |
341f9135 CC |
3672 | if (this_set == NULL) |
3673 | { | |
3674 | abbrev_base = 0; | |
3675 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3676 | } | |
3677 | else | |
3678 | { | |
3679 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3680 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3681 | } | |
3682 | ||
77145576 | 3683 | if (compunit.cu_version < 5) |
edba4e4a | 3684 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
77145576 | 3685 | |
015dc7e1 | 3686 | bool do_dwo_id = false; |
e6ca1878 | 3687 | uint64_t dwo_id = 0; |
9b87f84a TV |
3688 | if (compunit.cu_unit_type == DW_UT_split_compile |
3689 | || compunit.cu_unit_type == DW_UT_skeleton) | |
3690 | { | |
edba4e4a | 3691 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu); |
015dc7e1 | 3692 | do_dwo_id = true; |
9b87f84a TV |
3693 | } |
3694 | ||
f41e4712 NC |
3695 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3696 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3697 | { | |
3698 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3699 | compunit.cu_pointer_size, offset_size); | |
3700 | compunit.cu_pointer_size = offset_size; | |
3701 | } | |
2b6f5997 CC |
3702 | |
3703 | if (do_types) | |
b4eb7656 | 3704 | { |
edba4e4a AM |
3705 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, end_cu); |
3706 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end_cu); | |
b4eb7656 | 3707 | } |
2b6f5997 | 3708 | |
edba4e4a | 3709 | if (dwarf_start_die >= (size_t) (end_cu - section_begin)) |
ae7e7825 | 3710 | { |
edba4e4a | 3711 | start = end_cu; |
ae7e7825 NC |
3712 | continue; |
3713 | } | |
3714 | ||
19e6b90e | 3715 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 | 3716 | && num_debug_info_entries == 0 |
c4b2f181 | 3717 | && alloc_num_debug_info_entries > unit |
2b6f5997 | 3718 | && ! do_types) |
19e6b90e L |
3719 | { |
3720 | debug_information [unit].cu_offset = cu_offset; | |
3721 | debug_information [unit].pointer_size | |
3722 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3723 | debug_information [unit].offset_size = offset_size; |
3724 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3725 | debug_information [unit].base_address = 0; |
4723351a CC |
3726 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3727 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3728 | debug_information [unit].loc_offsets = NULL; |
3729 | debug_information [unit].have_frame_base = NULL; | |
3730 | debug_information [unit].max_loc_offsets = 0; | |
3731 | debug_information [unit].num_loc_offsets = 0; | |
3732 | debug_information [unit].range_lists = NULL; | |
3733 | debug_information [unit].max_range_lists= 0; | |
3734 | debug_information [unit].num_range_lists = 0; | |
3735 | } | |
3736 | ||
fd2f0033 | 3737 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3738 | { |
47704ddf KT |
3739 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3740 | dwarf_vmatoa ("x", cu_offset)); | |
3741 | printf (_(" Length: 0x%s (%s)\n"), | |
3742 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3743 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3744 | printf (_(" Version: %d\n"), compunit.cu_version); |
debd1a62 | 3745 | if (compunit.cu_version >= 5) |
4896932e MF |
3746 | { |
3747 | const char *name = get_DW_UT_name (compunit.cu_unit_type); | |
3748 | ||
3749 | printf (_(" Unit Type: %s (%x)\n"), | |
3750 | name ? name : "???", | |
3751 | compunit.cu_unit_type); | |
3752 | } | |
7282333f AM |
3753 | printf (_(" Abbrev Offset: 0x%s\n"), |
3754 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3755 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3756 | if (do_types) |
3757 | { | |
74bc6052 | 3758 | printf (_(" Signature: 0x%s\n"), |
af2ddf69 | 3759 | dwarf_vmatoa ("x", signature)); |
74bc6052 CC |
3760 | printf (_(" Type Offset: 0x%s\n"), |
3761 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3762 | } |
d60f7998 TV |
3763 | if (do_dwo_id) |
3764 | printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id)); | |
341f9135 CC |
3765 | if (this_set != NULL) |
3766 | { | |
3767 | dwarf_vma *offsets = this_set->section_offsets; | |
3768 | size_t *sizes = this_set->section_sizes; | |
3769 | ||
3770 | printf (_(" Section contributions:\n")); | |
3771 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3772 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3773 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3774 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3775 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3776 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3777 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3778 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3779 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3780 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3781 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3782 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3783 | } | |
19e6b90e L |
3784 | } |
3785 | ||
460c89ff | 3786 | tags = hdrptr; |
edba4e4a | 3787 | start = end_cu; |
460c89ff | 3788 | |
77145576 | 3789 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3790 | { |
47704ddf KT |
3791 | warn (_("CU at offset %s contains corrupt or " |
3792 | "unsupported version number: %d.\n"), | |
3793 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3794 | continue; |
3795 | } | |
3796 | ||
77145576 | 3797 | if (compunit.cu_unit_type != DW_UT_compile |
ec47b32a | 3798 | && compunit.cu_unit_type != DW_UT_partial |
9b87f84a TV |
3799 | && compunit.cu_unit_type != DW_UT_type |
3800 | && compunit.cu_unit_type != DW_UT_split_compile | |
3801 | && compunit.cu_unit_type != DW_UT_skeleton) | |
77145576 JK |
3802 | { |
3803 | warn (_("CU at offset %s contains corrupt or " | |
3804 | "unsupported unit type: %d.\n"), | |
3805 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3806 | continue; | |
3807 | } | |
3808 | ||
d493b283 | 3809 | /* Process the abbrevs used by this compilation unit. */ |
f2f9554b AM |
3810 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, |
3811 | compunit.cu_abbrev_offset); | |
3812 | if (list == NULL) | |
bcd213b2 | 3813 | { |
f2f9554b AM |
3814 | unsigned char *next; |
3815 | ||
3816 | list = new_abbrev_list (abbrev_base, | |
3817 | compunit.cu_abbrev_offset); | |
3818 | next = process_abbrev_set (&debug_displays[abbrev_sec].section, | |
3819 | abbrev_base, abbrev_size, | |
3820 | compunit.cu_abbrev_offset, list); | |
3821 | list->start_of_next_abbrevs = next; | |
bcd213b2 | 3822 | } |
19e6b90e L |
3823 | |
3824 | level = 0; | |
fd2f0033 TT |
3825 | last_level = level; |
3826 | saved_level = -1; | |
19e6b90e L |
3827 | while (tags < start) |
3828 | { | |
19e6b90e | 3829 | unsigned long abbrev_number; |
ec4d4525 | 3830 | unsigned long die_offset; |
19e6b90e L |
3831 | abbrev_entry *entry; |
3832 | abbrev_attr *attr; | |
fd2f0033 | 3833 | int do_printing = 1; |
19e6b90e | 3834 | |
ec4d4525 NC |
3835 | die_offset = tags - section_begin; |
3836 | ||
cd30bcef | 3837 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 3838 | |
eb7cc021 JK |
3839 | /* A null DIE marks the end of a list of siblings or it may also be |
3840 | a section padding. */ | |
19e6b90e L |
3841 | if (abbrev_number == 0) |
3842 | { | |
eb7cc021 JK |
3843 | /* Check if it can be a section padding for the last CU. */ |
3844 | if (level == 0 && start == end) | |
3845 | { | |
3846 | unsigned char *chk; | |
3847 | ||
3848 | for (chk = tags; chk < start; chk++) | |
3849 | if (*chk != 0) | |
3850 | break; | |
3851 | if (chk == start) | |
3852 | break; | |
3853 | } | |
3854 | ||
4337774f TT |
3855 | if (!do_loc && die_offset >= dwarf_start_die |
3856 | && (dwarf_cutoff_level == -1 | |
3857 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3858 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3859 | level, die_offset); | |
3860 | ||
19e6b90e | 3861 | --level; |
ec4d4525 NC |
3862 | if (level < 0) |
3863 | { | |
3864 | static unsigned num_bogus_warns = 0; | |
3865 | ||
3866 | if (num_bogus_warns < 3) | |
3867 | { | |
4723351a CC |
3868 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3869 | die_offset, section->name); | |
ec4d4525 NC |
3870 | num_bogus_warns ++; |
3871 | if (num_bogus_warns == 3) | |
3872 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3873 | } | |
3874 | } | |
fd2f0033 | 3875 | if (dwarf_start_die != 0 && level < saved_level) |
015dc7e1 | 3876 | return true; |
19e6b90e L |
3877 | continue; |
3878 | } | |
3879 | ||
4b78141a | 3880 | if (!do_loc) |
fd2f0033 TT |
3881 | { |
3882 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3883 | do_printing = 0; | |
3884 | else | |
3885 | { | |
3886 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3887 | saved_level = level; | |
3888 | do_printing = (dwarf_cutoff_level == -1 | |
3889 | || level < dwarf_cutoff_level); | |
3890 | if (do_printing) | |
3891 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3892 | level, die_offset, abbrev_number); | |
3893 | else if (dwarf_cutoff_level == -1 | |
3894 | || last_level < dwarf_cutoff_level) | |
3895 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3896 | last_level = level; | |
3897 | } | |
3898 | } | |
cecf136e | 3899 | |
19e6b90e L |
3900 | /* Scan through the abbreviation list until we reach the |
3901 | correct entry. */ | |
bcd213b2 | 3902 | if (list == NULL) |
19e6b90e L |
3903 | continue; |
3904 | ||
bcd213b2 NC |
3905 | for (entry = list->first_abbrev; entry != NULL; entry = entry->next) |
3906 | if (entry->number == abbrev_number) | |
3907 | break; | |
3908 | ||
19e6b90e L |
3909 | if (entry == NULL) |
3910 | { | |
fd2f0033 | 3911 | if (!do_loc && do_printing) |
4b78141a NC |
3912 | { |
3913 | printf ("\n"); | |
3914 | fflush (stdout); | |
3915 | } | |
f3853b34 | 3916 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3917 | die_offset, abbrev_number); |
015dc7e1 | 3918 | return false; |
19e6b90e L |
3919 | } |
3920 | ||
fd2f0033 | 3921 | if (!do_loc && do_printing) |
cc5914eb | 3922 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3923 | |
19e6b90e L |
3924 | switch (entry->tag) |
3925 | { | |
3926 | default: | |
3927 | need_base_address = 0; | |
3928 | break; | |
3929 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3930 | need_base_address = 1; |
3931 | need_dwo_info = do_loc; | |
19e6b90e L |
3932 | break; |
3933 | case DW_TAG_entry_point: | |
19e6b90e L |
3934 | case DW_TAG_subprogram: |
3935 | need_base_address = 0; | |
3936 | /* Assuming that there is no DW_AT_frame_base. */ | |
3937 | have_frame_base = 0; | |
3938 | break; | |
3939 | } | |
3940 | ||
9f272209 AO |
3941 | debug_info *debug_info_p = |
3942 | (debug_information && unit < alloc_num_debug_info_entries) | |
3943 | ? debug_information + unit : NULL; | |
3944 | ||
3945 | assert (!debug_info_p | |
3946 | || (debug_info_p->num_loc_offsets | |
3947 | == debug_info_p->num_loc_views)); | |
3948 | ||
399c99f7 L |
3949 | for (attr = entry->first_attr; |
3950 | attr && attr->attribute; | |
3951 | attr = attr->next) | |
4b78141a | 3952 | { |
fd2f0033 | 3953 | if (! do_loc && do_printing) |
4b78141a | 3954 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 3955 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
3956 | tags = read_and_display_attr (attr->attribute, |
3957 | attr->form, | |
77145576 | 3958 | attr->implicit_const, |
ec1b0fbb | 3959 | section_begin, |
341f9135 | 3960 | tags, |
edba4e4a | 3961 | start, |
341f9135 | 3962 | cu_offset, |
4b78141a NC |
3963 | compunit.cu_pointer_size, |
3964 | offset_size, | |
3965 | compunit.cu_version, | |
9f272209 | 3966 | debug_info_p, |
341f9135 CC |
3967 | do_loc || ! do_printing, |
3968 | section, | |
ec1b0fbb NC |
3969 | this_set, |
3970 | level); | |
4b78141a | 3971 | } |
cecf136e | 3972 | |
9f272209 AO |
3973 | /* If a locview attribute appears before a location one, |
3974 | make sure we don't associate it with an earlier | |
3975 | loclist. */ | |
3976 | if (debug_info_p) | |
3977 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3978 | { | |
3979 | case 1: | |
3980 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3981 | debug_info_p->num_loc_views++; | |
3982 | assert (debug_info_p->num_loc_views | |
3983 | == debug_info_p->num_loc_offsets); | |
3984 | break; | |
3985 | ||
3986 | case 0: | |
3987 | break; | |
3988 | ||
3989 | case -1: | |
3990 | warn(_("DIE has locviews without loclist\n")); | |
3991 | debug_info_p->num_loc_views--; | |
3992 | break; | |
3993 | ||
3994 | default: | |
3995 | assert (0); | |
3996 | } | |
3997 | ||
b4eb7656 AM |
3998 | if (entry->children) |
3999 | ++level; | |
4000 | } | |
19e6b90e | 4001 | } |
cecf136e | 4002 | |
19e6b90e L |
4003 | /* Set num_debug_info_entries here so that it can be used to check if |
4004 | we need to process .debug_loc and .debug_ranges sections. */ | |
4005 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
4006 | && num_debug_info_entries == 0 |
4007 | && ! do_types) | |
82b1b41b | 4008 | { |
b4eb7656 | 4009 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
4010 | num_debug_info_entries = alloc_num_debug_info_entries; |
4011 | else | |
4012 | num_debug_info_entries = num_units; | |
4013 | } | |
cecf136e | 4014 | |
19e6b90e | 4015 | if (!do_loc) |
467c65bc | 4016 | printf ("\n"); |
cecf136e | 4017 | |
015dc7e1 | 4018 | return true; |
19e6b90e L |
4019 | } |
4020 | ||
4021 | /* Locate and scan the .debug_info section in the file and record the pointer | |
4022 | sizes and offsets for the compilation units in it. Usually an executable | |
4023 | will have just one pointer size, but this is not guaranteed, and so we try | |
4024 | not to make any assumptions. Returns zero upon failure, or the number of | |
4025 | compilation units upon success. */ | |
4026 | ||
4027 | static unsigned int | |
4028 | load_debug_info (void * file) | |
4029 | { | |
1febe64d | 4030 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 4031 | section then do not bother to repeat the task. */ |
cc86f28f | 4032 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
4033 | return 0; |
4034 | ||
19e6b90e L |
4035 | /* If we already have the information there is nothing else to do. */ |
4036 | if (num_debug_info_entries > 0) | |
4037 | return num_debug_info_entries; | |
4038 | ||
341f9135 | 4039 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 4040 | (void) load_cu_tu_indexes (file); |
341f9135 | 4041 | |
dda8d76d | 4042 | if (load_debug_section_with_follow (info, file) |
015dc7e1 | 4043 | && process_debug_info (&debug_displays [info].section, file, abbrev, true, false)) |
19e6b90e | 4044 | return num_debug_info_entries; |
82b1b41b | 4045 | |
dda8d76d | 4046 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 4047 | && process_debug_info (&debug_displays [info_dwo].section, file, |
015dc7e1 | 4048 | abbrev_dwo, true, false)) |
4723351a | 4049 | return num_debug_info_entries; |
1febe64d | 4050 | |
cc86f28f | 4051 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 4052 | return 0; |
19e6b90e L |
4053 | } |
4054 | ||
b40bf0a2 NC |
4055 | /* Read a DWARF .debug_line section header starting at DATA. |
4056 | Upon success returns an updated DATA pointer and the LINFO | |
4057 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
4058 | Otherwise returns NULL. */ | |
19e6b90e | 4059 | |
b40bf0a2 NC |
4060 | static unsigned char * |
4061 | read_debug_line_header (struct dwarf_section * section, | |
4062 | unsigned char * data, | |
4063 | unsigned char * end, | |
4064 | DWARF2_Internal_LineInfo * linfo, | |
4065 | unsigned char ** end_of_sequence) | |
4066 | { | |
4067 | unsigned char *hdrptr; | |
19e6b90e | 4068 | |
b40bf0a2 NC |
4069 | /* Extract information from the Line Number Program Header. |
4070 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 4071 | hdrptr = data; |
19e6b90e | 4072 | |
b40bf0a2 NC |
4073 | /* Get and check the length of the block. */ |
4074 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 4075 | |
b40bf0a2 | 4076 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
4077 | { |
4078 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 4079 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 4080 | linfo->li_offset_size = 8; |
f41e4712 NC |
4081 | } |
4082 | else | |
37195e23 | 4083 | linfo->li_offset_size = 4; |
19e6b90e | 4084 | |
37195e23 | 4085 | if (linfo->li_length > (size_t) (end - hdrptr)) |
f41e4712 | 4086 | { |
8fcc61b4 NC |
4087 | /* If the length field has a relocation against it, then we should |
4088 | not complain if it is inaccurate (and probably negative). This | |
4089 | happens in object files when the .debug_line section is actually | |
4090 | comprised of several different .debug_line.* sections, (some of | |
4091 | which may be removed by linker garbage collection), and a relocation | |
4092 | is used to compute the correct length once that is done. */ | |
77145576 | 4093 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 4094 | { |
37195e23 | 4095 | linfo->li_length = end - hdrptr; |
b40bf0a2 NC |
4096 | } |
4097 | else | |
4098 | { | |
8fcc61b4 NC |
4099 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
4100 | (long) linfo->li_length); | |
b40bf0a2 NC |
4101 | return NULL; |
4102 | } | |
f41e4712 | 4103 | } |
37195e23 | 4104 | end = hdrptr + linfo->li_length; |
19e6b90e | 4105 | |
b40bf0a2 NC |
4106 | /* Get and check the version number. */ |
4107 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
4108 | ||
4109 | if (linfo->li_version != 2 | |
4110 | && linfo->li_version != 3 | |
77145576 JK |
4111 | && linfo->li_version != 4 |
4112 | && linfo->li_version != 5) | |
f41e4712 | 4113 | { |
77145576 JK |
4114 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
4115 | "is currently supported.\n")); | |
b40bf0a2 | 4116 | return NULL; |
f41e4712 | 4117 | } |
19e6b90e | 4118 | |
77145576 JK |
4119 | if (linfo->li_version >= 5) |
4120 | { | |
5496f3c6 | 4121 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
77145576 | 4122 | |
5496f3c6 NC |
4123 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
4124 | if (linfo->li_segment_size != 0) | |
77145576 JK |
4125 | { |
4126 | warn (_("The %s section contains " | |
4127 | "unsupported segment selector size: %d.\n"), | |
5496f3c6 NC |
4128 | section->name, linfo->li_segment_size); |
4129 | return NULL; | |
77145576 JK |
4130 | } |
4131 | } | |
4132 | ||
4133 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
4134 | linfo->li_offset_size, end); | |
b40bf0a2 | 4135 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 4136 | |
b40bf0a2 | 4137 | if (linfo->li_version >= 4) |
f41e4712 | 4138 | { |
b40bf0a2 | 4139 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 4140 | |
b40bf0a2 | 4141 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
4142 | { |
4143 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 4144 | return NULL; |
a233b20c | 4145 | } |
f41e4712 NC |
4146 | } |
4147 | else | |
b40bf0a2 | 4148 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 4149 | |
b40bf0a2 | 4150 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 4151 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
4152 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
4153 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 4154 | |
37195e23 | 4155 | *end_of_sequence = end; |
b40bf0a2 NC |
4156 | return hdrptr; |
4157 | } | |
19e6b90e | 4158 | |
77145576 | 4159 | static unsigned char * |
015dc7e1 AM |
4160 | display_formatted_table (unsigned char *data, |
4161 | unsigned char *start, | |
4162 | unsigned char *end, | |
4163 | const DWARF2_Internal_LineInfo *linfo, | |
4164 | struct dwarf_section *section, | |
4165 | bool is_dir) | |
77145576 JK |
4166 | { |
4167 | unsigned char *format_start, format_count, *format, formati; | |
4168 | dwarf_vma data_count, datai; | |
cd30bcef | 4169 | unsigned int namepass, last_entry = 0; |
5496f3c6 | 4170 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
521d4b19 | 4171 | |
77145576 | 4172 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
546cb2d8 NC |
4173 | if (do_checks && format_count > 5) |
4174 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), | |
4175 | table_name, format_count); | |
4176 | ||
77145576 JK |
4177 | format_start = data; |
4178 | for (formati = 0; formati < format_count; formati++) | |
4179 | { | |
cd30bcef AM |
4180 | SKIP_ULEB (data, end); |
4181 | SKIP_ULEB (data, end); | |
55b26492 | 4182 | if (data >= end) |
77145576 | 4183 | { |
5496f3c6 | 4184 | warn (_("%s: Corrupt format description entry\n"), table_name); |
77145576 JK |
4185 | return data; |
4186 | } | |
4187 | } | |
4188 | ||
cd30bcef | 4189 | READ_ULEB (data_count, data, end); |
546cb2d8 | 4190 | if (data_count == 0) |
77145576 | 4191 | { |
546cb2d8 | 4192 | printf (_("\n The %s is empty.\n"), table_name); |
77145576 JK |
4193 | return data; |
4194 | } | |
55b26492 | 4195 | else if (data >= end) |
77145576 | 4196 | { |
546cb2d8 NC |
4197 | warn (_("%s: Corrupt entry count - expected %s but none found\n"), |
4198 | table_name, dwarf_vmatoa ("x", data_count)); | |
77145576 JK |
4199 | return data; |
4200 | } | |
546cb2d8 | 4201 | |
5496f3c6 NC |
4202 | else if (format_count == 0) |
4203 | { | |
4204 | warn (_("%s: format count is zero, but the table is not empty\n"), | |
4205 | table_name); | |
4206 | return end; | |
4207 | } | |
77145576 | 4208 | |
5496f3c6 NC |
4209 | printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"), |
4210 | table_name, (long) (data - start), dwarf_vmatoa ("u", data_count), | |
4211 | format_count); | |
77145576 JK |
4212 | |
4213 | printf (_(" Entry")); | |
521d4b19 | 4214 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4215 | for (namepass = 0; namepass < 2; namepass++) |
4216 | { | |
4217 | format = format_start; | |
4218 | for (formati = 0; formati < format_count; formati++) | |
4219 | { | |
4220 | dwarf_vma content_type; | |
4221 | ||
cd30bcef | 4222 | READ_ULEB (content_type, format, end); |
77145576 JK |
4223 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
4224 | switch (content_type) | |
4225 | { | |
4226 | case DW_LNCT_path: | |
4227 | printf (_("\tName")); | |
4228 | break; | |
4229 | case DW_LNCT_directory_index: | |
4230 | printf (_("\tDir")); | |
4231 | break; | |
4232 | case DW_LNCT_timestamp: | |
4233 | printf (_("\tTime")); | |
4234 | break; | |
4235 | case DW_LNCT_size: | |
4236 | printf (_("\tSize")); | |
4237 | break; | |
4238 | case DW_LNCT_MD5: | |
5496f3c6 | 4239 | printf (_("\tMD5\t\t\t")); |
77145576 JK |
4240 | break; |
4241 | default: | |
4242 | printf (_("\t(Unknown format content type %s)"), | |
4243 | dwarf_vmatoa ("u", content_type)); | |
4244 | } | |
cd30bcef | 4245 | SKIP_ULEB (format, end); |
77145576 JK |
4246 | } |
4247 | } | |
4248 | putchar ('\n'); | |
4249 | ||
4250 | for (datai = 0; datai < data_count; datai++) | |
4251 | { | |
4252 | unsigned char *datapass = data; | |
4253 | ||
4254 | printf (" %d", last_entry++); | |
521d4b19 | 4255 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4256 | for (namepass = 0; namepass < 2; namepass++) |
4257 | { | |
4258 | format = format_start; | |
4259 | data = datapass; | |
4260 | for (formati = 0; formati < format_count; formati++) | |
4261 | { | |
4262 | dwarf_vma content_type, form; | |
4263 | ||
cd30bcef AM |
4264 | READ_ULEB (content_type, format, end); |
4265 | READ_ULEB (form, format, end); | |
4266 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
4267 | 0, 0, linfo->li_offset_size, | |
77145576 JK |
4268 | linfo->li_version, NULL, |
4269 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 4270 | section, NULL, '\t', -1); |
77145576 JK |
4271 | } |
4272 | } | |
5496f3c6 | 4273 | |
55b26492 | 4274 | if (data >= end && (datai < data_count - 1)) |
77145576 | 4275 | { |
5496f3c6 | 4276 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
77145576 JK |
4277 | return data; |
4278 | } | |
4279 | putchar ('\n'); | |
4280 | } | |
4281 | return data; | |
4282 | } | |
4283 | ||
e38332c2 NC |
4284 | static int |
4285 | display_debug_sup (struct dwarf_section * section, | |
4286 | void * file ATTRIBUTE_UNUSED) | |
4287 | { | |
4288 | unsigned char * start = section->start; | |
4289 | unsigned char * end = section->start + section->size; | |
4290 | unsigned int version; | |
4291 | char is_supplementary; | |
4292 | const unsigned char * sup_filename; | |
4293 | size_t sup_filename_len; | |
4294 | unsigned int num_read; | |
4295 | int status; | |
4296 | dwarf_vma checksum_len; | |
4297 | ||
4298 | ||
015dc7e1 | 4299 | introduce (section, true); |
e38332c2 NC |
4300 | if (section->size < 4) |
4301 | { | |
4302 | error (_("corrupt .debug_sup section: size is too small\n")); | |
4303 | return 0; | |
4304 | } | |
4305 | ||
4306 | /* Read the data. */ | |
4307 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); | |
4308 | if (version < 5) | |
4309 | warn (_("corrupt .debug_sup section: version < 5")); | |
4310 | ||
4311 | SAFE_BYTE_GET_AND_INC (is_supplementary, start, 1, end); | |
4312 | if (is_supplementary != 0 && is_supplementary != 1) | |
4313 | warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n")); | |
4314 | ||
4315 | sup_filename = start; | |
4316 | if (is_supplementary && sup_filename[0] != 0) | |
4317 | warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n")); | |
4318 | ||
4319 | sup_filename_len = strnlen ((const char *) start, end - start); | |
4320 | if (sup_filename_len == (size_t) (end - start)) | |
4321 | { | |
4322 | error (_("corrupt .debug_sup section: filename is not NUL terminated\n")); | |
4323 | return 0; | |
4324 | } | |
4325 | start += sup_filename_len + 1; | |
4326 | ||
015dc7e1 | 4327 | checksum_len = read_leb128 (start, end, false /* unsigned */, & num_read, & status); |
e38332c2 NC |
4328 | if (status) |
4329 | { | |
4330 | error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n")); | |
4331 | checksum_len = 0; | |
4332 | } | |
4333 | start += num_read; | |
4334 | if (checksum_len > (dwarf_vma) (end - start)) | |
4335 | { | |
4336 | error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n")); | |
4337 | checksum_len = end - start; | |
4338 | } | |
4339 | else if (checksum_len < (dwarf_vma) (end - start)) | |
4340 | { | |
4341 | warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"), | |
4342 | (long) ((end - start) - checksum_len)); | |
4343 | } | |
4344 | ||
4345 | printf (_(" Version: %u\n"), version); | |
4346 | printf (_(" Is Supp: %u\n"), is_supplementary); | |
4347 | printf (_(" Filename: %s\n"), sup_filename); | |
4348 | printf (_(" Checksum Len: %lu\n"), (long) checksum_len); | |
4349 | if (checksum_len > 0) | |
4350 | { | |
4351 | printf (_(" Checksum: ")); | |
4352 | while (checksum_len--) | |
4353 | printf ("0x%x ", * start++ ); | |
4354 | printf ("\n"); | |
4355 | } | |
4356 | return 1; | |
4357 | } | |
4358 | ||
b40bf0a2 | 4359 | static int |
dda8d76d NC |
4360 | display_debug_lines_raw (struct dwarf_section * section, |
4361 | unsigned char * data, | |
4362 | unsigned char * end, | |
4363 | void * file) | |
b40bf0a2 NC |
4364 | { |
4365 | unsigned char *start = section->start; | |
ba8826a8 | 4366 | int verbose_view = 0; |
19e6b90e | 4367 | |
015dc7e1 | 4368 | introduce (section, true); |
19e6b90e | 4369 | |
b40bf0a2 NC |
4370 | while (data < end) |
4371 | { | |
4372 | static DWARF2_Internal_LineInfo saved_linfo; | |
4373 | DWARF2_Internal_LineInfo linfo; | |
4374 | unsigned char *standard_opcodes; | |
4375 | unsigned char *end_of_sequence; | |
fe59e83d | 4376 | int i; |
19e6b90e | 4377 | |
24d127aa | 4378 | if (startswith (section->name, ".debug_line.") |
4925cdd7 NC |
4379 | /* Note: the following does not apply to .debug_line.dwo sections. |
4380 | These are full debug_line sections. */ | |
4381 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 4382 | { |
b40bf0a2 NC |
4383 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
4384 | section containing just the Line Number Statements. They are | |
4385 | created by the assembler and intended to be used alongside gcc's | |
4386 | -ffunction-sections command line option. When the linker's | |
4387 | garbage collection decides to discard a .text.<foo> section it | |
4388 | can then also discard the line number information in .debug_line.<foo>. | |
4389 | ||
4925cdd7 | 4390 | Since the section is a fragment it does not have the details |
b40bf0a2 | 4391 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 4392 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
4393 | end_of_sequence = end; |
4394 | standard_opcodes = NULL; | |
4395 | linfo = saved_linfo; | |
058037d3 NC |
4396 | /* PR 17531: file: 0522b371. */ |
4397 | if (linfo.li_line_range == 0) | |
4398 | { | |
1306a742 | 4399 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4400 | return 0; |
4401 | } | |
b40bf0a2 | 4402 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4403 | } |
19e6b90e L |
4404 | else |
4405 | { | |
b40bf0a2 | 4406 | unsigned char * hdrptr; |
19e6b90e | 4407 | |
b40bf0a2 NC |
4408 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4409 | & end_of_sequence)) == NULL) | |
4410 | return 0; | |
19e6b90e | 4411 | |
b40bf0a2 NC |
4412 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
4413 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
4414 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
5496f3c6 NC |
4415 | if (linfo.li_version >= 5) |
4416 | { | |
4417 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); | |
4418 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); | |
4419 | } | |
77ef8654 | 4420 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
4421 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
4422 | if (linfo.li_version >= 4) | |
4423 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
4424 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
4425 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4426 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4427 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 4428 | |
0a9d414a NC |
4429 | /* PR 17512: file: 1665-6428-0.004. */ |
4430 | if (linfo.li_line_range == 0) | |
4431 | { | |
4432 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4433 | linfo.li_line_range = 1; | |
4434 | } | |
77ef8654 | 4435 | |
b40bf0a2 | 4436 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4437 | |
b40bf0a2 NC |
4438 | /* Display the contents of the Opcodes table. */ |
4439 | standard_opcodes = hdrptr; | |
19e6b90e | 4440 | |
6937bb54 NC |
4441 | /* PR 17512: file: 002-417945-0.004. */ |
4442 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4443 | { | |
4444 | warn (_("Line Base extends beyond end of section\n")); | |
4445 | return 0; | |
4446 | } | |
4447 | ||
b40bf0a2 | 4448 | printf (_("\n Opcodes:\n")); |
19e6b90e | 4449 | |
b40bf0a2 | 4450 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
4451 | printf (ngettext (" Opcode %d has %d arg\n", |
4452 | " Opcode %d has %d args\n", | |
4453 | standard_opcodes[i - 1]), | |
4454 | i, standard_opcodes[i - 1]); | |
19e6b90e | 4455 | |
b40bf0a2 NC |
4456 | /* Display the contents of the Directory table. */ |
4457 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 4458 | |
77145576 | 4459 | if (linfo.li_version >= 5) |
b40bf0a2 | 4460 | { |
dda8d76d | 4461 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 4462 | |
77145576 | 4463 | data = display_formatted_table (data, start, end, &linfo, section, |
015dc7e1 | 4464 | true); |
77145576 | 4465 | data = display_formatted_table (data, start, end, &linfo, section, |
015dc7e1 | 4466 | false); |
77145576 JK |
4467 | } |
4468 | else | |
4469 | { | |
4470 | if (*data == 0) | |
4471 | printf (_("\n The Directory Table is empty.\n")); | |
4472 | else | |
a233b20c | 4473 | { |
77145576 | 4474 | unsigned int last_dir_entry = 0; |
6937bb54 | 4475 | |
77145576 JK |
4476 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
4477 | (long)(data - start)); | |
19e6b90e | 4478 | |
77145576 JK |
4479 | while (data < end && *data != 0) |
4480 | { | |
4481 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 4482 | |
a7077ce7 AM |
4483 | data += strnlen ((char *) data, end - data); |
4484 | if (data < end) | |
4485 | data++; | |
77145576 | 4486 | } |
19e6b90e | 4487 | |
77145576 JK |
4488 | /* PR 17512: file: 002-132094-0.004. */ |
4489 | if (data >= end - 1) | |
4490 | break; | |
4491 | } | |
19e6b90e | 4492 | |
77145576 | 4493 | /* Skip the NUL at the end of the table. */ |
a7077ce7 AM |
4494 | if (data < end) |
4495 | data++; | |
19e6b90e | 4496 | |
77145576 | 4497 | /* Display the contents of the File Name table. */ |
a7077ce7 | 4498 | if (data >= end || *data == 0) |
77145576 JK |
4499 | printf (_("\n The File Name Table is empty.\n")); |
4500 | else | |
4501 | { | |
4502 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
4503 | (long)(data - start)); | |
4504 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 4505 | |
77145576 | 4506 | while (data < end && *data != 0) |
b40bf0a2 | 4507 | { |
77145576 | 4508 | unsigned char *name; |
cd30bcef | 4509 | dwarf_vma val; |
77145576 JK |
4510 | |
4511 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4512 | name = data; | |
a7077ce7 AM |
4513 | data += strnlen ((char *) data, end - data); |
4514 | if (data < end) | |
4515 | data++; | |
77145576 | 4516 | |
cd30bcef AM |
4517 | READ_ULEB (val, data, end); |
4518 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4519 | READ_ULEB (val, data, end); | |
4520 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4521 | READ_ULEB (val, data, end); | |
4522 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
77145576 JK |
4523 | printf ("%.*s\n", (int)(end - name), name); |
4524 | ||
55b26492 | 4525 | if (data >= end) |
77145576 JK |
4526 | { |
4527 | warn (_("Corrupt file name table entry\n")); | |
4528 | break; | |
4529 | } | |
b40bf0a2 | 4530 | } |
a233b20c | 4531 | } |
77145576 JK |
4532 | |
4533 | /* Skip the NUL at the end of the table. */ | |
a7077ce7 AM |
4534 | if (data < end) |
4535 | data++; | |
b40bf0a2 | 4536 | } |
19e6b90e | 4537 | |
b40bf0a2 NC |
4538 | putchar ('\n'); |
4539 | saved_linfo = linfo; | |
4540 | } | |
19e6b90e | 4541 | |
b40bf0a2 NC |
4542 | /* Now display the statements. */ |
4543 | if (data >= end_of_sequence) | |
4544 | printf (_(" No Line Number Statements.\n")); | |
4545 | else | |
4546 | { | |
4547 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4548 | |
b40bf0a2 NC |
4549 | while (data < end_of_sequence) |
4550 | { | |
4551 | unsigned char op_code; | |
4552 | dwarf_signed_vma adv; | |
4553 | dwarf_vma uladv; | |
19e6b90e | 4554 | |
fe59e83d CC |
4555 | printf (" [0x%08lx]", (long)(data - start)); |
4556 | ||
b40bf0a2 | 4557 | op_code = *data++; |
19e6b90e | 4558 | |
b40bf0a2 | 4559 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4560 | { |
b40bf0a2 NC |
4561 | op_code -= linfo.li_opcode_base; |
4562 | uladv = (op_code / linfo.li_line_range); | |
4563 | if (linfo.li_max_ops_per_insn == 1) | |
4564 | { | |
4565 | uladv *= linfo.li_min_insn_length; | |
4566 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4567 | if (uladv) |
4568 | state_machine_regs.view = 0; | |
b40bf0a2 | 4569 | printf (_(" Special opcode %d: " |
ba8826a8 | 4570 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4571 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4572 | dwarf_vmatoa ("x", state_machine_regs.address), |
4573 | verbose_view && uladv | |
4574 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4575 | } |
4576 | else | |
4577 | { | |
ba8826a8 AO |
4578 | unsigned addrdelta |
4579 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4580 | / linfo.li_max_ops_per_insn) |
4581 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4582 | |
4583 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4584 | state_machine_regs.op_index |
4585 | = (state_machine_regs.op_index + uladv) | |
4586 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4587 | if (addrdelta) |
4588 | state_machine_regs.view = 0; | |
b40bf0a2 | 4589 | printf (_(" Special opcode %d: " |
ba8826a8 | 4590 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4591 | op_code, dwarf_vmatoa ("u", uladv), |
4592 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4593 | state_machine_regs.op_index, |
4594 | verbose_view && addrdelta | |
4595 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4596 | } |
4597 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4598 | state_machine_regs.line += adv; | |
ba8826a8 | 4599 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4600 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4601 | if (verbose_view || state_machine_regs.view) |
4602 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4603 | else | |
4604 | putchar ('\n'); | |
4605 | state_machine_regs.view++; | |
19e6b90e | 4606 | } |
cd30bcef AM |
4607 | else |
4608 | switch (op_code) | |
4609 | { | |
4610 | case DW_LNS_extended_op: | |
4611 | data += process_extended_line_op (data, | |
4612 | linfo.li_default_is_stmt, | |
4613 | end); | |
4614 | break; | |
4615 | ||
4616 | case DW_LNS_copy: | |
4617 | printf (_(" Copy")); | |
4618 | if (verbose_view || state_machine_regs.view) | |
4619 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4620 | else | |
4621 | putchar ('\n'); | |
4622 | state_machine_regs.view++; | |
4623 | break; | |
4624 | ||
4625 | case DW_LNS_advance_pc: | |
4626 | READ_ULEB (uladv, data, end); | |
4627 | if (linfo.li_max_ops_per_insn == 1) | |
4628 | { | |
4629 | uladv *= linfo.li_min_insn_length; | |
4630 | state_machine_regs.address += uladv; | |
4631 | if (uladv) | |
4632 | state_machine_regs.view = 0; | |
4633 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
4634 | dwarf_vmatoa ("u", uladv), | |
4635 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4636 | verbose_view && uladv | |
4637 | ? _(" (reset view)") : ""); | |
4638 | } | |
4639 | else | |
4640 | { | |
4641 | unsigned addrdelta | |
4642 | = ((state_machine_regs.op_index + uladv) | |
4643 | / linfo.li_max_ops_per_insn) | |
4644 | * linfo.li_min_insn_length; | |
4645 | state_machine_regs.address | |
4646 | += addrdelta; | |
4647 | state_machine_regs.op_index | |
4648 | = (state_machine_regs.op_index + uladv) | |
4649 | % linfo.li_max_ops_per_insn; | |
4650 | if (addrdelta) | |
4651 | state_machine_regs.view = 0; | |
4652 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
4653 | dwarf_vmatoa ("u", uladv), | |
4654 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4655 | state_machine_regs.op_index, | |
4656 | verbose_view && addrdelta | |
4657 | ? _(" (reset view)") : ""); | |
4658 | } | |
4659 | break; | |
4660 | ||
4661 | case DW_LNS_advance_line: | |
4662 | READ_SLEB (adv, data, end); | |
4663 | state_machine_regs.line += adv; | |
4664 | printf (_(" Advance Line by %s to %d\n"), | |
4665 | dwarf_vmatoa ("d", adv), | |
4666 | state_machine_regs.line); | |
4667 | break; | |
4668 | ||
4669 | case DW_LNS_set_file: | |
4670 | READ_ULEB (uladv, data, end); | |
4671 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4672 | dwarf_vmatoa ("u", uladv)); | |
4673 | state_machine_regs.file = uladv; | |
4674 | break; | |
4675 | ||
4676 | case DW_LNS_set_column: | |
4677 | READ_ULEB (uladv, data, end); | |
4678 | printf (_(" Set column to %s\n"), | |
4679 | dwarf_vmatoa ("u", uladv)); | |
4680 | state_machine_regs.column = uladv; | |
4681 | break; | |
4682 | ||
4683 | case DW_LNS_negate_stmt: | |
4684 | adv = state_machine_regs.is_stmt; | |
4685 | adv = ! adv; | |
4686 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4687 | state_machine_regs.is_stmt = adv; | |
4688 | break; | |
4689 | ||
4690 | case DW_LNS_set_basic_block: | |
4691 | printf (_(" Set basic block\n")); | |
4692 | state_machine_regs.basic_block = 1; | |
4693 | break; | |
4694 | ||
4695 | case DW_LNS_const_add_pc: | |
4696 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4697 | if (linfo.li_max_ops_per_insn) | |
4698 | { | |
4699 | uladv *= linfo.li_min_insn_length; | |
4700 | state_machine_regs.address += uladv; | |
4701 | if (uladv) | |
4702 | state_machine_regs.view = 0; | |
4703 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
4704 | dwarf_vmatoa ("u", uladv), | |
4705 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4706 | verbose_view && uladv | |
4707 | ? _(" (reset view)") : ""); | |
4708 | } | |
4709 | else | |
4710 | { | |
4711 | unsigned addrdelta | |
4712 | = ((state_machine_regs.op_index + uladv) | |
4713 | / linfo.li_max_ops_per_insn) | |
4714 | * linfo.li_min_insn_length; | |
4715 | state_machine_regs.address | |
4716 | += addrdelta; | |
4717 | state_machine_regs.op_index | |
4718 | = (state_machine_regs.op_index + uladv) | |
4719 | % linfo.li_max_ops_per_insn; | |
4720 | if (addrdelta) | |
4721 | state_machine_regs.view = 0; | |
4722 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
4723 | dwarf_vmatoa ("u", uladv), | |
4724 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4725 | state_machine_regs.op_index, | |
4726 | verbose_view && addrdelta | |
4727 | ? _(" (reset view)") : ""); | |
4728 | } | |
4729 | break; | |
4730 | ||
4731 | case DW_LNS_fixed_advance_pc: | |
4732 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4733 | state_machine_regs.address += uladv; | |
4734 | state_machine_regs.op_index = 0; | |
4735 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4736 | dwarf_vmatoa ("u", uladv), | |
4737 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
4738 | /* Do NOT reset view. */ | |
4739 | break; | |
4740 | ||
4741 | case DW_LNS_set_prologue_end: | |
4742 | printf (_(" Set prologue_end to true\n")); | |
4743 | break; | |
4744 | ||
4745 | case DW_LNS_set_epilogue_begin: | |
4746 | printf (_(" Set epilogue_begin to true\n")); | |
4747 | break; | |
4748 | ||
4749 | case DW_LNS_set_isa: | |
4750 | READ_ULEB (uladv, data, end); | |
4751 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4752 | break; | |
4753 | ||
4754 | default: | |
4755 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4756 | ||
4757 | if (standard_opcodes != NULL) | |
4758 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4759 | { | |
4760 | READ_ULEB (uladv, data, end); | |
4761 | printf ("0x%s%s", dwarf_vmatoa ("x", uladv), | |
4762 | i == 1 ? "" : ", "); | |
4763 | } | |
4764 | putchar ('\n'); | |
4765 | break; | |
4766 | } | |
19e6b90e | 4767 | } |
b40bf0a2 | 4768 | putchar ('\n'); |
19e6b90e | 4769 | } |
19e6b90e L |
4770 | } |
4771 | ||
4772 | return 1; | |
4773 | } | |
4774 | ||
a262ae96 NC |
4775 | typedef struct |
4776 | { | |
467c65bc NC |
4777 | unsigned char *name; |
4778 | unsigned int directory_index; | |
4779 | unsigned int modification_date; | |
4780 | unsigned int length; | |
a262ae96 NC |
4781 | } File_Entry; |
4782 | ||
4783 | /* Output a decoded representation of the .debug_line section. */ | |
4784 | ||
4785 | static int | |
dda8d76d | 4786 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4787 | unsigned char * start, |
dda8d76d NC |
4788 | unsigned char * data, |
4789 | unsigned char * end, | |
4790 | void * fileptr) | |
a262ae96 | 4791 | { |
b40bf0a2 NC |
4792 | static DWARF2_Internal_LineInfo saved_linfo; |
4793 | ||
015dc7e1 | 4794 | introduce (section, false); |
a262ae96 NC |
4795 | |
4796 | while (data < end) | |
4797 | { | |
4798 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4799 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4800 | unsigned char *standard_opcodes; |
4801 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4802 | int i; |
4803 | File_Entry *file_table = NULL; | |
143a3db0 | 4804 | unsigned int n_files = 0; |
a262ae96 | 4805 | unsigned char **directory_table = NULL; |
77145576 | 4806 | dwarf_vma n_directories = 0; |
a262ae96 | 4807 | |
24d127aa | 4808 | if (startswith (section->name, ".debug_line.") |
4925cdd7 NC |
4809 | /* Note: the following does not apply to .debug_line.dwo sections. |
4810 | These are full debug_line sections. */ | |
4811 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4812 | { |
4925cdd7 | 4813 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4814 | end_of_sequence = end; |
4815 | standard_opcodes = NULL; | |
4816 | linfo = saved_linfo; | |
058037d3 NC |
4817 | /* PR 17531: file: 0522b371. */ |
4818 | if (linfo.li_line_range == 0) | |
4819 | { | |
1306a742 | 4820 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4821 | return 0; |
4822 | } | |
b40bf0a2 | 4823 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4824 | } |
a262ae96 | 4825 | else |
b4eb7656 | 4826 | { |
b40bf0a2 | 4827 | unsigned char *hdrptr; |
a262ae96 | 4828 | |
b40bf0a2 NC |
4829 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4830 | & end_of_sequence)) == NULL) | |
a233b20c | 4831 | return 0; |
0c588247 | 4832 | |
058037d3 NC |
4833 | /* PR 17531: file: 0522b371. */ |
4834 | if (linfo.li_line_range == 0) | |
4835 | { | |
4836 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4837 | linfo.li_line_range = 1; | |
4838 | } | |
b40bf0a2 | 4839 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4840 | |
b40bf0a2 NC |
4841 | /* Save a pointer to the contents of the Opcodes table. */ |
4842 | standard_opcodes = hdrptr; | |
a262ae96 | 4843 | |
b40bf0a2 NC |
4844 | /* Traverse the Directory table just to count entries. */ |
4845 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4846 | /* PR 20440 */ |
4847 | if (data >= end) | |
4848 | { | |
4849 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4850 | linfo.li_opcode_base); | |
4851 | return 0; | |
4852 | } | |
4853 | ||
77145576 | 4854 | if (linfo.li_version >= 5) |
b40bf0a2 | 4855 | { |
77145576 JK |
4856 | unsigned char *format_start, format_count, *format; |
4857 | dwarf_vma formati, entryi; | |
a262ae96 | 4858 | |
dda8d76d | 4859 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4860 | |
4861 | /* Skip directories format. */ | |
4862 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4863 | if (do_checks && format_count > 1) |
4864 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), | |
4865 | format_count); | |
77145576 JK |
4866 | format_start = data; |
4867 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4868 | { |
cd30bcef AM |
4869 | SKIP_ULEB (data, end); |
4870 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4871 | } |
a262ae96 | 4872 | |
cd30bcef | 4873 | READ_ULEB (n_directories, data, end); |
55b26492 | 4874 | if (data >= end) |
d8024a91 | 4875 | { |
77145576 | 4876 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4877 | break; |
4878 | } | |
4879 | ||
070b775f NC |
4880 | if (n_directories == 0) |
4881 | directory_table = NULL; | |
4882 | else | |
4883 | directory_table = (unsigned char **) | |
4884 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4885 | |
77145576 | 4886 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4887 | { |
77145576 | 4888 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4889 | |
77145576 JK |
4890 | format = format_start; |
4891 | for (formati = 0; formati < format_count; formati++) | |
4892 | { | |
4893 | dwarf_vma content_type, form; | |
4894 | dwarf_vma uvalue; | |
4895 | ||
cd30bcef AM |
4896 | READ_ULEB (content_type, format, end); |
4897 | READ_ULEB (form, format, end); | |
55b26492 | 4898 | if (data >= end) |
77145576 JK |
4899 | { |
4900 | warn (_("Corrupt directories list\n")); | |
4901 | break; | |
4902 | } | |
4903 | switch (content_type) | |
4904 | { | |
4905 | case DW_LNCT_path: | |
4906 | switch (form) | |
4907 | { | |
4908 | case DW_FORM_string: | |
4909 | *pathp = data; | |
4910 | break; | |
4911 | case DW_FORM_line_strp: | |
4912 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4913 | end); | |
4914 | /* Remove const by the cast. */ | |
4915 | *pathp = (unsigned char *) | |
4916 | fetch_indirect_line_string (uvalue); | |
4917 | break; | |
4918 | } | |
4919 | break; | |
4920 | } | |
cd30bcef AM |
4921 | data = read_and_display_attr_value (0, form, 0, start, |
4922 | data, end, 0, 0, | |
77145576 JK |
4923 | linfo.li_offset_size, |
4924 | linfo.li_version, | |
4925 | NULL, 1, section, | |
ec1b0fbb | 4926 | NULL, '\t', -1); |
77145576 | 4927 | } |
55b26492 | 4928 | if (data >= end) |
77145576 JK |
4929 | { |
4930 | warn (_("Corrupt directories list\n")); | |
4931 | break; | |
4932 | } | |
4933 | } | |
a262ae96 | 4934 | |
77145576 JK |
4935 | /* Skip files format. */ |
4936 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4937 | if (do_checks && format_count > 5) |
4938 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), | |
4939 | format_count); | |
77145576 JK |
4940 | format_start = data; |
4941 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4942 | { |
cd30bcef AM |
4943 | SKIP_ULEB (data, end); |
4944 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4945 | } |
a262ae96 | 4946 | |
cd30bcef | 4947 | READ_ULEB (n_files, data, end); |
55b26492 | 4948 | if (data >= end && n_files > 0) |
d8024a91 | 4949 | { |
77145576 | 4950 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4951 | break; |
4952 | } | |
4953 | ||
070b775f NC |
4954 | if (n_files == 0) |
4955 | file_table = NULL; | |
4956 | else | |
4957 | file_table = (File_Entry *) xcalloc (1, n_files | |
4958 | * sizeof (File_Entry)); | |
a262ae96 | 4959 | |
77145576 | 4960 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4961 | { |
77145576 | 4962 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4963 | |
77145576 JK |
4964 | format = format_start; |
4965 | for (formati = 0; formati < format_count; formati++) | |
4966 | { | |
4967 | dwarf_vma content_type, form; | |
4968 | dwarf_vma uvalue; | |
cd30bcef | 4969 | unsigned char *tmp; |
77145576 | 4970 | |
cd30bcef AM |
4971 | READ_ULEB (content_type, format, end); |
4972 | READ_ULEB (form, format, end); | |
55b26492 | 4973 | if (data >= end) |
77145576 JK |
4974 | { |
4975 | warn (_("Corrupt file name list\n")); | |
4976 | break; | |
4977 | } | |
4978 | switch (content_type) | |
4979 | { | |
4980 | case DW_LNCT_path: | |
4981 | switch (form) | |
4982 | { | |
4983 | case DW_FORM_string: | |
4984 | file->name = data; | |
4985 | break; | |
4986 | case DW_FORM_line_strp: | |
4987 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4988 | end); | |
4989 | /* Remove const by the cast. */ | |
4990 | file->name = (unsigned char *) | |
4991 | fetch_indirect_line_string (uvalue); | |
4992 | break; | |
4993 | } | |
4994 | break; | |
4995 | case DW_LNCT_directory_index: | |
4996 | switch (form) | |
4997 | { | |
4998 | case DW_FORM_data1: | |
4999 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
5000 | end); | |
5001 | break; | |
5002 | case DW_FORM_data2: | |
5003 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
5004 | end); | |
5005 | break; | |
5006 | case DW_FORM_udata: | |
cd30bcef AM |
5007 | tmp = data; |
5008 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
5009 | break; |
5010 | } | |
5011 | break; | |
5012 | } | |
cd30bcef AM |
5013 | data = read_and_display_attr_value (0, form, 0, start, |
5014 | data, end, 0, 0, | |
77145576 JK |
5015 | linfo.li_offset_size, |
5016 | linfo.li_version, | |
5017 | NULL, 1, section, | |
ec1b0fbb | 5018 | NULL, '\t', -1); |
77145576 | 5019 | } |
55b26492 | 5020 | if (data >= end) |
77145576 JK |
5021 | { |
5022 | warn (_("Corrupt file name list\n")); | |
5023 | break; | |
5024 | } | |
5025 | } | |
5026 | } | |
5027 | else | |
5028 | { | |
5029 | if (*data != 0) | |
b40bf0a2 | 5030 | { |
77145576 JK |
5031 | unsigned char *ptr_directory_table = data; |
5032 | ||
5033 | while (data < end && *data != 0) | |
5034 | { | |
a7077ce7 AM |
5035 | data += strnlen ((char *) data, end - data); |
5036 | if (data < end) | |
5037 | data++; | |
77145576 JK |
5038 | n_directories++; |
5039 | } | |
5040 | ||
5041 | /* PR 20440 */ | |
5042 | if (data >= end) | |
5043 | { | |
5044 | warn (_("directory table ends unexpectedly\n")); | |
5045 | n_directories = 0; | |
5046 | break; | |
5047 | } | |
5048 | ||
5049 | /* Go through the directory table again to save the directories. */ | |
5050 | directory_table = (unsigned char **) | |
5051 | xmalloc (n_directories * sizeof (unsigned char *)); | |
5052 | ||
5053 | i = 0; | |
5054 | while (*ptr_directory_table != 0) | |
5055 | { | |
5056 | directory_table[i] = ptr_directory_table; | |
56051e28 AM |
5057 | ptr_directory_table |
5058 | += strlen ((char *) ptr_directory_table) + 1; | |
77145576 JK |
5059 | i++; |
5060 | } | |
b40bf0a2 | 5061 | } |
77145576 JK |
5062 | /* Skip the NUL at the end of the table. */ |
5063 | data++; | |
5064 | ||
5065 | /* Traverse the File Name table just to count the entries. */ | |
5066 | if (data < end && *data != 0) | |
b40bf0a2 | 5067 | { |
77145576 JK |
5068 | unsigned char *ptr_file_name_table = data; |
5069 | ||
5070 | while (data < end && *data != 0) | |
db9537d2 | 5071 | { |
cd30bcef AM |
5072 | /* Skip Name, directory index, last modification |
5073 | time and length of file. */ | |
a7077ce7 AM |
5074 | data += strnlen ((char *) data, end - data); |
5075 | if (data < end) | |
5076 | data++; | |
cd30bcef AM |
5077 | SKIP_ULEB (data, end); |
5078 | SKIP_ULEB (data, end); | |
5079 | SKIP_ULEB (data, end); | |
77145576 | 5080 | n_files++; |
db9537d2 | 5081 | } |
a262ae96 | 5082 | |
77145576 JK |
5083 | if (data >= end) |
5084 | { | |
5085 | warn (_("file table ends unexpectedly\n")); | |
5086 | n_files = 0; | |
5087 | break; | |
5088 | } | |
5089 | ||
5090 | /* Go through the file table again to save the strings. */ | |
5091 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 5092 | |
77145576 JK |
5093 | i = 0; |
5094 | while (*ptr_file_name_table != 0) | |
5095 | { | |
77145576 | 5096 | file_table[i].name = ptr_file_name_table; |
56051e28 AM |
5097 | ptr_file_name_table |
5098 | += strlen ((char *) ptr_file_name_table) + 1; | |
77145576 JK |
5099 | |
5100 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
5101 | READ_ULEB (file_table[i].directory_index, |
5102 | ptr_file_name_table, end); | |
5103 | READ_ULEB (file_table[i].modification_date, | |
5104 | ptr_file_name_table, end); | |
5105 | READ_ULEB (file_table[i].length, | |
5106 | ptr_file_name_table, end); | |
77145576 JK |
5107 | i++; |
5108 | } | |
5109 | i = 0; | |
b40bf0a2 | 5110 | } |
77145576 JK |
5111 | |
5112 | /* Skip the NUL at the end of the table. */ | |
5113 | data++; | |
b40bf0a2 | 5114 | } |
cc5914eb | 5115 | |
77145576 | 5116 | /* Print the Compilation Unit's name and a header. */ |
f082820d | 5117 | if (file_table == NULL) |
070b775f | 5118 | printf (_("CU: No directory table\n")); |
f082820d AM |
5119 | else if (directory_table == NULL) |
5120 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
5121 | else |
5122 | { | |
5123 | unsigned int ix = file_table[0].directory_index; | |
5124 | const char *directory; | |
5125 | ||
5126 | if (ix == 0) | |
5127 | directory = "."; | |
5128 | /* PR 20439 */ | |
5129 | else if (n_directories == 0) | |
5130 | directory = _("<unknown>"); | |
5131 | else if (ix > n_directories) | |
5132 | { | |
5133 | warn (_("directory index %u > number of directories %s\n"), | |
5134 | ix, dwarf_vmatoa ("u", n_directories)); | |
5135 | directory = _("<corrupt>"); | |
5136 | } | |
5137 | else | |
5138 | directory = (char *) directory_table[ix - 1]; | |
5139 | ||
5140 | if (do_wide || strlen (directory) < 76) | |
5141 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
5142 | else | |
5143 | printf ("%s:\n", file_table[0].name); | |
77145576 | 5144 | } |
a262ae96 | 5145 | |
070b775f NC |
5146 | if (n_files > 0) |
5147 | printf (_("File name Line number Starting address View Stmt\n")); | |
5148 | else | |
5149 | printf (_("CU: Empty file name table\n")); | |
b40bf0a2 NC |
5150 | saved_linfo = linfo; |
5151 | } | |
a262ae96 NC |
5152 | |
5153 | /* This loop iterates through the Dwarf Line Number Program. */ | |
5154 | while (data < end_of_sequence) | |
b4eb7656 | 5155 | { |
a262ae96 | 5156 | unsigned char op_code; |
ba8826a8 | 5157 | int xop; |
b4eb7656 AM |
5158 | int adv; |
5159 | unsigned long int uladv; | |
b4eb7656 | 5160 | int is_special_opcode = 0; |
a262ae96 | 5161 | |
b4eb7656 | 5162 | op_code = *data++; |
ba8826a8 | 5163 | xop = op_code; |
a262ae96 | 5164 | |
b4eb7656 | 5165 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 5166 | { |
91d6fa6a | 5167 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
5168 | uladv = (op_code / linfo.li_line_range); |
5169 | if (linfo.li_max_ops_per_insn == 1) | |
5170 | { | |
5171 | uladv *= linfo.li_min_insn_length; | |
5172 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
5173 | if (uladv) |
5174 | state_machine_regs.view = 0; | |
a233b20c JJ |
5175 | } |
5176 | else | |
5177 | { | |
ba8826a8 AO |
5178 | unsigned addrdelta |
5179 | = ((state_machine_regs.op_index + uladv) | |
5180 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 5181 | * linfo.li_min_insn_length; |
ba8826a8 AO |
5182 | state_machine_regs.address |
5183 | += addrdelta; | |
a233b20c JJ |
5184 | state_machine_regs.op_index |
5185 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 5186 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
5187 | if (addrdelta) |
5188 | state_machine_regs.view = 0; | |
a233b20c | 5189 | } |
a262ae96 | 5190 | |
b4eb7656 AM |
5191 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
5192 | state_machine_regs.line += adv; | |
5193 | is_special_opcode = 1; | |
ba8826a8 | 5194 | /* Increment view after printing this row. */ |
b4eb7656 | 5195 | } |
cd30bcef AM |
5196 | else |
5197 | switch (op_code) | |
5198 | { | |
5199 | case DW_LNS_extended_op: | |
5200 | { | |
5201 | unsigned int ext_op_code_len; | |
5202 | unsigned char ext_op_code; | |
5203 | unsigned char *op_code_end; | |
5204 | unsigned char *op_code_data = data; | |
5205 | ||
5206 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
5207 | op_code_end = op_code_data + ext_op_code_len; | |
5208 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
5209 | { | |
5210 | warn (_("Badly formed extended line op encountered!\n")); | |
5211 | break; | |
5212 | } | |
5213 | ext_op_code = *op_code_data++; | |
5214 | xop = ext_op_code; | |
5215 | xop = -xop; | |
5216 | ||
5217 | switch (ext_op_code) | |
5218 | { | |
5219 | case DW_LNE_end_sequence: | |
5220 | /* Reset stuff after printing this row. */ | |
5221 | break; | |
5222 | case DW_LNE_set_address: | |
5223 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
5224 | op_code_data, | |
5225 | op_code_end - op_code_data, | |
5226 | op_code_end); | |
5227 | state_machine_regs.op_index = 0; | |
5228 | state_machine_regs.view = 0; | |
5229 | break; | |
5230 | case DW_LNE_define_file: | |
5231 | file_table = (File_Entry *) xrealloc | |
5232 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
5233 | ||
5234 | ++state_machine_regs.last_file_entry; | |
5235 | /* Source file name. */ | |
5236 | file_table[n_files].name = op_code_data; | |
5237 | op_code_data += strlen ((char *) op_code_data) + 1; | |
5238 | /* Directory index. */ | |
5239 | READ_ULEB (file_table[n_files].directory_index, | |
5240 | op_code_data, op_code_end); | |
5241 | /* Last modification time. */ | |
5242 | READ_ULEB (file_table[n_files].modification_date, | |
5243 | op_code_data, op_code_end); | |
5244 | /* File length. */ | |
5245 | READ_ULEB (file_table[n_files].length, | |
5246 | op_code_data, op_code_end); | |
5247 | n_files++; | |
5248 | break; | |
5249 | ||
5250 | case DW_LNE_set_discriminator: | |
5251 | case DW_LNE_HP_set_sequence: | |
5252 | /* Simply ignored. */ | |
5253 | break; | |
5254 | ||
5255 | default: | |
5256 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 5257 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
5258 | break; |
5259 | } | |
5260 | data = op_code_end; | |
5261 | break; | |
5262 | } | |
5263 | case DW_LNS_copy: | |
5264 | /* Increment view after printing this row. */ | |
5265 | break; | |
5266 | ||
5267 | case DW_LNS_advance_pc: | |
5268 | READ_ULEB (uladv, data, end); | |
5269 | if (linfo.li_max_ops_per_insn == 1) | |
5270 | { | |
5271 | uladv *= linfo.li_min_insn_length; | |
5272 | state_machine_regs.address += uladv; | |
5273 | if (uladv) | |
5274 | state_machine_regs.view = 0; | |
5275 | } | |
5276 | else | |
5277 | { | |
5278 | unsigned addrdelta | |
5279 | = ((state_machine_regs.op_index + uladv) | |
5280 | / linfo.li_max_ops_per_insn) | |
5281 | * linfo.li_min_insn_length; | |
5282 | state_machine_regs.address | |
5283 | += addrdelta; | |
5284 | state_machine_regs.op_index | |
5285 | = (state_machine_regs.op_index + uladv) | |
5286 | % linfo.li_max_ops_per_insn; | |
5287 | if (addrdelta) | |
5288 | state_machine_regs.view = 0; | |
5289 | } | |
5290 | break; | |
5291 | ||
5292 | case DW_LNS_advance_line: | |
5293 | READ_SLEB (adv, data, end); | |
5294 | state_machine_regs.line += adv; | |
5295 | break; | |
5296 | ||
5297 | case DW_LNS_set_file: | |
5298 | READ_ULEB (uladv, data, end); | |
5299 | state_machine_regs.file = uladv; | |
5300 | ||
5301 | { | |
5302 | unsigned file = state_machine_regs.file - 1; | |
5303 | unsigned dir; | |
5304 | ||
5305 | if (file_table == NULL || n_files == 0) | |
5306 | printf (_("\n [Use file table entry %d]\n"), file); | |
5307 | /* PR 20439 */ | |
5308 | else if (file >= n_files) | |
5309 | { | |
5310 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
5311 | printf (_("\n <over large file table index %u>"), file); | |
5312 | } | |
5313 | else if ((dir = file_table[file].directory_index) == 0) | |
5314 | /* If directory index is 0, that means current directory. */ | |
5315 | printf ("\n./%s:[++]\n", file_table[file].name); | |
5316 | else if (directory_table == NULL || n_directories == 0) | |
5317 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
5318 | file_table[file].name, dir); | |
5319 | /* PR 20439 */ | |
5320 | else if (dir > n_directories) | |
5321 | { | |
5322 | warn (_("directory index %u > number of directories %s\n"), | |
5323 | dir, dwarf_vmatoa ("u", n_directories)); | |
5324 | printf (_("\n <over large directory table entry %u>\n"), dir); | |
5325 | } | |
5326 | else | |
5327 | printf ("\n%s/%s:\n", | |
5328 | /* The directory index starts counting at 1. */ | |
5329 | directory_table[dir - 1], file_table[file].name); | |
5330 | } | |
5331 | break; | |
5332 | ||
5333 | case DW_LNS_set_column: | |
5334 | READ_ULEB (uladv, data, end); | |
5335 | state_machine_regs.column = uladv; | |
5336 | break; | |
5337 | ||
5338 | case DW_LNS_negate_stmt: | |
5339 | adv = state_machine_regs.is_stmt; | |
5340 | adv = ! adv; | |
5341 | state_machine_regs.is_stmt = adv; | |
5342 | break; | |
5343 | ||
5344 | case DW_LNS_set_basic_block: | |
5345 | state_machine_regs.basic_block = 1; | |
5346 | break; | |
5347 | ||
5348 | case DW_LNS_const_add_pc: | |
5349 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
5350 | if (linfo.li_max_ops_per_insn == 1) | |
5351 | { | |
5352 | uladv *= linfo.li_min_insn_length; | |
5353 | state_machine_regs.address += uladv; | |
5354 | if (uladv) | |
5355 | state_machine_regs.view = 0; | |
5356 | } | |
5357 | else | |
5358 | { | |
5359 | unsigned addrdelta | |
5360 | = ((state_machine_regs.op_index + uladv) | |
5361 | / linfo.li_max_ops_per_insn) | |
5362 | * linfo.li_min_insn_length; | |
5363 | state_machine_regs.address | |
5364 | += addrdelta; | |
5365 | state_machine_regs.op_index | |
5366 | = (state_machine_regs.op_index + uladv) | |
5367 | % linfo.li_max_ops_per_insn; | |
5368 | if (addrdelta) | |
5369 | state_machine_regs.view = 0; | |
5370 | } | |
5371 | break; | |
5372 | ||
5373 | case DW_LNS_fixed_advance_pc: | |
5374 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5375 | state_machine_regs.address += uladv; | |
5376 | state_machine_regs.op_index = 0; | |
5377 | /* Do NOT reset view. */ | |
5378 | break; | |
5379 | ||
5380 | case DW_LNS_set_prologue_end: | |
5381 | break; | |
5382 | ||
5383 | case DW_LNS_set_epilogue_begin: | |
5384 | break; | |
5385 | ||
5386 | case DW_LNS_set_isa: | |
5387 | READ_ULEB (uladv, data, end); | |
5388 | printf (_(" Set ISA to %lu\n"), uladv); | |
5389 | break; | |
5390 | ||
5391 | default: | |
5392 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5393 | ||
5394 | if (standard_opcodes != NULL) | |
5395 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5396 | { | |
5397 | dwarf_vma val; | |
5398 | ||
5399 | READ_ULEB (val, data, end); | |
5400 | printf ("0x%s%s", dwarf_vmatoa ("x", val), | |
5401 | i == 1 ? "" : ", "); | |
5402 | } | |
5403 | putchar ('\n'); | |
5404 | break; | |
5405 | } | |
a262ae96 | 5406 | |
b4eb7656 AM |
5407 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
5408 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
5409 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
5410 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
5411 | { |
5412 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
5413 | char *fileName; | |
5414 | char *newFileName = NULL; | |
5415 | size_t fileNameLength; | |
b40bf0a2 NC |
5416 | |
5417 | if (file_table) | |
db9537d2 NC |
5418 | { |
5419 | unsigned indx = state_machine_regs.file - 1; | |
5420 | /* PR 20439 */ | |
5421 | if (indx >= n_files) | |
5422 | { | |
5423 | warn (_("corrupt file index %u encountered\n"), indx); | |
5424 | fileName = _("<corrupt>"); | |
5425 | } | |
5426 | else | |
5427 | fileName = (char *) file_table[indx].name; | |
5428 | } | |
b40bf0a2 | 5429 | else |
db9537d2 | 5430 | fileName = _("<unknown>"); |
b40bf0a2 NC |
5431 | |
5432 | fileNameLength = strlen (fileName); | |
539b54f0 AM |
5433 | newFileName = fileName; |
5434 | if (fileNameLength > MAX_FILENAME_LENGTH && !do_wide) | |
b4eb7656 AM |
5435 | { |
5436 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5437 | /* Truncate file name */ | |
539b54f0 AM |
5438 | memcpy (newFileName, |
5439 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5440 | MAX_FILENAME_LENGTH); | |
e1104d08 | 5441 | newFileName[MAX_FILENAME_LENGTH] = 0; |
b4eb7656 | 5442 | } |
b4eb7656 | 5443 | |
af2b3186 TV |
5444 | /* A row with end_seq set to true has a meaningful address, but |
5445 | the other information in the same row is not significant. | |
5446 | In such a row, print line as "-", and don't print | |
5447 | view/is_stmt. */ | |
539b54f0 | 5448 | if (!do_wide || fileNameLength <= MAX_FILENAME_LENGTH) |
b4eb7656 | 5449 | { |
a233b20c | 5450 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5451 | { |
5452 | if (xop == -DW_LNE_end_sequence) | |
5453 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x", | |
5454 | newFileName, "-", | |
5455 | state_machine_regs.address); | |
5456 | else | |
5457 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", | |
5458 | newFileName, state_machine_regs.line, | |
5459 | state_machine_regs.address); | |
5460 | } | |
a233b20c | 5461 | else |
af2b3186 TV |
5462 | { |
5463 | if (xop == -DW_LNE_end_sequence) | |
5464 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5465 | newFileName, "-", | |
5466 | state_machine_regs.address, | |
5467 | state_machine_regs.op_index); | |
5468 | else | |
5469 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5470 | newFileName, state_machine_regs.line, | |
5471 | state_machine_regs.address, | |
5472 | state_machine_regs.op_index); | |
5473 | } | |
b4eb7656 AM |
5474 | } |
5475 | else | |
5476 | { | |
a233b20c | 5477 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5478 | { |
5479 | if (xop == -DW_LNE_end_sequence) | |
5480 | printf ("%s %11s %#18" DWARF_VMA_FMT "x", | |
5481 | newFileName, "-", | |
5482 | state_machine_regs.address); | |
5483 | else | |
5484 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", | |
5485 | newFileName, state_machine_regs.line, | |
5486 | state_machine_regs.address); | |
5487 | } | |
a233b20c | 5488 | else |
af2b3186 TV |
5489 | { |
5490 | if (xop == -DW_LNE_end_sequence) | |
5491 | printf ("%s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5492 | newFileName, "-", | |
5493 | state_machine_regs.address, | |
5494 | state_machine_regs.op_index); | |
5495 | else | |
5496 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5497 | newFileName, state_machine_regs.line, | |
5498 | state_machine_regs.address, | |
5499 | state_machine_regs.op_index); | |
5500 | } | |
b4eb7656 | 5501 | } |
a262ae96 | 5502 | |
af2b3186 TV |
5503 | if (xop != -DW_LNE_end_sequence) |
5504 | { | |
5505 | if (state_machine_regs.view) | |
5506 | printf (" %6u", state_machine_regs.view); | |
5507 | else | |
5508 | printf (" "); | |
17f6ade2 | 5509 | |
af2b3186 TV |
5510 | if (state_machine_regs.is_stmt) |
5511 | printf (" x"); | |
5512 | } | |
17f6ade2 JD |
5513 | |
5514 | putchar ('\n'); | |
ba8826a8 AO |
5515 | state_machine_regs.view++; |
5516 | ||
5517 | if (xop == -DW_LNE_end_sequence) | |
5518 | { | |
5519 | reset_state_machine (linfo.li_default_is_stmt); | |
5520 | putchar ('\n'); | |
5521 | } | |
a262ae96 | 5522 | |
539b54f0 AM |
5523 | if (newFileName != fileName) |
5524 | free (newFileName); | |
b4eb7656 AM |
5525 | } |
5526 | } | |
b40bf0a2 NC |
5527 | |
5528 | if (file_table) | |
5529 | { | |
5530 | free (file_table); | |
5531 | file_table = NULL; | |
5532 | n_files = 0; | |
5533 | } | |
5534 | ||
5535 | if (directory_table) | |
5536 | { | |
5537 | free (directory_table); | |
5538 | directory_table = NULL; | |
5539 | n_directories = 0; | |
5540 | } | |
5541 | ||
a262ae96 NC |
5542 | putchar ('\n'); |
5543 | } | |
5544 | ||
5545 | return 1; | |
5546 | } | |
5547 | ||
5548 | static int | |
77145576 | 5549 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5550 | { |
5551 | unsigned char *data = section->start; | |
5552 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5553 | int retValRaw = 1; |
5554 | int retValDecoded = 1; | |
a262ae96 | 5555 | |
008f4c78 NC |
5556 | if (do_debug_lines == 0) |
5557 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5558 | ||
4cb93e3b | 5559 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5560 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5561 | |
4cb93e3b | 5562 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5563 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5564 | |
4cb93e3b | 5565 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5566 | return 0; |
5567 | ||
5568 | return 1; | |
5569 | } | |
5570 | ||
6e3d6dc1 NC |
5571 | static debug_info * |
5572 | find_debug_info_for_offset (unsigned long offset) | |
5573 | { | |
5574 | unsigned int i; | |
5575 | ||
5576 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5577 | return NULL; | |
5578 | ||
5579 | for (i = 0; i < num_debug_info_entries; i++) | |
5580 | if (debug_information[i].cu_offset == offset) | |
5581 | return debug_information + i; | |
5582 | ||
5583 | return NULL; | |
5584 | } | |
5585 | ||
459d52c8 DE |
5586 | static const char * |
5587 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5588 | { | |
5589 | /* See gdb/gdb-index.h. */ | |
5590 | static const char * const kinds[] = | |
5591 | { | |
5592 | N_ ("no info"), | |
5593 | N_ ("type"), | |
5594 | N_ ("variable"), | |
5595 | N_ ("function"), | |
5596 | N_ ("other"), | |
5597 | N_ ("unused5"), | |
5598 | N_ ("unused6"), | |
5599 | N_ ("unused7") | |
5600 | }; | |
5601 | ||
5602 | return _ (kinds[kind]); | |
5603 | } | |
5604 | ||
19e6b90e | 5605 | static int |
459d52c8 DE |
5606 | display_debug_pubnames_worker (struct dwarf_section *section, |
5607 | void *file ATTRIBUTE_UNUSED, | |
5608 | int is_gnu) | |
19e6b90e | 5609 | { |
91d6fa6a | 5610 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5611 | unsigned char *start = section->start; |
5612 | unsigned char *end = start + section->size; | |
5613 | ||
6e3d6dc1 NC |
5614 | /* It does not matter if this load fails, |
5615 | we test for that later on. */ | |
5616 | load_debug_info (file); | |
5617 | ||
015dc7e1 | 5618 | introduce (section, false); |
19e6b90e L |
5619 | |
5620 | while (start < end) | |
5621 | { | |
5622 | unsigned char *data; | |
35b2c89e AM |
5623 | unsigned long sec_off = start - section->start; |
5624 | unsigned int offset_size; | |
19e6b90e | 5625 | |
e98fdf1a | 5626 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5627 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5628 | { |
e98fdf1a | 5629 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e | 5630 | offset_size = 8; |
19e6b90e L |
5631 | } |
5632 | else | |
35b2c89e | 5633 | offset_size = 4; |
19e6b90e | 5634 | |
35b2c89e | 5635 | if (names.pn_length > (size_t) (end - start)) |
e98fdf1a AM |
5636 | { |
5637 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5638 | section->name, | |
35b2c89e | 5639 | sec_off, |
e98fdf1a AM |
5640 | dwarf_vmatoa ("x", names.pn_length)); |
5641 | break; | |
5642 | } | |
5643 | ||
5644 | data = start; | |
5645 | start += names.pn_length; | |
5646 | ||
35b2c89e AM |
5647 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, start); |
5648 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, start); | |
6e3d6dc1 NC |
5649 | |
5650 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5651 | && num_debug_info_entries > 0 | |
91d6fa6a | 5652 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5653 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5654 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5655 | |
35b2c89e | 5656 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, start); |
19e6b90e | 5657 | |
058037d3 NC |
5658 | printf (_(" Length: %ld\n"), |
5659 | (long) names.pn_length); | |
5660 | printf (_(" Version: %d\n"), | |
5661 | names.pn_version); | |
5662 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5663 | (unsigned long) names.pn_offset); | |
5664 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5665 | (long) names.pn_size); | |
19e6b90e | 5666 | |
91d6fa6a | 5667 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5668 | { |
5669 | static int warned = 0; | |
5670 | ||
5671 | if (! warned) | |
5672 | { | |
5673 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5674 | warned = 1; | |
5675 | } | |
5676 | ||
5677 | continue; | |
5678 | } | |
5679 | ||
459d52c8 DE |
5680 | if (is_gnu) |
5681 | printf (_("\n Offset Kind Name\n")); | |
5682 | else | |
5683 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5684 | |
e98fdf1a | 5685 | while (1) |
19e6b90e | 5686 | { |
f41e4712 | 5687 | bfd_size_type maxprint; |
e98fdf1a | 5688 | dwarf_vma offset; |
f41e4712 | 5689 | |
35b2c89e | 5690 | SAFE_BYTE_GET_AND_INC (offset, data, offset_size, start); |
19e6b90e | 5691 | |
e98fdf1a AM |
5692 | if (offset == 0) |
5693 | break; | |
b4eb7656 | 5694 | |
35b2c89e | 5695 | if (data >= start) |
e98fdf1a | 5696 | break; |
35b2c89e | 5697 | maxprint = (start - data) - 1; |
f41e4712 | 5698 | |
e98fdf1a AM |
5699 | if (is_gnu) |
5700 | { | |
5701 | unsigned int kind_data; | |
5702 | gdb_index_symbol_kind kind; | |
5703 | const char *kind_name; | |
5704 | int is_static; | |
5705 | ||
35b2c89e | 5706 | SAFE_BYTE_GET_AND_INC (kind_data, data, 1, start); |
e98fdf1a AM |
5707 | maxprint --; |
5708 | /* GCC computes the kind as the upper byte in the CU index | |
5709 | word, and then right shifts it by the CU index size. | |
5710 | Left shift KIND to where the gdb-index.h accessor macros | |
5711 | can use it. */ | |
5712 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5713 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5714 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5715 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5716 | printf (" %-6lx %s,%-10s %.*s\n", | |
5717 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5718 | kind_name, (int) maxprint, data); | |
19e6b90e | 5719 | } |
e98fdf1a AM |
5720 | else |
5721 | printf (" %-6lx\t%.*s\n", | |
5722 | (unsigned long) offset, (int) maxprint, data); | |
5723 | ||
a7077ce7 | 5724 | data += strnlen ((char *) data, maxprint); |
35b2c89e | 5725 | if (data < start) |
a7077ce7 | 5726 | data++; |
35b2c89e | 5727 | if (data >= start) |
e98fdf1a | 5728 | break; |
19e6b90e | 5729 | } |
19e6b90e L |
5730 | } |
5731 | ||
5732 | printf ("\n"); | |
5733 | return 1; | |
5734 | } | |
5735 | ||
459d52c8 DE |
5736 | static int |
5737 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5738 | { | |
5739 | return display_debug_pubnames_worker (section, file, 0); | |
5740 | } | |
5741 | ||
5742 | static int | |
5743 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5744 | { | |
5745 | return display_debug_pubnames_worker (section, file, 1); | |
5746 | } | |
5747 | ||
19e6b90e L |
5748 | static int |
5749 | display_debug_macinfo (struct dwarf_section *section, | |
5750 | void *file ATTRIBUTE_UNUSED) | |
5751 | { | |
5752 | unsigned char *start = section->start; | |
5753 | unsigned char *end = start + section->size; | |
5754 | unsigned char *curr = start; | |
19e6b90e L |
5755 | enum dwarf_macinfo_record_type op; |
5756 | ||
015dc7e1 | 5757 | introduce (section, false); |
19e6b90e L |
5758 | |
5759 | while (curr < end) | |
5760 | { | |
5761 | unsigned int lineno; | |
0c588247 | 5762 | const unsigned char *string; |
19e6b90e | 5763 | |
3f5e193b | 5764 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5765 | curr++; |
5766 | ||
5767 | switch (op) | |
5768 | { | |
5769 | case DW_MACINFO_start_file: | |
5770 | { | |
5771 | unsigned int filenum; | |
5772 | ||
cd30bcef AM |
5773 | READ_ULEB (lineno, curr, end); |
5774 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
5775 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
5776 | lineno, filenum); | |
5777 | } | |
5778 | break; | |
5779 | ||
5780 | case DW_MACINFO_end_file: | |
5781 | printf (_(" DW_MACINFO_end_file\n")); | |
5782 | break; | |
5783 | ||
5784 | case DW_MACINFO_define: | |
cd30bcef | 5785 | READ_ULEB (lineno, curr, end); |
0c588247 | 5786 | string = curr; |
c03df922 AM |
5787 | curr += strnlen ((char *) string, end - string); |
5788 | printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"), | |
5789 | lineno, (int) (curr - string), string); | |
5790 | if (curr < end) | |
5791 | curr++; | |
19e6b90e L |
5792 | break; |
5793 | ||
5794 | case DW_MACINFO_undef: | |
cd30bcef | 5795 | READ_ULEB (lineno, curr, end); |
0c588247 | 5796 | string = curr; |
c03df922 AM |
5797 | curr += strnlen ((char *) string, end - string); |
5798 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"), | |
5799 | lineno, (int) (curr - string), string); | |
5800 | if (curr < end) | |
5801 | curr++; | |
19e6b90e L |
5802 | break; |
5803 | ||
5804 | case DW_MACINFO_vendor_ext: | |
5805 | { | |
5806 | unsigned int constant; | |
5807 | ||
cd30bcef | 5808 | READ_ULEB (constant, curr, end); |
0c588247 | 5809 | string = curr; |
c03df922 AM |
5810 | curr += strnlen ((char *) string, end - string); |
5811 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"), | |
5812 | constant, (int) (curr - string), string); | |
5813 | if (curr < end) | |
5814 | curr++; | |
19e6b90e L |
5815 | } |
5816 | break; | |
5817 | } | |
5818 | } | |
5819 | ||
5820 | return 1; | |
5821 | } | |
5822 | ||
4ccf1e31 JJ |
5823 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5824 | filename and dirname corresponding to file name table entry with index | |
5825 | FILEIDX. Return NULL on failure. */ | |
5826 | ||
5827 | static unsigned char * | |
f6f0e17b NC |
5828 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5829 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5830 | unsigned char **dir_name) |
5831 | { | |
5832 | struct dwarf_section *section = &debug_displays [line].section; | |
5833 | unsigned char *hdrptr, *dirtable, *file_name; | |
46d1214d | 5834 | unsigned int offset_size; |
cd30bcef | 5835 | unsigned int version, opcode_base; |
4ccf1e31 | 5836 | dwarf_vma length, diridx; |
f6f0e17b | 5837 | const unsigned char * end; |
4ccf1e31 JJ |
5838 | |
5839 | *dir_name = NULL; | |
5840 | if (section->start == NULL | |
5841 | || line_offset >= section->size | |
5842 | || fileidx == 0) | |
5843 | return NULL; | |
5844 | ||
5845 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5846 | end = section->start + section->size; |
0c588247 NC |
5847 | |
5848 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5849 | if (length == 0xffffffff) |
5850 | { | |
5851 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5852 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 | 5853 | offset_size = 8; |
4ccf1e31 JJ |
5854 | } |
5855 | else | |
46d1214d AM |
5856 | offset_size = 4; |
5857 | ||
5858 | if (length > (size_t) (end - hdrptr) | |
5859 | || length < 2 + offset_size + 1 + 3 + 1) | |
4ccf1e31 | 5860 | return NULL; |
46d1214d | 5861 | end = hdrptr + length; |
0c588247 NC |
5862 | |
5863 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5864 | if (version != 2 && version != 3 && version != 4) |
5865 | return NULL; | |
5866 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5867 | if (version >= 4) | |
5868 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5869 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5870 | |
5871 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
46d1214d AM |
5872 | if (opcode_base == 0 |
5873 | || opcode_base - 1 >= (size_t) (end - hdrptr)) | |
4ccf1e31 | 5874 | return NULL; |
0c588247 | 5875 | |
4ccf1e31 | 5876 | hdrptr += opcode_base - 1; |
5c1c468d | 5877 | |
4ccf1e31 JJ |
5878 | dirtable = hdrptr; |
5879 | /* Skip over dirname table. */ | |
5880 | while (*hdrptr != '\0') | |
5c1c468d | 5881 | { |
46d1214d AM |
5882 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
5883 | if (hdrptr < end) | |
5884 | hdrptr++; | |
5c1c468d NC |
5885 | if (hdrptr >= end) |
5886 | return NULL; | |
5887 | } | |
4ccf1e31 | 5888 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5889 | |
4ccf1e31 | 5890 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5891 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5892 | { |
46d1214d AM |
5893 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
5894 | if (hdrptr < end) | |
5895 | hdrptr++; | |
cd30bcef AM |
5896 | SKIP_ULEB (hdrptr, end); |
5897 | SKIP_ULEB (hdrptr, end); | |
5898 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 5899 | } |
5c1c468d | 5900 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5901 | return NULL; |
5c1c468d | 5902 | |
4ccf1e31 | 5903 | file_name = hdrptr; |
46d1214d AM |
5904 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
5905 | if (hdrptr < end) | |
5906 | hdrptr++; | |
5c1c468d NC |
5907 | if (hdrptr >= end) |
5908 | return NULL; | |
cd30bcef | 5909 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
5910 | if (diridx == 0) |
5911 | return file_name; | |
5c1c468d | 5912 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
46d1214d AM |
5913 | { |
5914 | dirtable += strnlen ((char *) dirtable, end - dirtable); | |
5915 | if (dirtable < end) | |
5916 | dirtable++; | |
5917 | } | |
5c1c468d | 5918 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5919 | return NULL; |
5920 | *dir_name = dirtable; | |
5921 | return file_name; | |
5922 | } | |
5923 | ||
5924 | static int | |
5925 | display_debug_macro (struct dwarf_section *section, | |
5926 | void *file) | |
5927 | { | |
5928 | unsigned char *start = section->start; | |
5929 | unsigned char *end = start + section->size; | |
5930 | unsigned char *curr = start; | |
5931 | unsigned char *extended_op_buf[256]; | |
015dc7e1 | 5932 | bool is_dwo = false; |
d296b736 NC |
5933 | const char *suffix = strrchr (section->name, '.'); |
5934 | ||
5935 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
015dc7e1 | 5936 | is_dwo = true; |
4ccf1e31 | 5937 | |
dda8d76d NC |
5938 | load_debug_section_with_follow (str, file); |
5939 | load_debug_section_with_follow (line, file); | |
e4b7104b | 5940 | load_debug_section_with_follow (str_index, file); |
d296b736 | 5941 | |
015dc7e1 | 5942 | introduce (section, false); |
4ccf1e31 JJ |
5943 | |
5944 | while (curr < end) | |
5945 | { | |
5946 | unsigned int lineno, version, flags; | |
d296b736 | 5947 | unsigned int offset_size; |
0c588247 | 5948 | const unsigned char *string; |
4ccf1e31 JJ |
5949 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5950 | unsigned char **extended_ops = NULL; | |
5951 | ||
0c588247 | 5952 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5953 | if (version != 4 && version != 5) |
4ccf1e31 | 5954 | { |
0e12f6c8 TV |
5955 | error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"), |
5956 | section->name, version); | |
4ccf1e31 JJ |
5957 | return 0; |
5958 | } | |
5959 | ||
0c588247 | 5960 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
d296b736 | 5961 | offset_size = (flags & 1) ? 8 : 4; |
4ccf1e31 JJ |
5962 | printf (_(" Offset: 0x%lx\n"), |
5963 | (unsigned long) sec_offset); | |
5964 | printf (_(" Version: %d\n"), version); | |
5965 | printf (_(" Offset size: %d\n"), offset_size); | |
5966 | if (flags & 2) | |
5967 | { | |
0c588247 | 5968 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5969 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5970 | (unsigned long) line_offset); | |
5971 | } | |
5972 | if (flags & 4) | |
5973 | { | |
0c588247 | 5974 | unsigned int i, count, op; |
4ccf1e31 | 5975 | dwarf_vma nargs, n; |
0c588247 NC |
5976 | |
5977 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5978 | |
4ccf1e31 JJ |
5979 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5980 | extended_ops = extended_op_buf; | |
5981 | if (count) | |
5982 | { | |
5983 | printf (_(" Extension opcode arguments:\n")); | |
5984 | for (i = 0; i < count; i++) | |
5985 | { | |
0c588247 | 5986 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5987 | extended_ops[op] = curr; |
cd30bcef | 5988 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 5989 | if (nargs == 0) |
7a7e1061 | 5990 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5991 | else |
5992 | { | |
7a7e1061 | 5993 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5994 | for (n = 0; n < nargs; n++) |
5995 | { | |
0c588247 NC |
5996 | unsigned int form; |
5997 | ||
5998 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5999 | printf ("%s%s", get_FORM_name (form), |
6000 | n == nargs - 1 ? "\n" : ", "); | |
6001 | switch (form) | |
6002 | { | |
6003 | case DW_FORM_data1: | |
6004 | case DW_FORM_data2: | |
6005 | case DW_FORM_data4: | |
6006 | case DW_FORM_data8: | |
6007 | case DW_FORM_sdata: | |
6008 | case DW_FORM_udata: | |
6009 | case DW_FORM_block: | |
6010 | case DW_FORM_block1: | |
6011 | case DW_FORM_block2: | |
6012 | case DW_FORM_block4: | |
6013 | case DW_FORM_flag: | |
6014 | case DW_FORM_string: | |
6015 | case DW_FORM_strp: | |
6016 | case DW_FORM_sec_offset: | |
6017 | break; | |
6018 | default: | |
6019 | error (_("Invalid extension opcode form %s\n"), | |
6020 | get_FORM_name (form)); | |
6021 | return 0; | |
6022 | } | |
6023 | } | |
6024 | } | |
6025 | } | |
6026 | } | |
6027 | } | |
6028 | printf ("\n"); | |
6029 | ||
6030 | while (1) | |
6031 | { | |
6032 | unsigned int op; | |
6033 | ||
6034 | if (curr >= end) | |
6035 | { | |
6036 | error (_(".debug_macro section not zero terminated\n")); | |
6037 | return 0; | |
6038 | } | |
6039 | ||
0c588247 | 6040 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
6041 | if (op == 0) |
6042 | break; | |
6043 | ||
6044 | switch (op) | |
6045 | { | |
e4b7104b NC |
6046 | case DW_MACRO_define: |
6047 | READ_ULEB (lineno, curr, end); | |
6048 | string = curr; | |
b0d461ec AM |
6049 | curr += strnlen ((char *) string, end - string); |
6050 | printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"), | |
6051 | lineno, (int) (curr - string), string); | |
6052 | if (curr < end) | |
6053 | curr++; | |
e4b7104b NC |
6054 | break; |
6055 | ||
6056 | case DW_MACRO_undef: | |
6057 | READ_ULEB (lineno, curr, end); | |
6058 | string = curr; | |
b0d461ec AM |
6059 | curr += strnlen ((char *) string, end - string); |
6060 | printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"), | |
6061 | lineno, (int) (curr - string), string); | |
6062 | if (curr < end) | |
6063 | curr++; | |
e4b7104b NC |
6064 | break; |
6065 | ||
7a7e1061 | 6066 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
6067 | { |
6068 | unsigned int filenum; | |
6069 | unsigned char *file_name = NULL, *dir_name = NULL; | |
6070 | ||
cd30bcef AM |
6071 | READ_ULEB (lineno, curr, end); |
6072 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
6073 | |
6074 | if ((flags & 2) == 0) | |
7a7e1061 | 6075 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
6076 | else |
6077 | file_name | |
6078 | = get_line_filename_and_dirname (line_offset, filenum, | |
6079 | &dir_name); | |
6080 | if (file_name == NULL) | |
7a7e1061 | 6081 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
6082 | lineno, filenum); |
6083 | else | |
7a7e1061 | 6084 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
6085 | lineno, filenum, |
6086 | dir_name != NULL ? (const char *) dir_name : "", | |
6087 | dir_name != NULL ? "/" : "", file_name); | |
6088 | } | |
6089 | break; | |
6090 | ||
7a7e1061 JK |
6091 | case DW_MACRO_end_file: |
6092 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
6093 | break; |
6094 | ||
7a7e1061 | 6095 | case DW_MACRO_define_strp: |
cd30bcef | 6096 | READ_ULEB (lineno, curr, end); |
d296b736 NC |
6097 | if (version == 4 && is_dwo) |
6098 | READ_ULEB (offset, curr, end); | |
6099 | else | |
6100 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
4ccf1e31 | 6101 | string = fetch_indirect_string (offset); |
7a7e1061 | 6102 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6103 | lineno, string); |
6104 | break; | |
6105 | ||
7a7e1061 | 6106 | case DW_MACRO_undef_strp: |
cd30bcef | 6107 | READ_ULEB (lineno, curr, end); |
d296b736 NC |
6108 | if (version == 4 && is_dwo) |
6109 | READ_ULEB (offset, curr, end); | |
6110 | else | |
6111 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
4ccf1e31 | 6112 | string = fetch_indirect_string (offset); |
7a7e1061 | 6113 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6114 | lineno, string); |
6115 | break; | |
6116 | ||
7a7e1061 | 6117 | case DW_MACRO_import: |
0c588247 | 6118 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6119 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
6120 | (unsigned long) offset); |
6121 | break; | |
6122 | ||
7a7e1061 | 6123 | case DW_MACRO_define_sup: |
cd30bcef | 6124 | READ_ULEB (lineno, curr, end); |
0c588247 | 6125 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6126 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
6127 | lineno, (unsigned long) offset); |
6128 | break; | |
6129 | ||
7a7e1061 | 6130 | case DW_MACRO_undef_sup: |
cd30bcef | 6131 | READ_ULEB (lineno, curr, end); |
0c588247 | 6132 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6133 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
6134 | lineno, (unsigned long) offset); |
6135 | break; | |
6136 | ||
7a7e1061 | 6137 | case DW_MACRO_import_sup: |
0c588247 | 6138 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6139 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
6140 | (unsigned long) offset); |
6141 | break; | |
6142 | ||
e4b7104b NC |
6143 | case DW_MACRO_define_strx: |
6144 | case DW_MACRO_undef_strx: | |
6145 | READ_ULEB (lineno, curr, end); | |
6146 | READ_ULEB (offset, curr, end); | |
6147 | string = (const unsigned char *) | |
015dc7e1 | 6148 | fetch_indexed_string (offset, NULL, offset_size, false); |
e4b7104b NC |
6149 | if (op == DW_MACRO_define_strx) |
6150 | printf (" DW_MACRO_define_strx "); | |
6151 | else | |
6152 | printf (" DW_MACRO_undef_strx "); | |
6153 | if (do_wide) | |
39f381cb | 6154 | printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset)); |
e4b7104b NC |
6155 | printf (_("lineno : %d macro : %s\n"), |
6156 | lineno, string); | |
6157 | break; | |
6158 | ||
4ccf1e31 | 6159 | default: |
e4b7104b NC |
6160 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) |
6161 | { | |
6162 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); | |
6163 | break; | |
6164 | } | |
6165 | ||
4ccf1e31 JJ |
6166 | if (extended_ops == NULL || extended_ops[op] == NULL) |
6167 | { | |
6168 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
6169 | return 0; | |
6170 | } | |
6171 | else | |
6172 | { | |
6173 | /* Skip over unhandled opcodes. */ | |
6174 | dwarf_vma nargs, n; | |
6175 | unsigned char *desc = extended_ops[op]; | |
cd30bcef | 6176 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
6177 | if (nargs == 0) |
6178 | { | |
7a7e1061 | 6179 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
6180 | break; |
6181 | } | |
7a7e1061 | 6182 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
6183 | for (n = 0; n < nargs; n++) |
6184 | { | |
0c588247 NC |
6185 | int val; |
6186 | ||
77145576 | 6187 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 6188 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 6189 | curr |
77145576 | 6190 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 6191 | start, curr, end, 0, 0, offset_size, |
341f9135 | 6192 | version, NULL, 0, NULL, |
ec1b0fbb | 6193 | NULL, ' ', -1); |
4ccf1e31 JJ |
6194 | if (n != nargs - 1) |
6195 | printf (","); | |
6196 | } | |
6197 | printf ("\n"); | |
6198 | } | |
6199 | break; | |
6200 | } | |
6201 | } | |
6202 | ||
6203 | printf ("\n"); | |
b4eb7656 | 6204 | } |
4ccf1e31 JJ |
6205 | |
6206 | return 1; | |
6207 | } | |
6208 | ||
19e6b90e L |
6209 | static int |
6210 | display_debug_abbrev (struct dwarf_section *section, | |
6211 | void *file ATTRIBUTE_UNUSED) | |
6212 | { | |
6213 | abbrev_entry *entry; | |
6214 | unsigned char *start = section->start; | |
19e6b90e | 6215 | |
015dc7e1 | 6216 | introduce (section, false); |
19e6b90e L |
6217 | |
6218 | do | |
6219 | { | |
bcd213b2 NC |
6220 | abbrev_list * list; |
6221 | dwarf_vma offset; | |
7282333f | 6222 | |
bcd213b2 | 6223 | offset = start - section->start; |
76868f36 | 6224 | list = find_abbrev_list_by_abbrev_offset (0, offset); |
bcd213b2 NC |
6225 | if (list == NULL) |
6226 | { | |
76868f36 | 6227 | list = new_abbrev_list (0, offset); |
f2f9554b | 6228 | start = process_abbrev_set (section, 0, section->size, offset, list); |
bcd213b2 NC |
6229 | list->start_of_next_abbrevs = start; |
6230 | } | |
6231 | else | |
6232 | start = list->start_of_next_abbrevs; | |
19e6b90e | 6233 | |
bcd213b2 | 6234 | if (list->first_abbrev == NULL) |
19e6b90e L |
6235 | continue; |
6236 | ||
bcd213b2 | 6237 | printf (_(" Number TAG (0x%lx)\n"), (long) offset); |
19e6b90e | 6238 | |
bcd213b2 | 6239 | for (entry = list->first_abbrev; entry; entry = entry->next) |
19e6b90e L |
6240 | { |
6241 | abbrev_attr *attr; | |
6242 | ||
cc5914eb | 6243 | printf (" %ld %s [%s]\n", |
bcd213b2 | 6244 | entry->number, |
19e6b90e L |
6245 | get_TAG_name (entry->tag), |
6246 | entry->children ? _("has children") : _("no children")); | |
6247 | ||
6248 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
6249 | { |
6250 | printf (" %-18s %s", | |
6251 | get_AT_name (attr->attribute), | |
6252 | get_FORM_name (attr->form)); | |
6253 | if (attr->form == DW_FORM_implicit_const) | |
0121f438 | 6254 | printf (": %s", dwarf_vmatoa ("d", attr->implicit_const)); |
77145576 JK |
6255 | putchar ('\n'); |
6256 | } | |
19e6b90e L |
6257 | } |
6258 | } | |
6259 | while (start); | |
6260 | ||
6261 | printf ("\n"); | |
6262 | ||
6263 | return 1; | |
6264 | } | |
6265 | ||
42bcef4a AB |
6266 | /* Return true when ADDR is the maximum address, when addresses are |
6267 | POINTER_SIZE bytes long. */ | |
6268 | ||
015dc7e1 | 6269 | static bool |
42bcef4a AB |
6270 | is_max_address (dwarf_vma addr, unsigned int pointer_size) |
6271 | { | |
6272 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
6273 | return ((addr & mask) == mask); | |
6274 | } | |
6275 | ||
9f272209 AO |
6276 | /* Display a view pair list starting at *VSTART_PTR and ending at |
6277 | VLISTEND within SECTION. */ | |
6278 | ||
6279 | static void | |
6280 | display_view_pair_list (struct dwarf_section *section, | |
6281 | unsigned char **vstart_ptr, | |
6282 | unsigned int debug_info_entry, | |
6283 | unsigned char *vlistend) | |
6284 | { | |
6285 | unsigned char *vstart = *vstart_ptr; | |
6286 | unsigned char *section_end = section->start + section->size; | |
6287 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
6288 | ||
6289 | if (vlistend < section_end) | |
6290 | section_end = vlistend; | |
6291 | ||
6292 | putchar ('\n'); | |
6293 | ||
6294 | while (vstart < section_end) | |
6295 | { | |
6296 | dwarf_vma off = vstart - section->start; | |
6297 | dwarf_vma vbegin, vend; | |
6298 | ||
cd30bcef | 6299 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 6300 | if (vstart == section_end) |
cd30bcef | 6301 | break; |
9f272209 | 6302 | |
cd30bcef | 6303 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6304 | printf (" %8.8lx ", (unsigned long) off); |
6305 | ||
6306 | print_dwarf_view (vbegin, pointer_size, 1); | |
6307 | print_dwarf_view (vend, pointer_size, 1); | |
6308 | printf (_("location view pair\n")); | |
6309 | } | |
6310 | ||
6311 | putchar ('\n'); | |
6312 | *vstart_ptr = vstart; | |
6313 | } | |
6314 | ||
4723351a CC |
6315 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
6316 | ||
6317 | static void | |
6318 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
6319 | unsigned char **start_ptr, |
6320 | unsigned int debug_info_entry, | |
359ca075 JK |
6321 | dwarf_vma offset, |
6322 | dwarf_vma base_address, | |
9f272209 | 6323 | unsigned char **vstart_ptr, |
b4eb7656 | 6324 | int has_frame_base) |
4723351a | 6325 | { |
9f272209 | 6326 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6327 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6328 | unsigned long cu_offset; |
6329 | unsigned int pointer_size; | |
6330 | unsigned int offset_size; | |
6331 | int dwarf_version; | |
4723351a CC |
6332 | |
6333 | dwarf_vma begin; | |
6334 | dwarf_vma end; | |
6335 | unsigned short length; | |
6336 | int need_frame_base; | |
6337 | ||
82b1b41b NC |
6338 | if (debug_info_entry >= num_debug_info_entries) |
6339 | { | |
6340 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
6341 | debug_info_entry); | |
6342 | return; | |
6343 | } | |
b4eb7656 | 6344 | |
82b1b41b NC |
6345 | cu_offset = debug_information [debug_info_entry].cu_offset; |
6346 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6347 | offset_size = debug_information [debug_info_entry].offset_size; | |
6348 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 6349 | |
f41e4712 NC |
6350 | if (pointer_size < 2 || pointer_size > 8) |
6351 | { | |
6352 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6353 | pointer_size, debug_info_entry); | |
6354 | return; | |
6355 | } | |
6356 | ||
4723351a CC |
6357 | while (1) |
6358 | { | |
359ca075 | 6359 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 6360 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 6361 | |
78480097 | 6362 | if (2 * pointer_size > (size_t) (section_end - start)) |
b4eb7656 AM |
6363 | { |
6364 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6365 | (unsigned long) offset); |
b4eb7656 AM |
6366 | break; |
6367 | } | |
4723351a | 6368 | |
359ca075 | 6369 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 6370 | |
0c588247 NC |
6371 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
6372 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 6373 | |
4723351a | 6374 | if (begin == 0 && end == 0) |
b4eb7656 | 6375 | { |
d1c4b12b NC |
6376 | /* PR 18374: In a object file we can have a location list that |
6377 | starts with a begin and end of 0 because there are relocations | |
6378 | that need to be applied to the addresses. Actually applying | |
6379 | the relocations now does not help as they will probably resolve | |
6380 | to 0, since the object file has not been fully linked. Real | |
6381 | end of list markers will not have any relocations against them. */ | |
6382 | if (! reloc_at (section, off) | |
6383 | && ! reloc_at (section, off + pointer_size)) | |
6384 | { | |
6385 | printf (_("<End of list>\n")); | |
6386 | break; | |
6387 | } | |
b4eb7656 | 6388 | } |
4723351a CC |
6389 | |
6390 | /* Check base address specifiers. */ | |
42bcef4a AB |
6391 | if (is_max_address (begin, pointer_size) |
6392 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
6393 | { |
6394 | base_address = end; | |
6395 | print_dwarf_vma (begin, pointer_size); | |
6396 | print_dwarf_vma (end, pointer_size); | |
6397 | printf (_("(base address)\n")); | |
6398 | continue; | |
6399 | } | |
4723351a | 6400 | |
9f272209 AO |
6401 | if (vstart) |
6402 | { | |
9f272209 AO |
6403 | off = offset + (vstart - *start_ptr); |
6404 | ||
cd30bcef | 6405 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6406 | print_dwarf_view (vbegin, pointer_size, 1); |
6407 | ||
cd30bcef | 6408 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6409 | print_dwarf_view (vend, pointer_size, 1); |
6410 | ||
6411 | printf (_("views at %8.8lx for:\n %*s "), | |
6412 | (unsigned long) off, 8, ""); | |
6413 | } | |
6414 | ||
78480097 | 6415 | if (2 > (size_t) (section_end - start)) |
b4eb7656 AM |
6416 | { |
6417 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6418 | (unsigned long) offset); |
b4eb7656 AM |
6419 | break; |
6420 | } | |
4723351a | 6421 | |
0c588247 | 6422 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6423 | |
78480097 | 6424 | if (length > (size_t) (section_end - start)) |
b4eb7656 AM |
6425 | { |
6426 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6427 | (unsigned long) offset); |
b4eb7656 AM |
6428 | break; |
6429 | } | |
4723351a CC |
6430 | |
6431 | print_dwarf_vma (begin + base_address, pointer_size); | |
6432 | print_dwarf_vma (end + base_address, pointer_size); | |
6433 | ||
6434 | putchar ('('); | |
6435 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6436 | pointer_size, |
6437 | offset_size, | |
6438 | dwarf_version, | |
6439 | length, | |
6440 | cu_offset, section); | |
4723351a CC |
6441 | putchar (')'); |
6442 | ||
6443 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6444 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 6445 | |
9f272209 | 6446 | if (begin == end && vbegin == vend) |
b4eb7656 | 6447 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6448 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 6449 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
6450 | |
6451 | putchar ('\n'); | |
6452 | ||
6453 | start += length; | |
6454 | } | |
6455 | ||
6456 | *start_ptr = start; | |
9f272209 | 6457 | *vstart_ptr = vstart; |
4723351a CC |
6458 | } |
6459 | ||
77145576 JK |
6460 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6461 | ||
6462 | static void | |
6463 | display_loclists_list (struct dwarf_section *section, | |
6464 | unsigned char **start_ptr, | |
6465 | unsigned int debug_info_entry, | |
6466 | dwarf_vma offset, | |
6467 | dwarf_vma base_address, | |
9f272209 | 6468 | unsigned char **vstart_ptr, |
77145576 JK |
6469 | int has_frame_base) |
6470 | { | |
9f272209 | 6471 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
6472 | unsigned char *section_end = section->start + section->size; |
6473 | unsigned long cu_offset; | |
6474 | unsigned int pointer_size; | |
6475 | unsigned int offset_size; | |
6476 | int dwarf_version; | |
77145576 | 6477 | |
9dfd0db9 | 6478 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
6479 | dwarf_vma begin = -1, vbegin = -1; |
6480 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
6481 | dwarf_vma length; |
6482 | int need_frame_base; | |
6483 | ||
6484 | if (debug_info_entry >= num_debug_info_entries) | |
6485 | { | |
6486 | warn (_("No debug information available for " | |
6487 | "loclists lists of entry: %u\n"), | |
6488 | debug_info_entry); | |
6489 | return; | |
6490 | } | |
6491 | ||
6492 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6493 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6494 | offset_size = debug_information [debug_info_entry].offset_size; | |
6495 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6496 | ||
6497 | if (pointer_size < 2 || pointer_size > 8) | |
6498 | { | |
6499 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6500 | pointer_size, debug_info_entry); | |
6501 | return; | |
6502 | } | |
6503 | ||
6504 | while (1) | |
6505 | { | |
6506 | dwarf_vma off = offset + (start - *start_ptr); | |
6507 | enum dwarf_location_list_entry_type llet; | |
6508 | ||
6509 | if (start + 1 > section_end) | |
6510 | { | |
6511 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6512 | (unsigned long) offset); | |
6513 | break; | |
6514 | } | |
6515 | ||
6516 | printf (" %8.8lx ", (unsigned long) off); | |
6517 | ||
6518 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6519 | ||
1c9f770d MW |
6520 | if (vstart && (llet == DW_LLE_offset_pair |
6521 | || llet == DW_LLE_start_end | |
6522 | || llet == DW_LLE_start_length)) | |
9f272209 AO |
6523 | { |
6524 | off = offset + (vstart - *start_ptr); | |
6525 | ||
cd30bcef | 6526 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6527 | print_dwarf_view (vbegin, pointer_size, 1); |
6528 | ||
cd30bcef | 6529 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6530 | print_dwarf_view (vend, pointer_size, 1); |
6531 | ||
6532 | printf (_("views at %8.8lx for:\n %*s "), | |
6533 | (unsigned long) off, 8, ""); | |
6534 | } | |
6535 | ||
77145576 JK |
6536 | switch (llet) |
6537 | { | |
6538 | case DW_LLE_end_of_list: | |
6539 | printf (_("<End of list>\n")); | |
6540 | break; | |
6541 | case DW_LLE_offset_pair: | |
cd30bcef | 6542 | READ_ULEB (begin, start, section_end); |
1c9f770d | 6543 | begin += base_address; |
cd30bcef | 6544 | READ_ULEB (end, start, section_end); |
1c9f770d MW |
6545 | end += base_address; |
6546 | break; | |
6547 | case DW_LLE_start_end: | |
6548 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6549 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
6550 | break; | |
6551 | case DW_LLE_start_length: | |
6552 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6553 | READ_ULEB (end, start, section_end); | |
6554 | end += begin; | |
77145576 JK |
6555 | break; |
6556 | case DW_LLE_base_address: | |
6557 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6558 | section_end); | |
6559 | print_dwarf_vma (base_address, pointer_size); | |
6560 | printf (_("(base address)\n")); | |
6561 | break; | |
9f272209 AO |
6562 | #ifdef DW_LLE_view_pair |
6563 | case DW_LLE_view_pair: | |
6564 | if (vstart) | |
6565 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 6566 | READ_ULEB (vbegin, start, section_end); |
9f272209 AO |
6567 | print_dwarf_view (vbegin, pointer_size, 1); |
6568 | ||
cd30bcef | 6569 | READ_ULEB (vend, start, section_end); |
9f272209 AO |
6570 | print_dwarf_view (vend, pointer_size, 1); |
6571 | ||
6572 | printf (_("views for:\n")); | |
6573 | continue; | |
6574 | #endif | |
77145576 JK |
6575 | default: |
6576 | error (_("Invalid location list entry type %d\n"), llet); | |
6577 | return; | |
6578 | } | |
6579 | if (llet == DW_LLE_end_of_list) | |
6580 | break; | |
1c9f770d MW |
6581 | if (llet != DW_LLE_offset_pair |
6582 | && llet != DW_LLE_start_end | |
6583 | && llet != DW_LLE_start_length) | |
77145576 JK |
6584 | continue; |
6585 | ||
78480097 | 6586 | if (start == section_end) |
77145576 JK |
6587 | { |
6588 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6589 | (unsigned long) offset); | |
6590 | break; | |
6591 | } | |
cd30bcef | 6592 | READ_ULEB (length, start, section_end); |
77145576 | 6593 | |
78480097 AM |
6594 | if (length > (size_t) (section_end - start)) |
6595 | { | |
6596 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6597 | (unsigned long) offset); | |
6598 | break; | |
6599 | } | |
6600 | ||
1c9f770d MW |
6601 | print_dwarf_vma (begin, pointer_size); |
6602 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
6603 | |
6604 | putchar ('('); | |
6605 | need_frame_base = decode_location_expression (start, | |
6606 | pointer_size, | |
6607 | offset_size, | |
6608 | dwarf_version, | |
6609 | length, | |
6610 | cu_offset, section); | |
6611 | putchar (')'); | |
6612 | ||
6613 | if (need_frame_base && !has_frame_base) | |
6614 | printf (_(" [without DW_AT_frame_base]")); | |
6615 | ||
9f272209 | 6616 | if (begin == end && vbegin == vend) |
77145576 | 6617 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6618 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
6619 | fputs (_(" (start > end)"), stdout); |
6620 | ||
6621 | putchar ('\n'); | |
6622 | ||
6623 | start += length; | |
9f272209 | 6624 | vbegin = vend = -1; |
77145576 JK |
6625 | } |
6626 | ||
9f272209 AO |
6627 | if (vbegin != vm1 || vend != vm1) |
6628 | printf (_("Trailing view pair not used in a range")); | |
6629 | ||
77145576 | 6630 | *start_ptr = start; |
9f272209 | 6631 | *vstart_ptr = vstart; |
77145576 JK |
6632 | } |
6633 | ||
fab128ef CC |
6634 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
6635 | right-adjusted in a field of length LEN, and followed by a space. */ | |
6636 | ||
6637 | static void | |
6638 | print_addr_index (unsigned int idx, unsigned int len) | |
6639 | { | |
6640 | static char buf[15]; | |
6641 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6642 | printf ("%*s ", len, buf); |
fab128ef CC |
6643 | } |
6644 | ||
4723351a CC |
6645 | /* Display a location list from a .dwo section. It uses address indexes rather |
6646 | than embedded addresses. This code closely follows display_loc_list, but the | |
6647 | two are sufficiently different that combining things is very ugly. */ | |
6648 | ||
6649 | static void | |
6650 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6651 | unsigned char **start_ptr, |
6652 | unsigned int debug_info_entry, | |
359ca075 | 6653 | dwarf_vma offset, |
9f272209 | 6654 | unsigned char **vstart_ptr, |
b4eb7656 | 6655 | int has_frame_base) |
4723351a | 6656 | { |
9f272209 | 6657 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6658 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6659 | unsigned long cu_offset; |
6660 | unsigned int pointer_size; | |
6661 | unsigned int offset_size; | |
6662 | int dwarf_version; | |
4723351a CC |
6663 | int entry_type; |
6664 | unsigned short length; | |
6665 | int need_frame_base; | |
fab128ef | 6666 | unsigned int idx; |
4723351a | 6667 | |
82b1b41b NC |
6668 | if (debug_info_entry >= num_debug_info_entries) |
6669 | { | |
6670 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6671 | debug_info_entry); | |
6672 | return; | |
6673 | } | |
6674 | ||
6675 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6676 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6677 | offset_size = debug_information [debug_info_entry].offset_size; | |
6678 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6679 | ||
f41e4712 NC |
6680 | if (pointer_size < 2 || pointer_size > 8) |
6681 | { | |
6682 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6683 | pointer_size, debug_info_entry); | |
6684 | return; | |
6685 | } | |
6686 | ||
4723351a CC |
6687 | while (1) |
6688 | { | |
359ca075 | 6689 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6690 | |
fab128ef | 6691 | if (start >= section_end) |
b4eb7656 AM |
6692 | { |
6693 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6694 | (unsigned long) offset); |
b4eb7656 AM |
6695 | break; |
6696 | } | |
4723351a | 6697 | |
0c588247 | 6698 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6699 | |
6700 | if (vstart) | |
6701 | switch (entry_type) | |
6702 | { | |
6703 | default: | |
6704 | break; | |
6705 | ||
6706 | case 2: | |
6707 | case 3: | |
6708 | case 4: | |
6709 | { | |
6710 | dwarf_vma view; | |
6711 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6712 | ||
cd30bcef | 6713 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6714 | print_dwarf_view (view, 8, 1); |
6715 | ||
cd30bcef | 6716 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6717 | print_dwarf_view (view, 8, 1); |
6718 | ||
6719 | printf (_("views at %8.8lx for:\n %*s "), | |
6720 | (unsigned long) off, 8, ""); | |
6721 | ||
6722 | } | |
6723 | break; | |
6724 | } | |
6725 | ||
4723351a | 6726 | switch (entry_type) |
b4eb7656 AM |
6727 | { |
6728 | case 0: /* A terminating entry. */ | |
6729 | *start_ptr = start; | |
9f272209 | 6730 | *vstart_ptr = vstart; |
b4eb7656 AM |
6731 | printf (_("<End of list>\n")); |
6732 | return; | |
6733 | case 1: /* A base-address entry. */ | |
cd30bcef | 6734 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6735 | print_addr_index (idx, 8); |
9f272209 | 6736 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6737 | printf (_("(base address selection entry)\n")); |
6738 | continue; | |
6739 | case 2: /* A start/end entry. */ | |
cd30bcef | 6740 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6741 | print_addr_index (idx, 8); |
cd30bcef | 6742 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6743 | print_addr_index (idx, 8); |
6744 | break; | |
6745 | case 3: /* A start/length entry. */ | |
cd30bcef | 6746 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6747 | print_addr_index (idx, 8); |
6748 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6749 | printf ("%08x ", idx); | |
6750 | break; | |
6751 | case 4: /* An offset pair entry. */ | |
6752 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6753 | printf ("%08x ", idx); | |
6754 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6755 | printf ("%08x ", idx); | |
6756 | break; | |
6757 | default: | |
6758 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6759 | *start_ptr = start; | |
9f272209 | 6760 | *vstart_ptr = vstart; |
b4eb7656 AM |
6761 | return; |
6762 | } | |
4723351a | 6763 | |
78480097 | 6764 | if (2 > (size_t) (section_end - start)) |
b4eb7656 AM |
6765 | { |
6766 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6767 | (unsigned long) offset); |
b4eb7656 AM |
6768 | break; |
6769 | } | |
4723351a | 6770 | |
0c588247 | 6771 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
78480097 | 6772 | if (length > (size_t) (section_end - start)) |
b4eb7656 AM |
6773 | { |
6774 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6775 | (unsigned long) offset); |
b4eb7656 AM |
6776 | break; |
6777 | } | |
4723351a CC |
6778 | |
6779 | putchar ('('); | |
6780 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6781 | pointer_size, |
6782 | offset_size, | |
6783 | dwarf_version, | |
6784 | length, | |
6785 | cu_offset, section); | |
4723351a CC |
6786 | putchar (')'); |
6787 | ||
6788 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6789 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6790 | |
6791 | putchar ('\n'); | |
6792 | ||
6793 | start += length; | |
6794 | } | |
6795 | ||
6796 | *start_ptr = start; | |
9f272209 | 6797 | *vstart_ptr = vstart; |
4723351a CC |
6798 | } |
6799 | ||
9f272209 AO |
6800 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6801 | loc_views. */ | |
51d0d03f | 6802 | |
9f272209 | 6803 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6804 | |
6805 | static int | |
6806 | loc_offsets_compar (const void *ap, const void *bp) | |
6807 | { | |
6808 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6809 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6810 | ||
9f272209 AO |
6811 | int ret = (a > b) - (b > a); |
6812 | if (ret) | |
6813 | return ret; | |
6814 | ||
6815 | a = loc_views[*(const unsigned int *) ap]; | |
6816 | b = loc_views[*(const unsigned int *) bp]; | |
6817 | ||
6818 | ret = (a > b) - (b > a); | |
6819 | ||
6820 | return ret; | |
51d0d03f JJ |
6821 | } |
6822 | ||
19e6b90e L |
6823 | static int |
6824 | display_debug_loc (struct dwarf_section *section, void *file) | |
6825 | { | |
9f272209 | 6826 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6827 | unsigned long bytes; |
6828 | unsigned char *section_begin = start; | |
6829 | unsigned int num_loc_list = 0; | |
6830 | unsigned long last_offset = 0; | |
9f272209 | 6831 | unsigned long last_view = 0; |
19e6b90e L |
6832 | unsigned int first = 0; |
6833 | unsigned int i; | |
6834 | unsigned int j; | |
6835 | int seen_first_offset = 0; | |
51d0d03f | 6836 | int locs_sorted = 1; |
9f272209 | 6837 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6838 | unsigned int *array = NULL; |
4723351a | 6839 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 6840 | bool is_dwo = false; |
77145576 JK |
6841 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6842 | dwarf_vma expected_start = 0; | |
4723351a CC |
6843 | |
6844 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
015dc7e1 | 6845 | is_dwo = true; |
19e6b90e L |
6846 | |
6847 | bytes = section->size; | |
19e6b90e L |
6848 | |
6849 | if (bytes == 0) | |
6850 | { | |
6851 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6852 | return 0; | |
6853 | } | |
6854 | ||
77145576 JK |
6855 | if (is_loclists) |
6856 | { | |
6857 | unsigned char *hdrptr = section_begin; | |
6858 | dwarf_vma ll_length; | |
6859 | unsigned short ll_version; | |
6860 | unsigned char *end = section_begin + section->size; | |
6861 | unsigned char address_size, segment_selector_size; | |
6862 | uint32_t offset_entry_count; | |
6863 | ||
6864 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6865 | if (ll_length == 0xffffffff) | |
6866 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6867 | ||
6868 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6869 | if (ll_version != 5) | |
6870 | { | |
6871 | warn (_("The %s section contains corrupt or " | |
6872 | "unsupported version number: %d.\n"), | |
6873 | section->name, ll_version); | |
6874 | return 0; | |
6875 | } | |
6876 | ||
6877 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6878 | ||
6879 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6880 | if (segment_selector_size != 0) | |
6881 | { | |
6882 | warn (_("The %s section contains " | |
6883 | "unsupported segment selector size: %d.\n"), | |
6884 | section->name, segment_selector_size); | |
6885 | return 0; | |
6886 | } | |
6887 | ||
6888 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6889 | if (offset_entry_count != 0) | |
6890 | { | |
6891 | warn (_("The %s section contains " | |
6892 | "unsupported offset entry count: %d.\n"), | |
6893 | section->name, offset_entry_count); | |
6894 | return 0; | |
6895 | } | |
6896 | ||
6897 | expected_start = hdrptr - section_begin; | |
6898 | } | |
6899 | ||
1febe64d NC |
6900 | if (load_debug_info (file) == 0) |
6901 | { | |
6902 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6903 | section->name); | |
6904 | return 0; | |
6905 | } | |
19e6b90e L |
6906 | |
6907 | /* Check the order of location list in .debug_info section. If | |
6908 | offsets of location lists are in the ascending order, we can | |
6909 | use `debug_information' directly. */ | |
6910 | for (i = 0; i < num_debug_info_entries; i++) | |
6911 | { | |
6912 | unsigned int num; | |
6913 | ||
6914 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6915 | if (num > num_loc_list) |
6916 | num_loc_list = num; | |
19e6b90e L |
6917 | |
6918 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6919 | if (locs_sorted && num != 0) |
19e6b90e L |
6920 | { |
6921 | if (!seen_first_offset) | |
6922 | { | |
6923 | /* This is the first location list. */ | |
6924 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6925 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6926 | first = i; |
6927 | seen_first_offset = 1; | |
6928 | j = 1; | |
6929 | } | |
6930 | else | |
6931 | j = 0; | |
6932 | ||
6933 | for (; j < num; j++) | |
6934 | { | |
6935 | if (last_offset > | |
9f272209 AO |
6936 | debug_information [i].loc_offsets [j] |
6937 | || (last_offset == debug_information [i].loc_offsets [j] | |
6938 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6939 | { |
51d0d03f | 6940 | locs_sorted = 0; |
19e6b90e L |
6941 | break; |
6942 | } | |
6943 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6944 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6945 | } |
6946 | } | |
6947 | } | |
6948 | ||
19e6b90e L |
6949 | if (!seen_first_offset) |
6950 | error (_("No location lists in .debug_info section!\n")); | |
6951 | ||
d4bfc77b | 6952 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6953 | && debug_information [first].loc_offsets [0] != expected_start |
6954 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6955 | warn (_("Location lists in %s section start at 0x%s\n"), |
6956 | section->name, | |
6957 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6958 | |
51d0d03f JJ |
6959 | if (!locs_sorted) |
6960 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d | 6961 | |
015dc7e1 | 6962 | introduce (section, false); |
dda8d76d | 6963 | |
d1c4b12b NC |
6964 | if (reloc_at (section, 0)) |
6965 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6966 | |
d1c4b12b | 6967 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6968 | |
6969 | seen_first_offset = 0; | |
6970 | for (i = first; i < num_debug_info_entries; i++) | |
6971 | { | |
9f272209 | 6972 | dwarf_vma offset, voffset; |
359ca075 | 6973 | dwarf_vma base_address; |
d1c4b12b | 6974 | unsigned int k; |
19e6b90e L |
6975 | int has_frame_base; |
6976 | ||
51d0d03f JJ |
6977 | if (!locs_sorted) |
6978 | { | |
6979 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6980 | array[k] = k; | |
6981 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6982 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6983 | qsort (array, debug_information [i].num_loc_offsets, |
6984 | sizeof (*array), loc_offsets_compar); | |
6985 | } | |
19e6b90e | 6986 | |
9f272209 | 6987 | int adjacent_view_loclists = 1; |
51d0d03f | 6988 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6989 | { |
51d0d03f JJ |
6990 | j = locs_sorted ? k : array[k]; |
6991 | if (k | |
9f272209 | 6992 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6993 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6994 | == debug_information [i].loc_offsets [j]) |
6995 | && (debug_information [i].loc_views [locs_sorted | |
6996 | ? k - 1 : array [k - 1]] | |
6997 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6998 | continue; |
19e6b90e | 6999 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 7000 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 7001 | next = section_begin + offset; |
9f272209 AO |
7002 | voffset = debug_information [i].loc_views [j]; |
7003 | if (voffset != vm1) | |
7004 | vnext = section_begin + voffset; | |
7005 | else | |
7006 | vnext = NULL; | |
19e6b90e L |
7007 | base_address = debug_information [i].base_address; |
7008 | ||
9f272209 AO |
7009 | if (vnext && vnext < next) |
7010 | { | |
7011 | vstart = vnext; | |
7012 | display_view_pair_list (section, &vstart, i, next); | |
7013 | if (start == vnext) | |
7014 | start = vstart; | |
7015 | } | |
7016 | ||
7017 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
7018 | seen_first_offset = 1; |
7019 | else | |
7020 | { | |
7021 | if (start < next) | |
7022 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 7023 | (unsigned long) (start - section_begin), |
c8071705 | 7024 | (unsigned long) offset); |
19e6b90e L |
7025 | else if (start > next) |
7026 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 7027 | (unsigned long) (start - section_begin), |
c8071705 | 7028 | (unsigned long) offset); |
19e6b90e L |
7029 | } |
7030 | start = next; | |
9f272209 | 7031 | vstart = vnext; |
19e6b90e L |
7032 | |
7033 | if (offset >= bytes) | |
7034 | { | |
7035 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 7036 | (unsigned long) offset); |
19e6b90e L |
7037 | continue; |
7038 | } | |
7039 | ||
9f272209 AO |
7040 | if (vnext && voffset >= bytes) |
7041 | { | |
7042 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
7043 | (unsigned long) voffset); | |
7044 | continue; | |
7045 | } | |
7046 | ||
77145576 JK |
7047 | if (!is_loclists) |
7048 | { | |
7049 | if (is_dwo) | |
7050 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 7051 | &vstart, has_frame_base); |
77145576 JK |
7052 | else |
7053 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 7054 | &vstart, has_frame_base); |
77145576 | 7055 | } |
b4eb7656 | 7056 | else |
77145576 JK |
7057 | { |
7058 | if (is_dwo) | |
7059 | warn (_("DWO is not yet supported.\n")); | |
7060 | else | |
7061 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
7062 | &vstart, has_frame_base); |
7063 | } | |
7064 | ||
7065 | /* FIXME: this arrangement is quite simplistic. Nothing | |
7066 | requires locview lists to be adjacent to corresponding | |
7067 | loclists, and a single loclist could be augmented by | |
7068 | different locview lists, and vice-versa, unlikely as it | |
7069 | is that it would make sense to do so. Hopefully we'll | |
7070 | have view pair support built into loclists before we ever | |
7071 | need to address all these possibilities. */ | |
7072 | if (adjacent_view_loclists && vnext | |
7073 | && vnext != start && vstart != next) | |
7074 | { | |
7075 | adjacent_view_loclists = 0; | |
7076 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 7077 | } |
9f272209 AO |
7078 | |
7079 | if (vnext && vnext == start) | |
7080 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
7081 | } |
7082 | } | |
031cd65f | 7083 | |
4723351a | 7084 | if (start < section->start + section->size) |
d3a49aa8 AM |
7085 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
7086 | "There are %ld unused bytes at the end of section %s\n", | |
7087 | (long) (section->start + section->size - start)), | |
4723351a | 7088 | (long) (section->start + section->size - start), section->name); |
98fb390a | 7089 | putchar ('\n'); |
51d0d03f | 7090 | free (array); |
19e6b90e L |
7091 | return 1; |
7092 | } | |
7093 | ||
7094 | static int | |
7095 | display_debug_str (struct dwarf_section *section, | |
7096 | void *file ATTRIBUTE_UNUSED) | |
7097 | { | |
7098 | unsigned char *start = section->start; | |
7099 | unsigned long bytes = section->size; | |
7100 | dwarf_vma addr = section->address; | |
7101 | ||
7102 | if (bytes == 0) | |
7103 | { | |
7104 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7105 | return 0; | |
7106 | } | |
7107 | ||
015dc7e1 | 7108 | introduce (section, false); |
19e6b90e L |
7109 | |
7110 | while (bytes) | |
7111 | { | |
7112 | int j; | |
7113 | int k; | |
7114 | int lbytes; | |
7115 | ||
7116 | lbytes = (bytes > 16 ? 16 : bytes); | |
7117 | ||
7118 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
7119 | ||
7120 | for (j = 0; j < 16; j++) | |
7121 | { | |
7122 | if (j < lbytes) | |
7123 | printf ("%2.2x", start[j]); | |
7124 | else | |
7125 | printf (" "); | |
7126 | ||
7127 | if ((j & 3) == 3) | |
7128 | printf (" "); | |
7129 | } | |
7130 | ||
7131 | for (j = 0; j < lbytes; j++) | |
7132 | { | |
7133 | k = start[j]; | |
7134 | if (k >= ' ' && k < 0x80) | |
7135 | printf ("%c", k); | |
7136 | else | |
7137 | printf ("."); | |
7138 | } | |
7139 | ||
7140 | putchar ('\n'); | |
7141 | ||
7142 | start += lbytes; | |
7143 | addr += lbytes; | |
7144 | bytes -= lbytes; | |
7145 | } | |
7146 | ||
7147 | putchar ('\n'); | |
7148 | ||
7149 | return 1; | |
7150 | } | |
7151 | ||
19e6b90e L |
7152 | static int |
7153 | display_debug_info (struct dwarf_section *section, void *file) | |
7154 | { | |
015dc7e1 | 7155 | return process_debug_info (section, file, section->abbrev_sec, false, false); |
19e6b90e L |
7156 | } |
7157 | ||
2b6f5997 CC |
7158 | static int |
7159 | display_debug_types (struct dwarf_section *section, void *file) | |
7160 | { | |
015dc7e1 | 7161 | return process_debug_info (section, file, section->abbrev_sec, false, true); |
6f875884 TG |
7162 | } |
7163 | ||
7164 | static int | |
7165 | display_trace_info (struct dwarf_section *section, void *file) | |
7166 | { | |
015dc7e1 | 7167 | return process_debug_info (section, file, section->abbrev_sec, false, true); |
2b6f5997 | 7168 | } |
19e6b90e L |
7169 | |
7170 | static int | |
7171 | display_debug_aranges (struct dwarf_section *section, | |
7172 | void *file ATTRIBUTE_UNUSED) | |
7173 | { | |
7174 | unsigned char *start = section->start; | |
7175 | unsigned char *end = start + section->size; | |
7176 | ||
015dc7e1 | 7177 | introduce (section, false); |
19e6b90e | 7178 | |
6e3d6dc1 NC |
7179 | /* It does not matter if this load fails, |
7180 | we test for that later on. */ | |
7181 | load_debug_info (file); | |
7182 | ||
19e6b90e L |
7183 | while (start < end) |
7184 | { | |
7185 | unsigned char *hdrptr; | |
7186 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 7187 | unsigned char *addr_ranges; |
2d9472a2 NC |
7188 | dwarf_vma length; |
7189 | dwarf_vma address; | |
e98fdf1a | 7190 | unsigned long sec_off; |
53b8873b | 7191 | unsigned char address_size; |
19e6b90e | 7192 | int excess; |
bf5117e3 | 7193 | unsigned int offset_size; |
6ca07350 | 7194 | unsigned char *end_ranges; |
19e6b90e L |
7195 | |
7196 | hdrptr = start; | |
6ca07350 | 7197 | sec_off = hdrptr - section->start; |
19e6b90e | 7198 | |
0c588247 | 7199 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
7200 | if (arange.ar_length == 0xffffffff) |
7201 | { | |
0c588247 | 7202 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e | 7203 | offset_size = 8; |
19e6b90e L |
7204 | } |
7205 | else | |
6ca07350 | 7206 | offset_size = 4; |
19e6b90e | 7207 | |
6ca07350 | 7208 | if (arange.ar_length > (size_t) (end - hdrptr)) |
e98fdf1a AM |
7209 | { |
7210 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
7211 | section->name, | |
6ca07350 | 7212 | sec_off, |
e98fdf1a AM |
7213 | dwarf_vmatoa ("x", arange.ar_length)); |
7214 | break; | |
7215 | } | |
6ca07350 | 7216 | end_ranges = hdrptr + arange.ar_length; |
e98fdf1a | 7217 | |
6ca07350 AM |
7218 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end_ranges); |
7219 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, | |
7220 | end_ranges); | |
19e6b90e | 7221 | |
6e3d6dc1 NC |
7222 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
7223 | && num_debug_info_entries > 0 | |
7224 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
7225 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 7226 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 7227 | |
6ca07350 AM |
7228 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end_ranges); |
7229 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end_ranges); | |
19e6b90e L |
7230 | |
7231 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
7232 | { | |
67f101ee NC |
7233 | /* PR 19872: A version number of 0 probably means that there is |
7234 | padding at the end of the .debug_aranges section. Gold puts | |
7235 | it there when performing an incremental link, for example. | |
7236 | So do not generate a warning in this case. */ | |
7237 | if (arange.ar_version) | |
7238 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
7239 | break; |
7240 | } | |
7241 | ||
47704ddf KT |
7242 | printf (_(" Length: %ld\n"), |
7243 | (long) arange.ar_length); | |
19e6b90e | 7244 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
7245 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
7246 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
7247 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
7248 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
7249 | ||
53b8873b NC |
7250 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
7251 | ||
f41e4712 NC |
7252 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
7253 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
7254 | { |
7255 | error (_("Invalid address size in %s section!\n"), | |
7256 | section->name); | |
7257 | break; | |
7258 | } | |
7259 | ||
53b8873b NC |
7260 | /* The DWARF spec does not require that the address size be a power |
7261 | of two, but we do. This will have to change if we ever encounter | |
7262 | an uneven architecture. */ | |
7263 | if ((address_size & (address_size - 1)) != 0) | |
7264 | { | |
7265 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
7266 | break; | |
7267 | } | |
cecf136e | 7268 | |
209c9a13 NC |
7269 | if (address_size > 4) |
7270 | printf (_("\n Address Length\n")); | |
7271 | else | |
7272 | printf (_("\n Address Length\n")); | |
19e6b90e | 7273 | |
91d6fa6a | 7274 | addr_ranges = hdrptr; |
19e6b90e | 7275 | |
53b8873b NC |
7276 | /* Must pad to an alignment boundary that is twice the address size. */ |
7277 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 7278 | if (excess) |
91d6fa6a | 7279 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 7280 | |
6ca07350 | 7281 | start = end_ranges; |
1617e571 | 7282 | |
6bee34a1 | 7283 | while (2u * address_size <= (size_t) (start - addr_ranges)) |
19e6b90e | 7284 | { |
6ca07350 AM |
7285 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, start); |
7286 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, start); | |
19e6b90e | 7287 | |
80c35038 | 7288 | printf (" "); |
2d9472a2 NC |
7289 | print_dwarf_vma (address, address_size); |
7290 | print_dwarf_vma (length, address_size); | |
7291 | putchar ('\n'); | |
19e6b90e | 7292 | } |
19e6b90e L |
7293 | } |
7294 | ||
7295 | printf ("\n"); | |
7296 | ||
7297 | return 1; | |
7298 | } | |
7299 | ||
4723351a CC |
7300 | /* Comparison function for qsort. */ |
7301 | static int | |
7302 | comp_addr_base (const void * v0, const void * v1) | |
7303 | { | |
d367307b AM |
7304 | debug_info *info0 = *(debug_info **) v0; |
7305 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
7306 | return info0->addr_base - info1->addr_base; |
7307 | } | |
7308 | ||
7309 | /* Display the debug_addr section. */ | |
7310 | static int | |
7311 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 7312 | void *file) |
4723351a CC |
7313 | { |
7314 | debug_info **debug_addr_info; | |
7315 | unsigned char *entry; | |
7316 | unsigned char *end; | |
7317 | unsigned int i; | |
7318 | unsigned int count; | |
0e12f6c8 | 7319 | unsigned char * header; |
4723351a CC |
7320 | |
7321 | if (section->size == 0) | |
7322 | { | |
7323 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7324 | return 0; | |
7325 | } | |
7326 | ||
7327 | if (load_debug_info (file) == 0) | |
7328 | { | |
7329 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7330 | section->name); | |
7331 | return 0; | |
7332 | } | |
7333 | ||
015dc7e1 | 7334 | introduce (section, false); |
4723351a | 7335 | |
1306a742 NC |
7336 | /* PR 17531: file: cf38d01b. |
7337 | We use xcalloc because a corrupt file may not have initialised all of the | |
7338 | fields in the debug_info structure, which means that the sort below might | |
7339 | try to move uninitialised data. */ | |
7340 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 7341 | sizeof (debug_info *)); |
4723351a CC |
7342 | |
7343 | count = 0; | |
7344 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 7345 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
7346 | { |
7347 | /* PR 17531: file: cf38d01b. */ | |
7348 | if (debug_information[i].addr_base >= section->size) | |
7349 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
7350 | (unsigned long) debug_information[i].addr_base, i); | |
7351 | else | |
7352 | debug_addr_info [count++] = debug_information + i; | |
7353 | } | |
4723351a CC |
7354 | |
7355 | /* Add a sentinel to make iteration convenient. */ | |
7356 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
7357 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 7358 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 7359 | |
0e12f6c8 | 7360 | header = section->start; |
4723351a CC |
7361 | for (i = 0; i < count; i++) |
7362 | { | |
7363 | unsigned int idx; | |
fab128ef | 7364 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
7365 | |
7366 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 7367 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 7368 | |
fab128ef | 7369 | printf (_("\tIndex\tAddress\n")); |
4723351a | 7370 | entry = section->start + debug_addr_info [i]->addr_base; |
0e12f6c8 TV |
7371 | if (debug_addr_info [i]->dwarf_version >= 5) |
7372 | { | |
7373 | size_t header_size = entry - header; | |
7374 | unsigned char * curr_header = header; | |
7375 | dwarf_vma length; | |
7376 | int version; | |
7377 | int segment_selector_size; | |
7378 | ||
7379 | if (header_size != 8 && header_size != 16) | |
7380 | { | |
7381 | warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"), | |
7382 | section->name, (long) header_size); | |
7383 | return 0; | |
7384 | } | |
7385 | ||
7386 | SAFE_BYTE_GET_AND_INC (length, curr_header, 4, entry); | |
7387 | if (length == 0xffffffff) | |
a7077ce7 | 7388 | SAFE_BYTE_GET_AND_INC (length, curr_header, 8, entry); |
0e12f6c8 TV |
7389 | end = curr_header + length; |
7390 | ||
7391 | SAFE_BYTE_GET_AND_INC (version, curr_header, 2, entry); | |
7392 | if (version != 5) | |
7393 | warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"), | |
7394 | section->name, version); | |
7395 | ||
7396 | SAFE_BYTE_GET_AND_INC (address_size, curr_header, 1, entry); | |
7397 | SAFE_BYTE_GET_AND_INC (segment_selector_size, curr_header, 1, entry); | |
7398 | address_size += segment_selector_size; | |
7399 | } | |
7400 | else | |
7401 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
7402 | header = end; | |
4723351a CC |
7403 | idx = 0; |
7404 | while (entry < end) | |
b4eb7656 AM |
7405 | { |
7406 | dwarf_vma base = byte_get (entry, address_size); | |
7407 | printf (_("\t%d:\t"), idx); | |
7408 | print_dwarf_vma (base, address_size); | |
7409 | printf ("\n"); | |
7410 | entry += address_size; | |
7411 | idx++; | |
7412 | } | |
4723351a CC |
7413 | } |
7414 | printf ("\n"); | |
7415 | ||
7416 | free (debug_addr_info); | |
7417 | return 1; | |
7418 | } | |
7419 | ||
7420 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 7421 | |
4723351a CC |
7422 | static int |
7423 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 7424 | void *file ATTRIBUTE_UNUSED) |
4723351a | 7425 | { |
9f27c364 HPN |
7426 | unsigned long idx; |
7427 | ||
4723351a CC |
7428 | if (section->size == 0) |
7429 | { | |
7430 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7431 | return 0; | |
7432 | } | |
e4b7104b NC |
7433 | |
7434 | unsigned char *start = section->start; | |
7435 | unsigned char *end = start + section->size; | |
7436 | unsigned char *curr = start; | |
7437 | ||
63b4cc53 | 7438 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 7439 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
39f381cb NC |
7440 | |
7441 | if (dwo) | |
7442 | load_debug_section_with_follow (str_dwo, file); | |
7443 | else | |
7444 | load_debug_section_with_follow (str, file); | |
e4b7104b | 7445 | |
015dc7e1 | 7446 | introduce (section, false); |
e4b7104b NC |
7447 | |
7448 | while (curr < end) | |
7449 | { | |
7450 | dwarf_vma length; | |
7451 | dwarf_vma entry_length; | |
7452 | ||
7453 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
7454 | /* FIXME: We assume that this means 64-bit DWARF is being used. */ | |
7455 | if (length == 0xffffffff) | |
7456 | { | |
a7077ce7 | 7457 | SAFE_BYTE_GET_AND_INC (length, curr, 8, end); |
e4b7104b NC |
7458 | entry_length = 8; |
7459 | } | |
7460 | else | |
7461 | entry_length = 4; | |
7462 | ||
95abb394 | 7463 | unsigned char *entries_end; |
39f381cb NC |
7464 | if (length == 0) |
7465 | { | |
7466 | /* This is probably an old style .debug_str_offset section which | |
7467 | just contains offsets and no header (and the first offset is 0). */ | |
7468 | length = section->size; | |
7469 | curr = section->start; | |
95abb394 | 7470 | entries_end = end; |
e4b7104b | 7471 | |
39f381cb NC |
7472 | printf (_(" Length: %#lx\n"), (unsigned long) length); |
7473 | printf (_(" Index Offset [String]\n")); | |
7474 | } | |
7475 | else | |
7476 | { | |
b96a1bcb AM |
7477 | if (length <= (dwarf_vma) (end - curr)) |
7478 | entries_end = curr + length; | |
7479 | else | |
7480 | { | |
7481 | warn (_("Section %s is too small %#lx\n"), | |
7482 | section->name, (unsigned long) section->size); | |
7483 | entries_end = end; | |
7484 | } | |
95abb394 | 7485 | |
39f381cb | 7486 | int version; |
5250d2f0 | 7487 | SAFE_BYTE_GET_AND_INC (version, curr, 2, entries_end); |
39f381cb NC |
7488 | if (version != 5) |
7489 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); | |
7490 | ||
7491 | int padding; | |
5250d2f0 | 7492 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, entries_end); |
39f381cb NC |
7493 | if (padding != 0) |
7494 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); | |
7495 | ||
7496 | printf (_(" Length: %#lx\n"), (unsigned long) length); | |
7497 | printf (_(" Version: %#lx\n"), (unsigned long) version); | |
7498 | printf (_(" Index Offset [String]\n")); | |
7499 | } | |
e4b7104b | 7500 | |
95abb394 | 7501 | for (idx = 0; curr < entries_end; idx++) |
e4b7104b NC |
7502 | { |
7503 | dwarf_vma offset; | |
7504 | const unsigned char * string; | |
7505 | ||
a7077ce7 | 7506 | if ((dwarf_vma) (entries_end - curr) < entry_length) |
95abb394 TV |
7507 | /* Not enough space to read one entry_length, give up. */ |
7508 | return 0; | |
7509 | ||
c4375dd7 | 7510 | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, entries_end); |
39f381cb NC |
7511 | if (dwo) |
7512 | string = (const unsigned char *) | |
9f27c364 | 7513 | fetch_indexed_string (idx, NULL, entry_length, dwo); |
39f381cb NC |
7514 | else |
7515 | string = fetch_indirect_string (offset); | |
7516 | ||
9f27c364 | 7517 | printf (" %8lu %8s %s\n", idx, dwarf_vmatoa ("x", offset), |
e4b7104b NC |
7518 | string); |
7519 | } | |
7520 | } | |
39f381cb | 7521 | |
4723351a CC |
7522 | return 1; |
7523 | } | |
7524 | ||
01a8f077 JK |
7525 | /* Each debug_information[x].range_lists[y] gets this representation for |
7526 | sorting purposes. */ | |
7527 | ||
7528 | struct range_entry | |
467c65bc NC |
7529 | { |
7530 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 7531 | dwarf_vma ranges_offset; |
01a8f077 | 7532 | |
467c65bc NC |
7533 | /* Original debug_information to find parameters of the data. */ |
7534 | debug_info *debug_info_p; | |
7535 | }; | |
01a8f077 JK |
7536 | |
7537 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
7538 | ||
7539 | static int | |
7540 | range_entry_compar (const void *ap, const void *bp) | |
7541 | { | |
3f5e193b NC |
7542 | const struct range_entry *a_re = (const struct range_entry *) ap; |
7543 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
7544 | const dwarf_vma a = a_re->ranges_offset; |
7545 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
7546 | |
7547 | return (a > b) - (b > a); | |
7548 | } | |
7549 | ||
77145576 JK |
7550 | static void |
7551 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
7552 | unsigned int pointer_size, unsigned long offset, | |
7553 | unsigned long base_address) | |
7554 | { | |
7555 | while (start < finish) | |
7556 | { | |
7557 | dwarf_vma begin; | |
7558 | dwarf_vma end; | |
7559 | ||
7560 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7561 | if (start >= finish) | |
7562 | break; | |
7563 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7564 | ||
7565 | printf (" %8.8lx ", offset); | |
7566 | ||
7567 | if (begin == 0 && end == 0) | |
7568 | { | |
7569 | printf (_("<End of list>\n")); | |
7570 | break; | |
7571 | } | |
7572 | ||
7573 | /* Check base address specifiers. */ | |
7574 | if (is_max_address (begin, pointer_size) | |
7575 | && !is_max_address (end, pointer_size)) | |
7576 | { | |
7577 | base_address = end; | |
7578 | print_dwarf_vma (begin, pointer_size); | |
7579 | print_dwarf_vma (end, pointer_size); | |
7580 | printf ("(base address)\n"); | |
7581 | continue; | |
7582 | } | |
7583 | ||
7584 | print_dwarf_vma (begin + base_address, pointer_size); | |
7585 | print_dwarf_vma (end + base_address, pointer_size); | |
7586 | ||
7587 | if (begin == end) | |
7588 | fputs (_("(start == end)"), stdout); | |
7589 | else if (begin > end) | |
7590 | fputs (_("(start > end)"), stdout); | |
7591 | ||
7592 | putchar ('\n'); | |
7593 | } | |
7594 | } | |
7595 | ||
7596 | static void | |
7597 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
7598 | unsigned int pointer_size, unsigned long offset, | |
7599 | unsigned long base_address) | |
7600 | { | |
7601 | unsigned char *next = start; | |
7602 | ||
7603 | while (1) | |
7604 | { | |
7605 | unsigned long off = offset + (start - next); | |
7606 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
7607 | /* Initialize it due to a false compiler warning. */ |
7608 | dwarf_vma begin = -1, length, end = -1; | |
77145576 | 7609 | |
669f463d | 7610 | if (start >= finish) |
77145576 JK |
7611 | { |
7612 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
7613 | offset); | |
7614 | break; | |
7615 | } | |
7616 | ||
7617 | printf (" %8.8lx ", off); | |
7618 | ||
7619 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
7620 | ||
7621 | switch (rlet) | |
7622 | { | |
7623 | case DW_RLE_end_of_list: | |
7624 | printf (_("<End of list>\n")); | |
7625 | break; | |
7626 | case DW_RLE_base_address: | |
7627 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
7628 | print_dwarf_vma (base_address, pointer_size); | |
7629 | printf (_("(base address)\n")); | |
7630 | break; | |
7631 | case DW_RLE_start_length: | |
7632 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
cd30bcef | 7633 | READ_ULEB (length, start, finish); |
77145576 JK |
7634 | end = begin + length; |
7635 | break; | |
7636 | case DW_RLE_offset_pair: | |
cd30bcef AM |
7637 | READ_ULEB (begin, start, finish); |
7638 | READ_ULEB (end, start, finish); | |
77145576 JK |
7639 | break; |
7640 | case DW_RLE_start_end: | |
7641 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7642 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7643 | break; | |
7644 | default: | |
7645 | error (_("Invalid range list entry type %d\n"), rlet); | |
7646 | rlet = DW_RLE_end_of_list; | |
7647 | break; | |
7648 | } | |
7649 | if (rlet == DW_RLE_end_of_list) | |
7650 | break; | |
7651 | if (rlet == DW_RLE_base_address) | |
7652 | continue; | |
7653 | ||
4d932715 BE |
7654 | /* Only a DW_RLE_offset_pair needs the base address added. */ |
7655 | if (rlet == DW_RLE_offset_pair) | |
7656 | { | |
7657 | begin += base_address; | |
7658 | end += base_address; | |
7659 | } | |
7660 | ||
7661 | print_dwarf_vma (begin, pointer_size); | |
7662 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
7663 | |
7664 | if (begin == end) | |
7665 | fputs (_("(start == end)"), stdout); | |
7666 | else if (begin > end) | |
7667 | fputs (_("(start > end)"), stdout); | |
7668 | ||
7669 | putchar ('\n'); | |
7670 | } | |
7671 | } | |
7672 | ||
19e6b90e L |
7673 | static int |
7674 | display_debug_ranges (struct dwarf_section *section, | |
7675 | void *file ATTRIBUTE_UNUSED) | |
7676 | { | |
7677 | unsigned char *start = section->start; | |
a2ff7a4b | 7678 | unsigned char *last_start = start; |
f6f0e17b | 7679 | unsigned long bytes = section->size; |
19e6b90e | 7680 | unsigned char *section_begin = start; |
f6f0e17b | 7681 | unsigned char *finish = start + bytes; |
01a8f077 JK |
7682 | unsigned int num_range_list, i; |
7683 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
7684 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
7685 | /* Initialize it due to a false compiler warning. */ | |
7686 | unsigned char address_size = 0; | |
cb4c35cf | 7687 | dwarf_vma last_offset = 0; |
19e6b90e | 7688 | |
19e6b90e L |
7689 | if (bytes == 0) |
7690 | { | |
7691 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7692 | return 0; | |
7693 | } | |
7694 | ||
77145576 JK |
7695 | if (is_rnglists) |
7696 | { | |
7697 | dwarf_vma initial_length; | |
77145576 JK |
7698 | unsigned char segment_selector_size; |
7699 | unsigned int offset_size, offset_entry_count; | |
7700 | unsigned short version; | |
7701 | ||
7702 | /* Get and check the length of the block. */ | |
7703 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
7704 | ||
7705 | if (initial_length == 0xffffffff) | |
7706 | { | |
7707 | /* This section is 64-bit DWARF 3. */ | |
7708 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
7709 | offset_size = 8; | |
77145576 JK |
7710 | } |
7711 | else | |
b4951546 | 7712 | offset_size = 4; |
77145576 | 7713 | |
b4951546 | 7714 | if (initial_length > (size_t) (finish - start)) |
77145576 JK |
7715 | { |
7716 | /* If the length field has a relocation against it, then we should | |
7717 | not complain if it is inaccurate (and probably negative). | |
7718 | It is copied from .debug_line handling code. */ | |
7719 | if (reloc_at (section, (start - section->start) - offset_size)) | |
7720 | { | |
b4951546 | 7721 | initial_length = finish - start; |
77145576 JK |
7722 | } |
7723 | else | |
7724 | { | |
7725 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
7726 | (long) initial_length); | |
7727 | return 0; | |
7728 | } | |
7729 | } | |
b4951546 | 7730 | finish = start + initial_length; |
77145576 JK |
7731 | |
7732 | /* Get and check the version number. */ | |
7733 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
7734 | ||
7735 | if (version != 5) | |
7736 | { | |
7737 | warn (_("Only DWARF version 5 debug_rnglists info " | |
7738 | "is currently supported.\n")); | |
7739 | return 0; | |
7740 | } | |
7741 | ||
7742 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
7743 | ||
7744 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
7745 | if (segment_selector_size != 0) | |
7746 | { | |
7747 | warn (_("The %s section contains " | |
7748 | "unsupported segment selector size: %d.\n"), | |
7749 | section->name, segment_selector_size); | |
7750 | return 0; | |
7751 | } | |
7752 | ||
7753 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
7754 | if (offset_entry_count != 0) | |
7755 | { | |
7756 | warn (_("The %s section contains " | |
7757 | "unsupported offset entry count: %u.\n"), | |
7758 | section->name, offset_entry_count); | |
7759 | return 0; | |
7760 | } | |
7761 | } | |
7762 | ||
1febe64d NC |
7763 | if (load_debug_info (file) == 0) |
7764 | { | |
7765 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7766 | section->name); | |
7767 | return 0; | |
7768 | } | |
19e6b90e | 7769 | |
01a8f077 | 7770 | num_range_list = 0; |
19e6b90e | 7771 | for (i = 0; i < num_debug_info_entries; i++) |
52ff20fe TV |
7772 | { |
7773 | if (debug_information [i].dwarf_version < 5 && is_rnglists) | |
7774 | /* Skip .debug_rnglists reference. */ | |
7775 | continue; | |
7776 | if (debug_information [i].dwarf_version >= 5 && !is_rnglists) | |
7777 | /* Skip .debug_range reference. */ | |
7778 | continue; | |
7779 | num_range_list += debug_information [i].num_range_lists; | |
7780 | } | |
19e6b90e | 7781 | |
01a8f077 | 7782 | if (num_range_list == 0) |
4723351a CC |
7783 | { |
7784 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7785 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7786 | printf (_("No range lists in .debug_info section.\n")); |
7787 | return 1; | |
7788 | } | |
19e6b90e | 7789 | |
3f5e193b NC |
7790 | range_entries = (struct range_entry *) |
7791 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7792 | range_entry_fill = range_entries; |
19e6b90e | 7793 | |
01a8f077 JK |
7794 | for (i = 0; i < num_debug_info_entries; i++) |
7795 | { | |
7796 | debug_info *debug_info_p = &debug_information[i]; | |
7797 | unsigned int j; | |
7798 | ||
52ff20fe TV |
7799 | if (debug_information [i].dwarf_version < 5 && is_rnglists) |
7800 | /* Skip .debug_rnglists reference. */ | |
7801 | continue; | |
7802 | if (debug_information [i].dwarf_version >= 5 && !is_rnglists) | |
7803 | /* Skip .debug_range reference. */ | |
7804 | continue; | |
7805 | ||
01a8f077 JK |
7806 | for (j = 0; j < debug_info_p->num_range_lists; j++) |
7807 | { | |
7808 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7809 | range_entry_fill->debug_info_p = debug_info_p; | |
7810 | range_entry_fill++; | |
19e6b90e L |
7811 | } |
7812 | } | |
7813 | ||
01a8f077 JK |
7814 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7815 | range_entry_compar); | |
19e6b90e | 7816 | |
d493b283 | 7817 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7818 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7819 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7820 | |
015dc7e1 | 7821 | introduce (section, false); |
dda8d76d | 7822 | |
19e6b90e L |
7823 | printf (_(" Offset Begin End\n")); |
7824 | ||
01a8f077 | 7825 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7826 | { |
01a8f077 JK |
7827 | struct range_entry *range_entry = &range_entries[i]; |
7828 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7829 | unsigned int pointer_size; |
359ca075 | 7830 | dwarf_vma offset; |
01a8f077 | 7831 | unsigned char *next; |
359ca075 | 7832 | dwarf_vma base_address; |
19e6b90e | 7833 | |
77145576 | 7834 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7835 | offset = range_entry->ranges_offset; |
01a8f077 | 7836 | base_address = debug_info_p->base_address; |
cecf136e | 7837 | |
f41e4712 NC |
7838 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7839 | if (pointer_size < 2 || pointer_size > 8) | |
7840 | { | |
7841 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7842 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7843 | continue; |
7844 | } | |
b4eb7656 | 7845 | |
b4951546 | 7846 | if (offset > (size_t) (finish - section_begin)) |
d11ae95e NC |
7847 | { |
7848 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7849 | (unsigned long) offset, i); | |
7850 | continue; | |
7851 | } | |
b4951546 | 7852 | next = section_begin + offset; |
d11ae95e | 7853 | |
cb4c35cf AB |
7854 | /* If multiple DWARF entities reference the same range then we will |
7855 | have multiple entries in the `range_entries' list for the same | |
7856 | offset. Thanks to the sort above these will all be consecutive in | |
7857 | the `range_entries' list, so we can easily ignore duplicates | |
7858 | here. */ | |
7859 | if (i > 0 && last_offset == offset) | |
7860 | continue; | |
7861 | last_offset = offset; | |
7862 | ||
4723351a | 7863 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7864 | { |
01a8f077 JK |
7865 | if (start < next) |
7866 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7867 | (unsigned long) (start - section_begin), | |
7868 | (unsigned long) (next - section_begin), section->name); | |
7869 | else if (start > next) | |
a2ff7a4b AM |
7870 | { |
7871 | if (next == last_start) | |
7872 | continue; | |
7873 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7874 | (unsigned long) (start - section_begin), | |
7875 | (unsigned long) (next - section_begin), section->name); | |
7876 | } | |
01a8f077 | 7877 | } |
d11ae95e | 7878 | |
01a8f077 | 7879 | start = next; |
a2ff7a4b | 7880 | last_start = next; |
19e6b90e | 7881 | |
77145576 JK |
7882 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7883 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7884 | } |
7885 | putchar ('\n'); | |
01a8f077 JK |
7886 | |
7887 | free (range_entries); | |
7888 | ||
19e6b90e L |
7889 | return 1; |
7890 | } | |
7891 | ||
7892 | typedef struct Frame_Chunk | |
7893 | { | |
7894 | struct Frame_Chunk *next; | |
7895 | unsigned char *chunk_start; | |
a1165289 | 7896 | unsigned int ncols; |
19e6b90e L |
7897 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
7898 | short int *col_type; | |
7899 | int *col_offset; | |
7900 | char *augmentation; | |
7901 | unsigned int code_factor; | |
7902 | int data_factor; | |
bf5117e3 NC |
7903 | dwarf_vma pc_begin; |
7904 | dwarf_vma pc_range; | |
32ef3000 | 7905 | unsigned int cfa_reg; |
c8071705 | 7906 | dwarf_vma cfa_offset; |
a1165289 | 7907 | unsigned int ra; |
19e6b90e L |
7908 | unsigned char fde_encoding; |
7909 | unsigned char cfa_exp; | |
604282a7 JJ |
7910 | unsigned char ptr_size; |
7911 | unsigned char segment_size; | |
19e6b90e L |
7912 | } |
7913 | Frame_Chunk; | |
7914 | ||
1296bc99 AB |
7915 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
7916 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
7917 | static const char *const *dwarf_regnames; |
7918 | static unsigned int dwarf_regnames_count; | |
7919 | ||
1296bc99 | 7920 | |
19e6b90e L |
7921 | /* A marker for a col_type that means this column was never referenced |
7922 | in the frame info. */ | |
7923 | #define DW_CFA_unreferenced (-1) | |
7924 | ||
a1165289 | 7925 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7926 | -1 for invalid reg. */ |
7927 | ||
7928 | static int | |
7929 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7930 | { |
a1165289 | 7931 | unsigned int prev = fc->ncols; |
19e6b90e | 7932 | |
665ce1f6 L |
7933 | if (reg < (unsigned int) fc->ncols) |
7934 | return 0; | |
7935 | ||
d9acf707 | 7936 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
7937 | && reg > dwarf_regnames_count) |
7938 | return -1; | |
19e6b90e L |
7939 | |
7940 | fc->ncols = reg + 1; | |
a1165289 NC |
7941 | /* PR 17512: file: 10450-2643-0.004. |
7942 | If reg == -1 then this can happen... */ | |
7943 | if (fc->ncols == 0) | |
7944 | return -1; | |
7945 | ||
06614111 | 7946 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 7947 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
7948 | { |
7949 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7950 | fc->ncols = 0; | |
7951 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7952 | we ever encounter a valid binary that exceeds it. */ | |
7953 | return -1; | |
7954 | } | |
7955 | ||
3f5e193b | 7956 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7957 | sizeof (short int)); |
3f5e193b | 7958 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7959 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7960 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7961 | { | |
7962 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7963 | fc->ncols); | |
7964 | fc->ncols = 0; | |
7965 | return -1; | |
7966 | } | |
19e6b90e L |
7967 | |
7968 | while (prev < fc->ncols) | |
7969 | { | |
7970 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7971 | fc->col_offset[prev] = 0; | |
7972 | prev++; | |
7973 | } | |
665ce1f6 | 7974 | return 1; |
19e6b90e L |
7975 | } |
7976 | ||
2dc4cec1 L |
7977 | static const char *const dwarf_regnames_i386[] = |
7978 | { | |
43234a1e L |
7979 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7980 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7981 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7982 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7983 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7984 | NULL, NULL, /* 19 - 20 */ | |
7985 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7986 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7987 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7988 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7989 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7990 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7991 | "tr", "ldtr", /* 48 - 49 */ | |
7992 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7993 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7994 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7995 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7996 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7997 | NULL, NULL, NULL, /* 90 - 92 */ | |
7998 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7999 | }; |
8000 | ||
3d875af5 L |
8001 | static const char *const dwarf_regnames_iamcu[] = |
8002 | { | |
8003 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
8004 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
8005 | "eip", "eflags", NULL, /* 8 - 10 */ | |
8006 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
8007 | NULL, NULL, /* 19 - 20 */ | |
8008 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
8009 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
8010 | NULL, NULL, NULL, /* 37 - 39 */ | |
8011 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
8012 | "tr", "ldtr", /* 48 - 49 */ | |
8013 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
8014 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
8015 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
8016 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
8017 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
8018 | NULL, NULL, NULL, /* 90 - 92 */ | |
8019 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
8020 | }; | |
8021 | ||
99f6fdd9 | 8022 | static void |
b129eb0e RH |
8023 | init_dwarf_regnames_i386 (void) |
8024 | { | |
8025 | dwarf_regnames = dwarf_regnames_i386; | |
8026 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 8027 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
8028 | } |
8029 | ||
99f6fdd9 | 8030 | static void |
3d875af5 L |
8031 | init_dwarf_regnames_iamcu (void) |
8032 | { | |
8033 | dwarf_regnames = dwarf_regnames_iamcu; | |
8034 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 8035 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
8036 | } |
8037 | ||
2dc4cec1 L |
8038 | static const char *const dwarf_regnames_x86_64[] = |
8039 | { | |
8040 | "rax", "rdx", "rcx", "rbx", | |
8041 | "rsi", "rdi", "rbp", "rsp", | |
8042 | "r8", "r9", "r10", "r11", | |
8043 | "r12", "r13", "r14", "r15", | |
8044 | "rip", | |
8045 | "xmm0", "xmm1", "xmm2", "xmm3", | |
8046 | "xmm4", "xmm5", "xmm6", "xmm7", | |
8047 | "xmm8", "xmm9", "xmm10", "xmm11", | |
8048 | "xmm12", "xmm13", "xmm14", "xmm15", | |
8049 | "st0", "st1", "st2", "st3", | |
8050 | "st4", "st5", "st6", "st7", | |
8051 | "mm0", "mm1", "mm2", "mm3", | |
8052 | "mm4", "mm5", "mm6", "mm7", | |
8053 | "rflags", | |
8054 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
8055 | "fs.base", "gs.base", NULL, NULL, | |
8056 | "tr", "ldtr", | |
43234a1e L |
8057 | "mxcsr", "fcw", "fsw", |
8058 | "xmm16", "xmm17", "xmm18", "xmm19", | |
8059 | "xmm20", "xmm21", "xmm22", "xmm23", | |
8060 | "xmm24", "xmm25", "xmm26", "xmm27", | |
8061 | "xmm28", "xmm29", "xmm30", "xmm31", | |
8062 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
8063 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
8064 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
8065 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
8066 | NULL, NULL, NULL, /* 115 - 117 */ | |
8067 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
8068 | }; |
8069 | ||
99f6fdd9 | 8070 | static void |
b129eb0e RH |
8071 | init_dwarf_regnames_x86_64 (void) |
8072 | { | |
8073 | dwarf_regnames = dwarf_regnames_x86_64; | |
8074 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 8075 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
8076 | } |
8077 | ||
4ee22035 RH |
8078 | static const char *const dwarf_regnames_aarch64[] = |
8079 | { | |
b4eb7656 AM |
8080 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
8081 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
8082 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
8083 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
8084 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
8085 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
8086 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
8087 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
8088 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
8089 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
8090 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
8091 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
8092 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
8093 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
8094 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
8095 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
8096 | }; |
8097 | ||
99f6fdd9 | 8098 | static void |
4ee22035 RH |
8099 | init_dwarf_regnames_aarch64 (void) |
8100 | { | |
8101 | dwarf_regnames = dwarf_regnames_aarch64; | |
8102 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 8103 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
8104 | } |
8105 | ||
d6bb17b0 AA |
8106 | static const char *const dwarf_regnames_s390[] = |
8107 | { | |
8108 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
8109 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8110 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8111 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
8112 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
8113 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
8114 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
8115 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
8116 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
8117 | "pswm", "pswa", | |
8118 | NULL, NULL, | |
8119 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
8120 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
8121 | }; | |
8122 | ||
99f6fdd9 | 8123 | static void |
d6bb17b0 AA |
8124 | init_dwarf_regnames_s390 (void) |
8125 | { | |
8126 | dwarf_regnames = dwarf_regnames_s390; | |
8127 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 8128 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
8129 | } |
8130 | ||
5bb0830d AB |
8131 | static const char *const dwarf_regnames_riscv[] = |
8132 | { | |
8133 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
8134 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
8135 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
8136 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
8137 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
8138 | "fs0", "fs1", /* 40 - 41 */ | |
8139 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
8140 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
8141 | "fs10", "fs11", /* 58 - 59 */ | |
8142 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
8143 | }; | |
8144 | ||
4762fe62 AB |
8145 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
8146 | the large number of CSRs. */ | |
8147 | ||
8148 | static const char * | |
8149 | regname_internal_riscv (unsigned int regno) | |
8150 | { | |
8151 | const char *name = NULL; | |
8152 | ||
8153 | /* Lookup in the table first, this covers GPR and FPR. */ | |
8154 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
8155 | name = dwarf_regnames_riscv [regno]; | |
8156 | else if (regno >= 4096 && regno <= 8191) | |
8157 | { | |
8158 | /* This might be a CSR, these live in a sparse number space from 4096 | |
8159 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
8160 | document. */ | |
8161 | switch (regno) | |
8162 | { | |
8f595e9b NC |
8163 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
8164 | case VALUE + 4096: name = #NAME; break; | |
4762fe62 AB |
8165 | #include "opcode/riscv-opc.h" |
8166 | #undef DECLARE_CSR | |
8167 | ||
8168 | default: | |
8169 | { | |
8170 | static char csr_name[10]; | |
8171 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
8172 | name = csr_name; | |
8173 | } | |
8174 | break; | |
8175 | } | |
8176 | } | |
8177 | ||
8178 | return name; | |
8179 | } | |
8180 | ||
99f6fdd9 | 8181 | static void |
5bb0830d AB |
8182 | init_dwarf_regnames_riscv (void) |
8183 | { | |
4762fe62 AB |
8184 | dwarf_regnames = NULL; |
8185 | dwarf_regnames_count = 8192; | |
8186 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
8187 | } |
8188 | ||
2dc4cec1 | 8189 | void |
955ff7fc | 8190 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 8191 | { |
1296bc99 AB |
8192 | dwarf_regnames_lookup_func = NULL; |
8193 | ||
2dc4cec1 L |
8194 | switch (e_machine) |
8195 | { | |
8196 | case EM_386: | |
b129eb0e | 8197 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
8198 | break; |
8199 | ||
3d875af5 L |
8200 | case EM_IAMCU: |
8201 | init_dwarf_regnames_iamcu (); | |
8202 | break; | |
8203 | ||
2dc4cec1 | 8204 | case EM_X86_64: |
7f502d6c | 8205 | case EM_L1OM: |
7a9068fe | 8206 | case EM_K1OM: |
b129eb0e | 8207 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
8208 | break; |
8209 | ||
4ee22035 RH |
8210 | case EM_AARCH64: |
8211 | init_dwarf_regnames_aarch64 (); | |
8212 | break; | |
8213 | ||
d6bb17b0 AA |
8214 | case EM_S390: |
8215 | init_dwarf_regnames_s390 (); | |
8216 | break; | |
8217 | ||
5bb0830d AB |
8218 | case EM_RISCV: |
8219 | init_dwarf_regnames_riscv (); | |
8220 | break; | |
8221 | ||
2dc4cec1 L |
8222 | default: |
8223 | break; | |
8224 | } | |
8225 | } | |
8226 | ||
229a22cf AB |
8227 | /* Initialize the DWARF register name lookup state based on the |
8228 | architecture and specific machine type of a BFD. */ | |
8229 | ||
8230 | void | |
8231 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
8232 | unsigned long mach) | |
8233 | { | |
1296bc99 AB |
8234 | dwarf_regnames_lookup_func = NULL; |
8235 | ||
229a22cf AB |
8236 | switch (arch) |
8237 | { | |
8238 | case bfd_arch_i386: | |
8239 | switch (mach) | |
8240 | { | |
8241 | case bfd_mach_x86_64: | |
8242 | case bfd_mach_x86_64_intel_syntax: | |
229a22cf AB |
8243 | case bfd_mach_x64_32: |
8244 | case bfd_mach_x64_32_intel_syntax: | |
229a22cf AB |
8245 | init_dwarf_regnames_x86_64 (); |
8246 | break; | |
8247 | ||
8248 | default: | |
8249 | init_dwarf_regnames_i386 (); | |
8250 | break; | |
8251 | } | |
8252 | break; | |
8253 | ||
8254 | case bfd_arch_iamcu: | |
8255 | init_dwarf_regnames_iamcu (); | |
8256 | break; | |
8257 | ||
8258 | case bfd_arch_aarch64: | |
8259 | init_dwarf_regnames_aarch64(); | |
8260 | break; | |
8261 | ||
8262 | case bfd_arch_s390: | |
8263 | init_dwarf_regnames_s390 (); | |
8264 | break; | |
8265 | ||
8266 | case bfd_arch_riscv: | |
8267 | init_dwarf_regnames_riscv (); | |
8268 | break; | |
8269 | ||
8270 | default: | |
8271 | break; | |
8272 | } | |
8273 | } | |
8274 | ||
2dc4cec1 | 8275 | static const char * |
1296bc99 | 8276 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 8277 | { |
1296bc99 | 8278 | if (dwarf_regnames != NULL |
2dc4cec1 L |
8279 | && regno < dwarf_regnames_count |
8280 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
8281 | return dwarf_regnames [regno]; |
8282 | ||
8283 | return NULL; | |
8284 | } | |
8285 | ||
8286 | static const char * | |
8287 | regname (unsigned int regno, int name_only_p) | |
8288 | { | |
8289 | static char reg[64]; | |
8290 | ||
8291 | const char *name = NULL; | |
8292 | ||
8293 | if (dwarf_regnames_lookup_func != NULL) | |
8294 | name = dwarf_regnames_lookup_func (regno); | |
8295 | ||
8296 | if (name != NULL) | |
2dc4cec1 | 8297 | { |
1296bc99 AB |
8298 | if (name_only_p) |
8299 | return name; | |
8300 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
8301 | } |
8302 | else | |
8303 | snprintf (reg, sizeof (reg), "r%d", regno); | |
8304 | return reg; | |
8305 | } | |
8306 | ||
19e6b90e | 8307 | static void |
a1165289 | 8308 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 8309 | { |
a1165289 | 8310 | unsigned int r; |
19e6b90e L |
8311 | char tmp[100]; |
8312 | ||
d8024a91 | 8313 | if (*max_regs != fc->ncols) |
19e6b90e L |
8314 | *max_regs = fc->ncols; |
8315 | ||
8316 | if (*need_col_headers) | |
8317 | { | |
8318 | *need_col_headers = 0; | |
8319 | ||
288f0ba2 | 8320 | printf ("%-*s CFA ", eh_addr_size * 2, " LOC"); |
19e6b90e L |
8321 | |
8322 | for (r = 0; r < *max_regs; r++) | |
8323 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8324 | { | |
8325 | if (r == fc->ra) | |
50751e18 | 8326 | printf ("ra "); |
19e6b90e | 8327 | else |
2dc4cec1 | 8328 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
8329 | } |
8330 | ||
8331 | printf ("\n"); | |
8332 | } | |
8333 | ||
bf5117e3 | 8334 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
8335 | if (fc->cfa_exp) |
8336 | strcpy (tmp, "exp"); | |
8337 | else | |
c8071705 | 8338 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
8339 | printf ("%-8s ", tmp); |
8340 | ||
8341 | for (r = 0; r < fc->ncols; r++) | |
8342 | { | |
8343 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8344 | { | |
8345 | switch (fc->col_type[r]) | |
8346 | { | |
8347 | case DW_CFA_undefined: | |
8348 | strcpy (tmp, "u"); | |
8349 | break; | |
8350 | case DW_CFA_same_value: | |
8351 | strcpy (tmp, "s"); | |
8352 | break; | |
8353 | case DW_CFA_offset: | |
8354 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
8355 | break; | |
12eae2d3 JJ |
8356 | case DW_CFA_val_offset: |
8357 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
8358 | break; | |
19e6b90e | 8359 | case DW_CFA_register: |
2dc4cec1 | 8360 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
8361 | break; |
8362 | case DW_CFA_expression: | |
8363 | strcpy (tmp, "exp"); | |
8364 | break; | |
12eae2d3 JJ |
8365 | case DW_CFA_val_expression: |
8366 | strcpy (tmp, "vexp"); | |
8367 | break; | |
19e6b90e L |
8368 | default: |
8369 | strcpy (tmp, "n/a"); | |
8370 | break; | |
8371 | } | |
2dc4cec1 | 8372 | printf ("%-5s ", tmp); |
19e6b90e L |
8373 | } |
8374 | } | |
8375 | printf ("\n"); | |
8376 | } | |
8377 | ||
49727e46 | 8378 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 8379 | |
49727e46 AM |
8380 | static unsigned char * |
8381 | read_cie (unsigned char *start, unsigned char *end, | |
8382 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 8383 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
8384 | { |
8385 | int version; | |
8386 | Frame_Chunk *fc; | |
49727e46 | 8387 | unsigned char *augmentation_data = NULL; |
bf59c5d5 | 8388 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 8389 | |
041830e0 | 8390 | * p_cie = NULL; |
f41e4712 NC |
8391 | /* PR 17512: file: 001-228113-0.004. */ |
8392 | if (start >= end) | |
8393 | return end; | |
8394 | ||
49727e46 AM |
8395 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
8396 | memset (fc, 0, sizeof (Frame_Chunk)); | |
8397 | ||
8398 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
8399 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
8400 | ||
8401 | version = *start++; | |
8402 | ||
8403 | fc->augmentation = (char *) start; | |
f41e4712 NC |
8404 | /* PR 17512: file: 001-228113-0.004. |
8405 | Skip past augmentation name, but avoid running off the end of the data. */ | |
8406 | while (start < end) | |
8407 | if (* start ++ == '\0') | |
8408 | break; | |
8409 | if (start == end) | |
8410 | { | |
8411 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 8412 | goto fail; |
f41e4712 | 8413 | } |
49727e46 AM |
8414 | |
8415 | if (strcmp (fc->augmentation, "eh") == 0) | |
c93c4a85 AM |
8416 | { |
8417 | if (eh_addr_size > (size_t) (end - start)) | |
8418 | goto fail; | |
8419 | start += eh_addr_size; | |
8420 | } | |
49727e46 AM |
8421 | |
8422 | if (version >= 4) | |
8423 | { | |
c93c4a85 AM |
8424 | if (2 > (size_t) (end - start)) |
8425 | goto fail; | |
49727e46 | 8426 | GET (fc->ptr_size, 1); |
77ef8654 NC |
8427 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
8428 | { | |
8429 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 8430 | goto fail; |
77ef8654 NC |
8431 | } |
8432 | ||
49727e46 | 8433 | GET (fc->segment_size, 1); |
77ef8654 NC |
8434 | /* PR 17512: file: e99d2804. */ |
8435 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
8436 | { | |
8437 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 8438 | goto fail; |
77ef8654 NC |
8439 | } |
8440 | ||
49727e46 AM |
8441 | eh_addr_size = fc->ptr_size; |
8442 | } | |
8443 | else | |
8444 | { | |
8445 | fc->ptr_size = eh_addr_size; | |
8446 | fc->segment_size = 0; | |
8447 | } | |
442a6ce8 | 8448 | |
cd30bcef AM |
8449 | READ_ULEB (fc->code_factor, start, end); |
8450 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 8451 | |
c93c4a85 AM |
8452 | if (start >= end) |
8453 | goto fail; | |
8454 | ||
49727e46 AM |
8455 | if (version == 1) |
8456 | { | |
8457 | GET (fc->ra, 1); | |
8458 | } | |
8459 | else | |
8460 | { | |
cd30bcef | 8461 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
8462 | } |
8463 | ||
8464 | if (fc->augmentation[0] == 'z') | |
8465 | { | |
c93c4a85 AM |
8466 | if (start >= end) |
8467 | goto fail; | |
cd30bcef | 8468 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 8469 | augmentation_data = start; |
a1165289 | 8470 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 8471 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 8472 | { |
bf59c5d5 NC |
8473 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
8474 | dwarf_vmatoa ("x", augmentation_data_len), | |
8475 | (unsigned long) (end - start)); | |
442a6ce8 | 8476 | goto fail; |
a1165289 | 8477 | } |
9c0f3d3f | 8478 | start += augmentation_data_len; |
49727e46 AM |
8479 | } |
8480 | ||
8481 | if (augmentation_data_len) | |
8482 | { | |
058037d3 NC |
8483 | unsigned char *p; |
8484 | unsigned char *q; | |
8485 | unsigned char *qend; | |
b4eb7656 | 8486 | |
49727e46 AM |
8487 | p = (unsigned char *) fc->augmentation + 1; |
8488 | q = augmentation_data; | |
058037d3 NC |
8489 | qend = q + augmentation_data_len; |
8490 | ||
9c0f3d3f | 8491 | while (p < end && q < qend) |
49727e46 AM |
8492 | { |
8493 | if (*p == 'L') | |
8494 | q++; | |
8495 | else if (*p == 'P') | |
8496 | q += 1 + size_of_encoded_value (*q); | |
8497 | else if (*p == 'R') | |
8498 | fc->fde_encoding = *q++; | |
8499 | else if (*p == 'S') | |
8500 | ; | |
09038062 ST |
8501 | else if (*p == 'B') |
8502 | ; | |
49727e46 AM |
8503 | else |
8504 | break; | |
8505 | p++; | |
8506 | } | |
c361b9ac NC |
8507 | /* Note - it is OK if this loop terminates with q < qend. |
8508 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
8509 | } |
8510 | ||
8511 | *p_cie = fc; | |
8512 | if (p_version) | |
8513 | *p_version = version; | |
8514 | if (p_aug_len) | |
8515 | { | |
8516 | *p_aug_len = augmentation_data_len; | |
8517 | *p_aug = augmentation_data; | |
8518 | } | |
8519 | return start; | |
442a6ce8 NC |
8520 | |
8521 | fail: | |
8522 | free (fc->col_offset); | |
8523 | free (fc->col_type); | |
8524 | free (fc); | |
8525 | return end; | |
49727e46 AM |
8526 | } |
8527 | ||
d85bf2ba NC |
8528 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
8529 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
8530 | PRINTED contains the number of characters already written to the current | |
8531 | output line. */ | |
bf59c5d5 NC |
8532 | |
8533 | static void | |
d85bf2ba NC |
8534 | display_data (bfd_size_type printed, |
8535 | const unsigned char * data, | |
8536 | const bfd_size_type len) | |
bf59c5d5 | 8537 | { |
d85bf2ba NC |
8538 | if (do_wide || len < ((80 - printed) / 3)) |
8539 | for (printed = 0; printed < len; ++printed) | |
8540 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
8541 | else |
8542 | { | |
d85bf2ba | 8543 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 8544 | { |
d85bf2ba | 8545 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 8546 | putchar ('\n'); |
d85bf2ba | 8547 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
8548 | } |
8549 | } | |
d85bf2ba NC |
8550 | } |
8551 | ||
8552 | /* Prints out the contents on the augmentation data array. | |
8553 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
8554 | ||
8555 | static void | |
8556 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
8557 | { | |
8558 | bfd_size_type i; | |
8559 | ||
8560 | i = printf (_(" Augmentation data: ")); | |
8561 | display_data (i, data, len); | |
bf59c5d5 NC |
8562 | } |
8563 | ||
19e6b90e L |
8564 | static int |
8565 | display_debug_frames (struct dwarf_section *section, | |
8566 | void *file ATTRIBUTE_UNUSED) | |
8567 | { | |
8568 | unsigned char *start = section->start; | |
8569 | unsigned char *end = start + section->size; | |
8570 | unsigned char *section_start = start; | |
3391569f NC |
8571 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
8572 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 8573 | Frame_Chunk *rs; |
015dc7e1 | 8574 | bool is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 8575 | unsigned int max_regs = 0; |
665ce1f6 | 8576 | const char *bad_reg = _("bad register: "); |
77ef8654 | 8577 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 8578 | |
015dc7e1 | 8579 | introduce (section, false); |
19e6b90e L |
8580 | |
8581 | while (start < end) | |
8582 | { | |
8583 | unsigned char *saved_start; | |
8584 | unsigned char *block_end; | |
bf5117e3 NC |
8585 | dwarf_vma length; |
8586 | dwarf_vma cie_id; | |
19e6b90e L |
8587 | Frame_Chunk *fc; |
8588 | Frame_Chunk *cie; | |
8589 | int need_col_headers = 1; | |
8590 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 8591 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
8592 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
8593 | unsigned int offset_size; | |
015dc7e1 | 8594 | bool all_nops; |
a788aedd | 8595 | static Frame_Chunk fde_fc; |
19e6b90e L |
8596 | |
8597 | saved_start = start; | |
19e6b90e | 8598 | |
0c588247 | 8599 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 8600 | |
19e6b90e L |
8601 | if (length == 0) |
8602 | { | |
8603 | printf ("\n%08lx ZERO terminator\n\n", | |
8604 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
8605 | /* Skip any zero terminators that directly follow. |
8606 | A corrupt section size could have loaded a whole | |
8607 | slew of zero filled memory bytes. eg | |
8608 | PR 17512: file: 070-19381-0.004. */ | |
8609 | while (start < end && * start == 0) | |
8610 | ++ start; | |
b758e50f | 8611 | continue; |
19e6b90e L |
8612 | } |
8613 | ||
8614 | if (length == 0xffffffff) | |
8615 | { | |
0c588247 | 8616 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e | 8617 | offset_size = 8; |
19e6b90e L |
8618 | } |
8619 | else | |
5897a389 | 8620 | offset_size = 4; |
19e6b90e | 8621 | |
5897a389 | 8622 | if (length > (size_t) (end - start)) |
53b8873b | 8623 | { |
bf5117e3 NC |
8624 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
8625 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
8626 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
8627 | block_end = end; |
8628 | } | |
5897a389 AM |
8629 | else |
8630 | block_end = start + length; | |
0c588247 | 8631 | |
5897a389 | 8632 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, block_end); |
19e6b90e | 8633 | |
846a11e4 NC |
8634 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
8635 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
8636 | { |
8637 | int version; | |
a1165289 | 8638 | unsigned int mreg; |
19e6b90e | 8639 | |
5897a389 | 8640 | start = read_cie (start, block_end, &cie, &version, |
49727e46 | 8641 | &augmentation_data_len, &augmentation_data); |
041830e0 NC |
8642 | /* PR 17512: file: 027-135133-0.005. */ |
8643 | if (cie == NULL) | |
8644 | break; | |
a1165289 | 8645 | |
49727e46 | 8646 | fc = cie; |
19e6b90e L |
8647 | fc->next = chunks; |
8648 | chunks = fc; | |
8649 | fc->chunk_start = saved_start; | |
a1165289 | 8650 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8651 | if (mreg < fc->ra) |
8652 | mreg = fc->ra; | |
06614111 NC |
8653 | if (frame_need_space (fc, mreg) < 0) |
8654 | break; | |
49727e46 AM |
8655 | if (fc->fde_encoding) |
8656 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 8657 | |
bf5117e3 NC |
8658 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
8659 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 8660 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 8661 | |
19e6b90e | 8662 | if (do_debug_frames_interp) |
bf5117e3 NC |
8663 | { |
8664 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
8665 | fc->code_factor, fc->data_factor, fc->ra); | |
8666 | } | |
19e6b90e L |
8667 | else |
8668 | { | |
bf5117e3 | 8669 | printf ("CIE\n"); |
19e6b90e L |
8670 | printf (" Version: %d\n", version); |
8671 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
8672 | if (version >= 4) |
8673 | { | |
8674 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
8675 | printf (" Segment Size: %u\n", fc->segment_size); | |
8676 | } | |
19e6b90e L |
8677 | printf (" Code alignment factor: %u\n", fc->code_factor); |
8678 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
8679 | printf (" Return address column: %d\n", fc->ra); | |
8680 | ||
8681 | if (augmentation_data_len) | |
bf59c5d5 | 8682 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 8683 | |
19e6b90e L |
8684 | putchar ('\n'); |
8685 | } | |
19e6b90e L |
8686 | } |
8687 | else | |
8688 | { | |
8689 | unsigned char *look_for; | |
604282a7 | 8690 | unsigned long segment_selector; |
0d872fca | 8691 | dwarf_vma cie_off; |
19e6b90e | 8692 | |
0d872fca | 8693 | cie_off = cie_id; |
49727e46 AM |
8694 | if (is_eh) |
8695 | { | |
8696 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
0d872fca AM |
8697 | cie_off = (cie_off ^ sign) - sign; |
8698 | cie_off = start - 4 - section_start - cie_off; | |
49727e46 | 8699 | } |
19e6b90e | 8700 | |
0d872fca AM |
8701 | look_for = section_start + cie_off; |
8702 | if (cie_off <= (dwarf_vma) (saved_start - section_start)) | |
49727e46 AM |
8703 | { |
8704 | for (cie = chunks; cie ; cie = cie->next) | |
8705 | if (cie->chunk_start == look_for) | |
8706 | break; | |
8707 | } | |
d21f875d AM |
8708 | else if (cie_off >= section->size) |
8709 | cie = NULL; | |
49727e46 AM |
8710 | else |
8711 | { | |
8712 | for (cie = forward_refs; cie ; cie = cie->next) | |
8713 | if (cie->chunk_start == look_for) | |
8714 | break; | |
8715 | if (!cie) | |
8716 | { | |
8717 | unsigned int off_size; | |
8718 | unsigned char *cie_scan; | |
19e6b90e | 8719 | |
49727e46 AM |
8720 | cie_scan = look_for; |
8721 | off_size = 4; | |
8722 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
8723 | if (length == 0xffffffff) | |
8724 | { | |
8725 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
8726 | off_size = 8; | |
8727 | } | |
5897a389 | 8728 | if (length != 0 && length <= (size_t) (end - cie_scan)) |
49727e46 AM |
8729 | { |
8730 | dwarf_vma c_id; | |
5897a389 | 8731 | unsigned char *cie_end = cie_scan + length; |
49727e46 | 8732 | |
5897a389 AM |
8733 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, |
8734 | cie_end); | |
49727e46 AM |
8735 | if (is_eh |
8736 | ? c_id == 0 | |
8737 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
8738 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
8739 | { | |
8740 | int version; | |
a1165289 | 8741 | unsigned int mreg; |
49727e46 | 8742 | |
5897a389 | 8743 | read_cie (cie_scan, cie_end, &cie, &version, |
49727e46 | 8744 | &augmentation_data_len, &augmentation_data); |
a1165289 NC |
8745 | /* PR 17512: file: 3450-2098-0.004. */ |
8746 | if (cie == NULL) | |
8747 | { | |
8748 | warn (_("Failed to read CIE information\n")); | |
8749 | break; | |
8750 | } | |
49727e46 AM |
8751 | cie->next = forward_refs; |
8752 | forward_refs = cie; | |
8753 | cie->chunk_start = look_for; | |
a1165289 | 8754 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8755 | if (mreg < cie->ra) |
8756 | mreg = cie->ra; | |
06614111 NC |
8757 | if (frame_need_space (cie, mreg) < 0) |
8758 | { | |
8759 | warn (_("Invalid max register\n")); | |
8760 | break; | |
8761 | } | |
49727e46 AM |
8762 | if (cie->fde_encoding) |
8763 | encoded_ptr_size | |
8764 | = size_of_encoded_value (cie->fde_encoding); | |
8765 | } | |
8766 | } | |
8767 | } | |
8768 | } | |
8769 | ||
8770 | fc = &fde_fc; | |
8771 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
8772 | |
8773 | if (!cie) | |
8774 | { | |
bf5117e3 NC |
8775 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
8776 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
8777 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 8778 | fc->ncols = 0; |
3f5e193b NC |
8779 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
8780 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
8781 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
8782 | { | |
8783 | warn (_("Invalid max register\n")); | |
8784 | break; | |
8785 | } | |
19e6b90e L |
8786 | cie = fc; |
8787 | fc->augmentation = ""; | |
8788 | fc->fde_encoding = 0; | |
604282a7 JJ |
8789 | fc->ptr_size = eh_addr_size; |
8790 | fc->segment_size = 0; | |
19e6b90e L |
8791 | } |
8792 | else | |
8793 | { | |
8794 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8795 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8796 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8797 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8798 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8799 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8800 | fc->ptr_size = cie->ptr_size; |
8801 | eh_addr_size = cie->ptr_size; | |
8802 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8803 | fc->code_factor = cie->code_factor; |
8804 | fc->data_factor = cie->data_factor; | |
8805 | fc->cfa_reg = cie->cfa_reg; | |
8806 | fc->cfa_offset = cie->cfa_offset; | |
8807 | fc->ra = cie->ra; | |
06614111 NC |
8808 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8809 | { | |
8810 | warn (_("Invalid max register\n")); | |
8811 | break; | |
8812 | } | |
19e6b90e L |
8813 | fc->fde_encoding = cie->fde_encoding; |
8814 | } | |
8815 | ||
8816 | if (fc->fde_encoding) | |
8817 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8818 | ||
604282a7 JJ |
8819 | segment_selector = 0; |
8820 | if (fc->segment_size) | |
c8071705 NC |
8821 | { |
8822 | if (fc->segment_size > sizeof (segment_selector)) | |
8823 | { | |
8824 | /* PR 17512: file: 9e196b3e. */ | |
8825 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8826 | fc->segment_size = 4; | |
8827 | } | |
5897a389 AM |
8828 | SAFE_BYTE_GET_AND_INC (segment_selector, start, |
8829 | fc->segment_size, block_end); | |
c8071705 | 8830 | } |
041830e0 | 8831 | |
5897a389 AM |
8832 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, |
8833 | block_end); | |
19e6b90e | 8834 | |
0c588247 NC |
8835 | /* FIXME: It appears that sometimes the final pc_range value is |
8836 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8837 | run of the "objcopy on compressed debug sections" test for an | |
8838 | example of this. */ | |
5897a389 AM |
8839 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, |
8840 | block_end); | |
bf5117e3 | 8841 | |
19e6b90e L |
8842 | if (cie->augmentation[0] == 'z') |
8843 | { | |
5897a389 | 8844 | READ_ULEB (augmentation_data_len, start, block_end); |
19e6b90e | 8845 | augmentation_data = start; |
bf59c5d5 | 8846 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
5897a389 | 8847 | if (augmentation_data_len > (bfd_size_type) (block_end - start)) |
0a9d414a | 8848 | { |
d292364e AM |
8849 | warn (_("Augmentation data too long: 0x%s, " |
8850 | "expected at most %#lx\n"), | |
8851 | dwarf_vmatoa ("x", augmentation_data_len), | |
5897a389 AM |
8852 | (unsigned long) (block_end - start)); |
8853 | start = block_end; | |
0a9d414a NC |
8854 | augmentation_data = NULL; |
8855 | augmentation_data_len = 0; | |
8856 | } | |
d292364e | 8857 | start += augmentation_data_len; |
19e6b90e L |
8858 | } |
8859 | ||
bf5117e3 NC |
8860 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8861 | (unsigned long)(saved_start - section_start), | |
8862 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8863 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8864 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8865 | |
604282a7 JJ |
8866 | if (fc->segment_size) |
8867 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8868 | |
8869 | printf ("%s..%s\n", | |
8870 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8871 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8872 | ||
19e6b90e L |
8873 | if (! do_debug_frames_interp && augmentation_data_len) |
8874 | { | |
bf59c5d5 | 8875 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8876 | putchar ('\n'); |
8877 | } | |
8878 | } | |
8879 | ||
8880 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8881 | we're about to interpret instructions for the chunk. */ | |
8882 | /* ??? At present we need to do this always, since this sizes the | |
8883 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8884 | We should probably split the interpreted and non-interpreted bits | |
8885 | into two different routines, since there's so much that doesn't | |
8886 | really overlap between them. */ | |
8887 | if (1 || do_debug_frames_interp) | |
8888 | { | |
8889 | /* Start by making a pass over the chunk, allocating storage | |
8890 | and taking note of what registers are used. */ | |
8891 | unsigned char *tmp = start; | |
8892 | ||
8893 | while (start < block_end) | |
8894 | { | |
041830e0 NC |
8895 | unsigned int reg, op, opa; |
8896 | unsigned long temp; | |
19e6b90e L |
8897 | |
8898 | op = *start++; | |
8899 | opa = op & 0x3f; | |
8900 | if (op & 0xc0) | |
8901 | op &= 0xc0; | |
8902 | ||
8903 | /* Warning: if you add any more cases to this switch, be | |
8904 | sure to add them to the corresponding switch below. */ | |
8905 | switch (op) | |
8906 | { | |
8907 | case DW_CFA_advance_loc: | |
8908 | break; | |
8909 | case DW_CFA_offset: | |
5897a389 | 8910 | SKIP_ULEB (start, block_end); |
665ce1f6 L |
8911 | if (frame_need_space (fc, opa) >= 0) |
8912 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8913 | break; |
8914 | case DW_CFA_restore: | |
665ce1f6 L |
8915 | if (frame_need_space (fc, opa) >= 0) |
8916 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8917 | break; |
8918 | case DW_CFA_set_loc: | |
5897a389 AM |
8919 | if ((size_t) (block_end - start) < encoded_ptr_size) |
8920 | start = block_end; | |
8921 | else | |
8922 | start += encoded_ptr_size; | |
19e6b90e L |
8923 | break; |
8924 | case DW_CFA_advance_loc1: | |
5897a389 AM |
8925 | if ((size_t) (block_end - start) < 1) |
8926 | start = block_end; | |
8927 | else | |
8928 | start += 1; | |
19e6b90e L |
8929 | break; |
8930 | case DW_CFA_advance_loc2: | |
5897a389 AM |
8931 | if ((size_t) (block_end - start) < 2) |
8932 | start = block_end; | |
8933 | else | |
8934 | start += 2; | |
19e6b90e L |
8935 | break; |
8936 | case DW_CFA_advance_loc4: | |
5897a389 AM |
8937 | if ((size_t) (block_end - start) < 4) |
8938 | start = block_end; | |
8939 | else | |
8940 | start += 4; | |
19e6b90e L |
8941 | break; |
8942 | case DW_CFA_offset_extended: | |
12eae2d3 | 8943 | case DW_CFA_val_offset: |
5897a389 AM |
8944 | READ_ULEB (reg, start, block_end); |
8945 | SKIP_ULEB (start, block_end); | |
665ce1f6 L |
8946 | if (frame_need_space (fc, reg) >= 0) |
8947 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8948 | break; |
8949 | case DW_CFA_restore_extended: | |
5897a389 | 8950 | READ_ULEB (reg, start, block_end); |
665ce1f6 L |
8951 | if (frame_need_space (fc, reg) >= 0) |
8952 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8953 | break; |
8954 | case DW_CFA_undefined: | |
5897a389 | 8955 | READ_ULEB (reg, start, block_end); |
665ce1f6 L |
8956 | if (frame_need_space (fc, reg) >= 0) |
8957 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8958 | break; |
8959 | case DW_CFA_same_value: | |
5897a389 | 8960 | READ_ULEB (reg, start, block_end); |
665ce1f6 L |
8961 | if (frame_need_space (fc, reg) >= 0) |
8962 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8963 | break; |
8964 | case DW_CFA_register: | |
5897a389 AM |
8965 | READ_ULEB (reg, start, block_end); |
8966 | SKIP_ULEB (start, block_end); | |
665ce1f6 L |
8967 | if (frame_need_space (fc, reg) >= 0) |
8968 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8969 | break; |
8970 | case DW_CFA_def_cfa: | |
5897a389 AM |
8971 | SKIP_ULEB (start, block_end); |
8972 | SKIP_ULEB (start, block_end); | |
19e6b90e L |
8973 | break; |
8974 | case DW_CFA_def_cfa_register: | |
5897a389 | 8975 | SKIP_ULEB (start, block_end); |
19e6b90e L |
8976 | break; |
8977 | case DW_CFA_def_cfa_offset: | |
5897a389 | 8978 | SKIP_ULEB (start, block_end); |
19e6b90e L |
8979 | break; |
8980 | case DW_CFA_def_cfa_expression: | |
5897a389 AM |
8981 | READ_ULEB (temp, start, block_end); |
8982 | if ((size_t) (block_end - start) < temp) | |
8983 | start = block_end; | |
041830e0 | 8984 | else |
5897a389 | 8985 | start += temp; |
19e6b90e L |
8986 | break; |
8987 | case DW_CFA_expression: | |
12eae2d3 | 8988 | case DW_CFA_val_expression: |
5897a389 AM |
8989 | READ_ULEB (reg, start, block_end); |
8990 | READ_ULEB (temp, start, block_end); | |
8991 | if ((size_t) (block_end - start) < temp) | |
8992 | start = block_end; | |
041830e0 | 8993 | else |
5897a389 | 8994 | start += temp; |
665ce1f6 L |
8995 | if (frame_need_space (fc, reg) >= 0) |
8996 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8997 | break; |
8998 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 8999 | case DW_CFA_val_offset_sf: |
5897a389 AM |
9000 | READ_ULEB (reg, start, block_end); |
9001 | SKIP_SLEB (start, block_end); | |
665ce1f6 L |
9002 | if (frame_need_space (fc, reg) >= 0) |
9003 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9004 | break; |
9005 | case DW_CFA_def_cfa_sf: | |
5897a389 AM |
9006 | SKIP_ULEB (start, block_end); |
9007 | SKIP_SLEB (start, block_end); | |
19e6b90e L |
9008 | break; |
9009 | case DW_CFA_def_cfa_offset_sf: | |
5897a389 | 9010 | SKIP_SLEB (start, block_end); |
19e6b90e L |
9011 | break; |
9012 | case DW_CFA_MIPS_advance_loc8: | |
5897a389 AM |
9013 | if ((size_t) (block_end - start) < 8) |
9014 | start = block_end; | |
9015 | else | |
9016 | start += 8; | |
19e6b90e L |
9017 | break; |
9018 | case DW_CFA_GNU_args_size: | |
5897a389 | 9019 | SKIP_ULEB (start, block_end); |
19e6b90e L |
9020 | break; |
9021 | case DW_CFA_GNU_negative_offset_extended: | |
5897a389 AM |
9022 | READ_ULEB (reg, start, block_end); |
9023 | SKIP_ULEB (start, block_end); | |
665ce1f6 L |
9024 | if (frame_need_space (fc, reg) >= 0) |
9025 | fc->col_type[reg] = DW_CFA_undefined; | |
9026 | break; | |
19e6b90e L |
9027 | default: |
9028 | break; | |
9029 | } | |
9030 | } | |
9031 | start = tmp; | |
9032 | } | |
9033 | ||
015dc7e1 | 9034 | all_nops = true; |
5b6312fd | 9035 | |
19e6b90e L |
9036 | /* Now we know what registers are used, make a second pass over |
9037 | the chunk, this time actually printing out the info. */ | |
9038 | ||
9039 | while (start < block_end) | |
9040 | { | |
9041 | unsigned op, opa; | |
7f2c8a1d NC |
9042 | unsigned long ul, roffs; |
9043 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
9044 | are various functions, notably frame_space_needed() that assume that | |
9045 | reg is an unsigned int. */ | |
9046 | unsigned int reg; | |
9047 | dwarf_signed_vma l; | |
bf5117e3 | 9048 | dwarf_vma ofs; |
19e6b90e | 9049 | dwarf_vma vma; |
665ce1f6 | 9050 | const char *reg_prefix = ""; |
19e6b90e L |
9051 | |
9052 | op = *start++; | |
9053 | opa = op & 0x3f; | |
9054 | if (op & 0xc0) | |
9055 | op &= 0xc0; | |
9056 | ||
5b6312fd NC |
9057 | /* Make a note if something other than DW_CFA_nop happens. */ |
9058 | if (op != DW_CFA_nop) | |
015dc7e1 | 9059 | all_nops = false; |
5b6312fd | 9060 | |
19e6b90e L |
9061 | /* Warning: if you add any more cases to this switch, be |
9062 | sure to add them to the corresponding switch above. */ | |
9063 | switch (op) | |
9064 | { | |
9065 | case DW_CFA_advance_loc: | |
9066 | if (do_debug_frames_interp) | |
9067 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9068 | else | |
bf5117e3 | 9069 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 9070 | opa * fc->code_factor, |
b4eb7656 | 9071 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
9072 | fc->pc_begin + opa * fc->code_factor, |
9073 | fc->ptr_size)); | |
19e6b90e L |
9074 | fc->pc_begin += opa * fc->code_factor; |
9075 | break; | |
9076 | ||
9077 | case DW_CFA_offset: | |
5897a389 | 9078 | READ_ULEB (roffs, start, block_end); |
665ce1f6 L |
9079 | if (opa >= (unsigned int) fc->ncols) |
9080 | reg_prefix = bad_reg; | |
9081 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9082 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
9083 | reg_prefix, regname (opa, 0), | |
9084 | roffs * fc->data_factor); | |
9085 | if (*reg_prefix == '\0') | |
9086 | { | |
9087 | fc->col_type[opa] = DW_CFA_offset; | |
9088 | fc->col_offset[opa] = roffs * fc->data_factor; | |
9089 | } | |
19e6b90e L |
9090 | break; |
9091 | ||
9092 | case DW_CFA_restore: | |
50751e18 | 9093 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
9094 | reg_prefix = bad_reg; |
9095 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9096 | printf (" DW_CFA_restore: %s%s\n", | |
9097 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
9098 | if (*reg_prefix != '\0') |
9099 | break; | |
9100 | ||
9101 | if (opa >= (unsigned int) cie->ncols | |
9102 | || (do_debug_frames_interp | |
9103 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
9104 | { | |
9105 | fc->col_type[opa] = DW_CFA_undefined; | |
9106 | fc->col_offset[opa] = 0; | |
9107 | } | |
9108 | else | |
665ce1f6 L |
9109 | { |
9110 | fc->col_type[opa] = cie->col_type[opa]; | |
9111 | fc->col_offset[opa] = cie->col_offset[opa]; | |
9112 | } | |
19e6b90e L |
9113 | break; |
9114 | ||
9115 | case DW_CFA_set_loc: | |
5897a389 AM |
9116 | vma = get_encoded_value (&start, fc->fde_encoding, section, |
9117 | block_end); | |
19e6b90e L |
9118 | if (do_debug_frames_interp) |
9119 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9120 | else | |
bf5117e3 NC |
9121 | printf (" DW_CFA_set_loc: %s\n", |
9122 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
9123 | fc->pc_begin = vma; |
9124 | break; | |
9125 | ||
9126 | case DW_CFA_advance_loc1: | |
5897a389 | 9127 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, block_end); |
19e6b90e L |
9128 | if (do_debug_frames_interp) |
9129 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9130 | else | |
bf5117e3 NC |
9131 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
9132 | (unsigned long) (ofs * fc->code_factor), | |
9133 | dwarf_vmatoa_1 (NULL, | |
9134 | fc->pc_begin + ofs * fc->code_factor, | |
9135 | fc->ptr_size)); | |
19e6b90e L |
9136 | fc->pc_begin += ofs * fc->code_factor; |
9137 | break; | |
9138 | ||
9139 | case DW_CFA_advance_loc2: | |
6937bb54 | 9140 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
9141 | if (do_debug_frames_interp) |
9142 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9143 | else | |
bf5117e3 NC |
9144 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
9145 | (unsigned long) (ofs * fc->code_factor), | |
9146 | dwarf_vmatoa_1 (NULL, | |
9147 | fc->pc_begin + ofs * fc->code_factor, | |
9148 | fc->ptr_size)); | |
19e6b90e L |
9149 | fc->pc_begin += ofs * fc->code_factor; |
9150 | break; | |
9151 | ||
9152 | case DW_CFA_advance_loc4: | |
6937bb54 | 9153 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
9154 | if (do_debug_frames_interp) |
9155 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9156 | else | |
bf5117e3 NC |
9157 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
9158 | (unsigned long) (ofs * fc->code_factor), | |
9159 | dwarf_vmatoa_1 (NULL, | |
9160 | fc->pc_begin + ofs * fc->code_factor, | |
9161 | fc->ptr_size)); | |
19e6b90e L |
9162 | fc->pc_begin += ofs * fc->code_factor; |
9163 | break; | |
9164 | ||
9165 | case DW_CFA_offset_extended: | |
5897a389 AM |
9166 | READ_ULEB (reg, start, block_end); |
9167 | READ_ULEB (roffs, start, block_end); | |
665ce1f6 L |
9168 | if (reg >= (unsigned int) fc->ncols) |
9169 | reg_prefix = bad_reg; | |
9170 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9171 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
9172 | reg_prefix, regname (reg, 0), | |
9173 | roffs * fc->data_factor); | |
9174 | if (*reg_prefix == '\0') | |
9175 | { | |
9176 | fc->col_type[reg] = DW_CFA_offset; | |
9177 | fc->col_offset[reg] = roffs * fc->data_factor; | |
9178 | } | |
19e6b90e L |
9179 | break; |
9180 | ||
12eae2d3 | 9181 | case DW_CFA_val_offset: |
5897a389 AM |
9182 | READ_ULEB (reg, start, block_end); |
9183 | READ_ULEB (roffs, start, block_end); | |
665ce1f6 L |
9184 | if (reg >= (unsigned int) fc->ncols) |
9185 | reg_prefix = bad_reg; | |
9186 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9187 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
9188 | reg_prefix, regname (reg, 0), |
9189 | roffs * fc->data_factor); | |
9190 | if (*reg_prefix == '\0') | |
9191 | { | |
9192 | fc->col_type[reg] = DW_CFA_val_offset; | |
9193 | fc->col_offset[reg] = roffs * fc->data_factor; | |
9194 | } | |
12eae2d3 JJ |
9195 | break; |
9196 | ||
19e6b90e | 9197 | case DW_CFA_restore_extended: |
5897a389 | 9198 | READ_ULEB (reg, start, block_end); |
50751e18 | 9199 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
9200 | reg_prefix = bad_reg; |
9201 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9202 | printf (" DW_CFA_restore_extended: %s%s\n", | |
9203 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
9204 | if (*reg_prefix != '\0') |
9205 | break; | |
9206 | ||
9207 | if (reg >= (unsigned int) cie->ncols) | |
9208 | { | |
9209 | fc->col_type[reg] = DW_CFA_undefined; | |
9210 | fc->col_offset[reg] = 0; | |
9211 | } | |
9212 | else | |
665ce1f6 L |
9213 | { |
9214 | fc->col_type[reg] = cie->col_type[reg]; | |
9215 | fc->col_offset[reg] = cie->col_offset[reg]; | |
9216 | } | |
19e6b90e L |
9217 | break; |
9218 | ||
9219 | case DW_CFA_undefined: | |
5897a389 | 9220 | READ_ULEB (reg, start, block_end); |
665ce1f6 L |
9221 | if (reg >= (unsigned int) fc->ncols) |
9222 | reg_prefix = bad_reg; | |
9223 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9224 | printf (" DW_CFA_undefined: %s%s\n", | |
9225 | reg_prefix, regname (reg, 0)); | |
9226 | if (*reg_prefix == '\0') | |
9227 | { | |
9228 | fc->col_type[reg] = DW_CFA_undefined; | |
9229 | fc->col_offset[reg] = 0; | |
9230 | } | |
19e6b90e L |
9231 | break; |
9232 | ||
9233 | case DW_CFA_same_value: | |
5897a389 | 9234 | READ_ULEB (reg, start, block_end); |
665ce1f6 L |
9235 | if (reg >= (unsigned int) fc->ncols) |
9236 | reg_prefix = bad_reg; | |
9237 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9238 | printf (" DW_CFA_same_value: %s%s\n", | |
9239 | reg_prefix, regname (reg, 0)); | |
9240 | if (*reg_prefix == '\0') | |
9241 | { | |
9242 | fc->col_type[reg] = DW_CFA_same_value; | |
9243 | fc->col_offset[reg] = 0; | |
9244 | } | |
19e6b90e L |
9245 | break; |
9246 | ||
9247 | case DW_CFA_register: | |
5897a389 AM |
9248 | READ_ULEB (reg, start, block_end); |
9249 | READ_ULEB (roffs, start, block_end); | |
665ce1f6 L |
9250 | if (reg >= (unsigned int) fc->ncols) |
9251 | reg_prefix = bad_reg; | |
9252 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 9253 | { |
665ce1f6 L |
9254 | printf (" DW_CFA_register: %s%s in ", |
9255 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
9256 | puts (regname (roffs, 0)); |
9257 | } | |
665ce1f6 L |
9258 | if (*reg_prefix == '\0') |
9259 | { | |
9260 | fc->col_type[reg] = DW_CFA_register; | |
9261 | fc->col_offset[reg] = roffs; | |
9262 | } | |
19e6b90e L |
9263 | break; |
9264 | ||
9265 | case DW_CFA_remember_state: | |
9266 | if (! do_debug_frames_interp) | |
9267 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 9268 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 9269 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
9270 | rs->cfa_reg = fc->cfa_reg; |
9271 | rs->ra = fc->ra; | |
9272 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 9273 | rs->ncols = fc->ncols; |
3f5e193b | 9274 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 9275 | sizeof (* rs->col_type)); |
d71ad7fc RC |
9276 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
9277 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
9278 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
9279 | rs->next = remembered_state; |
9280 | remembered_state = rs; | |
9281 | break; | |
9282 | ||
9283 | case DW_CFA_restore_state: | |
9284 | if (! do_debug_frames_interp) | |
9285 | printf (" DW_CFA_restore_state\n"); | |
9286 | rs = remembered_state; | |
9287 | if (rs) | |
9288 | { | |
9289 | remembered_state = rs->next; | |
d71ad7fc RC |
9290 | fc->cfa_offset = rs->cfa_offset; |
9291 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
9292 | fc->ra = rs->ra; |
9293 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
9294 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
9295 | { | |
1306a742 | 9296 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
9297 | fc->ncols = 0; |
9298 | break; | |
9299 | } | |
d71ad7fc | 9300 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 9301 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 9302 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
9303 | free (rs->col_type); |
9304 | free (rs->col_offset); | |
9305 | free (rs); | |
9306 | } | |
9307 | else if (do_debug_frames_interp) | |
9308 | printf ("Mismatched DW_CFA_restore_state\n"); | |
9309 | break; | |
9310 | ||
9311 | case DW_CFA_def_cfa: | |
5897a389 AM |
9312 | READ_ULEB (fc->cfa_reg, start, block_end); |
9313 | READ_ULEB (fc->cfa_offset, start, block_end); | |
19e6b90e L |
9314 | fc->cfa_exp = 0; |
9315 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9316 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 9317 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9318 | break; |
9319 | ||
9320 | case DW_CFA_def_cfa_register: | |
5897a389 | 9321 | READ_ULEB (fc->cfa_reg, start, block_end); |
19e6b90e L |
9322 | fc->cfa_exp = 0; |
9323 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
9324 | printf (" DW_CFA_def_cfa_register: %s\n", |
9325 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
9326 | break; |
9327 | ||
9328 | case DW_CFA_def_cfa_offset: | |
5897a389 | 9329 | READ_ULEB (fc->cfa_offset, start, block_end); |
19e6b90e | 9330 | if (! do_debug_frames_interp) |
c8071705 | 9331 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9332 | break; |
9333 | ||
9334 | case DW_CFA_nop: | |
9335 | if (! do_debug_frames_interp) | |
9336 | printf (" DW_CFA_nop\n"); | |
9337 | break; | |
9338 | ||
9339 | case DW_CFA_def_cfa_expression: | |
5897a389 AM |
9340 | READ_ULEB (ul, start, block_end); |
9341 | if (ul > (size_t) (block_end - start)) | |
6937bb54 | 9342 | { |
a1165289 | 9343 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9344 | break; |
9345 | } | |
19e6b90e L |
9346 | if (! do_debug_frames_interp) |
9347 | { | |
9348 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
9349 | decode_location_expression (start, eh_addr_size, 0, -1, |
9350 | ul, 0, section); | |
19e6b90e L |
9351 | printf (")\n"); |
9352 | } | |
9353 | fc->cfa_exp = 1; | |
9354 | start += ul; | |
9355 | break; | |
9356 | ||
9357 | case DW_CFA_expression: | |
5897a389 AM |
9358 | READ_ULEB (reg, start, block_end); |
9359 | READ_ULEB (ul, start, block_end); | |
665ce1f6 L |
9360 | if (reg >= (unsigned int) fc->ncols) |
9361 | reg_prefix = bad_reg; | |
6937bb54 | 9362 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 9363 | /* PR 17512: file: 98c02eb4. */ |
5897a389 | 9364 | if (ul > (size_t) (block_end - start)) |
6937bb54 | 9365 | { |
a1165289 | 9366 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9367 | break; |
9368 | } | |
665ce1f6 | 9369 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 9370 | { |
665ce1f6 L |
9371 | printf (" DW_CFA_expression: %s%s (", |
9372 | reg_prefix, regname (reg, 0)); | |
b7807392 | 9373 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 9374 | ul, 0, section); |
19e6b90e L |
9375 | printf (")\n"); |
9376 | } | |
665ce1f6 L |
9377 | if (*reg_prefix == '\0') |
9378 | fc->col_type[reg] = DW_CFA_expression; | |
5897a389 | 9379 | start += ul; |
19e6b90e L |
9380 | break; |
9381 | ||
12eae2d3 | 9382 | case DW_CFA_val_expression: |
5897a389 AM |
9383 | READ_ULEB (reg, start, block_end); |
9384 | READ_ULEB (ul, start, block_end); | |
665ce1f6 L |
9385 | if (reg >= (unsigned int) fc->ncols) |
9386 | reg_prefix = bad_reg; | |
5897a389 | 9387 | if (ul > (size_t) (block_end - start)) |
6937bb54 | 9388 | { |
a1165289 | 9389 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
9390 | break; |
9391 | } | |
665ce1f6 | 9392 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 9393 | { |
665ce1f6 L |
9394 | printf (" DW_CFA_val_expression: %s%s (", |
9395 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
9396 | decode_location_expression (start, eh_addr_size, 0, -1, |
9397 | ul, 0, section); | |
12eae2d3 JJ |
9398 | printf (")\n"); |
9399 | } | |
665ce1f6 L |
9400 | if (*reg_prefix == '\0') |
9401 | fc->col_type[reg] = DW_CFA_val_expression; | |
5897a389 | 9402 | start += ul; |
12eae2d3 JJ |
9403 | break; |
9404 | ||
19e6b90e | 9405 | case DW_CFA_offset_extended_sf: |
5897a389 AM |
9406 | READ_ULEB (reg, start, block_end); |
9407 | READ_SLEB (l, start, block_end); | |
665ce1f6 L |
9408 | if (frame_need_space (fc, reg) < 0) |
9409 | reg_prefix = bad_reg; | |
9410 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9411 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
9412 | reg_prefix, regname (reg, 0), | |
c8071705 | 9413 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9414 | if (*reg_prefix == '\0') |
9415 | { | |
9416 | fc->col_type[reg] = DW_CFA_offset; | |
9417 | fc->col_offset[reg] = l * fc->data_factor; | |
9418 | } | |
19e6b90e L |
9419 | break; |
9420 | ||
12eae2d3 | 9421 | case DW_CFA_val_offset_sf: |
5897a389 AM |
9422 | READ_ULEB (reg, start, block_end); |
9423 | READ_SLEB (l, start, block_end); | |
665ce1f6 L |
9424 | if (frame_need_space (fc, reg) < 0) |
9425 | reg_prefix = bad_reg; | |
9426 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9427 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 9428 | reg_prefix, regname (reg, 0), |
c8071705 | 9429 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9430 | if (*reg_prefix == '\0') |
9431 | { | |
9432 | fc->col_type[reg] = DW_CFA_val_offset; | |
9433 | fc->col_offset[reg] = l * fc->data_factor; | |
9434 | } | |
12eae2d3 JJ |
9435 | break; |
9436 | ||
19e6b90e | 9437 | case DW_CFA_def_cfa_sf: |
5897a389 | 9438 | READ_ULEB (fc->cfa_reg, start, block_end); |
280c57ff RH |
9439 | READ_SLEB (l, start, block_end); |
9440 | l *= fc->data_factor; | |
9441 | fc->cfa_offset = l; | |
19e6b90e L |
9442 | fc->cfa_exp = 0; |
9443 | if (! do_debug_frames_interp) | |
280c57ff RH |
9444 | printf (" DW_CFA_def_cfa_sf: %s ofs %ld\n", |
9445 | regname (fc->cfa_reg, 0), (long) l); | |
19e6b90e L |
9446 | break; |
9447 | ||
9448 | case DW_CFA_def_cfa_offset_sf: | |
280c57ff RH |
9449 | READ_SLEB (l, start, block_end); |
9450 | l *= fc->data_factor; | |
9451 | fc->cfa_offset = l; | |
19e6b90e | 9452 | if (! do_debug_frames_interp) |
280c57ff | 9453 | printf (" DW_CFA_def_cfa_offset_sf: %ld\n", (long) l); |
19e6b90e L |
9454 | break; |
9455 | ||
9456 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 9457 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
9458 | if (do_debug_frames_interp) |
9459 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9460 | else | |
bf5117e3 NC |
9461 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
9462 | (unsigned long) (ofs * fc->code_factor), | |
9463 | dwarf_vmatoa_1 (NULL, | |
9464 | fc->pc_begin + ofs * fc->code_factor, | |
9465 | fc->ptr_size)); | |
19e6b90e L |
9466 | fc->pc_begin += ofs * fc->code_factor; |
9467 | break; | |
9468 | ||
9469 | case DW_CFA_GNU_window_save: | |
9470 | if (! do_debug_frames_interp) | |
9471 | printf (" DW_CFA_GNU_window_save\n"); | |
9472 | break; | |
9473 | ||
9474 | case DW_CFA_GNU_args_size: | |
5897a389 | 9475 | READ_ULEB (ul, start, block_end); |
19e6b90e L |
9476 | if (! do_debug_frames_interp) |
9477 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
9478 | break; | |
9479 | ||
9480 | case DW_CFA_GNU_negative_offset_extended: | |
5897a389 AM |
9481 | READ_ULEB (reg, start, block_end); |
9482 | READ_SLEB (l, start, block_end); | |
7f2c8a1d | 9483 | l = - l; |
665ce1f6 L |
9484 | if (frame_need_space (fc, reg) < 0) |
9485 | reg_prefix = bad_reg; | |
9486 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9487 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
9488 | reg_prefix, regname (reg, 0), | |
c8071705 | 9489 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9490 | if (*reg_prefix == '\0') |
9491 | { | |
9492 | fc->col_type[reg] = DW_CFA_offset; | |
9493 | fc->col_offset[reg] = l * fc->data_factor; | |
9494 | } | |
19e6b90e L |
9495 | break; |
9496 | ||
9497 | default: | |
53b8873b NC |
9498 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
9499 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
9500 | else | |
f41e4712 | 9501 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
9502 | start = block_end; |
9503 | } | |
9504 | } | |
9505 | ||
5b6312fd NC |
9506 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
9507 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
9508 | frame_display_row (fc, &need_col_headers, &max_regs); |
9509 | ||
a788aedd AM |
9510 | if (fde_fc.col_type != NULL) |
9511 | { | |
9512 | free (fde_fc.col_type); | |
9513 | fde_fc.col_type = NULL; | |
9514 | } | |
9515 | if (fde_fc.col_offset != NULL) | |
9516 | { | |
9517 | free (fde_fc.col_offset); | |
9518 | fde_fc.col_offset = NULL; | |
9519 | } | |
9520 | ||
19e6b90e | 9521 | start = block_end; |
604282a7 | 9522 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
9523 | } |
9524 | ||
9525 | printf ("\n"); | |
9526 | ||
3391569f NC |
9527 | while (remembered_state != NULL) |
9528 | { | |
9529 | rs = remembered_state; | |
9530 | remembered_state = rs->next; | |
9531 | free (rs->col_type); | |
9532 | free (rs->col_offset); | |
9533 | rs->next = NULL; /* Paranoia. */ | |
9534 | free (rs); | |
9535 | } | |
9536 | ||
9537 | while (chunks != NULL) | |
9538 | { | |
9539 | rs = chunks; | |
9540 | chunks = rs->next; | |
9541 | free (rs->col_type); | |
9542 | free (rs->col_offset); | |
9543 | rs->next = NULL; /* Paranoia. */ | |
9544 | free (rs); | |
9545 | } | |
9546 | ||
9547 | while (forward_refs != NULL) | |
9548 | { | |
9549 | rs = forward_refs; | |
9550 | forward_refs = rs->next; | |
9551 | free (rs->col_type); | |
9552 | free (rs->col_offset); | |
9553 | rs->next = NULL; /* Paranoia. */ | |
9554 | free (rs); | |
9555 | } | |
9556 | ||
19e6b90e L |
9557 | return 1; |
9558 | } | |
9559 | ||
9560 | #undef GET | |
19e6b90e | 9561 | |
61364358 JK |
9562 | static int |
9563 | display_debug_names (struct dwarf_section *section, void *file) | |
9564 | { | |
9565 | unsigned char *hdrptr = section->start; | |
9566 | dwarf_vma unit_length; | |
9567 | unsigned char *unit_start; | |
9568 | const unsigned char *const section_end = section->start + section->size; | |
9569 | unsigned char *unit_end; | |
9570 | ||
015dc7e1 | 9571 | introduce (section, false); |
61364358 | 9572 | |
dda8d76d | 9573 | load_debug_section_with_follow (str, file); |
61364358 JK |
9574 | |
9575 | for (; hdrptr < section_end; hdrptr = unit_end) | |
9576 | { | |
9577 | unsigned int offset_size; | |
9578 | uint16_t dwarf_version, padding; | |
9579 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
d7870f63 | 9580 | uint64_t bucket_count, name_count, abbrev_table_size; |
61364358 JK |
9581 | uint32_t augmentation_string_size; |
9582 | unsigned int i; | |
015dc7e1 | 9583 | bool augmentation_printable; |
48467cb9 | 9584 | const char *augmentation_string; |
d7870f63 | 9585 | size_t total; |
61364358 JK |
9586 | |
9587 | unit_start = hdrptr; | |
9588 | ||
9589 | /* Get and check the length of the block. */ | |
9590 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
9591 | ||
9592 | if (unit_length == 0xffffffff) | |
9593 | { | |
9594 | /* This section is 64-bit DWARF. */ | |
9595 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
9596 | offset_size = 8; | |
9597 | } | |
9598 | else | |
9599 | offset_size = 4; | |
61364358 | 9600 | |
d7870f63 AM |
9601 | if (unit_length > (size_t) (section_end - hdrptr) |
9602 | || unit_length < 2 + 2 + 4 * 7) | |
61364358 | 9603 | { |
d7870f63 | 9604 | too_short: |
e98fdf1a AM |
9605 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
9606 | section->name, | |
9607 | (unsigned long) (unit_start - section->start), | |
9608 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
9609 | return 0; |
9610 | } | |
d7870f63 | 9611 | unit_end = hdrptr + unit_length; |
61364358 JK |
9612 | |
9613 | /* Get and check the version number. */ | |
9614 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
9615 | printf (_("Version %ld\n"), (long) dwarf_version); | |
9616 | ||
9617 | /* Prior versions did not exist, and future versions may not be | |
9618 | backwards compatible. */ | |
9619 | if (dwarf_version != 5) | |
9620 | { | |
9621 | warn (_("Only DWARF version 5 .debug_names " | |
9622 | "is currently supported.\n")); | |
9623 | return 0; | |
9624 | } | |
9625 | ||
9626 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
9627 | if (padding != 0) | |
9628 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
9629 | padding); | |
9630 | ||
9631 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
9632 | if (comp_unit_count == 0) | |
9633 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
9634 | ||
9635 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
9636 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
9637 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
9638 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
9639 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
9640 | ||
9641 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
9642 | if (augmentation_string_size % 4 != 0) | |
9643 | { | |
9644 | warn (_("Augmentation string length %u must be rounded up " | |
9645 | "to a multiple of 4 in .debug_names.\n"), | |
9646 | augmentation_string_size); | |
9647 | augmentation_string_size += (-augmentation_string_size) & 3; | |
9648 | } | |
d7870f63 AM |
9649 | if (augmentation_string_size > (size_t) (unit_end - hdrptr)) |
9650 | goto too_short; | |
48467cb9 | 9651 | |
61364358 | 9652 | printf (_("Augmentation string:")); |
48467cb9 | 9653 | |
015dc7e1 | 9654 | augmentation_printable = true; |
48467cb9 TV |
9655 | augmentation_string = (const char *) hdrptr; |
9656 | ||
61364358 JK |
9657 | for (i = 0; i < augmentation_string_size; i++) |
9658 | { | |
9659 | unsigned char uc; | |
9660 | ||
9661 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
9662 | printf (" %02x", uc); | |
48467cb9 TV |
9663 | |
9664 | if (uc != 0 && !ISPRINT (uc)) | |
015dc7e1 | 9665 | augmentation_printable = false; |
48467cb9 TV |
9666 | } |
9667 | ||
9668 | if (augmentation_printable) | |
9669 | { | |
9670 | printf (" (\""); | |
9671 | for (i = 0; | |
9672 | i < augmentation_string_size && augmentation_string[i]; | |
9673 | ++i) | |
9674 | putchar (augmentation_string[i]); | |
9675 | printf ("\")"); | |
61364358 | 9676 | } |
61364358 JK |
9677 | putchar ('\n'); |
9678 | ||
9679 | printf (_("CU table:\n")); | |
d7870f63 AM |
9680 | if (_mul_overflow (comp_unit_count, offset_size, &total) |
9681 | || total > (size_t) (unit_end - hdrptr)) | |
9682 | goto too_short; | |
61364358 JK |
9683 | for (i = 0; i < comp_unit_count; i++) |
9684 | { | |
9685 | uint64_t cu_offset; | |
9686 | ||
9687 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
9688 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
9689 | } | |
9690 | putchar ('\n'); | |
9691 | ||
9692 | printf (_("TU table:\n")); | |
d7870f63 AM |
9693 | if (_mul_overflow (local_type_unit_count, offset_size, &total) |
9694 | || total > (size_t) (unit_end - hdrptr)) | |
9695 | goto too_short; | |
61364358 JK |
9696 | for (i = 0; i < local_type_unit_count; i++) |
9697 | { | |
9698 | uint64_t tu_offset; | |
9699 | ||
9700 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
9701 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
9702 | } | |
9703 | putchar ('\n'); | |
9704 | ||
9705 | printf (_("Foreign TU table:\n")); | |
d7870f63 AM |
9706 | if (_mul_overflow (foreign_type_unit_count, 8, &total) |
9707 | || total > (size_t) (unit_end - hdrptr)) | |
9708 | goto too_short; | |
61364358 JK |
9709 | for (i = 0; i < foreign_type_unit_count; i++) |
9710 | { | |
9711 | uint64_t signature; | |
9712 | ||
9713 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
9714 | printf (_("[%3u] "), i); | |
9715 | print_dwarf_vma (signature, 8); | |
9716 | putchar ('\n'); | |
9717 | } | |
9718 | putchar ('\n'); | |
9719 | ||
d7870f63 AM |
9720 | uint64_t xtra = (bucket_count * sizeof (uint32_t) |
9721 | + name_count * (sizeof (uint32_t) + 2 * offset_size) | |
9722 | + abbrev_table_size); | |
9723 | if (xtra > (size_t) (unit_end - hdrptr)) | |
9724 | { | |
9725 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
9726 | "for unit 0x%lx in the debug_names\n"), | |
9727 | (long) xtra, | |
9728 | (long) (unit_end - unit_start), | |
9729 | (long) (unit_start - section->start)); | |
9730 | return 0; | |
9731 | } | |
61364358 JK |
9732 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; |
9733 | hdrptr += bucket_count * sizeof (uint32_t); | |
9734 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
9735 | hdrptr += name_count * sizeof (uint32_t); | |
9736 | unsigned char *const name_table_string_offsets = hdrptr; | |
9737 | hdrptr += name_count * offset_size; | |
9738 | unsigned char *const name_table_entry_offsets = hdrptr; | |
9739 | hdrptr += name_count * offset_size; | |
9740 | unsigned char *const abbrev_table = hdrptr; | |
9741 | hdrptr += abbrev_table_size; | |
9742 | const unsigned char *const abbrev_table_end = hdrptr; | |
9743 | unsigned char *const entry_pool = hdrptr; | |
61364358 JK |
9744 | |
9745 | size_t buckets_filled = 0; | |
9746 | size_t bucketi; | |
9747 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
9748 | { | |
9749 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
9750 | ||
9751 | if (bucket != 0) | |
9752 | ++buckets_filled; | |
9753 | } | |
d3a49aa8 AM |
9754 | printf (ngettext ("Used %zu of %lu bucket.\n", |
9755 | "Used %zu of %lu buckets.\n", | |
9756 | bucket_count), | |
9757 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 9758 | |
0a79bef4 | 9759 | uint32_t hash_prev = 0; |
61364358 JK |
9760 | size_t hash_clash_count = 0; |
9761 | size_t longest_clash = 0; | |
9762 | size_t this_length = 0; | |
9763 | size_t hashi; | |
9764 | for (hashi = 0; hashi < name_count; hashi++) | |
9765 | { | |
9766 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
9767 | ||
9768 | if (hashi > 0) | |
9769 | { | |
9770 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
9771 | { | |
9772 | ++hash_clash_count; | |
9773 | ++this_length; | |
9774 | longest_clash = MAX (longest_clash, this_length); | |
9775 | } | |
9776 | else | |
9777 | this_length = 0; | |
9778 | } | |
9779 | hash_prev = hash_this; | |
9780 | } | |
9781 | printf (_("Out of %lu items there are %zu bucket clashes" | |
9782 | " (longest of %zu entries).\n"), | |
9783 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
9784 | assert (name_count == buckets_filled + hash_clash_count); | |
9785 | ||
9786 | struct abbrev_lookup_entry | |
9787 | { | |
9788 | dwarf_vma abbrev_tag; | |
9789 | unsigned char *abbrev_lookup_ptr; | |
9790 | }; | |
9791 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
9792 | size_t abbrev_lookup_used = 0; | |
9793 | size_t abbrev_lookup_allocated = 0; | |
9794 | ||
9795 | unsigned char *abbrevptr = abbrev_table; | |
9796 | for (;;) | |
9797 | { | |
cd30bcef AM |
9798 | dwarf_vma abbrev_tag; |
9799 | ||
9800 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
9801 | if (abbrev_tag == 0) |
9802 | break; | |
9803 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
9804 | { | |
9805 | abbrev_lookup_allocated = MAX (0x100, | |
9806 | abbrev_lookup_allocated * 2); | |
9807 | abbrev_lookup = xrealloc (abbrev_lookup, | |
9808 | (abbrev_lookup_allocated | |
9809 | * sizeof (*abbrev_lookup))); | |
9810 | } | |
9811 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
9812 | struct abbrev_lookup_entry *entry; | |
9813 | for (entry = abbrev_lookup; | |
9814 | entry < abbrev_lookup + abbrev_lookup_used; | |
9815 | entry++) | |
9816 | if (entry->abbrev_tag == abbrev_tag) | |
9817 | { | |
9818 | warn (_("Duplicate abbreviation tag %lu " | |
9819 | "in unit 0x%lx in the debug_names\n"), | |
9820 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
9821 | break; | |
9822 | } | |
9823 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
9824 | entry->abbrev_tag = abbrev_tag; | |
9825 | entry->abbrev_lookup_ptr = abbrevptr; | |
9826 | ||
9827 | /* Skip DWARF tag. */ | |
cd30bcef | 9828 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
9829 | for (;;) |
9830 | { | |
cd30bcef AM |
9831 | dwarf_vma xindex, form; |
9832 | ||
9833 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9834 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9835 | if (xindex == 0 && form == 0) |
61364358 JK |
9836 | break; |
9837 | } | |
9838 | } | |
9839 | ||
9840 | printf (_("\nSymbol table:\n")); | |
9841 | uint32_t namei; | |
9842 | for (namei = 0; namei < name_count; ++namei) | |
9843 | { | |
9844 | uint64_t string_offset, entry_offset; | |
6d1ad6f7 | 9845 | unsigned char *p; |
61364358 | 9846 | |
6d1ad6f7 AM |
9847 | p = name_table_string_offsets + namei * offset_size; |
9848 | SAFE_BYTE_GET (string_offset, p, offset_size, unit_end); | |
9849 | p = name_table_entry_offsets + namei * offset_size; | |
9850 | SAFE_BYTE_GET (entry_offset, p, offset_size, unit_end); | |
61364358 JK |
9851 | |
9852 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9853 | fetch_indirect_string (string_offset)); | |
9854 | ||
9855 | unsigned char *entryptr = entry_pool + entry_offset; | |
9856 | ||
279edac5 AM |
9857 | /* We need to scan first whether there is a single or multiple |
9858 | entries. TAGNO is -2 for the first entry, it is -1 for the | |
9859 | initial tag read of the second entry, then it becomes 0 for the | |
9860 | first entry for real printing etc. */ | |
61364358 JK |
9861 | int tagno = -2; |
9862 | /* Initialize it due to a false compiler warning. */ | |
9863 | dwarf_vma second_abbrev_tag = -1; | |
9864 | for (;;) | |
9865 | { | |
cd30bcef AM |
9866 | dwarf_vma abbrev_tag; |
9867 | dwarf_vma dwarf_tag; | |
9868 | const struct abbrev_lookup_entry *entry; | |
9869 | ||
9870 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
9871 | if (tagno == -1) |
9872 | { | |
9873 | second_abbrev_tag = abbrev_tag; | |
9874 | tagno = 0; | |
9875 | entryptr = entry_pool + entry_offset; | |
9876 | continue; | |
9877 | } | |
9878 | if (abbrev_tag == 0) | |
9879 | break; | |
9880 | if (tagno >= 0) | |
9881 | printf ("%s<%lu>", | |
9882 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9883 | (unsigned long) abbrev_tag); | |
9884 | ||
61364358 JK |
9885 | for (entry = abbrev_lookup; |
9886 | entry < abbrev_lookup + abbrev_lookup_used; | |
9887 | entry++) | |
9888 | if (entry->abbrev_tag == abbrev_tag) | |
9889 | break; | |
9890 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9891 | { | |
9892 | warn (_("Undefined abbreviation tag %lu " | |
9893 | "in unit 0x%lx in the debug_names\n"), | |
9894 | (long) abbrev_tag, | |
9895 | (long) (unit_start - section->start)); | |
9896 | break; | |
9897 | } | |
9898 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 9899 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
9900 | if (tagno >= 0) |
9901 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9902 | for (;;) | |
9903 | { | |
cd30bcef AM |
9904 | dwarf_vma xindex, form; |
9905 | ||
9906 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9907 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9908 | if (xindex == 0 && form == 0) |
61364358 JK |
9909 | break; |
9910 | ||
9911 | if (tagno >= 0) | |
1d827a72 | 9912 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9913 | entryptr = read_and_display_attr_value (0, form, 0, |
9914 | unit_start, entryptr, unit_end, | |
9915 | 0, 0, offset_size, | |
61364358 JK |
9916 | dwarf_version, NULL, |
9917 | (tagno < 0), NULL, | |
ec1b0fbb | 9918 | NULL, '=', -1); |
61364358 JK |
9919 | } |
9920 | ++tagno; | |
9921 | } | |
9922 | if (tagno <= 0) | |
9923 | printf (_(" <no entries>")); | |
9924 | putchar ('\n'); | |
9925 | } | |
9926 | ||
9927 | free (abbrev_lookup); | |
9928 | } | |
9929 | ||
9930 | return 1; | |
9931 | } | |
9932 | ||
dda8d76d | 9933 | static int |
d85bf2ba NC |
9934 | display_debug_links (struct dwarf_section * section, |
9935 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
9936 | { |
9937 | const unsigned char * filename; | |
9938 | unsigned int filelen; | |
9939 | ||
015dc7e1 | 9940 | introduce (section, false); |
dda8d76d NC |
9941 | |
9942 | /* The .gnu_debuglink section is formatted as: | |
9943 | (c-string) Filename. | |
9944 | (padding) If needed to reach a 4 byte boundary. | |
9945 | (uint32_t) CRC32 value. | |
9946 | ||
9947 | The .gun_debugaltlink section is formatted as: | |
9948 | (c-string) Filename. | |
9949 | (binary) Build-ID. */ | |
521d4b19 | 9950 | |
dda8d76d NC |
9951 | filename = section->start; |
9952 | filelen = strnlen ((const char *) filename, section->size); | |
9953 | if (filelen == section->size) | |
9954 | { | |
9955 | warn (_("The debuglink filename is corrupt/missing\n")); | |
9956 | return 0; | |
9957 | } | |
9958 | ||
9959 | printf (_(" Separate debug info file: %s\n"), filename); | |
9960 | ||
24d127aa | 9961 | if (startswith (section->name, ".gnu_debuglink")) |
dda8d76d NC |
9962 | { |
9963 | unsigned int crc32; | |
9964 | unsigned int crc_offset; | |
9965 | ||
9966 | crc_offset = filelen + 1; | |
9967 | crc_offset = (crc_offset + 3) & ~3; | |
9968 | if (crc_offset + 4 > section->size) | |
9969 | { | |
9970 | warn (_("CRC offset missing/truncated\n")); | |
9971 | return 0; | |
9972 | } | |
9973 | ||
9974 | crc32 = byte_get (filename + crc_offset, 4); | |
9975 | ||
9976 | printf (_(" CRC value: %#x\n"), crc32); | |
9977 | ||
9978 | if (crc_offset + 4 < section->size) | |
9979 | { | |
9980 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
9981 | (long)(section->size - (crc_offset + 4))); | |
9982 | return 0; | |
9983 | } | |
9984 | } | |
24d127aa | 9985 | else /* startswith (section->name, ".gnu_debugaltlink") */ |
dda8d76d NC |
9986 | { |
9987 | const unsigned char * build_id = section->start + filelen + 1; | |
9988 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
9989 | bfd_size_type printed; | |
9990 | ||
9991 | /* FIXME: Should we support smaller build-id notes ? */ | |
9992 | if (build_id_len < 0x14) | |
9993 | { | |
9994 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
9995 | return 0; | |
9996 | } | |
9997 | ||
9998 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 9999 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
10000 | putchar ('\n'); |
10001 | } | |
10002 | ||
10003 | putchar ('\n'); | |
10004 | return 1; | |
10005 | } | |
10006 | ||
5bbdf3d5 DE |
10007 | static int |
10008 | display_gdb_index (struct dwarf_section *section, | |
10009 | void *file ATTRIBUTE_UNUSED) | |
10010 | { | |
10011 | unsigned char *start = section->start; | |
10012 | uint32_t version; | |
10013 | uint32_t cu_list_offset, tu_list_offset; | |
10014 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
10015 | unsigned int cu_list_elements, tu_list_elements; | |
10016 | unsigned int address_table_size, symbol_table_slots; | |
10017 | unsigned char *cu_list, *tu_list; | |
10018 | unsigned char *address_table, *symbol_table, *constant_pool; | |
10019 | unsigned int i; | |
10020 | ||
10021 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
10022 | ||
015dc7e1 | 10023 | introduce (section, false); |
5bbdf3d5 DE |
10024 | |
10025 | if (section->size < 6 * sizeof (uint32_t)) | |
10026 | { | |
10027 | warn (_("Truncated header in the %s section.\n"), section->name); | |
10028 | return 0; | |
10029 | } | |
10030 | ||
10031 | version = byte_get_little_endian (start, 4); | |
da88a764 | 10032 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
10033 | |
10034 | /* Prior versions are obsolete, and future versions may not be | |
10035 | backwards compatible. */ | |
aa170720 | 10036 | if (version < 3 || version > 8) |
5bbdf3d5 | 10037 | { |
da88a764 | 10038 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
10039 | return 0; |
10040 | } | |
8d6eee87 TT |
10041 | if (version < 4) |
10042 | warn (_("The address table data in version 3 may be wrong.\n")); | |
10043 | if (version < 5) | |
10044 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
10045 | if (version < 6) | |
10046 | warn (_("Version 5 does not include inlined functions.\n")); | |
10047 | if (version < 7) | |
10048 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
10049 | /* Version 7 indices generated by Gold have bad type unit references, |
10050 | PR binutils/15021. But we don't know if the index was generated by | |
10051 | Gold or not, so to avoid worrying users with gdb-generated indices | |
10052 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
10053 | |
10054 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
10055 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
10056 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
10057 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
10058 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
10059 | ||
10060 | if (cu_list_offset > section->size | |
10061 | || tu_list_offset > section->size | |
10062 | || address_table_offset > section->size | |
10063 | || symbol_table_offset > section->size | |
10064 | || constant_pool_offset > section->size) | |
10065 | { | |
10066 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
10067 | return 0; | |
10068 | } | |
10069 | ||
53774b7e NC |
10070 | /* PR 17531: file: 418d0a8a. */ |
10071 | if (tu_list_offset < cu_list_offset) | |
10072 | { | |
10073 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
10074 | tu_list_offset, cu_list_offset); | |
10075 | return 0; | |
10076 | } | |
10077 | ||
5bbdf3d5 | 10078 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
10079 | |
10080 | if (address_table_offset < tu_list_offset) | |
10081 | { | |
10082 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
10083 | address_table_offset, tu_list_offset); | |
10084 | return 0; | |
10085 | } | |
10086 | ||
5bbdf3d5 | 10087 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
10088 | |
10089 | /* PR 17531: file: 18a47d3d. */ | |
10090 | if (symbol_table_offset < address_table_offset) | |
10091 | { | |
13bace4a | 10092 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
10093 | symbol_table_offset, address_table_offset); |
10094 | return 0; | |
10095 | } | |
10096 | ||
5bbdf3d5 | 10097 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
10098 | |
10099 | if (constant_pool_offset < symbol_table_offset) | |
10100 | { | |
10101 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
10102 | constant_pool_offset, symbol_table_offset); | |
10103 | return 0; | |
10104 | } | |
10105 | ||
5bbdf3d5 DE |
10106 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
10107 | ||
10108 | cu_list = start + cu_list_offset; | |
10109 | tu_list = start + tu_list_offset; | |
10110 | address_table = start + address_table_offset; | |
10111 | symbol_table = start + symbol_table_offset; | |
10112 | constant_pool = start + constant_pool_offset; | |
10113 | ||
bb19bf12 | 10114 | if (address_table_offset + address_table_size > section->size) |
acff9664 | 10115 | { |
1306a742 | 10116 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
10117 | return 0; |
10118 | } | |
b4eb7656 | 10119 | |
5bbdf3d5 DE |
10120 | printf (_("\nCU table:\n")); |
10121 | for (i = 0; i < cu_list_elements; i += 2) | |
10122 | { | |
10123 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
10124 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
10125 | ||
10126 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
10127 | (unsigned long) cu_offset, | |
10128 | (unsigned long) (cu_offset + cu_length - 1)); | |
10129 | } | |
10130 | ||
10131 | printf (_("\nTU table:\n")); | |
10132 | for (i = 0; i < tu_list_elements; i += 3) | |
10133 | { | |
10134 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
10135 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
10136 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
10137 | ||
10138 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
10139 | (unsigned long) tu_offset, | |
10140 | (unsigned long) type_offset); | |
10141 | print_dwarf_vma (signature, 8); | |
10142 | printf ("\n"); | |
10143 | } | |
10144 | ||
10145 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
10146 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
10147 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
10148 | { |
10149 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
10150 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
10151 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
10152 | ||
10153 | print_dwarf_vma (low, 8); | |
10154 | print_dwarf_vma (high, 8); | |
da88a764 | 10155 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
10156 | } |
10157 | ||
10158 | printf (_("\nSymbol table:\n")); | |
10159 | for (i = 0; i < symbol_table_slots; ++i) | |
10160 | { | |
10161 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
10162 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
10163 | uint32_t num_cus, cu; | |
10164 | ||
10165 | if (name_offset != 0 | |
10166 | || cu_vector_offset != 0) | |
10167 | { | |
10168 | unsigned int j; | |
10169 | ||
53774b7e | 10170 | /* PR 17531: file: 5b7b07ad. */ |
bb19bf12 | 10171 | if (name_offset >= section->size - constant_pool_offset) |
53774b7e NC |
10172 | { |
10173 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
10174 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
10175 | name_offset, i); | |
10176 | } | |
10177 | else | |
acff9664 NC |
10178 | printf ("[%3u] %.*s:", i, |
10179 | (int) (section->size - (constant_pool_offset + name_offset)), | |
10180 | constant_pool + name_offset); | |
53774b7e | 10181 | |
bb19bf12 AM |
10182 | if (section->size - constant_pool_offset < 4 |
10183 | || cu_vector_offset > section->size - constant_pool_offset - 4) | |
53774b7e NC |
10184 | { |
10185 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
10186 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
10187 | cu_vector_offset, i); | |
10188 | continue; | |
10189 | } | |
57028622 | 10190 | |
bb19bf12 | 10191 | num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4); |
53774b7e | 10192 | |
bb19bf12 AM |
10193 | if ((uint64_t) num_cus * 4 > section->size - (constant_pool_offset |
10194 | + cu_vector_offset + 4)) | |
53774b7e NC |
10195 | { |
10196 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 10197 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
10198 | num_cus, i); |
10199 | continue; | |
10200 | } | |
10201 | ||
8d6eee87 TT |
10202 | if (num_cus > 1) |
10203 | printf ("\n"); | |
f3853b34 | 10204 | |
5bbdf3d5 DE |
10205 | for (j = 0; j < num_cus; ++j) |
10206 | { | |
7c1cef97 | 10207 | int is_static; |
8d6eee87 TT |
10208 | gdb_index_symbol_kind kind; |
10209 | ||
5bbdf3d5 | 10210 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 10211 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
10212 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
10213 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 10214 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 10215 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
10216 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
10217 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 10218 | else |
8d6eee87 TT |
10219 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
10220 | ||
459d52c8 DE |
10221 | printf (" [%s, %s]", |
10222 | is_static ? _("static") : _("global"), | |
10223 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
10224 | if (num_cus > 1) |
10225 | printf ("\n"); | |
5bbdf3d5 | 10226 | } |
8d6eee87 TT |
10227 | if (num_cus <= 1) |
10228 | printf ("\n"); | |
5bbdf3d5 DE |
10229 | } |
10230 | } | |
10231 | ||
10232 | return 1; | |
10233 | } | |
10234 | ||
657d0d47 CC |
10235 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
10236 | ||
10237 | static void | |
10238 | prealloc_cu_tu_list (unsigned int nshndx) | |
10239 | { | |
10240 | if (shndx_pool == NULL) | |
10241 | { | |
10242 | shndx_pool_size = nshndx; | |
10243 | shndx_pool_used = 0; | |
10244 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
10245 | sizeof (unsigned int)); | |
10246 | } | |
10247 | else | |
10248 | { | |
10249 | shndx_pool_size = shndx_pool_used + nshndx; | |
10250 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
10251 | sizeof (unsigned int)); | |
10252 | } | |
10253 | } | |
10254 | ||
10255 | static void | |
10256 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
10257 | { | |
10258 | if (shndx_pool_used >= shndx_pool_size) | |
10259 | { | |
10260 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10261 | return; | |
10262 | } | |
10263 | shndx_pool [shndx_pool_used++] = shndx; | |
10264 | } | |
10265 | ||
10266 | static void | |
10267 | end_cu_tu_entry (void) | |
10268 | { | |
10269 | if (shndx_pool_used >= shndx_pool_size) | |
10270 | { | |
10271 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10272 | return; | |
10273 | } | |
10274 | shndx_pool [shndx_pool_used++] = 0; | |
10275 | } | |
10276 | ||
341f9135 CC |
10277 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
10278 | ||
10279 | static const char * | |
10280 | get_DW_SECT_short_name (unsigned int dw_sect) | |
10281 | { | |
10282 | static char buf[16]; | |
10283 | ||
10284 | switch (dw_sect) | |
10285 | { | |
10286 | case DW_SECT_INFO: | |
10287 | return "info"; | |
10288 | case DW_SECT_TYPES: | |
10289 | return "types"; | |
10290 | case DW_SECT_ABBREV: | |
10291 | return "abbrev"; | |
10292 | case DW_SECT_LINE: | |
10293 | return "line"; | |
10294 | case DW_SECT_LOC: | |
10295 | return "loc"; | |
10296 | case DW_SECT_STR_OFFSETS: | |
10297 | return "str_off"; | |
10298 | case DW_SECT_MACINFO: | |
10299 | return "macinfo"; | |
10300 | case DW_SECT_MACRO: | |
10301 | return "macro"; | |
10302 | default: | |
b4eb7656 | 10303 | break; |
341f9135 CC |
10304 | } |
10305 | ||
10306 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
10307 | return buf; | |
10308 | } | |
10309 | ||
10310 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
10311 | These sections are extensions for Fission. | |
10312 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
10313 | |
10314 | static int | |
10315 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
10316 | { | |
10317 | unsigned char *phdr = section->start; | |
10318 | unsigned char *limit = phdr + section->size; | |
10319 | unsigned char *phash; | |
10320 | unsigned char *pindex; | |
10321 | unsigned char *ppool; | |
10322 | unsigned int version; | |
341f9135 | 10323 | unsigned int ncols = 0; |
657d0d47 CC |
10324 | unsigned int nused; |
10325 | unsigned int nslots; | |
10326 | unsigned int i; | |
341f9135 | 10327 | unsigned int j; |
af2ddf69 | 10328 | dwarf_vma signature; |
b9c0d703 | 10329 | size_t total; |
657d0d47 | 10330 | |
6937bb54 NC |
10331 | /* PR 17512: file: 002-168123-0.004. */ |
10332 | if (phdr == NULL) | |
10333 | { | |
10334 | warn (_("Section %s is empty\n"), section->name); | |
10335 | return 0; | |
10336 | } | |
10337 | /* PR 17512: file: 002-376-0.004. */ | |
10338 | if (section->size < 24) | |
10339 | { | |
72c61a0d | 10340 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
10341 | section->name); |
10342 | return 0; | |
10343 | } | |
10344 | ||
6d1ad6f7 AM |
10345 | phash = phdr; |
10346 | SAFE_BYTE_GET_AND_INC (version, phash, 4, limit); | |
341f9135 | 10347 | if (version >= 2) |
6d1ad6f7 AM |
10348 | SAFE_BYTE_GET_AND_INC (ncols, phash, 4, limit); |
10349 | SAFE_BYTE_GET_AND_INC (nused, phash, 4, limit); | |
10350 | SAFE_BYTE_GET_AND_INC (nslots, phash, 4, limit); | |
6937bb54 | 10351 | |
8e2e3c6c AM |
10352 | pindex = phash + (size_t) nslots * 8; |
10353 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 10354 | |
657d0d47 CC |
10355 | if (do_display) |
10356 | { | |
015dc7e1 | 10357 | introduce (section, false); |
dda8d76d | 10358 | |
8e2e3c6c | 10359 | printf (_(" Version: %u\n"), version); |
341f9135 | 10360 | if (version >= 2) |
8e2e3c6c AM |
10361 | printf (_(" Number of columns: %u\n"), ncols); |
10362 | printf (_(" Number of used entries: %u\n"), nused); | |
10363 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
10364 | } |
10365 | ||
8e2e3c6c | 10366 | /* PR 17531: file: 45d69832. */ |
b9c0d703 AM |
10367 | if (_mul_overflow ((size_t) nslots, 12, &total) |
10368 | || total > (size_t) (limit - phash)) | |
657d0d47 | 10369 | { |
8e2e3c6c AM |
10370 | warn (ngettext ("Section %s is too small for %u slot\n", |
10371 | "Section %s is too small for %u slots\n", | |
10372 | nslots), | |
657d0d47 CC |
10373 | section->name, nslots); |
10374 | return 0; | |
10375 | } | |
10376 | ||
341f9135 | 10377 | if (version == 1) |
657d0d47 | 10378 | { |
341f9135 CC |
10379 | if (!do_display) |
10380 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
10381 | for (i = 0; i < nslots; i++) | |
657d0d47 | 10382 | { |
341f9135 CC |
10383 | unsigned char *shndx_list; |
10384 | unsigned int shndx; | |
10385 | ||
af2ddf69 AM |
10386 | SAFE_BYTE_GET (signature, phash, 8, limit); |
10387 | if (signature != 0) | |
657d0d47 | 10388 | { |
6937bb54 | 10389 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 10390 | shndx_list = ppool + j * 4; |
f3853b34 NC |
10391 | /* PR 17531: file: 705e010d. */ |
10392 | if (shndx_list < ppool) | |
10393 | { | |
10394 | warn (_("Section index pool located before start of section\n")); | |
10395 | return 0; | |
10396 | } | |
10397 | ||
341f9135 CC |
10398 | if (do_display) |
10399 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
af2ddf69 | 10400 | i, dwarf_vmatoa ("x", signature)); |
341f9135 | 10401 | for (;;) |
657d0d47 | 10402 | { |
341f9135 CC |
10403 | if (shndx_list >= limit) |
10404 | { | |
10405 | warn (_("Section %s too small for shndx pool\n"), | |
10406 | section->name); | |
10407 | return 0; | |
10408 | } | |
6937bb54 | 10409 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
10410 | if (shndx == 0) |
10411 | break; | |
10412 | if (do_display) | |
10413 | printf (" %d", shndx); | |
10414 | else | |
10415 | add_shndx_to_cu_tu_entry (shndx); | |
10416 | shndx_list += 4; | |
657d0d47 | 10417 | } |
657d0d47 | 10418 | if (do_display) |
341f9135 | 10419 | printf ("\n"); |
657d0d47 | 10420 | else |
341f9135 CC |
10421 | end_cu_tu_entry (); |
10422 | } | |
10423 | phash += 8; | |
10424 | pindex += 4; | |
10425 | } | |
10426 | } | |
10427 | else if (version == 2) | |
10428 | { | |
10429 | unsigned int val; | |
10430 | unsigned int dw_sect; | |
10431 | unsigned char *ph = phash; | |
10432 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
10433 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
10434 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
015dc7e1 | 10435 | bool is_tu_index; |
341f9135 CC |
10436 | struct cu_tu_set *this_set = NULL; |
10437 | unsigned int row; | |
10438 | unsigned char *prow; | |
b9c0d703 | 10439 | size_t temp; |
341f9135 CC |
10440 | |
10441 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
10442 | ||
362beea4 | 10443 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
10444 | Check for integer overflow (can occur when size_t is 32-bit) |
10445 | with overlarge ncols or nused values. */ | |
b9c0d703 AM |
10446 | if (nused == -1u |
10447 | || _mul_overflow ((size_t) ncols, 4, &temp) | |
10448 | || _mul_overflow ((size_t) nused + 1, temp, &total) | |
10449 | || total > (size_t) (limit - ppool)) | |
341f9135 CC |
10450 | { |
10451 | warn (_("Section %s too small for offset and size tables\n"), | |
10452 | section->name); | |
10453 | return 0; | |
10454 | } | |
10455 | ||
10456 | if (do_display) | |
10457 | { | |
10458 | printf (_(" Offset table\n")); | |
10459 | printf (" slot %-16s ", | |
10460 | is_tu_index ? _("signature") : _("dwo_id")); | |
10461 | } | |
10462 | else | |
10463 | { | |
10464 | if (is_tu_index) | |
10465 | { | |
10466 | tu_count = nused; | |
72c61a0d | 10467 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 10468 | this_set = tu_sets; |
657d0d47 | 10469 | } |
657d0d47 | 10470 | else |
341f9135 CC |
10471 | { |
10472 | cu_count = nused; | |
72c61a0d | 10473 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
10474 | this_set = cu_sets; |
10475 | } | |
10476 | } | |
6937bb54 | 10477 | |
341f9135 CC |
10478 | if (do_display) |
10479 | { | |
10480 | for (j = 0; j < ncols; j++) | |
10481 | { | |
6d1ad6f7 AM |
10482 | unsigned char *p = ppool + j * 4; |
10483 | SAFE_BYTE_GET (dw_sect, p, 4, limit); | |
341f9135 CC |
10484 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
10485 | } | |
10486 | printf ("\n"); | |
10487 | } | |
6937bb54 | 10488 | |
341f9135 CC |
10489 | for (i = 0; i < nslots; i++) |
10490 | { | |
af2ddf69 | 10491 | SAFE_BYTE_GET (signature, ph, 8, limit); |
6937bb54 NC |
10492 | |
10493 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10494 | if (row != 0) |
10495 | { | |
591f7597 | 10496 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 10497 | if (row > nused) |
591f7597 NC |
10498 | { |
10499 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
10500 | row, nused); | |
10501 | return 0; | |
10502 | } | |
10503 | ||
341f9135 | 10504 | if (!do_display) |
6aea08d9 NC |
10505 | { |
10506 | size_t num_copy = sizeof (uint64_t); | |
10507 | ||
b9c0d703 | 10508 | memcpy (&this_set[row - 1].signature, ph, num_copy); |
6aea08d9 | 10509 | } |
6937bb54 | 10510 | |
341f9135 CC |
10511 | prow = poffsets + (row - 1) * ncols * 4; |
10512 | if (do_display) | |
10513 | printf (_(" [%3d] 0x%s"), | |
af2ddf69 | 10514 | i, dwarf_vmatoa ("x", signature)); |
341f9135 CC |
10515 | for (j = 0; j < ncols; j++) |
10516 | { | |
6d1ad6f7 AM |
10517 | unsigned char *p = prow + j * 4; |
10518 | SAFE_BYTE_GET (val, p, 4, limit); | |
341f9135 CC |
10519 | if (do_display) |
10520 | printf (" %8d", val); | |
10521 | else | |
10522 | { | |
6d1ad6f7 AM |
10523 | p = ppool + j * 4; |
10524 | SAFE_BYTE_GET (dw_sect, p, 4, limit); | |
82b1b41b NC |
10525 | |
10526 | /* PR 17531: file: 10796eb3. */ | |
10527 | if (dw_sect >= DW_SECT_MAX) | |
10528 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10529 | else | |
10530 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
10531 | } |
10532 | } | |
6937bb54 | 10533 | |
341f9135 CC |
10534 | if (do_display) |
10535 | printf ("\n"); | |
10536 | } | |
10537 | ph += 8; | |
10538 | pi += 4; | |
10539 | } | |
10540 | ||
10541 | ph = phash; | |
10542 | pi = pindex; | |
10543 | if (do_display) | |
b4eb7656 | 10544 | { |
341f9135 CC |
10545 | printf ("\n"); |
10546 | printf (_(" Size table\n")); | |
10547 | printf (" slot %-16s ", | |
10548 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 10549 | } |
6937bb54 | 10550 | |
341f9135 CC |
10551 | for (j = 0; j < ncols; j++) |
10552 | { | |
6d1ad6f7 AM |
10553 | unsigned char *p = ppool + j * 4; |
10554 | SAFE_BYTE_GET (val, p, 4, limit); | |
341f9135 CC |
10555 | if (do_display) |
10556 | printf (" %8s", get_DW_SECT_short_name (val)); | |
10557 | } | |
6937bb54 | 10558 | |
341f9135 CC |
10559 | if (do_display) |
10560 | printf ("\n"); | |
6937bb54 | 10561 | |
341f9135 CC |
10562 | for (i = 0; i < nslots; i++) |
10563 | { | |
af2ddf69 | 10564 | SAFE_BYTE_GET (signature, ph, 8, limit); |
6937bb54 NC |
10565 | |
10566 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10567 | if (row != 0) |
10568 | { | |
10569 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 10570 | |
341f9135 CC |
10571 | if (do_display) |
10572 | printf (_(" [%3d] 0x%s"), | |
af2ddf69 | 10573 | i, dwarf_vmatoa ("x", signature)); |
6937bb54 | 10574 | |
341f9135 CC |
10575 | for (j = 0; j < ncols; j++) |
10576 | { | |
6d1ad6f7 AM |
10577 | unsigned char *p = prow + j * 4; |
10578 | SAFE_BYTE_GET (val, p, 4, limit); | |
341f9135 CC |
10579 | if (do_display) |
10580 | printf (" %8d", val); | |
10581 | else | |
10582 | { | |
6d1ad6f7 AM |
10583 | p = ppool + j * 4; |
10584 | SAFE_BYTE_GET (dw_sect, p, 4, limit); | |
82b1b41b NC |
10585 | if (dw_sect >= DW_SECT_MAX) |
10586 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10587 | else | |
341f9135 CC |
10588 | this_set [row - 1].section_sizes [dw_sect] = val; |
10589 | } | |
10590 | } | |
6937bb54 | 10591 | |
341f9135 CC |
10592 | if (do_display) |
10593 | printf ("\n"); | |
10594 | } | |
6937bb54 | 10595 | |
341f9135 CC |
10596 | ph += 8; |
10597 | pi += 4; | |
657d0d47 | 10598 | } |
657d0d47 | 10599 | } |
341f9135 | 10600 | else if (do_display) |
6937bb54 | 10601 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
10602 | |
10603 | if (do_display) | |
10604 | printf ("\n"); | |
10605 | ||
10606 | return 1; | |
10607 | } | |
10608 | ||
288f0ba2 AM |
10609 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
10610 | ||
657d0d47 CC |
10611 | /* Load the CU and TU indexes if present. This will build a list of |
10612 | section sets that we can use to associate a .debug_info.dwo section | |
10613 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
10614 | ||
015dc7e1 | 10615 | static bool |
657d0d47 CC |
10616 | load_cu_tu_indexes (void *file) |
10617 | { | |
10618 | /* If we have already loaded (or tried to load) the CU and TU indexes | |
10619 | then do not bother to repeat the task. */ | |
43a444f9 NC |
10620 | if (cu_tu_indexes_read == -1) |
10621 | { | |
015dc7e1 | 10622 | cu_tu_indexes_read = true; |
521d4b19 | 10623 | |
dda8d76d | 10624 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 | 10625 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
015dc7e1 | 10626 | cu_tu_indexes_read = false; |
43a444f9 | 10627 | |
dda8d76d | 10628 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 | 10629 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
015dc7e1 | 10630 | cu_tu_indexes_read = false; |
43a444f9 | 10631 | } |
657d0d47 | 10632 | |
015dc7e1 | 10633 | return (bool) cu_tu_indexes_read; |
657d0d47 CC |
10634 | } |
10635 | ||
10636 | /* Find the set of sections that includes section SHNDX. */ | |
10637 | ||
10638 | unsigned int * | |
10639 | find_cu_tu_set (void *file, unsigned int shndx) | |
10640 | { | |
10641 | unsigned int i; | |
10642 | ||
43a444f9 NC |
10643 | if (! load_cu_tu_indexes (file)) |
10644 | return NULL; | |
657d0d47 CC |
10645 | |
10646 | /* Find SHNDX in the shndx pool. */ | |
10647 | for (i = 0; i < shndx_pool_used; i++) | |
10648 | if (shndx_pool [i] == shndx) | |
10649 | break; | |
10650 | ||
10651 | if (i >= shndx_pool_used) | |
10652 | return NULL; | |
10653 | ||
10654 | /* Now backup to find the first entry in the set. */ | |
10655 | while (i > 0 && shndx_pool [i - 1] != 0) | |
10656 | i--; | |
10657 | ||
10658 | return shndx_pool + i; | |
10659 | } | |
10660 | ||
10661 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
10662 | ||
10663 | static int | |
10664 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
10665 | { | |
10666 | return process_cu_tu_index (section, 1); | |
10667 | } | |
10668 | ||
19e6b90e L |
10669 | static int |
10670 | display_debug_not_supported (struct dwarf_section *section, | |
10671 | void *file ATTRIBUTE_UNUSED) | |
10672 | { | |
10673 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
10674 | section->name); | |
10675 | ||
10676 | return 1; | |
10677 | } | |
10678 | ||
1306a742 NC |
10679 | /* Like malloc, but takes two parameters like calloc. |
10680 | Verifies that the first parameter is not too large. | |
82b1b41b | 10681 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 10682 | |
19e6b90e L |
10683 | void * |
10684 | cmalloc (size_t nmemb, size_t size) | |
10685 | { | |
10686 | /* Check for overflow. */ | |
10687 | if (nmemb >= ~(size_t) 0 / size) | |
10688 | return NULL; | |
82b1b41b NC |
10689 | |
10690 | return xmalloc (nmemb * size); | |
19e6b90e L |
10691 | } |
10692 | ||
1306a742 NC |
10693 | /* Like xmalloc, but takes two parameters like calloc. |
10694 | Verifies that the first parameter is not too large. | |
10695 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 10696 | |
72c61a0d | 10697 | void * |
1306a742 | 10698 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
10699 | { |
10700 | /* Check for overflow. */ | |
10701 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
10702 | { |
10703 | fprintf (stderr, | |
10704 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
10705 | (long) nmemb); | |
10706 | xexit (1); | |
10707 | } | |
72c61a0d | 10708 | |
1306a742 | 10709 | return xmalloc (nmemb * size); |
72c61a0d NC |
10710 | } |
10711 | ||
1306a742 NC |
10712 | /* Like xrealloc, but takes three parameters. |
10713 | Verifies that the second parameter is not too large. | |
10714 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 10715 | |
19e6b90e | 10716 | void * |
1306a742 | 10717 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
10718 | { |
10719 | /* Check for overflow. */ | |
10720 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10721 | { |
dda8d76d NC |
10722 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
10723 | (long) nmemb); | |
8490fb40 NC |
10724 | xexit (1); |
10725 | } | |
82b1b41b | 10726 | |
1306a742 | 10727 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
10728 | } |
10729 | ||
1306a742 | 10730 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 10731 | |
19e6b90e | 10732 | void * |
1306a742 | 10733 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
10734 | { |
10735 | /* Check for overflow. */ | |
10736 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10737 | { |
dda8d76d NC |
10738 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
10739 | (long) nmemb); | |
8490fb40 NC |
10740 | xexit (1); |
10741 | } | |
82b1b41b | 10742 | |
1306a742 | 10743 | return xcalloc (nmemb, size); |
19e6b90e L |
10744 | } |
10745 | ||
dda8d76d NC |
10746 | static unsigned long |
10747 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
10748 | const unsigned char * buf, | |
10749 | bfd_size_type len) | |
10750 | { | |
10751 | static const unsigned long crc32_table[256] = | |
10752 | { | |
10753 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
10754 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
10755 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
10756 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
10757 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
10758 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
10759 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
10760 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
10761 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
10762 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
10763 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
10764 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
10765 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
10766 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
10767 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
10768 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
10769 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
10770 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
10771 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
10772 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
10773 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
10774 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
10775 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
10776 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
10777 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
10778 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
10779 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
10780 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
10781 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
10782 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
10783 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
10784 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
10785 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
10786 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
10787 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
10788 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
10789 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
10790 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
10791 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
10792 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
10793 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
10794 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
10795 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
10796 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
10797 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
10798 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
10799 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
10800 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
10801 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
10802 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
10803 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
10804 | 0x2d02ef8d | |
10805 | }; | |
10806 | const unsigned char *end; | |
10807 | ||
10808 | crc = ~crc & 0xffffffff; | |
10809 | for (end = buf + len; buf < end; ++ buf) | |
10810 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10811 | return ~crc & 0xffffffff; | |
10812 | } | |
10813 | ||
015dc7e1 AM |
10814 | typedef bool (*check_func_type) (const char *, void *); |
10815 | typedef const char *(* parse_func_type) (struct dwarf_section *, void *); | |
dda8d76d | 10816 | |
015dc7e1 | 10817 | static bool |
dda8d76d NC |
10818 | check_gnu_debuglink (const char * pathname, void * crc_pointer) |
10819 | { | |
10820 | static unsigned char buffer [8 * 1024]; | |
10821 | FILE * f; | |
10822 | bfd_size_type count; | |
10823 | unsigned long crc = 0; | |
10824 | void * sep_data; | |
10825 | ||
10826 | sep_data = open_debug_file (pathname); | |
10827 | if (sep_data == NULL) | |
015dc7e1 | 10828 | return false; |
dda8d76d NC |
10829 | |
10830 | /* Yes - we are opening the file twice... */ | |
10831 | f = fopen (pathname, "rb"); | |
10832 | if (f == NULL) | |
10833 | { | |
10834 | /* Paranoia: This should never happen. */ | |
10835 | close_debug_file (sep_data); | |
10836 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
015dc7e1 | 10837 | return false; |
dda8d76d NC |
10838 | } |
10839 | ||
10840 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10841 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10842 | ||
10843 | fclose (f); | |
10844 | ||
10845 | if (crc != * (unsigned long *) crc_pointer) | |
10846 | { | |
10847 | close_debug_file (sep_data); | |
10848 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10849 | pathname); | |
015dc7e1 | 10850 | return false; |
dda8d76d NC |
10851 | } |
10852 | ||
015dc7e1 | 10853 | return true; |
dda8d76d NC |
10854 | } |
10855 | ||
10856 | static const char * | |
10857 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10858 | { | |
10859 | const char * name; | |
10860 | unsigned int crc_offset; | |
10861 | unsigned long * crc32 = (unsigned long *) data; | |
10862 | ||
10863 | /* The name is first. | |
10864 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10865 | name = (const char *) section->start; | |
10866 | ||
10867 | crc_offset = strnlen (name, section->size) + 1; | |
3d64c987 NC |
10868 | if (crc_offset == 1) |
10869 | return NULL; | |
dda8d76d NC |
10870 | crc_offset = (crc_offset + 3) & ~3; |
10871 | if (crc_offset + 4 > section->size) | |
10872 | return NULL; | |
10873 | ||
10874 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10875 | return name; | |
10876 | } | |
10877 | ||
015dc7e1 | 10878 | static bool |
dda8d76d NC |
10879 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) |
10880 | { | |
10881 | void * sep_data = open_debug_file (filename); | |
10882 | ||
10883 | if (sep_data == NULL) | |
015dc7e1 | 10884 | return false; |
dda8d76d NC |
10885 | |
10886 | /* FIXME: We should now extract the build-id in the separate file | |
10887 | and check it... */ | |
10888 | ||
015dc7e1 | 10889 | return true; |
dda8d76d NC |
10890 | } |
10891 | ||
10892 | typedef struct build_id_data | |
10893 | { | |
10894 | bfd_size_type len; | |
10895 | const unsigned char * data; | |
10896 | } Build_id_data; | |
10897 | ||
10898 | static const char * | |
10899 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10900 | { | |
10901 | const char * name; | |
10902 | bfd_size_type namelen; | |
10903 | bfd_size_type id_len; | |
10904 | Build_id_data * build_id_data; | |
10905 | ||
10906 | /* The name is first. | |
10907 | The build-id follows immediately, with no padding, up to the section's end. */ | |
10908 | ||
10909 | name = (const char *) section->start; | |
10910 | namelen = strnlen (name, section->size) + 1; | |
3d64c987 NC |
10911 | if (namelen == 1) |
10912 | return NULL; | |
dda8d76d NC |
10913 | if (namelen >= section->size) |
10914 | return NULL; | |
10915 | ||
10916 | id_len = section->size - namelen; | |
10917 | if (id_len < 0x14) | |
10918 | return NULL; | |
10919 | ||
dfbee680 | 10920 | build_id_data = (Build_id_data *) data; |
dda8d76d NC |
10921 | build_id_data->len = id_len; |
10922 | build_id_data->data = section->start + namelen; | |
10923 | ||
dda8d76d NC |
10924 | return name; |
10925 | } | |
10926 | ||
24841daa NC |
10927 | static void |
10928 | add_separate_debug_file (const char * filename, void * handle) | |
10929 | { | |
10930 | separate_info * i = xmalloc (sizeof * i); | |
10931 | ||
10932 | i->filename = filename; | |
10933 | i->handle = handle; | |
10934 | i->next = first_separate_info; | |
10935 | first_separate_info = i; | |
10936 | } | |
10937 | ||
301a9420 AM |
10938 | #if HAVE_LIBDEBUGINFOD |
10939 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
10940 | file. If successful, store the path of the file in filename and | |
10941 | return TRUE, otherwise return FALSE. */ | |
10942 | ||
015dc7e1 | 10943 | static bool |
301a9420 AM |
10944 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, |
10945 | char ** filename, | |
10946 | void * file) | |
10947 | { | |
10948 | size_t build_id_len; | |
10949 | unsigned char * build_id; | |
10950 | ||
10951 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
10952 | { | |
10953 | /* Get the build-id of file. */ | |
10954 | build_id = get_build_id (file); | |
10955 | build_id_len = 0; | |
10956 | } | |
10957 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
10958 | { | |
10959 | /* Get the build-id of the debugaltlink file. */ | |
10960 | unsigned int filelen; | |
10961 | ||
10962 | filelen = strnlen ((const char *)section->start, section->size); | |
10963 | if (filelen == section->size) | |
10964 | /* Corrupt debugaltlink. */ | |
015dc7e1 | 10965 | return false; |
301a9420 AM |
10966 | |
10967 | build_id = section->start + filelen + 1; | |
10968 | build_id_len = section->size - (filelen + 1); | |
10969 | ||
10970 | if (build_id_len == 0) | |
015dc7e1 | 10971 | return false; |
301a9420 AM |
10972 | } |
10973 | else | |
015dc7e1 | 10974 | return false; |
301a9420 AM |
10975 | |
10976 | if (build_id) | |
10977 | { | |
10978 | int fd; | |
10979 | debuginfod_client * client; | |
10980 | ||
10981 | client = debuginfod_begin (); | |
10982 | if (client == NULL) | |
015dc7e1 | 10983 | return false; |
301a9420 AM |
10984 | |
10985 | /* Query debuginfod servers for the target file. If found its path | |
10986 | will be stored in filename. */ | |
10987 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); | |
10988 | debuginfod_end (client); | |
10989 | ||
10990 | /* Only free build_id if we allocated space for a hex string | |
10991 | in get_build_id (). */ | |
10992 | if (build_id_len == 0) | |
10993 | free (build_id); | |
10994 | ||
10995 | if (fd >= 0) | |
10996 | { | |
10997 | /* File successfully retrieved. Close fd since we want to | |
10998 | use open_debug_file () on filename instead. */ | |
10999 | close (fd); | |
015dc7e1 | 11000 | return true; |
301a9420 AM |
11001 | } |
11002 | } | |
11003 | ||
015dc7e1 | 11004 | return false; |
301a9420 AM |
11005 | } |
11006 | #endif | |
11007 | ||
dda8d76d NC |
11008 | static void * |
11009 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 11010 | struct dwarf_section * xlink, |
dda8d76d NC |
11011 | parse_func_type parse_func, |
11012 | check_func_type check_func, | |
301a9420 AM |
11013 | void * func_data, |
11014 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
11015 | { |
11016 | const char * separate_filename; | |
24841daa | 11017 | char * debug_filename; |
dda8d76d NC |
11018 | char * canon_dir; |
11019 | size_t canon_dirlen; | |
11020 | size_t dirlen; | |
11021 | ||
2b63c337 | 11022 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
11023 | { |
11024 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 11025 | xlink->name ? xlink->name : xlink->uncompressed_name); |
ce139cd5 | 11026 | return NULL; |
dda8d76d | 11027 | } |
521d4b19 | 11028 | |
dda8d76d NC |
11029 | /* Attempt to locate the separate file. |
11030 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
11031 | ||
11032 | canon_dir = lrealpath (main_filename); | |
521d4b19 | 11033 | |
dda8d76d NC |
11034 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) |
11035 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
11036 | break; | |
11037 | canon_dir[canon_dirlen] = '\0'; | |
11038 | ||
11039 | #ifndef DEBUGDIR | |
11040 | #define DEBUGDIR "/lib/debug" | |
11041 | #endif | |
11042 | #ifndef EXTRA_DEBUG_ROOT1 | |
11043 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
11044 | #endif | |
11045 | #ifndef EXTRA_DEBUG_ROOT2 | |
11046 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
11047 | #endif | |
11048 | ||
24841daa NC |
11049 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
11050 | + canon_dirlen | |
11051 | + strlen (".debug/") | |
dda8d76d | 11052 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 11053 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
11054 | #endif |
11055 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 11056 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 11057 | #endif |
24841daa NC |
11058 | + strlen (separate_filename) |
11059 | + 1); | |
11060 | if (debug_filename == NULL) | |
dda8d76d NC |
11061 | { |
11062 | warn (_("Out of memory")); | |
3391569f | 11063 | free (canon_dir); |
dda8d76d NC |
11064 | return NULL; |
11065 | } | |
11066 | ||
11067 | /* First try in the current directory. */ | |
24841daa NC |
11068 | sprintf (debug_filename, "%s", separate_filename); |
11069 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11070 | goto found; |
11071 | ||
11072 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
11073 | sprintf (debug_filename, ".debug/%s", separate_filename); |
11074 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11075 | goto found; |
11076 | ||
11077 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
11078 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
11079 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11080 | goto found; |
11081 | ||
11082 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
11083 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
11084 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11085 | goto found; |
11086 | ||
11087 | #ifdef EXTRA_DEBUG_ROOT1 | |
11088 | /* Try the first extra debug file root. */ | |
24841daa NC |
11089 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
11090 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 11091 | goto found; |
39f0547e NC |
11092 | |
11093 | /* Try the first extra debug file root. */ | |
11094 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
11095 | if (check_func (debug_filename, func_data)) | |
11096 | goto found; | |
dda8d76d NC |
11097 | #endif |
11098 | ||
11099 | #ifdef EXTRA_DEBUG_ROOT2 | |
11100 | /* Try the second extra debug file root. */ | |
24841daa NC |
11101 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
11102 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11103 | goto found; |
11104 | #endif | |
11105 | ||
24841daa NC |
11106 | /* Then try in the global debug_filename directory. */ |
11107 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
11108 | dirlen = strlen (DEBUGDIR) - 1; |
11109 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
11110 | strcat (debug_filename, "/"); |
11111 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 11112 | |
24841daa | 11113 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
11114 | goto found; |
11115 | ||
301a9420 AM |
11116 | #if HAVE_LIBDEBUGINFOD |
11117 | { | |
11118 | char * tmp_filename; | |
11119 | ||
11120 | if (debuginfod_fetch_separate_debug_info (xlink, | |
11121 | & tmp_filename, | |
11122 | file)) | |
11123 | { | |
11124 | /* File successfully downloaded from server, replace | |
11125 | debug_filename with the file's path. */ | |
11126 | free (debug_filename); | |
11127 | debug_filename = tmp_filename; | |
11128 | goto found; | |
11129 | } | |
11130 | } | |
11131 | #endif | |
11132 | ||
ecd65684 L |
11133 | if (do_debug_links) |
11134 | { | |
11135 | /* Failed to find the file. */ | |
11136 | warn (_("could not find separate debug file '%s'\n"), | |
11137 | separate_filename); | |
11138 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11139 | |
11140 | #ifdef EXTRA_DEBUG_ROOT2 | |
ecd65684 L |
11141 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, |
11142 | separate_filename); | |
11143 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11144 | #endif |
11145 | ||
11146 | #ifdef EXTRA_DEBUG_ROOT1 | |
ecd65684 L |
11147 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, |
11148 | canon_dir, separate_filename); | |
11149 | warn (_("tried: %s\n"), debug_filename); | |
39f0547e | 11150 | |
ecd65684 L |
11151 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, |
11152 | separate_filename); | |
11153 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11154 | #endif |
11155 | ||
ecd65684 L |
11156 | sprintf (debug_filename, "%s.debug/%s", canon_dir, |
11157 | separate_filename); | |
11158 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11159 | |
ecd65684 L |
11160 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
11161 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11162 | |
ecd65684 L |
11163 | sprintf (debug_filename, ".debug/%s", separate_filename); |
11164 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11165 | |
ecd65684 L |
11166 | sprintf (debug_filename, "%s", separate_filename); |
11167 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11168 | |
301a9420 | 11169 | #if HAVE_LIBDEBUGINFOD |
ecd65684 L |
11170 | { |
11171 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
11172 | if (urls == NULL) | |
11173 | urls = ""; | |
301a9420 | 11174 | |
ecd65684 L |
11175 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); |
11176 | } | |
301a9420 | 11177 | #endif |
ecd65684 | 11178 | } |
301a9420 | 11179 | |
dda8d76d | 11180 | free (canon_dir); |
24841daa | 11181 | free (debug_filename); |
dda8d76d NC |
11182 | return NULL; |
11183 | ||
11184 | found: | |
11185 | free (canon_dir); | |
11186 | ||
24841daa NC |
11187 | void * debug_handle; |
11188 | ||
dda8d76d | 11189 | /* Now open the file.... */ |
24841daa | 11190 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 11191 | { |
24841daa NC |
11192 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
11193 | free (debug_filename); | |
ce139cd5 | 11194 | return NULL; |
dda8d76d NC |
11195 | } |
11196 | ||
11197 | /* FIXME: We do not check to see if there are any other separate debug info | |
11198 | files that would also match. */ | |
11199 | ||
ca0e11aa NC |
11200 | if (do_debug_links) |
11201 | printf (_("\n%s: Found separate debug info file: %s\n"), main_filename, debug_filename); | |
24841daa | 11202 | add_separate_debug_file (debug_filename, debug_handle); |
dda8d76d | 11203 | |
24841daa | 11204 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 11205 | the structure returned by open_debug_file(). */ |
24841daa | 11206 | return debug_handle; |
dda8d76d NC |
11207 | } |
11208 | ||
d85bf2ba NC |
11209 | /* Attempt to load a separate dwarf object file. */ |
11210 | ||
11211 | static void * | |
24841daa | 11212 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 11213 | { |
24841daa NC |
11214 | char * separate_filename; |
11215 | void * separate_handle; | |
d85bf2ba | 11216 | |
d9d9d8ef TV |
11217 | if (IS_ABSOLUTE_PATH (name)) |
11218 | separate_filename = strdup (name); | |
11219 | else | |
11220 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
11221 | separate_filename = concat (dir, "/", name, NULL); | |
24841daa | 11222 | if (separate_filename == NULL) |
d85bf2ba NC |
11223 | { |
11224 | warn (_("Out of memory allocating dwo filename\n")); | |
11225 | return NULL; | |
11226 | } | |
11227 | ||
24841daa | 11228 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 11229 | { |
24841daa NC |
11230 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
11231 | free (separate_filename); | |
d85bf2ba NC |
11232 | return NULL; |
11233 | } | |
11234 | ||
11235 | /* FIXME: We should check the dwo_id. */ | |
11236 | ||
24841daa | 11237 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
bfbfa6e7 | 11238 | |
24841daa NC |
11239 | add_separate_debug_file (separate_filename, separate_handle); |
11240 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
11241 | return separate_handle; | |
d85bf2ba NC |
11242 | } |
11243 | ||
e38332c2 NC |
11244 | static void |
11245 | load_debug_sup_file (const char * main_filename, void * file) | |
11246 | { | |
11247 | if (! load_debug_section (debug_sup, file)) | |
11248 | return; /* No .debug_sup section. */ | |
11249 | ||
11250 | struct dwarf_section * section; | |
11251 | section = & debug_displays [debug_sup].section; | |
11252 | assert (section != NULL); | |
11253 | ||
11254 | if (section->start == NULL || section->size < 5) | |
11255 | { | |
11256 | warn (_(".debug_sup section is corrupt/empty\n")); | |
11257 | return; | |
11258 | } | |
11259 | ||
11260 | if (section->start[2] != 0) | |
11261 | return; /* This is a supplementary file. */ | |
11262 | ||
11263 | const char * filename = (const char *) section->start + 3; | |
11264 | if (strnlen (filename, section->size - 3) == section->size - 3) | |
11265 | { | |
11266 | warn (_("filename in .debug_sup section is corrupt\n")); | |
11267 | return; | |
11268 | } | |
11269 | ||
11270 | if (filename[0] != '/' && strchr (main_filename, '/')) | |
11271 | { | |
11272 | char * new_name; | |
bfbfa6e7 NC |
11273 | int new_len; |
11274 | ||
11275 | new_len = asprintf (& new_name, "%.*s/%s", | |
11276 | (int) (strrchr (main_filename, '/') - main_filename), | |
11277 | main_filename, | |
11278 | filename); | |
11279 | if (new_len < 3) | |
11280 | { | |
11281 | warn (_("unable to construct path for supplementary debug file")); | |
11282 | if (new_len > -1) | |
11283 | free (new_name); | |
11284 | return; | |
11285 | } | |
11286 | filename = new_name; | |
11287 | } | |
11288 | else | |
11289 | { | |
11290 | /* PR 27796: Make sure that we pass a filename that can be free'd to | |
11291 | add_separate_debug_file(). */ | |
11292 | filename = strdup (filename); | |
11293 | if (filename == NULL) | |
11294 | { | |
11295 | warn (_("out of memory constructing filename for .debug_sup link\n")); | |
11296 | return; | |
11297 | } | |
e38332c2 NC |
11298 | } |
11299 | ||
bfbfa6e7 | 11300 | void * handle = open_debug_file (filename); |
e38332c2 NC |
11301 | if (handle == NULL) |
11302 | { | |
11303 | warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename); | |
bfbfa6e7 | 11304 | free ((void *) filename); |
e38332c2 NC |
11305 | return; |
11306 | } | |
11307 | ||
11308 | printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename, filename); | |
11309 | ||
11310 | /* FIXME: Compare the checksums, if present. */ | |
11311 | add_separate_debug_file (filename, handle); | |
11312 | } | |
11313 | ||
ce139cd5 NC |
11314 | /* Load a debuglink section and/or a debugaltlink section, if either are present. |
11315 | Recursively check the loaded files for more of these sections. | |
e38332c2 NC |
11316 | Also follow any links in .debug_sup sections. |
11317 | FIXME: Should also check for DWO_* entries in the newly loaded files. */ | |
ce139cd5 NC |
11318 | |
11319 | static void | |
11320 | check_for_and_load_links (void * file, const char * filename) | |
11321 | { | |
11322 | void * handle = NULL; | |
11323 | ||
11324 | if (load_debug_section (gnu_debugaltlink, file)) | |
11325 | { | |
11326 | Build_id_data build_id_data; | |
11327 | ||
11328 | handle = load_separate_debug_info (filename, | |
11329 | & debug_displays[gnu_debugaltlink].section, | |
11330 | parse_gnu_debugaltlink, | |
11331 | check_gnu_debugaltlink, | |
11332 | & build_id_data, | |
11333 | file); | |
11334 | if (handle) | |
11335 | { | |
11336 | assert (handle == first_separate_info->handle); | |
11337 | check_for_and_load_links (first_separate_info->handle, | |
11338 | first_separate_info->filename); | |
11339 | } | |
11340 | } | |
11341 | ||
11342 | if (load_debug_section (gnu_debuglink, file)) | |
11343 | { | |
11344 | unsigned long crc32; | |
11345 | ||
11346 | handle = load_separate_debug_info (filename, | |
11347 | & debug_displays[gnu_debuglink].section, | |
11348 | parse_gnu_debuglink, | |
11349 | check_gnu_debuglink, | |
11350 | & crc32, | |
11351 | file); | |
11352 | if (handle) | |
11353 | { | |
11354 | assert (handle == first_separate_info->handle); | |
11355 | check_for_and_load_links (first_separate_info->handle, | |
11356 | first_separate_info->filename); | |
11357 | } | |
11358 | } | |
e38332c2 NC |
11359 | |
11360 | load_debug_sup_file (filename, file); | |
ce139cd5 NC |
11361 | } |
11362 | ||
24841daa NC |
11363 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
11364 | Returns TRUE if any were found, FALSE otherwise. | |
11365 | If TRUE is returned then the linked list starting at first_separate_info | |
11366 | will be populated with open file handles. */ | |
dda8d76d | 11367 | |
015dc7e1 | 11368 | bool |
24841daa | 11369 | load_separate_debug_files (void * file, const char * filename) |
dda8d76d | 11370 | { |
8de3a6e2 NC |
11371 | /* Skip this operation if we are not interested in debug links. */ |
11372 | if (! do_follow_links && ! do_debug_links) | |
015dc7e1 | 11373 | return false; |
8de3a6e2 | 11374 | |
24841daa | 11375 | /* See if there are any dwo links. */ |
d85bf2ba NC |
11376 | if (load_debug_section (str, file) |
11377 | && load_debug_section (abbrev, file) | |
11378 | && load_debug_section (info, file)) | |
11379 | { | |
24841daa | 11380 | free_dwo_info (); |
d85bf2ba | 11381 | |
50ea0877 | 11382 | if (process_debug_info (& debug_displays[info].section, file, abbrev, |
015dc7e1 | 11383 | true, false)) |
d85bf2ba | 11384 | { |
015dc7e1 AM |
11385 | bool introduced = false; |
11386 | dwo_info *dwinfo; | |
11387 | const char *dir = NULL; | |
11388 | const char *id = NULL; | |
11389 | const char *name = NULL; | |
24841daa NC |
11390 | |
11391 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 11392 | { |
50ea0877 | 11393 | /* Accumulate NAME, DIR and ID fields. */ |
24841daa | 11394 | switch (dwinfo->type) |
d85bf2ba | 11395 | { |
24841daa | 11396 | case DWO_NAME: |
50ea0877 NC |
11397 | if (name != NULL) |
11398 | warn (_("Multiple DWO_NAMEs encountered for the same CU\n")); | |
11399 | name = dwinfo->value; | |
11400 | break; | |
11401 | ||
11402 | case DWO_DIR: | |
11403 | /* There can be multiple DW_AT_comp_dir entries in a CU, | |
11404 | so do not complain. */ | |
11405 | dir = dwinfo->value; | |
11406 | break; | |
11407 | ||
11408 | case DWO_ID: | |
11409 | if (id != NULL) | |
11410 | warn (_("multiple DWO_IDs encountered for the same CU\n")); | |
11411 | id = dwinfo->value; | |
11412 | break; | |
11413 | ||
11414 | default: | |
11415 | error (_("Unexpected DWO INFO type")); | |
11416 | break; | |
11417 | } | |
11418 | ||
11419 | /* If we have reached the end of our list, or we are changing | |
11420 | CUs, then display the information that we have accumulated | |
11421 | so far. */ | |
11422 | if (name != NULL | |
11423 | && (dwinfo->next == NULL | |
11424 | || dwinfo->next->cu_offset != dwinfo->cu_offset)) | |
11425 | { | |
24841daa NC |
11426 | if (do_debug_links) |
11427 | { | |
11428 | if (! introduced) | |
11429 | { | |
11430 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
11431 | debug_displays [info].section.uncompressed_name); | |
015dc7e1 | 11432 | introduced = true; |
24841daa | 11433 | } |
d85bf2ba | 11434 | |
50ea0877 | 11435 | printf (_(" Name: %s\n"), name); |
24841daa NC |
11436 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); |
11437 | if (id != NULL) | |
11438 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
11439 | else | |
50ea0877 | 11440 | printf (_(" ID: <not specified>\n")); |
24841daa NC |
11441 | printf ("\n\n"); |
11442 | } | |
11443 | ||
11444 | if (do_follow_links) | |
50ea0877 | 11445 | load_dwo_file (filename, name, dir, id); |
24841daa | 11446 | |
50ea0877 | 11447 | name = dir = id = NULL; |
24841daa | 11448 | } |
d85bf2ba NC |
11449 | } |
11450 | } | |
11451 | } | |
11452 | ||
dda8d76d | 11453 | if (! do_follow_links) |
8de3a6e2 NC |
11454 | /* The other debug links will be displayed by display_debug_links() |
11455 | so we do not need to do any further processing here. */ | |
015dc7e1 | 11456 | return false; |
dda8d76d NC |
11457 | |
11458 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
dda8d76d | 11459 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
d85bf2ba | 11460 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 11461 | |
ce139cd5 | 11462 | check_for_and_load_links (file, filename); |
24841daa | 11463 | if (first_separate_info != NULL) |
015dc7e1 | 11464 | return true; |
24841daa | 11465 | |
dda8d76d | 11466 | do_follow_links = 0; |
015dc7e1 | 11467 | return false; |
521d4b19 | 11468 | } |
dda8d76d | 11469 | |
19e6b90e L |
11470 | void |
11471 | free_debug_memory (void) | |
11472 | { | |
3f5e193b | 11473 | unsigned int i; |
19e6b90e | 11474 | |
bcd213b2 | 11475 | free_all_abbrevs (); |
19e6b90e | 11476 | |
bcd213b2 NC |
11477 | free (cu_abbrev_map); |
11478 | cu_abbrev_map = NULL; | |
11479 | next_free_abbrev_map_entry = 0; | |
521d4b19 | 11480 | |
288f0ba2 AM |
11481 | free (shndx_pool); |
11482 | shndx_pool = NULL; | |
11483 | shndx_pool_size = 0; | |
11484 | shndx_pool_used = 0; | |
11485 | free (cu_sets); | |
11486 | cu_sets = NULL; | |
11487 | cu_count = 0; | |
11488 | free (tu_sets); | |
11489 | tu_sets = NULL; | |
11490 | tu_count = 0; | |
11491 | ||
11492 | memset (level_type_signed, 0, sizeof level_type_signed); | |
11493 | cu_tu_indexes_read = -1; | |
11494 | ||
19e6b90e | 11495 | for (i = 0; i < max; i++) |
3f5e193b | 11496 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 11497 | |
cc86f28f | 11498 | if (debug_information != NULL) |
19e6b90e | 11499 | { |
82fcdb39 | 11500 | for (i = 0; i < alloc_num_debug_info_entries; i++) |
19e6b90e | 11501 | { |
82fcdb39 | 11502 | if (debug_information [i].max_loc_offsets) |
19e6b90e | 11503 | { |
82fcdb39 AM |
11504 | free (debug_information [i].loc_offsets); |
11505 | free (debug_information [i].have_frame_base); | |
19e6b90e | 11506 | } |
82fcdb39 AM |
11507 | if (debug_information [i].max_range_lists) |
11508 | free (debug_information [i].range_lists); | |
19e6b90e L |
11509 | } |
11510 | free (debug_information); | |
11511 | debug_information = NULL; | |
82b1b41b | 11512 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 11513 | } |
dda8d76d | 11514 | |
24841daa NC |
11515 | separate_info * d; |
11516 | separate_info * next; | |
dda8d76d | 11517 | |
24841daa NC |
11518 | for (d = first_separate_info; d != NULL; d = next) |
11519 | { | |
11520 | close_debug_file (d->handle); | |
11521 | free ((void *) d->filename); | |
11522 | next = d->next; | |
11523 | free ((void *) d); | |
dda8d76d | 11524 | } |
24841daa | 11525 | first_separate_info = NULL; |
521d4b19 | 11526 | |
24841daa | 11527 | free_dwo_info (); |
19e6b90e L |
11528 | } |
11529 | ||
4cb93e3b TG |
11530 | void |
11531 | dwarf_select_sections_by_names (const char *names) | |
11532 | { | |
11533 | typedef struct | |
11534 | { | |
11535 | const char * option; | |
11536 | int * variable; | |
f9f0e732 | 11537 | int val; |
4cb93e3b TG |
11538 | } |
11539 | debug_dump_long_opts; | |
11540 | ||
11541 | static const debug_dump_long_opts opts_table [] = | |
11542 | { | |
11543 | /* Please keep this table alpha- sorted. */ | |
11544 | { "Ranges", & do_debug_ranges, 1 }, | |
11545 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 11546 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 11547 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
11548 | { "cu_index", & do_debug_cu_index, 1 }, |
11549 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 11550 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
11551 | { "frames", & do_debug_frames, 1 }, |
11552 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
11553 | /* The special .gdb_index section. */ |
11554 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
11555 | { "info", & do_debug_info, 1 }, |
11556 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 11557 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
11558 | { "loc", & do_debug_loc, 1 }, |
11559 | { "macro", & do_debug_macinfo, 1 }, | |
c46b7066 | 11560 | { "no-follow-links", & do_follow_links, 0 }, |
4cb93e3b | 11561 | { "pubnames", & do_debug_pubnames, 1 }, |
357da287 | 11562 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 11563 | /* This entry is for compatibility |
4cb93e3b TG |
11564 | with earlier versions of readelf. */ |
11565 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 11566 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 11567 | { "str", & do_debug_str, 1 }, |
e4b7104b | 11568 | { "str-offsets", & do_debug_str_offsets, 1 }, |
6f875884 TG |
11569 | /* These trace_* sections are used by Itanium VMS. */ |
11570 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
11571 | { "trace_aranges", & do_trace_aranges, 1 }, | |
11572 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
11573 | { NULL, NULL, 0 } |
11574 | }; | |
11575 | ||
11576 | const char *p; | |
467c65bc | 11577 | |
4cb93e3b TG |
11578 | p = names; |
11579 | while (*p) | |
11580 | { | |
11581 | const debug_dump_long_opts * entry; | |
467c65bc | 11582 | |
4cb93e3b TG |
11583 | for (entry = opts_table; entry->option; entry++) |
11584 | { | |
11585 | size_t len = strlen (entry->option); | |
467c65bc | 11586 | |
4cb93e3b TG |
11587 | if (strncmp (p, entry->option, len) == 0 |
11588 | && (p[len] == ',' || p[len] == '\0')) | |
11589 | { | |
c46b7066 | 11590 | * entry->variable = entry->val; |
467c65bc | 11591 | |
4cb93e3b TG |
11592 | /* The --debug-dump=frames-interp option also |
11593 | enables the --debug-dump=frames option. */ | |
11594 | if (do_debug_frames_interp) | |
11595 | do_debug_frames = 1; | |
11596 | ||
11597 | p += len; | |
11598 | break; | |
11599 | } | |
11600 | } | |
467c65bc | 11601 | |
4cb93e3b TG |
11602 | if (entry->option == NULL) |
11603 | { | |
11604 | warn (_("Unrecognized debug option '%s'\n"), p); | |
11605 | p = strchr (p, ','); | |
11606 | if (p == NULL) | |
11607 | break; | |
11608 | } | |
467c65bc | 11609 | |
4cb93e3b TG |
11610 | if (*p == ',') |
11611 | p++; | |
11612 | } | |
11613 | } | |
11614 | ||
11615 | void | |
11616 | dwarf_select_sections_by_letters (const char *letters) | |
11617 | { | |
91d6fa6a | 11618 | unsigned int lindex = 0; |
4cb93e3b | 11619 | |
91d6fa6a NC |
11620 | while (letters[lindex]) |
11621 | switch (letters[lindex++]) | |
4cb93e3b | 11622 | { |
dda8d76d NC |
11623 | case 'A': do_debug_addr = 1; break; |
11624 | case 'a': do_debug_abbrevs = 1; break; | |
11625 | case 'c': do_debug_cu_index = 1; break; | |
11626 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
11627 | case 'f': do_debug_frames = 1; break; | |
11628 | case 'g': do_gdb_index = 1; break; | |
11629 | case 'i': do_debug_info = 1; break; | |
11630 | case 'K': do_follow_links = 1; break; | |
c46b7066 | 11631 | case 'N': do_follow_links = 0; break; |
dda8d76d NC |
11632 | case 'k': do_debug_links = 1; break; |
11633 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
11634 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
11635 | case 'm': do_debug_macinfo = 1; break; | |
e4b7104b | 11636 | case 'O': do_debug_str_offsets = 1; break; |
dda8d76d NC |
11637 | case 'o': do_debug_loc = 1; break; |
11638 | case 'p': do_debug_pubnames = 1; break; | |
11639 | case 'R': do_debug_ranges = 1; break; | |
11640 | case 'r': do_debug_aranges = 1; break; | |
11641 | case 's': do_debug_str = 1; break; | |
11642 | case 'T': do_trace_aranges = 1; break; | |
11643 | case 't': do_debug_pubtypes = 1; break; | |
11644 | case 'U': do_trace_info = 1; break; | |
11645 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 11646 | |
4cb93e3b | 11647 | default: |
7cc78d07 | 11648 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
11649 | break; |
11650 | } | |
11651 | } | |
11652 | ||
11653 | void | |
11654 | dwarf_select_sections_all (void) | |
11655 | { | |
11656 | do_debug_info = 1; | |
11657 | do_debug_abbrevs = 1; | |
11658 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
11659 | do_debug_pubnames = 1; | |
f9f0e732 | 11660 | do_debug_pubtypes = 1; |
4cb93e3b TG |
11661 | do_debug_aranges = 1; |
11662 | do_debug_ranges = 1; | |
11663 | do_debug_frames = 1; | |
11664 | do_debug_macinfo = 1; | |
11665 | do_debug_str = 1; | |
11666 | do_debug_loc = 1; | |
5bbdf3d5 | 11667 | do_gdb_index = 1; |
6f875884 TG |
11668 | do_trace_info = 1; |
11669 | do_trace_abbrevs = 1; | |
11670 | do_trace_aranges = 1; | |
657d0d47 CC |
11671 | do_debug_addr = 1; |
11672 | do_debug_cu_index = 1; | |
dda8d76d NC |
11673 | do_follow_links = 1; |
11674 | do_debug_links = 1; | |
e4b7104b | 11675 | do_debug_str_offsets = 1; |
4cb93e3b TG |
11676 | } |
11677 | ||
208599d9 AM |
11678 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0 |
11679 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0 | |
dda8d76d NC |
11680 | |
11681 | /* N.B. The order here must match the order in section_display_enum. */ | |
11682 | ||
19e6b90e L |
11683 | struct dwarf_section_display debug_displays[] = |
11684 | { | |
015dc7e1 AM |
11685 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, |
11686 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, true }, | |
11687 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, | |
11688 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, true }, | |
11689 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, | |
11690 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, false }, | |
11691 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, false }, | |
11692 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, | |
11693 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, | |
11694 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, | |
11695 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
11696 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
11697 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
11698 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
11699 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, false }, | |
11700 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, false }, | |
11701 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
11702 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
11703 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
11704 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
11705 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, true }, | |
11706 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
11707 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, false }, | |
11708 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, false }, | |
11709 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, true }, | |
11710 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, false }, | |
11711 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, false }, | |
11712 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, true }, | |
11713 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, | |
11714 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, true }, | |
11715 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, | |
11716 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
11717 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, | |
11718 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, | |
11719 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, true }, | |
11720 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, | |
11721 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, | |
11722 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, true }, | |
11723 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, | |
11724 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, | |
11725 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, | |
11726 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, | |
11727 | { { ".debug_sup", "", NO_ABBREVS }, display_debug_sup, &do_debug_links, false }, | |
dda8d76d NC |
11728 | /* Separate debug info files can containt their own .debug_str section, |
11729 | and this might be in *addition* to a .debug_str section already present | |
11730 | in the main file. Hence we need to have two entries for .debug_str. */ | |
015dc7e1 | 11731 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, |
19e6b90e | 11732 | }; |
b451e98a JK |
11733 | |
11734 | /* A static assertion. */ | |
11735 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |