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) | |
2214 | printf (", %s", orig_data); | |
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); |
19e6b90e L |
2520 | } |
2521 | ||
2522 | switch (form) | |
2523 | { | |
2524 | case DW_FORM_ref_addr: | |
2525 | if (!do_loc) | |
bcd213b2 | 2526 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2527 | break; |
2528 | ||
a081f3cd JJ |
2529 | case DW_FORM_GNU_ref_alt: |
2530 | if (!do_loc) | |
521d4b19 NC |
2531 | { |
2532 | if (do_wide) | |
2533 | /* We have already printed the form name. */ | |
2534 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); | |
2535 | else | |
2536 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); | |
2537 | } | |
dda8d76d | 2538 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2539 | break; |
2540 | ||
19e6b90e L |
2541 | case DW_FORM_ref1: |
2542 | case DW_FORM_ref2: | |
2543 | case DW_FORM_ref4: | |
e38332c2 | 2544 | case DW_FORM_ref_sup4: |
19e6b90e L |
2545 | case DW_FORM_ref_udata: |
2546 | if (!do_loc) | |
ef0b5f1c | 2547 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2548 | break; |
2549 | ||
2550 | case DW_FORM_data4: | |
2551 | case DW_FORM_addr: | |
932fd279 | 2552 | case DW_FORM_sec_offset: |
19e6b90e | 2553 | if (!do_loc) |
ef0b5f1c | 2554 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2555 | break; |
2556 | ||
932fd279 | 2557 | case DW_FORM_flag_present: |
19e6b90e L |
2558 | case DW_FORM_flag: |
2559 | case DW_FORM_data1: | |
2560 | case DW_FORM_data2: | |
2561 | case DW_FORM_sdata: | |
2562 | case DW_FORM_udata: | |
2563 | if (!do_loc) | |
ef0b5f1c | 2564 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2565 | break; |
2566 | ||
77145576 JK |
2567 | case DW_FORM_implicit_const: |
2568 | if (!do_loc) | |
2569 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2570 | break; | |
2571 | ||
e38332c2 | 2572 | case DW_FORM_ref_sup8: |
19e6b90e L |
2573 | case DW_FORM_ref8: |
2574 | case DW_FORM_data8: | |
2bc8690c | 2575 | if (!do_loc) |
19e6b90e | 2576 | { |
af2ddf69 | 2577 | dwarf_vma utmp = uvalue; |
a69c4772 | 2578 | if (form == DW_FORM_ref8) |
af2ddf69 AM |
2579 | utmp += cu_offset; |
2580 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", utmp)); | |
19e6b90e | 2581 | } |
19e6b90e L |
2582 | break; |
2583 | ||
2f6cd591 JK |
2584 | case DW_FORM_data16: |
2585 | if (!do_loc) | |
af2ddf69 AM |
2586 | printf (" 0x%s%s", |
2587 | uvalue_hi == 0 ? "" : dwarf_vmatoa ("x", uvalue_hi), | |
2588 | dwarf_vmatoa_1 ("x", uvalue, uvalue_hi == 0 ? 0 : 8)); | |
2f6cd591 JK |
2589 | break; |
2590 | ||
19e6b90e L |
2591 | case DW_FORM_string: |
2592 | if (!do_loc) | |
ef0b5f1c | 2593 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
a7077ce7 AM |
2594 | data += strnlen ((char *) data, end - data); |
2595 | if (data < end) | |
2596 | data++; | |
19e6b90e L |
2597 | break; |
2598 | ||
2599 | case DW_FORM_block: | |
932fd279 | 2600 | case DW_FORM_exprloc: |
cd30bcef AM |
2601 | READ_ULEB (uvalue, data, end); |
2602 | do_block: | |
2603 | block_start = data; | |
a1165289 NC |
2604 | if (block_start >= end) |
2605 | { | |
2606 | warn (_("Block ends prematurely\n")); | |
2607 | uvalue = 0; | |
2608 | block_start = end; | |
2609 | } | |
afc72f15 NC |
2610 | |
2611 | uvalue = check_uvalue (block_start, uvalue, end); | |
2612 | ||
19e6b90e L |
2613 | if (do_loc) |
2614 | data = block_start + uvalue; | |
2615 | else | |
ef0b5f1c | 2616 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2617 | break; |
2618 | ||
2619 | case DW_FORM_block1: | |
cd30bcef AM |
2620 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2621 | goto do_block; | |
19e6b90e L |
2622 | |
2623 | case DW_FORM_block2: | |
cd30bcef AM |
2624 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2625 | goto do_block; | |
19e6b90e L |
2626 | |
2627 | case DW_FORM_block4: | |
cd30bcef AM |
2628 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2629 | goto do_block; | |
19e6b90e L |
2630 | |
2631 | case DW_FORM_strp: | |
2632 | if (!do_loc) | |
521d4b19 NC |
2633 | { |
2634 | if (do_wide) | |
2635 | /* We have already displayed the form name. */ | |
2636 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2637 | dwarf_vmatoa ("x", uvalue), | |
2638 | fetch_indirect_string (uvalue)); | |
2639 | else | |
2640 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, | |
2641 | dwarf_vmatoa ("x", uvalue), | |
2642 | fetch_indirect_string (uvalue)); | |
2643 | } | |
19e6b90e L |
2644 | break; |
2645 | ||
77145576 JK |
2646 | case DW_FORM_line_strp: |
2647 | if (!do_loc) | |
521d4b19 NC |
2648 | { |
2649 | if (do_wide) | |
2650 | /* We have already displayed the form name. */ | |
2651 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2652 | dwarf_vmatoa ("x", uvalue), | |
2653 | fetch_indirect_line_string (uvalue)); | |
2654 | else | |
2655 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2656 | dwarf_vmatoa ("x", uvalue), | |
2657 | fetch_indirect_line_string (uvalue)); | |
2658 | } | |
77145576 JK |
2659 | break; |
2660 | ||
4723351a | 2661 | case DW_FORM_GNU_str_index: |
32e4f96c TV |
2662 | case DW_FORM_strx: |
2663 | case DW_FORM_strx1: | |
2664 | case DW_FORM_strx2: | |
2665 | case DW_FORM_strx3: | |
2666 | case DW_FORM_strx4: | |
4723351a | 2667 | if (!do_loc) |
b4eb7656 | 2668 | { |
63b4cc53 | 2669 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 2670 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
b4eb7656 | 2671 | |
521d4b19 NC |
2672 | if (do_wide) |
2673 | /* We have already displayed the form name. */ | |
2674 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2675 | dwarf_vmatoa ("x", uvalue), | |
2676 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2677 | else | |
2678 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, | |
2679 | dwarf_vmatoa ("x", uvalue), | |
2680 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
b4eb7656 | 2681 | } |
4723351a CC |
2682 | break; |
2683 | ||
a081f3cd JJ |
2684 | case DW_FORM_GNU_strp_alt: |
2685 | if (!do_loc) | |
dda8d76d | 2686 | { |
521d4b19 NC |
2687 | if (do_wide) |
2688 | /* We have already displayed the form name. */ | |
2689 | printf (_("%c(offset: 0x%s) %s"), delimiter, | |
2690 | dwarf_vmatoa ("x", uvalue), | |
2691 | fetch_alt_indirect_string (uvalue)); | |
2692 | else | |
2693 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2694 | dwarf_vmatoa ("x", uvalue), | |
2695 | fetch_alt_indirect_string (uvalue)); | |
dda8d76d | 2696 | } |
a081f3cd JJ |
2697 | break; |
2698 | ||
19e6b90e L |
2699 | case DW_FORM_indirect: |
2700 | /* Handled above. */ | |
2701 | break; | |
2702 | ||
2b6f5997 CC |
2703 | case DW_FORM_ref_sig8: |
2704 | if (!do_loc) | |
af2ddf69 AM |
2705 | printf ("%c%s: 0x%s", delimiter, do_wide ? "" : "signature", |
2706 | dwarf_vmatoa ("x", uvalue)); | |
2b6f5997 CC |
2707 | break; |
2708 | ||
4723351a | 2709 | case DW_FORM_GNU_addr_index: |
32e4f96c TV |
2710 | case DW_FORM_addrx: |
2711 | case DW_FORM_addrx1: | |
2712 | case DW_FORM_addrx2: | |
2713 | case DW_FORM_addrx3: | |
2714 | case DW_FORM_addrx4: | |
4723351a | 2715 | if (!do_loc) |
521d4b19 | 2716 | { |
32e4f96c TV |
2717 | dwarf_vma base; |
2718 | dwarf_vma offset; | |
2719 | ||
2720 | if (debug_info_p == NULL) | |
2721 | base = 0; | |
2722 | else if (debug_info_p->addr_base == DEBUG_INFO_UNAVAILABLE) | |
2723 | base = 0; | |
2724 | else | |
2725 | base = debug_info_p->addr_base; | |
2726 | ||
2727 | offset = base + uvalue * pointer_size; | |
2728 | ||
521d4b19 NC |
2729 | if (do_wide) |
2730 | /* We have already displayed the form name. */ | |
2731 | printf (_("%c(index: 0x%s): %s"), delimiter, | |
2732 | dwarf_vmatoa ("x", uvalue), | |
32e4f96c | 2733 | fetch_indexed_value (offset, pointer_size)); |
521d4b19 NC |
2734 | else |
2735 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, | |
2736 | dwarf_vmatoa ("x", uvalue), | |
32e4f96c | 2737 | fetch_indexed_value (offset, pointer_size)); |
521d4b19 | 2738 | } |
4723351a CC |
2739 | break; |
2740 | ||
e38332c2 NC |
2741 | case DW_FORM_strp_sup: |
2742 | if (!do_loc) | |
2743 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); | |
2744 | break; | |
2745 | ||
19e6b90e | 2746 | default: |
e38332c2 | 2747 | warn (_("Unrecognized form: 0x%lx\n"), form); |
19e6b90e L |
2748 | break; |
2749 | } | |
2750 | ||
19e6b90e | 2751 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2752 | && num_debug_info_entries == 0 |
2753 | && debug_info_p != NULL) | |
19e6b90e L |
2754 | { |
2755 | switch (attribute) | |
2756 | { | |
2757 | case DW_AT_frame_base: | |
2758 | have_frame_base = 1; | |
1a0670f3 | 2759 | /* Fall through. */ |
19e6b90e | 2760 | case DW_AT_location: |
9f272209 | 2761 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2762 | case DW_AT_string_length: |
2763 | case DW_AT_return_addr: | |
19e6b90e L |
2764 | case DW_AT_data_member_location: |
2765 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2766 | case DW_AT_segment: |
2767 | case DW_AT_static_link: | |
2768 | case DW_AT_use_location: | |
bc0a77d2 | 2769 | case DW_AT_call_value: |
629e7ca8 | 2770 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2771 | case DW_AT_call_data_value: |
629e7ca8 | 2772 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2773 | case DW_AT_call_target: |
629e7ca8 | 2774 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2775 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2776 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2777 | if ((dwarf_version < 4 |
212b6063 | 2778 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2779 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2780 | { |
2781 | /* Process location list. */ | |
91d6fa6a | 2782 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2783 | unsigned int num = debug_info_p->num_loc_offsets; |
2784 | ||
91d6fa6a | 2785 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2786 | { |
91d6fa6a | 2787 | lmax += 1024; |
467c65bc | 2788 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2789 | xcrealloc (debug_info_p->loc_offsets, |
2790 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2791 | debug_info_p->loc_views = (dwarf_vma *) |
2792 | xcrealloc (debug_info_p->loc_views, | |
2793 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2794 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2795 | xcrealloc (debug_info_p->have_frame_base, |
2796 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2797 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2798 | } |
341f9135 | 2799 | if (this_set != NULL) |
b4eb7656 | 2800 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2801 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2802 | if (attribute != DW_AT_GNU_locviews) |
2803 | { | |
a7504f87 NC |
2804 | /* Corrupt DWARF info can produce more offsets than views. |
2805 | See PR 23062 for an example. */ | |
2806 | if (debug_info_p->num_loc_offsets | |
2807 | > debug_info_p->num_loc_views) | |
2808 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2809 | else | |
2810 | { | |
2811 | debug_info_p->loc_offsets [num] = uvalue; | |
2812 | debug_info_p->num_loc_offsets++; | |
2813 | } | |
9f272209 AO |
2814 | } |
2815 | else | |
2816 | { | |
2817 | assert (debug_info_p->num_loc_views <= num); | |
2818 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2819 | if (num > debug_info_p->num_loc_offsets) |
2820 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2821 | else | |
2822 | { | |
2823 | debug_info_p->loc_views [num] = uvalue; | |
2824 | debug_info_p->num_loc_views++; | |
2825 | } | |
9f272209 | 2826 | } |
19e6b90e L |
2827 | } |
2828 | break; | |
e2a0d921 | 2829 | |
19e6b90e L |
2830 | case DW_AT_low_pc: |
2831 | if (need_base_address) | |
2832 | debug_info_p->base_address = uvalue; | |
2833 | break; | |
2834 | ||
4723351a | 2835 | case DW_AT_GNU_addr_base: |
32e4f96c | 2836 | case DW_AT_addr_base: |
b4eb7656 | 2837 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2838 | break; |
2839 | ||
2840 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2841 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2842 | break; |
2843 | ||
19e6b90e | 2844 | case DW_AT_ranges: |
b4eb7656 | 2845 | if ((dwarf_version < 4 |
212b6063 | 2846 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2847 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2848 | { |
2849 | /* Process range list. */ | |
91d6fa6a | 2850 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2851 | unsigned int num = debug_info_p->num_range_lists; |
2852 | ||
91d6fa6a | 2853 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2854 | { |
91d6fa6a | 2855 | lmax += 1024; |
467c65bc | 2856 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2857 | xcrealloc (debug_info_p->range_lists, |
2858 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2859 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2860 | } |
2861 | debug_info_p->range_lists [num] = uvalue; | |
2862 | debug_info_p->num_range_lists++; | |
2863 | } | |
2864 | break; | |
2865 | ||
d85bf2ba NC |
2866 | case DW_AT_GNU_dwo_name: |
2867 | case DW_AT_dwo_name: | |
2868 | if (need_dwo_info) | |
2869 | switch (form) | |
2870 | { | |
2871 | case DW_FORM_strp: | |
50ea0877 | 2872 | add_dwo_name ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 2873 | break; |
5568cc9e | 2874 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 2875 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 2876 | break; |
d85bf2ba | 2877 | case DW_FORM_GNU_str_index: |
32e4f96c TV |
2878 | case DW_FORM_strx: |
2879 | case DW_FORM_strx1: | |
2880 | case DW_FORM_strx2: | |
2881 | case DW_FORM_strx3: | |
2882 | case DW_FORM_strx4: | |
015dc7e1 | 2883 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset); |
d85bf2ba NC |
2884 | break; |
2885 | case DW_FORM_string: | |
50ea0877 | 2886 | add_dwo_name ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
2887 | break; |
2888 | default: | |
2889 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2890 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2891 | break; |
2892 | } | |
2893 | break; | |
521d4b19 | 2894 | |
d85bf2ba NC |
2895 | case DW_AT_comp_dir: |
2896 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2897 | if (need_dwo_info) | |
2898 | switch (form) | |
2899 | { | |
2900 | case DW_FORM_strp: | |
50ea0877 | 2901 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 2902 | break; |
5568cc9e | 2903 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 2904 | add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 2905 | break; |
d85bf2ba | 2906 | case DW_FORM_line_strp: |
50ea0877 | 2907 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue), cu_offset); |
d85bf2ba NC |
2908 | break; |
2909 | case DW_FORM_GNU_str_index: | |
32e4f96c TV |
2910 | case DW_FORM_strx: |
2911 | case DW_FORM_strx1: | |
2912 | case DW_FORM_strx2: | |
2913 | case DW_FORM_strx3: | |
2914 | case DW_FORM_strx4: | |
015dc7e1 | 2915 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset); |
d85bf2ba NC |
2916 | break; |
2917 | case DW_FORM_string: | |
50ea0877 | 2918 | add_dwo_dir ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
2919 | break; |
2920 | default: | |
2921 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2922 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2923 | break; |
2924 | } | |
2925 | break; | |
521d4b19 | 2926 | |
d85bf2ba NC |
2927 | case DW_AT_GNU_dwo_id: |
2928 | if (need_dwo_info) | |
2929 | switch (form) | |
2930 | { | |
2931 | case DW_FORM_data8: | |
24841daa | 2932 | /* FIXME: Record the length of the ID as well ? */ |
50ea0877 | 2933 | add_dwo_id ((const char *) (data - 8), cu_offset); |
d85bf2ba NC |
2934 | break; |
2935 | default: | |
2936 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2937 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2938 | break; |
2939 | } | |
2940 | break; | |
521d4b19 | 2941 | |
19e6b90e L |
2942 | default: |
2943 | break; | |
2944 | } | |
2945 | } | |
2946 | ||
4ccf1e31 | 2947 | if (do_loc || attribute == 0) |
19e6b90e L |
2948 | return data; |
2949 | ||
ec4d4525 | 2950 | /* For some attributes we can display further information. */ |
19e6b90e L |
2951 | switch (attribute) |
2952 | { | |
ec1b0fbb | 2953 | case DW_AT_type: |
b3fe587e AM |
2954 | if (level >= 0 && level < MAX_CU_NESTING |
2955 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb | 2956 | { |
015dc7e1 AM |
2957 | bool is_signed = false; |
2958 | abbrev_entry *type_abbrev; | |
2959 | unsigned char *type_data; | |
1b3892be | 2960 | abbrev_map *map; |
521d4b19 | 2961 | |
bcd213b2 | 2962 | type_abbrev = get_type_abbrev_from_form (form, uvalue, cu_offset, |
1b3892be | 2963 | section, NULL, &type_data, &map); |
bcd213b2 NC |
2964 | if (type_abbrev != NULL) |
2965 | { | |
1b3892be AM |
2966 | get_type_signedness (type_abbrev, section, type_data, |
2967 | map ? section->start + map->end : end, | |
2968 | map ? map->start : cu_offset, | |
bcd213b2 NC |
2969 | pointer_size, offset_size, dwarf_version, |
2970 | & is_signed, 0); | |
2971 | } | |
ec1b0fbb NC |
2972 | level_type_signed[level] = is_signed; |
2973 | } | |
2974 | break; | |
521d4b19 | 2975 | |
19e6b90e | 2976 | case DW_AT_inline: |
2e9e81a8 | 2977 | printf ("\t"); |
19e6b90e L |
2978 | switch (uvalue) |
2979 | { | |
2980 | case DW_INL_not_inlined: | |
2981 | printf (_("(not inlined)")); | |
2982 | break; | |
2983 | case DW_INL_inlined: | |
2984 | printf (_("(inlined)")); | |
2985 | break; | |
2986 | case DW_INL_declared_not_inlined: | |
2987 | printf (_("(declared as inline but ignored)")); | |
2988 | break; | |
2989 | case DW_INL_declared_inlined: | |
2990 | printf (_("(declared as inline and inlined)")); | |
2991 | break; | |
2992 | default: | |
47704ddf KT |
2993 | printf (_(" (Unknown inline attribute value: %s)"), |
2994 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2995 | break; |
2996 | } | |
2997 | break; | |
2998 | ||
2999 | case DW_AT_language: | |
2e9e81a8 | 3000 | printf ("\t"); |
19e6b90e L |
3001 | switch (uvalue) |
3002 | { | |
4b78141a | 3003 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 3004 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
3005 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
3006 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 3007 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
3008 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
3009 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
3010 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
3011 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 3012 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 3013 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 3014 | /* DWARF 2.1 values. */ |
4b78141a | 3015 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
3016 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
3017 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
3018 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
3019 | /* DWARF 3 values. */ |
3020 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
3021 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
3022 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
3023 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
3024 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
3025 | /* DWARF 4 values. */ |
3026 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 3027 | /* DWARF 5 values. */ |
2008a0db | 3028 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 3029 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
3030 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
3031 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
3032 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 3033 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
3034 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
3035 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 3036 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
3037 | case DW_LANG_Swift: printf ("(Swift)"); break; |
3038 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
3039 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 3040 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
3041 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
3042 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 3043 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
3044 | /* MIPS extension. */ |
3045 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
3046 | /* UPC extension. */ | |
3047 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
3048 | default: | |
4b78141a | 3049 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 3050 | printf (_("(implementation defined: %s)"), |
467c65bc | 3051 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 3052 | else |
9cf03b7e | 3053 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
3054 | break; |
3055 | } | |
3056 | break; | |
3057 | ||
3058 | case DW_AT_encoding: | |
2e9e81a8 | 3059 | printf ("\t"); |
19e6b90e L |
3060 | switch (uvalue) |
3061 | { | |
3062 | case DW_ATE_void: printf ("(void)"); break; | |
3063 | case DW_ATE_address: printf ("(machine address)"); break; | |
3064 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
3065 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
3066 | case DW_ATE_float: printf ("(float)"); break; | |
3067 | case DW_ATE_signed: printf ("(signed)"); break; | |
3068 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
3069 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
3070 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 3071 | /* DWARF 2.1 values: */ |
19e6b90e L |
3072 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
3073 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
3074 | /* DWARF 3 values: */ |
3075 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
3076 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
3077 | case DW_ATE_edited: printf ("(edited)"); break; | |
3078 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
3079 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
3080 | /* DWARF 4 values: */ |
3081 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
3082 | /* DWARF 5 values: */ | |
3083 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
3084 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
3085 | ||
e2a0d921 NC |
3086 | /* HP extensions: */ |
3087 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
3088 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
3089 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
3090 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
3091 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
3092 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
3093 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
3094 | ||
19e6b90e L |
3095 | default: |
3096 | if (uvalue >= DW_ATE_lo_user | |
3097 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 3098 | printf (_("(user defined type)")); |
19e6b90e | 3099 | else |
9cf03b7e | 3100 | printf (_("(unknown type)")); |
19e6b90e L |
3101 | break; |
3102 | } | |
3103 | break; | |
3104 | ||
3105 | case DW_AT_accessibility: | |
2e9e81a8 | 3106 | printf ("\t"); |
19e6b90e L |
3107 | switch (uvalue) |
3108 | { | |
3109 | case DW_ACCESS_public: printf ("(public)"); break; | |
3110 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
3111 | case DW_ACCESS_private: printf ("(private)"); break; | |
3112 | default: | |
9cf03b7e | 3113 | printf (_("(unknown accessibility)")); |
19e6b90e L |
3114 | break; |
3115 | } | |
3116 | break; | |
3117 | ||
3118 | case DW_AT_visibility: | |
2e9e81a8 | 3119 | printf ("\t"); |
19e6b90e L |
3120 | switch (uvalue) |
3121 | { | |
3122 | case DW_VIS_local: printf ("(local)"); break; | |
3123 | case DW_VIS_exported: printf ("(exported)"); break; | |
3124 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 3125 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
3126 | } |
3127 | break; | |
3128 | ||
04914e37 NC |
3129 | case DW_AT_endianity: |
3130 | printf ("\t"); | |
3131 | switch (uvalue) | |
3132 | { | |
3133 | case DW_END_default: printf ("(default)"); break; | |
3134 | case DW_END_big: printf ("(big)"); break; | |
3135 | case DW_END_little: printf ("(little)"); break; | |
3136 | default: | |
3137 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
3138 | printf (_("(user specified)")); | |
3139 | else | |
3140 | printf (_("(unknown endianity)")); | |
3141 | break; | |
3142 | } | |
3143 | break; | |
3144 | ||
19e6b90e | 3145 | case DW_AT_virtuality: |
2e9e81a8 | 3146 | printf ("\t"); |
19e6b90e L |
3147 | switch (uvalue) |
3148 | { | |
3149 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
3150 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
3151 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 3152 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
3153 | } |
3154 | break; | |
3155 | ||
3156 | case DW_AT_identifier_case: | |
2e9e81a8 | 3157 | printf ("\t"); |
19e6b90e L |
3158 | switch (uvalue) |
3159 | { | |
3160 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
3161 | case DW_ID_up_case: printf ("(up_case)"); break; | |
3162 | case DW_ID_down_case: printf ("(down_case)"); break; | |
3163 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 3164 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
3165 | } |
3166 | break; | |
3167 | ||
3168 | case DW_AT_calling_convention: | |
2e9e81a8 | 3169 | printf ("\t"); |
19e6b90e L |
3170 | switch (uvalue) |
3171 | { | |
3172 | case DW_CC_normal: printf ("(normal)"); break; | |
3173 | case DW_CC_program: printf ("(program)"); break; | |
3174 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
3175 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
3176 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
3177 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
3178 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
3179 | default: |
3180 | if (uvalue >= DW_CC_lo_user | |
3181 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 3182 | printf (_("(user defined)")); |
19e6b90e | 3183 | else |
9cf03b7e | 3184 | printf (_("(unknown convention)")); |
19e6b90e L |
3185 | } |
3186 | break; | |
3187 | ||
3188 | case DW_AT_ordering: | |
2e9e81a8 | 3189 | printf ("\t"); |
19e6b90e L |
3190 | switch (uvalue) |
3191 | { | |
04914e37 | 3192 | case 255: |
9cf03b7e | 3193 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
3194 | case 0: printf ("(row major)"); break; |
3195 | case 1: printf ("(column major)"); break; | |
3196 | } | |
3197 | break; | |
3198 | ||
04914e37 NC |
3199 | case DW_AT_decimal_sign: |
3200 | printf ("\t"); | |
3201 | switch (uvalue) | |
3202 | { | |
3203 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
3204 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
3205 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
3206 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
3207 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
3208 | default: printf (_("(unrecognised)")); break; | |
3209 | } | |
3210 | break; | |
3211 | ||
3212 | case DW_AT_defaulted: | |
3213 | printf ("\t"); | |
3214 | switch (uvalue) | |
3215 | { | |
3216 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
3217 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
3218 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
3219 | default: printf (_("(unrecognised)")); break; | |
3220 | } | |
3221 | break; | |
3222 | ||
3223 | case DW_AT_discr_list: | |
3224 | printf ("\t"); | |
ec1b0fbb | 3225 | display_discr_list (form, uvalue, data, end, level); |
04914e37 | 3226 | break; |
521d4b19 | 3227 | |
19e6b90e L |
3228 | case DW_AT_frame_base: |
3229 | have_frame_base = 1; | |
1a0670f3 | 3230 | /* Fall through. */ |
19e6b90e | 3231 | case DW_AT_location: |
e2a0d921 NC |
3232 | case DW_AT_string_length: |
3233 | case DW_AT_return_addr: | |
19e6b90e L |
3234 | case DW_AT_data_member_location: |
3235 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
3236 | case DW_AT_segment: |
3237 | case DW_AT_static_link: | |
3238 | case DW_AT_use_location: | |
bc0a77d2 | 3239 | case DW_AT_call_value: |
629e7ca8 | 3240 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 3241 | case DW_AT_call_data_value: |
629e7ca8 | 3242 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 3243 | case DW_AT_call_target: |
629e7ca8 | 3244 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 3245 | case DW_AT_call_target_clobbered: |
629e7ca8 | 3246 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 3247 | if ((dwarf_version < 4 |
b4eb7656 | 3248 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 3249 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 3250 | printf (_(" (location list)")); |
e2a0d921 | 3251 | /* Fall through. */ |
19e6b90e L |
3252 | case DW_AT_allocated: |
3253 | case DW_AT_associated: | |
3254 | case DW_AT_data_location: | |
3255 | case DW_AT_stride: | |
3256 | case DW_AT_upper_bound: | |
cecf136e | 3257 | case DW_AT_lower_bound: |
19e6b90e L |
3258 | if (block_start) |
3259 | { | |
3260 | int need_frame_base; | |
3261 | ||
2e9e81a8 | 3262 | printf ("\t("); |
19e6b90e L |
3263 | need_frame_base = decode_location_expression (block_start, |
3264 | pointer_size, | |
b7807392 JJ |
3265 | offset_size, |
3266 | dwarf_version, | |
19e6b90e | 3267 | uvalue, |
f1c4cc75 | 3268 | cu_offset, section); |
19e6b90e L |
3269 | printf (")"); |
3270 | if (need_frame_base && !have_frame_base) | |
3271 | printf (_(" [without DW_AT_frame_base]")); | |
3272 | } | |
19e6b90e L |
3273 | break; |
3274 | ||
c54207d3 NC |
3275 | case DW_AT_data_bit_offset: |
3276 | case DW_AT_byte_size: | |
3277 | case DW_AT_bit_size: | |
3278 | case DW_AT_string_length_byte_size: | |
3279 | case DW_AT_string_length_bit_size: | |
3280 | case DW_AT_bit_stride: | |
3281 | if (form == DW_FORM_exprloc) | |
3282 | { | |
3283 | printf ("\t("); | |
3284 | (void) decode_location_expression (block_start, pointer_size, | |
3285 | offset_size, dwarf_version, | |
3286 | uvalue, cu_offset, section); | |
3287 | printf (")"); | |
3288 | } | |
3289 | break; | |
3290 | ||
ec4d4525 NC |
3291 | case DW_AT_import: |
3292 | { | |
bcd213b2 NC |
3293 | unsigned long abbrev_number; |
3294 | abbrev_entry *entry; | |
2b6f5997 | 3295 | |
bcd213b2 NC |
3296 | entry = get_type_abbrev_from_form (form, uvalue, cu_offset, |
3297 | section, & abbrev_number, NULL, NULL); | |
3298 | if (entry == NULL) | |
3299 | { | |
3300 | if (form != DW_FORM_GNU_ref_alt) | |
3301 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), | |
3302 | dwarf_vmatoa ("x", uvalue), | |
3303 | (unsigned long) (orig_data - section->start)); | |
3304 | } | |
6e3d6dc1 NC |
3305 | else |
3306 | { | |
2e9e81a8 | 3307 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
bcd213b2 | 3308 | printf (" (%s)", get_TAG_name (entry->tag)); |
6e3d6dc1 NC |
3309 | printf ("]"); |
3310 | } | |
ec4d4525 NC |
3311 | } |
3312 | break; | |
3313 | ||
19e6b90e L |
3314 | default: |
3315 | break; | |
3316 | } | |
3317 | ||
3318 | return data; | |
3319 | } | |
3320 | ||
19e6b90e | 3321 | static unsigned char * |
dda8d76d NC |
3322 | read_and_display_attr (unsigned long attribute, |
3323 | unsigned long form, | |
3324 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 3325 | unsigned char * start, |
dda8d76d NC |
3326 | unsigned char * data, |
3327 | unsigned char * end, | |
3328 | dwarf_vma cu_offset, | |
3329 | dwarf_vma pointer_size, | |
3330 | dwarf_vma offset_size, | |
3331 | int dwarf_version, | |
3332 | debug_info * debug_info_p, | |
3333 | int do_loc, | |
3334 | struct dwarf_section * section, | |
ec1b0fbb NC |
3335 | struct cu_tu_set * this_set, |
3336 | int level) | |
19e6b90e L |
3337 | { |
3338 | if (!do_loc) | |
750f03b7 | 3339 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
3340 | data = read_and_display_attr_value (attribute, form, implicit_const, |
3341 | start, data, end, | |
f6f0e17b | 3342 | cu_offset, pointer_size, offset_size, |
19e6b90e | 3343 | dwarf_version, debug_info_p, |
ec1b0fbb | 3344 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
3345 | if (!do_loc) |
3346 | printf ("\n"); | |
3347 | return data; | |
3348 | } | |
3349 | ||
dda8d76d | 3350 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
3351 | following debug links, then attempt to load the requested section |
3352 | from one of the separate debug info files. */ | |
dda8d76d | 3353 | |
015dc7e1 | 3354 | static bool |
dda8d76d | 3355 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, |
24841daa | 3356 | void * handle) |
dda8d76d | 3357 | { |
24841daa | 3358 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3359 | { |
24841daa NC |
3360 | if (debug_displays[sec_enum].section.filename == NULL) |
3361 | { | |
3362 | /* See if we can associate a filename with this section. */ | |
3363 | separate_info * i; | |
3364 | ||
3365 | for (i = first_separate_info; i != NULL; i = i->next) | |
3366 | if (i->handle == handle) | |
3367 | { | |
3368 | debug_displays[sec_enum].section.filename = i->filename; | |
3369 | break; | |
3370 | } | |
3371 | } | |
3372 | ||
015dc7e1 | 3373 | return true; |
dda8d76d NC |
3374 | } |
3375 | ||
24841daa NC |
3376 | if (do_follow_links) |
3377 | { | |
3378 | separate_info * i; | |
3379 | ||
3380 | for (i = first_separate_info; i != NULL; i = i->next) | |
3381 | { | |
3382 | if (load_debug_section (sec_enum, i->handle)) | |
3383 | { | |
3384 | debug_displays[sec_enum].section.filename = i->filename; | |
3385 | ||
3386 | /* FIXME: We should check to see if any of the remaining debug info | |
3387 | files also contain this section, and, umm, do something about it. */ | |
015dc7e1 | 3388 | return true; |
24841daa NC |
3389 | } |
3390 | } | |
3391 | } | |
dda8d76d | 3392 | |
015dc7e1 | 3393 | return false; |
dda8d76d NC |
3394 | } |
3395 | ||
3396 | static void | |
015dc7e1 | 3397 | introduce (struct dwarf_section * section, bool raw) |
dda8d76d NC |
3398 | { |
3399 | if (raw) | |
3400 | { | |
3401 | if (do_follow_links && section->filename) | |
3402 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3403 | section->name, section->filename); | |
3404 | else | |
3405 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3406 | } | |
3407 | else | |
3408 | { | |
3409 | if (do_follow_links && section->filename) | |
3410 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3411 | section->name, section->filename); | |
3412 | else | |
3413 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3414 | } | |
3415 | } | |
521d4b19 | 3416 | |
d85bf2ba NC |
3417 | /* Process the contents of a .debug_info section. |
3418 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3419 | and we do not want to display anything to the user. | |
3420 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3421 | a .debug_info section. | |
3422 | The information displayed is restricted by the values in DWARF_START_DIE | |
3423 | and DWARF_CUTOFF_LEVEL. | |
3424 | Returns TRUE upon success. Otherwise an error or warning message is | |
3425 | printed and FALSE is returned. */ | |
19e6b90e | 3426 | |
015dc7e1 AM |
3427 | static bool |
3428 | process_debug_info (struct dwarf_section * section, | |
3429 | void *file, | |
3430 | enum dwarf_section_display_enum abbrev_sec, | |
3431 | bool do_loc, | |
3432 | bool do_types) | |
19e6b90e L |
3433 | { |
3434 | unsigned char *start = section->start; | |
3435 | unsigned char *end = start + section->size; | |
3436 | unsigned char *section_begin; | |
3437 | unsigned int unit; | |
3438 | unsigned int num_units = 0; | |
3439 | ||
edba4e4a AM |
3440 | /* First scan the section to get the number of comp units. |
3441 | Length sanity checks are done here. */ | |
3442 | for (section_begin = start, num_units = 0; section_begin < end; | |
3443 | num_units ++) | |
19e6b90e | 3444 | { |
767221a9 | 3445 | dwarf_vma length; |
19e6b90e | 3446 | |
edba4e4a AM |
3447 | /* Read the first 4 bytes. For a 32-bit DWARF section, this |
3448 | will be the length. For a 64-bit DWARF section, it'll be | |
3449 | the escape code 0xffffffff followed by an 8 byte length. */ | |
3450 | SAFE_BYTE_GET_AND_INC (length, section_begin, 4, end); | |
aca88567 | 3451 | |
edba4e4a AM |
3452 | if (length == 0xffffffff) |
3453 | SAFE_BYTE_GET_AND_INC (length, section_begin, 8, end); | |
3454 | else if (length >= 0xfffffff0 && length < 0xffffffff) | |
3455 | { | |
3456 | warn (_("Reserved length value (0x%s) found in section %s\n"), | |
3457 | dwarf_vmatoa ("x", length), section->name); | |
3458 | return false; | |
19e6b90e L |
3459 | } |
3460 | ||
edba4e4a AM |
3461 | /* Negative values are illegal, they may even cause infinite |
3462 | looping. This can happen if we can't accurately apply | |
3463 | relocations to an object file, or if the file is corrupt. */ | |
3464 | if (length > (size_t) (end - section_begin)) | |
19e6b90e | 3465 | { |
edba4e4a AM |
3466 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3467 | dwarf_vmatoa ("x", length), section->name); | |
015dc7e1 | 3468 | return false; |
19e6b90e | 3469 | } |
edba4e4a AM |
3470 | section_begin += length; |
3471 | } | |
3472 | ||
3473 | if (num_units == 0) | |
3474 | { | |
3475 | error (_("No comp units in %s section ?\n"), section->name); | |
3476 | return false; | |
3477 | } | |
3478 | ||
3479 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
3480 | && num_debug_info_entries == 0 | |
3481 | && ! do_types) | |
3482 | { | |
19e6b90e L |
3483 | |
3484 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3485 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3486 | sizeof (* debug_information)); |
19e6b90e L |
3487 | if (debug_information == NULL) |
3488 | { | |
f41e4712 | 3489 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3490 | num_units); |
82b1b41b | 3491 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
015dc7e1 | 3492 | return false; |
19e6b90e | 3493 | } |
d85bf2ba | 3494 | |
03a91817 NC |
3495 | /* PR 17531: file: 92ca3797. |
3496 | We cannot rely upon the debug_information array being initialised | |
3497 | before it is used. A corrupt file could easily contain references | |
3498 | to a unit for which information has not been made available. So | |
3499 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3500 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3501 | ||
82b1b41b | 3502 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3503 | } |
3504 | ||
3505 | if (!do_loc) | |
3506 | { | |
dda8d76d NC |
3507 | load_debug_section_with_follow (str, file); |
3508 | load_debug_section_with_follow (line_str, file); | |
3509 | load_debug_section_with_follow (str_dwo, file); | |
3510 | load_debug_section_with_follow (str_index, file); | |
3511 | load_debug_section_with_follow (str_index_dwo, file); | |
3512 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e | 3513 | } |
521d4b19 | 3514 | |
dda8d76d | 3515 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3516 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3517 | { |
3518 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3519 | debug_displays [abbrev_sec].section.uncompressed_name); |
015dc7e1 | 3520 | return false; |
19e6b90e L |
3521 | } |
3522 | ||
dda8d76d | 3523 | if (!do_loc && dwarf_start_die == 0) |
015dc7e1 | 3524 | introduce (section, false); |
bcd213b2 NC |
3525 | |
3526 | free_all_abbrevs (); | |
3527 | free (cu_abbrev_map); | |
3528 | cu_abbrev_map = NULL; | |
3529 | next_free_abbrev_map_entry = 0; | |
521d4b19 | 3530 | |
bcd213b2 NC |
3531 | /* In order to be able to resolve DW_FORM_ref_attr forms we need |
3532 | to load *all* of the abbrevs for all CUs in this .debug_info | |
3533 | section. This does effectively mean that we (partially) read | |
3534 | every CU header twice. */ | |
3535 | for (section_begin = start; start < end;) | |
3536 | { | |
3537 | DWARF2_Internal_CompUnit compunit; | |
3538 | unsigned char * hdrptr; | |
76868f36 L |
3539 | dwarf_vma abbrev_base; |
3540 | size_t abbrev_size; | |
bcd213b2 NC |
3541 | dwarf_vma cu_offset; |
3542 | unsigned int offset_size; | |
bcd213b2 NC |
3543 | struct cu_tu_set * this_set; |
3544 | abbrev_list * list; | |
edba4e4a | 3545 | unsigned char *end_cu; |
bcd213b2 NC |
3546 | |
3547 | hdrptr = start; | |
edba4e4a | 3548 | cu_offset = start - section_begin; |
bcd213b2 NC |
3549 | |
3550 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); | |
3551 | ||
3552 | if (compunit.cu_length == 0xffffffff) | |
3553 | { | |
3554 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); | |
3555 | offset_size = 8; | |
bcd213b2 NC |
3556 | } |
3557 | else | |
edba4e4a AM |
3558 | offset_size = 4; |
3559 | end_cu = hdrptr + compunit.cu_length; | |
bcd213b2 | 3560 | |
edba4e4a | 3561 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu); |
bcd213b2 NC |
3562 | |
3563 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); | |
3564 | ||
3565 | if (compunit.cu_version < 5) | |
3566 | { | |
3567 | compunit.cu_unit_type = DW_UT_compile; | |
3568 | /* Initialize it due to a false compiler warning. */ | |
3569 | compunit.cu_pointer_size = -1; | |
3570 | } | |
3571 | else | |
3572 | { | |
edba4e4a | 3573 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu); |
bcd213b2 NC |
3574 | do_types = (compunit.cu_unit_type == DW_UT_type); |
3575 | ||
edba4e4a | 3576 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
bcd213b2 NC |
3577 | } |
3578 | ||
edba4e4a AM |
3579 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, |
3580 | end_cu); | |
bcd213b2 | 3581 | |
9b87f84a TV |
3582 | if (compunit.cu_unit_type == DW_UT_split_compile |
3583 | || compunit.cu_unit_type == DW_UT_skeleton) | |
3584 | { | |
3585 | uint64_t dwo_id; | |
edba4e4a | 3586 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu); |
9b87f84a TV |
3587 | } |
3588 | ||
76868f36 L |
3589 | if (this_set == NULL) |
3590 | { | |
3591 | abbrev_base = 0; | |
3592 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3593 | } | |
3594 | else | |
3595 | { | |
3596 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3597 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3598 | } | |
3599 | ||
3600 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, | |
3601 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3602 | if (list == NULL) |
3603 | { | |
bcd213b2 NC |
3604 | unsigned char * next; |
3605 | ||
76868f36 L |
3606 | list = new_abbrev_list (abbrev_base, |
3607 | compunit.cu_abbrev_offset); | |
f2f9554b AM |
3608 | next = process_abbrev_set (&debug_displays[abbrev_sec].section, |
3609 | abbrev_base, abbrev_size, | |
3610 | compunit.cu_abbrev_offset, list); | |
bcd213b2 NC |
3611 | list->start_of_next_abbrevs = next; |
3612 | } | |
521d4b19 | 3613 | |
edba4e4a | 3614 | start = end_cu; |
bcd213b2 NC |
3615 | record_abbrev_list_for_cu (cu_offset, start - section_begin, list); |
3616 | } | |
3617 | ||
3618 | for (start = section_begin, unit = 0; start < end; unit++) | |
19e6b90e L |
3619 | { |
3620 | DWARF2_Internal_CompUnit compunit; | |
3621 | unsigned char *hdrptr; | |
19e6b90e | 3622 | unsigned char *tags; |
fd2f0033 | 3623 | int level, last_level, saved_level; |
467c65bc | 3624 | dwarf_vma cu_offset; |
bf5117e3 | 3625 | unsigned int offset_size; |
af2ddf69 | 3626 | dwarf_vma signature = 0; |
767221a9 | 3627 | dwarf_vma type_offset = 0; |
341f9135 CC |
3628 | struct cu_tu_set *this_set; |
3629 | dwarf_vma abbrev_base; | |
3630 | size_t abbrev_size; | |
bcd213b2 | 3631 | abbrev_list * list = NULL; |
edba4e4a | 3632 | unsigned char *end_cu; |
19e6b90e L |
3633 | |
3634 | hdrptr = start; | |
edba4e4a | 3635 | cu_offset = start - section_begin; |
19e6b90e | 3636 | |
0c588247 | 3637 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3638 | |
3639 | if (compunit.cu_length == 0xffffffff) | |
3640 | { | |
0c588247 | 3641 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e | 3642 | offset_size = 8; |
19e6b90e L |
3643 | } |
3644 | else | |
edba4e4a AM |
3645 | offset_size = 4; |
3646 | end_cu = hdrptr + compunit.cu_length; | |
19e6b90e | 3647 | |
edba4e4a | 3648 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu); |
19e6b90e | 3649 | |
341f9135 CC |
3650 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3651 | ||
77145576 JK |
3652 | if (compunit.cu_version < 5) |
3653 | { | |
3654 | compunit.cu_unit_type = DW_UT_compile; | |
3655 | /* Initialize it due to a false compiler warning. */ | |
3656 | compunit.cu_pointer_size = -1; | |
3657 | } | |
3658 | else | |
3659 | { | |
edba4e4a | 3660 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu); |
77145576 JK |
3661 | do_types = (compunit.cu_unit_type == DW_UT_type); |
3662 | ||
edba4e4a | 3663 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
77145576 JK |
3664 | } |
3665 | ||
edba4e4a | 3666 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end_cu); |
19e6b90e | 3667 | |
341f9135 CC |
3668 | if (this_set == NULL) |
3669 | { | |
3670 | abbrev_base = 0; | |
3671 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3672 | } | |
3673 | else | |
3674 | { | |
3675 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3676 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3677 | } | |
3678 | ||
77145576 | 3679 | if (compunit.cu_version < 5) |
edba4e4a | 3680 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu); |
77145576 | 3681 | |
015dc7e1 | 3682 | bool do_dwo_id = false; |
e6ca1878 | 3683 | uint64_t dwo_id = 0; |
9b87f84a TV |
3684 | if (compunit.cu_unit_type == DW_UT_split_compile |
3685 | || compunit.cu_unit_type == DW_UT_skeleton) | |
3686 | { | |
edba4e4a | 3687 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu); |
015dc7e1 | 3688 | do_dwo_id = true; |
9b87f84a TV |
3689 | } |
3690 | ||
f41e4712 NC |
3691 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3692 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3693 | { | |
3694 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3695 | compunit.cu_pointer_size, offset_size); | |
3696 | compunit.cu_pointer_size = offset_size; | |
3697 | } | |
2b6f5997 CC |
3698 | |
3699 | if (do_types) | |
b4eb7656 | 3700 | { |
edba4e4a AM |
3701 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, end_cu); |
3702 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end_cu); | |
b4eb7656 | 3703 | } |
2b6f5997 | 3704 | |
edba4e4a | 3705 | if (dwarf_start_die >= (size_t) (end_cu - section_begin)) |
ae7e7825 | 3706 | { |
edba4e4a | 3707 | start = end_cu; |
ae7e7825 NC |
3708 | continue; |
3709 | } | |
3710 | ||
19e6b90e | 3711 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 | 3712 | && num_debug_info_entries == 0 |
c4b2f181 | 3713 | && alloc_num_debug_info_entries > unit |
2b6f5997 | 3714 | && ! do_types) |
19e6b90e L |
3715 | { |
3716 | debug_information [unit].cu_offset = cu_offset; | |
3717 | debug_information [unit].pointer_size | |
3718 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3719 | debug_information [unit].offset_size = offset_size; |
3720 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3721 | debug_information [unit].base_address = 0; |
4723351a CC |
3722 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3723 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3724 | debug_information [unit].loc_offsets = NULL; |
3725 | debug_information [unit].have_frame_base = NULL; | |
3726 | debug_information [unit].max_loc_offsets = 0; | |
3727 | debug_information [unit].num_loc_offsets = 0; | |
3728 | debug_information [unit].range_lists = NULL; | |
3729 | debug_information [unit].max_range_lists= 0; | |
3730 | debug_information [unit].num_range_lists = 0; | |
3731 | } | |
3732 | ||
fd2f0033 | 3733 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3734 | { |
47704ddf KT |
3735 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3736 | dwarf_vmatoa ("x", cu_offset)); | |
3737 | printf (_(" Length: 0x%s (%s)\n"), | |
3738 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3739 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3740 | printf (_(" Version: %d\n"), compunit.cu_version); |
debd1a62 | 3741 | if (compunit.cu_version >= 5) |
4896932e MF |
3742 | { |
3743 | const char *name = get_DW_UT_name (compunit.cu_unit_type); | |
3744 | ||
3745 | printf (_(" Unit Type: %s (%x)\n"), | |
3746 | name ? name : "???", | |
3747 | compunit.cu_unit_type); | |
3748 | } | |
7282333f AM |
3749 | printf (_(" Abbrev Offset: 0x%s\n"), |
3750 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3751 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3752 | if (do_types) |
3753 | { | |
74bc6052 | 3754 | printf (_(" Signature: 0x%s\n"), |
af2ddf69 | 3755 | dwarf_vmatoa ("x", signature)); |
74bc6052 CC |
3756 | printf (_(" Type Offset: 0x%s\n"), |
3757 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3758 | } |
d60f7998 TV |
3759 | if (do_dwo_id) |
3760 | printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id)); | |
341f9135 CC |
3761 | if (this_set != NULL) |
3762 | { | |
3763 | dwarf_vma *offsets = this_set->section_offsets; | |
3764 | size_t *sizes = this_set->section_sizes; | |
3765 | ||
3766 | printf (_(" Section contributions:\n")); | |
3767 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3768 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3769 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3770 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3771 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3772 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3773 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3774 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3775 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3776 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3777 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3778 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3779 | } | |
19e6b90e L |
3780 | } |
3781 | ||
460c89ff | 3782 | tags = hdrptr; |
edba4e4a | 3783 | start = end_cu; |
460c89ff | 3784 | |
77145576 | 3785 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3786 | { |
47704ddf KT |
3787 | warn (_("CU at offset %s contains corrupt or " |
3788 | "unsupported version number: %d.\n"), | |
3789 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3790 | continue; |
3791 | } | |
3792 | ||
77145576 | 3793 | if (compunit.cu_unit_type != DW_UT_compile |
ec47b32a | 3794 | && compunit.cu_unit_type != DW_UT_partial |
9b87f84a TV |
3795 | && compunit.cu_unit_type != DW_UT_type |
3796 | && compunit.cu_unit_type != DW_UT_split_compile | |
3797 | && compunit.cu_unit_type != DW_UT_skeleton) | |
77145576 JK |
3798 | { |
3799 | warn (_("CU at offset %s contains corrupt or " | |
3800 | "unsupported unit type: %d.\n"), | |
3801 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3802 | continue; | |
3803 | } | |
3804 | ||
d493b283 | 3805 | /* Process the abbrevs used by this compilation unit. */ |
f2f9554b AM |
3806 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, |
3807 | compunit.cu_abbrev_offset); | |
3808 | if (list == NULL) | |
bcd213b2 | 3809 | { |
f2f9554b AM |
3810 | unsigned char *next; |
3811 | ||
3812 | list = new_abbrev_list (abbrev_base, | |
3813 | compunit.cu_abbrev_offset); | |
3814 | next = process_abbrev_set (&debug_displays[abbrev_sec].section, | |
3815 | abbrev_base, abbrev_size, | |
3816 | compunit.cu_abbrev_offset, list); | |
3817 | list->start_of_next_abbrevs = next; | |
bcd213b2 | 3818 | } |
19e6b90e L |
3819 | |
3820 | level = 0; | |
fd2f0033 TT |
3821 | last_level = level; |
3822 | saved_level = -1; | |
19e6b90e L |
3823 | while (tags < start) |
3824 | { | |
19e6b90e | 3825 | unsigned long abbrev_number; |
ec4d4525 | 3826 | unsigned long die_offset; |
19e6b90e L |
3827 | abbrev_entry *entry; |
3828 | abbrev_attr *attr; | |
fd2f0033 | 3829 | int do_printing = 1; |
19e6b90e | 3830 | |
ec4d4525 NC |
3831 | die_offset = tags - section_begin; |
3832 | ||
cd30bcef | 3833 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 3834 | |
eb7cc021 JK |
3835 | /* A null DIE marks the end of a list of siblings or it may also be |
3836 | a section padding. */ | |
19e6b90e L |
3837 | if (abbrev_number == 0) |
3838 | { | |
eb7cc021 JK |
3839 | /* Check if it can be a section padding for the last CU. */ |
3840 | if (level == 0 && start == end) | |
3841 | { | |
3842 | unsigned char *chk; | |
3843 | ||
3844 | for (chk = tags; chk < start; chk++) | |
3845 | if (*chk != 0) | |
3846 | break; | |
3847 | if (chk == start) | |
3848 | break; | |
3849 | } | |
3850 | ||
4337774f TT |
3851 | if (!do_loc && die_offset >= dwarf_start_die |
3852 | && (dwarf_cutoff_level == -1 | |
3853 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3854 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3855 | level, die_offset); | |
3856 | ||
19e6b90e | 3857 | --level; |
ec4d4525 NC |
3858 | if (level < 0) |
3859 | { | |
3860 | static unsigned num_bogus_warns = 0; | |
3861 | ||
3862 | if (num_bogus_warns < 3) | |
3863 | { | |
4723351a CC |
3864 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3865 | die_offset, section->name); | |
ec4d4525 NC |
3866 | num_bogus_warns ++; |
3867 | if (num_bogus_warns == 3) | |
3868 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3869 | } | |
3870 | } | |
fd2f0033 | 3871 | if (dwarf_start_die != 0 && level < saved_level) |
015dc7e1 | 3872 | return true; |
19e6b90e L |
3873 | continue; |
3874 | } | |
3875 | ||
4b78141a | 3876 | if (!do_loc) |
fd2f0033 TT |
3877 | { |
3878 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3879 | do_printing = 0; | |
3880 | else | |
3881 | { | |
3882 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3883 | saved_level = level; | |
3884 | do_printing = (dwarf_cutoff_level == -1 | |
3885 | || level < dwarf_cutoff_level); | |
3886 | if (do_printing) | |
3887 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3888 | level, die_offset, abbrev_number); | |
3889 | else if (dwarf_cutoff_level == -1 | |
3890 | || last_level < dwarf_cutoff_level) | |
3891 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3892 | last_level = level; | |
3893 | } | |
3894 | } | |
cecf136e | 3895 | |
19e6b90e L |
3896 | /* Scan through the abbreviation list until we reach the |
3897 | correct entry. */ | |
bcd213b2 | 3898 | if (list == NULL) |
19e6b90e L |
3899 | continue; |
3900 | ||
bcd213b2 NC |
3901 | for (entry = list->first_abbrev; entry != NULL; entry = entry->next) |
3902 | if (entry->number == abbrev_number) | |
3903 | break; | |
3904 | ||
19e6b90e L |
3905 | if (entry == NULL) |
3906 | { | |
fd2f0033 | 3907 | if (!do_loc && do_printing) |
4b78141a NC |
3908 | { |
3909 | printf ("\n"); | |
3910 | fflush (stdout); | |
3911 | } | |
f3853b34 | 3912 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3913 | die_offset, abbrev_number); |
015dc7e1 | 3914 | return false; |
19e6b90e L |
3915 | } |
3916 | ||
fd2f0033 | 3917 | if (!do_loc && do_printing) |
cc5914eb | 3918 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3919 | |
19e6b90e L |
3920 | switch (entry->tag) |
3921 | { | |
3922 | default: | |
3923 | need_base_address = 0; | |
3924 | break; | |
3925 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3926 | need_base_address = 1; |
3927 | need_dwo_info = do_loc; | |
19e6b90e L |
3928 | break; |
3929 | case DW_TAG_entry_point: | |
19e6b90e L |
3930 | case DW_TAG_subprogram: |
3931 | need_base_address = 0; | |
3932 | /* Assuming that there is no DW_AT_frame_base. */ | |
3933 | have_frame_base = 0; | |
3934 | break; | |
3935 | } | |
3936 | ||
9f272209 AO |
3937 | debug_info *debug_info_p = |
3938 | (debug_information && unit < alloc_num_debug_info_entries) | |
3939 | ? debug_information + unit : NULL; | |
3940 | ||
3941 | assert (!debug_info_p | |
3942 | || (debug_info_p->num_loc_offsets | |
3943 | == debug_info_p->num_loc_views)); | |
3944 | ||
399c99f7 L |
3945 | for (attr = entry->first_attr; |
3946 | attr && attr->attribute; | |
3947 | attr = attr->next) | |
4b78141a | 3948 | { |
fd2f0033 | 3949 | if (! do_loc && do_printing) |
4b78141a | 3950 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 3951 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
3952 | tags = read_and_display_attr (attr->attribute, |
3953 | attr->form, | |
77145576 | 3954 | attr->implicit_const, |
ec1b0fbb | 3955 | section_begin, |
341f9135 | 3956 | tags, |
edba4e4a | 3957 | start, |
341f9135 | 3958 | cu_offset, |
4b78141a NC |
3959 | compunit.cu_pointer_size, |
3960 | offset_size, | |
3961 | compunit.cu_version, | |
9f272209 | 3962 | debug_info_p, |
341f9135 CC |
3963 | do_loc || ! do_printing, |
3964 | section, | |
ec1b0fbb NC |
3965 | this_set, |
3966 | level); | |
4b78141a | 3967 | } |
cecf136e | 3968 | |
9f272209 AO |
3969 | /* If a locview attribute appears before a location one, |
3970 | make sure we don't associate it with an earlier | |
3971 | loclist. */ | |
3972 | if (debug_info_p) | |
3973 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3974 | { | |
3975 | case 1: | |
3976 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3977 | debug_info_p->num_loc_views++; | |
3978 | assert (debug_info_p->num_loc_views | |
3979 | == debug_info_p->num_loc_offsets); | |
3980 | break; | |
3981 | ||
3982 | case 0: | |
3983 | break; | |
3984 | ||
3985 | case -1: | |
3986 | warn(_("DIE has locviews without loclist\n")); | |
3987 | debug_info_p->num_loc_views--; | |
3988 | break; | |
3989 | ||
3990 | default: | |
3991 | assert (0); | |
3992 | } | |
3993 | ||
b4eb7656 AM |
3994 | if (entry->children) |
3995 | ++level; | |
3996 | } | |
19e6b90e | 3997 | } |
cecf136e | 3998 | |
19e6b90e L |
3999 | /* Set num_debug_info_entries here so that it can be used to check if |
4000 | we need to process .debug_loc and .debug_ranges sections. */ | |
4001 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
4002 | && num_debug_info_entries == 0 |
4003 | && ! do_types) | |
82b1b41b | 4004 | { |
b4eb7656 | 4005 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
4006 | num_debug_info_entries = alloc_num_debug_info_entries; |
4007 | else | |
4008 | num_debug_info_entries = num_units; | |
4009 | } | |
cecf136e | 4010 | |
19e6b90e | 4011 | if (!do_loc) |
467c65bc | 4012 | printf ("\n"); |
cecf136e | 4013 | |
015dc7e1 | 4014 | return true; |
19e6b90e L |
4015 | } |
4016 | ||
4017 | /* Locate and scan the .debug_info section in the file and record the pointer | |
4018 | sizes and offsets for the compilation units in it. Usually an executable | |
4019 | will have just one pointer size, but this is not guaranteed, and so we try | |
4020 | not to make any assumptions. Returns zero upon failure, or the number of | |
4021 | compilation units upon success. */ | |
4022 | ||
4023 | static unsigned int | |
4024 | load_debug_info (void * file) | |
4025 | { | |
1febe64d | 4026 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 4027 | section then do not bother to repeat the task. */ |
cc86f28f | 4028 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
4029 | return 0; |
4030 | ||
19e6b90e L |
4031 | /* If we already have the information there is nothing else to do. */ |
4032 | if (num_debug_info_entries > 0) | |
4033 | return num_debug_info_entries; | |
4034 | ||
341f9135 | 4035 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 4036 | (void) load_cu_tu_indexes (file); |
341f9135 | 4037 | |
dda8d76d | 4038 | if (load_debug_section_with_follow (info, file) |
015dc7e1 | 4039 | && process_debug_info (&debug_displays [info].section, file, abbrev, true, false)) |
19e6b90e | 4040 | return num_debug_info_entries; |
82b1b41b | 4041 | |
dda8d76d | 4042 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 4043 | && process_debug_info (&debug_displays [info_dwo].section, file, |
015dc7e1 | 4044 | abbrev_dwo, true, false)) |
4723351a | 4045 | return num_debug_info_entries; |
1febe64d | 4046 | |
cc86f28f | 4047 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 4048 | return 0; |
19e6b90e L |
4049 | } |
4050 | ||
b40bf0a2 NC |
4051 | /* Read a DWARF .debug_line section header starting at DATA. |
4052 | Upon success returns an updated DATA pointer and the LINFO | |
4053 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
4054 | Otherwise returns NULL. */ | |
19e6b90e | 4055 | |
b40bf0a2 NC |
4056 | static unsigned char * |
4057 | read_debug_line_header (struct dwarf_section * section, | |
4058 | unsigned char * data, | |
4059 | unsigned char * end, | |
4060 | DWARF2_Internal_LineInfo * linfo, | |
4061 | unsigned char ** end_of_sequence) | |
4062 | { | |
4063 | unsigned char *hdrptr; | |
19e6b90e | 4064 | |
b40bf0a2 NC |
4065 | /* Extract information from the Line Number Program Header. |
4066 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 4067 | hdrptr = data; |
19e6b90e | 4068 | |
b40bf0a2 NC |
4069 | /* Get and check the length of the block. */ |
4070 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 4071 | |
b40bf0a2 | 4072 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
4073 | { |
4074 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 4075 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 4076 | linfo->li_offset_size = 8; |
f41e4712 NC |
4077 | } |
4078 | else | |
37195e23 | 4079 | linfo->li_offset_size = 4; |
19e6b90e | 4080 | |
37195e23 | 4081 | if (linfo->li_length > (size_t) (end - hdrptr)) |
f41e4712 | 4082 | { |
8fcc61b4 NC |
4083 | /* If the length field has a relocation against it, then we should |
4084 | not complain if it is inaccurate (and probably negative). This | |
4085 | happens in object files when the .debug_line section is actually | |
4086 | comprised of several different .debug_line.* sections, (some of | |
4087 | which may be removed by linker garbage collection), and a relocation | |
4088 | is used to compute the correct length once that is done. */ | |
77145576 | 4089 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 4090 | { |
37195e23 | 4091 | linfo->li_length = end - hdrptr; |
b40bf0a2 NC |
4092 | } |
4093 | else | |
4094 | { | |
8fcc61b4 NC |
4095 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
4096 | (long) linfo->li_length); | |
b40bf0a2 NC |
4097 | return NULL; |
4098 | } | |
f41e4712 | 4099 | } |
37195e23 | 4100 | end = hdrptr + linfo->li_length; |
19e6b90e | 4101 | |
b40bf0a2 NC |
4102 | /* Get and check the version number. */ |
4103 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
4104 | ||
4105 | if (linfo->li_version != 2 | |
4106 | && linfo->li_version != 3 | |
77145576 JK |
4107 | && linfo->li_version != 4 |
4108 | && linfo->li_version != 5) | |
f41e4712 | 4109 | { |
77145576 JK |
4110 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
4111 | "is currently supported.\n")); | |
b40bf0a2 | 4112 | return NULL; |
f41e4712 | 4113 | } |
19e6b90e | 4114 | |
77145576 JK |
4115 | if (linfo->li_version >= 5) |
4116 | { | |
5496f3c6 | 4117 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
77145576 | 4118 | |
5496f3c6 NC |
4119 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
4120 | if (linfo->li_segment_size != 0) | |
77145576 JK |
4121 | { |
4122 | warn (_("The %s section contains " | |
4123 | "unsupported segment selector size: %d.\n"), | |
5496f3c6 NC |
4124 | section->name, linfo->li_segment_size); |
4125 | return NULL; | |
77145576 JK |
4126 | } |
4127 | } | |
4128 | ||
4129 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
4130 | linfo->li_offset_size, end); | |
b40bf0a2 | 4131 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 4132 | |
b40bf0a2 | 4133 | if (linfo->li_version >= 4) |
f41e4712 | 4134 | { |
b40bf0a2 | 4135 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 4136 | |
b40bf0a2 | 4137 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
4138 | { |
4139 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 4140 | return NULL; |
a233b20c | 4141 | } |
f41e4712 NC |
4142 | } |
4143 | else | |
b40bf0a2 | 4144 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 4145 | |
b40bf0a2 | 4146 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 4147 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
4148 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
4149 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 4150 | |
37195e23 | 4151 | *end_of_sequence = end; |
b40bf0a2 NC |
4152 | return hdrptr; |
4153 | } | |
19e6b90e | 4154 | |
77145576 | 4155 | static unsigned char * |
015dc7e1 AM |
4156 | display_formatted_table (unsigned char *data, |
4157 | unsigned char *start, | |
4158 | unsigned char *end, | |
4159 | const DWARF2_Internal_LineInfo *linfo, | |
4160 | struct dwarf_section *section, | |
4161 | bool is_dir) | |
77145576 JK |
4162 | { |
4163 | unsigned char *format_start, format_count, *format, formati; | |
4164 | dwarf_vma data_count, datai; | |
cd30bcef | 4165 | unsigned int namepass, last_entry = 0; |
5496f3c6 | 4166 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
521d4b19 | 4167 | |
77145576 | 4168 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
546cb2d8 NC |
4169 | if (do_checks && format_count > 5) |
4170 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), | |
4171 | table_name, format_count); | |
4172 | ||
77145576 JK |
4173 | format_start = data; |
4174 | for (formati = 0; formati < format_count; formati++) | |
4175 | { | |
cd30bcef AM |
4176 | SKIP_ULEB (data, end); |
4177 | SKIP_ULEB (data, end); | |
55b26492 | 4178 | if (data >= end) |
77145576 | 4179 | { |
5496f3c6 | 4180 | warn (_("%s: Corrupt format description entry\n"), table_name); |
77145576 JK |
4181 | return data; |
4182 | } | |
4183 | } | |
4184 | ||
cd30bcef | 4185 | READ_ULEB (data_count, data, end); |
546cb2d8 | 4186 | if (data_count == 0) |
77145576 | 4187 | { |
546cb2d8 | 4188 | printf (_("\n The %s is empty.\n"), table_name); |
77145576 JK |
4189 | return data; |
4190 | } | |
55b26492 | 4191 | else if (data >= end) |
77145576 | 4192 | { |
546cb2d8 NC |
4193 | warn (_("%s: Corrupt entry count - expected %s but none found\n"), |
4194 | table_name, dwarf_vmatoa ("x", data_count)); | |
77145576 JK |
4195 | return data; |
4196 | } | |
546cb2d8 | 4197 | |
5496f3c6 NC |
4198 | else if (format_count == 0) |
4199 | { | |
4200 | warn (_("%s: format count is zero, but the table is not empty\n"), | |
4201 | table_name); | |
4202 | return end; | |
4203 | } | |
77145576 | 4204 | |
5496f3c6 NC |
4205 | printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"), |
4206 | table_name, (long) (data - start), dwarf_vmatoa ("u", data_count), | |
4207 | format_count); | |
77145576 JK |
4208 | |
4209 | printf (_(" Entry")); | |
521d4b19 | 4210 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4211 | for (namepass = 0; namepass < 2; namepass++) |
4212 | { | |
4213 | format = format_start; | |
4214 | for (formati = 0; formati < format_count; formati++) | |
4215 | { | |
4216 | dwarf_vma content_type; | |
4217 | ||
cd30bcef | 4218 | READ_ULEB (content_type, format, end); |
77145576 JK |
4219 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
4220 | switch (content_type) | |
4221 | { | |
4222 | case DW_LNCT_path: | |
4223 | printf (_("\tName")); | |
4224 | break; | |
4225 | case DW_LNCT_directory_index: | |
4226 | printf (_("\tDir")); | |
4227 | break; | |
4228 | case DW_LNCT_timestamp: | |
4229 | printf (_("\tTime")); | |
4230 | break; | |
4231 | case DW_LNCT_size: | |
4232 | printf (_("\tSize")); | |
4233 | break; | |
4234 | case DW_LNCT_MD5: | |
5496f3c6 | 4235 | printf (_("\tMD5\t\t\t")); |
77145576 JK |
4236 | break; |
4237 | default: | |
4238 | printf (_("\t(Unknown format content type %s)"), | |
4239 | dwarf_vmatoa ("u", content_type)); | |
4240 | } | |
cd30bcef | 4241 | SKIP_ULEB (format, end); |
77145576 JK |
4242 | } |
4243 | } | |
4244 | putchar ('\n'); | |
4245 | ||
4246 | for (datai = 0; datai < data_count; datai++) | |
4247 | { | |
4248 | unsigned char *datapass = data; | |
4249 | ||
4250 | printf (" %d", last_entry++); | |
521d4b19 | 4251 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4252 | for (namepass = 0; namepass < 2; namepass++) |
4253 | { | |
4254 | format = format_start; | |
4255 | data = datapass; | |
4256 | for (formati = 0; formati < format_count; formati++) | |
4257 | { | |
4258 | dwarf_vma content_type, form; | |
4259 | ||
cd30bcef AM |
4260 | READ_ULEB (content_type, format, end); |
4261 | READ_ULEB (form, format, end); | |
4262 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
4263 | 0, 0, linfo->li_offset_size, | |
77145576 JK |
4264 | linfo->li_version, NULL, |
4265 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 4266 | section, NULL, '\t', -1); |
77145576 JK |
4267 | } |
4268 | } | |
5496f3c6 | 4269 | |
55b26492 | 4270 | if (data >= end && (datai < data_count - 1)) |
77145576 | 4271 | { |
5496f3c6 | 4272 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
77145576 JK |
4273 | return data; |
4274 | } | |
4275 | putchar ('\n'); | |
4276 | } | |
4277 | return data; | |
4278 | } | |
4279 | ||
e38332c2 NC |
4280 | static int |
4281 | display_debug_sup (struct dwarf_section * section, | |
4282 | void * file ATTRIBUTE_UNUSED) | |
4283 | { | |
4284 | unsigned char * start = section->start; | |
4285 | unsigned char * end = section->start + section->size; | |
4286 | unsigned int version; | |
4287 | char is_supplementary; | |
4288 | const unsigned char * sup_filename; | |
4289 | size_t sup_filename_len; | |
4290 | unsigned int num_read; | |
4291 | int status; | |
4292 | dwarf_vma checksum_len; | |
4293 | ||
4294 | ||
015dc7e1 | 4295 | introduce (section, true); |
e38332c2 NC |
4296 | if (section->size < 4) |
4297 | { | |
4298 | error (_("corrupt .debug_sup section: size is too small\n")); | |
4299 | return 0; | |
4300 | } | |
4301 | ||
4302 | /* Read the data. */ | |
4303 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); | |
4304 | if (version < 5) | |
4305 | warn (_("corrupt .debug_sup section: version < 5")); | |
4306 | ||
4307 | SAFE_BYTE_GET_AND_INC (is_supplementary, start, 1, end); | |
4308 | if (is_supplementary != 0 && is_supplementary != 1) | |
4309 | warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n")); | |
4310 | ||
4311 | sup_filename = start; | |
4312 | if (is_supplementary && sup_filename[0] != 0) | |
4313 | warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n")); | |
4314 | ||
4315 | sup_filename_len = strnlen ((const char *) start, end - start); | |
4316 | if (sup_filename_len == (size_t) (end - start)) | |
4317 | { | |
4318 | error (_("corrupt .debug_sup section: filename is not NUL terminated\n")); | |
4319 | return 0; | |
4320 | } | |
4321 | start += sup_filename_len + 1; | |
4322 | ||
015dc7e1 | 4323 | checksum_len = read_leb128 (start, end, false /* unsigned */, & num_read, & status); |
e38332c2 NC |
4324 | if (status) |
4325 | { | |
4326 | error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n")); | |
4327 | checksum_len = 0; | |
4328 | } | |
4329 | start += num_read; | |
4330 | if (checksum_len > (dwarf_vma) (end - start)) | |
4331 | { | |
4332 | error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n")); | |
4333 | checksum_len = end - start; | |
4334 | } | |
4335 | else if (checksum_len < (dwarf_vma) (end - start)) | |
4336 | { | |
4337 | warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"), | |
4338 | (long) ((end - start) - checksum_len)); | |
4339 | } | |
4340 | ||
4341 | printf (_(" Version: %u\n"), version); | |
4342 | printf (_(" Is Supp: %u\n"), is_supplementary); | |
4343 | printf (_(" Filename: %s\n"), sup_filename); | |
4344 | printf (_(" Checksum Len: %lu\n"), (long) checksum_len); | |
4345 | if (checksum_len > 0) | |
4346 | { | |
4347 | printf (_(" Checksum: ")); | |
4348 | while (checksum_len--) | |
4349 | printf ("0x%x ", * start++ ); | |
4350 | printf ("\n"); | |
4351 | } | |
4352 | return 1; | |
4353 | } | |
4354 | ||
b40bf0a2 | 4355 | static int |
dda8d76d NC |
4356 | display_debug_lines_raw (struct dwarf_section * section, |
4357 | unsigned char * data, | |
4358 | unsigned char * end, | |
4359 | void * file) | |
b40bf0a2 NC |
4360 | { |
4361 | unsigned char *start = section->start; | |
ba8826a8 | 4362 | int verbose_view = 0; |
19e6b90e | 4363 | |
015dc7e1 | 4364 | introduce (section, true); |
19e6b90e | 4365 | |
b40bf0a2 NC |
4366 | while (data < end) |
4367 | { | |
4368 | static DWARF2_Internal_LineInfo saved_linfo; | |
4369 | DWARF2_Internal_LineInfo linfo; | |
4370 | unsigned char *standard_opcodes; | |
4371 | unsigned char *end_of_sequence; | |
fe59e83d | 4372 | int i; |
19e6b90e | 4373 | |
24d127aa | 4374 | if (startswith (section->name, ".debug_line.") |
4925cdd7 NC |
4375 | /* Note: the following does not apply to .debug_line.dwo sections. |
4376 | These are full debug_line sections. */ | |
4377 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 4378 | { |
b40bf0a2 NC |
4379 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
4380 | section containing just the Line Number Statements. They are | |
4381 | created by the assembler and intended to be used alongside gcc's | |
4382 | -ffunction-sections command line option. When the linker's | |
4383 | garbage collection decides to discard a .text.<foo> section it | |
4384 | can then also discard the line number information in .debug_line.<foo>. | |
4385 | ||
4925cdd7 | 4386 | Since the section is a fragment it does not have the details |
b40bf0a2 | 4387 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 4388 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
4389 | end_of_sequence = end; |
4390 | standard_opcodes = NULL; | |
4391 | linfo = saved_linfo; | |
058037d3 NC |
4392 | /* PR 17531: file: 0522b371. */ |
4393 | if (linfo.li_line_range == 0) | |
4394 | { | |
1306a742 | 4395 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4396 | return 0; |
4397 | } | |
b40bf0a2 | 4398 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4399 | } |
19e6b90e L |
4400 | else |
4401 | { | |
b40bf0a2 | 4402 | unsigned char * hdrptr; |
19e6b90e | 4403 | |
b40bf0a2 NC |
4404 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4405 | & end_of_sequence)) == NULL) | |
4406 | return 0; | |
19e6b90e | 4407 | |
b40bf0a2 NC |
4408 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
4409 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
4410 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
5496f3c6 NC |
4411 | if (linfo.li_version >= 5) |
4412 | { | |
4413 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); | |
4414 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); | |
4415 | } | |
77ef8654 | 4416 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
4417 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
4418 | if (linfo.li_version >= 4) | |
4419 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
4420 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
4421 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4422 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4423 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 4424 | |
0a9d414a NC |
4425 | /* PR 17512: file: 1665-6428-0.004. */ |
4426 | if (linfo.li_line_range == 0) | |
4427 | { | |
4428 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4429 | linfo.li_line_range = 1; | |
4430 | } | |
77ef8654 | 4431 | |
b40bf0a2 | 4432 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4433 | |
b40bf0a2 NC |
4434 | /* Display the contents of the Opcodes table. */ |
4435 | standard_opcodes = hdrptr; | |
19e6b90e | 4436 | |
6937bb54 NC |
4437 | /* PR 17512: file: 002-417945-0.004. */ |
4438 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4439 | { | |
4440 | warn (_("Line Base extends beyond end of section\n")); | |
4441 | return 0; | |
4442 | } | |
4443 | ||
b40bf0a2 | 4444 | printf (_("\n Opcodes:\n")); |
19e6b90e | 4445 | |
b40bf0a2 | 4446 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
4447 | printf (ngettext (" Opcode %d has %d arg\n", |
4448 | " Opcode %d has %d args\n", | |
4449 | standard_opcodes[i - 1]), | |
4450 | i, standard_opcodes[i - 1]); | |
19e6b90e | 4451 | |
b40bf0a2 NC |
4452 | /* Display the contents of the Directory table. */ |
4453 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 4454 | |
77145576 | 4455 | if (linfo.li_version >= 5) |
b40bf0a2 | 4456 | { |
dda8d76d | 4457 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 4458 | |
77145576 | 4459 | data = display_formatted_table (data, start, end, &linfo, section, |
015dc7e1 | 4460 | true); |
77145576 | 4461 | data = display_formatted_table (data, start, end, &linfo, section, |
015dc7e1 | 4462 | false); |
77145576 JK |
4463 | } |
4464 | else | |
4465 | { | |
4466 | if (*data == 0) | |
4467 | printf (_("\n The Directory Table is empty.\n")); | |
4468 | else | |
a233b20c | 4469 | { |
77145576 | 4470 | unsigned int last_dir_entry = 0; |
6937bb54 | 4471 | |
77145576 JK |
4472 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
4473 | (long)(data - start)); | |
19e6b90e | 4474 | |
77145576 JK |
4475 | while (data < end && *data != 0) |
4476 | { | |
4477 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 4478 | |
a7077ce7 AM |
4479 | data += strnlen ((char *) data, end - data); |
4480 | if (data < end) | |
4481 | data++; | |
77145576 | 4482 | } |
19e6b90e | 4483 | |
77145576 JK |
4484 | /* PR 17512: file: 002-132094-0.004. */ |
4485 | if (data >= end - 1) | |
4486 | break; | |
4487 | } | |
19e6b90e | 4488 | |
77145576 | 4489 | /* Skip the NUL at the end of the table. */ |
a7077ce7 AM |
4490 | if (data < end) |
4491 | data++; | |
19e6b90e | 4492 | |
77145576 | 4493 | /* Display the contents of the File Name table. */ |
a7077ce7 | 4494 | if (data >= end || *data == 0) |
77145576 JK |
4495 | printf (_("\n The File Name Table is empty.\n")); |
4496 | else | |
4497 | { | |
4498 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
4499 | (long)(data - start)); | |
4500 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 4501 | |
77145576 | 4502 | while (data < end && *data != 0) |
b40bf0a2 | 4503 | { |
77145576 | 4504 | unsigned char *name; |
cd30bcef | 4505 | dwarf_vma val; |
77145576 JK |
4506 | |
4507 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4508 | name = data; | |
a7077ce7 AM |
4509 | data += strnlen ((char *) data, end - data); |
4510 | if (data < end) | |
4511 | data++; | |
77145576 | 4512 | |
cd30bcef AM |
4513 | READ_ULEB (val, data, end); |
4514 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4515 | READ_ULEB (val, data, end); | |
4516 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4517 | READ_ULEB (val, data, end); | |
4518 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
77145576 JK |
4519 | printf ("%.*s\n", (int)(end - name), name); |
4520 | ||
55b26492 | 4521 | if (data >= end) |
77145576 JK |
4522 | { |
4523 | warn (_("Corrupt file name table entry\n")); | |
4524 | break; | |
4525 | } | |
b40bf0a2 | 4526 | } |
a233b20c | 4527 | } |
77145576 JK |
4528 | |
4529 | /* Skip the NUL at the end of the table. */ | |
a7077ce7 AM |
4530 | if (data < end) |
4531 | data++; | |
b40bf0a2 | 4532 | } |
19e6b90e | 4533 | |
b40bf0a2 NC |
4534 | putchar ('\n'); |
4535 | saved_linfo = linfo; | |
4536 | } | |
19e6b90e | 4537 | |
b40bf0a2 NC |
4538 | /* Now display the statements. */ |
4539 | if (data >= end_of_sequence) | |
4540 | printf (_(" No Line Number Statements.\n")); | |
4541 | else | |
4542 | { | |
4543 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4544 | |
b40bf0a2 NC |
4545 | while (data < end_of_sequence) |
4546 | { | |
4547 | unsigned char op_code; | |
4548 | dwarf_signed_vma adv; | |
4549 | dwarf_vma uladv; | |
19e6b90e | 4550 | |
fe59e83d CC |
4551 | printf (" [0x%08lx]", (long)(data - start)); |
4552 | ||
b40bf0a2 | 4553 | op_code = *data++; |
19e6b90e | 4554 | |
b40bf0a2 | 4555 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4556 | { |
b40bf0a2 NC |
4557 | op_code -= linfo.li_opcode_base; |
4558 | uladv = (op_code / linfo.li_line_range); | |
4559 | if (linfo.li_max_ops_per_insn == 1) | |
4560 | { | |
4561 | uladv *= linfo.li_min_insn_length; | |
4562 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4563 | if (uladv) |
4564 | state_machine_regs.view = 0; | |
b40bf0a2 | 4565 | printf (_(" Special opcode %d: " |
ba8826a8 | 4566 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4567 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4568 | dwarf_vmatoa ("x", state_machine_regs.address), |
4569 | verbose_view && uladv | |
4570 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4571 | } |
4572 | else | |
4573 | { | |
ba8826a8 AO |
4574 | unsigned addrdelta |
4575 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4576 | / linfo.li_max_ops_per_insn) |
4577 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4578 | |
4579 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4580 | state_machine_regs.op_index |
4581 | = (state_machine_regs.op_index + uladv) | |
4582 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4583 | if (addrdelta) |
4584 | state_machine_regs.view = 0; | |
b40bf0a2 | 4585 | printf (_(" Special opcode %d: " |
ba8826a8 | 4586 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4587 | op_code, dwarf_vmatoa ("u", uladv), |
4588 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4589 | state_machine_regs.op_index, |
4590 | verbose_view && addrdelta | |
4591 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4592 | } |
4593 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4594 | state_machine_regs.line += adv; | |
ba8826a8 | 4595 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4596 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4597 | if (verbose_view || state_machine_regs.view) |
4598 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4599 | else | |
4600 | putchar ('\n'); | |
4601 | state_machine_regs.view++; | |
19e6b90e | 4602 | } |
cd30bcef AM |
4603 | else |
4604 | switch (op_code) | |
4605 | { | |
4606 | case DW_LNS_extended_op: | |
4607 | data += process_extended_line_op (data, | |
4608 | linfo.li_default_is_stmt, | |
4609 | end); | |
4610 | break; | |
4611 | ||
4612 | case DW_LNS_copy: | |
4613 | printf (_(" Copy")); | |
4614 | if (verbose_view || state_machine_regs.view) | |
4615 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4616 | else | |
4617 | putchar ('\n'); | |
4618 | state_machine_regs.view++; | |
4619 | break; | |
4620 | ||
4621 | case DW_LNS_advance_pc: | |
4622 | READ_ULEB (uladv, data, end); | |
4623 | if (linfo.li_max_ops_per_insn == 1) | |
4624 | { | |
4625 | uladv *= linfo.li_min_insn_length; | |
4626 | state_machine_regs.address += uladv; | |
4627 | if (uladv) | |
4628 | state_machine_regs.view = 0; | |
4629 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
4630 | dwarf_vmatoa ("u", uladv), | |
4631 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4632 | verbose_view && uladv | |
4633 | ? _(" (reset view)") : ""); | |
4634 | } | |
4635 | else | |
4636 | { | |
4637 | unsigned addrdelta | |
4638 | = ((state_machine_regs.op_index + uladv) | |
4639 | / linfo.li_max_ops_per_insn) | |
4640 | * linfo.li_min_insn_length; | |
4641 | state_machine_regs.address | |
4642 | += addrdelta; | |
4643 | state_machine_regs.op_index | |
4644 | = (state_machine_regs.op_index + uladv) | |
4645 | % linfo.li_max_ops_per_insn; | |
4646 | if (addrdelta) | |
4647 | state_machine_regs.view = 0; | |
4648 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
4649 | dwarf_vmatoa ("u", uladv), | |
4650 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4651 | state_machine_regs.op_index, | |
4652 | verbose_view && addrdelta | |
4653 | ? _(" (reset view)") : ""); | |
4654 | } | |
4655 | break; | |
4656 | ||
4657 | case DW_LNS_advance_line: | |
4658 | READ_SLEB (adv, data, end); | |
4659 | state_machine_regs.line += adv; | |
4660 | printf (_(" Advance Line by %s to %d\n"), | |
4661 | dwarf_vmatoa ("d", adv), | |
4662 | state_machine_regs.line); | |
4663 | break; | |
4664 | ||
4665 | case DW_LNS_set_file: | |
4666 | READ_ULEB (uladv, data, end); | |
4667 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4668 | dwarf_vmatoa ("u", uladv)); | |
4669 | state_machine_regs.file = uladv; | |
4670 | break; | |
4671 | ||
4672 | case DW_LNS_set_column: | |
4673 | READ_ULEB (uladv, data, end); | |
4674 | printf (_(" Set column to %s\n"), | |
4675 | dwarf_vmatoa ("u", uladv)); | |
4676 | state_machine_regs.column = uladv; | |
4677 | break; | |
4678 | ||
4679 | case DW_LNS_negate_stmt: | |
4680 | adv = state_machine_regs.is_stmt; | |
4681 | adv = ! adv; | |
4682 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4683 | state_machine_regs.is_stmt = adv; | |
4684 | break; | |
4685 | ||
4686 | case DW_LNS_set_basic_block: | |
4687 | printf (_(" Set basic block\n")); | |
4688 | state_machine_regs.basic_block = 1; | |
4689 | break; | |
4690 | ||
4691 | case DW_LNS_const_add_pc: | |
4692 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4693 | if (linfo.li_max_ops_per_insn) | |
4694 | { | |
4695 | uladv *= linfo.li_min_insn_length; | |
4696 | state_machine_regs.address += uladv; | |
4697 | if (uladv) | |
4698 | state_machine_regs.view = 0; | |
4699 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
4700 | dwarf_vmatoa ("u", uladv), | |
4701 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4702 | verbose_view && uladv | |
4703 | ? _(" (reset view)") : ""); | |
4704 | } | |
4705 | else | |
4706 | { | |
4707 | unsigned addrdelta | |
4708 | = ((state_machine_regs.op_index + uladv) | |
4709 | / linfo.li_max_ops_per_insn) | |
4710 | * linfo.li_min_insn_length; | |
4711 | state_machine_regs.address | |
4712 | += addrdelta; | |
4713 | state_machine_regs.op_index | |
4714 | = (state_machine_regs.op_index + uladv) | |
4715 | % linfo.li_max_ops_per_insn; | |
4716 | if (addrdelta) | |
4717 | state_machine_regs.view = 0; | |
4718 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
4719 | dwarf_vmatoa ("u", uladv), | |
4720 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4721 | state_machine_regs.op_index, | |
4722 | verbose_view && addrdelta | |
4723 | ? _(" (reset view)") : ""); | |
4724 | } | |
4725 | break; | |
4726 | ||
4727 | case DW_LNS_fixed_advance_pc: | |
4728 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4729 | state_machine_regs.address += uladv; | |
4730 | state_machine_regs.op_index = 0; | |
4731 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4732 | dwarf_vmatoa ("u", uladv), | |
4733 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
4734 | /* Do NOT reset view. */ | |
4735 | break; | |
4736 | ||
4737 | case DW_LNS_set_prologue_end: | |
4738 | printf (_(" Set prologue_end to true\n")); | |
4739 | break; | |
4740 | ||
4741 | case DW_LNS_set_epilogue_begin: | |
4742 | printf (_(" Set epilogue_begin to true\n")); | |
4743 | break; | |
4744 | ||
4745 | case DW_LNS_set_isa: | |
4746 | READ_ULEB (uladv, data, end); | |
4747 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4748 | break; | |
4749 | ||
4750 | default: | |
4751 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4752 | ||
4753 | if (standard_opcodes != NULL) | |
4754 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4755 | { | |
4756 | READ_ULEB (uladv, data, end); | |
4757 | printf ("0x%s%s", dwarf_vmatoa ("x", uladv), | |
4758 | i == 1 ? "" : ", "); | |
4759 | } | |
4760 | putchar ('\n'); | |
4761 | break; | |
4762 | } | |
19e6b90e | 4763 | } |
b40bf0a2 | 4764 | putchar ('\n'); |
19e6b90e | 4765 | } |
19e6b90e L |
4766 | } |
4767 | ||
4768 | return 1; | |
4769 | } | |
4770 | ||
a262ae96 NC |
4771 | typedef struct |
4772 | { | |
467c65bc NC |
4773 | unsigned char *name; |
4774 | unsigned int directory_index; | |
4775 | unsigned int modification_date; | |
4776 | unsigned int length; | |
a262ae96 NC |
4777 | } File_Entry; |
4778 | ||
4779 | /* Output a decoded representation of the .debug_line section. */ | |
4780 | ||
4781 | static int | |
dda8d76d | 4782 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4783 | unsigned char * start, |
dda8d76d NC |
4784 | unsigned char * data, |
4785 | unsigned char * end, | |
4786 | void * fileptr) | |
a262ae96 | 4787 | { |
b40bf0a2 NC |
4788 | static DWARF2_Internal_LineInfo saved_linfo; |
4789 | ||
015dc7e1 | 4790 | introduce (section, false); |
a262ae96 NC |
4791 | |
4792 | while (data < end) | |
4793 | { | |
4794 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4795 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4796 | unsigned char *standard_opcodes; |
4797 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4798 | int i; |
4799 | File_Entry *file_table = NULL; | |
143a3db0 | 4800 | unsigned int n_files = 0; |
a262ae96 | 4801 | unsigned char **directory_table = NULL; |
77145576 | 4802 | dwarf_vma n_directories = 0; |
a262ae96 | 4803 | |
24d127aa | 4804 | if (startswith (section->name, ".debug_line.") |
4925cdd7 NC |
4805 | /* Note: the following does not apply to .debug_line.dwo sections. |
4806 | These are full debug_line sections. */ | |
4807 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4808 | { |
4925cdd7 | 4809 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4810 | end_of_sequence = end; |
4811 | standard_opcodes = NULL; | |
4812 | linfo = saved_linfo; | |
058037d3 NC |
4813 | /* PR 17531: file: 0522b371. */ |
4814 | if (linfo.li_line_range == 0) | |
4815 | { | |
1306a742 | 4816 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4817 | return 0; |
4818 | } | |
b40bf0a2 | 4819 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4820 | } |
a262ae96 | 4821 | else |
b4eb7656 | 4822 | { |
b40bf0a2 | 4823 | unsigned char *hdrptr; |
a262ae96 | 4824 | |
b40bf0a2 NC |
4825 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4826 | & end_of_sequence)) == NULL) | |
a233b20c | 4827 | return 0; |
0c588247 | 4828 | |
058037d3 NC |
4829 | /* PR 17531: file: 0522b371. */ |
4830 | if (linfo.li_line_range == 0) | |
4831 | { | |
4832 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4833 | linfo.li_line_range = 1; | |
4834 | } | |
b40bf0a2 | 4835 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4836 | |
b40bf0a2 NC |
4837 | /* Save a pointer to the contents of the Opcodes table. */ |
4838 | standard_opcodes = hdrptr; | |
a262ae96 | 4839 | |
b40bf0a2 NC |
4840 | /* Traverse the Directory table just to count entries. */ |
4841 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4842 | /* PR 20440 */ |
4843 | if (data >= end) | |
4844 | { | |
4845 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4846 | linfo.li_opcode_base); | |
4847 | return 0; | |
4848 | } | |
4849 | ||
77145576 | 4850 | if (linfo.li_version >= 5) |
b40bf0a2 | 4851 | { |
77145576 JK |
4852 | unsigned char *format_start, format_count, *format; |
4853 | dwarf_vma formati, entryi; | |
a262ae96 | 4854 | |
dda8d76d | 4855 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4856 | |
4857 | /* Skip directories format. */ | |
4858 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4859 | if (do_checks && format_count > 1) |
4860 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), | |
4861 | format_count); | |
77145576 JK |
4862 | format_start = data; |
4863 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4864 | { |
cd30bcef AM |
4865 | SKIP_ULEB (data, end); |
4866 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4867 | } |
a262ae96 | 4868 | |
cd30bcef | 4869 | READ_ULEB (n_directories, data, end); |
55b26492 | 4870 | if (data >= end) |
d8024a91 | 4871 | { |
77145576 | 4872 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4873 | break; |
4874 | } | |
4875 | ||
070b775f NC |
4876 | if (n_directories == 0) |
4877 | directory_table = NULL; | |
4878 | else | |
4879 | directory_table = (unsigned char **) | |
4880 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4881 | |
77145576 | 4882 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4883 | { |
77145576 | 4884 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4885 | |
77145576 JK |
4886 | format = format_start; |
4887 | for (formati = 0; formati < format_count; formati++) | |
4888 | { | |
4889 | dwarf_vma content_type, form; | |
4890 | dwarf_vma uvalue; | |
4891 | ||
cd30bcef AM |
4892 | READ_ULEB (content_type, format, end); |
4893 | READ_ULEB (form, format, end); | |
55b26492 | 4894 | if (data >= end) |
77145576 JK |
4895 | { |
4896 | warn (_("Corrupt directories list\n")); | |
4897 | break; | |
4898 | } | |
4899 | switch (content_type) | |
4900 | { | |
4901 | case DW_LNCT_path: | |
4902 | switch (form) | |
4903 | { | |
4904 | case DW_FORM_string: | |
4905 | *pathp = data; | |
4906 | break; | |
4907 | case DW_FORM_line_strp: | |
4908 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4909 | end); | |
4910 | /* Remove const by the cast. */ | |
4911 | *pathp = (unsigned char *) | |
4912 | fetch_indirect_line_string (uvalue); | |
4913 | break; | |
4914 | } | |
4915 | break; | |
4916 | } | |
cd30bcef AM |
4917 | data = read_and_display_attr_value (0, form, 0, start, |
4918 | data, end, 0, 0, | |
77145576 JK |
4919 | linfo.li_offset_size, |
4920 | linfo.li_version, | |
4921 | NULL, 1, section, | |
ec1b0fbb | 4922 | NULL, '\t', -1); |
77145576 | 4923 | } |
55b26492 | 4924 | if (data >= end) |
77145576 JK |
4925 | { |
4926 | warn (_("Corrupt directories list\n")); | |
4927 | break; | |
4928 | } | |
4929 | } | |
a262ae96 | 4930 | |
77145576 JK |
4931 | /* Skip files format. */ |
4932 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4933 | if (do_checks && format_count > 5) |
4934 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), | |
4935 | format_count); | |
77145576 JK |
4936 | format_start = data; |
4937 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4938 | { |
cd30bcef AM |
4939 | SKIP_ULEB (data, end); |
4940 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4941 | } |
a262ae96 | 4942 | |
cd30bcef | 4943 | READ_ULEB (n_files, data, end); |
55b26492 | 4944 | if (data >= end && n_files > 0) |
d8024a91 | 4945 | { |
77145576 | 4946 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4947 | break; |
4948 | } | |
4949 | ||
070b775f NC |
4950 | if (n_files == 0) |
4951 | file_table = NULL; | |
4952 | else | |
4953 | file_table = (File_Entry *) xcalloc (1, n_files | |
4954 | * sizeof (File_Entry)); | |
a262ae96 | 4955 | |
77145576 | 4956 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4957 | { |
77145576 | 4958 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4959 | |
77145576 JK |
4960 | format = format_start; |
4961 | for (formati = 0; formati < format_count; formati++) | |
4962 | { | |
4963 | dwarf_vma content_type, form; | |
4964 | dwarf_vma uvalue; | |
cd30bcef | 4965 | unsigned char *tmp; |
77145576 | 4966 | |
cd30bcef AM |
4967 | READ_ULEB (content_type, format, end); |
4968 | READ_ULEB (form, format, end); | |
55b26492 | 4969 | if (data >= end) |
77145576 JK |
4970 | { |
4971 | warn (_("Corrupt file name list\n")); | |
4972 | break; | |
4973 | } | |
4974 | switch (content_type) | |
4975 | { | |
4976 | case DW_LNCT_path: | |
4977 | switch (form) | |
4978 | { | |
4979 | case DW_FORM_string: | |
4980 | file->name = data; | |
4981 | break; | |
4982 | case DW_FORM_line_strp: | |
4983 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4984 | end); | |
4985 | /* Remove const by the cast. */ | |
4986 | file->name = (unsigned char *) | |
4987 | fetch_indirect_line_string (uvalue); | |
4988 | break; | |
4989 | } | |
4990 | break; | |
4991 | case DW_LNCT_directory_index: | |
4992 | switch (form) | |
4993 | { | |
4994 | case DW_FORM_data1: | |
4995 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4996 | end); | |
4997 | break; | |
4998 | case DW_FORM_data2: | |
4999 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
5000 | end); | |
5001 | break; | |
5002 | case DW_FORM_udata: | |
cd30bcef AM |
5003 | tmp = data; |
5004 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
5005 | break; |
5006 | } | |
5007 | break; | |
5008 | } | |
cd30bcef AM |
5009 | data = read_and_display_attr_value (0, form, 0, start, |
5010 | data, end, 0, 0, | |
77145576 JK |
5011 | linfo.li_offset_size, |
5012 | linfo.li_version, | |
5013 | NULL, 1, section, | |
ec1b0fbb | 5014 | NULL, '\t', -1); |
77145576 | 5015 | } |
55b26492 | 5016 | if (data >= end) |
77145576 JK |
5017 | { |
5018 | warn (_("Corrupt file name list\n")); | |
5019 | break; | |
5020 | } | |
5021 | } | |
5022 | } | |
5023 | else | |
5024 | { | |
5025 | if (*data != 0) | |
b40bf0a2 | 5026 | { |
77145576 JK |
5027 | unsigned char *ptr_directory_table = data; |
5028 | ||
5029 | while (data < end && *data != 0) | |
5030 | { | |
a7077ce7 AM |
5031 | data += strnlen ((char *) data, end - data); |
5032 | if (data < end) | |
5033 | data++; | |
77145576 JK |
5034 | n_directories++; |
5035 | } | |
5036 | ||
5037 | /* PR 20440 */ | |
5038 | if (data >= end) | |
5039 | { | |
5040 | warn (_("directory table ends unexpectedly\n")); | |
5041 | n_directories = 0; | |
5042 | break; | |
5043 | } | |
5044 | ||
5045 | /* Go through the directory table again to save the directories. */ | |
5046 | directory_table = (unsigned char **) | |
5047 | xmalloc (n_directories * sizeof (unsigned char *)); | |
5048 | ||
5049 | i = 0; | |
5050 | while (*ptr_directory_table != 0) | |
5051 | { | |
5052 | directory_table[i] = ptr_directory_table; | |
56051e28 AM |
5053 | ptr_directory_table |
5054 | += strlen ((char *) ptr_directory_table) + 1; | |
77145576 JK |
5055 | i++; |
5056 | } | |
b40bf0a2 | 5057 | } |
77145576 JK |
5058 | /* Skip the NUL at the end of the table. */ |
5059 | data++; | |
5060 | ||
5061 | /* Traverse the File Name table just to count the entries. */ | |
5062 | if (data < end && *data != 0) | |
b40bf0a2 | 5063 | { |
77145576 JK |
5064 | unsigned char *ptr_file_name_table = data; |
5065 | ||
5066 | while (data < end && *data != 0) | |
db9537d2 | 5067 | { |
cd30bcef AM |
5068 | /* Skip Name, directory index, last modification |
5069 | time and length of file. */ | |
a7077ce7 AM |
5070 | data += strnlen ((char *) data, end - data); |
5071 | if (data < end) | |
5072 | data++; | |
cd30bcef AM |
5073 | SKIP_ULEB (data, end); |
5074 | SKIP_ULEB (data, end); | |
5075 | SKIP_ULEB (data, end); | |
77145576 | 5076 | n_files++; |
db9537d2 | 5077 | } |
a262ae96 | 5078 | |
77145576 JK |
5079 | if (data >= end) |
5080 | { | |
5081 | warn (_("file table ends unexpectedly\n")); | |
5082 | n_files = 0; | |
5083 | break; | |
5084 | } | |
5085 | ||
5086 | /* Go through the file table again to save the strings. */ | |
5087 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 5088 | |
77145576 JK |
5089 | i = 0; |
5090 | while (*ptr_file_name_table != 0) | |
5091 | { | |
77145576 | 5092 | file_table[i].name = ptr_file_name_table; |
56051e28 AM |
5093 | ptr_file_name_table |
5094 | += strlen ((char *) ptr_file_name_table) + 1; | |
77145576 JK |
5095 | |
5096 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
5097 | READ_ULEB (file_table[i].directory_index, |
5098 | ptr_file_name_table, end); | |
5099 | READ_ULEB (file_table[i].modification_date, | |
5100 | ptr_file_name_table, end); | |
5101 | READ_ULEB (file_table[i].length, | |
5102 | ptr_file_name_table, end); | |
77145576 JK |
5103 | i++; |
5104 | } | |
5105 | i = 0; | |
b40bf0a2 | 5106 | } |
77145576 JK |
5107 | |
5108 | /* Skip the NUL at the end of the table. */ | |
5109 | data++; | |
b40bf0a2 | 5110 | } |
cc5914eb | 5111 | |
77145576 | 5112 | /* Print the Compilation Unit's name and a header. */ |
f082820d | 5113 | if (file_table == NULL) |
070b775f | 5114 | printf (_("CU: No directory table\n")); |
f082820d AM |
5115 | else if (directory_table == NULL) |
5116 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
5117 | else |
5118 | { | |
5119 | unsigned int ix = file_table[0].directory_index; | |
5120 | const char *directory; | |
5121 | ||
5122 | if (ix == 0) | |
5123 | directory = "."; | |
5124 | /* PR 20439 */ | |
5125 | else if (n_directories == 0) | |
5126 | directory = _("<unknown>"); | |
5127 | else if (ix > n_directories) | |
5128 | { | |
5129 | warn (_("directory index %u > number of directories %s\n"), | |
5130 | ix, dwarf_vmatoa ("u", n_directories)); | |
5131 | directory = _("<corrupt>"); | |
5132 | } | |
5133 | else | |
5134 | directory = (char *) directory_table[ix - 1]; | |
5135 | ||
5136 | if (do_wide || strlen (directory) < 76) | |
5137 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
5138 | else | |
5139 | printf ("%s:\n", file_table[0].name); | |
77145576 | 5140 | } |
a262ae96 | 5141 | |
070b775f NC |
5142 | if (n_files > 0) |
5143 | printf (_("File name Line number Starting address View Stmt\n")); | |
5144 | else | |
5145 | printf (_("CU: Empty file name table\n")); | |
b40bf0a2 NC |
5146 | saved_linfo = linfo; |
5147 | } | |
a262ae96 NC |
5148 | |
5149 | /* This loop iterates through the Dwarf Line Number Program. */ | |
5150 | while (data < end_of_sequence) | |
b4eb7656 | 5151 | { |
a262ae96 | 5152 | unsigned char op_code; |
ba8826a8 | 5153 | int xop; |
b4eb7656 AM |
5154 | int adv; |
5155 | unsigned long int uladv; | |
b4eb7656 | 5156 | int is_special_opcode = 0; |
a262ae96 | 5157 | |
b4eb7656 | 5158 | op_code = *data++; |
ba8826a8 | 5159 | xop = op_code; |
a262ae96 | 5160 | |
b4eb7656 | 5161 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 5162 | { |
91d6fa6a | 5163 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
5164 | uladv = (op_code / linfo.li_line_range); |
5165 | if (linfo.li_max_ops_per_insn == 1) | |
5166 | { | |
5167 | uladv *= linfo.li_min_insn_length; | |
5168 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
5169 | if (uladv) |
5170 | state_machine_regs.view = 0; | |
a233b20c JJ |
5171 | } |
5172 | else | |
5173 | { | |
ba8826a8 AO |
5174 | unsigned addrdelta |
5175 | = ((state_machine_regs.op_index + uladv) | |
5176 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 5177 | * linfo.li_min_insn_length; |
ba8826a8 AO |
5178 | state_machine_regs.address |
5179 | += addrdelta; | |
a233b20c JJ |
5180 | state_machine_regs.op_index |
5181 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 5182 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
5183 | if (addrdelta) |
5184 | state_machine_regs.view = 0; | |
a233b20c | 5185 | } |
a262ae96 | 5186 | |
b4eb7656 AM |
5187 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
5188 | state_machine_regs.line += adv; | |
5189 | is_special_opcode = 1; | |
ba8826a8 | 5190 | /* Increment view after printing this row. */ |
b4eb7656 | 5191 | } |
cd30bcef AM |
5192 | else |
5193 | switch (op_code) | |
5194 | { | |
5195 | case DW_LNS_extended_op: | |
5196 | { | |
5197 | unsigned int ext_op_code_len; | |
5198 | unsigned char ext_op_code; | |
5199 | unsigned char *op_code_end; | |
5200 | unsigned char *op_code_data = data; | |
5201 | ||
5202 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
5203 | op_code_end = op_code_data + ext_op_code_len; | |
5204 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
5205 | { | |
5206 | warn (_("Badly formed extended line op encountered!\n")); | |
5207 | break; | |
5208 | } | |
5209 | ext_op_code = *op_code_data++; | |
5210 | xop = ext_op_code; | |
5211 | xop = -xop; | |
5212 | ||
5213 | switch (ext_op_code) | |
5214 | { | |
5215 | case DW_LNE_end_sequence: | |
5216 | /* Reset stuff after printing this row. */ | |
5217 | break; | |
5218 | case DW_LNE_set_address: | |
5219 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
5220 | op_code_data, | |
5221 | op_code_end - op_code_data, | |
5222 | op_code_end); | |
5223 | state_machine_regs.op_index = 0; | |
5224 | state_machine_regs.view = 0; | |
5225 | break; | |
5226 | case DW_LNE_define_file: | |
5227 | file_table = (File_Entry *) xrealloc | |
5228 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
5229 | ||
5230 | ++state_machine_regs.last_file_entry; | |
5231 | /* Source file name. */ | |
5232 | file_table[n_files].name = op_code_data; | |
5233 | op_code_data += strlen ((char *) op_code_data) + 1; | |
5234 | /* Directory index. */ | |
5235 | READ_ULEB (file_table[n_files].directory_index, | |
5236 | op_code_data, op_code_end); | |
5237 | /* Last modification time. */ | |
5238 | READ_ULEB (file_table[n_files].modification_date, | |
5239 | op_code_data, op_code_end); | |
5240 | /* File length. */ | |
5241 | READ_ULEB (file_table[n_files].length, | |
5242 | op_code_data, op_code_end); | |
5243 | n_files++; | |
5244 | break; | |
5245 | ||
5246 | case DW_LNE_set_discriminator: | |
5247 | case DW_LNE_HP_set_sequence: | |
5248 | /* Simply ignored. */ | |
5249 | break; | |
5250 | ||
5251 | default: | |
5252 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 5253 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
5254 | break; |
5255 | } | |
5256 | data = op_code_end; | |
5257 | break; | |
5258 | } | |
5259 | case DW_LNS_copy: | |
5260 | /* Increment view after printing this row. */ | |
5261 | break; | |
5262 | ||
5263 | case DW_LNS_advance_pc: | |
5264 | READ_ULEB (uladv, data, end); | |
5265 | if (linfo.li_max_ops_per_insn == 1) | |
5266 | { | |
5267 | uladv *= linfo.li_min_insn_length; | |
5268 | state_machine_regs.address += uladv; | |
5269 | if (uladv) | |
5270 | state_machine_regs.view = 0; | |
5271 | } | |
5272 | else | |
5273 | { | |
5274 | unsigned addrdelta | |
5275 | = ((state_machine_regs.op_index + uladv) | |
5276 | / linfo.li_max_ops_per_insn) | |
5277 | * linfo.li_min_insn_length; | |
5278 | state_machine_regs.address | |
5279 | += addrdelta; | |
5280 | state_machine_regs.op_index | |
5281 | = (state_machine_regs.op_index + uladv) | |
5282 | % linfo.li_max_ops_per_insn; | |
5283 | if (addrdelta) | |
5284 | state_machine_regs.view = 0; | |
5285 | } | |
5286 | break; | |
5287 | ||
5288 | case DW_LNS_advance_line: | |
5289 | READ_SLEB (adv, data, end); | |
5290 | state_machine_regs.line += adv; | |
5291 | break; | |
5292 | ||
5293 | case DW_LNS_set_file: | |
5294 | READ_ULEB (uladv, data, end); | |
5295 | state_machine_regs.file = uladv; | |
5296 | ||
5297 | { | |
5298 | unsigned file = state_machine_regs.file - 1; | |
5299 | unsigned dir; | |
5300 | ||
5301 | if (file_table == NULL || n_files == 0) | |
5302 | printf (_("\n [Use file table entry %d]\n"), file); | |
5303 | /* PR 20439 */ | |
5304 | else if (file >= n_files) | |
5305 | { | |
5306 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
5307 | printf (_("\n <over large file table index %u>"), file); | |
5308 | } | |
5309 | else if ((dir = file_table[file].directory_index) == 0) | |
5310 | /* If directory index is 0, that means current directory. */ | |
5311 | printf ("\n./%s:[++]\n", file_table[file].name); | |
5312 | else if (directory_table == NULL || n_directories == 0) | |
5313 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
5314 | file_table[file].name, dir); | |
5315 | /* PR 20439 */ | |
5316 | else if (dir > n_directories) | |
5317 | { | |
5318 | warn (_("directory index %u > number of directories %s\n"), | |
5319 | dir, dwarf_vmatoa ("u", n_directories)); | |
5320 | printf (_("\n <over large directory table entry %u>\n"), dir); | |
5321 | } | |
5322 | else | |
5323 | printf ("\n%s/%s:\n", | |
5324 | /* The directory index starts counting at 1. */ | |
5325 | directory_table[dir - 1], file_table[file].name); | |
5326 | } | |
5327 | break; | |
5328 | ||
5329 | case DW_LNS_set_column: | |
5330 | READ_ULEB (uladv, data, end); | |
5331 | state_machine_regs.column = uladv; | |
5332 | break; | |
5333 | ||
5334 | case DW_LNS_negate_stmt: | |
5335 | adv = state_machine_regs.is_stmt; | |
5336 | adv = ! adv; | |
5337 | state_machine_regs.is_stmt = adv; | |
5338 | break; | |
5339 | ||
5340 | case DW_LNS_set_basic_block: | |
5341 | state_machine_regs.basic_block = 1; | |
5342 | break; | |
5343 | ||
5344 | case DW_LNS_const_add_pc: | |
5345 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
5346 | if (linfo.li_max_ops_per_insn == 1) | |
5347 | { | |
5348 | uladv *= linfo.li_min_insn_length; | |
5349 | state_machine_regs.address += uladv; | |
5350 | if (uladv) | |
5351 | state_machine_regs.view = 0; | |
5352 | } | |
5353 | else | |
5354 | { | |
5355 | unsigned addrdelta | |
5356 | = ((state_machine_regs.op_index + uladv) | |
5357 | / linfo.li_max_ops_per_insn) | |
5358 | * linfo.li_min_insn_length; | |
5359 | state_machine_regs.address | |
5360 | += addrdelta; | |
5361 | state_machine_regs.op_index | |
5362 | = (state_machine_regs.op_index + uladv) | |
5363 | % linfo.li_max_ops_per_insn; | |
5364 | if (addrdelta) | |
5365 | state_machine_regs.view = 0; | |
5366 | } | |
5367 | break; | |
5368 | ||
5369 | case DW_LNS_fixed_advance_pc: | |
5370 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5371 | state_machine_regs.address += uladv; | |
5372 | state_machine_regs.op_index = 0; | |
5373 | /* Do NOT reset view. */ | |
5374 | break; | |
5375 | ||
5376 | case DW_LNS_set_prologue_end: | |
5377 | break; | |
5378 | ||
5379 | case DW_LNS_set_epilogue_begin: | |
5380 | break; | |
5381 | ||
5382 | case DW_LNS_set_isa: | |
5383 | READ_ULEB (uladv, data, end); | |
5384 | printf (_(" Set ISA to %lu\n"), uladv); | |
5385 | break; | |
5386 | ||
5387 | default: | |
5388 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5389 | ||
5390 | if (standard_opcodes != NULL) | |
5391 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5392 | { | |
5393 | dwarf_vma val; | |
5394 | ||
5395 | READ_ULEB (val, data, end); | |
5396 | printf ("0x%s%s", dwarf_vmatoa ("x", val), | |
5397 | i == 1 ? "" : ", "); | |
5398 | } | |
5399 | putchar ('\n'); | |
5400 | break; | |
5401 | } | |
a262ae96 | 5402 | |
b4eb7656 AM |
5403 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
5404 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
5405 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
5406 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
5407 | { |
5408 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
5409 | char *fileName; | |
5410 | char *newFileName = NULL; | |
5411 | size_t fileNameLength; | |
b40bf0a2 NC |
5412 | |
5413 | if (file_table) | |
db9537d2 NC |
5414 | { |
5415 | unsigned indx = state_machine_regs.file - 1; | |
5416 | /* PR 20439 */ | |
5417 | if (indx >= n_files) | |
5418 | { | |
5419 | warn (_("corrupt file index %u encountered\n"), indx); | |
5420 | fileName = _("<corrupt>"); | |
5421 | } | |
5422 | else | |
5423 | fileName = (char *) file_table[indx].name; | |
5424 | } | |
b40bf0a2 | 5425 | else |
db9537d2 | 5426 | fileName = _("<unknown>"); |
b40bf0a2 NC |
5427 | |
5428 | fileNameLength = strlen (fileName); | |
539b54f0 AM |
5429 | newFileName = fileName; |
5430 | if (fileNameLength > MAX_FILENAME_LENGTH && !do_wide) | |
b4eb7656 AM |
5431 | { |
5432 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5433 | /* Truncate file name */ | |
539b54f0 AM |
5434 | memcpy (newFileName, |
5435 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5436 | MAX_FILENAME_LENGTH); | |
e1104d08 | 5437 | newFileName[MAX_FILENAME_LENGTH] = 0; |
b4eb7656 | 5438 | } |
b4eb7656 | 5439 | |
af2b3186 TV |
5440 | /* A row with end_seq set to true has a meaningful address, but |
5441 | the other information in the same row is not significant. | |
5442 | In such a row, print line as "-", and don't print | |
5443 | view/is_stmt. */ | |
539b54f0 | 5444 | if (!do_wide || fileNameLength <= MAX_FILENAME_LENGTH) |
b4eb7656 | 5445 | { |
a233b20c | 5446 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5447 | { |
5448 | if (xop == -DW_LNE_end_sequence) | |
5449 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x", | |
5450 | newFileName, "-", | |
5451 | state_machine_regs.address); | |
5452 | else | |
5453 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", | |
5454 | newFileName, state_machine_regs.line, | |
5455 | state_machine_regs.address); | |
5456 | } | |
a233b20c | 5457 | else |
af2b3186 TV |
5458 | { |
5459 | if (xop == -DW_LNE_end_sequence) | |
5460 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5461 | newFileName, "-", | |
5462 | state_machine_regs.address, | |
5463 | state_machine_regs.op_index); | |
5464 | else | |
5465 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5466 | newFileName, state_machine_regs.line, | |
5467 | state_machine_regs.address, | |
5468 | state_machine_regs.op_index); | |
5469 | } | |
b4eb7656 AM |
5470 | } |
5471 | else | |
5472 | { | |
a233b20c | 5473 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5474 | { |
5475 | if (xop == -DW_LNE_end_sequence) | |
5476 | printf ("%s %11s %#18" DWARF_VMA_FMT "x", | |
5477 | newFileName, "-", | |
5478 | state_machine_regs.address); | |
5479 | else | |
5480 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", | |
5481 | newFileName, state_machine_regs.line, | |
5482 | state_machine_regs.address); | |
5483 | } | |
a233b20c | 5484 | else |
af2b3186 TV |
5485 | { |
5486 | if (xop == -DW_LNE_end_sequence) | |
5487 | printf ("%s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5488 | newFileName, "-", | |
5489 | state_machine_regs.address, | |
5490 | state_machine_regs.op_index); | |
5491 | else | |
5492 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5493 | newFileName, state_machine_regs.line, | |
5494 | state_machine_regs.address, | |
5495 | state_machine_regs.op_index); | |
5496 | } | |
b4eb7656 | 5497 | } |
a262ae96 | 5498 | |
af2b3186 TV |
5499 | if (xop != -DW_LNE_end_sequence) |
5500 | { | |
5501 | if (state_machine_regs.view) | |
5502 | printf (" %6u", state_machine_regs.view); | |
5503 | else | |
5504 | printf (" "); | |
17f6ade2 | 5505 | |
af2b3186 TV |
5506 | if (state_machine_regs.is_stmt) |
5507 | printf (" x"); | |
5508 | } | |
17f6ade2 JD |
5509 | |
5510 | putchar ('\n'); | |
ba8826a8 AO |
5511 | state_machine_regs.view++; |
5512 | ||
5513 | if (xop == -DW_LNE_end_sequence) | |
5514 | { | |
5515 | reset_state_machine (linfo.li_default_is_stmt); | |
5516 | putchar ('\n'); | |
5517 | } | |
a262ae96 | 5518 | |
539b54f0 AM |
5519 | if (newFileName != fileName) |
5520 | free (newFileName); | |
b4eb7656 AM |
5521 | } |
5522 | } | |
b40bf0a2 NC |
5523 | |
5524 | if (file_table) | |
5525 | { | |
5526 | free (file_table); | |
5527 | file_table = NULL; | |
5528 | n_files = 0; | |
5529 | } | |
5530 | ||
5531 | if (directory_table) | |
5532 | { | |
5533 | free (directory_table); | |
5534 | directory_table = NULL; | |
5535 | n_directories = 0; | |
5536 | } | |
5537 | ||
a262ae96 NC |
5538 | putchar ('\n'); |
5539 | } | |
5540 | ||
5541 | return 1; | |
5542 | } | |
5543 | ||
5544 | static int | |
77145576 | 5545 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5546 | { |
5547 | unsigned char *data = section->start; | |
5548 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5549 | int retValRaw = 1; |
5550 | int retValDecoded = 1; | |
a262ae96 | 5551 | |
008f4c78 NC |
5552 | if (do_debug_lines == 0) |
5553 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5554 | ||
4cb93e3b | 5555 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5556 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5557 | |
4cb93e3b | 5558 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5559 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5560 | |
4cb93e3b | 5561 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5562 | return 0; |
5563 | ||
5564 | return 1; | |
5565 | } | |
5566 | ||
6e3d6dc1 NC |
5567 | static debug_info * |
5568 | find_debug_info_for_offset (unsigned long offset) | |
5569 | { | |
5570 | unsigned int i; | |
5571 | ||
5572 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5573 | return NULL; | |
5574 | ||
5575 | for (i = 0; i < num_debug_info_entries; i++) | |
5576 | if (debug_information[i].cu_offset == offset) | |
5577 | return debug_information + i; | |
5578 | ||
5579 | return NULL; | |
5580 | } | |
5581 | ||
459d52c8 DE |
5582 | static const char * |
5583 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5584 | { | |
5585 | /* See gdb/gdb-index.h. */ | |
5586 | static const char * const kinds[] = | |
5587 | { | |
5588 | N_ ("no info"), | |
5589 | N_ ("type"), | |
5590 | N_ ("variable"), | |
5591 | N_ ("function"), | |
5592 | N_ ("other"), | |
5593 | N_ ("unused5"), | |
5594 | N_ ("unused6"), | |
5595 | N_ ("unused7") | |
5596 | }; | |
5597 | ||
5598 | return _ (kinds[kind]); | |
5599 | } | |
5600 | ||
19e6b90e | 5601 | static int |
459d52c8 DE |
5602 | display_debug_pubnames_worker (struct dwarf_section *section, |
5603 | void *file ATTRIBUTE_UNUSED, | |
5604 | int is_gnu) | |
19e6b90e | 5605 | { |
91d6fa6a | 5606 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5607 | unsigned char *start = section->start; |
5608 | unsigned char *end = start + section->size; | |
5609 | ||
6e3d6dc1 NC |
5610 | /* It does not matter if this load fails, |
5611 | we test for that later on. */ | |
5612 | load_debug_info (file); | |
5613 | ||
015dc7e1 | 5614 | introduce (section, false); |
19e6b90e L |
5615 | |
5616 | while (start < end) | |
5617 | { | |
5618 | unsigned char *data; | |
35b2c89e AM |
5619 | unsigned long sec_off = start - section->start; |
5620 | unsigned int offset_size; | |
19e6b90e | 5621 | |
e98fdf1a | 5622 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5623 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5624 | { |
e98fdf1a | 5625 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e | 5626 | offset_size = 8; |
19e6b90e L |
5627 | } |
5628 | else | |
35b2c89e | 5629 | offset_size = 4; |
19e6b90e | 5630 | |
35b2c89e | 5631 | if (names.pn_length > (size_t) (end - start)) |
e98fdf1a AM |
5632 | { |
5633 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5634 | section->name, | |
35b2c89e | 5635 | sec_off, |
e98fdf1a AM |
5636 | dwarf_vmatoa ("x", names.pn_length)); |
5637 | break; | |
5638 | } | |
5639 | ||
5640 | data = start; | |
5641 | start += names.pn_length; | |
5642 | ||
35b2c89e AM |
5643 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, start); |
5644 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, start); | |
6e3d6dc1 NC |
5645 | |
5646 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5647 | && num_debug_info_entries > 0 | |
91d6fa6a | 5648 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5649 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5650 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5651 | |
35b2c89e | 5652 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, start); |
19e6b90e | 5653 | |
058037d3 NC |
5654 | printf (_(" Length: %ld\n"), |
5655 | (long) names.pn_length); | |
5656 | printf (_(" Version: %d\n"), | |
5657 | names.pn_version); | |
5658 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5659 | (unsigned long) names.pn_offset); | |
5660 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5661 | (long) names.pn_size); | |
19e6b90e | 5662 | |
91d6fa6a | 5663 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5664 | { |
5665 | static int warned = 0; | |
5666 | ||
5667 | if (! warned) | |
5668 | { | |
5669 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5670 | warned = 1; | |
5671 | } | |
5672 | ||
5673 | continue; | |
5674 | } | |
5675 | ||
459d52c8 DE |
5676 | if (is_gnu) |
5677 | printf (_("\n Offset Kind Name\n")); | |
5678 | else | |
5679 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5680 | |
e98fdf1a | 5681 | while (1) |
19e6b90e | 5682 | { |
f41e4712 | 5683 | bfd_size_type maxprint; |
e98fdf1a | 5684 | dwarf_vma offset; |
f41e4712 | 5685 | |
35b2c89e | 5686 | SAFE_BYTE_GET_AND_INC (offset, data, offset_size, start); |
19e6b90e | 5687 | |
e98fdf1a AM |
5688 | if (offset == 0) |
5689 | break; | |
b4eb7656 | 5690 | |
35b2c89e | 5691 | if (data >= start) |
e98fdf1a | 5692 | break; |
35b2c89e | 5693 | maxprint = (start - data) - 1; |
f41e4712 | 5694 | |
e98fdf1a AM |
5695 | if (is_gnu) |
5696 | { | |
5697 | unsigned int kind_data; | |
5698 | gdb_index_symbol_kind kind; | |
5699 | const char *kind_name; | |
5700 | int is_static; | |
5701 | ||
35b2c89e | 5702 | SAFE_BYTE_GET_AND_INC (kind_data, data, 1, start); |
e98fdf1a AM |
5703 | maxprint --; |
5704 | /* GCC computes the kind as the upper byte in the CU index | |
5705 | word, and then right shifts it by the CU index size. | |
5706 | Left shift KIND to where the gdb-index.h accessor macros | |
5707 | can use it. */ | |
5708 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5709 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5710 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5711 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5712 | printf (" %-6lx %s,%-10s %.*s\n", | |
5713 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5714 | kind_name, (int) maxprint, data); | |
19e6b90e | 5715 | } |
e98fdf1a AM |
5716 | else |
5717 | printf (" %-6lx\t%.*s\n", | |
5718 | (unsigned long) offset, (int) maxprint, data); | |
5719 | ||
a7077ce7 | 5720 | data += strnlen ((char *) data, maxprint); |
35b2c89e | 5721 | if (data < start) |
a7077ce7 | 5722 | data++; |
35b2c89e | 5723 | if (data >= start) |
e98fdf1a | 5724 | break; |
19e6b90e | 5725 | } |
19e6b90e L |
5726 | } |
5727 | ||
5728 | printf ("\n"); | |
5729 | return 1; | |
5730 | } | |
5731 | ||
459d52c8 DE |
5732 | static int |
5733 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5734 | { | |
5735 | return display_debug_pubnames_worker (section, file, 0); | |
5736 | } | |
5737 | ||
5738 | static int | |
5739 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5740 | { | |
5741 | return display_debug_pubnames_worker (section, file, 1); | |
5742 | } | |
5743 | ||
19e6b90e L |
5744 | static int |
5745 | display_debug_macinfo (struct dwarf_section *section, | |
5746 | void *file ATTRIBUTE_UNUSED) | |
5747 | { | |
5748 | unsigned char *start = section->start; | |
5749 | unsigned char *end = start + section->size; | |
5750 | unsigned char *curr = start; | |
19e6b90e L |
5751 | enum dwarf_macinfo_record_type op; |
5752 | ||
015dc7e1 | 5753 | introduce (section, false); |
19e6b90e L |
5754 | |
5755 | while (curr < end) | |
5756 | { | |
5757 | unsigned int lineno; | |
0c588247 | 5758 | const unsigned char *string; |
19e6b90e | 5759 | |
3f5e193b | 5760 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5761 | curr++; |
5762 | ||
5763 | switch (op) | |
5764 | { | |
5765 | case DW_MACINFO_start_file: | |
5766 | { | |
5767 | unsigned int filenum; | |
5768 | ||
cd30bcef AM |
5769 | READ_ULEB (lineno, curr, end); |
5770 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
5771 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
5772 | lineno, filenum); | |
5773 | } | |
5774 | break; | |
5775 | ||
5776 | case DW_MACINFO_end_file: | |
5777 | printf (_(" DW_MACINFO_end_file\n")); | |
5778 | break; | |
5779 | ||
5780 | case DW_MACINFO_define: | |
cd30bcef | 5781 | READ_ULEB (lineno, curr, end); |
0c588247 | 5782 | string = curr; |
c03df922 AM |
5783 | curr += strnlen ((char *) string, end - string); |
5784 | printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"), | |
5785 | lineno, (int) (curr - string), string); | |
5786 | if (curr < end) | |
5787 | curr++; | |
19e6b90e L |
5788 | break; |
5789 | ||
5790 | case DW_MACINFO_undef: | |
cd30bcef | 5791 | READ_ULEB (lineno, curr, end); |
0c588247 | 5792 | string = curr; |
c03df922 AM |
5793 | curr += strnlen ((char *) string, end - string); |
5794 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"), | |
5795 | lineno, (int) (curr - string), string); | |
5796 | if (curr < end) | |
5797 | curr++; | |
19e6b90e L |
5798 | break; |
5799 | ||
5800 | case DW_MACINFO_vendor_ext: | |
5801 | { | |
5802 | unsigned int constant; | |
5803 | ||
cd30bcef | 5804 | READ_ULEB (constant, curr, end); |
0c588247 | 5805 | string = curr; |
c03df922 AM |
5806 | curr += strnlen ((char *) string, end - string); |
5807 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"), | |
5808 | constant, (int) (curr - string), string); | |
5809 | if (curr < end) | |
5810 | curr++; | |
19e6b90e L |
5811 | } |
5812 | break; | |
5813 | } | |
5814 | } | |
5815 | ||
5816 | return 1; | |
5817 | } | |
5818 | ||
4ccf1e31 JJ |
5819 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5820 | filename and dirname corresponding to file name table entry with index | |
5821 | FILEIDX. Return NULL on failure. */ | |
5822 | ||
5823 | static unsigned char * | |
f6f0e17b NC |
5824 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5825 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5826 | unsigned char **dir_name) |
5827 | { | |
5828 | struct dwarf_section *section = &debug_displays [line].section; | |
5829 | unsigned char *hdrptr, *dirtable, *file_name; | |
46d1214d | 5830 | unsigned int offset_size; |
cd30bcef | 5831 | unsigned int version, opcode_base; |
4ccf1e31 | 5832 | dwarf_vma length, diridx; |
f6f0e17b | 5833 | const unsigned char * end; |
4ccf1e31 JJ |
5834 | |
5835 | *dir_name = NULL; | |
5836 | if (section->start == NULL | |
5837 | || line_offset >= section->size | |
5838 | || fileidx == 0) | |
5839 | return NULL; | |
5840 | ||
5841 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5842 | end = section->start + section->size; |
0c588247 NC |
5843 | |
5844 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5845 | if (length == 0xffffffff) |
5846 | { | |
5847 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5848 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 | 5849 | offset_size = 8; |
4ccf1e31 JJ |
5850 | } |
5851 | else | |
46d1214d AM |
5852 | offset_size = 4; |
5853 | ||
5854 | if (length > (size_t) (end - hdrptr) | |
5855 | || length < 2 + offset_size + 1 + 3 + 1) | |
4ccf1e31 | 5856 | return NULL; |
46d1214d | 5857 | end = hdrptr + length; |
0c588247 NC |
5858 | |
5859 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5860 | if (version != 2 && version != 3 && version != 4) |
5861 | return NULL; | |
5862 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5863 | if (version >= 4) | |
5864 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5865 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5866 | |
5867 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
46d1214d AM |
5868 | if (opcode_base == 0 |
5869 | || opcode_base - 1 >= (size_t) (end - hdrptr)) | |
4ccf1e31 | 5870 | return NULL; |
0c588247 | 5871 | |
4ccf1e31 | 5872 | hdrptr += opcode_base - 1; |
5c1c468d | 5873 | |
4ccf1e31 JJ |
5874 | dirtable = hdrptr; |
5875 | /* Skip over dirname table. */ | |
5876 | while (*hdrptr != '\0') | |
5c1c468d | 5877 | { |
46d1214d AM |
5878 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
5879 | if (hdrptr < end) | |
5880 | hdrptr++; | |
5c1c468d NC |
5881 | if (hdrptr >= end) |
5882 | return NULL; | |
5883 | } | |
4ccf1e31 | 5884 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5885 | |
4ccf1e31 | 5886 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5887 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5888 | { |
46d1214d AM |
5889 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
5890 | if (hdrptr < end) | |
5891 | hdrptr++; | |
cd30bcef AM |
5892 | SKIP_ULEB (hdrptr, end); |
5893 | SKIP_ULEB (hdrptr, end); | |
5894 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 5895 | } |
5c1c468d | 5896 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5897 | return NULL; |
5c1c468d | 5898 | |
4ccf1e31 | 5899 | file_name = hdrptr; |
46d1214d AM |
5900 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr); |
5901 | if (hdrptr < end) | |
5902 | hdrptr++; | |
5c1c468d NC |
5903 | if (hdrptr >= end) |
5904 | return NULL; | |
cd30bcef | 5905 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
5906 | if (diridx == 0) |
5907 | return file_name; | |
5c1c468d | 5908 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
46d1214d AM |
5909 | { |
5910 | dirtable += strnlen ((char *) dirtable, end - dirtable); | |
5911 | if (dirtable < end) | |
5912 | dirtable++; | |
5913 | } | |
5c1c468d | 5914 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5915 | return NULL; |
5916 | *dir_name = dirtable; | |
5917 | return file_name; | |
5918 | } | |
5919 | ||
5920 | static int | |
5921 | display_debug_macro (struct dwarf_section *section, | |
5922 | void *file) | |
5923 | { | |
5924 | unsigned char *start = section->start; | |
5925 | unsigned char *end = start + section->size; | |
5926 | unsigned char *curr = start; | |
5927 | unsigned char *extended_op_buf[256]; | |
015dc7e1 | 5928 | bool is_dwo = false; |
d296b736 NC |
5929 | const char *suffix = strrchr (section->name, '.'); |
5930 | ||
5931 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
015dc7e1 | 5932 | is_dwo = true; |
4ccf1e31 | 5933 | |
dda8d76d NC |
5934 | load_debug_section_with_follow (str, file); |
5935 | load_debug_section_with_follow (line, file); | |
e4b7104b | 5936 | load_debug_section_with_follow (str_index, file); |
d296b736 | 5937 | |
015dc7e1 | 5938 | introduce (section, false); |
4ccf1e31 JJ |
5939 | |
5940 | while (curr < end) | |
5941 | { | |
5942 | unsigned int lineno, version, flags; | |
d296b736 | 5943 | unsigned int offset_size; |
0c588247 | 5944 | const unsigned char *string; |
4ccf1e31 JJ |
5945 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5946 | unsigned char **extended_ops = NULL; | |
5947 | ||
0c588247 | 5948 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5949 | if (version != 4 && version != 5) |
4ccf1e31 | 5950 | { |
0e12f6c8 TV |
5951 | error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"), |
5952 | section->name, version); | |
4ccf1e31 JJ |
5953 | return 0; |
5954 | } | |
5955 | ||
0c588247 | 5956 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
d296b736 | 5957 | offset_size = (flags & 1) ? 8 : 4; |
4ccf1e31 JJ |
5958 | printf (_(" Offset: 0x%lx\n"), |
5959 | (unsigned long) sec_offset); | |
5960 | printf (_(" Version: %d\n"), version); | |
5961 | printf (_(" Offset size: %d\n"), offset_size); | |
5962 | if (flags & 2) | |
5963 | { | |
0c588247 | 5964 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5965 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5966 | (unsigned long) line_offset); | |
5967 | } | |
5968 | if (flags & 4) | |
5969 | { | |
0c588247 | 5970 | unsigned int i, count, op; |
4ccf1e31 | 5971 | dwarf_vma nargs, n; |
0c588247 NC |
5972 | |
5973 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5974 | |
4ccf1e31 JJ |
5975 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5976 | extended_ops = extended_op_buf; | |
5977 | if (count) | |
5978 | { | |
5979 | printf (_(" Extension opcode arguments:\n")); | |
5980 | for (i = 0; i < count; i++) | |
5981 | { | |
0c588247 | 5982 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5983 | extended_ops[op] = curr; |
cd30bcef | 5984 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 5985 | if (nargs == 0) |
7a7e1061 | 5986 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5987 | else |
5988 | { | |
7a7e1061 | 5989 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5990 | for (n = 0; n < nargs; n++) |
5991 | { | |
0c588247 NC |
5992 | unsigned int form; |
5993 | ||
5994 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5995 | printf ("%s%s", get_FORM_name (form), |
5996 | n == nargs - 1 ? "\n" : ", "); | |
5997 | switch (form) | |
5998 | { | |
5999 | case DW_FORM_data1: | |
6000 | case DW_FORM_data2: | |
6001 | case DW_FORM_data4: | |
6002 | case DW_FORM_data8: | |
6003 | case DW_FORM_sdata: | |
6004 | case DW_FORM_udata: | |
6005 | case DW_FORM_block: | |
6006 | case DW_FORM_block1: | |
6007 | case DW_FORM_block2: | |
6008 | case DW_FORM_block4: | |
6009 | case DW_FORM_flag: | |
6010 | case DW_FORM_string: | |
6011 | case DW_FORM_strp: | |
6012 | case DW_FORM_sec_offset: | |
6013 | break; | |
6014 | default: | |
6015 | error (_("Invalid extension opcode form %s\n"), | |
6016 | get_FORM_name (form)); | |
6017 | return 0; | |
6018 | } | |
6019 | } | |
6020 | } | |
6021 | } | |
6022 | } | |
6023 | } | |
6024 | printf ("\n"); | |
6025 | ||
6026 | while (1) | |
6027 | { | |
6028 | unsigned int op; | |
6029 | ||
6030 | if (curr >= end) | |
6031 | { | |
6032 | error (_(".debug_macro section not zero terminated\n")); | |
6033 | return 0; | |
6034 | } | |
6035 | ||
0c588247 | 6036 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
6037 | if (op == 0) |
6038 | break; | |
6039 | ||
6040 | switch (op) | |
6041 | { | |
e4b7104b NC |
6042 | case DW_MACRO_define: |
6043 | READ_ULEB (lineno, curr, end); | |
6044 | string = curr; | |
b0d461ec AM |
6045 | curr += strnlen ((char *) string, end - string); |
6046 | printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"), | |
6047 | lineno, (int) (curr - string), string); | |
6048 | if (curr < end) | |
6049 | curr++; | |
e4b7104b NC |
6050 | break; |
6051 | ||
6052 | case DW_MACRO_undef: | |
6053 | READ_ULEB (lineno, curr, end); | |
6054 | string = curr; | |
b0d461ec AM |
6055 | curr += strnlen ((char *) string, end - string); |
6056 | printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"), | |
6057 | lineno, (int) (curr - string), string); | |
6058 | if (curr < end) | |
6059 | curr++; | |
e4b7104b NC |
6060 | break; |
6061 | ||
7a7e1061 | 6062 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
6063 | { |
6064 | unsigned int filenum; | |
6065 | unsigned char *file_name = NULL, *dir_name = NULL; | |
6066 | ||
cd30bcef AM |
6067 | READ_ULEB (lineno, curr, end); |
6068 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
6069 | |
6070 | if ((flags & 2) == 0) | |
7a7e1061 | 6071 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
6072 | else |
6073 | file_name | |
6074 | = get_line_filename_and_dirname (line_offset, filenum, | |
6075 | &dir_name); | |
6076 | if (file_name == NULL) | |
7a7e1061 | 6077 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
6078 | lineno, filenum); |
6079 | else | |
7a7e1061 | 6080 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
6081 | lineno, filenum, |
6082 | dir_name != NULL ? (const char *) dir_name : "", | |
6083 | dir_name != NULL ? "/" : "", file_name); | |
6084 | } | |
6085 | break; | |
6086 | ||
7a7e1061 JK |
6087 | case DW_MACRO_end_file: |
6088 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
6089 | break; |
6090 | ||
7a7e1061 | 6091 | case DW_MACRO_define_strp: |
cd30bcef | 6092 | READ_ULEB (lineno, curr, end); |
d296b736 NC |
6093 | if (version == 4 && is_dwo) |
6094 | READ_ULEB (offset, curr, end); | |
6095 | else | |
6096 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
4ccf1e31 | 6097 | string = fetch_indirect_string (offset); |
7a7e1061 | 6098 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6099 | lineno, string); |
6100 | break; | |
6101 | ||
7a7e1061 | 6102 | case DW_MACRO_undef_strp: |
cd30bcef | 6103 | READ_ULEB (lineno, curr, end); |
d296b736 NC |
6104 | if (version == 4 && is_dwo) |
6105 | READ_ULEB (offset, curr, end); | |
6106 | else | |
6107 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
4ccf1e31 | 6108 | string = fetch_indirect_string (offset); |
7a7e1061 | 6109 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6110 | lineno, string); |
6111 | break; | |
6112 | ||
7a7e1061 | 6113 | case DW_MACRO_import: |
0c588247 | 6114 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6115 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
6116 | (unsigned long) offset); |
6117 | break; | |
6118 | ||
7a7e1061 | 6119 | case DW_MACRO_define_sup: |
cd30bcef | 6120 | READ_ULEB (lineno, curr, end); |
0c588247 | 6121 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6122 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
6123 | lineno, (unsigned long) offset); |
6124 | break; | |
6125 | ||
7a7e1061 | 6126 | case DW_MACRO_undef_sup: |
cd30bcef | 6127 | READ_ULEB (lineno, curr, end); |
0c588247 | 6128 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6129 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
6130 | lineno, (unsigned long) offset); |
6131 | break; | |
6132 | ||
7a7e1061 | 6133 | case DW_MACRO_import_sup: |
0c588247 | 6134 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6135 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
6136 | (unsigned long) offset); |
6137 | break; | |
6138 | ||
e4b7104b NC |
6139 | case DW_MACRO_define_strx: |
6140 | case DW_MACRO_undef_strx: | |
6141 | READ_ULEB (lineno, curr, end); | |
6142 | READ_ULEB (offset, curr, end); | |
6143 | string = (const unsigned char *) | |
015dc7e1 | 6144 | fetch_indexed_string (offset, NULL, offset_size, false); |
e4b7104b NC |
6145 | if (op == DW_MACRO_define_strx) |
6146 | printf (" DW_MACRO_define_strx "); | |
6147 | else | |
6148 | printf (" DW_MACRO_undef_strx "); | |
6149 | if (do_wide) | |
39f381cb | 6150 | printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset)); |
e4b7104b NC |
6151 | printf (_("lineno : %d macro : %s\n"), |
6152 | lineno, string); | |
6153 | break; | |
6154 | ||
4ccf1e31 | 6155 | default: |
e4b7104b NC |
6156 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) |
6157 | { | |
6158 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); | |
6159 | break; | |
6160 | } | |
6161 | ||
4ccf1e31 JJ |
6162 | if (extended_ops == NULL || extended_ops[op] == NULL) |
6163 | { | |
6164 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
6165 | return 0; | |
6166 | } | |
6167 | else | |
6168 | { | |
6169 | /* Skip over unhandled opcodes. */ | |
6170 | dwarf_vma nargs, n; | |
6171 | unsigned char *desc = extended_ops[op]; | |
cd30bcef | 6172 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
6173 | if (nargs == 0) |
6174 | { | |
7a7e1061 | 6175 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
6176 | break; |
6177 | } | |
7a7e1061 | 6178 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
6179 | for (n = 0; n < nargs; n++) |
6180 | { | |
0c588247 NC |
6181 | int val; |
6182 | ||
77145576 | 6183 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 6184 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 6185 | curr |
77145576 | 6186 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 6187 | start, curr, end, 0, 0, offset_size, |
341f9135 | 6188 | version, NULL, 0, NULL, |
ec1b0fbb | 6189 | NULL, ' ', -1); |
4ccf1e31 JJ |
6190 | if (n != nargs - 1) |
6191 | printf (","); | |
6192 | } | |
6193 | printf ("\n"); | |
6194 | } | |
6195 | break; | |
6196 | } | |
6197 | } | |
6198 | ||
6199 | printf ("\n"); | |
b4eb7656 | 6200 | } |
4ccf1e31 JJ |
6201 | |
6202 | return 1; | |
6203 | } | |
6204 | ||
19e6b90e L |
6205 | static int |
6206 | display_debug_abbrev (struct dwarf_section *section, | |
6207 | void *file ATTRIBUTE_UNUSED) | |
6208 | { | |
6209 | abbrev_entry *entry; | |
6210 | unsigned char *start = section->start; | |
19e6b90e | 6211 | |
015dc7e1 | 6212 | introduce (section, false); |
19e6b90e L |
6213 | |
6214 | do | |
6215 | { | |
bcd213b2 NC |
6216 | abbrev_list * list; |
6217 | dwarf_vma offset; | |
7282333f | 6218 | |
bcd213b2 | 6219 | offset = start - section->start; |
76868f36 | 6220 | list = find_abbrev_list_by_abbrev_offset (0, offset); |
bcd213b2 NC |
6221 | if (list == NULL) |
6222 | { | |
76868f36 | 6223 | list = new_abbrev_list (0, offset); |
f2f9554b | 6224 | start = process_abbrev_set (section, 0, section->size, offset, list); |
bcd213b2 NC |
6225 | list->start_of_next_abbrevs = start; |
6226 | } | |
6227 | else | |
6228 | start = list->start_of_next_abbrevs; | |
19e6b90e | 6229 | |
bcd213b2 | 6230 | if (list->first_abbrev == NULL) |
19e6b90e L |
6231 | continue; |
6232 | ||
bcd213b2 | 6233 | printf (_(" Number TAG (0x%lx)\n"), (long) offset); |
19e6b90e | 6234 | |
bcd213b2 | 6235 | for (entry = list->first_abbrev; entry; entry = entry->next) |
19e6b90e L |
6236 | { |
6237 | abbrev_attr *attr; | |
6238 | ||
cc5914eb | 6239 | printf (" %ld %s [%s]\n", |
bcd213b2 | 6240 | entry->number, |
19e6b90e L |
6241 | get_TAG_name (entry->tag), |
6242 | entry->children ? _("has children") : _("no children")); | |
6243 | ||
6244 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
6245 | { |
6246 | printf (" %-18s %s", | |
6247 | get_AT_name (attr->attribute), | |
6248 | get_FORM_name (attr->form)); | |
6249 | if (attr->form == DW_FORM_implicit_const) | |
0121f438 | 6250 | printf (": %s", dwarf_vmatoa ("d", attr->implicit_const)); |
77145576 JK |
6251 | putchar ('\n'); |
6252 | } | |
19e6b90e L |
6253 | } |
6254 | } | |
6255 | while (start); | |
6256 | ||
6257 | printf ("\n"); | |
6258 | ||
6259 | return 1; | |
6260 | } | |
6261 | ||
42bcef4a AB |
6262 | /* Return true when ADDR is the maximum address, when addresses are |
6263 | POINTER_SIZE bytes long. */ | |
6264 | ||
015dc7e1 | 6265 | static bool |
42bcef4a AB |
6266 | is_max_address (dwarf_vma addr, unsigned int pointer_size) |
6267 | { | |
6268 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
6269 | return ((addr & mask) == mask); | |
6270 | } | |
6271 | ||
9f272209 AO |
6272 | /* Display a view pair list starting at *VSTART_PTR and ending at |
6273 | VLISTEND within SECTION. */ | |
6274 | ||
6275 | static void | |
6276 | display_view_pair_list (struct dwarf_section *section, | |
6277 | unsigned char **vstart_ptr, | |
6278 | unsigned int debug_info_entry, | |
6279 | unsigned char *vlistend) | |
6280 | { | |
6281 | unsigned char *vstart = *vstart_ptr; | |
6282 | unsigned char *section_end = section->start + section->size; | |
6283 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
6284 | ||
6285 | if (vlistend < section_end) | |
6286 | section_end = vlistend; | |
6287 | ||
6288 | putchar ('\n'); | |
6289 | ||
6290 | while (vstart < section_end) | |
6291 | { | |
6292 | dwarf_vma off = vstart - section->start; | |
6293 | dwarf_vma vbegin, vend; | |
6294 | ||
cd30bcef | 6295 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 6296 | if (vstart == section_end) |
cd30bcef | 6297 | break; |
9f272209 | 6298 | |
cd30bcef | 6299 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6300 | printf (" %8.8lx ", (unsigned long) off); |
6301 | ||
6302 | print_dwarf_view (vbegin, pointer_size, 1); | |
6303 | print_dwarf_view (vend, pointer_size, 1); | |
6304 | printf (_("location view pair\n")); | |
6305 | } | |
6306 | ||
6307 | putchar ('\n'); | |
6308 | *vstart_ptr = vstart; | |
6309 | } | |
6310 | ||
4723351a CC |
6311 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
6312 | ||
6313 | static void | |
6314 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
6315 | unsigned char **start_ptr, |
6316 | unsigned int debug_info_entry, | |
359ca075 JK |
6317 | dwarf_vma offset, |
6318 | dwarf_vma base_address, | |
9f272209 | 6319 | unsigned char **vstart_ptr, |
b4eb7656 | 6320 | int has_frame_base) |
4723351a | 6321 | { |
9f272209 | 6322 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6323 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6324 | unsigned long cu_offset; |
6325 | unsigned int pointer_size; | |
6326 | unsigned int offset_size; | |
6327 | int dwarf_version; | |
4723351a CC |
6328 | |
6329 | dwarf_vma begin; | |
6330 | dwarf_vma end; | |
6331 | unsigned short length; | |
6332 | int need_frame_base; | |
6333 | ||
82b1b41b NC |
6334 | if (debug_info_entry >= num_debug_info_entries) |
6335 | { | |
6336 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
6337 | debug_info_entry); | |
6338 | return; | |
6339 | } | |
b4eb7656 | 6340 | |
82b1b41b NC |
6341 | cu_offset = debug_information [debug_info_entry].cu_offset; |
6342 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6343 | offset_size = debug_information [debug_info_entry].offset_size; | |
6344 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 6345 | |
f41e4712 NC |
6346 | if (pointer_size < 2 || pointer_size > 8) |
6347 | { | |
6348 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6349 | pointer_size, debug_info_entry); | |
6350 | return; | |
6351 | } | |
6352 | ||
4723351a CC |
6353 | while (1) |
6354 | { | |
359ca075 | 6355 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 6356 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 6357 | |
78480097 | 6358 | if (2 * pointer_size > (size_t) (section_end - start)) |
b4eb7656 AM |
6359 | { |
6360 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6361 | (unsigned long) offset); |
b4eb7656 AM |
6362 | break; |
6363 | } | |
4723351a | 6364 | |
359ca075 | 6365 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 6366 | |
0c588247 NC |
6367 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
6368 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 6369 | |
4723351a | 6370 | if (begin == 0 && end == 0) |
b4eb7656 | 6371 | { |
d1c4b12b NC |
6372 | /* PR 18374: In a object file we can have a location list that |
6373 | starts with a begin and end of 0 because there are relocations | |
6374 | that need to be applied to the addresses. Actually applying | |
6375 | the relocations now does not help as they will probably resolve | |
6376 | to 0, since the object file has not been fully linked. Real | |
6377 | end of list markers will not have any relocations against them. */ | |
6378 | if (! reloc_at (section, off) | |
6379 | && ! reloc_at (section, off + pointer_size)) | |
6380 | { | |
6381 | printf (_("<End of list>\n")); | |
6382 | break; | |
6383 | } | |
b4eb7656 | 6384 | } |
4723351a CC |
6385 | |
6386 | /* Check base address specifiers. */ | |
42bcef4a AB |
6387 | if (is_max_address (begin, pointer_size) |
6388 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
6389 | { |
6390 | base_address = end; | |
6391 | print_dwarf_vma (begin, pointer_size); | |
6392 | print_dwarf_vma (end, pointer_size); | |
6393 | printf (_("(base address)\n")); | |
6394 | continue; | |
6395 | } | |
4723351a | 6396 | |
9f272209 AO |
6397 | if (vstart) |
6398 | { | |
9f272209 AO |
6399 | off = offset + (vstart - *start_ptr); |
6400 | ||
cd30bcef | 6401 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6402 | print_dwarf_view (vbegin, pointer_size, 1); |
6403 | ||
cd30bcef | 6404 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6405 | print_dwarf_view (vend, pointer_size, 1); |
6406 | ||
6407 | printf (_("views at %8.8lx for:\n %*s "), | |
6408 | (unsigned long) off, 8, ""); | |
6409 | } | |
6410 | ||
78480097 | 6411 | if (2 > (size_t) (section_end - start)) |
b4eb7656 AM |
6412 | { |
6413 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6414 | (unsigned long) offset); |
b4eb7656 AM |
6415 | break; |
6416 | } | |
4723351a | 6417 | |
0c588247 | 6418 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6419 | |
78480097 | 6420 | if (length > (size_t) (section_end - start)) |
b4eb7656 AM |
6421 | { |
6422 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6423 | (unsigned long) offset); |
b4eb7656 AM |
6424 | break; |
6425 | } | |
4723351a CC |
6426 | |
6427 | print_dwarf_vma (begin + base_address, pointer_size); | |
6428 | print_dwarf_vma (end + base_address, pointer_size); | |
6429 | ||
6430 | putchar ('('); | |
6431 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6432 | pointer_size, |
6433 | offset_size, | |
6434 | dwarf_version, | |
6435 | length, | |
6436 | cu_offset, section); | |
4723351a CC |
6437 | putchar (')'); |
6438 | ||
6439 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6440 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 6441 | |
9f272209 | 6442 | if (begin == end && vbegin == vend) |
b4eb7656 | 6443 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6444 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 6445 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
6446 | |
6447 | putchar ('\n'); | |
6448 | ||
6449 | start += length; | |
6450 | } | |
6451 | ||
6452 | *start_ptr = start; | |
9f272209 | 6453 | *vstart_ptr = vstart; |
4723351a CC |
6454 | } |
6455 | ||
77145576 JK |
6456 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6457 | ||
6458 | static void | |
6459 | display_loclists_list (struct dwarf_section *section, | |
6460 | unsigned char **start_ptr, | |
6461 | unsigned int debug_info_entry, | |
6462 | dwarf_vma offset, | |
6463 | dwarf_vma base_address, | |
9f272209 | 6464 | unsigned char **vstart_ptr, |
77145576 JK |
6465 | int has_frame_base) |
6466 | { | |
9f272209 | 6467 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
6468 | unsigned char *section_end = section->start + section->size; |
6469 | unsigned long cu_offset; | |
6470 | unsigned int pointer_size; | |
6471 | unsigned int offset_size; | |
6472 | int dwarf_version; | |
77145576 | 6473 | |
9dfd0db9 | 6474 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
6475 | dwarf_vma begin = -1, vbegin = -1; |
6476 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
6477 | dwarf_vma length; |
6478 | int need_frame_base; | |
6479 | ||
6480 | if (debug_info_entry >= num_debug_info_entries) | |
6481 | { | |
6482 | warn (_("No debug information available for " | |
6483 | "loclists lists of entry: %u\n"), | |
6484 | debug_info_entry); | |
6485 | return; | |
6486 | } | |
6487 | ||
6488 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6489 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6490 | offset_size = debug_information [debug_info_entry].offset_size; | |
6491 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6492 | ||
6493 | if (pointer_size < 2 || pointer_size > 8) | |
6494 | { | |
6495 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6496 | pointer_size, debug_info_entry); | |
6497 | return; | |
6498 | } | |
6499 | ||
6500 | while (1) | |
6501 | { | |
6502 | dwarf_vma off = offset + (start - *start_ptr); | |
6503 | enum dwarf_location_list_entry_type llet; | |
6504 | ||
6505 | if (start + 1 > section_end) | |
6506 | { | |
6507 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6508 | (unsigned long) offset); | |
6509 | break; | |
6510 | } | |
6511 | ||
6512 | printf (" %8.8lx ", (unsigned long) off); | |
6513 | ||
6514 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6515 | ||
1c9f770d MW |
6516 | if (vstart && (llet == DW_LLE_offset_pair |
6517 | || llet == DW_LLE_start_end | |
6518 | || llet == DW_LLE_start_length)) | |
9f272209 AO |
6519 | { |
6520 | off = offset + (vstart - *start_ptr); | |
6521 | ||
cd30bcef | 6522 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6523 | print_dwarf_view (vbegin, pointer_size, 1); |
6524 | ||
cd30bcef | 6525 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6526 | print_dwarf_view (vend, pointer_size, 1); |
6527 | ||
6528 | printf (_("views at %8.8lx for:\n %*s "), | |
6529 | (unsigned long) off, 8, ""); | |
6530 | } | |
6531 | ||
77145576 JK |
6532 | switch (llet) |
6533 | { | |
6534 | case DW_LLE_end_of_list: | |
6535 | printf (_("<End of list>\n")); | |
6536 | break; | |
6537 | case DW_LLE_offset_pair: | |
cd30bcef | 6538 | READ_ULEB (begin, start, section_end); |
1c9f770d | 6539 | begin += base_address; |
cd30bcef | 6540 | READ_ULEB (end, start, section_end); |
1c9f770d MW |
6541 | end += base_address; |
6542 | break; | |
6543 | case DW_LLE_start_end: | |
6544 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6545 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
6546 | break; | |
6547 | case DW_LLE_start_length: | |
6548 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6549 | READ_ULEB (end, start, section_end); | |
6550 | end += begin; | |
77145576 JK |
6551 | break; |
6552 | case DW_LLE_base_address: | |
6553 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6554 | section_end); | |
6555 | print_dwarf_vma (base_address, pointer_size); | |
6556 | printf (_("(base address)\n")); | |
6557 | break; | |
9f272209 AO |
6558 | #ifdef DW_LLE_view_pair |
6559 | case DW_LLE_view_pair: | |
6560 | if (vstart) | |
6561 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 6562 | READ_ULEB (vbegin, start, section_end); |
9f272209 AO |
6563 | print_dwarf_view (vbegin, pointer_size, 1); |
6564 | ||
cd30bcef | 6565 | READ_ULEB (vend, start, section_end); |
9f272209 AO |
6566 | print_dwarf_view (vend, pointer_size, 1); |
6567 | ||
6568 | printf (_("views for:\n")); | |
6569 | continue; | |
6570 | #endif | |
77145576 JK |
6571 | default: |
6572 | error (_("Invalid location list entry type %d\n"), llet); | |
6573 | return; | |
6574 | } | |
6575 | if (llet == DW_LLE_end_of_list) | |
6576 | break; | |
1c9f770d MW |
6577 | if (llet != DW_LLE_offset_pair |
6578 | && llet != DW_LLE_start_end | |
6579 | && llet != DW_LLE_start_length) | |
77145576 JK |
6580 | continue; |
6581 | ||
78480097 | 6582 | if (start == section_end) |
77145576 JK |
6583 | { |
6584 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6585 | (unsigned long) offset); | |
6586 | break; | |
6587 | } | |
cd30bcef | 6588 | READ_ULEB (length, start, section_end); |
77145576 | 6589 | |
78480097 AM |
6590 | if (length > (size_t) (section_end - start)) |
6591 | { | |
6592 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6593 | (unsigned long) offset); | |
6594 | break; | |
6595 | } | |
6596 | ||
1c9f770d MW |
6597 | print_dwarf_vma (begin, pointer_size); |
6598 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
6599 | |
6600 | putchar ('('); | |
6601 | need_frame_base = decode_location_expression (start, | |
6602 | pointer_size, | |
6603 | offset_size, | |
6604 | dwarf_version, | |
6605 | length, | |
6606 | cu_offset, section); | |
6607 | putchar (')'); | |
6608 | ||
6609 | if (need_frame_base && !has_frame_base) | |
6610 | printf (_(" [without DW_AT_frame_base]")); | |
6611 | ||
9f272209 | 6612 | if (begin == end && vbegin == vend) |
77145576 | 6613 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6614 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
6615 | fputs (_(" (start > end)"), stdout); |
6616 | ||
6617 | putchar ('\n'); | |
6618 | ||
6619 | start += length; | |
9f272209 | 6620 | vbegin = vend = -1; |
77145576 JK |
6621 | } |
6622 | ||
9f272209 AO |
6623 | if (vbegin != vm1 || vend != vm1) |
6624 | printf (_("Trailing view pair not used in a range")); | |
6625 | ||
77145576 | 6626 | *start_ptr = start; |
9f272209 | 6627 | *vstart_ptr = vstart; |
77145576 JK |
6628 | } |
6629 | ||
fab128ef CC |
6630 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
6631 | right-adjusted in a field of length LEN, and followed by a space. */ | |
6632 | ||
6633 | static void | |
6634 | print_addr_index (unsigned int idx, unsigned int len) | |
6635 | { | |
6636 | static char buf[15]; | |
6637 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6638 | printf ("%*s ", len, buf); |
fab128ef CC |
6639 | } |
6640 | ||
4723351a CC |
6641 | /* Display a location list from a .dwo section. It uses address indexes rather |
6642 | than embedded addresses. This code closely follows display_loc_list, but the | |
6643 | two are sufficiently different that combining things is very ugly. */ | |
6644 | ||
6645 | static void | |
6646 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6647 | unsigned char **start_ptr, |
6648 | unsigned int debug_info_entry, | |
359ca075 | 6649 | dwarf_vma offset, |
9f272209 | 6650 | unsigned char **vstart_ptr, |
b4eb7656 | 6651 | int has_frame_base) |
4723351a | 6652 | { |
9f272209 | 6653 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6654 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6655 | unsigned long cu_offset; |
6656 | unsigned int pointer_size; | |
6657 | unsigned int offset_size; | |
6658 | int dwarf_version; | |
4723351a CC |
6659 | int entry_type; |
6660 | unsigned short length; | |
6661 | int need_frame_base; | |
fab128ef | 6662 | unsigned int idx; |
4723351a | 6663 | |
82b1b41b NC |
6664 | if (debug_info_entry >= num_debug_info_entries) |
6665 | { | |
6666 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6667 | debug_info_entry); | |
6668 | return; | |
6669 | } | |
6670 | ||
6671 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6672 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6673 | offset_size = debug_information [debug_info_entry].offset_size; | |
6674 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6675 | ||
f41e4712 NC |
6676 | if (pointer_size < 2 || pointer_size > 8) |
6677 | { | |
6678 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6679 | pointer_size, debug_info_entry); | |
6680 | return; | |
6681 | } | |
6682 | ||
4723351a CC |
6683 | while (1) |
6684 | { | |
359ca075 | 6685 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6686 | |
fab128ef | 6687 | if (start >= section_end) |
b4eb7656 AM |
6688 | { |
6689 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6690 | (unsigned long) offset); |
b4eb7656 AM |
6691 | break; |
6692 | } | |
4723351a | 6693 | |
0c588247 | 6694 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6695 | |
6696 | if (vstart) | |
6697 | switch (entry_type) | |
6698 | { | |
6699 | default: | |
6700 | break; | |
6701 | ||
6702 | case 2: | |
6703 | case 3: | |
6704 | case 4: | |
6705 | { | |
6706 | dwarf_vma view; | |
6707 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6708 | ||
cd30bcef | 6709 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6710 | print_dwarf_view (view, 8, 1); |
6711 | ||
cd30bcef | 6712 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6713 | print_dwarf_view (view, 8, 1); |
6714 | ||
6715 | printf (_("views at %8.8lx for:\n %*s "), | |
6716 | (unsigned long) off, 8, ""); | |
6717 | ||
6718 | } | |
6719 | break; | |
6720 | } | |
6721 | ||
4723351a | 6722 | switch (entry_type) |
b4eb7656 AM |
6723 | { |
6724 | case 0: /* A terminating entry. */ | |
6725 | *start_ptr = start; | |
9f272209 | 6726 | *vstart_ptr = vstart; |
b4eb7656 AM |
6727 | printf (_("<End of list>\n")); |
6728 | return; | |
6729 | case 1: /* A base-address entry. */ | |
cd30bcef | 6730 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6731 | print_addr_index (idx, 8); |
9f272209 | 6732 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6733 | printf (_("(base address selection entry)\n")); |
6734 | continue; | |
6735 | case 2: /* A start/end entry. */ | |
cd30bcef | 6736 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6737 | print_addr_index (idx, 8); |
cd30bcef | 6738 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6739 | print_addr_index (idx, 8); |
6740 | break; | |
6741 | case 3: /* A start/length entry. */ | |
cd30bcef | 6742 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6743 | print_addr_index (idx, 8); |
6744 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6745 | printf ("%08x ", idx); | |
6746 | break; | |
6747 | case 4: /* An offset pair entry. */ | |
6748 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6749 | printf ("%08x ", idx); | |
6750 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6751 | printf ("%08x ", idx); | |
6752 | break; | |
6753 | default: | |
6754 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6755 | *start_ptr = start; | |
9f272209 | 6756 | *vstart_ptr = vstart; |
b4eb7656 AM |
6757 | return; |
6758 | } | |
4723351a | 6759 | |
78480097 | 6760 | if (2 > (size_t) (section_end - start)) |
b4eb7656 AM |
6761 | { |
6762 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6763 | (unsigned long) offset); |
b4eb7656 AM |
6764 | break; |
6765 | } | |
4723351a | 6766 | |
0c588247 | 6767 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
78480097 | 6768 | if (length > (size_t) (section_end - start)) |
b4eb7656 AM |
6769 | { |
6770 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6771 | (unsigned long) offset); |
b4eb7656 AM |
6772 | break; |
6773 | } | |
4723351a CC |
6774 | |
6775 | putchar ('('); | |
6776 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6777 | pointer_size, |
6778 | offset_size, | |
6779 | dwarf_version, | |
6780 | length, | |
6781 | cu_offset, section); | |
4723351a CC |
6782 | putchar (')'); |
6783 | ||
6784 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6785 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6786 | |
6787 | putchar ('\n'); | |
6788 | ||
6789 | start += length; | |
6790 | } | |
6791 | ||
6792 | *start_ptr = start; | |
9f272209 | 6793 | *vstart_ptr = vstart; |
4723351a CC |
6794 | } |
6795 | ||
9f272209 AO |
6796 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6797 | loc_views. */ | |
51d0d03f | 6798 | |
9f272209 | 6799 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6800 | |
6801 | static int | |
6802 | loc_offsets_compar (const void *ap, const void *bp) | |
6803 | { | |
6804 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6805 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6806 | ||
9f272209 AO |
6807 | int ret = (a > b) - (b > a); |
6808 | if (ret) | |
6809 | return ret; | |
6810 | ||
6811 | a = loc_views[*(const unsigned int *) ap]; | |
6812 | b = loc_views[*(const unsigned int *) bp]; | |
6813 | ||
6814 | ret = (a > b) - (b > a); | |
6815 | ||
6816 | return ret; | |
51d0d03f JJ |
6817 | } |
6818 | ||
19e6b90e L |
6819 | static int |
6820 | display_debug_loc (struct dwarf_section *section, void *file) | |
6821 | { | |
9f272209 | 6822 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6823 | unsigned long bytes; |
6824 | unsigned char *section_begin = start; | |
6825 | unsigned int num_loc_list = 0; | |
6826 | unsigned long last_offset = 0; | |
9f272209 | 6827 | unsigned long last_view = 0; |
19e6b90e L |
6828 | unsigned int first = 0; |
6829 | unsigned int i; | |
6830 | unsigned int j; | |
6831 | int seen_first_offset = 0; | |
51d0d03f | 6832 | int locs_sorted = 1; |
9f272209 | 6833 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6834 | unsigned int *array = NULL; |
4723351a | 6835 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 6836 | bool is_dwo = false; |
77145576 JK |
6837 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6838 | dwarf_vma expected_start = 0; | |
4723351a CC |
6839 | |
6840 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
015dc7e1 | 6841 | is_dwo = true; |
19e6b90e L |
6842 | |
6843 | bytes = section->size; | |
19e6b90e L |
6844 | |
6845 | if (bytes == 0) | |
6846 | { | |
6847 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6848 | return 0; | |
6849 | } | |
6850 | ||
77145576 JK |
6851 | if (is_loclists) |
6852 | { | |
6853 | unsigned char *hdrptr = section_begin; | |
6854 | dwarf_vma ll_length; | |
6855 | unsigned short ll_version; | |
6856 | unsigned char *end = section_begin + section->size; | |
6857 | unsigned char address_size, segment_selector_size; | |
6858 | uint32_t offset_entry_count; | |
6859 | ||
6860 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6861 | if (ll_length == 0xffffffff) | |
6862 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6863 | ||
6864 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6865 | if (ll_version != 5) | |
6866 | { | |
6867 | warn (_("The %s section contains corrupt or " | |
6868 | "unsupported version number: %d.\n"), | |
6869 | section->name, ll_version); | |
6870 | return 0; | |
6871 | } | |
6872 | ||
6873 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6874 | ||
6875 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6876 | if (segment_selector_size != 0) | |
6877 | { | |
6878 | warn (_("The %s section contains " | |
6879 | "unsupported segment selector size: %d.\n"), | |
6880 | section->name, segment_selector_size); | |
6881 | return 0; | |
6882 | } | |
6883 | ||
6884 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6885 | if (offset_entry_count != 0) | |
6886 | { | |
6887 | warn (_("The %s section contains " | |
6888 | "unsupported offset entry count: %d.\n"), | |
6889 | section->name, offset_entry_count); | |
6890 | return 0; | |
6891 | } | |
6892 | ||
6893 | expected_start = hdrptr - section_begin; | |
6894 | } | |
6895 | ||
1febe64d NC |
6896 | if (load_debug_info (file) == 0) |
6897 | { | |
6898 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6899 | section->name); | |
6900 | return 0; | |
6901 | } | |
19e6b90e L |
6902 | |
6903 | /* Check the order of location list in .debug_info section. If | |
6904 | offsets of location lists are in the ascending order, we can | |
6905 | use `debug_information' directly. */ | |
6906 | for (i = 0; i < num_debug_info_entries; i++) | |
6907 | { | |
6908 | unsigned int num; | |
6909 | ||
6910 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6911 | if (num > num_loc_list) |
6912 | num_loc_list = num; | |
19e6b90e L |
6913 | |
6914 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6915 | if (locs_sorted && num != 0) |
19e6b90e L |
6916 | { |
6917 | if (!seen_first_offset) | |
6918 | { | |
6919 | /* This is the first location list. */ | |
6920 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6921 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6922 | first = i; |
6923 | seen_first_offset = 1; | |
6924 | j = 1; | |
6925 | } | |
6926 | else | |
6927 | j = 0; | |
6928 | ||
6929 | for (; j < num; j++) | |
6930 | { | |
6931 | if (last_offset > | |
9f272209 AO |
6932 | debug_information [i].loc_offsets [j] |
6933 | || (last_offset == debug_information [i].loc_offsets [j] | |
6934 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6935 | { |
51d0d03f | 6936 | locs_sorted = 0; |
19e6b90e L |
6937 | break; |
6938 | } | |
6939 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6940 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6941 | } |
6942 | } | |
6943 | } | |
6944 | ||
19e6b90e L |
6945 | if (!seen_first_offset) |
6946 | error (_("No location lists in .debug_info section!\n")); | |
6947 | ||
d4bfc77b | 6948 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6949 | && debug_information [first].loc_offsets [0] != expected_start |
6950 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6951 | warn (_("Location lists in %s section start at 0x%s\n"), |
6952 | section->name, | |
6953 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6954 | |
51d0d03f JJ |
6955 | if (!locs_sorted) |
6956 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d | 6957 | |
015dc7e1 | 6958 | introduce (section, false); |
dda8d76d | 6959 | |
d1c4b12b NC |
6960 | if (reloc_at (section, 0)) |
6961 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6962 | |
d1c4b12b | 6963 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6964 | |
6965 | seen_first_offset = 0; | |
6966 | for (i = first; i < num_debug_info_entries; i++) | |
6967 | { | |
9f272209 | 6968 | dwarf_vma offset, voffset; |
359ca075 | 6969 | dwarf_vma base_address; |
d1c4b12b | 6970 | unsigned int k; |
19e6b90e L |
6971 | int has_frame_base; |
6972 | ||
51d0d03f JJ |
6973 | if (!locs_sorted) |
6974 | { | |
6975 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6976 | array[k] = k; | |
6977 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6978 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6979 | qsort (array, debug_information [i].num_loc_offsets, |
6980 | sizeof (*array), loc_offsets_compar); | |
6981 | } | |
19e6b90e | 6982 | |
9f272209 | 6983 | int adjacent_view_loclists = 1; |
51d0d03f | 6984 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6985 | { |
51d0d03f JJ |
6986 | j = locs_sorted ? k : array[k]; |
6987 | if (k | |
9f272209 | 6988 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6989 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6990 | == debug_information [i].loc_offsets [j]) |
6991 | && (debug_information [i].loc_views [locs_sorted | |
6992 | ? k - 1 : array [k - 1]] | |
6993 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6994 | continue; |
19e6b90e | 6995 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6996 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6997 | next = section_begin + offset; |
9f272209 AO |
6998 | voffset = debug_information [i].loc_views [j]; |
6999 | if (voffset != vm1) | |
7000 | vnext = section_begin + voffset; | |
7001 | else | |
7002 | vnext = NULL; | |
19e6b90e L |
7003 | base_address = debug_information [i].base_address; |
7004 | ||
9f272209 AO |
7005 | if (vnext && vnext < next) |
7006 | { | |
7007 | vstart = vnext; | |
7008 | display_view_pair_list (section, &vstart, i, next); | |
7009 | if (start == vnext) | |
7010 | start = vstart; | |
7011 | } | |
7012 | ||
7013 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
7014 | seen_first_offset = 1; |
7015 | else | |
7016 | { | |
7017 | if (start < next) | |
7018 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 7019 | (unsigned long) (start - section_begin), |
c8071705 | 7020 | (unsigned long) offset); |
19e6b90e L |
7021 | else if (start > next) |
7022 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 7023 | (unsigned long) (start - section_begin), |
c8071705 | 7024 | (unsigned long) offset); |
19e6b90e L |
7025 | } |
7026 | start = next; | |
9f272209 | 7027 | vstart = vnext; |
19e6b90e L |
7028 | |
7029 | if (offset >= bytes) | |
7030 | { | |
7031 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 7032 | (unsigned long) offset); |
19e6b90e L |
7033 | continue; |
7034 | } | |
7035 | ||
9f272209 AO |
7036 | if (vnext && voffset >= bytes) |
7037 | { | |
7038 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
7039 | (unsigned long) voffset); | |
7040 | continue; | |
7041 | } | |
7042 | ||
77145576 JK |
7043 | if (!is_loclists) |
7044 | { | |
7045 | if (is_dwo) | |
7046 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 7047 | &vstart, has_frame_base); |
77145576 JK |
7048 | else |
7049 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 7050 | &vstart, has_frame_base); |
77145576 | 7051 | } |
b4eb7656 | 7052 | else |
77145576 JK |
7053 | { |
7054 | if (is_dwo) | |
7055 | warn (_("DWO is not yet supported.\n")); | |
7056 | else | |
7057 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
7058 | &vstart, has_frame_base); |
7059 | } | |
7060 | ||
7061 | /* FIXME: this arrangement is quite simplistic. Nothing | |
7062 | requires locview lists to be adjacent to corresponding | |
7063 | loclists, and a single loclist could be augmented by | |
7064 | different locview lists, and vice-versa, unlikely as it | |
7065 | is that it would make sense to do so. Hopefully we'll | |
7066 | have view pair support built into loclists before we ever | |
7067 | need to address all these possibilities. */ | |
7068 | if (adjacent_view_loclists && vnext | |
7069 | && vnext != start && vstart != next) | |
7070 | { | |
7071 | adjacent_view_loclists = 0; | |
7072 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 7073 | } |
9f272209 AO |
7074 | |
7075 | if (vnext && vnext == start) | |
7076 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
7077 | } |
7078 | } | |
031cd65f | 7079 | |
4723351a | 7080 | if (start < section->start + section->size) |
d3a49aa8 AM |
7081 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
7082 | "There are %ld unused bytes at the end of section %s\n", | |
7083 | (long) (section->start + section->size - start)), | |
4723351a | 7084 | (long) (section->start + section->size - start), section->name); |
98fb390a | 7085 | putchar ('\n'); |
51d0d03f | 7086 | free (array); |
19e6b90e L |
7087 | return 1; |
7088 | } | |
7089 | ||
7090 | static int | |
7091 | display_debug_str (struct dwarf_section *section, | |
7092 | void *file ATTRIBUTE_UNUSED) | |
7093 | { | |
7094 | unsigned char *start = section->start; | |
7095 | unsigned long bytes = section->size; | |
7096 | dwarf_vma addr = section->address; | |
7097 | ||
7098 | if (bytes == 0) | |
7099 | { | |
7100 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7101 | return 0; | |
7102 | } | |
7103 | ||
015dc7e1 | 7104 | introduce (section, false); |
19e6b90e L |
7105 | |
7106 | while (bytes) | |
7107 | { | |
7108 | int j; | |
7109 | int k; | |
7110 | int lbytes; | |
7111 | ||
7112 | lbytes = (bytes > 16 ? 16 : bytes); | |
7113 | ||
7114 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
7115 | ||
7116 | for (j = 0; j < 16; j++) | |
7117 | { | |
7118 | if (j < lbytes) | |
7119 | printf ("%2.2x", start[j]); | |
7120 | else | |
7121 | printf (" "); | |
7122 | ||
7123 | if ((j & 3) == 3) | |
7124 | printf (" "); | |
7125 | } | |
7126 | ||
7127 | for (j = 0; j < lbytes; j++) | |
7128 | { | |
7129 | k = start[j]; | |
7130 | if (k >= ' ' && k < 0x80) | |
7131 | printf ("%c", k); | |
7132 | else | |
7133 | printf ("."); | |
7134 | } | |
7135 | ||
7136 | putchar ('\n'); | |
7137 | ||
7138 | start += lbytes; | |
7139 | addr += lbytes; | |
7140 | bytes -= lbytes; | |
7141 | } | |
7142 | ||
7143 | putchar ('\n'); | |
7144 | ||
7145 | return 1; | |
7146 | } | |
7147 | ||
19e6b90e L |
7148 | static int |
7149 | display_debug_info (struct dwarf_section *section, void *file) | |
7150 | { | |
015dc7e1 | 7151 | return process_debug_info (section, file, section->abbrev_sec, false, false); |
19e6b90e L |
7152 | } |
7153 | ||
2b6f5997 CC |
7154 | static int |
7155 | display_debug_types (struct dwarf_section *section, void *file) | |
7156 | { | |
015dc7e1 | 7157 | return process_debug_info (section, file, section->abbrev_sec, false, true); |
6f875884 TG |
7158 | } |
7159 | ||
7160 | static int | |
7161 | display_trace_info (struct dwarf_section *section, void *file) | |
7162 | { | |
015dc7e1 | 7163 | return process_debug_info (section, file, section->abbrev_sec, false, true); |
2b6f5997 | 7164 | } |
19e6b90e L |
7165 | |
7166 | static int | |
7167 | display_debug_aranges (struct dwarf_section *section, | |
7168 | void *file ATTRIBUTE_UNUSED) | |
7169 | { | |
7170 | unsigned char *start = section->start; | |
7171 | unsigned char *end = start + section->size; | |
7172 | ||
015dc7e1 | 7173 | introduce (section, false); |
19e6b90e | 7174 | |
6e3d6dc1 NC |
7175 | /* It does not matter if this load fails, |
7176 | we test for that later on. */ | |
7177 | load_debug_info (file); | |
7178 | ||
19e6b90e L |
7179 | while (start < end) |
7180 | { | |
7181 | unsigned char *hdrptr; | |
7182 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 7183 | unsigned char *addr_ranges; |
2d9472a2 NC |
7184 | dwarf_vma length; |
7185 | dwarf_vma address; | |
e98fdf1a | 7186 | unsigned long sec_off; |
53b8873b | 7187 | unsigned char address_size; |
19e6b90e | 7188 | int excess; |
bf5117e3 | 7189 | unsigned int offset_size; |
6ca07350 | 7190 | unsigned char *end_ranges; |
19e6b90e L |
7191 | |
7192 | hdrptr = start; | |
6ca07350 | 7193 | sec_off = hdrptr - section->start; |
19e6b90e | 7194 | |
0c588247 | 7195 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
7196 | if (arange.ar_length == 0xffffffff) |
7197 | { | |
0c588247 | 7198 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e | 7199 | offset_size = 8; |
19e6b90e L |
7200 | } |
7201 | else | |
6ca07350 | 7202 | offset_size = 4; |
19e6b90e | 7203 | |
6ca07350 | 7204 | if (arange.ar_length > (size_t) (end - hdrptr)) |
e98fdf1a AM |
7205 | { |
7206 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
7207 | section->name, | |
6ca07350 | 7208 | sec_off, |
e98fdf1a AM |
7209 | dwarf_vmatoa ("x", arange.ar_length)); |
7210 | break; | |
7211 | } | |
6ca07350 | 7212 | end_ranges = hdrptr + arange.ar_length; |
e98fdf1a | 7213 | |
6ca07350 AM |
7214 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end_ranges); |
7215 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, | |
7216 | end_ranges); | |
19e6b90e | 7217 | |
6e3d6dc1 NC |
7218 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
7219 | && num_debug_info_entries > 0 | |
7220 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
7221 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 7222 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 7223 | |
6ca07350 AM |
7224 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end_ranges); |
7225 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end_ranges); | |
19e6b90e L |
7226 | |
7227 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
7228 | { | |
67f101ee NC |
7229 | /* PR 19872: A version number of 0 probably means that there is |
7230 | padding at the end of the .debug_aranges section. Gold puts | |
7231 | it there when performing an incremental link, for example. | |
7232 | So do not generate a warning in this case. */ | |
7233 | if (arange.ar_version) | |
7234 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
7235 | break; |
7236 | } | |
7237 | ||
47704ddf KT |
7238 | printf (_(" Length: %ld\n"), |
7239 | (long) arange.ar_length); | |
19e6b90e | 7240 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
7241 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
7242 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
7243 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
7244 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
7245 | ||
53b8873b NC |
7246 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
7247 | ||
f41e4712 NC |
7248 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
7249 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
7250 | { |
7251 | error (_("Invalid address size in %s section!\n"), | |
7252 | section->name); | |
7253 | break; | |
7254 | } | |
7255 | ||
53b8873b NC |
7256 | /* The DWARF spec does not require that the address size be a power |
7257 | of two, but we do. This will have to change if we ever encounter | |
7258 | an uneven architecture. */ | |
7259 | if ((address_size & (address_size - 1)) != 0) | |
7260 | { | |
7261 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
7262 | break; | |
7263 | } | |
cecf136e | 7264 | |
209c9a13 NC |
7265 | if (address_size > 4) |
7266 | printf (_("\n Address Length\n")); | |
7267 | else | |
7268 | printf (_("\n Address Length\n")); | |
19e6b90e | 7269 | |
91d6fa6a | 7270 | addr_ranges = hdrptr; |
19e6b90e | 7271 | |
53b8873b NC |
7272 | /* Must pad to an alignment boundary that is twice the address size. */ |
7273 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 7274 | if (excess) |
91d6fa6a | 7275 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 7276 | |
6ca07350 | 7277 | start = end_ranges; |
1617e571 | 7278 | |
6bee34a1 | 7279 | while (2u * address_size <= (size_t) (start - addr_ranges)) |
19e6b90e | 7280 | { |
6ca07350 AM |
7281 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, start); |
7282 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, start); | |
19e6b90e | 7283 | |
80c35038 | 7284 | printf (" "); |
2d9472a2 NC |
7285 | print_dwarf_vma (address, address_size); |
7286 | print_dwarf_vma (length, address_size); | |
7287 | putchar ('\n'); | |
19e6b90e | 7288 | } |
19e6b90e L |
7289 | } |
7290 | ||
7291 | printf ("\n"); | |
7292 | ||
7293 | return 1; | |
7294 | } | |
7295 | ||
4723351a CC |
7296 | /* Comparison function for qsort. */ |
7297 | static int | |
7298 | comp_addr_base (const void * v0, const void * v1) | |
7299 | { | |
d367307b AM |
7300 | debug_info *info0 = *(debug_info **) v0; |
7301 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
7302 | return info0->addr_base - info1->addr_base; |
7303 | } | |
7304 | ||
7305 | /* Display the debug_addr section. */ | |
7306 | static int | |
7307 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 7308 | void *file) |
4723351a CC |
7309 | { |
7310 | debug_info **debug_addr_info; | |
7311 | unsigned char *entry; | |
7312 | unsigned char *end; | |
7313 | unsigned int i; | |
7314 | unsigned int count; | |
0e12f6c8 | 7315 | unsigned char * header; |
4723351a CC |
7316 | |
7317 | if (section->size == 0) | |
7318 | { | |
7319 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7320 | return 0; | |
7321 | } | |
7322 | ||
7323 | if (load_debug_info (file) == 0) | |
7324 | { | |
7325 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7326 | section->name); | |
7327 | return 0; | |
7328 | } | |
7329 | ||
015dc7e1 | 7330 | introduce (section, false); |
4723351a | 7331 | |
1306a742 NC |
7332 | /* PR 17531: file: cf38d01b. |
7333 | We use xcalloc because a corrupt file may not have initialised all of the | |
7334 | fields in the debug_info structure, which means that the sort below might | |
7335 | try to move uninitialised data. */ | |
7336 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 7337 | sizeof (debug_info *)); |
4723351a CC |
7338 | |
7339 | count = 0; | |
7340 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 7341 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
7342 | { |
7343 | /* PR 17531: file: cf38d01b. */ | |
7344 | if (debug_information[i].addr_base >= section->size) | |
7345 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
7346 | (unsigned long) debug_information[i].addr_base, i); | |
7347 | else | |
7348 | debug_addr_info [count++] = debug_information + i; | |
7349 | } | |
4723351a CC |
7350 | |
7351 | /* Add a sentinel to make iteration convenient. */ | |
7352 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
7353 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 7354 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 7355 | |
0e12f6c8 | 7356 | header = section->start; |
4723351a CC |
7357 | for (i = 0; i < count; i++) |
7358 | { | |
7359 | unsigned int idx; | |
fab128ef | 7360 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
7361 | |
7362 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 7363 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 7364 | |
fab128ef | 7365 | printf (_("\tIndex\tAddress\n")); |
4723351a | 7366 | entry = section->start + debug_addr_info [i]->addr_base; |
0e12f6c8 TV |
7367 | if (debug_addr_info [i]->dwarf_version >= 5) |
7368 | { | |
7369 | size_t header_size = entry - header; | |
7370 | unsigned char * curr_header = header; | |
7371 | dwarf_vma length; | |
7372 | int version; | |
7373 | int segment_selector_size; | |
7374 | ||
7375 | if (header_size != 8 && header_size != 16) | |
7376 | { | |
7377 | warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"), | |
7378 | section->name, (long) header_size); | |
7379 | return 0; | |
7380 | } | |
7381 | ||
7382 | SAFE_BYTE_GET_AND_INC (length, curr_header, 4, entry); | |
7383 | if (length == 0xffffffff) | |
a7077ce7 | 7384 | SAFE_BYTE_GET_AND_INC (length, curr_header, 8, entry); |
0e12f6c8 TV |
7385 | end = curr_header + length; |
7386 | ||
7387 | SAFE_BYTE_GET_AND_INC (version, curr_header, 2, entry); | |
7388 | if (version != 5) | |
7389 | warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"), | |
7390 | section->name, version); | |
7391 | ||
7392 | SAFE_BYTE_GET_AND_INC (address_size, curr_header, 1, entry); | |
7393 | SAFE_BYTE_GET_AND_INC (segment_selector_size, curr_header, 1, entry); | |
7394 | address_size += segment_selector_size; | |
7395 | } | |
7396 | else | |
7397 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
7398 | header = end; | |
4723351a CC |
7399 | idx = 0; |
7400 | while (entry < end) | |
b4eb7656 AM |
7401 | { |
7402 | dwarf_vma base = byte_get (entry, address_size); | |
7403 | printf (_("\t%d:\t"), idx); | |
7404 | print_dwarf_vma (base, address_size); | |
7405 | printf ("\n"); | |
7406 | entry += address_size; | |
7407 | idx++; | |
7408 | } | |
4723351a CC |
7409 | } |
7410 | printf ("\n"); | |
7411 | ||
7412 | free (debug_addr_info); | |
7413 | return 1; | |
7414 | } | |
7415 | ||
7416 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 7417 | |
4723351a CC |
7418 | static int |
7419 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 7420 | void *file ATTRIBUTE_UNUSED) |
4723351a | 7421 | { |
9f27c364 HPN |
7422 | unsigned long idx; |
7423 | ||
4723351a CC |
7424 | if (section->size == 0) |
7425 | { | |
7426 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7427 | return 0; | |
7428 | } | |
e4b7104b NC |
7429 | |
7430 | unsigned char *start = section->start; | |
7431 | unsigned char *end = start + section->size; | |
7432 | unsigned char *curr = start; | |
7433 | ||
63b4cc53 | 7434 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 7435 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
39f381cb NC |
7436 | |
7437 | if (dwo) | |
7438 | load_debug_section_with_follow (str_dwo, file); | |
7439 | else | |
7440 | load_debug_section_with_follow (str, file); | |
e4b7104b | 7441 | |
015dc7e1 | 7442 | introduce (section, false); |
e4b7104b NC |
7443 | |
7444 | while (curr < end) | |
7445 | { | |
7446 | dwarf_vma length; | |
7447 | dwarf_vma entry_length; | |
7448 | ||
7449 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
7450 | /* FIXME: We assume that this means 64-bit DWARF is being used. */ | |
7451 | if (length == 0xffffffff) | |
7452 | { | |
a7077ce7 | 7453 | SAFE_BYTE_GET_AND_INC (length, curr, 8, end); |
e4b7104b NC |
7454 | entry_length = 8; |
7455 | } | |
7456 | else | |
7457 | entry_length = 4; | |
7458 | ||
95abb394 | 7459 | unsigned char *entries_end; |
39f381cb NC |
7460 | if (length == 0) |
7461 | { | |
7462 | /* This is probably an old style .debug_str_offset section which | |
7463 | just contains offsets and no header (and the first offset is 0). */ | |
7464 | length = section->size; | |
7465 | curr = section->start; | |
95abb394 | 7466 | entries_end = end; |
e4b7104b | 7467 | |
39f381cb NC |
7468 | printf (_(" Length: %#lx\n"), (unsigned long) length); |
7469 | printf (_(" Index Offset [String]\n")); | |
7470 | } | |
7471 | else | |
7472 | { | |
b96a1bcb AM |
7473 | if (length <= (dwarf_vma) (end - curr)) |
7474 | entries_end = curr + length; | |
7475 | else | |
7476 | { | |
7477 | warn (_("Section %s is too small %#lx\n"), | |
7478 | section->name, (unsigned long) section->size); | |
7479 | entries_end = end; | |
7480 | } | |
95abb394 | 7481 | |
39f381cb | 7482 | int version; |
5250d2f0 | 7483 | SAFE_BYTE_GET_AND_INC (version, curr, 2, entries_end); |
39f381cb NC |
7484 | if (version != 5) |
7485 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); | |
7486 | ||
7487 | int padding; | |
5250d2f0 | 7488 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, entries_end); |
39f381cb NC |
7489 | if (padding != 0) |
7490 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); | |
7491 | ||
7492 | printf (_(" Length: %#lx\n"), (unsigned long) length); | |
7493 | printf (_(" Version: %#lx\n"), (unsigned long) version); | |
7494 | printf (_(" Index Offset [String]\n")); | |
7495 | } | |
e4b7104b | 7496 | |
95abb394 | 7497 | for (idx = 0; curr < entries_end; idx++) |
e4b7104b NC |
7498 | { |
7499 | dwarf_vma offset; | |
7500 | const unsigned char * string; | |
7501 | ||
a7077ce7 | 7502 | if ((dwarf_vma) (entries_end - curr) < entry_length) |
95abb394 TV |
7503 | /* Not enough space to read one entry_length, give up. */ |
7504 | return 0; | |
7505 | ||
c4375dd7 | 7506 | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, entries_end); |
39f381cb NC |
7507 | if (dwo) |
7508 | string = (const unsigned char *) | |
9f27c364 | 7509 | fetch_indexed_string (idx, NULL, entry_length, dwo); |
39f381cb NC |
7510 | else |
7511 | string = fetch_indirect_string (offset); | |
7512 | ||
9f27c364 | 7513 | printf (" %8lu %8s %s\n", idx, dwarf_vmatoa ("x", offset), |
e4b7104b NC |
7514 | string); |
7515 | } | |
7516 | } | |
39f381cb | 7517 | |
4723351a CC |
7518 | return 1; |
7519 | } | |
7520 | ||
01a8f077 JK |
7521 | /* Each debug_information[x].range_lists[y] gets this representation for |
7522 | sorting purposes. */ | |
7523 | ||
7524 | struct range_entry | |
467c65bc NC |
7525 | { |
7526 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 7527 | dwarf_vma ranges_offset; |
01a8f077 | 7528 | |
467c65bc NC |
7529 | /* Original debug_information to find parameters of the data. */ |
7530 | debug_info *debug_info_p; | |
7531 | }; | |
01a8f077 JK |
7532 | |
7533 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
7534 | ||
7535 | static int | |
7536 | range_entry_compar (const void *ap, const void *bp) | |
7537 | { | |
3f5e193b NC |
7538 | const struct range_entry *a_re = (const struct range_entry *) ap; |
7539 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
7540 | const dwarf_vma a = a_re->ranges_offset; |
7541 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
7542 | |
7543 | return (a > b) - (b > a); | |
7544 | } | |
7545 | ||
77145576 JK |
7546 | static void |
7547 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
7548 | unsigned int pointer_size, unsigned long offset, | |
7549 | unsigned long base_address) | |
7550 | { | |
7551 | while (start < finish) | |
7552 | { | |
7553 | dwarf_vma begin; | |
7554 | dwarf_vma end; | |
7555 | ||
7556 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7557 | if (start >= finish) | |
7558 | break; | |
7559 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7560 | ||
7561 | printf (" %8.8lx ", offset); | |
7562 | ||
7563 | if (begin == 0 && end == 0) | |
7564 | { | |
7565 | printf (_("<End of list>\n")); | |
7566 | break; | |
7567 | } | |
7568 | ||
7569 | /* Check base address specifiers. */ | |
7570 | if (is_max_address (begin, pointer_size) | |
7571 | && !is_max_address (end, pointer_size)) | |
7572 | { | |
7573 | base_address = end; | |
7574 | print_dwarf_vma (begin, pointer_size); | |
7575 | print_dwarf_vma (end, pointer_size); | |
7576 | printf ("(base address)\n"); | |
7577 | continue; | |
7578 | } | |
7579 | ||
7580 | print_dwarf_vma (begin + base_address, pointer_size); | |
7581 | print_dwarf_vma (end + base_address, pointer_size); | |
7582 | ||
7583 | if (begin == end) | |
7584 | fputs (_("(start == end)"), stdout); | |
7585 | else if (begin > end) | |
7586 | fputs (_("(start > end)"), stdout); | |
7587 | ||
7588 | putchar ('\n'); | |
7589 | } | |
7590 | } | |
7591 | ||
7592 | static void | |
7593 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
7594 | unsigned int pointer_size, unsigned long offset, | |
7595 | unsigned long base_address) | |
7596 | { | |
7597 | unsigned char *next = start; | |
7598 | ||
7599 | while (1) | |
7600 | { | |
7601 | unsigned long off = offset + (start - next); | |
7602 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
7603 | /* Initialize it due to a false compiler warning. */ |
7604 | dwarf_vma begin = -1, length, end = -1; | |
77145576 | 7605 | |
669f463d | 7606 | if (start >= finish) |
77145576 JK |
7607 | { |
7608 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
7609 | offset); | |
7610 | break; | |
7611 | } | |
7612 | ||
7613 | printf (" %8.8lx ", off); | |
7614 | ||
7615 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
7616 | ||
7617 | switch (rlet) | |
7618 | { | |
7619 | case DW_RLE_end_of_list: | |
7620 | printf (_("<End of list>\n")); | |
7621 | break; | |
7622 | case DW_RLE_base_address: | |
7623 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
7624 | print_dwarf_vma (base_address, pointer_size); | |
7625 | printf (_("(base address)\n")); | |
7626 | break; | |
7627 | case DW_RLE_start_length: | |
7628 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
cd30bcef | 7629 | READ_ULEB (length, start, finish); |
77145576 JK |
7630 | end = begin + length; |
7631 | break; | |
7632 | case DW_RLE_offset_pair: | |
cd30bcef AM |
7633 | READ_ULEB (begin, start, finish); |
7634 | READ_ULEB (end, start, finish); | |
77145576 JK |
7635 | break; |
7636 | case DW_RLE_start_end: | |
7637 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7638 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7639 | break; | |
7640 | default: | |
7641 | error (_("Invalid range list entry type %d\n"), rlet); | |
7642 | rlet = DW_RLE_end_of_list; | |
7643 | break; | |
7644 | } | |
7645 | if (rlet == DW_RLE_end_of_list) | |
7646 | break; | |
7647 | if (rlet == DW_RLE_base_address) | |
7648 | continue; | |
7649 | ||
4d932715 BE |
7650 | /* Only a DW_RLE_offset_pair needs the base address added. */ |
7651 | if (rlet == DW_RLE_offset_pair) | |
7652 | { | |
7653 | begin += base_address; | |
7654 | end += base_address; | |
7655 | } | |
7656 | ||
7657 | print_dwarf_vma (begin, pointer_size); | |
7658 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
7659 | |
7660 | if (begin == end) | |
7661 | fputs (_("(start == end)"), stdout); | |
7662 | else if (begin > end) | |
7663 | fputs (_("(start > end)"), stdout); | |
7664 | ||
7665 | putchar ('\n'); | |
7666 | } | |
7667 | } | |
7668 | ||
19e6b90e L |
7669 | static int |
7670 | display_debug_ranges (struct dwarf_section *section, | |
7671 | void *file ATTRIBUTE_UNUSED) | |
7672 | { | |
7673 | unsigned char *start = section->start; | |
a2ff7a4b | 7674 | unsigned char *last_start = start; |
f6f0e17b | 7675 | unsigned long bytes = section->size; |
19e6b90e | 7676 | unsigned char *section_begin = start; |
f6f0e17b | 7677 | unsigned char *finish = start + bytes; |
01a8f077 JK |
7678 | unsigned int num_range_list, i; |
7679 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
7680 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
7681 | /* Initialize it due to a false compiler warning. */ | |
7682 | unsigned char address_size = 0; | |
cb4c35cf | 7683 | dwarf_vma last_offset = 0; |
19e6b90e | 7684 | |
19e6b90e L |
7685 | if (bytes == 0) |
7686 | { | |
7687 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7688 | return 0; | |
7689 | } | |
7690 | ||
77145576 JK |
7691 | if (is_rnglists) |
7692 | { | |
7693 | dwarf_vma initial_length; | |
77145576 JK |
7694 | unsigned char segment_selector_size; |
7695 | unsigned int offset_size, offset_entry_count; | |
7696 | unsigned short version; | |
7697 | ||
7698 | /* Get and check the length of the block. */ | |
7699 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
7700 | ||
7701 | if (initial_length == 0xffffffff) | |
7702 | { | |
7703 | /* This section is 64-bit DWARF 3. */ | |
7704 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
7705 | offset_size = 8; | |
77145576 JK |
7706 | } |
7707 | else | |
b4951546 | 7708 | offset_size = 4; |
77145576 | 7709 | |
b4951546 | 7710 | if (initial_length > (size_t) (finish - start)) |
77145576 JK |
7711 | { |
7712 | /* If the length field has a relocation against it, then we should | |
7713 | not complain if it is inaccurate (and probably negative). | |
7714 | It is copied from .debug_line handling code. */ | |
7715 | if (reloc_at (section, (start - section->start) - offset_size)) | |
7716 | { | |
b4951546 | 7717 | initial_length = finish - start; |
77145576 JK |
7718 | } |
7719 | else | |
7720 | { | |
7721 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
7722 | (long) initial_length); | |
7723 | return 0; | |
7724 | } | |
7725 | } | |
b4951546 | 7726 | finish = start + initial_length; |
77145576 JK |
7727 | |
7728 | /* Get and check the version number. */ | |
7729 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
7730 | ||
7731 | if (version != 5) | |
7732 | { | |
7733 | warn (_("Only DWARF version 5 debug_rnglists info " | |
7734 | "is currently supported.\n")); | |
7735 | return 0; | |
7736 | } | |
7737 | ||
7738 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
7739 | ||
7740 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
7741 | if (segment_selector_size != 0) | |
7742 | { | |
7743 | warn (_("The %s section contains " | |
7744 | "unsupported segment selector size: %d.\n"), | |
7745 | section->name, segment_selector_size); | |
7746 | return 0; | |
7747 | } | |
7748 | ||
7749 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
7750 | if (offset_entry_count != 0) | |
7751 | { | |
7752 | warn (_("The %s section contains " | |
7753 | "unsupported offset entry count: %u.\n"), | |
7754 | section->name, offset_entry_count); | |
7755 | return 0; | |
7756 | } | |
7757 | } | |
7758 | ||
1febe64d NC |
7759 | if (load_debug_info (file) == 0) |
7760 | { | |
7761 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7762 | section->name); | |
7763 | return 0; | |
7764 | } | |
19e6b90e | 7765 | |
01a8f077 | 7766 | num_range_list = 0; |
19e6b90e | 7767 | for (i = 0; i < num_debug_info_entries; i++) |
52ff20fe TV |
7768 | { |
7769 | if (debug_information [i].dwarf_version < 5 && is_rnglists) | |
7770 | /* Skip .debug_rnglists reference. */ | |
7771 | continue; | |
7772 | if (debug_information [i].dwarf_version >= 5 && !is_rnglists) | |
7773 | /* Skip .debug_range reference. */ | |
7774 | continue; | |
7775 | num_range_list += debug_information [i].num_range_lists; | |
7776 | } | |
19e6b90e | 7777 | |
01a8f077 | 7778 | if (num_range_list == 0) |
4723351a CC |
7779 | { |
7780 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7781 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7782 | printf (_("No range lists in .debug_info section.\n")); |
7783 | return 1; | |
7784 | } | |
19e6b90e | 7785 | |
3f5e193b NC |
7786 | range_entries = (struct range_entry *) |
7787 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7788 | range_entry_fill = range_entries; |
19e6b90e | 7789 | |
01a8f077 JK |
7790 | for (i = 0; i < num_debug_info_entries; i++) |
7791 | { | |
7792 | debug_info *debug_info_p = &debug_information[i]; | |
7793 | unsigned int j; | |
7794 | ||
52ff20fe TV |
7795 | if (debug_information [i].dwarf_version < 5 && is_rnglists) |
7796 | /* Skip .debug_rnglists reference. */ | |
7797 | continue; | |
7798 | if (debug_information [i].dwarf_version >= 5 && !is_rnglists) | |
7799 | /* Skip .debug_range reference. */ | |
7800 | continue; | |
7801 | ||
01a8f077 JK |
7802 | for (j = 0; j < debug_info_p->num_range_lists; j++) |
7803 | { | |
7804 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7805 | range_entry_fill->debug_info_p = debug_info_p; | |
7806 | range_entry_fill++; | |
19e6b90e L |
7807 | } |
7808 | } | |
7809 | ||
01a8f077 JK |
7810 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7811 | range_entry_compar); | |
19e6b90e | 7812 | |
d493b283 | 7813 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7814 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7815 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7816 | |
015dc7e1 | 7817 | introduce (section, false); |
dda8d76d | 7818 | |
19e6b90e L |
7819 | printf (_(" Offset Begin End\n")); |
7820 | ||
01a8f077 | 7821 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7822 | { |
01a8f077 JK |
7823 | struct range_entry *range_entry = &range_entries[i]; |
7824 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7825 | unsigned int pointer_size; |
359ca075 | 7826 | dwarf_vma offset; |
01a8f077 | 7827 | unsigned char *next; |
359ca075 | 7828 | dwarf_vma base_address; |
19e6b90e | 7829 | |
77145576 | 7830 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7831 | offset = range_entry->ranges_offset; |
01a8f077 | 7832 | base_address = debug_info_p->base_address; |
cecf136e | 7833 | |
f41e4712 NC |
7834 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7835 | if (pointer_size < 2 || pointer_size > 8) | |
7836 | { | |
7837 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7838 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7839 | continue; |
7840 | } | |
b4eb7656 | 7841 | |
b4951546 | 7842 | if (offset > (size_t) (finish - section_begin)) |
d11ae95e NC |
7843 | { |
7844 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7845 | (unsigned long) offset, i); | |
7846 | continue; | |
7847 | } | |
b4951546 | 7848 | next = section_begin + offset; |
d11ae95e | 7849 | |
cb4c35cf AB |
7850 | /* If multiple DWARF entities reference the same range then we will |
7851 | have multiple entries in the `range_entries' list for the same | |
7852 | offset. Thanks to the sort above these will all be consecutive in | |
7853 | the `range_entries' list, so we can easily ignore duplicates | |
7854 | here. */ | |
7855 | if (i > 0 && last_offset == offset) | |
7856 | continue; | |
7857 | last_offset = offset; | |
7858 | ||
4723351a | 7859 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7860 | { |
01a8f077 JK |
7861 | if (start < next) |
7862 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7863 | (unsigned long) (start - section_begin), | |
7864 | (unsigned long) (next - section_begin), section->name); | |
7865 | else if (start > next) | |
a2ff7a4b AM |
7866 | { |
7867 | if (next == last_start) | |
7868 | continue; | |
7869 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7870 | (unsigned long) (start - section_begin), | |
7871 | (unsigned long) (next - section_begin), section->name); | |
7872 | } | |
01a8f077 | 7873 | } |
d11ae95e | 7874 | |
01a8f077 | 7875 | start = next; |
a2ff7a4b | 7876 | last_start = next; |
19e6b90e | 7877 | |
77145576 JK |
7878 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7879 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7880 | } |
7881 | putchar ('\n'); | |
01a8f077 JK |
7882 | |
7883 | free (range_entries); | |
7884 | ||
19e6b90e L |
7885 | return 1; |
7886 | } | |
7887 | ||
7888 | typedef struct Frame_Chunk | |
7889 | { | |
7890 | struct Frame_Chunk *next; | |
7891 | unsigned char *chunk_start; | |
a1165289 | 7892 | unsigned int ncols; |
19e6b90e L |
7893 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
7894 | short int *col_type; | |
7895 | int *col_offset; | |
7896 | char *augmentation; | |
7897 | unsigned int code_factor; | |
7898 | int data_factor; | |
bf5117e3 NC |
7899 | dwarf_vma pc_begin; |
7900 | dwarf_vma pc_range; | |
32ef3000 | 7901 | unsigned int cfa_reg; |
c8071705 | 7902 | dwarf_vma cfa_offset; |
a1165289 | 7903 | unsigned int ra; |
19e6b90e L |
7904 | unsigned char fde_encoding; |
7905 | unsigned char cfa_exp; | |
604282a7 JJ |
7906 | unsigned char ptr_size; |
7907 | unsigned char segment_size; | |
19e6b90e L |
7908 | } |
7909 | Frame_Chunk; | |
7910 | ||
1296bc99 AB |
7911 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
7912 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
7913 | static const char *const *dwarf_regnames; |
7914 | static unsigned int dwarf_regnames_count; | |
7915 | ||
1296bc99 | 7916 | |
19e6b90e L |
7917 | /* A marker for a col_type that means this column was never referenced |
7918 | in the frame info. */ | |
7919 | #define DW_CFA_unreferenced (-1) | |
7920 | ||
a1165289 | 7921 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7922 | -1 for invalid reg. */ |
7923 | ||
7924 | static int | |
7925 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7926 | { |
a1165289 | 7927 | unsigned int prev = fc->ncols; |
19e6b90e | 7928 | |
665ce1f6 L |
7929 | if (reg < (unsigned int) fc->ncols) |
7930 | return 0; | |
7931 | ||
d9acf707 | 7932 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
7933 | && reg > dwarf_regnames_count) |
7934 | return -1; | |
19e6b90e L |
7935 | |
7936 | fc->ncols = reg + 1; | |
a1165289 NC |
7937 | /* PR 17512: file: 10450-2643-0.004. |
7938 | If reg == -1 then this can happen... */ | |
7939 | if (fc->ncols == 0) | |
7940 | return -1; | |
7941 | ||
06614111 | 7942 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 7943 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
7944 | { |
7945 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7946 | fc->ncols = 0; | |
7947 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7948 | we ever encounter a valid binary that exceeds it. */ | |
7949 | return -1; | |
7950 | } | |
7951 | ||
3f5e193b | 7952 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7953 | sizeof (short int)); |
3f5e193b | 7954 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7955 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7956 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7957 | { | |
7958 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7959 | fc->ncols); | |
7960 | fc->ncols = 0; | |
7961 | return -1; | |
7962 | } | |
19e6b90e L |
7963 | |
7964 | while (prev < fc->ncols) | |
7965 | { | |
7966 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7967 | fc->col_offset[prev] = 0; | |
7968 | prev++; | |
7969 | } | |
665ce1f6 | 7970 | return 1; |
19e6b90e L |
7971 | } |
7972 | ||
2dc4cec1 L |
7973 | static const char *const dwarf_regnames_i386[] = |
7974 | { | |
43234a1e L |
7975 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7976 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7977 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7978 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7979 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7980 | NULL, NULL, /* 19 - 20 */ | |
7981 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7982 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7983 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7984 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7985 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7986 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7987 | "tr", "ldtr", /* 48 - 49 */ | |
7988 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7989 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7990 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7991 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7992 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7993 | NULL, NULL, NULL, /* 90 - 92 */ | |
7994 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7995 | }; |
7996 | ||
3d875af5 L |
7997 | static const char *const dwarf_regnames_iamcu[] = |
7998 | { | |
7999 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
8000 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
8001 | "eip", "eflags", NULL, /* 8 - 10 */ | |
8002 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
8003 | NULL, NULL, /* 19 - 20 */ | |
8004 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
8005 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
8006 | NULL, NULL, NULL, /* 37 - 39 */ | |
8007 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
8008 | "tr", "ldtr", /* 48 - 49 */ | |
8009 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
8010 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
8011 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
8012 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
8013 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
8014 | NULL, NULL, NULL, /* 90 - 92 */ | |
8015 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
8016 | }; | |
8017 | ||
99f6fdd9 | 8018 | static void |
b129eb0e RH |
8019 | init_dwarf_regnames_i386 (void) |
8020 | { | |
8021 | dwarf_regnames = dwarf_regnames_i386; | |
8022 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 8023 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
8024 | } |
8025 | ||
99f6fdd9 | 8026 | static void |
3d875af5 L |
8027 | init_dwarf_regnames_iamcu (void) |
8028 | { | |
8029 | dwarf_regnames = dwarf_regnames_iamcu; | |
8030 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 8031 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
8032 | } |
8033 | ||
2dc4cec1 L |
8034 | static const char *const dwarf_regnames_x86_64[] = |
8035 | { | |
8036 | "rax", "rdx", "rcx", "rbx", | |
8037 | "rsi", "rdi", "rbp", "rsp", | |
8038 | "r8", "r9", "r10", "r11", | |
8039 | "r12", "r13", "r14", "r15", | |
8040 | "rip", | |
8041 | "xmm0", "xmm1", "xmm2", "xmm3", | |
8042 | "xmm4", "xmm5", "xmm6", "xmm7", | |
8043 | "xmm8", "xmm9", "xmm10", "xmm11", | |
8044 | "xmm12", "xmm13", "xmm14", "xmm15", | |
8045 | "st0", "st1", "st2", "st3", | |
8046 | "st4", "st5", "st6", "st7", | |
8047 | "mm0", "mm1", "mm2", "mm3", | |
8048 | "mm4", "mm5", "mm6", "mm7", | |
8049 | "rflags", | |
8050 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
8051 | "fs.base", "gs.base", NULL, NULL, | |
8052 | "tr", "ldtr", | |
43234a1e L |
8053 | "mxcsr", "fcw", "fsw", |
8054 | "xmm16", "xmm17", "xmm18", "xmm19", | |
8055 | "xmm20", "xmm21", "xmm22", "xmm23", | |
8056 | "xmm24", "xmm25", "xmm26", "xmm27", | |
8057 | "xmm28", "xmm29", "xmm30", "xmm31", | |
8058 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
8059 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
8060 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
8061 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
8062 | NULL, NULL, NULL, /* 115 - 117 */ | |
8063 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
8064 | }; |
8065 | ||
99f6fdd9 | 8066 | static void |
b129eb0e RH |
8067 | init_dwarf_regnames_x86_64 (void) |
8068 | { | |
8069 | dwarf_regnames = dwarf_regnames_x86_64; | |
8070 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 8071 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
8072 | } |
8073 | ||
4ee22035 RH |
8074 | static const char *const dwarf_regnames_aarch64[] = |
8075 | { | |
b4eb7656 AM |
8076 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
8077 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
8078 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
8079 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
8080 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
8081 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
8082 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
8083 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
8084 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
8085 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
8086 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
8087 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
8088 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
8089 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
8090 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
8091 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
8092 | }; |
8093 | ||
99f6fdd9 | 8094 | static void |
4ee22035 RH |
8095 | init_dwarf_regnames_aarch64 (void) |
8096 | { | |
8097 | dwarf_regnames = dwarf_regnames_aarch64; | |
8098 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 8099 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
8100 | } |
8101 | ||
d6bb17b0 AA |
8102 | static const char *const dwarf_regnames_s390[] = |
8103 | { | |
8104 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
8105 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8106 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8107 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
8108 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
8109 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
8110 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
8111 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
8112 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
8113 | "pswm", "pswa", | |
8114 | NULL, NULL, | |
8115 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
8116 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
8117 | }; | |
8118 | ||
99f6fdd9 | 8119 | static void |
d6bb17b0 AA |
8120 | init_dwarf_regnames_s390 (void) |
8121 | { | |
8122 | dwarf_regnames = dwarf_regnames_s390; | |
8123 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 8124 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
8125 | } |
8126 | ||
5bb0830d AB |
8127 | static const char *const dwarf_regnames_riscv[] = |
8128 | { | |
8129 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
8130 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
8131 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
8132 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
8133 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
8134 | "fs0", "fs1", /* 40 - 41 */ | |
8135 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
8136 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
8137 | "fs10", "fs11", /* 58 - 59 */ | |
8138 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
8139 | }; | |
8140 | ||
4762fe62 AB |
8141 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
8142 | the large number of CSRs. */ | |
8143 | ||
8144 | static const char * | |
8145 | regname_internal_riscv (unsigned int regno) | |
8146 | { | |
8147 | const char *name = NULL; | |
8148 | ||
8149 | /* Lookup in the table first, this covers GPR and FPR. */ | |
8150 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
8151 | name = dwarf_regnames_riscv [regno]; | |
8152 | else if (regno >= 4096 && regno <= 8191) | |
8153 | { | |
8154 | /* This might be a CSR, these live in a sparse number space from 4096 | |
8155 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
8156 | document. */ | |
8157 | switch (regno) | |
8158 | { | |
8f595e9b NC |
8159 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
8160 | case VALUE + 4096: name = #NAME; break; | |
4762fe62 AB |
8161 | #include "opcode/riscv-opc.h" |
8162 | #undef DECLARE_CSR | |
8163 | ||
8164 | default: | |
8165 | { | |
8166 | static char csr_name[10]; | |
8167 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
8168 | name = csr_name; | |
8169 | } | |
8170 | break; | |
8171 | } | |
8172 | } | |
8173 | ||
8174 | return name; | |
8175 | } | |
8176 | ||
99f6fdd9 | 8177 | static void |
5bb0830d AB |
8178 | init_dwarf_regnames_riscv (void) |
8179 | { | |
4762fe62 AB |
8180 | dwarf_regnames = NULL; |
8181 | dwarf_regnames_count = 8192; | |
8182 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
8183 | } |
8184 | ||
2dc4cec1 | 8185 | void |
955ff7fc | 8186 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 8187 | { |
1296bc99 AB |
8188 | dwarf_regnames_lookup_func = NULL; |
8189 | ||
2dc4cec1 L |
8190 | switch (e_machine) |
8191 | { | |
8192 | case EM_386: | |
b129eb0e | 8193 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
8194 | break; |
8195 | ||
3d875af5 L |
8196 | case EM_IAMCU: |
8197 | init_dwarf_regnames_iamcu (); | |
8198 | break; | |
8199 | ||
2dc4cec1 | 8200 | case EM_X86_64: |
7f502d6c | 8201 | case EM_L1OM: |
7a9068fe | 8202 | case EM_K1OM: |
b129eb0e | 8203 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
8204 | break; |
8205 | ||
4ee22035 RH |
8206 | case EM_AARCH64: |
8207 | init_dwarf_regnames_aarch64 (); | |
8208 | break; | |
8209 | ||
d6bb17b0 AA |
8210 | case EM_S390: |
8211 | init_dwarf_regnames_s390 (); | |
8212 | break; | |
8213 | ||
5bb0830d AB |
8214 | case EM_RISCV: |
8215 | init_dwarf_regnames_riscv (); | |
8216 | break; | |
8217 | ||
2dc4cec1 L |
8218 | default: |
8219 | break; | |
8220 | } | |
8221 | } | |
8222 | ||
229a22cf AB |
8223 | /* Initialize the DWARF register name lookup state based on the |
8224 | architecture and specific machine type of a BFD. */ | |
8225 | ||
8226 | void | |
8227 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
8228 | unsigned long mach) | |
8229 | { | |
1296bc99 AB |
8230 | dwarf_regnames_lookup_func = NULL; |
8231 | ||
229a22cf AB |
8232 | switch (arch) |
8233 | { | |
8234 | case bfd_arch_i386: | |
8235 | switch (mach) | |
8236 | { | |
8237 | case bfd_mach_x86_64: | |
8238 | case bfd_mach_x86_64_intel_syntax: | |
229a22cf AB |
8239 | case bfd_mach_x64_32: |
8240 | case bfd_mach_x64_32_intel_syntax: | |
229a22cf AB |
8241 | init_dwarf_regnames_x86_64 (); |
8242 | break; | |
8243 | ||
8244 | default: | |
8245 | init_dwarf_regnames_i386 (); | |
8246 | break; | |
8247 | } | |
8248 | break; | |
8249 | ||
8250 | case bfd_arch_iamcu: | |
8251 | init_dwarf_regnames_iamcu (); | |
8252 | break; | |
8253 | ||
8254 | case bfd_arch_aarch64: | |
8255 | init_dwarf_regnames_aarch64(); | |
8256 | break; | |
8257 | ||
8258 | case bfd_arch_s390: | |
8259 | init_dwarf_regnames_s390 (); | |
8260 | break; | |
8261 | ||
8262 | case bfd_arch_riscv: | |
8263 | init_dwarf_regnames_riscv (); | |
8264 | break; | |
8265 | ||
8266 | default: | |
8267 | break; | |
8268 | } | |
8269 | } | |
8270 | ||
2dc4cec1 | 8271 | static const char * |
1296bc99 | 8272 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 8273 | { |
1296bc99 | 8274 | if (dwarf_regnames != NULL |
2dc4cec1 L |
8275 | && regno < dwarf_regnames_count |
8276 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
8277 | return dwarf_regnames [regno]; |
8278 | ||
8279 | return NULL; | |
8280 | } | |
8281 | ||
8282 | static const char * | |
8283 | regname (unsigned int regno, int name_only_p) | |
8284 | { | |
8285 | static char reg[64]; | |
8286 | ||
8287 | const char *name = NULL; | |
8288 | ||
8289 | if (dwarf_regnames_lookup_func != NULL) | |
8290 | name = dwarf_regnames_lookup_func (regno); | |
8291 | ||
8292 | if (name != NULL) | |
2dc4cec1 | 8293 | { |
1296bc99 AB |
8294 | if (name_only_p) |
8295 | return name; | |
8296 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
8297 | } |
8298 | else | |
8299 | snprintf (reg, sizeof (reg), "r%d", regno); | |
8300 | return reg; | |
8301 | } | |
8302 | ||
19e6b90e | 8303 | static void |
a1165289 | 8304 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 8305 | { |
a1165289 | 8306 | unsigned int r; |
19e6b90e L |
8307 | char tmp[100]; |
8308 | ||
d8024a91 | 8309 | if (*max_regs != fc->ncols) |
19e6b90e L |
8310 | *max_regs = fc->ncols; |
8311 | ||
8312 | if (*need_col_headers) | |
8313 | { | |
8314 | *need_col_headers = 0; | |
8315 | ||
288f0ba2 | 8316 | printf ("%-*s CFA ", eh_addr_size * 2, " LOC"); |
19e6b90e L |
8317 | |
8318 | for (r = 0; r < *max_regs; r++) | |
8319 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8320 | { | |
8321 | if (r == fc->ra) | |
50751e18 | 8322 | printf ("ra "); |
19e6b90e | 8323 | else |
2dc4cec1 | 8324 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
8325 | } |
8326 | ||
8327 | printf ("\n"); | |
8328 | } | |
8329 | ||
bf5117e3 | 8330 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
8331 | if (fc->cfa_exp) |
8332 | strcpy (tmp, "exp"); | |
8333 | else | |
c8071705 | 8334 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
8335 | printf ("%-8s ", tmp); |
8336 | ||
8337 | for (r = 0; r < fc->ncols; r++) | |
8338 | { | |
8339 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8340 | { | |
8341 | switch (fc->col_type[r]) | |
8342 | { | |
8343 | case DW_CFA_undefined: | |
8344 | strcpy (tmp, "u"); | |
8345 | break; | |
8346 | case DW_CFA_same_value: | |
8347 | strcpy (tmp, "s"); | |
8348 | break; | |
8349 | case DW_CFA_offset: | |
8350 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
8351 | break; | |
12eae2d3 JJ |
8352 | case DW_CFA_val_offset: |
8353 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
8354 | break; | |
19e6b90e | 8355 | case DW_CFA_register: |
2dc4cec1 | 8356 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
8357 | break; |
8358 | case DW_CFA_expression: | |
8359 | strcpy (tmp, "exp"); | |
8360 | break; | |
12eae2d3 JJ |
8361 | case DW_CFA_val_expression: |
8362 | strcpy (tmp, "vexp"); | |
8363 | break; | |
19e6b90e L |
8364 | default: |
8365 | strcpy (tmp, "n/a"); | |
8366 | break; | |
8367 | } | |
2dc4cec1 | 8368 | printf ("%-5s ", tmp); |
19e6b90e L |
8369 | } |
8370 | } | |
8371 | printf ("\n"); | |
8372 | } | |
8373 | ||
49727e46 | 8374 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 8375 | |
49727e46 AM |
8376 | static unsigned char * |
8377 | read_cie (unsigned char *start, unsigned char *end, | |
8378 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 8379 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
8380 | { |
8381 | int version; | |
8382 | Frame_Chunk *fc; | |
49727e46 | 8383 | unsigned char *augmentation_data = NULL; |
bf59c5d5 | 8384 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 8385 | |
041830e0 | 8386 | * p_cie = NULL; |
f41e4712 NC |
8387 | /* PR 17512: file: 001-228113-0.004. */ |
8388 | if (start >= end) | |
8389 | return end; | |
8390 | ||
49727e46 AM |
8391 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
8392 | memset (fc, 0, sizeof (Frame_Chunk)); | |
8393 | ||
8394 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
8395 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
8396 | ||
8397 | version = *start++; | |
8398 | ||
8399 | fc->augmentation = (char *) start; | |
f41e4712 NC |
8400 | /* PR 17512: file: 001-228113-0.004. |
8401 | Skip past augmentation name, but avoid running off the end of the data. */ | |
8402 | while (start < end) | |
8403 | if (* start ++ == '\0') | |
8404 | break; | |
8405 | if (start == end) | |
8406 | { | |
8407 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 8408 | goto fail; |
f41e4712 | 8409 | } |
49727e46 AM |
8410 | |
8411 | if (strcmp (fc->augmentation, "eh") == 0) | |
c93c4a85 AM |
8412 | { |
8413 | if (eh_addr_size > (size_t) (end - start)) | |
8414 | goto fail; | |
8415 | start += eh_addr_size; | |
8416 | } | |
49727e46 AM |
8417 | |
8418 | if (version >= 4) | |
8419 | { | |
c93c4a85 AM |
8420 | if (2 > (size_t) (end - start)) |
8421 | goto fail; | |
49727e46 | 8422 | GET (fc->ptr_size, 1); |
77ef8654 NC |
8423 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
8424 | { | |
8425 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 8426 | goto fail; |
77ef8654 NC |
8427 | } |
8428 | ||
49727e46 | 8429 | GET (fc->segment_size, 1); |
77ef8654 NC |
8430 | /* PR 17512: file: e99d2804. */ |
8431 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
8432 | { | |
8433 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 8434 | goto fail; |
77ef8654 NC |
8435 | } |
8436 | ||
49727e46 AM |
8437 | eh_addr_size = fc->ptr_size; |
8438 | } | |
8439 | else | |
8440 | { | |
8441 | fc->ptr_size = eh_addr_size; | |
8442 | fc->segment_size = 0; | |
8443 | } | |
442a6ce8 | 8444 | |
cd30bcef AM |
8445 | READ_ULEB (fc->code_factor, start, end); |
8446 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 8447 | |
c93c4a85 AM |
8448 | if (start >= end) |
8449 | goto fail; | |
8450 | ||
49727e46 AM |
8451 | if (version == 1) |
8452 | { | |
8453 | GET (fc->ra, 1); | |
8454 | } | |
8455 | else | |
8456 | { | |
cd30bcef | 8457 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
8458 | } |
8459 | ||
8460 | if (fc->augmentation[0] == 'z') | |
8461 | { | |
c93c4a85 AM |
8462 | if (start >= end) |
8463 | goto fail; | |
cd30bcef | 8464 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 8465 | augmentation_data = start; |
a1165289 | 8466 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 8467 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 8468 | { |
bf59c5d5 NC |
8469 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
8470 | dwarf_vmatoa ("x", augmentation_data_len), | |
8471 | (unsigned long) (end - start)); | |
442a6ce8 | 8472 | goto fail; |
a1165289 | 8473 | } |
9c0f3d3f | 8474 | start += augmentation_data_len; |
49727e46 AM |
8475 | } |
8476 | ||
8477 | if (augmentation_data_len) | |
8478 | { | |
058037d3 NC |
8479 | unsigned char *p; |
8480 | unsigned char *q; | |
8481 | unsigned char *qend; | |
b4eb7656 | 8482 | |
49727e46 AM |
8483 | p = (unsigned char *) fc->augmentation + 1; |
8484 | q = augmentation_data; | |
058037d3 NC |
8485 | qend = q + augmentation_data_len; |
8486 | ||
9c0f3d3f | 8487 | while (p < end && q < qend) |
49727e46 AM |
8488 | { |
8489 | if (*p == 'L') | |
8490 | q++; | |
8491 | else if (*p == 'P') | |
8492 | q += 1 + size_of_encoded_value (*q); | |
8493 | else if (*p == 'R') | |
8494 | fc->fde_encoding = *q++; | |
8495 | else if (*p == 'S') | |
8496 | ; | |
09038062 ST |
8497 | else if (*p == 'B') |
8498 | ; | |
49727e46 AM |
8499 | else |
8500 | break; | |
8501 | p++; | |
8502 | } | |
c361b9ac NC |
8503 | /* Note - it is OK if this loop terminates with q < qend. |
8504 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
8505 | } |
8506 | ||
8507 | *p_cie = fc; | |
8508 | if (p_version) | |
8509 | *p_version = version; | |
8510 | if (p_aug_len) | |
8511 | { | |
8512 | *p_aug_len = augmentation_data_len; | |
8513 | *p_aug = augmentation_data; | |
8514 | } | |
8515 | return start; | |
442a6ce8 NC |
8516 | |
8517 | fail: | |
8518 | free (fc->col_offset); | |
8519 | free (fc->col_type); | |
8520 | free (fc); | |
8521 | return end; | |
49727e46 AM |
8522 | } |
8523 | ||
d85bf2ba NC |
8524 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
8525 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
8526 | PRINTED contains the number of characters already written to the current | |
8527 | output line. */ | |
bf59c5d5 NC |
8528 | |
8529 | static void | |
d85bf2ba NC |
8530 | display_data (bfd_size_type printed, |
8531 | const unsigned char * data, | |
8532 | const bfd_size_type len) | |
bf59c5d5 | 8533 | { |
d85bf2ba NC |
8534 | if (do_wide || len < ((80 - printed) / 3)) |
8535 | for (printed = 0; printed < len; ++printed) | |
8536 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
8537 | else |
8538 | { | |
d85bf2ba | 8539 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 8540 | { |
d85bf2ba | 8541 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 8542 | putchar ('\n'); |
d85bf2ba | 8543 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
8544 | } |
8545 | } | |
d85bf2ba NC |
8546 | } |
8547 | ||
8548 | /* Prints out the contents on the augmentation data array. | |
8549 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
8550 | ||
8551 | static void | |
8552 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
8553 | { | |
8554 | bfd_size_type i; | |
8555 | ||
8556 | i = printf (_(" Augmentation data: ")); | |
8557 | display_data (i, data, len); | |
bf59c5d5 NC |
8558 | } |
8559 | ||
19e6b90e L |
8560 | static int |
8561 | display_debug_frames (struct dwarf_section *section, | |
8562 | void *file ATTRIBUTE_UNUSED) | |
8563 | { | |
8564 | unsigned char *start = section->start; | |
8565 | unsigned char *end = start + section->size; | |
8566 | unsigned char *section_start = start; | |
3391569f NC |
8567 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
8568 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 8569 | Frame_Chunk *rs; |
015dc7e1 | 8570 | bool is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 8571 | unsigned int max_regs = 0; |
665ce1f6 | 8572 | const char *bad_reg = _("bad register: "); |
77ef8654 | 8573 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 8574 | |
015dc7e1 | 8575 | introduce (section, false); |
19e6b90e L |
8576 | |
8577 | while (start < end) | |
8578 | { | |
8579 | unsigned char *saved_start; | |
8580 | unsigned char *block_end; | |
bf5117e3 NC |
8581 | dwarf_vma length; |
8582 | dwarf_vma cie_id; | |
19e6b90e L |
8583 | Frame_Chunk *fc; |
8584 | Frame_Chunk *cie; | |
8585 | int need_col_headers = 1; | |
8586 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 8587 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
8588 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
8589 | unsigned int offset_size; | |
015dc7e1 | 8590 | bool all_nops; |
a788aedd | 8591 | static Frame_Chunk fde_fc; |
19e6b90e L |
8592 | |
8593 | saved_start = start; | |
19e6b90e | 8594 | |
0c588247 | 8595 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 8596 | |
19e6b90e L |
8597 | if (length == 0) |
8598 | { | |
8599 | printf ("\n%08lx ZERO terminator\n\n", | |
8600 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
8601 | /* Skip any zero terminators that directly follow. |
8602 | A corrupt section size could have loaded a whole | |
8603 | slew of zero filled memory bytes. eg | |
8604 | PR 17512: file: 070-19381-0.004. */ | |
8605 | while (start < end && * start == 0) | |
8606 | ++ start; | |
b758e50f | 8607 | continue; |
19e6b90e L |
8608 | } |
8609 | ||
8610 | if (length == 0xffffffff) | |
8611 | { | |
0c588247 | 8612 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e | 8613 | offset_size = 8; |
19e6b90e L |
8614 | } |
8615 | else | |
5897a389 | 8616 | offset_size = 4; |
19e6b90e | 8617 | |
5897a389 | 8618 | if (length > (size_t) (end - start)) |
53b8873b | 8619 | { |
bf5117e3 NC |
8620 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
8621 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
8622 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
8623 | block_end = end; |
8624 | } | |
5897a389 AM |
8625 | else |
8626 | block_end = start + length; | |
0c588247 | 8627 | |
5897a389 | 8628 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, block_end); |
19e6b90e | 8629 | |
846a11e4 NC |
8630 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
8631 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
8632 | { |
8633 | int version; | |
a1165289 | 8634 | unsigned int mreg; |
19e6b90e | 8635 | |
5897a389 | 8636 | start = read_cie (start, block_end, &cie, &version, |
49727e46 | 8637 | &augmentation_data_len, &augmentation_data); |
041830e0 NC |
8638 | /* PR 17512: file: 027-135133-0.005. */ |
8639 | if (cie == NULL) | |
8640 | break; | |
a1165289 | 8641 | |
49727e46 | 8642 | fc = cie; |
19e6b90e L |
8643 | fc->next = chunks; |
8644 | chunks = fc; | |
8645 | fc->chunk_start = saved_start; | |
a1165289 | 8646 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8647 | if (mreg < fc->ra) |
8648 | mreg = fc->ra; | |
06614111 NC |
8649 | if (frame_need_space (fc, mreg) < 0) |
8650 | break; | |
49727e46 AM |
8651 | if (fc->fde_encoding) |
8652 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 8653 | |
bf5117e3 NC |
8654 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
8655 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 8656 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 8657 | |
19e6b90e | 8658 | if (do_debug_frames_interp) |
bf5117e3 NC |
8659 | { |
8660 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
8661 | fc->code_factor, fc->data_factor, fc->ra); | |
8662 | } | |
19e6b90e L |
8663 | else |
8664 | { | |
bf5117e3 | 8665 | printf ("CIE\n"); |
19e6b90e L |
8666 | printf (" Version: %d\n", version); |
8667 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
8668 | if (version >= 4) |
8669 | { | |
8670 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
8671 | printf (" Segment Size: %u\n", fc->segment_size); | |
8672 | } | |
19e6b90e L |
8673 | printf (" Code alignment factor: %u\n", fc->code_factor); |
8674 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
8675 | printf (" Return address column: %d\n", fc->ra); | |
8676 | ||
8677 | if (augmentation_data_len) | |
bf59c5d5 | 8678 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 8679 | |
19e6b90e L |
8680 | putchar ('\n'); |
8681 | } | |
19e6b90e L |
8682 | } |
8683 | else | |
8684 | { | |
8685 | unsigned char *look_for; | |
604282a7 | 8686 | unsigned long segment_selector; |
0d872fca | 8687 | dwarf_vma cie_off; |
19e6b90e | 8688 | |
0d872fca | 8689 | cie_off = cie_id; |
49727e46 AM |
8690 | if (is_eh) |
8691 | { | |
8692 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
0d872fca AM |
8693 | cie_off = (cie_off ^ sign) - sign; |
8694 | cie_off = start - 4 - section_start - cie_off; | |
49727e46 | 8695 | } |
19e6b90e | 8696 | |
0d872fca AM |
8697 | look_for = section_start + cie_off; |
8698 | if (cie_off <= (dwarf_vma) (saved_start - section_start)) | |
49727e46 AM |
8699 | { |
8700 | for (cie = chunks; cie ; cie = cie->next) | |
8701 | if (cie->chunk_start == look_for) | |
8702 | break; | |
8703 | } | |
d21f875d AM |
8704 | else if (cie_off >= section->size) |
8705 | cie = NULL; | |
49727e46 AM |
8706 | else |
8707 | { | |
8708 | for (cie = forward_refs; cie ; cie = cie->next) | |
8709 | if (cie->chunk_start == look_for) | |
8710 | break; | |
8711 | if (!cie) | |
8712 | { | |
8713 | unsigned int off_size; | |
8714 | unsigned char *cie_scan; | |
19e6b90e | 8715 | |
49727e46 AM |
8716 | cie_scan = look_for; |
8717 | off_size = 4; | |
8718 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
8719 | if (length == 0xffffffff) | |
8720 | { | |
8721 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
8722 | off_size = 8; | |
8723 | } | |
5897a389 | 8724 | if (length != 0 && length <= (size_t) (end - cie_scan)) |
49727e46 AM |
8725 | { |
8726 | dwarf_vma c_id; | |
5897a389 | 8727 | unsigned char *cie_end = cie_scan + length; |
49727e46 | 8728 | |
5897a389 AM |
8729 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, |
8730 | cie_end); | |
49727e46 AM |
8731 | if (is_eh |
8732 | ? c_id == 0 | |
8733 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
8734 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
8735 | { | |
8736 | int version; | |
a1165289 | 8737 | unsigned int mreg; |
49727e46 | 8738 | |
5897a389 | 8739 | read_cie (cie_scan, cie_end, &cie, &version, |
49727e46 | 8740 | &augmentation_data_len, &augmentation_data); |
a1165289 NC |
8741 | /* PR 17512: file: 3450-2098-0.004. */ |
8742 | if (cie == NULL) | |
8743 | { | |
8744 | warn (_("Failed to read CIE information\n")); | |
8745 | break; | |
8746 | } | |
49727e46 AM |
8747 | cie->next = forward_refs; |
8748 | forward_refs = cie; | |
8749 | cie->chunk_start = look_for; | |
a1165289 | 8750 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8751 | if (mreg < cie->ra) |
8752 | mreg = cie->ra; | |
06614111 NC |
8753 | if (frame_need_space (cie, mreg) < 0) |
8754 | { | |
8755 | warn (_("Invalid max register\n")); | |
8756 | break; | |
8757 | } | |
49727e46 AM |
8758 | if (cie->fde_encoding) |
8759 | encoded_ptr_size | |
8760 | = size_of_encoded_value (cie->fde_encoding); | |
8761 | } | |
8762 | } | |
8763 | } | |
8764 | } | |
8765 | ||
8766 | fc = &fde_fc; | |
8767 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
8768 | |
8769 | if (!cie) | |
8770 | { | |
bf5117e3 NC |
8771 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
8772 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
8773 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 8774 | fc->ncols = 0; |
3f5e193b NC |
8775 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
8776 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
8777 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
8778 | { | |
8779 | warn (_("Invalid max register\n")); | |
8780 | break; | |
8781 | } | |
19e6b90e L |
8782 | cie = fc; |
8783 | fc->augmentation = ""; | |
8784 | fc->fde_encoding = 0; | |
604282a7 JJ |
8785 | fc->ptr_size = eh_addr_size; |
8786 | fc->segment_size = 0; | |
19e6b90e L |
8787 | } |
8788 | else | |
8789 | { | |
8790 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8791 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8792 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8793 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8794 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8795 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8796 | fc->ptr_size = cie->ptr_size; |
8797 | eh_addr_size = cie->ptr_size; | |
8798 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8799 | fc->code_factor = cie->code_factor; |
8800 | fc->data_factor = cie->data_factor; | |
8801 | fc->cfa_reg = cie->cfa_reg; | |
8802 | fc->cfa_offset = cie->cfa_offset; | |
8803 | fc->ra = cie->ra; | |
06614111 NC |
8804 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8805 | { | |
8806 | warn (_("Invalid max register\n")); | |
8807 | break; | |
8808 | } | |
19e6b90e L |
8809 | fc->fde_encoding = cie->fde_encoding; |
8810 | } | |
8811 | ||
8812 | if (fc->fde_encoding) | |
8813 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8814 | ||
604282a7 JJ |
8815 | segment_selector = 0; |
8816 | if (fc->segment_size) | |
c8071705 NC |
8817 | { |
8818 | if (fc->segment_size > sizeof (segment_selector)) | |
8819 | { | |
8820 | /* PR 17512: file: 9e196b3e. */ | |
8821 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8822 | fc->segment_size = 4; | |
8823 | } | |
5897a389 AM |
8824 | SAFE_BYTE_GET_AND_INC (segment_selector, start, |
8825 | fc->segment_size, block_end); | |
c8071705 | 8826 | } |
041830e0 | 8827 | |
5897a389 AM |
8828 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, |
8829 | block_end); | |
19e6b90e | 8830 | |
0c588247 NC |
8831 | /* FIXME: It appears that sometimes the final pc_range value is |
8832 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8833 | run of the "objcopy on compressed debug sections" test for an | |
8834 | example of this. */ | |
5897a389 AM |
8835 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, |
8836 | block_end); | |
bf5117e3 | 8837 | |
19e6b90e L |
8838 | if (cie->augmentation[0] == 'z') |
8839 | { | |
5897a389 | 8840 | READ_ULEB (augmentation_data_len, start, block_end); |
19e6b90e | 8841 | augmentation_data = start; |
bf59c5d5 | 8842 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
5897a389 | 8843 | if (augmentation_data_len > (bfd_size_type) (block_end - start)) |
0a9d414a | 8844 | { |
d292364e AM |
8845 | warn (_("Augmentation data too long: 0x%s, " |
8846 | "expected at most %#lx\n"), | |
8847 | dwarf_vmatoa ("x", augmentation_data_len), | |
5897a389 AM |
8848 | (unsigned long) (block_end - start)); |
8849 | start = block_end; | |
0a9d414a NC |
8850 | augmentation_data = NULL; |
8851 | augmentation_data_len = 0; | |
8852 | } | |
d292364e | 8853 | start += augmentation_data_len; |
19e6b90e L |
8854 | } |
8855 | ||
bf5117e3 NC |
8856 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8857 | (unsigned long)(saved_start - section_start), | |
8858 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8859 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8860 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8861 | |
604282a7 JJ |
8862 | if (fc->segment_size) |
8863 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8864 | |
8865 | printf ("%s..%s\n", | |
8866 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8867 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8868 | ||
19e6b90e L |
8869 | if (! do_debug_frames_interp && augmentation_data_len) |
8870 | { | |
bf59c5d5 | 8871 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8872 | putchar ('\n'); |
8873 | } | |
8874 | } | |
8875 | ||
8876 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8877 | we're about to interpret instructions for the chunk. */ | |
8878 | /* ??? At present we need to do this always, since this sizes the | |
8879 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8880 | We should probably split the interpreted and non-interpreted bits | |
8881 | into two different routines, since there's so much that doesn't | |
8882 | really overlap between them. */ | |
8883 | if (1 || do_debug_frames_interp) | |
8884 | { | |
8885 | /* Start by making a pass over the chunk, allocating storage | |
8886 | and taking note of what registers are used. */ | |
8887 | unsigned char *tmp = start; | |
8888 | ||
8889 | while (start < block_end) | |
8890 | { | |
041830e0 NC |
8891 | unsigned int reg, op, opa; |
8892 | unsigned long temp; | |
19e6b90e L |
8893 | |
8894 | op = *start++; | |
8895 | opa = op & 0x3f; | |
8896 | if (op & 0xc0) | |
8897 | op &= 0xc0; | |
8898 | ||
8899 | /* Warning: if you add any more cases to this switch, be | |
8900 | sure to add them to the corresponding switch below. */ | |
8901 | switch (op) | |
8902 | { | |
8903 | case DW_CFA_advance_loc: | |
8904 | break; | |
8905 | case DW_CFA_offset: | |
5897a389 | 8906 | SKIP_ULEB (start, block_end); |
665ce1f6 L |
8907 | if (frame_need_space (fc, opa) >= 0) |
8908 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8909 | break; |
8910 | case DW_CFA_restore: | |
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_set_loc: | |
5897a389 AM |
8915 | if ((size_t) (block_end - start) < encoded_ptr_size) |
8916 | start = block_end; | |
8917 | else | |
8918 | start += encoded_ptr_size; | |
19e6b90e L |
8919 | break; |
8920 | case DW_CFA_advance_loc1: | |
5897a389 AM |
8921 | if ((size_t) (block_end - start) < 1) |
8922 | start = block_end; | |
8923 | else | |
8924 | start += 1; | |
19e6b90e L |
8925 | break; |
8926 | case DW_CFA_advance_loc2: | |
5897a389 AM |
8927 | if ((size_t) (block_end - start) < 2) |
8928 | start = block_end; | |
8929 | else | |
8930 | start += 2; | |
19e6b90e L |
8931 | break; |
8932 | case DW_CFA_advance_loc4: | |
5897a389 AM |
8933 | if ((size_t) (block_end - start) < 4) |
8934 | start = block_end; | |
8935 | else | |
8936 | start += 4; | |
19e6b90e L |
8937 | break; |
8938 | case DW_CFA_offset_extended: | |
12eae2d3 | 8939 | case DW_CFA_val_offset: |
5897a389 AM |
8940 | READ_ULEB (reg, start, block_end); |
8941 | SKIP_ULEB (start, block_end); | |
665ce1f6 L |
8942 | if (frame_need_space (fc, reg) >= 0) |
8943 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8944 | break; |
8945 | case DW_CFA_restore_extended: | |
5897a389 | 8946 | READ_ULEB (reg, start, block_end); |
665ce1f6 L |
8947 | if (frame_need_space (fc, reg) >= 0) |
8948 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8949 | break; |
8950 | case DW_CFA_undefined: | |
5897a389 | 8951 | READ_ULEB (reg, start, block_end); |
665ce1f6 L |
8952 | if (frame_need_space (fc, reg) >= 0) |
8953 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8954 | break; |
8955 | case DW_CFA_same_value: | |
5897a389 | 8956 | READ_ULEB (reg, start, block_end); |
665ce1f6 L |
8957 | if (frame_need_space (fc, reg) >= 0) |
8958 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8959 | break; |
8960 | case DW_CFA_register: | |
5897a389 AM |
8961 | READ_ULEB (reg, start, block_end); |
8962 | SKIP_ULEB (start, block_end); | |
665ce1f6 L |
8963 | if (frame_need_space (fc, reg) >= 0) |
8964 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8965 | break; |
8966 | case DW_CFA_def_cfa: | |
5897a389 AM |
8967 | SKIP_ULEB (start, block_end); |
8968 | SKIP_ULEB (start, block_end); | |
19e6b90e L |
8969 | break; |
8970 | case DW_CFA_def_cfa_register: | |
5897a389 | 8971 | SKIP_ULEB (start, block_end); |
19e6b90e L |
8972 | break; |
8973 | case DW_CFA_def_cfa_offset: | |
5897a389 | 8974 | SKIP_ULEB (start, block_end); |
19e6b90e L |
8975 | break; |
8976 | case DW_CFA_def_cfa_expression: | |
5897a389 AM |
8977 | READ_ULEB (temp, start, block_end); |
8978 | if ((size_t) (block_end - start) < temp) | |
8979 | start = block_end; | |
041830e0 | 8980 | else |
5897a389 | 8981 | start += temp; |
19e6b90e L |
8982 | break; |
8983 | case DW_CFA_expression: | |
12eae2d3 | 8984 | case DW_CFA_val_expression: |
5897a389 AM |
8985 | READ_ULEB (reg, start, block_end); |
8986 | READ_ULEB (temp, start, block_end); | |
8987 | if ((size_t) (block_end - start) < temp) | |
8988 | start = block_end; | |
041830e0 | 8989 | else |
5897a389 | 8990 | start += temp; |
665ce1f6 L |
8991 | if (frame_need_space (fc, reg) >= 0) |
8992 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8993 | break; |
8994 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 8995 | case DW_CFA_val_offset_sf: |
5897a389 AM |
8996 | READ_ULEB (reg, start, block_end); |
8997 | SKIP_SLEB (start, block_end); | |
665ce1f6 L |
8998 | if (frame_need_space (fc, reg) >= 0) |
8999 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9000 | break; |
9001 | case DW_CFA_def_cfa_sf: | |
5897a389 AM |
9002 | SKIP_ULEB (start, block_end); |
9003 | SKIP_SLEB (start, block_end); | |
19e6b90e L |
9004 | break; |
9005 | case DW_CFA_def_cfa_offset_sf: | |
5897a389 | 9006 | SKIP_SLEB (start, block_end); |
19e6b90e L |
9007 | break; |
9008 | case DW_CFA_MIPS_advance_loc8: | |
5897a389 AM |
9009 | if ((size_t) (block_end - start) < 8) |
9010 | start = block_end; | |
9011 | else | |
9012 | start += 8; | |
19e6b90e L |
9013 | break; |
9014 | case DW_CFA_GNU_args_size: | |
5897a389 | 9015 | SKIP_ULEB (start, block_end); |
19e6b90e L |
9016 | break; |
9017 | case DW_CFA_GNU_negative_offset_extended: | |
5897a389 AM |
9018 | READ_ULEB (reg, start, block_end); |
9019 | SKIP_ULEB (start, block_end); | |
665ce1f6 L |
9020 | if (frame_need_space (fc, reg) >= 0) |
9021 | fc->col_type[reg] = DW_CFA_undefined; | |
9022 | break; | |
19e6b90e L |
9023 | default: |
9024 | break; | |
9025 | } | |
9026 | } | |
9027 | start = tmp; | |
9028 | } | |
9029 | ||
015dc7e1 | 9030 | all_nops = true; |
5b6312fd | 9031 | |
19e6b90e L |
9032 | /* Now we know what registers are used, make a second pass over |
9033 | the chunk, this time actually printing out the info. */ | |
9034 | ||
9035 | while (start < block_end) | |
9036 | { | |
9037 | unsigned op, opa; | |
7f2c8a1d NC |
9038 | unsigned long ul, roffs; |
9039 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
9040 | are various functions, notably frame_space_needed() that assume that | |
9041 | reg is an unsigned int. */ | |
9042 | unsigned int reg; | |
9043 | dwarf_signed_vma l; | |
bf5117e3 | 9044 | dwarf_vma ofs; |
19e6b90e | 9045 | dwarf_vma vma; |
665ce1f6 | 9046 | const char *reg_prefix = ""; |
19e6b90e L |
9047 | |
9048 | op = *start++; | |
9049 | opa = op & 0x3f; | |
9050 | if (op & 0xc0) | |
9051 | op &= 0xc0; | |
9052 | ||
5b6312fd NC |
9053 | /* Make a note if something other than DW_CFA_nop happens. */ |
9054 | if (op != DW_CFA_nop) | |
015dc7e1 | 9055 | all_nops = false; |
5b6312fd | 9056 | |
19e6b90e L |
9057 | /* Warning: if you add any more cases to this switch, be |
9058 | sure to add them to the corresponding switch above. */ | |
9059 | switch (op) | |
9060 | { | |
9061 | case DW_CFA_advance_loc: | |
9062 | if (do_debug_frames_interp) | |
9063 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9064 | else | |
bf5117e3 | 9065 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 9066 | opa * fc->code_factor, |
b4eb7656 | 9067 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
9068 | fc->pc_begin + opa * fc->code_factor, |
9069 | fc->ptr_size)); | |
19e6b90e L |
9070 | fc->pc_begin += opa * fc->code_factor; |
9071 | break; | |
9072 | ||
9073 | case DW_CFA_offset: | |
5897a389 | 9074 | READ_ULEB (roffs, start, block_end); |
665ce1f6 L |
9075 | if (opa >= (unsigned int) fc->ncols) |
9076 | reg_prefix = bad_reg; | |
9077 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9078 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
9079 | reg_prefix, regname (opa, 0), | |
9080 | roffs * fc->data_factor); | |
9081 | if (*reg_prefix == '\0') | |
9082 | { | |
9083 | fc->col_type[opa] = DW_CFA_offset; | |
9084 | fc->col_offset[opa] = roffs * fc->data_factor; | |
9085 | } | |
19e6b90e L |
9086 | break; |
9087 | ||
9088 | case DW_CFA_restore: | |
50751e18 | 9089 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
9090 | reg_prefix = bad_reg; |
9091 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9092 | printf (" DW_CFA_restore: %s%s\n", | |
9093 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
9094 | if (*reg_prefix != '\0') |
9095 | break; | |
9096 | ||
9097 | if (opa >= (unsigned int) cie->ncols | |
9098 | || (do_debug_frames_interp | |
9099 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
9100 | { | |
9101 | fc->col_type[opa] = DW_CFA_undefined; | |
9102 | fc->col_offset[opa] = 0; | |
9103 | } | |
9104 | else | |
665ce1f6 L |
9105 | { |
9106 | fc->col_type[opa] = cie->col_type[opa]; | |
9107 | fc->col_offset[opa] = cie->col_offset[opa]; | |
9108 | } | |
19e6b90e L |
9109 | break; |
9110 | ||
9111 | case DW_CFA_set_loc: | |
5897a389 AM |
9112 | vma = get_encoded_value (&start, fc->fde_encoding, section, |
9113 | block_end); | |
19e6b90e L |
9114 | if (do_debug_frames_interp) |
9115 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9116 | else | |
bf5117e3 NC |
9117 | printf (" DW_CFA_set_loc: %s\n", |
9118 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
9119 | fc->pc_begin = vma; |
9120 | break; | |
9121 | ||
9122 | case DW_CFA_advance_loc1: | |
5897a389 | 9123 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, block_end); |
19e6b90e L |
9124 | if (do_debug_frames_interp) |
9125 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9126 | else | |
bf5117e3 NC |
9127 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
9128 | (unsigned long) (ofs * fc->code_factor), | |
9129 | dwarf_vmatoa_1 (NULL, | |
9130 | fc->pc_begin + ofs * fc->code_factor, | |
9131 | fc->ptr_size)); | |
19e6b90e L |
9132 | fc->pc_begin += ofs * fc->code_factor; |
9133 | break; | |
9134 | ||
9135 | case DW_CFA_advance_loc2: | |
6937bb54 | 9136 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
9137 | if (do_debug_frames_interp) |
9138 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9139 | else | |
bf5117e3 NC |
9140 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
9141 | (unsigned long) (ofs * fc->code_factor), | |
9142 | dwarf_vmatoa_1 (NULL, | |
9143 | fc->pc_begin + ofs * fc->code_factor, | |
9144 | fc->ptr_size)); | |
19e6b90e L |
9145 | fc->pc_begin += ofs * fc->code_factor; |
9146 | break; | |
9147 | ||
9148 | case DW_CFA_advance_loc4: | |
6937bb54 | 9149 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
9150 | if (do_debug_frames_interp) |
9151 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9152 | else | |
bf5117e3 NC |
9153 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
9154 | (unsigned long) (ofs * fc->code_factor), | |
9155 | dwarf_vmatoa_1 (NULL, | |
9156 | fc->pc_begin + ofs * fc->code_factor, | |
9157 | fc->ptr_size)); | |
19e6b90e L |
9158 | fc->pc_begin += ofs * fc->code_factor; |
9159 | break; | |
9160 | ||
9161 | case DW_CFA_offset_extended: | |
5897a389 AM |
9162 | READ_ULEB (reg, start, block_end); |
9163 | READ_ULEB (roffs, start, block_end); | |
665ce1f6 L |
9164 | if (reg >= (unsigned int) fc->ncols) |
9165 | reg_prefix = bad_reg; | |
9166 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9167 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
9168 | reg_prefix, regname (reg, 0), | |
9169 | roffs * fc->data_factor); | |
9170 | if (*reg_prefix == '\0') | |
9171 | { | |
9172 | fc->col_type[reg] = DW_CFA_offset; | |
9173 | fc->col_offset[reg] = roffs * fc->data_factor; | |
9174 | } | |
19e6b90e L |
9175 | break; |
9176 | ||
12eae2d3 | 9177 | case DW_CFA_val_offset: |
5897a389 AM |
9178 | READ_ULEB (reg, start, block_end); |
9179 | READ_ULEB (roffs, start, block_end); | |
665ce1f6 L |
9180 | if (reg >= (unsigned int) fc->ncols) |
9181 | reg_prefix = bad_reg; | |
9182 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9183 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
9184 | reg_prefix, regname (reg, 0), |
9185 | roffs * fc->data_factor); | |
9186 | if (*reg_prefix == '\0') | |
9187 | { | |
9188 | fc->col_type[reg] = DW_CFA_val_offset; | |
9189 | fc->col_offset[reg] = roffs * fc->data_factor; | |
9190 | } | |
12eae2d3 JJ |
9191 | break; |
9192 | ||
19e6b90e | 9193 | case DW_CFA_restore_extended: |
5897a389 | 9194 | READ_ULEB (reg, start, block_end); |
50751e18 | 9195 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
9196 | reg_prefix = bad_reg; |
9197 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9198 | printf (" DW_CFA_restore_extended: %s%s\n", | |
9199 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
9200 | if (*reg_prefix != '\0') |
9201 | break; | |
9202 | ||
9203 | if (reg >= (unsigned int) cie->ncols) | |
9204 | { | |
9205 | fc->col_type[reg] = DW_CFA_undefined; | |
9206 | fc->col_offset[reg] = 0; | |
9207 | } | |
9208 | else | |
665ce1f6 L |
9209 | { |
9210 | fc->col_type[reg] = cie->col_type[reg]; | |
9211 | fc->col_offset[reg] = cie->col_offset[reg]; | |
9212 | } | |
19e6b90e L |
9213 | break; |
9214 | ||
9215 | case DW_CFA_undefined: | |
5897a389 | 9216 | READ_ULEB (reg, start, block_end); |
665ce1f6 L |
9217 | if (reg >= (unsigned int) fc->ncols) |
9218 | reg_prefix = bad_reg; | |
9219 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9220 | printf (" DW_CFA_undefined: %s%s\n", | |
9221 | reg_prefix, regname (reg, 0)); | |
9222 | if (*reg_prefix == '\0') | |
9223 | { | |
9224 | fc->col_type[reg] = DW_CFA_undefined; | |
9225 | fc->col_offset[reg] = 0; | |
9226 | } | |
19e6b90e L |
9227 | break; |
9228 | ||
9229 | case DW_CFA_same_value: | |
5897a389 | 9230 | READ_ULEB (reg, start, block_end); |
665ce1f6 L |
9231 | if (reg >= (unsigned int) fc->ncols) |
9232 | reg_prefix = bad_reg; | |
9233 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9234 | printf (" DW_CFA_same_value: %s%s\n", | |
9235 | reg_prefix, regname (reg, 0)); | |
9236 | if (*reg_prefix == '\0') | |
9237 | { | |
9238 | fc->col_type[reg] = DW_CFA_same_value; | |
9239 | fc->col_offset[reg] = 0; | |
9240 | } | |
19e6b90e L |
9241 | break; |
9242 | ||
9243 | case DW_CFA_register: | |
5897a389 AM |
9244 | READ_ULEB (reg, start, block_end); |
9245 | READ_ULEB (roffs, start, block_end); | |
665ce1f6 L |
9246 | if (reg >= (unsigned int) fc->ncols) |
9247 | reg_prefix = bad_reg; | |
9248 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 9249 | { |
665ce1f6 L |
9250 | printf (" DW_CFA_register: %s%s in ", |
9251 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
9252 | puts (regname (roffs, 0)); |
9253 | } | |
665ce1f6 L |
9254 | if (*reg_prefix == '\0') |
9255 | { | |
9256 | fc->col_type[reg] = DW_CFA_register; | |
9257 | fc->col_offset[reg] = roffs; | |
9258 | } | |
19e6b90e L |
9259 | break; |
9260 | ||
9261 | case DW_CFA_remember_state: | |
9262 | if (! do_debug_frames_interp) | |
9263 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 9264 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 9265 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
9266 | rs->cfa_reg = fc->cfa_reg; |
9267 | rs->ra = fc->ra; | |
9268 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 9269 | rs->ncols = fc->ncols; |
3f5e193b | 9270 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 9271 | sizeof (* rs->col_type)); |
d71ad7fc RC |
9272 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
9273 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
9274 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
9275 | rs->next = remembered_state; |
9276 | remembered_state = rs; | |
9277 | break; | |
9278 | ||
9279 | case DW_CFA_restore_state: | |
9280 | if (! do_debug_frames_interp) | |
9281 | printf (" DW_CFA_restore_state\n"); | |
9282 | rs = remembered_state; | |
9283 | if (rs) | |
9284 | { | |
9285 | remembered_state = rs->next; | |
d71ad7fc RC |
9286 | fc->cfa_offset = rs->cfa_offset; |
9287 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
9288 | fc->ra = rs->ra; |
9289 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
9290 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
9291 | { | |
1306a742 | 9292 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
9293 | fc->ncols = 0; |
9294 | break; | |
9295 | } | |
d71ad7fc | 9296 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 9297 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 9298 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
9299 | free (rs->col_type); |
9300 | free (rs->col_offset); | |
9301 | free (rs); | |
9302 | } | |
9303 | else if (do_debug_frames_interp) | |
9304 | printf ("Mismatched DW_CFA_restore_state\n"); | |
9305 | break; | |
9306 | ||
9307 | case DW_CFA_def_cfa: | |
5897a389 AM |
9308 | READ_ULEB (fc->cfa_reg, start, block_end); |
9309 | READ_ULEB (fc->cfa_offset, start, block_end); | |
19e6b90e L |
9310 | fc->cfa_exp = 0; |
9311 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9312 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 9313 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9314 | break; |
9315 | ||
9316 | case DW_CFA_def_cfa_register: | |
5897a389 | 9317 | READ_ULEB (fc->cfa_reg, start, block_end); |
19e6b90e L |
9318 | fc->cfa_exp = 0; |
9319 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
9320 | printf (" DW_CFA_def_cfa_register: %s\n", |
9321 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
9322 | break; |
9323 | ||
9324 | case DW_CFA_def_cfa_offset: | |
5897a389 | 9325 | READ_ULEB (fc->cfa_offset, start, block_end); |
19e6b90e | 9326 | if (! do_debug_frames_interp) |
c8071705 | 9327 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9328 | break; |
9329 | ||
9330 | case DW_CFA_nop: | |
9331 | if (! do_debug_frames_interp) | |
9332 | printf (" DW_CFA_nop\n"); | |
9333 | break; | |
9334 | ||
9335 | case DW_CFA_def_cfa_expression: | |
5897a389 AM |
9336 | READ_ULEB (ul, start, block_end); |
9337 | if (ul > (size_t) (block_end - start)) | |
6937bb54 | 9338 | { |
a1165289 | 9339 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9340 | break; |
9341 | } | |
19e6b90e L |
9342 | if (! do_debug_frames_interp) |
9343 | { | |
9344 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
9345 | decode_location_expression (start, eh_addr_size, 0, -1, |
9346 | ul, 0, section); | |
19e6b90e L |
9347 | printf (")\n"); |
9348 | } | |
9349 | fc->cfa_exp = 1; | |
9350 | start += ul; | |
9351 | break; | |
9352 | ||
9353 | case DW_CFA_expression: | |
5897a389 AM |
9354 | READ_ULEB (reg, start, block_end); |
9355 | READ_ULEB (ul, start, block_end); | |
665ce1f6 L |
9356 | if (reg >= (unsigned int) fc->ncols) |
9357 | reg_prefix = bad_reg; | |
6937bb54 | 9358 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 9359 | /* PR 17512: file: 98c02eb4. */ |
5897a389 | 9360 | if (ul > (size_t) (block_end - start)) |
6937bb54 | 9361 | { |
a1165289 | 9362 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9363 | break; |
9364 | } | |
665ce1f6 | 9365 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 9366 | { |
665ce1f6 L |
9367 | printf (" DW_CFA_expression: %s%s (", |
9368 | reg_prefix, regname (reg, 0)); | |
b7807392 | 9369 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 9370 | ul, 0, section); |
19e6b90e L |
9371 | printf (")\n"); |
9372 | } | |
665ce1f6 L |
9373 | if (*reg_prefix == '\0') |
9374 | fc->col_type[reg] = DW_CFA_expression; | |
5897a389 | 9375 | start += ul; |
19e6b90e L |
9376 | break; |
9377 | ||
12eae2d3 | 9378 | case DW_CFA_val_expression: |
5897a389 AM |
9379 | READ_ULEB (reg, start, block_end); |
9380 | READ_ULEB (ul, start, block_end); | |
665ce1f6 L |
9381 | if (reg >= (unsigned int) fc->ncols) |
9382 | reg_prefix = bad_reg; | |
5897a389 | 9383 | if (ul > (size_t) (block_end - start)) |
6937bb54 | 9384 | { |
a1165289 | 9385 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
9386 | break; |
9387 | } | |
665ce1f6 | 9388 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 9389 | { |
665ce1f6 L |
9390 | printf (" DW_CFA_val_expression: %s%s (", |
9391 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
9392 | decode_location_expression (start, eh_addr_size, 0, -1, |
9393 | ul, 0, section); | |
12eae2d3 JJ |
9394 | printf (")\n"); |
9395 | } | |
665ce1f6 L |
9396 | if (*reg_prefix == '\0') |
9397 | fc->col_type[reg] = DW_CFA_val_expression; | |
5897a389 | 9398 | start += ul; |
12eae2d3 JJ |
9399 | break; |
9400 | ||
19e6b90e | 9401 | case DW_CFA_offset_extended_sf: |
5897a389 AM |
9402 | READ_ULEB (reg, start, block_end); |
9403 | READ_SLEB (l, start, block_end); | |
665ce1f6 L |
9404 | if (frame_need_space (fc, reg) < 0) |
9405 | reg_prefix = bad_reg; | |
9406 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9407 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
9408 | reg_prefix, regname (reg, 0), | |
c8071705 | 9409 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9410 | if (*reg_prefix == '\0') |
9411 | { | |
9412 | fc->col_type[reg] = DW_CFA_offset; | |
9413 | fc->col_offset[reg] = l * fc->data_factor; | |
9414 | } | |
19e6b90e L |
9415 | break; |
9416 | ||
12eae2d3 | 9417 | case DW_CFA_val_offset_sf: |
5897a389 AM |
9418 | READ_ULEB (reg, start, block_end); |
9419 | READ_SLEB (l, start, block_end); | |
665ce1f6 L |
9420 | if (frame_need_space (fc, reg) < 0) |
9421 | reg_prefix = bad_reg; | |
9422 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9423 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 9424 | reg_prefix, regname (reg, 0), |
c8071705 | 9425 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9426 | if (*reg_prefix == '\0') |
9427 | { | |
9428 | fc->col_type[reg] = DW_CFA_val_offset; | |
9429 | fc->col_offset[reg] = l * fc->data_factor; | |
9430 | } | |
12eae2d3 JJ |
9431 | break; |
9432 | ||
19e6b90e | 9433 | case DW_CFA_def_cfa_sf: |
5897a389 AM |
9434 | READ_ULEB (fc->cfa_reg, start, block_end); |
9435 | READ_ULEB (fc->cfa_offset, start, block_end); | |
19e6b90e L |
9436 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
9437 | fc->cfa_exp = 0; | |
9438 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9439 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 9440 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9441 | break; |
9442 | ||
9443 | case DW_CFA_def_cfa_offset_sf: | |
5897a389 | 9444 | READ_ULEB (fc->cfa_offset, start, block_end); |
c8071705 | 9445 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 9446 | if (! do_debug_frames_interp) |
c8071705 | 9447 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9448 | break; |
9449 | ||
9450 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 9451 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
9452 | if (do_debug_frames_interp) |
9453 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9454 | else | |
bf5117e3 NC |
9455 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
9456 | (unsigned long) (ofs * fc->code_factor), | |
9457 | dwarf_vmatoa_1 (NULL, | |
9458 | fc->pc_begin + ofs * fc->code_factor, | |
9459 | fc->ptr_size)); | |
19e6b90e L |
9460 | fc->pc_begin += ofs * fc->code_factor; |
9461 | break; | |
9462 | ||
9463 | case DW_CFA_GNU_window_save: | |
9464 | if (! do_debug_frames_interp) | |
9465 | printf (" DW_CFA_GNU_window_save\n"); | |
9466 | break; | |
9467 | ||
9468 | case DW_CFA_GNU_args_size: | |
5897a389 | 9469 | READ_ULEB (ul, start, block_end); |
19e6b90e L |
9470 | if (! do_debug_frames_interp) |
9471 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
9472 | break; | |
9473 | ||
9474 | case DW_CFA_GNU_negative_offset_extended: | |
5897a389 AM |
9475 | READ_ULEB (reg, start, block_end); |
9476 | READ_SLEB (l, start, block_end); | |
7f2c8a1d | 9477 | l = - l; |
665ce1f6 L |
9478 | if (frame_need_space (fc, reg) < 0) |
9479 | reg_prefix = bad_reg; | |
9480 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9481 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
9482 | reg_prefix, regname (reg, 0), | |
c8071705 | 9483 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9484 | if (*reg_prefix == '\0') |
9485 | { | |
9486 | fc->col_type[reg] = DW_CFA_offset; | |
9487 | fc->col_offset[reg] = l * fc->data_factor; | |
9488 | } | |
19e6b90e L |
9489 | break; |
9490 | ||
9491 | default: | |
53b8873b NC |
9492 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
9493 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
9494 | else | |
f41e4712 | 9495 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
9496 | start = block_end; |
9497 | } | |
9498 | } | |
9499 | ||
5b6312fd NC |
9500 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
9501 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
9502 | frame_display_row (fc, &need_col_headers, &max_regs); |
9503 | ||
a788aedd AM |
9504 | if (fde_fc.col_type != NULL) |
9505 | { | |
9506 | free (fde_fc.col_type); | |
9507 | fde_fc.col_type = NULL; | |
9508 | } | |
9509 | if (fde_fc.col_offset != NULL) | |
9510 | { | |
9511 | free (fde_fc.col_offset); | |
9512 | fde_fc.col_offset = NULL; | |
9513 | } | |
9514 | ||
19e6b90e | 9515 | start = block_end; |
604282a7 | 9516 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
9517 | } |
9518 | ||
9519 | printf ("\n"); | |
9520 | ||
3391569f NC |
9521 | while (remembered_state != NULL) |
9522 | { | |
9523 | rs = remembered_state; | |
9524 | remembered_state = rs->next; | |
9525 | free (rs->col_type); | |
9526 | free (rs->col_offset); | |
9527 | rs->next = NULL; /* Paranoia. */ | |
9528 | free (rs); | |
9529 | } | |
9530 | ||
9531 | while (chunks != NULL) | |
9532 | { | |
9533 | rs = chunks; | |
9534 | chunks = rs->next; | |
9535 | free (rs->col_type); | |
9536 | free (rs->col_offset); | |
9537 | rs->next = NULL; /* Paranoia. */ | |
9538 | free (rs); | |
9539 | } | |
9540 | ||
9541 | while (forward_refs != NULL) | |
9542 | { | |
9543 | rs = forward_refs; | |
9544 | forward_refs = rs->next; | |
9545 | free (rs->col_type); | |
9546 | free (rs->col_offset); | |
9547 | rs->next = NULL; /* Paranoia. */ | |
9548 | free (rs); | |
9549 | } | |
9550 | ||
19e6b90e L |
9551 | return 1; |
9552 | } | |
9553 | ||
9554 | #undef GET | |
19e6b90e | 9555 | |
61364358 JK |
9556 | static int |
9557 | display_debug_names (struct dwarf_section *section, void *file) | |
9558 | { | |
9559 | unsigned char *hdrptr = section->start; | |
9560 | dwarf_vma unit_length; | |
9561 | unsigned char *unit_start; | |
9562 | const unsigned char *const section_end = section->start + section->size; | |
9563 | unsigned char *unit_end; | |
9564 | ||
015dc7e1 | 9565 | introduce (section, false); |
61364358 | 9566 | |
dda8d76d | 9567 | load_debug_section_with_follow (str, file); |
61364358 JK |
9568 | |
9569 | for (; hdrptr < section_end; hdrptr = unit_end) | |
9570 | { | |
9571 | unsigned int offset_size; | |
9572 | uint16_t dwarf_version, padding; | |
9573 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
d7870f63 | 9574 | uint64_t bucket_count, name_count, abbrev_table_size; |
61364358 JK |
9575 | uint32_t augmentation_string_size; |
9576 | unsigned int i; | |
015dc7e1 | 9577 | bool augmentation_printable; |
48467cb9 | 9578 | const char *augmentation_string; |
d7870f63 | 9579 | size_t total; |
61364358 JK |
9580 | |
9581 | unit_start = hdrptr; | |
9582 | ||
9583 | /* Get and check the length of the block. */ | |
9584 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
9585 | ||
9586 | if (unit_length == 0xffffffff) | |
9587 | { | |
9588 | /* This section is 64-bit DWARF. */ | |
9589 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
9590 | offset_size = 8; | |
9591 | } | |
9592 | else | |
9593 | offset_size = 4; | |
61364358 | 9594 | |
d7870f63 AM |
9595 | if (unit_length > (size_t) (section_end - hdrptr) |
9596 | || unit_length < 2 + 2 + 4 * 7) | |
61364358 | 9597 | { |
d7870f63 | 9598 | too_short: |
e98fdf1a AM |
9599 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
9600 | section->name, | |
9601 | (unsigned long) (unit_start - section->start), | |
9602 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
9603 | return 0; |
9604 | } | |
d7870f63 | 9605 | unit_end = hdrptr + unit_length; |
61364358 JK |
9606 | |
9607 | /* Get and check the version number. */ | |
9608 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
9609 | printf (_("Version %ld\n"), (long) dwarf_version); | |
9610 | ||
9611 | /* Prior versions did not exist, and future versions may not be | |
9612 | backwards compatible. */ | |
9613 | if (dwarf_version != 5) | |
9614 | { | |
9615 | warn (_("Only DWARF version 5 .debug_names " | |
9616 | "is currently supported.\n")); | |
9617 | return 0; | |
9618 | } | |
9619 | ||
9620 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
9621 | if (padding != 0) | |
9622 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
9623 | padding); | |
9624 | ||
9625 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
9626 | if (comp_unit_count == 0) | |
9627 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
9628 | ||
9629 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
9630 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
9631 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
9632 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
9633 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
9634 | ||
9635 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
9636 | if (augmentation_string_size % 4 != 0) | |
9637 | { | |
9638 | warn (_("Augmentation string length %u must be rounded up " | |
9639 | "to a multiple of 4 in .debug_names.\n"), | |
9640 | augmentation_string_size); | |
9641 | augmentation_string_size += (-augmentation_string_size) & 3; | |
9642 | } | |
d7870f63 AM |
9643 | if (augmentation_string_size > (size_t) (unit_end - hdrptr)) |
9644 | goto too_short; | |
48467cb9 | 9645 | |
61364358 | 9646 | printf (_("Augmentation string:")); |
48467cb9 | 9647 | |
015dc7e1 | 9648 | augmentation_printable = true; |
48467cb9 TV |
9649 | augmentation_string = (const char *) hdrptr; |
9650 | ||
61364358 JK |
9651 | for (i = 0; i < augmentation_string_size; i++) |
9652 | { | |
9653 | unsigned char uc; | |
9654 | ||
9655 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
9656 | printf (" %02x", uc); | |
48467cb9 TV |
9657 | |
9658 | if (uc != 0 && !ISPRINT (uc)) | |
015dc7e1 | 9659 | augmentation_printable = false; |
48467cb9 TV |
9660 | } |
9661 | ||
9662 | if (augmentation_printable) | |
9663 | { | |
9664 | printf (" (\""); | |
9665 | for (i = 0; | |
9666 | i < augmentation_string_size && augmentation_string[i]; | |
9667 | ++i) | |
9668 | putchar (augmentation_string[i]); | |
9669 | printf ("\")"); | |
61364358 | 9670 | } |
61364358 JK |
9671 | putchar ('\n'); |
9672 | ||
9673 | printf (_("CU table:\n")); | |
d7870f63 AM |
9674 | if (_mul_overflow (comp_unit_count, offset_size, &total) |
9675 | || total > (size_t) (unit_end - hdrptr)) | |
9676 | goto too_short; | |
61364358 JK |
9677 | for (i = 0; i < comp_unit_count; i++) |
9678 | { | |
9679 | uint64_t cu_offset; | |
9680 | ||
9681 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
9682 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
9683 | } | |
9684 | putchar ('\n'); | |
9685 | ||
9686 | printf (_("TU table:\n")); | |
d7870f63 AM |
9687 | if (_mul_overflow (local_type_unit_count, offset_size, &total) |
9688 | || total > (size_t) (unit_end - hdrptr)) | |
9689 | goto too_short; | |
61364358 JK |
9690 | for (i = 0; i < local_type_unit_count; i++) |
9691 | { | |
9692 | uint64_t tu_offset; | |
9693 | ||
9694 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
9695 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
9696 | } | |
9697 | putchar ('\n'); | |
9698 | ||
9699 | printf (_("Foreign TU table:\n")); | |
d7870f63 AM |
9700 | if (_mul_overflow (foreign_type_unit_count, 8, &total) |
9701 | || total > (size_t) (unit_end - hdrptr)) | |
9702 | goto too_short; | |
61364358 JK |
9703 | for (i = 0; i < foreign_type_unit_count; i++) |
9704 | { | |
9705 | uint64_t signature; | |
9706 | ||
9707 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
9708 | printf (_("[%3u] "), i); | |
9709 | print_dwarf_vma (signature, 8); | |
9710 | putchar ('\n'); | |
9711 | } | |
9712 | putchar ('\n'); | |
9713 | ||
d7870f63 AM |
9714 | uint64_t xtra = (bucket_count * sizeof (uint32_t) |
9715 | + name_count * (sizeof (uint32_t) + 2 * offset_size) | |
9716 | + abbrev_table_size); | |
9717 | if (xtra > (size_t) (unit_end - hdrptr)) | |
9718 | { | |
9719 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
9720 | "for unit 0x%lx in the debug_names\n"), | |
9721 | (long) xtra, | |
9722 | (long) (unit_end - unit_start), | |
9723 | (long) (unit_start - section->start)); | |
9724 | return 0; | |
9725 | } | |
61364358 JK |
9726 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; |
9727 | hdrptr += bucket_count * sizeof (uint32_t); | |
9728 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
9729 | hdrptr += name_count * sizeof (uint32_t); | |
9730 | unsigned char *const name_table_string_offsets = hdrptr; | |
9731 | hdrptr += name_count * offset_size; | |
9732 | unsigned char *const name_table_entry_offsets = hdrptr; | |
9733 | hdrptr += name_count * offset_size; | |
9734 | unsigned char *const abbrev_table = hdrptr; | |
9735 | hdrptr += abbrev_table_size; | |
9736 | const unsigned char *const abbrev_table_end = hdrptr; | |
9737 | unsigned char *const entry_pool = hdrptr; | |
61364358 JK |
9738 | |
9739 | size_t buckets_filled = 0; | |
9740 | size_t bucketi; | |
9741 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
9742 | { | |
9743 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
9744 | ||
9745 | if (bucket != 0) | |
9746 | ++buckets_filled; | |
9747 | } | |
d3a49aa8 AM |
9748 | printf (ngettext ("Used %zu of %lu bucket.\n", |
9749 | "Used %zu of %lu buckets.\n", | |
9750 | bucket_count), | |
9751 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 9752 | |
0a79bef4 | 9753 | uint32_t hash_prev = 0; |
61364358 JK |
9754 | size_t hash_clash_count = 0; |
9755 | size_t longest_clash = 0; | |
9756 | size_t this_length = 0; | |
9757 | size_t hashi; | |
9758 | for (hashi = 0; hashi < name_count; hashi++) | |
9759 | { | |
9760 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
9761 | ||
9762 | if (hashi > 0) | |
9763 | { | |
9764 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
9765 | { | |
9766 | ++hash_clash_count; | |
9767 | ++this_length; | |
9768 | longest_clash = MAX (longest_clash, this_length); | |
9769 | } | |
9770 | else | |
9771 | this_length = 0; | |
9772 | } | |
9773 | hash_prev = hash_this; | |
9774 | } | |
9775 | printf (_("Out of %lu items there are %zu bucket clashes" | |
9776 | " (longest of %zu entries).\n"), | |
9777 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
9778 | assert (name_count == buckets_filled + hash_clash_count); | |
9779 | ||
9780 | struct abbrev_lookup_entry | |
9781 | { | |
9782 | dwarf_vma abbrev_tag; | |
9783 | unsigned char *abbrev_lookup_ptr; | |
9784 | }; | |
9785 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
9786 | size_t abbrev_lookup_used = 0; | |
9787 | size_t abbrev_lookup_allocated = 0; | |
9788 | ||
9789 | unsigned char *abbrevptr = abbrev_table; | |
9790 | for (;;) | |
9791 | { | |
cd30bcef AM |
9792 | dwarf_vma abbrev_tag; |
9793 | ||
9794 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
9795 | if (abbrev_tag == 0) |
9796 | break; | |
9797 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
9798 | { | |
9799 | abbrev_lookup_allocated = MAX (0x100, | |
9800 | abbrev_lookup_allocated * 2); | |
9801 | abbrev_lookup = xrealloc (abbrev_lookup, | |
9802 | (abbrev_lookup_allocated | |
9803 | * sizeof (*abbrev_lookup))); | |
9804 | } | |
9805 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
9806 | struct abbrev_lookup_entry *entry; | |
9807 | for (entry = abbrev_lookup; | |
9808 | entry < abbrev_lookup + abbrev_lookup_used; | |
9809 | entry++) | |
9810 | if (entry->abbrev_tag == abbrev_tag) | |
9811 | { | |
9812 | warn (_("Duplicate abbreviation tag %lu " | |
9813 | "in unit 0x%lx in the debug_names\n"), | |
9814 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
9815 | break; | |
9816 | } | |
9817 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
9818 | entry->abbrev_tag = abbrev_tag; | |
9819 | entry->abbrev_lookup_ptr = abbrevptr; | |
9820 | ||
9821 | /* Skip DWARF tag. */ | |
cd30bcef | 9822 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
9823 | for (;;) |
9824 | { | |
cd30bcef AM |
9825 | dwarf_vma xindex, form; |
9826 | ||
9827 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9828 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9829 | if (xindex == 0 && form == 0) |
61364358 JK |
9830 | break; |
9831 | } | |
9832 | } | |
9833 | ||
9834 | printf (_("\nSymbol table:\n")); | |
9835 | uint32_t namei; | |
9836 | for (namei = 0; namei < name_count; ++namei) | |
9837 | { | |
9838 | uint64_t string_offset, entry_offset; | |
6d1ad6f7 | 9839 | unsigned char *p; |
61364358 | 9840 | |
6d1ad6f7 AM |
9841 | p = name_table_string_offsets + namei * offset_size; |
9842 | SAFE_BYTE_GET (string_offset, p, offset_size, unit_end); | |
9843 | p = name_table_entry_offsets + namei * offset_size; | |
9844 | SAFE_BYTE_GET (entry_offset, p, offset_size, unit_end); | |
61364358 JK |
9845 | |
9846 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9847 | fetch_indirect_string (string_offset)); | |
9848 | ||
9849 | unsigned char *entryptr = entry_pool + entry_offset; | |
9850 | ||
279edac5 AM |
9851 | /* We need to scan first whether there is a single or multiple |
9852 | entries. TAGNO is -2 for the first entry, it is -1 for the | |
9853 | initial tag read of the second entry, then it becomes 0 for the | |
9854 | first entry for real printing etc. */ | |
61364358 JK |
9855 | int tagno = -2; |
9856 | /* Initialize it due to a false compiler warning. */ | |
9857 | dwarf_vma second_abbrev_tag = -1; | |
9858 | for (;;) | |
9859 | { | |
cd30bcef AM |
9860 | dwarf_vma abbrev_tag; |
9861 | dwarf_vma dwarf_tag; | |
9862 | const struct abbrev_lookup_entry *entry; | |
9863 | ||
9864 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
9865 | if (tagno == -1) |
9866 | { | |
9867 | second_abbrev_tag = abbrev_tag; | |
9868 | tagno = 0; | |
9869 | entryptr = entry_pool + entry_offset; | |
9870 | continue; | |
9871 | } | |
9872 | if (abbrev_tag == 0) | |
9873 | break; | |
9874 | if (tagno >= 0) | |
9875 | printf ("%s<%lu>", | |
9876 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9877 | (unsigned long) abbrev_tag); | |
9878 | ||
61364358 JK |
9879 | for (entry = abbrev_lookup; |
9880 | entry < abbrev_lookup + abbrev_lookup_used; | |
9881 | entry++) | |
9882 | if (entry->abbrev_tag == abbrev_tag) | |
9883 | break; | |
9884 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9885 | { | |
9886 | warn (_("Undefined abbreviation tag %lu " | |
9887 | "in unit 0x%lx in the debug_names\n"), | |
9888 | (long) abbrev_tag, | |
9889 | (long) (unit_start - section->start)); | |
9890 | break; | |
9891 | } | |
9892 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 9893 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
9894 | if (tagno >= 0) |
9895 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9896 | for (;;) | |
9897 | { | |
cd30bcef AM |
9898 | dwarf_vma xindex, form; |
9899 | ||
9900 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9901 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9902 | if (xindex == 0 && form == 0) |
61364358 JK |
9903 | break; |
9904 | ||
9905 | if (tagno >= 0) | |
1d827a72 | 9906 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9907 | entryptr = read_and_display_attr_value (0, form, 0, |
9908 | unit_start, entryptr, unit_end, | |
9909 | 0, 0, offset_size, | |
61364358 JK |
9910 | dwarf_version, NULL, |
9911 | (tagno < 0), NULL, | |
ec1b0fbb | 9912 | NULL, '=', -1); |
61364358 JK |
9913 | } |
9914 | ++tagno; | |
9915 | } | |
9916 | if (tagno <= 0) | |
9917 | printf (_(" <no entries>")); | |
9918 | putchar ('\n'); | |
9919 | } | |
9920 | ||
9921 | free (abbrev_lookup); | |
9922 | } | |
9923 | ||
9924 | return 1; | |
9925 | } | |
9926 | ||
dda8d76d | 9927 | static int |
d85bf2ba NC |
9928 | display_debug_links (struct dwarf_section * section, |
9929 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
9930 | { |
9931 | const unsigned char * filename; | |
9932 | unsigned int filelen; | |
9933 | ||
015dc7e1 | 9934 | introduce (section, false); |
dda8d76d NC |
9935 | |
9936 | /* The .gnu_debuglink section is formatted as: | |
9937 | (c-string) Filename. | |
9938 | (padding) If needed to reach a 4 byte boundary. | |
9939 | (uint32_t) CRC32 value. | |
9940 | ||
9941 | The .gun_debugaltlink section is formatted as: | |
9942 | (c-string) Filename. | |
9943 | (binary) Build-ID. */ | |
521d4b19 | 9944 | |
dda8d76d NC |
9945 | filename = section->start; |
9946 | filelen = strnlen ((const char *) filename, section->size); | |
9947 | if (filelen == section->size) | |
9948 | { | |
9949 | warn (_("The debuglink filename is corrupt/missing\n")); | |
9950 | return 0; | |
9951 | } | |
9952 | ||
9953 | printf (_(" Separate debug info file: %s\n"), filename); | |
9954 | ||
24d127aa | 9955 | if (startswith (section->name, ".gnu_debuglink")) |
dda8d76d NC |
9956 | { |
9957 | unsigned int crc32; | |
9958 | unsigned int crc_offset; | |
9959 | ||
9960 | crc_offset = filelen + 1; | |
9961 | crc_offset = (crc_offset + 3) & ~3; | |
9962 | if (crc_offset + 4 > section->size) | |
9963 | { | |
9964 | warn (_("CRC offset missing/truncated\n")); | |
9965 | return 0; | |
9966 | } | |
9967 | ||
9968 | crc32 = byte_get (filename + crc_offset, 4); | |
9969 | ||
9970 | printf (_(" CRC value: %#x\n"), crc32); | |
9971 | ||
9972 | if (crc_offset + 4 < section->size) | |
9973 | { | |
9974 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
9975 | (long)(section->size - (crc_offset + 4))); | |
9976 | return 0; | |
9977 | } | |
9978 | } | |
24d127aa | 9979 | else /* startswith (section->name, ".gnu_debugaltlink") */ |
dda8d76d NC |
9980 | { |
9981 | const unsigned char * build_id = section->start + filelen + 1; | |
9982 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
9983 | bfd_size_type printed; | |
9984 | ||
9985 | /* FIXME: Should we support smaller build-id notes ? */ | |
9986 | if (build_id_len < 0x14) | |
9987 | { | |
9988 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
9989 | return 0; | |
9990 | } | |
9991 | ||
9992 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 9993 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
9994 | putchar ('\n'); |
9995 | } | |
9996 | ||
9997 | putchar ('\n'); | |
9998 | return 1; | |
9999 | } | |
10000 | ||
5bbdf3d5 DE |
10001 | static int |
10002 | display_gdb_index (struct dwarf_section *section, | |
10003 | void *file ATTRIBUTE_UNUSED) | |
10004 | { | |
10005 | unsigned char *start = section->start; | |
10006 | uint32_t version; | |
10007 | uint32_t cu_list_offset, tu_list_offset; | |
10008 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
10009 | unsigned int cu_list_elements, tu_list_elements; | |
10010 | unsigned int address_table_size, symbol_table_slots; | |
10011 | unsigned char *cu_list, *tu_list; | |
10012 | unsigned char *address_table, *symbol_table, *constant_pool; | |
10013 | unsigned int i; | |
10014 | ||
10015 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
10016 | ||
015dc7e1 | 10017 | introduce (section, false); |
5bbdf3d5 DE |
10018 | |
10019 | if (section->size < 6 * sizeof (uint32_t)) | |
10020 | { | |
10021 | warn (_("Truncated header in the %s section.\n"), section->name); | |
10022 | return 0; | |
10023 | } | |
10024 | ||
10025 | version = byte_get_little_endian (start, 4); | |
da88a764 | 10026 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
10027 | |
10028 | /* Prior versions are obsolete, and future versions may not be | |
10029 | backwards compatible. */ | |
aa170720 | 10030 | if (version < 3 || version > 8) |
5bbdf3d5 | 10031 | { |
da88a764 | 10032 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
10033 | return 0; |
10034 | } | |
8d6eee87 TT |
10035 | if (version < 4) |
10036 | warn (_("The address table data in version 3 may be wrong.\n")); | |
10037 | if (version < 5) | |
10038 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
10039 | if (version < 6) | |
10040 | warn (_("Version 5 does not include inlined functions.\n")); | |
10041 | if (version < 7) | |
10042 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
10043 | /* Version 7 indices generated by Gold have bad type unit references, |
10044 | PR binutils/15021. But we don't know if the index was generated by | |
10045 | Gold or not, so to avoid worrying users with gdb-generated indices | |
10046 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
10047 | |
10048 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
10049 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
10050 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
10051 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
10052 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
10053 | ||
10054 | if (cu_list_offset > section->size | |
10055 | || tu_list_offset > section->size | |
10056 | || address_table_offset > section->size | |
10057 | || symbol_table_offset > section->size | |
10058 | || constant_pool_offset > section->size) | |
10059 | { | |
10060 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
10061 | return 0; | |
10062 | } | |
10063 | ||
53774b7e NC |
10064 | /* PR 17531: file: 418d0a8a. */ |
10065 | if (tu_list_offset < cu_list_offset) | |
10066 | { | |
10067 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
10068 | tu_list_offset, cu_list_offset); | |
10069 | return 0; | |
10070 | } | |
10071 | ||
5bbdf3d5 | 10072 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
10073 | |
10074 | if (address_table_offset < tu_list_offset) | |
10075 | { | |
10076 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
10077 | address_table_offset, tu_list_offset); | |
10078 | return 0; | |
10079 | } | |
10080 | ||
5bbdf3d5 | 10081 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
10082 | |
10083 | /* PR 17531: file: 18a47d3d. */ | |
10084 | if (symbol_table_offset < address_table_offset) | |
10085 | { | |
13bace4a | 10086 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
10087 | symbol_table_offset, address_table_offset); |
10088 | return 0; | |
10089 | } | |
10090 | ||
5bbdf3d5 | 10091 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
10092 | |
10093 | if (constant_pool_offset < symbol_table_offset) | |
10094 | { | |
10095 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
10096 | constant_pool_offset, symbol_table_offset); | |
10097 | return 0; | |
10098 | } | |
10099 | ||
5bbdf3d5 DE |
10100 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
10101 | ||
10102 | cu_list = start + cu_list_offset; | |
10103 | tu_list = start + tu_list_offset; | |
10104 | address_table = start + address_table_offset; | |
10105 | symbol_table = start + symbol_table_offset; | |
10106 | constant_pool = start + constant_pool_offset; | |
10107 | ||
bb19bf12 | 10108 | if (address_table_offset + address_table_size > section->size) |
acff9664 | 10109 | { |
1306a742 | 10110 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
10111 | return 0; |
10112 | } | |
b4eb7656 | 10113 | |
5bbdf3d5 DE |
10114 | printf (_("\nCU table:\n")); |
10115 | for (i = 0; i < cu_list_elements; i += 2) | |
10116 | { | |
10117 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
10118 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
10119 | ||
10120 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
10121 | (unsigned long) cu_offset, | |
10122 | (unsigned long) (cu_offset + cu_length - 1)); | |
10123 | } | |
10124 | ||
10125 | printf (_("\nTU table:\n")); | |
10126 | for (i = 0; i < tu_list_elements; i += 3) | |
10127 | { | |
10128 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
10129 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
10130 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
10131 | ||
10132 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
10133 | (unsigned long) tu_offset, | |
10134 | (unsigned long) type_offset); | |
10135 | print_dwarf_vma (signature, 8); | |
10136 | printf ("\n"); | |
10137 | } | |
10138 | ||
10139 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
10140 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
10141 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
10142 | { |
10143 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
10144 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
10145 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
10146 | ||
10147 | print_dwarf_vma (low, 8); | |
10148 | print_dwarf_vma (high, 8); | |
da88a764 | 10149 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
10150 | } |
10151 | ||
10152 | printf (_("\nSymbol table:\n")); | |
10153 | for (i = 0; i < symbol_table_slots; ++i) | |
10154 | { | |
10155 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
10156 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
10157 | uint32_t num_cus, cu; | |
10158 | ||
10159 | if (name_offset != 0 | |
10160 | || cu_vector_offset != 0) | |
10161 | { | |
10162 | unsigned int j; | |
10163 | ||
53774b7e | 10164 | /* PR 17531: file: 5b7b07ad. */ |
bb19bf12 | 10165 | if (name_offset >= section->size - constant_pool_offset) |
53774b7e NC |
10166 | { |
10167 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
10168 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
10169 | name_offset, i); | |
10170 | } | |
10171 | else | |
acff9664 NC |
10172 | printf ("[%3u] %.*s:", i, |
10173 | (int) (section->size - (constant_pool_offset + name_offset)), | |
10174 | constant_pool + name_offset); | |
53774b7e | 10175 | |
bb19bf12 AM |
10176 | if (section->size - constant_pool_offset < 4 |
10177 | || cu_vector_offset > section->size - constant_pool_offset - 4) | |
53774b7e NC |
10178 | { |
10179 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
10180 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
10181 | cu_vector_offset, i); | |
10182 | continue; | |
10183 | } | |
57028622 | 10184 | |
bb19bf12 | 10185 | num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4); |
53774b7e | 10186 | |
bb19bf12 AM |
10187 | if ((uint64_t) num_cus * 4 > section->size - (constant_pool_offset |
10188 | + cu_vector_offset + 4)) | |
53774b7e NC |
10189 | { |
10190 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 10191 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
10192 | num_cus, i); |
10193 | continue; | |
10194 | } | |
10195 | ||
8d6eee87 TT |
10196 | if (num_cus > 1) |
10197 | printf ("\n"); | |
f3853b34 | 10198 | |
5bbdf3d5 DE |
10199 | for (j = 0; j < num_cus; ++j) |
10200 | { | |
7c1cef97 | 10201 | int is_static; |
8d6eee87 TT |
10202 | gdb_index_symbol_kind kind; |
10203 | ||
5bbdf3d5 | 10204 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 10205 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
10206 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
10207 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 10208 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 10209 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
10210 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
10211 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 10212 | else |
8d6eee87 TT |
10213 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
10214 | ||
459d52c8 DE |
10215 | printf (" [%s, %s]", |
10216 | is_static ? _("static") : _("global"), | |
10217 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
10218 | if (num_cus > 1) |
10219 | printf ("\n"); | |
5bbdf3d5 | 10220 | } |
8d6eee87 TT |
10221 | if (num_cus <= 1) |
10222 | printf ("\n"); | |
5bbdf3d5 DE |
10223 | } |
10224 | } | |
10225 | ||
10226 | return 1; | |
10227 | } | |
10228 | ||
657d0d47 CC |
10229 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
10230 | ||
10231 | static void | |
10232 | prealloc_cu_tu_list (unsigned int nshndx) | |
10233 | { | |
10234 | if (shndx_pool == NULL) | |
10235 | { | |
10236 | shndx_pool_size = nshndx; | |
10237 | shndx_pool_used = 0; | |
10238 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
10239 | sizeof (unsigned int)); | |
10240 | } | |
10241 | else | |
10242 | { | |
10243 | shndx_pool_size = shndx_pool_used + nshndx; | |
10244 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
10245 | sizeof (unsigned int)); | |
10246 | } | |
10247 | } | |
10248 | ||
10249 | static void | |
10250 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
10251 | { | |
10252 | if (shndx_pool_used >= shndx_pool_size) | |
10253 | { | |
10254 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10255 | return; | |
10256 | } | |
10257 | shndx_pool [shndx_pool_used++] = shndx; | |
10258 | } | |
10259 | ||
10260 | static void | |
10261 | end_cu_tu_entry (void) | |
10262 | { | |
10263 | if (shndx_pool_used >= shndx_pool_size) | |
10264 | { | |
10265 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10266 | return; | |
10267 | } | |
10268 | shndx_pool [shndx_pool_used++] = 0; | |
10269 | } | |
10270 | ||
341f9135 CC |
10271 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
10272 | ||
10273 | static const char * | |
10274 | get_DW_SECT_short_name (unsigned int dw_sect) | |
10275 | { | |
10276 | static char buf[16]; | |
10277 | ||
10278 | switch (dw_sect) | |
10279 | { | |
10280 | case DW_SECT_INFO: | |
10281 | return "info"; | |
10282 | case DW_SECT_TYPES: | |
10283 | return "types"; | |
10284 | case DW_SECT_ABBREV: | |
10285 | return "abbrev"; | |
10286 | case DW_SECT_LINE: | |
10287 | return "line"; | |
10288 | case DW_SECT_LOC: | |
10289 | return "loc"; | |
10290 | case DW_SECT_STR_OFFSETS: | |
10291 | return "str_off"; | |
10292 | case DW_SECT_MACINFO: | |
10293 | return "macinfo"; | |
10294 | case DW_SECT_MACRO: | |
10295 | return "macro"; | |
10296 | default: | |
b4eb7656 | 10297 | break; |
341f9135 CC |
10298 | } |
10299 | ||
10300 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
10301 | return buf; | |
10302 | } | |
10303 | ||
10304 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
10305 | These sections are extensions for Fission. | |
10306 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
10307 | |
10308 | static int | |
10309 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
10310 | { | |
10311 | unsigned char *phdr = section->start; | |
10312 | unsigned char *limit = phdr + section->size; | |
10313 | unsigned char *phash; | |
10314 | unsigned char *pindex; | |
10315 | unsigned char *ppool; | |
10316 | unsigned int version; | |
341f9135 | 10317 | unsigned int ncols = 0; |
657d0d47 CC |
10318 | unsigned int nused; |
10319 | unsigned int nslots; | |
10320 | unsigned int i; | |
341f9135 | 10321 | unsigned int j; |
af2ddf69 | 10322 | dwarf_vma signature; |
b9c0d703 | 10323 | size_t total; |
657d0d47 | 10324 | |
6937bb54 NC |
10325 | /* PR 17512: file: 002-168123-0.004. */ |
10326 | if (phdr == NULL) | |
10327 | { | |
10328 | warn (_("Section %s is empty\n"), section->name); | |
10329 | return 0; | |
10330 | } | |
10331 | /* PR 17512: file: 002-376-0.004. */ | |
10332 | if (section->size < 24) | |
10333 | { | |
72c61a0d | 10334 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
10335 | section->name); |
10336 | return 0; | |
10337 | } | |
10338 | ||
6d1ad6f7 AM |
10339 | phash = phdr; |
10340 | SAFE_BYTE_GET_AND_INC (version, phash, 4, limit); | |
341f9135 | 10341 | if (version >= 2) |
6d1ad6f7 AM |
10342 | SAFE_BYTE_GET_AND_INC (ncols, phash, 4, limit); |
10343 | SAFE_BYTE_GET_AND_INC (nused, phash, 4, limit); | |
10344 | SAFE_BYTE_GET_AND_INC (nslots, phash, 4, limit); | |
6937bb54 | 10345 | |
8e2e3c6c AM |
10346 | pindex = phash + (size_t) nslots * 8; |
10347 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 10348 | |
657d0d47 CC |
10349 | if (do_display) |
10350 | { | |
015dc7e1 | 10351 | introduce (section, false); |
dda8d76d | 10352 | |
8e2e3c6c | 10353 | printf (_(" Version: %u\n"), version); |
341f9135 | 10354 | if (version >= 2) |
8e2e3c6c AM |
10355 | printf (_(" Number of columns: %u\n"), ncols); |
10356 | printf (_(" Number of used entries: %u\n"), nused); | |
10357 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
10358 | } |
10359 | ||
8e2e3c6c | 10360 | /* PR 17531: file: 45d69832. */ |
b9c0d703 AM |
10361 | if (_mul_overflow ((size_t) nslots, 12, &total) |
10362 | || total > (size_t) (limit - phash)) | |
657d0d47 | 10363 | { |
8e2e3c6c AM |
10364 | warn (ngettext ("Section %s is too small for %u slot\n", |
10365 | "Section %s is too small for %u slots\n", | |
10366 | nslots), | |
657d0d47 CC |
10367 | section->name, nslots); |
10368 | return 0; | |
10369 | } | |
10370 | ||
341f9135 | 10371 | if (version == 1) |
657d0d47 | 10372 | { |
341f9135 CC |
10373 | if (!do_display) |
10374 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
10375 | for (i = 0; i < nslots; i++) | |
657d0d47 | 10376 | { |
341f9135 CC |
10377 | unsigned char *shndx_list; |
10378 | unsigned int shndx; | |
10379 | ||
af2ddf69 AM |
10380 | SAFE_BYTE_GET (signature, phash, 8, limit); |
10381 | if (signature != 0) | |
657d0d47 | 10382 | { |
6937bb54 | 10383 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 10384 | shndx_list = ppool + j * 4; |
f3853b34 NC |
10385 | /* PR 17531: file: 705e010d. */ |
10386 | if (shndx_list < ppool) | |
10387 | { | |
10388 | warn (_("Section index pool located before start of section\n")); | |
10389 | return 0; | |
10390 | } | |
10391 | ||
341f9135 CC |
10392 | if (do_display) |
10393 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
af2ddf69 | 10394 | i, dwarf_vmatoa ("x", signature)); |
341f9135 | 10395 | for (;;) |
657d0d47 | 10396 | { |
341f9135 CC |
10397 | if (shndx_list >= limit) |
10398 | { | |
10399 | warn (_("Section %s too small for shndx pool\n"), | |
10400 | section->name); | |
10401 | return 0; | |
10402 | } | |
6937bb54 | 10403 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
10404 | if (shndx == 0) |
10405 | break; | |
10406 | if (do_display) | |
10407 | printf (" %d", shndx); | |
10408 | else | |
10409 | add_shndx_to_cu_tu_entry (shndx); | |
10410 | shndx_list += 4; | |
657d0d47 | 10411 | } |
657d0d47 | 10412 | if (do_display) |
341f9135 | 10413 | printf ("\n"); |
657d0d47 | 10414 | else |
341f9135 CC |
10415 | end_cu_tu_entry (); |
10416 | } | |
10417 | phash += 8; | |
10418 | pindex += 4; | |
10419 | } | |
10420 | } | |
10421 | else if (version == 2) | |
10422 | { | |
10423 | unsigned int val; | |
10424 | unsigned int dw_sect; | |
10425 | unsigned char *ph = phash; | |
10426 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
10427 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
10428 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
015dc7e1 | 10429 | bool is_tu_index; |
341f9135 CC |
10430 | struct cu_tu_set *this_set = NULL; |
10431 | unsigned int row; | |
10432 | unsigned char *prow; | |
b9c0d703 | 10433 | size_t temp; |
341f9135 CC |
10434 | |
10435 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
10436 | ||
362beea4 | 10437 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
10438 | Check for integer overflow (can occur when size_t is 32-bit) |
10439 | with overlarge ncols or nused values. */ | |
b9c0d703 AM |
10440 | if (nused == -1u |
10441 | || _mul_overflow ((size_t) ncols, 4, &temp) | |
10442 | || _mul_overflow ((size_t) nused + 1, temp, &total) | |
10443 | || total > (size_t) (limit - ppool)) | |
341f9135 CC |
10444 | { |
10445 | warn (_("Section %s too small for offset and size tables\n"), | |
10446 | section->name); | |
10447 | return 0; | |
10448 | } | |
10449 | ||
10450 | if (do_display) | |
10451 | { | |
10452 | printf (_(" Offset table\n")); | |
10453 | printf (" slot %-16s ", | |
10454 | is_tu_index ? _("signature") : _("dwo_id")); | |
10455 | } | |
10456 | else | |
10457 | { | |
10458 | if (is_tu_index) | |
10459 | { | |
10460 | tu_count = nused; | |
72c61a0d | 10461 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 10462 | this_set = tu_sets; |
657d0d47 | 10463 | } |
657d0d47 | 10464 | else |
341f9135 CC |
10465 | { |
10466 | cu_count = nused; | |
72c61a0d | 10467 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
10468 | this_set = cu_sets; |
10469 | } | |
10470 | } | |
6937bb54 | 10471 | |
341f9135 CC |
10472 | if (do_display) |
10473 | { | |
10474 | for (j = 0; j < ncols; j++) | |
10475 | { | |
6d1ad6f7 AM |
10476 | unsigned char *p = ppool + j * 4; |
10477 | SAFE_BYTE_GET (dw_sect, p, 4, limit); | |
341f9135 CC |
10478 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
10479 | } | |
10480 | printf ("\n"); | |
10481 | } | |
6937bb54 | 10482 | |
341f9135 CC |
10483 | for (i = 0; i < nslots; i++) |
10484 | { | |
af2ddf69 | 10485 | SAFE_BYTE_GET (signature, ph, 8, limit); |
6937bb54 NC |
10486 | |
10487 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10488 | if (row != 0) |
10489 | { | |
591f7597 | 10490 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 10491 | if (row > nused) |
591f7597 NC |
10492 | { |
10493 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
10494 | row, nused); | |
10495 | return 0; | |
10496 | } | |
10497 | ||
341f9135 | 10498 | if (!do_display) |
6aea08d9 NC |
10499 | { |
10500 | size_t num_copy = sizeof (uint64_t); | |
10501 | ||
b9c0d703 | 10502 | memcpy (&this_set[row - 1].signature, ph, num_copy); |
6aea08d9 | 10503 | } |
6937bb54 | 10504 | |
341f9135 CC |
10505 | prow = poffsets + (row - 1) * ncols * 4; |
10506 | if (do_display) | |
10507 | printf (_(" [%3d] 0x%s"), | |
af2ddf69 | 10508 | i, dwarf_vmatoa ("x", signature)); |
341f9135 CC |
10509 | for (j = 0; j < ncols; j++) |
10510 | { | |
6d1ad6f7 AM |
10511 | unsigned char *p = prow + j * 4; |
10512 | SAFE_BYTE_GET (val, p, 4, limit); | |
341f9135 CC |
10513 | if (do_display) |
10514 | printf (" %8d", val); | |
10515 | else | |
10516 | { | |
6d1ad6f7 AM |
10517 | p = ppool + j * 4; |
10518 | SAFE_BYTE_GET (dw_sect, p, 4, limit); | |
82b1b41b NC |
10519 | |
10520 | /* PR 17531: file: 10796eb3. */ | |
10521 | if (dw_sect >= DW_SECT_MAX) | |
10522 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10523 | else | |
10524 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
10525 | } |
10526 | } | |
6937bb54 | 10527 | |
341f9135 CC |
10528 | if (do_display) |
10529 | printf ("\n"); | |
10530 | } | |
10531 | ph += 8; | |
10532 | pi += 4; | |
10533 | } | |
10534 | ||
10535 | ph = phash; | |
10536 | pi = pindex; | |
10537 | if (do_display) | |
b4eb7656 | 10538 | { |
341f9135 CC |
10539 | printf ("\n"); |
10540 | printf (_(" Size table\n")); | |
10541 | printf (" slot %-16s ", | |
10542 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 10543 | } |
6937bb54 | 10544 | |
341f9135 CC |
10545 | for (j = 0; j < ncols; j++) |
10546 | { | |
6d1ad6f7 AM |
10547 | unsigned char *p = ppool + j * 4; |
10548 | SAFE_BYTE_GET (val, p, 4, limit); | |
341f9135 CC |
10549 | if (do_display) |
10550 | printf (" %8s", get_DW_SECT_short_name (val)); | |
10551 | } | |
6937bb54 | 10552 | |
341f9135 CC |
10553 | if (do_display) |
10554 | printf ("\n"); | |
6937bb54 | 10555 | |
341f9135 CC |
10556 | for (i = 0; i < nslots; i++) |
10557 | { | |
af2ddf69 | 10558 | SAFE_BYTE_GET (signature, ph, 8, limit); |
6937bb54 NC |
10559 | |
10560 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10561 | if (row != 0) |
10562 | { | |
10563 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 10564 | |
341f9135 CC |
10565 | if (do_display) |
10566 | printf (_(" [%3d] 0x%s"), | |
af2ddf69 | 10567 | i, dwarf_vmatoa ("x", signature)); |
6937bb54 | 10568 | |
341f9135 CC |
10569 | for (j = 0; j < ncols; j++) |
10570 | { | |
6d1ad6f7 AM |
10571 | unsigned char *p = prow + j * 4; |
10572 | SAFE_BYTE_GET (val, p, 4, limit); | |
341f9135 CC |
10573 | if (do_display) |
10574 | printf (" %8d", val); | |
10575 | else | |
10576 | { | |
6d1ad6f7 AM |
10577 | p = ppool + j * 4; |
10578 | SAFE_BYTE_GET (dw_sect, p, 4, limit); | |
82b1b41b NC |
10579 | if (dw_sect >= DW_SECT_MAX) |
10580 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10581 | else | |
341f9135 CC |
10582 | this_set [row - 1].section_sizes [dw_sect] = val; |
10583 | } | |
10584 | } | |
6937bb54 | 10585 | |
341f9135 CC |
10586 | if (do_display) |
10587 | printf ("\n"); | |
10588 | } | |
6937bb54 | 10589 | |
341f9135 CC |
10590 | ph += 8; |
10591 | pi += 4; | |
657d0d47 | 10592 | } |
657d0d47 | 10593 | } |
341f9135 | 10594 | else if (do_display) |
6937bb54 | 10595 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
10596 | |
10597 | if (do_display) | |
10598 | printf ("\n"); | |
10599 | ||
10600 | return 1; | |
10601 | } | |
10602 | ||
288f0ba2 AM |
10603 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
10604 | ||
657d0d47 CC |
10605 | /* Load the CU and TU indexes if present. This will build a list of |
10606 | section sets that we can use to associate a .debug_info.dwo section | |
10607 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
10608 | ||
015dc7e1 | 10609 | static bool |
657d0d47 CC |
10610 | load_cu_tu_indexes (void *file) |
10611 | { | |
10612 | /* If we have already loaded (or tried to load) the CU and TU indexes | |
10613 | then do not bother to repeat the task. */ | |
43a444f9 NC |
10614 | if (cu_tu_indexes_read == -1) |
10615 | { | |
015dc7e1 | 10616 | cu_tu_indexes_read = true; |
521d4b19 | 10617 | |
dda8d76d | 10618 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 | 10619 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
015dc7e1 | 10620 | cu_tu_indexes_read = false; |
43a444f9 | 10621 | |
dda8d76d | 10622 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 | 10623 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
015dc7e1 | 10624 | cu_tu_indexes_read = false; |
43a444f9 | 10625 | } |
657d0d47 | 10626 | |
015dc7e1 | 10627 | return (bool) cu_tu_indexes_read; |
657d0d47 CC |
10628 | } |
10629 | ||
10630 | /* Find the set of sections that includes section SHNDX. */ | |
10631 | ||
10632 | unsigned int * | |
10633 | find_cu_tu_set (void *file, unsigned int shndx) | |
10634 | { | |
10635 | unsigned int i; | |
10636 | ||
43a444f9 NC |
10637 | if (! load_cu_tu_indexes (file)) |
10638 | return NULL; | |
657d0d47 CC |
10639 | |
10640 | /* Find SHNDX in the shndx pool. */ | |
10641 | for (i = 0; i < shndx_pool_used; i++) | |
10642 | if (shndx_pool [i] == shndx) | |
10643 | break; | |
10644 | ||
10645 | if (i >= shndx_pool_used) | |
10646 | return NULL; | |
10647 | ||
10648 | /* Now backup to find the first entry in the set. */ | |
10649 | while (i > 0 && shndx_pool [i - 1] != 0) | |
10650 | i--; | |
10651 | ||
10652 | return shndx_pool + i; | |
10653 | } | |
10654 | ||
10655 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
10656 | ||
10657 | static int | |
10658 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
10659 | { | |
10660 | return process_cu_tu_index (section, 1); | |
10661 | } | |
10662 | ||
19e6b90e L |
10663 | static int |
10664 | display_debug_not_supported (struct dwarf_section *section, | |
10665 | void *file ATTRIBUTE_UNUSED) | |
10666 | { | |
10667 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
10668 | section->name); | |
10669 | ||
10670 | return 1; | |
10671 | } | |
10672 | ||
1306a742 NC |
10673 | /* Like malloc, but takes two parameters like calloc. |
10674 | Verifies that the first parameter is not too large. | |
82b1b41b | 10675 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 10676 | |
19e6b90e L |
10677 | void * |
10678 | cmalloc (size_t nmemb, size_t size) | |
10679 | { | |
10680 | /* Check for overflow. */ | |
10681 | if (nmemb >= ~(size_t) 0 / size) | |
10682 | return NULL; | |
82b1b41b NC |
10683 | |
10684 | return xmalloc (nmemb * size); | |
19e6b90e L |
10685 | } |
10686 | ||
1306a742 NC |
10687 | /* Like xmalloc, but takes two parameters like calloc. |
10688 | Verifies that the first parameter is not too large. | |
10689 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 10690 | |
72c61a0d | 10691 | void * |
1306a742 | 10692 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
10693 | { |
10694 | /* Check for overflow. */ | |
10695 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
10696 | { |
10697 | fprintf (stderr, | |
10698 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
10699 | (long) nmemb); | |
10700 | xexit (1); | |
10701 | } | |
72c61a0d | 10702 | |
1306a742 | 10703 | return xmalloc (nmemb * size); |
72c61a0d NC |
10704 | } |
10705 | ||
1306a742 NC |
10706 | /* Like xrealloc, but takes three parameters. |
10707 | Verifies that the second parameter is not too large. | |
10708 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 10709 | |
19e6b90e | 10710 | void * |
1306a742 | 10711 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
10712 | { |
10713 | /* Check for overflow. */ | |
10714 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10715 | { |
dda8d76d NC |
10716 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
10717 | (long) nmemb); | |
8490fb40 NC |
10718 | xexit (1); |
10719 | } | |
82b1b41b | 10720 | |
1306a742 | 10721 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
10722 | } |
10723 | ||
1306a742 | 10724 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 10725 | |
19e6b90e | 10726 | void * |
1306a742 | 10727 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
10728 | { |
10729 | /* Check for overflow. */ | |
10730 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10731 | { |
dda8d76d NC |
10732 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
10733 | (long) nmemb); | |
8490fb40 NC |
10734 | xexit (1); |
10735 | } | |
82b1b41b | 10736 | |
1306a742 | 10737 | return xcalloc (nmemb, size); |
19e6b90e L |
10738 | } |
10739 | ||
dda8d76d NC |
10740 | static unsigned long |
10741 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
10742 | const unsigned char * buf, | |
10743 | bfd_size_type len) | |
10744 | { | |
10745 | static const unsigned long crc32_table[256] = | |
10746 | { | |
10747 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
10748 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
10749 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
10750 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
10751 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
10752 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
10753 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
10754 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
10755 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
10756 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
10757 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
10758 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
10759 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
10760 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
10761 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
10762 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
10763 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
10764 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
10765 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
10766 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
10767 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
10768 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
10769 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
10770 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
10771 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
10772 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
10773 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
10774 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
10775 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
10776 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
10777 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
10778 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
10779 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
10780 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
10781 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
10782 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
10783 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
10784 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
10785 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
10786 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
10787 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
10788 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
10789 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
10790 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
10791 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
10792 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
10793 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
10794 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
10795 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
10796 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
10797 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
10798 | 0x2d02ef8d | |
10799 | }; | |
10800 | const unsigned char *end; | |
10801 | ||
10802 | crc = ~crc & 0xffffffff; | |
10803 | for (end = buf + len; buf < end; ++ buf) | |
10804 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10805 | return ~crc & 0xffffffff; | |
10806 | } | |
10807 | ||
015dc7e1 AM |
10808 | typedef bool (*check_func_type) (const char *, void *); |
10809 | typedef const char *(* parse_func_type) (struct dwarf_section *, void *); | |
dda8d76d | 10810 | |
015dc7e1 | 10811 | static bool |
dda8d76d NC |
10812 | check_gnu_debuglink (const char * pathname, void * crc_pointer) |
10813 | { | |
10814 | static unsigned char buffer [8 * 1024]; | |
10815 | FILE * f; | |
10816 | bfd_size_type count; | |
10817 | unsigned long crc = 0; | |
10818 | void * sep_data; | |
10819 | ||
10820 | sep_data = open_debug_file (pathname); | |
10821 | if (sep_data == NULL) | |
015dc7e1 | 10822 | return false; |
dda8d76d NC |
10823 | |
10824 | /* Yes - we are opening the file twice... */ | |
10825 | f = fopen (pathname, "rb"); | |
10826 | if (f == NULL) | |
10827 | { | |
10828 | /* Paranoia: This should never happen. */ | |
10829 | close_debug_file (sep_data); | |
10830 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
015dc7e1 | 10831 | return false; |
dda8d76d NC |
10832 | } |
10833 | ||
10834 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10835 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10836 | ||
10837 | fclose (f); | |
10838 | ||
10839 | if (crc != * (unsigned long *) crc_pointer) | |
10840 | { | |
10841 | close_debug_file (sep_data); | |
10842 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10843 | pathname); | |
015dc7e1 | 10844 | return false; |
dda8d76d NC |
10845 | } |
10846 | ||
015dc7e1 | 10847 | return true; |
dda8d76d NC |
10848 | } |
10849 | ||
10850 | static const char * | |
10851 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10852 | { | |
10853 | const char * name; | |
10854 | unsigned int crc_offset; | |
10855 | unsigned long * crc32 = (unsigned long *) data; | |
10856 | ||
10857 | /* The name is first. | |
10858 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10859 | name = (const char *) section->start; | |
10860 | ||
10861 | crc_offset = strnlen (name, section->size) + 1; | |
3d64c987 NC |
10862 | if (crc_offset == 1) |
10863 | return NULL; | |
dda8d76d NC |
10864 | crc_offset = (crc_offset + 3) & ~3; |
10865 | if (crc_offset + 4 > section->size) | |
10866 | return NULL; | |
10867 | ||
10868 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10869 | return name; | |
10870 | } | |
10871 | ||
015dc7e1 | 10872 | static bool |
dda8d76d NC |
10873 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) |
10874 | { | |
10875 | void * sep_data = open_debug_file (filename); | |
10876 | ||
10877 | if (sep_data == NULL) | |
015dc7e1 | 10878 | return false; |
dda8d76d NC |
10879 | |
10880 | /* FIXME: We should now extract the build-id in the separate file | |
10881 | and check it... */ | |
10882 | ||
015dc7e1 | 10883 | return true; |
dda8d76d NC |
10884 | } |
10885 | ||
10886 | typedef struct build_id_data | |
10887 | { | |
10888 | bfd_size_type len; | |
10889 | const unsigned char * data; | |
10890 | } Build_id_data; | |
10891 | ||
10892 | static const char * | |
10893 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10894 | { | |
10895 | const char * name; | |
10896 | bfd_size_type namelen; | |
10897 | bfd_size_type id_len; | |
10898 | Build_id_data * build_id_data; | |
10899 | ||
10900 | /* The name is first. | |
10901 | The build-id follows immediately, with no padding, up to the section's end. */ | |
10902 | ||
10903 | name = (const char *) section->start; | |
10904 | namelen = strnlen (name, section->size) + 1; | |
3d64c987 NC |
10905 | if (namelen == 1) |
10906 | return NULL; | |
dda8d76d NC |
10907 | if (namelen >= section->size) |
10908 | return NULL; | |
10909 | ||
10910 | id_len = section->size - namelen; | |
10911 | if (id_len < 0x14) | |
10912 | return NULL; | |
10913 | ||
dfbee680 | 10914 | build_id_data = (Build_id_data *) data; |
dda8d76d NC |
10915 | build_id_data->len = id_len; |
10916 | build_id_data->data = section->start + namelen; | |
10917 | ||
dda8d76d NC |
10918 | return name; |
10919 | } | |
10920 | ||
24841daa NC |
10921 | static void |
10922 | add_separate_debug_file (const char * filename, void * handle) | |
10923 | { | |
10924 | separate_info * i = xmalloc (sizeof * i); | |
10925 | ||
10926 | i->filename = filename; | |
10927 | i->handle = handle; | |
10928 | i->next = first_separate_info; | |
10929 | first_separate_info = i; | |
10930 | } | |
10931 | ||
301a9420 AM |
10932 | #if HAVE_LIBDEBUGINFOD |
10933 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
10934 | file. If successful, store the path of the file in filename and | |
10935 | return TRUE, otherwise return FALSE. */ | |
10936 | ||
015dc7e1 | 10937 | static bool |
301a9420 AM |
10938 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, |
10939 | char ** filename, | |
10940 | void * file) | |
10941 | { | |
10942 | size_t build_id_len; | |
10943 | unsigned char * build_id; | |
10944 | ||
10945 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
10946 | { | |
10947 | /* Get the build-id of file. */ | |
10948 | build_id = get_build_id (file); | |
10949 | build_id_len = 0; | |
10950 | } | |
10951 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
10952 | { | |
10953 | /* Get the build-id of the debugaltlink file. */ | |
10954 | unsigned int filelen; | |
10955 | ||
10956 | filelen = strnlen ((const char *)section->start, section->size); | |
10957 | if (filelen == section->size) | |
10958 | /* Corrupt debugaltlink. */ | |
015dc7e1 | 10959 | return false; |
301a9420 AM |
10960 | |
10961 | build_id = section->start + filelen + 1; | |
10962 | build_id_len = section->size - (filelen + 1); | |
10963 | ||
10964 | if (build_id_len == 0) | |
015dc7e1 | 10965 | return false; |
301a9420 AM |
10966 | } |
10967 | else | |
015dc7e1 | 10968 | return false; |
301a9420 AM |
10969 | |
10970 | if (build_id) | |
10971 | { | |
10972 | int fd; | |
10973 | debuginfod_client * client; | |
10974 | ||
10975 | client = debuginfod_begin (); | |
10976 | if (client == NULL) | |
015dc7e1 | 10977 | return false; |
301a9420 AM |
10978 | |
10979 | /* Query debuginfod servers for the target file. If found its path | |
10980 | will be stored in filename. */ | |
10981 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); | |
10982 | debuginfod_end (client); | |
10983 | ||
10984 | /* Only free build_id if we allocated space for a hex string | |
10985 | in get_build_id (). */ | |
10986 | if (build_id_len == 0) | |
10987 | free (build_id); | |
10988 | ||
10989 | if (fd >= 0) | |
10990 | { | |
10991 | /* File successfully retrieved. Close fd since we want to | |
10992 | use open_debug_file () on filename instead. */ | |
10993 | close (fd); | |
015dc7e1 | 10994 | return true; |
301a9420 AM |
10995 | } |
10996 | } | |
10997 | ||
015dc7e1 | 10998 | return false; |
301a9420 AM |
10999 | } |
11000 | #endif | |
11001 | ||
dda8d76d NC |
11002 | static void * |
11003 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 11004 | struct dwarf_section * xlink, |
dda8d76d NC |
11005 | parse_func_type parse_func, |
11006 | check_func_type check_func, | |
301a9420 AM |
11007 | void * func_data, |
11008 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
11009 | { |
11010 | const char * separate_filename; | |
24841daa | 11011 | char * debug_filename; |
dda8d76d NC |
11012 | char * canon_dir; |
11013 | size_t canon_dirlen; | |
11014 | size_t dirlen; | |
11015 | ||
2b63c337 | 11016 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
11017 | { |
11018 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 11019 | xlink->name ? xlink->name : xlink->uncompressed_name); |
ce139cd5 | 11020 | return NULL; |
dda8d76d | 11021 | } |
521d4b19 | 11022 | |
dda8d76d NC |
11023 | /* Attempt to locate the separate file. |
11024 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
11025 | ||
11026 | canon_dir = lrealpath (main_filename); | |
521d4b19 | 11027 | |
dda8d76d NC |
11028 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) |
11029 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
11030 | break; | |
11031 | canon_dir[canon_dirlen] = '\0'; | |
11032 | ||
11033 | #ifndef DEBUGDIR | |
11034 | #define DEBUGDIR "/lib/debug" | |
11035 | #endif | |
11036 | #ifndef EXTRA_DEBUG_ROOT1 | |
11037 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
11038 | #endif | |
11039 | #ifndef EXTRA_DEBUG_ROOT2 | |
11040 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
11041 | #endif | |
11042 | ||
24841daa NC |
11043 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
11044 | + canon_dirlen | |
11045 | + strlen (".debug/") | |
dda8d76d | 11046 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 11047 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
11048 | #endif |
11049 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 11050 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 11051 | #endif |
24841daa NC |
11052 | + strlen (separate_filename) |
11053 | + 1); | |
11054 | if (debug_filename == NULL) | |
dda8d76d NC |
11055 | { |
11056 | warn (_("Out of memory")); | |
3391569f | 11057 | free (canon_dir); |
dda8d76d NC |
11058 | return NULL; |
11059 | } | |
11060 | ||
11061 | /* First try in the current directory. */ | |
24841daa NC |
11062 | sprintf (debug_filename, "%s", separate_filename); |
11063 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11064 | goto found; |
11065 | ||
11066 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
11067 | sprintf (debug_filename, ".debug/%s", separate_filename); |
11068 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11069 | goto found; |
11070 | ||
11071 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
11072 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
11073 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11074 | goto found; |
11075 | ||
11076 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
11077 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
11078 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11079 | goto found; |
11080 | ||
11081 | #ifdef EXTRA_DEBUG_ROOT1 | |
11082 | /* Try the first extra debug file root. */ | |
24841daa NC |
11083 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
11084 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 11085 | goto found; |
39f0547e NC |
11086 | |
11087 | /* Try the first extra debug file root. */ | |
11088 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
11089 | if (check_func (debug_filename, func_data)) | |
11090 | goto found; | |
dda8d76d NC |
11091 | #endif |
11092 | ||
11093 | #ifdef EXTRA_DEBUG_ROOT2 | |
11094 | /* Try the second extra debug file root. */ | |
24841daa NC |
11095 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
11096 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11097 | goto found; |
11098 | #endif | |
11099 | ||
24841daa NC |
11100 | /* Then try in the global debug_filename directory. */ |
11101 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
11102 | dirlen = strlen (DEBUGDIR) - 1; |
11103 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
11104 | strcat (debug_filename, "/"); |
11105 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 11106 | |
24841daa | 11107 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
11108 | goto found; |
11109 | ||
301a9420 AM |
11110 | #if HAVE_LIBDEBUGINFOD |
11111 | { | |
11112 | char * tmp_filename; | |
11113 | ||
11114 | if (debuginfod_fetch_separate_debug_info (xlink, | |
11115 | & tmp_filename, | |
11116 | file)) | |
11117 | { | |
11118 | /* File successfully downloaded from server, replace | |
11119 | debug_filename with the file's path. */ | |
11120 | free (debug_filename); | |
11121 | debug_filename = tmp_filename; | |
11122 | goto found; | |
11123 | } | |
11124 | } | |
11125 | #endif | |
11126 | ||
ecd65684 L |
11127 | if (do_debug_links) |
11128 | { | |
11129 | /* Failed to find the file. */ | |
11130 | warn (_("could not find separate debug file '%s'\n"), | |
11131 | separate_filename); | |
11132 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11133 | |
11134 | #ifdef EXTRA_DEBUG_ROOT2 | |
ecd65684 L |
11135 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, |
11136 | separate_filename); | |
11137 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11138 | #endif |
11139 | ||
11140 | #ifdef EXTRA_DEBUG_ROOT1 | |
ecd65684 L |
11141 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, |
11142 | canon_dir, separate_filename); | |
11143 | warn (_("tried: %s\n"), debug_filename); | |
39f0547e | 11144 | |
ecd65684 L |
11145 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, |
11146 | separate_filename); | |
11147 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11148 | #endif |
11149 | ||
ecd65684 L |
11150 | sprintf (debug_filename, "%s.debug/%s", canon_dir, |
11151 | separate_filename); | |
11152 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11153 | |
ecd65684 L |
11154 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
11155 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11156 | |
ecd65684 L |
11157 | sprintf (debug_filename, ".debug/%s", separate_filename); |
11158 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11159 | |
ecd65684 L |
11160 | sprintf (debug_filename, "%s", separate_filename); |
11161 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11162 | |
301a9420 | 11163 | #if HAVE_LIBDEBUGINFOD |
ecd65684 L |
11164 | { |
11165 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
11166 | if (urls == NULL) | |
11167 | urls = ""; | |
301a9420 | 11168 | |
ecd65684 L |
11169 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); |
11170 | } | |
301a9420 | 11171 | #endif |
ecd65684 | 11172 | } |
301a9420 | 11173 | |
dda8d76d | 11174 | free (canon_dir); |
24841daa | 11175 | free (debug_filename); |
dda8d76d NC |
11176 | return NULL; |
11177 | ||
11178 | found: | |
11179 | free (canon_dir); | |
11180 | ||
24841daa NC |
11181 | void * debug_handle; |
11182 | ||
dda8d76d | 11183 | /* Now open the file.... */ |
24841daa | 11184 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 11185 | { |
24841daa NC |
11186 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
11187 | free (debug_filename); | |
ce139cd5 | 11188 | return NULL; |
dda8d76d NC |
11189 | } |
11190 | ||
11191 | /* FIXME: We do not check to see if there are any other separate debug info | |
11192 | files that would also match. */ | |
11193 | ||
ca0e11aa NC |
11194 | if (do_debug_links) |
11195 | printf (_("\n%s: Found separate debug info file: %s\n"), main_filename, debug_filename); | |
24841daa | 11196 | add_separate_debug_file (debug_filename, debug_handle); |
dda8d76d | 11197 | |
24841daa | 11198 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 11199 | the structure returned by open_debug_file(). */ |
24841daa | 11200 | return debug_handle; |
dda8d76d NC |
11201 | } |
11202 | ||
d85bf2ba NC |
11203 | /* Attempt to load a separate dwarf object file. */ |
11204 | ||
11205 | static void * | |
24841daa | 11206 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 11207 | { |
24841daa NC |
11208 | char * separate_filename; |
11209 | void * separate_handle; | |
d85bf2ba | 11210 | |
d9d9d8ef TV |
11211 | if (IS_ABSOLUTE_PATH (name)) |
11212 | separate_filename = strdup (name); | |
11213 | else | |
11214 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
11215 | separate_filename = concat (dir, "/", name, NULL); | |
24841daa | 11216 | if (separate_filename == NULL) |
d85bf2ba NC |
11217 | { |
11218 | warn (_("Out of memory allocating dwo filename\n")); | |
11219 | return NULL; | |
11220 | } | |
11221 | ||
24841daa | 11222 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 11223 | { |
24841daa NC |
11224 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
11225 | free (separate_filename); | |
d85bf2ba NC |
11226 | return NULL; |
11227 | } | |
11228 | ||
11229 | /* FIXME: We should check the dwo_id. */ | |
11230 | ||
24841daa | 11231 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
bfbfa6e7 | 11232 | |
24841daa NC |
11233 | add_separate_debug_file (separate_filename, separate_handle); |
11234 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
11235 | return separate_handle; | |
d85bf2ba NC |
11236 | } |
11237 | ||
e38332c2 NC |
11238 | static void |
11239 | load_debug_sup_file (const char * main_filename, void * file) | |
11240 | { | |
11241 | if (! load_debug_section (debug_sup, file)) | |
11242 | return; /* No .debug_sup section. */ | |
11243 | ||
11244 | struct dwarf_section * section; | |
11245 | section = & debug_displays [debug_sup].section; | |
11246 | assert (section != NULL); | |
11247 | ||
11248 | if (section->start == NULL || section->size < 5) | |
11249 | { | |
11250 | warn (_(".debug_sup section is corrupt/empty\n")); | |
11251 | return; | |
11252 | } | |
11253 | ||
11254 | if (section->start[2] != 0) | |
11255 | return; /* This is a supplementary file. */ | |
11256 | ||
11257 | const char * filename = (const char *) section->start + 3; | |
11258 | if (strnlen (filename, section->size - 3) == section->size - 3) | |
11259 | { | |
11260 | warn (_("filename in .debug_sup section is corrupt\n")); | |
11261 | return; | |
11262 | } | |
11263 | ||
11264 | if (filename[0] != '/' && strchr (main_filename, '/')) | |
11265 | { | |
11266 | char * new_name; | |
bfbfa6e7 NC |
11267 | int new_len; |
11268 | ||
11269 | new_len = asprintf (& new_name, "%.*s/%s", | |
11270 | (int) (strrchr (main_filename, '/') - main_filename), | |
11271 | main_filename, | |
11272 | filename); | |
11273 | if (new_len < 3) | |
11274 | { | |
11275 | warn (_("unable to construct path for supplementary debug file")); | |
11276 | if (new_len > -1) | |
11277 | free (new_name); | |
11278 | return; | |
11279 | } | |
11280 | filename = new_name; | |
11281 | } | |
11282 | else | |
11283 | { | |
11284 | /* PR 27796: Make sure that we pass a filename that can be free'd to | |
11285 | add_separate_debug_file(). */ | |
11286 | filename = strdup (filename); | |
11287 | if (filename == NULL) | |
11288 | { | |
11289 | warn (_("out of memory constructing filename for .debug_sup link\n")); | |
11290 | return; | |
11291 | } | |
e38332c2 NC |
11292 | } |
11293 | ||
bfbfa6e7 | 11294 | void * handle = open_debug_file (filename); |
e38332c2 NC |
11295 | if (handle == NULL) |
11296 | { | |
11297 | warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename); | |
bfbfa6e7 | 11298 | free ((void *) filename); |
e38332c2 NC |
11299 | return; |
11300 | } | |
11301 | ||
11302 | printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename, filename); | |
11303 | ||
11304 | /* FIXME: Compare the checksums, if present. */ | |
11305 | add_separate_debug_file (filename, handle); | |
11306 | } | |
11307 | ||
ce139cd5 NC |
11308 | /* Load a debuglink section and/or a debugaltlink section, if either are present. |
11309 | Recursively check the loaded files for more of these sections. | |
e38332c2 NC |
11310 | Also follow any links in .debug_sup sections. |
11311 | FIXME: Should also check for DWO_* entries in the newly loaded files. */ | |
ce139cd5 NC |
11312 | |
11313 | static void | |
11314 | check_for_and_load_links (void * file, const char * filename) | |
11315 | { | |
11316 | void * handle = NULL; | |
11317 | ||
11318 | if (load_debug_section (gnu_debugaltlink, file)) | |
11319 | { | |
11320 | Build_id_data build_id_data; | |
11321 | ||
11322 | handle = load_separate_debug_info (filename, | |
11323 | & debug_displays[gnu_debugaltlink].section, | |
11324 | parse_gnu_debugaltlink, | |
11325 | check_gnu_debugaltlink, | |
11326 | & build_id_data, | |
11327 | file); | |
11328 | if (handle) | |
11329 | { | |
11330 | assert (handle == first_separate_info->handle); | |
11331 | check_for_and_load_links (first_separate_info->handle, | |
11332 | first_separate_info->filename); | |
11333 | } | |
11334 | } | |
11335 | ||
11336 | if (load_debug_section (gnu_debuglink, file)) | |
11337 | { | |
11338 | unsigned long crc32; | |
11339 | ||
11340 | handle = load_separate_debug_info (filename, | |
11341 | & debug_displays[gnu_debuglink].section, | |
11342 | parse_gnu_debuglink, | |
11343 | check_gnu_debuglink, | |
11344 | & crc32, | |
11345 | file); | |
11346 | if (handle) | |
11347 | { | |
11348 | assert (handle == first_separate_info->handle); | |
11349 | check_for_and_load_links (first_separate_info->handle, | |
11350 | first_separate_info->filename); | |
11351 | } | |
11352 | } | |
e38332c2 NC |
11353 | |
11354 | load_debug_sup_file (filename, file); | |
ce139cd5 NC |
11355 | } |
11356 | ||
24841daa NC |
11357 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
11358 | Returns TRUE if any were found, FALSE otherwise. | |
11359 | If TRUE is returned then the linked list starting at first_separate_info | |
11360 | will be populated with open file handles. */ | |
dda8d76d | 11361 | |
015dc7e1 | 11362 | bool |
24841daa | 11363 | load_separate_debug_files (void * file, const char * filename) |
dda8d76d | 11364 | { |
8de3a6e2 NC |
11365 | /* Skip this operation if we are not interested in debug links. */ |
11366 | if (! do_follow_links && ! do_debug_links) | |
015dc7e1 | 11367 | return false; |
8de3a6e2 | 11368 | |
24841daa | 11369 | /* See if there are any dwo links. */ |
d85bf2ba NC |
11370 | if (load_debug_section (str, file) |
11371 | && load_debug_section (abbrev, file) | |
11372 | && load_debug_section (info, file)) | |
11373 | { | |
24841daa | 11374 | free_dwo_info (); |
d85bf2ba | 11375 | |
50ea0877 | 11376 | if (process_debug_info (& debug_displays[info].section, file, abbrev, |
015dc7e1 | 11377 | true, false)) |
d85bf2ba | 11378 | { |
015dc7e1 AM |
11379 | bool introduced = false; |
11380 | dwo_info *dwinfo; | |
11381 | const char *dir = NULL; | |
11382 | const char *id = NULL; | |
11383 | const char *name = NULL; | |
24841daa NC |
11384 | |
11385 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 11386 | { |
50ea0877 | 11387 | /* Accumulate NAME, DIR and ID fields. */ |
24841daa | 11388 | switch (dwinfo->type) |
d85bf2ba | 11389 | { |
24841daa | 11390 | case DWO_NAME: |
50ea0877 NC |
11391 | if (name != NULL) |
11392 | warn (_("Multiple DWO_NAMEs encountered for the same CU\n")); | |
11393 | name = dwinfo->value; | |
11394 | break; | |
11395 | ||
11396 | case DWO_DIR: | |
11397 | /* There can be multiple DW_AT_comp_dir entries in a CU, | |
11398 | so do not complain. */ | |
11399 | dir = dwinfo->value; | |
11400 | break; | |
11401 | ||
11402 | case DWO_ID: | |
11403 | if (id != NULL) | |
11404 | warn (_("multiple DWO_IDs encountered for the same CU\n")); | |
11405 | id = dwinfo->value; | |
11406 | break; | |
11407 | ||
11408 | default: | |
11409 | error (_("Unexpected DWO INFO type")); | |
11410 | break; | |
11411 | } | |
11412 | ||
11413 | /* If we have reached the end of our list, or we are changing | |
11414 | CUs, then display the information that we have accumulated | |
11415 | so far. */ | |
11416 | if (name != NULL | |
11417 | && (dwinfo->next == NULL | |
11418 | || dwinfo->next->cu_offset != dwinfo->cu_offset)) | |
11419 | { | |
24841daa NC |
11420 | if (do_debug_links) |
11421 | { | |
11422 | if (! introduced) | |
11423 | { | |
11424 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
11425 | debug_displays [info].section.uncompressed_name); | |
015dc7e1 | 11426 | introduced = true; |
24841daa | 11427 | } |
d85bf2ba | 11428 | |
50ea0877 | 11429 | printf (_(" Name: %s\n"), name); |
24841daa NC |
11430 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); |
11431 | if (id != NULL) | |
11432 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
11433 | else | |
50ea0877 | 11434 | printf (_(" ID: <not specified>\n")); |
24841daa NC |
11435 | printf ("\n\n"); |
11436 | } | |
11437 | ||
11438 | if (do_follow_links) | |
50ea0877 | 11439 | load_dwo_file (filename, name, dir, id); |
24841daa | 11440 | |
50ea0877 | 11441 | name = dir = id = NULL; |
24841daa | 11442 | } |
d85bf2ba NC |
11443 | } |
11444 | } | |
11445 | } | |
11446 | ||
dda8d76d | 11447 | if (! do_follow_links) |
8de3a6e2 NC |
11448 | /* The other debug links will be displayed by display_debug_links() |
11449 | so we do not need to do any further processing here. */ | |
015dc7e1 | 11450 | return false; |
dda8d76d NC |
11451 | |
11452 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
dda8d76d | 11453 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
d85bf2ba | 11454 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 11455 | |
ce139cd5 | 11456 | check_for_and_load_links (file, filename); |
24841daa | 11457 | if (first_separate_info != NULL) |
015dc7e1 | 11458 | return true; |
24841daa | 11459 | |
dda8d76d | 11460 | do_follow_links = 0; |
015dc7e1 | 11461 | return false; |
521d4b19 | 11462 | } |
dda8d76d | 11463 | |
19e6b90e L |
11464 | void |
11465 | free_debug_memory (void) | |
11466 | { | |
3f5e193b | 11467 | unsigned int i; |
19e6b90e | 11468 | |
bcd213b2 | 11469 | free_all_abbrevs (); |
19e6b90e | 11470 | |
bcd213b2 NC |
11471 | free (cu_abbrev_map); |
11472 | cu_abbrev_map = NULL; | |
11473 | next_free_abbrev_map_entry = 0; | |
521d4b19 | 11474 | |
288f0ba2 AM |
11475 | free (shndx_pool); |
11476 | shndx_pool = NULL; | |
11477 | shndx_pool_size = 0; | |
11478 | shndx_pool_used = 0; | |
11479 | free (cu_sets); | |
11480 | cu_sets = NULL; | |
11481 | cu_count = 0; | |
11482 | free (tu_sets); | |
11483 | tu_sets = NULL; | |
11484 | tu_count = 0; | |
11485 | ||
11486 | memset (level_type_signed, 0, sizeof level_type_signed); | |
11487 | cu_tu_indexes_read = -1; | |
11488 | ||
19e6b90e | 11489 | for (i = 0; i < max; i++) |
3f5e193b | 11490 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 11491 | |
cc86f28f | 11492 | if (debug_information != NULL) |
19e6b90e | 11493 | { |
82fcdb39 | 11494 | for (i = 0; i < alloc_num_debug_info_entries; i++) |
19e6b90e | 11495 | { |
82fcdb39 | 11496 | if (debug_information [i].max_loc_offsets) |
19e6b90e | 11497 | { |
82fcdb39 AM |
11498 | free (debug_information [i].loc_offsets); |
11499 | free (debug_information [i].have_frame_base); | |
19e6b90e | 11500 | } |
82fcdb39 AM |
11501 | if (debug_information [i].max_range_lists) |
11502 | free (debug_information [i].range_lists); | |
19e6b90e L |
11503 | } |
11504 | free (debug_information); | |
11505 | debug_information = NULL; | |
82b1b41b | 11506 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 11507 | } |
dda8d76d | 11508 | |
24841daa NC |
11509 | separate_info * d; |
11510 | separate_info * next; | |
dda8d76d | 11511 | |
24841daa NC |
11512 | for (d = first_separate_info; d != NULL; d = next) |
11513 | { | |
11514 | close_debug_file (d->handle); | |
11515 | free ((void *) d->filename); | |
11516 | next = d->next; | |
11517 | free ((void *) d); | |
dda8d76d | 11518 | } |
24841daa | 11519 | first_separate_info = NULL; |
521d4b19 | 11520 | |
24841daa | 11521 | free_dwo_info (); |
19e6b90e L |
11522 | } |
11523 | ||
4cb93e3b TG |
11524 | void |
11525 | dwarf_select_sections_by_names (const char *names) | |
11526 | { | |
11527 | typedef struct | |
11528 | { | |
11529 | const char * option; | |
11530 | int * variable; | |
f9f0e732 | 11531 | int val; |
4cb93e3b TG |
11532 | } |
11533 | debug_dump_long_opts; | |
11534 | ||
11535 | static const debug_dump_long_opts opts_table [] = | |
11536 | { | |
11537 | /* Please keep this table alpha- sorted. */ | |
11538 | { "Ranges", & do_debug_ranges, 1 }, | |
11539 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 11540 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 11541 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
11542 | { "cu_index", & do_debug_cu_index, 1 }, |
11543 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 11544 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
11545 | { "frames", & do_debug_frames, 1 }, |
11546 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
11547 | /* The special .gdb_index section. */ |
11548 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
11549 | { "info", & do_debug_info, 1 }, |
11550 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 11551 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
11552 | { "loc", & do_debug_loc, 1 }, |
11553 | { "macro", & do_debug_macinfo, 1 }, | |
c46b7066 | 11554 | { "no-follow-links", & do_follow_links, 0 }, |
4cb93e3b | 11555 | { "pubnames", & do_debug_pubnames, 1 }, |
357da287 | 11556 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 11557 | /* This entry is for compatibility |
4cb93e3b TG |
11558 | with earlier versions of readelf. */ |
11559 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 11560 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 11561 | { "str", & do_debug_str, 1 }, |
e4b7104b | 11562 | { "str-offsets", & do_debug_str_offsets, 1 }, |
6f875884 TG |
11563 | /* These trace_* sections are used by Itanium VMS. */ |
11564 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
11565 | { "trace_aranges", & do_trace_aranges, 1 }, | |
11566 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
11567 | { NULL, NULL, 0 } |
11568 | }; | |
11569 | ||
11570 | const char *p; | |
467c65bc | 11571 | |
4cb93e3b TG |
11572 | p = names; |
11573 | while (*p) | |
11574 | { | |
11575 | const debug_dump_long_opts * entry; | |
467c65bc | 11576 | |
4cb93e3b TG |
11577 | for (entry = opts_table; entry->option; entry++) |
11578 | { | |
11579 | size_t len = strlen (entry->option); | |
467c65bc | 11580 | |
4cb93e3b TG |
11581 | if (strncmp (p, entry->option, len) == 0 |
11582 | && (p[len] == ',' || p[len] == '\0')) | |
11583 | { | |
c46b7066 | 11584 | * entry->variable = entry->val; |
467c65bc | 11585 | |
4cb93e3b TG |
11586 | /* The --debug-dump=frames-interp option also |
11587 | enables the --debug-dump=frames option. */ | |
11588 | if (do_debug_frames_interp) | |
11589 | do_debug_frames = 1; | |
11590 | ||
11591 | p += len; | |
11592 | break; | |
11593 | } | |
11594 | } | |
467c65bc | 11595 | |
4cb93e3b TG |
11596 | if (entry->option == NULL) |
11597 | { | |
11598 | warn (_("Unrecognized debug option '%s'\n"), p); | |
11599 | p = strchr (p, ','); | |
11600 | if (p == NULL) | |
11601 | break; | |
11602 | } | |
467c65bc | 11603 | |
4cb93e3b TG |
11604 | if (*p == ',') |
11605 | p++; | |
11606 | } | |
11607 | } | |
11608 | ||
11609 | void | |
11610 | dwarf_select_sections_by_letters (const char *letters) | |
11611 | { | |
91d6fa6a | 11612 | unsigned int lindex = 0; |
4cb93e3b | 11613 | |
91d6fa6a NC |
11614 | while (letters[lindex]) |
11615 | switch (letters[lindex++]) | |
4cb93e3b | 11616 | { |
dda8d76d NC |
11617 | case 'A': do_debug_addr = 1; break; |
11618 | case 'a': do_debug_abbrevs = 1; break; | |
11619 | case 'c': do_debug_cu_index = 1; break; | |
11620 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
11621 | case 'f': do_debug_frames = 1; break; | |
11622 | case 'g': do_gdb_index = 1; break; | |
11623 | case 'i': do_debug_info = 1; break; | |
11624 | case 'K': do_follow_links = 1; break; | |
c46b7066 | 11625 | case 'N': do_follow_links = 0; break; |
dda8d76d NC |
11626 | case 'k': do_debug_links = 1; break; |
11627 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
11628 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
11629 | case 'm': do_debug_macinfo = 1; break; | |
e4b7104b | 11630 | case 'O': do_debug_str_offsets = 1; break; |
dda8d76d NC |
11631 | case 'o': do_debug_loc = 1; break; |
11632 | case 'p': do_debug_pubnames = 1; break; | |
11633 | case 'R': do_debug_ranges = 1; break; | |
11634 | case 'r': do_debug_aranges = 1; break; | |
11635 | case 's': do_debug_str = 1; break; | |
11636 | case 'T': do_trace_aranges = 1; break; | |
11637 | case 't': do_debug_pubtypes = 1; break; | |
11638 | case 'U': do_trace_info = 1; break; | |
11639 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 11640 | |
4cb93e3b | 11641 | default: |
7cc78d07 | 11642 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
11643 | break; |
11644 | } | |
11645 | } | |
11646 | ||
11647 | void | |
11648 | dwarf_select_sections_all (void) | |
11649 | { | |
11650 | do_debug_info = 1; | |
11651 | do_debug_abbrevs = 1; | |
11652 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
11653 | do_debug_pubnames = 1; | |
f9f0e732 | 11654 | do_debug_pubtypes = 1; |
4cb93e3b TG |
11655 | do_debug_aranges = 1; |
11656 | do_debug_ranges = 1; | |
11657 | do_debug_frames = 1; | |
11658 | do_debug_macinfo = 1; | |
11659 | do_debug_str = 1; | |
11660 | do_debug_loc = 1; | |
5bbdf3d5 | 11661 | do_gdb_index = 1; |
6f875884 TG |
11662 | do_trace_info = 1; |
11663 | do_trace_abbrevs = 1; | |
11664 | do_trace_aranges = 1; | |
657d0d47 CC |
11665 | do_debug_addr = 1; |
11666 | do_debug_cu_index = 1; | |
dda8d76d NC |
11667 | do_follow_links = 1; |
11668 | do_debug_links = 1; | |
e4b7104b | 11669 | do_debug_str_offsets = 1; |
4cb93e3b TG |
11670 | } |
11671 | ||
208599d9 AM |
11672 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0 |
11673 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0 | |
dda8d76d NC |
11674 | |
11675 | /* N.B. The order here must match the order in section_display_enum. */ | |
11676 | ||
19e6b90e L |
11677 | struct dwarf_section_display debug_displays[] = |
11678 | { | |
015dc7e1 AM |
11679 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, |
11680 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, true }, | |
11681 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, | |
11682 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, true }, | |
11683 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, | |
11684 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, false }, | |
11685 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, false }, | |
11686 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, | |
11687 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, | |
11688 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, | |
11689 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
11690 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
11691 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
11692 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
11693 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, false }, | |
11694 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, false }, | |
11695 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
11696 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
11697 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
11698 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
11699 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, true }, | |
11700 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
11701 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, false }, | |
11702 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, false }, | |
11703 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, true }, | |
11704 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, false }, | |
11705 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, false }, | |
11706 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, true }, | |
11707 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, | |
11708 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, true }, | |
11709 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, | |
11710 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
11711 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, | |
11712 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, | |
11713 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, true }, | |
11714 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, | |
11715 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, | |
11716 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, true }, | |
11717 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, | |
11718 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, | |
11719 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, | |
11720 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, | |
11721 | { { ".debug_sup", "", NO_ABBREVS }, display_debug_sup, &do_debug_links, false }, | |
dda8d76d NC |
11722 | /* Separate debug info files can containt their own .debug_str section, |
11723 | and this might be in *addition* to a .debug_str section already present | |
11724 | in the main file. Hence we need to have two entries for .debug_str. */ | |
015dc7e1 | 11725 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, |
19e6b90e | 11726 | }; |
b451e98a JK |
11727 | |
11728 | /* A static assertion. */ | |
11729 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |