Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
2571583a | 2 | Copyright (C) 2005-2017 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" |
61364358 JK |
31 | #include <assert.h> |
32 | ||
33 | #undef MAX | |
34 | #undef MIN | |
35 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
36 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
19e6b90e | 37 | |
18464d4d JK |
38 | static const char *regname (unsigned int regno, int row); |
39 | ||
19e6b90e L |
40 | static int have_frame_base; |
41 | static int need_base_address; | |
42 | ||
19e6b90e | 43 | static unsigned int num_debug_info_entries = 0; |
82b1b41b | 44 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 45 | static debug_info *debug_information = NULL; |
cc86f28f NC |
46 | /* Special value for num_debug_info_entries to indicate |
47 | that the .debug_info section could not be loaded/parsed. */ | |
48 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 49 | |
77ef8654 | 50 | unsigned int eh_addr_size; |
19e6b90e L |
51 | |
52 | int do_debug_info; | |
53 | int do_debug_abbrevs; | |
54 | int do_debug_lines; | |
55 | int do_debug_pubnames; | |
f9f0e732 | 56 | int do_debug_pubtypes; |
19e6b90e L |
57 | int do_debug_aranges; |
58 | int do_debug_ranges; | |
59 | int do_debug_frames; | |
60 | int do_debug_frames_interp; | |
61 | int do_debug_macinfo; | |
62 | int do_debug_str; | |
63 | int do_debug_loc; | |
5bbdf3d5 | 64 | int do_gdb_index; |
6f875884 TG |
65 | int do_trace_info; |
66 | int do_trace_abbrevs; | |
67 | int do_trace_aranges; | |
657d0d47 CC |
68 | int do_debug_addr; |
69 | int do_debug_cu_index; | |
a262ae96 | 70 | int do_wide; |
19e6b90e | 71 | |
fd2f0033 TT |
72 | int dwarf_cutoff_level = -1; |
73 | unsigned long dwarf_start_die; | |
74 | ||
4723351a CC |
75 | int dwarf_check = 0; |
76 | ||
9f272209 AO |
77 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
78 | testing whether e.g. a locview list is present. */ | |
79 | static const dwarf_vma vm1 = -1; | |
80 | ||
341f9135 CC |
81 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
82 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
83 | as a zero-terminated list of section indexes comprising one set of debug | |
84 | sections from a .dwo file. */ | |
85 | ||
341f9135 CC |
86 | static unsigned int *shndx_pool = NULL; |
87 | static unsigned int shndx_pool_size = 0; | |
88 | static unsigned int shndx_pool_used = 0; | |
89 | ||
90 | /* For version 2 package files, each set contains an array of section offsets | |
91 | and an array of section sizes, giving the offset and size of the | |
92 | contribution from a CU or TU within one of the debug sections. | |
93 | When displaying debug info from a package file, we need to use these | |
94 | tables to locate the corresponding contributions to each section. */ | |
95 | ||
96 | struct cu_tu_set | |
97 | { | |
98 | uint64_t signature; | |
99 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
100 | size_t section_sizes[DW_SECT_MAX]; | |
101 | }; | |
102 | ||
103 | static int cu_count = 0; | |
104 | static int tu_count = 0; | |
105 | static struct cu_tu_set *cu_sets = NULL; | |
106 | static struct cu_tu_set *tu_sets = NULL; | |
107 | ||
43a444f9 | 108 | static bfd_boolean load_cu_tu_indexes (void *); |
341f9135 | 109 | |
4cb93e3b TG |
110 | /* Values for do_debug_lines. */ |
111 | #define FLAG_DEBUG_LINES_RAW 1 | |
112 | #define FLAG_DEBUG_LINES_DECODED 2 | |
113 | ||
77ef8654 | 114 | static unsigned int |
f1c4cc75 RH |
115 | size_of_encoded_value (int encoding) |
116 | { | |
117 | switch (encoding & 0x7) | |
118 | { | |
119 | default: /* ??? */ | |
120 | case 0: return eh_addr_size; | |
121 | case 2: return 2; | |
122 | case 3: return 4; | |
123 | case 4: return 8; | |
124 | } | |
125 | } | |
126 | ||
127 | static dwarf_vma | |
041830e0 | 128 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 129 | int encoding, |
041830e0 NC |
130 | struct dwarf_section *section, |
131 | unsigned char * end) | |
f1c4cc75 | 132 | { |
041830e0 | 133 | unsigned char * data = * pdata; |
6937bb54 | 134 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 135 | dwarf_vma val; |
f1c4cc75 | 136 | |
041830e0 NC |
137 | if (data + size >= end) |
138 | { | |
139 | warn (_("Encoded value extends past end of section\n")); | |
140 | * pdata = end; | |
141 | return 0; | |
142 | } | |
143 | ||
6937bb54 NC |
144 | /* PR 17512: file: 002-829853-0.004. */ |
145 | if (size > 8) | |
146 | { | |
147 | warn (_("Encoded size of %d is too large to read\n"), size); | |
148 | * pdata = end; | |
149 | return 0; | |
150 | } | |
151 | ||
0a9d414a NC |
152 | /* PR 17512: file: 1085-5603-0.004. */ |
153 | if (size == 0) | |
154 | { | |
155 | warn (_("Encoded size of 0 is too small to read\n")); | |
156 | * pdata = end; | |
157 | return 0; | |
158 | } | |
159 | ||
f1c4cc75 | 160 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 161 | val = byte_get_signed (data, size); |
f1c4cc75 | 162 | else |
bad62cf5 AM |
163 | val = byte_get (data, size); |
164 | ||
165 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
166 | val += section->address + (data - section->start); | |
041830e0 NC |
167 | |
168 | * pdata = data + size; | |
bad62cf5 | 169 | return val; |
f1c4cc75 RH |
170 | } |
171 | ||
4c219c2e AM |
172 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
173 | # ifndef __MINGW32__ | |
174 | # define DWARF_VMA_FMT "ll" | |
175 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
176 | # else | |
177 | # define DWARF_VMA_FMT "I64" | |
178 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
179 | # endif | |
2e14fae2 | 180 | #else |
4c219c2e AM |
181 | # define DWARF_VMA_FMT "l" |
182 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
183 | #endif |
184 | ||
bf5117e3 NC |
185 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
186 | buffer containing the converted VALUE. The value is converted according | |
187 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
188 | it specifies the maximum number of bytes to be displayed in the converted | |
189 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 190 | |
47704ddf | 191 | static const char * |
bf5117e3 | 192 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
193 | { |
194 | /* As dwarf_vmatoa is used more then once in a printf call | |
195 | for output, we are cycling through an fixed array of pointers | |
196 | for return address. */ | |
197 | static int buf_pos = 0; | |
467c65bc NC |
198 | static struct dwarf_vmatoa_buf |
199 | { | |
47704ddf KT |
200 | char place[64]; |
201 | } buf[16]; | |
47704ddf KT |
202 | char *ret; |
203 | ||
47704ddf | 204 | ret = buf[buf_pos++].place; |
467c65bc | 205 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 206 | |
bf5117e3 NC |
207 | if (num_bytes) |
208 | { | |
222c2bf0 | 209 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
210 | integer value, so we print the full value into a buffer and then select |
211 | the precision we need. */ | |
212 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
213 | if (num_bytes > 8) | |
214 | num_bytes = 8; | |
215 | return ret + (16 - 2 * num_bytes); | |
216 | } | |
217 | else | |
218 | { | |
219 | char fmt[32]; | |
220 | ||
0bae9e9e NC |
221 | if (fmtch) |
222 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
223 | else | |
224 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
225 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
226 | return ret; | |
227 | } | |
228 | } | |
47704ddf | 229 | |
bf5117e3 NC |
230 | static inline const char * |
231 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
232 | { | |
233 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
234 | } | |
235 | ||
236 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
237 | hexadecimal format, followed by a space. The length of the VALUE (and | |
238 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
239 | ||
240 | static void | |
241 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
242 | { | |
243 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
244 | } |
245 | ||
9f272209 AO |
246 | /* Print a view number in hexadecimal value, with the same width |
247 | print_dwarf_vma would have printed it with the same num_bytes. | |
248 | Print blanks for zero view, unless force is nonzero. */ | |
249 | ||
250 | static void | |
251 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
252 | { | |
253 | int len; | |
254 | if (!num_bytes) | |
255 | len = 4; | |
256 | else | |
257 | len = num_bytes * 2; | |
258 | ||
259 | assert (value == (unsigned long) value); | |
260 | if (value || force) | |
261 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
262 | else | |
263 | printf ("%*s", len + 1, ""); | |
264 | } | |
265 | ||
74bc6052 CC |
266 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
267 | For reentrancy, this uses a buffer provided by the caller. */ | |
268 | ||
269 | static const char * | |
270 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
271 | unsigned int buf_len) | |
272 | { | |
273 | int len = 0; | |
274 | ||
275 | if (hvalue == 0) | |
276 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
277 | else | |
278 | { | |
279 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
280 | snprintf (buf + len, buf_len - len, | |
281 | "%08" DWARF_VMA_FMT "x", lvalue); | |
282 | } | |
283 | ||
284 | return buf; | |
285 | } | |
286 | ||
f6f0e17b NC |
287 | /* Read in a LEB128 encoded value starting at address DATA. |
288 | If SIGN is true, return a signed LEB128 value. | |
289 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
290 | No bytes will be read at address END or beyond. */ | |
291 | ||
467c65bc | 292 | dwarf_vma |
f6f0e17b NC |
293 | read_leb128 (unsigned char *data, |
294 | unsigned int *length_return, | |
295 | bfd_boolean sign, | |
296 | const unsigned char * const end) | |
19e6b90e | 297 | { |
467c65bc | 298 | dwarf_vma result = 0; |
19e6b90e L |
299 | unsigned int num_read = 0; |
300 | unsigned int shift = 0; | |
f6f0e17b | 301 | unsigned char byte = 0; |
19e6b90e | 302 | |
f6f0e17b | 303 | while (data < end) |
19e6b90e L |
304 | { |
305 | byte = *data++; | |
306 | num_read++; | |
307 | ||
467c65bc | 308 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
19e6b90e L |
309 | |
310 | shift += 7; | |
f6f0e17b NC |
311 | if ((byte & 0x80) == 0) |
312 | break; | |
77ef8654 NC |
313 | |
314 | /* PR 17512: file: 0ca183b8. | |
315 | FIXME: Should we signal this error somehow ? */ | |
f641dd96 | 316 | if (shift >= sizeof (result) * 8) |
77ef8654 | 317 | break; |
19e6b90e | 318 | } |
19e6b90e L |
319 | |
320 | if (length_return != NULL) | |
321 | *length_return = num_read; | |
322 | ||
323 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
c4e0beac | 324 | result |= -((dwarf_vma) 1 << shift); |
19e6b90e L |
325 | |
326 | return result; | |
327 | } | |
328 | ||
467c65bc | 329 | /* Create a signed version to avoid painful typecasts. */ |
f6f0e17b NC |
330 | static inline dwarf_signed_vma |
331 | read_sleb128 (unsigned char * data, | |
332 | unsigned int * length_return, | |
333 | const unsigned char * const end) | |
334 | { | |
335 | return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end); | |
336 | } | |
337 | ||
338 | static inline dwarf_vma | |
339 | read_uleb128 (unsigned char * data, | |
340 | unsigned int * length_return, | |
341 | const unsigned char * const end) | |
467c65bc | 342 | { |
f6f0e17b | 343 | return read_leb128 (data, length_return, FALSE, end); |
467c65bc NC |
344 | } |
345 | ||
7f2c8a1d NC |
346 | #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return |
347 | #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return | |
348 | ||
349 | #define READ_ULEB(var) \ | |
350 | do \ | |
351 | { \ | |
352 | dwarf_vma _val; \ | |
353 | \ | |
354 | (var) = _val = read_uleb128 (start, &length_return, end); \ | |
355 | if ((var) != _val) \ | |
19474787 | 356 | error (_("Internal error: %s%d: LEB value (%#" DWARF_VMA_FMT "x) too large for containing variable\n"), \ |
7f2c8a1d NC |
357 | __FILE__, __LINE__, _val); \ |
358 | start += length_return; \ | |
359 | } \ | |
360 | while (0) | |
361 | ||
362 | #define READ_SLEB(var) \ | |
363 | do \ | |
364 | { \ | |
365 | dwarf_signed_vma _val; \ | |
366 | \ | |
367 | (var) = _val = read_sleb128 (start, &length_return, end); \ | |
368 | if ((var) != _val) \ | |
19474787 | 369 | error (_("Internal error: %s%d: LEB value (%#" DWARF_VMA_FMT "x) too large for containing variable\n"), \ |
7f2c8a1d NC |
370 | __FILE__, __LINE__, _val); \ |
371 | start += length_return; \ | |
372 | } \ | |
373 | while (0) | |
374 | ||
0c588247 NC |
375 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
376 | do \ | |
377 | { \ | |
378 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
379 | if (sizeof (VAL) < amount) \ |
380 | { \ | |
381 | error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\ | |
382 | amount, (int) sizeof (VAL)); \ | |
383 | amount = sizeof (VAL); \ | |
384 | } \ | |
0c588247 NC |
385 | if (((PTR) + amount) >= (END)) \ |
386 | { \ | |
387 | if ((PTR) < (END)) \ | |
388 | amount = (END) - (PTR); \ | |
389 | else \ | |
390 | amount = 0; \ | |
391 | } \ | |
6937bb54 | 392 | if (amount == 0 || amount > 8) \ |
0c588247 | 393 | VAL = 0; \ |
6937bb54 NC |
394 | else \ |
395 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
396 | } \ |
397 | while (0) | |
398 | ||
399 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ | |
400 | do \ | |
401 | { \ | |
402 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
403 | PTR += AMOUNT; \ | |
404 | } \ | |
405 | while (0) | |
406 | ||
407 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ | |
408 | do \ | |
409 | { \ | |
410 | unsigned int amount = (AMOUNT); \ | |
411 | if (((PTR) + amount) >= (END)) \ | |
412 | { \ | |
413 | if ((PTR) < (END)) \ | |
414 | amount = (END) - (PTR); \ | |
415 | else \ | |
416 | amount = 0; \ | |
417 | } \ | |
418 | if (amount) \ | |
419 | VAL = byte_get_signed ((PTR), amount); \ | |
420 | else \ | |
421 | VAL = 0; \ | |
422 | } \ | |
423 | while (0) | |
424 | ||
425 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ | |
426 | do \ | |
427 | { \ | |
428 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
429 | PTR += AMOUNT; \ | |
430 | } \ | |
431 | while (0) | |
432 | ||
433 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
434 | do \ | |
435 | { \ | |
87bc83b3 | 436 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
437 | { \ |
438 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
439 | } \ | |
440 | else \ | |
441 | { \ | |
0c588247 NC |
442 | * (LOW) = * (HIGH) = 0; \ |
443 | } \ | |
444 | } \ | |
445 | while (0) | |
446 | ||
19e6b90e L |
447 | typedef struct State_Machine_Registers |
448 | { | |
467c65bc | 449 | dwarf_vma address; |
ba8826a8 | 450 | unsigned int view; |
19e6b90e L |
451 | unsigned int file; |
452 | unsigned int line; | |
453 | unsigned int column; | |
454 | int is_stmt; | |
455 | int basic_block; | |
a233b20c JJ |
456 | unsigned char op_index; |
457 | unsigned char end_sequence; | |
ba8826a8 AO |
458 | /* This variable hold the number of the last entry seen |
459 | in the File Table. */ | |
19e6b90e L |
460 | unsigned int last_file_entry; |
461 | } SMR; | |
462 | ||
463 | static SMR state_machine_regs; | |
464 | ||
465 | static void | |
466 | reset_state_machine (int is_stmt) | |
467 | { | |
468 | state_machine_regs.address = 0; | |
ba8826a8 | 469 | state_machine_regs.view = 0; |
a233b20c | 470 | state_machine_regs.op_index = 0; |
19e6b90e L |
471 | state_machine_regs.file = 1; |
472 | state_machine_regs.line = 1; | |
473 | state_machine_regs.column = 0; | |
474 | state_machine_regs.is_stmt = is_stmt; | |
475 | state_machine_regs.basic_block = 0; | |
476 | state_machine_regs.end_sequence = 0; | |
477 | state_machine_regs.last_file_entry = 0; | |
478 | } | |
479 | ||
480 | /* Handled an extend line op. | |
481 | Returns the number of bytes read. */ | |
482 | ||
483 | static int | |
f6f0e17b NC |
484 | process_extended_line_op (unsigned char * data, |
485 | int is_stmt, | |
486 | unsigned char * end) | |
19e6b90e L |
487 | { |
488 | unsigned char op_code; | |
489 | unsigned int bytes_read; | |
490 | unsigned int len; | |
491 | unsigned char *name; | |
143a3db0 | 492 | unsigned char *orig_data = data; |
f6f0e17b | 493 | dwarf_vma adr; |
19e6b90e | 494 | |
f6f0e17b | 495 | len = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
496 | data += bytes_read; |
497 | ||
e44c58ce | 498 | if (len == 0 || data == end || len > (uintptr_t) (end - data)) |
19e6b90e | 499 | { |
f41e4712 | 500 | warn (_("Badly formed extended line op encountered!\n")); |
19e6b90e L |
501 | return bytes_read; |
502 | } | |
503 | ||
504 | len += bytes_read; | |
505 | op_code = *data++; | |
506 | ||
507 | printf (_(" Extended opcode %d: "), op_code); | |
508 | ||
509 | switch (op_code) | |
510 | { | |
511 | case DW_LNE_end_sequence: | |
512 | printf (_("End of Sequence\n\n")); | |
513 | reset_state_machine (is_stmt); | |
514 | break; | |
515 | ||
516 | case DW_LNE_set_address: | |
6937bb54 NC |
517 | /* PR 17512: file: 002-100480-0.004. */ |
518 | if (len - bytes_read - 1 > 8) | |
77ef8654 NC |
519 | { |
520 | warn (_("Length (%d) of DW_LNE_set_address op is too long\n"), | |
521 | len - bytes_read - 1); | |
522 | adr = 0; | |
523 | } | |
524 | else | |
525 | SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end); | |
47704ddf | 526 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 527 | state_machine_regs.address = adr; |
ba8826a8 | 528 | state_machine_regs.view = 0; |
a233b20c | 529 | state_machine_regs.op_index = 0; |
19e6b90e L |
530 | break; |
531 | ||
532 | case DW_LNE_define_file: | |
143a3db0 | 533 | printf (_("define new File Table entry\n")); |
19e6b90e | 534 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 535 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 536 | |
d949ff56 NC |
537 | { |
538 | size_t l; | |
539 | ||
540 | name = data; | |
541 | l = strnlen ((char *) data, end - data); | |
542 | data += len + 1; | |
543 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
544 | data += bytes_read; | |
545 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
546 | data += bytes_read; | |
547 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
548 | data += bytes_read; | |
549 | printf ("%.*s\n\n", (int) l, name); | |
550 | } | |
f6f0e17b NC |
551 | |
552 | if (((unsigned int) (data - orig_data) != len) || data == end) | |
b4eb7656 | 553 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
554 | break; |
555 | ||
ed4a4bdf | 556 | case DW_LNE_set_discriminator: |
47704ddf | 557 | printf (_("set Discriminator to %s\n"), |
f6f0e17b | 558 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
ed4a4bdf CC |
559 | break; |
560 | ||
e2a0d921 NC |
561 | /* HP extensions. */ |
562 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 563 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
564 | break; |
565 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 566 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
567 | break; |
568 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 569 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
570 | break; |
571 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 572 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
573 | break; |
574 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 575 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
576 | break; |
577 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 578 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
579 | break; |
580 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 581 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
582 | break; |
583 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 584 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
585 | break; |
586 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 587 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
588 | break; |
589 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 590 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 591 | break; |
43294ab7 TG |
592 | case DW_LNE_HP_source_file_correlation: |
593 | { | |
b4eb7656 AM |
594 | unsigned char *edata = data + len - bytes_read - 1; |
595 | ||
596 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
597 | ||
598 | while (data < edata) | |
599 | { | |
600 | unsigned int opc; | |
601 | ||
602 | opc = read_uleb128 (data, & bytes_read, edata); | |
603 | data += bytes_read; | |
604 | ||
605 | switch (opc) | |
606 | { | |
607 | case DW_LNE_HP_SFC_formfeed: | |
608 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
609 | break; | |
610 | case DW_LNE_HP_SFC_set_listing_line: | |
611 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", | |
612 | dwarf_vmatoa ("u", | |
613 | read_uleb128 (data, & bytes_read, edata))); | |
614 | data += bytes_read; | |
615 | break; | |
616 | case DW_LNE_HP_SFC_associate: | |
617 | printf (" DW_LNE_HP_SFC_associate "); | |
618 | printf ("(%s", | |
619 | dwarf_vmatoa ("u", | |
620 | read_uleb128 (data, & bytes_read, edata))); | |
621 | data += bytes_read; | |
622 | printf (",%s", | |
623 | dwarf_vmatoa ("u", | |
624 | read_uleb128 (data, & bytes_read, edata))); | |
625 | data += bytes_read; | |
626 | printf (",%s)\n", | |
627 | dwarf_vmatoa ("u", | |
628 | read_uleb128 (data, & bytes_read, edata))); | |
629 | data += bytes_read; | |
630 | break; | |
631 | default: | |
632 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
633 | data = edata; | |
634 | break; | |
635 | } | |
636 | } | |
43294ab7 TG |
637 | } |
638 | break; | |
cecf136e | 639 | |
19e6b90e | 640 | default: |
7e665af3 | 641 | { |
b4eb7656 AM |
642 | unsigned int rlen = len - bytes_read - 1; |
643 | ||
644 | if (op_code >= DW_LNE_lo_user | |
645 | /* The test against DW_LNW_hi_user is redundant due to | |
646 | the limited range of the unsigned char data type used | |
647 | for op_code. */ | |
648 | /*&& op_code <= DW_LNE_hi_user*/) | |
649 | printf (_("user defined: ")); | |
650 | else | |
651 | printf (_("UNKNOWN: ")); | |
652 | printf (_("length %d ["), rlen); | |
653 | for (; rlen; rlen--) | |
654 | printf (" %02x", *data++); | |
655 | printf ("]\n"); | |
7e665af3 | 656 | } |
19e6b90e L |
657 | break; |
658 | } | |
659 | ||
660 | return len; | |
661 | } | |
662 | ||
0c588247 | 663 | static const unsigned char * |
467c65bc | 664 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
665 | { |
666 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 667 | const unsigned char * ret; |
19e6b90e L |
668 | |
669 | if (section->start == NULL) | |
0c588247 | 670 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 671 | |
d949ff56 | 672 | if (offset >= section->size) |
19e6b90e | 673 | { |
467c65bc NC |
674 | warn (_("DW_FORM_strp offset too big: %s\n"), |
675 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 676 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
677 | } |
678 | ||
d949ff56 NC |
679 | ret = section->start + offset; |
680 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
681 | NUL byte. Since our caller is expecting to receive a well formed C | |
682 | string we test for the lack of a terminating byte here. */ | |
683 | if (strnlen ((const char *) ret, section->size - offset) | |
684 | == section->size - offset) | |
685 | ret = (const unsigned char *) | |
686 | _("<no NUL byte at end of .debug_str section>"); | |
687 | ||
688 | return ret; | |
19e6b90e L |
689 | } |
690 | ||
77145576 JK |
691 | static const unsigned char * |
692 | fetch_indirect_line_string (dwarf_vma offset) | |
693 | { | |
694 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 695 | const unsigned char * ret; |
77145576 JK |
696 | |
697 | if (section->start == NULL) | |
698 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
699 | ||
d949ff56 | 700 | if (offset >= section->size) |
77145576 JK |
701 | { |
702 | warn (_("DW_FORM_line_strp offset too big: %s\n"), | |
703 | dwarf_vmatoa ("x", offset)); | |
704 | return (const unsigned char *) _("<offset is too big>"); | |
705 | } | |
706 | ||
d949ff56 NC |
707 | ret = section->start + offset; |
708 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
709 | with a NUL byte. Since our caller is expecting to receive a well formed | |
710 | C string we test for the lack of a terminating byte here. */ | |
711 | if (strnlen ((const char *) ret, section->size - offset) | |
712 | == section->size - offset) | |
713 | ret = (const unsigned char *) | |
714 | _("<no NUL byte at end of .debug_line_str section>"); | |
715 | ||
716 | return ret; | |
77145576 JK |
717 | } |
718 | ||
4723351a | 719 | static const char * |
341f9135 CC |
720 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
721 | dwarf_vma offset_size, int dwo) | |
4723351a CC |
722 | { |
723 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
724 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
725 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
726 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
727 | dwarf_vma index_offset = idx * offset_size; | |
728 | dwarf_vma str_offset; | |
d949ff56 | 729 | const char * ret; |
4723351a CC |
730 | |
731 | if (index_section->start == NULL) | |
732 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
733 | : _("<no .debug_str_offsets section>")); | |
734 | ||
341f9135 CC |
735 | if (this_set != NULL) |
736 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
d949ff56 | 737 | if (index_offset >= index_section->size) |
4723351a CC |
738 | { |
739 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), | |
740 | dwarf_vmatoa ("x", index_offset)); | |
741 | return _("<index offset is too big>"); | |
742 | } | |
743 | ||
744 | if (str_section->start == NULL) | |
745 | return (dwo ? _("<no .debug_str.dwo section>") | |
746 | : _("<no .debug_str section>")); | |
747 | ||
748 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
749 | str_offset -= str_section->address; | |
d949ff56 | 750 | if (str_offset >= str_section->size) |
4723351a CC |
751 | { |
752 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
753 | dwarf_vmatoa ("x", str_offset)); | |
754 | return _("<indirect index offset is too big>"); | |
755 | } | |
756 | ||
d949ff56 NC |
757 | ret = (const char *) str_section->start + str_offset; |
758 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
759 | Since our caller is expecting to receive a well formed C string we test | |
760 | for the lack of a terminating byte here. */ | |
761 | if (strnlen (ret, str_section->size - str_offset) | |
762 | == str_section->size - str_offset) | |
763 | ret = (const char *) _("<no NUL byte at end of section>"); | |
764 | ||
765 | return ret; | |
4723351a CC |
766 | } |
767 | ||
768 | static const char * | |
769 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
770 | { | |
771 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
772 | ||
773 | if (section->start == NULL) | |
774 | return (_("<no .debug_addr section>")); | |
775 | ||
776 | if (offset + bytes > section->size) | |
777 | { | |
778 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 779 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
780 | return "<offset too big>"; |
781 | } | |
782 | ||
783 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
784 | } | |
785 | ||
786 | ||
19e6b90e L |
787 | /* FIXME: There are better and more efficient ways to handle |
788 | these structures. For now though, I just want something that | |
789 | is simple to implement. */ | |
790 | typedef struct abbrev_attr | |
791 | { | |
792 | unsigned long attribute; | |
793 | unsigned long form; | |
77145576 | 794 | bfd_signed_vma implicit_const; |
19e6b90e L |
795 | struct abbrev_attr *next; |
796 | } | |
797 | abbrev_attr; | |
798 | ||
799 | typedef struct abbrev_entry | |
800 | { | |
801 | unsigned long entry; | |
802 | unsigned long tag; | |
803 | int children; | |
804 | struct abbrev_attr *first_attr; | |
805 | struct abbrev_attr *last_attr; | |
806 | struct abbrev_entry *next; | |
807 | } | |
808 | abbrev_entry; | |
809 | ||
810 | static abbrev_entry *first_abbrev = NULL; | |
811 | static abbrev_entry *last_abbrev = NULL; | |
812 | ||
813 | static void | |
814 | free_abbrevs (void) | |
815 | { | |
91d6fa6a | 816 | abbrev_entry *abbrv; |
19e6b90e | 817 | |
91d6fa6a | 818 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 819 | { |
91d6fa6a | 820 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
821 | abbrev_attr *attr; |
822 | ||
91d6fa6a | 823 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 824 | { |
91d6fa6a | 825 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
826 | |
827 | free (attr); | |
91d6fa6a | 828 | attr = next_attr; |
19e6b90e L |
829 | } |
830 | ||
91d6fa6a NC |
831 | free (abbrv); |
832 | abbrv = next_abbrev; | |
19e6b90e L |
833 | } |
834 | ||
835 | last_abbrev = first_abbrev = NULL; | |
836 | } | |
837 | ||
838 | static void | |
839 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
840 | { | |
841 | abbrev_entry *entry; | |
842 | ||
3f5e193b | 843 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
844 | if (entry == NULL) |
845 | /* ugg */ | |
846 | return; | |
847 | ||
848 | entry->entry = number; | |
849 | entry->tag = tag; | |
850 | entry->children = children; | |
851 | entry->first_attr = NULL; | |
852 | entry->last_attr = NULL; | |
853 | entry->next = NULL; | |
854 | ||
855 | if (first_abbrev == NULL) | |
856 | first_abbrev = entry; | |
857 | else | |
858 | last_abbrev->next = entry; | |
859 | ||
860 | last_abbrev = entry; | |
861 | } | |
862 | ||
863 | static void | |
77145576 JK |
864 | add_abbrev_attr (unsigned long attribute, unsigned long form, |
865 | bfd_signed_vma implicit_const) | |
19e6b90e L |
866 | { |
867 | abbrev_attr *attr; | |
868 | ||
3f5e193b | 869 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
870 | if (attr == NULL) |
871 | /* ugg */ | |
872 | return; | |
873 | ||
874 | attr->attribute = attribute; | |
875 | attr->form = form; | |
77145576 | 876 | attr->implicit_const = implicit_const; |
19e6b90e L |
877 | attr->next = NULL; |
878 | ||
879 | if (last_abbrev->first_attr == NULL) | |
880 | last_abbrev->first_attr = attr; | |
881 | else | |
882 | last_abbrev->last_attr->next = attr; | |
883 | ||
884 | last_abbrev->last_attr = attr; | |
885 | } | |
886 | ||
887 | /* Processes the (partial) contents of a .debug_abbrev section. | |
888 | Returns NULL if the end of the section was encountered. | |
889 | Returns the address after the last byte read if the end of | |
890 | an abbreviation set was found. */ | |
891 | ||
892 | static unsigned char * | |
893 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
894 | { | |
895 | if (first_abbrev != NULL) | |
896 | return NULL; | |
897 | ||
898 | while (start < end) | |
899 | { | |
900 | unsigned int bytes_read; | |
901 | unsigned long entry; | |
902 | unsigned long tag; | |
903 | unsigned long attribute; | |
904 | int children; | |
905 | ||
f6f0e17b | 906 | entry = read_uleb128 (start, & bytes_read, end); |
19e6b90e L |
907 | start += bytes_read; |
908 | ||
909 | /* A single zero is supposed to end the section according | |
910 | to the standard. If there's more, then signal that to | |
911 | the caller. */ | |
f6f0e17b NC |
912 | if (start == end) |
913 | return NULL; | |
19e6b90e | 914 | if (entry == 0) |
f6f0e17b | 915 | return start; |
19e6b90e | 916 | |
f6f0e17b | 917 | tag = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 918 | start += bytes_read; |
f6f0e17b NC |
919 | if (start == end) |
920 | return NULL; | |
19e6b90e L |
921 | |
922 | children = *start++; | |
923 | ||
924 | add_abbrev (entry, tag, children); | |
925 | ||
926 | do | |
927 | { | |
928 | unsigned long form; | |
77145576 JK |
929 | /* Initialize it due to a false compiler warning. */ |
930 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 931 | |
f6f0e17b | 932 | attribute = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 933 | start += bytes_read; |
f6f0e17b NC |
934 | if (start == end) |
935 | break; | |
19e6b90e | 936 | |
f6f0e17b | 937 | form = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 938 | start += bytes_read; |
f6f0e17b NC |
939 | if (start == end) |
940 | break; | |
19e6b90e | 941 | |
77145576 JK |
942 | if (form == DW_FORM_implicit_const) |
943 | { | |
944 | implicit_const = read_sleb128 (start, & bytes_read, end); | |
945 | start += bytes_read; | |
946 | if (start == end) | |
947 | break; | |
948 | } | |
949 | ||
950 | add_abbrev_attr (attribute, form, implicit_const); | |
19e6b90e L |
951 | } |
952 | while (attribute != 0); | |
953 | } | |
954 | ||
399c99f7 L |
955 | /* Report the missing single zero which ends the section. */ |
956 | error (_(".debug_abbrev section not zero terminated\n")); | |
957 | ||
19e6b90e L |
958 | return NULL; |
959 | } | |
960 | ||
a19c41a7 | 961 | static const char * |
19e6b90e L |
962 | get_TAG_name (unsigned long tag) |
963 | { | |
b9c361e0 | 964 | const char *name = get_DW_TAG_name ((unsigned int)tag); |
a19c41a7 TT |
965 | |
966 | if (name == NULL) | |
19e6b90e | 967 | { |
a19c41a7 | 968 | static char buffer[100]; |
19e6b90e | 969 | |
a19c41a7 TT |
970 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag); |
971 | return buffer; | |
19e6b90e | 972 | } |
a19c41a7 TT |
973 | |
974 | return name; | |
19e6b90e L |
975 | } |
976 | ||
a19c41a7 | 977 | static const char * |
19e6b90e L |
978 | get_FORM_name (unsigned long form) |
979 | { | |
399c99f7 | 980 | const char *name; |
bf5117e3 | 981 | |
399c99f7 L |
982 | if (form == 0) |
983 | return "DW_FORM value: 0"; | |
a19c41a7 | 984 | |
399c99f7 | 985 | name = get_DW_FORM_name (form); |
a19c41a7 | 986 | if (name == NULL) |
19e6b90e | 987 | { |
a19c41a7 | 988 | static char buffer[100]; |
19e6b90e | 989 | |
a19c41a7 TT |
990 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
991 | return buffer; | |
19e6b90e | 992 | } |
a19c41a7 TT |
993 | |
994 | return name; | |
19e6b90e L |
995 | } |
996 | ||
61364358 JK |
997 | static const char * |
998 | get_IDX_name (unsigned long idx) | |
999 | { | |
1000 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1001 | ||
1002 | if (name == NULL) | |
1003 | { | |
1004 | static char buffer[100]; | |
1005 | ||
1006 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1007 | return buffer; | |
1008 | } | |
1009 | ||
1010 | return name; | |
1011 | } | |
1012 | ||
19e6b90e | 1013 | static unsigned char * |
0c588247 NC |
1014 | display_block (unsigned char *data, |
1015 | dwarf_vma length, | |
ef0b5f1c | 1016 | const unsigned char * const end, char delimiter) |
19e6b90e | 1017 | { |
0c588247 NC |
1018 | dwarf_vma maxlen; |
1019 | ||
ef0b5f1c | 1020 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1021 | if (data > end) |
1022 | return (unsigned char *) end; | |
19e6b90e | 1023 | |
0c588247 NC |
1024 | maxlen = (dwarf_vma) (end - data); |
1025 | length = length > maxlen ? maxlen : length; | |
1026 | ||
19e6b90e L |
1027 | while (length --) |
1028 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1029 | ||
1030 | return data; | |
1031 | } | |
1032 | ||
1033 | static int | |
1034 | decode_location_expression (unsigned char * data, | |
1035 | unsigned int pointer_size, | |
b7807392 JJ |
1036 | unsigned int offset_size, |
1037 | int dwarf_version, | |
467c65bc NC |
1038 | dwarf_vma length, |
1039 | dwarf_vma cu_offset, | |
f1c4cc75 | 1040 | struct dwarf_section * section) |
19e6b90e L |
1041 | { |
1042 | unsigned op; | |
1043 | unsigned int bytes_read; | |
467c65bc | 1044 | dwarf_vma uvalue; |
0c588247 | 1045 | dwarf_signed_vma svalue; |
19e6b90e L |
1046 | unsigned char *end = data + length; |
1047 | int need_frame_base = 0; | |
1048 | ||
1049 | while (data < end) | |
1050 | { | |
1051 | op = *data++; | |
1052 | ||
1053 | switch (op) | |
1054 | { | |
1055 | case DW_OP_addr: | |
0c588247 NC |
1056 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1057 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1058 | break; |
1059 | case DW_OP_deref: | |
1060 | printf ("DW_OP_deref"); | |
1061 | break; | |
1062 | case DW_OP_const1u: | |
0c588247 NC |
1063 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1064 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1065 | break; |
1066 | case DW_OP_const1s: | |
0c588247 NC |
1067 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1068 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1069 | break; |
1070 | case DW_OP_const2u: | |
87bc83b3 | 1071 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1072 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1073 | break; |
1074 | case DW_OP_const2s: | |
0c588247 NC |
1075 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1076 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1077 | break; |
1078 | case DW_OP_const4u: | |
0c588247 NC |
1079 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1080 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1081 | break; |
1082 | case DW_OP_const4s: | |
0c588247 NC |
1083 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1084 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1085 | break; |
1086 | case DW_OP_const8u: | |
0c588247 NC |
1087 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1088 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1089 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1090 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1091 | break; |
1092 | case DW_OP_const8s: | |
0c588247 NC |
1093 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1094 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1095 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1096 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1097 | break; |
1098 | case DW_OP_constu: | |
467c65bc | 1099 | printf ("DW_OP_constu: %s", |
f6f0e17b | 1100 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1101 | data += bytes_read; |
1102 | break; | |
1103 | case DW_OP_consts: | |
467c65bc | 1104 | printf ("DW_OP_consts: %s", |
f6f0e17b | 1105 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1106 | data += bytes_read; |
1107 | break; | |
1108 | case DW_OP_dup: | |
1109 | printf ("DW_OP_dup"); | |
1110 | break; | |
1111 | case DW_OP_drop: | |
1112 | printf ("DW_OP_drop"); | |
1113 | break; | |
1114 | case DW_OP_over: | |
1115 | printf ("DW_OP_over"); | |
1116 | break; | |
1117 | case DW_OP_pick: | |
0c588247 NC |
1118 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1119 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1120 | break; |
1121 | case DW_OP_swap: | |
1122 | printf ("DW_OP_swap"); | |
1123 | break; | |
1124 | case DW_OP_rot: | |
1125 | printf ("DW_OP_rot"); | |
1126 | break; | |
1127 | case DW_OP_xderef: | |
1128 | printf ("DW_OP_xderef"); | |
1129 | break; | |
1130 | case DW_OP_abs: | |
1131 | printf ("DW_OP_abs"); | |
1132 | break; | |
1133 | case DW_OP_and: | |
1134 | printf ("DW_OP_and"); | |
1135 | break; | |
1136 | case DW_OP_div: | |
1137 | printf ("DW_OP_div"); | |
1138 | break; | |
1139 | case DW_OP_minus: | |
1140 | printf ("DW_OP_minus"); | |
1141 | break; | |
1142 | case DW_OP_mod: | |
1143 | printf ("DW_OP_mod"); | |
1144 | break; | |
1145 | case DW_OP_mul: | |
1146 | printf ("DW_OP_mul"); | |
1147 | break; | |
1148 | case DW_OP_neg: | |
1149 | printf ("DW_OP_neg"); | |
1150 | break; | |
1151 | case DW_OP_not: | |
1152 | printf ("DW_OP_not"); | |
1153 | break; | |
1154 | case DW_OP_or: | |
1155 | printf ("DW_OP_or"); | |
1156 | break; | |
1157 | case DW_OP_plus: | |
1158 | printf ("DW_OP_plus"); | |
1159 | break; | |
1160 | case DW_OP_plus_uconst: | |
467c65bc | 1161 | printf ("DW_OP_plus_uconst: %s", |
f6f0e17b | 1162 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1163 | data += bytes_read; |
1164 | break; | |
1165 | case DW_OP_shl: | |
1166 | printf ("DW_OP_shl"); | |
1167 | break; | |
1168 | case DW_OP_shr: | |
1169 | printf ("DW_OP_shr"); | |
1170 | break; | |
1171 | case DW_OP_shra: | |
1172 | printf ("DW_OP_shra"); | |
1173 | break; | |
1174 | case DW_OP_xor: | |
1175 | printf ("DW_OP_xor"); | |
1176 | break; | |
1177 | case DW_OP_bra: | |
0c588247 NC |
1178 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1179 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1180 | break; |
1181 | case DW_OP_eq: | |
1182 | printf ("DW_OP_eq"); | |
1183 | break; | |
1184 | case DW_OP_ge: | |
1185 | printf ("DW_OP_ge"); | |
1186 | break; | |
1187 | case DW_OP_gt: | |
1188 | printf ("DW_OP_gt"); | |
1189 | break; | |
1190 | case DW_OP_le: | |
1191 | printf ("DW_OP_le"); | |
1192 | break; | |
1193 | case DW_OP_lt: | |
1194 | printf ("DW_OP_lt"); | |
1195 | break; | |
1196 | case DW_OP_ne: | |
1197 | printf ("DW_OP_ne"); | |
1198 | break; | |
1199 | case DW_OP_skip: | |
0c588247 NC |
1200 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1201 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1202 | break; |
1203 | ||
1204 | case DW_OP_lit0: | |
1205 | case DW_OP_lit1: | |
1206 | case DW_OP_lit2: | |
1207 | case DW_OP_lit3: | |
1208 | case DW_OP_lit4: | |
1209 | case DW_OP_lit5: | |
1210 | case DW_OP_lit6: | |
1211 | case DW_OP_lit7: | |
1212 | case DW_OP_lit8: | |
1213 | case DW_OP_lit9: | |
1214 | case DW_OP_lit10: | |
1215 | case DW_OP_lit11: | |
1216 | case DW_OP_lit12: | |
1217 | case DW_OP_lit13: | |
1218 | case DW_OP_lit14: | |
1219 | case DW_OP_lit15: | |
1220 | case DW_OP_lit16: | |
1221 | case DW_OP_lit17: | |
1222 | case DW_OP_lit18: | |
1223 | case DW_OP_lit19: | |
1224 | case DW_OP_lit20: | |
1225 | case DW_OP_lit21: | |
1226 | case DW_OP_lit22: | |
1227 | case DW_OP_lit23: | |
1228 | case DW_OP_lit24: | |
1229 | case DW_OP_lit25: | |
1230 | case DW_OP_lit26: | |
1231 | case DW_OP_lit27: | |
1232 | case DW_OP_lit28: | |
1233 | case DW_OP_lit29: | |
1234 | case DW_OP_lit30: | |
1235 | case DW_OP_lit31: | |
1236 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1237 | break; | |
1238 | ||
1239 | case DW_OP_reg0: | |
1240 | case DW_OP_reg1: | |
1241 | case DW_OP_reg2: | |
1242 | case DW_OP_reg3: | |
1243 | case DW_OP_reg4: | |
1244 | case DW_OP_reg5: | |
1245 | case DW_OP_reg6: | |
1246 | case DW_OP_reg7: | |
1247 | case DW_OP_reg8: | |
1248 | case DW_OP_reg9: | |
1249 | case DW_OP_reg10: | |
1250 | case DW_OP_reg11: | |
1251 | case DW_OP_reg12: | |
1252 | case DW_OP_reg13: | |
1253 | case DW_OP_reg14: | |
1254 | case DW_OP_reg15: | |
1255 | case DW_OP_reg16: | |
1256 | case DW_OP_reg17: | |
1257 | case DW_OP_reg18: | |
1258 | case DW_OP_reg19: | |
1259 | case DW_OP_reg20: | |
1260 | case DW_OP_reg21: | |
1261 | case DW_OP_reg22: | |
1262 | case DW_OP_reg23: | |
1263 | case DW_OP_reg24: | |
1264 | case DW_OP_reg25: | |
1265 | case DW_OP_reg26: | |
1266 | case DW_OP_reg27: | |
1267 | case DW_OP_reg28: | |
1268 | case DW_OP_reg29: | |
1269 | case DW_OP_reg30: | |
1270 | case DW_OP_reg31: | |
18464d4d JK |
1271 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1272 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1273 | break; |
1274 | ||
1275 | case DW_OP_breg0: | |
1276 | case DW_OP_breg1: | |
1277 | case DW_OP_breg2: | |
1278 | case DW_OP_breg3: | |
1279 | case DW_OP_breg4: | |
1280 | case DW_OP_breg5: | |
1281 | case DW_OP_breg6: | |
1282 | case DW_OP_breg7: | |
1283 | case DW_OP_breg8: | |
1284 | case DW_OP_breg9: | |
1285 | case DW_OP_breg10: | |
1286 | case DW_OP_breg11: | |
1287 | case DW_OP_breg12: | |
1288 | case DW_OP_breg13: | |
1289 | case DW_OP_breg14: | |
1290 | case DW_OP_breg15: | |
1291 | case DW_OP_breg16: | |
1292 | case DW_OP_breg17: | |
1293 | case DW_OP_breg18: | |
1294 | case DW_OP_breg19: | |
1295 | case DW_OP_breg20: | |
1296 | case DW_OP_breg21: | |
1297 | case DW_OP_breg22: | |
1298 | case DW_OP_breg23: | |
1299 | case DW_OP_breg24: | |
1300 | case DW_OP_breg25: | |
1301 | case DW_OP_breg26: | |
1302 | case DW_OP_breg27: | |
1303 | case DW_OP_breg28: | |
1304 | case DW_OP_breg29: | |
1305 | case DW_OP_breg30: | |
1306 | case DW_OP_breg31: | |
467c65bc | 1307 | printf ("DW_OP_breg%d (%s): %s", |
47704ddf | 1308 | op - DW_OP_breg0, |
18464d4d | 1309 | regname (op - DW_OP_breg0, 1), |
f6f0e17b | 1310 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1311 | data += bytes_read; |
1312 | break; | |
1313 | ||
1314 | case DW_OP_regx: | |
f6f0e17b | 1315 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1316 | data += bytes_read; |
467c65bc NC |
1317 | printf ("DW_OP_regx: %s (%s)", |
1318 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1319 | break; |
1320 | case DW_OP_fbreg: | |
1321 | need_frame_base = 1; | |
467c65bc | 1322 | printf ("DW_OP_fbreg: %s", |
f6f0e17b | 1323 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1324 | data += bytes_read; |
1325 | break; | |
1326 | case DW_OP_bregx: | |
f6f0e17b | 1327 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1328 | data += bytes_read; |
467c65bc NC |
1329 | printf ("DW_OP_bregx: %s (%s) %s", |
1330 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
f6f0e17b | 1331 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1332 | data += bytes_read; |
1333 | break; | |
1334 | case DW_OP_piece: | |
467c65bc | 1335 | printf ("DW_OP_piece: %s", |
f6f0e17b | 1336 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1337 | data += bytes_read; |
1338 | break; | |
1339 | case DW_OP_deref_size: | |
0c588247 NC |
1340 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1341 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1342 | break; |
1343 | case DW_OP_xderef_size: | |
0c588247 NC |
1344 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1345 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1346 | break; |
1347 | case DW_OP_nop: | |
1348 | printf ("DW_OP_nop"); | |
1349 | break; | |
1350 | ||
1351 | /* DWARF 3 extensions. */ | |
1352 | case DW_OP_push_object_address: | |
1353 | printf ("DW_OP_push_object_address"); | |
1354 | break; | |
1355 | case DW_OP_call2: | |
1356 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1357 | this ought to be an 8-byte wide computation. */ | |
0c588247 | 1358 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1359 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1360 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1361 | break; |
1362 | case DW_OP_call4: | |
1363 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1364 | this ought to be an 8-byte wide computation. */ | |
0c588247 | 1365 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1366 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1367 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1368 | break; |
1369 | case DW_OP_call_ref: | |
e2a0d921 NC |
1370 | /* XXX: Strictly speaking for 64-bit DWARF3 files |
1371 | this ought to be an 8-byte wide computation. */ | |
b7807392 JJ |
1372 | if (dwarf_version == -1) |
1373 | { | |
1374 | printf (_("(DW_OP_call_ref in frame info)")); | |
1375 | /* No way to tell where the next op is, so just bail. */ | |
1376 | return need_frame_base; | |
1377 | } | |
1378 | if (dwarf_version == 2) | |
1379 | { | |
0c588247 | 1380 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1381 | } |
1382 | else | |
1383 | { | |
0c588247 | 1384 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1385 | } |
0c588247 | 1386 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1387 | break; |
a87b0a59 NS |
1388 | case DW_OP_form_tls_address: |
1389 | printf ("DW_OP_form_tls_address"); | |
1390 | break; | |
e2a0d921 NC |
1391 | case DW_OP_call_frame_cfa: |
1392 | printf ("DW_OP_call_frame_cfa"); | |
1393 | break; | |
1394 | case DW_OP_bit_piece: | |
1395 | printf ("DW_OP_bit_piece: "); | |
9cf03b7e | 1396 | printf (_("size: %s "), |
f6f0e17b | 1397 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 | 1398 | data += bytes_read; |
9cf03b7e | 1399 | printf (_("offset: %s "), |
f6f0e17b | 1400 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 NC |
1401 | data += bytes_read; |
1402 | break; | |
19e6b90e | 1403 | |
3244e8f5 JJ |
1404 | /* DWARF 4 extensions. */ |
1405 | case DW_OP_stack_value: | |
1406 | printf ("DW_OP_stack_value"); | |
1407 | break; | |
1408 | ||
1409 | case DW_OP_implicit_value: | |
1410 | printf ("DW_OP_implicit_value"); | |
f6f0e17b | 1411 | uvalue = read_uleb128 (data, &bytes_read, end); |
3244e8f5 | 1412 | data += bytes_read; |
ef0b5f1c | 1413 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1414 | break; |
1415 | ||
19e6b90e L |
1416 | /* GNU extensions. */ |
1417 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1418 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1419 | break; |
1420 | case DW_OP_GNU_uninit: | |
1421 | printf ("DW_OP_GNU_uninit"); | |
1422 | /* FIXME: Is there data associated with this OP ? */ | |
1423 | break; | |
f1c4cc75 RH |
1424 | case DW_OP_GNU_encoded_addr: |
1425 | { | |
6937bb54 | 1426 | int encoding = 0; |
f1c4cc75 | 1427 | dwarf_vma addr; |
467c65bc | 1428 | |
6937bb54 NC |
1429 | if (data < end) |
1430 | encoding = *data++; | |
041830e0 | 1431 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1432 | |
1433 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1434 | print_dwarf_vma (addr, pointer_size); | |
1435 | } | |
1436 | break; | |
bc0a77d2 | 1437 | case DW_OP_implicit_pointer: |
b7807392 JJ |
1438 | case DW_OP_GNU_implicit_pointer: |
1439 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1440 | this ought to be an 8-byte wide computation. */ | |
1441 | if (dwarf_version == -1) | |
1442 | { | |
bc0a77d2 JK |
1443 | printf (_("(%s in frame info)"), |
1444 | (op == DW_OP_implicit_pointer | |
1445 | ? "DW_OP_implicit_pointer" | |
1446 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1447 | /* No way to tell where the next op is, so just bail. */ |
1448 | return need_frame_base; | |
1449 | } | |
1450 | if (dwarf_version == 2) | |
1451 | { | |
0c588247 | 1452 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1453 | } |
1454 | else | |
1455 | { | |
0c588247 | 1456 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1457 | } |
bc0a77d2 JK |
1458 | printf ("%s: <0x%s> %s", |
1459 | (op == DW_OP_implicit_pointer | |
1460 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 NC |
1461 | dwarf_vmatoa ("x", uvalue), |
1462 | dwarf_vmatoa ("d", read_sleb128 (data, | |
1463 | &bytes_read, end))); | |
1464 | data += bytes_read; | |
b7807392 | 1465 | break; |
77145576 | 1466 | case DW_OP_entry_value: |
0892011d | 1467 | case DW_OP_GNU_entry_value: |
f6f0e17b | 1468 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1469 | data += bytes_read; |
058037d3 NC |
1470 | /* PR 17531: file: 0cc9cd00. */ |
1471 | if (uvalue > (dwarf_vma) (end - data)) | |
1472 | uvalue = end - data; | |
77145576 JK |
1473 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1474 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1475 | if (decode_location_expression (data, pointer_size, offset_size, |
1476 | dwarf_version, uvalue, | |
1477 | cu_offset, section)) | |
1478 | need_frame_base = 1; | |
1479 | putchar (')'); | |
1480 | data += uvalue; | |
6937bb54 NC |
1481 | if (data > end) |
1482 | data = end; | |
0892011d | 1483 | break; |
bc0a77d2 | 1484 | case DW_OP_const_type: |
0892011d | 1485 | case DW_OP_GNU_const_type: |
f6f0e17b | 1486 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1487 | data += bytes_read; |
bc0a77d2 JK |
1488 | printf ("%s: <0x%s> ", |
1489 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1490 | : "DW_OP_GNU_const_type"), | |
0892011d | 1491 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1492 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1493 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1494 | break; |
bc0a77d2 | 1495 | case DW_OP_regval_type: |
0892011d | 1496 | case DW_OP_GNU_regval_type: |
f6f0e17b | 1497 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1498 | data += bytes_read; |
bc0a77d2 JK |
1499 | printf ("%s: %s (%s)", |
1500 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1501 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1502 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
f6f0e17b | 1503 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1504 | data += bytes_read; |
1505 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1506 | break; | |
bc0a77d2 | 1507 | case DW_OP_deref_type: |
0892011d | 1508 | case DW_OP_GNU_deref_type: |
0c588247 | 1509 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1510 | printf ("%s: %ld", |
1511 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1512 | : "DW_OP_GNU_deref_type"), | |
1513 | (long) uvalue); | |
f6f0e17b | 1514 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1515 | data += bytes_read; |
1516 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1517 | break; | |
bc0a77d2 | 1518 | case DW_OP_convert: |
0892011d | 1519 | case DW_OP_GNU_convert: |
f6f0e17b | 1520 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1521 | data += bytes_read; |
bc0a77d2 JK |
1522 | printf ("%s <0x%s>", |
1523 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1524 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1525 | break; |
bc0a77d2 | 1526 | case DW_OP_reinterpret: |
0892011d | 1527 | case DW_OP_GNU_reinterpret: |
f6f0e17b | 1528 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1529 | data += bytes_read; |
bc0a77d2 JK |
1530 | printf ("%s <0x%s>", |
1531 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1532 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1533 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1534 | break; | |
1535 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1536 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1537 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1538 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1539 | break; |
b4eb7656 AM |
1540 | case DW_OP_GNU_addr_index: |
1541 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1542 | data += bytes_read; | |
1543 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1544 | break; | |
1545 | case DW_OP_GNU_const_index: | |
1546 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1547 | data += bytes_read; | |
1548 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1549 | break; | |
e2a0d921 NC |
1550 | |
1551 | /* HP extensions. */ | |
1552 | case DW_OP_HP_is_value: | |
1553 | printf ("DW_OP_HP_is_value"); | |
1554 | /* FIXME: Is there data associated with this OP ? */ | |
1555 | break; | |
1556 | case DW_OP_HP_fltconst4: | |
1557 | printf ("DW_OP_HP_fltconst4"); | |
1558 | /* FIXME: Is there data associated with this OP ? */ | |
1559 | break; | |
1560 | case DW_OP_HP_fltconst8: | |
1561 | printf ("DW_OP_HP_fltconst8"); | |
1562 | /* FIXME: Is there data associated with this OP ? */ | |
1563 | break; | |
1564 | case DW_OP_HP_mod_range: | |
1565 | printf ("DW_OP_HP_mod_range"); | |
1566 | /* FIXME: Is there data associated with this OP ? */ | |
1567 | break; | |
1568 | case DW_OP_HP_unmod_range: | |
1569 | printf ("DW_OP_HP_unmod_range"); | |
1570 | /* FIXME: Is there data associated with this OP ? */ | |
1571 | break; | |
1572 | case DW_OP_HP_tls: | |
1573 | printf ("DW_OP_HP_tls"); | |
1574 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1575 | break; |
1576 | ||
35d60fe4 NC |
1577 | /* PGI (STMicroelectronics) extensions. */ |
1578 | case DW_OP_PGI_omp_thread_num: | |
1579 | /* Pushes the thread number for the current thread as it would be | |
1580 | returned by the standard OpenMP library function: | |
1581 | omp_get_thread_num(). The "current thread" is the thread for | |
1582 | which the expression is being evaluated. */ | |
1583 | printf ("DW_OP_PGI_omp_thread_num"); | |
1584 | break; | |
1585 | ||
19e6b90e L |
1586 | default: |
1587 | if (op >= DW_OP_lo_user | |
1588 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1589 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1590 | else |
0502a2b4 | 1591 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1592 | /* No way to tell where the next op is, so just bail. */ |
1593 | return need_frame_base; | |
1594 | } | |
1595 | ||
1596 | /* Separate the ops. */ | |
1597 | if (data < end) | |
1598 | printf ("; "); | |
1599 | } | |
1600 | ||
1601 | return need_frame_base; | |
1602 | } | |
1603 | ||
341f9135 CC |
1604 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1605 | This is used for DWARF package files. */ | |
1606 | ||
1607 | static struct cu_tu_set * | |
1608 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1609 | { | |
1610 | struct cu_tu_set *p; | |
1611 | unsigned int nsets; | |
1612 | unsigned int dw_sect; | |
1613 | ||
1614 | if (do_types) | |
1615 | { | |
1616 | p = tu_sets; | |
1617 | nsets = tu_count; | |
1618 | dw_sect = DW_SECT_TYPES; | |
1619 | } | |
1620 | else | |
1621 | { | |
1622 | p = cu_sets; | |
1623 | nsets = cu_count; | |
1624 | dw_sect = DW_SECT_INFO; | |
1625 | } | |
1626 | while (nsets > 0) | |
1627 | { | |
1628 | if (p->section_offsets [dw_sect] == cu_offset) | |
1629 | return p; | |
1630 | p++; | |
1631 | nsets--; | |
1632 | } | |
1633 | return NULL; | |
1634 | } | |
1635 | ||
a69c4772 NC |
1636 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1637 | static void | |
1638 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1639 | { | |
1640 | dwarf_vma tmp = * low_bits; | |
1641 | ||
1642 | tmp += inc; | |
1643 | ||
1644 | /* FIXME: There is probably a better way of handling this: | |
1645 | ||
1646 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1647 | type. Plus regardless of its size LOW_BITS is meant to | |
1648 | only hold 32-bits, so if there is overflow or wrap around | |
1649 | we must propagate into HIGH_BITS. */ | |
1650 | if (tmp < * low_bits) | |
1651 | { | |
1652 | ++ * high_bits; | |
1653 | } | |
1654 | else if (sizeof (tmp) > 8 | |
1655 | && (tmp >> 31) > 1) | |
1656 | { | |
1657 | ++ * high_bits; | |
1658 | tmp &= 0xFFFFFFFF; | |
1659 | } | |
1660 | ||
1661 | * low_bits = tmp; | |
1662 | } | |
1663 | ||
19e6b90e | 1664 | static unsigned char * |
6e3d6dc1 NC |
1665 | read_and_display_attr_value (unsigned long attribute, |
1666 | unsigned long form, | |
77145576 | 1667 | dwarf_signed_vma implicit_const, |
ec4d4525 | 1668 | unsigned char * data, |
f6f0e17b | 1669 | unsigned char * end, |
467c65bc NC |
1670 | dwarf_vma cu_offset, |
1671 | dwarf_vma pointer_size, | |
1672 | dwarf_vma offset_size, | |
6e3d6dc1 NC |
1673 | int dwarf_version, |
1674 | debug_info * debug_info_p, | |
1675 | int do_loc, | |
341f9135 | 1676 | struct dwarf_section * section, |
ef0b5f1c | 1677 | struct cu_tu_set * this_set, char delimiter) |
19e6b90e | 1678 | { |
467c65bc | 1679 | dwarf_vma uvalue = 0; |
19e6b90e | 1680 | unsigned char *block_start = NULL; |
6e3d6dc1 | 1681 | unsigned char * orig_data = data; |
19e6b90e L |
1682 | unsigned int bytes_read; |
1683 | ||
f41e4712 | 1684 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 1685 | { |
f41e4712 | 1686 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
1687 | return data; |
1688 | } | |
1689 | ||
19e6b90e L |
1690 | switch (form) |
1691 | { | |
1692 | default: | |
1693 | break; | |
1694 | ||
1695 | case DW_FORM_ref_addr: | |
1696 | if (dwarf_version == 2) | |
0c588247 | 1697 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
932fd279 | 1698 | else if (dwarf_version == 3 || dwarf_version == 4) |
0c588247 | 1699 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 1700 | else |
467c65bc NC |
1701 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
1702 | ||
19e6b90e L |
1703 | break; |
1704 | ||
1705 | case DW_FORM_addr: | |
0c588247 | 1706 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
1707 | break; |
1708 | ||
1709 | case DW_FORM_strp: | |
77145576 | 1710 | case DW_FORM_line_strp: |
932fd279 | 1711 | case DW_FORM_sec_offset: |
a081f3cd JJ |
1712 | case DW_FORM_GNU_ref_alt: |
1713 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 1714 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
1715 | break; |
1716 | ||
932fd279 JJ |
1717 | case DW_FORM_flag_present: |
1718 | uvalue = 1; | |
1719 | break; | |
1720 | ||
19e6b90e L |
1721 | case DW_FORM_ref1: |
1722 | case DW_FORM_flag: | |
1723 | case DW_FORM_data1: | |
0c588247 | 1724 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
1725 | break; |
1726 | ||
1727 | case DW_FORM_ref2: | |
1728 | case DW_FORM_data2: | |
0c588247 | 1729 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
1730 | break; |
1731 | ||
1732 | case DW_FORM_ref4: | |
1733 | case DW_FORM_data4: | |
0c588247 | 1734 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
1735 | break; |
1736 | ||
1737 | case DW_FORM_sdata: | |
f6f0e17b | 1738 | uvalue = read_sleb128 (data, & bytes_read, end); |
19e6b90e L |
1739 | data += bytes_read; |
1740 | break; | |
1741 | ||
4723351a | 1742 | case DW_FORM_GNU_str_index: |
f6f0e17b | 1743 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1744 | data += bytes_read; |
1745 | break; | |
1746 | ||
19e6b90e L |
1747 | case DW_FORM_ref_udata: |
1748 | case DW_FORM_udata: | |
f6f0e17b | 1749 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1750 | data += bytes_read; |
1751 | break; | |
1752 | ||
1753 | case DW_FORM_indirect: | |
f6f0e17b | 1754 | form = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1755 | data += bytes_read; |
1756 | if (!do_loc) | |
ef0b5f1c | 1757 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 JK |
1758 | if (form == DW_FORM_implicit_const) |
1759 | { | |
1760 | implicit_const = read_sleb128 (data, & bytes_read, end); | |
1761 | data += bytes_read; | |
1762 | } | |
1763 | return read_and_display_attr_value (attribute, form, implicit_const, data, | |
1764 | end, cu_offset, pointer_size, | |
19e6b90e | 1765 | offset_size, dwarf_version, |
ec4d4525 | 1766 | debug_info_p, do_loc, |
ef0b5f1c | 1767 | section, this_set, delimiter); |
4723351a | 1768 | case DW_FORM_GNU_addr_index: |
f6f0e17b | 1769 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1770 | data += bytes_read; |
1771 | break; | |
19e6b90e L |
1772 | } |
1773 | ||
1774 | switch (form) | |
1775 | { | |
1776 | case DW_FORM_ref_addr: | |
1777 | if (!do_loc) | |
ef0b5f1c | 1778 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
1779 | break; |
1780 | ||
a081f3cd JJ |
1781 | case DW_FORM_GNU_ref_alt: |
1782 | if (!do_loc) | |
ef0b5f1c | 1783 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
a081f3cd JJ |
1784 | break; |
1785 | ||
19e6b90e L |
1786 | case DW_FORM_ref1: |
1787 | case DW_FORM_ref2: | |
1788 | case DW_FORM_ref4: | |
1789 | case DW_FORM_ref_udata: | |
1790 | if (!do_loc) | |
ef0b5f1c | 1791 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
1792 | break; |
1793 | ||
1794 | case DW_FORM_data4: | |
1795 | case DW_FORM_addr: | |
932fd279 | 1796 | case DW_FORM_sec_offset: |
19e6b90e | 1797 | if (!do_loc) |
ef0b5f1c | 1798 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
1799 | break; |
1800 | ||
932fd279 | 1801 | case DW_FORM_flag_present: |
19e6b90e L |
1802 | case DW_FORM_flag: |
1803 | case DW_FORM_data1: | |
1804 | case DW_FORM_data2: | |
1805 | case DW_FORM_sdata: | |
1806 | case DW_FORM_udata: | |
1807 | if (!do_loc) | |
ef0b5f1c | 1808 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
1809 | break; |
1810 | ||
77145576 JK |
1811 | case DW_FORM_implicit_const: |
1812 | if (!do_loc) | |
1813 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
1814 | break; | |
1815 | ||
19e6b90e L |
1816 | case DW_FORM_ref8: |
1817 | case DW_FORM_data8: | |
2bc8690c | 1818 | if (!do_loc) |
19e6b90e | 1819 | { |
74bc6052 | 1820 | dwarf_vma high_bits; |
a69c4772 | 1821 | dwarf_vma utmp; |
74bc6052 CC |
1822 | char buf[64]; |
1823 | ||
0c588247 | 1824 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
1825 | utmp = uvalue; |
1826 | if (form == DW_FORM_ref8) | |
1827 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 1828 | printf ("%c0x%s", delimiter, |
a69c4772 | 1829 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 1830 | } |
0c588247 | 1831 | |
19e6b90e L |
1832 | if ((do_loc || do_debug_loc || do_debug_ranges) |
1833 | && num_debug_info_entries == 0) | |
1834 | { | |
1835 | if (sizeof (uvalue) == 8) | |
0c588247 | 1836 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 1837 | else |
467c65bc | 1838 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 1839 | } |
0c588247 | 1840 | |
19e6b90e L |
1841 | data += 8; |
1842 | break; | |
1843 | ||
2f6cd591 JK |
1844 | case DW_FORM_data16: |
1845 | if (!do_loc) | |
1846 | { | |
1847 | dwarf_vma left_high_bits, left_low_bits; | |
1848 | dwarf_vma right_high_bits, right_low_bits; | |
1849 | ||
1850 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
1851 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
1852 | if (byte_get == byte_get_little_endian) | |
1853 | { | |
1854 | /* Swap them. */ | |
1855 | left_high_bits ^= right_high_bits; | |
1856 | right_high_bits ^= left_high_bits; | |
1857 | left_high_bits ^= right_high_bits; | |
1858 | left_low_bits ^= right_low_bits; | |
1859 | right_low_bits ^= left_low_bits; | |
1860 | left_low_bits ^= right_low_bits; | |
1861 | } | |
1862 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
1863 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
1864 | left_high_bits, left_low_bits, right_high_bits, | |
1865 | right_low_bits); | |
1866 | } | |
1867 | data += 16; | |
1868 | break; | |
1869 | ||
19e6b90e L |
1870 | case DW_FORM_string: |
1871 | if (!do_loc) | |
ef0b5f1c | 1872 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 1873 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
1874 | break; |
1875 | ||
1876 | case DW_FORM_block: | |
932fd279 | 1877 | case DW_FORM_exprloc: |
f6f0e17b | 1878 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e | 1879 | block_start = data + bytes_read; |
a1165289 NC |
1880 | if (block_start >= end) |
1881 | { | |
1882 | warn (_("Block ends prematurely\n")); | |
1883 | uvalue = 0; | |
1884 | block_start = end; | |
1885 | } | |
f3853b34 NC |
1886 | /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with |
1887 | gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute | |
1888 | block_start + uvalue here. */ | |
1889 | data = block_start + uvalue; | |
f41e4712 | 1890 | /* PR 17512: file: 008-103549-0.001:0.1. */ |
f3853b34 | 1891 | if (block_start + uvalue > end || data < block_start) |
f41e4712 NC |
1892 | { |
1893 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1894 | uvalue = end - block_start; | |
1895 | } | |
19e6b90e L |
1896 | if (do_loc) |
1897 | data = block_start + uvalue; | |
1898 | else | |
ef0b5f1c | 1899 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
1900 | break; |
1901 | ||
1902 | case DW_FORM_block1: | |
0c588247 | 1903 | SAFE_BYTE_GET (uvalue, data, 1, end); |
19e6b90e | 1904 | block_start = data + 1; |
a1165289 NC |
1905 | if (block_start >= end) |
1906 | { | |
1907 | warn (_("Block ends prematurely\n")); | |
1908 | uvalue = 0; | |
1909 | block_start = end; | |
1910 | } | |
f3853b34 NC |
1911 | data = block_start + uvalue; |
1912 | if (block_start + uvalue > end || data < block_start) | |
f41e4712 NC |
1913 | { |
1914 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1915 | uvalue = end - block_start; | |
1916 | } | |
19e6b90e L |
1917 | if (do_loc) |
1918 | data = block_start + uvalue; | |
1919 | else | |
ef0b5f1c | 1920 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
1921 | break; |
1922 | ||
1923 | case DW_FORM_block2: | |
0c588247 | 1924 | SAFE_BYTE_GET (uvalue, data, 2, end); |
19e6b90e | 1925 | block_start = data + 2; |
a1165289 NC |
1926 | if (block_start >= end) |
1927 | { | |
1928 | warn (_("Block ends prematurely\n")); | |
1929 | uvalue = 0; | |
1930 | block_start = end; | |
1931 | } | |
f3853b34 NC |
1932 | data = block_start + uvalue; |
1933 | if (block_start + uvalue > end || data < block_start) | |
f41e4712 NC |
1934 | { |
1935 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1936 | uvalue = end - block_start; | |
1937 | } | |
19e6b90e L |
1938 | if (do_loc) |
1939 | data = block_start + uvalue; | |
1940 | else | |
ef0b5f1c | 1941 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
1942 | break; |
1943 | ||
1944 | case DW_FORM_block4: | |
0c588247 | 1945 | SAFE_BYTE_GET (uvalue, data, 4, end); |
19e6b90e | 1946 | block_start = data + 4; |
a1165289 NC |
1947 | /* PR 17512: file: 3371-3907-0.004. */ |
1948 | if (block_start >= end) | |
1949 | { | |
1950 | warn (_("Block ends prematurely\n")); | |
1951 | uvalue = 0; | |
1952 | block_start = end; | |
1953 | } | |
f3853b34 NC |
1954 | data = block_start + uvalue; |
1955 | if (block_start + uvalue > end | |
b4eb7656 | 1956 | /* PR 17531: file: 5b5f0592. */ |
f3853b34 | 1957 | || data < block_start) |
f41e4712 NC |
1958 | { |
1959 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1960 | uvalue = end - block_start; | |
1961 | } | |
19e6b90e L |
1962 | if (do_loc) |
1963 | data = block_start + uvalue; | |
1964 | else | |
ef0b5f1c | 1965 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
1966 | break; |
1967 | ||
1968 | case DW_FORM_strp: | |
1969 | if (!do_loc) | |
ef0b5f1c | 1970 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
1971 | dwarf_vmatoa ("x", uvalue), |
1972 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
1973 | break; |
1974 | ||
77145576 JK |
1975 | case DW_FORM_line_strp: |
1976 | if (!do_loc) | |
1977 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
1978 | dwarf_vmatoa ("x", uvalue), | |
1979 | fetch_indirect_line_string (uvalue)); | |
1980 | break; | |
1981 | ||
4723351a CC |
1982 | case DW_FORM_GNU_str_index: |
1983 | if (!do_loc) | |
b4eb7656 AM |
1984 | { |
1985 | const char *suffix = strrchr (section->name, '.'); | |
1986 | int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0; | |
1987 | ||
ef0b5f1c | 1988 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
1989 | dwarf_vmatoa ("x", uvalue), |
1990 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
1991 | } | |
4723351a CC |
1992 | break; |
1993 | ||
a081f3cd JJ |
1994 | case DW_FORM_GNU_strp_alt: |
1995 | if (!do_loc) | |
ef0b5f1c | 1996 | printf (_("%c(alt indirect string, offset: 0x%s)"), delimiter, |
a081f3cd JJ |
1997 | dwarf_vmatoa ("x", uvalue)); |
1998 | break; | |
1999 | ||
19e6b90e L |
2000 | case DW_FORM_indirect: |
2001 | /* Handled above. */ | |
2002 | break; | |
2003 | ||
2b6f5997 CC |
2004 | case DW_FORM_ref_sig8: |
2005 | if (!do_loc) | |
2006 | { | |
74bc6052 CC |
2007 | dwarf_vma high_bits; |
2008 | char buf[64]; | |
2009 | ||
0c588247 | 2010 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 2011 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 2012 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 2013 | } |
74bc6052 | 2014 | data += 8; |
2b6f5997 CC |
2015 | break; |
2016 | ||
4723351a CC |
2017 | case DW_FORM_GNU_addr_index: |
2018 | if (!do_loc) | |
ef0b5f1c | 2019 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2020 | dwarf_vmatoa ("x", uvalue), |
2021 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
2022 | break; |
2023 | ||
19e6b90e L |
2024 | default: |
2025 | warn (_("Unrecognized form: %lu\n"), form); | |
2026 | break; | |
2027 | } | |
2028 | ||
19e6b90e | 2029 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2030 | && num_debug_info_entries == 0 |
2031 | && debug_info_p != NULL) | |
19e6b90e L |
2032 | { |
2033 | switch (attribute) | |
2034 | { | |
2035 | case DW_AT_frame_base: | |
2036 | have_frame_base = 1; | |
1a0670f3 | 2037 | /* Fall through. */ |
19e6b90e | 2038 | case DW_AT_location: |
9f272209 | 2039 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2040 | case DW_AT_string_length: |
2041 | case DW_AT_return_addr: | |
19e6b90e L |
2042 | case DW_AT_data_member_location: |
2043 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2044 | case DW_AT_segment: |
2045 | case DW_AT_static_link: | |
2046 | case DW_AT_use_location: | |
bc0a77d2 | 2047 | case DW_AT_call_value: |
629e7ca8 | 2048 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2049 | case DW_AT_call_data_value: |
629e7ca8 | 2050 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2051 | case DW_AT_call_target: |
629e7ca8 | 2052 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2053 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2054 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2055 | if ((dwarf_version < 4 |
212b6063 | 2056 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2057 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2058 | { |
2059 | /* Process location list. */ | |
91d6fa6a | 2060 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2061 | unsigned int num = debug_info_p->num_loc_offsets; |
2062 | ||
91d6fa6a | 2063 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2064 | { |
91d6fa6a | 2065 | lmax += 1024; |
467c65bc | 2066 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2067 | xcrealloc (debug_info_p->loc_offsets, |
2068 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2069 | debug_info_p->loc_views = (dwarf_vma *) |
2070 | xcrealloc (debug_info_p->loc_views, | |
2071 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2072 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2073 | xcrealloc (debug_info_p->have_frame_base, |
2074 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2075 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2076 | } |
341f9135 | 2077 | if (this_set != NULL) |
b4eb7656 | 2078 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2079 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2080 | if (attribute != DW_AT_GNU_locviews) |
2081 | { | |
2082 | debug_info_p->loc_offsets [num] = uvalue; | |
2083 | debug_info_p->num_loc_offsets++; | |
2084 | assert (debug_info_p->num_loc_offsets | |
2085 | - debug_info_p->num_loc_views <= 1); | |
2086 | } | |
2087 | else | |
2088 | { | |
2089 | assert (debug_info_p->num_loc_views <= num); | |
2090 | num = debug_info_p->num_loc_views; | |
2091 | debug_info_p->loc_views [num] = uvalue; | |
2092 | debug_info_p->num_loc_views++; | |
2093 | assert (debug_info_p->num_loc_views | |
2094 | - debug_info_p->num_loc_offsets <= 1); | |
2095 | } | |
19e6b90e L |
2096 | } |
2097 | break; | |
e2a0d921 | 2098 | |
19e6b90e L |
2099 | case DW_AT_low_pc: |
2100 | if (need_base_address) | |
2101 | debug_info_p->base_address = uvalue; | |
2102 | break; | |
2103 | ||
4723351a | 2104 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2105 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2106 | break; |
2107 | ||
2108 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2109 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2110 | break; |
2111 | ||
19e6b90e | 2112 | case DW_AT_ranges: |
b4eb7656 | 2113 | if ((dwarf_version < 4 |
212b6063 | 2114 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2115 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2116 | { |
2117 | /* Process range list. */ | |
91d6fa6a | 2118 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2119 | unsigned int num = debug_info_p->num_range_lists; |
2120 | ||
91d6fa6a | 2121 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2122 | { |
91d6fa6a | 2123 | lmax += 1024; |
467c65bc | 2124 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2125 | xcrealloc (debug_info_p->range_lists, |
2126 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2127 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2128 | } |
2129 | debug_info_p->range_lists [num] = uvalue; | |
2130 | debug_info_p->num_range_lists++; | |
2131 | } | |
2132 | break; | |
2133 | ||
2134 | default: | |
2135 | break; | |
2136 | } | |
2137 | } | |
2138 | ||
4ccf1e31 | 2139 | if (do_loc || attribute == 0) |
19e6b90e L |
2140 | return data; |
2141 | ||
ec4d4525 | 2142 | /* For some attributes we can display further information. */ |
19e6b90e L |
2143 | switch (attribute) |
2144 | { | |
2145 | case DW_AT_inline: | |
2e9e81a8 | 2146 | printf ("\t"); |
19e6b90e L |
2147 | switch (uvalue) |
2148 | { | |
2149 | case DW_INL_not_inlined: | |
2150 | printf (_("(not inlined)")); | |
2151 | break; | |
2152 | case DW_INL_inlined: | |
2153 | printf (_("(inlined)")); | |
2154 | break; | |
2155 | case DW_INL_declared_not_inlined: | |
2156 | printf (_("(declared as inline but ignored)")); | |
2157 | break; | |
2158 | case DW_INL_declared_inlined: | |
2159 | printf (_("(declared as inline and inlined)")); | |
2160 | break; | |
2161 | default: | |
47704ddf KT |
2162 | printf (_(" (Unknown inline attribute value: %s)"), |
2163 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2164 | break; |
2165 | } | |
2166 | break; | |
2167 | ||
2168 | case DW_AT_language: | |
2e9e81a8 | 2169 | printf ("\t"); |
19e6b90e L |
2170 | switch (uvalue) |
2171 | { | |
4b78141a | 2172 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2173 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2174 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2175 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2176 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2177 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2178 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2179 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2180 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2181 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2182 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2183 | /* DWARF 2.1 values. */ |
4b78141a | 2184 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2185 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2186 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2187 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2188 | /* DWARF 3 values. */ |
2189 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2190 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2191 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2192 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2193 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2194 | /* DWARF 4 values. */ |
2195 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 ILT |
2196 | /* DWARF 5 values. */ |
2197 | case DW_LANG_Go: printf ("(Go)"); break; | |
8bc10620 | 2198 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
6ddfe5b4 | 2199 | case DW_LANG_C11: printf ("(C11)"); break; |
8bc10620 | 2200 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2201 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2202 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
19e6b90e L |
2203 | /* MIPS extension. */ |
2204 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2205 | /* UPC extension. */ | |
2206 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2207 | default: | |
4b78141a | 2208 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2209 | printf (_("(implementation defined: %s)"), |
467c65bc | 2210 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2211 | else |
9cf03b7e | 2212 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2213 | break; |
2214 | } | |
2215 | break; | |
2216 | ||
2217 | case DW_AT_encoding: | |
2e9e81a8 | 2218 | printf ("\t"); |
19e6b90e L |
2219 | switch (uvalue) |
2220 | { | |
2221 | case DW_ATE_void: printf ("(void)"); break; | |
2222 | case DW_ATE_address: printf ("(machine address)"); break; | |
2223 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2224 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2225 | case DW_ATE_float: printf ("(float)"); break; | |
2226 | case DW_ATE_signed: printf ("(signed)"); break; | |
2227 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2228 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2229 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2230 | /* DWARF 2.1 values: */ |
19e6b90e L |
2231 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2232 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2233 | /* DWARF 3 values: */ |
2234 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2235 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2236 | case DW_ATE_edited: printf ("(edited)"); break; | |
2237 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2238 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
2239 | /* HP extensions: */ | |
2240 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2241 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2242 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2243 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2244 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2245 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2246 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
153a2776 NC |
2247 | /* DWARF 4 values: */ |
2248 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
e2a0d921 | 2249 | |
19e6b90e L |
2250 | default: |
2251 | if (uvalue >= DW_ATE_lo_user | |
2252 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2253 | printf (_("(user defined type)")); |
19e6b90e | 2254 | else |
9cf03b7e | 2255 | printf (_("(unknown type)")); |
19e6b90e L |
2256 | break; |
2257 | } | |
2258 | break; | |
2259 | ||
2260 | case DW_AT_accessibility: | |
2e9e81a8 | 2261 | printf ("\t"); |
19e6b90e L |
2262 | switch (uvalue) |
2263 | { | |
2264 | case DW_ACCESS_public: printf ("(public)"); break; | |
2265 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2266 | case DW_ACCESS_private: printf ("(private)"); break; | |
2267 | default: | |
9cf03b7e | 2268 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2269 | break; |
2270 | } | |
2271 | break; | |
2272 | ||
2273 | case DW_AT_visibility: | |
2e9e81a8 | 2274 | printf ("\t"); |
19e6b90e L |
2275 | switch (uvalue) |
2276 | { | |
2277 | case DW_VIS_local: printf ("(local)"); break; | |
2278 | case DW_VIS_exported: printf ("(exported)"); break; | |
2279 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2280 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2281 | } |
2282 | break; | |
2283 | ||
2284 | case DW_AT_virtuality: | |
2e9e81a8 | 2285 | printf ("\t"); |
19e6b90e L |
2286 | switch (uvalue) |
2287 | { | |
2288 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2289 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2290 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2291 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2292 | } |
2293 | break; | |
2294 | ||
2295 | case DW_AT_identifier_case: | |
2e9e81a8 | 2296 | printf ("\t"); |
19e6b90e L |
2297 | switch (uvalue) |
2298 | { | |
2299 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2300 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2301 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2302 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2303 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2304 | } |
2305 | break; | |
2306 | ||
2307 | case DW_AT_calling_convention: | |
2e9e81a8 | 2308 | printf ("\t"); |
19e6b90e L |
2309 | switch (uvalue) |
2310 | { | |
2311 | case DW_CC_normal: printf ("(normal)"); break; | |
2312 | case DW_CC_program: printf ("(program)"); break; | |
2313 | case DW_CC_nocall: printf ("(nocall)"); break; | |
2314 | default: | |
2315 | if (uvalue >= DW_CC_lo_user | |
2316 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2317 | printf (_("(user defined)")); |
19e6b90e | 2318 | else |
9cf03b7e | 2319 | printf (_("(unknown convention)")); |
19e6b90e L |
2320 | } |
2321 | break; | |
2322 | ||
2323 | case DW_AT_ordering: | |
2e9e81a8 | 2324 | printf ("\t"); |
19e6b90e L |
2325 | switch (uvalue) |
2326 | { | |
9cf03b7e | 2327 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2328 | case 0: printf ("(row major)"); break; |
2329 | case 1: printf ("(column major)"); break; | |
2330 | } | |
2331 | break; | |
2332 | ||
2333 | case DW_AT_frame_base: | |
2334 | have_frame_base = 1; | |
1a0670f3 | 2335 | /* Fall through. */ |
19e6b90e | 2336 | case DW_AT_location: |
e2a0d921 NC |
2337 | case DW_AT_string_length: |
2338 | case DW_AT_return_addr: | |
19e6b90e L |
2339 | case DW_AT_data_member_location: |
2340 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2341 | case DW_AT_segment: |
2342 | case DW_AT_static_link: | |
2343 | case DW_AT_use_location: | |
bc0a77d2 | 2344 | case DW_AT_call_value: |
629e7ca8 | 2345 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2346 | case DW_AT_call_data_value: |
629e7ca8 | 2347 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2348 | case DW_AT_call_target: |
629e7ca8 | 2349 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2350 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2351 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 2352 | if ((dwarf_version < 4 |
b4eb7656 | 2353 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2354 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 2355 | printf (_(" (location list)")); |
e2a0d921 | 2356 | /* Fall through. */ |
19e6b90e L |
2357 | case DW_AT_allocated: |
2358 | case DW_AT_associated: | |
2359 | case DW_AT_data_location: | |
2360 | case DW_AT_stride: | |
2361 | case DW_AT_upper_bound: | |
cecf136e | 2362 | case DW_AT_lower_bound: |
19e6b90e L |
2363 | if (block_start) |
2364 | { | |
2365 | int need_frame_base; | |
2366 | ||
2e9e81a8 | 2367 | printf ("\t("); |
19e6b90e L |
2368 | need_frame_base = decode_location_expression (block_start, |
2369 | pointer_size, | |
b7807392 JJ |
2370 | offset_size, |
2371 | dwarf_version, | |
19e6b90e | 2372 | uvalue, |
f1c4cc75 | 2373 | cu_offset, section); |
19e6b90e L |
2374 | printf (")"); |
2375 | if (need_frame_base && !have_frame_base) | |
2376 | printf (_(" [without DW_AT_frame_base]")); | |
2377 | } | |
19e6b90e L |
2378 | break; |
2379 | ||
ec4d4525 NC |
2380 | case DW_AT_import: |
2381 | { | |
a081f3cd JJ |
2382 | if (form == DW_FORM_ref_sig8 |
2383 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 2384 | break; |
2b6f5997 | 2385 | |
ec4d4525 NC |
2386 | if (form == DW_FORM_ref1 |
2387 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
2388 | || form == DW_FORM_ref4 |
2389 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
2390 | uvalue += cu_offset; |
2391 | ||
6e3d6dc1 | 2392 | if (uvalue >= section->size) |
f3853b34 | 2393 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
2394 | dwarf_vmatoa ("x", uvalue), |
2395 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
2396 | else |
2397 | { | |
2398 | unsigned long abbrev_number; | |
2399 | abbrev_entry * entry; | |
2400 | ||
f6f0e17b | 2401 | abbrev_number = read_uleb128 (section->start + uvalue, NULL, end); |
cecf136e | 2402 | |
2e9e81a8 | 2403 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
2404 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
2405 | use different abbrev table, and we don't track .debug_info chunks | |
2406 | yet. */ | |
2407 | if (form != DW_FORM_ref_addr) | |
2408 | { | |
2409 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
2410 | if (entry->entry == abbrev_number) | |
2411 | break; | |
2412 | if (entry != NULL) | |
2413 | printf (" (%s)", get_TAG_name (entry->tag)); | |
2414 | } | |
6e3d6dc1 NC |
2415 | printf ("]"); |
2416 | } | |
ec4d4525 NC |
2417 | } |
2418 | break; | |
2419 | ||
19e6b90e L |
2420 | default: |
2421 | break; | |
2422 | } | |
2423 | ||
2424 | return data; | |
2425 | } | |
2426 | ||
a19c41a7 | 2427 | static const char * |
19e6b90e L |
2428 | get_AT_name (unsigned long attribute) |
2429 | { | |
a19c41a7 | 2430 | const char *name; |
e2a0d921 | 2431 | |
399c99f7 L |
2432 | if (attribute == 0) |
2433 | return "DW_AT value: 0"; | |
2434 | ||
a19c41a7 TT |
2435 | /* One value is shared by the MIPS and HP extensions: */ |
2436 | if (attribute == DW_AT_MIPS_fde) | |
2437 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
19e6b90e | 2438 | |
a19c41a7 TT |
2439 | name = get_DW_AT_name (attribute); |
2440 | ||
2441 | if (name == NULL) | |
2442 | { | |
2443 | static char buffer[100]; | |
2444 | ||
2445 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
2446 | attribute); | |
2447 | return buffer; | |
19e6b90e | 2448 | } |
a19c41a7 TT |
2449 | |
2450 | return name; | |
19e6b90e L |
2451 | } |
2452 | ||
2453 | static unsigned char * | |
6e3d6dc1 NC |
2454 | read_and_display_attr (unsigned long attribute, |
2455 | unsigned long form, | |
77145576 | 2456 | dwarf_signed_vma implicit_const, |
ec4d4525 | 2457 | unsigned char * data, |
f6f0e17b | 2458 | unsigned char * end, |
467c65bc NC |
2459 | dwarf_vma cu_offset, |
2460 | dwarf_vma pointer_size, | |
2461 | dwarf_vma offset_size, | |
6e3d6dc1 NC |
2462 | int dwarf_version, |
2463 | debug_info * debug_info_p, | |
2464 | int do_loc, | |
341f9135 CC |
2465 | struct dwarf_section * section, |
2466 | struct cu_tu_set * this_set) | |
19e6b90e L |
2467 | { |
2468 | if (!do_loc) | |
750f03b7 | 2469 | printf (" %-18s:", get_AT_name (attribute)); |
77145576 | 2470 | data = read_and_display_attr_value (attribute, form, implicit_const, data, end, |
f6f0e17b | 2471 | cu_offset, pointer_size, offset_size, |
19e6b90e | 2472 | dwarf_version, debug_info_p, |
ef0b5f1c | 2473 | do_loc, section, this_set, ' '); |
19e6b90e L |
2474 | if (!do_loc) |
2475 | printf ("\n"); | |
2476 | return data; | |
2477 | } | |
2478 | ||
19e6b90e L |
2479 | /* Process the contents of a .debug_info section. If do_loc is non-zero |
2480 | then we are scanning for location lists and we do not want to display | |
2b6f5997 CC |
2481 | anything to the user. If do_types is non-zero, we are processing |
2482 | a .debug_types section instead of a .debug_info section. */ | |
19e6b90e L |
2483 | |
2484 | static int | |
6e3d6dc1 NC |
2485 | process_debug_info (struct dwarf_section *section, |
2486 | void *file, | |
b4eb7656 | 2487 | enum dwarf_section_display_enum abbrev_sec, |
2b6f5997 CC |
2488 | int do_loc, |
2489 | int do_types) | |
19e6b90e L |
2490 | { |
2491 | unsigned char *start = section->start; | |
2492 | unsigned char *end = start + section->size; | |
2493 | unsigned char *section_begin; | |
2494 | unsigned int unit; | |
2495 | unsigned int num_units = 0; | |
2496 | ||
2497 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2498 | && num_debug_info_entries == 0 |
2499 | && ! do_types) | |
19e6b90e | 2500 | { |
767221a9 | 2501 | dwarf_vma length; |
19e6b90e L |
2502 | |
2503 | /* First scan the section to get the number of comp units. */ | |
2504 | for (section_begin = start, num_units = 0; section_begin < end; | |
2505 | num_units ++) | |
2506 | { | |
2507 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
2508 | will be the length. For a 64-bit DWARF section, it'll be | |
2509 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 2510 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
2511 | |
2512 | if (length == 0xffffffff) | |
2513 | { | |
0c588247 | 2514 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
2515 | section_begin += length + 12; |
2516 | } | |
ec4d4525 NC |
2517 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
2518 | { | |
767221a9 NC |
2519 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
2520 | dwarf_vmatoa ("x", length), section->name); | |
ec4d4525 NC |
2521 | return 0; |
2522 | } | |
19e6b90e L |
2523 | else |
2524 | section_begin += length + 4; | |
aca88567 NC |
2525 | |
2526 | /* Negative values are illegal, they may even cause infinite | |
2527 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
2528 | relocations to an object file, or if the file is corrupt. */ |
2529 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 2530 | { |
767221a9 NC |
2531 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
2532 | dwarf_vmatoa ("x", length), section->name); | |
aca88567 NC |
2533 | return 0; |
2534 | } | |
19e6b90e L |
2535 | } |
2536 | ||
2537 | if (num_units == 0) | |
2538 | { | |
f41e4712 | 2539 | error (_("No comp units in %s section ?\n"), section->name); |
19e6b90e L |
2540 | return 0; |
2541 | } | |
2542 | ||
2543 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 2544 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 2545 | sizeof (* debug_information)); |
19e6b90e L |
2546 | if (debug_information == NULL) |
2547 | { | |
f41e4712 | 2548 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 2549 | num_units); |
82b1b41b | 2550 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e L |
2551 | return 0; |
2552 | } | |
03a91817 NC |
2553 | /* PR 17531: file: 92ca3797. |
2554 | We cannot rely upon the debug_information array being initialised | |
2555 | before it is used. A corrupt file could easily contain references | |
2556 | to a unit for which information has not been made available. So | |
2557 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
2558 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
2559 | ||
82b1b41b | 2560 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
2561 | } |
2562 | ||
2563 | if (!do_loc) | |
2564 | { | |
fd2f0033 TT |
2565 | if (dwarf_start_die == 0) |
2566 | printf (_("Contents of the %s section:\n\n"), section->name); | |
19e6b90e L |
2567 | |
2568 | load_debug_section (str, file); | |
77145576 | 2569 | load_debug_section (line_str, file); |
4723351a CC |
2570 | load_debug_section (str_dwo, file); |
2571 | load_debug_section (str_index, file); | |
2572 | load_debug_section (str_index_dwo, file); | |
2573 | load_debug_section (debug_addr, file); | |
19e6b90e L |
2574 | } |
2575 | ||
6f875884 TG |
2576 | load_debug_section (abbrev_sec, file); |
2577 | if (debug_displays [abbrev_sec].section.start == NULL) | |
19e6b90e L |
2578 | { |
2579 | warn (_("Unable to locate %s section!\n"), | |
6f875884 | 2580 | debug_displays [abbrev_sec].section.name); |
19e6b90e L |
2581 | return 0; |
2582 | } | |
2583 | ||
2584 | for (section_begin = start, unit = 0; start < end; unit++) | |
2585 | { | |
2586 | DWARF2_Internal_CompUnit compunit; | |
2587 | unsigned char *hdrptr; | |
19e6b90e | 2588 | unsigned char *tags; |
fd2f0033 | 2589 | int level, last_level, saved_level; |
467c65bc | 2590 | dwarf_vma cu_offset; |
bf5117e3 | 2591 | unsigned int offset_size; |
19e6b90e | 2592 | int initial_length_size; |
74bc6052 CC |
2593 | dwarf_vma signature_high = 0; |
2594 | dwarf_vma signature_low = 0; | |
767221a9 | 2595 | dwarf_vma type_offset = 0; |
341f9135 CC |
2596 | struct cu_tu_set *this_set; |
2597 | dwarf_vma abbrev_base; | |
2598 | size_t abbrev_size; | |
19e6b90e L |
2599 | |
2600 | hdrptr = start; | |
2601 | ||
0c588247 | 2602 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
2603 | |
2604 | if (compunit.cu_length == 0xffffffff) | |
2605 | { | |
0c588247 | 2606 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
2607 | offset_size = 8; |
2608 | initial_length_size = 12; | |
2609 | } | |
2610 | else | |
2611 | { | |
2612 | offset_size = 4; | |
2613 | initial_length_size = 4; | |
2614 | } | |
2615 | ||
0c588247 | 2616 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
2617 | |
2618 | cu_offset = start - section_begin; | |
19e6b90e | 2619 | |
341f9135 CC |
2620 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
2621 | ||
77145576 JK |
2622 | if (compunit.cu_version < 5) |
2623 | { | |
2624 | compunit.cu_unit_type = DW_UT_compile; | |
2625 | /* Initialize it due to a false compiler warning. */ | |
2626 | compunit.cu_pointer_size = -1; | |
2627 | } | |
2628 | else | |
2629 | { | |
2630 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
2631 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
2632 | ||
2633 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
2634 | } | |
2635 | ||
0c588247 | 2636 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 2637 | |
341f9135 CC |
2638 | if (this_set == NULL) |
2639 | { | |
2640 | abbrev_base = 0; | |
2641 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
2642 | } | |
2643 | else | |
2644 | { | |
2645 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
2646 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
2647 | } | |
2648 | ||
77145576 JK |
2649 | if (compunit.cu_version < 5) |
2650 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
2651 | ||
f41e4712 NC |
2652 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
2653 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
2654 | { | |
2655 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
2656 | compunit.cu_pointer_size, offset_size); | |
2657 | compunit.cu_pointer_size = offset_size; | |
2658 | } | |
2b6f5997 CC |
2659 | |
2660 | if (do_types) | |
b4eb7656 | 2661 | { |
0c588247 | 2662 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 2663 | hdrptr += 8; |
0c588247 | 2664 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 2665 | } |
2b6f5997 | 2666 | |
19e6b90e | 2667 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
2668 | && num_debug_info_entries == 0 |
2669 | && ! do_types) | |
19e6b90e L |
2670 | { |
2671 | debug_information [unit].cu_offset = cu_offset; | |
2672 | debug_information [unit].pointer_size | |
2673 | = compunit.cu_pointer_size; | |
b7807392 JJ |
2674 | debug_information [unit].offset_size = offset_size; |
2675 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 2676 | debug_information [unit].base_address = 0; |
4723351a CC |
2677 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
2678 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
2679 | debug_information [unit].loc_offsets = NULL; |
2680 | debug_information [unit].have_frame_base = NULL; | |
2681 | debug_information [unit].max_loc_offsets = 0; | |
2682 | debug_information [unit].num_loc_offsets = 0; | |
2683 | debug_information [unit].range_lists = NULL; | |
2684 | debug_information [unit].max_range_lists= 0; | |
2685 | debug_information [unit].num_range_lists = 0; | |
2686 | } | |
2687 | ||
fd2f0033 | 2688 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 2689 | { |
47704ddf KT |
2690 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
2691 | dwarf_vmatoa ("x", cu_offset)); | |
2692 | printf (_(" Length: 0x%s (%s)\n"), | |
2693 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 2694 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 2695 | printf (_(" Version: %d\n"), compunit.cu_version); |
7282333f AM |
2696 | printf (_(" Abbrev Offset: 0x%s\n"), |
2697 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 2698 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
2699 | if (do_types) |
2700 | { | |
74bc6052 CC |
2701 | char buf[64]; |
2702 | ||
2703 | printf (_(" Signature: 0x%s\n"), | |
2704 | dwarf_vmatoa64 (signature_high, signature_low, | |
2705 | buf, sizeof (buf))); | |
2706 | printf (_(" Type Offset: 0x%s\n"), | |
2707 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 2708 | } |
341f9135 CC |
2709 | if (this_set != NULL) |
2710 | { | |
2711 | dwarf_vma *offsets = this_set->section_offsets; | |
2712 | size_t *sizes = this_set->section_sizes; | |
2713 | ||
2714 | printf (_(" Section contributions:\n")); | |
2715 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
2716 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
2717 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
2718 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
2719 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
2720 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
2721 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
2722 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
2723 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
2724 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
2725 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
2726 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
2727 | } | |
19e6b90e L |
2728 | } |
2729 | ||
460c89ff NS |
2730 | if (cu_offset + compunit.cu_length + initial_length_size |
2731 | > section->size) | |
2732 | { | |
47704ddf | 2733 | warn (_("Debug info is corrupted, length of CU at %s" |
b4eb7656 | 2734 | " extends beyond end of section (length = %s)\n"), |
47704ddf KT |
2735 | dwarf_vmatoa ("x", cu_offset), |
2736 | dwarf_vmatoa ("x", compunit.cu_length)); | |
57028622 | 2737 | num_units = unit; |
460c89ff NS |
2738 | break; |
2739 | } | |
2740 | tags = hdrptr; | |
2741 | start += compunit.cu_length + initial_length_size; | |
2742 | ||
57028622 NC |
2743 | if (start > end) |
2744 | { | |
2745 | warn (_("Debug info is corrupt. CU at %s extends beyond end of section"), | |
2746 | dwarf_vmatoa ("x", cu_offset)); | |
2747 | start = end; | |
2748 | } | |
2749 | ||
77145576 | 2750 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 2751 | { |
47704ddf KT |
2752 | warn (_("CU at offset %s contains corrupt or " |
2753 | "unsupported version number: %d.\n"), | |
2754 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
2755 | continue; |
2756 | } | |
2757 | ||
77145576 JK |
2758 | if (compunit.cu_unit_type != DW_UT_compile |
2759 | && compunit.cu_unit_type != DW_UT_type) | |
2760 | { | |
2761 | warn (_("CU at offset %s contains corrupt or " | |
2762 | "unsupported unit type: %d.\n"), | |
2763 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
2764 | continue; | |
2765 | } | |
2766 | ||
19e6b90e L |
2767 | free_abbrevs (); |
2768 | ||
d493b283 | 2769 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 2770 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
2771 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
2772 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 2773 | (unsigned long) abbrev_size); |
b4eb7656 | 2774 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
2775 | else if ((abbrev_base + abbrev_size) |
2776 | > debug_displays [abbrev_sec].section.size) | |
2777 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
2778 | (unsigned long) abbrev_base + abbrev_size, | |
2779 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
2780 | else |
2781 | process_abbrev_section | |
341f9135 CC |
2782 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
2783 | + abbrev_base + compunit.cu_abbrev_offset), | |
2784 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
2785 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
2786 | |
2787 | level = 0; | |
fd2f0033 TT |
2788 | last_level = level; |
2789 | saved_level = -1; | |
19e6b90e L |
2790 | while (tags < start) |
2791 | { | |
2792 | unsigned int bytes_read; | |
2793 | unsigned long abbrev_number; | |
ec4d4525 | 2794 | unsigned long die_offset; |
19e6b90e L |
2795 | abbrev_entry *entry; |
2796 | abbrev_attr *attr; | |
fd2f0033 | 2797 | int do_printing = 1; |
19e6b90e | 2798 | |
ec4d4525 NC |
2799 | die_offset = tags - section_begin; |
2800 | ||
f6f0e17b | 2801 | abbrev_number = read_uleb128 (tags, & bytes_read, start); |
19e6b90e L |
2802 | tags += bytes_read; |
2803 | ||
eb7cc021 JK |
2804 | /* A null DIE marks the end of a list of siblings or it may also be |
2805 | a section padding. */ | |
19e6b90e L |
2806 | if (abbrev_number == 0) |
2807 | { | |
eb7cc021 JK |
2808 | /* Check if it can be a section padding for the last CU. */ |
2809 | if (level == 0 && start == end) | |
2810 | { | |
2811 | unsigned char *chk; | |
2812 | ||
2813 | for (chk = tags; chk < start; chk++) | |
2814 | if (*chk != 0) | |
2815 | break; | |
2816 | if (chk == start) | |
2817 | break; | |
2818 | } | |
2819 | ||
4337774f TT |
2820 | if (!do_loc && die_offset >= dwarf_start_die |
2821 | && (dwarf_cutoff_level == -1 | |
2822 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
2823 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
2824 | level, die_offset); | |
2825 | ||
19e6b90e | 2826 | --level; |
ec4d4525 NC |
2827 | if (level < 0) |
2828 | { | |
2829 | static unsigned num_bogus_warns = 0; | |
2830 | ||
2831 | if (num_bogus_warns < 3) | |
2832 | { | |
4723351a CC |
2833 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
2834 | die_offset, section->name); | |
ec4d4525 NC |
2835 | num_bogus_warns ++; |
2836 | if (num_bogus_warns == 3) | |
2837 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
2838 | } | |
2839 | } | |
fd2f0033 TT |
2840 | if (dwarf_start_die != 0 && level < saved_level) |
2841 | return 1; | |
19e6b90e L |
2842 | continue; |
2843 | } | |
2844 | ||
4b78141a | 2845 | if (!do_loc) |
fd2f0033 TT |
2846 | { |
2847 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
2848 | do_printing = 0; | |
2849 | else | |
2850 | { | |
2851 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
2852 | saved_level = level; | |
2853 | do_printing = (dwarf_cutoff_level == -1 | |
2854 | || level < dwarf_cutoff_level); | |
2855 | if (do_printing) | |
2856 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
2857 | level, die_offset, abbrev_number); | |
2858 | else if (dwarf_cutoff_level == -1 | |
2859 | || last_level < dwarf_cutoff_level) | |
2860 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
2861 | last_level = level; | |
2862 | } | |
2863 | } | |
cecf136e | 2864 | |
19e6b90e L |
2865 | /* Scan through the abbreviation list until we reach the |
2866 | correct entry. */ | |
2867 | for (entry = first_abbrev; | |
2868 | entry && entry->entry != abbrev_number; | |
2869 | entry = entry->next) | |
2870 | continue; | |
2871 | ||
2872 | if (entry == NULL) | |
2873 | { | |
fd2f0033 | 2874 | if (!do_loc && do_printing) |
4b78141a NC |
2875 | { |
2876 | printf ("\n"); | |
2877 | fflush (stdout); | |
2878 | } | |
f3853b34 | 2879 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 2880 | die_offset, abbrev_number); |
19e6b90e L |
2881 | return 0; |
2882 | } | |
2883 | ||
fd2f0033 | 2884 | if (!do_loc && do_printing) |
cc5914eb | 2885 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 2886 | |
19e6b90e L |
2887 | switch (entry->tag) |
2888 | { | |
2889 | default: | |
2890 | need_base_address = 0; | |
2891 | break; | |
2892 | case DW_TAG_compile_unit: | |
2893 | need_base_address = 1; | |
2894 | break; | |
2895 | case DW_TAG_entry_point: | |
19e6b90e L |
2896 | case DW_TAG_subprogram: |
2897 | need_base_address = 0; | |
2898 | /* Assuming that there is no DW_AT_frame_base. */ | |
2899 | have_frame_base = 0; | |
2900 | break; | |
2901 | } | |
2902 | ||
9f272209 AO |
2903 | debug_info *debug_info_p = |
2904 | (debug_information && unit < alloc_num_debug_info_entries) | |
2905 | ? debug_information + unit : NULL; | |
2906 | ||
2907 | assert (!debug_info_p | |
2908 | || (debug_info_p->num_loc_offsets | |
2909 | == debug_info_p->num_loc_views)); | |
2910 | ||
399c99f7 L |
2911 | for (attr = entry->first_attr; |
2912 | attr && attr->attribute; | |
2913 | attr = attr->next) | |
4b78141a | 2914 | { |
fd2f0033 | 2915 | if (! do_loc && do_printing) |
4b78141a | 2916 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 TT |
2917 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
2918 | ||
4b78141a NC |
2919 | tags = read_and_display_attr (attr->attribute, |
2920 | attr->form, | |
77145576 | 2921 | attr->implicit_const, |
341f9135 | 2922 | tags, |
f6f0e17b | 2923 | end, |
341f9135 | 2924 | cu_offset, |
4b78141a NC |
2925 | compunit.cu_pointer_size, |
2926 | offset_size, | |
2927 | compunit.cu_version, | |
9f272209 | 2928 | debug_info_p, |
341f9135 CC |
2929 | do_loc || ! do_printing, |
2930 | section, | |
2931 | this_set); | |
4b78141a | 2932 | } |
cecf136e | 2933 | |
9f272209 AO |
2934 | /* If a locview attribute appears before a location one, |
2935 | make sure we don't associate it with an earlier | |
2936 | loclist. */ | |
2937 | if (debug_info_p) | |
2938 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
2939 | { | |
2940 | case 1: | |
2941 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
2942 | debug_info_p->num_loc_views++; | |
2943 | assert (debug_info_p->num_loc_views | |
2944 | == debug_info_p->num_loc_offsets); | |
2945 | break; | |
2946 | ||
2947 | case 0: | |
2948 | break; | |
2949 | ||
2950 | case -1: | |
2951 | warn(_("DIE has locviews without loclist\n")); | |
2952 | debug_info_p->num_loc_views--; | |
2953 | break; | |
2954 | ||
2955 | default: | |
2956 | assert (0); | |
2957 | } | |
2958 | ||
b4eb7656 AM |
2959 | if (entry->children) |
2960 | ++level; | |
2961 | } | |
19e6b90e | 2962 | } |
cecf136e | 2963 | |
19e6b90e L |
2964 | /* Set num_debug_info_entries here so that it can be used to check if |
2965 | we need to process .debug_loc and .debug_ranges sections. */ | |
2966 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2967 | && num_debug_info_entries == 0 |
2968 | && ! do_types) | |
82b1b41b | 2969 | { |
b4eb7656 | 2970 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
2971 | num_debug_info_entries = alloc_num_debug_info_entries; |
2972 | else | |
2973 | num_debug_info_entries = num_units; | |
2974 | } | |
cecf136e | 2975 | |
19e6b90e | 2976 | if (!do_loc) |
467c65bc | 2977 | printf ("\n"); |
cecf136e | 2978 | |
19e6b90e L |
2979 | return 1; |
2980 | } | |
2981 | ||
2982 | /* Locate and scan the .debug_info section in the file and record the pointer | |
2983 | sizes and offsets for the compilation units in it. Usually an executable | |
2984 | will have just one pointer size, but this is not guaranteed, and so we try | |
2985 | not to make any assumptions. Returns zero upon failure, or the number of | |
2986 | compilation units upon success. */ | |
2987 | ||
2988 | static unsigned int | |
2989 | load_debug_info (void * file) | |
2990 | { | |
1febe64d | 2991 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 2992 | section then do not bother to repeat the task. */ |
cc86f28f | 2993 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
2994 | return 0; |
2995 | ||
19e6b90e L |
2996 | /* If we already have the information there is nothing else to do. */ |
2997 | if (num_debug_info_entries > 0) | |
2998 | return num_debug_info_entries; | |
2999 | ||
341f9135 | 3000 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 3001 | (void) load_cu_tu_indexes (file); |
341f9135 | 3002 | |
19e6b90e | 3003 | if (load_debug_section (info, file) |
6f875884 | 3004 | && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0)) |
19e6b90e | 3005 | return num_debug_info_entries; |
82b1b41b NC |
3006 | |
3007 | if (load_debug_section (info_dwo, file) | |
3008 | && process_debug_info (&debug_displays [info_dwo].section, file, | |
3009 | abbrev_dwo, 1, 0)) | |
4723351a | 3010 | return num_debug_info_entries; |
1febe64d | 3011 | |
cc86f28f | 3012 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 3013 | return 0; |
19e6b90e L |
3014 | } |
3015 | ||
b40bf0a2 NC |
3016 | /* Read a DWARF .debug_line section header starting at DATA. |
3017 | Upon success returns an updated DATA pointer and the LINFO | |
3018 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
3019 | Otherwise returns NULL. */ | |
19e6b90e | 3020 | |
b40bf0a2 NC |
3021 | static unsigned char * |
3022 | read_debug_line_header (struct dwarf_section * section, | |
3023 | unsigned char * data, | |
3024 | unsigned char * end, | |
3025 | DWARF2_Internal_LineInfo * linfo, | |
3026 | unsigned char ** end_of_sequence) | |
3027 | { | |
3028 | unsigned char *hdrptr; | |
b40bf0a2 | 3029 | unsigned int initial_length_size; |
77145576 | 3030 | unsigned char address_size, segment_selector_size; |
19e6b90e | 3031 | |
b40bf0a2 NC |
3032 | /* Extract information from the Line Number Program Header. |
3033 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 3034 | hdrptr = data; |
19e6b90e | 3035 | |
b40bf0a2 NC |
3036 | /* Get and check the length of the block. */ |
3037 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 3038 | |
b40bf0a2 | 3039 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
3040 | { |
3041 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 3042 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 3043 | linfo->li_offset_size = 8; |
f41e4712 NC |
3044 | initial_length_size = 12; |
3045 | } | |
3046 | else | |
3047 | { | |
77145576 | 3048 | linfo->li_offset_size = 4; |
f41e4712 NC |
3049 | initial_length_size = 4; |
3050 | } | |
19e6b90e | 3051 | |
b40bf0a2 | 3052 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 3053 | { |
8fcc61b4 NC |
3054 | /* If the length field has a relocation against it, then we should |
3055 | not complain if it is inaccurate (and probably negative). This | |
3056 | happens in object files when the .debug_line section is actually | |
3057 | comprised of several different .debug_line.* sections, (some of | |
3058 | which may be removed by linker garbage collection), and a relocation | |
3059 | is used to compute the correct length once that is done. */ | |
77145576 | 3060 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 3061 | { |
8fcc61b4 | 3062 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
3063 | } |
3064 | else | |
3065 | { | |
8fcc61b4 NC |
3066 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
3067 | (long) linfo->li_length); | |
b40bf0a2 NC |
3068 | return NULL; |
3069 | } | |
f41e4712 | 3070 | } |
19e6b90e | 3071 | |
b40bf0a2 NC |
3072 | /* Get and check the version number. */ |
3073 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
3074 | ||
3075 | if (linfo->li_version != 2 | |
3076 | && linfo->li_version != 3 | |
77145576 JK |
3077 | && linfo->li_version != 4 |
3078 | && linfo->li_version != 5) | |
f41e4712 | 3079 | { |
77145576 JK |
3080 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
3081 | "is currently supported.\n")); | |
b40bf0a2 | 3082 | return NULL; |
f41e4712 | 3083 | } |
19e6b90e | 3084 | |
77145576 JK |
3085 | if (linfo->li_version >= 5) |
3086 | { | |
3087 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
3088 | ||
3089 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
3090 | if (segment_selector_size != 0) | |
3091 | { | |
3092 | warn (_("The %s section contains " | |
3093 | "unsupported segment selector size: %d.\n"), | |
3094 | section->name, segment_selector_size); | |
3095 | return 0; | |
3096 | } | |
3097 | } | |
3098 | ||
3099 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
3100 | linfo->li_offset_size, end); | |
b40bf0a2 | 3101 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 3102 | |
b40bf0a2 | 3103 | if (linfo->li_version >= 4) |
f41e4712 | 3104 | { |
b40bf0a2 | 3105 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 3106 | |
b40bf0a2 | 3107 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
3108 | { |
3109 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 3110 | return NULL; |
a233b20c | 3111 | } |
f41e4712 NC |
3112 | } |
3113 | else | |
b40bf0a2 | 3114 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 3115 | |
b40bf0a2 | 3116 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 3117 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
3118 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
3119 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 3120 | |
b40bf0a2 | 3121 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 3122 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
3123 | if (* end_of_sequence > end) |
3124 | { | |
4c219c2e AM |
3125 | warn (_("Line length %s extends beyond end of section\n"), |
3126 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
3127 | * end_of_sequence = end; |
3128 | return NULL; | |
3129 | } | |
3130 | ||
b40bf0a2 NC |
3131 | return hdrptr; |
3132 | } | |
19e6b90e | 3133 | |
77145576 JK |
3134 | static unsigned char * |
3135 | display_formatted_table (unsigned char *data, | |
3136 | unsigned char *start, unsigned char *end, | |
3137 | const DWARF2_Internal_LineInfo *linfo, | |
3138 | struct dwarf_section *section, const char *what) | |
3139 | { | |
3140 | unsigned char *format_start, format_count, *format, formati; | |
3141 | dwarf_vma data_count, datai; | |
3142 | unsigned int bytes_read, namepass, last_entry = 0; | |
3143 | ||
3144 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3145 | format_start = data; | |
3146 | for (formati = 0; formati < format_count; formati++) | |
3147 | { | |
3148 | read_uleb128 (data, & bytes_read, end); | |
3149 | data += bytes_read; | |
3150 | read_uleb128 (data, & bytes_read, end); | |
3151 | data += bytes_read; | |
3152 | if (data == end) | |
3153 | { | |
14357de1 | 3154 | warn (_("Corrupt %s format table entry\n"), what); |
77145576 JK |
3155 | return data; |
3156 | } | |
3157 | } | |
3158 | ||
3159 | data_count = read_uleb128 (data, & bytes_read, end); | |
3160 | data += bytes_read; | |
3161 | if (data == end) | |
3162 | { | |
3163 | warn (_("Corrupt %s list\n"), what); | |
3164 | return data; | |
3165 | } | |
3166 | ||
3167 | if (data_count == 0) | |
3168 | { | |
3169 | printf (_("\n The %s Table is empty.\n"), what); | |
3170 | return data; | |
3171 | } | |
3172 | ||
3173 | printf (_("\n The %s Table (offset 0x%lx):\n"), what, | |
3174 | (long)(data - start)); | |
3175 | ||
3176 | printf (_(" Entry")); | |
3177 | /* Delay displaying name as the last entry for better screen layout. */ | |
3178 | for (namepass = 0; namepass < 2; namepass++) | |
3179 | { | |
3180 | format = format_start; | |
3181 | for (formati = 0; formati < format_count; formati++) | |
3182 | { | |
3183 | dwarf_vma content_type; | |
3184 | ||
3185 | content_type = read_uleb128 (format, & bytes_read, end); | |
3186 | format += bytes_read; | |
3187 | if ((content_type == DW_LNCT_path) == (namepass == 1)) | |
3188 | switch (content_type) | |
3189 | { | |
3190 | case DW_LNCT_path: | |
3191 | printf (_("\tName")); | |
3192 | break; | |
3193 | case DW_LNCT_directory_index: | |
3194 | printf (_("\tDir")); | |
3195 | break; | |
3196 | case DW_LNCT_timestamp: | |
3197 | printf (_("\tTime")); | |
3198 | break; | |
3199 | case DW_LNCT_size: | |
3200 | printf (_("\tSize")); | |
3201 | break; | |
3202 | case DW_LNCT_MD5: | |
3203 | printf (_("\tMD5")); | |
3204 | break; | |
3205 | default: | |
3206 | printf (_("\t(Unknown format content type %s)"), | |
3207 | dwarf_vmatoa ("u", content_type)); | |
3208 | } | |
3209 | read_uleb128 (format, & bytes_read, end); | |
3210 | format += bytes_read; | |
3211 | } | |
3212 | } | |
3213 | putchar ('\n'); | |
3214 | ||
3215 | for (datai = 0; datai < data_count; datai++) | |
3216 | { | |
3217 | unsigned char *datapass = data; | |
3218 | ||
3219 | printf (" %d", last_entry++); | |
3220 | /* Delay displaying name as the last entry for better screen layout. */ | |
3221 | for (namepass = 0; namepass < 2; namepass++) | |
3222 | { | |
3223 | format = format_start; | |
3224 | data = datapass; | |
3225 | for (formati = 0; formati < format_count; formati++) | |
3226 | { | |
3227 | dwarf_vma content_type, form; | |
3228 | ||
3229 | content_type = read_uleb128 (format, & bytes_read, end); | |
3230 | format += bytes_read; | |
3231 | form = read_uleb128 (format, & bytes_read, end); | |
3232 | format += bytes_read; | |
3233 | data = read_and_display_attr_value (0, form, 0, data, end, 0, 0, | |
3234 | linfo->li_offset_size, | |
3235 | linfo->li_version, NULL, | |
3236 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
3237 | section, NULL, '\t'); | |
3238 | } | |
3239 | } | |
3240 | if (data == end) | |
3241 | { | |
3242 | warn (_("Corrupt %s entries list\n"), what); | |
3243 | return data; | |
3244 | } | |
3245 | putchar ('\n'); | |
3246 | } | |
3247 | return data; | |
3248 | } | |
3249 | ||
b40bf0a2 NC |
3250 | static int |
3251 | display_debug_lines_raw (struct dwarf_section *section, | |
3252 | unsigned char *data, | |
77145576 | 3253 | unsigned char *end, void *file) |
b40bf0a2 NC |
3254 | { |
3255 | unsigned char *start = section->start; | |
ba8826a8 | 3256 | int verbose_view = 0; |
19e6b90e | 3257 | |
b40bf0a2 | 3258 | printf (_("Raw dump of debug contents of section %s:\n\n"), |
b4eb7656 | 3259 | section->name); |
19e6b90e | 3260 | |
b40bf0a2 NC |
3261 | while (data < end) |
3262 | { | |
3263 | static DWARF2_Internal_LineInfo saved_linfo; | |
3264 | DWARF2_Internal_LineInfo linfo; | |
3265 | unsigned char *standard_opcodes; | |
3266 | unsigned char *end_of_sequence; | |
fe59e83d | 3267 | int i; |
19e6b90e | 3268 | |
4925cdd7 NC |
3269 | if (const_strneq (section->name, ".debug_line.") |
3270 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3271 | These are full debug_line sections. */ | |
3272 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 3273 | { |
b40bf0a2 NC |
3274 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
3275 | section containing just the Line Number Statements. They are | |
3276 | created by the assembler and intended to be used alongside gcc's | |
3277 | -ffunction-sections command line option. When the linker's | |
3278 | garbage collection decides to discard a .text.<foo> section it | |
3279 | can then also discard the line number information in .debug_line.<foo>. | |
3280 | ||
4925cdd7 | 3281 | Since the section is a fragment it does not have the details |
b40bf0a2 | 3282 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 3283 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
3284 | end_of_sequence = end; |
3285 | standard_opcodes = NULL; | |
3286 | linfo = saved_linfo; | |
058037d3 NC |
3287 | /* PR 17531: file: 0522b371. */ |
3288 | if (linfo.li_line_range == 0) | |
3289 | { | |
1306a742 | 3290 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3291 | return 0; |
3292 | } | |
b40bf0a2 | 3293 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3294 | } |
19e6b90e L |
3295 | else |
3296 | { | |
b40bf0a2 | 3297 | unsigned char * hdrptr; |
19e6b90e | 3298 | |
b40bf0a2 NC |
3299 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3300 | & end_of_sequence)) == NULL) | |
3301 | return 0; | |
19e6b90e | 3302 | |
b40bf0a2 NC |
3303 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
3304 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
3305 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
77ef8654 | 3306 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
3307 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
3308 | if (linfo.li_version >= 4) | |
3309 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
3310 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
3311 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
3312 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
3313 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 3314 | |
0a9d414a NC |
3315 | /* PR 17512: file: 1665-6428-0.004. */ |
3316 | if (linfo.li_line_range == 0) | |
3317 | { | |
3318 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
3319 | linfo.li_line_range = 1; | |
3320 | } | |
77ef8654 | 3321 | |
b40bf0a2 | 3322 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3323 | |
b40bf0a2 NC |
3324 | /* Display the contents of the Opcodes table. */ |
3325 | standard_opcodes = hdrptr; | |
19e6b90e | 3326 | |
6937bb54 NC |
3327 | /* PR 17512: file: 002-417945-0.004. */ |
3328 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
3329 | { | |
3330 | warn (_("Line Base extends beyond end of section\n")); | |
3331 | return 0; | |
3332 | } | |
3333 | ||
b40bf0a2 | 3334 | printf (_("\n Opcodes:\n")); |
19e6b90e | 3335 | |
b40bf0a2 NC |
3336 | for (i = 1; i < linfo.li_opcode_base; i++) |
3337 | printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); | |
19e6b90e | 3338 | |
b40bf0a2 NC |
3339 | /* Display the contents of the Directory table. */ |
3340 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 3341 | |
77145576 | 3342 | if (linfo.li_version >= 5) |
b40bf0a2 | 3343 | { |
77145576 | 3344 | load_debug_section (line_str, file); |
19e6b90e | 3345 | |
77145576 JK |
3346 | data = display_formatted_table (data, start, end, &linfo, section, |
3347 | _("Directory")); | |
3348 | data = display_formatted_table (data, start, end, &linfo, section, | |
3349 | _("File name")); | |
3350 | } | |
3351 | else | |
3352 | { | |
3353 | if (*data == 0) | |
3354 | printf (_("\n The Directory Table is empty.\n")); | |
3355 | else | |
a233b20c | 3356 | { |
77145576 | 3357 | unsigned int last_dir_entry = 0; |
6937bb54 | 3358 | |
77145576 JK |
3359 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
3360 | (long)(data - start)); | |
19e6b90e | 3361 | |
77145576 JK |
3362 | while (data < end && *data != 0) |
3363 | { | |
3364 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 3365 | |
77145576 JK |
3366 | data += strnlen ((char *) data, end - data) + 1; |
3367 | } | |
19e6b90e | 3368 | |
77145576 JK |
3369 | /* PR 17512: file: 002-132094-0.004. */ |
3370 | if (data >= end - 1) | |
3371 | break; | |
3372 | } | |
19e6b90e | 3373 | |
77145576 JK |
3374 | /* Skip the NUL at the end of the table. */ |
3375 | data++; | |
19e6b90e | 3376 | |
77145576 JK |
3377 | /* Display the contents of the File Name table. */ |
3378 | if (*data == 0) | |
3379 | printf (_("\n The File Name Table is empty.\n")); | |
3380 | else | |
3381 | { | |
3382 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3383 | (long)(data - start)); | |
3384 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 3385 | |
77145576 | 3386 | while (data < end && *data != 0) |
b40bf0a2 | 3387 | { |
77145576 JK |
3388 | unsigned char *name; |
3389 | unsigned int bytes_read; | |
3390 | ||
3391 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
3392 | name = data; | |
3393 | data += strnlen ((char *) data, end - data) + 1; | |
3394 | ||
3395 | printf ("%s\t", | |
3396 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3397 | data += bytes_read; | |
3398 | printf ("%s\t", | |
3399 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3400 | data += bytes_read; | |
3401 | printf ("%s\t", | |
3402 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3403 | data += bytes_read; | |
3404 | printf ("%.*s\n", (int)(end - name), name); | |
3405 | ||
3406 | if (data == end) | |
3407 | { | |
3408 | warn (_("Corrupt file name table entry\n")); | |
3409 | break; | |
3410 | } | |
b40bf0a2 | 3411 | } |
a233b20c | 3412 | } |
77145576 JK |
3413 | |
3414 | /* Skip the NUL at the end of the table. */ | |
3415 | data++; | |
b40bf0a2 | 3416 | } |
19e6b90e | 3417 | |
b40bf0a2 NC |
3418 | putchar ('\n'); |
3419 | saved_linfo = linfo; | |
3420 | } | |
19e6b90e | 3421 | |
b40bf0a2 NC |
3422 | /* Now display the statements. */ |
3423 | if (data >= end_of_sequence) | |
3424 | printf (_(" No Line Number Statements.\n")); | |
3425 | else | |
3426 | { | |
3427 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 3428 | |
b40bf0a2 NC |
3429 | while (data < end_of_sequence) |
3430 | { | |
3431 | unsigned char op_code; | |
3432 | dwarf_signed_vma adv; | |
3433 | dwarf_vma uladv; | |
3434 | unsigned int bytes_read; | |
19e6b90e | 3435 | |
fe59e83d CC |
3436 | printf (" [0x%08lx]", (long)(data - start)); |
3437 | ||
b40bf0a2 | 3438 | op_code = *data++; |
19e6b90e | 3439 | |
b40bf0a2 | 3440 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 3441 | { |
b40bf0a2 NC |
3442 | op_code -= linfo.li_opcode_base; |
3443 | uladv = (op_code / linfo.li_line_range); | |
3444 | if (linfo.li_max_ops_per_insn == 1) | |
3445 | { | |
3446 | uladv *= linfo.li_min_insn_length; | |
3447 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
3448 | if (uladv) |
3449 | state_machine_regs.view = 0; | |
b40bf0a2 | 3450 | printf (_(" Special opcode %d: " |
ba8826a8 | 3451 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 3452 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
3453 | dwarf_vmatoa ("x", state_machine_regs.address), |
3454 | verbose_view && uladv | |
3455 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3456 | } |
3457 | else | |
3458 | { | |
ba8826a8 AO |
3459 | unsigned addrdelta |
3460 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
3461 | / linfo.li_max_ops_per_insn) |
3462 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
3463 | |
3464 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
3465 | state_machine_regs.op_index |
3466 | = (state_machine_regs.op_index + uladv) | |
3467 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
3468 | if (addrdelta) |
3469 | state_machine_regs.view = 0; | |
b40bf0a2 | 3470 | printf (_(" Special opcode %d: " |
ba8826a8 | 3471 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
3472 | op_code, dwarf_vmatoa ("u", uladv), |
3473 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
3474 | state_machine_regs.op_index, |
3475 | verbose_view && addrdelta | |
3476 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3477 | } |
3478 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
3479 | state_machine_regs.line += adv; | |
ba8826a8 | 3480 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 3481 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
3482 | if (verbose_view || state_machine_regs.view) |
3483 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
3484 | else | |
3485 | putchar ('\n'); | |
3486 | state_machine_regs.view++; | |
19e6b90e | 3487 | } |
b40bf0a2 NC |
3488 | else switch (op_code) |
3489 | { | |
3490 | case DW_LNS_extended_op: | |
3491 | data += process_extended_line_op (data, linfo.li_default_is_stmt, end); | |
3492 | break; | |
3493 | ||
3494 | case DW_LNS_copy: | |
ba8826a8 AO |
3495 | printf (_(" Copy")); |
3496 | if (verbose_view || state_machine_regs.view) | |
3497 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
3498 | else | |
3499 | putchar ('\n'); | |
3500 | state_machine_regs.view++; | |
b40bf0a2 NC |
3501 | break; |
3502 | ||
3503 | case DW_LNS_advance_pc: | |
3504 | uladv = read_uleb128 (data, & bytes_read, end); | |
3505 | data += bytes_read; | |
3506 | if (linfo.li_max_ops_per_insn == 1) | |
3507 | { | |
3508 | uladv *= linfo.li_min_insn_length; | |
3509 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
3510 | if (uladv) |
3511 | state_machine_regs.view = 0; | |
3512 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
b40bf0a2 | 3513 | dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
3514 | dwarf_vmatoa ("x", state_machine_regs.address), |
3515 | verbose_view && uladv | |
3516 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3517 | } |
3518 | else | |
3519 | { | |
ba8826a8 AO |
3520 | unsigned addrdelta |
3521 | = ((state_machine_regs.op_index + uladv) | |
3522 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 3523 | * linfo.li_min_insn_length; |
ba8826a8 AO |
3524 | state_machine_regs.address |
3525 | += addrdelta; | |
b40bf0a2 NC |
3526 | state_machine_regs.op_index |
3527 | = (state_machine_regs.op_index + uladv) | |
3528 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
3529 | if (addrdelta) |
3530 | state_machine_regs.view = 0; | |
3531 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
b40bf0a2 NC |
3532 | dwarf_vmatoa ("u", uladv), |
3533 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
3534 | state_machine_regs.op_index, |
3535 | verbose_view && addrdelta | |
3536 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3537 | } |
3538 | break; | |
3539 | ||
3540 | case DW_LNS_advance_line: | |
3541 | adv = read_sleb128 (data, & bytes_read, end); | |
3542 | data += bytes_read; | |
3543 | state_machine_regs.line += adv; | |
3544 | printf (_(" Advance Line by %s to %d\n"), | |
3545 | dwarf_vmatoa ("d", adv), | |
3546 | state_machine_regs.line); | |
3547 | break; | |
3548 | ||
3549 | case DW_LNS_set_file: | |
3550 | adv = read_uleb128 (data, & bytes_read, end); | |
3551 | data += bytes_read; | |
3552 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
3553 | dwarf_vmatoa ("d", adv)); | |
3554 | state_machine_regs.file = adv; | |
3555 | break; | |
3556 | ||
3557 | case DW_LNS_set_column: | |
3558 | uladv = read_uleb128 (data, & bytes_read, end); | |
3559 | data += bytes_read; | |
3560 | printf (_(" Set column to %s\n"), | |
3561 | dwarf_vmatoa ("u", uladv)); | |
3562 | state_machine_regs.column = uladv; | |
3563 | break; | |
3564 | ||
3565 | case DW_LNS_negate_stmt: | |
3566 | adv = state_machine_regs.is_stmt; | |
3567 | adv = ! adv; | |
3568 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
3569 | state_machine_regs.is_stmt = adv; | |
3570 | break; | |
3571 | ||
3572 | case DW_LNS_set_basic_block: | |
3573 | printf (_(" Set basic block\n")); | |
3574 | state_machine_regs.basic_block = 1; | |
3575 | break; | |
3576 | ||
3577 | case DW_LNS_const_add_pc: | |
3578 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
3579 | if (linfo.li_max_ops_per_insn) | |
3580 | { | |
3581 | uladv *= linfo.li_min_insn_length; | |
3582 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
3583 | if (uladv) |
3584 | state_machine_regs.view = 0; | |
3585 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
b40bf0a2 | 3586 | dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
3587 | dwarf_vmatoa ("x", state_machine_regs.address), |
3588 | verbose_view && uladv | |
3589 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3590 | } |
3591 | else | |
3592 | { | |
ba8826a8 AO |
3593 | unsigned addrdelta |
3594 | = ((state_machine_regs.op_index + uladv) | |
3595 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 3596 | * linfo.li_min_insn_length; |
ba8826a8 AO |
3597 | state_machine_regs.address |
3598 | += addrdelta; | |
b40bf0a2 NC |
3599 | state_machine_regs.op_index |
3600 | = (state_machine_regs.op_index + uladv) | |
3601 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
3602 | if (addrdelta) |
3603 | state_machine_regs.view = 0; | |
3604 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
b40bf0a2 NC |
3605 | dwarf_vmatoa ("u", uladv), |
3606 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
3607 | state_machine_regs.op_index, |
3608 | verbose_view && addrdelta | |
3609 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3610 | } |
3611 | break; | |
3612 | ||
3613 | case DW_LNS_fixed_advance_pc: | |
3614 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
3615 | state_machine_regs.address += uladv; | |
3616 | state_machine_regs.op_index = 0; | |
3617 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
3618 | dwarf_vmatoa ("u", uladv), | |
3619 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
ba8826a8 | 3620 | /* Do NOT reset view. */ |
b40bf0a2 NC |
3621 | break; |
3622 | ||
3623 | case DW_LNS_set_prologue_end: | |
3624 | printf (_(" Set prologue_end to true\n")); | |
3625 | break; | |
3626 | ||
3627 | case DW_LNS_set_epilogue_begin: | |
3628 | printf (_(" Set epilogue_begin to true\n")); | |
3629 | break; | |
3630 | ||
3631 | case DW_LNS_set_isa: | |
3632 | uladv = read_uleb128 (data, & bytes_read, end); | |
3633 | data += bytes_read; | |
3634 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
3635 | break; | |
3636 | ||
3637 | default: | |
3638 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
3639 | ||
3640 | if (standard_opcodes != NULL) | |
3641 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
3642 | { | |
3643 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
3644 | &bytes_read, end)), | |
3645 | i == 1 ? "" : ", "); | |
3646 | data += bytes_read; | |
3647 | } | |
3648 | putchar ('\n'); | |
3649 | break; | |
3650 | } | |
19e6b90e | 3651 | } |
b40bf0a2 | 3652 | putchar ('\n'); |
19e6b90e | 3653 | } |
19e6b90e L |
3654 | } |
3655 | ||
3656 | return 1; | |
3657 | } | |
3658 | ||
a262ae96 NC |
3659 | typedef struct |
3660 | { | |
467c65bc NC |
3661 | unsigned char *name; |
3662 | unsigned int directory_index; | |
3663 | unsigned int modification_date; | |
3664 | unsigned int length; | |
a262ae96 NC |
3665 | } File_Entry; |
3666 | ||
3667 | /* Output a decoded representation of the .debug_line section. */ | |
3668 | ||
3669 | static int | |
3670 | display_debug_lines_decoded (struct dwarf_section *section, | |
3671 | unsigned char *data, | |
77145576 | 3672 | unsigned char *end, void *fileptr) |
a262ae96 | 3673 | { |
b40bf0a2 NC |
3674 | static DWARF2_Internal_LineInfo saved_linfo; |
3675 | ||
a262ae96 | 3676 | printf (_("Decoded dump of debug contents of section %s:\n\n"), |
b4eb7656 | 3677 | section->name); |
a262ae96 NC |
3678 | |
3679 | while (data < end) | |
3680 | { | |
3681 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 3682 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
3683 | unsigned char *standard_opcodes; |
3684 | unsigned char *end_of_sequence; | |
a262ae96 NC |
3685 | int i; |
3686 | File_Entry *file_table = NULL; | |
143a3db0 | 3687 | unsigned int n_files = 0; |
a262ae96 | 3688 | unsigned char **directory_table = NULL; |
77145576 | 3689 | dwarf_vma n_directories = 0; |
a262ae96 | 3690 | |
4925cdd7 NC |
3691 | if (const_strneq (section->name, ".debug_line.") |
3692 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3693 | These are full debug_line sections. */ | |
3694 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 3695 | { |
4925cdd7 | 3696 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
3697 | end_of_sequence = end; |
3698 | standard_opcodes = NULL; | |
3699 | linfo = saved_linfo; | |
058037d3 NC |
3700 | /* PR 17531: file: 0522b371. */ |
3701 | if (linfo.li_line_range == 0) | |
3702 | { | |
1306a742 | 3703 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3704 | return 0; |
3705 | } | |
b40bf0a2 | 3706 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 3707 | } |
a262ae96 | 3708 | else |
b4eb7656 | 3709 | { |
b40bf0a2 | 3710 | unsigned char *hdrptr; |
a262ae96 | 3711 | |
b40bf0a2 NC |
3712 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3713 | & end_of_sequence)) == NULL) | |
a233b20c | 3714 | return 0; |
0c588247 | 3715 | |
058037d3 NC |
3716 | /* PR 17531: file: 0522b371. */ |
3717 | if (linfo.li_line_range == 0) | |
3718 | { | |
3719 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
3720 | linfo.li_line_range = 1; | |
3721 | } | |
b40bf0a2 | 3722 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 3723 | |
b40bf0a2 NC |
3724 | /* Save a pointer to the contents of the Opcodes table. */ |
3725 | standard_opcodes = hdrptr; | |
a262ae96 | 3726 | |
b40bf0a2 NC |
3727 | /* Traverse the Directory table just to count entries. */ |
3728 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
3729 | /* PR 20440 */ |
3730 | if (data >= end) | |
3731 | { | |
3732 | warn (_("opcode base of %d extends beyond end of section\n"), | |
3733 | linfo.li_opcode_base); | |
3734 | return 0; | |
3735 | } | |
3736 | ||
77145576 | 3737 | if (linfo.li_version >= 5) |
b40bf0a2 | 3738 | { |
77145576 JK |
3739 | unsigned char *format_start, format_count, *format; |
3740 | dwarf_vma formati, entryi; | |
3741 | unsigned int bytes_read; | |
a262ae96 | 3742 | |
77145576 JK |
3743 | load_debug_section (line_str, fileptr); |
3744 | ||
3745 | /* Skip directories format. */ | |
3746 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3747 | format_start = data; | |
3748 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 3749 | { |
77145576 JK |
3750 | read_uleb128 (data, & bytes_read, end); |
3751 | data += bytes_read; | |
3752 | read_uleb128 (data, & bytes_read, end); | |
3753 | data += bytes_read; | |
b40bf0a2 | 3754 | } |
a262ae96 | 3755 | |
77145576 JK |
3756 | n_directories = read_uleb128 (data, & bytes_read, end); |
3757 | data += bytes_read; | |
3758 | if (data == end) | |
d8024a91 | 3759 | { |
77145576 | 3760 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
3761 | break; |
3762 | } | |
3763 | ||
b40bf0a2 NC |
3764 | directory_table = (unsigned char **) |
3765 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 3766 | |
77145576 | 3767 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 3768 | { |
77145576 | 3769 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 3770 | |
77145576 JK |
3771 | format = format_start; |
3772 | for (formati = 0; formati < format_count; formati++) | |
3773 | { | |
3774 | dwarf_vma content_type, form; | |
3775 | dwarf_vma uvalue; | |
3776 | ||
3777 | content_type = read_uleb128 (format, & bytes_read, end); | |
3778 | format += bytes_read; | |
3779 | form = read_uleb128 (format, & bytes_read, end); | |
3780 | format += bytes_read; | |
3781 | if (data == end) | |
3782 | { | |
3783 | warn (_("Corrupt directories list\n")); | |
3784 | break; | |
3785 | } | |
3786 | switch (content_type) | |
3787 | { | |
3788 | case DW_LNCT_path: | |
3789 | switch (form) | |
3790 | { | |
3791 | case DW_FORM_string: | |
3792 | *pathp = data; | |
3793 | break; | |
3794 | case DW_FORM_line_strp: | |
3795 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
3796 | end); | |
3797 | /* Remove const by the cast. */ | |
3798 | *pathp = (unsigned char *) | |
3799 | fetch_indirect_line_string (uvalue); | |
3800 | break; | |
3801 | } | |
3802 | break; | |
3803 | } | |
3804 | data = read_and_display_attr_value (0, form, 0, data, end, | |
3805 | 0, 0, | |
3806 | linfo.li_offset_size, | |
3807 | linfo.li_version, | |
3808 | NULL, 1, section, | |
3809 | NULL, '\t'); | |
3810 | } | |
3811 | if (data == end) | |
3812 | { | |
3813 | warn (_("Corrupt directories list\n")); | |
3814 | break; | |
3815 | } | |
3816 | } | |
a262ae96 | 3817 | |
77145576 JK |
3818 | /* Skip files format. */ |
3819 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3820 | format_start = data; | |
3821 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 3822 | { |
b40bf0a2 NC |
3823 | read_uleb128 (data, & bytes_read, end); |
3824 | data += bytes_read; | |
3825 | read_uleb128 (data, & bytes_read, end); | |
3826 | data += bytes_read; | |
b40bf0a2 | 3827 | } |
a262ae96 | 3828 | |
77145576 JK |
3829 | n_files = read_uleb128 (data, & bytes_read, end); |
3830 | data += bytes_read; | |
3831 | if (data == end) | |
d8024a91 | 3832 | { |
77145576 | 3833 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
3834 | break; |
3835 | } | |
3836 | ||
77145576 JK |
3837 | file_table = (File_Entry *) xcalloc (1, n_files |
3838 | * sizeof (File_Entry)); | |
a262ae96 | 3839 | |
77145576 | 3840 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 3841 | { |
77145576 | 3842 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 3843 | |
77145576 JK |
3844 | format = format_start; |
3845 | for (formati = 0; formati < format_count; formati++) | |
3846 | { | |
3847 | dwarf_vma content_type, form; | |
3848 | dwarf_vma uvalue; | |
3849 | ||
3850 | content_type = read_uleb128 (format, & bytes_read, end); | |
3851 | format += bytes_read; | |
3852 | form = read_uleb128 (format, & bytes_read, end); | |
3853 | format += bytes_read; | |
3854 | if (data == end) | |
3855 | { | |
3856 | warn (_("Corrupt file name list\n")); | |
3857 | break; | |
3858 | } | |
3859 | switch (content_type) | |
3860 | { | |
3861 | case DW_LNCT_path: | |
3862 | switch (form) | |
3863 | { | |
3864 | case DW_FORM_string: | |
3865 | file->name = data; | |
3866 | break; | |
3867 | case DW_FORM_line_strp: | |
3868 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
3869 | end); | |
3870 | /* Remove const by the cast. */ | |
3871 | file->name = (unsigned char *) | |
3872 | fetch_indirect_line_string (uvalue); | |
3873 | break; | |
3874 | } | |
3875 | break; | |
3876 | case DW_LNCT_directory_index: | |
3877 | switch (form) | |
3878 | { | |
3879 | case DW_FORM_data1: | |
3880 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
3881 | end); | |
3882 | break; | |
3883 | case DW_FORM_data2: | |
3884 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
3885 | end); | |
3886 | break; | |
3887 | case DW_FORM_udata: | |
3888 | file->directory_index = read_uleb128 (data, NULL, | |
3889 | end); | |
3890 | break; | |
3891 | } | |
3892 | break; | |
3893 | } | |
3894 | data = read_and_display_attr_value (0, form, 0, data, end, | |
3895 | 0, 0, | |
3896 | linfo.li_offset_size, | |
3897 | linfo.li_version, | |
3898 | NULL, 1, section, | |
3899 | NULL, '\t'); | |
3900 | } | |
3901 | if (data == end) | |
3902 | { | |
3903 | warn (_("Corrupt file name list\n")); | |
3904 | break; | |
3905 | } | |
3906 | } | |
3907 | } | |
3908 | else | |
3909 | { | |
3910 | if (*data != 0) | |
b40bf0a2 | 3911 | { |
77145576 JK |
3912 | unsigned char *ptr_directory_table = data; |
3913 | ||
3914 | while (data < end && *data != 0) | |
3915 | { | |
3916 | data += strnlen ((char *) data, end - data) + 1; | |
3917 | n_directories++; | |
3918 | } | |
3919 | ||
3920 | /* PR 20440 */ | |
3921 | if (data >= end) | |
3922 | { | |
3923 | warn (_("directory table ends unexpectedly\n")); | |
3924 | n_directories = 0; | |
3925 | break; | |
3926 | } | |
3927 | ||
3928 | /* Go through the directory table again to save the directories. */ | |
3929 | directory_table = (unsigned char **) | |
3930 | xmalloc (n_directories * sizeof (unsigned char *)); | |
3931 | ||
3932 | i = 0; | |
3933 | while (*ptr_directory_table != 0) | |
3934 | { | |
3935 | directory_table[i] = ptr_directory_table; | |
3936 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
3937 | ptr_directory_table - end) + 1; | |
3938 | i++; | |
3939 | } | |
b40bf0a2 | 3940 | } |
77145576 JK |
3941 | /* Skip the NUL at the end of the table. */ |
3942 | data++; | |
3943 | ||
3944 | /* Traverse the File Name table just to count the entries. */ | |
3945 | if (data < end && *data != 0) | |
b40bf0a2 | 3946 | { |
77145576 JK |
3947 | unsigned char *ptr_file_name_table = data; |
3948 | ||
3949 | while (data < end && *data != 0) | |
db9537d2 | 3950 | { |
77145576 JK |
3951 | unsigned int bytes_read; |
3952 | ||
3953 | /* Skip Name, directory index, last modification time and length | |
3954 | of file. */ | |
3955 | data += strnlen ((char *) data, end - data) + 1; | |
3956 | read_uleb128 (data, & bytes_read, end); | |
3957 | data += bytes_read; | |
3958 | read_uleb128 (data, & bytes_read, end); | |
3959 | data += bytes_read; | |
3960 | read_uleb128 (data, & bytes_read, end); | |
3961 | data += bytes_read; | |
3962 | ||
3963 | n_files++; | |
db9537d2 | 3964 | } |
a262ae96 | 3965 | |
77145576 JK |
3966 | if (data >= end) |
3967 | { | |
3968 | warn (_("file table ends unexpectedly\n")); | |
3969 | n_files = 0; | |
3970 | break; | |
3971 | } | |
3972 | ||
3973 | /* Go through the file table again to save the strings. */ | |
3974 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 3975 | |
77145576 JK |
3976 | i = 0; |
3977 | while (*ptr_file_name_table != 0) | |
3978 | { | |
3979 | unsigned int bytes_read; | |
3980 | ||
3981 | file_table[i].name = ptr_file_name_table; | |
3982 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
3983 | end - ptr_file_name_table) + 1; | |
3984 | ||
3985 | /* We are not interested in directory, time or size. */ | |
3986 | file_table[i].directory_index = read_uleb128 (ptr_file_name_table, | |
3987 | & bytes_read, end); | |
3988 | ptr_file_name_table += bytes_read; | |
3989 | file_table[i].modification_date = read_uleb128 (ptr_file_name_table, | |
3990 | & bytes_read, end); | |
3991 | ptr_file_name_table += bytes_read; | |
3992 | file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end); | |
3993 | ptr_file_name_table += bytes_read; | |
3994 | i++; | |
3995 | } | |
3996 | i = 0; | |
b40bf0a2 | 3997 | } |
77145576 JK |
3998 | |
3999 | /* Skip the NUL at the end of the table. */ | |
4000 | data++; | |
b40bf0a2 | 4001 | } |
cc5914eb | 4002 | |
77145576 | 4003 | /* Print the Compilation Unit's name and a header. */ |
f082820d AM |
4004 | if (file_table == NULL) |
4005 | ; | |
4006 | else if (directory_table == NULL) | |
4007 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
4008 | else |
4009 | { | |
4010 | unsigned int ix = file_table[0].directory_index; | |
4011 | const char *directory; | |
4012 | ||
4013 | if (ix == 0) | |
4014 | directory = "."; | |
4015 | /* PR 20439 */ | |
4016 | else if (n_directories == 0) | |
4017 | directory = _("<unknown>"); | |
4018 | else if (ix > n_directories) | |
4019 | { | |
4020 | warn (_("directory index %u > number of directories %s\n"), | |
4021 | ix, dwarf_vmatoa ("u", n_directories)); | |
4022 | directory = _("<corrupt>"); | |
4023 | } | |
4024 | else | |
4025 | directory = (char *) directory_table[ix - 1]; | |
4026 | ||
4027 | if (do_wide || strlen (directory) < 76) | |
4028 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
4029 | else | |
4030 | printf ("%s:\n", file_table[0].name); | |
77145576 | 4031 | } |
a262ae96 | 4032 | |
ba8826a8 | 4033 | printf (_("File name Line number Starting address View\n")); |
b40bf0a2 NC |
4034 | saved_linfo = linfo; |
4035 | } | |
a262ae96 NC |
4036 | |
4037 | /* This loop iterates through the Dwarf Line Number Program. */ | |
4038 | while (data < end_of_sequence) | |
b4eb7656 | 4039 | { |
a262ae96 | 4040 | unsigned char op_code; |
ba8826a8 | 4041 | int xop; |
b4eb7656 AM |
4042 | int adv; |
4043 | unsigned long int uladv; | |
4044 | unsigned int bytes_read; | |
4045 | int is_special_opcode = 0; | |
a262ae96 | 4046 | |
b4eb7656 | 4047 | op_code = *data++; |
ba8826a8 | 4048 | xop = op_code; |
a262ae96 | 4049 | |
b4eb7656 | 4050 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 4051 | { |
91d6fa6a | 4052 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
4053 | uladv = (op_code / linfo.li_line_range); |
4054 | if (linfo.li_max_ops_per_insn == 1) | |
4055 | { | |
4056 | uladv *= linfo.li_min_insn_length; | |
4057 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4058 | if (uladv) |
4059 | state_machine_regs.view = 0; | |
a233b20c JJ |
4060 | } |
4061 | else | |
4062 | { | |
ba8826a8 AO |
4063 | unsigned addrdelta |
4064 | = ((state_machine_regs.op_index + uladv) | |
4065 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4066 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4067 | state_machine_regs.address |
4068 | += addrdelta; | |
a233b20c JJ |
4069 | state_machine_regs.op_index |
4070 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 4071 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
4072 | if (addrdelta) |
4073 | state_machine_regs.view = 0; | |
a233b20c | 4074 | } |
a262ae96 | 4075 | |
b4eb7656 AM |
4076 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
4077 | state_machine_regs.line += adv; | |
4078 | is_special_opcode = 1; | |
ba8826a8 | 4079 | /* Increment view after printing this row. */ |
b4eb7656 AM |
4080 | } |
4081 | else switch (op_code) | |
b40bf0a2 NC |
4082 | { |
4083 | case DW_LNS_extended_op: | |
4084 | { | |
4085 | unsigned int ext_op_code_len; | |
4086 | unsigned char ext_op_code; | |
4087 | unsigned char *op_code_data = data; | |
4088 | ||
4089 | ext_op_code_len = read_uleb128 (op_code_data, &bytes_read, | |
4090 | end_of_sequence); | |
4091 | op_code_data += bytes_read; | |
4092 | ||
4093 | if (ext_op_code_len == 0) | |
4094 | { | |
f41e4712 | 4095 | warn (_("Badly formed extended line op encountered!\n")); |
b40bf0a2 NC |
4096 | break; |
4097 | } | |
4098 | ext_op_code_len += bytes_read; | |
4099 | ext_op_code = *op_code_data++; | |
ba8826a8 AO |
4100 | xop = ext_op_code; |
4101 | xop = -xop; | |
b40bf0a2 NC |
4102 | |
4103 | switch (ext_op_code) | |
4104 | { | |
4105 | case DW_LNE_end_sequence: | |
ba8826a8 | 4106 | /* Reset stuff after printing this row. */ |
b40bf0a2 NC |
4107 | break; |
4108 | case DW_LNE_set_address: | |
4109 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
87bc83b3 CC |
4110 | op_code_data, |
4111 | ext_op_code_len - bytes_read - 1, | |
b40bf0a2 NC |
4112 | end); |
4113 | state_machine_regs.op_index = 0; | |
ba8826a8 | 4114 | state_machine_regs.view = 0; |
b40bf0a2 NC |
4115 | break; |
4116 | case DW_LNE_define_file: | |
4117 | { | |
4118 | file_table = (File_Entry *) xrealloc | |
4119 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
4120 | ||
4121 | ++state_machine_regs.last_file_entry; | |
4122 | /* Source file name. */ | |
4123 | file_table[n_files].name = op_code_data; | |
4124 | op_code_data += strlen ((char *) op_code_data) + 1; | |
4125 | /* Directory index. */ | |
4126 | file_table[n_files].directory_index = | |
4127 | read_uleb128 (op_code_data, & bytes_read, | |
4128 | end_of_sequence); | |
4129 | op_code_data += bytes_read; | |
4130 | /* Last modification time. */ | |
4131 | file_table[n_files].modification_date = | |
4132 | read_uleb128 (op_code_data, & bytes_read, | |
4133 | end_of_sequence); | |
4134 | op_code_data += bytes_read; | |
4135 | /* File length. */ | |
4136 | file_table[n_files].length = | |
4137 | read_uleb128 (op_code_data, & bytes_read, | |
4138 | end_of_sequence); | |
4139 | ||
4140 | n_files++; | |
4141 | break; | |
4142 | } | |
4143 | case DW_LNE_set_discriminator: | |
4144 | case DW_LNE_HP_set_sequence: | |
4145 | /* Simply ignored. */ | |
4146 | break; | |
4147 | ||
4148 | default: | |
4149 | printf (_("UNKNOWN (%u): length %d\n"), | |
4150 | ext_op_code, ext_op_code_len - bytes_read); | |
4151 | break; | |
4152 | } | |
4153 | data += ext_op_code_len; | |
4154 | break; | |
4155 | } | |
4156 | case DW_LNS_copy: | |
ba8826a8 | 4157 | /* Increment view after printing this row. */ |
b40bf0a2 NC |
4158 | break; |
4159 | ||
4160 | case DW_LNS_advance_pc: | |
4161 | uladv = read_uleb128 (data, & bytes_read, end); | |
4162 | data += bytes_read; | |
4163 | if (linfo.li_max_ops_per_insn == 1) | |
4164 | { | |
4165 | uladv *= linfo.li_min_insn_length; | |
4166 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4167 | if (uladv) |
4168 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4169 | } |
4170 | else | |
4171 | { | |
ba8826a8 AO |
4172 | unsigned addrdelta |
4173 | = ((state_machine_regs.op_index + uladv) | |
4174 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4175 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4176 | state_machine_regs.address |
4177 | += addrdelta; | |
b40bf0a2 NC |
4178 | state_machine_regs.op_index |
4179 | = (state_machine_regs.op_index + uladv) | |
4180 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4181 | if (addrdelta) |
4182 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4183 | } |
4184 | break; | |
4185 | ||
4186 | case DW_LNS_advance_line: | |
4187 | adv = read_sleb128 (data, & bytes_read, end); | |
4188 | data += bytes_read; | |
4189 | state_machine_regs.line += adv; | |
4190 | break; | |
4191 | ||
4192 | case DW_LNS_set_file: | |
4193 | adv = read_uleb128 (data, & bytes_read, end); | |
4194 | data += bytes_read; | |
4195 | state_machine_regs.file = adv; | |
4196 | ||
db9537d2 NC |
4197 | { |
4198 | unsigned file = state_machine_regs.file - 1; | |
4199 | unsigned dir; | |
4200 | ||
4201 | if (file_table == NULL || n_files == 0) | |
4202 | printf (_("\n [Use file table entry %d]\n"), file); | |
4203 | /* PR 20439 */ | |
4204 | else if (file >= n_files) | |
4205 | { | |
4206 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
4207 | printf (_("\n <over large file table index %u>"), file); | |
4208 | } | |
4209 | else if ((dir = file_table[file].directory_index) == 0) | |
4210 | /* If directory index is 0, that means current directory. */ | |
4211 | printf ("\n./%s:[++]\n", file_table[file].name); | |
4212 | else if (directory_table == NULL || n_directories == 0) | |
4213 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
4214 | file_table[file].name, dir); | |
4215 | /* PR 20439 */ | |
4216 | else if (dir > n_directories) | |
4217 | { | |
77145576 JK |
4218 | warn (_("directory index %u > number of directories %s\n"), |
4219 | dir, dwarf_vmatoa ("u", n_directories)); | |
db9537d2 NC |
4220 | printf (_("\n <over large directory table entry %u>\n"), dir); |
4221 | } | |
4222 | else | |
4223 | printf ("\n%s/%s:\n", | |
4224 | /* The directory index starts counting at 1. */ | |
4225 | directory_table[dir - 1], file_table[file].name); | |
4226 | } | |
b40bf0a2 NC |
4227 | break; |
4228 | ||
4229 | case DW_LNS_set_column: | |
4230 | uladv = read_uleb128 (data, & bytes_read, end); | |
4231 | data += bytes_read; | |
4232 | state_machine_regs.column = uladv; | |
4233 | break; | |
4234 | ||
4235 | case DW_LNS_negate_stmt: | |
4236 | adv = state_machine_regs.is_stmt; | |
4237 | adv = ! adv; | |
4238 | state_machine_regs.is_stmt = adv; | |
4239 | break; | |
4240 | ||
4241 | case DW_LNS_set_basic_block: | |
4242 | state_machine_regs.basic_block = 1; | |
4243 | break; | |
4244 | ||
4245 | case DW_LNS_const_add_pc: | |
4246 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4247 | if (linfo.li_max_ops_per_insn == 1) | |
4248 | { | |
4249 | uladv *= linfo.li_min_insn_length; | |
4250 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4251 | if (uladv) |
4252 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4253 | } |
4254 | else | |
4255 | { | |
ba8826a8 AO |
4256 | unsigned addrdelta |
4257 | = ((state_machine_regs.op_index + uladv) | |
4258 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4259 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4260 | state_machine_regs.address |
4261 | += addrdelta; | |
b40bf0a2 NC |
4262 | state_machine_regs.op_index |
4263 | = (state_machine_regs.op_index + uladv) | |
4264 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4265 | if (addrdelta) |
4266 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4267 | } |
4268 | break; | |
4269 | ||
4270 | case DW_LNS_fixed_advance_pc: | |
4271 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4272 | state_machine_regs.address += uladv; | |
4273 | state_machine_regs.op_index = 0; | |
ba8826a8 | 4274 | /* Do NOT reset view. */ |
b40bf0a2 NC |
4275 | break; |
4276 | ||
4277 | case DW_LNS_set_prologue_end: | |
4278 | break; | |
4279 | ||
4280 | case DW_LNS_set_epilogue_begin: | |
4281 | break; | |
4282 | ||
4283 | case DW_LNS_set_isa: | |
4284 | uladv = read_uleb128 (data, & bytes_read, end); | |
4285 | data += bytes_read; | |
4286 | printf (_(" Set ISA to %lu\n"), uladv); | |
4287 | break; | |
4288 | ||
4289 | default: | |
4290 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4291 | ||
4292 | if (standard_opcodes != NULL) | |
4293 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4294 | { | |
4295 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
4296 | &bytes_read, end)), | |
4297 | i == 1 ? "" : ", "); | |
4298 | data += bytes_read; | |
4299 | } | |
4300 | putchar ('\n'); | |
4301 | break; | |
4302 | } | |
a262ae96 | 4303 | |
b4eb7656 AM |
4304 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
4305 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
4306 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
4307 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
4308 | { |
4309 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
4310 | char *fileName; | |
4311 | char *newFileName = NULL; | |
4312 | size_t fileNameLength; | |
b40bf0a2 NC |
4313 | |
4314 | if (file_table) | |
db9537d2 NC |
4315 | { |
4316 | unsigned indx = state_machine_regs.file - 1; | |
4317 | /* PR 20439 */ | |
4318 | if (indx >= n_files) | |
4319 | { | |
4320 | warn (_("corrupt file index %u encountered\n"), indx); | |
4321 | fileName = _("<corrupt>"); | |
4322 | } | |
4323 | else | |
4324 | fileName = (char *) file_table[indx].name; | |
4325 | } | |
b40bf0a2 | 4326 | else |
db9537d2 | 4327 | fileName = _("<unknown>"); |
b40bf0a2 NC |
4328 | |
4329 | fileNameLength = strlen (fileName); | |
a262ae96 | 4330 | |
b4eb7656 AM |
4331 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
4332 | { | |
4333 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
4334 | /* Truncate file name */ | |
4335 | strncpy (newFileName, | |
4336 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
4337 | MAX_FILENAME_LENGTH + 1); | |
4338 | } | |
4339 | else | |
4340 | { | |
4341 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
4342 | strncpy (newFileName, fileName, fileNameLength + 1); | |
4343 | } | |
4344 | ||
4345 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
4346 | { | |
a233b20c | 4347 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4348 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4349 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4350 | state_machine_regs.address); |
4351 | else | |
ba8826a8 | 4352 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4353 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4354 | state_machine_regs.address, |
4355 | state_machine_regs.op_index); | |
b4eb7656 AM |
4356 | } |
4357 | else | |
4358 | { | |
a233b20c | 4359 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4360 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4361 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4362 | state_machine_regs.address); |
4363 | else | |
ba8826a8 | 4364 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4365 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4366 | state_machine_regs.address, |
4367 | state_machine_regs.op_index); | |
b4eb7656 | 4368 | } |
a262ae96 | 4369 | |
ba8826a8 AO |
4370 | if (state_machine_regs.view) |
4371 | printf (" %6u\n", state_machine_regs.view); | |
4372 | else | |
4373 | putchar ('\n'); | |
4374 | state_machine_regs.view++; | |
4375 | ||
4376 | if (xop == -DW_LNE_end_sequence) | |
4377 | { | |
4378 | reset_state_machine (linfo.li_default_is_stmt); | |
4379 | putchar ('\n'); | |
4380 | } | |
a262ae96 | 4381 | |
b4eb7656 AM |
4382 | free (newFileName); |
4383 | } | |
4384 | } | |
b40bf0a2 NC |
4385 | |
4386 | if (file_table) | |
4387 | { | |
4388 | free (file_table); | |
4389 | file_table = NULL; | |
4390 | n_files = 0; | |
4391 | } | |
4392 | ||
4393 | if (directory_table) | |
4394 | { | |
4395 | free (directory_table); | |
4396 | directory_table = NULL; | |
4397 | n_directories = 0; | |
4398 | } | |
4399 | ||
a262ae96 NC |
4400 | putchar ('\n'); |
4401 | } | |
4402 | ||
4403 | return 1; | |
4404 | } | |
4405 | ||
4406 | static int | |
77145576 | 4407 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
4408 | { |
4409 | unsigned char *data = section->start; | |
4410 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
4411 | int retValRaw = 1; |
4412 | int retValDecoded = 1; | |
a262ae96 | 4413 | |
008f4c78 NC |
4414 | if (do_debug_lines == 0) |
4415 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
4416 | ||
4cb93e3b | 4417 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 4418 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 4419 | |
4cb93e3b | 4420 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
77145576 | 4421 | retValDecoded = display_debug_lines_decoded (section, data, end, file); |
a262ae96 | 4422 | |
4cb93e3b | 4423 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
4424 | return 0; |
4425 | ||
4426 | return 1; | |
4427 | } | |
4428 | ||
6e3d6dc1 NC |
4429 | static debug_info * |
4430 | find_debug_info_for_offset (unsigned long offset) | |
4431 | { | |
4432 | unsigned int i; | |
4433 | ||
4434 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
4435 | return NULL; | |
4436 | ||
4437 | for (i = 0; i < num_debug_info_entries; i++) | |
4438 | if (debug_information[i].cu_offset == offset) | |
4439 | return debug_information + i; | |
4440 | ||
4441 | return NULL; | |
4442 | } | |
4443 | ||
459d52c8 DE |
4444 | static const char * |
4445 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
4446 | { | |
4447 | /* See gdb/gdb-index.h. */ | |
4448 | static const char * const kinds[] = | |
4449 | { | |
4450 | N_ ("no info"), | |
4451 | N_ ("type"), | |
4452 | N_ ("variable"), | |
4453 | N_ ("function"), | |
4454 | N_ ("other"), | |
4455 | N_ ("unused5"), | |
4456 | N_ ("unused6"), | |
4457 | N_ ("unused7") | |
4458 | }; | |
4459 | ||
4460 | return _ (kinds[kind]); | |
4461 | } | |
4462 | ||
19e6b90e | 4463 | static int |
459d52c8 DE |
4464 | display_debug_pubnames_worker (struct dwarf_section *section, |
4465 | void *file ATTRIBUTE_UNUSED, | |
4466 | int is_gnu) | |
19e6b90e | 4467 | { |
91d6fa6a | 4468 | DWARF2_Internal_PubNames names; |
19e6b90e L |
4469 | unsigned char *start = section->start; |
4470 | unsigned char *end = start + section->size; | |
4471 | ||
6e3d6dc1 NC |
4472 | /* It does not matter if this load fails, |
4473 | we test for that later on. */ | |
4474 | load_debug_info (file); | |
4475 | ||
19e6b90e L |
4476 | printf (_("Contents of the %s section:\n\n"), section->name); |
4477 | ||
4478 | while (start < end) | |
4479 | { | |
4480 | unsigned char *data; | |
362beea4 | 4481 | unsigned char *adr; |
834f871c | 4482 | dwarf_vma offset; |
bf5117e3 | 4483 | unsigned int offset_size, initial_length_size; |
19e6b90e L |
4484 | |
4485 | data = start; | |
4486 | ||
0c588247 | 4487 | SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end); |
91d6fa6a | 4488 | if (names.pn_length == 0xffffffff) |
19e6b90e | 4489 | { |
0c588247 | 4490 | SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end); |
19e6b90e L |
4491 | offset_size = 8; |
4492 | initial_length_size = 12; | |
4493 | } | |
4494 | else | |
4495 | { | |
4496 | offset_size = 4; | |
4497 | initial_length_size = 4; | |
4498 | } | |
4499 | ||
0c588247 NC |
4500 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
4501 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
4502 | |
4503 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
4504 | && num_debug_info_entries > 0 | |
91d6fa6a | 4505 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 4506 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 4507 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 4508 | |
0c588247 | 4509 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 4510 | |
362beea4 | 4511 | adr = start + names.pn_length + initial_length_size; |
058037d3 | 4512 | /* PR 17531: file: 7615b6b2. */ |
57028622 NC |
4513 | if ((dwarf_signed_vma) names.pn_length < 0 |
4514 | /* PR 17531: file: a5dbeaa7. */ | |
362beea4 | 4515 | || adr < start) |
058037d3 NC |
4516 | { |
4517 | warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length); | |
4518 | start = end; | |
4519 | } | |
4520 | else | |
362beea4 | 4521 | start = adr; |
b4eb7656 | 4522 | |
058037d3 NC |
4523 | printf (_(" Length: %ld\n"), |
4524 | (long) names.pn_length); | |
4525 | printf (_(" Version: %d\n"), | |
4526 | names.pn_version); | |
4527 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
4528 | (unsigned long) names.pn_offset); | |
4529 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
4530 | (long) names.pn_size); | |
19e6b90e | 4531 | |
91d6fa6a | 4532 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
4533 | { |
4534 | static int warned = 0; | |
4535 | ||
4536 | if (! warned) | |
4537 | { | |
4538 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
4539 | warned = 1; | |
4540 | } | |
4541 | ||
4542 | continue; | |
4543 | } | |
4544 | ||
459d52c8 DE |
4545 | if (is_gnu) |
4546 | printf (_("\n Offset Kind Name\n")); | |
4547 | else | |
4548 | printf (_("\n Offset\tName\n")); | |
19e6b90e L |
4549 | |
4550 | do | |
4551 | { | |
f41e4712 NC |
4552 | bfd_size_type maxprint; |
4553 | ||
0c588247 | 4554 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e L |
4555 | |
4556 | if (offset != 0) | |
4557 | { | |
4558 | data += offset_size; | |
f41e4712 NC |
4559 | if (data >= end) |
4560 | break; | |
4561 | maxprint = (end - data) - 1; | |
b4eb7656 | 4562 | |
459d52c8 DE |
4563 | if (is_gnu) |
4564 | { | |
4565 | unsigned int kind_data; | |
4566 | gdb_index_symbol_kind kind; | |
4567 | const char *kind_name; | |
4568 | int is_static; | |
4569 | ||
4570 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
4571 | data++; | |
f41e4712 | 4572 | maxprint --; |
459d52c8 DE |
4573 | /* GCC computes the kind as the upper byte in the CU index |
4574 | word, and then right shifts it by the CU index size. | |
4575 | Left shift KIND to where the gdb-index.h accessor macros | |
4576 | can use it. */ | |
4577 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
4578 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
4579 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
4580 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
f41e4712 | 4581 | printf (" %-6lx %s,%-10s %.*s\n", |
834f871c | 4582 | (unsigned long) offset, is_static ? _("s") : _("g"), |
f41e4712 | 4583 | kind_name, (int) maxprint, data); |
459d52c8 DE |
4584 | } |
4585 | else | |
b4eb7656 AM |
4586 | printf (" %-6lx\t%.*s\n", |
4587 | (unsigned long) offset, (int) maxprint, data); | |
f41e4712 NC |
4588 | |
4589 | data += strnlen ((char *) data, maxprint) + 1; | |
4590 | if (data >= end) | |
4591 | break; | |
19e6b90e L |
4592 | } |
4593 | } | |
4594 | while (offset != 0); | |
4595 | } | |
4596 | ||
4597 | printf ("\n"); | |
4598 | return 1; | |
4599 | } | |
4600 | ||
459d52c8 DE |
4601 | static int |
4602 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
4603 | { | |
4604 | return display_debug_pubnames_worker (section, file, 0); | |
4605 | } | |
4606 | ||
4607 | static int | |
4608 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
4609 | { | |
4610 | return display_debug_pubnames_worker (section, file, 1); | |
4611 | } | |
4612 | ||
19e6b90e L |
4613 | static int |
4614 | display_debug_macinfo (struct dwarf_section *section, | |
4615 | void *file ATTRIBUTE_UNUSED) | |
4616 | { | |
4617 | unsigned char *start = section->start; | |
4618 | unsigned char *end = start + section->size; | |
4619 | unsigned char *curr = start; | |
4620 | unsigned int bytes_read; | |
4621 | enum dwarf_macinfo_record_type op; | |
4622 | ||
4623 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4624 | ||
4625 | while (curr < end) | |
4626 | { | |
4627 | unsigned int lineno; | |
0c588247 | 4628 | const unsigned char *string; |
19e6b90e | 4629 | |
3f5e193b | 4630 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
4631 | curr++; |
4632 | ||
4633 | switch (op) | |
4634 | { | |
4635 | case DW_MACINFO_start_file: | |
4636 | { | |
4637 | unsigned int filenum; | |
4638 | ||
f6f0e17b | 4639 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 4640 | curr += bytes_read; |
f6f0e17b | 4641 | filenum = read_uleb128 (curr, & bytes_read, end); |
19e6b90e L |
4642 | curr += bytes_read; |
4643 | ||
4644 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
4645 | lineno, filenum); | |
4646 | } | |
4647 | break; | |
4648 | ||
4649 | case DW_MACINFO_end_file: | |
4650 | printf (_(" DW_MACINFO_end_file\n")); | |
4651 | break; | |
4652 | ||
4653 | case DW_MACINFO_define: | |
f6f0e17b | 4654 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 4655 | curr += bytes_read; |
0c588247 NC |
4656 | string = curr; |
4657 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
4658 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
4659 | lineno, string); | |
4660 | break; | |
4661 | ||
4662 | case DW_MACINFO_undef: | |
f6f0e17b | 4663 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 4664 | curr += bytes_read; |
0c588247 NC |
4665 | string = curr; |
4666 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
4667 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
4668 | lineno, string); | |
4669 | break; | |
4670 | ||
4671 | case DW_MACINFO_vendor_ext: | |
4672 | { | |
4673 | unsigned int constant; | |
4674 | ||
f6f0e17b | 4675 | constant = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 4676 | curr += bytes_read; |
0c588247 NC |
4677 | string = curr; |
4678 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
4679 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
4680 | constant, string); | |
4681 | } | |
4682 | break; | |
4683 | } | |
4684 | } | |
4685 | ||
4686 | return 1; | |
4687 | } | |
4688 | ||
4ccf1e31 JJ |
4689 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
4690 | filename and dirname corresponding to file name table entry with index | |
4691 | FILEIDX. Return NULL on failure. */ | |
4692 | ||
4693 | static unsigned char * | |
f6f0e17b NC |
4694 | get_line_filename_and_dirname (dwarf_vma line_offset, |
4695 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
4696 | unsigned char **dir_name) |
4697 | { | |
4698 | struct dwarf_section *section = &debug_displays [line].section; | |
4699 | unsigned char *hdrptr, *dirtable, *file_name; | |
4700 | unsigned int offset_size, initial_length_size; | |
4701 | unsigned int version, opcode_base, bytes_read; | |
4702 | dwarf_vma length, diridx; | |
f6f0e17b | 4703 | const unsigned char * end; |
4ccf1e31 JJ |
4704 | |
4705 | *dir_name = NULL; | |
4706 | if (section->start == NULL | |
4707 | || line_offset >= section->size | |
4708 | || fileidx == 0) | |
4709 | return NULL; | |
4710 | ||
4711 | hdrptr = section->start + line_offset; | |
f6f0e17b | 4712 | end = section->start + section->size; |
0c588247 NC |
4713 | |
4714 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
4715 | if (length == 0xffffffff) |
4716 | { | |
4717 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 4718 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
4719 | offset_size = 8; |
4720 | initial_length_size = 12; | |
4721 | } | |
4722 | else | |
4723 | { | |
4724 | offset_size = 4; | |
4725 | initial_length_size = 4; | |
4726 | } | |
4727 | if (length + initial_length_size > section->size) | |
4728 | return NULL; | |
0c588247 NC |
4729 | |
4730 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
4731 | if (version != 2 && version != 3 && version != 4) |
4732 | return NULL; | |
4733 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
4734 | if (version >= 4) | |
4735 | hdrptr++; /* Skip max_ops_per_insn. */ | |
4736 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
4737 | |
4738 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
4739 | if (opcode_base == 0) |
4740 | return NULL; | |
0c588247 | 4741 | |
4ccf1e31 JJ |
4742 | hdrptr += opcode_base - 1; |
4743 | dirtable = hdrptr; | |
4744 | /* Skip over dirname table. */ | |
4745 | while (*hdrptr != '\0') | |
0c588247 | 4746 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
4ccf1e31 JJ |
4747 | hdrptr++; /* Skip the NUL at the end of the table. */ |
4748 | /* Now skip over preceding filename table entries. */ | |
4749 | for (; *hdrptr != '\0' && fileidx > 1; fileidx--) | |
4750 | { | |
0c588247 | 4751 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 4752 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 4753 | hdrptr += bytes_read; |
f6f0e17b | 4754 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 4755 | hdrptr += bytes_read; |
f6f0e17b | 4756 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
4757 | hdrptr += bytes_read; |
4758 | } | |
f6f0e17b | 4759 | if (hdrptr == end || *hdrptr == '\0') |
4ccf1e31 JJ |
4760 | return NULL; |
4761 | file_name = hdrptr; | |
0c588247 | 4762 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 4763 | diridx = read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
4764 | if (diridx == 0) |
4765 | return file_name; | |
4766 | for (; *dirtable != '\0' && diridx > 1; diridx--) | |
0c588247 | 4767 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
4ccf1e31 JJ |
4768 | if (*dirtable == '\0') |
4769 | return NULL; | |
4770 | *dir_name = dirtable; | |
4771 | return file_name; | |
4772 | } | |
4773 | ||
4774 | static int | |
4775 | display_debug_macro (struct dwarf_section *section, | |
4776 | void *file) | |
4777 | { | |
4778 | unsigned char *start = section->start; | |
4779 | unsigned char *end = start + section->size; | |
4780 | unsigned char *curr = start; | |
4781 | unsigned char *extended_op_buf[256]; | |
4782 | unsigned int bytes_read; | |
4783 | ||
4784 | load_debug_section (str, file); | |
4785 | load_debug_section (line, file); | |
4786 | ||
4787 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4788 | ||
4789 | while (curr < end) | |
4790 | { | |
4791 | unsigned int lineno, version, flags; | |
4792 | unsigned int offset_size = 4; | |
0c588247 | 4793 | const unsigned char *string; |
4ccf1e31 JJ |
4794 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
4795 | unsigned char **extended_ops = NULL; | |
4796 | ||
0c588247 | 4797 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 4798 | if (version != 4 && version != 5) |
4ccf1e31 | 4799 | { |
7a7e1061 | 4800 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
4801 | section->name); |
4802 | return 0; | |
4803 | } | |
4804 | ||
0c588247 | 4805 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
4806 | if (flags & 1) |
4807 | offset_size = 8; | |
4808 | printf (_(" Offset: 0x%lx\n"), | |
4809 | (unsigned long) sec_offset); | |
4810 | printf (_(" Version: %d\n"), version); | |
4811 | printf (_(" Offset size: %d\n"), offset_size); | |
4812 | if (flags & 2) | |
4813 | { | |
0c588247 | 4814 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
4815 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
4816 | (unsigned long) line_offset); | |
4817 | } | |
4818 | if (flags & 4) | |
4819 | { | |
0c588247 | 4820 | unsigned int i, count, op; |
4ccf1e31 | 4821 | dwarf_vma nargs, n; |
0c588247 NC |
4822 | |
4823 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 4824 | |
4ccf1e31 JJ |
4825 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
4826 | extended_ops = extended_op_buf; | |
4827 | if (count) | |
4828 | { | |
4829 | printf (_(" Extension opcode arguments:\n")); | |
4830 | for (i = 0; i < count; i++) | |
4831 | { | |
0c588247 | 4832 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 4833 | extended_ops[op] = curr; |
f6f0e17b | 4834 | nargs = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
4835 | curr += bytes_read; |
4836 | if (nargs == 0) | |
7a7e1061 | 4837 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
4838 | else |
4839 | { | |
7a7e1061 | 4840 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
4841 | for (n = 0; n < nargs; n++) |
4842 | { | |
0c588247 NC |
4843 | unsigned int form; |
4844 | ||
4845 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
4846 | printf ("%s%s", get_FORM_name (form), |
4847 | n == nargs - 1 ? "\n" : ", "); | |
4848 | switch (form) | |
4849 | { | |
4850 | case DW_FORM_data1: | |
4851 | case DW_FORM_data2: | |
4852 | case DW_FORM_data4: | |
4853 | case DW_FORM_data8: | |
4854 | case DW_FORM_sdata: | |
4855 | case DW_FORM_udata: | |
4856 | case DW_FORM_block: | |
4857 | case DW_FORM_block1: | |
4858 | case DW_FORM_block2: | |
4859 | case DW_FORM_block4: | |
4860 | case DW_FORM_flag: | |
4861 | case DW_FORM_string: | |
4862 | case DW_FORM_strp: | |
4863 | case DW_FORM_sec_offset: | |
4864 | break; | |
4865 | default: | |
4866 | error (_("Invalid extension opcode form %s\n"), | |
4867 | get_FORM_name (form)); | |
4868 | return 0; | |
4869 | } | |
4870 | } | |
4871 | } | |
4872 | } | |
4873 | } | |
4874 | } | |
4875 | printf ("\n"); | |
4876 | ||
4877 | while (1) | |
4878 | { | |
4879 | unsigned int op; | |
4880 | ||
4881 | if (curr >= end) | |
4882 | { | |
4883 | error (_(".debug_macro section not zero terminated\n")); | |
4884 | return 0; | |
4885 | } | |
4886 | ||
0c588247 | 4887 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
4888 | if (op == 0) |
4889 | break; | |
4890 | ||
4891 | switch (op) | |
4892 | { | |
7a7e1061 | 4893 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
4894 | { |
4895 | unsigned int filenum; | |
4896 | unsigned char *file_name = NULL, *dir_name = NULL; | |
4897 | ||
f6f0e17b | 4898 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4899 | curr += bytes_read; |
f6f0e17b | 4900 | filenum = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
4901 | curr += bytes_read; |
4902 | ||
4903 | if ((flags & 2) == 0) | |
7a7e1061 | 4904 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
4905 | else |
4906 | file_name | |
4907 | = get_line_filename_and_dirname (line_offset, filenum, | |
4908 | &dir_name); | |
4909 | if (file_name == NULL) | |
7a7e1061 | 4910 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
4911 | lineno, filenum); |
4912 | else | |
7a7e1061 | 4913 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
4914 | lineno, filenum, |
4915 | dir_name != NULL ? (const char *) dir_name : "", | |
4916 | dir_name != NULL ? "/" : "", file_name); | |
4917 | } | |
4918 | break; | |
4919 | ||
7a7e1061 JK |
4920 | case DW_MACRO_end_file: |
4921 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
4922 | break; |
4923 | ||
7a7e1061 | 4924 | case DW_MACRO_define: |
f6f0e17b | 4925 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4926 | curr += bytes_read; |
0c588247 NC |
4927 | string = curr; |
4928 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 4929 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
4930 | lineno, string); |
4931 | break; | |
4932 | ||
7a7e1061 | 4933 | case DW_MACRO_undef: |
f6f0e17b | 4934 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4935 | curr += bytes_read; |
0c588247 NC |
4936 | string = curr; |
4937 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 4938 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
4939 | lineno, string); |
4940 | break; | |
4941 | ||
7a7e1061 | 4942 | case DW_MACRO_define_strp: |
f6f0e17b | 4943 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4944 | curr += bytes_read; |
0c588247 | 4945 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 4946 | string = fetch_indirect_string (offset); |
7a7e1061 | 4947 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
4948 | lineno, string); |
4949 | break; | |
4950 | ||
7a7e1061 | 4951 | case DW_MACRO_undef_strp: |
f6f0e17b | 4952 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4953 | curr += bytes_read; |
0c588247 | 4954 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 4955 | string = fetch_indirect_string (offset); |
7a7e1061 | 4956 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
4957 | lineno, string); |
4958 | break; | |
4959 | ||
7a7e1061 | 4960 | case DW_MACRO_import: |
0c588247 | 4961 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 4962 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
4963 | (unsigned long) offset); |
4964 | break; | |
4965 | ||
7a7e1061 | 4966 | case DW_MACRO_define_sup: |
f6f0e17b | 4967 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 4968 | curr += bytes_read; |
0c588247 | 4969 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 4970 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
4971 | lineno, (unsigned long) offset); |
4972 | break; | |
4973 | ||
7a7e1061 | 4974 | case DW_MACRO_undef_sup: |
f6f0e17b | 4975 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 4976 | curr += bytes_read; |
0c588247 | 4977 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 4978 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
4979 | lineno, (unsigned long) offset); |
4980 | break; | |
4981 | ||
7a7e1061 | 4982 | case DW_MACRO_import_sup: |
0c588247 | 4983 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 4984 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
4985 | (unsigned long) offset); |
4986 | break; | |
4987 | ||
4ccf1e31 JJ |
4988 | default: |
4989 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
4990 | { | |
4991 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
4992 | return 0; | |
4993 | } | |
4994 | else | |
4995 | { | |
4996 | /* Skip over unhandled opcodes. */ | |
4997 | dwarf_vma nargs, n; | |
4998 | unsigned char *desc = extended_ops[op]; | |
f6f0e17b | 4999 | nargs = read_uleb128 (desc, &bytes_read, end); |
4ccf1e31 JJ |
5000 | desc += bytes_read; |
5001 | if (nargs == 0) | |
5002 | { | |
7a7e1061 | 5003 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
5004 | break; |
5005 | } | |
7a7e1061 | 5006 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
5007 | for (n = 0; n < nargs; n++) |
5008 | { | |
0c588247 NC |
5009 | int val; |
5010 | ||
77145576 | 5011 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 5012 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 5013 | curr |
77145576 | 5014 | = read_and_display_attr_value (0, val, 0, |
f6f0e17b | 5015 | curr, end, 0, 0, offset_size, |
341f9135 | 5016 | version, NULL, 0, NULL, |
ef0b5f1c | 5017 | NULL, ' '); |
4ccf1e31 JJ |
5018 | if (n != nargs - 1) |
5019 | printf (","); | |
5020 | } | |
5021 | printf ("\n"); | |
5022 | } | |
5023 | break; | |
5024 | } | |
5025 | } | |
5026 | ||
5027 | printf ("\n"); | |
b4eb7656 | 5028 | } |
4ccf1e31 JJ |
5029 | |
5030 | return 1; | |
5031 | } | |
5032 | ||
19e6b90e L |
5033 | static int |
5034 | display_debug_abbrev (struct dwarf_section *section, | |
5035 | void *file ATTRIBUTE_UNUSED) | |
5036 | { | |
5037 | abbrev_entry *entry; | |
5038 | unsigned char *start = section->start; | |
5039 | unsigned char *end = start + section->size; | |
5040 | ||
5041 | printf (_("Contents of the %s section:\n\n"), section->name); | |
5042 | ||
5043 | do | |
5044 | { | |
7282333f AM |
5045 | unsigned char *last; |
5046 | ||
19e6b90e L |
5047 | free_abbrevs (); |
5048 | ||
7282333f | 5049 | last = start; |
19e6b90e L |
5050 | start = process_abbrev_section (start, end); |
5051 | ||
5052 | if (first_abbrev == NULL) | |
5053 | continue; | |
5054 | ||
7282333f | 5055 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
5056 | |
5057 | for (entry = first_abbrev; entry; entry = entry->next) | |
5058 | { | |
5059 | abbrev_attr *attr; | |
5060 | ||
cc5914eb | 5061 | printf (" %ld %s [%s]\n", |
19e6b90e L |
5062 | entry->entry, |
5063 | get_TAG_name (entry->tag), | |
5064 | entry->children ? _("has children") : _("no children")); | |
5065 | ||
5066 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
5067 | { |
5068 | printf (" %-18s %s", | |
5069 | get_AT_name (attr->attribute), | |
5070 | get_FORM_name (attr->form)); | |
5071 | if (attr->form == DW_FORM_implicit_const) | |
5072 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
5073 | putchar ('\n'); | |
5074 | } | |
19e6b90e L |
5075 | } |
5076 | } | |
5077 | while (start); | |
5078 | ||
5079 | printf ("\n"); | |
5080 | ||
5081 | return 1; | |
5082 | } | |
5083 | ||
42bcef4a AB |
5084 | /* Return true when ADDR is the maximum address, when addresses are |
5085 | POINTER_SIZE bytes long. */ | |
5086 | ||
5087 | static bfd_boolean | |
5088 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
5089 | { | |
5090 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
5091 | return ((addr & mask) == mask); | |
5092 | } | |
5093 | ||
9f272209 AO |
5094 | /* Display a view pair list starting at *VSTART_PTR and ending at |
5095 | VLISTEND within SECTION. */ | |
5096 | ||
5097 | static void | |
5098 | display_view_pair_list (struct dwarf_section *section, | |
5099 | unsigned char **vstart_ptr, | |
5100 | unsigned int debug_info_entry, | |
5101 | unsigned char *vlistend) | |
5102 | { | |
5103 | unsigned char *vstart = *vstart_ptr; | |
5104 | unsigned char *section_end = section->start + section->size; | |
5105 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
5106 | ||
5107 | if (vlistend < section_end) | |
5108 | section_end = vlistend; | |
5109 | ||
5110 | putchar ('\n'); | |
5111 | ||
5112 | while (vstart < section_end) | |
5113 | { | |
5114 | dwarf_vma off = vstart - section->start; | |
5115 | dwarf_vma vbegin, vend; | |
5116 | ||
5117 | unsigned int bytes_read; | |
5118 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5119 | vstart += bytes_read; | |
5120 | if (vstart == section_end) | |
5121 | { | |
5122 | vstart -= bytes_read; | |
5123 | break; | |
5124 | } | |
5125 | ||
5126 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5127 | vstart += bytes_read; | |
5128 | ||
5129 | printf (" %8.8lx ", (unsigned long) off); | |
5130 | ||
5131 | print_dwarf_view (vbegin, pointer_size, 1); | |
5132 | print_dwarf_view (vend, pointer_size, 1); | |
5133 | printf (_("location view pair\n")); | |
5134 | } | |
5135 | ||
5136 | putchar ('\n'); | |
5137 | *vstart_ptr = vstart; | |
5138 | } | |
5139 | ||
4723351a CC |
5140 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
5141 | ||
5142 | static void | |
5143 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
5144 | unsigned char **start_ptr, |
5145 | unsigned int debug_info_entry, | |
359ca075 JK |
5146 | dwarf_vma offset, |
5147 | dwarf_vma base_address, | |
9f272209 | 5148 | unsigned char **vstart_ptr, |
b4eb7656 | 5149 | int has_frame_base) |
4723351a | 5150 | { |
9f272209 | 5151 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5152 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5153 | unsigned long cu_offset; |
5154 | unsigned int pointer_size; | |
5155 | unsigned int offset_size; | |
5156 | int dwarf_version; | |
4723351a CC |
5157 | |
5158 | dwarf_vma begin; | |
5159 | dwarf_vma end; | |
5160 | unsigned short length; | |
5161 | int need_frame_base; | |
5162 | ||
82b1b41b NC |
5163 | if (debug_info_entry >= num_debug_info_entries) |
5164 | { | |
5165 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
5166 | debug_info_entry); | |
5167 | return; | |
5168 | } | |
b4eb7656 | 5169 | |
82b1b41b NC |
5170 | cu_offset = debug_information [debug_info_entry].cu_offset; |
5171 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5172 | offset_size = debug_information [debug_info_entry].offset_size; | |
5173 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 5174 | |
f41e4712 NC |
5175 | if (pointer_size < 2 || pointer_size > 8) |
5176 | { | |
5177 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5178 | pointer_size, debug_info_entry); | |
5179 | return; | |
5180 | } | |
5181 | ||
4723351a CC |
5182 | while (1) |
5183 | { | |
359ca075 | 5184 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 5185 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 5186 | |
4723351a | 5187 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
5188 | { |
5189 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5190 | (unsigned long) offset); |
b4eb7656 AM |
5191 | break; |
5192 | } | |
4723351a | 5193 | |
359ca075 | 5194 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 5195 | |
0c588247 NC |
5196 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
5197 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 5198 | |
4723351a | 5199 | if (begin == 0 && end == 0) |
b4eb7656 | 5200 | { |
d1c4b12b NC |
5201 | /* PR 18374: In a object file we can have a location list that |
5202 | starts with a begin and end of 0 because there are relocations | |
5203 | that need to be applied to the addresses. Actually applying | |
5204 | the relocations now does not help as they will probably resolve | |
5205 | to 0, since the object file has not been fully linked. Real | |
5206 | end of list markers will not have any relocations against them. */ | |
5207 | if (! reloc_at (section, off) | |
5208 | && ! reloc_at (section, off + pointer_size)) | |
5209 | { | |
5210 | printf (_("<End of list>\n")); | |
5211 | break; | |
5212 | } | |
b4eb7656 | 5213 | } |
4723351a CC |
5214 | |
5215 | /* Check base address specifiers. */ | |
42bcef4a AB |
5216 | if (is_max_address (begin, pointer_size) |
5217 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
5218 | { |
5219 | base_address = end; | |
5220 | print_dwarf_vma (begin, pointer_size); | |
5221 | print_dwarf_vma (end, pointer_size); | |
5222 | printf (_("(base address)\n")); | |
5223 | continue; | |
5224 | } | |
4723351a | 5225 | |
9f272209 AO |
5226 | if (vstart) |
5227 | { | |
5228 | unsigned int bytes_read; | |
5229 | ||
5230 | off = offset + (vstart - *start_ptr); | |
5231 | ||
5232 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5233 | vstart += bytes_read; | |
5234 | print_dwarf_view (vbegin, pointer_size, 1); | |
5235 | ||
5236 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5237 | vstart += bytes_read; | |
5238 | print_dwarf_view (vend, pointer_size, 1); | |
5239 | ||
5240 | printf (_("views at %8.8lx for:\n %*s "), | |
5241 | (unsigned long) off, 8, ""); | |
5242 | } | |
5243 | ||
4723351a | 5244 | if (start + 2 > section_end) |
b4eb7656 AM |
5245 | { |
5246 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5247 | (unsigned long) offset); |
b4eb7656 AM |
5248 | break; |
5249 | } | |
4723351a | 5250 | |
0c588247 | 5251 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
5252 | |
5253 | if (start + length > section_end) | |
b4eb7656 AM |
5254 | { |
5255 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5256 | (unsigned long) offset); |
b4eb7656 AM |
5257 | break; |
5258 | } | |
4723351a CC |
5259 | |
5260 | print_dwarf_vma (begin + base_address, pointer_size); | |
5261 | print_dwarf_vma (end + base_address, pointer_size); | |
5262 | ||
5263 | putchar ('('); | |
5264 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5265 | pointer_size, |
5266 | offset_size, | |
5267 | dwarf_version, | |
5268 | length, | |
5269 | cu_offset, section); | |
4723351a CC |
5270 | putchar (')'); |
5271 | ||
5272 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5273 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 5274 | |
9f272209 | 5275 | if (begin == end && vbegin == vend) |
b4eb7656 | 5276 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5277 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 5278 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
5279 | |
5280 | putchar ('\n'); | |
5281 | ||
5282 | start += length; | |
5283 | } | |
5284 | ||
5285 | *start_ptr = start; | |
9f272209 | 5286 | *vstart_ptr = vstart; |
4723351a CC |
5287 | } |
5288 | ||
77145576 JK |
5289 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
5290 | ||
5291 | static void | |
5292 | display_loclists_list (struct dwarf_section *section, | |
5293 | unsigned char **start_ptr, | |
5294 | unsigned int debug_info_entry, | |
5295 | dwarf_vma offset, | |
5296 | dwarf_vma base_address, | |
9f272209 | 5297 | unsigned char **vstart_ptr, |
77145576 JK |
5298 | int has_frame_base) |
5299 | { | |
9f272209 | 5300 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
5301 | unsigned char *section_end = section->start + section->size; |
5302 | unsigned long cu_offset; | |
5303 | unsigned int pointer_size; | |
5304 | unsigned int offset_size; | |
5305 | int dwarf_version; | |
5306 | unsigned int bytes_read; | |
5307 | ||
9dfd0db9 | 5308 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
5309 | dwarf_vma begin = -1, vbegin = -1; |
5310 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
5311 | dwarf_vma length; |
5312 | int need_frame_base; | |
5313 | ||
5314 | if (debug_info_entry >= num_debug_info_entries) | |
5315 | { | |
5316 | warn (_("No debug information available for " | |
5317 | "loclists lists of entry: %u\n"), | |
5318 | debug_info_entry); | |
5319 | return; | |
5320 | } | |
5321 | ||
5322 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5323 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5324 | offset_size = debug_information [debug_info_entry].offset_size; | |
5325 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5326 | ||
5327 | if (pointer_size < 2 || pointer_size > 8) | |
5328 | { | |
5329 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5330 | pointer_size, debug_info_entry); | |
5331 | return; | |
5332 | } | |
5333 | ||
5334 | while (1) | |
5335 | { | |
5336 | dwarf_vma off = offset + (start - *start_ptr); | |
5337 | enum dwarf_location_list_entry_type llet; | |
5338 | ||
5339 | if (start + 1 > section_end) | |
5340 | { | |
5341 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5342 | (unsigned long) offset); | |
5343 | break; | |
5344 | } | |
5345 | ||
5346 | printf (" %8.8lx ", (unsigned long) off); | |
5347 | ||
5348 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
5349 | ||
9f272209 AO |
5350 | if (vstart && llet == DW_LLE_offset_pair) |
5351 | { | |
5352 | off = offset + (vstart - *start_ptr); | |
5353 | ||
5354 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5355 | vstart += bytes_read; | |
5356 | print_dwarf_view (vbegin, pointer_size, 1); | |
5357 | ||
5358 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5359 | vstart += bytes_read; | |
5360 | print_dwarf_view (vend, pointer_size, 1); | |
5361 | ||
5362 | printf (_("views at %8.8lx for:\n %*s "), | |
5363 | (unsigned long) off, 8, ""); | |
5364 | } | |
5365 | ||
77145576 JK |
5366 | switch (llet) |
5367 | { | |
5368 | case DW_LLE_end_of_list: | |
5369 | printf (_("<End of list>\n")); | |
5370 | break; | |
5371 | case DW_LLE_offset_pair: | |
5372 | begin = read_uleb128 (start, &bytes_read, section_end); | |
5373 | start += bytes_read; | |
5374 | end = read_uleb128 (start, &bytes_read, section_end); | |
5375 | start += bytes_read; | |
5376 | break; | |
5377 | case DW_LLE_base_address: | |
5378 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
5379 | section_end); | |
5380 | print_dwarf_vma (base_address, pointer_size); | |
5381 | printf (_("(base address)\n")); | |
5382 | break; | |
9f272209 AO |
5383 | #ifdef DW_LLE_view_pair |
5384 | case DW_LLE_view_pair: | |
5385 | if (vstart) | |
5386 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
5387 | vbegin = read_uleb128 (start, &bytes_read, section_end); | |
5388 | start += bytes_read; | |
5389 | print_dwarf_view (vbegin, pointer_size, 1); | |
5390 | ||
5391 | vend = read_uleb128 (start, &bytes_read, section_end); | |
5392 | start += bytes_read; | |
5393 | print_dwarf_view (vend, pointer_size, 1); | |
5394 | ||
5395 | printf (_("views for:\n")); | |
5396 | continue; | |
5397 | #endif | |
77145576 JK |
5398 | default: |
5399 | error (_("Invalid location list entry type %d\n"), llet); | |
5400 | return; | |
5401 | } | |
5402 | if (llet == DW_LLE_end_of_list) | |
5403 | break; | |
5404 | if (llet != DW_LLE_offset_pair) | |
5405 | continue; | |
5406 | ||
5407 | if (start + 2 > section_end) | |
5408 | { | |
5409 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5410 | (unsigned long) offset); | |
5411 | break; | |
5412 | } | |
5413 | ||
5414 | length = read_uleb128 (start, &bytes_read, section_end); | |
5415 | start += bytes_read; | |
5416 | ||
5417 | print_dwarf_vma (begin + base_address, pointer_size); | |
5418 | print_dwarf_vma (end + base_address, pointer_size); | |
5419 | ||
5420 | putchar ('('); | |
5421 | need_frame_base = decode_location_expression (start, | |
5422 | pointer_size, | |
5423 | offset_size, | |
5424 | dwarf_version, | |
5425 | length, | |
5426 | cu_offset, section); | |
5427 | putchar (')'); | |
5428 | ||
5429 | if (need_frame_base && !has_frame_base) | |
5430 | printf (_(" [without DW_AT_frame_base]")); | |
5431 | ||
9f272209 | 5432 | if (begin == end && vbegin == vend) |
77145576 | 5433 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5434 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
5435 | fputs (_(" (start > end)"), stdout); |
5436 | ||
5437 | putchar ('\n'); | |
5438 | ||
5439 | start += length; | |
9f272209 | 5440 | vbegin = vend = -1; |
77145576 JK |
5441 | } |
5442 | ||
9f272209 AO |
5443 | if (vbegin != vm1 || vend != vm1) |
5444 | printf (_("Trailing view pair not used in a range")); | |
5445 | ||
77145576 | 5446 | *start_ptr = start; |
9f272209 | 5447 | *vstart_ptr = vstart; |
77145576 JK |
5448 | } |
5449 | ||
fab128ef CC |
5450 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
5451 | right-adjusted in a field of length LEN, and followed by a space. */ | |
5452 | ||
5453 | static void | |
5454 | print_addr_index (unsigned int idx, unsigned int len) | |
5455 | { | |
5456 | static char buf[15]; | |
5457 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 5458 | printf ("%*s ", len, buf); |
fab128ef CC |
5459 | } |
5460 | ||
4723351a CC |
5461 | /* Display a location list from a .dwo section. It uses address indexes rather |
5462 | than embedded addresses. This code closely follows display_loc_list, but the | |
5463 | two are sufficiently different that combining things is very ugly. */ | |
5464 | ||
5465 | static void | |
5466 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
5467 | unsigned char **start_ptr, |
5468 | unsigned int debug_info_entry, | |
359ca075 | 5469 | dwarf_vma offset, |
9f272209 | 5470 | unsigned char **vstart_ptr, |
b4eb7656 | 5471 | int has_frame_base) |
4723351a | 5472 | { |
9f272209 | 5473 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5474 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5475 | unsigned long cu_offset; |
5476 | unsigned int pointer_size; | |
5477 | unsigned int offset_size; | |
5478 | int dwarf_version; | |
4723351a CC |
5479 | int entry_type; |
5480 | unsigned short length; | |
5481 | int need_frame_base; | |
fab128ef | 5482 | unsigned int idx; |
4723351a CC |
5483 | unsigned int bytes_read; |
5484 | ||
82b1b41b NC |
5485 | if (debug_info_entry >= num_debug_info_entries) |
5486 | { | |
5487 | warn (_("No debug information for loc lists of entry: %u\n"), | |
5488 | debug_info_entry); | |
5489 | return; | |
5490 | } | |
5491 | ||
5492 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5493 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5494 | offset_size = debug_information [debug_info_entry].offset_size; | |
5495 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5496 | ||
f41e4712 NC |
5497 | if (pointer_size < 2 || pointer_size > 8) |
5498 | { | |
5499 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5500 | pointer_size, debug_info_entry); | |
5501 | return; | |
5502 | } | |
5503 | ||
4723351a CC |
5504 | while (1) |
5505 | { | |
359ca075 | 5506 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 5507 | |
fab128ef | 5508 | if (start >= section_end) |
b4eb7656 AM |
5509 | { |
5510 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5511 | (unsigned long) offset); |
b4eb7656 AM |
5512 | break; |
5513 | } | |
4723351a | 5514 | |
0c588247 | 5515 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
5516 | |
5517 | if (vstart) | |
5518 | switch (entry_type) | |
5519 | { | |
5520 | default: | |
5521 | break; | |
5522 | ||
5523 | case 2: | |
5524 | case 3: | |
5525 | case 4: | |
5526 | { | |
5527 | dwarf_vma view; | |
5528 | dwarf_vma off = offset + (vstart - *start_ptr); | |
5529 | ||
5530 | view = read_uleb128 (vstart, &bytes_read, section_end); | |
5531 | vstart += bytes_read; | |
5532 | print_dwarf_view (view, 8, 1); | |
5533 | ||
5534 | view = read_uleb128 (vstart, &bytes_read, section_end); | |
5535 | vstart += bytes_read; | |
5536 | print_dwarf_view (view, 8, 1); | |
5537 | ||
5538 | printf (_("views at %8.8lx for:\n %*s "), | |
5539 | (unsigned long) off, 8, ""); | |
5540 | ||
5541 | } | |
5542 | break; | |
5543 | } | |
5544 | ||
4723351a | 5545 | switch (entry_type) |
b4eb7656 AM |
5546 | { |
5547 | case 0: /* A terminating entry. */ | |
5548 | *start_ptr = start; | |
9f272209 | 5549 | *vstart_ptr = vstart; |
b4eb7656 AM |
5550 | printf (_("<End of list>\n")); |
5551 | return; | |
5552 | case 1: /* A base-address entry. */ | |
5553 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5554 | start += bytes_read; | |
5555 | print_addr_index (idx, 8); | |
9f272209 | 5556 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
5557 | printf (_("(base address selection entry)\n")); |
5558 | continue; | |
5559 | case 2: /* A start/end entry. */ | |
5560 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5561 | start += bytes_read; | |
5562 | print_addr_index (idx, 8); | |
5563 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5564 | start += bytes_read; | |
5565 | print_addr_index (idx, 8); | |
5566 | break; | |
5567 | case 3: /* A start/length entry. */ | |
5568 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5569 | start += bytes_read; | |
5570 | print_addr_index (idx, 8); | |
5571 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
5572 | printf ("%08x ", idx); | |
5573 | break; | |
5574 | case 4: /* An offset pair entry. */ | |
5575 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
5576 | printf ("%08x ", idx); | |
5577 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
5578 | printf ("%08x ", idx); | |
5579 | break; | |
5580 | default: | |
5581 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
5582 | *start_ptr = start; | |
9f272209 | 5583 | *vstart_ptr = vstart; |
b4eb7656 AM |
5584 | return; |
5585 | } | |
4723351a CC |
5586 | |
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 | 5595 | if (start + length > section_end) |
b4eb7656 AM |
5596 | { |
5597 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5598 | (unsigned long) offset); |
b4eb7656 AM |
5599 | break; |
5600 | } | |
4723351a CC |
5601 | |
5602 | putchar ('('); | |
5603 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5604 | pointer_size, |
5605 | offset_size, | |
5606 | dwarf_version, | |
5607 | length, | |
5608 | cu_offset, section); | |
4723351a CC |
5609 | putchar (')'); |
5610 | ||
5611 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5612 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
5613 | |
5614 | putchar ('\n'); | |
5615 | ||
5616 | start += length; | |
5617 | } | |
5618 | ||
5619 | *start_ptr = start; | |
9f272209 | 5620 | *vstart_ptr = vstart; |
4723351a CC |
5621 | } |
5622 | ||
9f272209 AO |
5623 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
5624 | loc_views. */ | |
51d0d03f | 5625 | |
9f272209 | 5626 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
5627 | |
5628 | static int | |
5629 | loc_offsets_compar (const void *ap, const void *bp) | |
5630 | { | |
5631 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
5632 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
5633 | ||
9f272209 AO |
5634 | int ret = (a > b) - (b > a); |
5635 | if (ret) | |
5636 | return ret; | |
5637 | ||
5638 | a = loc_views[*(const unsigned int *) ap]; | |
5639 | b = loc_views[*(const unsigned int *) bp]; | |
5640 | ||
5641 | ret = (a > b) - (b > a); | |
5642 | ||
5643 | return ret; | |
51d0d03f JJ |
5644 | } |
5645 | ||
19e6b90e L |
5646 | static int |
5647 | display_debug_loc (struct dwarf_section *section, void *file) | |
5648 | { | |
9f272209 | 5649 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
5650 | unsigned long bytes; |
5651 | unsigned char *section_begin = start; | |
5652 | unsigned int num_loc_list = 0; | |
5653 | unsigned long last_offset = 0; | |
9f272209 | 5654 | unsigned long last_view = 0; |
19e6b90e L |
5655 | unsigned int first = 0; |
5656 | unsigned int i; | |
5657 | unsigned int j; | |
5658 | int seen_first_offset = 0; | |
51d0d03f | 5659 | int locs_sorted = 1; |
9f272209 | 5660 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 5661 | unsigned int *array = NULL; |
4723351a CC |
5662 | const char *suffix = strrchr (section->name, '.'); |
5663 | int is_dwo = 0; | |
77145576 JK |
5664 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
5665 | dwarf_vma expected_start = 0; | |
4723351a CC |
5666 | |
5667 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
5668 | is_dwo = 1; | |
19e6b90e L |
5669 | |
5670 | bytes = section->size; | |
19e6b90e L |
5671 | |
5672 | if (bytes == 0) | |
5673 | { | |
5674 | printf (_("\nThe %s section is empty.\n"), section->name); | |
5675 | return 0; | |
5676 | } | |
5677 | ||
77145576 JK |
5678 | if (is_loclists) |
5679 | { | |
5680 | unsigned char *hdrptr = section_begin; | |
5681 | dwarf_vma ll_length; | |
5682 | unsigned short ll_version; | |
5683 | unsigned char *end = section_begin + section->size; | |
5684 | unsigned char address_size, segment_selector_size; | |
5685 | uint32_t offset_entry_count; | |
5686 | ||
5687 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
5688 | if (ll_length == 0xffffffff) | |
5689 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
5690 | ||
5691 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
5692 | if (ll_version != 5) | |
5693 | { | |
5694 | warn (_("The %s section contains corrupt or " | |
5695 | "unsupported version number: %d.\n"), | |
5696 | section->name, ll_version); | |
5697 | return 0; | |
5698 | } | |
5699 | ||
5700 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
5701 | ||
5702 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
5703 | if (segment_selector_size != 0) | |
5704 | { | |
5705 | warn (_("The %s section contains " | |
5706 | "unsupported segment selector size: %d.\n"), | |
5707 | section->name, segment_selector_size); | |
5708 | return 0; | |
5709 | } | |
5710 | ||
5711 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
5712 | if (offset_entry_count != 0) | |
5713 | { | |
5714 | warn (_("The %s section contains " | |
5715 | "unsupported offset entry count: %d.\n"), | |
5716 | section->name, offset_entry_count); | |
5717 | return 0; | |
5718 | } | |
5719 | ||
5720 | expected_start = hdrptr - section_begin; | |
5721 | } | |
5722 | ||
1febe64d NC |
5723 | if (load_debug_info (file) == 0) |
5724 | { | |
5725 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
5726 | section->name); | |
5727 | return 0; | |
5728 | } | |
19e6b90e L |
5729 | |
5730 | /* Check the order of location list in .debug_info section. If | |
5731 | offsets of location lists are in the ascending order, we can | |
5732 | use `debug_information' directly. */ | |
5733 | for (i = 0; i < num_debug_info_entries; i++) | |
5734 | { | |
5735 | unsigned int num; | |
5736 | ||
5737 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
5738 | if (num > num_loc_list) |
5739 | num_loc_list = num; | |
19e6b90e L |
5740 | |
5741 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 5742 | if (locs_sorted && num != 0) |
19e6b90e L |
5743 | { |
5744 | if (!seen_first_offset) | |
5745 | { | |
5746 | /* This is the first location list. */ | |
5747 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 5748 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
5749 | first = i; |
5750 | seen_first_offset = 1; | |
5751 | j = 1; | |
5752 | } | |
5753 | else | |
5754 | j = 0; | |
5755 | ||
5756 | for (; j < num; j++) | |
5757 | { | |
5758 | if (last_offset > | |
9f272209 AO |
5759 | debug_information [i].loc_offsets [j] |
5760 | || (last_offset == debug_information [i].loc_offsets [j] | |
5761 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 5762 | { |
51d0d03f | 5763 | locs_sorted = 0; |
19e6b90e L |
5764 | break; |
5765 | } | |
5766 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 5767 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
5768 | } |
5769 | } | |
5770 | } | |
5771 | ||
19e6b90e L |
5772 | if (!seen_first_offset) |
5773 | error (_("No location lists in .debug_info section!\n")); | |
5774 | ||
d4bfc77b | 5775 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
5776 | && debug_information [first].loc_offsets [0] != expected_start |
5777 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
5778 | warn (_("Location lists in %s section start at 0x%s\n"), |
5779 | section->name, | |
5780 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 5781 | |
51d0d03f JJ |
5782 | if (!locs_sorted) |
5783 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
19e6b90e | 5784 | printf (_("Contents of the %s section:\n\n"), section->name); |
d1c4b12b NC |
5785 | if (reloc_at (section, 0)) |
5786 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
5787 | printf (_(" Offset Begin End Expression\n")); | |
19e6b90e L |
5788 | |
5789 | seen_first_offset = 0; | |
5790 | for (i = first; i < num_debug_info_entries; i++) | |
5791 | { | |
9f272209 | 5792 | dwarf_vma offset, voffset; |
359ca075 | 5793 | dwarf_vma base_address; |
d1c4b12b | 5794 | unsigned int k; |
19e6b90e L |
5795 | int has_frame_base; |
5796 | ||
51d0d03f JJ |
5797 | if (!locs_sorted) |
5798 | { | |
5799 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
5800 | array[k] = k; | |
5801 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 5802 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
5803 | qsort (array, debug_information [i].num_loc_offsets, |
5804 | sizeof (*array), loc_offsets_compar); | |
5805 | } | |
19e6b90e | 5806 | |
9f272209 | 5807 | int adjacent_view_loclists = 1; |
51d0d03f | 5808 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 5809 | { |
51d0d03f JJ |
5810 | j = locs_sorted ? k : array[k]; |
5811 | if (k | |
9f272209 | 5812 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 5813 | ? k - 1 : array [k - 1]] |
9f272209 AO |
5814 | == debug_information [i].loc_offsets [j]) |
5815 | && (debug_information [i].loc_views [locs_sorted | |
5816 | ? k - 1 : array [k - 1]] | |
5817 | == debug_information [i].loc_views [j])) | |
51d0d03f | 5818 | continue; |
19e6b90e | 5819 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 5820 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 5821 | next = section_begin + offset; |
9f272209 AO |
5822 | voffset = debug_information [i].loc_views [j]; |
5823 | if (voffset != vm1) | |
5824 | vnext = section_begin + voffset; | |
5825 | else | |
5826 | vnext = NULL; | |
19e6b90e L |
5827 | base_address = debug_information [i].base_address; |
5828 | ||
9f272209 AO |
5829 | if (vnext && vnext < next) |
5830 | { | |
5831 | vstart = vnext; | |
5832 | display_view_pair_list (section, &vstart, i, next); | |
5833 | if (start == vnext) | |
5834 | start = vstart; | |
5835 | } | |
5836 | ||
5837 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
5838 | seen_first_offset = 1; |
5839 | else | |
5840 | { | |
5841 | if (start < next) | |
5842 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 5843 | (unsigned long) (start - section_begin), |
c8071705 | 5844 | (unsigned long) offset); |
19e6b90e L |
5845 | else if (start > next) |
5846 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 5847 | (unsigned long) (start - section_begin), |
c8071705 | 5848 | (unsigned long) offset); |
19e6b90e L |
5849 | } |
5850 | start = next; | |
9f272209 | 5851 | vstart = vnext; |
19e6b90e L |
5852 | |
5853 | if (offset >= bytes) | |
5854 | { | |
5855 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 5856 | (unsigned long) offset); |
19e6b90e L |
5857 | continue; |
5858 | } | |
5859 | ||
9f272209 AO |
5860 | if (vnext && voffset >= bytes) |
5861 | { | |
5862 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
5863 | (unsigned long) voffset); | |
5864 | continue; | |
5865 | } | |
5866 | ||
77145576 JK |
5867 | if (!is_loclists) |
5868 | { | |
5869 | if (is_dwo) | |
5870 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 5871 | &vstart, has_frame_base); |
77145576 JK |
5872 | else |
5873 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 5874 | &vstart, has_frame_base); |
77145576 | 5875 | } |
b4eb7656 | 5876 | else |
77145576 JK |
5877 | { |
5878 | if (is_dwo) | |
5879 | warn (_("DWO is not yet supported.\n")); | |
5880 | else | |
5881 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
5882 | &vstart, has_frame_base); |
5883 | } | |
5884 | ||
5885 | /* FIXME: this arrangement is quite simplistic. Nothing | |
5886 | requires locview lists to be adjacent to corresponding | |
5887 | loclists, and a single loclist could be augmented by | |
5888 | different locview lists, and vice-versa, unlikely as it | |
5889 | is that it would make sense to do so. Hopefully we'll | |
5890 | have view pair support built into loclists before we ever | |
5891 | need to address all these possibilities. */ | |
5892 | if (adjacent_view_loclists && vnext | |
5893 | && vnext != start && vstart != next) | |
5894 | { | |
5895 | adjacent_view_loclists = 0; | |
5896 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 5897 | } |
9f272209 AO |
5898 | |
5899 | if (vnext && vnext == start) | |
5900 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
5901 | } |
5902 | } | |
031cd65f | 5903 | |
4723351a | 5904 | if (start < section->start + section->size) |
031cd65f | 5905 | warn (_("There are %ld unused bytes at the end of section %s\n"), |
4723351a | 5906 | (long) (section->start + section->size - start), section->name); |
98fb390a | 5907 | putchar ('\n'); |
51d0d03f | 5908 | free (array); |
19e6b90e L |
5909 | return 1; |
5910 | } | |
5911 | ||
5912 | static int | |
5913 | display_debug_str (struct dwarf_section *section, | |
5914 | void *file ATTRIBUTE_UNUSED) | |
5915 | { | |
5916 | unsigned char *start = section->start; | |
5917 | unsigned long bytes = section->size; | |
5918 | dwarf_vma addr = section->address; | |
5919 | ||
5920 | if (bytes == 0) | |
5921 | { | |
5922 | printf (_("\nThe %s section is empty.\n"), section->name); | |
5923 | return 0; | |
5924 | } | |
5925 | ||
5926 | printf (_("Contents of the %s section:\n\n"), section->name); | |
5927 | ||
5928 | while (bytes) | |
5929 | { | |
5930 | int j; | |
5931 | int k; | |
5932 | int lbytes; | |
5933 | ||
5934 | lbytes = (bytes > 16 ? 16 : bytes); | |
5935 | ||
5936 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
5937 | ||
5938 | for (j = 0; j < 16; j++) | |
5939 | { | |
5940 | if (j < lbytes) | |
5941 | printf ("%2.2x", start[j]); | |
5942 | else | |
5943 | printf (" "); | |
5944 | ||
5945 | if ((j & 3) == 3) | |
5946 | printf (" "); | |
5947 | } | |
5948 | ||
5949 | for (j = 0; j < lbytes; j++) | |
5950 | { | |
5951 | k = start[j]; | |
5952 | if (k >= ' ' && k < 0x80) | |
5953 | printf ("%c", k); | |
5954 | else | |
5955 | printf ("."); | |
5956 | } | |
5957 | ||
5958 | putchar ('\n'); | |
5959 | ||
5960 | start += lbytes; | |
5961 | addr += lbytes; | |
5962 | bytes -= lbytes; | |
5963 | } | |
5964 | ||
5965 | putchar ('\n'); | |
5966 | ||
5967 | return 1; | |
5968 | } | |
5969 | ||
19e6b90e L |
5970 | static int |
5971 | display_debug_info (struct dwarf_section *section, void *file) | |
5972 | { | |
4723351a | 5973 | return process_debug_info (section, file, section->abbrev_sec, 0, 0); |
19e6b90e L |
5974 | } |
5975 | ||
2b6f5997 CC |
5976 | static int |
5977 | display_debug_types (struct dwarf_section *section, void *file) | |
5978 | { | |
4723351a | 5979 | return process_debug_info (section, file, section->abbrev_sec, 0, 1); |
6f875884 TG |
5980 | } |
5981 | ||
5982 | static int | |
5983 | display_trace_info (struct dwarf_section *section, void *file) | |
5984 | { | |
4723351a | 5985 | return process_debug_info (section, file, section->abbrev_sec, 0, 0); |
2b6f5997 | 5986 | } |
19e6b90e L |
5987 | |
5988 | static int | |
5989 | display_debug_aranges (struct dwarf_section *section, | |
5990 | void *file ATTRIBUTE_UNUSED) | |
5991 | { | |
5992 | unsigned char *start = section->start; | |
5993 | unsigned char *end = start + section->size; | |
5994 | ||
80c35038 | 5995 | printf (_("Contents of the %s section:\n\n"), section->name); |
19e6b90e | 5996 | |
6e3d6dc1 NC |
5997 | /* It does not matter if this load fails, |
5998 | we test for that later on. */ | |
5999 | load_debug_info (file); | |
6000 | ||
19e6b90e L |
6001 | while (start < end) |
6002 | { | |
6003 | unsigned char *hdrptr; | |
6004 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 6005 | unsigned char *addr_ranges; |
2d9472a2 NC |
6006 | dwarf_vma length; |
6007 | dwarf_vma address; | |
53b8873b | 6008 | unsigned char address_size; |
19e6b90e | 6009 | int excess; |
bf5117e3 NC |
6010 | unsigned int offset_size; |
6011 | unsigned int initial_length_size; | |
19e6b90e L |
6012 | |
6013 | hdrptr = start; | |
6014 | ||
0c588247 | 6015 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
6016 | if (arange.ar_length == 0xffffffff) |
6017 | { | |
0c588247 | 6018 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
6019 | offset_size = 8; |
6020 | initial_length_size = 12; | |
6021 | } | |
6022 | else | |
6023 | { | |
6024 | offset_size = 4; | |
6025 | initial_length_size = 4; | |
6026 | } | |
6027 | ||
0c588247 NC |
6028 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
6029 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 6030 | |
6e3d6dc1 NC |
6031 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
6032 | && num_debug_info_entries > 0 | |
6033 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
6034 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 6035 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 6036 | |
0c588247 NC |
6037 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
6038 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
6039 | |
6040 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
6041 | { | |
67f101ee NC |
6042 | /* PR 19872: A version number of 0 probably means that there is |
6043 | padding at the end of the .debug_aranges section. Gold puts | |
6044 | it there when performing an incremental link, for example. | |
6045 | So do not generate a warning in this case. */ | |
6046 | if (arange.ar_version) | |
6047 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
6048 | break; |
6049 | } | |
6050 | ||
47704ddf KT |
6051 | printf (_(" Length: %ld\n"), |
6052 | (long) arange.ar_length); | |
19e6b90e | 6053 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
6054 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
6055 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
6056 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
6057 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
6058 | ||
53b8873b NC |
6059 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
6060 | ||
f41e4712 NC |
6061 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
6062 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
6063 | { |
6064 | error (_("Invalid address size in %s section!\n"), | |
6065 | section->name); | |
6066 | break; | |
6067 | } | |
6068 | ||
53b8873b NC |
6069 | /* The DWARF spec does not require that the address size be a power |
6070 | of two, but we do. This will have to change if we ever encounter | |
6071 | an uneven architecture. */ | |
6072 | if ((address_size & (address_size - 1)) != 0) | |
6073 | { | |
6074 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
6075 | break; | |
6076 | } | |
cecf136e | 6077 | |
209c9a13 NC |
6078 | if (address_size > 4) |
6079 | printf (_("\n Address Length\n")); | |
6080 | else | |
6081 | printf (_("\n Address Length\n")); | |
19e6b90e | 6082 | |
91d6fa6a | 6083 | addr_ranges = hdrptr; |
19e6b90e | 6084 | |
53b8873b NC |
6085 | /* Must pad to an alignment boundary that is twice the address size. */ |
6086 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 6087 | if (excess) |
91d6fa6a | 6088 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 6089 | |
ffc0f143 NC |
6090 | hdrptr = start + arange.ar_length + initial_length_size; |
6091 | if (hdrptr < start || hdrptr > end) | |
6092 | { | |
6093 | error (_("Excessive header length: %lx\n"), (long) arange.ar_length); | |
6094 | break; | |
6095 | } | |
6096 | start = hdrptr; | |
1617e571 | 6097 | |
91d6fa6a | 6098 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 6099 | { |
0c588247 NC |
6100 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
6101 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 6102 | |
80c35038 | 6103 | printf (" "); |
2d9472a2 NC |
6104 | print_dwarf_vma (address, address_size); |
6105 | print_dwarf_vma (length, address_size); | |
6106 | putchar ('\n'); | |
19e6b90e | 6107 | } |
19e6b90e L |
6108 | } |
6109 | ||
6110 | printf ("\n"); | |
6111 | ||
6112 | return 1; | |
6113 | } | |
6114 | ||
4723351a CC |
6115 | /* Comparison function for qsort. */ |
6116 | static int | |
6117 | comp_addr_base (const void * v0, const void * v1) | |
6118 | { | |
6119 | debug_info * info0 = (debug_info *) v0; | |
6120 | debug_info * info1 = (debug_info *) v1; | |
6121 | return info0->addr_base - info1->addr_base; | |
6122 | } | |
6123 | ||
6124 | /* Display the debug_addr section. */ | |
6125 | static int | |
6126 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 6127 | void *file) |
4723351a CC |
6128 | { |
6129 | debug_info **debug_addr_info; | |
6130 | unsigned char *entry; | |
6131 | unsigned char *end; | |
6132 | unsigned int i; | |
6133 | unsigned int count; | |
6134 | ||
6135 | if (section->size == 0) | |
6136 | { | |
6137 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6138 | return 0; | |
6139 | } | |
6140 | ||
6141 | if (load_debug_info (file) == 0) | |
6142 | { | |
6143 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6144 | section->name); | |
6145 | return 0; | |
6146 | } | |
6147 | ||
6148 | printf (_("Contents of the %s section:\n\n"), section->name); | |
6149 | ||
1306a742 NC |
6150 | /* PR 17531: file: cf38d01b. |
6151 | We use xcalloc because a corrupt file may not have initialised all of the | |
6152 | fields in the debug_info structure, which means that the sort below might | |
6153 | try to move uninitialised data. */ | |
6154 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 6155 | sizeof (debug_info *)); |
4723351a CC |
6156 | |
6157 | count = 0; | |
6158 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 6159 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
6160 | { |
6161 | /* PR 17531: file: cf38d01b. */ | |
6162 | if (debug_information[i].addr_base >= section->size) | |
6163 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
6164 | (unsigned long) debug_information[i].addr_base, i); | |
6165 | else | |
6166 | debug_addr_info [count++] = debug_information + i; | |
6167 | } | |
4723351a CC |
6168 | |
6169 | /* Add a sentinel to make iteration convenient. */ | |
6170 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
6171 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 6172 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 6173 | |
4723351a CC |
6174 | for (i = 0; i < count; i++) |
6175 | { | |
6176 | unsigned int idx; | |
fab128ef | 6177 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
6178 | |
6179 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 6180 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 6181 | |
fab128ef | 6182 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
6183 | entry = section->start + debug_addr_info [i]->addr_base; |
6184 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
6185 | idx = 0; | |
6186 | while (entry < end) | |
b4eb7656 AM |
6187 | { |
6188 | dwarf_vma base = byte_get (entry, address_size); | |
6189 | printf (_("\t%d:\t"), idx); | |
6190 | print_dwarf_vma (base, address_size); | |
6191 | printf ("\n"); | |
6192 | entry += address_size; | |
6193 | idx++; | |
6194 | } | |
4723351a CC |
6195 | } |
6196 | printf ("\n"); | |
6197 | ||
6198 | free (debug_addr_info); | |
6199 | return 1; | |
6200 | } | |
6201 | ||
6202 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
6203 | static int | |
6204 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 6205 | void *file ATTRIBUTE_UNUSED) |
4723351a CC |
6206 | { |
6207 | if (section->size == 0) | |
6208 | { | |
6209 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6210 | return 0; | |
6211 | } | |
6212 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
6213 | what the offset size is for this section. */ | |
6214 | return 1; | |
6215 | } | |
6216 | ||
01a8f077 JK |
6217 | /* Each debug_information[x].range_lists[y] gets this representation for |
6218 | sorting purposes. */ | |
6219 | ||
6220 | struct range_entry | |
467c65bc NC |
6221 | { |
6222 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 6223 | dwarf_vma ranges_offset; |
01a8f077 | 6224 | |
467c65bc NC |
6225 | /* Original debug_information to find parameters of the data. */ |
6226 | debug_info *debug_info_p; | |
6227 | }; | |
01a8f077 JK |
6228 | |
6229 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
6230 | ||
6231 | static int | |
6232 | range_entry_compar (const void *ap, const void *bp) | |
6233 | { | |
3f5e193b NC |
6234 | const struct range_entry *a_re = (const struct range_entry *) ap; |
6235 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
6236 | const dwarf_vma a = a_re->ranges_offset; |
6237 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
6238 | |
6239 | return (a > b) - (b > a); | |
6240 | } | |
6241 | ||
77145576 JK |
6242 | static void |
6243 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
6244 | unsigned int pointer_size, unsigned long offset, | |
6245 | unsigned long base_address) | |
6246 | { | |
6247 | while (start < finish) | |
6248 | { | |
6249 | dwarf_vma begin; | |
6250 | dwarf_vma end; | |
6251 | ||
6252 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6253 | if (start >= finish) | |
6254 | break; | |
6255 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6256 | ||
6257 | printf (" %8.8lx ", offset); | |
6258 | ||
6259 | if (begin == 0 && end == 0) | |
6260 | { | |
6261 | printf (_("<End of list>\n")); | |
6262 | break; | |
6263 | } | |
6264 | ||
6265 | /* Check base address specifiers. */ | |
6266 | if (is_max_address (begin, pointer_size) | |
6267 | && !is_max_address (end, pointer_size)) | |
6268 | { | |
6269 | base_address = end; | |
6270 | print_dwarf_vma (begin, pointer_size); | |
6271 | print_dwarf_vma (end, pointer_size); | |
6272 | printf ("(base address)\n"); | |
6273 | continue; | |
6274 | } | |
6275 | ||
6276 | print_dwarf_vma (begin + base_address, pointer_size); | |
6277 | print_dwarf_vma (end + base_address, pointer_size); | |
6278 | ||
6279 | if (begin == end) | |
6280 | fputs (_("(start == end)"), stdout); | |
6281 | else if (begin > end) | |
6282 | fputs (_("(start > end)"), stdout); | |
6283 | ||
6284 | putchar ('\n'); | |
6285 | } | |
6286 | } | |
6287 | ||
6288 | static void | |
6289 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
6290 | unsigned int pointer_size, unsigned long offset, | |
6291 | unsigned long base_address) | |
6292 | { | |
6293 | unsigned char *next = start; | |
6294 | ||
6295 | while (1) | |
6296 | { | |
6297 | unsigned long off = offset + (start - next); | |
6298 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
6299 | /* Initialize it due to a false compiler warning. */ |
6300 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
6301 | unsigned int bytes_read; |
6302 | ||
6303 | if (start + 1 > finish) | |
6304 | { | |
6305 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
6306 | offset); | |
6307 | break; | |
6308 | } | |
6309 | ||
6310 | printf (" %8.8lx ", off); | |
6311 | ||
6312 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
6313 | ||
6314 | switch (rlet) | |
6315 | { | |
6316 | case DW_RLE_end_of_list: | |
6317 | printf (_("<End of list>\n")); | |
6318 | break; | |
6319 | case DW_RLE_base_address: | |
6320 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
6321 | print_dwarf_vma (base_address, pointer_size); | |
6322 | printf (_("(base address)\n")); | |
6323 | break; | |
6324 | case DW_RLE_start_length: | |
6325 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6326 | length = read_uleb128 (start, &bytes_read, finish); | |
6327 | start += bytes_read; | |
6328 | end = begin + length; | |
6329 | break; | |
6330 | case DW_RLE_offset_pair: | |
6331 | begin = read_uleb128 (start, &bytes_read, finish); | |
6332 | start += bytes_read; | |
6333 | end = read_uleb128 (start, &bytes_read, finish); | |
6334 | start += bytes_read; | |
6335 | break; | |
6336 | case DW_RLE_start_end: | |
6337 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6338 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6339 | break; | |
6340 | default: | |
6341 | error (_("Invalid range list entry type %d\n"), rlet); | |
6342 | rlet = DW_RLE_end_of_list; | |
6343 | break; | |
6344 | } | |
6345 | if (rlet == DW_RLE_end_of_list) | |
6346 | break; | |
6347 | if (rlet == DW_RLE_base_address) | |
6348 | continue; | |
6349 | ||
6350 | print_dwarf_vma (begin + base_address, pointer_size); | |
6351 | print_dwarf_vma (end + base_address, pointer_size); | |
6352 | ||
6353 | if (begin == end) | |
6354 | fputs (_("(start == end)"), stdout); | |
6355 | else if (begin > end) | |
6356 | fputs (_("(start > end)"), stdout); | |
6357 | ||
6358 | putchar ('\n'); | |
6359 | } | |
6360 | } | |
6361 | ||
19e6b90e L |
6362 | static int |
6363 | display_debug_ranges (struct dwarf_section *section, | |
6364 | void *file ATTRIBUTE_UNUSED) | |
6365 | { | |
6366 | unsigned char *start = section->start; | |
a2ff7a4b | 6367 | unsigned char *last_start = start; |
f6f0e17b | 6368 | unsigned long bytes = section->size; |
19e6b90e | 6369 | unsigned char *section_begin = start; |
f6f0e17b | 6370 | unsigned char *finish = start + bytes; |
01a8f077 JK |
6371 | unsigned int num_range_list, i; |
6372 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
6373 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
6374 | /* Initialize it due to a false compiler warning. */ | |
6375 | unsigned char address_size = 0; | |
19e6b90e | 6376 | |
19e6b90e L |
6377 | if (bytes == 0) |
6378 | { | |
6379 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6380 | return 0; | |
6381 | } | |
6382 | ||
77145576 JK |
6383 | if (is_rnglists) |
6384 | { | |
6385 | dwarf_vma initial_length; | |
6386 | unsigned int initial_length_size; | |
6387 | unsigned char segment_selector_size; | |
6388 | unsigned int offset_size, offset_entry_count; | |
6389 | unsigned short version; | |
6390 | ||
6391 | /* Get and check the length of the block. */ | |
6392 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
6393 | ||
6394 | if (initial_length == 0xffffffff) | |
6395 | { | |
6396 | /* This section is 64-bit DWARF 3. */ | |
6397 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
6398 | offset_size = 8; | |
6399 | initial_length_size = 12; | |
6400 | } | |
6401 | else | |
6402 | { | |
6403 | offset_size = 4; | |
6404 | initial_length_size = 4; | |
6405 | } | |
6406 | ||
6407 | if (initial_length + initial_length_size > section->size) | |
6408 | { | |
6409 | /* If the length field has a relocation against it, then we should | |
6410 | not complain if it is inaccurate (and probably negative). | |
6411 | It is copied from .debug_line handling code. */ | |
6412 | if (reloc_at (section, (start - section->start) - offset_size)) | |
6413 | { | |
6414 | initial_length = (finish - start) - initial_length_size; | |
6415 | } | |
6416 | else | |
6417 | { | |
6418 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
6419 | (long) initial_length); | |
6420 | return 0; | |
6421 | } | |
6422 | } | |
6423 | ||
6424 | /* Get and check the version number. */ | |
6425 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
6426 | ||
6427 | if (version != 5) | |
6428 | { | |
6429 | warn (_("Only DWARF version 5 debug_rnglists info " | |
6430 | "is currently supported.\n")); | |
6431 | return 0; | |
6432 | } | |
6433 | ||
6434 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
6435 | ||
6436 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
6437 | if (segment_selector_size != 0) | |
6438 | { | |
6439 | warn (_("The %s section contains " | |
6440 | "unsupported segment selector size: %d.\n"), | |
6441 | section->name, segment_selector_size); | |
6442 | return 0; | |
6443 | } | |
6444 | ||
6445 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
6446 | if (offset_entry_count != 0) | |
6447 | { | |
6448 | warn (_("The %s section contains " | |
6449 | "unsupported offset entry count: %u.\n"), | |
6450 | section->name, offset_entry_count); | |
6451 | return 0; | |
6452 | } | |
6453 | } | |
6454 | ||
1febe64d NC |
6455 | if (load_debug_info (file) == 0) |
6456 | { | |
6457 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6458 | section->name); | |
6459 | return 0; | |
6460 | } | |
19e6b90e | 6461 | |
01a8f077 | 6462 | num_range_list = 0; |
19e6b90e | 6463 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 6464 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 6465 | |
01a8f077 | 6466 | if (num_range_list == 0) |
4723351a CC |
6467 | { |
6468 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 6469 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
6470 | printf (_("No range lists in .debug_info section.\n")); |
6471 | return 1; | |
6472 | } | |
19e6b90e | 6473 | |
3f5e193b NC |
6474 | range_entries = (struct range_entry *) |
6475 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 6476 | range_entry_fill = range_entries; |
19e6b90e | 6477 | |
01a8f077 JK |
6478 | for (i = 0; i < num_debug_info_entries; i++) |
6479 | { | |
6480 | debug_info *debug_info_p = &debug_information[i]; | |
6481 | unsigned int j; | |
6482 | ||
6483 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
6484 | { | |
6485 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
6486 | range_entry_fill->debug_info_p = debug_info_p; | |
6487 | range_entry_fill++; | |
19e6b90e L |
6488 | } |
6489 | } | |
6490 | ||
01a8f077 JK |
6491 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
6492 | range_entry_compar); | |
19e6b90e | 6493 | |
d493b283 | 6494 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 6495 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 6496 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e L |
6497 | |
6498 | printf (_("Contents of the %s section:\n\n"), section->name); | |
6499 | printf (_(" Offset Begin End\n")); | |
6500 | ||
01a8f077 | 6501 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 6502 | { |
01a8f077 JK |
6503 | struct range_entry *range_entry = &range_entries[i]; |
6504 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 6505 | unsigned int pointer_size; |
359ca075 | 6506 | dwarf_vma offset; |
01a8f077 | 6507 | unsigned char *next; |
359ca075 | 6508 | dwarf_vma base_address; |
19e6b90e | 6509 | |
77145576 | 6510 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 6511 | offset = range_entry->ranges_offset; |
01a8f077 JK |
6512 | next = section_begin + offset; |
6513 | base_address = debug_info_p->base_address; | |
cecf136e | 6514 | |
f41e4712 NC |
6515 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
6516 | if (pointer_size < 2 || pointer_size > 8) | |
6517 | { | |
6518 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 6519 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
6520 | continue; |
6521 | } | |
b4eb7656 | 6522 | |
4723351a | 6523 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 6524 | { |
01a8f077 JK |
6525 | if (start < next) |
6526 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
6527 | (unsigned long) (start - section_begin), | |
6528 | (unsigned long) (next - section_begin), section->name); | |
6529 | else if (start > next) | |
a2ff7a4b AM |
6530 | { |
6531 | if (next == last_start) | |
6532 | continue; | |
6533 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
6534 | (unsigned long) (start - section_begin), | |
6535 | (unsigned long) (next - section_begin), section->name); | |
6536 | } | |
01a8f077 JK |
6537 | } |
6538 | start = next; | |
a2ff7a4b | 6539 | last_start = next; |
19e6b90e | 6540 | |
77145576 JK |
6541 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
6542 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
6543 | } |
6544 | putchar ('\n'); | |
01a8f077 JK |
6545 | |
6546 | free (range_entries); | |
6547 | ||
19e6b90e L |
6548 | return 1; |
6549 | } | |
6550 | ||
6551 | typedef struct Frame_Chunk | |
6552 | { | |
6553 | struct Frame_Chunk *next; | |
6554 | unsigned char *chunk_start; | |
a1165289 | 6555 | unsigned int ncols; |
19e6b90e L |
6556 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
6557 | short int *col_type; | |
6558 | int *col_offset; | |
6559 | char *augmentation; | |
6560 | unsigned int code_factor; | |
6561 | int data_factor; | |
bf5117e3 NC |
6562 | dwarf_vma pc_begin; |
6563 | dwarf_vma pc_range; | |
19e6b90e | 6564 | int cfa_reg; |
c8071705 | 6565 | dwarf_vma cfa_offset; |
a1165289 | 6566 | unsigned int ra; |
19e6b90e L |
6567 | unsigned char fde_encoding; |
6568 | unsigned char cfa_exp; | |
604282a7 JJ |
6569 | unsigned char ptr_size; |
6570 | unsigned char segment_size; | |
19e6b90e L |
6571 | } |
6572 | Frame_Chunk; | |
6573 | ||
665ce1f6 L |
6574 | static const char *const *dwarf_regnames; |
6575 | static unsigned int dwarf_regnames_count; | |
6576 | ||
19e6b90e L |
6577 | /* A marker for a col_type that means this column was never referenced |
6578 | in the frame info. */ | |
6579 | #define DW_CFA_unreferenced (-1) | |
6580 | ||
a1165289 | 6581 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
6582 | -1 for invalid reg. */ |
6583 | ||
6584 | static int | |
6585 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 6586 | { |
a1165289 | 6587 | unsigned int prev = fc->ncols; |
19e6b90e | 6588 | |
665ce1f6 L |
6589 | if (reg < (unsigned int) fc->ncols) |
6590 | return 0; | |
6591 | ||
6592 | if (dwarf_regnames_count | |
6593 | && reg > dwarf_regnames_count) | |
6594 | return -1; | |
19e6b90e L |
6595 | |
6596 | fc->ncols = reg + 1; | |
a1165289 NC |
6597 | /* PR 17512: file: 10450-2643-0.004. |
6598 | If reg == -1 then this can happen... */ | |
6599 | if (fc->ncols == 0) | |
6600 | return -1; | |
6601 | ||
06614111 NC |
6602 | /* PR 17512: file: 2844a11d. */ |
6603 | if (fc->ncols > 1024) | |
6604 | { | |
6605 | error (_("Unfeasibly large register number: %u\n"), reg); | |
6606 | fc->ncols = 0; | |
6607 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
6608 | we ever encounter a valid binary that exceeds it. */ | |
6609 | return -1; | |
6610 | } | |
6611 | ||
3f5e193b | 6612 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 6613 | sizeof (short int)); |
3f5e193b | 6614 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 6615 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
6616 | if (fc->col_type == NULL || fc->col_offset == NULL) |
6617 | { | |
6618 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
6619 | fc->ncols); | |
6620 | fc->ncols = 0; | |
6621 | return -1; | |
6622 | } | |
19e6b90e L |
6623 | |
6624 | while (prev < fc->ncols) | |
6625 | { | |
6626 | fc->col_type[prev] = DW_CFA_unreferenced; | |
6627 | fc->col_offset[prev] = 0; | |
6628 | prev++; | |
6629 | } | |
665ce1f6 | 6630 | return 1; |
19e6b90e L |
6631 | } |
6632 | ||
2dc4cec1 L |
6633 | static const char *const dwarf_regnames_i386[] = |
6634 | { | |
43234a1e L |
6635 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
6636 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
6637 | "eip", "eflags", NULL, /* 8 - 10 */ | |
6638 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
6639 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
6640 | NULL, NULL, /* 19 - 20 */ | |
6641 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
6642 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
6643 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
6644 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
6645 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
6646 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
6647 | "tr", "ldtr", /* 48 - 49 */ | |
6648 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
6649 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
6650 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
6651 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
6652 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
6653 | NULL, NULL, NULL, /* 90 - 92 */ | |
6654 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
6655 | }; |
6656 | ||
3d875af5 L |
6657 | static const char *const dwarf_regnames_iamcu[] = |
6658 | { | |
6659 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
6660 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
6661 | "eip", "eflags", NULL, /* 8 - 10 */ | |
6662 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
6663 | NULL, NULL, /* 19 - 20 */ | |
6664 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
6665 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
6666 | NULL, NULL, NULL, /* 37 - 39 */ | |
6667 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
6668 | "tr", "ldtr", /* 48 - 49 */ | |
6669 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
6670 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
6671 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
6672 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
6673 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
6674 | NULL, NULL, NULL, /* 90 - 92 */ | |
6675 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
6676 | }; | |
6677 | ||
b129eb0e RH |
6678 | void |
6679 | init_dwarf_regnames_i386 (void) | |
6680 | { | |
6681 | dwarf_regnames = dwarf_regnames_i386; | |
6682 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
6683 | } | |
6684 | ||
3d875af5 L |
6685 | void |
6686 | init_dwarf_regnames_iamcu (void) | |
6687 | { | |
6688 | dwarf_regnames = dwarf_regnames_iamcu; | |
6689 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
6690 | } | |
6691 | ||
2dc4cec1 L |
6692 | static const char *const dwarf_regnames_x86_64[] = |
6693 | { | |
6694 | "rax", "rdx", "rcx", "rbx", | |
6695 | "rsi", "rdi", "rbp", "rsp", | |
6696 | "r8", "r9", "r10", "r11", | |
6697 | "r12", "r13", "r14", "r15", | |
6698 | "rip", | |
6699 | "xmm0", "xmm1", "xmm2", "xmm3", | |
6700 | "xmm4", "xmm5", "xmm6", "xmm7", | |
6701 | "xmm8", "xmm9", "xmm10", "xmm11", | |
6702 | "xmm12", "xmm13", "xmm14", "xmm15", | |
6703 | "st0", "st1", "st2", "st3", | |
6704 | "st4", "st5", "st6", "st7", | |
6705 | "mm0", "mm1", "mm2", "mm3", | |
6706 | "mm4", "mm5", "mm6", "mm7", | |
6707 | "rflags", | |
6708 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
6709 | "fs.base", "gs.base", NULL, NULL, | |
6710 | "tr", "ldtr", | |
43234a1e L |
6711 | "mxcsr", "fcw", "fsw", |
6712 | "xmm16", "xmm17", "xmm18", "xmm19", | |
6713 | "xmm20", "xmm21", "xmm22", "xmm23", | |
6714 | "xmm24", "xmm25", "xmm26", "xmm27", | |
6715 | "xmm28", "xmm29", "xmm30", "xmm31", | |
6716 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
6717 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
6718 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
6719 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
6720 | NULL, NULL, NULL, /* 115 - 117 */ | |
6721 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
6722 | }; |
6723 | ||
b129eb0e RH |
6724 | void |
6725 | init_dwarf_regnames_x86_64 (void) | |
6726 | { | |
6727 | dwarf_regnames = dwarf_regnames_x86_64; | |
6728 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
6729 | } | |
6730 | ||
4ee22035 RH |
6731 | static const char *const dwarf_regnames_aarch64[] = |
6732 | { | |
b4eb7656 AM |
6733 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
6734 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
6735 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
6736 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
6737 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
6738 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
6739 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
6740 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
b4eb7656 AM |
6741 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
6742 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
6743 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
6744 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
6745 | }; | |
6746 | ||
6747 | void | |
6748 | init_dwarf_regnames_aarch64 (void) | |
6749 | { | |
6750 | dwarf_regnames = dwarf_regnames_aarch64; | |
6751 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
6752 | } | |
6753 | ||
d6bb17b0 AA |
6754 | static const char *const dwarf_regnames_s390[] = |
6755 | { | |
6756 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
6757 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
6758 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
6759 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
6760 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
6761 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
6762 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
6763 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
6764 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
6765 | "pswm", "pswa", | |
6766 | NULL, NULL, | |
6767 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
6768 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
6769 | }; | |
6770 | ||
6771 | void | |
6772 | init_dwarf_regnames_s390 (void) | |
6773 | { | |
6774 | dwarf_regnames = dwarf_regnames_s390; | |
6775 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
6776 | } | |
6777 | ||
2dc4cec1 L |
6778 | void |
6779 | init_dwarf_regnames (unsigned int e_machine) | |
6780 | { | |
6781 | switch (e_machine) | |
6782 | { | |
6783 | case EM_386: | |
b129eb0e | 6784 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
6785 | break; |
6786 | ||
3d875af5 L |
6787 | case EM_IAMCU: |
6788 | init_dwarf_regnames_iamcu (); | |
6789 | break; | |
6790 | ||
2dc4cec1 | 6791 | case EM_X86_64: |
7f502d6c | 6792 | case EM_L1OM: |
7a9068fe | 6793 | case EM_K1OM: |
b129eb0e | 6794 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
6795 | break; |
6796 | ||
4ee22035 RH |
6797 | case EM_AARCH64: |
6798 | init_dwarf_regnames_aarch64 (); | |
6799 | break; | |
6800 | ||
d6bb17b0 AA |
6801 | case EM_S390: |
6802 | init_dwarf_regnames_s390 (); | |
6803 | break; | |
6804 | ||
2dc4cec1 L |
6805 | default: |
6806 | break; | |
6807 | } | |
6808 | } | |
6809 | ||
6810 | static const char * | |
6811 | regname (unsigned int regno, int row) | |
6812 | { | |
6813 | static char reg[64]; | |
7f2c8a1d | 6814 | |
2dc4cec1 L |
6815 | if (dwarf_regnames |
6816 | && regno < dwarf_regnames_count | |
6817 | && dwarf_regnames [regno] != NULL) | |
6818 | { | |
6819 | if (row) | |
6820 | return dwarf_regnames [regno]; | |
6821 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, | |
6822 | dwarf_regnames [regno]); | |
6823 | } | |
6824 | else | |
6825 | snprintf (reg, sizeof (reg), "r%d", regno); | |
6826 | return reg; | |
6827 | } | |
6828 | ||
19e6b90e | 6829 | static void |
a1165289 | 6830 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 6831 | { |
a1165289 | 6832 | unsigned int r; |
19e6b90e L |
6833 | char tmp[100]; |
6834 | ||
d8024a91 | 6835 | if (*max_regs != fc->ncols) |
19e6b90e L |
6836 | *max_regs = fc->ncols; |
6837 | ||
6838 | if (*need_col_headers) | |
6839 | { | |
91d6fa6a | 6840 | static const char *sloc = " LOC"; |
2dc4cec1 | 6841 | |
19e6b90e L |
6842 | *need_col_headers = 0; |
6843 | ||
91d6fa6a | 6844 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
6845 | |
6846 | for (r = 0; r < *max_regs; r++) | |
6847 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
6848 | { | |
6849 | if (r == fc->ra) | |
50751e18 | 6850 | printf ("ra "); |
19e6b90e | 6851 | else |
2dc4cec1 | 6852 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
6853 | } |
6854 | ||
6855 | printf ("\n"); | |
6856 | } | |
6857 | ||
bf5117e3 | 6858 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
6859 | if (fc->cfa_exp) |
6860 | strcpy (tmp, "exp"); | |
6861 | else | |
c8071705 | 6862 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
6863 | printf ("%-8s ", tmp); |
6864 | ||
6865 | for (r = 0; r < fc->ncols; r++) | |
6866 | { | |
6867 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
6868 | { | |
6869 | switch (fc->col_type[r]) | |
6870 | { | |
6871 | case DW_CFA_undefined: | |
6872 | strcpy (tmp, "u"); | |
6873 | break; | |
6874 | case DW_CFA_same_value: | |
6875 | strcpy (tmp, "s"); | |
6876 | break; | |
6877 | case DW_CFA_offset: | |
6878 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
6879 | break; | |
12eae2d3 JJ |
6880 | case DW_CFA_val_offset: |
6881 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
6882 | break; | |
19e6b90e | 6883 | case DW_CFA_register: |
2dc4cec1 | 6884 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
6885 | break; |
6886 | case DW_CFA_expression: | |
6887 | strcpy (tmp, "exp"); | |
6888 | break; | |
12eae2d3 JJ |
6889 | case DW_CFA_val_expression: |
6890 | strcpy (tmp, "vexp"); | |
6891 | break; | |
19e6b90e L |
6892 | default: |
6893 | strcpy (tmp, "n/a"); | |
6894 | break; | |
6895 | } | |
2dc4cec1 | 6896 | printf ("%-5s ", tmp); |
19e6b90e L |
6897 | } |
6898 | } | |
6899 | printf ("\n"); | |
6900 | } | |
6901 | ||
49727e46 | 6902 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 6903 | |
49727e46 AM |
6904 | static unsigned char * |
6905 | read_cie (unsigned char *start, unsigned char *end, | |
6906 | Frame_Chunk **p_cie, int *p_version, | |
6907 | unsigned long *p_aug_len, unsigned char **p_aug) | |
6908 | { | |
6909 | int version; | |
6910 | Frame_Chunk *fc; | |
6911 | unsigned int length_return; | |
6912 | unsigned char *augmentation_data = NULL; | |
6913 | unsigned long augmentation_data_len = 0; | |
6914 | ||
041830e0 | 6915 | * p_cie = NULL; |
f41e4712 NC |
6916 | /* PR 17512: file: 001-228113-0.004. */ |
6917 | if (start >= end) | |
6918 | return end; | |
6919 | ||
49727e46 AM |
6920 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
6921 | memset (fc, 0, sizeof (Frame_Chunk)); | |
6922 | ||
6923 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
6924 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
6925 | ||
6926 | version = *start++; | |
6927 | ||
6928 | fc->augmentation = (char *) start; | |
f41e4712 NC |
6929 | /* PR 17512: file: 001-228113-0.004. |
6930 | Skip past augmentation name, but avoid running off the end of the data. */ | |
6931 | while (start < end) | |
6932 | if (* start ++ == '\0') | |
6933 | break; | |
6934 | if (start == end) | |
6935 | { | |
6936 | warn (_("No terminator for augmentation name\n")); | |
6937 | return start; | |
6938 | } | |
49727e46 AM |
6939 | |
6940 | if (strcmp (fc->augmentation, "eh") == 0) | |
6941 | start += eh_addr_size; | |
6942 | ||
6943 | if (version >= 4) | |
6944 | { | |
6945 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
6946 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
6947 | { | |
6948 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
6949 | return end; | |
6950 | } | |
6951 | ||
49727e46 | 6952 | GET (fc->segment_size, 1); |
77ef8654 NC |
6953 | /* PR 17512: file: e99d2804. */ |
6954 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
6955 | { | |
6956 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
6957 | return end; | |
6958 | } | |
6959 | ||
49727e46 AM |
6960 | eh_addr_size = fc->ptr_size; |
6961 | } | |
6962 | else | |
6963 | { | |
6964 | fc->ptr_size = eh_addr_size; | |
6965 | fc->segment_size = 0; | |
6966 | } | |
7f2c8a1d NC |
6967 | READ_ULEB (fc->code_factor); |
6968 | READ_SLEB (fc->data_factor); | |
49727e46 AM |
6969 | if (version == 1) |
6970 | { | |
6971 | GET (fc->ra, 1); | |
6972 | } | |
6973 | else | |
6974 | { | |
7f2c8a1d | 6975 | READ_ULEB (fc->ra); |
49727e46 AM |
6976 | } |
6977 | ||
6978 | if (fc->augmentation[0] == 'z') | |
6979 | { | |
7f2c8a1d | 6980 | READ_ULEB (augmentation_data_len); |
49727e46 AM |
6981 | augmentation_data = start; |
6982 | start += augmentation_data_len; | |
a1165289 NC |
6983 | /* PR 17512: file: 11042-2589-0.004. */ |
6984 | if (start > end) | |
6985 | { | |
7f2c8a1d NC |
6986 | warn (_("Augmentation data too long: %#lx, expected at most %#lx\n"), |
6987 | augmentation_data_len, (long)((end - start) + augmentation_data_len)); | |
a1165289 NC |
6988 | return end; |
6989 | } | |
49727e46 AM |
6990 | } |
6991 | ||
6992 | if (augmentation_data_len) | |
6993 | { | |
058037d3 NC |
6994 | unsigned char *p; |
6995 | unsigned char *q; | |
6996 | unsigned char *qend; | |
b4eb7656 | 6997 | |
49727e46 AM |
6998 | p = (unsigned char *) fc->augmentation + 1; |
6999 | q = augmentation_data; | |
058037d3 NC |
7000 | qend = q + augmentation_data_len; |
7001 | ||
7002 | /* PR 17531: file: 015adfaa. */ | |
7003 | if (qend < q) | |
7004 | { | |
7005 | warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len); | |
7006 | augmentation_data_len = 0; | |
7007 | } | |
49727e46 | 7008 | |
a1165289 | 7009 | while (p < end && q < augmentation_data + augmentation_data_len) |
49727e46 AM |
7010 | { |
7011 | if (*p == 'L') | |
7012 | q++; | |
7013 | else if (*p == 'P') | |
7014 | q += 1 + size_of_encoded_value (*q); | |
7015 | else if (*p == 'R') | |
7016 | fc->fde_encoding = *q++; | |
7017 | else if (*p == 'S') | |
7018 | ; | |
7019 | else | |
7020 | break; | |
7021 | p++; | |
7022 | } | |
c361b9ac NC |
7023 | /* Note - it is OK if this loop terminates with q < qend. |
7024 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
7025 | } |
7026 | ||
7027 | *p_cie = fc; | |
7028 | if (p_version) | |
7029 | *p_version = version; | |
7030 | if (p_aug_len) | |
7031 | { | |
7032 | *p_aug_len = augmentation_data_len; | |
7033 | *p_aug = augmentation_data; | |
7034 | } | |
7035 | return start; | |
7036 | } | |
7037 | ||
19e6b90e L |
7038 | static int |
7039 | display_debug_frames (struct dwarf_section *section, | |
7040 | void *file ATTRIBUTE_UNUSED) | |
7041 | { | |
7042 | unsigned char *start = section->start; | |
7043 | unsigned char *end = start + section->size; | |
7044 | unsigned char *section_start = start; | |
49727e46 | 7045 | Frame_Chunk *chunks = 0, *forward_refs = 0; |
19e6b90e L |
7046 | Frame_Chunk *remembered_state = 0; |
7047 | Frame_Chunk *rs; | |
7048 | int is_eh = strcmp (section->name, ".eh_frame") == 0; | |
7049 | unsigned int length_return; | |
a1165289 | 7050 | unsigned int max_regs = 0; |
665ce1f6 | 7051 | const char *bad_reg = _("bad register: "); |
77ef8654 | 7052 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 7053 | |
80c35038 | 7054 | printf (_("Contents of the %s section:\n"), section->name); |
19e6b90e L |
7055 | |
7056 | while (start < end) | |
7057 | { | |
7058 | unsigned char *saved_start; | |
7059 | unsigned char *block_end; | |
bf5117e3 NC |
7060 | dwarf_vma length; |
7061 | dwarf_vma cie_id; | |
19e6b90e L |
7062 | Frame_Chunk *fc; |
7063 | Frame_Chunk *cie; | |
7064 | int need_col_headers = 1; | |
7065 | unsigned char *augmentation_data = NULL; | |
7066 | unsigned long augmentation_data_len = 0; | |
bf5117e3 NC |
7067 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
7068 | unsigned int offset_size; | |
7069 | unsigned int initial_length_size; | |
5b6312fd | 7070 | bfd_boolean all_nops; |
19e6b90e L |
7071 | |
7072 | saved_start = start; | |
19e6b90e | 7073 | |
0c588247 | 7074 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 7075 | |
19e6b90e L |
7076 | if (length == 0) |
7077 | { | |
7078 | printf ("\n%08lx ZERO terminator\n\n", | |
7079 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
7080 | /* Skip any zero terminators that directly follow. |
7081 | A corrupt section size could have loaded a whole | |
7082 | slew of zero filled memory bytes. eg | |
7083 | PR 17512: file: 070-19381-0.004. */ | |
7084 | while (start < end && * start == 0) | |
7085 | ++ start; | |
b758e50f | 7086 | continue; |
19e6b90e L |
7087 | } |
7088 | ||
7089 | if (length == 0xffffffff) | |
7090 | { | |
0c588247 | 7091 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
7092 | offset_size = 8; |
7093 | initial_length_size = 12; | |
7094 | } | |
7095 | else | |
7096 | { | |
7097 | offset_size = 4; | |
7098 | initial_length_size = 4; | |
7099 | } | |
7100 | ||
7101 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 7102 | if (block_end > end || block_end < start) |
53b8873b | 7103 | { |
bf5117e3 NC |
7104 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
7105 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
7106 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
7107 | block_end = end; |
7108 | } | |
0c588247 NC |
7109 | |
7110 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 7111 | |
846a11e4 NC |
7112 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
7113 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
7114 | { |
7115 | int version; | |
a1165289 | 7116 | unsigned int mreg; |
19e6b90e | 7117 | |
49727e46 AM |
7118 | start = read_cie (start, end, &cie, &version, |
7119 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
7120 | /* PR 17512: file: 027-135133-0.005. */ |
7121 | if (cie == NULL) | |
7122 | break; | |
a1165289 | 7123 | |
49727e46 | 7124 | fc = cie; |
19e6b90e L |
7125 | fc->next = chunks; |
7126 | chunks = fc; | |
7127 | fc->chunk_start = saved_start; | |
a1165289 | 7128 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7129 | if (mreg < fc->ra) |
7130 | mreg = fc->ra; | |
06614111 NC |
7131 | if (frame_need_space (fc, mreg) < 0) |
7132 | break; | |
49727e46 AM |
7133 | if (fc->fde_encoding) |
7134 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 7135 | |
bf5117e3 NC |
7136 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
7137 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 7138 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 7139 | |
19e6b90e | 7140 | if (do_debug_frames_interp) |
bf5117e3 NC |
7141 | { |
7142 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
7143 | fc->code_factor, fc->data_factor, fc->ra); | |
7144 | } | |
19e6b90e L |
7145 | else |
7146 | { | |
bf5117e3 | 7147 | printf ("CIE\n"); |
19e6b90e L |
7148 | printf (" Version: %d\n", version); |
7149 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
7150 | if (version >= 4) |
7151 | { | |
7152 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
7153 | printf (" Segment Size: %u\n", fc->segment_size); | |
7154 | } | |
19e6b90e L |
7155 | printf (" Code alignment factor: %u\n", fc->code_factor); |
7156 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
7157 | printf (" Return address column: %d\n", fc->ra); | |
7158 | ||
7159 | if (augmentation_data_len) | |
7160 | { | |
7161 | unsigned long i; | |
a1165289 | 7162 | |
19e6b90e L |
7163 | printf (" Augmentation data: "); |
7164 | for (i = 0; i < augmentation_data_len; ++i) | |
a1165289 NC |
7165 | /* FIXME: If do_wide is FALSE, then we should |
7166 | add carriage returns at 80 columns... */ | |
19e6b90e L |
7167 | printf (" %02x", augmentation_data[i]); |
7168 | putchar ('\n'); | |
7169 | } | |
7170 | putchar ('\n'); | |
7171 | } | |
19e6b90e L |
7172 | } |
7173 | else | |
7174 | { | |
7175 | unsigned char *look_for; | |
7176 | static Frame_Chunk fde_fc; | |
604282a7 | 7177 | unsigned long segment_selector; |
19e6b90e | 7178 | |
49727e46 AM |
7179 | if (is_eh) |
7180 | { | |
7181 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
7182 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
7183 | } | |
7184 | else | |
7185 | look_for = section_start + cie_id; | |
19e6b90e | 7186 | |
49727e46 AM |
7187 | if (look_for <= saved_start) |
7188 | { | |
7189 | for (cie = chunks; cie ; cie = cie->next) | |
7190 | if (cie->chunk_start == look_for) | |
7191 | break; | |
7192 | } | |
7193 | else | |
7194 | { | |
7195 | for (cie = forward_refs; cie ; cie = cie->next) | |
7196 | if (cie->chunk_start == look_for) | |
7197 | break; | |
7198 | if (!cie) | |
7199 | { | |
7200 | unsigned int off_size; | |
7201 | unsigned char *cie_scan; | |
19e6b90e | 7202 | |
49727e46 AM |
7203 | cie_scan = look_for; |
7204 | off_size = 4; | |
7205 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
7206 | if (length == 0xffffffff) | |
7207 | { | |
7208 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
7209 | off_size = 8; | |
7210 | } | |
7211 | if (length != 0) | |
7212 | { | |
7213 | dwarf_vma c_id; | |
7214 | ||
7215 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
7216 | if (is_eh | |
7217 | ? c_id == 0 | |
7218 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
7219 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
7220 | { | |
7221 | int version; | |
a1165289 | 7222 | unsigned int mreg; |
49727e46 AM |
7223 | |
7224 | read_cie (cie_scan, end, &cie, &version, | |
7225 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
7226 | /* PR 17512: file: 3450-2098-0.004. */ |
7227 | if (cie == NULL) | |
7228 | { | |
7229 | warn (_("Failed to read CIE information\n")); | |
7230 | break; | |
7231 | } | |
49727e46 AM |
7232 | cie->next = forward_refs; |
7233 | forward_refs = cie; | |
7234 | cie->chunk_start = look_for; | |
a1165289 | 7235 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7236 | if (mreg < cie->ra) |
7237 | mreg = cie->ra; | |
06614111 NC |
7238 | if (frame_need_space (cie, mreg) < 0) |
7239 | { | |
7240 | warn (_("Invalid max register\n")); | |
7241 | break; | |
7242 | } | |
49727e46 AM |
7243 | if (cie->fde_encoding) |
7244 | encoded_ptr_size | |
7245 | = size_of_encoded_value (cie->fde_encoding); | |
7246 | } | |
7247 | } | |
7248 | } | |
7249 | } | |
7250 | ||
7251 | fc = &fde_fc; | |
7252 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
7253 | |
7254 | if (!cie) | |
7255 | { | |
bf5117e3 NC |
7256 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
7257 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
7258 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 7259 | fc->ncols = 0; |
3f5e193b NC |
7260 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
7261 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
7262 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
7263 | { | |
7264 | warn (_("Invalid max register\n")); | |
7265 | break; | |
7266 | } | |
19e6b90e L |
7267 | cie = fc; |
7268 | fc->augmentation = ""; | |
7269 | fc->fde_encoding = 0; | |
604282a7 JJ |
7270 | fc->ptr_size = eh_addr_size; |
7271 | fc->segment_size = 0; | |
19e6b90e L |
7272 | } |
7273 | else | |
7274 | { | |
7275 | fc->ncols = cie->ncols; | |
3f5e193b NC |
7276 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
7277 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
7278 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
7279 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
7280 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
7281 | fc->ptr_size = cie->ptr_size; |
7282 | eh_addr_size = cie->ptr_size; | |
7283 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
7284 | fc->code_factor = cie->code_factor; |
7285 | fc->data_factor = cie->data_factor; | |
7286 | fc->cfa_reg = cie->cfa_reg; | |
7287 | fc->cfa_offset = cie->cfa_offset; | |
7288 | fc->ra = cie->ra; | |
06614111 NC |
7289 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
7290 | { | |
7291 | warn (_("Invalid max register\n")); | |
7292 | break; | |
7293 | } | |
19e6b90e L |
7294 | fc->fde_encoding = cie->fde_encoding; |
7295 | } | |
7296 | ||
7297 | if (fc->fde_encoding) | |
7298 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
7299 | ||
604282a7 JJ |
7300 | segment_selector = 0; |
7301 | if (fc->segment_size) | |
c8071705 NC |
7302 | { |
7303 | if (fc->segment_size > sizeof (segment_selector)) | |
7304 | { | |
7305 | /* PR 17512: file: 9e196b3e. */ | |
7306 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
7307 | fc->segment_size = 4; | |
7308 | } | |
7309 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
7310 | } | |
041830e0 NC |
7311 | |
7312 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 7313 | |
0c588247 NC |
7314 | /* FIXME: It appears that sometimes the final pc_range value is |
7315 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
7316 | run of the "objcopy on compressed debug sections" test for an | |
7317 | example of this. */ | |
7318 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 7319 | |
19e6b90e L |
7320 | if (cie->augmentation[0] == 'z') |
7321 | { | |
7f2c8a1d | 7322 | READ_ULEB (augmentation_data_len); |
19e6b90e L |
7323 | augmentation_data = start; |
7324 | start += augmentation_data_len; | |
0a9d414a | 7325 | /* PR 17512: file: 722-8446-0.004. */ |
53774b7e | 7326 | if (start >= end || ((signed long) augmentation_data_len) < 0) |
0a9d414a NC |
7327 | { |
7328 | warn (_("Corrupt augmentation data length: %lx\n"), | |
7329 | augmentation_data_len); | |
7330 | start = end; | |
7331 | augmentation_data = NULL; | |
7332 | augmentation_data_len = 0; | |
7333 | } | |
19e6b90e L |
7334 | } |
7335 | ||
bf5117e3 NC |
7336 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
7337 | (unsigned long)(saved_start - section_start), | |
7338 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 7339 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 7340 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 7341 | |
604282a7 JJ |
7342 | if (fc->segment_size) |
7343 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
7344 | |
7345 | printf ("%s..%s\n", | |
7346 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
7347 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
7348 | ||
19e6b90e L |
7349 | if (! do_debug_frames_interp && augmentation_data_len) |
7350 | { | |
7351 | unsigned long i; | |
7352 | ||
7353 | printf (" Augmentation data: "); | |
7354 | for (i = 0; i < augmentation_data_len; ++i) | |
7355 | printf (" %02x", augmentation_data[i]); | |
7356 | putchar ('\n'); | |
7357 | putchar ('\n'); | |
7358 | } | |
7359 | } | |
7360 | ||
7361 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
7362 | we're about to interpret instructions for the chunk. */ | |
7363 | /* ??? At present we need to do this always, since this sizes the | |
7364 | fc->col_type and fc->col_offset arrays, which we write into always. | |
7365 | We should probably split the interpreted and non-interpreted bits | |
7366 | into two different routines, since there's so much that doesn't | |
7367 | really overlap between them. */ | |
7368 | if (1 || do_debug_frames_interp) | |
7369 | { | |
7370 | /* Start by making a pass over the chunk, allocating storage | |
7371 | and taking note of what registers are used. */ | |
7372 | unsigned char *tmp = start; | |
7373 | ||
7374 | while (start < block_end) | |
7375 | { | |
041830e0 NC |
7376 | unsigned int reg, op, opa; |
7377 | unsigned long temp; | |
5929c344 | 7378 | unsigned char * new_start; |
19e6b90e L |
7379 | |
7380 | op = *start++; | |
7381 | opa = op & 0x3f; | |
7382 | if (op & 0xc0) | |
7383 | op &= 0xc0; | |
7384 | ||
7385 | /* Warning: if you add any more cases to this switch, be | |
7386 | sure to add them to the corresponding switch below. */ | |
7387 | switch (op) | |
7388 | { | |
7389 | case DW_CFA_advance_loc: | |
7390 | break; | |
7391 | case DW_CFA_offset: | |
7f2c8a1d | 7392 | SKIP_ULEB (); |
665ce1f6 L |
7393 | if (frame_need_space (fc, opa) >= 0) |
7394 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
7395 | break; |
7396 | case DW_CFA_restore: | |
665ce1f6 L |
7397 | if (frame_need_space (fc, opa) >= 0) |
7398 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
7399 | break; |
7400 | case DW_CFA_set_loc: | |
7401 | start += encoded_ptr_size; | |
7402 | break; | |
7403 | case DW_CFA_advance_loc1: | |
7404 | start += 1; | |
7405 | break; | |
7406 | case DW_CFA_advance_loc2: | |
7407 | start += 2; | |
7408 | break; | |
7409 | case DW_CFA_advance_loc4: | |
7410 | start += 4; | |
7411 | break; | |
7412 | case DW_CFA_offset_extended: | |
12eae2d3 | 7413 | case DW_CFA_val_offset: |
7f2c8a1d NC |
7414 | READ_ULEB (reg); |
7415 | SKIP_ULEB (); | |
665ce1f6 L |
7416 | if (frame_need_space (fc, reg) >= 0) |
7417 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7418 | break; |
7419 | case DW_CFA_restore_extended: | |
7f2c8a1d | 7420 | READ_ULEB (reg); |
665ce1f6 L |
7421 | if (frame_need_space (fc, reg) >= 0) |
7422 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7423 | break; |
7424 | case DW_CFA_undefined: | |
7f2c8a1d | 7425 | READ_ULEB (reg); |
665ce1f6 L |
7426 | if (frame_need_space (fc, reg) >= 0) |
7427 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7428 | break; |
7429 | case DW_CFA_same_value: | |
7f2c8a1d | 7430 | READ_ULEB (reg); |
665ce1f6 L |
7431 | if (frame_need_space (fc, reg) >= 0) |
7432 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7433 | break; |
7434 | case DW_CFA_register: | |
7f2c8a1d NC |
7435 | READ_ULEB (reg); |
7436 | SKIP_ULEB (); | |
665ce1f6 L |
7437 | if (frame_need_space (fc, reg) >= 0) |
7438 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7439 | break; |
7440 | case DW_CFA_def_cfa: | |
7f2c8a1d NC |
7441 | SKIP_ULEB (); |
7442 | SKIP_ULEB (); | |
19e6b90e L |
7443 | break; |
7444 | case DW_CFA_def_cfa_register: | |
7f2c8a1d | 7445 | SKIP_ULEB (); |
19e6b90e L |
7446 | break; |
7447 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 7448 | SKIP_ULEB (); |
19e6b90e L |
7449 | break; |
7450 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 7451 | READ_ULEB (temp); |
5929c344 NC |
7452 | new_start = start + temp; |
7453 | if (new_start < start) | |
041830e0 NC |
7454 | { |
7455 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
7456 | start = block_end; | |
7457 | } | |
7458 | else | |
5929c344 | 7459 | start = new_start; |
19e6b90e L |
7460 | break; |
7461 | case DW_CFA_expression: | |
12eae2d3 | 7462 | case DW_CFA_val_expression: |
7f2c8a1d NC |
7463 | READ_ULEB (reg); |
7464 | READ_ULEB (temp); | |
5929c344 NC |
7465 | new_start = start + temp; |
7466 | if (new_start < start) | |
041830e0 | 7467 | { |
b4eb7656 | 7468 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
7469 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
7470 | start = block_end; | |
7471 | } | |
7472 | else | |
5929c344 | 7473 | start = new_start; |
665ce1f6 L |
7474 | if (frame_need_space (fc, reg) >= 0) |
7475 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7476 | break; |
7477 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 7478 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
7479 | READ_ULEB (reg); |
7480 | SKIP_SLEB (); | |
665ce1f6 L |
7481 | if (frame_need_space (fc, reg) >= 0) |
7482 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7483 | break; |
7484 | case DW_CFA_def_cfa_sf: | |
7f2c8a1d NC |
7485 | SKIP_ULEB (); |
7486 | SKIP_SLEB (); | |
19e6b90e L |
7487 | break; |
7488 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 7489 | SKIP_SLEB (); |
19e6b90e L |
7490 | break; |
7491 | case DW_CFA_MIPS_advance_loc8: | |
7492 | start += 8; | |
7493 | break; | |
7494 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 7495 | SKIP_ULEB (); |
19e6b90e L |
7496 | break; |
7497 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
7498 | READ_ULEB (reg); |
7499 | SKIP_ULEB (); | |
665ce1f6 L |
7500 | if (frame_need_space (fc, reg) >= 0) |
7501 | fc->col_type[reg] = DW_CFA_undefined; | |
7502 | break; | |
19e6b90e L |
7503 | default: |
7504 | break; | |
7505 | } | |
7506 | } | |
7507 | start = tmp; | |
7508 | } | |
7509 | ||
5b6312fd NC |
7510 | all_nops = TRUE; |
7511 | ||
19e6b90e L |
7512 | /* Now we know what registers are used, make a second pass over |
7513 | the chunk, this time actually printing out the info. */ | |
7514 | ||
7515 | while (start < block_end) | |
7516 | { | |
362beea4 | 7517 | unsigned char * tmp; |
19e6b90e | 7518 | unsigned op, opa; |
7f2c8a1d NC |
7519 | unsigned long ul, roffs; |
7520 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
7521 | are various functions, notably frame_space_needed() that assume that | |
7522 | reg is an unsigned int. */ | |
7523 | unsigned int reg; | |
7524 | dwarf_signed_vma l; | |
bf5117e3 | 7525 | dwarf_vma ofs; |
19e6b90e | 7526 | dwarf_vma vma; |
665ce1f6 | 7527 | const char *reg_prefix = ""; |
19e6b90e L |
7528 | |
7529 | op = *start++; | |
7530 | opa = op & 0x3f; | |
7531 | if (op & 0xc0) | |
7532 | op &= 0xc0; | |
7533 | ||
5b6312fd NC |
7534 | /* Make a note if something other than DW_CFA_nop happens. */ |
7535 | if (op != DW_CFA_nop) | |
7536 | all_nops = FALSE; | |
7537 | ||
19e6b90e L |
7538 | /* Warning: if you add any more cases to this switch, be |
7539 | sure to add them to the corresponding switch above. */ | |
7540 | switch (op) | |
7541 | { | |
7542 | case DW_CFA_advance_loc: | |
7543 | if (do_debug_frames_interp) | |
7544 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7545 | else | |
bf5117e3 | 7546 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 7547 | opa * fc->code_factor, |
b4eb7656 | 7548 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
7549 | fc->pc_begin + opa * fc->code_factor, |
7550 | fc->ptr_size)); | |
19e6b90e L |
7551 | fc->pc_begin += opa * fc->code_factor; |
7552 | break; | |
7553 | ||
7554 | case DW_CFA_offset: | |
7f2c8a1d | 7555 | READ_ULEB (roffs); |
665ce1f6 L |
7556 | if (opa >= (unsigned int) fc->ncols) |
7557 | reg_prefix = bad_reg; | |
7558 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7559 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
7560 | reg_prefix, regname (opa, 0), | |
7561 | roffs * fc->data_factor); | |
7562 | if (*reg_prefix == '\0') | |
7563 | { | |
7564 | fc->col_type[opa] = DW_CFA_offset; | |
7565 | fc->col_offset[opa] = roffs * fc->data_factor; | |
7566 | } | |
19e6b90e L |
7567 | break; |
7568 | ||
7569 | case DW_CFA_restore: | |
50751e18 | 7570 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
7571 | reg_prefix = bad_reg; |
7572 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7573 | printf (" DW_CFA_restore: %s%s\n", | |
7574 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
7575 | if (*reg_prefix != '\0') |
7576 | break; | |
7577 | ||
7578 | if (opa >= (unsigned int) cie->ncols | |
7579 | || (do_debug_frames_interp | |
7580 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
7581 | { | |
7582 | fc->col_type[opa] = DW_CFA_undefined; | |
7583 | fc->col_offset[opa] = 0; | |
7584 | } | |
7585 | else | |
665ce1f6 L |
7586 | { |
7587 | fc->col_type[opa] = cie->col_type[opa]; | |
7588 | fc->col_offset[opa] = cie->col_offset[opa]; | |
7589 | } | |
19e6b90e L |
7590 | break; |
7591 | ||
7592 | case DW_CFA_set_loc: | |
6937bb54 | 7593 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
7594 | if (do_debug_frames_interp) |
7595 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7596 | else | |
bf5117e3 NC |
7597 | printf (" DW_CFA_set_loc: %s\n", |
7598 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
7599 | fc->pc_begin = vma; |
7600 | break; | |
7601 | ||
7602 | case DW_CFA_advance_loc1: | |
0c588247 | 7603 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
7604 | if (do_debug_frames_interp) |
7605 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7606 | else | |
bf5117e3 NC |
7607 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
7608 | (unsigned long) (ofs * fc->code_factor), | |
7609 | dwarf_vmatoa_1 (NULL, | |
7610 | fc->pc_begin + ofs * fc->code_factor, | |
7611 | fc->ptr_size)); | |
19e6b90e L |
7612 | fc->pc_begin += ofs * fc->code_factor; |
7613 | break; | |
7614 | ||
7615 | case DW_CFA_advance_loc2: | |
6937bb54 | 7616 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
7617 | if (do_debug_frames_interp) |
7618 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7619 | else | |
bf5117e3 NC |
7620 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
7621 | (unsigned long) (ofs * fc->code_factor), | |
7622 | dwarf_vmatoa_1 (NULL, | |
7623 | fc->pc_begin + ofs * fc->code_factor, | |
7624 | fc->ptr_size)); | |
19e6b90e L |
7625 | fc->pc_begin += ofs * fc->code_factor; |
7626 | break; | |
7627 | ||
7628 | case DW_CFA_advance_loc4: | |
6937bb54 | 7629 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
7630 | if (do_debug_frames_interp) |
7631 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7632 | else | |
bf5117e3 NC |
7633 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
7634 | (unsigned long) (ofs * fc->code_factor), | |
7635 | dwarf_vmatoa_1 (NULL, | |
7636 | fc->pc_begin + ofs * fc->code_factor, | |
7637 | fc->ptr_size)); | |
19e6b90e L |
7638 | fc->pc_begin += ofs * fc->code_factor; |
7639 | break; | |
7640 | ||
7641 | case DW_CFA_offset_extended: | |
7f2c8a1d NC |
7642 | READ_ULEB (reg); |
7643 | READ_ULEB (roffs); | |
665ce1f6 L |
7644 | if (reg >= (unsigned int) fc->ncols) |
7645 | reg_prefix = bad_reg; | |
7646 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7647 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
7648 | reg_prefix, regname (reg, 0), | |
7649 | roffs * fc->data_factor); | |
7650 | if (*reg_prefix == '\0') | |
7651 | { | |
7652 | fc->col_type[reg] = DW_CFA_offset; | |
7653 | fc->col_offset[reg] = roffs * fc->data_factor; | |
7654 | } | |
19e6b90e L |
7655 | break; |
7656 | ||
12eae2d3 | 7657 | case DW_CFA_val_offset: |
7f2c8a1d NC |
7658 | READ_ULEB (reg); |
7659 | READ_ULEB (roffs); | |
665ce1f6 L |
7660 | if (reg >= (unsigned int) fc->ncols) |
7661 | reg_prefix = bad_reg; | |
7662 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 7663 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
7664 | reg_prefix, regname (reg, 0), |
7665 | roffs * fc->data_factor); | |
7666 | if (*reg_prefix == '\0') | |
7667 | { | |
7668 | fc->col_type[reg] = DW_CFA_val_offset; | |
7669 | fc->col_offset[reg] = roffs * fc->data_factor; | |
7670 | } | |
12eae2d3 JJ |
7671 | break; |
7672 | ||
19e6b90e | 7673 | case DW_CFA_restore_extended: |
7f2c8a1d | 7674 | READ_ULEB (reg); |
50751e18 | 7675 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
7676 | reg_prefix = bad_reg; |
7677 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7678 | printf (" DW_CFA_restore_extended: %s%s\n", | |
7679 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
7680 | if (*reg_prefix != '\0') |
7681 | break; | |
7682 | ||
7683 | if (reg >= (unsigned int) cie->ncols) | |
7684 | { | |
7685 | fc->col_type[reg] = DW_CFA_undefined; | |
7686 | fc->col_offset[reg] = 0; | |
7687 | } | |
7688 | else | |
665ce1f6 L |
7689 | { |
7690 | fc->col_type[reg] = cie->col_type[reg]; | |
7691 | fc->col_offset[reg] = cie->col_offset[reg]; | |
7692 | } | |
19e6b90e L |
7693 | break; |
7694 | ||
7695 | case DW_CFA_undefined: | |
7f2c8a1d | 7696 | READ_ULEB (reg); |
665ce1f6 L |
7697 | if (reg >= (unsigned int) fc->ncols) |
7698 | reg_prefix = bad_reg; | |
7699 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7700 | printf (" DW_CFA_undefined: %s%s\n", | |
7701 | reg_prefix, regname (reg, 0)); | |
7702 | if (*reg_prefix == '\0') | |
7703 | { | |
7704 | fc->col_type[reg] = DW_CFA_undefined; | |
7705 | fc->col_offset[reg] = 0; | |
7706 | } | |
19e6b90e L |
7707 | break; |
7708 | ||
7709 | case DW_CFA_same_value: | |
7f2c8a1d | 7710 | READ_ULEB (reg); |
665ce1f6 L |
7711 | if (reg >= (unsigned int) fc->ncols) |
7712 | reg_prefix = bad_reg; | |
7713 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7714 | printf (" DW_CFA_same_value: %s%s\n", | |
7715 | reg_prefix, regname (reg, 0)); | |
7716 | if (*reg_prefix == '\0') | |
7717 | { | |
7718 | fc->col_type[reg] = DW_CFA_same_value; | |
7719 | fc->col_offset[reg] = 0; | |
7720 | } | |
19e6b90e L |
7721 | break; |
7722 | ||
7723 | case DW_CFA_register: | |
7f2c8a1d NC |
7724 | READ_ULEB (reg); |
7725 | READ_ULEB (roffs); | |
665ce1f6 L |
7726 | if (reg >= (unsigned int) fc->ncols) |
7727 | reg_prefix = bad_reg; | |
7728 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 7729 | { |
665ce1f6 L |
7730 | printf (" DW_CFA_register: %s%s in ", |
7731 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
7732 | puts (regname (roffs, 0)); |
7733 | } | |
665ce1f6 L |
7734 | if (*reg_prefix == '\0') |
7735 | { | |
7736 | fc->col_type[reg] = DW_CFA_register; | |
7737 | fc->col_offset[reg] = roffs; | |
7738 | } | |
19e6b90e L |
7739 | break; |
7740 | ||
7741 | case DW_CFA_remember_state: | |
7742 | if (! do_debug_frames_interp) | |
7743 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 7744 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 7745 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
7746 | rs->cfa_reg = fc->cfa_reg; |
7747 | rs->ra = fc->ra; | |
7748 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 7749 | rs->ncols = fc->ncols; |
3f5e193b | 7750 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 7751 | sizeof (* rs->col_type)); |
d71ad7fc RC |
7752 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
7753 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
7754 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
7755 | rs->next = remembered_state; |
7756 | remembered_state = rs; | |
7757 | break; | |
7758 | ||
7759 | case DW_CFA_restore_state: | |
7760 | if (! do_debug_frames_interp) | |
7761 | printf (" DW_CFA_restore_state\n"); | |
7762 | rs = remembered_state; | |
7763 | if (rs) | |
7764 | { | |
7765 | remembered_state = rs->next; | |
d71ad7fc RC |
7766 | fc->cfa_offset = rs->cfa_offset; |
7767 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
7768 | fc->ra = rs->ra; |
7769 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
7770 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
7771 | { | |
1306a742 | 7772 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
7773 | fc->ncols = 0; |
7774 | break; | |
7775 | } | |
d71ad7fc | 7776 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 7777 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 7778 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
7779 | free (rs->col_type); |
7780 | free (rs->col_offset); | |
7781 | free (rs); | |
7782 | } | |
7783 | else if (do_debug_frames_interp) | |
7784 | printf ("Mismatched DW_CFA_restore_state\n"); | |
7785 | break; | |
7786 | ||
7787 | case DW_CFA_def_cfa: | |
7f2c8a1d NC |
7788 | READ_SLEB (fc->cfa_reg); |
7789 | READ_ULEB (fc->cfa_offset); | |
19e6b90e L |
7790 | fc->cfa_exp = 0; |
7791 | if (! do_debug_frames_interp) | |
2dc4cec1 | 7792 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 7793 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
7794 | break; |
7795 | ||
7796 | case DW_CFA_def_cfa_register: | |
7f2c8a1d | 7797 | READ_SLEB (fc->cfa_reg); |
19e6b90e L |
7798 | fc->cfa_exp = 0; |
7799 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
7800 | printf (" DW_CFA_def_cfa_register: %s\n", |
7801 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
7802 | break; |
7803 | ||
7804 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 7805 | READ_ULEB (fc->cfa_offset); |
19e6b90e | 7806 | if (! do_debug_frames_interp) |
c8071705 | 7807 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
7808 | break; |
7809 | ||
7810 | case DW_CFA_nop: | |
7811 | if (! do_debug_frames_interp) | |
7812 | printf (" DW_CFA_nop\n"); | |
7813 | break; | |
7814 | ||
7815 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 7816 | READ_ULEB (ul); |
7460c0ab | 7817 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 7818 | { |
a1165289 | 7819 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
7820 | break; |
7821 | } | |
19e6b90e L |
7822 | if (! do_debug_frames_interp) |
7823 | { | |
7824 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
7825 | decode_location_expression (start, eh_addr_size, 0, -1, |
7826 | ul, 0, section); | |
19e6b90e L |
7827 | printf (")\n"); |
7828 | } | |
7829 | fc->cfa_exp = 1; | |
7830 | start += ul; | |
7831 | break; | |
7832 | ||
7833 | case DW_CFA_expression: | |
7f2c8a1d NC |
7834 | READ_ULEB (reg); |
7835 | READ_ULEB (ul); | |
665ce1f6 L |
7836 | if (reg >= (unsigned int) fc->ncols) |
7837 | reg_prefix = bad_reg; | |
6937bb54 | 7838 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 7839 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
7840 | tmp = start + ul; |
7841 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 7842 | { |
a1165289 | 7843 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
7844 | break; |
7845 | } | |
665ce1f6 | 7846 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 7847 | { |
665ce1f6 L |
7848 | printf (" DW_CFA_expression: %s%s (", |
7849 | reg_prefix, regname (reg, 0)); | |
b7807392 | 7850 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 7851 | ul, 0, section); |
19e6b90e L |
7852 | printf (")\n"); |
7853 | } | |
665ce1f6 L |
7854 | if (*reg_prefix == '\0') |
7855 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 7856 | start = tmp; |
19e6b90e L |
7857 | break; |
7858 | ||
12eae2d3 | 7859 | case DW_CFA_val_expression: |
7f2c8a1d NC |
7860 | READ_ULEB (reg); |
7861 | READ_ULEB (ul); | |
665ce1f6 L |
7862 | if (reg >= (unsigned int) fc->ncols) |
7863 | reg_prefix = bad_reg; | |
362beea4 NC |
7864 | tmp = start + ul; |
7865 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 7866 | { |
a1165289 | 7867 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
7868 | break; |
7869 | } | |
665ce1f6 | 7870 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 7871 | { |
665ce1f6 L |
7872 | printf (" DW_CFA_val_expression: %s%s (", |
7873 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
7874 | decode_location_expression (start, eh_addr_size, 0, -1, |
7875 | ul, 0, section); | |
12eae2d3 JJ |
7876 | printf (")\n"); |
7877 | } | |
665ce1f6 L |
7878 | if (*reg_prefix == '\0') |
7879 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 7880 | start = tmp; |
12eae2d3 JJ |
7881 | break; |
7882 | ||
19e6b90e | 7883 | case DW_CFA_offset_extended_sf: |
7f2c8a1d NC |
7884 | READ_ULEB (reg); |
7885 | READ_SLEB (l); | |
665ce1f6 L |
7886 | if (frame_need_space (fc, reg) < 0) |
7887 | reg_prefix = bad_reg; | |
7888 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7889 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
7890 | reg_prefix, regname (reg, 0), | |
c8071705 | 7891 | (long)(l * fc->data_factor)); |
665ce1f6 L |
7892 | if (*reg_prefix == '\0') |
7893 | { | |
7894 | fc->col_type[reg] = DW_CFA_offset; | |
7895 | fc->col_offset[reg] = l * fc->data_factor; | |
7896 | } | |
19e6b90e L |
7897 | break; |
7898 | ||
12eae2d3 | 7899 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
7900 | READ_ULEB (reg); |
7901 | READ_SLEB (l); | |
665ce1f6 L |
7902 | if (frame_need_space (fc, reg) < 0) |
7903 | reg_prefix = bad_reg; | |
7904 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 7905 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 7906 | reg_prefix, regname (reg, 0), |
c8071705 | 7907 | (long)(l * fc->data_factor)); |
665ce1f6 L |
7908 | if (*reg_prefix == '\0') |
7909 | { | |
7910 | fc->col_type[reg] = DW_CFA_val_offset; | |
7911 | fc->col_offset[reg] = l * fc->data_factor; | |
7912 | } | |
12eae2d3 JJ |
7913 | break; |
7914 | ||
19e6b90e | 7915 | case DW_CFA_def_cfa_sf: |
7f2c8a1d NC |
7916 | READ_SLEB (fc->cfa_reg); |
7917 | READ_ULEB (fc->cfa_offset); | |
19e6b90e L |
7918 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
7919 | fc->cfa_exp = 0; | |
7920 | if (! do_debug_frames_interp) | |
2dc4cec1 | 7921 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 7922 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
7923 | break; |
7924 | ||
7925 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 7926 | READ_ULEB (fc->cfa_offset); |
c8071705 | 7927 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 7928 | if (! do_debug_frames_interp) |
c8071705 | 7929 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
7930 | break; |
7931 | ||
7932 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 7933 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
7934 | if (do_debug_frames_interp) |
7935 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7936 | else | |
bf5117e3 NC |
7937 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
7938 | (unsigned long) (ofs * fc->code_factor), | |
7939 | dwarf_vmatoa_1 (NULL, | |
7940 | fc->pc_begin + ofs * fc->code_factor, | |
7941 | fc->ptr_size)); | |
19e6b90e L |
7942 | fc->pc_begin += ofs * fc->code_factor; |
7943 | break; | |
7944 | ||
7945 | case DW_CFA_GNU_window_save: | |
7946 | if (! do_debug_frames_interp) | |
7947 | printf (" DW_CFA_GNU_window_save\n"); | |
7948 | break; | |
7949 | ||
7950 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 7951 | READ_ULEB (ul); |
19e6b90e L |
7952 | if (! do_debug_frames_interp) |
7953 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
7954 | break; | |
7955 | ||
7956 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
7957 | READ_ULEB (reg); |
7958 | READ_SLEB (l); | |
7959 | l = - l; | |
665ce1f6 L |
7960 | if (frame_need_space (fc, reg) < 0) |
7961 | reg_prefix = bad_reg; | |
7962 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7963 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
7964 | reg_prefix, regname (reg, 0), | |
c8071705 | 7965 | (long)(l * fc->data_factor)); |
665ce1f6 L |
7966 | if (*reg_prefix == '\0') |
7967 | { | |
7968 | fc->col_type[reg] = DW_CFA_offset; | |
7969 | fc->col_offset[reg] = l * fc->data_factor; | |
7970 | } | |
19e6b90e L |
7971 | break; |
7972 | ||
7973 | default: | |
53b8873b NC |
7974 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
7975 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
7976 | else | |
f41e4712 | 7977 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
7978 | start = block_end; |
7979 | } | |
7980 | } | |
7981 | ||
5b6312fd NC |
7982 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
7983 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
7984 | frame_display_row (fc, &need_col_headers, &max_regs); |
7985 | ||
7986 | start = block_end; | |
604282a7 | 7987 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
7988 | } |
7989 | ||
7990 | printf ("\n"); | |
7991 | ||
7992 | return 1; | |
7993 | } | |
7994 | ||
7995 | #undef GET | |
19e6b90e | 7996 | |
61364358 JK |
7997 | static int |
7998 | display_debug_names (struct dwarf_section *section, void *file) | |
7999 | { | |
8000 | unsigned char *hdrptr = section->start; | |
8001 | dwarf_vma unit_length; | |
8002 | unsigned char *unit_start; | |
8003 | const unsigned char *const section_end = section->start + section->size; | |
8004 | unsigned char *unit_end; | |
8005 | ||
8006 | printf (_("Contents of the %s section:\n"), section->name); | |
8007 | ||
8008 | load_debug_section (str, file); | |
8009 | ||
8010 | for (; hdrptr < section_end; hdrptr = unit_end) | |
8011 | { | |
8012 | unsigned int offset_size; | |
8013 | uint16_t dwarf_version, padding; | |
8014 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
8015 | uint32_t bucket_count, name_count, abbrev_table_size; | |
8016 | uint32_t augmentation_string_size; | |
8017 | unsigned int i; | |
8018 | ||
8019 | unit_start = hdrptr; | |
8020 | ||
8021 | /* Get and check the length of the block. */ | |
8022 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
8023 | ||
8024 | if (unit_length == 0xffffffff) | |
8025 | { | |
8026 | /* This section is 64-bit DWARF. */ | |
8027 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
8028 | offset_size = 8; | |
8029 | } | |
8030 | else | |
8031 | offset_size = 4; | |
8032 | unit_end = hdrptr + unit_length; | |
8033 | ||
8034 | if ((hdrptr - section->start) + unit_length > section->size) | |
8035 | { | |
8036 | warn (_("The length field (0x%lx) for unit 0x%lx in the debug_names " | |
8037 | "header is wrong - the section is too small\n"), | |
8038 | (long) unit_length, (long) (unit_start - section->start)); | |
8039 | return 0; | |
8040 | } | |
8041 | ||
8042 | /* Get and check the version number. */ | |
8043 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
8044 | printf (_("Version %ld\n"), (long) dwarf_version); | |
8045 | ||
8046 | /* Prior versions did not exist, and future versions may not be | |
8047 | backwards compatible. */ | |
8048 | if (dwarf_version != 5) | |
8049 | { | |
8050 | warn (_("Only DWARF version 5 .debug_names " | |
8051 | "is currently supported.\n")); | |
8052 | return 0; | |
8053 | } | |
8054 | ||
8055 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
8056 | if (padding != 0) | |
8057 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
8058 | padding); | |
8059 | ||
8060 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
8061 | if (comp_unit_count == 0) | |
8062 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
8063 | ||
8064 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
8065 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
8066 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
8067 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
8068 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
8069 | ||
8070 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
8071 | if (augmentation_string_size % 4 != 0) | |
8072 | { | |
8073 | warn (_("Augmentation string length %u must be rounded up " | |
8074 | "to a multiple of 4 in .debug_names.\n"), | |
8075 | augmentation_string_size); | |
8076 | augmentation_string_size += (-augmentation_string_size) & 3; | |
8077 | } | |
8078 | printf (_("Augmentation string:")); | |
8079 | for (i = 0; i < augmentation_string_size; i++) | |
8080 | { | |
8081 | unsigned char uc; | |
8082 | ||
8083 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
8084 | printf (" %02x", uc); | |
8085 | } | |
8086 | putchar ('\n'); | |
8087 | putchar ('\n'); | |
8088 | ||
8089 | printf (_("CU table:\n")); | |
8090 | for (i = 0; i < comp_unit_count; i++) | |
8091 | { | |
8092 | uint64_t cu_offset; | |
8093 | ||
8094 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
8095 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
8096 | } | |
8097 | putchar ('\n'); | |
8098 | ||
8099 | printf (_("TU table:\n")); | |
8100 | for (i = 0; i < local_type_unit_count; i++) | |
8101 | { | |
8102 | uint64_t tu_offset; | |
8103 | ||
8104 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
8105 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
8106 | } | |
8107 | putchar ('\n'); | |
8108 | ||
8109 | printf (_("Foreign TU table:\n")); | |
8110 | for (i = 0; i < foreign_type_unit_count; i++) | |
8111 | { | |
8112 | uint64_t signature; | |
8113 | ||
8114 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
8115 | printf (_("[%3u] "), i); | |
8116 | print_dwarf_vma (signature, 8); | |
8117 | putchar ('\n'); | |
8118 | } | |
8119 | putchar ('\n'); | |
8120 | ||
8121 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
8122 | hdrptr += bucket_count * sizeof (uint32_t); | |
8123 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
8124 | hdrptr += name_count * sizeof (uint32_t); | |
8125 | unsigned char *const name_table_string_offsets = hdrptr; | |
8126 | hdrptr += name_count * offset_size; | |
8127 | unsigned char *const name_table_entry_offsets = hdrptr; | |
8128 | hdrptr += name_count * offset_size; | |
8129 | unsigned char *const abbrev_table = hdrptr; | |
8130 | hdrptr += abbrev_table_size; | |
8131 | const unsigned char *const abbrev_table_end = hdrptr; | |
8132 | unsigned char *const entry_pool = hdrptr; | |
8133 | if (hdrptr > unit_end) | |
8134 | { | |
8135 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
8136 | "for unit 0x%lx in the debug_names\n"), | |
8137 | (long) (hdrptr - section->start), | |
8138 | (long) (unit_end - section->start), | |
8139 | (long) (unit_start - section->start)); | |
8140 | return 0; | |
8141 | } | |
8142 | ||
8143 | size_t buckets_filled = 0; | |
8144 | size_t bucketi; | |
8145 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
8146 | { | |
8147 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
8148 | ||
8149 | if (bucket != 0) | |
8150 | ++buckets_filled; | |
8151 | } | |
8152 | printf (_("Used %zu of %lu buckets.\n"), buckets_filled, | |
8153 | (unsigned long) bucket_count); | |
8154 | ||
0a79bef4 | 8155 | uint32_t hash_prev = 0; |
61364358 JK |
8156 | size_t hash_clash_count = 0; |
8157 | size_t longest_clash = 0; | |
8158 | size_t this_length = 0; | |
8159 | size_t hashi; | |
8160 | for (hashi = 0; hashi < name_count; hashi++) | |
8161 | { | |
8162 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
8163 | ||
8164 | if (hashi > 0) | |
8165 | { | |
8166 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
8167 | { | |
8168 | ++hash_clash_count; | |
8169 | ++this_length; | |
8170 | longest_clash = MAX (longest_clash, this_length); | |
8171 | } | |
8172 | else | |
8173 | this_length = 0; | |
8174 | } | |
8175 | hash_prev = hash_this; | |
8176 | } | |
8177 | printf (_("Out of %lu items there are %zu bucket clashes" | |
8178 | " (longest of %zu entries).\n"), | |
8179 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
8180 | assert (name_count == buckets_filled + hash_clash_count); | |
8181 | ||
8182 | struct abbrev_lookup_entry | |
8183 | { | |
8184 | dwarf_vma abbrev_tag; | |
8185 | unsigned char *abbrev_lookup_ptr; | |
8186 | }; | |
8187 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
8188 | size_t abbrev_lookup_used = 0; | |
8189 | size_t abbrev_lookup_allocated = 0; | |
8190 | ||
8191 | unsigned char *abbrevptr = abbrev_table; | |
8192 | for (;;) | |
8193 | { | |
8194 | unsigned int bytes_read; | |
8195 | const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read, | |
8196 | abbrev_table_end); | |
8197 | abbrevptr += bytes_read; | |
8198 | if (abbrev_tag == 0) | |
8199 | break; | |
8200 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
8201 | { | |
8202 | abbrev_lookup_allocated = MAX (0x100, | |
8203 | abbrev_lookup_allocated * 2); | |
8204 | abbrev_lookup = xrealloc (abbrev_lookup, | |
8205 | (abbrev_lookup_allocated | |
8206 | * sizeof (*abbrev_lookup))); | |
8207 | } | |
8208 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
8209 | struct abbrev_lookup_entry *entry; | |
8210 | for (entry = abbrev_lookup; | |
8211 | entry < abbrev_lookup + abbrev_lookup_used; | |
8212 | entry++) | |
8213 | if (entry->abbrev_tag == abbrev_tag) | |
8214 | { | |
8215 | warn (_("Duplicate abbreviation tag %lu " | |
8216 | "in unit 0x%lx in the debug_names\n"), | |
8217 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
8218 | break; | |
8219 | } | |
8220 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
8221 | entry->abbrev_tag = abbrev_tag; | |
8222 | entry->abbrev_lookup_ptr = abbrevptr; | |
8223 | ||
8224 | /* Skip DWARF tag. */ | |
8225 | read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end); | |
8226 | abbrevptr += bytes_read; | |
8227 | for (;;) | |
8228 | { | |
1d827a72 L |
8229 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
8230 | &bytes_read, | |
8231 | abbrev_table_end); | |
61364358 JK |
8232 | abbrevptr += bytes_read; |
8233 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
8234 | abbrev_table_end); | |
8235 | abbrevptr += bytes_read; | |
1d827a72 | 8236 | if (xindex == 0 && form == 0) |
61364358 JK |
8237 | break; |
8238 | } | |
8239 | } | |
8240 | ||
8241 | printf (_("\nSymbol table:\n")); | |
8242 | uint32_t namei; | |
8243 | for (namei = 0; namei < name_count; ++namei) | |
8244 | { | |
8245 | uint64_t string_offset, entry_offset; | |
8246 | ||
8247 | SAFE_BYTE_GET (string_offset, | |
8248 | name_table_string_offsets + namei * offset_size, | |
8249 | offset_size, unit_end); | |
8250 | SAFE_BYTE_GET (entry_offset, | |
8251 | name_table_entry_offsets + namei * offset_size, | |
8252 | offset_size, unit_end); | |
8253 | ||
8254 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
8255 | fetch_indirect_string (string_offset)); | |
8256 | ||
8257 | unsigned char *entryptr = entry_pool + entry_offset; | |
8258 | ||
8259 | // We need to scan first whether there is a single or multiple | |
8260 | // entries. TAGNO is -2 for the first entry, it is -1 for the | |
8261 | // initial tag read of the second entry, then it becomes 0 for the | |
8262 | // first entry for real printing etc. | |
8263 | int tagno = -2; | |
8264 | /* Initialize it due to a false compiler warning. */ | |
8265 | dwarf_vma second_abbrev_tag = -1; | |
8266 | for (;;) | |
8267 | { | |
8268 | unsigned int bytes_read; | |
8269 | const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read, | |
8270 | unit_end); | |
8271 | entryptr += bytes_read; | |
8272 | if (tagno == -1) | |
8273 | { | |
8274 | second_abbrev_tag = abbrev_tag; | |
8275 | tagno = 0; | |
8276 | entryptr = entry_pool + entry_offset; | |
8277 | continue; | |
8278 | } | |
8279 | if (abbrev_tag == 0) | |
8280 | break; | |
8281 | if (tagno >= 0) | |
8282 | printf ("%s<%lu>", | |
8283 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
8284 | (unsigned long) abbrev_tag); | |
8285 | ||
8286 | const struct abbrev_lookup_entry *entry; | |
8287 | for (entry = abbrev_lookup; | |
8288 | entry < abbrev_lookup + abbrev_lookup_used; | |
8289 | entry++) | |
8290 | if (entry->abbrev_tag == abbrev_tag) | |
8291 | break; | |
8292 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
8293 | { | |
8294 | warn (_("Undefined abbreviation tag %lu " | |
8295 | "in unit 0x%lx in the debug_names\n"), | |
8296 | (long) abbrev_tag, | |
8297 | (long) (unit_start - section->start)); | |
8298 | break; | |
8299 | } | |
8300 | abbrevptr = entry->abbrev_lookup_ptr; | |
8301 | const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read, | |
8302 | abbrev_table_end); | |
8303 | abbrevptr += bytes_read; | |
8304 | if (tagno >= 0) | |
8305 | printf (" %s", get_TAG_name (dwarf_tag)); | |
8306 | for (;;) | |
8307 | { | |
1d827a72 L |
8308 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
8309 | &bytes_read, | |
8310 | abbrev_table_end); | |
61364358 JK |
8311 | abbrevptr += bytes_read; |
8312 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
8313 | abbrev_table_end); | |
8314 | abbrevptr += bytes_read; | |
1d827a72 | 8315 | if (xindex == 0 && form == 0) |
61364358 JK |
8316 | break; |
8317 | ||
8318 | if (tagno >= 0) | |
1d827a72 | 8319 | printf (" %s", get_IDX_name (xindex)); |
61364358 JK |
8320 | entryptr = read_and_display_attr_value (0, form, 0, entryptr, |
8321 | unit_end, 0, 0, | |
8322 | offset_size, | |
8323 | dwarf_version, NULL, | |
8324 | (tagno < 0), NULL, | |
8325 | NULL, '='); | |
8326 | } | |
8327 | ++tagno; | |
8328 | } | |
8329 | if (tagno <= 0) | |
8330 | printf (_(" <no entries>")); | |
8331 | putchar ('\n'); | |
8332 | } | |
8333 | ||
8334 | free (abbrev_lookup); | |
8335 | } | |
8336 | ||
8337 | return 1; | |
8338 | } | |
8339 | ||
5bbdf3d5 DE |
8340 | static int |
8341 | display_gdb_index (struct dwarf_section *section, | |
8342 | void *file ATTRIBUTE_UNUSED) | |
8343 | { | |
8344 | unsigned char *start = section->start; | |
8345 | uint32_t version; | |
8346 | uint32_t cu_list_offset, tu_list_offset; | |
8347 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
8348 | unsigned int cu_list_elements, tu_list_elements; | |
8349 | unsigned int address_table_size, symbol_table_slots; | |
8350 | unsigned char *cu_list, *tu_list; | |
8351 | unsigned char *address_table, *symbol_table, *constant_pool; | |
8352 | unsigned int i; | |
8353 | ||
8354 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
8355 | ||
8356 | printf (_("Contents of the %s section:\n"), section->name); | |
8357 | ||
8358 | if (section->size < 6 * sizeof (uint32_t)) | |
8359 | { | |
8360 | warn (_("Truncated header in the %s section.\n"), section->name); | |
8361 | return 0; | |
8362 | } | |
8363 | ||
8364 | version = byte_get_little_endian (start, 4); | |
da88a764 | 8365 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
8366 | |
8367 | /* Prior versions are obsolete, and future versions may not be | |
8368 | backwards compatible. */ | |
aa170720 | 8369 | if (version < 3 || version > 8) |
5bbdf3d5 | 8370 | { |
da88a764 | 8371 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
8372 | return 0; |
8373 | } | |
8d6eee87 TT |
8374 | if (version < 4) |
8375 | warn (_("The address table data in version 3 may be wrong.\n")); | |
8376 | if (version < 5) | |
8377 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
8378 | if (version < 6) | |
8379 | warn (_("Version 5 does not include inlined functions.\n")); | |
8380 | if (version < 7) | |
8381 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
8382 | /* Version 7 indices generated by Gold have bad type unit references, |
8383 | PR binutils/15021. But we don't know if the index was generated by | |
8384 | Gold or not, so to avoid worrying users with gdb-generated indices | |
8385 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
8386 | |
8387 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
8388 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
8389 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
8390 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
8391 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
8392 | ||
8393 | if (cu_list_offset > section->size | |
8394 | || tu_list_offset > section->size | |
8395 | || address_table_offset > section->size | |
8396 | || symbol_table_offset > section->size | |
8397 | || constant_pool_offset > section->size) | |
8398 | { | |
8399 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
8400 | return 0; | |
8401 | } | |
8402 | ||
53774b7e NC |
8403 | /* PR 17531: file: 418d0a8a. */ |
8404 | if (tu_list_offset < cu_list_offset) | |
8405 | { | |
8406 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
8407 | tu_list_offset, cu_list_offset); | |
8408 | return 0; | |
8409 | } | |
8410 | ||
5bbdf3d5 | 8411 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
8412 | |
8413 | if (address_table_offset < tu_list_offset) | |
8414 | { | |
8415 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
8416 | address_table_offset, tu_list_offset); | |
8417 | return 0; | |
8418 | } | |
8419 | ||
5bbdf3d5 | 8420 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
8421 | |
8422 | /* PR 17531: file: 18a47d3d. */ | |
8423 | if (symbol_table_offset < address_table_offset) | |
8424 | { | |
13bace4a | 8425 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
8426 | symbol_table_offset, address_table_offset); |
8427 | return 0; | |
8428 | } | |
8429 | ||
5bbdf3d5 | 8430 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
8431 | |
8432 | if (constant_pool_offset < symbol_table_offset) | |
8433 | { | |
8434 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
8435 | constant_pool_offset, symbol_table_offset); | |
8436 | return 0; | |
8437 | } | |
8438 | ||
5bbdf3d5 DE |
8439 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
8440 | ||
8441 | cu_list = start + cu_list_offset; | |
8442 | tu_list = start + tu_list_offset; | |
8443 | address_table = start + address_table_offset; | |
8444 | symbol_table = start + symbol_table_offset; | |
8445 | constant_pool = start + constant_pool_offset; | |
8446 | ||
28d909e5 | 8447 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 8448 | { |
1306a742 | 8449 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
8450 | return 0; |
8451 | } | |
b4eb7656 | 8452 | |
5bbdf3d5 DE |
8453 | printf (_("\nCU table:\n")); |
8454 | for (i = 0; i < cu_list_elements; i += 2) | |
8455 | { | |
8456 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
8457 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
8458 | ||
8459 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
8460 | (unsigned long) cu_offset, | |
8461 | (unsigned long) (cu_offset + cu_length - 1)); | |
8462 | } | |
8463 | ||
8464 | printf (_("\nTU table:\n")); | |
8465 | for (i = 0; i < tu_list_elements; i += 3) | |
8466 | { | |
8467 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
8468 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
8469 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
8470 | ||
8471 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
8472 | (unsigned long) tu_offset, | |
8473 | (unsigned long) type_offset); | |
8474 | print_dwarf_vma (signature, 8); | |
8475 | printf ("\n"); | |
8476 | } | |
8477 | ||
8478 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
8479 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
8480 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
8481 | { |
8482 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
8483 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
8484 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
8485 | ||
8486 | print_dwarf_vma (low, 8); | |
8487 | print_dwarf_vma (high, 8); | |
da88a764 | 8488 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
8489 | } |
8490 | ||
8491 | printf (_("\nSymbol table:\n")); | |
8492 | for (i = 0; i < symbol_table_slots; ++i) | |
8493 | { | |
8494 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
8495 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
8496 | uint32_t num_cus, cu; | |
8497 | ||
8498 | if (name_offset != 0 | |
8499 | || cu_vector_offset != 0) | |
8500 | { | |
8501 | unsigned int j; | |
362beea4 | 8502 | unsigned char * adr; |
5bbdf3d5 | 8503 | |
362beea4 | 8504 | adr = constant_pool + name_offset; |
53774b7e | 8505 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 8506 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
8507 | { |
8508 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
8509 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
8510 | name_offset, i); | |
8511 | } | |
8512 | else | |
acff9664 NC |
8513 | printf ("[%3u] %.*s:", i, |
8514 | (int) (section->size - (constant_pool_offset + name_offset)), | |
8515 | constant_pool + name_offset); | |
53774b7e | 8516 | |
362beea4 NC |
8517 | adr = constant_pool + cu_vector_offset; |
8518 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
8519 | { |
8520 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
8521 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
8522 | cu_vector_offset, i); | |
8523 | continue; | |
8524 | } | |
57028622 | 8525 | |
362beea4 | 8526 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 8527 | |
362beea4 | 8528 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 8529 | if (num_cus * 4 < num_cus |
362beea4 NC |
8530 | || adr >= section->start + section->size |
8531 | || adr < constant_pool) | |
53774b7e NC |
8532 | { |
8533 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 8534 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
8535 | num_cus, i); |
8536 | continue; | |
8537 | } | |
8538 | ||
8d6eee87 TT |
8539 | if (num_cus > 1) |
8540 | printf ("\n"); | |
f3853b34 | 8541 | |
5bbdf3d5 DE |
8542 | for (j = 0; j < num_cus; ++j) |
8543 | { | |
7c1cef97 | 8544 | int is_static; |
8d6eee87 TT |
8545 | gdb_index_symbol_kind kind; |
8546 | ||
5bbdf3d5 | 8547 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 8548 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
8549 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
8550 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 8551 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 8552 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
8553 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
8554 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 8555 | else |
8d6eee87 TT |
8556 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
8557 | ||
459d52c8 DE |
8558 | printf (" [%s, %s]", |
8559 | is_static ? _("static") : _("global"), | |
8560 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
8561 | if (num_cus > 1) |
8562 | printf ("\n"); | |
5bbdf3d5 | 8563 | } |
8d6eee87 TT |
8564 | if (num_cus <= 1) |
8565 | printf ("\n"); | |
5bbdf3d5 DE |
8566 | } |
8567 | } | |
8568 | ||
8569 | return 1; | |
8570 | } | |
8571 | ||
657d0d47 CC |
8572 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
8573 | ||
8574 | static void | |
8575 | prealloc_cu_tu_list (unsigned int nshndx) | |
8576 | { | |
8577 | if (shndx_pool == NULL) | |
8578 | { | |
8579 | shndx_pool_size = nshndx; | |
8580 | shndx_pool_used = 0; | |
8581 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
8582 | sizeof (unsigned int)); | |
8583 | } | |
8584 | else | |
8585 | { | |
8586 | shndx_pool_size = shndx_pool_used + nshndx; | |
8587 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
8588 | sizeof (unsigned int)); | |
8589 | } | |
8590 | } | |
8591 | ||
8592 | static void | |
8593 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
8594 | { | |
8595 | if (shndx_pool_used >= shndx_pool_size) | |
8596 | { | |
8597 | error (_("Internal error: out of space in the shndx pool.\n")); | |
8598 | return; | |
8599 | } | |
8600 | shndx_pool [shndx_pool_used++] = shndx; | |
8601 | } | |
8602 | ||
8603 | static void | |
8604 | end_cu_tu_entry (void) | |
8605 | { | |
8606 | if (shndx_pool_used >= shndx_pool_size) | |
8607 | { | |
8608 | error (_("Internal error: out of space in the shndx pool.\n")); | |
8609 | return; | |
8610 | } | |
8611 | shndx_pool [shndx_pool_used++] = 0; | |
8612 | } | |
8613 | ||
341f9135 CC |
8614 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
8615 | ||
8616 | static const char * | |
8617 | get_DW_SECT_short_name (unsigned int dw_sect) | |
8618 | { | |
8619 | static char buf[16]; | |
8620 | ||
8621 | switch (dw_sect) | |
8622 | { | |
8623 | case DW_SECT_INFO: | |
8624 | return "info"; | |
8625 | case DW_SECT_TYPES: | |
8626 | return "types"; | |
8627 | case DW_SECT_ABBREV: | |
8628 | return "abbrev"; | |
8629 | case DW_SECT_LINE: | |
8630 | return "line"; | |
8631 | case DW_SECT_LOC: | |
8632 | return "loc"; | |
8633 | case DW_SECT_STR_OFFSETS: | |
8634 | return "str_off"; | |
8635 | case DW_SECT_MACINFO: | |
8636 | return "macinfo"; | |
8637 | case DW_SECT_MACRO: | |
8638 | return "macro"; | |
8639 | default: | |
b4eb7656 | 8640 | break; |
341f9135 CC |
8641 | } |
8642 | ||
8643 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
8644 | return buf; | |
8645 | } | |
8646 | ||
8647 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
8648 | These sections are extensions for Fission. | |
8649 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
8650 | |
8651 | static int | |
8652 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
8653 | { | |
8654 | unsigned char *phdr = section->start; | |
8655 | unsigned char *limit = phdr + section->size; | |
8656 | unsigned char *phash; | |
8657 | unsigned char *pindex; | |
8658 | unsigned char *ppool; | |
8659 | unsigned int version; | |
341f9135 | 8660 | unsigned int ncols = 0; |
657d0d47 CC |
8661 | unsigned int nused; |
8662 | unsigned int nslots; | |
8663 | unsigned int i; | |
341f9135 CC |
8664 | unsigned int j; |
8665 | dwarf_vma signature_high; | |
8666 | dwarf_vma signature_low; | |
8667 | char buf[64]; | |
657d0d47 | 8668 | |
6937bb54 NC |
8669 | /* PR 17512: file: 002-168123-0.004. */ |
8670 | if (phdr == NULL) | |
8671 | { | |
8672 | warn (_("Section %s is empty\n"), section->name); | |
8673 | return 0; | |
8674 | } | |
8675 | /* PR 17512: file: 002-376-0.004. */ | |
8676 | if (section->size < 24) | |
8677 | { | |
72c61a0d | 8678 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
8679 | section->name); |
8680 | return 0; | |
8681 | } | |
8682 | ||
8683 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 8684 | if (version >= 2) |
6937bb54 NC |
8685 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
8686 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
8687 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
8688 | ||
657d0d47 CC |
8689 | phash = phdr + 16; |
8690 | pindex = phash + nslots * 8; | |
8691 | ppool = pindex + nslots * 4; | |
8692 | ||
57028622 | 8693 | /* PR 17531: file: 45d69832. */ |
03a91817 | 8694 | if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0)) |
57028622 NC |
8695 | { |
8696 | warn (_("Section %s is too small for %d slots\n"), | |
8697 | section->name, nslots); | |
8698 | return 0; | |
8699 | } | |
8700 | ||
657d0d47 CC |
8701 | if (do_display) |
8702 | { | |
8703 | printf (_("Contents of the %s section:\n\n"), section->name); | |
8704 | printf (_(" Version: %d\n"), version); | |
341f9135 CC |
8705 | if (version >= 2) |
8706 | printf (_(" Number of columns: %d\n"), ncols); | |
657d0d47 CC |
8707 | printf (_(" Number of used entries: %d\n"), nused); |
8708 | printf (_(" Number of slots: %d\n\n"), nslots); | |
8709 | } | |
8710 | ||
03a91817 | 8711 | if (ppool > limit || ppool < phdr) |
657d0d47 CC |
8712 | { |
8713 | warn (_("Section %s too small for %d hash table entries\n"), | |
8714 | section->name, nslots); | |
8715 | return 0; | |
8716 | } | |
8717 | ||
341f9135 | 8718 | if (version == 1) |
657d0d47 | 8719 | { |
341f9135 CC |
8720 | if (!do_display) |
8721 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
8722 | for (i = 0; i < nslots; i++) | |
657d0d47 | 8723 | { |
341f9135 CC |
8724 | unsigned char *shndx_list; |
8725 | unsigned int shndx; | |
8726 | ||
6937bb54 | 8727 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 8728 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 8729 | { |
6937bb54 | 8730 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 8731 | shndx_list = ppool + j * 4; |
f3853b34 NC |
8732 | /* PR 17531: file: 705e010d. */ |
8733 | if (shndx_list < ppool) | |
8734 | { | |
8735 | warn (_("Section index pool located before start of section\n")); | |
8736 | return 0; | |
8737 | } | |
8738 | ||
341f9135 CC |
8739 | if (do_display) |
8740 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
8741 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
8742 | buf, sizeof (buf))); | |
8743 | for (;;) | |
657d0d47 | 8744 | { |
341f9135 CC |
8745 | if (shndx_list >= limit) |
8746 | { | |
8747 | warn (_("Section %s too small for shndx pool\n"), | |
8748 | section->name); | |
8749 | return 0; | |
8750 | } | |
6937bb54 | 8751 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
8752 | if (shndx == 0) |
8753 | break; | |
8754 | if (do_display) | |
8755 | printf (" %d", shndx); | |
8756 | else | |
8757 | add_shndx_to_cu_tu_entry (shndx); | |
8758 | shndx_list += 4; | |
657d0d47 | 8759 | } |
657d0d47 | 8760 | if (do_display) |
341f9135 | 8761 | printf ("\n"); |
657d0d47 | 8762 | else |
341f9135 CC |
8763 | end_cu_tu_entry (); |
8764 | } | |
8765 | phash += 8; | |
8766 | pindex += 4; | |
8767 | } | |
8768 | } | |
8769 | else if (version == 2) | |
8770 | { | |
8771 | unsigned int val; | |
8772 | unsigned int dw_sect; | |
8773 | unsigned char *ph = phash; | |
8774 | unsigned char *pi = pindex; | |
8775 | unsigned char *poffsets = ppool + ncols * 4; | |
8776 | unsigned char *psizes = poffsets + nused * ncols * 4; | |
8777 | unsigned char *pend = psizes + nused * ncols * 4; | |
8778 | bfd_boolean is_tu_index; | |
8779 | struct cu_tu_set *this_set = NULL; | |
8780 | unsigned int row; | |
8781 | unsigned char *prow; | |
8782 | ||
8783 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
8784 | ||
362beea4 | 8785 | /* PR 17531: file: 0dd159bf. |
b4eb7656 | 8786 | Check for wraparound with an overlarge ncols value. */ |
c8071705 | 8787 | if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols) |
362beea4 NC |
8788 | { |
8789 | warn (_("Overlarge number of columns: %x\n"), ncols); | |
8790 | return 0; | |
8791 | } | |
8792 | ||
341f9135 CC |
8793 | if (pend > limit) |
8794 | { | |
8795 | warn (_("Section %s too small for offset and size tables\n"), | |
8796 | section->name); | |
8797 | return 0; | |
8798 | } | |
8799 | ||
8800 | if (do_display) | |
8801 | { | |
8802 | printf (_(" Offset table\n")); | |
8803 | printf (" slot %-16s ", | |
8804 | is_tu_index ? _("signature") : _("dwo_id")); | |
8805 | } | |
8806 | else | |
8807 | { | |
8808 | if (is_tu_index) | |
8809 | { | |
8810 | tu_count = nused; | |
72c61a0d | 8811 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 8812 | this_set = tu_sets; |
657d0d47 | 8813 | } |
657d0d47 | 8814 | else |
341f9135 CC |
8815 | { |
8816 | cu_count = nused; | |
72c61a0d | 8817 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
8818 | this_set = cu_sets; |
8819 | } | |
8820 | } | |
6937bb54 | 8821 | |
341f9135 CC |
8822 | if (do_display) |
8823 | { | |
8824 | for (j = 0; j < ncols; j++) | |
8825 | { | |
6937bb54 | 8826 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
8827 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
8828 | } | |
8829 | printf ("\n"); | |
8830 | } | |
6937bb54 | 8831 | |
341f9135 CC |
8832 | for (i = 0; i < nslots; i++) |
8833 | { | |
6937bb54 NC |
8834 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
8835 | ||
8836 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
8837 | if (row != 0) |
8838 | { | |
591f7597 | 8839 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 8840 | if (row > nused) |
591f7597 NC |
8841 | { |
8842 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
8843 | row, nused); | |
8844 | return 0; | |
8845 | } | |
8846 | ||
341f9135 CC |
8847 | if (!do_display) |
8848 | memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t)); | |
6937bb54 | 8849 | |
341f9135 | 8850 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
8851 | /* PR 17531: file: b8ce60a8. */ |
8852 | if (prow < poffsets || prow > limit) | |
8853 | { | |
8854 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
8855 | row, ncols); | |
8856 | return 0; | |
8857 | } | |
3aade688 | 8858 | |
341f9135 CC |
8859 | if (do_display) |
8860 | printf (_(" [%3d] 0x%s"), | |
8861 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
8862 | buf, sizeof (buf))); | |
8863 | for (j = 0; j < ncols; j++) | |
8864 | { | |
6937bb54 | 8865 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
8866 | if (do_display) |
8867 | printf (" %8d", val); | |
8868 | else | |
8869 | { | |
6937bb54 | 8870 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
8871 | |
8872 | /* PR 17531: file: 10796eb3. */ | |
8873 | if (dw_sect >= DW_SECT_MAX) | |
8874 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
8875 | else | |
8876 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
8877 | } |
8878 | } | |
6937bb54 | 8879 | |
341f9135 CC |
8880 | if (do_display) |
8881 | printf ("\n"); | |
8882 | } | |
8883 | ph += 8; | |
8884 | pi += 4; | |
8885 | } | |
8886 | ||
8887 | ph = phash; | |
8888 | pi = pindex; | |
8889 | if (do_display) | |
b4eb7656 | 8890 | { |
341f9135 CC |
8891 | printf ("\n"); |
8892 | printf (_(" Size table\n")); | |
8893 | printf (" slot %-16s ", | |
8894 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 8895 | } |
6937bb54 | 8896 | |
341f9135 CC |
8897 | for (j = 0; j < ncols; j++) |
8898 | { | |
6937bb54 | 8899 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
8900 | if (do_display) |
8901 | printf (" %8s", get_DW_SECT_short_name (val)); | |
8902 | } | |
6937bb54 | 8903 | |
341f9135 CC |
8904 | if (do_display) |
8905 | printf ("\n"); | |
6937bb54 | 8906 | |
341f9135 CC |
8907 | for (i = 0; i < nslots; i++) |
8908 | { | |
6937bb54 NC |
8909 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
8910 | ||
8911 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
8912 | if (row != 0) |
8913 | { | |
8914 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 8915 | |
341f9135 CC |
8916 | if (do_display) |
8917 | printf (_(" [%3d] 0x%s"), | |
8918 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
8919 | buf, sizeof (buf))); | |
6937bb54 | 8920 | |
341f9135 CC |
8921 | for (j = 0; j < ncols; j++) |
8922 | { | |
6937bb54 | 8923 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
8924 | if (do_display) |
8925 | printf (" %8d", val); | |
8926 | else | |
8927 | { | |
6937bb54 | 8928 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
8929 | if (dw_sect >= DW_SECT_MAX) |
8930 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
8931 | else | |
341f9135 CC |
8932 | this_set [row - 1].section_sizes [dw_sect] = val; |
8933 | } | |
8934 | } | |
6937bb54 | 8935 | |
341f9135 CC |
8936 | if (do_display) |
8937 | printf ("\n"); | |
8938 | } | |
6937bb54 | 8939 | |
341f9135 CC |
8940 | ph += 8; |
8941 | pi += 4; | |
657d0d47 | 8942 | } |
657d0d47 | 8943 | } |
341f9135 | 8944 | else if (do_display) |
6937bb54 | 8945 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
8946 | |
8947 | if (do_display) | |
8948 | printf ("\n"); | |
8949 | ||
8950 | return 1; | |
8951 | } | |
8952 | ||
8953 | /* Load the CU and TU indexes if present. This will build a list of | |
8954 | section sets that we can use to associate a .debug_info.dwo section | |
8955 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
8956 | ||
43a444f9 | 8957 | static bfd_boolean |
657d0d47 CC |
8958 | load_cu_tu_indexes (void *file) |
8959 | { | |
43a444f9 NC |
8960 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
8961 | ||
657d0d47 CC |
8962 | /* If we have already loaded (or tried to load) the CU and TU indexes |
8963 | then do not bother to repeat the task. */ | |
43a444f9 NC |
8964 | if (cu_tu_indexes_read == -1) |
8965 | { | |
8966 | cu_tu_indexes_read = TRUE; | |
8967 | ||
8968 | if (load_debug_section (dwp_cu_index, file)) | |
8969 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) | |
8970 | cu_tu_indexes_read = FALSE; | |
8971 | ||
8972 | if (load_debug_section (dwp_tu_index, file)) | |
8973 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) | |
8974 | cu_tu_indexes_read = FALSE; | |
8975 | } | |
657d0d47 | 8976 | |
43a444f9 | 8977 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
8978 | } |
8979 | ||
8980 | /* Find the set of sections that includes section SHNDX. */ | |
8981 | ||
8982 | unsigned int * | |
8983 | find_cu_tu_set (void *file, unsigned int shndx) | |
8984 | { | |
8985 | unsigned int i; | |
8986 | ||
43a444f9 NC |
8987 | if (! load_cu_tu_indexes (file)) |
8988 | return NULL; | |
657d0d47 CC |
8989 | |
8990 | /* Find SHNDX in the shndx pool. */ | |
8991 | for (i = 0; i < shndx_pool_used; i++) | |
8992 | if (shndx_pool [i] == shndx) | |
8993 | break; | |
8994 | ||
8995 | if (i >= shndx_pool_used) | |
8996 | return NULL; | |
8997 | ||
8998 | /* Now backup to find the first entry in the set. */ | |
8999 | while (i > 0 && shndx_pool [i - 1] != 0) | |
9000 | i--; | |
9001 | ||
9002 | return shndx_pool + i; | |
9003 | } | |
9004 | ||
9005 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
9006 | ||
9007 | static int | |
9008 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
9009 | { | |
9010 | return process_cu_tu_index (section, 1); | |
9011 | } | |
9012 | ||
19e6b90e L |
9013 | static int |
9014 | display_debug_not_supported (struct dwarf_section *section, | |
9015 | void *file ATTRIBUTE_UNUSED) | |
9016 | { | |
9017 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
9018 | section->name); | |
9019 | ||
9020 | return 1; | |
9021 | } | |
9022 | ||
1306a742 NC |
9023 | /* Like malloc, but takes two parameters like calloc. |
9024 | Verifies that the first parameter is not too large. | |
82b1b41b | 9025 | Note: does *not* initialise the allocated memory to zero. */ |
19e6b90e L |
9026 | void * |
9027 | cmalloc (size_t nmemb, size_t size) | |
9028 | { | |
9029 | /* Check for overflow. */ | |
9030 | if (nmemb >= ~(size_t) 0 / size) | |
9031 | return NULL; | |
82b1b41b NC |
9032 | |
9033 | return xmalloc (nmemb * size); | |
19e6b90e L |
9034 | } |
9035 | ||
1306a742 NC |
9036 | /* Like xmalloc, but takes two parameters like calloc. |
9037 | Verifies that the first parameter is not too large. | |
9038 | Note: does *not* initialise the allocated memory to zero. */ | |
72c61a0d | 9039 | void * |
1306a742 | 9040 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
9041 | { |
9042 | /* Check for overflow. */ | |
9043 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
9044 | { |
9045 | fprintf (stderr, | |
9046 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
9047 | (long) nmemb); | |
9048 | xexit (1); | |
9049 | } | |
72c61a0d | 9050 | |
1306a742 | 9051 | return xmalloc (nmemb * size); |
72c61a0d NC |
9052 | } |
9053 | ||
1306a742 NC |
9054 | /* Like xrealloc, but takes three parameters. |
9055 | Verifies that the second parameter is not too large. | |
9056 | Note: does *not* initialise any new memory to zero. */ | |
19e6b90e | 9057 | void * |
1306a742 | 9058 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
9059 | { |
9060 | /* Check for overflow. */ | |
9061 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
9062 | { |
9063 | fprintf (stderr, | |
9064 | _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), | |
9065 | (long) nmemb); | |
9066 | xexit (1); | |
9067 | } | |
82b1b41b | 9068 | |
1306a742 | 9069 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
9070 | } |
9071 | ||
1306a742 | 9072 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
19e6b90e | 9073 | void * |
1306a742 | 9074 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
9075 | { |
9076 | /* Check for overflow. */ | |
9077 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
9078 | { |
9079 | fprintf (stderr, | |
9080 | _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), | |
9081 | (long) nmemb); | |
9082 | xexit (1); | |
9083 | } | |
82b1b41b | 9084 | |
1306a742 | 9085 | return xcalloc (nmemb, size); |
19e6b90e L |
9086 | } |
9087 | ||
19e6b90e L |
9088 | void |
9089 | free_debug_memory (void) | |
9090 | { | |
3f5e193b | 9091 | unsigned int i; |
19e6b90e L |
9092 | |
9093 | free_abbrevs (); | |
9094 | ||
9095 | for (i = 0; i < max; i++) | |
3f5e193b | 9096 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 9097 | |
cc86f28f | 9098 | if (debug_information != NULL) |
19e6b90e | 9099 | { |
cc86f28f | 9100 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 9101 | { |
cc86f28f | 9102 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 9103 | { |
cc86f28f NC |
9104 | if (!debug_information [i].max_loc_offsets) |
9105 | { | |
9106 | free (debug_information [i].loc_offsets); | |
9107 | free (debug_information [i].have_frame_base); | |
9108 | } | |
9109 | if (!debug_information [i].max_range_lists) | |
9110 | free (debug_information [i].range_lists); | |
19e6b90e | 9111 | } |
19e6b90e L |
9112 | } |
9113 | free (debug_information); | |
9114 | debug_information = NULL; | |
82b1b41b | 9115 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 9116 | } |
19e6b90e L |
9117 | } |
9118 | ||
4cb93e3b TG |
9119 | void |
9120 | dwarf_select_sections_by_names (const char *names) | |
9121 | { | |
9122 | typedef struct | |
9123 | { | |
9124 | const char * option; | |
9125 | int * variable; | |
f9f0e732 | 9126 | int val; |
4cb93e3b TG |
9127 | } |
9128 | debug_dump_long_opts; | |
9129 | ||
9130 | static const debug_dump_long_opts opts_table [] = | |
9131 | { | |
9132 | /* Please keep this table alpha- sorted. */ | |
9133 | { "Ranges", & do_debug_ranges, 1 }, | |
9134 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 9135 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 9136 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
9137 | { "cu_index", & do_debug_cu_index, 1 }, |
9138 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
4cb93e3b TG |
9139 | { "frames", & do_debug_frames, 1 }, |
9140 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
9141 | /* The special .gdb_index section. */ |
9142 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
9143 | { "info", & do_debug_info, 1 }, |
9144 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
4cb93e3b TG |
9145 | { "loc", & do_debug_loc, 1 }, |
9146 | { "macro", & do_debug_macinfo, 1 }, | |
9147 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 9148 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 9149 | /* This entry is for compatibility |
4cb93e3b TG |
9150 | with earlier versions of readelf. */ |
9151 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 9152 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 9153 | { "str", & do_debug_str, 1 }, |
6f875884 TG |
9154 | /* These trace_* sections are used by Itanium VMS. */ |
9155 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
9156 | { "trace_aranges", & do_trace_aranges, 1 }, | |
9157 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
9158 | { NULL, NULL, 0 } |
9159 | }; | |
9160 | ||
9161 | const char *p; | |
467c65bc | 9162 | |
4cb93e3b TG |
9163 | p = names; |
9164 | while (*p) | |
9165 | { | |
9166 | const debug_dump_long_opts * entry; | |
467c65bc | 9167 | |
4cb93e3b TG |
9168 | for (entry = opts_table; entry->option; entry++) |
9169 | { | |
9170 | size_t len = strlen (entry->option); | |
467c65bc | 9171 | |
4cb93e3b TG |
9172 | if (strncmp (p, entry->option, len) == 0 |
9173 | && (p[len] == ',' || p[len] == '\0')) | |
9174 | { | |
9175 | * entry->variable |= entry->val; | |
467c65bc | 9176 | |
4cb93e3b TG |
9177 | /* The --debug-dump=frames-interp option also |
9178 | enables the --debug-dump=frames option. */ | |
9179 | if (do_debug_frames_interp) | |
9180 | do_debug_frames = 1; | |
9181 | ||
9182 | p += len; | |
9183 | break; | |
9184 | } | |
9185 | } | |
467c65bc | 9186 | |
4cb93e3b TG |
9187 | if (entry->option == NULL) |
9188 | { | |
9189 | warn (_("Unrecognized debug option '%s'\n"), p); | |
9190 | p = strchr (p, ','); | |
9191 | if (p == NULL) | |
9192 | break; | |
9193 | } | |
467c65bc | 9194 | |
4cb93e3b TG |
9195 | if (*p == ',') |
9196 | p++; | |
9197 | } | |
9198 | } | |
9199 | ||
9200 | void | |
9201 | dwarf_select_sections_by_letters (const char *letters) | |
9202 | { | |
91d6fa6a | 9203 | unsigned int lindex = 0; |
4cb93e3b | 9204 | |
91d6fa6a NC |
9205 | while (letters[lindex]) |
9206 | switch (letters[lindex++]) | |
4cb93e3b TG |
9207 | { |
9208 | case 'i': | |
9209 | do_debug_info = 1; | |
9210 | break; | |
467c65bc | 9211 | |
4cb93e3b TG |
9212 | case 'a': |
9213 | do_debug_abbrevs = 1; | |
9214 | break; | |
467c65bc | 9215 | |
4cb93e3b TG |
9216 | case 'l': |
9217 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
9218 | break; | |
467c65bc | 9219 | |
4cb93e3b TG |
9220 | case 'L': |
9221 | do_debug_lines |= FLAG_DEBUG_LINES_DECODED; | |
9222 | break; | |
467c65bc | 9223 | |
4cb93e3b TG |
9224 | case 'p': |
9225 | do_debug_pubnames = 1; | |
9226 | break; | |
467c65bc | 9227 | |
f9f0e732 NC |
9228 | case 't': |
9229 | do_debug_pubtypes = 1; | |
9230 | break; | |
467c65bc | 9231 | |
4cb93e3b TG |
9232 | case 'r': |
9233 | do_debug_aranges = 1; | |
9234 | break; | |
467c65bc | 9235 | |
4cb93e3b TG |
9236 | case 'R': |
9237 | do_debug_ranges = 1; | |
9238 | break; | |
467c65bc | 9239 | |
4cb93e3b TG |
9240 | case 'F': |
9241 | do_debug_frames_interp = 1; | |
1a0670f3 | 9242 | /* Fall through. */ |
4cb93e3b TG |
9243 | case 'f': |
9244 | do_debug_frames = 1; | |
9245 | break; | |
467c65bc | 9246 | |
4cb93e3b TG |
9247 | case 'm': |
9248 | do_debug_macinfo = 1; | |
9249 | break; | |
467c65bc | 9250 | |
4cb93e3b TG |
9251 | case 's': |
9252 | do_debug_str = 1; | |
9253 | break; | |
467c65bc | 9254 | |
4cb93e3b TG |
9255 | case 'o': |
9256 | do_debug_loc = 1; | |
9257 | break; | |
467c65bc | 9258 | |
4cb93e3b | 9259 | default: |
7cc78d07 | 9260 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
9261 | break; |
9262 | } | |
9263 | } | |
9264 | ||
9265 | void | |
9266 | dwarf_select_sections_all (void) | |
9267 | { | |
9268 | do_debug_info = 1; | |
9269 | do_debug_abbrevs = 1; | |
9270 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
9271 | do_debug_pubnames = 1; | |
f9f0e732 | 9272 | do_debug_pubtypes = 1; |
4cb93e3b TG |
9273 | do_debug_aranges = 1; |
9274 | do_debug_ranges = 1; | |
9275 | do_debug_frames = 1; | |
9276 | do_debug_macinfo = 1; | |
9277 | do_debug_str = 1; | |
9278 | do_debug_loc = 1; | |
5bbdf3d5 | 9279 | do_gdb_index = 1; |
6f875884 TG |
9280 | do_trace_info = 1; |
9281 | do_trace_abbrevs = 1; | |
9282 | do_trace_aranges = 1; | |
657d0d47 CC |
9283 | do_debug_addr = 1; |
9284 | do_debug_cu_index = 1; | |
4cb93e3b TG |
9285 | } |
9286 | ||
19e6b90e L |
9287 | struct dwarf_section_display debug_displays[] = |
9288 | { | |
d1c4b12b NC |
9289 | { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
9290 | display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
9291 | { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9292 | display_debug_aranges, &do_debug_aranges, TRUE }, | |
9293 | { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9294 | display_debug_frames, &do_debug_frames, TRUE }, | |
9295 | { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL }, | |
9296 | display_debug_info, &do_debug_info, TRUE }, | |
9297 | { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9298 | display_debug_lines, &do_debug_lines, TRUE }, | |
9299 | { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9300 | display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
9301 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9302 | display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
9303 | { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9304 | display_debug_frames, &do_debug_frames, TRUE }, | |
9305 | { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9306 | display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
9307 | { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9308 | display_debug_macro, &do_debug_macinfo, TRUE }, | |
9309 | { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9310 | display_debug_str, &do_debug_str, FALSE }, | |
77145576 JK |
9311 | { { ".debug_line_str", ".zdebug_line_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
9312 | display_debug_str, &do_debug_str, FALSE }, | |
d1c4b12b NC |
9313 | { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
9314 | display_debug_loc, &do_debug_loc, TRUE }, | |
77145576 JK |
9315 | { { ".debug_loclists", ".zdebug_loclists", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
9316 | display_debug_loc, &do_debug_loc, TRUE }, | |
d1c4b12b NC |
9317 | { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
9318 | display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
9319 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9320 | display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
9321 | { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9322 | display_debug_ranges, &do_debug_ranges, TRUE }, | |
77145576 JK |
9323 | { { ".debug_rnglists", ".zdebug_rnglists", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
9324 | display_debug_ranges, &do_debug_ranges, TRUE }, | |
d1c4b12b NC |
9325 | { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
9326 | display_debug_not_supported, NULL, FALSE }, | |
9327 | { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9328 | display_debug_not_supported, NULL, FALSE }, | |
9329 | { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL }, | |
9330 | display_debug_types, &do_debug_info, TRUE }, | |
9331 | { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9332 | display_debug_not_supported, NULL, FALSE }, | |
9333 | { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9334 | display_gdb_index, &do_gdb_index, FALSE }, | |
61364358 JK |
9335 | { { ".debug_names", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
9336 | display_debug_names, &do_gdb_index, FALSE }, | |
d1c4b12b NC |
9337 | { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL, 0, NULL }, |
9338 | display_trace_info, &do_trace_info, TRUE }, | |
9339 | { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9340 | display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
9341 | { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9342 | display_debug_aranges, &do_trace_aranges, FALSE }, | |
9343 | { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL }, | |
9344 | display_debug_info, &do_debug_info, TRUE }, | |
9345 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9346 | display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
9347 | { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL }, | |
9348 | display_debug_types, &do_debug_info, TRUE }, | |
9349 | { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9350 | display_debug_lines, &do_debug_lines, TRUE }, | |
9351 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9352 | display_debug_loc, &do_debug_loc, TRUE }, | |
9353 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9354 | display_debug_macro, &do_debug_macinfo, TRUE }, | |
9355 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9356 | display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
9357 | { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9358 | display_debug_str, &do_debug_str, TRUE }, | |
9359 | { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9360 | display_debug_str_offsets, NULL, FALSE }, | |
9361 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9362 | display_debug_str_offsets, NULL, FALSE }, | |
9363 | { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9364 | display_debug_addr, &do_debug_addr, TRUE }, | |
9365 | { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9366 | display_cu_index, &do_debug_cu_index, FALSE }, | |
9367 | { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9368 | display_cu_index, &do_debug_cu_index, FALSE }, | |
19e6b90e | 9369 | }; |
b451e98a JK |
9370 | |
9371 | /* A static assertion. */ | |
9372 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |