Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
82704155 | 2 | Copyright (C) 2005-2019 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" |
5bbdf3d5 | 24 | #include "bfd_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" |
61364358 JK |
32 | #include <assert.h> |
33 | ||
34 | #undef MAX | |
35 | #undef MIN | |
36 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
37 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
19e6b90e | 38 | |
18464d4d JK |
39 | static const char *regname (unsigned int regno, int row); |
40 | ||
19e6b90e L |
41 | static int have_frame_base; |
42 | static int need_base_address; | |
43 | ||
19e6b90e | 44 | static unsigned int num_debug_info_entries = 0; |
82b1b41b | 45 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 46 | static debug_info *debug_information = NULL; |
cc86f28f NC |
47 | /* Special value for num_debug_info_entries to indicate |
48 | that the .debug_info section could not be loaded/parsed. */ | |
49 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 50 | |
d85bf2ba NC |
51 | static const char * dwo_name; |
52 | static const char * dwo_dir; | |
53 | static const unsigned char * dwo_id; | |
54 | static bfd_size_type dwo_id_len; | |
55 | static bfd_boolean need_dwo_info; | |
56 | ||
77ef8654 | 57 | unsigned int eh_addr_size; |
19e6b90e L |
58 | |
59 | int do_debug_info; | |
60 | int do_debug_abbrevs; | |
61 | int do_debug_lines; | |
62 | int do_debug_pubnames; | |
f9f0e732 | 63 | int do_debug_pubtypes; |
19e6b90e L |
64 | int do_debug_aranges; |
65 | int do_debug_ranges; | |
66 | int do_debug_frames; | |
67 | int do_debug_frames_interp; | |
68 | int do_debug_macinfo; | |
69 | int do_debug_str; | |
70 | int do_debug_loc; | |
5bbdf3d5 | 71 | int do_gdb_index; |
6f875884 TG |
72 | int do_trace_info; |
73 | int do_trace_abbrevs; | |
74 | int do_trace_aranges; | |
657d0d47 CC |
75 | int do_debug_addr; |
76 | int do_debug_cu_index; | |
a262ae96 | 77 | int do_wide; |
dda8d76d NC |
78 | int do_debug_links; |
79 | int do_follow_links; | |
19e6b90e | 80 | |
fd2f0033 TT |
81 | int dwarf_cutoff_level = -1; |
82 | unsigned long dwarf_start_die; | |
83 | ||
4723351a CC |
84 | int dwarf_check = 0; |
85 | ||
9f272209 AO |
86 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
87 | testing whether e.g. a locview list is present. */ | |
88 | static const dwarf_vma vm1 = -1; | |
89 | ||
341f9135 CC |
90 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
91 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
92 | as a zero-terminated list of section indexes comprising one set of debug | |
93 | sections from a .dwo file. */ | |
94 | ||
341f9135 CC |
95 | static unsigned int *shndx_pool = NULL; |
96 | static unsigned int shndx_pool_size = 0; | |
97 | static unsigned int shndx_pool_used = 0; | |
98 | ||
dda8d76d NC |
99 | /* Pointer to a separate file containing extra debug information. */ |
100 | static void * separate_debug_file = NULL; | |
101 | static const char * separate_debug_filename = NULL; | |
102 | ||
341f9135 CC |
103 | /* For version 2 package files, each set contains an array of section offsets |
104 | and an array of section sizes, giving the offset and size of the | |
105 | contribution from a CU or TU within one of the debug sections. | |
106 | When displaying debug info from a package file, we need to use these | |
107 | tables to locate the corresponding contributions to each section. */ | |
108 | ||
109 | struct cu_tu_set | |
110 | { | |
111 | uint64_t signature; | |
112 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
113 | size_t section_sizes[DW_SECT_MAX]; | |
114 | }; | |
115 | ||
116 | static int cu_count = 0; | |
117 | static int tu_count = 0; | |
118 | static struct cu_tu_set *cu_sets = NULL; | |
119 | static struct cu_tu_set *tu_sets = NULL; | |
120 | ||
43a444f9 | 121 | static bfd_boolean load_cu_tu_indexes (void *); |
341f9135 | 122 | |
4cb93e3b TG |
123 | /* Values for do_debug_lines. */ |
124 | #define FLAG_DEBUG_LINES_RAW 1 | |
125 | #define FLAG_DEBUG_LINES_DECODED 2 | |
126 | ||
77ef8654 | 127 | static unsigned int |
f1c4cc75 RH |
128 | size_of_encoded_value (int encoding) |
129 | { | |
130 | switch (encoding & 0x7) | |
131 | { | |
132 | default: /* ??? */ | |
133 | case 0: return eh_addr_size; | |
134 | case 2: return 2; | |
135 | case 3: return 4; | |
136 | case 4: return 8; | |
137 | } | |
138 | } | |
139 | ||
140 | static dwarf_vma | |
041830e0 | 141 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 142 | int encoding, |
041830e0 NC |
143 | struct dwarf_section *section, |
144 | unsigned char * end) | |
f1c4cc75 | 145 | { |
041830e0 | 146 | unsigned char * data = * pdata; |
6937bb54 | 147 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 148 | dwarf_vma val; |
f1c4cc75 | 149 | |
041830e0 NC |
150 | if (data + size >= end) |
151 | { | |
152 | warn (_("Encoded value extends past end of section\n")); | |
153 | * pdata = end; | |
154 | return 0; | |
155 | } | |
156 | ||
6937bb54 NC |
157 | /* PR 17512: file: 002-829853-0.004. */ |
158 | if (size > 8) | |
159 | { | |
160 | warn (_("Encoded size of %d is too large to read\n"), size); | |
161 | * pdata = end; | |
162 | return 0; | |
163 | } | |
164 | ||
0a9d414a NC |
165 | /* PR 17512: file: 1085-5603-0.004. */ |
166 | if (size == 0) | |
167 | { | |
168 | warn (_("Encoded size of 0 is too small to read\n")); | |
169 | * pdata = end; | |
170 | return 0; | |
171 | } | |
172 | ||
f1c4cc75 | 173 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 174 | val = byte_get_signed (data, size); |
f1c4cc75 | 175 | else |
bad62cf5 AM |
176 | val = byte_get (data, size); |
177 | ||
178 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
179 | val += section->address + (data - section->start); | |
041830e0 NC |
180 | |
181 | * pdata = data + size; | |
bad62cf5 | 182 | return val; |
f1c4cc75 RH |
183 | } |
184 | ||
4c219c2e AM |
185 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
186 | # ifndef __MINGW32__ | |
187 | # define DWARF_VMA_FMT "ll" | |
188 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
189 | # else | |
190 | # define DWARF_VMA_FMT "I64" | |
191 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
192 | # endif | |
2e14fae2 | 193 | #else |
4c219c2e AM |
194 | # define DWARF_VMA_FMT "l" |
195 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
196 | #endif |
197 | ||
bf5117e3 NC |
198 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
199 | buffer containing the converted VALUE. The value is converted according | |
200 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
201 | it specifies the maximum number of bytes to be displayed in the converted | |
202 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 203 | |
47704ddf | 204 | static const char * |
bf5117e3 | 205 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
206 | { |
207 | /* As dwarf_vmatoa is used more then once in a printf call | |
208 | for output, we are cycling through an fixed array of pointers | |
209 | for return address. */ | |
210 | static int buf_pos = 0; | |
467c65bc NC |
211 | static struct dwarf_vmatoa_buf |
212 | { | |
47704ddf KT |
213 | char place[64]; |
214 | } buf[16]; | |
47704ddf KT |
215 | char *ret; |
216 | ||
47704ddf | 217 | ret = buf[buf_pos++].place; |
467c65bc | 218 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 219 | |
bf5117e3 NC |
220 | if (num_bytes) |
221 | { | |
222c2bf0 | 222 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
223 | integer value, so we print the full value into a buffer and then select |
224 | the precision we need. */ | |
225 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
226 | if (num_bytes > 8) | |
227 | num_bytes = 8; | |
228 | return ret + (16 - 2 * num_bytes); | |
229 | } | |
230 | else | |
231 | { | |
232 | char fmt[32]; | |
233 | ||
0bae9e9e NC |
234 | if (fmtch) |
235 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
236 | else | |
237 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
238 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
239 | return ret; | |
240 | } | |
241 | } | |
47704ddf | 242 | |
bf5117e3 NC |
243 | static inline const char * |
244 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
245 | { | |
246 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
247 | } | |
248 | ||
249 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
250 | hexadecimal format, followed by a space. The length of the VALUE (and | |
251 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
252 | ||
253 | static void | |
254 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
255 | { | |
256 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
257 | } |
258 | ||
9f272209 AO |
259 | /* Print a view number in hexadecimal value, with the same width |
260 | print_dwarf_vma would have printed it with the same num_bytes. | |
261 | Print blanks for zero view, unless force is nonzero. */ | |
262 | ||
263 | static void | |
264 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
265 | { | |
266 | int len; | |
267 | if (!num_bytes) | |
268 | len = 4; | |
269 | else | |
270 | len = num_bytes * 2; | |
271 | ||
272 | assert (value == (unsigned long) value); | |
273 | if (value || force) | |
274 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
275 | else | |
276 | printf ("%*s", len + 1, ""); | |
277 | } | |
278 | ||
74bc6052 CC |
279 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
280 | For reentrancy, this uses a buffer provided by the caller. */ | |
281 | ||
282 | static const char * | |
283 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
284 | unsigned int buf_len) | |
285 | { | |
286 | int len = 0; | |
287 | ||
288 | if (hvalue == 0) | |
289 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
290 | else | |
291 | { | |
292 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
293 | snprintf (buf + len, buf_len - len, | |
294 | "%08" DWARF_VMA_FMT "x", lvalue); | |
295 | } | |
296 | ||
297 | return buf; | |
298 | } | |
299 | ||
f6f0e17b NC |
300 | /* Read in a LEB128 encoded value starting at address DATA. |
301 | If SIGN is true, return a signed LEB128 value. | |
302 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
303 | No bytes will be read at address END or beyond. */ | |
304 | ||
467c65bc | 305 | dwarf_vma |
f6f0e17b NC |
306 | read_leb128 (unsigned char *data, |
307 | unsigned int *length_return, | |
308 | bfd_boolean sign, | |
309 | const unsigned char * const end) | |
19e6b90e | 310 | { |
467c65bc | 311 | dwarf_vma result = 0; |
19e6b90e L |
312 | unsigned int num_read = 0; |
313 | unsigned int shift = 0; | |
f6f0e17b | 314 | unsigned char byte = 0; |
19e6b90e | 315 | |
f6f0e17b | 316 | while (data < end) |
19e6b90e L |
317 | { |
318 | byte = *data++; | |
319 | num_read++; | |
320 | ||
467c65bc | 321 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
19e6b90e L |
322 | |
323 | shift += 7; | |
f6f0e17b NC |
324 | if ((byte & 0x80) == 0) |
325 | break; | |
77ef8654 NC |
326 | |
327 | /* PR 17512: file: 0ca183b8. | |
328 | FIXME: Should we signal this error somehow ? */ | |
f641dd96 | 329 | if (shift >= sizeof (result) * 8) |
77ef8654 | 330 | break; |
19e6b90e | 331 | } |
19e6b90e L |
332 | |
333 | if (length_return != NULL) | |
334 | *length_return = num_read; | |
335 | ||
336 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
c4e0beac | 337 | result |= -((dwarf_vma) 1 << shift); |
19e6b90e L |
338 | |
339 | return result; | |
340 | } | |
341 | ||
467c65bc | 342 | /* Create a signed version to avoid painful typecasts. */ |
f6f0e17b NC |
343 | static inline dwarf_signed_vma |
344 | read_sleb128 (unsigned char * data, | |
345 | unsigned int * length_return, | |
346 | const unsigned char * const end) | |
347 | { | |
348 | return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end); | |
349 | } | |
350 | ||
351 | static inline dwarf_vma | |
352 | read_uleb128 (unsigned char * data, | |
353 | unsigned int * length_return, | |
354 | const unsigned char * const end) | |
467c65bc | 355 | { |
f6f0e17b | 356 | return read_leb128 (data, length_return, FALSE, end); |
467c65bc NC |
357 | } |
358 | ||
7f2c8a1d NC |
359 | #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return |
360 | #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return | |
361 | ||
362 | #define READ_ULEB(var) \ | |
363 | do \ | |
364 | { \ | |
365 | dwarf_vma _val; \ | |
366 | \ | |
367 | (var) = _val = read_uleb128 (start, &length_return, end); \ | |
368 | if ((var) != _val) \ | |
66cfc0fd AM |
369 | error (_("Internal error: %s:%d: LEB value (%s) " \ |
370 | "too large for containing variable\n"), \ | |
371 | __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \ | |
7f2c8a1d NC |
372 | start += length_return; \ |
373 | } \ | |
374 | while (0) | |
375 | ||
376 | #define READ_SLEB(var) \ | |
377 | do \ | |
378 | { \ | |
379 | dwarf_signed_vma _val; \ | |
380 | \ | |
381 | (var) = _val = read_sleb128 (start, &length_return, end); \ | |
382 | if ((var) != _val) \ | |
66cfc0fd AM |
383 | error (_("Internal error: %s:%d: LEB value (%s) " \ |
384 | "too large for containing variable\n"), \ | |
385 | __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \ | |
7f2c8a1d NC |
386 | start += length_return; \ |
387 | } \ | |
388 | while (0) | |
389 | ||
d11ae95e NC |
390 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
391 | Checks to make sure that the read will not reach or pass END | |
392 | and that VAL is big enough to hold AMOUNT bytes. */ | |
0c588247 NC |
393 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
394 | do \ | |
395 | { \ | |
396 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
397 | if (sizeof (VAL) < amount) \ |
398 | { \ | |
d3a49aa8 AM |
399 | error (ngettext ("internal error: attempt to read %d byte " \ |
400 | "of data in to %d sized variable", \ | |
401 | "internal error: attempt to read %d bytes " \ | |
402 | "of data in to %d sized variable", \ | |
403 | amount), \ | |
34b9f729 NC |
404 | amount, (int) sizeof (VAL)); \ |
405 | amount = sizeof (VAL); \ | |
406 | } \ | |
0c588247 NC |
407 | if (((PTR) + amount) >= (END)) \ |
408 | { \ | |
409 | if ((PTR) < (END)) \ | |
410 | amount = (END) - (PTR); \ | |
411 | else \ | |
412 | amount = 0; \ | |
413 | } \ | |
6937bb54 | 414 | if (amount == 0 || amount > 8) \ |
0c588247 | 415 | VAL = 0; \ |
6937bb54 NC |
416 | else \ |
417 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
418 | } \ |
419 | while (0) | |
420 | ||
d11ae95e | 421 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
422 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
423 | do \ | |
424 | { \ | |
425 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
426 | PTR += AMOUNT; \ | |
427 | } \ | |
428 | while (0) | |
429 | ||
d11ae95e | 430 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
0c588247 NC |
431 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
432 | do \ | |
433 | { \ | |
434 | unsigned int amount = (AMOUNT); \ | |
435 | if (((PTR) + amount) >= (END)) \ | |
436 | { \ | |
437 | if ((PTR) < (END)) \ | |
438 | amount = (END) - (PTR); \ | |
439 | else \ | |
440 | amount = 0; \ | |
441 | } \ | |
442 | if (amount) \ | |
443 | VAL = byte_get_signed ((PTR), amount); \ | |
444 | else \ | |
445 | VAL = 0; \ | |
446 | } \ | |
447 | while (0) | |
448 | ||
d11ae95e | 449 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
450 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
451 | do \ | |
452 | { \ | |
453 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
454 | PTR += AMOUNT; \ | |
455 | } \ | |
456 | while (0) | |
457 | ||
458 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
459 | do \ | |
460 | { \ | |
87bc83b3 | 461 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
462 | { \ |
463 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
464 | } \ | |
465 | else \ | |
466 | { \ | |
0c588247 NC |
467 | * (LOW) = * (HIGH) = 0; \ |
468 | } \ | |
469 | } \ | |
470 | while (0) | |
471 | ||
19e6b90e L |
472 | typedef struct State_Machine_Registers |
473 | { | |
467c65bc | 474 | dwarf_vma address; |
ba8826a8 | 475 | unsigned int view; |
19e6b90e L |
476 | unsigned int file; |
477 | unsigned int line; | |
478 | unsigned int column; | |
479 | int is_stmt; | |
480 | int basic_block; | |
a233b20c JJ |
481 | unsigned char op_index; |
482 | unsigned char end_sequence; | |
ba8826a8 AO |
483 | /* This variable hold the number of the last entry seen |
484 | in the File Table. */ | |
19e6b90e L |
485 | unsigned int last_file_entry; |
486 | } SMR; | |
487 | ||
488 | static SMR state_machine_regs; | |
489 | ||
490 | static void | |
491 | reset_state_machine (int is_stmt) | |
492 | { | |
493 | state_machine_regs.address = 0; | |
ba8826a8 | 494 | state_machine_regs.view = 0; |
a233b20c | 495 | state_machine_regs.op_index = 0; |
19e6b90e L |
496 | state_machine_regs.file = 1; |
497 | state_machine_regs.line = 1; | |
498 | state_machine_regs.column = 0; | |
499 | state_machine_regs.is_stmt = is_stmt; | |
500 | state_machine_regs.basic_block = 0; | |
501 | state_machine_regs.end_sequence = 0; | |
502 | state_machine_regs.last_file_entry = 0; | |
503 | } | |
504 | ||
505 | /* Handled an extend line op. | |
506 | Returns the number of bytes read. */ | |
507 | ||
508 | static int | |
f6f0e17b NC |
509 | process_extended_line_op (unsigned char * data, |
510 | int is_stmt, | |
511 | unsigned char * end) | |
19e6b90e L |
512 | { |
513 | unsigned char op_code; | |
514 | unsigned int bytes_read; | |
515 | unsigned int len; | |
516 | unsigned char *name; | |
143a3db0 | 517 | unsigned char *orig_data = data; |
f6f0e17b | 518 | dwarf_vma adr; |
19e6b90e | 519 | |
f6f0e17b | 520 | len = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
521 | data += bytes_read; |
522 | ||
e44c58ce | 523 | if (len == 0 || data == end || len > (uintptr_t) (end - data)) |
19e6b90e | 524 | { |
f41e4712 | 525 | warn (_("Badly formed extended line op encountered!\n")); |
19e6b90e L |
526 | return bytes_read; |
527 | } | |
528 | ||
529 | len += bytes_read; | |
530 | op_code = *data++; | |
531 | ||
532 | printf (_(" Extended opcode %d: "), op_code); | |
533 | ||
534 | switch (op_code) | |
535 | { | |
536 | case DW_LNE_end_sequence: | |
537 | printf (_("End of Sequence\n\n")); | |
538 | reset_state_machine (is_stmt); | |
539 | break; | |
540 | ||
541 | case DW_LNE_set_address: | |
6937bb54 NC |
542 | /* PR 17512: file: 002-100480-0.004. */ |
543 | if (len - bytes_read - 1 > 8) | |
77ef8654 NC |
544 | { |
545 | warn (_("Length (%d) of DW_LNE_set_address op is too long\n"), | |
546 | len - bytes_read - 1); | |
547 | adr = 0; | |
548 | } | |
549 | else | |
550 | SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end); | |
47704ddf | 551 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 552 | state_machine_regs.address = adr; |
ba8826a8 | 553 | state_machine_regs.view = 0; |
a233b20c | 554 | state_machine_regs.op_index = 0; |
19e6b90e L |
555 | break; |
556 | ||
557 | case DW_LNE_define_file: | |
143a3db0 | 558 | printf (_("define new File Table entry\n")); |
19e6b90e | 559 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 560 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 561 | |
d949ff56 NC |
562 | { |
563 | size_t l; | |
564 | ||
565 | name = data; | |
566 | l = strnlen ((char *) data, end - data); | |
567 | data += len + 1; | |
568 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
569 | data += bytes_read; | |
570 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
571 | data += bytes_read; | |
572 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
573 | data += bytes_read; | |
574 | printf ("%.*s\n\n", (int) l, name); | |
575 | } | |
f6f0e17b NC |
576 | |
577 | if (((unsigned int) (data - orig_data) != len) || data == end) | |
b4eb7656 | 578 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
579 | break; |
580 | ||
ed4a4bdf | 581 | case DW_LNE_set_discriminator: |
47704ddf | 582 | printf (_("set Discriminator to %s\n"), |
f6f0e17b | 583 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
ed4a4bdf CC |
584 | break; |
585 | ||
e2a0d921 NC |
586 | /* HP extensions. */ |
587 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 588 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
589 | break; |
590 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 591 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
592 | break; |
593 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 594 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
595 | break; |
596 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 597 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
598 | break; |
599 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 600 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
601 | break; |
602 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 603 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
604 | break; |
605 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 606 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
607 | break; |
608 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 609 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
610 | break; |
611 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 612 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
613 | break; |
614 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 615 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 616 | break; |
43294ab7 TG |
617 | case DW_LNE_HP_source_file_correlation: |
618 | { | |
b4eb7656 AM |
619 | unsigned char *edata = data + len - bytes_read - 1; |
620 | ||
621 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
622 | ||
623 | while (data < edata) | |
624 | { | |
625 | unsigned int opc; | |
626 | ||
627 | opc = read_uleb128 (data, & bytes_read, edata); | |
628 | data += bytes_read; | |
629 | ||
630 | switch (opc) | |
631 | { | |
632 | case DW_LNE_HP_SFC_formfeed: | |
633 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
634 | break; | |
635 | case DW_LNE_HP_SFC_set_listing_line: | |
636 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", | |
637 | dwarf_vmatoa ("u", | |
638 | read_uleb128 (data, & bytes_read, edata))); | |
639 | data += bytes_read; | |
640 | break; | |
641 | case DW_LNE_HP_SFC_associate: | |
642 | printf (" DW_LNE_HP_SFC_associate "); | |
643 | printf ("(%s", | |
644 | dwarf_vmatoa ("u", | |
645 | read_uleb128 (data, & bytes_read, edata))); | |
646 | data += bytes_read; | |
647 | printf (",%s", | |
648 | dwarf_vmatoa ("u", | |
649 | read_uleb128 (data, & bytes_read, edata))); | |
650 | data += bytes_read; | |
651 | printf (",%s)\n", | |
652 | dwarf_vmatoa ("u", | |
653 | read_uleb128 (data, & bytes_read, edata))); | |
654 | data += bytes_read; | |
655 | break; | |
656 | default: | |
657 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
658 | data = edata; | |
659 | break; | |
660 | } | |
661 | } | |
43294ab7 TG |
662 | } |
663 | break; | |
cecf136e | 664 | |
19e6b90e | 665 | default: |
7e665af3 | 666 | { |
b4eb7656 AM |
667 | unsigned int rlen = len - bytes_read - 1; |
668 | ||
669 | if (op_code >= DW_LNE_lo_user | |
670 | /* The test against DW_LNW_hi_user is redundant due to | |
671 | the limited range of the unsigned char data type used | |
672 | for op_code. */ | |
673 | /*&& op_code <= DW_LNE_hi_user*/) | |
674 | printf (_("user defined: ")); | |
675 | else | |
676 | printf (_("UNKNOWN: ")); | |
677 | printf (_("length %d ["), rlen); | |
678 | for (; rlen; rlen--) | |
679 | printf (" %02x", *data++); | |
680 | printf ("]\n"); | |
7e665af3 | 681 | } |
19e6b90e L |
682 | break; |
683 | } | |
684 | ||
685 | return len; | |
686 | } | |
687 | ||
0c588247 | 688 | static const unsigned char * |
467c65bc | 689 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
690 | { |
691 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 692 | const unsigned char * ret; |
19e6b90e L |
693 | |
694 | if (section->start == NULL) | |
0c588247 | 695 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 696 | |
d949ff56 | 697 | if (offset >= section->size) |
19e6b90e | 698 | { |
467c65bc NC |
699 | warn (_("DW_FORM_strp offset too big: %s\n"), |
700 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 701 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
702 | } |
703 | ||
d949ff56 NC |
704 | ret = section->start + offset; |
705 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
706 | NUL byte. Since our caller is expecting to receive a well formed C | |
707 | string we test for the lack of a terminating byte here. */ | |
708 | if (strnlen ((const char *) ret, section->size - offset) | |
709 | == section->size - offset) | |
710 | ret = (const unsigned char *) | |
711 | _("<no NUL byte at end of .debug_str section>"); | |
712 | ||
713 | return ret; | |
19e6b90e L |
714 | } |
715 | ||
77145576 JK |
716 | static const unsigned char * |
717 | fetch_indirect_line_string (dwarf_vma offset) | |
718 | { | |
719 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 720 | const unsigned char * ret; |
77145576 JK |
721 | |
722 | if (section->start == NULL) | |
723 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
724 | ||
d949ff56 | 725 | if (offset >= section->size) |
77145576 JK |
726 | { |
727 | warn (_("DW_FORM_line_strp offset too big: %s\n"), | |
728 | dwarf_vmatoa ("x", offset)); | |
729 | return (const unsigned char *) _("<offset is too big>"); | |
730 | } | |
731 | ||
d949ff56 NC |
732 | ret = section->start + offset; |
733 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
734 | with a NUL byte. Since our caller is expecting to receive a well formed | |
735 | C string we test for the lack of a terminating byte here. */ | |
736 | if (strnlen ((const char *) ret, section->size - offset) | |
737 | == section->size - offset) | |
738 | ret = (const unsigned char *) | |
739 | _("<no NUL byte at end of .debug_line_str section>"); | |
740 | ||
741 | return ret; | |
77145576 JK |
742 | } |
743 | ||
4723351a | 744 | static const char * |
341f9135 | 745 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
d85bf2ba | 746 | dwarf_vma offset_size, bfd_boolean dwo) |
4723351a CC |
747 | { |
748 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
749 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
750 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
751 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
752 | dwarf_vma index_offset = idx * offset_size; | |
753 | dwarf_vma str_offset; | |
d949ff56 | 754 | const char * ret; |
4723351a CC |
755 | |
756 | if (index_section->start == NULL) | |
757 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
758 | : _("<no .debug_str_offsets section>")); | |
759 | ||
341f9135 CC |
760 | if (this_set != NULL) |
761 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
d949ff56 | 762 | if (index_offset >= index_section->size) |
4723351a CC |
763 | { |
764 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), | |
765 | dwarf_vmatoa ("x", index_offset)); | |
766 | return _("<index offset is too big>"); | |
767 | } | |
768 | ||
769 | if (str_section->start == NULL) | |
770 | return (dwo ? _("<no .debug_str.dwo section>") | |
771 | : _("<no .debug_str section>")); | |
772 | ||
773 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
774 | str_offset -= str_section->address; | |
d949ff56 | 775 | if (str_offset >= str_section->size) |
4723351a CC |
776 | { |
777 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
778 | dwarf_vmatoa ("x", str_offset)); | |
779 | return _("<indirect index offset is too big>"); | |
780 | } | |
781 | ||
d949ff56 NC |
782 | ret = (const char *) str_section->start + str_offset; |
783 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
784 | Since our caller is expecting to receive a well formed C string we test | |
785 | for the lack of a terminating byte here. */ | |
786 | if (strnlen (ret, str_section->size - str_offset) | |
787 | == str_section->size - str_offset) | |
788 | ret = (const char *) _("<no NUL byte at end of section>"); | |
789 | ||
790 | return ret; | |
4723351a CC |
791 | } |
792 | ||
793 | static const char * | |
794 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
795 | { | |
796 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
797 | ||
798 | if (section->start == NULL) | |
799 | return (_("<no .debug_addr section>")); | |
800 | ||
801 | if (offset + bytes > section->size) | |
802 | { | |
803 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 804 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
805 | return "<offset too big>"; |
806 | } | |
807 | ||
808 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
809 | } | |
810 | ||
811 | ||
19e6b90e L |
812 | /* FIXME: There are better and more efficient ways to handle |
813 | these structures. For now though, I just want something that | |
814 | is simple to implement. */ | |
815 | typedef struct abbrev_attr | |
816 | { | |
817 | unsigned long attribute; | |
818 | unsigned long form; | |
77145576 | 819 | bfd_signed_vma implicit_const; |
19e6b90e L |
820 | struct abbrev_attr *next; |
821 | } | |
822 | abbrev_attr; | |
823 | ||
824 | typedef struct abbrev_entry | |
825 | { | |
826 | unsigned long entry; | |
827 | unsigned long tag; | |
828 | int children; | |
829 | struct abbrev_attr *first_attr; | |
830 | struct abbrev_attr *last_attr; | |
831 | struct abbrev_entry *next; | |
832 | } | |
833 | abbrev_entry; | |
834 | ||
835 | static abbrev_entry *first_abbrev = NULL; | |
836 | static abbrev_entry *last_abbrev = NULL; | |
837 | ||
838 | static void | |
839 | free_abbrevs (void) | |
840 | { | |
91d6fa6a | 841 | abbrev_entry *abbrv; |
19e6b90e | 842 | |
91d6fa6a | 843 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 844 | { |
91d6fa6a | 845 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
846 | abbrev_attr *attr; |
847 | ||
91d6fa6a | 848 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 849 | { |
91d6fa6a | 850 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
851 | |
852 | free (attr); | |
91d6fa6a | 853 | attr = next_attr; |
19e6b90e L |
854 | } |
855 | ||
91d6fa6a NC |
856 | free (abbrv); |
857 | abbrv = next_abbrev; | |
19e6b90e L |
858 | } |
859 | ||
860 | last_abbrev = first_abbrev = NULL; | |
861 | } | |
862 | ||
863 | static void | |
864 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
865 | { | |
866 | abbrev_entry *entry; | |
867 | ||
3f5e193b | 868 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
869 | if (entry == NULL) |
870 | /* ugg */ | |
871 | return; | |
872 | ||
873 | entry->entry = number; | |
874 | entry->tag = tag; | |
875 | entry->children = children; | |
876 | entry->first_attr = NULL; | |
877 | entry->last_attr = NULL; | |
878 | entry->next = NULL; | |
879 | ||
880 | if (first_abbrev == NULL) | |
881 | first_abbrev = entry; | |
882 | else | |
883 | last_abbrev->next = entry; | |
884 | ||
885 | last_abbrev = entry; | |
886 | } | |
887 | ||
888 | static void | |
77145576 JK |
889 | add_abbrev_attr (unsigned long attribute, unsigned long form, |
890 | bfd_signed_vma implicit_const) | |
19e6b90e L |
891 | { |
892 | abbrev_attr *attr; | |
893 | ||
3f5e193b | 894 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
895 | if (attr == NULL) |
896 | /* ugg */ | |
897 | return; | |
898 | ||
899 | attr->attribute = attribute; | |
900 | attr->form = form; | |
77145576 | 901 | attr->implicit_const = implicit_const; |
19e6b90e L |
902 | attr->next = NULL; |
903 | ||
904 | if (last_abbrev->first_attr == NULL) | |
905 | last_abbrev->first_attr = attr; | |
906 | else | |
907 | last_abbrev->last_attr->next = attr; | |
908 | ||
909 | last_abbrev->last_attr = attr; | |
910 | } | |
911 | ||
912 | /* Processes the (partial) contents of a .debug_abbrev section. | |
913 | Returns NULL if the end of the section was encountered. | |
914 | Returns the address after the last byte read if the end of | |
915 | an abbreviation set was found. */ | |
916 | ||
917 | static unsigned char * | |
918 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
919 | { | |
920 | if (first_abbrev != NULL) | |
921 | return NULL; | |
922 | ||
923 | while (start < end) | |
924 | { | |
925 | unsigned int bytes_read; | |
926 | unsigned long entry; | |
927 | unsigned long tag; | |
928 | unsigned long attribute; | |
929 | int children; | |
930 | ||
f6f0e17b | 931 | entry = read_uleb128 (start, & bytes_read, end); |
19e6b90e L |
932 | start += bytes_read; |
933 | ||
934 | /* A single zero is supposed to end the section according | |
935 | to the standard. If there's more, then signal that to | |
936 | the caller. */ | |
f6f0e17b NC |
937 | if (start == end) |
938 | return NULL; | |
19e6b90e | 939 | if (entry == 0) |
f6f0e17b | 940 | return start; |
19e6b90e | 941 | |
f6f0e17b | 942 | tag = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 943 | start += bytes_read; |
f6f0e17b NC |
944 | if (start == end) |
945 | return NULL; | |
19e6b90e L |
946 | |
947 | children = *start++; | |
948 | ||
949 | add_abbrev (entry, tag, children); | |
950 | ||
951 | do | |
952 | { | |
953 | unsigned long form; | |
77145576 JK |
954 | /* Initialize it due to a false compiler warning. */ |
955 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 956 | |
f6f0e17b | 957 | attribute = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 958 | start += bytes_read; |
f6f0e17b NC |
959 | if (start == end) |
960 | break; | |
19e6b90e | 961 | |
f6f0e17b | 962 | form = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 963 | start += bytes_read; |
f6f0e17b NC |
964 | if (start == end) |
965 | break; | |
19e6b90e | 966 | |
77145576 JK |
967 | if (form == DW_FORM_implicit_const) |
968 | { | |
969 | implicit_const = read_sleb128 (start, & bytes_read, end); | |
970 | start += bytes_read; | |
971 | if (start == end) | |
972 | break; | |
973 | } | |
974 | ||
975 | add_abbrev_attr (attribute, form, implicit_const); | |
19e6b90e L |
976 | } |
977 | while (attribute != 0); | |
978 | } | |
979 | ||
399c99f7 L |
980 | /* Report the missing single zero which ends the section. */ |
981 | error (_(".debug_abbrev section not zero terminated\n")); | |
982 | ||
19e6b90e L |
983 | return NULL; |
984 | } | |
985 | ||
a19c41a7 | 986 | static const char * |
19e6b90e L |
987 | get_TAG_name (unsigned long tag) |
988 | { | |
04914e37 | 989 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
990 | |
991 | if (name == NULL) | |
19e6b90e | 992 | { |
a19c41a7 | 993 | static char buffer[100]; |
19e6b90e | 994 | |
04914e37 NC |
995 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
996 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
997 | else | |
998 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 999 | return buffer; |
19e6b90e | 1000 | } |
a19c41a7 TT |
1001 | |
1002 | return name; | |
19e6b90e L |
1003 | } |
1004 | ||
a19c41a7 | 1005 | static const char * |
19e6b90e L |
1006 | get_FORM_name (unsigned long form) |
1007 | { | |
399c99f7 | 1008 | const char *name; |
bf5117e3 | 1009 | |
399c99f7 L |
1010 | if (form == 0) |
1011 | return "DW_FORM value: 0"; | |
a19c41a7 | 1012 | |
399c99f7 | 1013 | name = get_DW_FORM_name (form); |
a19c41a7 | 1014 | if (name == NULL) |
19e6b90e | 1015 | { |
a19c41a7 | 1016 | static char buffer[100]; |
19e6b90e | 1017 | |
a19c41a7 TT |
1018 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1019 | return buffer; | |
19e6b90e | 1020 | } |
a19c41a7 TT |
1021 | |
1022 | return name; | |
19e6b90e L |
1023 | } |
1024 | ||
61364358 JK |
1025 | static const char * |
1026 | get_IDX_name (unsigned long idx) | |
1027 | { | |
1028 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1029 | ||
1030 | if (name == NULL) | |
1031 | { | |
1032 | static char buffer[100]; | |
1033 | ||
1034 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1035 | return buffer; | |
1036 | } | |
1037 | ||
1038 | return name; | |
1039 | } | |
1040 | ||
19e6b90e | 1041 | static unsigned char * |
0c588247 NC |
1042 | display_block (unsigned char *data, |
1043 | dwarf_vma length, | |
ef0b5f1c | 1044 | const unsigned char * const end, char delimiter) |
19e6b90e | 1045 | { |
0c588247 NC |
1046 | dwarf_vma maxlen; |
1047 | ||
ef0b5f1c | 1048 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1049 | if (data > end) |
1050 | return (unsigned char *) end; | |
19e6b90e | 1051 | |
0c588247 NC |
1052 | maxlen = (dwarf_vma) (end - data); |
1053 | length = length > maxlen ? maxlen : length; | |
1054 | ||
19e6b90e L |
1055 | while (length --) |
1056 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1057 | ||
1058 | return data; | |
1059 | } | |
1060 | ||
1061 | static int | |
1062 | decode_location_expression (unsigned char * data, | |
1063 | unsigned int pointer_size, | |
b7807392 JJ |
1064 | unsigned int offset_size, |
1065 | int dwarf_version, | |
467c65bc NC |
1066 | dwarf_vma length, |
1067 | dwarf_vma cu_offset, | |
f1c4cc75 | 1068 | struct dwarf_section * section) |
19e6b90e L |
1069 | { |
1070 | unsigned op; | |
1071 | unsigned int bytes_read; | |
467c65bc | 1072 | dwarf_vma uvalue; |
0c588247 | 1073 | dwarf_signed_vma svalue; |
19e6b90e L |
1074 | unsigned char *end = data + length; |
1075 | int need_frame_base = 0; | |
1076 | ||
1077 | while (data < end) | |
1078 | { | |
1079 | op = *data++; | |
1080 | ||
1081 | switch (op) | |
1082 | { | |
1083 | case DW_OP_addr: | |
0c588247 NC |
1084 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1085 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1086 | break; |
1087 | case DW_OP_deref: | |
1088 | printf ("DW_OP_deref"); | |
1089 | break; | |
1090 | case DW_OP_const1u: | |
0c588247 NC |
1091 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1092 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1093 | break; |
1094 | case DW_OP_const1s: | |
0c588247 NC |
1095 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1096 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1097 | break; |
1098 | case DW_OP_const2u: | |
87bc83b3 | 1099 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1100 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1101 | break; |
1102 | case DW_OP_const2s: | |
0c588247 NC |
1103 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1104 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1105 | break; |
1106 | case DW_OP_const4u: | |
0c588247 NC |
1107 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1108 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1109 | break; |
1110 | case DW_OP_const4s: | |
0c588247 NC |
1111 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1112 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1113 | break; |
1114 | case DW_OP_const8u: | |
0c588247 NC |
1115 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1116 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1117 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1118 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1119 | break; |
1120 | case DW_OP_const8s: | |
0c588247 NC |
1121 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1122 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1123 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1124 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1125 | break; |
1126 | case DW_OP_constu: | |
467c65bc | 1127 | printf ("DW_OP_constu: %s", |
f6f0e17b | 1128 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1129 | data += bytes_read; |
1130 | break; | |
1131 | case DW_OP_consts: | |
467c65bc | 1132 | printf ("DW_OP_consts: %s", |
f6f0e17b | 1133 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1134 | data += bytes_read; |
1135 | break; | |
1136 | case DW_OP_dup: | |
1137 | printf ("DW_OP_dup"); | |
1138 | break; | |
1139 | case DW_OP_drop: | |
1140 | printf ("DW_OP_drop"); | |
1141 | break; | |
1142 | case DW_OP_over: | |
1143 | printf ("DW_OP_over"); | |
1144 | break; | |
1145 | case DW_OP_pick: | |
0c588247 NC |
1146 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1147 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1148 | break; |
1149 | case DW_OP_swap: | |
1150 | printf ("DW_OP_swap"); | |
1151 | break; | |
1152 | case DW_OP_rot: | |
1153 | printf ("DW_OP_rot"); | |
1154 | break; | |
1155 | case DW_OP_xderef: | |
1156 | printf ("DW_OP_xderef"); | |
1157 | break; | |
1158 | case DW_OP_abs: | |
1159 | printf ("DW_OP_abs"); | |
1160 | break; | |
1161 | case DW_OP_and: | |
1162 | printf ("DW_OP_and"); | |
1163 | break; | |
1164 | case DW_OP_div: | |
1165 | printf ("DW_OP_div"); | |
1166 | break; | |
1167 | case DW_OP_minus: | |
1168 | printf ("DW_OP_minus"); | |
1169 | break; | |
1170 | case DW_OP_mod: | |
1171 | printf ("DW_OP_mod"); | |
1172 | break; | |
1173 | case DW_OP_mul: | |
1174 | printf ("DW_OP_mul"); | |
1175 | break; | |
1176 | case DW_OP_neg: | |
1177 | printf ("DW_OP_neg"); | |
1178 | break; | |
1179 | case DW_OP_not: | |
1180 | printf ("DW_OP_not"); | |
1181 | break; | |
1182 | case DW_OP_or: | |
1183 | printf ("DW_OP_or"); | |
1184 | break; | |
1185 | case DW_OP_plus: | |
1186 | printf ("DW_OP_plus"); | |
1187 | break; | |
1188 | case DW_OP_plus_uconst: | |
467c65bc | 1189 | printf ("DW_OP_plus_uconst: %s", |
f6f0e17b | 1190 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1191 | data += bytes_read; |
1192 | break; | |
1193 | case DW_OP_shl: | |
1194 | printf ("DW_OP_shl"); | |
1195 | break; | |
1196 | case DW_OP_shr: | |
1197 | printf ("DW_OP_shr"); | |
1198 | break; | |
1199 | case DW_OP_shra: | |
1200 | printf ("DW_OP_shra"); | |
1201 | break; | |
1202 | case DW_OP_xor: | |
1203 | printf ("DW_OP_xor"); | |
1204 | break; | |
1205 | case DW_OP_bra: | |
0c588247 NC |
1206 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1207 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1208 | break; |
1209 | case DW_OP_eq: | |
1210 | printf ("DW_OP_eq"); | |
1211 | break; | |
1212 | case DW_OP_ge: | |
1213 | printf ("DW_OP_ge"); | |
1214 | break; | |
1215 | case DW_OP_gt: | |
1216 | printf ("DW_OP_gt"); | |
1217 | break; | |
1218 | case DW_OP_le: | |
1219 | printf ("DW_OP_le"); | |
1220 | break; | |
1221 | case DW_OP_lt: | |
1222 | printf ("DW_OP_lt"); | |
1223 | break; | |
1224 | case DW_OP_ne: | |
1225 | printf ("DW_OP_ne"); | |
1226 | break; | |
1227 | case DW_OP_skip: | |
0c588247 NC |
1228 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1229 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1230 | break; |
1231 | ||
1232 | case DW_OP_lit0: | |
1233 | case DW_OP_lit1: | |
1234 | case DW_OP_lit2: | |
1235 | case DW_OP_lit3: | |
1236 | case DW_OP_lit4: | |
1237 | case DW_OP_lit5: | |
1238 | case DW_OP_lit6: | |
1239 | case DW_OP_lit7: | |
1240 | case DW_OP_lit8: | |
1241 | case DW_OP_lit9: | |
1242 | case DW_OP_lit10: | |
1243 | case DW_OP_lit11: | |
1244 | case DW_OP_lit12: | |
1245 | case DW_OP_lit13: | |
1246 | case DW_OP_lit14: | |
1247 | case DW_OP_lit15: | |
1248 | case DW_OP_lit16: | |
1249 | case DW_OP_lit17: | |
1250 | case DW_OP_lit18: | |
1251 | case DW_OP_lit19: | |
1252 | case DW_OP_lit20: | |
1253 | case DW_OP_lit21: | |
1254 | case DW_OP_lit22: | |
1255 | case DW_OP_lit23: | |
1256 | case DW_OP_lit24: | |
1257 | case DW_OP_lit25: | |
1258 | case DW_OP_lit26: | |
1259 | case DW_OP_lit27: | |
1260 | case DW_OP_lit28: | |
1261 | case DW_OP_lit29: | |
1262 | case DW_OP_lit30: | |
1263 | case DW_OP_lit31: | |
1264 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1265 | break; | |
1266 | ||
1267 | case DW_OP_reg0: | |
1268 | case DW_OP_reg1: | |
1269 | case DW_OP_reg2: | |
1270 | case DW_OP_reg3: | |
1271 | case DW_OP_reg4: | |
1272 | case DW_OP_reg5: | |
1273 | case DW_OP_reg6: | |
1274 | case DW_OP_reg7: | |
1275 | case DW_OP_reg8: | |
1276 | case DW_OP_reg9: | |
1277 | case DW_OP_reg10: | |
1278 | case DW_OP_reg11: | |
1279 | case DW_OP_reg12: | |
1280 | case DW_OP_reg13: | |
1281 | case DW_OP_reg14: | |
1282 | case DW_OP_reg15: | |
1283 | case DW_OP_reg16: | |
1284 | case DW_OP_reg17: | |
1285 | case DW_OP_reg18: | |
1286 | case DW_OP_reg19: | |
1287 | case DW_OP_reg20: | |
1288 | case DW_OP_reg21: | |
1289 | case DW_OP_reg22: | |
1290 | case DW_OP_reg23: | |
1291 | case DW_OP_reg24: | |
1292 | case DW_OP_reg25: | |
1293 | case DW_OP_reg26: | |
1294 | case DW_OP_reg27: | |
1295 | case DW_OP_reg28: | |
1296 | case DW_OP_reg29: | |
1297 | case DW_OP_reg30: | |
1298 | case DW_OP_reg31: | |
18464d4d JK |
1299 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1300 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1301 | break; |
1302 | ||
1303 | case DW_OP_breg0: | |
1304 | case DW_OP_breg1: | |
1305 | case DW_OP_breg2: | |
1306 | case DW_OP_breg3: | |
1307 | case DW_OP_breg4: | |
1308 | case DW_OP_breg5: | |
1309 | case DW_OP_breg6: | |
1310 | case DW_OP_breg7: | |
1311 | case DW_OP_breg8: | |
1312 | case DW_OP_breg9: | |
1313 | case DW_OP_breg10: | |
1314 | case DW_OP_breg11: | |
1315 | case DW_OP_breg12: | |
1316 | case DW_OP_breg13: | |
1317 | case DW_OP_breg14: | |
1318 | case DW_OP_breg15: | |
1319 | case DW_OP_breg16: | |
1320 | case DW_OP_breg17: | |
1321 | case DW_OP_breg18: | |
1322 | case DW_OP_breg19: | |
1323 | case DW_OP_breg20: | |
1324 | case DW_OP_breg21: | |
1325 | case DW_OP_breg22: | |
1326 | case DW_OP_breg23: | |
1327 | case DW_OP_breg24: | |
1328 | case DW_OP_breg25: | |
1329 | case DW_OP_breg26: | |
1330 | case DW_OP_breg27: | |
1331 | case DW_OP_breg28: | |
1332 | case DW_OP_breg29: | |
1333 | case DW_OP_breg30: | |
1334 | case DW_OP_breg31: | |
467c65bc | 1335 | printf ("DW_OP_breg%d (%s): %s", |
47704ddf | 1336 | op - DW_OP_breg0, |
18464d4d | 1337 | regname (op - DW_OP_breg0, 1), |
f6f0e17b | 1338 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1339 | data += bytes_read; |
1340 | break; | |
1341 | ||
1342 | case DW_OP_regx: | |
f6f0e17b | 1343 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1344 | data += bytes_read; |
467c65bc NC |
1345 | printf ("DW_OP_regx: %s (%s)", |
1346 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1347 | break; |
1348 | case DW_OP_fbreg: | |
1349 | need_frame_base = 1; | |
467c65bc | 1350 | printf ("DW_OP_fbreg: %s", |
f6f0e17b | 1351 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1352 | data += bytes_read; |
1353 | break; | |
1354 | case DW_OP_bregx: | |
f6f0e17b | 1355 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1356 | data += bytes_read; |
467c65bc NC |
1357 | printf ("DW_OP_bregx: %s (%s) %s", |
1358 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
f6f0e17b | 1359 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1360 | data += bytes_read; |
1361 | break; | |
1362 | case DW_OP_piece: | |
467c65bc | 1363 | printf ("DW_OP_piece: %s", |
f6f0e17b | 1364 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1365 | data += bytes_read; |
1366 | break; | |
1367 | case DW_OP_deref_size: | |
0c588247 NC |
1368 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1369 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1370 | break; |
1371 | case DW_OP_xderef_size: | |
0c588247 NC |
1372 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1373 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1374 | break; |
1375 | case DW_OP_nop: | |
1376 | printf ("DW_OP_nop"); | |
1377 | break; | |
1378 | ||
1379 | /* DWARF 3 extensions. */ | |
1380 | case DW_OP_push_object_address: | |
1381 | printf ("DW_OP_push_object_address"); | |
1382 | break; | |
1383 | case DW_OP_call2: | |
d85bf2ba | 1384 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1385 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1386 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1387 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1388 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1389 | break; |
1390 | case DW_OP_call4: | |
d85bf2ba | 1391 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1392 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1393 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1394 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1395 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1396 | break; |
1397 | case DW_OP_call_ref: | |
d85bf2ba | 1398 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1399 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1400 | if (dwarf_version == -1) |
1401 | { | |
1402 | printf (_("(DW_OP_call_ref in frame info)")); | |
1403 | /* No way to tell where the next op is, so just bail. */ | |
1404 | return need_frame_base; | |
1405 | } | |
1406 | if (dwarf_version == 2) | |
1407 | { | |
0c588247 | 1408 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1409 | } |
1410 | else | |
1411 | { | |
0c588247 | 1412 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1413 | } |
0c588247 | 1414 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1415 | break; |
a87b0a59 NS |
1416 | case DW_OP_form_tls_address: |
1417 | printf ("DW_OP_form_tls_address"); | |
1418 | break; | |
e2a0d921 NC |
1419 | case DW_OP_call_frame_cfa: |
1420 | printf ("DW_OP_call_frame_cfa"); | |
1421 | break; | |
1422 | case DW_OP_bit_piece: | |
1423 | printf ("DW_OP_bit_piece: "); | |
9cf03b7e | 1424 | printf (_("size: %s "), |
f6f0e17b | 1425 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 | 1426 | data += bytes_read; |
9cf03b7e | 1427 | printf (_("offset: %s "), |
f6f0e17b | 1428 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 NC |
1429 | data += bytes_read; |
1430 | break; | |
19e6b90e | 1431 | |
3244e8f5 JJ |
1432 | /* DWARF 4 extensions. */ |
1433 | case DW_OP_stack_value: | |
1434 | printf ("DW_OP_stack_value"); | |
1435 | break; | |
1436 | ||
1437 | case DW_OP_implicit_value: | |
1438 | printf ("DW_OP_implicit_value"); | |
f6f0e17b | 1439 | uvalue = read_uleb128 (data, &bytes_read, end); |
3244e8f5 | 1440 | data += bytes_read; |
ef0b5f1c | 1441 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1442 | break; |
1443 | ||
19e6b90e L |
1444 | /* GNU extensions. */ |
1445 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1446 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1447 | break; |
1448 | case DW_OP_GNU_uninit: | |
1449 | printf ("DW_OP_GNU_uninit"); | |
1450 | /* FIXME: Is there data associated with this OP ? */ | |
1451 | break; | |
f1c4cc75 RH |
1452 | case DW_OP_GNU_encoded_addr: |
1453 | { | |
6937bb54 | 1454 | int encoding = 0; |
f1c4cc75 | 1455 | dwarf_vma addr; |
467c65bc | 1456 | |
6937bb54 NC |
1457 | if (data < end) |
1458 | encoding = *data++; | |
041830e0 | 1459 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1460 | |
1461 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1462 | print_dwarf_vma (addr, pointer_size); | |
1463 | } | |
1464 | break; | |
bc0a77d2 | 1465 | case DW_OP_implicit_pointer: |
b7807392 | 1466 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1467 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1468 | this ought to be an 8-byte wide computation. */ |
1469 | if (dwarf_version == -1) | |
1470 | { | |
bc0a77d2 JK |
1471 | printf (_("(%s in frame info)"), |
1472 | (op == DW_OP_implicit_pointer | |
1473 | ? "DW_OP_implicit_pointer" | |
1474 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1475 | /* No way to tell where the next op is, so just bail. */ |
1476 | return need_frame_base; | |
1477 | } | |
1478 | if (dwarf_version == 2) | |
1479 | { | |
0c588247 | 1480 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1481 | } |
1482 | else | |
1483 | { | |
0c588247 | 1484 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1485 | } |
bc0a77d2 JK |
1486 | printf ("%s: <0x%s> %s", |
1487 | (op == DW_OP_implicit_pointer | |
1488 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 NC |
1489 | dwarf_vmatoa ("x", uvalue), |
1490 | dwarf_vmatoa ("d", read_sleb128 (data, | |
1491 | &bytes_read, end))); | |
1492 | data += bytes_read; | |
b7807392 | 1493 | break; |
77145576 | 1494 | case DW_OP_entry_value: |
0892011d | 1495 | case DW_OP_GNU_entry_value: |
f6f0e17b | 1496 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1497 | data += bytes_read; |
058037d3 NC |
1498 | /* PR 17531: file: 0cc9cd00. */ |
1499 | if (uvalue > (dwarf_vma) (end - data)) | |
1500 | uvalue = end - data; | |
77145576 JK |
1501 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1502 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1503 | if (decode_location_expression (data, pointer_size, offset_size, |
1504 | dwarf_version, uvalue, | |
1505 | cu_offset, section)) | |
1506 | need_frame_base = 1; | |
1507 | putchar (')'); | |
1508 | data += uvalue; | |
6937bb54 NC |
1509 | if (data > end) |
1510 | data = end; | |
0892011d | 1511 | break; |
bc0a77d2 | 1512 | case DW_OP_const_type: |
0892011d | 1513 | case DW_OP_GNU_const_type: |
f6f0e17b | 1514 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1515 | data += bytes_read; |
bc0a77d2 JK |
1516 | printf ("%s: <0x%s> ", |
1517 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1518 | : "DW_OP_GNU_const_type"), | |
0892011d | 1519 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1520 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1521 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1522 | break; |
bc0a77d2 | 1523 | case DW_OP_regval_type: |
0892011d | 1524 | case DW_OP_GNU_regval_type: |
f6f0e17b | 1525 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1526 | data += bytes_read; |
bc0a77d2 JK |
1527 | printf ("%s: %s (%s)", |
1528 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1529 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1530 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
f6f0e17b | 1531 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1532 | data += bytes_read; |
1533 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1534 | break; | |
bc0a77d2 | 1535 | case DW_OP_deref_type: |
0892011d | 1536 | case DW_OP_GNU_deref_type: |
0c588247 | 1537 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1538 | printf ("%s: %ld", |
1539 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1540 | : "DW_OP_GNU_deref_type"), | |
1541 | (long) uvalue); | |
f6f0e17b | 1542 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1543 | data += bytes_read; |
1544 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1545 | break; | |
bc0a77d2 | 1546 | case DW_OP_convert: |
0892011d | 1547 | case DW_OP_GNU_convert: |
f6f0e17b | 1548 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1549 | data += bytes_read; |
bc0a77d2 JK |
1550 | printf ("%s <0x%s>", |
1551 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1552 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1553 | break; |
bc0a77d2 | 1554 | case DW_OP_reinterpret: |
0892011d | 1555 | case DW_OP_GNU_reinterpret: |
f6f0e17b | 1556 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1557 | data += bytes_read; |
bc0a77d2 JK |
1558 | printf ("%s <0x%s>", |
1559 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1560 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1561 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1562 | break; | |
1563 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1564 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1565 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1566 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1567 | break; |
b4eb7656 AM |
1568 | case DW_OP_GNU_addr_index: |
1569 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1570 | data += bytes_read; | |
1571 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1572 | break; | |
1573 | case DW_OP_GNU_const_index: | |
1574 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1575 | data += bytes_read; | |
1576 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1577 | break; | |
f384a1f0 KB |
1578 | case DW_OP_GNU_variable_value: |
1579 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1580 | this ought to be an 8-byte wide computation. */ | |
1581 | if (dwarf_version == -1) | |
1582 | { | |
1583 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1584 | /* No way to tell where the next op is, so just bail. */ | |
1585 | return need_frame_base; | |
1586 | } | |
1587 | if (dwarf_version == 2) | |
1588 | { | |
1589 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1590 | } | |
1591 | else | |
1592 | { | |
1593 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1594 | } | |
1595 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1596 | break; | |
e2a0d921 NC |
1597 | |
1598 | /* HP extensions. */ | |
1599 | case DW_OP_HP_is_value: | |
1600 | printf ("DW_OP_HP_is_value"); | |
1601 | /* FIXME: Is there data associated with this OP ? */ | |
1602 | break; | |
1603 | case DW_OP_HP_fltconst4: | |
1604 | printf ("DW_OP_HP_fltconst4"); | |
1605 | /* FIXME: Is there data associated with this OP ? */ | |
1606 | break; | |
1607 | case DW_OP_HP_fltconst8: | |
1608 | printf ("DW_OP_HP_fltconst8"); | |
1609 | /* FIXME: Is there data associated with this OP ? */ | |
1610 | break; | |
1611 | case DW_OP_HP_mod_range: | |
1612 | printf ("DW_OP_HP_mod_range"); | |
1613 | /* FIXME: Is there data associated with this OP ? */ | |
1614 | break; | |
1615 | case DW_OP_HP_unmod_range: | |
1616 | printf ("DW_OP_HP_unmod_range"); | |
1617 | /* FIXME: Is there data associated with this OP ? */ | |
1618 | break; | |
1619 | case DW_OP_HP_tls: | |
1620 | printf ("DW_OP_HP_tls"); | |
1621 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1622 | break; |
1623 | ||
35d60fe4 NC |
1624 | /* PGI (STMicroelectronics) extensions. */ |
1625 | case DW_OP_PGI_omp_thread_num: | |
1626 | /* Pushes the thread number for the current thread as it would be | |
1627 | returned by the standard OpenMP library function: | |
1628 | omp_get_thread_num(). The "current thread" is the thread for | |
1629 | which the expression is being evaluated. */ | |
1630 | printf ("DW_OP_PGI_omp_thread_num"); | |
1631 | break; | |
1632 | ||
19e6b90e L |
1633 | default: |
1634 | if (op >= DW_OP_lo_user | |
1635 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1636 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1637 | else |
0502a2b4 | 1638 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1639 | /* No way to tell where the next op is, so just bail. */ |
1640 | return need_frame_base; | |
1641 | } | |
1642 | ||
1643 | /* Separate the ops. */ | |
1644 | if (data < end) | |
1645 | printf ("; "); | |
1646 | } | |
1647 | ||
1648 | return need_frame_base; | |
1649 | } | |
1650 | ||
341f9135 CC |
1651 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1652 | This is used for DWARF package files. */ | |
1653 | ||
1654 | static struct cu_tu_set * | |
1655 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1656 | { | |
1657 | struct cu_tu_set *p; | |
1658 | unsigned int nsets; | |
1659 | unsigned int dw_sect; | |
1660 | ||
1661 | if (do_types) | |
1662 | { | |
1663 | p = tu_sets; | |
1664 | nsets = tu_count; | |
1665 | dw_sect = DW_SECT_TYPES; | |
1666 | } | |
1667 | else | |
1668 | { | |
1669 | p = cu_sets; | |
1670 | nsets = cu_count; | |
1671 | dw_sect = DW_SECT_INFO; | |
1672 | } | |
1673 | while (nsets > 0) | |
1674 | { | |
1675 | if (p->section_offsets [dw_sect] == cu_offset) | |
1676 | return p; | |
1677 | p++; | |
1678 | nsets--; | |
1679 | } | |
1680 | return NULL; | |
1681 | } | |
1682 | ||
a69c4772 NC |
1683 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1684 | static void | |
1685 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1686 | { | |
1687 | dwarf_vma tmp = * low_bits; | |
1688 | ||
1689 | tmp += inc; | |
1690 | ||
1691 | /* FIXME: There is probably a better way of handling this: | |
1692 | ||
1693 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1694 | type. Plus regardless of its size LOW_BITS is meant to | |
1695 | only hold 32-bits, so if there is overflow or wrap around | |
1696 | we must propagate into HIGH_BITS. */ | |
1697 | if (tmp < * low_bits) | |
1698 | { | |
1699 | ++ * high_bits; | |
1700 | } | |
1701 | else if (sizeof (tmp) > 8 | |
1702 | && (tmp >> 31) > 1) | |
1703 | { | |
1704 | ++ * high_bits; | |
1705 | tmp &= 0xFFFFFFFF; | |
1706 | } | |
1707 | ||
1708 | * low_bits = tmp; | |
1709 | } | |
1710 | ||
dda8d76d NC |
1711 | static const char * |
1712 | fetch_alt_indirect_string (dwarf_vma offset) | |
1713 | { | |
1714 | struct dwarf_section * section; | |
1715 | const char * ret; | |
1716 | ||
1717 | if (! do_follow_links) | |
1718 | return ""; | |
1719 | ||
1720 | if (separate_debug_file == NULL) | |
1721 | return _("<following link not possible>"); | |
1722 | ||
1723 | if (! load_debug_section (separate_debug_str, separate_debug_file)) | |
1724 | return _("<could not load separate string section>"); | |
1725 | ||
1726 | section = &debug_displays [separate_debug_str].section; | |
1727 | if (section->start == NULL) | |
1728 | return _("<no .debug_str section>"); | |
1729 | ||
1730 | if (offset >= section->size) | |
1731 | { | |
1732 | warn (_("DW_FORM_GNU_strp_alt offset too big: %s\n"), dwarf_vmatoa ("x", offset)); | |
1733 | return _("<offset is too big>"); | |
1734 | } | |
1735 | ||
1736 | ret = (const char *) (section->start + offset); | |
1737 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1738 | NUL byte. Since our caller is expecting to receive a well formed C | |
1739 | string we test for the lack of a terminating byte here. */ | |
1740 | if (strnlen ((const char *) ret, section->size - offset) | |
1741 | == section->size - offset) | |
1742 | return _("<no NUL byte at end of .debug_str section>"); | |
1743 | ||
1744 | return ret; | |
1745 | } | |
1746 | ||
d85bf2ba NC |
1747 | static const char * |
1748 | get_AT_name (unsigned long attribute) | |
1749 | { | |
1750 | const char *name; | |
1751 | ||
1752 | if (attribute == 0) | |
1753 | return "DW_AT value: 0"; | |
1754 | ||
1755 | /* One value is shared by the MIPS and HP extensions: */ | |
1756 | if (attribute == DW_AT_MIPS_fde) | |
1757 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1758 | ||
1759 | name = get_DW_AT_name (attribute); | |
1760 | ||
1761 | if (name == NULL) | |
1762 | { | |
1763 | static char buffer[100]; | |
1764 | ||
1765 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1766 | attribute); | |
1767 | return buffer; | |
1768 | } | |
1769 | ||
1770 | return name; | |
1771 | } | |
1772 | ||
19e6b90e | 1773 | static unsigned char * |
dda8d76d NC |
1774 | read_and_display_attr_value (unsigned long attribute, |
1775 | unsigned long form, | |
1776 | dwarf_signed_vma implicit_const, | |
1777 | unsigned char * data, | |
1778 | unsigned char * end, | |
1779 | dwarf_vma cu_offset, | |
1780 | dwarf_vma pointer_size, | |
1781 | dwarf_vma offset_size, | |
1782 | int dwarf_version, | |
1783 | debug_info * debug_info_p, | |
1784 | int do_loc, | |
1785 | struct dwarf_section * section, | |
1786 | struct cu_tu_set * this_set, | |
1787 | char delimiter) | |
19e6b90e | 1788 | { |
467c65bc | 1789 | dwarf_vma uvalue = 0; |
19e6b90e | 1790 | unsigned char *block_start = NULL; |
6e3d6dc1 | 1791 | unsigned char * orig_data = data; |
19e6b90e L |
1792 | unsigned int bytes_read; |
1793 | ||
f41e4712 | 1794 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 1795 | { |
f41e4712 | 1796 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
1797 | return data; |
1798 | } | |
1799 | ||
19e6b90e L |
1800 | switch (form) |
1801 | { | |
1802 | default: | |
1803 | break; | |
1804 | ||
1805 | case DW_FORM_ref_addr: | |
1806 | if (dwarf_version == 2) | |
0c588247 | 1807 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
932fd279 | 1808 | else if (dwarf_version == 3 || dwarf_version == 4) |
0c588247 | 1809 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 1810 | else |
467c65bc NC |
1811 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
1812 | ||
19e6b90e L |
1813 | break; |
1814 | ||
1815 | case DW_FORM_addr: | |
0c588247 | 1816 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
1817 | break; |
1818 | ||
1819 | case DW_FORM_strp: | |
77145576 | 1820 | case DW_FORM_line_strp: |
932fd279 | 1821 | case DW_FORM_sec_offset: |
a081f3cd JJ |
1822 | case DW_FORM_GNU_ref_alt: |
1823 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 1824 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
1825 | break; |
1826 | ||
932fd279 JJ |
1827 | case DW_FORM_flag_present: |
1828 | uvalue = 1; | |
1829 | break; | |
1830 | ||
19e6b90e L |
1831 | case DW_FORM_ref1: |
1832 | case DW_FORM_flag: | |
1833 | case DW_FORM_data1: | |
0c588247 | 1834 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
1835 | break; |
1836 | ||
1837 | case DW_FORM_ref2: | |
1838 | case DW_FORM_data2: | |
0c588247 | 1839 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
1840 | break; |
1841 | ||
1842 | case DW_FORM_ref4: | |
1843 | case DW_FORM_data4: | |
0c588247 | 1844 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
1845 | break; |
1846 | ||
1847 | case DW_FORM_sdata: | |
f6f0e17b | 1848 | uvalue = read_sleb128 (data, & bytes_read, end); |
19e6b90e L |
1849 | data += bytes_read; |
1850 | break; | |
1851 | ||
4723351a | 1852 | case DW_FORM_GNU_str_index: |
f6f0e17b | 1853 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1854 | data += bytes_read; |
1855 | break; | |
1856 | ||
19e6b90e L |
1857 | case DW_FORM_ref_udata: |
1858 | case DW_FORM_udata: | |
f6f0e17b | 1859 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1860 | data += bytes_read; |
1861 | break; | |
1862 | ||
1863 | case DW_FORM_indirect: | |
f6f0e17b | 1864 | form = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1865 | data += bytes_read; |
1866 | if (!do_loc) | |
ef0b5f1c | 1867 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 JK |
1868 | if (form == DW_FORM_implicit_const) |
1869 | { | |
1870 | implicit_const = read_sleb128 (data, & bytes_read, end); | |
1871 | data += bytes_read; | |
1872 | } | |
1873 | return read_and_display_attr_value (attribute, form, implicit_const, data, | |
1874 | end, cu_offset, pointer_size, | |
19e6b90e | 1875 | offset_size, dwarf_version, |
ec4d4525 | 1876 | debug_info_p, do_loc, |
ef0b5f1c | 1877 | section, this_set, delimiter); |
4723351a | 1878 | case DW_FORM_GNU_addr_index: |
f6f0e17b | 1879 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1880 | data += bytes_read; |
1881 | break; | |
19e6b90e L |
1882 | } |
1883 | ||
1884 | switch (form) | |
1885 | { | |
1886 | case DW_FORM_ref_addr: | |
1887 | if (!do_loc) | |
ef0b5f1c | 1888 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
1889 | break; |
1890 | ||
a081f3cd JJ |
1891 | case DW_FORM_GNU_ref_alt: |
1892 | if (!do_loc) | |
ef0b5f1c | 1893 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
dda8d76d | 1894 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
1895 | break; |
1896 | ||
19e6b90e L |
1897 | case DW_FORM_ref1: |
1898 | case DW_FORM_ref2: | |
1899 | case DW_FORM_ref4: | |
1900 | case DW_FORM_ref_udata: | |
1901 | if (!do_loc) | |
ef0b5f1c | 1902 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
1903 | break; |
1904 | ||
1905 | case DW_FORM_data4: | |
1906 | case DW_FORM_addr: | |
932fd279 | 1907 | case DW_FORM_sec_offset: |
19e6b90e | 1908 | if (!do_loc) |
ef0b5f1c | 1909 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
1910 | break; |
1911 | ||
932fd279 | 1912 | case DW_FORM_flag_present: |
19e6b90e L |
1913 | case DW_FORM_flag: |
1914 | case DW_FORM_data1: | |
1915 | case DW_FORM_data2: | |
1916 | case DW_FORM_sdata: | |
1917 | case DW_FORM_udata: | |
1918 | if (!do_loc) | |
ef0b5f1c | 1919 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
1920 | break; |
1921 | ||
77145576 JK |
1922 | case DW_FORM_implicit_const: |
1923 | if (!do_loc) | |
1924 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
1925 | break; | |
1926 | ||
19e6b90e L |
1927 | case DW_FORM_ref8: |
1928 | case DW_FORM_data8: | |
2bc8690c | 1929 | if (!do_loc) |
19e6b90e | 1930 | { |
74bc6052 | 1931 | dwarf_vma high_bits; |
a69c4772 | 1932 | dwarf_vma utmp; |
74bc6052 CC |
1933 | char buf[64]; |
1934 | ||
0c588247 | 1935 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
1936 | utmp = uvalue; |
1937 | if (form == DW_FORM_ref8) | |
1938 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 1939 | printf ("%c0x%s", delimiter, |
a69c4772 | 1940 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 1941 | } |
0c588247 | 1942 | |
19e6b90e L |
1943 | if ((do_loc || do_debug_loc || do_debug_ranges) |
1944 | && num_debug_info_entries == 0) | |
1945 | { | |
1946 | if (sizeof (uvalue) == 8) | |
0c588247 | 1947 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 1948 | else |
467c65bc | 1949 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 1950 | } |
0c588247 | 1951 | |
19e6b90e L |
1952 | data += 8; |
1953 | break; | |
1954 | ||
2f6cd591 JK |
1955 | case DW_FORM_data16: |
1956 | if (!do_loc) | |
1957 | { | |
1958 | dwarf_vma left_high_bits, left_low_bits; | |
1959 | dwarf_vma right_high_bits, right_low_bits; | |
1960 | ||
1961 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
1962 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
1963 | if (byte_get == byte_get_little_endian) | |
1964 | { | |
1965 | /* Swap them. */ | |
1966 | left_high_bits ^= right_high_bits; | |
1967 | right_high_bits ^= left_high_bits; | |
1968 | left_high_bits ^= right_high_bits; | |
1969 | left_low_bits ^= right_low_bits; | |
1970 | right_low_bits ^= left_low_bits; | |
1971 | left_low_bits ^= right_low_bits; | |
1972 | } | |
1973 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
1974 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
1975 | left_high_bits, left_low_bits, right_high_bits, | |
1976 | right_low_bits); | |
1977 | } | |
1978 | data += 16; | |
1979 | break; | |
1980 | ||
19e6b90e L |
1981 | case DW_FORM_string: |
1982 | if (!do_loc) | |
ef0b5f1c | 1983 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 1984 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
1985 | break; |
1986 | ||
1987 | case DW_FORM_block: | |
932fd279 | 1988 | case DW_FORM_exprloc: |
f6f0e17b | 1989 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e | 1990 | block_start = data + bytes_read; |
a1165289 NC |
1991 | if (block_start >= end) |
1992 | { | |
1993 | warn (_("Block ends prematurely\n")); | |
1994 | uvalue = 0; | |
1995 | block_start = end; | |
1996 | } | |
f3853b34 NC |
1997 | /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with |
1998 | gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute | |
1999 | block_start + uvalue here. */ | |
2000 | data = block_start + uvalue; | |
f41e4712 | 2001 | /* PR 17512: file: 008-103549-0.001:0.1. */ |
f3853b34 | 2002 | if (block_start + uvalue > end || data < block_start) |
f41e4712 NC |
2003 | { |
2004 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
2005 | uvalue = end - block_start; | |
2006 | } | |
19e6b90e L |
2007 | if (do_loc) |
2008 | data = block_start + uvalue; | |
2009 | else | |
ef0b5f1c | 2010 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2011 | break; |
2012 | ||
2013 | case DW_FORM_block1: | |
0c588247 | 2014 | SAFE_BYTE_GET (uvalue, data, 1, end); |
19e6b90e | 2015 | block_start = data + 1; |
a1165289 NC |
2016 | if (block_start >= end) |
2017 | { | |
2018 | warn (_("Block ends prematurely\n")); | |
2019 | uvalue = 0; | |
2020 | block_start = end; | |
2021 | } | |
f3853b34 NC |
2022 | data = block_start + uvalue; |
2023 | if (block_start + uvalue > end || data < block_start) | |
f41e4712 NC |
2024 | { |
2025 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
2026 | uvalue = end - block_start; | |
2027 | } | |
19e6b90e L |
2028 | if (do_loc) |
2029 | data = block_start + uvalue; | |
2030 | else | |
ef0b5f1c | 2031 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2032 | break; |
2033 | ||
2034 | case DW_FORM_block2: | |
0c588247 | 2035 | SAFE_BYTE_GET (uvalue, data, 2, end); |
19e6b90e | 2036 | block_start = data + 2; |
a1165289 NC |
2037 | if (block_start >= end) |
2038 | { | |
2039 | warn (_("Block ends prematurely\n")); | |
2040 | uvalue = 0; | |
2041 | block_start = end; | |
2042 | } | |
f3853b34 NC |
2043 | data = block_start + uvalue; |
2044 | if (block_start + uvalue > end || data < block_start) | |
f41e4712 NC |
2045 | { |
2046 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
2047 | uvalue = end - block_start; | |
2048 | } | |
19e6b90e L |
2049 | if (do_loc) |
2050 | data = block_start + uvalue; | |
2051 | else | |
ef0b5f1c | 2052 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2053 | break; |
2054 | ||
2055 | case DW_FORM_block4: | |
0c588247 | 2056 | SAFE_BYTE_GET (uvalue, data, 4, end); |
19e6b90e | 2057 | block_start = data + 4; |
a1165289 NC |
2058 | /* PR 17512: file: 3371-3907-0.004. */ |
2059 | if (block_start >= end) | |
2060 | { | |
2061 | warn (_("Block ends prematurely\n")); | |
2062 | uvalue = 0; | |
2063 | block_start = end; | |
2064 | } | |
f3853b34 NC |
2065 | data = block_start + uvalue; |
2066 | if (block_start + uvalue > end | |
b4eb7656 | 2067 | /* PR 17531: file: 5b5f0592. */ |
f3853b34 | 2068 | || data < block_start) |
f41e4712 NC |
2069 | { |
2070 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
2071 | uvalue = end - block_start; | |
2072 | } | |
19e6b90e L |
2073 | if (do_loc) |
2074 | data = block_start + uvalue; | |
2075 | else | |
ef0b5f1c | 2076 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2077 | break; |
2078 | ||
2079 | case DW_FORM_strp: | |
2080 | if (!do_loc) | |
ef0b5f1c | 2081 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
2082 | dwarf_vmatoa ("x", uvalue), |
2083 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
2084 | break; |
2085 | ||
77145576 JK |
2086 | case DW_FORM_line_strp: |
2087 | if (!do_loc) | |
2088 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2089 | dwarf_vmatoa ("x", uvalue), | |
2090 | fetch_indirect_line_string (uvalue)); | |
2091 | break; | |
2092 | ||
4723351a CC |
2093 | case DW_FORM_GNU_str_index: |
2094 | if (!do_loc) | |
b4eb7656 | 2095 | { |
d85bf2ba NC |
2096 | const char * suffix = strrchr (section->name, '.'); |
2097 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2098 | |
ef0b5f1c | 2099 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2100 | dwarf_vmatoa ("x", uvalue), |
2101 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2102 | } | |
4723351a CC |
2103 | break; |
2104 | ||
a081f3cd JJ |
2105 | case DW_FORM_GNU_strp_alt: |
2106 | if (!do_loc) | |
dda8d76d NC |
2107 | { |
2108 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2109 | dwarf_vmatoa ("x", uvalue), | |
2110 | fetch_alt_indirect_string (uvalue)); | |
2111 | } | |
a081f3cd JJ |
2112 | break; |
2113 | ||
19e6b90e L |
2114 | case DW_FORM_indirect: |
2115 | /* Handled above. */ | |
2116 | break; | |
2117 | ||
2b6f5997 CC |
2118 | case DW_FORM_ref_sig8: |
2119 | if (!do_loc) | |
2120 | { | |
74bc6052 CC |
2121 | dwarf_vma high_bits; |
2122 | char buf[64]; | |
2123 | ||
0c588247 | 2124 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 2125 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 2126 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 2127 | } |
74bc6052 | 2128 | data += 8; |
2b6f5997 CC |
2129 | break; |
2130 | ||
4723351a CC |
2131 | case DW_FORM_GNU_addr_index: |
2132 | if (!do_loc) | |
ef0b5f1c | 2133 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2134 | dwarf_vmatoa ("x", uvalue), |
2135 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
2136 | break; |
2137 | ||
19e6b90e L |
2138 | default: |
2139 | warn (_("Unrecognized form: %lu\n"), form); | |
2140 | break; | |
2141 | } | |
2142 | ||
19e6b90e | 2143 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2144 | && num_debug_info_entries == 0 |
2145 | && debug_info_p != NULL) | |
19e6b90e L |
2146 | { |
2147 | switch (attribute) | |
2148 | { | |
2149 | case DW_AT_frame_base: | |
2150 | have_frame_base = 1; | |
1a0670f3 | 2151 | /* Fall through. */ |
19e6b90e | 2152 | case DW_AT_location: |
9f272209 | 2153 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2154 | case DW_AT_string_length: |
2155 | case DW_AT_return_addr: | |
19e6b90e L |
2156 | case DW_AT_data_member_location: |
2157 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2158 | case DW_AT_segment: |
2159 | case DW_AT_static_link: | |
2160 | case DW_AT_use_location: | |
bc0a77d2 | 2161 | case DW_AT_call_value: |
629e7ca8 | 2162 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2163 | case DW_AT_call_data_value: |
629e7ca8 | 2164 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2165 | case DW_AT_call_target: |
629e7ca8 | 2166 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2167 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2168 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2169 | if ((dwarf_version < 4 |
212b6063 | 2170 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2171 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2172 | { |
2173 | /* Process location list. */ | |
91d6fa6a | 2174 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2175 | unsigned int num = debug_info_p->num_loc_offsets; |
2176 | ||
91d6fa6a | 2177 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2178 | { |
91d6fa6a | 2179 | lmax += 1024; |
467c65bc | 2180 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2181 | xcrealloc (debug_info_p->loc_offsets, |
2182 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2183 | debug_info_p->loc_views = (dwarf_vma *) |
2184 | xcrealloc (debug_info_p->loc_views, | |
2185 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2186 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2187 | xcrealloc (debug_info_p->have_frame_base, |
2188 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2189 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2190 | } |
341f9135 | 2191 | if (this_set != NULL) |
b4eb7656 | 2192 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2193 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2194 | if (attribute != DW_AT_GNU_locviews) |
2195 | { | |
a7504f87 NC |
2196 | /* Corrupt DWARF info can produce more offsets than views. |
2197 | See PR 23062 for an example. */ | |
2198 | if (debug_info_p->num_loc_offsets | |
2199 | > debug_info_p->num_loc_views) | |
2200 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2201 | else | |
2202 | { | |
2203 | debug_info_p->loc_offsets [num] = uvalue; | |
2204 | debug_info_p->num_loc_offsets++; | |
2205 | } | |
9f272209 AO |
2206 | } |
2207 | else | |
2208 | { | |
2209 | assert (debug_info_p->num_loc_views <= num); | |
2210 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2211 | if (num > debug_info_p->num_loc_offsets) |
2212 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2213 | else | |
2214 | { | |
2215 | debug_info_p->loc_views [num] = uvalue; | |
2216 | debug_info_p->num_loc_views++; | |
2217 | } | |
9f272209 | 2218 | } |
19e6b90e L |
2219 | } |
2220 | break; | |
e2a0d921 | 2221 | |
19e6b90e L |
2222 | case DW_AT_low_pc: |
2223 | if (need_base_address) | |
2224 | debug_info_p->base_address = uvalue; | |
2225 | break; | |
2226 | ||
4723351a | 2227 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2228 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2229 | break; |
2230 | ||
2231 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2232 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2233 | break; |
2234 | ||
19e6b90e | 2235 | case DW_AT_ranges: |
b4eb7656 | 2236 | if ((dwarf_version < 4 |
212b6063 | 2237 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2238 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2239 | { |
2240 | /* Process range list. */ | |
91d6fa6a | 2241 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2242 | unsigned int num = debug_info_p->num_range_lists; |
2243 | ||
91d6fa6a | 2244 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2245 | { |
91d6fa6a | 2246 | lmax += 1024; |
467c65bc | 2247 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2248 | xcrealloc (debug_info_p->range_lists, |
2249 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2250 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2251 | } |
2252 | debug_info_p->range_lists [num] = uvalue; | |
2253 | debug_info_p->num_range_lists++; | |
2254 | } | |
2255 | break; | |
2256 | ||
d85bf2ba NC |
2257 | case DW_AT_GNU_dwo_name: |
2258 | case DW_AT_dwo_name: | |
2259 | if (need_dwo_info) | |
2260 | switch (form) | |
2261 | { | |
2262 | case DW_FORM_strp: | |
2263 | dwo_name = (const char *) fetch_indirect_string (uvalue); | |
2264 | break; | |
2265 | case DW_FORM_GNU_str_index: | |
2266 | dwo_name = fetch_indexed_string (uvalue, this_set, offset_size, FALSE); | |
2267 | break; | |
2268 | case DW_FORM_string: | |
2269 | dwo_name = (const char *) orig_data; | |
2270 | break; | |
2271 | default: | |
2272 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2273 | get_FORM_name (form), get_AT_name (attribute)); | |
2274 | dwo_name = _("<unknown>"); | |
2275 | break; | |
2276 | } | |
2277 | break; | |
2278 | ||
2279 | case DW_AT_comp_dir: | |
2280 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2281 | if (need_dwo_info) | |
2282 | switch (form) | |
2283 | { | |
2284 | case DW_FORM_strp: | |
2285 | dwo_dir = (const char *) fetch_indirect_string (uvalue); | |
2286 | break; | |
2287 | case DW_FORM_line_strp: | |
2288 | dwo_dir = (const char *) fetch_indirect_line_string (uvalue); | |
2289 | break; | |
2290 | case DW_FORM_GNU_str_index: | |
2291 | dwo_dir = fetch_indexed_string (uvalue, this_set, offset_size, FALSE); | |
2292 | break; | |
2293 | case DW_FORM_string: | |
2294 | dwo_dir = (const char *) orig_data; | |
2295 | break; | |
2296 | default: | |
2297 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2298 | get_FORM_name (form), get_AT_name (attribute)); | |
2299 | dwo_dir = _("<unknown>"); | |
2300 | break; | |
2301 | } | |
2302 | break; | |
2303 | ||
2304 | case DW_AT_GNU_dwo_id: | |
2305 | if (need_dwo_info) | |
2306 | switch (form) | |
2307 | { | |
2308 | case DW_FORM_data8: | |
2309 | dwo_id = data - 8; | |
2310 | dwo_id_len = 8; | |
2311 | break; | |
2312 | default: | |
2313 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2314 | get_FORM_name (form), get_AT_name (attribute)); | |
2315 | dwo_id = NULL; | |
2316 | break; | |
2317 | } | |
2318 | break; | |
2319 | ||
19e6b90e L |
2320 | default: |
2321 | break; | |
2322 | } | |
2323 | } | |
2324 | ||
4ccf1e31 | 2325 | if (do_loc || attribute == 0) |
19e6b90e L |
2326 | return data; |
2327 | ||
ec4d4525 | 2328 | /* For some attributes we can display further information. */ |
19e6b90e L |
2329 | switch (attribute) |
2330 | { | |
2331 | case DW_AT_inline: | |
2e9e81a8 | 2332 | printf ("\t"); |
19e6b90e L |
2333 | switch (uvalue) |
2334 | { | |
2335 | case DW_INL_not_inlined: | |
2336 | printf (_("(not inlined)")); | |
2337 | break; | |
2338 | case DW_INL_inlined: | |
2339 | printf (_("(inlined)")); | |
2340 | break; | |
2341 | case DW_INL_declared_not_inlined: | |
2342 | printf (_("(declared as inline but ignored)")); | |
2343 | break; | |
2344 | case DW_INL_declared_inlined: | |
2345 | printf (_("(declared as inline and inlined)")); | |
2346 | break; | |
2347 | default: | |
47704ddf KT |
2348 | printf (_(" (Unknown inline attribute value: %s)"), |
2349 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2350 | break; |
2351 | } | |
2352 | break; | |
2353 | ||
2354 | case DW_AT_language: | |
2e9e81a8 | 2355 | printf ("\t"); |
19e6b90e L |
2356 | switch (uvalue) |
2357 | { | |
4b78141a | 2358 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2359 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2360 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2361 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2362 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2363 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2364 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2365 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2366 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2367 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2368 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2369 | /* DWARF 2.1 values. */ |
4b78141a | 2370 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2371 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2372 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2373 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2374 | /* DWARF 3 values. */ |
2375 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2376 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2377 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2378 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2379 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2380 | /* DWARF 4 values. */ |
2381 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 2382 | /* DWARF 5 values. */ |
2008a0db | 2383 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 2384 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
2385 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
2386 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
2387 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 2388 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
2389 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
2390 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 2391 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
2392 | case DW_LANG_Swift: printf ("(Swift)"); break; |
2393 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
2394 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 2395 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2396 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2397 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 2398 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
2399 | /* MIPS extension. */ |
2400 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2401 | /* UPC extension. */ | |
2402 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2403 | default: | |
4b78141a | 2404 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2405 | printf (_("(implementation defined: %s)"), |
467c65bc | 2406 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2407 | else |
9cf03b7e | 2408 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2409 | break; |
2410 | } | |
2411 | break; | |
2412 | ||
2413 | case DW_AT_encoding: | |
2e9e81a8 | 2414 | printf ("\t"); |
19e6b90e L |
2415 | switch (uvalue) |
2416 | { | |
2417 | case DW_ATE_void: printf ("(void)"); break; | |
2418 | case DW_ATE_address: printf ("(machine address)"); break; | |
2419 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2420 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2421 | case DW_ATE_float: printf ("(float)"); break; | |
2422 | case DW_ATE_signed: printf ("(signed)"); break; | |
2423 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2424 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2425 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2426 | /* DWARF 2.1 values: */ |
19e6b90e L |
2427 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2428 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2429 | /* DWARF 3 values: */ |
2430 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2431 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2432 | case DW_ATE_edited: printf ("(edited)"); break; | |
2433 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2434 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
2435 | /* DWARF 4 values: */ |
2436 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
2437 | /* DWARF 5 values: */ | |
2438 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
2439 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
2440 | ||
e2a0d921 NC |
2441 | /* HP extensions: */ |
2442 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2443 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2444 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2445 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2446 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2447 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2448 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
2449 | ||
19e6b90e L |
2450 | default: |
2451 | if (uvalue >= DW_ATE_lo_user | |
2452 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2453 | printf (_("(user defined type)")); |
19e6b90e | 2454 | else |
9cf03b7e | 2455 | printf (_("(unknown type)")); |
19e6b90e L |
2456 | break; |
2457 | } | |
2458 | break; | |
2459 | ||
2460 | case DW_AT_accessibility: | |
2e9e81a8 | 2461 | printf ("\t"); |
19e6b90e L |
2462 | switch (uvalue) |
2463 | { | |
2464 | case DW_ACCESS_public: printf ("(public)"); break; | |
2465 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2466 | case DW_ACCESS_private: printf ("(private)"); break; | |
2467 | default: | |
9cf03b7e | 2468 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2469 | break; |
2470 | } | |
2471 | break; | |
2472 | ||
2473 | case DW_AT_visibility: | |
2e9e81a8 | 2474 | printf ("\t"); |
19e6b90e L |
2475 | switch (uvalue) |
2476 | { | |
2477 | case DW_VIS_local: printf ("(local)"); break; | |
2478 | case DW_VIS_exported: printf ("(exported)"); break; | |
2479 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2480 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2481 | } |
2482 | break; | |
2483 | ||
04914e37 NC |
2484 | case DW_AT_endianity: |
2485 | printf ("\t"); | |
2486 | switch (uvalue) | |
2487 | { | |
2488 | case DW_END_default: printf ("(default)"); break; | |
2489 | case DW_END_big: printf ("(big)"); break; | |
2490 | case DW_END_little: printf ("(little)"); break; | |
2491 | default: | |
2492 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
2493 | printf (_("(user specified)")); | |
2494 | else | |
2495 | printf (_("(unknown endianity)")); | |
2496 | break; | |
2497 | } | |
2498 | break; | |
2499 | ||
19e6b90e | 2500 | case DW_AT_virtuality: |
2e9e81a8 | 2501 | printf ("\t"); |
19e6b90e L |
2502 | switch (uvalue) |
2503 | { | |
2504 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2505 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2506 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2507 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2508 | } |
2509 | break; | |
2510 | ||
2511 | case DW_AT_identifier_case: | |
2e9e81a8 | 2512 | printf ("\t"); |
19e6b90e L |
2513 | switch (uvalue) |
2514 | { | |
2515 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2516 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2517 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2518 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2519 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2520 | } |
2521 | break; | |
2522 | ||
2523 | case DW_AT_calling_convention: | |
2e9e81a8 | 2524 | printf ("\t"); |
19e6b90e L |
2525 | switch (uvalue) |
2526 | { | |
2527 | case DW_CC_normal: printf ("(normal)"); break; | |
2528 | case DW_CC_program: printf ("(program)"); break; | |
2529 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
2530 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
2531 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
2532 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
2533 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
2534 | default: |
2535 | if (uvalue >= DW_CC_lo_user | |
2536 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2537 | printf (_("(user defined)")); |
19e6b90e | 2538 | else |
9cf03b7e | 2539 | printf (_("(unknown convention)")); |
19e6b90e L |
2540 | } |
2541 | break; | |
2542 | ||
2543 | case DW_AT_ordering: | |
2e9e81a8 | 2544 | printf ("\t"); |
19e6b90e L |
2545 | switch (uvalue) |
2546 | { | |
04914e37 | 2547 | case 255: |
9cf03b7e | 2548 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2549 | case 0: printf ("(row major)"); break; |
2550 | case 1: printf ("(column major)"); break; | |
2551 | } | |
2552 | break; | |
2553 | ||
04914e37 NC |
2554 | case DW_AT_decimal_sign: |
2555 | printf ("\t"); | |
2556 | switch (uvalue) | |
2557 | { | |
2558 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
2559 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
2560 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
2561 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
2562 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
2563 | default: printf (_("(unrecognised)")); break; | |
2564 | } | |
2565 | break; | |
2566 | ||
2567 | case DW_AT_defaulted: | |
2568 | printf ("\t"); | |
2569 | switch (uvalue) | |
2570 | { | |
2571 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
2572 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
2573 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
2574 | default: printf (_("(unrecognised)")); break; | |
2575 | } | |
2576 | break; | |
2577 | ||
2578 | case DW_AT_discr_list: | |
2579 | printf ("\t"); | |
2580 | switch (uvalue) | |
2581 | { | |
2582 | case DW_DSC_label: printf (_("(label)")); break; | |
2583 | case DW_DSC_range: printf (_("(range)")); break; | |
2584 | default: printf (_("(unrecognised)")); break; | |
2585 | } | |
2586 | break; | |
2587 | ||
19e6b90e L |
2588 | case DW_AT_frame_base: |
2589 | have_frame_base = 1; | |
1a0670f3 | 2590 | /* Fall through. */ |
19e6b90e | 2591 | case DW_AT_location: |
e2a0d921 NC |
2592 | case DW_AT_string_length: |
2593 | case DW_AT_return_addr: | |
19e6b90e L |
2594 | case DW_AT_data_member_location: |
2595 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2596 | case DW_AT_segment: |
2597 | case DW_AT_static_link: | |
2598 | case DW_AT_use_location: | |
bc0a77d2 | 2599 | case DW_AT_call_value: |
629e7ca8 | 2600 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2601 | case DW_AT_call_data_value: |
629e7ca8 | 2602 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2603 | case DW_AT_call_target: |
629e7ca8 | 2604 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2605 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2606 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 2607 | if ((dwarf_version < 4 |
b4eb7656 | 2608 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2609 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 2610 | printf (_(" (location list)")); |
e2a0d921 | 2611 | /* Fall through. */ |
19e6b90e L |
2612 | case DW_AT_allocated: |
2613 | case DW_AT_associated: | |
2614 | case DW_AT_data_location: | |
2615 | case DW_AT_stride: | |
2616 | case DW_AT_upper_bound: | |
cecf136e | 2617 | case DW_AT_lower_bound: |
19e6b90e L |
2618 | if (block_start) |
2619 | { | |
2620 | int need_frame_base; | |
2621 | ||
2e9e81a8 | 2622 | printf ("\t("); |
19e6b90e L |
2623 | need_frame_base = decode_location_expression (block_start, |
2624 | pointer_size, | |
b7807392 JJ |
2625 | offset_size, |
2626 | dwarf_version, | |
19e6b90e | 2627 | uvalue, |
f1c4cc75 | 2628 | cu_offset, section); |
19e6b90e L |
2629 | printf (")"); |
2630 | if (need_frame_base && !have_frame_base) | |
2631 | printf (_(" [without DW_AT_frame_base]")); | |
2632 | } | |
19e6b90e L |
2633 | break; |
2634 | ||
c54207d3 NC |
2635 | case DW_AT_data_bit_offset: |
2636 | case DW_AT_byte_size: | |
2637 | case DW_AT_bit_size: | |
2638 | case DW_AT_string_length_byte_size: | |
2639 | case DW_AT_string_length_bit_size: | |
2640 | case DW_AT_bit_stride: | |
2641 | if (form == DW_FORM_exprloc) | |
2642 | { | |
2643 | printf ("\t("); | |
2644 | (void) decode_location_expression (block_start, pointer_size, | |
2645 | offset_size, dwarf_version, | |
2646 | uvalue, cu_offset, section); | |
2647 | printf (")"); | |
2648 | } | |
2649 | break; | |
2650 | ||
ec4d4525 NC |
2651 | case DW_AT_import: |
2652 | { | |
a081f3cd JJ |
2653 | if (form == DW_FORM_ref_sig8 |
2654 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 2655 | break; |
2b6f5997 | 2656 | |
ec4d4525 NC |
2657 | if (form == DW_FORM_ref1 |
2658 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
2659 | || form == DW_FORM_ref4 |
2660 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
2661 | uvalue += cu_offset; |
2662 | ||
6e3d6dc1 | 2663 | if (uvalue >= section->size) |
f3853b34 | 2664 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
2665 | dwarf_vmatoa ("x", uvalue), |
2666 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
2667 | else |
2668 | { | |
2669 | unsigned long abbrev_number; | |
2670 | abbrev_entry * entry; | |
2671 | ||
f6f0e17b | 2672 | abbrev_number = read_uleb128 (section->start + uvalue, NULL, end); |
cecf136e | 2673 | |
2e9e81a8 | 2674 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
2675 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
2676 | use different abbrev table, and we don't track .debug_info chunks | |
2677 | yet. */ | |
2678 | if (form != DW_FORM_ref_addr) | |
2679 | { | |
2680 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
2681 | if (entry->entry == abbrev_number) | |
2682 | break; | |
2683 | if (entry != NULL) | |
2684 | printf (" (%s)", get_TAG_name (entry->tag)); | |
2685 | } | |
6e3d6dc1 NC |
2686 | printf ("]"); |
2687 | } | |
ec4d4525 NC |
2688 | } |
2689 | break; | |
2690 | ||
19e6b90e L |
2691 | default: |
2692 | break; | |
2693 | } | |
2694 | ||
2695 | return data; | |
2696 | } | |
2697 | ||
19e6b90e | 2698 | static unsigned char * |
dda8d76d NC |
2699 | read_and_display_attr (unsigned long attribute, |
2700 | unsigned long form, | |
2701 | dwarf_signed_vma implicit_const, | |
2702 | unsigned char * data, | |
2703 | unsigned char * end, | |
2704 | dwarf_vma cu_offset, | |
2705 | dwarf_vma pointer_size, | |
2706 | dwarf_vma offset_size, | |
2707 | int dwarf_version, | |
2708 | debug_info * debug_info_p, | |
2709 | int do_loc, | |
2710 | struct dwarf_section * section, | |
2711 | struct cu_tu_set * this_set) | |
19e6b90e L |
2712 | { |
2713 | if (!do_loc) | |
750f03b7 | 2714 | printf (" %-18s:", get_AT_name (attribute)); |
77145576 | 2715 | data = read_and_display_attr_value (attribute, form, implicit_const, data, end, |
f6f0e17b | 2716 | cu_offset, pointer_size, offset_size, |
19e6b90e | 2717 | dwarf_version, debug_info_p, |
ef0b5f1c | 2718 | do_loc, section, this_set, ' '); |
19e6b90e L |
2719 | if (!do_loc) |
2720 | printf ("\n"); | |
2721 | return data; | |
2722 | } | |
2723 | ||
dda8d76d NC |
2724 | /* Like load_debug_section, but if the ordinary call fails, and we are |
2725 | following debug links, and we have been able to load a separate debug | |
2726 | info file, then attempt to load the requested section from the separate | |
2727 | file. */ | |
2728 | ||
2729 | static bfd_boolean | |
2730 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
2731 | void * data) | |
2732 | { | |
2733 | if (load_debug_section (sec_enum, data)) | |
2734 | { | |
2735 | if (data == separate_debug_file) | |
2736 | debug_displays[sec_enum].section.filename = separate_debug_filename; | |
2737 | ||
2738 | /* FIXME: We should check to see if there is a separate debug info file | |
2739 | that also contains this section, and if so, issue a warning. */ | |
2740 | return TRUE; | |
2741 | } | |
2742 | ||
2743 | if (do_follow_links && separate_debug_file != NULL) | |
2744 | if (load_debug_section (sec_enum, separate_debug_file)) | |
2745 | { | |
2746 | debug_displays[sec_enum].section.filename = separate_debug_filename; | |
2747 | return TRUE; | |
2748 | } | |
2749 | ||
2750 | return FALSE; | |
2751 | } | |
2752 | ||
2753 | static void | |
2754 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
2755 | { | |
2756 | if (raw) | |
2757 | { | |
2758 | if (do_follow_links && section->filename) | |
2759 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
2760 | section->name, section->filename); | |
2761 | else | |
2762 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
2763 | } | |
2764 | else | |
2765 | { | |
2766 | if (do_follow_links && section->filename) | |
2767 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
2768 | section->name, section->filename); | |
2769 | else | |
2770 | printf (_("Contents of the %s section:\n\n"), section->name); | |
2771 | } | |
2772 | } | |
2773 | ||
d85bf2ba NC |
2774 | /* Process the contents of a .debug_info section. |
2775 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
2776 | and we do not want to display anything to the user. | |
2777 | If do_types is TRUE, we are processing a .debug_types section instead of | |
2778 | a .debug_info section. | |
2779 | The information displayed is restricted by the values in DWARF_START_DIE | |
2780 | and DWARF_CUTOFF_LEVEL. | |
2781 | Returns TRUE upon success. Otherwise an error or warning message is | |
2782 | printed and FALSE is returned. */ | |
19e6b90e | 2783 | |
d85bf2ba NC |
2784 | static bfd_boolean |
2785 | process_debug_info (struct dwarf_section * section, | |
2786 | void * file, | |
2787 | enum dwarf_section_display_enum abbrev_sec, | |
2788 | bfd_boolean do_loc, | |
2789 | bfd_boolean do_types) | |
19e6b90e L |
2790 | { |
2791 | unsigned char *start = section->start; | |
2792 | unsigned char *end = start + section->size; | |
2793 | unsigned char *section_begin; | |
2794 | unsigned int unit; | |
2795 | unsigned int num_units = 0; | |
2796 | ||
2797 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2798 | && num_debug_info_entries == 0 |
2799 | && ! do_types) | |
19e6b90e | 2800 | { |
767221a9 | 2801 | dwarf_vma length; |
19e6b90e L |
2802 | |
2803 | /* First scan the section to get the number of comp units. */ | |
2804 | for (section_begin = start, num_units = 0; section_begin < end; | |
2805 | num_units ++) | |
2806 | { | |
2807 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
2808 | will be the length. For a 64-bit DWARF section, it'll be | |
2809 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 2810 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
2811 | |
2812 | if (length == 0xffffffff) | |
2813 | { | |
0c588247 | 2814 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
2815 | section_begin += length + 12; |
2816 | } | |
ec4d4525 NC |
2817 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
2818 | { | |
767221a9 NC |
2819 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
2820 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 2821 | return FALSE; |
ec4d4525 | 2822 | } |
19e6b90e L |
2823 | else |
2824 | section_begin += length + 4; | |
aca88567 NC |
2825 | |
2826 | /* Negative values are illegal, they may even cause infinite | |
2827 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
2828 | relocations to an object file, or if the file is corrupt. */ |
2829 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 2830 | { |
767221a9 NC |
2831 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
2832 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 2833 | return FALSE; |
aca88567 | 2834 | } |
19e6b90e L |
2835 | } |
2836 | ||
2837 | if (num_units == 0) | |
2838 | { | |
f41e4712 | 2839 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 2840 | return FALSE; |
19e6b90e L |
2841 | } |
2842 | ||
2843 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 2844 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 2845 | sizeof (* debug_information)); |
19e6b90e L |
2846 | if (debug_information == NULL) |
2847 | { | |
f41e4712 | 2848 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 2849 | num_units); |
82b1b41b | 2850 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 2851 | return FALSE; |
19e6b90e | 2852 | } |
d85bf2ba | 2853 | |
03a91817 NC |
2854 | /* PR 17531: file: 92ca3797. |
2855 | We cannot rely upon the debug_information array being initialised | |
2856 | before it is used. A corrupt file could easily contain references | |
2857 | to a unit for which information has not been made available. So | |
2858 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
2859 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
2860 | ||
82b1b41b | 2861 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
2862 | } |
2863 | ||
2864 | if (!do_loc) | |
2865 | { | |
dda8d76d NC |
2866 | load_debug_section_with_follow (str, file); |
2867 | load_debug_section_with_follow (line_str, file); | |
2868 | load_debug_section_with_follow (str_dwo, file); | |
2869 | load_debug_section_with_follow (str_index, file); | |
2870 | load_debug_section_with_follow (str_index_dwo, file); | |
2871 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e L |
2872 | } |
2873 | ||
dda8d76d | 2874 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 2875 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
2876 | { |
2877 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 2878 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 2879 | return FALSE; |
19e6b90e L |
2880 | } |
2881 | ||
dda8d76d NC |
2882 | if (!do_loc && dwarf_start_die == 0) |
2883 | introduce (section, FALSE); | |
2884 | ||
19e6b90e L |
2885 | for (section_begin = start, unit = 0; start < end; unit++) |
2886 | { | |
2887 | DWARF2_Internal_CompUnit compunit; | |
2888 | unsigned char *hdrptr; | |
19e6b90e | 2889 | unsigned char *tags; |
fd2f0033 | 2890 | int level, last_level, saved_level; |
467c65bc | 2891 | dwarf_vma cu_offset; |
e98fdf1a | 2892 | unsigned long sec_off; |
bf5117e3 | 2893 | unsigned int offset_size; |
19485196 | 2894 | unsigned int initial_length_size; |
74bc6052 CC |
2895 | dwarf_vma signature_high = 0; |
2896 | dwarf_vma signature_low = 0; | |
767221a9 | 2897 | dwarf_vma type_offset = 0; |
341f9135 CC |
2898 | struct cu_tu_set *this_set; |
2899 | dwarf_vma abbrev_base; | |
2900 | size_t abbrev_size; | |
19e6b90e L |
2901 | |
2902 | hdrptr = start; | |
2903 | ||
0c588247 | 2904 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
2905 | |
2906 | if (compunit.cu_length == 0xffffffff) | |
2907 | { | |
0c588247 | 2908 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
2909 | offset_size = 8; |
2910 | initial_length_size = 12; | |
2911 | } | |
2912 | else | |
2913 | { | |
2914 | offset_size = 4; | |
2915 | initial_length_size = 4; | |
2916 | } | |
2917 | ||
0c588247 | 2918 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
2919 | |
2920 | cu_offset = start - section_begin; | |
19e6b90e | 2921 | |
341f9135 CC |
2922 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
2923 | ||
77145576 JK |
2924 | if (compunit.cu_version < 5) |
2925 | { | |
2926 | compunit.cu_unit_type = DW_UT_compile; | |
2927 | /* Initialize it due to a false compiler warning. */ | |
2928 | compunit.cu_pointer_size = -1; | |
2929 | } | |
2930 | else | |
2931 | { | |
2932 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
2933 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
2934 | ||
2935 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
2936 | } | |
2937 | ||
0c588247 | 2938 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 2939 | |
341f9135 CC |
2940 | if (this_set == NULL) |
2941 | { | |
2942 | abbrev_base = 0; | |
2943 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
2944 | } | |
2945 | else | |
2946 | { | |
2947 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
2948 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
2949 | } | |
2950 | ||
77145576 JK |
2951 | if (compunit.cu_version < 5) |
2952 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
2953 | ||
f41e4712 NC |
2954 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
2955 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
2956 | { | |
2957 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
2958 | compunit.cu_pointer_size, offset_size); | |
2959 | compunit.cu_pointer_size = offset_size; | |
2960 | } | |
2b6f5997 CC |
2961 | |
2962 | if (do_types) | |
b4eb7656 | 2963 | { |
0c588247 | 2964 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 2965 | hdrptr += 8; |
0c588247 | 2966 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 2967 | } |
2b6f5997 | 2968 | |
ae7e7825 NC |
2969 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
2970 | + initial_length_size)) | |
2971 | { | |
2972 | start = section_begin + cu_offset + compunit.cu_length | |
2973 | + initial_length_size; | |
2974 | continue; | |
2975 | } | |
2976 | ||
19e6b90e | 2977 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
2978 | && num_debug_info_entries == 0 |
2979 | && ! do_types) | |
19e6b90e L |
2980 | { |
2981 | debug_information [unit].cu_offset = cu_offset; | |
2982 | debug_information [unit].pointer_size | |
2983 | = compunit.cu_pointer_size; | |
b7807392 JJ |
2984 | debug_information [unit].offset_size = offset_size; |
2985 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 2986 | debug_information [unit].base_address = 0; |
4723351a CC |
2987 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
2988 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
2989 | debug_information [unit].loc_offsets = NULL; |
2990 | debug_information [unit].have_frame_base = NULL; | |
2991 | debug_information [unit].max_loc_offsets = 0; | |
2992 | debug_information [unit].num_loc_offsets = 0; | |
2993 | debug_information [unit].range_lists = NULL; | |
2994 | debug_information [unit].max_range_lists= 0; | |
2995 | debug_information [unit].num_range_lists = 0; | |
2996 | } | |
2997 | ||
fd2f0033 | 2998 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 2999 | { |
47704ddf KT |
3000 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3001 | dwarf_vmatoa ("x", cu_offset)); | |
3002 | printf (_(" Length: 0x%s (%s)\n"), | |
3003 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3004 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3005 | printf (_(" Version: %d\n"), compunit.cu_version); |
7282333f AM |
3006 | printf (_(" Abbrev Offset: 0x%s\n"), |
3007 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3008 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3009 | if (do_types) |
3010 | { | |
74bc6052 CC |
3011 | char buf[64]; |
3012 | ||
3013 | printf (_(" Signature: 0x%s\n"), | |
3014 | dwarf_vmatoa64 (signature_high, signature_low, | |
3015 | buf, sizeof (buf))); | |
3016 | printf (_(" Type Offset: 0x%s\n"), | |
3017 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3018 | } |
341f9135 CC |
3019 | if (this_set != NULL) |
3020 | { | |
3021 | dwarf_vma *offsets = this_set->section_offsets; | |
3022 | size_t *sizes = this_set->section_sizes; | |
3023 | ||
3024 | printf (_(" Section contributions:\n")); | |
3025 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3026 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3027 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3028 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3029 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3030 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3031 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3032 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3033 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3034 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3035 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3036 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3037 | } | |
19e6b90e L |
3038 | } |
3039 | ||
e98fdf1a AM |
3040 | sec_off = cu_offset + initial_length_size; |
3041 | if (sec_off + compunit.cu_length < sec_off | |
3042 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3043 | { |
e98fdf1a AM |
3044 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3045 | section->name, | |
3046 | (unsigned long) cu_offset, | |
19485196 NC |
3047 | dwarf_vmatoa ("x", compunit.cu_length)); |
3048 | num_units = unit; | |
3049 | break; | |
3050 | } | |
3051 | ||
460c89ff NS |
3052 | tags = hdrptr; |
3053 | start += compunit.cu_length + initial_length_size; | |
3054 | ||
77145576 | 3055 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3056 | { |
47704ddf KT |
3057 | warn (_("CU at offset %s contains corrupt or " |
3058 | "unsupported version number: %d.\n"), | |
3059 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3060 | continue; |
3061 | } | |
3062 | ||
77145576 JK |
3063 | if (compunit.cu_unit_type != DW_UT_compile |
3064 | && compunit.cu_unit_type != DW_UT_type) | |
3065 | { | |
3066 | warn (_("CU at offset %s contains corrupt or " | |
3067 | "unsupported unit type: %d.\n"), | |
3068 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3069 | continue; | |
3070 | } | |
3071 | ||
19e6b90e L |
3072 | free_abbrevs (); |
3073 | ||
d493b283 | 3074 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3075 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3076 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3077 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3078 | (unsigned long) abbrev_size); |
b4eb7656 | 3079 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3080 | else if ((abbrev_base + abbrev_size) |
3081 | > debug_displays [abbrev_sec].section.size) | |
3082 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3083 | (unsigned long) abbrev_base + abbrev_size, | |
3084 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
3085 | else |
3086 | process_abbrev_section | |
341f9135 CC |
3087 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
3088 | + abbrev_base + compunit.cu_abbrev_offset), | |
3089 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3090 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
3091 | |
3092 | level = 0; | |
fd2f0033 TT |
3093 | last_level = level; |
3094 | saved_level = -1; | |
19e6b90e L |
3095 | while (tags < start) |
3096 | { | |
3097 | unsigned int bytes_read; | |
3098 | unsigned long abbrev_number; | |
ec4d4525 | 3099 | unsigned long die_offset; |
19e6b90e L |
3100 | abbrev_entry *entry; |
3101 | abbrev_attr *attr; | |
fd2f0033 | 3102 | int do_printing = 1; |
19e6b90e | 3103 | |
ec4d4525 NC |
3104 | die_offset = tags - section_begin; |
3105 | ||
f6f0e17b | 3106 | abbrev_number = read_uleb128 (tags, & bytes_read, start); |
19e6b90e L |
3107 | tags += bytes_read; |
3108 | ||
eb7cc021 JK |
3109 | /* A null DIE marks the end of a list of siblings or it may also be |
3110 | a section padding. */ | |
19e6b90e L |
3111 | if (abbrev_number == 0) |
3112 | { | |
eb7cc021 JK |
3113 | /* Check if it can be a section padding for the last CU. */ |
3114 | if (level == 0 && start == end) | |
3115 | { | |
3116 | unsigned char *chk; | |
3117 | ||
3118 | for (chk = tags; chk < start; chk++) | |
3119 | if (*chk != 0) | |
3120 | break; | |
3121 | if (chk == start) | |
3122 | break; | |
3123 | } | |
3124 | ||
4337774f TT |
3125 | if (!do_loc && die_offset >= dwarf_start_die |
3126 | && (dwarf_cutoff_level == -1 | |
3127 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3128 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3129 | level, die_offset); | |
3130 | ||
19e6b90e | 3131 | --level; |
ec4d4525 NC |
3132 | if (level < 0) |
3133 | { | |
3134 | static unsigned num_bogus_warns = 0; | |
3135 | ||
3136 | if (num_bogus_warns < 3) | |
3137 | { | |
4723351a CC |
3138 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3139 | die_offset, section->name); | |
ec4d4525 NC |
3140 | num_bogus_warns ++; |
3141 | if (num_bogus_warns == 3) | |
3142 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3143 | } | |
3144 | } | |
fd2f0033 | 3145 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3146 | return TRUE; |
19e6b90e L |
3147 | continue; |
3148 | } | |
3149 | ||
4b78141a | 3150 | if (!do_loc) |
fd2f0033 TT |
3151 | { |
3152 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3153 | do_printing = 0; | |
3154 | else | |
3155 | { | |
3156 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3157 | saved_level = level; | |
3158 | do_printing = (dwarf_cutoff_level == -1 | |
3159 | || level < dwarf_cutoff_level); | |
3160 | if (do_printing) | |
3161 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3162 | level, die_offset, abbrev_number); | |
3163 | else if (dwarf_cutoff_level == -1 | |
3164 | || last_level < dwarf_cutoff_level) | |
3165 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3166 | last_level = level; | |
3167 | } | |
3168 | } | |
cecf136e | 3169 | |
19e6b90e L |
3170 | /* Scan through the abbreviation list until we reach the |
3171 | correct entry. */ | |
3172 | for (entry = first_abbrev; | |
3173 | entry && entry->entry != abbrev_number; | |
3174 | entry = entry->next) | |
3175 | continue; | |
3176 | ||
3177 | if (entry == NULL) | |
3178 | { | |
fd2f0033 | 3179 | if (!do_loc && do_printing) |
4b78141a NC |
3180 | { |
3181 | printf ("\n"); | |
3182 | fflush (stdout); | |
3183 | } | |
f3853b34 | 3184 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3185 | die_offset, abbrev_number); |
d85bf2ba | 3186 | return FALSE; |
19e6b90e L |
3187 | } |
3188 | ||
fd2f0033 | 3189 | if (!do_loc && do_printing) |
cc5914eb | 3190 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3191 | |
19e6b90e L |
3192 | switch (entry->tag) |
3193 | { | |
3194 | default: | |
3195 | need_base_address = 0; | |
3196 | break; | |
3197 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3198 | need_base_address = 1; |
3199 | need_dwo_info = do_loc; | |
19e6b90e L |
3200 | break; |
3201 | case DW_TAG_entry_point: | |
19e6b90e L |
3202 | case DW_TAG_subprogram: |
3203 | need_base_address = 0; | |
3204 | /* Assuming that there is no DW_AT_frame_base. */ | |
3205 | have_frame_base = 0; | |
3206 | break; | |
3207 | } | |
3208 | ||
9f272209 AO |
3209 | debug_info *debug_info_p = |
3210 | (debug_information && unit < alloc_num_debug_info_entries) | |
3211 | ? debug_information + unit : NULL; | |
3212 | ||
3213 | assert (!debug_info_p | |
3214 | || (debug_info_p->num_loc_offsets | |
3215 | == debug_info_p->num_loc_views)); | |
3216 | ||
399c99f7 L |
3217 | for (attr = entry->first_attr; |
3218 | attr && attr->attribute; | |
3219 | attr = attr->next) | |
4b78141a | 3220 | { |
fd2f0033 | 3221 | if (! do_loc && do_printing) |
4b78141a | 3222 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 TT |
3223 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
3224 | ||
4b78141a NC |
3225 | tags = read_and_display_attr (attr->attribute, |
3226 | attr->form, | |
77145576 | 3227 | attr->implicit_const, |
341f9135 | 3228 | tags, |
f6f0e17b | 3229 | end, |
341f9135 | 3230 | cu_offset, |
4b78141a NC |
3231 | compunit.cu_pointer_size, |
3232 | offset_size, | |
3233 | compunit.cu_version, | |
9f272209 | 3234 | debug_info_p, |
341f9135 CC |
3235 | do_loc || ! do_printing, |
3236 | section, | |
3237 | this_set); | |
4b78141a | 3238 | } |
cecf136e | 3239 | |
9f272209 AO |
3240 | /* If a locview attribute appears before a location one, |
3241 | make sure we don't associate it with an earlier | |
3242 | loclist. */ | |
3243 | if (debug_info_p) | |
3244 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3245 | { | |
3246 | case 1: | |
3247 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3248 | debug_info_p->num_loc_views++; | |
3249 | assert (debug_info_p->num_loc_views | |
3250 | == debug_info_p->num_loc_offsets); | |
3251 | break; | |
3252 | ||
3253 | case 0: | |
3254 | break; | |
3255 | ||
3256 | case -1: | |
3257 | warn(_("DIE has locviews without loclist\n")); | |
3258 | debug_info_p->num_loc_views--; | |
3259 | break; | |
3260 | ||
3261 | default: | |
3262 | assert (0); | |
3263 | } | |
3264 | ||
b4eb7656 AM |
3265 | if (entry->children) |
3266 | ++level; | |
3267 | } | |
19e6b90e | 3268 | } |
cecf136e | 3269 | |
19e6b90e L |
3270 | /* Set num_debug_info_entries here so that it can be used to check if |
3271 | we need to process .debug_loc and .debug_ranges sections. */ | |
3272 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3273 | && num_debug_info_entries == 0 |
3274 | && ! do_types) | |
82b1b41b | 3275 | { |
b4eb7656 | 3276 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
3277 | num_debug_info_entries = alloc_num_debug_info_entries; |
3278 | else | |
3279 | num_debug_info_entries = num_units; | |
3280 | } | |
cecf136e | 3281 | |
19e6b90e | 3282 | if (!do_loc) |
467c65bc | 3283 | printf ("\n"); |
cecf136e | 3284 | |
d85bf2ba | 3285 | return TRUE; |
19e6b90e L |
3286 | } |
3287 | ||
3288 | /* Locate and scan the .debug_info section in the file and record the pointer | |
3289 | sizes and offsets for the compilation units in it. Usually an executable | |
3290 | will have just one pointer size, but this is not guaranteed, and so we try | |
3291 | not to make any assumptions. Returns zero upon failure, or the number of | |
3292 | compilation units upon success. */ | |
3293 | ||
3294 | static unsigned int | |
3295 | load_debug_info (void * file) | |
3296 | { | |
1febe64d | 3297 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 3298 | section then do not bother to repeat the task. */ |
cc86f28f | 3299 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
3300 | return 0; |
3301 | ||
19e6b90e L |
3302 | /* If we already have the information there is nothing else to do. */ |
3303 | if (num_debug_info_entries > 0) | |
3304 | return num_debug_info_entries; | |
3305 | ||
341f9135 | 3306 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 3307 | (void) load_cu_tu_indexes (file); |
341f9135 | 3308 | |
dda8d76d | 3309 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 3310 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 3311 | return num_debug_info_entries; |
82b1b41b | 3312 | |
dda8d76d | 3313 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 3314 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 3315 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 3316 | return num_debug_info_entries; |
1febe64d | 3317 | |
cc86f28f | 3318 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 3319 | return 0; |
19e6b90e L |
3320 | } |
3321 | ||
b40bf0a2 NC |
3322 | /* Read a DWARF .debug_line section header starting at DATA. |
3323 | Upon success returns an updated DATA pointer and the LINFO | |
3324 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
3325 | Otherwise returns NULL. */ | |
19e6b90e | 3326 | |
b40bf0a2 NC |
3327 | static unsigned char * |
3328 | read_debug_line_header (struct dwarf_section * section, | |
3329 | unsigned char * data, | |
3330 | unsigned char * end, | |
3331 | DWARF2_Internal_LineInfo * linfo, | |
3332 | unsigned char ** end_of_sequence) | |
3333 | { | |
3334 | unsigned char *hdrptr; | |
b40bf0a2 | 3335 | unsigned int initial_length_size; |
77145576 | 3336 | unsigned char address_size, segment_selector_size; |
19e6b90e | 3337 | |
b40bf0a2 NC |
3338 | /* Extract information from the Line Number Program Header. |
3339 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 3340 | hdrptr = data; |
19e6b90e | 3341 | |
b40bf0a2 NC |
3342 | /* Get and check the length of the block. */ |
3343 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 3344 | |
b40bf0a2 | 3345 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
3346 | { |
3347 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 3348 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 3349 | linfo->li_offset_size = 8; |
f41e4712 NC |
3350 | initial_length_size = 12; |
3351 | } | |
3352 | else | |
3353 | { | |
77145576 | 3354 | linfo->li_offset_size = 4; |
f41e4712 NC |
3355 | initial_length_size = 4; |
3356 | } | |
19e6b90e | 3357 | |
b40bf0a2 | 3358 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 3359 | { |
8fcc61b4 NC |
3360 | /* If the length field has a relocation against it, then we should |
3361 | not complain if it is inaccurate (and probably negative). This | |
3362 | happens in object files when the .debug_line section is actually | |
3363 | comprised of several different .debug_line.* sections, (some of | |
3364 | which may be removed by linker garbage collection), and a relocation | |
3365 | is used to compute the correct length once that is done. */ | |
77145576 | 3366 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 3367 | { |
8fcc61b4 | 3368 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
3369 | } |
3370 | else | |
3371 | { | |
8fcc61b4 NC |
3372 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
3373 | (long) linfo->li_length); | |
b40bf0a2 NC |
3374 | return NULL; |
3375 | } | |
f41e4712 | 3376 | } |
19e6b90e | 3377 | |
b40bf0a2 NC |
3378 | /* Get and check the version number. */ |
3379 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
3380 | ||
3381 | if (linfo->li_version != 2 | |
3382 | && linfo->li_version != 3 | |
77145576 JK |
3383 | && linfo->li_version != 4 |
3384 | && linfo->li_version != 5) | |
f41e4712 | 3385 | { |
77145576 JK |
3386 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
3387 | "is currently supported.\n")); | |
b40bf0a2 | 3388 | return NULL; |
f41e4712 | 3389 | } |
19e6b90e | 3390 | |
77145576 JK |
3391 | if (linfo->li_version >= 5) |
3392 | { | |
3393 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
3394 | ||
3395 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
3396 | if (segment_selector_size != 0) | |
3397 | { | |
3398 | warn (_("The %s section contains " | |
3399 | "unsupported segment selector size: %d.\n"), | |
3400 | section->name, segment_selector_size); | |
3401 | return 0; | |
3402 | } | |
3403 | } | |
3404 | ||
3405 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
3406 | linfo->li_offset_size, end); | |
b40bf0a2 | 3407 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 3408 | |
b40bf0a2 | 3409 | if (linfo->li_version >= 4) |
f41e4712 | 3410 | { |
b40bf0a2 | 3411 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 3412 | |
b40bf0a2 | 3413 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
3414 | { |
3415 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 3416 | return NULL; |
a233b20c | 3417 | } |
f41e4712 NC |
3418 | } |
3419 | else | |
b40bf0a2 | 3420 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 3421 | |
b40bf0a2 | 3422 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 3423 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
3424 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
3425 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 3426 | |
b40bf0a2 | 3427 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 3428 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
3429 | if (* end_of_sequence > end) |
3430 | { | |
4c219c2e AM |
3431 | warn (_("Line length %s extends beyond end of section\n"), |
3432 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
3433 | * end_of_sequence = end; |
3434 | return NULL; | |
3435 | } | |
3436 | ||
b40bf0a2 NC |
3437 | return hdrptr; |
3438 | } | |
19e6b90e | 3439 | |
77145576 | 3440 | static unsigned char * |
dda8d76d NC |
3441 | display_formatted_table (unsigned char * data, |
3442 | unsigned char * start, | |
3443 | unsigned char * end, | |
3444 | const DWARF2_Internal_LineInfo * linfo, | |
3445 | struct dwarf_section * section, | |
7b8d9e8c | 3446 | bfd_boolean is_dir) |
77145576 JK |
3447 | { |
3448 | unsigned char *format_start, format_count, *format, formati; | |
3449 | dwarf_vma data_count, datai; | |
3450 | unsigned int bytes_read, namepass, last_entry = 0; | |
3451 | ||
3452 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3453 | format_start = data; | |
3454 | for (formati = 0; formati < format_count; formati++) | |
3455 | { | |
3456 | read_uleb128 (data, & bytes_read, end); | |
3457 | data += bytes_read; | |
3458 | read_uleb128 (data, & bytes_read, end); | |
3459 | data += bytes_read; | |
3460 | if (data == end) | |
3461 | { | |
7b8d9e8c AM |
3462 | if (is_dir) |
3463 | warn (_("Corrupt directory format table entry\n")); | |
3464 | else | |
3465 | warn (_("Corrupt file name format table entry\n")); | |
77145576 JK |
3466 | return data; |
3467 | } | |
3468 | } | |
3469 | ||
3470 | data_count = read_uleb128 (data, & bytes_read, end); | |
3471 | data += bytes_read; | |
3472 | if (data == end) | |
3473 | { | |
7b8d9e8c AM |
3474 | if (is_dir) |
3475 | warn (_("Corrupt directory list\n")); | |
3476 | else | |
3477 | warn (_("Corrupt file name list\n")); | |
77145576 JK |
3478 | return data; |
3479 | } | |
3480 | ||
3481 | if (data_count == 0) | |
3482 | { | |
7b8d9e8c AM |
3483 | if (is_dir) |
3484 | printf (_("\n The Directory Table is empty.\n")); | |
3485 | else | |
3486 | printf (_("\n The File Name Table is empty.\n")); | |
77145576 JK |
3487 | return data; |
3488 | } | |
3489 | ||
7b8d9e8c AM |
3490 | if (is_dir) |
3491 | printf (_("\n The Directory Table (offset 0x%lx):\n"), | |
3492 | (long) (data - start)); | |
3493 | else | |
3494 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3495 | (long) (data - start)); | |
77145576 JK |
3496 | |
3497 | printf (_(" Entry")); | |
3498 | /* Delay displaying name as the last entry for better screen layout. */ | |
3499 | for (namepass = 0; namepass < 2; namepass++) | |
3500 | { | |
3501 | format = format_start; | |
3502 | for (formati = 0; formati < format_count; formati++) | |
3503 | { | |
3504 | dwarf_vma content_type; | |
3505 | ||
3506 | content_type = read_uleb128 (format, & bytes_read, end); | |
3507 | format += bytes_read; | |
3508 | if ((content_type == DW_LNCT_path) == (namepass == 1)) | |
3509 | switch (content_type) | |
3510 | { | |
3511 | case DW_LNCT_path: | |
3512 | printf (_("\tName")); | |
3513 | break; | |
3514 | case DW_LNCT_directory_index: | |
3515 | printf (_("\tDir")); | |
3516 | break; | |
3517 | case DW_LNCT_timestamp: | |
3518 | printf (_("\tTime")); | |
3519 | break; | |
3520 | case DW_LNCT_size: | |
3521 | printf (_("\tSize")); | |
3522 | break; | |
3523 | case DW_LNCT_MD5: | |
3524 | printf (_("\tMD5")); | |
3525 | break; | |
3526 | default: | |
3527 | printf (_("\t(Unknown format content type %s)"), | |
3528 | dwarf_vmatoa ("u", content_type)); | |
3529 | } | |
3530 | read_uleb128 (format, & bytes_read, end); | |
3531 | format += bytes_read; | |
3532 | } | |
3533 | } | |
3534 | putchar ('\n'); | |
3535 | ||
3536 | for (datai = 0; datai < data_count; datai++) | |
3537 | { | |
3538 | unsigned char *datapass = data; | |
3539 | ||
3540 | printf (" %d", last_entry++); | |
3541 | /* Delay displaying name as the last entry for better screen layout. */ | |
3542 | for (namepass = 0; namepass < 2; namepass++) | |
3543 | { | |
3544 | format = format_start; | |
3545 | data = datapass; | |
3546 | for (formati = 0; formati < format_count; formati++) | |
3547 | { | |
3548 | dwarf_vma content_type, form; | |
3549 | ||
3550 | content_type = read_uleb128 (format, & bytes_read, end); | |
3551 | format += bytes_read; | |
3552 | form = read_uleb128 (format, & bytes_read, end); | |
3553 | format += bytes_read; | |
3554 | data = read_and_display_attr_value (0, form, 0, data, end, 0, 0, | |
3555 | linfo->li_offset_size, | |
3556 | linfo->li_version, NULL, | |
3557 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
3558 | section, NULL, '\t'); | |
3559 | } | |
3560 | } | |
3561 | if (data == end) | |
3562 | { | |
7b8d9e8c AM |
3563 | if (is_dir) |
3564 | warn (_("Corrupt directory entries list\n")); | |
3565 | else | |
3566 | warn (_("Corrupt file name entries list\n")); | |
77145576 JK |
3567 | return data; |
3568 | } | |
3569 | putchar ('\n'); | |
3570 | } | |
3571 | return data; | |
3572 | } | |
3573 | ||
b40bf0a2 | 3574 | static int |
dda8d76d NC |
3575 | display_debug_lines_raw (struct dwarf_section * section, |
3576 | unsigned char * data, | |
3577 | unsigned char * end, | |
3578 | void * file) | |
b40bf0a2 NC |
3579 | { |
3580 | unsigned char *start = section->start; | |
ba8826a8 | 3581 | int verbose_view = 0; |
19e6b90e | 3582 | |
dda8d76d | 3583 | introduce (section, TRUE); |
19e6b90e | 3584 | |
b40bf0a2 NC |
3585 | while (data < end) |
3586 | { | |
3587 | static DWARF2_Internal_LineInfo saved_linfo; | |
3588 | DWARF2_Internal_LineInfo linfo; | |
3589 | unsigned char *standard_opcodes; | |
3590 | unsigned char *end_of_sequence; | |
fe59e83d | 3591 | int i; |
19e6b90e | 3592 | |
4925cdd7 NC |
3593 | if (const_strneq (section->name, ".debug_line.") |
3594 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3595 | These are full debug_line sections. */ | |
3596 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 3597 | { |
b40bf0a2 NC |
3598 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
3599 | section containing just the Line Number Statements. They are | |
3600 | created by the assembler and intended to be used alongside gcc's | |
3601 | -ffunction-sections command line option. When the linker's | |
3602 | garbage collection decides to discard a .text.<foo> section it | |
3603 | can then also discard the line number information in .debug_line.<foo>. | |
3604 | ||
4925cdd7 | 3605 | Since the section is a fragment it does not have the details |
b40bf0a2 | 3606 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 3607 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
3608 | end_of_sequence = end; |
3609 | standard_opcodes = NULL; | |
3610 | linfo = saved_linfo; | |
058037d3 NC |
3611 | /* PR 17531: file: 0522b371. */ |
3612 | if (linfo.li_line_range == 0) | |
3613 | { | |
1306a742 | 3614 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3615 | return 0; |
3616 | } | |
b40bf0a2 | 3617 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3618 | } |
19e6b90e L |
3619 | else |
3620 | { | |
b40bf0a2 | 3621 | unsigned char * hdrptr; |
19e6b90e | 3622 | |
b40bf0a2 NC |
3623 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3624 | & end_of_sequence)) == NULL) | |
3625 | return 0; | |
19e6b90e | 3626 | |
b40bf0a2 NC |
3627 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
3628 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
3629 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
77ef8654 | 3630 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
3631 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
3632 | if (linfo.li_version >= 4) | |
3633 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
3634 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
3635 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
3636 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
3637 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 3638 | |
0a9d414a NC |
3639 | /* PR 17512: file: 1665-6428-0.004. */ |
3640 | if (linfo.li_line_range == 0) | |
3641 | { | |
3642 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
3643 | linfo.li_line_range = 1; | |
3644 | } | |
77ef8654 | 3645 | |
b40bf0a2 | 3646 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3647 | |
b40bf0a2 NC |
3648 | /* Display the contents of the Opcodes table. */ |
3649 | standard_opcodes = hdrptr; | |
19e6b90e | 3650 | |
6937bb54 NC |
3651 | /* PR 17512: file: 002-417945-0.004. */ |
3652 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
3653 | { | |
3654 | warn (_("Line Base extends beyond end of section\n")); | |
3655 | return 0; | |
3656 | } | |
3657 | ||
b40bf0a2 | 3658 | printf (_("\n Opcodes:\n")); |
19e6b90e | 3659 | |
b40bf0a2 | 3660 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
3661 | printf (ngettext (" Opcode %d has %d arg\n", |
3662 | " Opcode %d has %d args\n", | |
3663 | standard_opcodes[i - 1]), | |
3664 | i, standard_opcodes[i - 1]); | |
19e6b90e | 3665 | |
b40bf0a2 NC |
3666 | /* Display the contents of the Directory table. */ |
3667 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 3668 | |
77145576 | 3669 | if (linfo.li_version >= 5) |
b40bf0a2 | 3670 | { |
dda8d76d | 3671 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 3672 | |
77145576 | 3673 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 3674 | TRUE); |
77145576 | 3675 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 3676 | FALSE); |
77145576 JK |
3677 | } |
3678 | else | |
3679 | { | |
3680 | if (*data == 0) | |
3681 | printf (_("\n The Directory Table is empty.\n")); | |
3682 | else | |
a233b20c | 3683 | { |
77145576 | 3684 | unsigned int last_dir_entry = 0; |
6937bb54 | 3685 | |
77145576 JK |
3686 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
3687 | (long)(data - start)); | |
19e6b90e | 3688 | |
77145576 JK |
3689 | while (data < end && *data != 0) |
3690 | { | |
3691 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 3692 | |
77145576 JK |
3693 | data += strnlen ((char *) data, end - data) + 1; |
3694 | } | |
19e6b90e | 3695 | |
77145576 JK |
3696 | /* PR 17512: file: 002-132094-0.004. */ |
3697 | if (data >= end - 1) | |
3698 | break; | |
3699 | } | |
19e6b90e | 3700 | |
77145576 JK |
3701 | /* Skip the NUL at the end of the table. */ |
3702 | data++; | |
19e6b90e | 3703 | |
77145576 JK |
3704 | /* Display the contents of the File Name table. */ |
3705 | if (*data == 0) | |
3706 | printf (_("\n The File Name Table is empty.\n")); | |
3707 | else | |
3708 | { | |
3709 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3710 | (long)(data - start)); | |
3711 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 3712 | |
77145576 | 3713 | while (data < end && *data != 0) |
b40bf0a2 | 3714 | { |
77145576 JK |
3715 | unsigned char *name; |
3716 | unsigned int bytes_read; | |
3717 | ||
3718 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
3719 | name = data; | |
3720 | data += strnlen ((char *) data, end - data) + 1; | |
3721 | ||
3722 | printf ("%s\t", | |
3723 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3724 | data += bytes_read; | |
3725 | printf ("%s\t", | |
3726 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3727 | data += bytes_read; | |
3728 | printf ("%s\t", | |
3729 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3730 | data += bytes_read; | |
3731 | printf ("%.*s\n", (int)(end - name), name); | |
3732 | ||
3733 | if (data == end) | |
3734 | { | |
3735 | warn (_("Corrupt file name table entry\n")); | |
3736 | break; | |
3737 | } | |
b40bf0a2 | 3738 | } |
a233b20c | 3739 | } |
77145576 JK |
3740 | |
3741 | /* Skip the NUL at the end of the table. */ | |
3742 | data++; | |
b40bf0a2 | 3743 | } |
19e6b90e | 3744 | |
b40bf0a2 NC |
3745 | putchar ('\n'); |
3746 | saved_linfo = linfo; | |
3747 | } | |
19e6b90e | 3748 | |
b40bf0a2 NC |
3749 | /* Now display the statements. */ |
3750 | if (data >= end_of_sequence) | |
3751 | printf (_(" No Line Number Statements.\n")); | |
3752 | else | |
3753 | { | |
3754 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 3755 | |
b40bf0a2 NC |
3756 | while (data < end_of_sequence) |
3757 | { | |
3758 | unsigned char op_code; | |
3759 | dwarf_signed_vma adv; | |
3760 | dwarf_vma uladv; | |
3761 | unsigned int bytes_read; | |
19e6b90e | 3762 | |
fe59e83d CC |
3763 | printf (" [0x%08lx]", (long)(data - start)); |
3764 | ||
b40bf0a2 | 3765 | op_code = *data++; |
19e6b90e | 3766 | |
b40bf0a2 | 3767 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 3768 | { |
b40bf0a2 NC |
3769 | op_code -= linfo.li_opcode_base; |
3770 | uladv = (op_code / linfo.li_line_range); | |
3771 | if (linfo.li_max_ops_per_insn == 1) | |
3772 | { | |
3773 | uladv *= linfo.li_min_insn_length; | |
3774 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
3775 | if (uladv) |
3776 | state_machine_regs.view = 0; | |
b40bf0a2 | 3777 | printf (_(" Special opcode %d: " |
ba8826a8 | 3778 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 3779 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
3780 | dwarf_vmatoa ("x", state_machine_regs.address), |
3781 | verbose_view && uladv | |
3782 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3783 | } |
3784 | else | |
3785 | { | |
ba8826a8 AO |
3786 | unsigned addrdelta |
3787 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
3788 | / linfo.li_max_ops_per_insn) |
3789 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
3790 | |
3791 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
3792 | state_machine_regs.op_index |
3793 | = (state_machine_regs.op_index + uladv) | |
3794 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
3795 | if (addrdelta) |
3796 | state_machine_regs.view = 0; | |
b40bf0a2 | 3797 | printf (_(" Special opcode %d: " |
ba8826a8 | 3798 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
3799 | op_code, dwarf_vmatoa ("u", uladv), |
3800 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
3801 | state_machine_regs.op_index, |
3802 | verbose_view && addrdelta | |
3803 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3804 | } |
3805 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
3806 | state_machine_regs.line += adv; | |
ba8826a8 | 3807 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 3808 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
3809 | if (verbose_view || state_machine_regs.view) |
3810 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
3811 | else | |
3812 | putchar ('\n'); | |
3813 | state_machine_regs.view++; | |
19e6b90e | 3814 | } |
b40bf0a2 NC |
3815 | else switch (op_code) |
3816 | { | |
3817 | case DW_LNS_extended_op: | |
3818 | data += process_extended_line_op (data, linfo.li_default_is_stmt, end); | |
3819 | break; | |
3820 | ||
3821 | case DW_LNS_copy: | |
ba8826a8 AO |
3822 | printf (_(" Copy")); |
3823 | if (verbose_view || state_machine_regs.view) | |
3824 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
3825 | else | |
3826 | putchar ('\n'); | |
3827 | state_machine_regs.view++; | |
b40bf0a2 NC |
3828 | break; |
3829 | ||
3830 | case DW_LNS_advance_pc: | |
3831 | uladv = read_uleb128 (data, & bytes_read, end); | |
3832 | data += bytes_read; | |
3833 | if (linfo.li_max_ops_per_insn == 1) | |
3834 | { | |
3835 | uladv *= linfo.li_min_insn_length; | |
3836 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
3837 | if (uladv) |
3838 | state_machine_regs.view = 0; | |
3839 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
b40bf0a2 | 3840 | dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
3841 | dwarf_vmatoa ("x", state_machine_regs.address), |
3842 | verbose_view && uladv | |
3843 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3844 | } |
3845 | else | |
3846 | { | |
ba8826a8 AO |
3847 | unsigned addrdelta |
3848 | = ((state_machine_regs.op_index + uladv) | |
3849 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 3850 | * linfo.li_min_insn_length; |
ba8826a8 AO |
3851 | state_machine_regs.address |
3852 | += addrdelta; | |
b40bf0a2 NC |
3853 | state_machine_regs.op_index |
3854 | = (state_machine_regs.op_index + uladv) | |
3855 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
3856 | if (addrdelta) |
3857 | state_machine_regs.view = 0; | |
3858 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
b40bf0a2 NC |
3859 | dwarf_vmatoa ("u", uladv), |
3860 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
3861 | state_machine_regs.op_index, |
3862 | verbose_view && addrdelta | |
3863 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3864 | } |
3865 | break; | |
3866 | ||
3867 | case DW_LNS_advance_line: | |
3868 | adv = read_sleb128 (data, & bytes_read, end); | |
3869 | data += bytes_read; | |
3870 | state_machine_regs.line += adv; | |
3871 | printf (_(" Advance Line by %s to %d\n"), | |
3872 | dwarf_vmatoa ("d", adv), | |
3873 | state_machine_regs.line); | |
3874 | break; | |
3875 | ||
3876 | case DW_LNS_set_file: | |
3877 | adv = read_uleb128 (data, & bytes_read, end); | |
3878 | data += bytes_read; | |
3879 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
3880 | dwarf_vmatoa ("d", adv)); | |
3881 | state_machine_regs.file = adv; | |
3882 | break; | |
3883 | ||
3884 | case DW_LNS_set_column: | |
3885 | uladv = read_uleb128 (data, & bytes_read, end); | |
3886 | data += bytes_read; | |
3887 | printf (_(" Set column to %s\n"), | |
3888 | dwarf_vmatoa ("u", uladv)); | |
3889 | state_machine_regs.column = uladv; | |
3890 | break; | |
3891 | ||
3892 | case DW_LNS_negate_stmt: | |
3893 | adv = state_machine_regs.is_stmt; | |
3894 | adv = ! adv; | |
3895 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
3896 | state_machine_regs.is_stmt = adv; | |
3897 | break; | |
3898 | ||
3899 | case DW_LNS_set_basic_block: | |
3900 | printf (_(" Set basic block\n")); | |
3901 | state_machine_regs.basic_block = 1; | |
3902 | break; | |
3903 | ||
3904 | case DW_LNS_const_add_pc: | |
3905 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
3906 | if (linfo.li_max_ops_per_insn) | |
3907 | { | |
3908 | uladv *= linfo.li_min_insn_length; | |
3909 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
3910 | if (uladv) |
3911 | state_machine_regs.view = 0; | |
3912 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
b40bf0a2 | 3913 | dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
3914 | dwarf_vmatoa ("x", state_machine_regs.address), |
3915 | verbose_view && uladv | |
3916 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3917 | } |
3918 | else | |
3919 | { | |
ba8826a8 AO |
3920 | unsigned addrdelta |
3921 | = ((state_machine_regs.op_index + uladv) | |
3922 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 3923 | * linfo.li_min_insn_length; |
ba8826a8 AO |
3924 | state_machine_regs.address |
3925 | += addrdelta; | |
b40bf0a2 NC |
3926 | state_machine_regs.op_index |
3927 | = (state_machine_regs.op_index + uladv) | |
3928 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
3929 | if (addrdelta) |
3930 | state_machine_regs.view = 0; | |
3931 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
b40bf0a2 NC |
3932 | dwarf_vmatoa ("u", uladv), |
3933 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
3934 | state_machine_regs.op_index, |
3935 | verbose_view && addrdelta | |
3936 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3937 | } |
3938 | break; | |
3939 | ||
3940 | case DW_LNS_fixed_advance_pc: | |
3941 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
3942 | state_machine_regs.address += uladv; | |
3943 | state_machine_regs.op_index = 0; | |
3944 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
3945 | dwarf_vmatoa ("u", uladv), | |
3946 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
ba8826a8 | 3947 | /* Do NOT reset view. */ |
b40bf0a2 NC |
3948 | break; |
3949 | ||
3950 | case DW_LNS_set_prologue_end: | |
3951 | printf (_(" Set prologue_end to true\n")); | |
3952 | break; | |
3953 | ||
3954 | case DW_LNS_set_epilogue_begin: | |
3955 | printf (_(" Set epilogue_begin to true\n")); | |
3956 | break; | |
3957 | ||
3958 | case DW_LNS_set_isa: | |
3959 | uladv = read_uleb128 (data, & bytes_read, end); | |
3960 | data += bytes_read; | |
3961 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
3962 | break; | |
3963 | ||
3964 | default: | |
3965 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
3966 | ||
3967 | if (standard_opcodes != NULL) | |
3968 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
3969 | { | |
3970 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
3971 | &bytes_read, end)), | |
3972 | i == 1 ? "" : ", "); | |
3973 | data += bytes_read; | |
3974 | } | |
3975 | putchar ('\n'); | |
3976 | break; | |
3977 | } | |
19e6b90e | 3978 | } |
b40bf0a2 | 3979 | putchar ('\n'); |
19e6b90e | 3980 | } |
19e6b90e L |
3981 | } |
3982 | ||
3983 | return 1; | |
3984 | } | |
3985 | ||
a262ae96 NC |
3986 | typedef struct |
3987 | { | |
467c65bc NC |
3988 | unsigned char *name; |
3989 | unsigned int directory_index; | |
3990 | unsigned int modification_date; | |
3991 | unsigned int length; | |
a262ae96 NC |
3992 | } File_Entry; |
3993 | ||
3994 | /* Output a decoded representation of the .debug_line section. */ | |
3995 | ||
3996 | static int | |
dda8d76d NC |
3997 | display_debug_lines_decoded (struct dwarf_section * section, |
3998 | unsigned char * data, | |
3999 | unsigned char * end, | |
4000 | void * fileptr) | |
a262ae96 | 4001 | { |
b40bf0a2 NC |
4002 | static DWARF2_Internal_LineInfo saved_linfo; |
4003 | ||
dda8d76d | 4004 | introduce (section, FALSE); |
a262ae96 NC |
4005 | |
4006 | while (data < end) | |
4007 | { | |
4008 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4009 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4010 | unsigned char *standard_opcodes; |
4011 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4012 | int i; |
4013 | File_Entry *file_table = NULL; | |
143a3db0 | 4014 | unsigned int n_files = 0; |
a262ae96 | 4015 | unsigned char **directory_table = NULL; |
77145576 | 4016 | dwarf_vma n_directories = 0; |
a262ae96 | 4017 | |
4925cdd7 NC |
4018 | if (const_strneq (section->name, ".debug_line.") |
4019 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4020 | These are full debug_line sections. */ | |
4021 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4022 | { |
4925cdd7 | 4023 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4024 | end_of_sequence = end; |
4025 | standard_opcodes = NULL; | |
4026 | linfo = saved_linfo; | |
058037d3 NC |
4027 | /* PR 17531: file: 0522b371. */ |
4028 | if (linfo.li_line_range == 0) | |
4029 | { | |
1306a742 | 4030 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4031 | return 0; |
4032 | } | |
b40bf0a2 | 4033 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4034 | } |
a262ae96 | 4035 | else |
b4eb7656 | 4036 | { |
b40bf0a2 | 4037 | unsigned char *hdrptr; |
a262ae96 | 4038 | |
b40bf0a2 NC |
4039 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4040 | & end_of_sequence)) == NULL) | |
a233b20c | 4041 | return 0; |
0c588247 | 4042 | |
058037d3 NC |
4043 | /* PR 17531: file: 0522b371. */ |
4044 | if (linfo.li_line_range == 0) | |
4045 | { | |
4046 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4047 | linfo.li_line_range = 1; | |
4048 | } | |
b40bf0a2 | 4049 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4050 | |
b40bf0a2 NC |
4051 | /* Save a pointer to the contents of the Opcodes table. */ |
4052 | standard_opcodes = hdrptr; | |
a262ae96 | 4053 | |
b40bf0a2 NC |
4054 | /* Traverse the Directory table just to count entries. */ |
4055 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4056 | /* PR 20440 */ |
4057 | if (data >= end) | |
4058 | { | |
4059 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4060 | linfo.li_opcode_base); | |
4061 | return 0; | |
4062 | } | |
4063 | ||
77145576 | 4064 | if (linfo.li_version >= 5) |
b40bf0a2 | 4065 | { |
77145576 JK |
4066 | unsigned char *format_start, format_count, *format; |
4067 | dwarf_vma formati, entryi; | |
4068 | unsigned int bytes_read; | |
a262ae96 | 4069 | |
dda8d76d | 4070 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4071 | |
4072 | /* Skip directories format. */ | |
4073 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4074 | format_start = data; | |
4075 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4076 | { |
77145576 JK |
4077 | read_uleb128 (data, & bytes_read, end); |
4078 | data += bytes_read; | |
4079 | read_uleb128 (data, & bytes_read, end); | |
4080 | data += bytes_read; | |
b40bf0a2 | 4081 | } |
a262ae96 | 4082 | |
77145576 JK |
4083 | n_directories = read_uleb128 (data, & bytes_read, end); |
4084 | data += bytes_read; | |
4085 | if (data == end) | |
d8024a91 | 4086 | { |
77145576 | 4087 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4088 | break; |
4089 | } | |
4090 | ||
b40bf0a2 NC |
4091 | directory_table = (unsigned char **) |
4092 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4093 | |
77145576 | 4094 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4095 | { |
77145576 | 4096 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4097 | |
77145576 JK |
4098 | format = format_start; |
4099 | for (formati = 0; formati < format_count; formati++) | |
4100 | { | |
4101 | dwarf_vma content_type, form; | |
4102 | dwarf_vma uvalue; | |
4103 | ||
4104 | content_type = read_uleb128 (format, & bytes_read, end); | |
4105 | format += bytes_read; | |
4106 | form = read_uleb128 (format, & bytes_read, end); | |
4107 | format += bytes_read; | |
4108 | if (data == end) | |
4109 | { | |
4110 | warn (_("Corrupt directories list\n")); | |
4111 | break; | |
4112 | } | |
4113 | switch (content_type) | |
4114 | { | |
4115 | case DW_LNCT_path: | |
4116 | switch (form) | |
4117 | { | |
4118 | case DW_FORM_string: | |
4119 | *pathp = data; | |
4120 | break; | |
4121 | case DW_FORM_line_strp: | |
4122 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4123 | end); | |
4124 | /* Remove const by the cast. */ | |
4125 | *pathp = (unsigned char *) | |
4126 | fetch_indirect_line_string (uvalue); | |
4127 | break; | |
4128 | } | |
4129 | break; | |
4130 | } | |
4131 | data = read_and_display_attr_value (0, form, 0, data, end, | |
4132 | 0, 0, | |
4133 | linfo.li_offset_size, | |
4134 | linfo.li_version, | |
4135 | NULL, 1, section, | |
4136 | NULL, '\t'); | |
4137 | } | |
4138 | if (data == end) | |
4139 | { | |
4140 | warn (_("Corrupt directories list\n")); | |
4141 | break; | |
4142 | } | |
4143 | } | |
a262ae96 | 4144 | |
77145576 JK |
4145 | /* Skip files format. */ |
4146 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4147 | format_start = data; | |
4148 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4149 | { |
b40bf0a2 NC |
4150 | read_uleb128 (data, & bytes_read, end); |
4151 | data += bytes_read; | |
4152 | read_uleb128 (data, & bytes_read, end); | |
4153 | data += bytes_read; | |
b40bf0a2 | 4154 | } |
a262ae96 | 4155 | |
77145576 JK |
4156 | n_files = read_uleb128 (data, & bytes_read, end); |
4157 | data += bytes_read; | |
4158 | if (data == end) | |
d8024a91 | 4159 | { |
77145576 | 4160 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4161 | break; |
4162 | } | |
4163 | ||
77145576 JK |
4164 | file_table = (File_Entry *) xcalloc (1, n_files |
4165 | * sizeof (File_Entry)); | |
a262ae96 | 4166 | |
77145576 | 4167 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4168 | { |
77145576 | 4169 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4170 | |
77145576 JK |
4171 | format = format_start; |
4172 | for (formati = 0; formati < format_count; formati++) | |
4173 | { | |
4174 | dwarf_vma content_type, form; | |
4175 | dwarf_vma uvalue; | |
4176 | ||
4177 | content_type = read_uleb128 (format, & bytes_read, end); | |
4178 | format += bytes_read; | |
4179 | form = read_uleb128 (format, & bytes_read, end); | |
4180 | format += bytes_read; | |
4181 | if (data == end) | |
4182 | { | |
4183 | warn (_("Corrupt file name list\n")); | |
4184 | break; | |
4185 | } | |
4186 | switch (content_type) | |
4187 | { | |
4188 | case DW_LNCT_path: | |
4189 | switch (form) | |
4190 | { | |
4191 | case DW_FORM_string: | |
4192 | file->name = data; | |
4193 | break; | |
4194 | case DW_FORM_line_strp: | |
4195 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4196 | end); | |
4197 | /* Remove const by the cast. */ | |
4198 | file->name = (unsigned char *) | |
4199 | fetch_indirect_line_string (uvalue); | |
4200 | break; | |
4201 | } | |
4202 | break; | |
4203 | case DW_LNCT_directory_index: | |
4204 | switch (form) | |
4205 | { | |
4206 | case DW_FORM_data1: | |
4207 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4208 | end); | |
4209 | break; | |
4210 | case DW_FORM_data2: | |
4211 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
4212 | end); | |
4213 | break; | |
4214 | case DW_FORM_udata: | |
4215 | file->directory_index = read_uleb128 (data, NULL, | |
4216 | end); | |
4217 | break; | |
4218 | } | |
4219 | break; | |
4220 | } | |
4221 | data = read_and_display_attr_value (0, form, 0, data, end, | |
4222 | 0, 0, | |
4223 | linfo.li_offset_size, | |
4224 | linfo.li_version, | |
4225 | NULL, 1, section, | |
4226 | NULL, '\t'); | |
4227 | } | |
4228 | if (data == end) | |
4229 | { | |
4230 | warn (_("Corrupt file name list\n")); | |
4231 | break; | |
4232 | } | |
4233 | } | |
4234 | } | |
4235 | else | |
4236 | { | |
4237 | if (*data != 0) | |
b40bf0a2 | 4238 | { |
77145576 JK |
4239 | unsigned char *ptr_directory_table = data; |
4240 | ||
4241 | while (data < end && *data != 0) | |
4242 | { | |
4243 | data += strnlen ((char *) data, end - data) + 1; | |
4244 | n_directories++; | |
4245 | } | |
4246 | ||
4247 | /* PR 20440 */ | |
4248 | if (data >= end) | |
4249 | { | |
4250 | warn (_("directory table ends unexpectedly\n")); | |
4251 | n_directories = 0; | |
4252 | break; | |
4253 | } | |
4254 | ||
4255 | /* Go through the directory table again to save the directories. */ | |
4256 | directory_table = (unsigned char **) | |
4257 | xmalloc (n_directories * sizeof (unsigned char *)); | |
4258 | ||
4259 | i = 0; | |
4260 | while (*ptr_directory_table != 0) | |
4261 | { | |
4262 | directory_table[i] = ptr_directory_table; | |
4263 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
4264 | ptr_directory_table - end) + 1; | |
4265 | i++; | |
4266 | } | |
b40bf0a2 | 4267 | } |
77145576 JK |
4268 | /* Skip the NUL at the end of the table. */ |
4269 | data++; | |
4270 | ||
4271 | /* Traverse the File Name table just to count the entries. */ | |
4272 | if (data < end && *data != 0) | |
b40bf0a2 | 4273 | { |
77145576 JK |
4274 | unsigned char *ptr_file_name_table = data; |
4275 | ||
4276 | while (data < end && *data != 0) | |
db9537d2 | 4277 | { |
77145576 JK |
4278 | unsigned int bytes_read; |
4279 | ||
4280 | /* Skip Name, directory index, last modification time and length | |
4281 | of file. */ | |
4282 | data += strnlen ((char *) data, end - data) + 1; | |
4283 | read_uleb128 (data, & bytes_read, end); | |
4284 | data += bytes_read; | |
4285 | read_uleb128 (data, & bytes_read, end); | |
4286 | data += bytes_read; | |
4287 | read_uleb128 (data, & bytes_read, end); | |
4288 | data += bytes_read; | |
4289 | ||
4290 | n_files++; | |
db9537d2 | 4291 | } |
a262ae96 | 4292 | |
77145576 JK |
4293 | if (data >= end) |
4294 | { | |
4295 | warn (_("file table ends unexpectedly\n")); | |
4296 | n_files = 0; | |
4297 | break; | |
4298 | } | |
4299 | ||
4300 | /* Go through the file table again to save the strings. */ | |
4301 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 4302 | |
77145576 JK |
4303 | i = 0; |
4304 | while (*ptr_file_name_table != 0) | |
4305 | { | |
4306 | unsigned int bytes_read; | |
4307 | ||
4308 | file_table[i].name = ptr_file_name_table; | |
4309 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
4310 | end - ptr_file_name_table) + 1; | |
4311 | ||
4312 | /* We are not interested in directory, time or size. */ | |
4313 | file_table[i].directory_index = read_uleb128 (ptr_file_name_table, | |
4314 | & bytes_read, end); | |
4315 | ptr_file_name_table += bytes_read; | |
4316 | file_table[i].modification_date = read_uleb128 (ptr_file_name_table, | |
4317 | & bytes_read, end); | |
4318 | ptr_file_name_table += bytes_read; | |
4319 | file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end); | |
4320 | ptr_file_name_table += bytes_read; | |
4321 | i++; | |
4322 | } | |
4323 | i = 0; | |
b40bf0a2 | 4324 | } |
77145576 JK |
4325 | |
4326 | /* Skip the NUL at the end of the table. */ | |
4327 | data++; | |
b40bf0a2 | 4328 | } |
cc5914eb | 4329 | |
77145576 | 4330 | /* Print the Compilation Unit's name and a header. */ |
f082820d AM |
4331 | if (file_table == NULL) |
4332 | ; | |
4333 | else if (directory_table == NULL) | |
4334 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
4335 | else |
4336 | { | |
4337 | unsigned int ix = file_table[0].directory_index; | |
4338 | const char *directory; | |
4339 | ||
4340 | if (ix == 0) | |
4341 | directory = "."; | |
4342 | /* PR 20439 */ | |
4343 | else if (n_directories == 0) | |
4344 | directory = _("<unknown>"); | |
4345 | else if (ix > n_directories) | |
4346 | { | |
4347 | warn (_("directory index %u > number of directories %s\n"), | |
4348 | ix, dwarf_vmatoa ("u", n_directories)); | |
4349 | directory = _("<corrupt>"); | |
4350 | } | |
4351 | else | |
4352 | directory = (char *) directory_table[ix - 1]; | |
4353 | ||
4354 | if (do_wide || strlen (directory) < 76) | |
4355 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
4356 | else | |
4357 | printf ("%s:\n", file_table[0].name); | |
77145576 | 4358 | } |
a262ae96 | 4359 | |
17f6ade2 | 4360 | printf (_("File name Line number Starting address View Stmt\n")); |
b40bf0a2 NC |
4361 | saved_linfo = linfo; |
4362 | } | |
a262ae96 NC |
4363 | |
4364 | /* This loop iterates through the Dwarf Line Number Program. */ | |
4365 | while (data < end_of_sequence) | |
b4eb7656 | 4366 | { |
a262ae96 | 4367 | unsigned char op_code; |
ba8826a8 | 4368 | int xop; |
b4eb7656 AM |
4369 | int adv; |
4370 | unsigned long int uladv; | |
4371 | unsigned int bytes_read; | |
4372 | int is_special_opcode = 0; | |
a262ae96 | 4373 | |
b4eb7656 | 4374 | op_code = *data++; |
ba8826a8 | 4375 | xop = op_code; |
a262ae96 | 4376 | |
b4eb7656 | 4377 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 4378 | { |
91d6fa6a | 4379 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
4380 | uladv = (op_code / linfo.li_line_range); |
4381 | if (linfo.li_max_ops_per_insn == 1) | |
4382 | { | |
4383 | uladv *= linfo.li_min_insn_length; | |
4384 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4385 | if (uladv) |
4386 | state_machine_regs.view = 0; | |
a233b20c JJ |
4387 | } |
4388 | else | |
4389 | { | |
ba8826a8 AO |
4390 | unsigned addrdelta |
4391 | = ((state_machine_regs.op_index + uladv) | |
4392 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4393 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4394 | state_machine_regs.address |
4395 | += addrdelta; | |
a233b20c JJ |
4396 | state_machine_regs.op_index |
4397 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 4398 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
4399 | if (addrdelta) |
4400 | state_machine_regs.view = 0; | |
a233b20c | 4401 | } |
a262ae96 | 4402 | |
b4eb7656 AM |
4403 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
4404 | state_machine_regs.line += adv; | |
4405 | is_special_opcode = 1; | |
ba8826a8 | 4406 | /* Increment view after printing this row. */ |
b4eb7656 AM |
4407 | } |
4408 | else switch (op_code) | |
b40bf0a2 NC |
4409 | { |
4410 | case DW_LNS_extended_op: | |
4411 | { | |
4412 | unsigned int ext_op_code_len; | |
4413 | unsigned char ext_op_code; | |
4414 | unsigned char *op_code_data = data; | |
4415 | ||
4416 | ext_op_code_len = read_uleb128 (op_code_data, &bytes_read, | |
4417 | end_of_sequence); | |
4418 | op_code_data += bytes_read; | |
4419 | ||
4420 | if (ext_op_code_len == 0) | |
4421 | { | |
f41e4712 | 4422 | warn (_("Badly formed extended line op encountered!\n")); |
b40bf0a2 NC |
4423 | break; |
4424 | } | |
4425 | ext_op_code_len += bytes_read; | |
4426 | ext_op_code = *op_code_data++; | |
ba8826a8 AO |
4427 | xop = ext_op_code; |
4428 | xop = -xop; | |
b40bf0a2 NC |
4429 | |
4430 | switch (ext_op_code) | |
4431 | { | |
4432 | case DW_LNE_end_sequence: | |
ba8826a8 | 4433 | /* Reset stuff after printing this row. */ |
b40bf0a2 NC |
4434 | break; |
4435 | case DW_LNE_set_address: | |
4436 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
87bc83b3 CC |
4437 | op_code_data, |
4438 | ext_op_code_len - bytes_read - 1, | |
b40bf0a2 NC |
4439 | end); |
4440 | state_machine_regs.op_index = 0; | |
ba8826a8 | 4441 | state_machine_regs.view = 0; |
b40bf0a2 NC |
4442 | break; |
4443 | case DW_LNE_define_file: | |
4444 | { | |
4445 | file_table = (File_Entry *) xrealloc | |
4446 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
4447 | ||
4448 | ++state_machine_regs.last_file_entry; | |
4449 | /* Source file name. */ | |
4450 | file_table[n_files].name = op_code_data; | |
4451 | op_code_data += strlen ((char *) op_code_data) + 1; | |
4452 | /* Directory index. */ | |
4453 | file_table[n_files].directory_index = | |
4454 | read_uleb128 (op_code_data, & bytes_read, | |
4455 | end_of_sequence); | |
4456 | op_code_data += bytes_read; | |
4457 | /* Last modification time. */ | |
4458 | file_table[n_files].modification_date = | |
4459 | read_uleb128 (op_code_data, & bytes_read, | |
4460 | end_of_sequence); | |
4461 | op_code_data += bytes_read; | |
4462 | /* File length. */ | |
4463 | file_table[n_files].length = | |
4464 | read_uleb128 (op_code_data, & bytes_read, | |
4465 | end_of_sequence); | |
4466 | ||
4467 | n_files++; | |
4468 | break; | |
4469 | } | |
4470 | case DW_LNE_set_discriminator: | |
4471 | case DW_LNE_HP_set_sequence: | |
4472 | /* Simply ignored. */ | |
4473 | break; | |
4474 | ||
4475 | default: | |
4476 | printf (_("UNKNOWN (%u): length %d\n"), | |
4477 | ext_op_code, ext_op_code_len - bytes_read); | |
4478 | break; | |
4479 | } | |
4480 | data += ext_op_code_len; | |
4481 | break; | |
4482 | } | |
4483 | case DW_LNS_copy: | |
ba8826a8 | 4484 | /* Increment view after printing this row. */ |
b40bf0a2 NC |
4485 | break; |
4486 | ||
4487 | case DW_LNS_advance_pc: | |
4488 | uladv = read_uleb128 (data, & bytes_read, end); | |
4489 | data += bytes_read; | |
4490 | if (linfo.li_max_ops_per_insn == 1) | |
4491 | { | |
4492 | uladv *= linfo.li_min_insn_length; | |
4493 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4494 | if (uladv) |
4495 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4496 | } |
4497 | else | |
4498 | { | |
ba8826a8 AO |
4499 | unsigned addrdelta |
4500 | = ((state_machine_regs.op_index + uladv) | |
4501 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4502 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4503 | state_machine_regs.address |
4504 | += addrdelta; | |
b40bf0a2 NC |
4505 | state_machine_regs.op_index |
4506 | = (state_machine_regs.op_index + uladv) | |
4507 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4508 | if (addrdelta) |
4509 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4510 | } |
4511 | break; | |
4512 | ||
4513 | case DW_LNS_advance_line: | |
4514 | adv = read_sleb128 (data, & bytes_read, end); | |
4515 | data += bytes_read; | |
4516 | state_machine_regs.line += adv; | |
4517 | break; | |
4518 | ||
4519 | case DW_LNS_set_file: | |
4520 | adv = read_uleb128 (data, & bytes_read, end); | |
4521 | data += bytes_read; | |
4522 | state_machine_regs.file = adv; | |
4523 | ||
db9537d2 NC |
4524 | { |
4525 | unsigned file = state_machine_regs.file - 1; | |
4526 | unsigned dir; | |
4527 | ||
4528 | if (file_table == NULL || n_files == 0) | |
4529 | printf (_("\n [Use file table entry %d]\n"), file); | |
4530 | /* PR 20439 */ | |
4531 | else if (file >= n_files) | |
4532 | { | |
4533 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
4534 | printf (_("\n <over large file table index %u>"), file); | |
4535 | } | |
4536 | else if ((dir = file_table[file].directory_index) == 0) | |
4537 | /* If directory index is 0, that means current directory. */ | |
4538 | printf ("\n./%s:[++]\n", file_table[file].name); | |
4539 | else if (directory_table == NULL || n_directories == 0) | |
4540 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
4541 | file_table[file].name, dir); | |
4542 | /* PR 20439 */ | |
4543 | else if (dir > n_directories) | |
4544 | { | |
77145576 JK |
4545 | warn (_("directory index %u > number of directories %s\n"), |
4546 | dir, dwarf_vmatoa ("u", n_directories)); | |
db9537d2 NC |
4547 | printf (_("\n <over large directory table entry %u>\n"), dir); |
4548 | } | |
4549 | else | |
4550 | printf ("\n%s/%s:\n", | |
4551 | /* The directory index starts counting at 1. */ | |
4552 | directory_table[dir - 1], file_table[file].name); | |
4553 | } | |
b40bf0a2 NC |
4554 | break; |
4555 | ||
4556 | case DW_LNS_set_column: | |
4557 | uladv = read_uleb128 (data, & bytes_read, end); | |
4558 | data += bytes_read; | |
4559 | state_machine_regs.column = uladv; | |
4560 | break; | |
4561 | ||
4562 | case DW_LNS_negate_stmt: | |
4563 | adv = state_machine_regs.is_stmt; | |
4564 | adv = ! adv; | |
4565 | state_machine_regs.is_stmt = adv; | |
4566 | break; | |
4567 | ||
4568 | case DW_LNS_set_basic_block: | |
4569 | state_machine_regs.basic_block = 1; | |
4570 | break; | |
4571 | ||
4572 | case DW_LNS_const_add_pc: | |
4573 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4574 | if (linfo.li_max_ops_per_insn == 1) | |
4575 | { | |
4576 | uladv *= linfo.li_min_insn_length; | |
4577 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4578 | if (uladv) |
4579 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4580 | } |
4581 | else | |
4582 | { | |
ba8826a8 AO |
4583 | unsigned addrdelta |
4584 | = ((state_machine_regs.op_index + uladv) | |
4585 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4586 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4587 | state_machine_regs.address |
4588 | += addrdelta; | |
b40bf0a2 NC |
4589 | state_machine_regs.op_index |
4590 | = (state_machine_regs.op_index + uladv) | |
4591 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4592 | if (addrdelta) |
4593 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4594 | } |
4595 | break; | |
4596 | ||
4597 | case DW_LNS_fixed_advance_pc: | |
4598 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4599 | state_machine_regs.address += uladv; | |
4600 | state_machine_regs.op_index = 0; | |
ba8826a8 | 4601 | /* Do NOT reset view. */ |
b40bf0a2 NC |
4602 | break; |
4603 | ||
4604 | case DW_LNS_set_prologue_end: | |
4605 | break; | |
4606 | ||
4607 | case DW_LNS_set_epilogue_begin: | |
4608 | break; | |
4609 | ||
4610 | case DW_LNS_set_isa: | |
4611 | uladv = read_uleb128 (data, & bytes_read, end); | |
4612 | data += bytes_read; | |
4613 | printf (_(" Set ISA to %lu\n"), uladv); | |
4614 | break; | |
4615 | ||
4616 | default: | |
4617 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4618 | ||
4619 | if (standard_opcodes != NULL) | |
4620 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4621 | { | |
4622 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
4623 | &bytes_read, end)), | |
4624 | i == 1 ? "" : ", "); | |
4625 | data += bytes_read; | |
4626 | } | |
4627 | putchar ('\n'); | |
4628 | break; | |
4629 | } | |
a262ae96 | 4630 | |
b4eb7656 AM |
4631 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
4632 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
4633 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
4634 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
4635 | { |
4636 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
4637 | char *fileName; | |
4638 | char *newFileName = NULL; | |
4639 | size_t fileNameLength; | |
b40bf0a2 NC |
4640 | |
4641 | if (file_table) | |
db9537d2 NC |
4642 | { |
4643 | unsigned indx = state_machine_regs.file - 1; | |
4644 | /* PR 20439 */ | |
4645 | if (indx >= n_files) | |
4646 | { | |
4647 | warn (_("corrupt file index %u encountered\n"), indx); | |
4648 | fileName = _("<corrupt>"); | |
4649 | } | |
4650 | else | |
4651 | fileName = (char *) file_table[indx].name; | |
4652 | } | |
b40bf0a2 | 4653 | else |
db9537d2 | 4654 | fileName = _("<unknown>"); |
b40bf0a2 NC |
4655 | |
4656 | fileNameLength = strlen (fileName); | |
a262ae96 | 4657 | |
b4eb7656 AM |
4658 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
4659 | { | |
4660 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
4661 | /* Truncate file name */ | |
4662 | strncpy (newFileName, | |
4663 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
4664 | MAX_FILENAME_LENGTH + 1); | |
4665 | } | |
4666 | else | |
4667 | { | |
4668 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
4669 | strncpy (newFileName, fileName, fileNameLength + 1); | |
4670 | } | |
4671 | ||
4672 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
4673 | { | |
a233b20c | 4674 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4675 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4676 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4677 | state_machine_regs.address); |
4678 | else | |
ba8826a8 | 4679 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4680 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4681 | state_machine_regs.address, |
4682 | state_machine_regs.op_index); | |
b4eb7656 AM |
4683 | } |
4684 | else | |
4685 | { | |
a233b20c | 4686 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4687 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4688 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4689 | state_machine_regs.address); |
4690 | else | |
ba8826a8 | 4691 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4692 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4693 | state_machine_regs.address, |
4694 | state_machine_regs.op_index); | |
b4eb7656 | 4695 | } |
a262ae96 | 4696 | |
ba8826a8 | 4697 | if (state_machine_regs.view) |
17f6ade2 | 4698 | printf (" %6u", state_machine_regs.view); |
ba8826a8 | 4699 | else |
17f6ade2 JD |
4700 | printf (" "); |
4701 | ||
4702 | if (state_machine_regs.is_stmt) | |
4703 | printf (" x"); | |
4704 | ||
4705 | putchar ('\n'); | |
ba8826a8 AO |
4706 | state_machine_regs.view++; |
4707 | ||
4708 | if (xop == -DW_LNE_end_sequence) | |
4709 | { | |
4710 | reset_state_machine (linfo.li_default_is_stmt); | |
4711 | putchar ('\n'); | |
4712 | } | |
a262ae96 | 4713 | |
b4eb7656 AM |
4714 | free (newFileName); |
4715 | } | |
4716 | } | |
b40bf0a2 NC |
4717 | |
4718 | if (file_table) | |
4719 | { | |
4720 | free (file_table); | |
4721 | file_table = NULL; | |
4722 | n_files = 0; | |
4723 | } | |
4724 | ||
4725 | if (directory_table) | |
4726 | { | |
4727 | free (directory_table); | |
4728 | directory_table = NULL; | |
4729 | n_directories = 0; | |
4730 | } | |
4731 | ||
a262ae96 NC |
4732 | putchar ('\n'); |
4733 | } | |
4734 | ||
4735 | return 1; | |
4736 | } | |
4737 | ||
4738 | static int | |
77145576 | 4739 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
4740 | { |
4741 | unsigned char *data = section->start; | |
4742 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
4743 | int retValRaw = 1; |
4744 | int retValDecoded = 1; | |
a262ae96 | 4745 | |
008f4c78 NC |
4746 | if (do_debug_lines == 0) |
4747 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
4748 | ||
4cb93e3b | 4749 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 4750 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 4751 | |
4cb93e3b | 4752 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
77145576 | 4753 | retValDecoded = display_debug_lines_decoded (section, data, end, file); |
a262ae96 | 4754 | |
4cb93e3b | 4755 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
4756 | return 0; |
4757 | ||
4758 | return 1; | |
4759 | } | |
4760 | ||
6e3d6dc1 NC |
4761 | static debug_info * |
4762 | find_debug_info_for_offset (unsigned long offset) | |
4763 | { | |
4764 | unsigned int i; | |
4765 | ||
4766 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
4767 | return NULL; | |
4768 | ||
4769 | for (i = 0; i < num_debug_info_entries; i++) | |
4770 | if (debug_information[i].cu_offset == offset) | |
4771 | return debug_information + i; | |
4772 | ||
4773 | return NULL; | |
4774 | } | |
4775 | ||
459d52c8 DE |
4776 | static const char * |
4777 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
4778 | { | |
4779 | /* See gdb/gdb-index.h. */ | |
4780 | static const char * const kinds[] = | |
4781 | { | |
4782 | N_ ("no info"), | |
4783 | N_ ("type"), | |
4784 | N_ ("variable"), | |
4785 | N_ ("function"), | |
4786 | N_ ("other"), | |
4787 | N_ ("unused5"), | |
4788 | N_ ("unused6"), | |
4789 | N_ ("unused7") | |
4790 | }; | |
4791 | ||
4792 | return _ (kinds[kind]); | |
4793 | } | |
4794 | ||
19e6b90e | 4795 | static int |
459d52c8 DE |
4796 | display_debug_pubnames_worker (struct dwarf_section *section, |
4797 | void *file ATTRIBUTE_UNUSED, | |
4798 | int is_gnu) | |
19e6b90e | 4799 | { |
91d6fa6a | 4800 | DWARF2_Internal_PubNames names; |
19e6b90e L |
4801 | unsigned char *start = section->start; |
4802 | unsigned char *end = start + section->size; | |
4803 | ||
6e3d6dc1 NC |
4804 | /* It does not matter if this load fails, |
4805 | we test for that later on. */ | |
4806 | load_debug_info (file); | |
4807 | ||
dda8d76d | 4808 | introduce (section, FALSE); |
19e6b90e L |
4809 | |
4810 | while (start < end) | |
4811 | { | |
4812 | unsigned char *data; | |
e98fdf1a | 4813 | unsigned long sec_off; |
bf5117e3 | 4814 | unsigned int offset_size, initial_length_size; |
19e6b90e | 4815 | |
e98fdf1a | 4816 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 4817 | if (names.pn_length == 0xffffffff) |
19e6b90e | 4818 | { |
e98fdf1a | 4819 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
4820 | offset_size = 8; |
4821 | initial_length_size = 12; | |
4822 | } | |
4823 | else | |
4824 | { | |
4825 | offset_size = 4; | |
4826 | initial_length_size = 4; | |
4827 | } | |
4828 | ||
e98fdf1a AM |
4829 | sec_off = start - section->start; |
4830 | if (sec_off + names.pn_length < sec_off | |
4831 | || sec_off + names.pn_length > section->size) | |
4832 | { | |
4833 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
4834 | section->name, | |
4835 | sec_off - initial_length_size, | |
4836 | dwarf_vmatoa ("x", names.pn_length)); | |
4837 | break; | |
4838 | } | |
4839 | ||
4840 | data = start; | |
4841 | start += names.pn_length; | |
4842 | ||
0c588247 NC |
4843 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
4844 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
4845 | |
4846 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
4847 | && num_debug_info_entries > 0 | |
91d6fa6a | 4848 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 4849 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 4850 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 4851 | |
0c588247 | 4852 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 4853 | |
058037d3 NC |
4854 | printf (_(" Length: %ld\n"), |
4855 | (long) names.pn_length); | |
4856 | printf (_(" Version: %d\n"), | |
4857 | names.pn_version); | |
4858 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
4859 | (unsigned long) names.pn_offset); | |
4860 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
4861 | (long) names.pn_size); | |
19e6b90e | 4862 | |
91d6fa6a | 4863 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
4864 | { |
4865 | static int warned = 0; | |
4866 | ||
4867 | if (! warned) | |
4868 | { | |
4869 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
4870 | warned = 1; | |
4871 | } | |
4872 | ||
4873 | continue; | |
4874 | } | |
4875 | ||
459d52c8 DE |
4876 | if (is_gnu) |
4877 | printf (_("\n Offset Kind Name\n")); | |
4878 | else | |
4879 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 4880 | |
e98fdf1a | 4881 | while (1) |
19e6b90e | 4882 | { |
f41e4712 | 4883 | bfd_size_type maxprint; |
e98fdf1a | 4884 | dwarf_vma offset; |
f41e4712 | 4885 | |
0c588247 | 4886 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 4887 | |
e98fdf1a AM |
4888 | if (offset == 0) |
4889 | break; | |
b4eb7656 | 4890 | |
e98fdf1a AM |
4891 | data += offset_size; |
4892 | if (data >= end) | |
4893 | break; | |
4894 | maxprint = (end - data) - 1; | |
f41e4712 | 4895 | |
e98fdf1a AM |
4896 | if (is_gnu) |
4897 | { | |
4898 | unsigned int kind_data; | |
4899 | gdb_index_symbol_kind kind; | |
4900 | const char *kind_name; | |
4901 | int is_static; | |
4902 | ||
4903 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
4904 | data++; | |
4905 | maxprint --; | |
4906 | /* GCC computes the kind as the upper byte in the CU index | |
4907 | word, and then right shifts it by the CU index size. | |
4908 | Left shift KIND to where the gdb-index.h accessor macros | |
4909 | can use it. */ | |
4910 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
4911 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
4912 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
4913 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
4914 | printf (" %-6lx %s,%-10s %.*s\n", | |
4915 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
4916 | kind_name, (int) maxprint, data); | |
19e6b90e | 4917 | } |
e98fdf1a AM |
4918 | else |
4919 | printf (" %-6lx\t%.*s\n", | |
4920 | (unsigned long) offset, (int) maxprint, data); | |
4921 | ||
4922 | data += strnlen ((char *) data, maxprint) + 1; | |
4923 | if (data >= end) | |
4924 | break; | |
19e6b90e | 4925 | } |
19e6b90e L |
4926 | } |
4927 | ||
4928 | printf ("\n"); | |
4929 | return 1; | |
4930 | } | |
4931 | ||
459d52c8 DE |
4932 | static int |
4933 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
4934 | { | |
4935 | return display_debug_pubnames_worker (section, file, 0); | |
4936 | } | |
4937 | ||
4938 | static int | |
4939 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
4940 | { | |
4941 | return display_debug_pubnames_worker (section, file, 1); | |
4942 | } | |
4943 | ||
19e6b90e L |
4944 | static int |
4945 | display_debug_macinfo (struct dwarf_section *section, | |
4946 | void *file ATTRIBUTE_UNUSED) | |
4947 | { | |
4948 | unsigned char *start = section->start; | |
4949 | unsigned char *end = start + section->size; | |
4950 | unsigned char *curr = start; | |
4951 | unsigned int bytes_read; | |
4952 | enum dwarf_macinfo_record_type op; | |
4953 | ||
dda8d76d | 4954 | introduce (section, FALSE); |
19e6b90e L |
4955 | |
4956 | while (curr < end) | |
4957 | { | |
4958 | unsigned int lineno; | |
0c588247 | 4959 | const unsigned char *string; |
19e6b90e | 4960 | |
3f5e193b | 4961 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
4962 | curr++; |
4963 | ||
4964 | switch (op) | |
4965 | { | |
4966 | case DW_MACINFO_start_file: | |
4967 | { | |
4968 | unsigned int filenum; | |
4969 | ||
f6f0e17b | 4970 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 4971 | curr += bytes_read; |
f6f0e17b | 4972 | filenum = read_uleb128 (curr, & bytes_read, end); |
19e6b90e L |
4973 | curr += bytes_read; |
4974 | ||
4975 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
4976 | lineno, filenum); | |
4977 | } | |
4978 | break; | |
4979 | ||
4980 | case DW_MACINFO_end_file: | |
4981 | printf (_(" DW_MACINFO_end_file\n")); | |
4982 | break; | |
4983 | ||
4984 | case DW_MACINFO_define: | |
f6f0e17b | 4985 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 4986 | curr += bytes_read; |
0c588247 NC |
4987 | string = curr; |
4988 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
4989 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
4990 | lineno, string); | |
4991 | break; | |
4992 | ||
4993 | case DW_MACINFO_undef: | |
f6f0e17b | 4994 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 4995 | curr += bytes_read; |
0c588247 NC |
4996 | string = curr; |
4997 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
4998 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
4999 | lineno, string); | |
5000 | break; | |
5001 | ||
5002 | case DW_MACINFO_vendor_ext: | |
5003 | { | |
5004 | unsigned int constant; | |
5005 | ||
f6f0e17b | 5006 | constant = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5007 | curr += bytes_read; |
0c588247 NC |
5008 | string = curr; |
5009 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5010 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5011 | constant, string); | |
5012 | } | |
5013 | break; | |
5014 | } | |
5015 | } | |
5016 | ||
5017 | return 1; | |
5018 | } | |
5019 | ||
4ccf1e31 JJ |
5020 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5021 | filename and dirname corresponding to file name table entry with index | |
5022 | FILEIDX. Return NULL on failure. */ | |
5023 | ||
5024 | static unsigned char * | |
f6f0e17b NC |
5025 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5026 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5027 | unsigned char **dir_name) |
5028 | { | |
5029 | struct dwarf_section *section = &debug_displays [line].section; | |
5030 | unsigned char *hdrptr, *dirtable, *file_name; | |
5031 | unsigned int offset_size, initial_length_size; | |
5032 | unsigned int version, opcode_base, bytes_read; | |
5033 | dwarf_vma length, diridx; | |
f6f0e17b | 5034 | const unsigned char * end; |
4ccf1e31 JJ |
5035 | |
5036 | *dir_name = NULL; | |
5037 | if (section->start == NULL | |
5038 | || line_offset >= section->size | |
5039 | || fileidx == 0) | |
5040 | return NULL; | |
5041 | ||
5042 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5043 | end = section->start + section->size; |
0c588247 NC |
5044 | |
5045 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5046 | if (length == 0xffffffff) |
5047 | { | |
5048 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5049 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5050 | offset_size = 8; |
5051 | initial_length_size = 12; | |
5052 | } | |
5053 | else | |
5054 | { | |
5055 | offset_size = 4; | |
5056 | initial_length_size = 4; | |
5057 | } | |
e98fdf1a AM |
5058 | if (length + initial_length_size < length |
5059 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5060 | return NULL; |
0c588247 NC |
5061 | |
5062 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5063 | if (version != 2 && version != 3 && version != 4) |
5064 | return NULL; | |
5065 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5066 | if (version >= 4) | |
5067 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5068 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5069 | |
5070 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5071 | if (opcode_base == 0) |
5072 | return NULL; | |
0c588247 | 5073 | |
4ccf1e31 | 5074 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5075 | if (hdrptr >= end) |
5076 | return NULL; | |
5077 | ||
4ccf1e31 JJ |
5078 | dirtable = hdrptr; |
5079 | /* Skip over dirname table. */ | |
5080 | while (*hdrptr != '\0') | |
5c1c468d NC |
5081 | { |
5082 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
5083 | if (hdrptr >= end) | |
5084 | return NULL; | |
5085 | } | |
4ccf1e31 | 5086 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5087 | |
4ccf1e31 | 5088 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5089 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5090 | { |
0c588247 | 5091 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 5092 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 5093 | hdrptr += bytes_read; |
f6f0e17b | 5094 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 5095 | hdrptr += bytes_read; |
f6f0e17b | 5096 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
5097 | hdrptr += bytes_read; |
5098 | } | |
5c1c468d | 5099 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5100 | return NULL; |
5c1c468d | 5101 | |
4ccf1e31 | 5102 | file_name = hdrptr; |
0c588247 | 5103 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
5104 | if (hdrptr >= end) |
5105 | return NULL; | |
f6f0e17b | 5106 | diridx = read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
5107 | if (diridx == 0) |
5108 | return file_name; | |
5c1c468d | 5109 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 5110 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 5111 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5112 | return NULL; |
5113 | *dir_name = dirtable; | |
5114 | return file_name; | |
5115 | } | |
5116 | ||
5117 | static int | |
5118 | display_debug_macro (struct dwarf_section *section, | |
5119 | void *file) | |
5120 | { | |
5121 | unsigned char *start = section->start; | |
5122 | unsigned char *end = start + section->size; | |
5123 | unsigned char *curr = start; | |
5124 | unsigned char *extended_op_buf[256]; | |
5125 | unsigned int bytes_read; | |
5126 | ||
dda8d76d NC |
5127 | load_debug_section_with_follow (str, file); |
5128 | load_debug_section_with_follow (line, file); | |
4ccf1e31 | 5129 | |
dda8d76d | 5130 | introduce (section, FALSE); |
4ccf1e31 JJ |
5131 | |
5132 | while (curr < end) | |
5133 | { | |
5134 | unsigned int lineno, version, flags; | |
5135 | unsigned int offset_size = 4; | |
0c588247 | 5136 | const unsigned char *string; |
4ccf1e31 JJ |
5137 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5138 | unsigned char **extended_ops = NULL; | |
5139 | ||
0c588247 | 5140 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5141 | if (version != 4 && version != 5) |
4ccf1e31 | 5142 | { |
7a7e1061 | 5143 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
5144 | section->name); |
5145 | return 0; | |
5146 | } | |
5147 | ||
0c588247 | 5148 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
5149 | if (flags & 1) |
5150 | offset_size = 8; | |
5151 | printf (_(" Offset: 0x%lx\n"), | |
5152 | (unsigned long) sec_offset); | |
5153 | printf (_(" Version: %d\n"), version); | |
5154 | printf (_(" Offset size: %d\n"), offset_size); | |
5155 | if (flags & 2) | |
5156 | { | |
0c588247 | 5157 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5158 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5159 | (unsigned long) line_offset); | |
5160 | } | |
5161 | if (flags & 4) | |
5162 | { | |
0c588247 | 5163 | unsigned int i, count, op; |
4ccf1e31 | 5164 | dwarf_vma nargs, n; |
0c588247 NC |
5165 | |
5166 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5167 | |
4ccf1e31 JJ |
5168 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5169 | extended_ops = extended_op_buf; | |
5170 | if (count) | |
5171 | { | |
5172 | printf (_(" Extension opcode arguments:\n")); | |
5173 | for (i = 0; i < count; i++) | |
5174 | { | |
0c588247 | 5175 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5176 | extended_ops[op] = curr; |
f6f0e17b | 5177 | nargs = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
5178 | curr += bytes_read; |
5179 | if (nargs == 0) | |
7a7e1061 | 5180 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5181 | else |
5182 | { | |
7a7e1061 | 5183 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5184 | for (n = 0; n < nargs; n++) |
5185 | { | |
0c588247 NC |
5186 | unsigned int form; |
5187 | ||
5188 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5189 | printf ("%s%s", get_FORM_name (form), |
5190 | n == nargs - 1 ? "\n" : ", "); | |
5191 | switch (form) | |
5192 | { | |
5193 | case DW_FORM_data1: | |
5194 | case DW_FORM_data2: | |
5195 | case DW_FORM_data4: | |
5196 | case DW_FORM_data8: | |
5197 | case DW_FORM_sdata: | |
5198 | case DW_FORM_udata: | |
5199 | case DW_FORM_block: | |
5200 | case DW_FORM_block1: | |
5201 | case DW_FORM_block2: | |
5202 | case DW_FORM_block4: | |
5203 | case DW_FORM_flag: | |
5204 | case DW_FORM_string: | |
5205 | case DW_FORM_strp: | |
5206 | case DW_FORM_sec_offset: | |
5207 | break; | |
5208 | default: | |
5209 | error (_("Invalid extension opcode form %s\n"), | |
5210 | get_FORM_name (form)); | |
5211 | return 0; | |
5212 | } | |
5213 | } | |
5214 | } | |
5215 | } | |
5216 | } | |
5217 | } | |
5218 | printf ("\n"); | |
5219 | ||
5220 | while (1) | |
5221 | { | |
5222 | unsigned int op; | |
5223 | ||
5224 | if (curr >= end) | |
5225 | { | |
5226 | error (_(".debug_macro section not zero terminated\n")); | |
5227 | return 0; | |
5228 | } | |
5229 | ||
0c588247 | 5230 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
5231 | if (op == 0) |
5232 | break; | |
5233 | ||
5234 | switch (op) | |
5235 | { | |
7a7e1061 | 5236 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
5237 | { |
5238 | unsigned int filenum; | |
5239 | unsigned char *file_name = NULL, *dir_name = NULL; | |
5240 | ||
f6f0e17b | 5241 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5242 | curr += bytes_read; |
f6f0e17b | 5243 | filenum = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
5244 | curr += bytes_read; |
5245 | ||
5246 | if ((flags & 2) == 0) | |
7a7e1061 | 5247 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
5248 | else |
5249 | file_name | |
5250 | = get_line_filename_and_dirname (line_offset, filenum, | |
5251 | &dir_name); | |
5252 | if (file_name == NULL) | |
7a7e1061 | 5253 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
5254 | lineno, filenum); |
5255 | else | |
7a7e1061 | 5256 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
5257 | lineno, filenum, |
5258 | dir_name != NULL ? (const char *) dir_name : "", | |
5259 | dir_name != NULL ? "/" : "", file_name); | |
5260 | } | |
5261 | break; | |
5262 | ||
7a7e1061 JK |
5263 | case DW_MACRO_end_file: |
5264 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
5265 | break; |
5266 | ||
7a7e1061 | 5267 | case DW_MACRO_define: |
f6f0e17b | 5268 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5269 | curr += bytes_read; |
0c588247 NC |
5270 | string = curr; |
5271 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5272 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5273 | lineno, string); |
5274 | break; | |
5275 | ||
7a7e1061 | 5276 | case DW_MACRO_undef: |
f6f0e17b | 5277 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5278 | curr += bytes_read; |
0c588247 NC |
5279 | string = curr; |
5280 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5281 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5282 | lineno, string); |
5283 | break; | |
5284 | ||
7a7e1061 | 5285 | case DW_MACRO_define_strp: |
f6f0e17b | 5286 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5287 | curr += bytes_read; |
0c588247 | 5288 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5289 | string = fetch_indirect_string (offset); |
7a7e1061 | 5290 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5291 | lineno, string); |
5292 | break; | |
5293 | ||
7a7e1061 | 5294 | case DW_MACRO_undef_strp: |
f6f0e17b | 5295 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5296 | curr += bytes_read; |
0c588247 | 5297 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5298 | string = fetch_indirect_string (offset); |
7a7e1061 | 5299 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5300 | lineno, string); |
5301 | break; | |
5302 | ||
7a7e1061 | 5303 | case DW_MACRO_import: |
0c588247 | 5304 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5305 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
5306 | (unsigned long) offset); |
5307 | break; | |
5308 | ||
7a7e1061 | 5309 | case DW_MACRO_define_sup: |
f6f0e17b | 5310 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 5311 | curr += bytes_read; |
0c588247 | 5312 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5313 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5314 | lineno, (unsigned long) offset); |
5315 | break; | |
5316 | ||
7a7e1061 | 5317 | case DW_MACRO_undef_sup: |
f6f0e17b | 5318 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 5319 | curr += bytes_read; |
0c588247 | 5320 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5321 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5322 | lineno, (unsigned long) offset); |
5323 | break; | |
5324 | ||
7a7e1061 | 5325 | case DW_MACRO_import_sup: |
0c588247 | 5326 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5327 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
5328 | (unsigned long) offset); |
5329 | break; | |
5330 | ||
4ccf1e31 JJ |
5331 | default: |
5332 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
5333 | { | |
5334 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
5335 | return 0; | |
5336 | } | |
5337 | else | |
5338 | { | |
5339 | /* Skip over unhandled opcodes. */ | |
5340 | dwarf_vma nargs, n; | |
5341 | unsigned char *desc = extended_ops[op]; | |
f6f0e17b | 5342 | nargs = read_uleb128 (desc, &bytes_read, end); |
4ccf1e31 JJ |
5343 | desc += bytes_read; |
5344 | if (nargs == 0) | |
5345 | { | |
7a7e1061 | 5346 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
5347 | break; |
5348 | } | |
7a7e1061 | 5349 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
5350 | for (n = 0; n < nargs; n++) |
5351 | { | |
0c588247 NC |
5352 | int val; |
5353 | ||
77145576 | 5354 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 5355 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 5356 | curr |
77145576 | 5357 | = read_and_display_attr_value (0, val, 0, |
f6f0e17b | 5358 | curr, end, 0, 0, offset_size, |
341f9135 | 5359 | version, NULL, 0, NULL, |
ef0b5f1c | 5360 | NULL, ' '); |
4ccf1e31 JJ |
5361 | if (n != nargs - 1) |
5362 | printf (","); | |
5363 | } | |
5364 | printf ("\n"); | |
5365 | } | |
5366 | break; | |
5367 | } | |
5368 | } | |
5369 | ||
5370 | printf ("\n"); | |
b4eb7656 | 5371 | } |
4ccf1e31 JJ |
5372 | |
5373 | return 1; | |
5374 | } | |
5375 | ||
19e6b90e L |
5376 | static int |
5377 | display_debug_abbrev (struct dwarf_section *section, | |
5378 | void *file ATTRIBUTE_UNUSED) | |
5379 | { | |
5380 | abbrev_entry *entry; | |
5381 | unsigned char *start = section->start; | |
5382 | unsigned char *end = start + section->size; | |
5383 | ||
dda8d76d | 5384 | introduce (section, FALSE); |
19e6b90e L |
5385 | |
5386 | do | |
5387 | { | |
7282333f AM |
5388 | unsigned char *last; |
5389 | ||
19e6b90e L |
5390 | free_abbrevs (); |
5391 | ||
7282333f | 5392 | last = start; |
19e6b90e L |
5393 | start = process_abbrev_section (start, end); |
5394 | ||
5395 | if (first_abbrev == NULL) | |
5396 | continue; | |
5397 | ||
7282333f | 5398 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
5399 | |
5400 | for (entry = first_abbrev; entry; entry = entry->next) | |
5401 | { | |
5402 | abbrev_attr *attr; | |
5403 | ||
cc5914eb | 5404 | printf (" %ld %s [%s]\n", |
19e6b90e L |
5405 | entry->entry, |
5406 | get_TAG_name (entry->tag), | |
5407 | entry->children ? _("has children") : _("no children")); | |
5408 | ||
5409 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
5410 | { |
5411 | printf (" %-18s %s", | |
5412 | get_AT_name (attr->attribute), | |
5413 | get_FORM_name (attr->form)); | |
5414 | if (attr->form == DW_FORM_implicit_const) | |
5415 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
5416 | putchar ('\n'); | |
5417 | } | |
19e6b90e L |
5418 | } |
5419 | } | |
5420 | while (start); | |
5421 | ||
5422 | printf ("\n"); | |
5423 | ||
5424 | return 1; | |
5425 | } | |
5426 | ||
42bcef4a AB |
5427 | /* Return true when ADDR is the maximum address, when addresses are |
5428 | POINTER_SIZE bytes long. */ | |
5429 | ||
5430 | static bfd_boolean | |
5431 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
5432 | { | |
5433 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
5434 | return ((addr & mask) == mask); | |
5435 | } | |
5436 | ||
9f272209 AO |
5437 | /* Display a view pair list starting at *VSTART_PTR and ending at |
5438 | VLISTEND within SECTION. */ | |
5439 | ||
5440 | static void | |
5441 | display_view_pair_list (struct dwarf_section *section, | |
5442 | unsigned char **vstart_ptr, | |
5443 | unsigned int debug_info_entry, | |
5444 | unsigned char *vlistend) | |
5445 | { | |
5446 | unsigned char *vstart = *vstart_ptr; | |
5447 | unsigned char *section_end = section->start + section->size; | |
5448 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
5449 | ||
5450 | if (vlistend < section_end) | |
5451 | section_end = vlistend; | |
5452 | ||
5453 | putchar ('\n'); | |
5454 | ||
5455 | while (vstart < section_end) | |
5456 | { | |
5457 | dwarf_vma off = vstart - section->start; | |
5458 | dwarf_vma vbegin, vend; | |
5459 | ||
5460 | unsigned int bytes_read; | |
5461 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5462 | vstart += bytes_read; | |
5463 | if (vstart == section_end) | |
5464 | { | |
5465 | vstart -= bytes_read; | |
5466 | break; | |
5467 | } | |
5468 | ||
5469 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5470 | vstart += bytes_read; | |
5471 | ||
5472 | printf (" %8.8lx ", (unsigned long) off); | |
5473 | ||
5474 | print_dwarf_view (vbegin, pointer_size, 1); | |
5475 | print_dwarf_view (vend, pointer_size, 1); | |
5476 | printf (_("location view pair\n")); | |
5477 | } | |
5478 | ||
5479 | putchar ('\n'); | |
5480 | *vstart_ptr = vstart; | |
5481 | } | |
5482 | ||
4723351a CC |
5483 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
5484 | ||
5485 | static void | |
5486 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
5487 | unsigned char **start_ptr, |
5488 | unsigned int debug_info_entry, | |
359ca075 JK |
5489 | dwarf_vma offset, |
5490 | dwarf_vma base_address, | |
9f272209 | 5491 | unsigned char **vstart_ptr, |
b4eb7656 | 5492 | int has_frame_base) |
4723351a | 5493 | { |
9f272209 | 5494 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5495 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5496 | unsigned long cu_offset; |
5497 | unsigned int pointer_size; | |
5498 | unsigned int offset_size; | |
5499 | int dwarf_version; | |
4723351a CC |
5500 | |
5501 | dwarf_vma begin; | |
5502 | dwarf_vma end; | |
5503 | unsigned short length; | |
5504 | int need_frame_base; | |
5505 | ||
82b1b41b NC |
5506 | if (debug_info_entry >= num_debug_info_entries) |
5507 | { | |
5508 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
5509 | debug_info_entry); | |
5510 | return; | |
5511 | } | |
b4eb7656 | 5512 | |
82b1b41b NC |
5513 | cu_offset = debug_information [debug_info_entry].cu_offset; |
5514 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5515 | offset_size = debug_information [debug_info_entry].offset_size; | |
5516 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 5517 | |
f41e4712 NC |
5518 | if (pointer_size < 2 || pointer_size > 8) |
5519 | { | |
5520 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5521 | pointer_size, debug_info_entry); | |
5522 | return; | |
5523 | } | |
5524 | ||
4723351a CC |
5525 | while (1) |
5526 | { | |
359ca075 | 5527 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 5528 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 5529 | |
4723351a | 5530 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
5531 | { |
5532 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5533 | (unsigned long) offset); |
b4eb7656 AM |
5534 | break; |
5535 | } | |
4723351a | 5536 | |
359ca075 | 5537 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 5538 | |
0c588247 NC |
5539 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
5540 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 5541 | |
4723351a | 5542 | if (begin == 0 && end == 0) |
b4eb7656 | 5543 | { |
d1c4b12b NC |
5544 | /* PR 18374: In a object file we can have a location list that |
5545 | starts with a begin and end of 0 because there are relocations | |
5546 | that need to be applied to the addresses. Actually applying | |
5547 | the relocations now does not help as they will probably resolve | |
5548 | to 0, since the object file has not been fully linked. Real | |
5549 | end of list markers will not have any relocations against them. */ | |
5550 | if (! reloc_at (section, off) | |
5551 | && ! reloc_at (section, off + pointer_size)) | |
5552 | { | |
5553 | printf (_("<End of list>\n")); | |
5554 | break; | |
5555 | } | |
b4eb7656 | 5556 | } |
4723351a CC |
5557 | |
5558 | /* Check base address specifiers. */ | |
42bcef4a AB |
5559 | if (is_max_address (begin, pointer_size) |
5560 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
5561 | { |
5562 | base_address = end; | |
5563 | print_dwarf_vma (begin, pointer_size); | |
5564 | print_dwarf_vma (end, pointer_size); | |
5565 | printf (_("(base address)\n")); | |
5566 | continue; | |
5567 | } | |
4723351a | 5568 | |
9f272209 AO |
5569 | if (vstart) |
5570 | { | |
5571 | unsigned int bytes_read; | |
5572 | ||
5573 | off = offset + (vstart - *start_ptr); | |
5574 | ||
5575 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5576 | vstart += bytes_read; | |
5577 | print_dwarf_view (vbegin, pointer_size, 1); | |
5578 | ||
5579 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5580 | vstart += bytes_read; | |
5581 | print_dwarf_view (vend, pointer_size, 1); | |
5582 | ||
5583 | printf (_("views at %8.8lx for:\n %*s "), | |
5584 | (unsigned long) off, 8, ""); | |
5585 | } | |
5586 | ||
4723351a | 5587 | if (start + 2 > section_end) |
b4eb7656 AM |
5588 | { |
5589 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5590 | (unsigned long) offset); |
b4eb7656 AM |
5591 | break; |
5592 | } | |
4723351a | 5593 | |
0c588247 | 5594 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
5595 | |
5596 | if (start + length > section_end) | |
b4eb7656 AM |
5597 | { |
5598 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5599 | (unsigned long) offset); |
b4eb7656 AM |
5600 | break; |
5601 | } | |
4723351a CC |
5602 | |
5603 | print_dwarf_vma (begin + base_address, pointer_size); | |
5604 | print_dwarf_vma (end + base_address, pointer_size); | |
5605 | ||
5606 | putchar ('('); | |
5607 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5608 | pointer_size, |
5609 | offset_size, | |
5610 | dwarf_version, | |
5611 | length, | |
5612 | cu_offset, section); | |
4723351a CC |
5613 | putchar (')'); |
5614 | ||
5615 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5616 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 5617 | |
9f272209 | 5618 | if (begin == end && vbegin == vend) |
b4eb7656 | 5619 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5620 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 5621 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
5622 | |
5623 | putchar ('\n'); | |
5624 | ||
5625 | start += length; | |
5626 | } | |
5627 | ||
5628 | *start_ptr = start; | |
9f272209 | 5629 | *vstart_ptr = vstart; |
4723351a CC |
5630 | } |
5631 | ||
77145576 JK |
5632 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
5633 | ||
5634 | static void | |
5635 | display_loclists_list (struct dwarf_section *section, | |
5636 | unsigned char **start_ptr, | |
5637 | unsigned int debug_info_entry, | |
5638 | dwarf_vma offset, | |
5639 | dwarf_vma base_address, | |
9f272209 | 5640 | unsigned char **vstart_ptr, |
77145576 JK |
5641 | int has_frame_base) |
5642 | { | |
9f272209 | 5643 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
5644 | unsigned char *section_end = section->start + section->size; |
5645 | unsigned long cu_offset; | |
5646 | unsigned int pointer_size; | |
5647 | unsigned int offset_size; | |
5648 | int dwarf_version; | |
5649 | unsigned int bytes_read; | |
5650 | ||
9dfd0db9 | 5651 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
5652 | dwarf_vma begin = -1, vbegin = -1; |
5653 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
5654 | dwarf_vma length; |
5655 | int need_frame_base; | |
5656 | ||
5657 | if (debug_info_entry >= num_debug_info_entries) | |
5658 | { | |
5659 | warn (_("No debug information available for " | |
5660 | "loclists lists of entry: %u\n"), | |
5661 | debug_info_entry); | |
5662 | return; | |
5663 | } | |
5664 | ||
5665 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5666 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5667 | offset_size = debug_information [debug_info_entry].offset_size; | |
5668 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5669 | ||
5670 | if (pointer_size < 2 || pointer_size > 8) | |
5671 | { | |
5672 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5673 | pointer_size, debug_info_entry); | |
5674 | return; | |
5675 | } | |
5676 | ||
5677 | while (1) | |
5678 | { | |
5679 | dwarf_vma off = offset + (start - *start_ptr); | |
5680 | enum dwarf_location_list_entry_type llet; | |
5681 | ||
5682 | if (start + 1 > section_end) | |
5683 | { | |
5684 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5685 | (unsigned long) offset); | |
5686 | break; | |
5687 | } | |
5688 | ||
5689 | printf (" %8.8lx ", (unsigned long) off); | |
5690 | ||
5691 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
5692 | ||
9f272209 AO |
5693 | if (vstart && llet == DW_LLE_offset_pair) |
5694 | { | |
5695 | off = offset + (vstart - *start_ptr); | |
5696 | ||
5697 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5698 | vstart += bytes_read; | |
5699 | print_dwarf_view (vbegin, pointer_size, 1); | |
5700 | ||
5701 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5702 | vstart += bytes_read; | |
5703 | print_dwarf_view (vend, pointer_size, 1); | |
5704 | ||
5705 | printf (_("views at %8.8lx for:\n %*s "), | |
5706 | (unsigned long) off, 8, ""); | |
5707 | } | |
5708 | ||
77145576 JK |
5709 | switch (llet) |
5710 | { | |
5711 | case DW_LLE_end_of_list: | |
5712 | printf (_("<End of list>\n")); | |
5713 | break; | |
5714 | case DW_LLE_offset_pair: | |
5715 | begin = read_uleb128 (start, &bytes_read, section_end); | |
5716 | start += bytes_read; | |
5717 | end = read_uleb128 (start, &bytes_read, section_end); | |
5718 | start += bytes_read; | |
5719 | break; | |
5720 | case DW_LLE_base_address: | |
5721 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
5722 | section_end); | |
5723 | print_dwarf_vma (base_address, pointer_size); | |
5724 | printf (_("(base address)\n")); | |
5725 | break; | |
9f272209 AO |
5726 | #ifdef DW_LLE_view_pair |
5727 | case DW_LLE_view_pair: | |
5728 | if (vstart) | |
5729 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
5730 | vbegin = read_uleb128 (start, &bytes_read, section_end); | |
5731 | start += bytes_read; | |
5732 | print_dwarf_view (vbegin, pointer_size, 1); | |
5733 | ||
5734 | vend = read_uleb128 (start, &bytes_read, section_end); | |
5735 | start += bytes_read; | |
5736 | print_dwarf_view (vend, pointer_size, 1); | |
5737 | ||
5738 | printf (_("views for:\n")); | |
5739 | continue; | |
5740 | #endif | |
77145576 JK |
5741 | default: |
5742 | error (_("Invalid location list entry type %d\n"), llet); | |
5743 | return; | |
5744 | } | |
5745 | if (llet == DW_LLE_end_of_list) | |
5746 | break; | |
5747 | if (llet != DW_LLE_offset_pair) | |
5748 | continue; | |
5749 | ||
5750 | if (start + 2 > section_end) | |
5751 | { | |
5752 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5753 | (unsigned long) offset); | |
5754 | break; | |
5755 | } | |
5756 | ||
5757 | length = read_uleb128 (start, &bytes_read, section_end); | |
5758 | start += bytes_read; | |
5759 | ||
5760 | print_dwarf_vma (begin + base_address, pointer_size); | |
5761 | print_dwarf_vma (end + base_address, pointer_size); | |
5762 | ||
5763 | putchar ('('); | |
5764 | need_frame_base = decode_location_expression (start, | |
5765 | pointer_size, | |
5766 | offset_size, | |
5767 | dwarf_version, | |
5768 | length, | |
5769 | cu_offset, section); | |
5770 | putchar (')'); | |
5771 | ||
5772 | if (need_frame_base && !has_frame_base) | |
5773 | printf (_(" [without DW_AT_frame_base]")); | |
5774 | ||
9f272209 | 5775 | if (begin == end && vbegin == vend) |
77145576 | 5776 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5777 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
5778 | fputs (_(" (start > end)"), stdout); |
5779 | ||
5780 | putchar ('\n'); | |
5781 | ||
5782 | start += length; | |
9f272209 | 5783 | vbegin = vend = -1; |
77145576 JK |
5784 | } |
5785 | ||
9f272209 AO |
5786 | if (vbegin != vm1 || vend != vm1) |
5787 | printf (_("Trailing view pair not used in a range")); | |
5788 | ||
77145576 | 5789 | *start_ptr = start; |
9f272209 | 5790 | *vstart_ptr = vstart; |
77145576 JK |
5791 | } |
5792 | ||
fab128ef CC |
5793 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
5794 | right-adjusted in a field of length LEN, and followed by a space. */ | |
5795 | ||
5796 | static void | |
5797 | print_addr_index (unsigned int idx, unsigned int len) | |
5798 | { | |
5799 | static char buf[15]; | |
5800 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 5801 | printf ("%*s ", len, buf); |
fab128ef CC |
5802 | } |
5803 | ||
4723351a CC |
5804 | /* Display a location list from a .dwo section. It uses address indexes rather |
5805 | than embedded addresses. This code closely follows display_loc_list, but the | |
5806 | two are sufficiently different that combining things is very ugly. */ | |
5807 | ||
5808 | static void | |
5809 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
5810 | unsigned char **start_ptr, |
5811 | unsigned int debug_info_entry, | |
359ca075 | 5812 | dwarf_vma offset, |
9f272209 | 5813 | unsigned char **vstart_ptr, |
b4eb7656 | 5814 | int has_frame_base) |
4723351a | 5815 | { |
9f272209 | 5816 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5817 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5818 | unsigned long cu_offset; |
5819 | unsigned int pointer_size; | |
5820 | unsigned int offset_size; | |
5821 | int dwarf_version; | |
4723351a CC |
5822 | int entry_type; |
5823 | unsigned short length; | |
5824 | int need_frame_base; | |
fab128ef | 5825 | unsigned int idx; |
4723351a CC |
5826 | unsigned int bytes_read; |
5827 | ||
82b1b41b NC |
5828 | if (debug_info_entry >= num_debug_info_entries) |
5829 | { | |
5830 | warn (_("No debug information for loc lists of entry: %u\n"), | |
5831 | debug_info_entry); | |
5832 | return; | |
5833 | } | |
5834 | ||
5835 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5836 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5837 | offset_size = debug_information [debug_info_entry].offset_size; | |
5838 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5839 | ||
f41e4712 NC |
5840 | if (pointer_size < 2 || pointer_size > 8) |
5841 | { | |
5842 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5843 | pointer_size, debug_info_entry); | |
5844 | return; | |
5845 | } | |
5846 | ||
4723351a CC |
5847 | while (1) |
5848 | { | |
359ca075 | 5849 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 5850 | |
fab128ef | 5851 | if (start >= section_end) |
b4eb7656 AM |
5852 | { |
5853 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5854 | (unsigned long) offset); |
b4eb7656 AM |
5855 | break; |
5856 | } | |
4723351a | 5857 | |
0c588247 | 5858 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
5859 | |
5860 | if (vstart) | |
5861 | switch (entry_type) | |
5862 | { | |
5863 | default: | |
5864 | break; | |
5865 | ||
5866 | case 2: | |
5867 | case 3: | |
5868 | case 4: | |
5869 | { | |
5870 | dwarf_vma view; | |
5871 | dwarf_vma off = offset + (vstart - *start_ptr); | |
5872 | ||
5873 | view = read_uleb128 (vstart, &bytes_read, section_end); | |
5874 | vstart += bytes_read; | |
5875 | print_dwarf_view (view, 8, 1); | |
5876 | ||
5877 | view = read_uleb128 (vstart, &bytes_read, section_end); | |
5878 | vstart += bytes_read; | |
5879 | print_dwarf_view (view, 8, 1); | |
5880 | ||
5881 | printf (_("views at %8.8lx for:\n %*s "), | |
5882 | (unsigned long) off, 8, ""); | |
5883 | ||
5884 | } | |
5885 | break; | |
5886 | } | |
5887 | ||
4723351a | 5888 | switch (entry_type) |
b4eb7656 AM |
5889 | { |
5890 | case 0: /* A terminating entry. */ | |
5891 | *start_ptr = start; | |
9f272209 | 5892 | *vstart_ptr = vstart; |
b4eb7656 AM |
5893 | printf (_("<End of list>\n")); |
5894 | return; | |
5895 | case 1: /* A base-address entry. */ | |
5896 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5897 | start += bytes_read; | |
5898 | print_addr_index (idx, 8); | |
9f272209 | 5899 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
5900 | printf (_("(base address selection entry)\n")); |
5901 | continue; | |
5902 | case 2: /* A start/end entry. */ | |
5903 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5904 | start += bytes_read; | |
5905 | print_addr_index (idx, 8); | |
5906 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5907 | start += bytes_read; | |
5908 | print_addr_index (idx, 8); | |
5909 | break; | |
5910 | case 3: /* A start/length entry. */ | |
5911 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5912 | start += bytes_read; | |
5913 | print_addr_index (idx, 8); | |
5914 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
5915 | printf ("%08x ", idx); | |
5916 | break; | |
5917 | case 4: /* An offset pair entry. */ | |
5918 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
5919 | printf ("%08x ", idx); | |
5920 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
5921 | printf ("%08x ", idx); | |
5922 | break; | |
5923 | default: | |
5924 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
5925 | *start_ptr = start; | |
9f272209 | 5926 | *vstart_ptr = vstart; |
b4eb7656 AM |
5927 | return; |
5928 | } | |
4723351a CC |
5929 | |
5930 | if (start + 2 > section_end) | |
b4eb7656 AM |
5931 | { |
5932 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5933 | (unsigned long) offset); |
b4eb7656 AM |
5934 | break; |
5935 | } | |
4723351a | 5936 | |
0c588247 | 5937 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 5938 | if (start + length > section_end) |
b4eb7656 AM |
5939 | { |
5940 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5941 | (unsigned long) offset); |
b4eb7656 AM |
5942 | break; |
5943 | } | |
4723351a CC |
5944 | |
5945 | putchar ('('); | |
5946 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5947 | pointer_size, |
5948 | offset_size, | |
5949 | dwarf_version, | |
5950 | length, | |
5951 | cu_offset, section); | |
4723351a CC |
5952 | putchar (')'); |
5953 | ||
5954 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5955 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
5956 | |
5957 | putchar ('\n'); | |
5958 | ||
5959 | start += length; | |
5960 | } | |
5961 | ||
5962 | *start_ptr = start; | |
9f272209 | 5963 | *vstart_ptr = vstart; |
4723351a CC |
5964 | } |
5965 | ||
9f272209 AO |
5966 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
5967 | loc_views. */ | |
51d0d03f | 5968 | |
9f272209 | 5969 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
5970 | |
5971 | static int | |
5972 | loc_offsets_compar (const void *ap, const void *bp) | |
5973 | { | |
5974 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
5975 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
5976 | ||
9f272209 AO |
5977 | int ret = (a > b) - (b > a); |
5978 | if (ret) | |
5979 | return ret; | |
5980 | ||
5981 | a = loc_views[*(const unsigned int *) ap]; | |
5982 | b = loc_views[*(const unsigned int *) bp]; | |
5983 | ||
5984 | ret = (a > b) - (b > a); | |
5985 | ||
5986 | return ret; | |
51d0d03f JJ |
5987 | } |
5988 | ||
19e6b90e L |
5989 | static int |
5990 | display_debug_loc (struct dwarf_section *section, void *file) | |
5991 | { | |
9f272209 | 5992 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
5993 | unsigned long bytes; |
5994 | unsigned char *section_begin = start; | |
5995 | unsigned int num_loc_list = 0; | |
5996 | unsigned long last_offset = 0; | |
9f272209 | 5997 | unsigned long last_view = 0; |
19e6b90e L |
5998 | unsigned int first = 0; |
5999 | unsigned int i; | |
6000 | unsigned int j; | |
6001 | int seen_first_offset = 0; | |
51d0d03f | 6002 | int locs_sorted = 1; |
9f272209 | 6003 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6004 | unsigned int *array = NULL; |
4723351a CC |
6005 | const char *suffix = strrchr (section->name, '.'); |
6006 | int is_dwo = 0; | |
77145576 JK |
6007 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6008 | dwarf_vma expected_start = 0; | |
4723351a CC |
6009 | |
6010 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
6011 | is_dwo = 1; | |
19e6b90e L |
6012 | |
6013 | bytes = section->size; | |
19e6b90e L |
6014 | |
6015 | if (bytes == 0) | |
6016 | { | |
6017 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6018 | return 0; | |
6019 | } | |
6020 | ||
77145576 JK |
6021 | if (is_loclists) |
6022 | { | |
6023 | unsigned char *hdrptr = section_begin; | |
6024 | dwarf_vma ll_length; | |
6025 | unsigned short ll_version; | |
6026 | unsigned char *end = section_begin + section->size; | |
6027 | unsigned char address_size, segment_selector_size; | |
6028 | uint32_t offset_entry_count; | |
6029 | ||
6030 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6031 | if (ll_length == 0xffffffff) | |
6032 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6033 | ||
6034 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6035 | if (ll_version != 5) | |
6036 | { | |
6037 | warn (_("The %s section contains corrupt or " | |
6038 | "unsupported version number: %d.\n"), | |
6039 | section->name, ll_version); | |
6040 | return 0; | |
6041 | } | |
6042 | ||
6043 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6044 | ||
6045 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6046 | if (segment_selector_size != 0) | |
6047 | { | |
6048 | warn (_("The %s section contains " | |
6049 | "unsupported segment selector size: %d.\n"), | |
6050 | section->name, segment_selector_size); | |
6051 | return 0; | |
6052 | } | |
6053 | ||
6054 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6055 | if (offset_entry_count != 0) | |
6056 | { | |
6057 | warn (_("The %s section contains " | |
6058 | "unsupported offset entry count: %d.\n"), | |
6059 | section->name, offset_entry_count); | |
6060 | return 0; | |
6061 | } | |
6062 | ||
6063 | expected_start = hdrptr - section_begin; | |
6064 | } | |
6065 | ||
1febe64d NC |
6066 | if (load_debug_info (file) == 0) |
6067 | { | |
6068 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6069 | section->name); | |
6070 | return 0; | |
6071 | } | |
19e6b90e L |
6072 | |
6073 | /* Check the order of location list in .debug_info section. If | |
6074 | offsets of location lists are in the ascending order, we can | |
6075 | use `debug_information' directly. */ | |
6076 | for (i = 0; i < num_debug_info_entries; i++) | |
6077 | { | |
6078 | unsigned int num; | |
6079 | ||
6080 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6081 | if (num > num_loc_list) |
6082 | num_loc_list = num; | |
19e6b90e L |
6083 | |
6084 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6085 | if (locs_sorted && num != 0) |
19e6b90e L |
6086 | { |
6087 | if (!seen_first_offset) | |
6088 | { | |
6089 | /* This is the first location list. */ | |
6090 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6091 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6092 | first = i; |
6093 | seen_first_offset = 1; | |
6094 | j = 1; | |
6095 | } | |
6096 | else | |
6097 | j = 0; | |
6098 | ||
6099 | for (; j < num; j++) | |
6100 | { | |
6101 | if (last_offset > | |
9f272209 AO |
6102 | debug_information [i].loc_offsets [j] |
6103 | || (last_offset == debug_information [i].loc_offsets [j] | |
6104 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6105 | { |
51d0d03f | 6106 | locs_sorted = 0; |
19e6b90e L |
6107 | break; |
6108 | } | |
6109 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6110 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6111 | } |
6112 | } | |
6113 | } | |
6114 | ||
19e6b90e L |
6115 | if (!seen_first_offset) |
6116 | error (_("No location lists in .debug_info section!\n")); | |
6117 | ||
d4bfc77b | 6118 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6119 | && debug_information [first].loc_offsets [0] != expected_start |
6120 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6121 | warn (_("Location lists in %s section start at 0x%s\n"), |
6122 | section->name, | |
6123 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6124 | |
51d0d03f JJ |
6125 | if (!locs_sorted) |
6126 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
6127 | |
6128 | introduce (section, FALSE); | |
6129 | ||
d1c4b12b NC |
6130 | if (reloc_at (section, 0)) |
6131 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6132 | |
d1c4b12b | 6133 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6134 | |
6135 | seen_first_offset = 0; | |
6136 | for (i = first; i < num_debug_info_entries; i++) | |
6137 | { | |
9f272209 | 6138 | dwarf_vma offset, voffset; |
359ca075 | 6139 | dwarf_vma base_address; |
d1c4b12b | 6140 | unsigned int k; |
19e6b90e L |
6141 | int has_frame_base; |
6142 | ||
51d0d03f JJ |
6143 | if (!locs_sorted) |
6144 | { | |
6145 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6146 | array[k] = k; | |
6147 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6148 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6149 | qsort (array, debug_information [i].num_loc_offsets, |
6150 | sizeof (*array), loc_offsets_compar); | |
6151 | } | |
19e6b90e | 6152 | |
9f272209 | 6153 | int adjacent_view_loclists = 1; |
51d0d03f | 6154 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6155 | { |
51d0d03f JJ |
6156 | j = locs_sorted ? k : array[k]; |
6157 | if (k | |
9f272209 | 6158 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6159 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6160 | == debug_information [i].loc_offsets [j]) |
6161 | && (debug_information [i].loc_views [locs_sorted | |
6162 | ? k - 1 : array [k - 1]] | |
6163 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6164 | continue; |
19e6b90e | 6165 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6166 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6167 | next = section_begin + offset; |
9f272209 AO |
6168 | voffset = debug_information [i].loc_views [j]; |
6169 | if (voffset != vm1) | |
6170 | vnext = section_begin + voffset; | |
6171 | else | |
6172 | vnext = NULL; | |
19e6b90e L |
6173 | base_address = debug_information [i].base_address; |
6174 | ||
9f272209 AO |
6175 | if (vnext && vnext < next) |
6176 | { | |
6177 | vstart = vnext; | |
6178 | display_view_pair_list (section, &vstart, i, next); | |
6179 | if (start == vnext) | |
6180 | start = vstart; | |
6181 | } | |
6182 | ||
6183 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
6184 | seen_first_offset = 1; |
6185 | else | |
6186 | { | |
6187 | if (start < next) | |
6188 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6189 | (unsigned long) (start - section_begin), |
c8071705 | 6190 | (unsigned long) offset); |
19e6b90e L |
6191 | else if (start > next) |
6192 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6193 | (unsigned long) (start - section_begin), |
c8071705 | 6194 | (unsigned long) offset); |
19e6b90e L |
6195 | } |
6196 | start = next; | |
9f272209 | 6197 | vstart = vnext; |
19e6b90e L |
6198 | |
6199 | if (offset >= bytes) | |
6200 | { | |
6201 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 6202 | (unsigned long) offset); |
19e6b90e L |
6203 | continue; |
6204 | } | |
6205 | ||
9f272209 AO |
6206 | if (vnext && voffset >= bytes) |
6207 | { | |
6208 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
6209 | (unsigned long) voffset); | |
6210 | continue; | |
6211 | } | |
6212 | ||
77145576 JK |
6213 | if (!is_loclists) |
6214 | { | |
6215 | if (is_dwo) | |
6216 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 6217 | &vstart, has_frame_base); |
77145576 JK |
6218 | else |
6219 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 6220 | &vstart, has_frame_base); |
77145576 | 6221 | } |
b4eb7656 | 6222 | else |
77145576 JK |
6223 | { |
6224 | if (is_dwo) | |
6225 | warn (_("DWO is not yet supported.\n")); | |
6226 | else | |
6227 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
6228 | &vstart, has_frame_base); |
6229 | } | |
6230 | ||
6231 | /* FIXME: this arrangement is quite simplistic. Nothing | |
6232 | requires locview lists to be adjacent to corresponding | |
6233 | loclists, and a single loclist could be augmented by | |
6234 | different locview lists, and vice-versa, unlikely as it | |
6235 | is that it would make sense to do so. Hopefully we'll | |
6236 | have view pair support built into loclists before we ever | |
6237 | need to address all these possibilities. */ | |
6238 | if (adjacent_view_loclists && vnext | |
6239 | && vnext != start && vstart != next) | |
6240 | { | |
6241 | adjacent_view_loclists = 0; | |
6242 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 6243 | } |
9f272209 AO |
6244 | |
6245 | if (vnext && vnext == start) | |
6246 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
6247 | } |
6248 | } | |
031cd65f | 6249 | |
4723351a | 6250 | if (start < section->start + section->size) |
d3a49aa8 AM |
6251 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
6252 | "There are %ld unused bytes at the end of section %s\n", | |
6253 | (long) (section->start + section->size - start)), | |
4723351a | 6254 | (long) (section->start + section->size - start), section->name); |
98fb390a | 6255 | putchar ('\n'); |
51d0d03f | 6256 | free (array); |
19e6b90e L |
6257 | return 1; |
6258 | } | |
6259 | ||
6260 | static int | |
6261 | display_debug_str (struct dwarf_section *section, | |
6262 | void *file ATTRIBUTE_UNUSED) | |
6263 | { | |
6264 | unsigned char *start = section->start; | |
6265 | unsigned long bytes = section->size; | |
6266 | dwarf_vma addr = section->address; | |
6267 | ||
6268 | if (bytes == 0) | |
6269 | { | |
6270 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6271 | return 0; | |
6272 | } | |
6273 | ||
dda8d76d | 6274 | introduce (section, FALSE); |
19e6b90e L |
6275 | |
6276 | while (bytes) | |
6277 | { | |
6278 | int j; | |
6279 | int k; | |
6280 | int lbytes; | |
6281 | ||
6282 | lbytes = (bytes > 16 ? 16 : bytes); | |
6283 | ||
6284 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
6285 | ||
6286 | for (j = 0; j < 16; j++) | |
6287 | { | |
6288 | if (j < lbytes) | |
6289 | printf ("%2.2x", start[j]); | |
6290 | else | |
6291 | printf (" "); | |
6292 | ||
6293 | if ((j & 3) == 3) | |
6294 | printf (" "); | |
6295 | } | |
6296 | ||
6297 | for (j = 0; j < lbytes; j++) | |
6298 | { | |
6299 | k = start[j]; | |
6300 | if (k >= ' ' && k < 0x80) | |
6301 | printf ("%c", k); | |
6302 | else | |
6303 | printf ("."); | |
6304 | } | |
6305 | ||
6306 | putchar ('\n'); | |
6307 | ||
6308 | start += lbytes; | |
6309 | addr += lbytes; | |
6310 | bytes -= lbytes; | |
6311 | } | |
6312 | ||
6313 | putchar ('\n'); | |
6314 | ||
6315 | return 1; | |
6316 | } | |
6317 | ||
19e6b90e L |
6318 | static int |
6319 | display_debug_info (struct dwarf_section *section, void *file) | |
6320 | { | |
d85bf2ba | 6321 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
6322 | } |
6323 | ||
2b6f5997 CC |
6324 | static int |
6325 | display_debug_types (struct dwarf_section *section, void *file) | |
6326 | { | |
d85bf2ba | 6327 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
6328 | } |
6329 | ||
6330 | static int | |
6331 | display_trace_info (struct dwarf_section *section, void *file) | |
6332 | { | |
d85bf2ba | 6333 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 6334 | } |
19e6b90e L |
6335 | |
6336 | static int | |
6337 | display_debug_aranges (struct dwarf_section *section, | |
6338 | void *file ATTRIBUTE_UNUSED) | |
6339 | { | |
6340 | unsigned char *start = section->start; | |
6341 | unsigned char *end = start + section->size; | |
6342 | ||
dda8d76d | 6343 | introduce (section, FALSE); |
19e6b90e | 6344 | |
6e3d6dc1 NC |
6345 | /* It does not matter if this load fails, |
6346 | we test for that later on. */ | |
6347 | load_debug_info (file); | |
6348 | ||
19e6b90e L |
6349 | while (start < end) |
6350 | { | |
6351 | unsigned char *hdrptr; | |
6352 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 6353 | unsigned char *addr_ranges; |
2d9472a2 NC |
6354 | dwarf_vma length; |
6355 | dwarf_vma address; | |
e98fdf1a | 6356 | unsigned long sec_off; |
53b8873b | 6357 | unsigned char address_size; |
19e6b90e | 6358 | int excess; |
bf5117e3 NC |
6359 | unsigned int offset_size; |
6360 | unsigned int initial_length_size; | |
19e6b90e L |
6361 | |
6362 | hdrptr = start; | |
6363 | ||
0c588247 | 6364 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
6365 | if (arange.ar_length == 0xffffffff) |
6366 | { | |
0c588247 | 6367 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
6368 | offset_size = 8; |
6369 | initial_length_size = 12; | |
6370 | } | |
6371 | else | |
6372 | { | |
6373 | offset_size = 4; | |
6374 | initial_length_size = 4; | |
6375 | } | |
6376 | ||
e98fdf1a AM |
6377 | sec_off = hdrptr - section->start; |
6378 | if (sec_off + arange.ar_length < sec_off | |
6379 | || sec_off + arange.ar_length > section->size) | |
6380 | { | |
6381 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
6382 | section->name, | |
6383 | sec_off - initial_length_size, | |
6384 | dwarf_vmatoa ("x", arange.ar_length)); | |
6385 | break; | |
6386 | } | |
6387 | ||
0c588247 NC |
6388 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
6389 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 6390 | |
6e3d6dc1 NC |
6391 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
6392 | && num_debug_info_entries > 0 | |
6393 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
6394 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 6395 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 6396 | |
0c588247 NC |
6397 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
6398 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
6399 | |
6400 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
6401 | { | |
67f101ee NC |
6402 | /* PR 19872: A version number of 0 probably means that there is |
6403 | padding at the end of the .debug_aranges section. Gold puts | |
6404 | it there when performing an incremental link, for example. | |
6405 | So do not generate a warning in this case. */ | |
6406 | if (arange.ar_version) | |
6407 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
6408 | break; |
6409 | } | |
6410 | ||
47704ddf KT |
6411 | printf (_(" Length: %ld\n"), |
6412 | (long) arange.ar_length); | |
19e6b90e | 6413 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
6414 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
6415 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
6416 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
6417 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
6418 | ||
53b8873b NC |
6419 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
6420 | ||
f41e4712 NC |
6421 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
6422 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
6423 | { |
6424 | error (_("Invalid address size in %s section!\n"), | |
6425 | section->name); | |
6426 | break; | |
6427 | } | |
6428 | ||
53b8873b NC |
6429 | /* The DWARF spec does not require that the address size be a power |
6430 | of two, but we do. This will have to change if we ever encounter | |
6431 | an uneven architecture. */ | |
6432 | if ((address_size & (address_size - 1)) != 0) | |
6433 | { | |
6434 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
6435 | break; | |
6436 | } | |
cecf136e | 6437 | |
209c9a13 NC |
6438 | if (address_size > 4) |
6439 | printf (_("\n Address Length\n")); | |
6440 | else | |
6441 | printf (_("\n Address Length\n")); | |
19e6b90e | 6442 | |
91d6fa6a | 6443 | addr_ranges = hdrptr; |
19e6b90e | 6444 | |
53b8873b NC |
6445 | /* Must pad to an alignment boundary that is twice the address size. */ |
6446 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 6447 | if (excess) |
91d6fa6a | 6448 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 6449 | |
e98fdf1a | 6450 | start += arange.ar_length + initial_length_size; |
1617e571 | 6451 | |
91d6fa6a | 6452 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 6453 | { |
0c588247 NC |
6454 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
6455 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 6456 | |
80c35038 | 6457 | printf (" "); |
2d9472a2 NC |
6458 | print_dwarf_vma (address, address_size); |
6459 | print_dwarf_vma (length, address_size); | |
6460 | putchar ('\n'); | |
19e6b90e | 6461 | } |
19e6b90e L |
6462 | } |
6463 | ||
6464 | printf ("\n"); | |
6465 | ||
6466 | return 1; | |
6467 | } | |
6468 | ||
4723351a CC |
6469 | /* Comparison function for qsort. */ |
6470 | static int | |
6471 | comp_addr_base (const void * v0, const void * v1) | |
6472 | { | |
6473 | debug_info * info0 = (debug_info *) v0; | |
6474 | debug_info * info1 = (debug_info *) v1; | |
6475 | return info0->addr_base - info1->addr_base; | |
6476 | } | |
6477 | ||
6478 | /* Display the debug_addr section. */ | |
6479 | static int | |
6480 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 6481 | void *file) |
4723351a CC |
6482 | { |
6483 | debug_info **debug_addr_info; | |
6484 | unsigned char *entry; | |
6485 | unsigned char *end; | |
6486 | unsigned int i; | |
6487 | unsigned int count; | |
6488 | ||
6489 | if (section->size == 0) | |
6490 | { | |
6491 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6492 | return 0; | |
6493 | } | |
6494 | ||
6495 | if (load_debug_info (file) == 0) | |
6496 | { | |
6497 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6498 | section->name); | |
6499 | return 0; | |
6500 | } | |
6501 | ||
dda8d76d | 6502 | introduce (section, FALSE); |
4723351a | 6503 | |
1306a742 NC |
6504 | /* PR 17531: file: cf38d01b. |
6505 | We use xcalloc because a corrupt file may not have initialised all of the | |
6506 | fields in the debug_info structure, which means that the sort below might | |
6507 | try to move uninitialised data. */ | |
6508 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 6509 | sizeof (debug_info *)); |
4723351a CC |
6510 | |
6511 | count = 0; | |
6512 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 6513 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
6514 | { |
6515 | /* PR 17531: file: cf38d01b. */ | |
6516 | if (debug_information[i].addr_base >= section->size) | |
6517 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
6518 | (unsigned long) debug_information[i].addr_base, i); | |
6519 | else | |
6520 | debug_addr_info [count++] = debug_information + i; | |
6521 | } | |
4723351a CC |
6522 | |
6523 | /* Add a sentinel to make iteration convenient. */ | |
6524 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
6525 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 6526 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 6527 | |
4723351a CC |
6528 | for (i = 0; i < count; i++) |
6529 | { | |
6530 | unsigned int idx; | |
fab128ef | 6531 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
6532 | |
6533 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 6534 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 6535 | |
fab128ef | 6536 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
6537 | entry = section->start + debug_addr_info [i]->addr_base; |
6538 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
6539 | idx = 0; | |
6540 | while (entry < end) | |
b4eb7656 AM |
6541 | { |
6542 | dwarf_vma base = byte_get (entry, address_size); | |
6543 | printf (_("\t%d:\t"), idx); | |
6544 | print_dwarf_vma (base, address_size); | |
6545 | printf ("\n"); | |
6546 | entry += address_size; | |
6547 | idx++; | |
6548 | } | |
4723351a CC |
6549 | } |
6550 | printf ("\n"); | |
6551 | ||
6552 | free (debug_addr_info); | |
6553 | return 1; | |
6554 | } | |
6555 | ||
6556 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
6557 | static int | |
6558 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 6559 | void *file ATTRIBUTE_UNUSED) |
4723351a CC |
6560 | { |
6561 | if (section->size == 0) | |
6562 | { | |
6563 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6564 | return 0; | |
6565 | } | |
6566 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
6567 | what the offset size is for this section. */ | |
6568 | return 1; | |
6569 | } | |
6570 | ||
01a8f077 JK |
6571 | /* Each debug_information[x].range_lists[y] gets this representation for |
6572 | sorting purposes. */ | |
6573 | ||
6574 | struct range_entry | |
467c65bc NC |
6575 | { |
6576 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 6577 | dwarf_vma ranges_offset; |
01a8f077 | 6578 | |
467c65bc NC |
6579 | /* Original debug_information to find parameters of the data. */ |
6580 | debug_info *debug_info_p; | |
6581 | }; | |
01a8f077 JK |
6582 | |
6583 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
6584 | ||
6585 | static int | |
6586 | range_entry_compar (const void *ap, const void *bp) | |
6587 | { | |
3f5e193b NC |
6588 | const struct range_entry *a_re = (const struct range_entry *) ap; |
6589 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
6590 | const dwarf_vma a = a_re->ranges_offset; |
6591 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
6592 | |
6593 | return (a > b) - (b > a); | |
6594 | } | |
6595 | ||
77145576 JK |
6596 | static void |
6597 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
6598 | unsigned int pointer_size, unsigned long offset, | |
6599 | unsigned long base_address) | |
6600 | { | |
6601 | while (start < finish) | |
6602 | { | |
6603 | dwarf_vma begin; | |
6604 | dwarf_vma end; | |
6605 | ||
6606 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6607 | if (start >= finish) | |
6608 | break; | |
6609 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6610 | ||
d11ae95e | 6611 | |
77145576 JK |
6612 | printf (" %8.8lx ", offset); |
6613 | ||
6614 | if (begin == 0 && end == 0) | |
6615 | { | |
6616 | printf (_("<End of list>\n")); | |
6617 | break; | |
6618 | } | |
6619 | ||
6620 | /* Check base address specifiers. */ | |
6621 | if (is_max_address (begin, pointer_size) | |
6622 | && !is_max_address (end, pointer_size)) | |
6623 | { | |
6624 | base_address = end; | |
6625 | print_dwarf_vma (begin, pointer_size); | |
6626 | print_dwarf_vma (end, pointer_size); | |
6627 | printf ("(base address)\n"); | |
6628 | continue; | |
6629 | } | |
6630 | ||
6631 | print_dwarf_vma (begin + base_address, pointer_size); | |
6632 | print_dwarf_vma (end + base_address, pointer_size); | |
6633 | ||
6634 | if (begin == end) | |
6635 | fputs (_("(start == end)"), stdout); | |
6636 | else if (begin > end) | |
6637 | fputs (_("(start > end)"), stdout); | |
6638 | ||
6639 | putchar ('\n'); | |
6640 | } | |
6641 | } | |
6642 | ||
6643 | static void | |
6644 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
6645 | unsigned int pointer_size, unsigned long offset, | |
6646 | unsigned long base_address) | |
6647 | { | |
6648 | unsigned char *next = start; | |
6649 | ||
6650 | while (1) | |
6651 | { | |
6652 | unsigned long off = offset + (start - next); | |
6653 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
6654 | /* Initialize it due to a false compiler warning. */ |
6655 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
6656 | unsigned int bytes_read; |
6657 | ||
6658 | if (start + 1 > finish) | |
6659 | { | |
6660 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
6661 | offset); | |
6662 | break; | |
6663 | } | |
6664 | ||
6665 | printf (" %8.8lx ", off); | |
6666 | ||
6667 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
6668 | ||
6669 | switch (rlet) | |
6670 | { | |
6671 | case DW_RLE_end_of_list: | |
6672 | printf (_("<End of list>\n")); | |
6673 | break; | |
6674 | case DW_RLE_base_address: | |
6675 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
6676 | print_dwarf_vma (base_address, pointer_size); | |
6677 | printf (_("(base address)\n")); | |
6678 | break; | |
6679 | case DW_RLE_start_length: | |
6680 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6681 | length = read_uleb128 (start, &bytes_read, finish); | |
6682 | start += bytes_read; | |
6683 | end = begin + length; | |
6684 | break; | |
6685 | case DW_RLE_offset_pair: | |
6686 | begin = read_uleb128 (start, &bytes_read, finish); | |
6687 | start += bytes_read; | |
6688 | end = read_uleb128 (start, &bytes_read, finish); | |
6689 | start += bytes_read; | |
6690 | break; | |
6691 | case DW_RLE_start_end: | |
6692 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6693 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6694 | break; | |
6695 | default: | |
6696 | error (_("Invalid range list entry type %d\n"), rlet); | |
6697 | rlet = DW_RLE_end_of_list; | |
6698 | break; | |
6699 | } | |
6700 | if (rlet == DW_RLE_end_of_list) | |
6701 | break; | |
6702 | if (rlet == DW_RLE_base_address) | |
6703 | continue; | |
6704 | ||
6705 | print_dwarf_vma (begin + base_address, pointer_size); | |
6706 | print_dwarf_vma (end + base_address, pointer_size); | |
6707 | ||
6708 | if (begin == end) | |
6709 | fputs (_("(start == end)"), stdout); | |
6710 | else if (begin > end) | |
6711 | fputs (_("(start > end)"), stdout); | |
6712 | ||
6713 | putchar ('\n'); | |
6714 | } | |
6715 | } | |
6716 | ||
19e6b90e L |
6717 | static int |
6718 | display_debug_ranges (struct dwarf_section *section, | |
6719 | void *file ATTRIBUTE_UNUSED) | |
6720 | { | |
6721 | unsigned char *start = section->start; | |
a2ff7a4b | 6722 | unsigned char *last_start = start; |
f6f0e17b | 6723 | unsigned long bytes = section->size; |
19e6b90e | 6724 | unsigned char *section_begin = start; |
f6f0e17b | 6725 | unsigned char *finish = start + bytes; |
01a8f077 JK |
6726 | unsigned int num_range_list, i; |
6727 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
6728 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
6729 | /* Initialize it due to a false compiler warning. */ | |
6730 | unsigned char address_size = 0; | |
19e6b90e | 6731 | |
19e6b90e L |
6732 | if (bytes == 0) |
6733 | { | |
6734 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6735 | return 0; | |
6736 | } | |
6737 | ||
77145576 JK |
6738 | if (is_rnglists) |
6739 | { | |
6740 | dwarf_vma initial_length; | |
6741 | unsigned int initial_length_size; | |
6742 | unsigned char segment_selector_size; | |
6743 | unsigned int offset_size, offset_entry_count; | |
6744 | unsigned short version; | |
6745 | ||
6746 | /* Get and check the length of the block. */ | |
6747 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
6748 | ||
6749 | if (initial_length == 0xffffffff) | |
6750 | { | |
6751 | /* This section is 64-bit DWARF 3. */ | |
6752 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
6753 | offset_size = 8; | |
6754 | initial_length_size = 12; | |
6755 | } | |
6756 | else | |
6757 | { | |
6758 | offset_size = 4; | |
6759 | initial_length_size = 4; | |
6760 | } | |
6761 | ||
6762 | if (initial_length + initial_length_size > section->size) | |
6763 | { | |
6764 | /* If the length field has a relocation against it, then we should | |
6765 | not complain if it is inaccurate (and probably negative). | |
6766 | It is copied from .debug_line handling code. */ | |
6767 | if (reloc_at (section, (start - section->start) - offset_size)) | |
6768 | { | |
6769 | initial_length = (finish - start) - initial_length_size; | |
6770 | } | |
6771 | else | |
6772 | { | |
6773 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
6774 | (long) initial_length); | |
6775 | return 0; | |
6776 | } | |
6777 | } | |
6778 | ||
6779 | /* Get and check the version number. */ | |
6780 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
6781 | ||
6782 | if (version != 5) | |
6783 | { | |
6784 | warn (_("Only DWARF version 5 debug_rnglists info " | |
6785 | "is currently supported.\n")); | |
6786 | return 0; | |
6787 | } | |
6788 | ||
6789 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
6790 | ||
6791 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
6792 | if (segment_selector_size != 0) | |
6793 | { | |
6794 | warn (_("The %s section contains " | |
6795 | "unsupported segment selector size: %d.\n"), | |
6796 | section->name, segment_selector_size); | |
6797 | return 0; | |
6798 | } | |
6799 | ||
6800 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
6801 | if (offset_entry_count != 0) | |
6802 | { | |
6803 | warn (_("The %s section contains " | |
6804 | "unsupported offset entry count: %u.\n"), | |
6805 | section->name, offset_entry_count); | |
6806 | return 0; | |
6807 | } | |
6808 | } | |
6809 | ||
1febe64d NC |
6810 | if (load_debug_info (file) == 0) |
6811 | { | |
6812 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6813 | section->name); | |
6814 | return 0; | |
6815 | } | |
19e6b90e | 6816 | |
01a8f077 | 6817 | num_range_list = 0; |
19e6b90e | 6818 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 6819 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 6820 | |
01a8f077 | 6821 | if (num_range_list == 0) |
4723351a CC |
6822 | { |
6823 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 6824 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
6825 | printf (_("No range lists in .debug_info section.\n")); |
6826 | return 1; | |
6827 | } | |
19e6b90e | 6828 | |
3f5e193b NC |
6829 | range_entries = (struct range_entry *) |
6830 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 6831 | range_entry_fill = range_entries; |
19e6b90e | 6832 | |
01a8f077 JK |
6833 | for (i = 0; i < num_debug_info_entries; i++) |
6834 | { | |
6835 | debug_info *debug_info_p = &debug_information[i]; | |
6836 | unsigned int j; | |
6837 | ||
6838 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
6839 | { | |
6840 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
6841 | range_entry_fill->debug_info_p = debug_info_p; | |
6842 | range_entry_fill++; | |
19e6b90e L |
6843 | } |
6844 | } | |
6845 | ||
01a8f077 JK |
6846 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
6847 | range_entry_compar); | |
19e6b90e | 6848 | |
d493b283 | 6849 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 6850 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 6851 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 6852 | |
dda8d76d NC |
6853 | introduce (section, FALSE); |
6854 | ||
19e6b90e L |
6855 | printf (_(" Offset Begin End\n")); |
6856 | ||
01a8f077 | 6857 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 6858 | { |
01a8f077 JK |
6859 | struct range_entry *range_entry = &range_entries[i]; |
6860 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 6861 | unsigned int pointer_size; |
359ca075 | 6862 | dwarf_vma offset; |
01a8f077 | 6863 | unsigned char *next; |
359ca075 | 6864 | dwarf_vma base_address; |
19e6b90e | 6865 | |
77145576 | 6866 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 6867 | offset = range_entry->ranges_offset; |
01a8f077 JK |
6868 | next = section_begin + offset; |
6869 | base_address = debug_info_p->base_address; | |
cecf136e | 6870 | |
f41e4712 NC |
6871 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
6872 | if (pointer_size < 2 || pointer_size > 8) | |
6873 | { | |
6874 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 6875 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
6876 | continue; |
6877 | } | |
b4eb7656 | 6878 | |
d11ae95e NC |
6879 | if (next < section_begin || next >= finish) |
6880 | { | |
6881 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
6882 | (unsigned long) offset, i); | |
6883 | continue; | |
6884 | } | |
6885 | ||
4723351a | 6886 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 6887 | { |
01a8f077 JK |
6888 | if (start < next) |
6889 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
6890 | (unsigned long) (start - section_begin), | |
6891 | (unsigned long) (next - section_begin), section->name); | |
6892 | else if (start > next) | |
a2ff7a4b AM |
6893 | { |
6894 | if (next == last_start) | |
6895 | continue; | |
6896 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
6897 | (unsigned long) (start - section_begin), | |
6898 | (unsigned long) (next - section_begin), section->name); | |
6899 | } | |
01a8f077 | 6900 | } |
d11ae95e | 6901 | |
01a8f077 | 6902 | start = next; |
a2ff7a4b | 6903 | last_start = next; |
19e6b90e | 6904 | |
77145576 JK |
6905 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
6906 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
6907 | } |
6908 | putchar ('\n'); | |
01a8f077 JK |
6909 | |
6910 | free (range_entries); | |
6911 | ||
19e6b90e L |
6912 | return 1; |
6913 | } | |
6914 | ||
6915 | typedef struct Frame_Chunk | |
6916 | { | |
6917 | struct Frame_Chunk *next; | |
6918 | unsigned char *chunk_start; | |
a1165289 | 6919 | unsigned int ncols; |
19e6b90e L |
6920 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
6921 | short int *col_type; | |
6922 | int *col_offset; | |
6923 | char *augmentation; | |
6924 | unsigned int code_factor; | |
6925 | int data_factor; | |
bf5117e3 NC |
6926 | dwarf_vma pc_begin; |
6927 | dwarf_vma pc_range; | |
32ef3000 | 6928 | unsigned int cfa_reg; |
c8071705 | 6929 | dwarf_vma cfa_offset; |
a1165289 | 6930 | unsigned int ra; |
19e6b90e L |
6931 | unsigned char fde_encoding; |
6932 | unsigned char cfa_exp; | |
604282a7 JJ |
6933 | unsigned char ptr_size; |
6934 | unsigned char segment_size; | |
19e6b90e L |
6935 | } |
6936 | Frame_Chunk; | |
6937 | ||
665ce1f6 L |
6938 | static const char *const *dwarf_regnames; |
6939 | static unsigned int dwarf_regnames_count; | |
6940 | ||
19e6b90e L |
6941 | /* A marker for a col_type that means this column was never referenced |
6942 | in the frame info. */ | |
6943 | #define DW_CFA_unreferenced (-1) | |
6944 | ||
a1165289 | 6945 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
6946 | -1 for invalid reg. */ |
6947 | ||
6948 | static int | |
6949 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 6950 | { |
a1165289 | 6951 | unsigned int prev = fc->ncols; |
19e6b90e | 6952 | |
665ce1f6 L |
6953 | if (reg < (unsigned int) fc->ncols) |
6954 | return 0; | |
6955 | ||
6956 | if (dwarf_regnames_count | |
6957 | && reg > dwarf_regnames_count) | |
6958 | return -1; | |
19e6b90e L |
6959 | |
6960 | fc->ncols = reg + 1; | |
a1165289 NC |
6961 | /* PR 17512: file: 10450-2643-0.004. |
6962 | If reg == -1 then this can happen... */ | |
6963 | if (fc->ncols == 0) | |
6964 | return -1; | |
6965 | ||
06614111 NC |
6966 | /* PR 17512: file: 2844a11d. */ |
6967 | if (fc->ncols > 1024) | |
6968 | { | |
6969 | error (_("Unfeasibly large register number: %u\n"), reg); | |
6970 | fc->ncols = 0; | |
6971 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
6972 | we ever encounter a valid binary that exceeds it. */ | |
6973 | return -1; | |
6974 | } | |
6975 | ||
3f5e193b | 6976 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 6977 | sizeof (short int)); |
3f5e193b | 6978 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 6979 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
6980 | if (fc->col_type == NULL || fc->col_offset == NULL) |
6981 | { | |
6982 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
6983 | fc->ncols); | |
6984 | fc->ncols = 0; | |
6985 | return -1; | |
6986 | } | |
19e6b90e L |
6987 | |
6988 | while (prev < fc->ncols) | |
6989 | { | |
6990 | fc->col_type[prev] = DW_CFA_unreferenced; | |
6991 | fc->col_offset[prev] = 0; | |
6992 | prev++; | |
6993 | } | |
665ce1f6 | 6994 | return 1; |
19e6b90e L |
6995 | } |
6996 | ||
2dc4cec1 L |
6997 | static const char *const dwarf_regnames_i386[] = |
6998 | { | |
43234a1e L |
6999 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7000 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7001 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7002 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7003 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7004 | NULL, NULL, /* 19 - 20 */ | |
7005 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7006 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7007 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7008 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7009 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7010 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7011 | "tr", "ldtr", /* 48 - 49 */ | |
7012 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7013 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7014 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7015 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7016 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7017 | NULL, NULL, NULL, /* 90 - 92 */ | |
7018 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7019 | }; |
7020 | ||
3d875af5 L |
7021 | static const char *const dwarf_regnames_iamcu[] = |
7022 | { | |
7023 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
7024 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7025 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7026 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
7027 | NULL, NULL, /* 19 - 20 */ | |
7028 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
7029 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
7030 | NULL, NULL, NULL, /* 37 - 39 */ | |
7031 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7032 | "tr", "ldtr", /* 48 - 49 */ | |
7033 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7034 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7035 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7036 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7037 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7038 | NULL, NULL, NULL, /* 90 - 92 */ | |
7039 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
7040 | }; | |
7041 | ||
b129eb0e RH |
7042 | void |
7043 | init_dwarf_regnames_i386 (void) | |
7044 | { | |
7045 | dwarf_regnames = dwarf_regnames_i386; | |
7046 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
7047 | } | |
7048 | ||
3d875af5 L |
7049 | void |
7050 | init_dwarf_regnames_iamcu (void) | |
7051 | { | |
7052 | dwarf_regnames = dwarf_regnames_iamcu; | |
7053 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
7054 | } | |
7055 | ||
2dc4cec1 L |
7056 | static const char *const dwarf_regnames_x86_64[] = |
7057 | { | |
7058 | "rax", "rdx", "rcx", "rbx", | |
7059 | "rsi", "rdi", "rbp", "rsp", | |
7060 | "r8", "r9", "r10", "r11", | |
7061 | "r12", "r13", "r14", "r15", | |
7062 | "rip", | |
7063 | "xmm0", "xmm1", "xmm2", "xmm3", | |
7064 | "xmm4", "xmm5", "xmm6", "xmm7", | |
7065 | "xmm8", "xmm9", "xmm10", "xmm11", | |
7066 | "xmm12", "xmm13", "xmm14", "xmm15", | |
7067 | "st0", "st1", "st2", "st3", | |
7068 | "st4", "st5", "st6", "st7", | |
7069 | "mm0", "mm1", "mm2", "mm3", | |
7070 | "mm4", "mm5", "mm6", "mm7", | |
7071 | "rflags", | |
7072 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
7073 | "fs.base", "gs.base", NULL, NULL, | |
7074 | "tr", "ldtr", | |
43234a1e L |
7075 | "mxcsr", "fcw", "fsw", |
7076 | "xmm16", "xmm17", "xmm18", "xmm19", | |
7077 | "xmm20", "xmm21", "xmm22", "xmm23", | |
7078 | "xmm24", "xmm25", "xmm26", "xmm27", | |
7079 | "xmm28", "xmm29", "xmm30", "xmm31", | |
7080 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
7081 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
7082 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
7083 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
7084 | NULL, NULL, NULL, /* 115 - 117 */ | |
7085 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
7086 | }; |
7087 | ||
b129eb0e RH |
7088 | void |
7089 | init_dwarf_regnames_x86_64 (void) | |
7090 | { | |
7091 | dwarf_regnames = dwarf_regnames_x86_64; | |
7092 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
7093 | } | |
7094 | ||
4ee22035 RH |
7095 | static const char *const dwarf_regnames_aarch64[] = |
7096 | { | |
b4eb7656 AM |
7097 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
7098 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
7099 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
7100 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
7101 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
7102 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7103 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7104 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
b4eb7656 AM |
7105 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
7106 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
7107 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
7108 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
7109 | }; | |
7110 | ||
7111 | void | |
7112 | init_dwarf_regnames_aarch64 (void) | |
7113 | { | |
7114 | dwarf_regnames = dwarf_regnames_aarch64; | |
7115 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
7116 | } | |
7117 | ||
d6bb17b0 AA |
7118 | static const char *const dwarf_regnames_s390[] = |
7119 | { | |
7120 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
7121 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7122 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7123 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
7124 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
7125 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
7126 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
7127 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
7128 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
7129 | "pswm", "pswa", | |
7130 | NULL, NULL, | |
7131 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
7132 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
7133 | }; | |
7134 | ||
7135 | void | |
7136 | init_dwarf_regnames_s390 (void) | |
7137 | { | |
7138 | dwarf_regnames = dwarf_regnames_s390; | |
7139 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
7140 | } | |
7141 | ||
5bb0830d AB |
7142 | static const char *const dwarf_regnames_riscv[] = |
7143 | { | |
7144 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
7145 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
7146 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
7147 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
7148 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
7149 | "fs0", "fs1", /* 40 - 41 */ | |
7150 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
7151 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
7152 | "fs10", "fs11", /* 58 - 59 */ | |
7153 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
7154 | }; | |
7155 | ||
7156 | void | |
7157 | init_dwarf_regnames_riscv (void) | |
7158 | { | |
7159 | dwarf_regnames = dwarf_regnames_riscv; | |
7160 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_riscv); | |
7161 | } | |
7162 | ||
2dc4cec1 L |
7163 | void |
7164 | init_dwarf_regnames (unsigned int e_machine) | |
7165 | { | |
7166 | switch (e_machine) | |
7167 | { | |
7168 | case EM_386: | |
b129eb0e | 7169 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
7170 | break; |
7171 | ||
3d875af5 L |
7172 | case EM_IAMCU: |
7173 | init_dwarf_regnames_iamcu (); | |
7174 | break; | |
7175 | ||
2dc4cec1 | 7176 | case EM_X86_64: |
7f502d6c | 7177 | case EM_L1OM: |
7a9068fe | 7178 | case EM_K1OM: |
b129eb0e | 7179 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
7180 | break; |
7181 | ||
4ee22035 RH |
7182 | case EM_AARCH64: |
7183 | init_dwarf_regnames_aarch64 (); | |
7184 | break; | |
7185 | ||
d6bb17b0 AA |
7186 | case EM_S390: |
7187 | init_dwarf_regnames_s390 (); | |
7188 | break; | |
7189 | ||
5bb0830d AB |
7190 | case EM_RISCV: |
7191 | init_dwarf_regnames_riscv (); | |
7192 | break; | |
7193 | ||
2dc4cec1 L |
7194 | default: |
7195 | break; | |
7196 | } | |
7197 | } | |
7198 | ||
7199 | static const char * | |
7200 | regname (unsigned int regno, int row) | |
7201 | { | |
7202 | static char reg[64]; | |
7f2c8a1d | 7203 | |
2dc4cec1 L |
7204 | if (dwarf_regnames |
7205 | && regno < dwarf_regnames_count | |
7206 | && dwarf_regnames [regno] != NULL) | |
7207 | { | |
7208 | if (row) | |
7209 | return dwarf_regnames [regno]; | |
7210 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, | |
7211 | dwarf_regnames [regno]); | |
7212 | } | |
7213 | else | |
7214 | snprintf (reg, sizeof (reg), "r%d", regno); | |
7215 | return reg; | |
7216 | } | |
7217 | ||
19e6b90e | 7218 | static void |
a1165289 | 7219 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 7220 | { |
a1165289 | 7221 | unsigned int r; |
19e6b90e L |
7222 | char tmp[100]; |
7223 | ||
d8024a91 | 7224 | if (*max_regs != fc->ncols) |
19e6b90e L |
7225 | *max_regs = fc->ncols; |
7226 | ||
7227 | if (*need_col_headers) | |
7228 | { | |
91d6fa6a | 7229 | static const char *sloc = " LOC"; |
2dc4cec1 | 7230 | |
19e6b90e L |
7231 | *need_col_headers = 0; |
7232 | ||
91d6fa6a | 7233 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
7234 | |
7235 | for (r = 0; r < *max_regs; r++) | |
7236 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7237 | { | |
7238 | if (r == fc->ra) | |
50751e18 | 7239 | printf ("ra "); |
19e6b90e | 7240 | else |
2dc4cec1 | 7241 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
7242 | } |
7243 | ||
7244 | printf ("\n"); | |
7245 | } | |
7246 | ||
bf5117e3 | 7247 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
7248 | if (fc->cfa_exp) |
7249 | strcpy (tmp, "exp"); | |
7250 | else | |
c8071705 | 7251 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
7252 | printf ("%-8s ", tmp); |
7253 | ||
7254 | for (r = 0; r < fc->ncols; r++) | |
7255 | { | |
7256 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7257 | { | |
7258 | switch (fc->col_type[r]) | |
7259 | { | |
7260 | case DW_CFA_undefined: | |
7261 | strcpy (tmp, "u"); | |
7262 | break; | |
7263 | case DW_CFA_same_value: | |
7264 | strcpy (tmp, "s"); | |
7265 | break; | |
7266 | case DW_CFA_offset: | |
7267 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
7268 | break; | |
12eae2d3 JJ |
7269 | case DW_CFA_val_offset: |
7270 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
7271 | break; | |
19e6b90e | 7272 | case DW_CFA_register: |
2dc4cec1 | 7273 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
7274 | break; |
7275 | case DW_CFA_expression: | |
7276 | strcpy (tmp, "exp"); | |
7277 | break; | |
12eae2d3 JJ |
7278 | case DW_CFA_val_expression: |
7279 | strcpy (tmp, "vexp"); | |
7280 | break; | |
19e6b90e L |
7281 | default: |
7282 | strcpy (tmp, "n/a"); | |
7283 | break; | |
7284 | } | |
2dc4cec1 | 7285 | printf ("%-5s ", tmp); |
19e6b90e L |
7286 | } |
7287 | } | |
7288 | printf ("\n"); | |
7289 | } | |
7290 | ||
49727e46 | 7291 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 7292 | |
49727e46 AM |
7293 | static unsigned char * |
7294 | read_cie (unsigned char *start, unsigned char *end, | |
7295 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 7296 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
7297 | { |
7298 | int version; | |
7299 | Frame_Chunk *fc; | |
7300 | unsigned int length_return; | |
7301 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 7302 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 7303 | |
041830e0 | 7304 | * p_cie = NULL; |
f41e4712 NC |
7305 | /* PR 17512: file: 001-228113-0.004. */ |
7306 | if (start >= end) | |
7307 | return end; | |
7308 | ||
49727e46 AM |
7309 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
7310 | memset (fc, 0, sizeof (Frame_Chunk)); | |
7311 | ||
7312 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
7313 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
7314 | ||
7315 | version = *start++; | |
7316 | ||
7317 | fc->augmentation = (char *) start; | |
f41e4712 NC |
7318 | /* PR 17512: file: 001-228113-0.004. |
7319 | Skip past augmentation name, but avoid running off the end of the data. */ | |
7320 | while (start < end) | |
7321 | if (* start ++ == '\0') | |
7322 | break; | |
7323 | if (start == end) | |
7324 | { | |
7325 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 7326 | goto fail; |
f41e4712 | 7327 | } |
49727e46 AM |
7328 | |
7329 | if (strcmp (fc->augmentation, "eh") == 0) | |
7330 | start += eh_addr_size; | |
7331 | ||
7332 | if (version >= 4) | |
7333 | { | |
7334 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
7335 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
7336 | { | |
7337 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 7338 | goto fail; |
77ef8654 NC |
7339 | } |
7340 | ||
49727e46 | 7341 | GET (fc->segment_size, 1); |
77ef8654 NC |
7342 | /* PR 17512: file: e99d2804. */ |
7343 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
7344 | { | |
7345 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 7346 | goto fail; |
77ef8654 NC |
7347 | } |
7348 | ||
49727e46 AM |
7349 | eh_addr_size = fc->ptr_size; |
7350 | } | |
7351 | else | |
7352 | { | |
7353 | fc->ptr_size = eh_addr_size; | |
7354 | fc->segment_size = 0; | |
7355 | } | |
442a6ce8 | 7356 | |
7f2c8a1d NC |
7357 | READ_ULEB (fc->code_factor); |
7358 | READ_SLEB (fc->data_factor); | |
442a6ce8 | 7359 | |
49727e46 AM |
7360 | if (version == 1) |
7361 | { | |
7362 | GET (fc->ra, 1); | |
7363 | } | |
7364 | else | |
7365 | { | |
7f2c8a1d | 7366 | READ_ULEB (fc->ra); |
49727e46 AM |
7367 | } |
7368 | ||
7369 | if (fc->augmentation[0] == 'z') | |
7370 | { | |
7f2c8a1d | 7371 | READ_ULEB (augmentation_data_len); |
49727e46 | 7372 | augmentation_data = start; |
a1165289 | 7373 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 7374 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 7375 | { |
bf59c5d5 NC |
7376 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
7377 | dwarf_vmatoa ("x", augmentation_data_len), | |
7378 | (unsigned long) (end - start)); | |
442a6ce8 | 7379 | goto fail; |
a1165289 | 7380 | } |
9c0f3d3f | 7381 | start += augmentation_data_len; |
49727e46 AM |
7382 | } |
7383 | ||
7384 | if (augmentation_data_len) | |
7385 | { | |
058037d3 NC |
7386 | unsigned char *p; |
7387 | unsigned char *q; | |
7388 | unsigned char *qend; | |
b4eb7656 | 7389 | |
49727e46 AM |
7390 | p = (unsigned char *) fc->augmentation + 1; |
7391 | q = augmentation_data; | |
058037d3 NC |
7392 | qend = q + augmentation_data_len; |
7393 | ||
9c0f3d3f | 7394 | while (p < end && q < qend) |
49727e46 AM |
7395 | { |
7396 | if (*p == 'L') | |
7397 | q++; | |
7398 | else if (*p == 'P') | |
7399 | q += 1 + size_of_encoded_value (*q); | |
7400 | else if (*p == 'R') | |
7401 | fc->fde_encoding = *q++; | |
7402 | else if (*p == 'S') | |
7403 | ; | |
09038062 ST |
7404 | else if (*p == 'B') |
7405 | ; | |
49727e46 AM |
7406 | else |
7407 | break; | |
7408 | p++; | |
7409 | } | |
c361b9ac NC |
7410 | /* Note - it is OK if this loop terminates with q < qend. |
7411 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
7412 | } |
7413 | ||
7414 | *p_cie = fc; | |
7415 | if (p_version) | |
7416 | *p_version = version; | |
7417 | if (p_aug_len) | |
7418 | { | |
7419 | *p_aug_len = augmentation_data_len; | |
7420 | *p_aug = augmentation_data; | |
7421 | } | |
7422 | return start; | |
442a6ce8 NC |
7423 | |
7424 | fail: | |
7425 | free (fc->col_offset); | |
7426 | free (fc->col_type); | |
7427 | free (fc); | |
7428 | return end; | |
49727e46 AM |
7429 | } |
7430 | ||
d85bf2ba NC |
7431 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
7432 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
7433 | PRINTED contains the number of characters already written to the current | |
7434 | output line. */ | |
bf59c5d5 NC |
7435 | |
7436 | static void | |
d85bf2ba NC |
7437 | display_data (bfd_size_type printed, |
7438 | const unsigned char * data, | |
7439 | const bfd_size_type len) | |
bf59c5d5 | 7440 | { |
d85bf2ba NC |
7441 | if (do_wide || len < ((80 - printed) / 3)) |
7442 | for (printed = 0; printed < len; ++printed) | |
7443 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
7444 | else |
7445 | { | |
d85bf2ba | 7446 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 7447 | { |
d85bf2ba | 7448 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 7449 | putchar ('\n'); |
d85bf2ba | 7450 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
7451 | } |
7452 | } | |
d85bf2ba NC |
7453 | } |
7454 | ||
7455 | /* Prints out the contents on the augmentation data array. | |
7456 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
7457 | ||
7458 | static void | |
7459 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
7460 | { | |
7461 | bfd_size_type i; | |
7462 | ||
7463 | i = printf (_(" Augmentation data: ")); | |
7464 | display_data (i, data, len); | |
bf59c5d5 NC |
7465 | } |
7466 | ||
19e6b90e L |
7467 | static int |
7468 | display_debug_frames (struct dwarf_section *section, | |
7469 | void *file ATTRIBUTE_UNUSED) | |
7470 | { | |
7471 | unsigned char *start = section->start; | |
7472 | unsigned char *end = start + section->size; | |
7473 | unsigned char *section_start = start; | |
3391569f NC |
7474 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
7475 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 7476 | Frame_Chunk *rs; |
3391569f | 7477 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
19e6b90e | 7478 | unsigned int length_return; |
a1165289 | 7479 | unsigned int max_regs = 0; |
665ce1f6 | 7480 | const char *bad_reg = _("bad register: "); |
77ef8654 | 7481 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 7482 | |
dda8d76d | 7483 | introduce (section, FALSE); |
19e6b90e L |
7484 | |
7485 | while (start < end) | |
7486 | { | |
7487 | unsigned char *saved_start; | |
7488 | unsigned char *block_end; | |
bf5117e3 NC |
7489 | dwarf_vma length; |
7490 | dwarf_vma cie_id; | |
19e6b90e L |
7491 | Frame_Chunk *fc; |
7492 | Frame_Chunk *cie; | |
7493 | int need_col_headers = 1; | |
7494 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 7495 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
7496 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
7497 | unsigned int offset_size; | |
7498 | unsigned int initial_length_size; | |
5b6312fd | 7499 | bfd_boolean all_nops; |
19e6b90e L |
7500 | |
7501 | saved_start = start; | |
19e6b90e | 7502 | |
0c588247 | 7503 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 7504 | |
19e6b90e L |
7505 | if (length == 0) |
7506 | { | |
7507 | printf ("\n%08lx ZERO terminator\n\n", | |
7508 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
7509 | /* Skip any zero terminators that directly follow. |
7510 | A corrupt section size could have loaded a whole | |
7511 | slew of zero filled memory bytes. eg | |
7512 | PR 17512: file: 070-19381-0.004. */ | |
7513 | while (start < end && * start == 0) | |
7514 | ++ start; | |
b758e50f | 7515 | continue; |
19e6b90e L |
7516 | } |
7517 | ||
7518 | if (length == 0xffffffff) | |
7519 | { | |
0c588247 | 7520 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
7521 | offset_size = 8; |
7522 | initial_length_size = 12; | |
7523 | } | |
7524 | else | |
7525 | { | |
7526 | offset_size = 4; | |
7527 | initial_length_size = 4; | |
7528 | } | |
7529 | ||
7530 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 7531 | if (block_end > end || block_end < start) |
53b8873b | 7532 | { |
bf5117e3 NC |
7533 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
7534 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
7535 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
7536 | block_end = end; |
7537 | } | |
0c588247 NC |
7538 | |
7539 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 7540 | |
846a11e4 NC |
7541 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
7542 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
7543 | { |
7544 | int version; | |
a1165289 | 7545 | unsigned int mreg; |
19e6b90e | 7546 | |
49727e46 AM |
7547 | start = read_cie (start, end, &cie, &version, |
7548 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
7549 | /* PR 17512: file: 027-135133-0.005. */ |
7550 | if (cie == NULL) | |
7551 | break; | |
a1165289 | 7552 | |
49727e46 | 7553 | fc = cie; |
19e6b90e L |
7554 | fc->next = chunks; |
7555 | chunks = fc; | |
7556 | fc->chunk_start = saved_start; | |
a1165289 | 7557 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7558 | if (mreg < fc->ra) |
7559 | mreg = fc->ra; | |
06614111 NC |
7560 | if (frame_need_space (fc, mreg) < 0) |
7561 | break; | |
49727e46 AM |
7562 | if (fc->fde_encoding) |
7563 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 7564 | |
bf5117e3 NC |
7565 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
7566 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 7567 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 7568 | |
19e6b90e | 7569 | if (do_debug_frames_interp) |
bf5117e3 NC |
7570 | { |
7571 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
7572 | fc->code_factor, fc->data_factor, fc->ra); | |
7573 | } | |
19e6b90e L |
7574 | else |
7575 | { | |
bf5117e3 | 7576 | printf ("CIE\n"); |
19e6b90e L |
7577 | printf (" Version: %d\n", version); |
7578 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
7579 | if (version >= 4) |
7580 | { | |
7581 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
7582 | printf (" Segment Size: %u\n", fc->segment_size); | |
7583 | } | |
19e6b90e L |
7584 | printf (" Code alignment factor: %u\n", fc->code_factor); |
7585 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
7586 | printf (" Return address column: %d\n", fc->ra); | |
7587 | ||
7588 | if (augmentation_data_len) | |
bf59c5d5 | 7589 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 7590 | |
19e6b90e L |
7591 | putchar ('\n'); |
7592 | } | |
19e6b90e L |
7593 | } |
7594 | else | |
7595 | { | |
7596 | unsigned char *look_for; | |
7597 | static Frame_Chunk fde_fc; | |
604282a7 | 7598 | unsigned long segment_selector; |
19e6b90e | 7599 | |
49727e46 AM |
7600 | if (is_eh) |
7601 | { | |
7602 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
7603 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
7604 | } | |
7605 | else | |
7606 | look_for = section_start + cie_id; | |
19e6b90e | 7607 | |
49727e46 AM |
7608 | if (look_for <= saved_start) |
7609 | { | |
7610 | for (cie = chunks; cie ; cie = cie->next) | |
7611 | if (cie->chunk_start == look_for) | |
7612 | break; | |
7613 | } | |
7614 | else | |
7615 | { | |
7616 | for (cie = forward_refs; cie ; cie = cie->next) | |
7617 | if (cie->chunk_start == look_for) | |
7618 | break; | |
7619 | if (!cie) | |
7620 | { | |
7621 | unsigned int off_size; | |
7622 | unsigned char *cie_scan; | |
19e6b90e | 7623 | |
49727e46 AM |
7624 | cie_scan = look_for; |
7625 | off_size = 4; | |
7626 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
7627 | if (length == 0xffffffff) | |
7628 | { | |
7629 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
7630 | off_size = 8; | |
7631 | } | |
7632 | if (length != 0) | |
7633 | { | |
7634 | dwarf_vma c_id; | |
7635 | ||
7636 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
7637 | if (is_eh | |
7638 | ? c_id == 0 | |
7639 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
7640 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
7641 | { | |
7642 | int version; | |
a1165289 | 7643 | unsigned int mreg; |
49727e46 AM |
7644 | |
7645 | read_cie (cie_scan, end, &cie, &version, | |
7646 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
7647 | /* PR 17512: file: 3450-2098-0.004. */ |
7648 | if (cie == NULL) | |
7649 | { | |
7650 | warn (_("Failed to read CIE information\n")); | |
7651 | break; | |
7652 | } | |
49727e46 AM |
7653 | cie->next = forward_refs; |
7654 | forward_refs = cie; | |
7655 | cie->chunk_start = look_for; | |
a1165289 | 7656 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7657 | if (mreg < cie->ra) |
7658 | mreg = cie->ra; | |
06614111 NC |
7659 | if (frame_need_space (cie, mreg) < 0) |
7660 | { | |
7661 | warn (_("Invalid max register\n")); | |
7662 | break; | |
7663 | } | |
49727e46 AM |
7664 | if (cie->fde_encoding) |
7665 | encoded_ptr_size | |
7666 | = size_of_encoded_value (cie->fde_encoding); | |
7667 | } | |
7668 | } | |
7669 | } | |
7670 | } | |
7671 | ||
7672 | fc = &fde_fc; | |
7673 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
7674 | |
7675 | if (!cie) | |
7676 | { | |
bf5117e3 NC |
7677 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
7678 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
7679 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 7680 | fc->ncols = 0; |
3f5e193b NC |
7681 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
7682 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
7683 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
7684 | { | |
7685 | warn (_("Invalid max register\n")); | |
7686 | break; | |
7687 | } | |
19e6b90e L |
7688 | cie = fc; |
7689 | fc->augmentation = ""; | |
7690 | fc->fde_encoding = 0; | |
604282a7 JJ |
7691 | fc->ptr_size = eh_addr_size; |
7692 | fc->segment_size = 0; | |
19e6b90e L |
7693 | } |
7694 | else | |
7695 | { | |
7696 | fc->ncols = cie->ncols; | |
3f5e193b NC |
7697 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
7698 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
7699 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
7700 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
7701 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
7702 | fc->ptr_size = cie->ptr_size; |
7703 | eh_addr_size = cie->ptr_size; | |
7704 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
7705 | fc->code_factor = cie->code_factor; |
7706 | fc->data_factor = cie->data_factor; | |
7707 | fc->cfa_reg = cie->cfa_reg; | |
7708 | fc->cfa_offset = cie->cfa_offset; | |
7709 | fc->ra = cie->ra; | |
06614111 NC |
7710 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
7711 | { | |
7712 | warn (_("Invalid max register\n")); | |
7713 | break; | |
7714 | } | |
19e6b90e L |
7715 | fc->fde_encoding = cie->fde_encoding; |
7716 | } | |
7717 | ||
7718 | if (fc->fde_encoding) | |
7719 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
7720 | ||
604282a7 JJ |
7721 | segment_selector = 0; |
7722 | if (fc->segment_size) | |
c8071705 NC |
7723 | { |
7724 | if (fc->segment_size > sizeof (segment_selector)) | |
7725 | { | |
7726 | /* PR 17512: file: 9e196b3e. */ | |
7727 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
7728 | fc->segment_size = 4; | |
7729 | } | |
7730 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
7731 | } | |
041830e0 NC |
7732 | |
7733 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 7734 | |
0c588247 NC |
7735 | /* FIXME: It appears that sometimes the final pc_range value is |
7736 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
7737 | run of the "objcopy on compressed debug sections" test for an | |
7738 | example of this. */ | |
7739 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 7740 | |
19e6b90e L |
7741 | if (cie->augmentation[0] == 'z') |
7742 | { | |
7f2c8a1d | 7743 | READ_ULEB (augmentation_data_len); |
19e6b90e L |
7744 | augmentation_data = start; |
7745 | start += augmentation_data_len; | |
bf59c5d5 NC |
7746 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
7747 | if (start >= end | |
7748 | || ((bfd_signed_vma) augmentation_data_len) < 0 | |
7749 | || augmentation_data > start) | |
0a9d414a | 7750 | { |
bf59c5d5 NC |
7751 | warn (_("Corrupt augmentation data length: 0x%s\n"), |
7752 | dwarf_vmatoa ("x", augmentation_data_len)); | |
0a9d414a NC |
7753 | start = end; |
7754 | augmentation_data = NULL; | |
7755 | augmentation_data_len = 0; | |
7756 | } | |
19e6b90e L |
7757 | } |
7758 | ||
bf5117e3 NC |
7759 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
7760 | (unsigned long)(saved_start - section_start), | |
7761 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 7762 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 7763 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 7764 | |
604282a7 JJ |
7765 | if (fc->segment_size) |
7766 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
7767 | |
7768 | printf ("%s..%s\n", | |
7769 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
7770 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
7771 | ||
19e6b90e L |
7772 | if (! do_debug_frames_interp && augmentation_data_len) |
7773 | { | |
bf59c5d5 | 7774 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
7775 | putchar ('\n'); |
7776 | } | |
7777 | } | |
7778 | ||
7779 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
7780 | we're about to interpret instructions for the chunk. */ | |
7781 | /* ??? At present we need to do this always, since this sizes the | |
7782 | fc->col_type and fc->col_offset arrays, which we write into always. | |
7783 | We should probably split the interpreted and non-interpreted bits | |
7784 | into two different routines, since there's so much that doesn't | |
7785 | really overlap between them. */ | |
7786 | if (1 || do_debug_frames_interp) | |
7787 | { | |
7788 | /* Start by making a pass over the chunk, allocating storage | |
7789 | and taking note of what registers are used. */ | |
7790 | unsigned char *tmp = start; | |
7791 | ||
7792 | while (start < block_end) | |
7793 | { | |
041830e0 NC |
7794 | unsigned int reg, op, opa; |
7795 | unsigned long temp; | |
5929c344 | 7796 | unsigned char * new_start; |
19e6b90e L |
7797 | |
7798 | op = *start++; | |
7799 | opa = op & 0x3f; | |
7800 | if (op & 0xc0) | |
7801 | op &= 0xc0; | |
7802 | ||
7803 | /* Warning: if you add any more cases to this switch, be | |
7804 | sure to add them to the corresponding switch below. */ | |
7805 | switch (op) | |
7806 | { | |
7807 | case DW_CFA_advance_loc: | |
7808 | break; | |
7809 | case DW_CFA_offset: | |
7f2c8a1d | 7810 | SKIP_ULEB (); |
665ce1f6 L |
7811 | if (frame_need_space (fc, opa) >= 0) |
7812 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
7813 | break; |
7814 | case DW_CFA_restore: | |
665ce1f6 L |
7815 | if (frame_need_space (fc, opa) >= 0) |
7816 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
7817 | break; |
7818 | case DW_CFA_set_loc: | |
7819 | start += encoded_ptr_size; | |
7820 | break; | |
7821 | case DW_CFA_advance_loc1: | |
7822 | start += 1; | |
7823 | break; | |
7824 | case DW_CFA_advance_loc2: | |
7825 | start += 2; | |
7826 | break; | |
7827 | case DW_CFA_advance_loc4: | |
7828 | start += 4; | |
7829 | break; | |
7830 | case DW_CFA_offset_extended: | |
12eae2d3 | 7831 | case DW_CFA_val_offset: |
7f2c8a1d NC |
7832 | READ_ULEB (reg); |
7833 | SKIP_ULEB (); | |
665ce1f6 L |
7834 | if (frame_need_space (fc, reg) >= 0) |
7835 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7836 | break; |
7837 | case DW_CFA_restore_extended: | |
7f2c8a1d | 7838 | READ_ULEB (reg); |
665ce1f6 L |
7839 | if (frame_need_space (fc, reg) >= 0) |
7840 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7841 | break; |
7842 | case DW_CFA_undefined: | |
7f2c8a1d | 7843 | READ_ULEB (reg); |
665ce1f6 L |
7844 | if (frame_need_space (fc, reg) >= 0) |
7845 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7846 | break; |
7847 | case DW_CFA_same_value: | |
7f2c8a1d | 7848 | READ_ULEB (reg); |
665ce1f6 L |
7849 | if (frame_need_space (fc, reg) >= 0) |
7850 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7851 | break; |
7852 | case DW_CFA_register: | |
7f2c8a1d NC |
7853 | READ_ULEB (reg); |
7854 | SKIP_ULEB (); | |
665ce1f6 L |
7855 | if (frame_need_space (fc, reg) >= 0) |
7856 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7857 | break; |
7858 | case DW_CFA_def_cfa: | |
7f2c8a1d NC |
7859 | SKIP_ULEB (); |
7860 | SKIP_ULEB (); | |
19e6b90e L |
7861 | break; |
7862 | case DW_CFA_def_cfa_register: | |
7f2c8a1d | 7863 | SKIP_ULEB (); |
19e6b90e L |
7864 | break; |
7865 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 7866 | SKIP_ULEB (); |
19e6b90e L |
7867 | break; |
7868 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 7869 | READ_ULEB (temp); |
5929c344 NC |
7870 | new_start = start + temp; |
7871 | if (new_start < start) | |
041830e0 NC |
7872 | { |
7873 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
7874 | start = block_end; | |
7875 | } | |
7876 | else | |
5929c344 | 7877 | start = new_start; |
19e6b90e L |
7878 | break; |
7879 | case DW_CFA_expression: | |
12eae2d3 | 7880 | case DW_CFA_val_expression: |
7f2c8a1d NC |
7881 | READ_ULEB (reg); |
7882 | READ_ULEB (temp); | |
5929c344 NC |
7883 | new_start = start + temp; |
7884 | if (new_start < start) | |
041830e0 | 7885 | { |
b4eb7656 | 7886 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
7887 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
7888 | start = block_end; | |
7889 | } | |
7890 | else | |
5929c344 | 7891 | start = new_start; |
665ce1f6 L |
7892 | if (frame_need_space (fc, reg) >= 0) |
7893 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7894 | break; |
7895 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 7896 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
7897 | READ_ULEB (reg); |
7898 | SKIP_SLEB (); | |
665ce1f6 L |
7899 | if (frame_need_space (fc, reg) >= 0) |
7900 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7901 | break; |
7902 | case DW_CFA_def_cfa_sf: | |
7f2c8a1d NC |
7903 | SKIP_ULEB (); |
7904 | SKIP_SLEB (); | |
19e6b90e L |
7905 | break; |
7906 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 7907 | SKIP_SLEB (); |
19e6b90e L |
7908 | break; |
7909 | case DW_CFA_MIPS_advance_loc8: | |
7910 | start += 8; | |
7911 | break; | |
7912 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 7913 | SKIP_ULEB (); |
19e6b90e L |
7914 | break; |
7915 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
7916 | READ_ULEB (reg); |
7917 | SKIP_ULEB (); | |
665ce1f6 L |
7918 | if (frame_need_space (fc, reg) >= 0) |
7919 | fc->col_type[reg] = DW_CFA_undefined; | |
7920 | break; | |
19e6b90e L |
7921 | default: |
7922 | break; | |
7923 | } | |
7924 | } | |
7925 | start = tmp; | |
7926 | } | |
7927 | ||
5b6312fd NC |
7928 | all_nops = TRUE; |
7929 | ||
19e6b90e L |
7930 | /* Now we know what registers are used, make a second pass over |
7931 | the chunk, this time actually printing out the info. */ | |
7932 | ||
7933 | while (start < block_end) | |
7934 | { | |
362beea4 | 7935 | unsigned char * tmp; |
19e6b90e | 7936 | unsigned op, opa; |
7f2c8a1d NC |
7937 | unsigned long ul, roffs; |
7938 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
7939 | are various functions, notably frame_space_needed() that assume that | |
7940 | reg is an unsigned int. */ | |
7941 | unsigned int reg; | |
7942 | dwarf_signed_vma l; | |
bf5117e3 | 7943 | dwarf_vma ofs; |
19e6b90e | 7944 | dwarf_vma vma; |
665ce1f6 | 7945 | const char *reg_prefix = ""; |
19e6b90e L |
7946 | |
7947 | op = *start++; | |
7948 | opa = op & 0x3f; | |
7949 | if (op & 0xc0) | |
7950 | op &= 0xc0; | |
7951 | ||
5b6312fd NC |
7952 | /* Make a note if something other than DW_CFA_nop happens. */ |
7953 | if (op != DW_CFA_nop) | |
7954 | all_nops = FALSE; | |
7955 | ||
19e6b90e L |
7956 | /* Warning: if you add any more cases to this switch, be |
7957 | sure to add them to the corresponding switch above. */ | |
7958 | switch (op) | |
7959 | { | |
7960 | case DW_CFA_advance_loc: | |
7961 | if (do_debug_frames_interp) | |
7962 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7963 | else | |
bf5117e3 | 7964 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 7965 | opa * fc->code_factor, |
b4eb7656 | 7966 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
7967 | fc->pc_begin + opa * fc->code_factor, |
7968 | fc->ptr_size)); | |
19e6b90e L |
7969 | fc->pc_begin += opa * fc->code_factor; |
7970 | break; | |
7971 | ||
7972 | case DW_CFA_offset: | |
7f2c8a1d | 7973 | READ_ULEB (roffs); |
665ce1f6 L |
7974 | if (opa >= (unsigned int) fc->ncols) |
7975 | reg_prefix = bad_reg; | |
7976 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7977 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
7978 | reg_prefix, regname (opa, 0), | |
7979 | roffs * fc->data_factor); | |
7980 | if (*reg_prefix == '\0') | |
7981 | { | |
7982 | fc->col_type[opa] = DW_CFA_offset; | |
7983 | fc->col_offset[opa] = roffs * fc->data_factor; | |
7984 | } | |
19e6b90e L |
7985 | break; |
7986 | ||
7987 | case DW_CFA_restore: | |
50751e18 | 7988 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
7989 | reg_prefix = bad_reg; |
7990 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7991 | printf (" DW_CFA_restore: %s%s\n", | |
7992 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
7993 | if (*reg_prefix != '\0') |
7994 | break; | |
7995 | ||
7996 | if (opa >= (unsigned int) cie->ncols | |
7997 | || (do_debug_frames_interp | |
7998 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
7999 | { | |
8000 | fc->col_type[opa] = DW_CFA_undefined; | |
8001 | fc->col_offset[opa] = 0; | |
8002 | } | |
8003 | else | |
665ce1f6 L |
8004 | { |
8005 | fc->col_type[opa] = cie->col_type[opa]; | |
8006 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8007 | } | |
19e6b90e L |
8008 | break; |
8009 | ||
8010 | case DW_CFA_set_loc: | |
6937bb54 | 8011 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
8012 | if (do_debug_frames_interp) |
8013 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8014 | else | |
bf5117e3 NC |
8015 | printf (" DW_CFA_set_loc: %s\n", |
8016 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
8017 | fc->pc_begin = vma; |
8018 | break; | |
8019 | ||
8020 | case DW_CFA_advance_loc1: | |
0c588247 | 8021 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
8022 | if (do_debug_frames_interp) |
8023 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8024 | else | |
bf5117e3 NC |
8025 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
8026 | (unsigned long) (ofs * fc->code_factor), | |
8027 | dwarf_vmatoa_1 (NULL, | |
8028 | fc->pc_begin + ofs * fc->code_factor, | |
8029 | fc->ptr_size)); | |
19e6b90e L |
8030 | fc->pc_begin += ofs * fc->code_factor; |
8031 | break; | |
8032 | ||
8033 | case DW_CFA_advance_loc2: | |
6937bb54 | 8034 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
8035 | if (do_debug_frames_interp) |
8036 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8037 | else | |
bf5117e3 NC |
8038 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
8039 | (unsigned long) (ofs * fc->code_factor), | |
8040 | dwarf_vmatoa_1 (NULL, | |
8041 | fc->pc_begin + ofs * fc->code_factor, | |
8042 | fc->ptr_size)); | |
19e6b90e L |
8043 | fc->pc_begin += ofs * fc->code_factor; |
8044 | break; | |
8045 | ||
8046 | case DW_CFA_advance_loc4: | |
6937bb54 | 8047 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
8048 | if (do_debug_frames_interp) |
8049 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8050 | else | |
bf5117e3 NC |
8051 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
8052 | (unsigned long) (ofs * fc->code_factor), | |
8053 | dwarf_vmatoa_1 (NULL, | |
8054 | fc->pc_begin + ofs * fc->code_factor, | |
8055 | fc->ptr_size)); | |
19e6b90e L |
8056 | fc->pc_begin += ofs * fc->code_factor; |
8057 | break; | |
8058 | ||
8059 | case DW_CFA_offset_extended: | |
7f2c8a1d NC |
8060 | READ_ULEB (reg); |
8061 | READ_ULEB (roffs); | |
665ce1f6 L |
8062 | if (reg >= (unsigned int) fc->ncols) |
8063 | reg_prefix = bad_reg; | |
8064 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8065 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
8066 | reg_prefix, regname (reg, 0), | |
8067 | roffs * fc->data_factor); | |
8068 | if (*reg_prefix == '\0') | |
8069 | { | |
8070 | fc->col_type[reg] = DW_CFA_offset; | |
8071 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8072 | } | |
19e6b90e L |
8073 | break; |
8074 | ||
12eae2d3 | 8075 | case DW_CFA_val_offset: |
7f2c8a1d NC |
8076 | READ_ULEB (reg); |
8077 | READ_ULEB (roffs); | |
665ce1f6 L |
8078 | if (reg >= (unsigned int) fc->ncols) |
8079 | reg_prefix = bad_reg; | |
8080 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8081 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
8082 | reg_prefix, regname (reg, 0), |
8083 | roffs * fc->data_factor); | |
8084 | if (*reg_prefix == '\0') | |
8085 | { | |
8086 | fc->col_type[reg] = DW_CFA_val_offset; | |
8087 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8088 | } | |
12eae2d3 JJ |
8089 | break; |
8090 | ||
19e6b90e | 8091 | case DW_CFA_restore_extended: |
7f2c8a1d | 8092 | READ_ULEB (reg); |
50751e18 | 8093 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
8094 | reg_prefix = bad_reg; |
8095 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8096 | printf (" DW_CFA_restore_extended: %s%s\n", | |
8097 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
8098 | if (*reg_prefix != '\0') |
8099 | break; | |
8100 | ||
8101 | if (reg >= (unsigned int) cie->ncols) | |
8102 | { | |
8103 | fc->col_type[reg] = DW_CFA_undefined; | |
8104 | fc->col_offset[reg] = 0; | |
8105 | } | |
8106 | else | |
665ce1f6 L |
8107 | { |
8108 | fc->col_type[reg] = cie->col_type[reg]; | |
8109 | fc->col_offset[reg] = cie->col_offset[reg]; | |
8110 | } | |
19e6b90e L |
8111 | break; |
8112 | ||
8113 | case DW_CFA_undefined: | |
7f2c8a1d | 8114 | READ_ULEB (reg); |
665ce1f6 L |
8115 | if (reg >= (unsigned int) fc->ncols) |
8116 | reg_prefix = bad_reg; | |
8117 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8118 | printf (" DW_CFA_undefined: %s%s\n", | |
8119 | reg_prefix, regname (reg, 0)); | |
8120 | if (*reg_prefix == '\0') | |
8121 | { | |
8122 | fc->col_type[reg] = DW_CFA_undefined; | |
8123 | fc->col_offset[reg] = 0; | |
8124 | } | |
19e6b90e L |
8125 | break; |
8126 | ||
8127 | case DW_CFA_same_value: | |
7f2c8a1d | 8128 | READ_ULEB (reg); |
665ce1f6 L |
8129 | if (reg >= (unsigned int) fc->ncols) |
8130 | reg_prefix = bad_reg; | |
8131 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8132 | printf (" DW_CFA_same_value: %s%s\n", | |
8133 | reg_prefix, regname (reg, 0)); | |
8134 | if (*reg_prefix == '\0') | |
8135 | { | |
8136 | fc->col_type[reg] = DW_CFA_same_value; | |
8137 | fc->col_offset[reg] = 0; | |
8138 | } | |
19e6b90e L |
8139 | break; |
8140 | ||
8141 | case DW_CFA_register: | |
7f2c8a1d NC |
8142 | READ_ULEB (reg); |
8143 | READ_ULEB (roffs); | |
665ce1f6 L |
8144 | if (reg >= (unsigned int) fc->ncols) |
8145 | reg_prefix = bad_reg; | |
8146 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 8147 | { |
665ce1f6 L |
8148 | printf (" DW_CFA_register: %s%s in ", |
8149 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
8150 | puts (regname (roffs, 0)); |
8151 | } | |
665ce1f6 L |
8152 | if (*reg_prefix == '\0') |
8153 | { | |
8154 | fc->col_type[reg] = DW_CFA_register; | |
8155 | fc->col_offset[reg] = roffs; | |
8156 | } | |
19e6b90e L |
8157 | break; |
8158 | ||
8159 | case DW_CFA_remember_state: | |
8160 | if (! do_debug_frames_interp) | |
8161 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 8162 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 8163 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
8164 | rs->cfa_reg = fc->cfa_reg; |
8165 | rs->ra = fc->ra; | |
8166 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 8167 | rs->ncols = fc->ncols; |
3f5e193b | 8168 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 8169 | sizeof (* rs->col_type)); |
d71ad7fc RC |
8170 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
8171 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
8172 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
8173 | rs->next = remembered_state; |
8174 | remembered_state = rs; | |
8175 | break; | |
8176 | ||
8177 | case DW_CFA_restore_state: | |
8178 | if (! do_debug_frames_interp) | |
8179 | printf (" DW_CFA_restore_state\n"); | |
8180 | rs = remembered_state; | |
8181 | if (rs) | |
8182 | { | |
8183 | remembered_state = rs->next; | |
d71ad7fc RC |
8184 | fc->cfa_offset = rs->cfa_offset; |
8185 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
8186 | fc->ra = rs->ra; |
8187 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
8188 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
8189 | { | |
1306a742 | 8190 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
8191 | fc->ncols = 0; |
8192 | break; | |
8193 | } | |
d71ad7fc | 8194 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 8195 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 8196 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
8197 | free (rs->col_type); |
8198 | free (rs->col_offset); | |
8199 | free (rs); | |
8200 | } | |
8201 | else if (do_debug_frames_interp) | |
8202 | printf ("Mismatched DW_CFA_restore_state\n"); | |
8203 | break; | |
8204 | ||
8205 | case DW_CFA_def_cfa: | |
32ef3000 | 8206 | READ_ULEB (fc->cfa_reg); |
7f2c8a1d | 8207 | READ_ULEB (fc->cfa_offset); |
19e6b90e L |
8208 | fc->cfa_exp = 0; |
8209 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8210 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 8211 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8212 | break; |
8213 | ||
8214 | case DW_CFA_def_cfa_register: | |
32ef3000 | 8215 | READ_ULEB (fc->cfa_reg); |
19e6b90e L |
8216 | fc->cfa_exp = 0; |
8217 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
8218 | printf (" DW_CFA_def_cfa_register: %s\n", |
8219 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
8220 | break; |
8221 | ||
8222 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 8223 | READ_ULEB (fc->cfa_offset); |
19e6b90e | 8224 | if (! do_debug_frames_interp) |
c8071705 | 8225 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8226 | break; |
8227 | ||
8228 | case DW_CFA_nop: | |
8229 | if (! do_debug_frames_interp) | |
8230 | printf (" DW_CFA_nop\n"); | |
8231 | break; | |
8232 | ||
8233 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 8234 | READ_ULEB (ul); |
7460c0ab | 8235 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 8236 | { |
a1165289 | 8237 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8238 | break; |
8239 | } | |
19e6b90e L |
8240 | if (! do_debug_frames_interp) |
8241 | { | |
8242 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
8243 | decode_location_expression (start, eh_addr_size, 0, -1, |
8244 | ul, 0, section); | |
19e6b90e L |
8245 | printf (")\n"); |
8246 | } | |
8247 | fc->cfa_exp = 1; | |
8248 | start += ul; | |
8249 | break; | |
8250 | ||
8251 | case DW_CFA_expression: | |
7f2c8a1d NC |
8252 | READ_ULEB (reg); |
8253 | READ_ULEB (ul); | |
665ce1f6 L |
8254 | if (reg >= (unsigned int) fc->ncols) |
8255 | reg_prefix = bad_reg; | |
6937bb54 | 8256 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 8257 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
8258 | tmp = start + ul; |
8259 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8260 | { |
a1165289 | 8261 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8262 | break; |
8263 | } | |
665ce1f6 | 8264 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 8265 | { |
665ce1f6 L |
8266 | printf (" DW_CFA_expression: %s%s (", |
8267 | reg_prefix, regname (reg, 0)); | |
b7807392 | 8268 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 8269 | ul, 0, section); |
19e6b90e L |
8270 | printf (")\n"); |
8271 | } | |
665ce1f6 L |
8272 | if (*reg_prefix == '\0') |
8273 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 8274 | start = tmp; |
19e6b90e L |
8275 | break; |
8276 | ||
12eae2d3 | 8277 | case DW_CFA_val_expression: |
7f2c8a1d NC |
8278 | READ_ULEB (reg); |
8279 | READ_ULEB (ul); | |
665ce1f6 L |
8280 | if (reg >= (unsigned int) fc->ncols) |
8281 | reg_prefix = bad_reg; | |
362beea4 NC |
8282 | tmp = start + ul; |
8283 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8284 | { |
a1165289 | 8285 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
8286 | break; |
8287 | } | |
665ce1f6 | 8288 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 8289 | { |
665ce1f6 L |
8290 | printf (" DW_CFA_val_expression: %s%s (", |
8291 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
8292 | decode_location_expression (start, eh_addr_size, 0, -1, |
8293 | ul, 0, section); | |
12eae2d3 JJ |
8294 | printf (")\n"); |
8295 | } | |
665ce1f6 L |
8296 | if (*reg_prefix == '\0') |
8297 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 8298 | start = tmp; |
12eae2d3 JJ |
8299 | break; |
8300 | ||
19e6b90e | 8301 | case DW_CFA_offset_extended_sf: |
7f2c8a1d NC |
8302 | READ_ULEB (reg); |
8303 | READ_SLEB (l); | |
665ce1f6 L |
8304 | if (frame_need_space (fc, reg) < 0) |
8305 | reg_prefix = bad_reg; | |
8306 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8307 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
8308 | reg_prefix, regname (reg, 0), | |
c8071705 | 8309 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8310 | if (*reg_prefix == '\0') |
8311 | { | |
8312 | fc->col_type[reg] = DW_CFA_offset; | |
8313 | fc->col_offset[reg] = l * fc->data_factor; | |
8314 | } | |
19e6b90e L |
8315 | break; |
8316 | ||
12eae2d3 | 8317 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
8318 | READ_ULEB (reg); |
8319 | READ_SLEB (l); | |
665ce1f6 L |
8320 | if (frame_need_space (fc, reg) < 0) |
8321 | reg_prefix = bad_reg; | |
8322 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8323 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 8324 | reg_prefix, regname (reg, 0), |
c8071705 | 8325 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8326 | if (*reg_prefix == '\0') |
8327 | { | |
8328 | fc->col_type[reg] = DW_CFA_val_offset; | |
8329 | fc->col_offset[reg] = l * fc->data_factor; | |
8330 | } | |
12eae2d3 JJ |
8331 | break; |
8332 | ||
19e6b90e | 8333 | case DW_CFA_def_cfa_sf: |
32ef3000 | 8334 | READ_ULEB (fc->cfa_reg); |
7f2c8a1d | 8335 | READ_ULEB (fc->cfa_offset); |
19e6b90e L |
8336 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
8337 | fc->cfa_exp = 0; | |
8338 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8339 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 8340 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8341 | break; |
8342 | ||
8343 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 8344 | READ_ULEB (fc->cfa_offset); |
c8071705 | 8345 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 8346 | if (! do_debug_frames_interp) |
c8071705 | 8347 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8348 | break; |
8349 | ||
8350 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 8351 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
8352 | if (do_debug_frames_interp) |
8353 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8354 | else | |
bf5117e3 NC |
8355 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
8356 | (unsigned long) (ofs * fc->code_factor), | |
8357 | dwarf_vmatoa_1 (NULL, | |
8358 | fc->pc_begin + ofs * fc->code_factor, | |
8359 | fc->ptr_size)); | |
19e6b90e L |
8360 | fc->pc_begin += ofs * fc->code_factor; |
8361 | break; | |
8362 | ||
8363 | case DW_CFA_GNU_window_save: | |
8364 | if (! do_debug_frames_interp) | |
8365 | printf (" DW_CFA_GNU_window_save\n"); | |
8366 | break; | |
8367 | ||
8368 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 8369 | READ_ULEB (ul); |
19e6b90e L |
8370 | if (! do_debug_frames_interp) |
8371 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
8372 | break; | |
8373 | ||
8374 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
8375 | READ_ULEB (reg); |
8376 | READ_SLEB (l); | |
8377 | l = - l; | |
665ce1f6 L |
8378 | if (frame_need_space (fc, reg) < 0) |
8379 | reg_prefix = bad_reg; | |
8380 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8381 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
8382 | reg_prefix, regname (reg, 0), | |
c8071705 | 8383 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8384 | if (*reg_prefix == '\0') |
8385 | { | |
8386 | fc->col_type[reg] = DW_CFA_offset; | |
8387 | fc->col_offset[reg] = l * fc->data_factor; | |
8388 | } | |
19e6b90e L |
8389 | break; |
8390 | ||
8391 | default: | |
53b8873b NC |
8392 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
8393 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
8394 | else | |
f41e4712 | 8395 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
8396 | start = block_end; |
8397 | } | |
8398 | } | |
8399 | ||
5b6312fd NC |
8400 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
8401 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
8402 | frame_display_row (fc, &need_col_headers, &max_regs); |
8403 | ||
8404 | start = block_end; | |
604282a7 | 8405 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
8406 | } |
8407 | ||
8408 | printf ("\n"); | |
8409 | ||
3391569f NC |
8410 | while (remembered_state != NULL) |
8411 | { | |
8412 | rs = remembered_state; | |
8413 | remembered_state = rs->next; | |
8414 | free (rs->col_type); | |
8415 | free (rs->col_offset); | |
8416 | rs->next = NULL; /* Paranoia. */ | |
8417 | free (rs); | |
8418 | } | |
8419 | ||
8420 | while (chunks != NULL) | |
8421 | { | |
8422 | rs = chunks; | |
8423 | chunks = rs->next; | |
8424 | free (rs->col_type); | |
8425 | free (rs->col_offset); | |
8426 | rs->next = NULL; /* Paranoia. */ | |
8427 | free (rs); | |
8428 | } | |
8429 | ||
8430 | while (forward_refs != NULL) | |
8431 | { | |
8432 | rs = forward_refs; | |
8433 | forward_refs = rs->next; | |
8434 | free (rs->col_type); | |
8435 | free (rs->col_offset); | |
8436 | rs->next = NULL; /* Paranoia. */ | |
8437 | free (rs); | |
8438 | } | |
8439 | ||
19e6b90e L |
8440 | return 1; |
8441 | } | |
8442 | ||
8443 | #undef GET | |
19e6b90e | 8444 | |
61364358 JK |
8445 | static int |
8446 | display_debug_names (struct dwarf_section *section, void *file) | |
8447 | { | |
8448 | unsigned char *hdrptr = section->start; | |
8449 | dwarf_vma unit_length; | |
8450 | unsigned char *unit_start; | |
8451 | const unsigned char *const section_end = section->start + section->size; | |
8452 | unsigned char *unit_end; | |
8453 | ||
dda8d76d | 8454 | introduce (section, FALSE); |
61364358 | 8455 | |
dda8d76d | 8456 | load_debug_section_with_follow (str, file); |
61364358 JK |
8457 | |
8458 | for (; hdrptr < section_end; hdrptr = unit_end) | |
8459 | { | |
8460 | unsigned int offset_size; | |
8461 | uint16_t dwarf_version, padding; | |
8462 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
8463 | uint32_t bucket_count, name_count, abbrev_table_size; | |
8464 | uint32_t augmentation_string_size; | |
8465 | unsigned int i; | |
e98fdf1a | 8466 | unsigned long sec_off; |
61364358 JK |
8467 | |
8468 | unit_start = hdrptr; | |
8469 | ||
8470 | /* Get and check the length of the block. */ | |
8471 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
8472 | ||
8473 | if (unit_length == 0xffffffff) | |
8474 | { | |
8475 | /* This section is 64-bit DWARF. */ | |
8476 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
8477 | offset_size = 8; | |
8478 | } | |
8479 | else | |
8480 | offset_size = 4; | |
8481 | unit_end = hdrptr + unit_length; | |
8482 | ||
e98fdf1a AM |
8483 | sec_off = hdrptr - section->start; |
8484 | if (sec_off + unit_length < sec_off | |
8485 | || sec_off + unit_length > section->size) | |
61364358 | 8486 | { |
e98fdf1a AM |
8487 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
8488 | section->name, | |
8489 | (unsigned long) (unit_start - section->start), | |
8490 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
8491 | return 0; |
8492 | } | |
8493 | ||
8494 | /* Get and check the version number. */ | |
8495 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
8496 | printf (_("Version %ld\n"), (long) dwarf_version); | |
8497 | ||
8498 | /* Prior versions did not exist, and future versions may not be | |
8499 | backwards compatible. */ | |
8500 | if (dwarf_version != 5) | |
8501 | { | |
8502 | warn (_("Only DWARF version 5 .debug_names " | |
8503 | "is currently supported.\n")); | |
8504 | return 0; | |
8505 | } | |
8506 | ||
8507 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
8508 | if (padding != 0) | |
8509 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
8510 | padding); | |
8511 | ||
8512 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
8513 | if (comp_unit_count == 0) | |
8514 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
8515 | ||
8516 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
8517 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
8518 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
8519 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
8520 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
8521 | ||
8522 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
8523 | if (augmentation_string_size % 4 != 0) | |
8524 | { | |
8525 | warn (_("Augmentation string length %u must be rounded up " | |
8526 | "to a multiple of 4 in .debug_names.\n"), | |
8527 | augmentation_string_size); | |
8528 | augmentation_string_size += (-augmentation_string_size) & 3; | |
8529 | } | |
8530 | printf (_("Augmentation string:")); | |
8531 | for (i = 0; i < augmentation_string_size; i++) | |
8532 | { | |
8533 | unsigned char uc; | |
8534 | ||
8535 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
8536 | printf (" %02x", uc); | |
8537 | } | |
8538 | putchar ('\n'); | |
8539 | putchar ('\n'); | |
8540 | ||
8541 | printf (_("CU table:\n")); | |
8542 | for (i = 0; i < comp_unit_count; i++) | |
8543 | { | |
8544 | uint64_t cu_offset; | |
8545 | ||
8546 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
8547 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
8548 | } | |
8549 | putchar ('\n'); | |
8550 | ||
8551 | printf (_("TU table:\n")); | |
8552 | for (i = 0; i < local_type_unit_count; i++) | |
8553 | { | |
8554 | uint64_t tu_offset; | |
8555 | ||
8556 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
8557 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
8558 | } | |
8559 | putchar ('\n'); | |
8560 | ||
8561 | printf (_("Foreign TU table:\n")); | |
8562 | for (i = 0; i < foreign_type_unit_count; i++) | |
8563 | { | |
8564 | uint64_t signature; | |
8565 | ||
8566 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
8567 | printf (_("[%3u] "), i); | |
8568 | print_dwarf_vma (signature, 8); | |
8569 | putchar ('\n'); | |
8570 | } | |
8571 | putchar ('\n'); | |
8572 | ||
8573 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
8574 | hdrptr += bucket_count * sizeof (uint32_t); | |
8575 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
8576 | hdrptr += name_count * sizeof (uint32_t); | |
8577 | unsigned char *const name_table_string_offsets = hdrptr; | |
8578 | hdrptr += name_count * offset_size; | |
8579 | unsigned char *const name_table_entry_offsets = hdrptr; | |
8580 | hdrptr += name_count * offset_size; | |
8581 | unsigned char *const abbrev_table = hdrptr; | |
8582 | hdrptr += abbrev_table_size; | |
8583 | const unsigned char *const abbrev_table_end = hdrptr; | |
8584 | unsigned char *const entry_pool = hdrptr; | |
8585 | if (hdrptr > unit_end) | |
8586 | { | |
8587 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
8588 | "for unit 0x%lx in the debug_names\n"), | |
8589 | (long) (hdrptr - section->start), | |
8590 | (long) (unit_end - section->start), | |
8591 | (long) (unit_start - section->start)); | |
8592 | return 0; | |
8593 | } | |
8594 | ||
8595 | size_t buckets_filled = 0; | |
8596 | size_t bucketi; | |
8597 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
8598 | { | |
8599 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
8600 | ||
8601 | if (bucket != 0) | |
8602 | ++buckets_filled; | |
8603 | } | |
d3a49aa8 AM |
8604 | printf (ngettext ("Used %zu of %lu bucket.\n", |
8605 | "Used %zu of %lu buckets.\n", | |
8606 | bucket_count), | |
8607 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 8608 | |
0a79bef4 | 8609 | uint32_t hash_prev = 0; |
61364358 JK |
8610 | size_t hash_clash_count = 0; |
8611 | size_t longest_clash = 0; | |
8612 | size_t this_length = 0; | |
8613 | size_t hashi; | |
8614 | for (hashi = 0; hashi < name_count; hashi++) | |
8615 | { | |
8616 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
8617 | ||
8618 | if (hashi > 0) | |
8619 | { | |
8620 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
8621 | { | |
8622 | ++hash_clash_count; | |
8623 | ++this_length; | |
8624 | longest_clash = MAX (longest_clash, this_length); | |
8625 | } | |
8626 | else | |
8627 | this_length = 0; | |
8628 | } | |
8629 | hash_prev = hash_this; | |
8630 | } | |
8631 | printf (_("Out of %lu items there are %zu bucket clashes" | |
8632 | " (longest of %zu entries).\n"), | |
8633 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
8634 | assert (name_count == buckets_filled + hash_clash_count); | |
8635 | ||
8636 | struct abbrev_lookup_entry | |
8637 | { | |
8638 | dwarf_vma abbrev_tag; | |
8639 | unsigned char *abbrev_lookup_ptr; | |
8640 | }; | |
8641 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
8642 | size_t abbrev_lookup_used = 0; | |
8643 | size_t abbrev_lookup_allocated = 0; | |
8644 | ||
8645 | unsigned char *abbrevptr = abbrev_table; | |
8646 | for (;;) | |
8647 | { | |
8648 | unsigned int bytes_read; | |
8649 | const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read, | |
8650 | abbrev_table_end); | |
8651 | abbrevptr += bytes_read; | |
8652 | if (abbrev_tag == 0) | |
8653 | break; | |
8654 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
8655 | { | |
8656 | abbrev_lookup_allocated = MAX (0x100, | |
8657 | abbrev_lookup_allocated * 2); | |
8658 | abbrev_lookup = xrealloc (abbrev_lookup, | |
8659 | (abbrev_lookup_allocated | |
8660 | * sizeof (*abbrev_lookup))); | |
8661 | } | |
8662 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
8663 | struct abbrev_lookup_entry *entry; | |
8664 | for (entry = abbrev_lookup; | |
8665 | entry < abbrev_lookup + abbrev_lookup_used; | |
8666 | entry++) | |
8667 | if (entry->abbrev_tag == abbrev_tag) | |
8668 | { | |
8669 | warn (_("Duplicate abbreviation tag %lu " | |
8670 | "in unit 0x%lx in the debug_names\n"), | |
8671 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
8672 | break; | |
8673 | } | |
8674 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
8675 | entry->abbrev_tag = abbrev_tag; | |
8676 | entry->abbrev_lookup_ptr = abbrevptr; | |
8677 | ||
8678 | /* Skip DWARF tag. */ | |
8679 | read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end); | |
8680 | abbrevptr += bytes_read; | |
8681 | for (;;) | |
8682 | { | |
1d827a72 L |
8683 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
8684 | &bytes_read, | |
8685 | abbrev_table_end); | |
61364358 JK |
8686 | abbrevptr += bytes_read; |
8687 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
8688 | abbrev_table_end); | |
8689 | abbrevptr += bytes_read; | |
1d827a72 | 8690 | if (xindex == 0 && form == 0) |
61364358 JK |
8691 | break; |
8692 | } | |
8693 | } | |
8694 | ||
8695 | printf (_("\nSymbol table:\n")); | |
8696 | uint32_t namei; | |
8697 | for (namei = 0; namei < name_count; ++namei) | |
8698 | { | |
8699 | uint64_t string_offset, entry_offset; | |
8700 | ||
8701 | SAFE_BYTE_GET (string_offset, | |
8702 | name_table_string_offsets + namei * offset_size, | |
8703 | offset_size, unit_end); | |
8704 | SAFE_BYTE_GET (entry_offset, | |
8705 | name_table_entry_offsets + namei * offset_size, | |
8706 | offset_size, unit_end); | |
8707 | ||
8708 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
8709 | fetch_indirect_string (string_offset)); | |
8710 | ||
8711 | unsigned char *entryptr = entry_pool + entry_offset; | |
8712 | ||
8713 | // We need to scan first whether there is a single or multiple | |
8714 | // entries. TAGNO is -2 for the first entry, it is -1 for the | |
8715 | // initial tag read of the second entry, then it becomes 0 for the | |
8716 | // first entry for real printing etc. | |
8717 | int tagno = -2; | |
8718 | /* Initialize it due to a false compiler warning. */ | |
8719 | dwarf_vma second_abbrev_tag = -1; | |
8720 | for (;;) | |
8721 | { | |
8722 | unsigned int bytes_read; | |
8723 | const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read, | |
8724 | unit_end); | |
8725 | entryptr += bytes_read; | |
8726 | if (tagno == -1) | |
8727 | { | |
8728 | second_abbrev_tag = abbrev_tag; | |
8729 | tagno = 0; | |
8730 | entryptr = entry_pool + entry_offset; | |
8731 | continue; | |
8732 | } | |
8733 | if (abbrev_tag == 0) | |
8734 | break; | |
8735 | if (tagno >= 0) | |
8736 | printf ("%s<%lu>", | |
8737 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
8738 | (unsigned long) abbrev_tag); | |
8739 | ||
8740 | const struct abbrev_lookup_entry *entry; | |
8741 | for (entry = abbrev_lookup; | |
8742 | entry < abbrev_lookup + abbrev_lookup_used; | |
8743 | entry++) | |
8744 | if (entry->abbrev_tag == abbrev_tag) | |
8745 | break; | |
8746 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
8747 | { | |
8748 | warn (_("Undefined abbreviation tag %lu " | |
8749 | "in unit 0x%lx in the debug_names\n"), | |
8750 | (long) abbrev_tag, | |
8751 | (long) (unit_start - section->start)); | |
8752 | break; | |
8753 | } | |
8754 | abbrevptr = entry->abbrev_lookup_ptr; | |
8755 | const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read, | |
8756 | abbrev_table_end); | |
8757 | abbrevptr += bytes_read; | |
8758 | if (tagno >= 0) | |
8759 | printf (" %s", get_TAG_name (dwarf_tag)); | |
8760 | for (;;) | |
8761 | { | |
1d827a72 L |
8762 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
8763 | &bytes_read, | |
8764 | abbrev_table_end); | |
61364358 JK |
8765 | abbrevptr += bytes_read; |
8766 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
8767 | abbrev_table_end); | |
8768 | abbrevptr += bytes_read; | |
1d827a72 | 8769 | if (xindex == 0 && form == 0) |
61364358 JK |
8770 | break; |
8771 | ||
8772 | if (tagno >= 0) | |
1d827a72 | 8773 | printf (" %s", get_IDX_name (xindex)); |
61364358 JK |
8774 | entryptr = read_and_display_attr_value (0, form, 0, entryptr, |
8775 | unit_end, 0, 0, | |
8776 | offset_size, | |
8777 | dwarf_version, NULL, | |
8778 | (tagno < 0), NULL, | |
8779 | NULL, '='); | |
8780 | } | |
8781 | ++tagno; | |
8782 | } | |
8783 | if (tagno <= 0) | |
8784 | printf (_(" <no entries>")); | |
8785 | putchar ('\n'); | |
8786 | } | |
8787 | ||
8788 | free (abbrev_lookup); | |
8789 | } | |
8790 | ||
8791 | return 1; | |
8792 | } | |
8793 | ||
dda8d76d | 8794 | static int |
d85bf2ba NC |
8795 | display_debug_links (struct dwarf_section * section, |
8796 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
8797 | { |
8798 | const unsigned char * filename; | |
8799 | unsigned int filelen; | |
8800 | ||
8801 | introduce (section, FALSE); | |
8802 | ||
8803 | /* The .gnu_debuglink section is formatted as: | |
8804 | (c-string) Filename. | |
8805 | (padding) If needed to reach a 4 byte boundary. | |
8806 | (uint32_t) CRC32 value. | |
8807 | ||
8808 | The .gun_debugaltlink section is formatted as: | |
8809 | (c-string) Filename. | |
8810 | (binary) Build-ID. */ | |
8811 | ||
8812 | filename = section->start; | |
8813 | filelen = strnlen ((const char *) filename, section->size); | |
8814 | if (filelen == section->size) | |
8815 | { | |
8816 | warn (_("The debuglink filename is corrupt/missing\n")); | |
8817 | return 0; | |
8818 | } | |
8819 | ||
8820 | printf (_(" Separate debug info file: %s\n"), filename); | |
8821 | ||
8822 | if (const_strneq (section->name, ".gnu_debuglink")) | |
8823 | { | |
8824 | unsigned int crc32; | |
8825 | unsigned int crc_offset; | |
8826 | ||
8827 | crc_offset = filelen + 1; | |
8828 | crc_offset = (crc_offset + 3) & ~3; | |
8829 | if (crc_offset + 4 > section->size) | |
8830 | { | |
8831 | warn (_("CRC offset missing/truncated\n")); | |
8832 | return 0; | |
8833 | } | |
8834 | ||
8835 | crc32 = byte_get (filename + crc_offset, 4); | |
8836 | ||
8837 | printf (_(" CRC value: %#x\n"), crc32); | |
8838 | ||
8839 | if (crc_offset + 4 < section->size) | |
8840 | { | |
8841 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
8842 | (long)(section->size - (crc_offset + 4))); | |
8843 | return 0; | |
8844 | } | |
8845 | } | |
8846 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
8847 | { | |
8848 | const unsigned char * build_id = section->start + filelen + 1; | |
8849 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
8850 | bfd_size_type printed; | |
8851 | ||
8852 | /* FIXME: Should we support smaller build-id notes ? */ | |
8853 | if (build_id_len < 0x14) | |
8854 | { | |
8855 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
8856 | return 0; | |
8857 | } | |
8858 | ||
8859 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 8860 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
8861 | putchar ('\n'); |
8862 | } | |
8863 | ||
8864 | putchar ('\n'); | |
8865 | return 1; | |
8866 | } | |
8867 | ||
5bbdf3d5 DE |
8868 | static int |
8869 | display_gdb_index (struct dwarf_section *section, | |
8870 | void *file ATTRIBUTE_UNUSED) | |
8871 | { | |
8872 | unsigned char *start = section->start; | |
8873 | uint32_t version; | |
8874 | uint32_t cu_list_offset, tu_list_offset; | |
8875 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
8876 | unsigned int cu_list_elements, tu_list_elements; | |
8877 | unsigned int address_table_size, symbol_table_slots; | |
8878 | unsigned char *cu_list, *tu_list; | |
8879 | unsigned char *address_table, *symbol_table, *constant_pool; | |
8880 | unsigned int i; | |
8881 | ||
8882 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
8883 | ||
dda8d76d | 8884 | introduce (section, FALSE); |
5bbdf3d5 DE |
8885 | |
8886 | if (section->size < 6 * sizeof (uint32_t)) | |
8887 | { | |
8888 | warn (_("Truncated header in the %s section.\n"), section->name); | |
8889 | return 0; | |
8890 | } | |
8891 | ||
8892 | version = byte_get_little_endian (start, 4); | |
da88a764 | 8893 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
8894 | |
8895 | /* Prior versions are obsolete, and future versions may not be | |
8896 | backwards compatible. */ | |
aa170720 | 8897 | if (version < 3 || version > 8) |
5bbdf3d5 | 8898 | { |
da88a764 | 8899 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
8900 | return 0; |
8901 | } | |
8d6eee87 TT |
8902 | if (version < 4) |
8903 | warn (_("The address table data in version 3 may be wrong.\n")); | |
8904 | if (version < 5) | |
8905 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
8906 | if (version < 6) | |
8907 | warn (_("Version 5 does not include inlined functions.\n")); | |
8908 | if (version < 7) | |
8909 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
8910 | /* Version 7 indices generated by Gold have bad type unit references, |
8911 | PR binutils/15021. But we don't know if the index was generated by | |
8912 | Gold or not, so to avoid worrying users with gdb-generated indices | |
8913 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
8914 | |
8915 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
8916 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
8917 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
8918 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
8919 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
8920 | ||
8921 | if (cu_list_offset > section->size | |
8922 | || tu_list_offset > section->size | |
8923 | || address_table_offset > section->size | |
8924 | || symbol_table_offset > section->size | |
8925 | || constant_pool_offset > section->size) | |
8926 | { | |
8927 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
8928 | return 0; | |
8929 | } | |
8930 | ||
53774b7e NC |
8931 | /* PR 17531: file: 418d0a8a. */ |
8932 | if (tu_list_offset < cu_list_offset) | |
8933 | { | |
8934 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
8935 | tu_list_offset, cu_list_offset); | |
8936 | return 0; | |
8937 | } | |
8938 | ||
5bbdf3d5 | 8939 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
8940 | |
8941 | if (address_table_offset < tu_list_offset) | |
8942 | { | |
8943 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
8944 | address_table_offset, tu_list_offset); | |
8945 | return 0; | |
8946 | } | |
8947 | ||
5bbdf3d5 | 8948 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
8949 | |
8950 | /* PR 17531: file: 18a47d3d. */ | |
8951 | if (symbol_table_offset < address_table_offset) | |
8952 | { | |
13bace4a | 8953 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
8954 | symbol_table_offset, address_table_offset); |
8955 | return 0; | |
8956 | } | |
8957 | ||
5bbdf3d5 | 8958 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
8959 | |
8960 | if (constant_pool_offset < symbol_table_offset) | |
8961 | { | |
8962 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
8963 | constant_pool_offset, symbol_table_offset); | |
8964 | return 0; | |
8965 | } | |
8966 | ||
5bbdf3d5 DE |
8967 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
8968 | ||
8969 | cu_list = start + cu_list_offset; | |
8970 | tu_list = start + tu_list_offset; | |
8971 | address_table = start + address_table_offset; | |
8972 | symbol_table = start + symbol_table_offset; | |
8973 | constant_pool = start + constant_pool_offset; | |
8974 | ||
28d909e5 | 8975 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 8976 | { |
1306a742 | 8977 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
8978 | return 0; |
8979 | } | |
b4eb7656 | 8980 | |
5bbdf3d5 DE |
8981 | printf (_("\nCU table:\n")); |
8982 | for (i = 0; i < cu_list_elements; i += 2) | |
8983 | { | |
8984 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
8985 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
8986 | ||
8987 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
8988 | (unsigned long) cu_offset, | |
8989 | (unsigned long) (cu_offset + cu_length - 1)); | |
8990 | } | |
8991 | ||
8992 | printf (_("\nTU table:\n")); | |
8993 | for (i = 0; i < tu_list_elements; i += 3) | |
8994 | { | |
8995 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
8996 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
8997 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
8998 | ||
8999 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
9000 | (unsigned long) tu_offset, | |
9001 | (unsigned long) type_offset); | |
9002 | print_dwarf_vma (signature, 8); | |
9003 | printf ("\n"); | |
9004 | } | |
9005 | ||
9006 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
9007 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
9008 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
9009 | { |
9010 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
9011 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
9012 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
9013 | ||
9014 | print_dwarf_vma (low, 8); | |
9015 | print_dwarf_vma (high, 8); | |
da88a764 | 9016 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
9017 | } |
9018 | ||
9019 | printf (_("\nSymbol table:\n")); | |
9020 | for (i = 0; i < symbol_table_slots; ++i) | |
9021 | { | |
9022 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
9023 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
9024 | uint32_t num_cus, cu; | |
9025 | ||
9026 | if (name_offset != 0 | |
9027 | || cu_vector_offset != 0) | |
9028 | { | |
9029 | unsigned int j; | |
362beea4 | 9030 | unsigned char * adr; |
5bbdf3d5 | 9031 | |
362beea4 | 9032 | adr = constant_pool + name_offset; |
53774b7e | 9033 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 9034 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
9035 | { |
9036 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
9037 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
9038 | name_offset, i); | |
9039 | } | |
9040 | else | |
acff9664 NC |
9041 | printf ("[%3u] %.*s:", i, |
9042 | (int) (section->size - (constant_pool_offset + name_offset)), | |
9043 | constant_pool + name_offset); | |
53774b7e | 9044 | |
362beea4 NC |
9045 | adr = constant_pool + cu_vector_offset; |
9046 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
9047 | { |
9048 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
9049 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
9050 | cu_vector_offset, i); | |
9051 | continue; | |
9052 | } | |
57028622 | 9053 | |
362beea4 | 9054 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 9055 | |
362beea4 | 9056 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 9057 | if (num_cus * 4 < num_cus |
362beea4 NC |
9058 | || adr >= section->start + section->size |
9059 | || adr < constant_pool) | |
53774b7e NC |
9060 | { |
9061 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 9062 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
9063 | num_cus, i); |
9064 | continue; | |
9065 | } | |
9066 | ||
8d6eee87 TT |
9067 | if (num_cus > 1) |
9068 | printf ("\n"); | |
f3853b34 | 9069 | |
5bbdf3d5 DE |
9070 | for (j = 0; j < num_cus; ++j) |
9071 | { | |
7c1cef97 | 9072 | int is_static; |
8d6eee87 TT |
9073 | gdb_index_symbol_kind kind; |
9074 | ||
5bbdf3d5 | 9075 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 9076 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
9077 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
9078 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 9079 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 9080 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
9081 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
9082 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 9083 | else |
8d6eee87 TT |
9084 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
9085 | ||
459d52c8 DE |
9086 | printf (" [%s, %s]", |
9087 | is_static ? _("static") : _("global"), | |
9088 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
9089 | if (num_cus > 1) |
9090 | printf ("\n"); | |
5bbdf3d5 | 9091 | } |
8d6eee87 TT |
9092 | if (num_cus <= 1) |
9093 | printf ("\n"); | |
5bbdf3d5 DE |
9094 | } |
9095 | } | |
9096 | ||
9097 | return 1; | |
9098 | } | |
9099 | ||
657d0d47 CC |
9100 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
9101 | ||
9102 | static void | |
9103 | prealloc_cu_tu_list (unsigned int nshndx) | |
9104 | { | |
9105 | if (shndx_pool == NULL) | |
9106 | { | |
9107 | shndx_pool_size = nshndx; | |
9108 | shndx_pool_used = 0; | |
9109 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
9110 | sizeof (unsigned int)); | |
9111 | } | |
9112 | else | |
9113 | { | |
9114 | shndx_pool_size = shndx_pool_used + nshndx; | |
9115 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
9116 | sizeof (unsigned int)); | |
9117 | } | |
9118 | } | |
9119 | ||
9120 | static void | |
9121 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
9122 | { | |
9123 | if (shndx_pool_used >= shndx_pool_size) | |
9124 | { | |
9125 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9126 | return; | |
9127 | } | |
9128 | shndx_pool [shndx_pool_used++] = shndx; | |
9129 | } | |
9130 | ||
9131 | static void | |
9132 | end_cu_tu_entry (void) | |
9133 | { | |
9134 | if (shndx_pool_used >= shndx_pool_size) | |
9135 | { | |
9136 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9137 | return; | |
9138 | } | |
9139 | shndx_pool [shndx_pool_used++] = 0; | |
9140 | } | |
9141 | ||
341f9135 CC |
9142 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
9143 | ||
9144 | static const char * | |
9145 | get_DW_SECT_short_name (unsigned int dw_sect) | |
9146 | { | |
9147 | static char buf[16]; | |
9148 | ||
9149 | switch (dw_sect) | |
9150 | { | |
9151 | case DW_SECT_INFO: | |
9152 | return "info"; | |
9153 | case DW_SECT_TYPES: | |
9154 | return "types"; | |
9155 | case DW_SECT_ABBREV: | |
9156 | return "abbrev"; | |
9157 | case DW_SECT_LINE: | |
9158 | return "line"; | |
9159 | case DW_SECT_LOC: | |
9160 | return "loc"; | |
9161 | case DW_SECT_STR_OFFSETS: | |
9162 | return "str_off"; | |
9163 | case DW_SECT_MACINFO: | |
9164 | return "macinfo"; | |
9165 | case DW_SECT_MACRO: | |
9166 | return "macro"; | |
9167 | default: | |
b4eb7656 | 9168 | break; |
341f9135 CC |
9169 | } |
9170 | ||
9171 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
9172 | return buf; | |
9173 | } | |
9174 | ||
9175 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
9176 | These sections are extensions for Fission. | |
9177 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
9178 | |
9179 | static int | |
9180 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
9181 | { | |
9182 | unsigned char *phdr = section->start; | |
9183 | unsigned char *limit = phdr + section->size; | |
9184 | unsigned char *phash; | |
9185 | unsigned char *pindex; | |
9186 | unsigned char *ppool; | |
9187 | unsigned int version; | |
341f9135 | 9188 | unsigned int ncols = 0; |
657d0d47 CC |
9189 | unsigned int nused; |
9190 | unsigned int nslots; | |
9191 | unsigned int i; | |
341f9135 CC |
9192 | unsigned int j; |
9193 | dwarf_vma signature_high; | |
9194 | dwarf_vma signature_low; | |
9195 | char buf[64]; | |
657d0d47 | 9196 | |
6937bb54 NC |
9197 | /* PR 17512: file: 002-168123-0.004. */ |
9198 | if (phdr == NULL) | |
9199 | { | |
9200 | warn (_("Section %s is empty\n"), section->name); | |
9201 | return 0; | |
9202 | } | |
9203 | /* PR 17512: file: 002-376-0.004. */ | |
9204 | if (section->size < 24) | |
9205 | { | |
72c61a0d | 9206 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
9207 | section->name); |
9208 | return 0; | |
9209 | } | |
9210 | ||
9211 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 9212 | if (version >= 2) |
6937bb54 NC |
9213 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
9214 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
9215 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
9216 | ||
657d0d47 CC |
9217 | phash = phdr + 16; |
9218 | pindex = phash + nslots * 8; | |
9219 | ppool = pindex + nslots * 4; | |
9220 | ||
57028622 | 9221 | /* PR 17531: file: 45d69832. */ |
03a91817 | 9222 | if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0)) |
57028622 | 9223 | { |
d3a49aa8 AM |
9224 | warn (ngettext ("Section %s is too small for %d slot\n", |
9225 | "Section %s is too small for %d slots\n", | |
9226 | nslots), | |
57028622 NC |
9227 | section->name, nslots); |
9228 | return 0; | |
9229 | } | |
9230 | ||
657d0d47 CC |
9231 | if (do_display) |
9232 | { | |
dda8d76d NC |
9233 | introduce (section, FALSE); |
9234 | ||
657d0d47 | 9235 | printf (_(" Version: %d\n"), version); |
341f9135 CC |
9236 | if (version >= 2) |
9237 | printf (_(" Number of columns: %d\n"), ncols); | |
657d0d47 CC |
9238 | printf (_(" Number of used entries: %d\n"), nused); |
9239 | printf (_(" Number of slots: %d\n\n"), nslots); | |
9240 | } | |
9241 | ||
03a91817 | 9242 | if (ppool > limit || ppool < phdr) |
657d0d47 CC |
9243 | { |
9244 | warn (_("Section %s too small for %d hash table entries\n"), | |
9245 | section->name, nslots); | |
9246 | return 0; | |
9247 | } | |
9248 | ||
341f9135 | 9249 | if (version == 1) |
657d0d47 | 9250 | { |
341f9135 CC |
9251 | if (!do_display) |
9252 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
9253 | for (i = 0; i < nslots; i++) | |
657d0d47 | 9254 | { |
341f9135 CC |
9255 | unsigned char *shndx_list; |
9256 | unsigned int shndx; | |
9257 | ||
6937bb54 | 9258 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 9259 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 9260 | { |
6937bb54 | 9261 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 9262 | shndx_list = ppool + j * 4; |
f3853b34 NC |
9263 | /* PR 17531: file: 705e010d. */ |
9264 | if (shndx_list < ppool) | |
9265 | { | |
9266 | warn (_("Section index pool located before start of section\n")); | |
9267 | return 0; | |
9268 | } | |
9269 | ||
341f9135 CC |
9270 | if (do_display) |
9271 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
9272 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9273 | buf, sizeof (buf))); | |
9274 | for (;;) | |
657d0d47 | 9275 | { |
341f9135 CC |
9276 | if (shndx_list >= limit) |
9277 | { | |
9278 | warn (_("Section %s too small for shndx pool\n"), | |
9279 | section->name); | |
9280 | return 0; | |
9281 | } | |
6937bb54 | 9282 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
9283 | if (shndx == 0) |
9284 | break; | |
9285 | if (do_display) | |
9286 | printf (" %d", shndx); | |
9287 | else | |
9288 | add_shndx_to_cu_tu_entry (shndx); | |
9289 | shndx_list += 4; | |
657d0d47 | 9290 | } |
657d0d47 | 9291 | if (do_display) |
341f9135 | 9292 | printf ("\n"); |
657d0d47 | 9293 | else |
341f9135 CC |
9294 | end_cu_tu_entry (); |
9295 | } | |
9296 | phash += 8; | |
9297 | pindex += 4; | |
9298 | } | |
9299 | } | |
9300 | else if (version == 2) | |
9301 | { | |
9302 | unsigned int val; | |
9303 | unsigned int dw_sect; | |
9304 | unsigned char *ph = phash; | |
9305 | unsigned char *pi = pindex; | |
9306 | unsigned char *poffsets = ppool + ncols * 4; | |
9307 | unsigned char *psizes = poffsets + nused * ncols * 4; | |
9308 | unsigned char *pend = psizes + nused * ncols * 4; | |
9309 | bfd_boolean is_tu_index; | |
9310 | struct cu_tu_set *this_set = NULL; | |
9311 | unsigned int row; | |
9312 | unsigned char *prow; | |
9313 | ||
9314 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
9315 | ||
362beea4 | 9316 | /* PR 17531: file: 0dd159bf. |
b4eb7656 | 9317 | Check for wraparound with an overlarge ncols value. */ |
c8071705 | 9318 | if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols) |
362beea4 NC |
9319 | { |
9320 | warn (_("Overlarge number of columns: %x\n"), ncols); | |
9321 | return 0; | |
9322 | } | |
9323 | ||
341f9135 CC |
9324 | if (pend > limit) |
9325 | { | |
9326 | warn (_("Section %s too small for offset and size tables\n"), | |
9327 | section->name); | |
9328 | return 0; | |
9329 | } | |
9330 | ||
9331 | if (do_display) | |
9332 | { | |
9333 | printf (_(" Offset table\n")); | |
9334 | printf (" slot %-16s ", | |
9335 | is_tu_index ? _("signature") : _("dwo_id")); | |
9336 | } | |
9337 | else | |
9338 | { | |
9339 | if (is_tu_index) | |
9340 | { | |
9341 | tu_count = nused; | |
72c61a0d | 9342 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 9343 | this_set = tu_sets; |
657d0d47 | 9344 | } |
657d0d47 | 9345 | else |
341f9135 CC |
9346 | { |
9347 | cu_count = nused; | |
72c61a0d | 9348 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
9349 | this_set = cu_sets; |
9350 | } | |
9351 | } | |
6937bb54 | 9352 | |
341f9135 CC |
9353 | if (do_display) |
9354 | { | |
9355 | for (j = 0; j < ncols; j++) | |
9356 | { | |
6937bb54 | 9357 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
9358 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
9359 | } | |
9360 | printf ("\n"); | |
9361 | } | |
6937bb54 | 9362 | |
341f9135 CC |
9363 | for (i = 0; i < nslots; i++) |
9364 | { | |
6937bb54 NC |
9365 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9366 | ||
9367 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9368 | if (row != 0) |
9369 | { | |
591f7597 | 9370 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 9371 | if (row > nused) |
591f7597 NC |
9372 | { |
9373 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
9374 | row, nused); | |
9375 | return 0; | |
9376 | } | |
9377 | ||
341f9135 | 9378 | if (!do_display) |
6aea08d9 NC |
9379 | { |
9380 | size_t num_copy = sizeof (uint64_t); | |
9381 | ||
9382 | /* PR 23064: Beware of buffer overflow. */ | |
9383 | if (ph + num_copy < limit) | |
9384 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
9385 | else | |
9386 | { | |
9387 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
9388 | return 0; | |
9389 | } | |
9390 | } | |
6937bb54 | 9391 | |
341f9135 | 9392 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
9393 | /* PR 17531: file: b8ce60a8. */ |
9394 | if (prow < poffsets || prow > limit) | |
9395 | { | |
9396 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
9397 | row, ncols); | |
9398 | return 0; | |
9399 | } | |
3aade688 | 9400 | |
341f9135 CC |
9401 | if (do_display) |
9402 | printf (_(" [%3d] 0x%s"), | |
9403 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9404 | buf, sizeof (buf))); | |
9405 | for (j = 0; j < ncols; j++) | |
9406 | { | |
6937bb54 | 9407 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9408 | if (do_display) |
9409 | printf (" %8d", val); | |
9410 | else | |
9411 | { | |
6937bb54 | 9412 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9413 | |
9414 | /* PR 17531: file: 10796eb3. */ | |
9415 | if (dw_sect >= DW_SECT_MAX) | |
9416 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9417 | else | |
9418 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
9419 | } |
9420 | } | |
6937bb54 | 9421 | |
341f9135 CC |
9422 | if (do_display) |
9423 | printf ("\n"); | |
9424 | } | |
9425 | ph += 8; | |
9426 | pi += 4; | |
9427 | } | |
9428 | ||
9429 | ph = phash; | |
9430 | pi = pindex; | |
9431 | if (do_display) | |
b4eb7656 | 9432 | { |
341f9135 CC |
9433 | printf ("\n"); |
9434 | printf (_(" Size table\n")); | |
9435 | printf (" slot %-16s ", | |
9436 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 9437 | } |
6937bb54 | 9438 | |
341f9135 CC |
9439 | for (j = 0; j < ncols; j++) |
9440 | { | |
6937bb54 | 9441 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
9442 | if (do_display) |
9443 | printf (" %8s", get_DW_SECT_short_name (val)); | |
9444 | } | |
6937bb54 | 9445 | |
341f9135 CC |
9446 | if (do_display) |
9447 | printf ("\n"); | |
6937bb54 | 9448 | |
341f9135 CC |
9449 | for (i = 0; i < nslots; i++) |
9450 | { | |
6937bb54 NC |
9451 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9452 | ||
9453 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9454 | if (row != 0) |
9455 | { | |
9456 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 9457 | |
341f9135 CC |
9458 | if (do_display) |
9459 | printf (_(" [%3d] 0x%s"), | |
9460 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9461 | buf, sizeof (buf))); | |
6937bb54 | 9462 | |
341f9135 CC |
9463 | for (j = 0; j < ncols; j++) |
9464 | { | |
6937bb54 | 9465 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9466 | if (do_display) |
9467 | printf (" %8d", val); | |
9468 | else | |
9469 | { | |
6937bb54 | 9470 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9471 | if (dw_sect >= DW_SECT_MAX) |
9472 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9473 | else | |
341f9135 CC |
9474 | this_set [row - 1].section_sizes [dw_sect] = val; |
9475 | } | |
9476 | } | |
6937bb54 | 9477 | |
341f9135 CC |
9478 | if (do_display) |
9479 | printf ("\n"); | |
9480 | } | |
6937bb54 | 9481 | |
341f9135 CC |
9482 | ph += 8; |
9483 | pi += 4; | |
657d0d47 | 9484 | } |
657d0d47 | 9485 | } |
341f9135 | 9486 | else if (do_display) |
6937bb54 | 9487 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
9488 | |
9489 | if (do_display) | |
9490 | printf ("\n"); | |
9491 | ||
9492 | return 1; | |
9493 | } | |
9494 | ||
9495 | /* Load the CU and TU indexes if present. This will build a list of | |
9496 | section sets that we can use to associate a .debug_info.dwo section | |
9497 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
9498 | ||
43a444f9 | 9499 | static bfd_boolean |
657d0d47 CC |
9500 | load_cu_tu_indexes (void *file) |
9501 | { | |
43a444f9 NC |
9502 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
9503 | ||
657d0d47 CC |
9504 | /* If we have already loaded (or tried to load) the CU and TU indexes |
9505 | then do not bother to repeat the task. */ | |
43a444f9 NC |
9506 | if (cu_tu_indexes_read == -1) |
9507 | { | |
9508 | cu_tu_indexes_read = TRUE; | |
9509 | ||
dda8d76d | 9510 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
9511 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
9512 | cu_tu_indexes_read = FALSE; | |
9513 | ||
dda8d76d | 9514 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
9515 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
9516 | cu_tu_indexes_read = FALSE; | |
9517 | } | |
657d0d47 | 9518 | |
43a444f9 | 9519 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
9520 | } |
9521 | ||
9522 | /* Find the set of sections that includes section SHNDX. */ | |
9523 | ||
9524 | unsigned int * | |
9525 | find_cu_tu_set (void *file, unsigned int shndx) | |
9526 | { | |
9527 | unsigned int i; | |
9528 | ||
43a444f9 NC |
9529 | if (! load_cu_tu_indexes (file)) |
9530 | return NULL; | |
657d0d47 CC |
9531 | |
9532 | /* Find SHNDX in the shndx pool. */ | |
9533 | for (i = 0; i < shndx_pool_used; i++) | |
9534 | if (shndx_pool [i] == shndx) | |
9535 | break; | |
9536 | ||
9537 | if (i >= shndx_pool_used) | |
9538 | return NULL; | |
9539 | ||
9540 | /* Now backup to find the first entry in the set. */ | |
9541 | while (i > 0 && shndx_pool [i - 1] != 0) | |
9542 | i--; | |
9543 | ||
9544 | return shndx_pool + i; | |
9545 | } | |
9546 | ||
9547 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
9548 | ||
9549 | static int | |
9550 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
9551 | { | |
9552 | return process_cu_tu_index (section, 1); | |
9553 | } | |
9554 | ||
19e6b90e L |
9555 | static int |
9556 | display_debug_not_supported (struct dwarf_section *section, | |
9557 | void *file ATTRIBUTE_UNUSED) | |
9558 | { | |
9559 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
9560 | section->name); | |
9561 | ||
9562 | return 1; | |
9563 | } | |
9564 | ||
1306a742 NC |
9565 | /* Like malloc, but takes two parameters like calloc. |
9566 | Verifies that the first parameter is not too large. | |
82b1b41b | 9567 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 9568 | |
19e6b90e L |
9569 | void * |
9570 | cmalloc (size_t nmemb, size_t size) | |
9571 | { | |
9572 | /* Check for overflow. */ | |
9573 | if (nmemb >= ~(size_t) 0 / size) | |
9574 | return NULL; | |
82b1b41b NC |
9575 | |
9576 | return xmalloc (nmemb * size); | |
19e6b90e L |
9577 | } |
9578 | ||
1306a742 NC |
9579 | /* Like xmalloc, but takes two parameters like calloc. |
9580 | Verifies that the first parameter is not too large. | |
9581 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 9582 | |
72c61a0d | 9583 | void * |
1306a742 | 9584 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
9585 | { |
9586 | /* Check for overflow. */ | |
9587 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
9588 | { |
9589 | fprintf (stderr, | |
9590 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
9591 | (long) nmemb); | |
9592 | xexit (1); | |
9593 | } | |
72c61a0d | 9594 | |
1306a742 | 9595 | return xmalloc (nmemb * size); |
72c61a0d NC |
9596 | } |
9597 | ||
1306a742 NC |
9598 | /* Like xrealloc, but takes three parameters. |
9599 | Verifies that the second parameter is not too large. | |
9600 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 9601 | |
19e6b90e | 9602 | void * |
1306a742 | 9603 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
9604 | { |
9605 | /* Check for overflow. */ | |
9606 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 9607 | { |
dda8d76d NC |
9608 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
9609 | (long) nmemb); | |
8490fb40 NC |
9610 | xexit (1); |
9611 | } | |
82b1b41b | 9612 | |
1306a742 | 9613 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
9614 | } |
9615 | ||
1306a742 | 9616 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 9617 | |
19e6b90e | 9618 | void * |
1306a742 | 9619 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
9620 | { |
9621 | /* Check for overflow. */ | |
9622 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 9623 | { |
dda8d76d NC |
9624 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
9625 | (long) nmemb); | |
8490fb40 NC |
9626 | xexit (1); |
9627 | } | |
82b1b41b | 9628 | |
1306a742 | 9629 | return xcalloc (nmemb, size); |
19e6b90e L |
9630 | } |
9631 | ||
dda8d76d NC |
9632 | static unsigned long |
9633 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
9634 | const unsigned char * buf, | |
9635 | bfd_size_type len) | |
9636 | { | |
9637 | static const unsigned long crc32_table[256] = | |
9638 | { | |
9639 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
9640 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
9641 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
9642 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
9643 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
9644 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
9645 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
9646 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
9647 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
9648 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
9649 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
9650 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
9651 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
9652 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
9653 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
9654 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
9655 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
9656 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
9657 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
9658 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
9659 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
9660 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
9661 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
9662 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
9663 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
9664 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
9665 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
9666 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
9667 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
9668 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
9669 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
9670 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
9671 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
9672 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
9673 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
9674 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
9675 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
9676 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
9677 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
9678 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
9679 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
9680 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
9681 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
9682 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
9683 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
9684 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
9685 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
9686 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
9687 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
9688 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
9689 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
9690 | 0x2d02ef8d | |
9691 | }; | |
9692 | const unsigned char *end; | |
9693 | ||
9694 | crc = ~crc & 0xffffffff; | |
9695 | for (end = buf + len; buf < end; ++ buf) | |
9696 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
9697 | return ~crc & 0xffffffff; | |
9698 | } | |
9699 | ||
9700 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
9701 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
9702 | ||
9703 | static bfd_boolean | |
9704 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
9705 | { | |
9706 | static unsigned char buffer [8 * 1024]; | |
9707 | FILE * f; | |
9708 | bfd_size_type count; | |
9709 | unsigned long crc = 0; | |
9710 | void * sep_data; | |
9711 | ||
9712 | sep_data = open_debug_file (pathname); | |
9713 | if (sep_data == NULL) | |
9714 | return FALSE; | |
9715 | ||
9716 | /* Yes - we are opening the file twice... */ | |
9717 | f = fopen (pathname, "rb"); | |
9718 | if (f == NULL) | |
9719 | { | |
9720 | /* Paranoia: This should never happen. */ | |
9721 | close_debug_file (sep_data); | |
9722 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
9723 | return FALSE; | |
9724 | } | |
9725 | ||
9726 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
9727 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
9728 | ||
9729 | fclose (f); | |
9730 | ||
9731 | if (crc != * (unsigned long *) crc_pointer) | |
9732 | { | |
9733 | close_debug_file (sep_data); | |
9734 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
9735 | pathname); | |
9736 | return FALSE; | |
9737 | } | |
9738 | ||
9739 | return TRUE; | |
9740 | } | |
9741 | ||
9742 | static const char * | |
9743 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
9744 | { | |
9745 | const char * name; | |
9746 | unsigned int crc_offset; | |
9747 | unsigned long * crc32 = (unsigned long *) data; | |
9748 | ||
9749 | /* The name is first. | |
9750 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
9751 | name = (const char *) section->start; | |
9752 | ||
9753 | crc_offset = strnlen (name, section->size) + 1; | |
9754 | crc_offset = (crc_offset + 3) & ~3; | |
9755 | if (crc_offset + 4 > section->size) | |
9756 | return NULL; | |
9757 | ||
9758 | * crc32 = byte_get (section->start + crc_offset, 4); | |
9759 | return name; | |
9760 | } | |
9761 | ||
9762 | static bfd_boolean | |
9763 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
9764 | { | |
9765 | void * sep_data = open_debug_file (filename); | |
9766 | ||
9767 | if (sep_data == NULL) | |
9768 | return FALSE; | |
9769 | ||
9770 | /* FIXME: We should now extract the build-id in the separate file | |
9771 | and check it... */ | |
9772 | ||
9773 | return TRUE; | |
9774 | } | |
9775 | ||
9776 | typedef struct build_id_data | |
9777 | { | |
9778 | bfd_size_type len; | |
9779 | const unsigned char * data; | |
9780 | } Build_id_data; | |
9781 | ||
9782 | static const char * | |
9783 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
9784 | { | |
9785 | const char * name; | |
9786 | bfd_size_type namelen; | |
9787 | bfd_size_type id_len; | |
9788 | Build_id_data * build_id_data; | |
9789 | ||
9790 | /* The name is first. | |
9791 | The build-id follows immediately, with no padding, up to the section's end. */ | |
9792 | ||
9793 | name = (const char *) section->start; | |
9794 | namelen = strnlen (name, section->size) + 1; | |
9795 | if (namelen >= section->size) | |
9796 | return NULL; | |
9797 | ||
9798 | id_len = section->size - namelen; | |
9799 | if (id_len < 0x14) | |
9800 | return NULL; | |
9801 | ||
9802 | build_id_data = calloc (1, sizeof * build_id_data); | |
9803 | if (build_id_data == NULL) | |
9804 | return NULL; | |
9805 | ||
9806 | build_id_data->len = id_len; | |
9807 | build_id_data->data = section->start + namelen; | |
9808 | ||
9809 | * (Build_id_data **) data = build_id_data; | |
9810 | ||
9811 | return name; | |
9812 | } | |
9813 | ||
9814 | static void * | |
9815 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 9816 | struct dwarf_section * xlink, |
dda8d76d NC |
9817 | parse_func_type parse_func, |
9818 | check_func_type check_func, | |
9819 | void * func_data) | |
9820 | { | |
9821 | const char * separate_filename; | |
9822 | char * debugfile; | |
9823 | char * canon_dir; | |
9824 | size_t canon_dirlen; | |
9825 | size_t dirlen; | |
9826 | ||
2b63c337 | 9827 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
9828 | { |
9829 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 9830 | xlink->name ? xlink->name : xlink->uncompressed_name); |
dda8d76d NC |
9831 | return FALSE; |
9832 | } | |
9833 | ||
9834 | /* Attempt to locate the separate file. | |
9835 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
9836 | ||
9837 | canon_dir = lrealpath (main_filename); | |
9838 | ||
9839 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) | |
9840 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
9841 | break; | |
9842 | canon_dir[canon_dirlen] = '\0'; | |
9843 | ||
9844 | #ifndef DEBUGDIR | |
9845 | #define DEBUGDIR "/lib/debug" | |
9846 | #endif | |
9847 | #ifndef EXTRA_DEBUG_ROOT1 | |
9848 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
9849 | #endif | |
9850 | #ifndef EXTRA_DEBUG_ROOT2 | |
9851 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
9852 | #endif | |
9853 | ||
9854 | debugfile = (char *) malloc (strlen (DEBUGDIR) + 1 | |
9855 | + canon_dirlen | |
9856 | + strlen (".debug/") | |
9857 | #ifdef EXTRA_DEBUG_ROOT1 | |
9858 | + strlen (EXTRA_DEBUG_ROOT1) | |
9859 | #endif | |
9860 | #ifdef EXTRA_DEBUG_ROOT2 | |
9861 | + strlen (EXTRA_DEBUG_ROOT2) | |
9862 | #endif | |
9863 | + strlen (separate_filename) | |
9864 | + 1); | |
9865 | if (debugfile == NULL) | |
9866 | { | |
9867 | warn (_("Out of memory")); | |
3391569f | 9868 | free (canon_dir); |
dda8d76d NC |
9869 | return NULL; |
9870 | } | |
9871 | ||
9872 | /* First try in the current directory. */ | |
9873 | sprintf (debugfile, "%s", separate_filename); | |
9874 | if (check_func (debugfile, func_data)) | |
9875 | goto found; | |
9876 | ||
9877 | /* Then try in a subdirectory called .debug. */ | |
9878 | sprintf (debugfile, ".debug/%s", separate_filename); | |
9879 | if (check_func (debugfile, func_data)) | |
9880 | goto found; | |
9881 | ||
9882 | /* Then try in the same directory as the original file. */ | |
9883 | sprintf (debugfile, "%s%s", canon_dir, separate_filename); | |
9884 | if (check_func (debugfile, func_data)) | |
9885 | goto found; | |
9886 | ||
9887 | /* And the .debug subdirectory of that directory. */ | |
9888 | sprintf (debugfile, "%s.debug/%s", canon_dir, separate_filename); | |
9889 | if (check_func (debugfile, func_data)) | |
9890 | goto found; | |
9891 | ||
9892 | #ifdef EXTRA_DEBUG_ROOT1 | |
9893 | /* Try the first extra debug file root. */ | |
9894 | sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); | |
9895 | if (check_func (debugfile, func_data)) | |
9896 | goto found; | |
9897 | #endif | |
9898 | ||
9899 | #ifdef EXTRA_DEBUG_ROOT2 | |
9900 | /* Try the second extra debug file root. */ | |
9901 | sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); | |
9902 | if (check_func (debugfile, func_data)) | |
9903 | goto found; | |
9904 | #endif | |
9905 | ||
9906 | /* Then try in the global debugfile directory. */ | |
9907 | strcpy (debugfile, DEBUGDIR); | |
9908 | dirlen = strlen (DEBUGDIR) - 1; | |
9909 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
9910 | strcat (debugfile, "/"); | |
9911 | strcat (debugfile, (const char *) separate_filename); | |
9912 | ||
9913 | if (check_func (debugfile, func_data)) | |
9914 | goto found; | |
9915 | ||
9916 | /* Failed to find the file. */ | |
9917 | warn (_("could not find separate debug file '%s'\n"), separate_filename); | |
9918 | warn (_("tried: %s\n"), debugfile); | |
9919 | ||
9920 | #ifdef EXTRA_DEBUG_ROOT2 | |
9921 | sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); | |
9922 | warn (_("tried: %s\n"), debugfile); | |
9923 | #endif | |
9924 | ||
9925 | #ifdef EXTRA_DEBUG_ROOT1 | |
9926 | sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); | |
9927 | warn (_("tried: %s\n"), debugfile); | |
9928 | #endif | |
9929 | ||
9930 | sprintf (debugfile, "%s.debug/%s", canon_dir, separate_filename); | |
9931 | warn (_("tried: %s\n"), debugfile); | |
9932 | ||
9933 | sprintf (debugfile, "%s%s", canon_dir, separate_filename); | |
9934 | warn (_("tried: %s\n"), debugfile); | |
9935 | ||
9936 | sprintf (debugfile, ".debug/%s", separate_filename); | |
9937 | warn (_("tried: %s\n"), debugfile); | |
9938 | ||
9939 | sprintf (debugfile, "%s", separate_filename); | |
9940 | warn (_("tried: %s\n"), debugfile); | |
9941 | ||
9942 | free (canon_dir); | |
9943 | free (debugfile); | |
9944 | return NULL; | |
9945 | ||
9946 | found: | |
9947 | free (canon_dir); | |
9948 | ||
9949 | /* Now open the file.... */ | |
9950 | if ((separate_debug_file = open_debug_file (debugfile)) == NULL) | |
9951 | { | |
9952 | warn (_("failed to open separate debug file: %s\n"), debugfile); | |
9953 | free (debugfile); | |
9954 | return FALSE; | |
9955 | } | |
9956 | ||
9957 | /* FIXME: We do not check to see if there are any other separate debug info | |
9958 | files that would also match. */ | |
9959 | ||
9960 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debugfile); | |
9961 | separate_debug_filename = debugfile; | |
9962 | ||
9963 | /* Do not free debugfile - it might be referenced inside | |
9964 | the structure returned by open_debug_file(). */ | |
9965 | return separate_debug_file; | |
9966 | } | |
9967 | ||
d85bf2ba NC |
9968 | /* Attempt to load a separate dwarf object file. */ |
9969 | ||
9970 | static void * | |
9971 | load_dwo_file (const char * main_filename) | |
9972 | { | |
9973 | char * filename; | |
9974 | ||
9975 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
9976 | filename = concat (dwo_dir, "/", dwo_name, NULL); | |
9977 | if (filename == NULL) | |
9978 | { | |
9979 | warn (_("Out of memory allocating dwo filename\n")); | |
9980 | return NULL; | |
9981 | } | |
9982 | ||
9983 | if ((separate_debug_file = open_debug_file (filename)) == NULL) | |
9984 | { | |
9985 | warn (_("Unable to load dwo file: %s\n"), filename); | |
9986 | free (filename); | |
9987 | return NULL; | |
9988 | } | |
9989 | ||
9990 | /* FIXME: We should check the dwo_id. */ | |
9991 | ||
9992 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, filename); | |
9993 | separate_debug_filename = filename; | |
9994 | return separate_debug_file; | |
9995 | } | |
9996 | ||
dda8d76d NC |
9997 | /* Load a separate debug info file, if it exists. |
9998 | Returns the data pointer that is the result of calling open_debug_file | |
d85bf2ba NC |
9999 | on the separate debug info file, or NULL if there were problems or there |
10000 | is no such file. */ | |
dda8d76d NC |
10001 | |
10002 | void * | |
10003 | load_separate_debug_file (void * file, const char * filename) | |
10004 | { | |
8de3a6e2 NC |
10005 | /* Skip this operation if we are not interested in debug links. */ |
10006 | if (! do_follow_links && ! do_debug_links) | |
10007 | return NULL; | |
10008 | ||
d85bf2ba NC |
10009 | /* See if there is a dwo link. */ |
10010 | if (load_debug_section (str, file) | |
10011 | && load_debug_section (abbrev, file) | |
10012 | && load_debug_section (info, file)) | |
10013 | { | |
10014 | dwo_name = dwo_dir = NULL; | |
10015 | dwo_id = NULL; | |
10016 | dwo_id_len = 0; | |
10017 | ||
10018 | if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE)) | |
10019 | { | |
10020 | if (dwo_name != NULL) | |
10021 | { | |
10022 | if (do_debug_links) | |
10023 | { | |
10024 | printf (_("The %s section contains a link to a dwo file:\n"), | |
10025 | debug_displays [info].section.uncompressed_name); | |
10026 | printf (_(" Name: %s\n"), dwo_name); | |
10027 | printf (_(" Directory: %s\n"), dwo_dir ? dwo_dir : _("<not-found>")); | |
10028 | if (dwo_id != NULL) | |
10029 | display_data (printf (_(" ID: ")), dwo_id, dwo_id_len); | |
10030 | else | |
10031 | printf (_(" ID: <unknown>\n")); | |
10032 | printf ("\n\n"); | |
10033 | } | |
10034 | ||
10035 | /* FIXME: We do not check to see if there are any more dwo links in the file... */ | |
10036 | if (do_follow_links) | |
10037 | return load_dwo_file (filename); | |
10038 | } | |
10039 | } | |
10040 | } | |
10041 | ||
dda8d76d | 10042 | if (! do_follow_links) |
8de3a6e2 NC |
10043 | /* The other debug links will be displayed by display_debug_links() |
10044 | so we do not need to do any further processing here. */ | |
dda8d76d NC |
10045 | return NULL; |
10046 | ||
10047 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
10048 | /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */ | |
10049 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ | |
d85bf2ba | 10050 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 10051 | |
dda8d76d NC |
10052 | if (load_debug_section (gnu_debugaltlink, file)) |
10053 | { | |
10054 | Build_id_data * build_id_data; | |
10055 | ||
10056 | return load_separate_debug_info (filename, | |
10057 | & debug_displays[gnu_debugaltlink].section, | |
10058 | parse_gnu_debugaltlink, | |
10059 | check_gnu_debugaltlink, | |
10060 | & build_id_data); | |
10061 | } | |
10062 | ||
10063 | if (load_debug_section (gnu_debuglink, file)) | |
10064 | { | |
10065 | unsigned long crc32; | |
10066 | ||
10067 | return load_separate_debug_info (filename, | |
10068 | & debug_displays[gnu_debuglink].section, | |
10069 | parse_gnu_debuglink, | |
10070 | check_gnu_debuglink, | |
10071 | & crc32); | |
10072 | } | |
10073 | ||
10074 | do_follow_links = 0; | |
10075 | return NULL; | |
10076 | } | |
10077 | ||
19e6b90e L |
10078 | void |
10079 | free_debug_memory (void) | |
10080 | { | |
3f5e193b | 10081 | unsigned int i; |
19e6b90e L |
10082 | |
10083 | free_abbrevs (); | |
10084 | ||
10085 | for (i = 0; i < max; i++) | |
3f5e193b | 10086 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 10087 | |
cc86f28f | 10088 | if (debug_information != NULL) |
19e6b90e | 10089 | { |
cc86f28f | 10090 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 10091 | { |
cc86f28f | 10092 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 10093 | { |
cc86f28f NC |
10094 | if (!debug_information [i].max_loc_offsets) |
10095 | { | |
10096 | free (debug_information [i].loc_offsets); | |
10097 | free (debug_information [i].have_frame_base); | |
10098 | } | |
10099 | if (!debug_information [i].max_range_lists) | |
10100 | free (debug_information [i].range_lists); | |
19e6b90e | 10101 | } |
19e6b90e L |
10102 | } |
10103 | free (debug_information); | |
10104 | debug_information = NULL; | |
82b1b41b | 10105 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 10106 | } |
dda8d76d NC |
10107 | |
10108 | if (separate_debug_file != NULL) | |
10109 | { | |
10110 | close_debug_file (separate_debug_file); | |
10111 | separate_debug_file = NULL; | |
10112 | ||
10113 | free ((void *) separate_debug_filename); | |
10114 | separate_debug_filename = NULL; | |
10115 | } | |
19e6b90e L |
10116 | } |
10117 | ||
4cb93e3b TG |
10118 | void |
10119 | dwarf_select_sections_by_names (const char *names) | |
10120 | { | |
10121 | typedef struct | |
10122 | { | |
10123 | const char * option; | |
10124 | int * variable; | |
f9f0e732 | 10125 | int val; |
4cb93e3b TG |
10126 | } |
10127 | debug_dump_long_opts; | |
10128 | ||
10129 | static const debug_dump_long_opts opts_table [] = | |
10130 | { | |
10131 | /* Please keep this table alpha- sorted. */ | |
10132 | { "Ranges", & do_debug_ranges, 1 }, | |
10133 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 10134 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 10135 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
10136 | { "cu_index", & do_debug_cu_index, 1 }, |
10137 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 10138 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
10139 | { "frames", & do_debug_frames, 1 }, |
10140 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
10141 | /* The special .gdb_index section. */ |
10142 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
10143 | { "info", & do_debug_info, 1 }, |
10144 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 10145 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
10146 | { "loc", & do_debug_loc, 1 }, |
10147 | { "macro", & do_debug_macinfo, 1 }, | |
10148 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 10149 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 10150 | /* This entry is for compatibility |
4cb93e3b TG |
10151 | with earlier versions of readelf. */ |
10152 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 10153 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 10154 | { "str", & do_debug_str, 1 }, |
6f875884 TG |
10155 | /* These trace_* sections are used by Itanium VMS. */ |
10156 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
10157 | { "trace_aranges", & do_trace_aranges, 1 }, | |
10158 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
10159 | { NULL, NULL, 0 } |
10160 | }; | |
10161 | ||
10162 | const char *p; | |
467c65bc | 10163 | |
4cb93e3b TG |
10164 | p = names; |
10165 | while (*p) | |
10166 | { | |
10167 | const debug_dump_long_opts * entry; | |
467c65bc | 10168 | |
4cb93e3b TG |
10169 | for (entry = opts_table; entry->option; entry++) |
10170 | { | |
10171 | size_t len = strlen (entry->option); | |
467c65bc | 10172 | |
4cb93e3b TG |
10173 | if (strncmp (p, entry->option, len) == 0 |
10174 | && (p[len] == ',' || p[len] == '\0')) | |
10175 | { | |
10176 | * entry->variable |= entry->val; | |
467c65bc | 10177 | |
4cb93e3b TG |
10178 | /* The --debug-dump=frames-interp option also |
10179 | enables the --debug-dump=frames option. */ | |
10180 | if (do_debug_frames_interp) | |
10181 | do_debug_frames = 1; | |
10182 | ||
10183 | p += len; | |
10184 | break; | |
10185 | } | |
10186 | } | |
467c65bc | 10187 | |
4cb93e3b TG |
10188 | if (entry->option == NULL) |
10189 | { | |
10190 | warn (_("Unrecognized debug option '%s'\n"), p); | |
10191 | p = strchr (p, ','); | |
10192 | if (p == NULL) | |
10193 | break; | |
10194 | } | |
467c65bc | 10195 | |
4cb93e3b TG |
10196 | if (*p == ',') |
10197 | p++; | |
10198 | } | |
10199 | } | |
10200 | ||
10201 | void | |
10202 | dwarf_select_sections_by_letters (const char *letters) | |
10203 | { | |
91d6fa6a | 10204 | unsigned int lindex = 0; |
4cb93e3b | 10205 | |
91d6fa6a NC |
10206 | while (letters[lindex]) |
10207 | switch (letters[lindex++]) | |
4cb93e3b | 10208 | { |
dda8d76d NC |
10209 | case 'A': do_debug_addr = 1; break; |
10210 | case 'a': do_debug_abbrevs = 1; break; | |
10211 | case 'c': do_debug_cu_index = 1; break; | |
10212 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
10213 | case 'f': do_debug_frames = 1; break; | |
10214 | case 'g': do_gdb_index = 1; break; | |
10215 | case 'i': do_debug_info = 1; break; | |
10216 | case 'K': do_follow_links = 1; break; | |
10217 | case 'k': do_debug_links = 1; break; | |
10218 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
10219 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
10220 | case 'm': do_debug_macinfo = 1; break; | |
10221 | case 'o': do_debug_loc = 1; break; | |
10222 | case 'p': do_debug_pubnames = 1; break; | |
10223 | case 'R': do_debug_ranges = 1; break; | |
10224 | case 'r': do_debug_aranges = 1; break; | |
10225 | case 's': do_debug_str = 1; break; | |
10226 | case 'T': do_trace_aranges = 1; break; | |
10227 | case 't': do_debug_pubtypes = 1; break; | |
10228 | case 'U': do_trace_info = 1; break; | |
10229 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 10230 | |
4cb93e3b | 10231 | default: |
7cc78d07 | 10232 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
10233 | break; |
10234 | } | |
10235 | } | |
10236 | ||
10237 | void | |
10238 | dwarf_select_sections_all (void) | |
10239 | { | |
10240 | do_debug_info = 1; | |
10241 | do_debug_abbrevs = 1; | |
10242 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
10243 | do_debug_pubnames = 1; | |
f9f0e732 | 10244 | do_debug_pubtypes = 1; |
4cb93e3b TG |
10245 | do_debug_aranges = 1; |
10246 | do_debug_ranges = 1; | |
10247 | do_debug_frames = 1; | |
10248 | do_debug_macinfo = 1; | |
10249 | do_debug_str = 1; | |
10250 | do_debug_loc = 1; | |
5bbdf3d5 | 10251 | do_gdb_index = 1; |
6f875884 TG |
10252 | do_trace_info = 1; |
10253 | do_trace_abbrevs = 1; | |
10254 | do_trace_aranges = 1; | |
657d0d47 CC |
10255 | do_debug_addr = 1; |
10256 | do_debug_cu_index = 1; | |
dda8d76d NC |
10257 | do_follow_links = 1; |
10258 | do_debug_links = 1; | |
4cb93e3b TG |
10259 | } |
10260 | ||
dda8d76d NC |
10261 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
10262 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL | |
10263 | ||
10264 | /* N.B. The order here must match the order in section_display_enum. */ | |
10265 | ||
19e6b90e L |
10266 | struct dwarf_section_display debug_displays[] = |
10267 | { | |
dda8d76d NC |
10268 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
10269 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
10270 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10271 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
10272 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10273 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
10274 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
10275 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10276 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10277 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10278 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10279 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10280 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10281 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10282 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
10283 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
10284 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10285 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10286 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10287 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10288 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
10289 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10290 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
10291 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
10292 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
10293 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
10294 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
10295 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
10296 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
10297 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
10298 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10299 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10300 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10301 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10302 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
10303 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10304 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10305 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, | |
10306 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10307 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10308 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10309 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10310 | /* Separate debug info files can containt their own .debug_str section, | |
10311 | and this might be in *addition* to a .debug_str section already present | |
10312 | in the main file. Hence we need to have two entries for .debug_str. */ | |
10313 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 10314 | }; |
b451e98a JK |
10315 | |
10316 | /* A static assertion. */ | |
10317 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |