]>
Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
b90efa5b | 2 | Copyright (C) 2005-2015 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" |
19e6b90e | 31 | |
18464d4d JK |
32 | static const char *regname (unsigned int regno, int row); |
33 | ||
19e6b90e L |
34 | static int have_frame_base; |
35 | static int need_base_address; | |
36 | ||
37 | static unsigned int last_pointer_size = 0; | |
38 | static int warned_about_missing_comp_units = FALSE; | |
39 | ||
40 | static unsigned int num_debug_info_entries = 0; | |
82b1b41b | 41 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 42 | static debug_info *debug_information = NULL; |
cc86f28f NC |
43 | /* Special value for num_debug_info_entries to indicate |
44 | that the .debug_info section could not be loaded/parsed. */ | |
45 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 46 | |
2dc4cec1 | 47 | int eh_addr_size; |
19e6b90e L |
48 | |
49 | int do_debug_info; | |
50 | int do_debug_abbrevs; | |
51 | int do_debug_lines; | |
52 | int do_debug_pubnames; | |
f9f0e732 | 53 | int do_debug_pubtypes; |
19e6b90e L |
54 | int do_debug_aranges; |
55 | int do_debug_ranges; | |
56 | int do_debug_frames; | |
57 | int do_debug_frames_interp; | |
58 | int do_debug_macinfo; | |
59 | int do_debug_str; | |
60 | int do_debug_loc; | |
5bbdf3d5 | 61 | int do_gdb_index; |
6f875884 TG |
62 | int do_trace_info; |
63 | int do_trace_abbrevs; | |
64 | int do_trace_aranges; | |
657d0d47 CC |
65 | int do_debug_addr; |
66 | int do_debug_cu_index; | |
a262ae96 | 67 | int do_wide; |
19e6b90e | 68 | |
fd2f0033 TT |
69 | int dwarf_cutoff_level = -1; |
70 | unsigned long dwarf_start_die; | |
71 | ||
4723351a CC |
72 | int dwarf_check = 0; |
73 | ||
341f9135 CC |
74 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
75 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
76 | as a zero-terminated list of section indexes comprising one set of debug | |
77 | sections from a .dwo file. */ | |
78 | ||
79 | static int cu_tu_indexes_read = 0; | |
80 | static unsigned int *shndx_pool = NULL; | |
81 | static unsigned int shndx_pool_size = 0; | |
82 | static unsigned int shndx_pool_used = 0; | |
83 | ||
84 | /* For version 2 package files, each set contains an array of section offsets | |
85 | and an array of section sizes, giving the offset and size of the | |
86 | contribution from a CU or TU within one of the debug sections. | |
87 | When displaying debug info from a package file, we need to use these | |
88 | tables to locate the corresponding contributions to each section. */ | |
89 | ||
90 | struct cu_tu_set | |
91 | { | |
92 | uint64_t signature; | |
93 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
94 | size_t section_sizes[DW_SECT_MAX]; | |
95 | }; | |
96 | ||
97 | static int cu_count = 0; | |
98 | static int tu_count = 0; | |
99 | static struct cu_tu_set *cu_sets = NULL; | |
100 | static struct cu_tu_set *tu_sets = NULL; | |
101 | ||
102 | static void load_cu_tu_indexes (void *file); | |
103 | ||
4cb93e3b TG |
104 | /* Values for do_debug_lines. */ |
105 | #define FLAG_DEBUG_LINES_RAW 1 | |
106 | #define FLAG_DEBUG_LINES_DECODED 2 | |
107 | ||
f1c4cc75 RH |
108 | static int |
109 | size_of_encoded_value (int encoding) | |
110 | { | |
111 | switch (encoding & 0x7) | |
112 | { | |
113 | default: /* ??? */ | |
114 | case 0: return eh_addr_size; | |
115 | case 2: return 2; | |
116 | case 3: return 4; | |
117 | case 4: return 8; | |
118 | } | |
119 | } | |
120 | ||
121 | static dwarf_vma | |
041830e0 | 122 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 123 | int encoding, |
041830e0 NC |
124 | struct dwarf_section *section, |
125 | unsigned char * end) | |
f1c4cc75 | 126 | { |
041830e0 | 127 | unsigned char * data = * pdata; |
6937bb54 | 128 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 129 | dwarf_vma val; |
f1c4cc75 | 130 | |
041830e0 NC |
131 | if (data + size >= end) |
132 | { | |
133 | warn (_("Encoded value extends past end of section\n")); | |
134 | * pdata = end; | |
135 | return 0; | |
136 | } | |
137 | ||
6937bb54 NC |
138 | /* PR 17512: file: 002-829853-0.004. */ |
139 | if (size > 8) | |
140 | { | |
141 | warn (_("Encoded size of %d is too large to read\n"), size); | |
142 | * pdata = end; | |
143 | return 0; | |
144 | } | |
145 | ||
0a9d414a NC |
146 | /* PR 17512: file: 1085-5603-0.004. */ |
147 | if (size == 0) | |
148 | { | |
149 | warn (_("Encoded size of 0 is too small to read\n")); | |
150 | * pdata = end; | |
151 | return 0; | |
152 | } | |
153 | ||
f1c4cc75 | 154 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 155 | val = byte_get_signed (data, size); |
f1c4cc75 | 156 | else |
bad62cf5 AM |
157 | val = byte_get (data, size); |
158 | ||
159 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
160 | val += section->address + (data - section->start); | |
041830e0 NC |
161 | |
162 | * pdata = data + size; | |
bad62cf5 | 163 | return val; |
f1c4cc75 RH |
164 | } |
165 | ||
4c219c2e AM |
166 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
167 | # ifndef __MINGW32__ | |
168 | # define DWARF_VMA_FMT "ll" | |
169 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
170 | # else | |
171 | # define DWARF_VMA_FMT "I64" | |
172 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
173 | # endif | |
2e14fae2 | 174 | #else |
4c219c2e AM |
175 | # define DWARF_VMA_FMT "l" |
176 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
177 | #endif |
178 | ||
bf5117e3 NC |
179 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
180 | buffer containing the converted VALUE. The value is converted according | |
181 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
182 | it specifies the maximum number of bytes to be displayed in the converted | |
183 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 184 | |
47704ddf | 185 | static const char * |
bf5117e3 | 186 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
187 | { |
188 | /* As dwarf_vmatoa is used more then once in a printf call | |
189 | for output, we are cycling through an fixed array of pointers | |
190 | for return address. */ | |
191 | static int buf_pos = 0; | |
467c65bc NC |
192 | static struct dwarf_vmatoa_buf |
193 | { | |
47704ddf KT |
194 | char place[64]; |
195 | } buf[16]; | |
47704ddf KT |
196 | char *ret; |
197 | ||
47704ddf | 198 | ret = buf[buf_pos++].place; |
467c65bc | 199 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 200 | |
bf5117e3 NC |
201 | if (num_bytes) |
202 | { | |
203 | /* Printf does not have a way of specifiying a maximum field width for an | |
204 | integer value, so we print the full value into a buffer and then select | |
205 | the precision we need. */ | |
206 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
207 | if (num_bytes > 8) | |
208 | num_bytes = 8; | |
209 | return ret + (16 - 2 * num_bytes); | |
210 | } | |
211 | else | |
212 | { | |
213 | char fmt[32]; | |
214 | ||
215 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
216 | snprintf (ret, sizeof (buf[0].place), fmt, value); | |
217 | return ret; | |
218 | } | |
219 | } | |
47704ddf | 220 | |
bf5117e3 NC |
221 | static inline const char * |
222 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
223 | { | |
224 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
225 | } | |
226 | ||
227 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
228 | hexadecimal format, followed by a space. The length of the VALUE (and | |
229 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
230 | ||
231 | static void | |
232 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
233 | { | |
234 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
235 | } |
236 | ||
74bc6052 CC |
237 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
238 | For reentrancy, this uses a buffer provided by the caller. */ | |
239 | ||
240 | static const char * | |
241 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
242 | unsigned int buf_len) | |
243 | { | |
244 | int len = 0; | |
245 | ||
246 | if (hvalue == 0) | |
247 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
248 | else | |
249 | { | |
250 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
251 | snprintf (buf + len, buf_len - len, | |
252 | "%08" DWARF_VMA_FMT "x", lvalue); | |
253 | } | |
254 | ||
255 | return buf; | |
256 | } | |
257 | ||
f6f0e17b NC |
258 | /* Read in a LEB128 encoded value starting at address DATA. |
259 | If SIGN is true, return a signed LEB128 value. | |
260 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
261 | No bytes will be read at address END or beyond. */ | |
262 | ||
467c65bc | 263 | dwarf_vma |
f6f0e17b NC |
264 | read_leb128 (unsigned char *data, |
265 | unsigned int *length_return, | |
266 | bfd_boolean sign, | |
267 | const unsigned char * const end) | |
19e6b90e | 268 | { |
467c65bc | 269 | dwarf_vma result = 0; |
19e6b90e L |
270 | unsigned int num_read = 0; |
271 | unsigned int shift = 0; | |
f6f0e17b | 272 | unsigned char byte = 0; |
19e6b90e | 273 | |
f6f0e17b | 274 | while (data < end) |
19e6b90e L |
275 | { |
276 | byte = *data++; | |
277 | num_read++; | |
278 | ||
467c65bc | 279 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
19e6b90e L |
280 | |
281 | shift += 7; | |
f6f0e17b NC |
282 | if ((byte & 0x80) == 0) |
283 | break; | |
19e6b90e | 284 | } |
19e6b90e L |
285 | |
286 | if (length_return != NULL) | |
287 | *length_return = num_read; | |
288 | ||
289 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
65879393 | 290 | result |= (dwarf_vma) -1 << shift; |
19e6b90e L |
291 | |
292 | return result; | |
293 | } | |
294 | ||
467c65bc | 295 | /* Create a signed version to avoid painful typecasts. */ |
f6f0e17b NC |
296 | static inline dwarf_signed_vma |
297 | read_sleb128 (unsigned char * data, | |
298 | unsigned int * length_return, | |
299 | const unsigned char * const end) | |
300 | { | |
301 | return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end); | |
302 | } | |
303 | ||
304 | static inline dwarf_vma | |
305 | read_uleb128 (unsigned char * data, | |
306 | unsigned int * length_return, | |
307 | const unsigned char * const end) | |
467c65bc | 308 | { |
f6f0e17b | 309 | return read_leb128 (data, length_return, FALSE, end); |
467c65bc NC |
310 | } |
311 | ||
0c588247 NC |
312 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
313 | do \ | |
314 | { \ | |
e39462cb | 315 | int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \ |
0c588247 NC |
316 | unsigned int amount = (AMOUNT); \ |
317 | if (((PTR) + amount) >= (END)) \ | |
318 | { \ | |
319 | if ((PTR) < (END)) \ | |
320 | amount = (END) - (PTR); \ | |
321 | else \ | |
322 | amount = 0; \ | |
323 | } \ | |
6937bb54 | 324 | if (amount == 0 || amount > 8) \ |
0c588247 | 325 | VAL = 0; \ |
6937bb54 NC |
326 | else \ |
327 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
328 | } \ |
329 | while (0) | |
330 | ||
331 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ | |
332 | do \ | |
333 | { \ | |
334 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
335 | PTR += AMOUNT; \ | |
336 | } \ | |
337 | while (0) | |
338 | ||
339 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ | |
340 | do \ | |
341 | { \ | |
342 | unsigned int amount = (AMOUNT); \ | |
343 | if (((PTR) + amount) >= (END)) \ | |
344 | { \ | |
345 | if ((PTR) < (END)) \ | |
346 | amount = (END) - (PTR); \ | |
347 | else \ | |
348 | amount = 0; \ | |
349 | } \ | |
350 | if (amount) \ | |
351 | VAL = byte_get_signed ((PTR), amount); \ | |
352 | else \ | |
353 | VAL = 0; \ | |
354 | } \ | |
355 | while (0) | |
356 | ||
357 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ | |
358 | do \ | |
359 | { \ | |
360 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
361 | PTR += AMOUNT; \ | |
362 | } \ | |
363 | while (0) | |
364 | ||
365 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
366 | do \ | |
367 | { \ | |
87bc83b3 | 368 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
369 | { \ |
370 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
371 | } \ | |
372 | else \ | |
373 | { \ | |
0c588247 NC |
374 | * (LOW) = * (HIGH) = 0; \ |
375 | } \ | |
376 | } \ | |
377 | while (0) | |
378 | ||
19e6b90e L |
379 | typedef struct State_Machine_Registers |
380 | { | |
467c65bc | 381 | dwarf_vma address; |
19e6b90e L |
382 | unsigned int file; |
383 | unsigned int line; | |
384 | unsigned int column; | |
385 | int is_stmt; | |
386 | int basic_block; | |
a233b20c JJ |
387 | unsigned char op_index; |
388 | unsigned char end_sequence; | |
19e6b90e L |
389 | /* This variable hold the number of the last entry seen |
390 | in the File Table. */ | |
391 | unsigned int last_file_entry; | |
392 | } SMR; | |
393 | ||
394 | static SMR state_machine_regs; | |
395 | ||
396 | static void | |
397 | reset_state_machine (int is_stmt) | |
398 | { | |
399 | state_machine_regs.address = 0; | |
a233b20c | 400 | state_machine_regs.op_index = 0; |
19e6b90e L |
401 | state_machine_regs.file = 1; |
402 | state_machine_regs.line = 1; | |
403 | state_machine_regs.column = 0; | |
404 | state_machine_regs.is_stmt = is_stmt; | |
405 | state_machine_regs.basic_block = 0; | |
406 | state_machine_regs.end_sequence = 0; | |
407 | state_machine_regs.last_file_entry = 0; | |
408 | } | |
409 | ||
410 | /* Handled an extend line op. | |
411 | Returns the number of bytes read. */ | |
412 | ||
413 | static int | |
f6f0e17b NC |
414 | process_extended_line_op (unsigned char * data, |
415 | int is_stmt, | |
416 | unsigned char * end) | |
19e6b90e L |
417 | { |
418 | unsigned char op_code; | |
419 | unsigned int bytes_read; | |
420 | unsigned int len; | |
421 | unsigned char *name; | |
143a3db0 | 422 | unsigned char *orig_data = data; |
f6f0e17b | 423 | dwarf_vma adr; |
19e6b90e | 424 | |
f6f0e17b | 425 | len = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
426 | data += bytes_read; |
427 | ||
e44c58ce | 428 | if (len == 0 || data == end || len > (uintptr_t) (end - data)) |
19e6b90e | 429 | { |
f41e4712 | 430 | warn (_("Badly formed extended line op encountered!\n")); |
19e6b90e L |
431 | return bytes_read; |
432 | } | |
433 | ||
434 | len += bytes_read; | |
435 | op_code = *data++; | |
436 | ||
437 | printf (_(" Extended opcode %d: "), op_code); | |
438 | ||
439 | switch (op_code) | |
440 | { | |
441 | case DW_LNE_end_sequence: | |
442 | printf (_("End of Sequence\n\n")); | |
443 | reset_state_machine (is_stmt); | |
444 | break; | |
445 | ||
446 | case DW_LNE_set_address: | |
6937bb54 NC |
447 | /* PR 17512: file: 002-100480-0.004. */ |
448 | if (len - bytes_read - 1 > 8) | |
449 | warn (_("Length (%d) of DW_LNE_set_address op is too long\n"), | |
450 | len - bytes_read - 1); | |
0c588247 | 451 | SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end); |
47704ddf | 452 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 453 | state_machine_regs.address = adr; |
a233b20c | 454 | state_machine_regs.op_index = 0; |
19e6b90e L |
455 | break; |
456 | ||
457 | case DW_LNE_define_file: | |
143a3db0 | 458 | printf (_("define new File Table entry\n")); |
19e6b90e | 459 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 460 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 461 | |
19e6b90e | 462 | name = data; |
0c588247 | 463 | data += strnlen ((char *) data, end - data) + 1; |
f6f0e17b | 464 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
19e6b90e | 465 | data += bytes_read; |
f6f0e17b | 466 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
19e6b90e | 467 | data += bytes_read; |
f6f0e17b | 468 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
143a3db0 | 469 | data += bytes_read; |
f6f0e17b NC |
470 | printf ("%s\n\n", name); |
471 | ||
472 | if (((unsigned int) (data - orig_data) != len) || data == end) | |
473 | warn (_("DW_LNE_define_file: Bad opcode length\n")); | |
19e6b90e L |
474 | break; |
475 | ||
ed4a4bdf | 476 | case DW_LNE_set_discriminator: |
47704ddf | 477 | printf (_("set Discriminator to %s\n"), |
f6f0e17b | 478 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
ed4a4bdf CC |
479 | break; |
480 | ||
e2a0d921 NC |
481 | /* HP extensions. */ |
482 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 483 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
484 | break; |
485 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 486 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
487 | break; |
488 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 489 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
490 | break; |
491 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 492 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
493 | break; |
494 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 495 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
496 | break; |
497 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 498 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
499 | break; |
500 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 501 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
502 | break; |
503 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 504 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
505 | break; |
506 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 507 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
508 | break; |
509 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 510 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 511 | break; |
43294ab7 TG |
512 | case DW_LNE_HP_source_file_correlation: |
513 | { | |
514 | unsigned char *edata = data + len - bytes_read - 1; | |
515 | ||
516 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
517 | ||
518 | while (data < edata) | |
519 | { | |
520 | unsigned int opc; | |
521 | ||
f6f0e17b | 522 | opc = read_uleb128 (data, & bytes_read, edata); |
43294ab7 TG |
523 | data += bytes_read; |
524 | ||
525 | switch (opc) | |
526 | { | |
527 | case DW_LNE_HP_SFC_formfeed: | |
528 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
529 | break; | |
530 | case DW_LNE_HP_SFC_set_listing_line: | |
531 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", | |
532 | dwarf_vmatoa ("u", | |
f6f0e17b | 533 | read_uleb128 (data, & bytes_read, edata))); |
43294ab7 TG |
534 | data += bytes_read; |
535 | break; | |
536 | case DW_LNE_HP_SFC_associate: | |
537 | printf (" DW_LNE_HP_SFC_associate "); | |
9cf03b7e | 538 | printf ("(%s", |
43294ab7 | 539 | dwarf_vmatoa ("u", |
f6f0e17b | 540 | read_uleb128 (data, & bytes_read, edata))); |
43294ab7 | 541 | data += bytes_read; |
9cf03b7e | 542 | printf (",%s", |
43294ab7 | 543 | dwarf_vmatoa ("u", |
f6f0e17b | 544 | read_uleb128 (data, & bytes_read, edata))); |
43294ab7 | 545 | data += bytes_read; |
9cf03b7e | 546 | printf (",%s)\n", |
43294ab7 | 547 | dwarf_vmatoa ("u", |
f6f0e17b | 548 | read_uleb128 (data, & bytes_read, edata))); |
43294ab7 TG |
549 | data += bytes_read; |
550 | break; | |
551 | default: | |
9cf03b7e | 552 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); |
43294ab7 TG |
553 | data = edata; |
554 | break; | |
555 | } | |
556 | } | |
557 | } | |
558 | break; | |
cecf136e | 559 | |
19e6b90e | 560 | default: |
7e665af3 TG |
561 | { |
562 | unsigned int rlen = len - bytes_read - 1; | |
563 | ||
564 | if (op_code >= DW_LNE_lo_user | |
565 | /* The test against DW_LNW_hi_user is redundant due to | |
566 | the limited range of the unsigned char data type used | |
567 | for op_code. */ | |
568 | /*&& op_code <= DW_LNE_hi_user*/) | |
569 | printf (_("user defined: ")); | |
570 | else | |
571 | printf (_("UNKNOWN: ")); | |
572 | printf (_("length %d ["), rlen); | |
573 | for (; rlen; rlen--) | |
574 | printf (" %02x", *data++); | |
575 | printf ("]\n"); | |
576 | } | |
19e6b90e L |
577 | break; |
578 | } | |
579 | ||
580 | return len; | |
581 | } | |
582 | ||
0c588247 | 583 | static const unsigned char * |
467c65bc | 584 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
585 | { |
586 | struct dwarf_section *section = &debug_displays [str].section; | |
587 | ||
588 | if (section->start == NULL) | |
0c588247 | 589 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e L |
590 | |
591 | if (offset > section->size) | |
592 | { | |
467c65bc NC |
593 | warn (_("DW_FORM_strp offset too big: %s\n"), |
594 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 595 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
596 | } |
597 | ||
0c588247 | 598 | return (const unsigned char *) section->start + offset; |
19e6b90e L |
599 | } |
600 | ||
4723351a | 601 | static const char * |
341f9135 CC |
602 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
603 | dwarf_vma offset_size, int dwo) | |
4723351a CC |
604 | { |
605 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
606 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
607 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
608 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
609 | dwarf_vma index_offset = idx * offset_size; | |
610 | dwarf_vma str_offset; | |
611 | ||
612 | if (index_section->start == NULL) | |
613 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
614 | : _("<no .debug_str_offsets section>")); | |
615 | ||
341f9135 CC |
616 | if (this_set != NULL) |
617 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
4723351a CC |
618 | if (index_offset > index_section->size) |
619 | { | |
620 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), | |
621 | dwarf_vmatoa ("x", index_offset)); | |
622 | return _("<index offset is too big>"); | |
623 | } | |
624 | ||
625 | if (str_section->start == NULL) | |
626 | return (dwo ? _("<no .debug_str.dwo section>") | |
627 | : _("<no .debug_str section>")); | |
628 | ||
629 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
630 | str_offset -= str_section->address; | |
631 | if (str_offset > str_section->size) | |
632 | { | |
633 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
634 | dwarf_vmatoa ("x", str_offset)); | |
635 | return _("<indirect index offset is too big>"); | |
636 | } | |
637 | ||
638 | return (const char *) str_section->start + str_offset; | |
639 | } | |
640 | ||
641 | static const char * | |
642 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
643 | { | |
644 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
645 | ||
646 | if (section->start == NULL) | |
647 | return (_("<no .debug_addr section>")); | |
648 | ||
649 | if (offset + bytes > section->size) | |
650 | { | |
651 | warn (_("Offset into section %s too big: %s\n"), | |
652 | section->name, dwarf_vmatoa ("x", offset)); | |
653 | return "<offset too big>"; | |
654 | } | |
655 | ||
656 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
657 | } | |
658 | ||
659 | ||
19e6b90e L |
660 | /* FIXME: There are better and more efficient ways to handle |
661 | these structures. For now though, I just want something that | |
662 | is simple to implement. */ | |
663 | typedef struct abbrev_attr | |
664 | { | |
665 | unsigned long attribute; | |
666 | unsigned long form; | |
667 | struct abbrev_attr *next; | |
668 | } | |
669 | abbrev_attr; | |
670 | ||
671 | typedef struct abbrev_entry | |
672 | { | |
673 | unsigned long entry; | |
674 | unsigned long tag; | |
675 | int children; | |
676 | struct abbrev_attr *first_attr; | |
677 | struct abbrev_attr *last_attr; | |
678 | struct abbrev_entry *next; | |
679 | } | |
680 | abbrev_entry; | |
681 | ||
682 | static abbrev_entry *first_abbrev = NULL; | |
683 | static abbrev_entry *last_abbrev = NULL; | |
684 | ||
685 | static void | |
686 | free_abbrevs (void) | |
687 | { | |
91d6fa6a | 688 | abbrev_entry *abbrv; |
19e6b90e | 689 | |
91d6fa6a | 690 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 691 | { |
91d6fa6a | 692 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
693 | abbrev_attr *attr; |
694 | ||
91d6fa6a | 695 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 696 | { |
91d6fa6a | 697 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
698 | |
699 | free (attr); | |
91d6fa6a | 700 | attr = next_attr; |
19e6b90e L |
701 | } |
702 | ||
91d6fa6a NC |
703 | free (abbrv); |
704 | abbrv = next_abbrev; | |
19e6b90e L |
705 | } |
706 | ||
707 | last_abbrev = first_abbrev = NULL; | |
708 | } | |
709 | ||
710 | static void | |
711 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
712 | { | |
713 | abbrev_entry *entry; | |
714 | ||
3f5e193b | 715 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
716 | if (entry == NULL) |
717 | /* ugg */ | |
718 | return; | |
719 | ||
720 | entry->entry = number; | |
721 | entry->tag = tag; | |
722 | entry->children = children; | |
723 | entry->first_attr = NULL; | |
724 | entry->last_attr = NULL; | |
725 | entry->next = NULL; | |
726 | ||
727 | if (first_abbrev == NULL) | |
728 | first_abbrev = entry; | |
729 | else | |
730 | last_abbrev->next = entry; | |
731 | ||
732 | last_abbrev = entry; | |
733 | } | |
734 | ||
735 | static void | |
736 | add_abbrev_attr (unsigned long attribute, unsigned long form) | |
737 | { | |
738 | abbrev_attr *attr; | |
739 | ||
3f5e193b | 740 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
741 | if (attr == NULL) |
742 | /* ugg */ | |
743 | return; | |
744 | ||
745 | attr->attribute = attribute; | |
746 | attr->form = form; | |
747 | attr->next = NULL; | |
748 | ||
749 | if (last_abbrev->first_attr == NULL) | |
750 | last_abbrev->first_attr = attr; | |
751 | else | |
752 | last_abbrev->last_attr->next = attr; | |
753 | ||
754 | last_abbrev->last_attr = attr; | |
755 | } | |
756 | ||
757 | /* Processes the (partial) contents of a .debug_abbrev section. | |
758 | Returns NULL if the end of the section was encountered. | |
759 | Returns the address after the last byte read if the end of | |
760 | an abbreviation set was found. */ | |
761 | ||
762 | static unsigned char * | |
763 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
764 | { | |
765 | if (first_abbrev != NULL) | |
766 | return NULL; | |
767 | ||
768 | while (start < end) | |
769 | { | |
770 | unsigned int bytes_read; | |
771 | unsigned long entry; | |
772 | unsigned long tag; | |
773 | unsigned long attribute; | |
774 | int children; | |
775 | ||
f6f0e17b | 776 | entry = read_uleb128 (start, & bytes_read, end); |
19e6b90e L |
777 | start += bytes_read; |
778 | ||
779 | /* A single zero is supposed to end the section according | |
780 | to the standard. If there's more, then signal that to | |
781 | the caller. */ | |
f6f0e17b NC |
782 | if (start == end) |
783 | return NULL; | |
19e6b90e | 784 | if (entry == 0) |
f6f0e17b | 785 | return start; |
19e6b90e | 786 | |
f6f0e17b | 787 | tag = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 788 | start += bytes_read; |
f6f0e17b NC |
789 | if (start == end) |
790 | return NULL; | |
19e6b90e L |
791 | |
792 | children = *start++; | |
793 | ||
794 | add_abbrev (entry, tag, children); | |
795 | ||
796 | do | |
797 | { | |
798 | unsigned long form; | |
799 | ||
f6f0e17b | 800 | attribute = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 801 | start += bytes_read; |
f6f0e17b NC |
802 | if (start == end) |
803 | break; | |
19e6b90e | 804 | |
f6f0e17b | 805 | form = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 806 | start += bytes_read; |
f6f0e17b NC |
807 | if (start == end) |
808 | break; | |
19e6b90e | 809 | |
399c99f7 | 810 | add_abbrev_attr (attribute, form); |
19e6b90e L |
811 | } |
812 | while (attribute != 0); | |
813 | } | |
814 | ||
399c99f7 L |
815 | /* Report the missing single zero which ends the section. */ |
816 | error (_(".debug_abbrev section not zero terminated\n")); | |
817 | ||
19e6b90e L |
818 | return NULL; |
819 | } | |
820 | ||
a19c41a7 | 821 | static const char * |
19e6b90e L |
822 | get_TAG_name (unsigned long tag) |
823 | { | |
b9c361e0 | 824 | const char *name = get_DW_TAG_name ((unsigned int)tag); |
a19c41a7 TT |
825 | |
826 | if (name == NULL) | |
19e6b90e | 827 | { |
a19c41a7 | 828 | static char buffer[100]; |
19e6b90e | 829 | |
a19c41a7 TT |
830 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag); |
831 | return buffer; | |
19e6b90e | 832 | } |
a19c41a7 TT |
833 | |
834 | return name; | |
19e6b90e L |
835 | } |
836 | ||
a19c41a7 | 837 | static const char * |
19e6b90e L |
838 | get_FORM_name (unsigned long form) |
839 | { | |
399c99f7 | 840 | const char *name; |
bf5117e3 | 841 | |
399c99f7 L |
842 | if (form == 0) |
843 | return "DW_FORM value: 0"; | |
a19c41a7 | 844 | |
399c99f7 | 845 | name = get_DW_FORM_name (form); |
a19c41a7 | 846 | if (name == NULL) |
19e6b90e | 847 | { |
a19c41a7 | 848 | static char buffer[100]; |
19e6b90e | 849 | |
a19c41a7 TT |
850 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
851 | return buffer; | |
19e6b90e | 852 | } |
a19c41a7 TT |
853 | |
854 | return name; | |
19e6b90e L |
855 | } |
856 | ||
857 | static unsigned char * | |
0c588247 NC |
858 | display_block (unsigned char *data, |
859 | dwarf_vma length, | |
860 | const unsigned char * const end) | |
19e6b90e | 861 | { |
0c588247 NC |
862 | dwarf_vma maxlen; |
863 | ||
467c65bc | 864 | printf (_(" %s byte block: "), dwarf_vmatoa ("u", length)); |
a1165289 NC |
865 | if (data > end) |
866 | return (unsigned char *) end; | |
19e6b90e | 867 | |
0c588247 NC |
868 | maxlen = (dwarf_vma) (end - data); |
869 | length = length > maxlen ? maxlen : length; | |
870 | ||
19e6b90e L |
871 | while (length --) |
872 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
873 | ||
874 | return data; | |
875 | } | |
876 | ||
877 | static int | |
878 | decode_location_expression (unsigned char * data, | |
879 | unsigned int pointer_size, | |
b7807392 JJ |
880 | unsigned int offset_size, |
881 | int dwarf_version, | |
467c65bc NC |
882 | dwarf_vma length, |
883 | dwarf_vma cu_offset, | |
f1c4cc75 | 884 | struct dwarf_section * section) |
19e6b90e L |
885 | { |
886 | unsigned op; | |
887 | unsigned int bytes_read; | |
467c65bc | 888 | dwarf_vma uvalue; |
0c588247 | 889 | dwarf_signed_vma svalue; |
19e6b90e L |
890 | unsigned char *end = data + length; |
891 | int need_frame_base = 0; | |
892 | ||
893 | while (data < end) | |
894 | { | |
895 | op = *data++; | |
896 | ||
897 | switch (op) | |
898 | { | |
899 | case DW_OP_addr: | |
0c588247 NC |
900 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
901 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
902 | break; |
903 | case DW_OP_deref: | |
904 | printf ("DW_OP_deref"); | |
905 | break; | |
906 | case DW_OP_const1u: | |
0c588247 NC |
907 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
908 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
909 | break; |
910 | case DW_OP_const1s: | |
0c588247 NC |
911 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
912 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
913 | break; |
914 | case DW_OP_const2u: | |
87bc83b3 | 915 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 916 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
917 | break; |
918 | case DW_OP_const2s: | |
0c588247 NC |
919 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
920 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
921 | break; |
922 | case DW_OP_const4u: | |
0c588247 NC |
923 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
924 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
925 | break; |
926 | case DW_OP_const4s: | |
0c588247 NC |
927 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
928 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
929 | break; |
930 | case DW_OP_const8u: | |
0c588247 NC |
931 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
932 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
933 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
934 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
935 | break; |
936 | case DW_OP_const8s: | |
0c588247 NC |
937 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
938 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
939 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
940 | printf ("%ld", (long) svalue); | |
19e6b90e L |
941 | break; |
942 | case DW_OP_constu: | |
467c65bc | 943 | printf ("DW_OP_constu: %s", |
f6f0e17b | 944 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
945 | data += bytes_read; |
946 | break; | |
947 | case DW_OP_consts: | |
467c65bc | 948 | printf ("DW_OP_consts: %s", |
f6f0e17b | 949 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
950 | data += bytes_read; |
951 | break; | |
952 | case DW_OP_dup: | |
953 | printf ("DW_OP_dup"); | |
954 | break; | |
955 | case DW_OP_drop: | |
956 | printf ("DW_OP_drop"); | |
957 | break; | |
958 | case DW_OP_over: | |
959 | printf ("DW_OP_over"); | |
960 | break; | |
961 | case DW_OP_pick: | |
0c588247 NC |
962 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
963 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
964 | break; |
965 | case DW_OP_swap: | |
966 | printf ("DW_OP_swap"); | |
967 | break; | |
968 | case DW_OP_rot: | |
969 | printf ("DW_OP_rot"); | |
970 | break; | |
971 | case DW_OP_xderef: | |
972 | printf ("DW_OP_xderef"); | |
973 | break; | |
974 | case DW_OP_abs: | |
975 | printf ("DW_OP_abs"); | |
976 | break; | |
977 | case DW_OP_and: | |
978 | printf ("DW_OP_and"); | |
979 | break; | |
980 | case DW_OP_div: | |
981 | printf ("DW_OP_div"); | |
982 | break; | |
983 | case DW_OP_minus: | |
984 | printf ("DW_OP_minus"); | |
985 | break; | |
986 | case DW_OP_mod: | |
987 | printf ("DW_OP_mod"); | |
988 | break; | |
989 | case DW_OP_mul: | |
990 | printf ("DW_OP_mul"); | |
991 | break; | |
992 | case DW_OP_neg: | |
993 | printf ("DW_OP_neg"); | |
994 | break; | |
995 | case DW_OP_not: | |
996 | printf ("DW_OP_not"); | |
997 | break; | |
998 | case DW_OP_or: | |
999 | printf ("DW_OP_or"); | |
1000 | break; | |
1001 | case DW_OP_plus: | |
1002 | printf ("DW_OP_plus"); | |
1003 | break; | |
1004 | case DW_OP_plus_uconst: | |
467c65bc | 1005 | printf ("DW_OP_plus_uconst: %s", |
f6f0e17b | 1006 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1007 | data += bytes_read; |
1008 | break; | |
1009 | case DW_OP_shl: | |
1010 | printf ("DW_OP_shl"); | |
1011 | break; | |
1012 | case DW_OP_shr: | |
1013 | printf ("DW_OP_shr"); | |
1014 | break; | |
1015 | case DW_OP_shra: | |
1016 | printf ("DW_OP_shra"); | |
1017 | break; | |
1018 | case DW_OP_xor: | |
1019 | printf ("DW_OP_xor"); | |
1020 | break; | |
1021 | case DW_OP_bra: | |
0c588247 NC |
1022 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1023 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1024 | break; |
1025 | case DW_OP_eq: | |
1026 | printf ("DW_OP_eq"); | |
1027 | break; | |
1028 | case DW_OP_ge: | |
1029 | printf ("DW_OP_ge"); | |
1030 | break; | |
1031 | case DW_OP_gt: | |
1032 | printf ("DW_OP_gt"); | |
1033 | break; | |
1034 | case DW_OP_le: | |
1035 | printf ("DW_OP_le"); | |
1036 | break; | |
1037 | case DW_OP_lt: | |
1038 | printf ("DW_OP_lt"); | |
1039 | break; | |
1040 | case DW_OP_ne: | |
1041 | printf ("DW_OP_ne"); | |
1042 | break; | |
1043 | case DW_OP_skip: | |
0c588247 NC |
1044 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1045 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1046 | break; |
1047 | ||
1048 | case DW_OP_lit0: | |
1049 | case DW_OP_lit1: | |
1050 | case DW_OP_lit2: | |
1051 | case DW_OP_lit3: | |
1052 | case DW_OP_lit4: | |
1053 | case DW_OP_lit5: | |
1054 | case DW_OP_lit6: | |
1055 | case DW_OP_lit7: | |
1056 | case DW_OP_lit8: | |
1057 | case DW_OP_lit9: | |
1058 | case DW_OP_lit10: | |
1059 | case DW_OP_lit11: | |
1060 | case DW_OP_lit12: | |
1061 | case DW_OP_lit13: | |
1062 | case DW_OP_lit14: | |
1063 | case DW_OP_lit15: | |
1064 | case DW_OP_lit16: | |
1065 | case DW_OP_lit17: | |
1066 | case DW_OP_lit18: | |
1067 | case DW_OP_lit19: | |
1068 | case DW_OP_lit20: | |
1069 | case DW_OP_lit21: | |
1070 | case DW_OP_lit22: | |
1071 | case DW_OP_lit23: | |
1072 | case DW_OP_lit24: | |
1073 | case DW_OP_lit25: | |
1074 | case DW_OP_lit26: | |
1075 | case DW_OP_lit27: | |
1076 | case DW_OP_lit28: | |
1077 | case DW_OP_lit29: | |
1078 | case DW_OP_lit30: | |
1079 | case DW_OP_lit31: | |
1080 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1081 | break; | |
1082 | ||
1083 | case DW_OP_reg0: | |
1084 | case DW_OP_reg1: | |
1085 | case DW_OP_reg2: | |
1086 | case DW_OP_reg3: | |
1087 | case DW_OP_reg4: | |
1088 | case DW_OP_reg5: | |
1089 | case DW_OP_reg6: | |
1090 | case DW_OP_reg7: | |
1091 | case DW_OP_reg8: | |
1092 | case DW_OP_reg9: | |
1093 | case DW_OP_reg10: | |
1094 | case DW_OP_reg11: | |
1095 | case DW_OP_reg12: | |
1096 | case DW_OP_reg13: | |
1097 | case DW_OP_reg14: | |
1098 | case DW_OP_reg15: | |
1099 | case DW_OP_reg16: | |
1100 | case DW_OP_reg17: | |
1101 | case DW_OP_reg18: | |
1102 | case DW_OP_reg19: | |
1103 | case DW_OP_reg20: | |
1104 | case DW_OP_reg21: | |
1105 | case DW_OP_reg22: | |
1106 | case DW_OP_reg23: | |
1107 | case DW_OP_reg24: | |
1108 | case DW_OP_reg25: | |
1109 | case DW_OP_reg26: | |
1110 | case DW_OP_reg27: | |
1111 | case DW_OP_reg28: | |
1112 | case DW_OP_reg29: | |
1113 | case DW_OP_reg30: | |
1114 | case DW_OP_reg31: | |
18464d4d JK |
1115 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1116 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1117 | break; |
1118 | ||
1119 | case DW_OP_breg0: | |
1120 | case DW_OP_breg1: | |
1121 | case DW_OP_breg2: | |
1122 | case DW_OP_breg3: | |
1123 | case DW_OP_breg4: | |
1124 | case DW_OP_breg5: | |
1125 | case DW_OP_breg6: | |
1126 | case DW_OP_breg7: | |
1127 | case DW_OP_breg8: | |
1128 | case DW_OP_breg9: | |
1129 | case DW_OP_breg10: | |
1130 | case DW_OP_breg11: | |
1131 | case DW_OP_breg12: | |
1132 | case DW_OP_breg13: | |
1133 | case DW_OP_breg14: | |
1134 | case DW_OP_breg15: | |
1135 | case DW_OP_breg16: | |
1136 | case DW_OP_breg17: | |
1137 | case DW_OP_breg18: | |
1138 | case DW_OP_breg19: | |
1139 | case DW_OP_breg20: | |
1140 | case DW_OP_breg21: | |
1141 | case DW_OP_breg22: | |
1142 | case DW_OP_breg23: | |
1143 | case DW_OP_breg24: | |
1144 | case DW_OP_breg25: | |
1145 | case DW_OP_breg26: | |
1146 | case DW_OP_breg27: | |
1147 | case DW_OP_breg28: | |
1148 | case DW_OP_breg29: | |
1149 | case DW_OP_breg30: | |
1150 | case DW_OP_breg31: | |
467c65bc | 1151 | printf ("DW_OP_breg%d (%s): %s", |
47704ddf | 1152 | op - DW_OP_breg0, |
18464d4d | 1153 | regname (op - DW_OP_breg0, 1), |
f6f0e17b | 1154 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1155 | data += bytes_read; |
1156 | break; | |
1157 | ||
1158 | case DW_OP_regx: | |
f6f0e17b | 1159 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1160 | data += bytes_read; |
467c65bc NC |
1161 | printf ("DW_OP_regx: %s (%s)", |
1162 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1163 | break; |
1164 | case DW_OP_fbreg: | |
1165 | need_frame_base = 1; | |
467c65bc | 1166 | printf ("DW_OP_fbreg: %s", |
f6f0e17b | 1167 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1168 | data += bytes_read; |
1169 | break; | |
1170 | case DW_OP_bregx: | |
f6f0e17b | 1171 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1172 | data += bytes_read; |
467c65bc NC |
1173 | printf ("DW_OP_bregx: %s (%s) %s", |
1174 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
f6f0e17b | 1175 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1176 | data += bytes_read; |
1177 | break; | |
1178 | case DW_OP_piece: | |
467c65bc | 1179 | printf ("DW_OP_piece: %s", |
f6f0e17b | 1180 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1181 | data += bytes_read; |
1182 | break; | |
1183 | case DW_OP_deref_size: | |
0c588247 NC |
1184 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1185 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1186 | break; |
1187 | case DW_OP_xderef_size: | |
0c588247 NC |
1188 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1189 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1190 | break; |
1191 | case DW_OP_nop: | |
1192 | printf ("DW_OP_nop"); | |
1193 | break; | |
1194 | ||
1195 | /* DWARF 3 extensions. */ | |
1196 | case DW_OP_push_object_address: | |
1197 | printf ("DW_OP_push_object_address"); | |
1198 | break; | |
1199 | case DW_OP_call2: | |
1200 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1201 | this ought to be an 8-byte wide computation. */ | |
0c588247 | 1202 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1203 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1204 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1205 | break; |
1206 | case DW_OP_call4: | |
1207 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1208 | this ought to be an 8-byte wide computation. */ | |
0c588247 | 1209 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1210 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1211 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1212 | break; |
1213 | case DW_OP_call_ref: | |
e2a0d921 NC |
1214 | /* XXX: Strictly speaking for 64-bit DWARF3 files |
1215 | this ought to be an 8-byte wide computation. */ | |
b7807392 JJ |
1216 | if (dwarf_version == -1) |
1217 | { | |
1218 | printf (_("(DW_OP_call_ref in frame info)")); | |
1219 | /* No way to tell where the next op is, so just bail. */ | |
1220 | return need_frame_base; | |
1221 | } | |
1222 | if (dwarf_version == 2) | |
1223 | { | |
0c588247 | 1224 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1225 | } |
1226 | else | |
1227 | { | |
0c588247 | 1228 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1229 | } |
0c588247 | 1230 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1231 | break; |
a87b0a59 NS |
1232 | case DW_OP_form_tls_address: |
1233 | printf ("DW_OP_form_tls_address"); | |
1234 | break; | |
e2a0d921 NC |
1235 | case DW_OP_call_frame_cfa: |
1236 | printf ("DW_OP_call_frame_cfa"); | |
1237 | break; | |
1238 | case DW_OP_bit_piece: | |
1239 | printf ("DW_OP_bit_piece: "); | |
9cf03b7e | 1240 | printf (_("size: %s "), |
f6f0e17b | 1241 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 | 1242 | data += bytes_read; |
9cf03b7e | 1243 | printf (_("offset: %s "), |
f6f0e17b | 1244 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 NC |
1245 | data += bytes_read; |
1246 | break; | |
19e6b90e | 1247 | |
3244e8f5 JJ |
1248 | /* DWARF 4 extensions. */ |
1249 | case DW_OP_stack_value: | |
1250 | printf ("DW_OP_stack_value"); | |
1251 | break; | |
1252 | ||
1253 | case DW_OP_implicit_value: | |
1254 | printf ("DW_OP_implicit_value"); | |
f6f0e17b | 1255 | uvalue = read_uleb128 (data, &bytes_read, end); |
3244e8f5 | 1256 | data += bytes_read; |
6937bb54 | 1257 | data = display_block (data, uvalue, end); |
3244e8f5 JJ |
1258 | break; |
1259 | ||
19e6b90e L |
1260 | /* GNU extensions. */ |
1261 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1262 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1263 | break; |
1264 | case DW_OP_GNU_uninit: | |
1265 | printf ("DW_OP_GNU_uninit"); | |
1266 | /* FIXME: Is there data associated with this OP ? */ | |
1267 | break; | |
f1c4cc75 RH |
1268 | case DW_OP_GNU_encoded_addr: |
1269 | { | |
6937bb54 | 1270 | int encoding = 0; |
f1c4cc75 | 1271 | dwarf_vma addr; |
467c65bc | 1272 | |
6937bb54 NC |
1273 | if (data < end) |
1274 | encoding = *data++; | |
041830e0 | 1275 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1276 | |
1277 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1278 | print_dwarf_vma (addr, pointer_size); | |
1279 | } | |
1280 | break; | |
b7807392 JJ |
1281 | case DW_OP_GNU_implicit_pointer: |
1282 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1283 | this ought to be an 8-byte wide computation. */ | |
1284 | if (dwarf_version == -1) | |
1285 | { | |
1286 | printf (_("(DW_OP_GNU_implicit_pointer in frame info)")); | |
1287 | /* No way to tell where the next op is, so just bail. */ | |
1288 | return need_frame_base; | |
1289 | } | |
1290 | if (dwarf_version == 2) | |
1291 | { | |
0c588247 | 1292 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1293 | } |
1294 | else | |
1295 | { | |
0c588247 | 1296 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1297 | } |
0c588247 NC |
1298 | printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s", |
1299 | dwarf_vmatoa ("x", uvalue), | |
1300 | dwarf_vmatoa ("d", read_sleb128 (data, | |
1301 | &bytes_read, end))); | |
1302 | data += bytes_read; | |
b7807392 | 1303 | break; |
0892011d | 1304 | case DW_OP_GNU_entry_value: |
f6f0e17b | 1305 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1306 | data += bytes_read; |
058037d3 NC |
1307 | /* PR 17531: file: 0cc9cd00. */ |
1308 | if (uvalue > (dwarf_vma) (end - data)) | |
1309 | uvalue = end - data; | |
0892011d JJ |
1310 | printf ("DW_OP_GNU_entry_value: ("); |
1311 | if (decode_location_expression (data, pointer_size, offset_size, | |
1312 | dwarf_version, uvalue, | |
1313 | cu_offset, section)) | |
1314 | need_frame_base = 1; | |
1315 | putchar (')'); | |
1316 | data += uvalue; | |
6937bb54 NC |
1317 | if (data > end) |
1318 | data = end; | |
0892011d JJ |
1319 | break; |
1320 | case DW_OP_GNU_const_type: | |
f6f0e17b | 1321 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1322 | data += bytes_read; |
1323 | printf ("DW_OP_GNU_const_type: <0x%s> ", | |
1324 | dwarf_vmatoa ("x", cu_offset + uvalue)); | |
0c588247 | 1325 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
6937bb54 | 1326 | data = display_block (data, uvalue, end); |
0892011d JJ |
1327 | break; |
1328 | case DW_OP_GNU_regval_type: | |
f6f0e17b | 1329 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1330 | data += bytes_read; |
1331 | printf ("DW_OP_GNU_regval_type: %s (%s)", | |
1332 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
f6f0e17b | 1333 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1334 | data += bytes_read; |
1335 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1336 | break; | |
1337 | case DW_OP_GNU_deref_type: | |
0c588247 NC |
1338 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1339 | printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue); | |
f6f0e17b | 1340 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1341 | data += bytes_read; |
1342 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1343 | break; | |
1344 | case DW_OP_GNU_convert: | |
f6f0e17b | 1345 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1346 | data += bytes_read; |
1347 | printf ("DW_OP_GNU_convert <0x%s>", | |
f8b999f9 | 1348 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d JJ |
1349 | break; |
1350 | case DW_OP_GNU_reinterpret: | |
f6f0e17b | 1351 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1352 | data += bytes_read; |
1353 | printf ("DW_OP_GNU_reinterpret <0x%s>", | |
f8b999f9 JJ |
1354 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1355 | break; | |
1356 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1357 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1358 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1359 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1360 | break; |
4723351a | 1361 | case DW_OP_GNU_addr_index: |
f6f0e17b | 1362 | uvalue = read_uleb128 (data, &bytes_read, end); |
4723351a CC |
1363 | data += bytes_read; |
1364 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1365 | break; | |
aae628c1 | 1366 | case DW_OP_GNU_const_index: |
f6f0e17b | 1367 | uvalue = read_uleb128 (data, &bytes_read, end); |
aae628c1 CC |
1368 | data += bytes_read; |
1369 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1370 | break; | |
e2a0d921 NC |
1371 | |
1372 | /* HP extensions. */ | |
1373 | case DW_OP_HP_is_value: | |
1374 | printf ("DW_OP_HP_is_value"); | |
1375 | /* FIXME: Is there data associated with this OP ? */ | |
1376 | break; | |
1377 | case DW_OP_HP_fltconst4: | |
1378 | printf ("DW_OP_HP_fltconst4"); | |
1379 | /* FIXME: Is there data associated with this OP ? */ | |
1380 | break; | |
1381 | case DW_OP_HP_fltconst8: | |
1382 | printf ("DW_OP_HP_fltconst8"); | |
1383 | /* FIXME: Is there data associated with this OP ? */ | |
1384 | break; | |
1385 | case DW_OP_HP_mod_range: | |
1386 | printf ("DW_OP_HP_mod_range"); | |
1387 | /* FIXME: Is there data associated with this OP ? */ | |
1388 | break; | |
1389 | case DW_OP_HP_unmod_range: | |
1390 | printf ("DW_OP_HP_unmod_range"); | |
1391 | /* FIXME: Is there data associated with this OP ? */ | |
1392 | break; | |
1393 | case DW_OP_HP_tls: | |
1394 | printf ("DW_OP_HP_tls"); | |
1395 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1396 | break; |
1397 | ||
35d60fe4 NC |
1398 | /* PGI (STMicroelectronics) extensions. */ |
1399 | case DW_OP_PGI_omp_thread_num: | |
1400 | /* Pushes the thread number for the current thread as it would be | |
1401 | returned by the standard OpenMP library function: | |
1402 | omp_get_thread_num(). The "current thread" is the thread for | |
1403 | which the expression is being evaluated. */ | |
1404 | printf ("DW_OP_PGI_omp_thread_num"); | |
1405 | break; | |
1406 | ||
19e6b90e L |
1407 | default: |
1408 | if (op >= DW_OP_lo_user | |
1409 | && op <= DW_OP_hi_user) | |
1410 | printf (_("(User defined location op)")); | |
1411 | else | |
1412 | printf (_("(Unknown location op)")); | |
1413 | /* No way to tell where the next op is, so just bail. */ | |
1414 | return need_frame_base; | |
1415 | } | |
1416 | ||
1417 | /* Separate the ops. */ | |
1418 | if (data < end) | |
1419 | printf ("; "); | |
1420 | } | |
1421 | ||
1422 | return need_frame_base; | |
1423 | } | |
1424 | ||
341f9135 CC |
1425 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1426 | This is used for DWARF package files. */ | |
1427 | ||
1428 | static struct cu_tu_set * | |
1429 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1430 | { | |
1431 | struct cu_tu_set *p; | |
1432 | unsigned int nsets; | |
1433 | unsigned int dw_sect; | |
1434 | ||
1435 | if (do_types) | |
1436 | { | |
1437 | p = tu_sets; | |
1438 | nsets = tu_count; | |
1439 | dw_sect = DW_SECT_TYPES; | |
1440 | } | |
1441 | else | |
1442 | { | |
1443 | p = cu_sets; | |
1444 | nsets = cu_count; | |
1445 | dw_sect = DW_SECT_INFO; | |
1446 | } | |
1447 | while (nsets > 0) | |
1448 | { | |
1449 | if (p->section_offsets [dw_sect] == cu_offset) | |
1450 | return p; | |
1451 | p++; | |
1452 | nsets--; | |
1453 | } | |
1454 | return NULL; | |
1455 | } | |
1456 | ||
a69c4772 NC |
1457 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1458 | static void | |
1459 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1460 | { | |
1461 | dwarf_vma tmp = * low_bits; | |
1462 | ||
1463 | tmp += inc; | |
1464 | ||
1465 | /* FIXME: There is probably a better way of handling this: | |
1466 | ||
1467 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1468 | type. Plus regardless of its size LOW_BITS is meant to | |
1469 | only hold 32-bits, so if there is overflow or wrap around | |
1470 | we must propagate into HIGH_BITS. */ | |
1471 | if (tmp < * low_bits) | |
1472 | { | |
1473 | ++ * high_bits; | |
1474 | } | |
1475 | else if (sizeof (tmp) > 8 | |
1476 | && (tmp >> 31) > 1) | |
1477 | { | |
1478 | ++ * high_bits; | |
1479 | tmp &= 0xFFFFFFFF; | |
1480 | } | |
1481 | ||
1482 | * low_bits = tmp; | |
1483 | } | |
1484 | ||
19e6b90e | 1485 | static unsigned char * |
6e3d6dc1 NC |
1486 | read_and_display_attr_value (unsigned long attribute, |
1487 | unsigned long form, | |
ec4d4525 | 1488 | unsigned char * data, |
f6f0e17b | 1489 | unsigned char * end, |
467c65bc NC |
1490 | dwarf_vma cu_offset, |
1491 | dwarf_vma pointer_size, | |
1492 | dwarf_vma offset_size, | |
6e3d6dc1 NC |
1493 | int dwarf_version, |
1494 | debug_info * debug_info_p, | |
1495 | int do_loc, | |
341f9135 CC |
1496 | struct dwarf_section * section, |
1497 | struct cu_tu_set * this_set) | |
19e6b90e | 1498 | { |
467c65bc | 1499 | dwarf_vma uvalue = 0; |
19e6b90e | 1500 | unsigned char *block_start = NULL; |
6e3d6dc1 | 1501 | unsigned char * orig_data = data; |
19e6b90e L |
1502 | unsigned int bytes_read; |
1503 | ||
f41e4712 | 1504 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 1505 | { |
f41e4712 | 1506 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
1507 | return data; |
1508 | } | |
1509 | ||
19e6b90e L |
1510 | switch (form) |
1511 | { | |
1512 | default: | |
1513 | break; | |
1514 | ||
1515 | case DW_FORM_ref_addr: | |
1516 | if (dwarf_version == 2) | |
0c588247 | 1517 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
932fd279 | 1518 | else if (dwarf_version == 3 || dwarf_version == 4) |
0c588247 | 1519 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 1520 | else |
467c65bc NC |
1521 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
1522 | ||
19e6b90e L |
1523 | break; |
1524 | ||
1525 | case DW_FORM_addr: | |
0c588247 | 1526 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
1527 | break; |
1528 | ||
1529 | case DW_FORM_strp: | |
932fd279 | 1530 | case DW_FORM_sec_offset: |
a081f3cd JJ |
1531 | case DW_FORM_GNU_ref_alt: |
1532 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 1533 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
1534 | break; |
1535 | ||
932fd279 JJ |
1536 | case DW_FORM_flag_present: |
1537 | uvalue = 1; | |
1538 | break; | |
1539 | ||
19e6b90e L |
1540 | case DW_FORM_ref1: |
1541 | case DW_FORM_flag: | |
1542 | case DW_FORM_data1: | |
0c588247 | 1543 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
1544 | break; |
1545 | ||
1546 | case DW_FORM_ref2: | |
1547 | case DW_FORM_data2: | |
0c588247 | 1548 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
1549 | break; |
1550 | ||
1551 | case DW_FORM_ref4: | |
1552 | case DW_FORM_data4: | |
0c588247 | 1553 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
1554 | break; |
1555 | ||
1556 | case DW_FORM_sdata: | |
f6f0e17b | 1557 | uvalue = read_sleb128 (data, & bytes_read, end); |
19e6b90e L |
1558 | data += bytes_read; |
1559 | break; | |
1560 | ||
4723351a | 1561 | case DW_FORM_GNU_str_index: |
f6f0e17b | 1562 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1563 | data += bytes_read; |
1564 | break; | |
1565 | ||
19e6b90e L |
1566 | case DW_FORM_ref_udata: |
1567 | case DW_FORM_udata: | |
f6f0e17b | 1568 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1569 | data += bytes_read; |
1570 | break; | |
1571 | ||
1572 | case DW_FORM_indirect: | |
f6f0e17b | 1573 | form = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1574 | data += bytes_read; |
1575 | if (!do_loc) | |
1576 | printf (" %s", get_FORM_name (form)); | |
f6f0e17b | 1577 | return read_and_display_attr_value (attribute, form, data, end, |
19e6b90e L |
1578 | cu_offset, pointer_size, |
1579 | offset_size, dwarf_version, | |
ec4d4525 | 1580 | debug_info_p, do_loc, |
341f9135 | 1581 | section, this_set); |
4723351a | 1582 | case DW_FORM_GNU_addr_index: |
f6f0e17b | 1583 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1584 | data += bytes_read; |
1585 | break; | |
19e6b90e L |
1586 | } |
1587 | ||
1588 | switch (form) | |
1589 | { | |
1590 | case DW_FORM_ref_addr: | |
1591 | if (!do_loc) | |
467c65bc | 1592 | printf (" <0x%s>", dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
1593 | break; |
1594 | ||
a081f3cd JJ |
1595 | case DW_FORM_GNU_ref_alt: |
1596 | if (!do_loc) | |
1597 | printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue)); | |
1598 | break; | |
1599 | ||
19e6b90e L |
1600 | case DW_FORM_ref1: |
1601 | case DW_FORM_ref2: | |
1602 | case DW_FORM_ref4: | |
1603 | case DW_FORM_ref_udata: | |
1604 | if (!do_loc) | |
467c65bc | 1605 | printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
1606 | break; |
1607 | ||
1608 | case DW_FORM_data4: | |
1609 | case DW_FORM_addr: | |
932fd279 | 1610 | case DW_FORM_sec_offset: |
19e6b90e | 1611 | if (!do_loc) |
467c65bc | 1612 | printf (" 0x%s", dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
1613 | break; |
1614 | ||
932fd279 | 1615 | case DW_FORM_flag_present: |
19e6b90e L |
1616 | case DW_FORM_flag: |
1617 | case DW_FORM_data1: | |
1618 | case DW_FORM_data2: | |
1619 | case DW_FORM_sdata: | |
1620 | case DW_FORM_udata: | |
1621 | if (!do_loc) | |
467c65bc | 1622 | printf (" %s", dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
1623 | break; |
1624 | ||
1625 | case DW_FORM_ref8: | |
1626 | case DW_FORM_data8: | |
2bc8690c | 1627 | if (!do_loc) |
19e6b90e | 1628 | { |
74bc6052 | 1629 | dwarf_vma high_bits; |
a69c4772 | 1630 | dwarf_vma utmp; |
74bc6052 CC |
1631 | char buf[64]; |
1632 | ||
0c588247 | 1633 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
1634 | utmp = uvalue; |
1635 | if (form == DW_FORM_ref8) | |
1636 | add64 (& high_bits, & utmp, cu_offset); | |
74bc6052 | 1637 | printf (" 0x%s", |
a69c4772 | 1638 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 1639 | } |
0c588247 | 1640 | |
19e6b90e L |
1641 | if ((do_loc || do_debug_loc || do_debug_ranges) |
1642 | && num_debug_info_entries == 0) | |
1643 | { | |
1644 | if (sizeof (uvalue) == 8) | |
0c588247 | 1645 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 1646 | else |
467c65bc | 1647 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 1648 | } |
0c588247 | 1649 | |
19e6b90e L |
1650 | data += 8; |
1651 | break; | |
1652 | ||
1653 | case DW_FORM_string: | |
1654 | if (!do_loc) | |
2bdc3eca | 1655 | printf (" %.*s", (int) (end - data), data); |
0c588247 | 1656 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
1657 | break; |
1658 | ||
1659 | case DW_FORM_block: | |
932fd279 | 1660 | case DW_FORM_exprloc: |
f6f0e17b | 1661 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e | 1662 | block_start = data + bytes_read; |
a1165289 NC |
1663 | if (block_start >= end) |
1664 | { | |
1665 | warn (_("Block ends prematurely\n")); | |
1666 | uvalue = 0; | |
1667 | block_start = end; | |
1668 | } | |
f3853b34 NC |
1669 | /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with |
1670 | gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute | |
1671 | block_start + uvalue here. */ | |
1672 | data = block_start + uvalue; | |
f41e4712 | 1673 | /* PR 17512: file: 008-103549-0.001:0.1. */ |
f3853b34 | 1674 | if (block_start + uvalue > end || data < block_start) |
f41e4712 NC |
1675 | { |
1676 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1677 | uvalue = end - block_start; | |
1678 | } | |
19e6b90e L |
1679 | if (do_loc) |
1680 | data = block_start + uvalue; | |
1681 | else | |
0c588247 | 1682 | data = display_block (block_start, uvalue, end); |
19e6b90e L |
1683 | break; |
1684 | ||
1685 | case DW_FORM_block1: | |
0c588247 | 1686 | SAFE_BYTE_GET (uvalue, data, 1, end); |
19e6b90e | 1687 | block_start = data + 1; |
a1165289 NC |
1688 | if (block_start >= end) |
1689 | { | |
1690 | warn (_("Block ends prematurely\n")); | |
1691 | uvalue = 0; | |
1692 | block_start = end; | |
1693 | } | |
f3853b34 NC |
1694 | data = block_start + uvalue; |
1695 | if (block_start + uvalue > end || data < block_start) | |
f41e4712 NC |
1696 | { |
1697 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1698 | uvalue = end - block_start; | |
1699 | } | |
19e6b90e L |
1700 | if (do_loc) |
1701 | data = block_start + uvalue; | |
1702 | else | |
0c588247 | 1703 | data = display_block (block_start, uvalue, end); |
19e6b90e L |
1704 | break; |
1705 | ||
1706 | case DW_FORM_block2: | |
0c588247 | 1707 | SAFE_BYTE_GET (uvalue, data, 2, end); |
19e6b90e | 1708 | block_start = data + 2; |
a1165289 NC |
1709 | if (block_start >= end) |
1710 | { | |
1711 | warn (_("Block ends prematurely\n")); | |
1712 | uvalue = 0; | |
1713 | block_start = end; | |
1714 | } | |
f3853b34 NC |
1715 | data = block_start + uvalue; |
1716 | if (block_start + uvalue > end || data < block_start) | |
f41e4712 NC |
1717 | { |
1718 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1719 | uvalue = end - block_start; | |
1720 | } | |
19e6b90e L |
1721 | if (do_loc) |
1722 | data = block_start + uvalue; | |
1723 | else | |
0c588247 | 1724 | data = display_block (block_start, uvalue, end); |
19e6b90e L |
1725 | break; |
1726 | ||
1727 | case DW_FORM_block4: | |
0c588247 | 1728 | SAFE_BYTE_GET (uvalue, data, 4, end); |
19e6b90e | 1729 | block_start = data + 4; |
a1165289 NC |
1730 | /* PR 17512: file: 3371-3907-0.004. */ |
1731 | if (block_start >= end) | |
1732 | { | |
1733 | warn (_("Block ends prematurely\n")); | |
1734 | uvalue = 0; | |
1735 | block_start = end; | |
1736 | } | |
f3853b34 NC |
1737 | data = block_start + uvalue; |
1738 | if (block_start + uvalue > end | |
1739 | /* PR 17531: file: 5b5f0592. */ | |
1740 | || data < block_start) | |
f41e4712 NC |
1741 | { |
1742 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1743 | uvalue = end - block_start; | |
1744 | } | |
19e6b90e L |
1745 | if (do_loc) |
1746 | data = block_start + uvalue; | |
1747 | else | |
0c588247 | 1748 | data = display_block (block_start, uvalue, end); |
19e6b90e L |
1749 | break; |
1750 | ||
1751 | case DW_FORM_strp: | |
1752 | if (!do_loc) | |
47704ddf KT |
1753 | printf (_(" (indirect string, offset: 0x%s): %s"), |
1754 | dwarf_vmatoa ("x", uvalue), | |
1755 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
1756 | break; |
1757 | ||
4723351a CC |
1758 | case DW_FORM_GNU_str_index: |
1759 | if (!do_loc) | |
1760 | { | |
1761 | const char *suffix = strrchr (section->name, '.'); | |
1762 | int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0; | |
1763 | ||
1764 | printf (_(" (indexed string: 0x%s): %s"), | |
1765 | dwarf_vmatoa ("x", uvalue), | |
341f9135 | 1766 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); |
4723351a CC |
1767 | } |
1768 | break; | |
1769 | ||
a081f3cd JJ |
1770 | case DW_FORM_GNU_strp_alt: |
1771 | if (!do_loc) | |
1772 | printf (_(" (alt indirect string, offset: 0x%s)"), | |
1773 | dwarf_vmatoa ("x", uvalue)); | |
1774 | break; | |
1775 | ||
19e6b90e L |
1776 | case DW_FORM_indirect: |
1777 | /* Handled above. */ | |
1778 | break; | |
1779 | ||
2b6f5997 CC |
1780 | case DW_FORM_ref_sig8: |
1781 | if (!do_loc) | |
1782 | { | |
74bc6052 CC |
1783 | dwarf_vma high_bits; |
1784 | char buf[64]; | |
1785 | ||
0c588247 | 1786 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
74bc6052 CC |
1787 | printf (" signature: 0x%s", |
1788 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); | |
2b6f5997 | 1789 | } |
74bc6052 | 1790 | data += 8; |
2b6f5997 CC |
1791 | break; |
1792 | ||
4723351a CC |
1793 | case DW_FORM_GNU_addr_index: |
1794 | if (!do_loc) | |
1795 | printf (_(" (addr_index: 0x%s): %s"), | |
1796 | dwarf_vmatoa ("x", uvalue), | |
1797 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
1798 | break; | |
1799 | ||
19e6b90e L |
1800 | default: |
1801 | warn (_("Unrecognized form: %lu\n"), form); | |
1802 | break; | |
1803 | } | |
1804 | ||
19e6b90e | 1805 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
1806 | && num_debug_info_entries == 0 |
1807 | && debug_info_p != NULL) | |
19e6b90e L |
1808 | { |
1809 | switch (attribute) | |
1810 | { | |
1811 | case DW_AT_frame_base: | |
1812 | have_frame_base = 1; | |
1813 | case DW_AT_location: | |
e2a0d921 NC |
1814 | case DW_AT_string_length: |
1815 | case DW_AT_return_addr: | |
19e6b90e L |
1816 | case DW_AT_data_member_location: |
1817 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
1818 | case DW_AT_segment: |
1819 | case DW_AT_static_link: | |
1820 | case DW_AT_use_location: | |
629e7ca8 JJ |
1821 | case DW_AT_GNU_call_site_value: |
1822 | case DW_AT_GNU_call_site_data_value: | |
1823 | case DW_AT_GNU_call_site_target: | |
1824 | case DW_AT_GNU_call_site_target_clobbered: | |
212b6063 JK |
1825 | if ((dwarf_version < 4 |
1826 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) | |
932fd279 | 1827 | || form == DW_FORM_sec_offset) |
19e6b90e L |
1828 | { |
1829 | /* Process location list. */ | |
91d6fa6a | 1830 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
1831 | unsigned int num = debug_info_p->num_loc_offsets; |
1832 | ||
91d6fa6a | 1833 | if (lmax == 0 || num >= lmax) |
19e6b90e | 1834 | { |
91d6fa6a | 1835 | lmax += 1024; |
467c65bc | 1836 | debug_info_p->loc_offsets = (dwarf_vma *) |
3f5e193b | 1837 | xcrealloc (debug_info_p->loc_offsets, |
91d6fa6a | 1838 | lmax, sizeof (*debug_info_p->loc_offsets)); |
3f5e193b NC |
1839 | debug_info_p->have_frame_base = (int *) |
1840 | xcrealloc (debug_info_p->have_frame_base, | |
91d6fa6a NC |
1841 | lmax, sizeof (*debug_info_p->have_frame_base)); |
1842 | debug_info_p->max_loc_offsets = lmax; | |
19e6b90e | 1843 | } |
341f9135 CC |
1844 | if (this_set != NULL) |
1845 | uvalue += this_set->section_offsets [DW_SECT_LOC]; | |
19e6b90e L |
1846 | debug_info_p->loc_offsets [num] = uvalue; |
1847 | debug_info_p->have_frame_base [num] = have_frame_base; | |
1848 | debug_info_p->num_loc_offsets++; | |
1849 | } | |
1850 | break; | |
e2a0d921 | 1851 | |
19e6b90e L |
1852 | case DW_AT_low_pc: |
1853 | if (need_base_address) | |
1854 | debug_info_p->base_address = uvalue; | |
1855 | break; | |
1856 | ||
4723351a CC |
1857 | case DW_AT_GNU_addr_base: |
1858 | debug_info_p->addr_base = uvalue; | |
1859 | break; | |
1860 | ||
1861 | case DW_AT_GNU_ranges_base: | |
1862 | debug_info_p->ranges_base = uvalue; | |
1863 | break; | |
1864 | ||
19e6b90e | 1865 | case DW_AT_ranges: |
212b6063 JK |
1866 | if ((dwarf_version < 4 |
1867 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) | |
932fd279 | 1868 | || form == DW_FORM_sec_offset) |
19e6b90e L |
1869 | { |
1870 | /* Process range list. */ | |
91d6fa6a | 1871 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
1872 | unsigned int num = debug_info_p->num_range_lists; |
1873 | ||
91d6fa6a | 1874 | if (lmax == 0 || num >= lmax) |
19e6b90e | 1875 | { |
91d6fa6a | 1876 | lmax += 1024; |
467c65bc | 1877 | debug_info_p->range_lists = (dwarf_vma *) |
3f5e193b | 1878 | xcrealloc (debug_info_p->range_lists, |
91d6fa6a NC |
1879 | lmax, sizeof (*debug_info_p->range_lists)); |
1880 | debug_info_p->max_range_lists = lmax; | |
19e6b90e L |
1881 | } |
1882 | debug_info_p->range_lists [num] = uvalue; | |
1883 | debug_info_p->num_range_lists++; | |
1884 | } | |
1885 | break; | |
1886 | ||
1887 | default: | |
1888 | break; | |
1889 | } | |
1890 | } | |
1891 | ||
4ccf1e31 | 1892 | if (do_loc || attribute == 0) |
19e6b90e L |
1893 | return data; |
1894 | ||
ec4d4525 | 1895 | /* For some attributes we can display further information. */ |
19e6b90e L |
1896 | switch (attribute) |
1897 | { | |
1898 | case DW_AT_inline: | |
2e9e81a8 | 1899 | printf ("\t"); |
19e6b90e L |
1900 | switch (uvalue) |
1901 | { | |
1902 | case DW_INL_not_inlined: | |
1903 | printf (_("(not inlined)")); | |
1904 | break; | |
1905 | case DW_INL_inlined: | |
1906 | printf (_("(inlined)")); | |
1907 | break; | |
1908 | case DW_INL_declared_not_inlined: | |
1909 | printf (_("(declared as inline but ignored)")); | |
1910 | break; | |
1911 | case DW_INL_declared_inlined: | |
1912 | printf (_("(declared as inline and inlined)")); | |
1913 | break; | |
1914 | default: | |
47704ddf KT |
1915 | printf (_(" (Unknown inline attribute value: %s)"), |
1916 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1917 | break; |
1918 | } | |
1919 | break; | |
1920 | ||
1921 | case DW_AT_language: | |
2e9e81a8 | 1922 | printf ("\t"); |
19e6b90e L |
1923 | switch (uvalue) |
1924 | { | |
4b78141a | 1925 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 1926 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
1927 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
1928 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 1929 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
1930 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
1931 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
1932 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
1933 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 1934 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 1935 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 1936 | /* DWARF 2.1 values. */ |
4b78141a | 1937 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
1938 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
1939 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
1940 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
1941 | /* DWARF 3 values. */ |
1942 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
1943 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
1944 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
1945 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
1946 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
1947 | /* DWARF 4 values. */ |
1948 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 ILT |
1949 | /* DWARF 5 values. */ |
1950 | case DW_LANG_Go: printf ("(Go)"); break; | |
8bc10620 | 1951 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
6ddfe5b4 | 1952 | case DW_LANG_C11: printf ("(C11)"); break; |
8bc10620 | 1953 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
1954 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
1955 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
19e6b90e L |
1956 | /* MIPS extension. */ |
1957 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
1958 | /* UPC extension. */ | |
1959 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
1960 | default: | |
4b78141a | 1961 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 1962 | printf (_("(implementation defined: %s)"), |
467c65bc | 1963 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 1964 | else |
9cf03b7e | 1965 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
1966 | break; |
1967 | } | |
1968 | break; | |
1969 | ||
1970 | case DW_AT_encoding: | |
2e9e81a8 | 1971 | printf ("\t"); |
19e6b90e L |
1972 | switch (uvalue) |
1973 | { | |
1974 | case DW_ATE_void: printf ("(void)"); break; | |
1975 | case DW_ATE_address: printf ("(machine address)"); break; | |
1976 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
1977 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
1978 | case DW_ATE_float: printf ("(float)"); break; | |
1979 | case DW_ATE_signed: printf ("(signed)"); break; | |
1980 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
1981 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
1982 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 1983 | /* DWARF 2.1 values: */ |
19e6b90e L |
1984 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
1985 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
1986 | /* DWARF 3 values: */ |
1987 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
1988 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
1989 | case DW_ATE_edited: printf ("(edited)"); break; | |
1990 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
1991 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
1992 | /* HP extensions: */ | |
1993 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
1994 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
1995 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
1996 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
1997 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
1998 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
1999 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
2000 | ||
19e6b90e L |
2001 | default: |
2002 | if (uvalue >= DW_ATE_lo_user | |
2003 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2004 | printf (_("(user defined type)")); |
19e6b90e | 2005 | else |
9cf03b7e | 2006 | printf (_("(unknown type)")); |
19e6b90e L |
2007 | break; |
2008 | } | |
2009 | break; | |
2010 | ||
2011 | case DW_AT_accessibility: | |
2e9e81a8 | 2012 | printf ("\t"); |
19e6b90e L |
2013 | switch (uvalue) |
2014 | { | |
2015 | case DW_ACCESS_public: printf ("(public)"); break; | |
2016 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2017 | case DW_ACCESS_private: printf ("(private)"); break; | |
2018 | default: | |
9cf03b7e | 2019 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2020 | break; |
2021 | } | |
2022 | break; | |
2023 | ||
2024 | case DW_AT_visibility: | |
2e9e81a8 | 2025 | printf ("\t"); |
19e6b90e L |
2026 | switch (uvalue) |
2027 | { | |
2028 | case DW_VIS_local: printf ("(local)"); break; | |
2029 | case DW_VIS_exported: printf ("(exported)"); break; | |
2030 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2031 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2032 | } |
2033 | break; | |
2034 | ||
2035 | case DW_AT_virtuality: | |
2e9e81a8 | 2036 | printf ("\t"); |
19e6b90e L |
2037 | switch (uvalue) |
2038 | { | |
2039 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2040 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2041 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2042 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2043 | } |
2044 | break; | |
2045 | ||
2046 | case DW_AT_identifier_case: | |
2e9e81a8 | 2047 | printf ("\t"); |
19e6b90e L |
2048 | switch (uvalue) |
2049 | { | |
2050 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2051 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2052 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2053 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2054 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2055 | } |
2056 | break; | |
2057 | ||
2058 | case DW_AT_calling_convention: | |
2e9e81a8 | 2059 | printf ("\t"); |
19e6b90e L |
2060 | switch (uvalue) |
2061 | { | |
2062 | case DW_CC_normal: printf ("(normal)"); break; | |
2063 | case DW_CC_program: printf ("(program)"); break; | |
2064 | case DW_CC_nocall: printf ("(nocall)"); break; | |
2065 | default: | |
2066 | if (uvalue >= DW_CC_lo_user | |
2067 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2068 | printf (_("(user defined)")); |
19e6b90e | 2069 | else |
9cf03b7e | 2070 | printf (_("(unknown convention)")); |
19e6b90e L |
2071 | } |
2072 | break; | |
2073 | ||
2074 | case DW_AT_ordering: | |
2e9e81a8 | 2075 | printf ("\t"); |
19e6b90e L |
2076 | switch (uvalue) |
2077 | { | |
9cf03b7e | 2078 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2079 | case 0: printf ("(row major)"); break; |
2080 | case 1: printf ("(column major)"); break; | |
2081 | } | |
2082 | break; | |
2083 | ||
2084 | case DW_AT_frame_base: | |
2085 | have_frame_base = 1; | |
2086 | case DW_AT_location: | |
e2a0d921 NC |
2087 | case DW_AT_string_length: |
2088 | case DW_AT_return_addr: | |
19e6b90e L |
2089 | case DW_AT_data_member_location: |
2090 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2091 | case DW_AT_segment: |
2092 | case DW_AT_static_link: | |
2093 | case DW_AT_use_location: | |
629e7ca8 JJ |
2094 | case DW_AT_GNU_call_site_value: |
2095 | case DW_AT_GNU_call_site_data_value: | |
2096 | case DW_AT_GNU_call_site_target: | |
2097 | case DW_AT_GNU_call_site_target_clobbered: | |
212b6063 JK |
2098 | if ((dwarf_version < 4 |
2099 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) | |
932fd279 | 2100 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 2101 | printf (_(" (location list)")); |
e2a0d921 | 2102 | /* Fall through. */ |
19e6b90e L |
2103 | case DW_AT_allocated: |
2104 | case DW_AT_associated: | |
2105 | case DW_AT_data_location: | |
2106 | case DW_AT_stride: | |
2107 | case DW_AT_upper_bound: | |
cecf136e | 2108 | case DW_AT_lower_bound: |
19e6b90e L |
2109 | if (block_start) |
2110 | { | |
2111 | int need_frame_base; | |
2112 | ||
2e9e81a8 | 2113 | printf ("\t("); |
19e6b90e L |
2114 | need_frame_base = decode_location_expression (block_start, |
2115 | pointer_size, | |
b7807392 JJ |
2116 | offset_size, |
2117 | dwarf_version, | |
19e6b90e | 2118 | uvalue, |
f1c4cc75 | 2119 | cu_offset, section); |
19e6b90e L |
2120 | printf (")"); |
2121 | if (need_frame_base && !have_frame_base) | |
2122 | printf (_(" [without DW_AT_frame_base]")); | |
2123 | } | |
19e6b90e L |
2124 | break; |
2125 | ||
ec4d4525 NC |
2126 | case DW_AT_import: |
2127 | { | |
a081f3cd JJ |
2128 | if (form == DW_FORM_ref_sig8 |
2129 | || form == DW_FORM_GNU_ref_alt) | |
2b6f5997 CC |
2130 | break; |
2131 | ||
ec4d4525 NC |
2132 | if (form == DW_FORM_ref1 |
2133 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
2134 | || form == DW_FORM_ref4 |
2135 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
2136 | uvalue += cu_offset; |
2137 | ||
6e3d6dc1 | 2138 | if (uvalue >= section->size) |
f3853b34 | 2139 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
2140 | dwarf_vmatoa ("x", uvalue), |
2141 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
2142 | else |
2143 | { | |
2144 | unsigned long abbrev_number; | |
2145 | abbrev_entry * entry; | |
2146 | ||
f6f0e17b | 2147 | abbrev_number = read_uleb128 (section->start + uvalue, NULL, end); |
cecf136e | 2148 | |
2e9e81a8 | 2149 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
2150 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
2151 | use different abbrev table, and we don't track .debug_info chunks | |
2152 | yet. */ | |
2153 | if (form != DW_FORM_ref_addr) | |
2154 | { | |
2155 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
2156 | if (entry->entry == abbrev_number) | |
2157 | break; | |
2158 | if (entry != NULL) | |
2159 | printf (" (%s)", get_TAG_name (entry->tag)); | |
2160 | } | |
6e3d6dc1 NC |
2161 | printf ("]"); |
2162 | } | |
ec4d4525 NC |
2163 | } |
2164 | break; | |
2165 | ||
19e6b90e L |
2166 | default: |
2167 | break; | |
2168 | } | |
2169 | ||
2170 | return data; | |
2171 | } | |
2172 | ||
a19c41a7 | 2173 | static const char * |
19e6b90e L |
2174 | get_AT_name (unsigned long attribute) |
2175 | { | |
a19c41a7 | 2176 | const char *name; |
e2a0d921 | 2177 | |
399c99f7 L |
2178 | if (attribute == 0) |
2179 | return "DW_AT value: 0"; | |
2180 | ||
a19c41a7 TT |
2181 | /* One value is shared by the MIPS and HP extensions: */ |
2182 | if (attribute == DW_AT_MIPS_fde) | |
2183 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
19e6b90e | 2184 | |
a19c41a7 TT |
2185 | name = get_DW_AT_name (attribute); |
2186 | ||
2187 | if (name == NULL) | |
2188 | { | |
2189 | static char buffer[100]; | |
2190 | ||
2191 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
2192 | attribute); | |
2193 | return buffer; | |
19e6b90e | 2194 | } |
a19c41a7 TT |
2195 | |
2196 | return name; | |
19e6b90e L |
2197 | } |
2198 | ||
2199 | static unsigned char * | |
6e3d6dc1 NC |
2200 | read_and_display_attr (unsigned long attribute, |
2201 | unsigned long form, | |
ec4d4525 | 2202 | unsigned char * data, |
f6f0e17b | 2203 | unsigned char * end, |
467c65bc NC |
2204 | dwarf_vma cu_offset, |
2205 | dwarf_vma pointer_size, | |
2206 | dwarf_vma offset_size, | |
6e3d6dc1 NC |
2207 | int dwarf_version, |
2208 | debug_info * debug_info_p, | |
2209 | int do_loc, | |
341f9135 CC |
2210 | struct dwarf_section * section, |
2211 | struct cu_tu_set * this_set) | |
19e6b90e L |
2212 | { |
2213 | if (!do_loc) | |
750f03b7 | 2214 | printf (" %-18s:", get_AT_name (attribute)); |
f6f0e17b NC |
2215 | data = read_and_display_attr_value (attribute, form, data, end, |
2216 | cu_offset, pointer_size, offset_size, | |
19e6b90e | 2217 | dwarf_version, debug_info_p, |
341f9135 | 2218 | do_loc, section, this_set); |
19e6b90e L |
2219 | if (!do_loc) |
2220 | printf ("\n"); | |
2221 | return data; | |
2222 | } | |
2223 | ||
19e6b90e L |
2224 | /* Process the contents of a .debug_info section. If do_loc is non-zero |
2225 | then we are scanning for location lists and we do not want to display | |
2b6f5997 CC |
2226 | anything to the user. If do_types is non-zero, we are processing |
2227 | a .debug_types section instead of a .debug_info section. */ | |
19e6b90e L |
2228 | |
2229 | static int | |
6e3d6dc1 NC |
2230 | process_debug_info (struct dwarf_section *section, |
2231 | void *file, | |
6f875884 | 2232 | enum dwarf_section_display_enum abbrev_sec, |
2b6f5997 CC |
2233 | int do_loc, |
2234 | int do_types) | |
19e6b90e L |
2235 | { |
2236 | unsigned char *start = section->start; | |
2237 | unsigned char *end = start + section->size; | |
2238 | unsigned char *section_begin; | |
2239 | unsigned int unit; | |
2240 | unsigned int num_units = 0; | |
2241 | ||
2242 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2243 | && num_debug_info_entries == 0 |
2244 | && ! do_types) | |
19e6b90e | 2245 | { |
767221a9 | 2246 | dwarf_vma length; |
19e6b90e L |
2247 | |
2248 | /* First scan the section to get the number of comp units. */ | |
2249 | for (section_begin = start, num_units = 0; section_begin < end; | |
2250 | num_units ++) | |
2251 | { | |
2252 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
2253 | will be the length. For a 64-bit DWARF section, it'll be | |
2254 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 2255 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
2256 | |
2257 | if (length == 0xffffffff) | |
2258 | { | |
0c588247 | 2259 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
2260 | section_begin += length + 12; |
2261 | } | |
ec4d4525 NC |
2262 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
2263 | { | |
767221a9 NC |
2264 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
2265 | dwarf_vmatoa ("x", length), section->name); | |
ec4d4525 NC |
2266 | return 0; |
2267 | } | |
19e6b90e L |
2268 | else |
2269 | section_begin += length + 4; | |
aca88567 NC |
2270 | |
2271 | /* Negative values are illegal, they may even cause infinite | |
2272 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
2273 | relocations to an object file, or if the file is corrupt. */ |
2274 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 2275 | { |
767221a9 NC |
2276 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
2277 | dwarf_vmatoa ("x", length), section->name); | |
aca88567 NC |
2278 | return 0; |
2279 | } | |
19e6b90e L |
2280 | } |
2281 | ||
2282 | if (num_units == 0) | |
2283 | { | |
f41e4712 | 2284 | error (_("No comp units in %s section ?\n"), section->name); |
19e6b90e L |
2285 | return 0; |
2286 | } | |
2287 | ||
2288 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 2289 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 2290 | sizeof (* debug_information)); |
19e6b90e L |
2291 | if (debug_information == NULL) |
2292 | { | |
f41e4712 | 2293 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 2294 | num_units); |
82b1b41b | 2295 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e L |
2296 | return 0; |
2297 | } | |
82b1b41b | 2298 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
2299 | } |
2300 | ||
2301 | if (!do_loc) | |
2302 | { | |
fd2f0033 TT |
2303 | if (dwarf_start_die == 0) |
2304 | printf (_("Contents of the %s section:\n\n"), section->name); | |
19e6b90e L |
2305 | |
2306 | load_debug_section (str, file); | |
4723351a CC |
2307 | load_debug_section (str_dwo, file); |
2308 | load_debug_section (str_index, file); | |
2309 | load_debug_section (str_index_dwo, file); | |
2310 | load_debug_section (debug_addr, file); | |
19e6b90e L |
2311 | } |
2312 | ||
6f875884 TG |
2313 | load_debug_section (abbrev_sec, file); |
2314 | if (debug_displays [abbrev_sec].section.start == NULL) | |
19e6b90e L |
2315 | { |
2316 | warn (_("Unable to locate %s section!\n"), | |
6f875884 | 2317 | debug_displays [abbrev_sec].section.name); |
19e6b90e L |
2318 | return 0; |
2319 | } | |
2320 | ||
2321 | for (section_begin = start, unit = 0; start < end; unit++) | |
2322 | { | |
2323 | DWARF2_Internal_CompUnit compunit; | |
2324 | unsigned char *hdrptr; | |
19e6b90e | 2325 | unsigned char *tags; |
fd2f0033 | 2326 | int level, last_level, saved_level; |
467c65bc | 2327 | dwarf_vma cu_offset; |
bf5117e3 | 2328 | unsigned int offset_size; |
19e6b90e | 2329 | int initial_length_size; |
74bc6052 CC |
2330 | dwarf_vma signature_high = 0; |
2331 | dwarf_vma signature_low = 0; | |
767221a9 | 2332 | dwarf_vma type_offset = 0; |
341f9135 CC |
2333 | struct cu_tu_set *this_set; |
2334 | dwarf_vma abbrev_base; | |
2335 | size_t abbrev_size; | |
19e6b90e L |
2336 | |
2337 | hdrptr = start; | |
2338 | ||
0c588247 | 2339 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
2340 | |
2341 | if (compunit.cu_length == 0xffffffff) | |
2342 | { | |
0c588247 | 2343 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
2344 | offset_size = 8; |
2345 | initial_length_size = 12; | |
2346 | } | |
2347 | else | |
2348 | { | |
2349 | offset_size = 4; | |
2350 | initial_length_size = 4; | |
2351 | } | |
2352 | ||
0c588247 | 2353 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
2354 | |
2355 | cu_offset = start - section_begin; | |
19e6b90e | 2356 | |
341f9135 CC |
2357 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
2358 | ||
0c588247 | 2359 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 2360 | |
341f9135 CC |
2361 | if (this_set == NULL) |
2362 | { | |
2363 | abbrev_base = 0; | |
2364 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
2365 | } | |
2366 | else | |
2367 | { | |
2368 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
2369 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
2370 | } | |
2371 | ||
0c588247 | 2372 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); |
f41e4712 NC |
2373 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
2374 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
2375 | { | |
2376 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
2377 | compunit.cu_pointer_size, offset_size); | |
2378 | compunit.cu_pointer_size = offset_size; | |
2379 | } | |
2b6f5997 CC |
2380 | |
2381 | if (do_types) | |
2382 | { | |
0c588247 | 2383 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 2384 | hdrptr += 8; |
0c588247 | 2385 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
2b6f5997 CC |
2386 | } |
2387 | ||
19e6b90e | 2388 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
2389 | && num_debug_info_entries == 0 |
2390 | && ! do_types) | |
19e6b90e L |
2391 | { |
2392 | debug_information [unit].cu_offset = cu_offset; | |
2393 | debug_information [unit].pointer_size | |
2394 | = compunit.cu_pointer_size; | |
b7807392 JJ |
2395 | debug_information [unit].offset_size = offset_size; |
2396 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 2397 | debug_information [unit].base_address = 0; |
4723351a CC |
2398 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
2399 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
2400 | debug_information [unit].loc_offsets = NULL; |
2401 | debug_information [unit].have_frame_base = NULL; | |
2402 | debug_information [unit].max_loc_offsets = 0; | |
2403 | debug_information [unit].num_loc_offsets = 0; | |
2404 | debug_information [unit].range_lists = NULL; | |
2405 | debug_information [unit].max_range_lists= 0; | |
2406 | debug_information [unit].num_range_lists = 0; | |
2407 | } | |
2408 | ||
fd2f0033 | 2409 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 2410 | { |
47704ddf KT |
2411 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
2412 | dwarf_vmatoa ("x", cu_offset)); | |
2413 | printf (_(" Length: 0x%s (%s)\n"), | |
2414 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 2415 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 2416 | printf (_(" Version: %d\n"), compunit.cu_version); |
7282333f AM |
2417 | printf (_(" Abbrev Offset: 0x%s\n"), |
2418 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 2419 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
2420 | if (do_types) |
2421 | { | |
74bc6052 CC |
2422 | char buf[64]; |
2423 | ||
2424 | printf (_(" Signature: 0x%s\n"), | |
2425 | dwarf_vmatoa64 (signature_high, signature_low, | |
2426 | buf, sizeof (buf))); | |
2427 | printf (_(" Type Offset: 0x%s\n"), | |
2428 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 2429 | } |
341f9135 CC |
2430 | if (this_set != NULL) |
2431 | { | |
2432 | dwarf_vma *offsets = this_set->section_offsets; | |
2433 | size_t *sizes = this_set->section_sizes; | |
2434 | ||
2435 | printf (_(" Section contributions:\n")); | |
2436 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
2437 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
2438 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
2439 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
2440 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
2441 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
2442 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
2443 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
2444 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
2445 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
2446 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
2447 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
2448 | } | |
19e6b90e L |
2449 | } |
2450 | ||
460c89ff NS |
2451 | if (cu_offset + compunit.cu_length + initial_length_size |
2452 | > section->size) | |
2453 | { | |
47704ddf KT |
2454 | warn (_("Debug info is corrupted, length of CU at %s" |
2455 | " extends beyond end of section (length = %s)\n"), | |
2456 | dwarf_vmatoa ("x", cu_offset), | |
2457 | dwarf_vmatoa ("x", compunit.cu_length)); | |
57028622 | 2458 | num_units = unit; |
460c89ff NS |
2459 | break; |
2460 | } | |
2461 | tags = hdrptr; | |
2462 | start += compunit.cu_length + initial_length_size; | |
2463 | ||
57028622 NC |
2464 | if (start > end) |
2465 | { | |
2466 | warn (_("Debug info is corrupt. CU at %s extends beyond end of section"), | |
2467 | dwarf_vmatoa ("x", cu_offset)); | |
2468 | start = end; | |
2469 | } | |
2470 | ||
932fd279 JJ |
2471 | if (compunit.cu_version != 2 |
2472 | && compunit.cu_version != 3 | |
2473 | && compunit.cu_version != 4) | |
19e6b90e | 2474 | { |
47704ddf KT |
2475 | warn (_("CU at offset %s contains corrupt or " |
2476 | "unsupported version number: %d.\n"), | |
2477 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
2478 | continue; |
2479 | } | |
2480 | ||
2481 | free_abbrevs (); | |
2482 | ||
d493b283 | 2483 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 2484 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
2485 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
2486 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 2487 | (unsigned long) abbrev_size); |
72c61a0d | 2488 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
2489 | else if ((abbrev_base + abbrev_size) |
2490 | > debug_displays [abbrev_sec].section.size) | |
2491 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
2492 | (unsigned long) abbrev_base + abbrev_size, | |
2493 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
2494 | else |
2495 | process_abbrev_section | |
341f9135 CC |
2496 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
2497 | + abbrev_base + compunit.cu_abbrev_offset), | |
2498 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
2499 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
2500 | |
2501 | level = 0; | |
fd2f0033 TT |
2502 | last_level = level; |
2503 | saved_level = -1; | |
19e6b90e L |
2504 | while (tags < start) |
2505 | { | |
2506 | unsigned int bytes_read; | |
2507 | unsigned long abbrev_number; | |
ec4d4525 | 2508 | unsigned long die_offset; |
19e6b90e L |
2509 | abbrev_entry *entry; |
2510 | abbrev_attr *attr; | |
fd2f0033 | 2511 | int do_printing = 1; |
19e6b90e | 2512 | |
ec4d4525 NC |
2513 | die_offset = tags - section_begin; |
2514 | ||
f6f0e17b | 2515 | abbrev_number = read_uleb128 (tags, & bytes_read, start); |
19e6b90e L |
2516 | tags += bytes_read; |
2517 | ||
eb7cc021 JK |
2518 | /* A null DIE marks the end of a list of siblings or it may also be |
2519 | a section padding. */ | |
19e6b90e L |
2520 | if (abbrev_number == 0) |
2521 | { | |
eb7cc021 JK |
2522 | /* Check if it can be a section padding for the last CU. */ |
2523 | if (level == 0 && start == end) | |
2524 | { | |
2525 | unsigned char *chk; | |
2526 | ||
2527 | for (chk = tags; chk < start; chk++) | |
2528 | if (*chk != 0) | |
2529 | break; | |
2530 | if (chk == start) | |
2531 | break; | |
2532 | } | |
2533 | ||
4337774f TT |
2534 | if (!do_loc && die_offset >= dwarf_start_die |
2535 | && (dwarf_cutoff_level == -1 | |
2536 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
2537 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
2538 | level, die_offset); | |
2539 | ||
19e6b90e | 2540 | --level; |
ec4d4525 NC |
2541 | if (level < 0) |
2542 | { | |
2543 | static unsigned num_bogus_warns = 0; | |
2544 | ||
2545 | if (num_bogus_warns < 3) | |
2546 | { | |
4723351a CC |
2547 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
2548 | die_offset, section->name); | |
ec4d4525 NC |
2549 | num_bogus_warns ++; |
2550 | if (num_bogus_warns == 3) | |
2551 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
2552 | } | |
2553 | } | |
fd2f0033 TT |
2554 | if (dwarf_start_die != 0 && level < saved_level) |
2555 | return 1; | |
19e6b90e L |
2556 | continue; |
2557 | } | |
2558 | ||
4b78141a | 2559 | if (!do_loc) |
fd2f0033 TT |
2560 | { |
2561 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
2562 | do_printing = 0; | |
2563 | else | |
2564 | { | |
2565 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
2566 | saved_level = level; | |
2567 | do_printing = (dwarf_cutoff_level == -1 | |
2568 | || level < dwarf_cutoff_level); | |
2569 | if (do_printing) | |
2570 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
2571 | level, die_offset, abbrev_number); | |
2572 | else if (dwarf_cutoff_level == -1 | |
2573 | || last_level < dwarf_cutoff_level) | |
2574 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
2575 | last_level = level; | |
2576 | } | |
2577 | } | |
cecf136e | 2578 | |
19e6b90e L |
2579 | /* Scan through the abbreviation list until we reach the |
2580 | correct entry. */ | |
2581 | for (entry = first_abbrev; | |
2582 | entry && entry->entry != abbrev_number; | |
2583 | entry = entry->next) | |
2584 | continue; | |
2585 | ||
2586 | if (entry == NULL) | |
2587 | { | |
fd2f0033 | 2588 | if (!do_loc && do_printing) |
4b78141a NC |
2589 | { |
2590 | printf ("\n"); | |
2591 | fflush (stdout); | |
2592 | } | |
f3853b34 | 2593 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 2594 | die_offset, abbrev_number); |
19e6b90e L |
2595 | return 0; |
2596 | } | |
2597 | ||
fd2f0033 | 2598 | if (!do_loc && do_printing) |
cc5914eb | 2599 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 2600 | |
19e6b90e L |
2601 | switch (entry->tag) |
2602 | { | |
2603 | default: | |
2604 | need_base_address = 0; | |
2605 | break; | |
2606 | case DW_TAG_compile_unit: | |
2607 | need_base_address = 1; | |
2608 | break; | |
2609 | case DW_TAG_entry_point: | |
19e6b90e L |
2610 | case DW_TAG_subprogram: |
2611 | need_base_address = 0; | |
2612 | /* Assuming that there is no DW_AT_frame_base. */ | |
2613 | have_frame_base = 0; | |
2614 | break; | |
2615 | } | |
2616 | ||
399c99f7 L |
2617 | for (attr = entry->first_attr; |
2618 | attr && attr->attribute; | |
2619 | attr = attr->next) | |
4b78141a | 2620 | { |
fd2f0033 TT |
2621 | debug_info *arg; |
2622 | ||
2623 | if (! do_loc && do_printing) | |
4b78141a | 2624 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 TT |
2625 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
2626 | ||
82b1b41b NC |
2627 | if (debug_information && unit < alloc_num_debug_info_entries) |
2628 | arg = debug_information + unit; | |
2629 | else | |
2630 | arg = NULL; | |
f3853b34 | 2631 | |
4b78141a NC |
2632 | tags = read_and_display_attr (attr->attribute, |
2633 | attr->form, | |
341f9135 | 2634 | tags, |
f6f0e17b | 2635 | end, |
341f9135 | 2636 | cu_offset, |
4b78141a NC |
2637 | compunit.cu_pointer_size, |
2638 | offset_size, | |
2639 | compunit.cu_version, | |
fd2f0033 | 2640 | arg, |
341f9135 CC |
2641 | do_loc || ! do_printing, |
2642 | section, | |
2643 | this_set); | |
4b78141a | 2644 | } |
cecf136e | 2645 | |
19e6b90e L |
2646 | if (entry->children) |
2647 | ++level; | |
2648 | } | |
2649 | } | |
cecf136e | 2650 | |
19e6b90e L |
2651 | /* Set num_debug_info_entries here so that it can be used to check if |
2652 | we need to process .debug_loc and .debug_ranges sections. */ | |
2653 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2654 | && num_debug_info_entries == 0 |
2655 | && ! do_types) | |
82b1b41b NC |
2656 | { |
2657 | if (num_units > alloc_num_debug_info_entries) | |
2658 | num_debug_info_entries = alloc_num_debug_info_entries; | |
2659 | else | |
2660 | num_debug_info_entries = num_units; | |
2661 | } | |
cecf136e | 2662 | |
19e6b90e | 2663 | if (!do_loc) |
467c65bc | 2664 | printf ("\n"); |
cecf136e | 2665 | |
19e6b90e L |
2666 | return 1; |
2667 | } | |
2668 | ||
2669 | /* Locate and scan the .debug_info section in the file and record the pointer | |
2670 | sizes and offsets for the compilation units in it. Usually an executable | |
2671 | will have just one pointer size, but this is not guaranteed, and so we try | |
2672 | not to make any assumptions. Returns zero upon failure, or the number of | |
2673 | compilation units upon success. */ | |
2674 | ||
2675 | static unsigned int | |
2676 | load_debug_info (void * file) | |
2677 | { | |
2678 | /* Reset the last pointer size so that we can issue correct error | |
2679 | messages if we are displaying the contents of more than one section. */ | |
2680 | last_pointer_size = 0; | |
2681 | warned_about_missing_comp_units = FALSE; | |
2682 | ||
1febe64d | 2683 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 2684 | section then do not bother to repeat the task. */ |
cc86f28f | 2685 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
2686 | return 0; |
2687 | ||
19e6b90e L |
2688 | /* If we already have the information there is nothing else to do. */ |
2689 | if (num_debug_info_entries > 0) | |
2690 | return num_debug_info_entries; | |
2691 | ||
341f9135 CC |
2692 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
2693 | load_cu_tu_indexes (file); | |
2694 | ||
19e6b90e | 2695 | if (load_debug_section (info, file) |
6f875884 | 2696 | && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0)) |
19e6b90e | 2697 | return num_debug_info_entries; |
82b1b41b NC |
2698 | |
2699 | if (load_debug_section (info_dwo, file) | |
2700 | && process_debug_info (&debug_displays [info_dwo].section, file, | |
2701 | abbrev_dwo, 1, 0)) | |
4723351a | 2702 | return num_debug_info_entries; |
1febe64d | 2703 | |
cc86f28f | 2704 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 2705 | return 0; |
19e6b90e L |
2706 | } |
2707 | ||
b40bf0a2 NC |
2708 | /* Read a DWARF .debug_line section header starting at DATA. |
2709 | Upon success returns an updated DATA pointer and the LINFO | |
2710 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
2711 | Otherwise returns NULL. */ | |
19e6b90e | 2712 | |
b40bf0a2 NC |
2713 | static unsigned char * |
2714 | read_debug_line_header (struct dwarf_section * section, | |
2715 | unsigned char * data, | |
2716 | unsigned char * end, | |
2717 | DWARF2_Internal_LineInfo * linfo, | |
2718 | unsigned char ** end_of_sequence) | |
2719 | { | |
2720 | unsigned char *hdrptr; | |
2721 | unsigned int offset_size; | |
2722 | unsigned int initial_length_size; | |
19e6b90e | 2723 | |
b40bf0a2 NC |
2724 | /* Extract information from the Line Number Program Header. |
2725 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 2726 | hdrptr = data; |
19e6b90e | 2727 | |
b40bf0a2 NC |
2728 | /* Get and check the length of the block. */ |
2729 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 2730 | |
b40bf0a2 | 2731 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
2732 | { |
2733 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 2734 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
f41e4712 NC |
2735 | offset_size = 8; |
2736 | initial_length_size = 12; | |
2737 | } | |
2738 | else | |
2739 | { | |
2740 | offset_size = 4; | |
2741 | initial_length_size = 4; | |
2742 | } | |
19e6b90e | 2743 | |
b40bf0a2 | 2744 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 2745 | { |
b40bf0a2 NC |
2746 | /* If the length is just a bias against the initial_length_size then |
2747 | this means that the field has a relocation against it which has not | |
2748 | been applied. (Ie we are dealing with an object file, not a linked | |
2749 | binary). Do not complain but instead assume that the rest of the | |
2750 | section applies to this particular header. */ | |
2751 | if (linfo->li_length == - initial_length_size) | |
2752 | { | |
2753 | linfo->li_length = section->size - initial_length_size; | |
2754 | } | |
2755 | else | |
2756 | { | |
f41e4712 | 2757 | warn (_("The line info appears to be corrupt - the section is too small\n")); |
b40bf0a2 NC |
2758 | return NULL; |
2759 | } | |
f41e4712 | 2760 | } |
19e6b90e | 2761 | |
b40bf0a2 NC |
2762 | /* Get and check the version number. */ |
2763 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
2764 | ||
2765 | if (linfo->li_version != 2 | |
2766 | && linfo->li_version != 3 | |
2767 | && linfo->li_version != 4) | |
f41e4712 NC |
2768 | { |
2769 | warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n")); | |
b40bf0a2 | 2770 | return NULL; |
f41e4712 | 2771 | } |
19e6b90e | 2772 | |
b40bf0a2 NC |
2773 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, offset_size, end); |
2774 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); | |
0c588247 | 2775 | |
b40bf0a2 | 2776 | if (linfo->li_version >= 4) |
f41e4712 | 2777 | { |
b40bf0a2 | 2778 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 2779 | |
b40bf0a2 | 2780 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
2781 | { |
2782 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 2783 | return NULL; |
a233b20c | 2784 | } |
f41e4712 NC |
2785 | } |
2786 | else | |
b40bf0a2 | 2787 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 2788 | |
b40bf0a2 | 2789 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 2790 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
2791 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
2792 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 2793 | |
b40bf0a2 | 2794 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
6937bb54 NC |
2795 | /* PR 17512: file:002-117414-0.004. */ |
2796 | if (* end_of_sequence > end) | |
2797 | { | |
4c219c2e AM |
2798 | warn (_("Line length %s extends beyond end of section\n"), |
2799 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
2800 | * end_of_sequence = end; |
2801 | return NULL; | |
2802 | } | |
2803 | ||
b40bf0a2 NC |
2804 | return hdrptr; |
2805 | } | |
19e6b90e | 2806 | |
b40bf0a2 NC |
2807 | static int |
2808 | display_debug_lines_raw (struct dwarf_section *section, | |
2809 | unsigned char *data, | |
2810 | unsigned char *end) | |
2811 | { | |
2812 | unsigned char *start = section->start; | |
19e6b90e | 2813 | |
b40bf0a2 NC |
2814 | printf (_("Raw dump of debug contents of section %s:\n\n"), |
2815 | section->name); | |
19e6b90e | 2816 | |
b40bf0a2 NC |
2817 | while (data < end) |
2818 | { | |
2819 | static DWARF2_Internal_LineInfo saved_linfo; | |
2820 | DWARF2_Internal_LineInfo linfo; | |
2821 | unsigned char *standard_opcodes; | |
2822 | unsigned char *end_of_sequence; | |
fe59e83d CC |
2823 | unsigned int last_dir_entry = 0; |
2824 | int i; | |
19e6b90e | 2825 | |
4925cdd7 NC |
2826 | if (const_strneq (section->name, ".debug_line.") |
2827 | /* Note: the following does not apply to .debug_line.dwo sections. | |
2828 | These are full debug_line sections. */ | |
2829 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 2830 | { |
b40bf0a2 NC |
2831 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
2832 | section containing just the Line Number Statements. They are | |
2833 | created by the assembler and intended to be used alongside gcc's | |
2834 | -ffunction-sections command line option. When the linker's | |
2835 | garbage collection decides to discard a .text.<foo> section it | |
2836 | can then also discard the line number information in .debug_line.<foo>. | |
2837 | ||
4925cdd7 | 2838 | Since the section is a fragment it does not have the details |
b40bf0a2 | 2839 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 2840 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
2841 | end_of_sequence = end; |
2842 | standard_opcodes = NULL; | |
2843 | linfo = saved_linfo; | |
058037d3 NC |
2844 | /* PR 17531: file: 0522b371. */ |
2845 | if (linfo.li_line_range == 0) | |
2846 | { | |
1306a742 | 2847 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
2848 | return 0; |
2849 | } | |
b40bf0a2 | 2850 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 2851 | } |
19e6b90e L |
2852 | else |
2853 | { | |
b40bf0a2 | 2854 | unsigned char * hdrptr; |
19e6b90e | 2855 | |
b40bf0a2 NC |
2856 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
2857 | & end_of_sequence)) == NULL) | |
2858 | return 0; | |
19e6b90e | 2859 | |
b40bf0a2 NC |
2860 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
2861 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
2862 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
2863 | printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length); | |
2864 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); | |
2865 | if (linfo.li_version >= 4) | |
2866 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
2867 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
2868 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
2869 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
2870 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 2871 | |
0a9d414a NC |
2872 | /* PR 17512: file: 1665-6428-0.004. */ |
2873 | if (linfo.li_line_range == 0) | |
2874 | { | |
2875 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
2876 | linfo.li_line_range = 1; | |
2877 | } | |
058037d3 | 2878 | |
b40bf0a2 | 2879 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 2880 | |
b40bf0a2 NC |
2881 | /* Display the contents of the Opcodes table. */ |
2882 | standard_opcodes = hdrptr; | |
19e6b90e | 2883 | |
6937bb54 NC |
2884 | /* PR 17512: file: 002-417945-0.004. */ |
2885 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
2886 | { | |
2887 | warn (_("Line Base extends beyond end of section\n")); | |
2888 | return 0; | |
2889 | } | |
2890 | ||
b40bf0a2 | 2891 | printf (_("\n Opcodes:\n")); |
19e6b90e | 2892 | |
b40bf0a2 NC |
2893 | for (i = 1; i < linfo.li_opcode_base; i++) |
2894 | printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); | |
19e6b90e | 2895 | |
b40bf0a2 NC |
2896 | /* Display the contents of the Directory table. */ |
2897 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 2898 | |
b40bf0a2 NC |
2899 | if (*data == 0) |
2900 | printf (_("\n The Directory Table is empty.\n")); | |
2901 | else | |
2902 | { | |
fe59e83d CC |
2903 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
2904 | (long)(data - start)); | |
19e6b90e | 2905 | |
6937bb54 | 2906 | while (data < end && *data != 0) |
a233b20c | 2907 | { |
6937bb54 | 2908 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); |
b40bf0a2 NC |
2909 | |
2910 | data += strnlen ((char *) data, end - data) + 1; | |
a233b20c | 2911 | } |
6937bb54 NC |
2912 | |
2913 | /* PR 17512: file: 002-132094-0.004. */ | |
2914 | if (data >= end - 1) | |
2915 | break; | |
b40bf0a2 | 2916 | } |
19e6b90e | 2917 | |
b40bf0a2 NC |
2918 | /* Skip the NUL at the end of the table. */ |
2919 | data++; | |
19e6b90e | 2920 | |
b40bf0a2 NC |
2921 | /* Display the contents of the File Name table. */ |
2922 | if (*data == 0) | |
2923 | printf (_("\n The File Name Table is empty.\n")); | |
2924 | else | |
2925 | { | |
fe59e83d CC |
2926 | printf (_("\n The File Name Table (offset 0x%lx):\n"), |
2927 | (long)(data - start)); | |
b40bf0a2 | 2928 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
19e6b90e | 2929 | |
6937bb54 | 2930 | while (data < end && *data != 0) |
b40bf0a2 NC |
2931 | { |
2932 | unsigned char *name; | |
2933 | unsigned int bytes_read; | |
19e6b90e | 2934 | |
b40bf0a2 NC |
2935 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
2936 | name = data; | |
2937 | data += strnlen ((char *) data, end - data) + 1; | |
19e6b90e | 2938 | |
b40bf0a2 NC |
2939 | printf ("%s\t", |
2940 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
2941 | data += bytes_read; | |
2942 | printf ("%s\t", | |
2943 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
2944 | data += bytes_read; | |
2945 | printf ("%s\t", | |
2946 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
2947 | data += bytes_read; | |
6937bb54 | 2948 | printf ("%.*s\n", (int)(end - name), name); |
19e6b90e | 2949 | |
b40bf0a2 NC |
2950 | if (data == end) |
2951 | { | |
2952 | warn (_("Corrupt file name table entry\n")); | |
2953 | break; | |
2954 | } | |
a233b20c | 2955 | } |
b40bf0a2 | 2956 | } |
19e6b90e | 2957 | |
b40bf0a2 NC |
2958 | /* Skip the NUL at the end of the table. */ |
2959 | data++; | |
2960 | putchar ('\n'); | |
2961 | saved_linfo = linfo; | |
2962 | } | |
19e6b90e | 2963 | |
b40bf0a2 NC |
2964 | /* Now display the statements. */ |
2965 | if (data >= end_of_sequence) | |
2966 | printf (_(" No Line Number Statements.\n")); | |
2967 | else | |
2968 | { | |
2969 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 2970 | |
b40bf0a2 NC |
2971 | while (data < end_of_sequence) |
2972 | { | |
2973 | unsigned char op_code; | |
2974 | dwarf_signed_vma adv; | |
2975 | dwarf_vma uladv; | |
2976 | unsigned int bytes_read; | |
19e6b90e | 2977 | |
fe59e83d CC |
2978 | printf (" [0x%08lx]", (long)(data - start)); |
2979 | ||
b40bf0a2 | 2980 | op_code = *data++; |
19e6b90e | 2981 | |
b40bf0a2 | 2982 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 2983 | { |
b40bf0a2 NC |
2984 | op_code -= linfo.li_opcode_base; |
2985 | uladv = (op_code / linfo.li_line_range); | |
2986 | if (linfo.li_max_ops_per_insn == 1) | |
2987 | { | |
2988 | uladv *= linfo.li_min_insn_length; | |
2989 | state_machine_regs.address += uladv; | |
2990 | printf (_(" Special opcode %d: " | |
2991 | "advance Address by %s to 0x%s"), | |
2992 | op_code, dwarf_vmatoa ("u", uladv), | |
2993 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
2994 | } | |
2995 | else | |
2996 | { | |
2997 | state_machine_regs.address | |
2998 | += ((state_machine_regs.op_index + uladv) | |
2999 | / linfo.li_max_ops_per_insn) | |
3000 | * linfo.li_min_insn_length; | |
3001 | state_machine_regs.op_index | |
3002 | = (state_machine_regs.op_index + uladv) | |
3003 | % linfo.li_max_ops_per_insn; | |
3004 | printf (_(" Special opcode %d: " | |
3005 | "advance Address by %s to 0x%s[%d]"), | |
3006 | op_code, dwarf_vmatoa ("u", uladv), | |
3007 | dwarf_vmatoa ("x", state_machine_regs.address), | |
3008 | state_machine_regs.op_index); | |
3009 | } | |
3010 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
3011 | state_machine_regs.line += adv; | |
3012 | printf (_(" and Line by %s to %d\n"), | |
3013 | dwarf_vmatoa ("d", adv), state_machine_regs.line); | |
19e6b90e | 3014 | } |
b40bf0a2 NC |
3015 | else switch (op_code) |
3016 | { | |
3017 | case DW_LNS_extended_op: | |
3018 | data += process_extended_line_op (data, linfo.li_default_is_stmt, end); | |
3019 | break; | |
3020 | ||
3021 | case DW_LNS_copy: | |
3022 | printf (_(" Copy\n")); | |
3023 | break; | |
3024 | ||
3025 | case DW_LNS_advance_pc: | |
3026 | uladv = read_uleb128 (data, & bytes_read, end); | |
3027 | data += bytes_read; | |
3028 | if (linfo.li_max_ops_per_insn == 1) | |
3029 | { | |
3030 | uladv *= linfo.li_min_insn_length; | |
3031 | state_machine_regs.address += uladv; | |
3032 | printf (_(" Advance PC by %s to 0x%s\n"), | |
3033 | dwarf_vmatoa ("u", uladv), | |
3034 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
3035 | } | |
3036 | else | |
3037 | { | |
3038 | state_machine_regs.address | |
3039 | += ((state_machine_regs.op_index + uladv) | |
3040 | / linfo.li_max_ops_per_insn) | |
3041 | * linfo.li_min_insn_length; | |
3042 | state_machine_regs.op_index | |
3043 | = (state_machine_regs.op_index + uladv) | |
3044 | % linfo.li_max_ops_per_insn; | |
3045 | printf (_(" Advance PC by %s to 0x%s[%d]\n"), | |
3046 | dwarf_vmatoa ("u", uladv), | |
3047 | dwarf_vmatoa ("x", state_machine_regs.address), | |
3048 | state_machine_regs.op_index); | |
3049 | } | |
3050 | break; | |
3051 | ||
3052 | case DW_LNS_advance_line: | |
3053 | adv = read_sleb128 (data, & bytes_read, end); | |
3054 | data += bytes_read; | |
3055 | state_machine_regs.line += adv; | |
3056 | printf (_(" Advance Line by %s to %d\n"), | |
3057 | dwarf_vmatoa ("d", adv), | |
3058 | state_machine_regs.line); | |
3059 | break; | |
3060 | ||
3061 | case DW_LNS_set_file: | |
3062 | adv = read_uleb128 (data, & bytes_read, end); | |
3063 | data += bytes_read; | |
3064 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
3065 | dwarf_vmatoa ("d", adv)); | |
3066 | state_machine_regs.file = adv; | |
3067 | break; | |
3068 | ||
3069 | case DW_LNS_set_column: | |
3070 | uladv = read_uleb128 (data, & bytes_read, end); | |
3071 | data += bytes_read; | |
3072 | printf (_(" Set column to %s\n"), | |
3073 | dwarf_vmatoa ("u", uladv)); | |
3074 | state_machine_regs.column = uladv; | |
3075 | break; | |
3076 | ||
3077 | case DW_LNS_negate_stmt: | |
3078 | adv = state_machine_regs.is_stmt; | |
3079 | adv = ! adv; | |
3080 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
3081 | state_machine_regs.is_stmt = adv; | |
3082 | break; | |
3083 | ||
3084 | case DW_LNS_set_basic_block: | |
3085 | printf (_(" Set basic block\n")); | |
3086 | state_machine_regs.basic_block = 1; | |
3087 | break; | |
3088 | ||
3089 | case DW_LNS_const_add_pc: | |
3090 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
3091 | if (linfo.li_max_ops_per_insn) | |
3092 | { | |
3093 | uladv *= linfo.li_min_insn_length; | |
3094 | state_machine_regs.address += uladv; | |
3095 | printf (_(" Advance PC by constant %s to 0x%s\n"), | |
3096 | dwarf_vmatoa ("u", uladv), | |
3097 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
3098 | } | |
3099 | else | |
3100 | { | |
3101 | state_machine_regs.address | |
3102 | += ((state_machine_regs.op_index + uladv) | |
3103 | / linfo.li_max_ops_per_insn) | |
3104 | * linfo.li_min_insn_length; | |
3105 | state_machine_regs.op_index | |
3106 | = (state_machine_regs.op_index + uladv) | |
3107 | % linfo.li_max_ops_per_insn; | |
3108 | printf (_(" Advance PC by constant %s to 0x%s[%d]\n"), | |
3109 | dwarf_vmatoa ("u", uladv), | |
3110 | dwarf_vmatoa ("x", state_machine_regs.address), | |
3111 | state_machine_regs.op_index); | |
3112 | } | |
3113 | break; | |
3114 | ||
3115 | case DW_LNS_fixed_advance_pc: | |
3116 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
3117 | state_machine_regs.address += uladv; | |
3118 | state_machine_regs.op_index = 0; | |
3119 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
3120 | dwarf_vmatoa ("u", uladv), | |
3121 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
3122 | break; | |
3123 | ||
3124 | case DW_LNS_set_prologue_end: | |
3125 | printf (_(" Set prologue_end to true\n")); | |
3126 | break; | |
3127 | ||
3128 | case DW_LNS_set_epilogue_begin: | |
3129 | printf (_(" Set epilogue_begin to true\n")); | |
3130 | break; | |
3131 | ||
3132 | case DW_LNS_set_isa: | |
3133 | uladv = read_uleb128 (data, & bytes_read, end); | |
3134 | data += bytes_read; | |
3135 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
3136 | break; | |
3137 | ||
3138 | default: | |
3139 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
3140 | ||
3141 | if (standard_opcodes != NULL) | |
3142 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
3143 | { | |
3144 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
3145 | &bytes_read, end)), | |
3146 | i == 1 ? "" : ", "); | |
3147 | data += bytes_read; | |
3148 | } | |
3149 | putchar ('\n'); | |
3150 | break; | |
3151 | } | |
19e6b90e | 3152 | } |
b40bf0a2 | 3153 | putchar ('\n'); |
19e6b90e | 3154 | } |
19e6b90e L |
3155 | } |
3156 | ||
3157 | return 1; | |
3158 | } | |
3159 | ||
a262ae96 NC |
3160 | typedef struct |
3161 | { | |
467c65bc NC |
3162 | unsigned char *name; |
3163 | unsigned int directory_index; | |
3164 | unsigned int modification_date; | |
3165 | unsigned int length; | |
a262ae96 NC |
3166 | } File_Entry; |
3167 | ||
3168 | /* Output a decoded representation of the .debug_line section. */ | |
3169 | ||
3170 | static int | |
3171 | display_debug_lines_decoded (struct dwarf_section *section, | |
3172 | unsigned char *data, | |
3173 | unsigned char *end) | |
3174 | { | |
b40bf0a2 NC |
3175 | static DWARF2_Internal_LineInfo saved_linfo; |
3176 | ||
a262ae96 NC |
3177 | printf (_("Decoded dump of debug contents of section %s:\n\n"), |
3178 | section->name); | |
3179 | ||
3180 | while (data < end) | |
3181 | { | |
3182 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 3183 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
3184 | unsigned char *standard_opcodes; |
3185 | unsigned char *end_of_sequence; | |
a262ae96 NC |
3186 | int i; |
3187 | File_Entry *file_table = NULL; | |
143a3db0 | 3188 | unsigned int n_files = 0; |
a262ae96 | 3189 | unsigned char **directory_table = NULL; |
143a3db0 | 3190 | unsigned int n_directories = 0; |
a262ae96 | 3191 | |
4925cdd7 NC |
3192 | if (const_strneq (section->name, ".debug_line.") |
3193 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3194 | These are full debug_line sections. */ | |
3195 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
a262ae96 | 3196 | { |
4925cdd7 | 3197 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
3198 | end_of_sequence = end; |
3199 | standard_opcodes = NULL; | |
3200 | linfo = saved_linfo; | |
058037d3 NC |
3201 | /* PR 17531: file: 0522b371. */ |
3202 | if (linfo.li_line_range == 0) | |
3203 | { | |
1306a742 | 3204 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3205 | return 0; |
3206 | } | |
b40bf0a2 | 3207 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 NC |
3208 | } |
3209 | else | |
3210 | { | |
b40bf0a2 | 3211 | unsigned char *hdrptr; |
a262ae96 | 3212 | |
b40bf0a2 NC |
3213 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3214 | & end_of_sequence)) == NULL) | |
a233b20c | 3215 | return 0; |
0c588247 | 3216 | |
058037d3 NC |
3217 | /* PR 17531: file: 0522b371. */ |
3218 | if (linfo.li_line_range == 0) | |
3219 | { | |
3220 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
3221 | linfo.li_line_range = 1; | |
3222 | } | |
b40bf0a2 | 3223 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 3224 | |
b40bf0a2 NC |
3225 | /* Save a pointer to the contents of the Opcodes table. */ |
3226 | standard_opcodes = hdrptr; | |
a262ae96 | 3227 | |
b40bf0a2 NC |
3228 | /* Traverse the Directory table just to count entries. */ |
3229 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
3230 | if (*data != 0) | |
3231 | { | |
3232 | unsigned char *ptr_directory_table = data; | |
a262ae96 | 3233 | |
b40bf0a2 NC |
3234 | while (*data != 0) |
3235 | { | |
3236 | data += strnlen ((char *) data, end - data) + 1; | |
3237 | n_directories++; | |
3238 | } | |
a262ae96 | 3239 | |
b40bf0a2 NC |
3240 | /* Go through the directory table again to save the directories. */ |
3241 | directory_table = (unsigned char **) | |
3242 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 3243 | |
b40bf0a2 NC |
3244 | i = 0; |
3245 | while (*ptr_directory_table != 0) | |
3246 | { | |
3247 | directory_table[i] = ptr_directory_table; | |
3248 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
3249 | ptr_directory_table - end) + 1; | |
3250 | i++; | |
3251 | } | |
a262ae96 | 3252 | } |
b40bf0a2 NC |
3253 | /* Skip the NUL at the end of the table. */ |
3254 | data++; | |
a262ae96 | 3255 | |
b40bf0a2 NC |
3256 | /* Traverse the File Name table just to count the entries. */ |
3257 | if (*data != 0) | |
3258 | { | |
3259 | unsigned char *ptr_file_name_table = data; | |
a262ae96 | 3260 | |
b40bf0a2 NC |
3261 | while (*data != 0) |
3262 | { | |
3263 | unsigned int bytes_read; | |
a262ae96 | 3264 | |
b40bf0a2 NC |
3265 | /* Skip Name, directory index, last modification time and length |
3266 | of file. */ | |
3267 | data += strnlen ((char *) data, end - data) + 1; | |
3268 | read_uleb128 (data, & bytes_read, end); | |
3269 | data += bytes_read; | |
3270 | read_uleb128 (data, & bytes_read, end); | |
3271 | data += bytes_read; | |
3272 | read_uleb128 (data, & bytes_read, end); | |
3273 | data += bytes_read; | |
a262ae96 | 3274 | |
b40bf0a2 NC |
3275 | n_files++; |
3276 | } | |
a262ae96 | 3277 | |
b40bf0a2 NC |
3278 | /* Go through the file table again to save the strings. */ |
3279 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
a262ae96 | 3280 | |
b40bf0a2 NC |
3281 | i = 0; |
3282 | while (*ptr_file_name_table != 0) | |
3283 | { | |
3284 | unsigned int bytes_read; | |
3285 | ||
3286 | file_table[i].name = ptr_file_name_table; | |
3287 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
3288 | end - ptr_file_name_table) + 1; | |
3289 | ||
3290 | /* We are not interested in directory, time or size. */ | |
3291 | file_table[i].directory_index = read_uleb128 (ptr_file_name_table, | |
3292 | & bytes_read, end); | |
3293 | ptr_file_name_table += bytes_read; | |
3294 | file_table[i].modification_date = read_uleb128 (ptr_file_name_table, | |
3295 | & bytes_read, end); | |
3296 | ptr_file_name_table += bytes_read; | |
3297 | file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end); | |
3298 | ptr_file_name_table += bytes_read; | |
3299 | i++; | |
3300 | } | |
3301 | i = 0; | |
a262ae96 | 3302 | |
b40bf0a2 NC |
3303 | /* Print the Compilation Unit's name and a header. */ |
3304 | if (directory_table == NULL) | |
3305 | { | |
3306 | printf (_("CU: %s:\n"), file_table[0].name); | |
3307 | printf (_("File name Line number Starting address\n")); | |
3308 | } | |
3309 | else | |
3310 | { | |
3311 | unsigned int ix = file_table[0].directory_index; | |
3312 | const char *directory = ix ? (char *)directory_table[ix - 1] : "."; | |
a262ae96 | 3313 | |
b40bf0a2 NC |
3314 | if (do_wide || strlen (directory) < 76) |
3315 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
3316 | else | |
3317 | printf ("%s:\n", file_table[0].name); | |
0c588247 | 3318 | |
b40bf0a2 NC |
3319 | printf (_("File name Line number Starting address\n")); |
3320 | } | |
3321 | } | |
cc5914eb | 3322 | |
b40bf0a2 NC |
3323 | /* Skip the NUL at the end of the table. */ |
3324 | data++; | |
a262ae96 | 3325 | |
b40bf0a2 NC |
3326 | saved_linfo = linfo; |
3327 | } | |
a262ae96 NC |
3328 | |
3329 | /* This loop iterates through the Dwarf Line Number Program. */ | |
3330 | while (data < end_of_sequence) | |
3331 | { | |
3332 | unsigned char op_code; | |
3333 | int adv; | |
3334 | unsigned long int uladv; | |
3335 | unsigned int bytes_read; | |
3336 | int is_special_opcode = 0; | |
3337 | ||
3338 | op_code = *data++; | |
a262ae96 | 3339 | |
91d6fa6a | 3340 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 3341 | { |
91d6fa6a | 3342 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
3343 | uladv = (op_code / linfo.li_line_range); |
3344 | if (linfo.li_max_ops_per_insn == 1) | |
3345 | { | |
3346 | uladv *= linfo.li_min_insn_length; | |
3347 | state_machine_regs.address += uladv; | |
3348 | } | |
3349 | else | |
3350 | { | |
3351 | state_machine_regs.address | |
3352 | += ((state_machine_regs.op_index + uladv) | |
3353 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 3354 | * linfo.li_min_insn_length; |
a233b20c JJ |
3355 | state_machine_regs.op_index |
3356 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 3357 | % linfo.li_max_ops_per_insn; |
a233b20c | 3358 | } |
a262ae96 | 3359 | |
91d6fa6a | 3360 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
a262ae96 NC |
3361 | state_machine_regs.line += adv; |
3362 | is_special_opcode = 1; | |
3363 | } | |
3364 | else switch (op_code) | |
b40bf0a2 NC |
3365 | { |
3366 | case DW_LNS_extended_op: | |
3367 | { | |
3368 | unsigned int ext_op_code_len; | |
3369 | unsigned char ext_op_code; | |
3370 | unsigned char *op_code_data = data; | |
3371 | ||
3372 | ext_op_code_len = read_uleb128 (op_code_data, &bytes_read, | |
3373 | end_of_sequence); | |
3374 | op_code_data += bytes_read; | |
3375 | ||
3376 | if (ext_op_code_len == 0) | |
3377 | { | |
f41e4712 | 3378 | warn (_("Badly formed extended line op encountered!\n")); |
b40bf0a2 NC |
3379 | break; |
3380 | } | |
3381 | ext_op_code_len += bytes_read; | |
3382 | ext_op_code = *op_code_data++; | |
3383 | ||
3384 | switch (ext_op_code) | |
3385 | { | |
3386 | case DW_LNE_end_sequence: | |
3387 | reset_state_machine (linfo.li_default_is_stmt); | |
3388 | break; | |
3389 | case DW_LNE_set_address: | |
3390 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
87bc83b3 CC |
3391 | op_code_data, |
3392 | ext_op_code_len - bytes_read - 1, | |
b40bf0a2 NC |
3393 | end); |
3394 | state_machine_regs.op_index = 0; | |
3395 | break; | |
3396 | case DW_LNE_define_file: | |
3397 | { | |
3398 | file_table = (File_Entry *) xrealloc | |
3399 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
3400 | ||
3401 | ++state_machine_regs.last_file_entry; | |
3402 | /* Source file name. */ | |
3403 | file_table[n_files].name = op_code_data; | |
3404 | op_code_data += strlen ((char *) op_code_data) + 1; | |
3405 | /* Directory index. */ | |
3406 | file_table[n_files].directory_index = | |
3407 | read_uleb128 (op_code_data, & bytes_read, | |
3408 | end_of_sequence); | |
3409 | op_code_data += bytes_read; | |
3410 | /* Last modification time. */ | |
3411 | file_table[n_files].modification_date = | |
3412 | read_uleb128 (op_code_data, & bytes_read, | |
3413 | end_of_sequence); | |
3414 | op_code_data += bytes_read; | |
3415 | /* File length. */ | |
3416 | file_table[n_files].length = | |
3417 | read_uleb128 (op_code_data, & bytes_read, | |
3418 | end_of_sequence); | |
3419 | ||
3420 | n_files++; | |
3421 | break; | |
3422 | } | |
3423 | case DW_LNE_set_discriminator: | |
3424 | case DW_LNE_HP_set_sequence: | |
3425 | /* Simply ignored. */ | |
3426 | break; | |
3427 | ||
3428 | default: | |
3429 | printf (_("UNKNOWN (%u): length %d\n"), | |
3430 | ext_op_code, ext_op_code_len - bytes_read); | |
3431 | break; | |
3432 | } | |
3433 | data += ext_op_code_len; | |
3434 | break; | |
3435 | } | |
3436 | case DW_LNS_copy: | |
3437 | break; | |
3438 | ||
3439 | case DW_LNS_advance_pc: | |
3440 | uladv = read_uleb128 (data, & bytes_read, end); | |
3441 | data += bytes_read; | |
3442 | if (linfo.li_max_ops_per_insn == 1) | |
3443 | { | |
3444 | uladv *= linfo.li_min_insn_length; | |
3445 | state_machine_regs.address += uladv; | |
3446 | } | |
3447 | else | |
3448 | { | |
3449 | state_machine_regs.address | |
3450 | += ((state_machine_regs.op_index + uladv) | |
3451 | / linfo.li_max_ops_per_insn) | |
3452 | * linfo.li_min_insn_length; | |
3453 | state_machine_regs.op_index | |
3454 | = (state_machine_regs.op_index + uladv) | |
3455 | % linfo.li_max_ops_per_insn; | |
3456 | } | |
3457 | break; | |
3458 | ||
3459 | case DW_LNS_advance_line: | |
3460 | adv = read_sleb128 (data, & bytes_read, end); | |
3461 | data += bytes_read; | |
3462 | state_machine_regs.line += adv; | |
3463 | break; | |
3464 | ||
3465 | case DW_LNS_set_file: | |
3466 | adv = read_uleb128 (data, & bytes_read, end); | |
3467 | data += bytes_read; | |
3468 | state_machine_regs.file = adv; | |
3469 | ||
3470 | if (file_table == NULL) | |
3471 | printf (_("\n [Use file table entry %d]\n"), state_machine_regs.file - 1); | |
3472 | else if (file_table[state_machine_regs.file - 1].directory_index == 0) | |
3473 | /* If directory index is 0, that means current directory. */ | |
3474 | printf ("\n./%s:[++]\n", | |
3475 | file_table[state_machine_regs.file - 1].name); | |
3476 | else if (directory_table == NULL) | |
3477 | printf (_("\n [Use directory table entry %d]\n"), | |
3478 | file_table[state_machine_regs.file - 1].directory_index - 1); | |
3479 | else | |
3480 | /* The directory index starts counting at 1. */ | |
3481 | printf ("\n%s/%s:\n", | |
3482 | directory_table[file_table[state_machine_regs.file - 1].directory_index - 1], | |
3483 | file_table[state_machine_regs.file - 1].name); | |
3484 | break; | |
3485 | ||
3486 | case DW_LNS_set_column: | |
3487 | uladv = read_uleb128 (data, & bytes_read, end); | |
3488 | data += bytes_read; | |
3489 | state_machine_regs.column = uladv; | |
3490 | break; | |
3491 | ||
3492 | case DW_LNS_negate_stmt: | |
3493 | adv = state_machine_regs.is_stmt; | |
3494 | adv = ! adv; | |
3495 | state_machine_regs.is_stmt = adv; | |
3496 | break; | |
3497 | ||
3498 | case DW_LNS_set_basic_block: | |
3499 | state_machine_regs.basic_block = 1; | |
3500 | break; | |
3501 | ||
3502 | case DW_LNS_const_add_pc: | |
3503 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
3504 | if (linfo.li_max_ops_per_insn == 1) | |
3505 | { | |
3506 | uladv *= linfo.li_min_insn_length; | |
3507 | state_machine_regs.address += uladv; | |
3508 | } | |
3509 | else | |
3510 | { | |
3511 | state_machine_regs.address | |
3512 | += ((state_machine_regs.op_index + uladv) | |
3513 | / linfo.li_max_ops_per_insn) | |
3514 | * linfo.li_min_insn_length; | |
3515 | state_machine_regs.op_index | |
3516 | = (state_machine_regs.op_index + uladv) | |
3517 | % linfo.li_max_ops_per_insn; | |
3518 | } | |
3519 | break; | |
3520 | ||
3521 | case DW_LNS_fixed_advance_pc: | |
3522 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
3523 | state_machine_regs.address += uladv; | |
3524 | state_machine_regs.op_index = 0; | |
3525 | break; | |
3526 | ||
3527 | case DW_LNS_set_prologue_end: | |
3528 | break; | |
3529 | ||
3530 | case DW_LNS_set_epilogue_begin: | |
3531 | break; | |
3532 | ||
3533 | case DW_LNS_set_isa: | |
3534 | uladv = read_uleb128 (data, & bytes_read, end); | |
3535 | data += bytes_read; | |
3536 | printf (_(" Set ISA to %lu\n"), uladv); | |
3537 | break; | |
3538 | ||
3539 | default: | |
3540 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
3541 | ||
3542 | if (standard_opcodes != NULL) | |
3543 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
3544 | { | |
3545 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
3546 | &bytes_read, end)), | |
3547 | i == 1 ? "" : ", "); | |
3548 | data += bytes_read; | |
3549 | } | |
3550 | putchar ('\n'); | |
3551 | break; | |
3552 | } | |
a262ae96 NC |
3553 | |
3554 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row | |
3555 | to the DWARF address/line matrix. */ | |
3556 | if ((is_special_opcode) || (op_code == DW_LNE_end_sequence) | |
3557 | || (op_code == DW_LNS_copy)) | |
3558 | { | |
3559 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
b40bf0a2 | 3560 | char *fileName; |
a262ae96 | 3561 | char *newFileName = NULL; |
b40bf0a2 NC |
3562 | size_t fileNameLength; |
3563 | ||
3564 | if (file_table) | |
3565 | fileName = (char *) file_table[state_machine_regs.file - 1].name; | |
3566 | else | |
3567 | fileName = "<unknown>"; | |
3568 | ||
3569 | fileNameLength = strlen (fileName); | |
a262ae96 NC |
3570 | |
3571 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) | |
3572 | { | |
3f5e193b | 3573 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); |
a262ae96 NC |
3574 | /* Truncate file name */ |
3575 | strncpy (newFileName, | |
3576 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
3577 | MAX_FILENAME_LENGTH + 1); | |
3578 | } | |
3579 | else | |
3580 | { | |
3f5e193b | 3581 | newFileName = (char *) xmalloc (fileNameLength + 1); |
a262ae96 NC |
3582 | strncpy (newFileName, fileName, fileNameLength + 1); |
3583 | } | |
3584 | ||
3585 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
3586 | { | |
a233b20c | 3587 | if (linfo.li_max_ops_per_insn == 1) |
467c65bc NC |
3588 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n", |
3589 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3590 | state_machine_regs.address); |
3591 | else | |
467c65bc NC |
3592 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n", |
3593 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3594 | state_machine_regs.address, |
3595 | state_machine_regs.op_index); | |
a262ae96 NC |
3596 | } |
3597 | else | |
3598 | { | |
a233b20c | 3599 | if (linfo.li_max_ops_per_insn == 1) |
467c65bc NC |
3600 | printf ("%s %11d %#18" DWARF_VMA_FMT "x\n", |
3601 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3602 | state_machine_regs.address); |
3603 | else | |
467c65bc NC |
3604 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n", |
3605 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3606 | state_machine_regs.address, |
3607 | state_machine_regs.op_index); | |
a262ae96 NC |
3608 | } |
3609 | ||
3610 | if (op_code == DW_LNE_end_sequence) | |
3611 | printf ("\n"); | |
3612 | ||
3613 | free (newFileName); | |
3614 | } | |
3615 | } | |
b40bf0a2 NC |
3616 | |
3617 | if (file_table) | |
3618 | { | |
3619 | free (file_table); | |
3620 | file_table = NULL; | |
3621 | n_files = 0; | |
3622 | } | |
3623 | ||
3624 | if (directory_table) | |
3625 | { | |
3626 | free (directory_table); | |
3627 | directory_table = NULL; | |
3628 | n_directories = 0; | |
3629 | } | |
3630 | ||
a262ae96 NC |
3631 | putchar ('\n'); |
3632 | } | |
3633 | ||
3634 | return 1; | |
3635 | } | |
3636 | ||
3637 | static int | |
1c4cc746 | 3638 | display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) |
a262ae96 NC |
3639 | { |
3640 | unsigned char *data = section->start; | |
3641 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
3642 | int retValRaw = 1; |
3643 | int retValDecoded = 1; | |
a262ae96 | 3644 | |
008f4c78 NC |
3645 | if (do_debug_lines == 0) |
3646 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
3647 | ||
4cb93e3b | 3648 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
a262ae96 NC |
3649 | retValRaw = display_debug_lines_raw (section, data, end); |
3650 | ||
4cb93e3b | 3651 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
a262ae96 NC |
3652 | retValDecoded = display_debug_lines_decoded (section, data, end); |
3653 | ||
4cb93e3b | 3654 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
3655 | return 0; |
3656 | ||
3657 | return 1; | |
3658 | } | |
3659 | ||
6e3d6dc1 NC |
3660 | static debug_info * |
3661 | find_debug_info_for_offset (unsigned long offset) | |
3662 | { | |
3663 | unsigned int i; | |
3664 | ||
3665 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
3666 | return NULL; | |
3667 | ||
3668 | for (i = 0; i < num_debug_info_entries; i++) | |
3669 | if (debug_information[i].cu_offset == offset) | |
3670 | return debug_information + i; | |
3671 | ||
3672 | return NULL; | |
3673 | } | |
3674 | ||
459d52c8 DE |
3675 | static const char * |
3676 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
3677 | { | |
3678 | /* See gdb/gdb-index.h. */ | |
3679 | static const char * const kinds[] = | |
3680 | { | |
3681 | N_ ("no info"), | |
3682 | N_ ("type"), | |
3683 | N_ ("variable"), | |
3684 | N_ ("function"), | |
3685 | N_ ("other"), | |
3686 | N_ ("unused5"), | |
3687 | N_ ("unused6"), | |
3688 | N_ ("unused7") | |
3689 | }; | |
3690 | ||
3691 | return _ (kinds[kind]); | |
3692 | } | |
3693 | ||
19e6b90e | 3694 | static int |
459d52c8 DE |
3695 | display_debug_pubnames_worker (struct dwarf_section *section, |
3696 | void *file ATTRIBUTE_UNUSED, | |
3697 | int is_gnu) | |
19e6b90e | 3698 | { |
91d6fa6a | 3699 | DWARF2_Internal_PubNames names; |
19e6b90e L |
3700 | unsigned char *start = section->start; |
3701 | unsigned char *end = start + section->size; | |
3702 | ||
6e3d6dc1 NC |
3703 | /* It does not matter if this load fails, |
3704 | we test for that later on. */ | |
3705 | load_debug_info (file); | |
3706 | ||
19e6b90e L |
3707 | printf (_("Contents of the %s section:\n\n"), section->name); |
3708 | ||
3709 | while (start < end) | |
3710 | { | |
3711 | unsigned char *data; | |
3712 | unsigned long offset; | |
bf5117e3 | 3713 | unsigned int offset_size, initial_length_size; |
19e6b90e L |
3714 | |
3715 | data = start; | |
3716 | ||
0c588247 | 3717 | SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end); |
91d6fa6a | 3718 | if (names.pn_length == 0xffffffff) |
19e6b90e | 3719 | { |
0c588247 | 3720 | SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end); |
19e6b90e L |
3721 | offset_size = 8; |
3722 | initial_length_size = 12; | |
3723 | } | |
3724 | else | |
3725 | { | |
3726 | offset_size = 4; | |
3727 | initial_length_size = 4; | |
3728 | } | |
3729 | ||
0c588247 NC |
3730 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
3731 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
3732 | |
3733 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
3734 | && num_debug_info_entries > 0 | |
91d6fa6a | 3735 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 3736 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 3737 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 3738 | |
0c588247 | 3739 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 3740 | |
058037d3 | 3741 | /* PR 17531: file: 7615b6b2. */ |
57028622 NC |
3742 | if ((dwarf_signed_vma) names.pn_length < 0 |
3743 | /* PR 17531: file: a5dbeaa7. */ | |
3744 | || start + names.pn_length + initial_length_size < start) | |
058037d3 NC |
3745 | { |
3746 | warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length); | |
3747 | start = end; | |
3748 | } | |
3749 | else | |
3750 | start += names.pn_length + initial_length_size; | |
3751 | ||
3752 | printf (_(" Length: %ld\n"), | |
3753 | (long) names.pn_length); | |
3754 | printf (_(" Version: %d\n"), | |
3755 | names.pn_version); | |
3756 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
3757 | (unsigned long) names.pn_offset); | |
3758 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
3759 | (long) names.pn_size); | |
19e6b90e | 3760 | |
91d6fa6a | 3761 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
3762 | { |
3763 | static int warned = 0; | |
3764 | ||
3765 | if (! warned) | |
3766 | { | |
3767 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
3768 | warned = 1; | |
3769 | } | |
3770 | ||
3771 | continue; | |
3772 | } | |
3773 | ||
459d52c8 DE |
3774 | if (is_gnu) |
3775 | printf (_("\n Offset Kind Name\n")); | |
3776 | else | |
3777 | printf (_("\n Offset\tName\n")); | |
19e6b90e L |
3778 | |
3779 | do | |
3780 | { | |
f41e4712 NC |
3781 | bfd_size_type maxprint; |
3782 | ||
0c588247 | 3783 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e L |
3784 | |
3785 | if (offset != 0) | |
3786 | { | |
3787 | data += offset_size; | |
f41e4712 NC |
3788 | if (data >= end) |
3789 | break; | |
3790 | maxprint = (end - data) - 1; | |
3791 | ||
459d52c8 DE |
3792 | if (is_gnu) |
3793 | { | |
3794 | unsigned int kind_data; | |
3795 | gdb_index_symbol_kind kind; | |
3796 | const char *kind_name; | |
3797 | int is_static; | |
3798 | ||
3799 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
3800 | data++; | |
f41e4712 | 3801 | maxprint --; |
459d52c8 DE |
3802 | /* GCC computes the kind as the upper byte in the CU index |
3803 | word, and then right shifts it by the CU index size. | |
3804 | Left shift KIND to where the gdb-index.h accessor macros | |
3805 | can use it. */ | |
3806 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
3807 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
3808 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
3809 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
f41e4712 | 3810 | printf (" %-6lx %s,%-10s %.*s\n", |
459d52c8 | 3811 | offset, is_static ? _("s") : _("g"), |
f41e4712 | 3812 | kind_name, (int) maxprint, data); |
459d52c8 DE |
3813 | } |
3814 | else | |
f41e4712 NC |
3815 | printf (" %-6lx\t%.*s\n", offset, (int) maxprint, data); |
3816 | ||
3817 | data += strnlen ((char *) data, maxprint) + 1; | |
3818 | if (data >= end) | |
3819 | break; | |
19e6b90e L |
3820 | } |
3821 | } | |
3822 | while (offset != 0); | |
3823 | } | |
3824 | ||
3825 | printf ("\n"); | |
3826 | return 1; | |
3827 | } | |
3828 | ||
459d52c8 DE |
3829 | static int |
3830 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
3831 | { | |
3832 | return display_debug_pubnames_worker (section, file, 0); | |
3833 | } | |
3834 | ||
3835 | static int | |
3836 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
3837 | { | |
3838 | return display_debug_pubnames_worker (section, file, 1); | |
3839 | } | |
3840 | ||
19e6b90e L |
3841 | static int |
3842 | display_debug_macinfo (struct dwarf_section *section, | |
3843 | void *file ATTRIBUTE_UNUSED) | |
3844 | { | |
3845 | unsigned char *start = section->start; | |
3846 | unsigned char *end = start + section->size; | |
3847 | unsigned char *curr = start; | |
3848 | unsigned int bytes_read; | |
3849 | enum dwarf_macinfo_record_type op; | |
3850 | ||
3851 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3852 | ||
3853 | while (curr < end) | |
3854 | { | |
3855 | unsigned int lineno; | |
0c588247 | 3856 | const unsigned char *string; |
19e6b90e | 3857 | |
3f5e193b | 3858 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
3859 | curr++; |
3860 | ||
3861 | switch (op) | |
3862 | { | |
3863 | case DW_MACINFO_start_file: | |
3864 | { | |
3865 | unsigned int filenum; | |
3866 | ||
f6f0e17b | 3867 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 3868 | curr += bytes_read; |
f6f0e17b | 3869 | filenum = read_uleb128 (curr, & bytes_read, end); |
19e6b90e L |
3870 | curr += bytes_read; |
3871 | ||
3872 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
3873 | lineno, filenum); | |
3874 | } | |
3875 | break; | |
3876 | ||
3877 | case DW_MACINFO_end_file: | |
3878 | printf (_(" DW_MACINFO_end_file\n")); | |
3879 | break; | |
3880 | ||
3881 | case DW_MACINFO_define: | |
f6f0e17b | 3882 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 3883 | curr += bytes_read; |
0c588247 NC |
3884 | string = curr; |
3885 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
3886 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
3887 | lineno, string); | |
3888 | break; | |
3889 | ||
3890 | case DW_MACINFO_undef: | |
f6f0e17b | 3891 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 3892 | curr += bytes_read; |
0c588247 NC |
3893 | string = curr; |
3894 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
3895 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
3896 | lineno, string); | |
3897 | break; | |
3898 | ||
3899 | case DW_MACINFO_vendor_ext: | |
3900 | { | |
3901 | unsigned int constant; | |
3902 | ||
f6f0e17b | 3903 | constant = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 3904 | curr += bytes_read; |
0c588247 NC |
3905 | string = curr; |
3906 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
3907 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
3908 | constant, string); | |
3909 | } | |
3910 | break; | |
3911 | } | |
3912 | } | |
3913 | ||
3914 | return 1; | |
3915 | } | |
3916 | ||
4ccf1e31 JJ |
3917 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
3918 | filename and dirname corresponding to file name table entry with index | |
3919 | FILEIDX. Return NULL on failure. */ | |
3920 | ||
3921 | static unsigned char * | |
f6f0e17b NC |
3922 | get_line_filename_and_dirname (dwarf_vma line_offset, |
3923 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
3924 | unsigned char **dir_name) |
3925 | { | |
3926 | struct dwarf_section *section = &debug_displays [line].section; | |
3927 | unsigned char *hdrptr, *dirtable, *file_name; | |
3928 | unsigned int offset_size, initial_length_size; | |
3929 | unsigned int version, opcode_base, bytes_read; | |
3930 | dwarf_vma length, diridx; | |
f6f0e17b | 3931 | const unsigned char * end; |
4ccf1e31 JJ |
3932 | |
3933 | *dir_name = NULL; | |
3934 | if (section->start == NULL | |
3935 | || line_offset >= section->size | |
3936 | || fileidx == 0) | |
3937 | return NULL; | |
3938 | ||
3939 | hdrptr = section->start + line_offset; | |
f6f0e17b | 3940 | end = section->start + section->size; |
0c588247 NC |
3941 | |
3942 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
3943 | if (length == 0xffffffff) |
3944 | { | |
3945 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 3946 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
3947 | offset_size = 8; |
3948 | initial_length_size = 12; | |
3949 | } | |
3950 | else | |
3951 | { | |
3952 | offset_size = 4; | |
3953 | initial_length_size = 4; | |
3954 | } | |
3955 | if (length + initial_length_size > section->size) | |
3956 | return NULL; | |
0c588247 NC |
3957 | |
3958 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
3959 | if (version != 2 && version != 3 && version != 4) |
3960 | return NULL; | |
3961 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
3962 | if (version >= 4) | |
3963 | hdrptr++; /* Skip max_ops_per_insn. */ | |
3964 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
3965 | |
3966 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
3967 | if (opcode_base == 0) |
3968 | return NULL; | |
0c588247 | 3969 | |
4ccf1e31 JJ |
3970 | hdrptr += opcode_base - 1; |
3971 | dirtable = hdrptr; | |
3972 | /* Skip over dirname table. */ | |
3973 | while (*hdrptr != '\0') | |
0c588247 | 3974 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
4ccf1e31 JJ |
3975 | hdrptr++; /* Skip the NUL at the end of the table. */ |
3976 | /* Now skip over preceding filename table entries. */ | |
3977 | for (; *hdrptr != '\0' && fileidx > 1; fileidx--) | |
3978 | { | |
0c588247 | 3979 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 3980 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 3981 | hdrptr += bytes_read; |
f6f0e17b | 3982 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 3983 | hdrptr += bytes_read; |
f6f0e17b | 3984 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
3985 | hdrptr += bytes_read; |
3986 | } | |
f6f0e17b | 3987 | if (hdrptr == end || *hdrptr == '\0') |
4ccf1e31 JJ |
3988 | return NULL; |
3989 | file_name = hdrptr; | |
0c588247 | 3990 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 3991 | diridx = read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
3992 | if (diridx == 0) |
3993 | return file_name; | |
3994 | for (; *dirtable != '\0' && diridx > 1; diridx--) | |
0c588247 | 3995 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
4ccf1e31 JJ |
3996 | if (*dirtable == '\0') |
3997 | return NULL; | |
3998 | *dir_name = dirtable; | |
3999 | return file_name; | |
4000 | } | |
4001 | ||
4002 | static int | |
4003 | display_debug_macro (struct dwarf_section *section, | |
4004 | void *file) | |
4005 | { | |
4006 | unsigned char *start = section->start; | |
4007 | unsigned char *end = start + section->size; | |
4008 | unsigned char *curr = start; | |
4009 | unsigned char *extended_op_buf[256]; | |
4010 | unsigned int bytes_read; | |
4011 | ||
4012 | load_debug_section (str, file); | |
4013 | load_debug_section (line, file); | |
4014 | ||
4015 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4016 | ||
4017 | while (curr < end) | |
4018 | { | |
4019 | unsigned int lineno, version, flags; | |
4020 | unsigned int offset_size = 4; | |
0c588247 | 4021 | const unsigned char *string; |
4ccf1e31 JJ |
4022 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
4023 | unsigned char **extended_ops = NULL; | |
4024 | ||
0c588247 | 4025 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
4ccf1e31 JJ |
4026 | if (version != 4) |
4027 | { | |
4028 | error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"), | |
4029 | section->name); | |
4030 | return 0; | |
4031 | } | |
4032 | ||
0c588247 | 4033 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
4034 | if (flags & 1) |
4035 | offset_size = 8; | |
4036 | printf (_(" Offset: 0x%lx\n"), | |
4037 | (unsigned long) sec_offset); | |
4038 | printf (_(" Version: %d\n"), version); | |
4039 | printf (_(" Offset size: %d\n"), offset_size); | |
4040 | if (flags & 2) | |
4041 | { | |
0c588247 | 4042 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
4043 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
4044 | (unsigned long) line_offset); | |
4045 | } | |
4046 | if (flags & 4) | |
4047 | { | |
0c588247 | 4048 | unsigned int i, count, op; |
4ccf1e31 | 4049 | dwarf_vma nargs, n; |
0c588247 NC |
4050 | |
4051 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 4052 | |
4ccf1e31 JJ |
4053 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
4054 | extended_ops = extended_op_buf; | |
4055 | if (count) | |
4056 | { | |
4057 | printf (_(" Extension opcode arguments:\n")); | |
4058 | for (i = 0; i < count; i++) | |
4059 | { | |
0c588247 | 4060 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 4061 | extended_ops[op] = curr; |
f6f0e17b | 4062 | nargs = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
4063 | curr += bytes_read; |
4064 | if (nargs == 0) | |
4065 | printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op); | |
4066 | else | |
4067 | { | |
4068 | printf (_(" DW_MACRO_GNU_%02x arguments: "), op); | |
4069 | for (n = 0; n < nargs; n++) | |
4070 | { | |
0c588247 NC |
4071 | unsigned int form; |
4072 | ||
4073 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
4074 | printf ("%s%s", get_FORM_name (form), |
4075 | n == nargs - 1 ? "\n" : ", "); | |
4076 | switch (form) | |
4077 | { | |
4078 | case DW_FORM_data1: | |
4079 | case DW_FORM_data2: | |
4080 | case DW_FORM_data4: | |
4081 | case DW_FORM_data8: | |
4082 | case DW_FORM_sdata: | |
4083 | case DW_FORM_udata: | |
4084 | case DW_FORM_block: | |
4085 | case DW_FORM_block1: | |
4086 | case DW_FORM_block2: | |
4087 | case DW_FORM_block4: | |
4088 | case DW_FORM_flag: | |
4089 | case DW_FORM_string: | |
4090 | case DW_FORM_strp: | |
4091 | case DW_FORM_sec_offset: | |
4092 | break; | |
4093 | default: | |
4094 | error (_("Invalid extension opcode form %s\n"), | |
4095 | get_FORM_name (form)); | |
4096 | return 0; | |
4097 | } | |
4098 | } | |
4099 | } | |
4100 | } | |
4101 | } | |
4102 | } | |
4103 | printf ("\n"); | |
4104 | ||
4105 | while (1) | |
4106 | { | |
4107 | unsigned int op; | |
4108 | ||
4109 | if (curr >= end) | |
4110 | { | |
4111 | error (_(".debug_macro section not zero terminated\n")); | |
4112 | return 0; | |
4113 | } | |
4114 | ||
0c588247 | 4115 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
4116 | if (op == 0) |
4117 | break; | |
4118 | ||
4119 | switch (op) | |
4120 | { | |
4121 | case DW_MACRO_GNU_start_file: | |
4122 | { | |
4123 | unsigned int filenum; | |
4124 | unsigned char *file_name = NULL, *dir_name = NULL; | |
4125 | ||
f6f0e17b | 4126 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4127 | curr += bytes_read; |
f6f0e17b | 4128 | filenum = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
4129 | curr += bytes_read; |
4130 | ||
4131 | if ((flags & 2) == 0) | |
4132 | error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n")); | |
4133 | else | |
4134 | file_name | |
4135 | = get_line_filename_and_dirname (line_offset, filenum, | |
4136 | &dir_name); | |
4137 | if (file_name == NULL) | |
4138 | printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"), | |
4139 | lineno, filenum); | |
4140 | else | |
4141 | printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), | |
4142 | lineno, filenum, | |
4143 | dir_name != NULL ? (const char *) dir_name : "", | |
4144 | dir_name != NULL ? "/" : "", file_name); | |
4145 | } | |
4146 | break; | |
4147 | ||
4148 | case DW_MACRO_GNU_end_file: | |
4149 | printf (_(" DW_MACRO_GNU_end_file\n")); | |
4150 | break; | |
4151 | ||
4152 | case DW_MACRO_GNU_define: | |
f6f0e17b | 4153 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4154 | curr += bytes_read; |
0c588247 NC |
4155 | string = curr; |
4156 | curr += strnlen ((char *) string, end - string) + 1; | |
4ccf1e31 JJ |
4157 | printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"), |
4158 | lineno, string); | |
4159 | break; | |
4160 | ||
4161 | case DW_MACRO_GNU_undef: | |
f6f0e17b | 4162 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4163 | curr += bytes_read; |
0c588247 NC |
4164 | string = curr; |
4165 | curr += strnlen ((char *) string, end - string) + 1; | |
4ccf1e31 JJ |
4166 | printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"), |
4167 | lineno, string); | |
4168 | break; | |
4169 | ||
4170 | case DW_MACRO_GNU_define_indirect: | |
f6f0e17b | 4171 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4172 | curr += bytes_read; |
0c588247 | 4173 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 JJ |
4174 | string = fetch_indirect_string (offset); |
4175 | printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"), | |
4176 | lineno, string); | |
4177 | break; | |
4178 | ||
4179 | case DW_MACRO_GNU_undef_indirect: | |
f6f0e17b | 4180 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4181 | curr += bytes_read; |
0c588247 | 4182 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 JJ |
4183 | string = fetch_indirect_string (offset); |
4184 | printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"), | |
4185 | lineno, string); | |
4186 | break; | |
4187 | ||
4188 | case DW_MACRO_GNU_transparent_include: | |
0c588247 | 4189 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 JJ |
4190 | printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"), |
4191 | (unsigned long) offset); | |
4192 | break; | |
4193 | ||
a081f3cd | 4194 | case DW_MACRO_GNU_define_indirect_alt: |
f6f0e17b | 4195 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 4196 | curr += bytes_read; |
0c588247 | 4197 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
a081f3cd JJ |
4198 | printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"), |
4199 | lineno, (unsigned long) offset); | |
4200 | break; | |
4201 | ||
4202 | case DW_MACRO_GNU_undef_indirect_alt: | |
f6f0e17b | 4203 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 4204 | curr += bytes_read; |
0c588247 | 4205 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
a081f3cd JJ |
4206 | printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"), |
4207 | lineno, (unsigned long) offset); | |
4208 | break; | |
4209 | ||
4210 | case DW_MACRO_GNU_transparent_include_alt: | |
0c588247 | 4211 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
a081f3cd JJ |
4212 | printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"), |
4213 | (unsigned long) offset); | |
4214 | break; | |
4215 | ||
4ccf1e31 JJ |
4216 | default: |
4217 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
4218 | { | |
4219 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
4220 | return 0; | |
4221 | } | |
4222 | else | |
4223 | { | |
4224 | /* Skip over unhandled opcodes. */ | |
4225 | dwarf_vma nargs, n; | |
4226 | unsigned char *desc = extended_ops[op]; | |
f6f0e17b | 4227 | nargs = read_uleb128 (desc, &bytes_read, end); |
4ccf1e31 JJ |
4228 | desc += bytes_read; |
4229 | if (nargs == 0) | |
4230 | { | |
4231 | printf (_(" DW_MACRO_GNU_%02x\n"), op); | |
4232 | break; | |
4233 | } | |
4234 | printf (_(" DW_MACRO_GNU_%02x -"), op); | |
4235 | for (n = 0; n < nargs; n++) | |
4236 | { | |
0c588247 NC |
4237 | int val; |
4238 | ||
4239 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); | |
4ccf1e31 | 4240 | curr |
0c588247 | 4241 | = read_and_display_attr_value (0, val, |
f6f0e17b | 4242 | curr, end, 0, 0, offset_size, |
341f9135 CC |
4243 | version, NULL, 0, NULL, |
4244 | NULL); | |
4ccf1e31 JJ |
4245 | if (n != nargs - 1) |
4246 | printf (","); | |
4247 | } | |
4248 | printf ("\n"); | |
4249 | } | |
4250 | break; | |
4251 | } | |
4252 | } | |
4253 | ||
4254 | printf ("\n"); | |
4255 | } | |
4256 | ||
4257 | return 1; | |
4258 | } | |
4259 | ||
19e6b90e L |
4260 | static int |
4261 | display_debug_abbrev (struct dwarf_section *section, | |
4262 | void *file ATTRIBUTE_UNUSED) | |
4263 | { | |
4264 | abbrev_entry *entry; | |
4265 | unsigned char *start = section->start; | |
4266 | unsigned char *end = start + section->size; | |
4267 | ||
4268 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4269 | ||
4270 | do | |
4271 | { | |
7282333f AM |
4272 | unsigned char *last; |
4273 | ||
19e6b90e L |
4274 | free_abbrevs (); |
4275 | ||
7282333f | 4276 | last = start; |
19e6b90e L |
4277 | start = process_abbrev_section (start, end); |
4278 | ||
4279 | if (first_abbrev == NULL) | |
4280 | continue; | |
4281 | ||
7282333f | 4282 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
4283 | |
4284 | for (entry = first_abbrev; entry; entry = entry->next) | |
4285 | { | |
4286 | abbrev_attr *attr; | |
4287 | ||
cc5914eb | 4288 | printf (" %ld %s [%s]\n", |
19e6b90e L |
4289 | entry->entry, |
4290 | get_TAG_name (entry->tag), | |
4291 | entry->children ? _("has children") : _("no children")); | |
4292 | ||
4293 | for (attr = entry->first_attr; attr; attr = attr->next) | |
cc5914eb | 4294 | printf (" %-18s %s\n", |
19e6b90e L |
4295 | get_AT_name (attr->attribute), |
4296 | get_FORM_name (attr->form)); | |
4297 | } | |
4298 | } | |
4299 | while (start); | |
4300 | ||
4301 | printf ("\n"); | |
4302 | ||
4303 | return 1; | |
4304 | } | |
4305 | ||
4723351a CC |
4306 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
4307 | ||
4308 | static void | |
4309 | display_loc_list (struct dwarf_section *section, | |
4310 | unsigned char **start_ptr, | |
82b1b41b | 4311 | unsigned int debug_info_entry, |
4723351a CC |
4312 | unsigned long offset, |
4313 | unsigned long base_address, | |
4314 | int has_frame_base) | |
4315 | { | |
4316 | unsigned char *start = *start_ptr; | |
4317 | unsigned char *section_end = section->start + section->size; | |
82b1b41b NC |
4318 | unsigned long cu_offset; |
4319 | unsigned int pointer_size; | |
4320 | unsigned int offset_size; | |
4321 | int dwarf_version; | |
4723351a CC |
4322 | |
4323 | dwarf_vma begin; | |
4324 | dwarf_vma end; | |
4325 | unsigned short length; | |
4326 | int need_frame_base; | |
4327 | ||
82b1b41b NC |
4328 | if (debug_info_entry >= num_debug_info_entries) |
4329 | { | |
4330 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
4331 | debug_info_entry); | |
4332 | return; | |
4333 | } | |
4334 | ||
4335 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
4336 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
4337 | offset_size = debug_information [debug_info_entry].offset_size; | |
4338 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
4339 | ||
f41e4712 NC |
4340 | if (pointer_size < 2 || pointer_size > 8) |
4341 | { | |
4342 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
4343 | pointer_size, debug_info_entry); | |
4344 | return; | |
4345 | } | |
4346 | ||
4723351a CC |
4347 | while (1) |
4348 | { | |
4349 | if (start + 2 * pointer_size > section_end) | |
4350 | { | |
4351 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
4352 | offset); | |
4353 | break; | |
4354 | } | |
4355 | ||
fab128ef CC |
4356 | printf (" %8.8lx ", offset + (start - *start_ptr)); |
4357 | ||
4723351a CC |
4358 | /* Note: we use sign extension here in order to be sure that we can detect |
4359 | the -1 escape value. Sign extension into the top 32 bits of a 32-bit | |
4360 | address will not affect the values that we display since we always show | |
4361 | hex values, and always the bottom 32-bits. */ | |
0c588247 NC |
4362 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
4363 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 4364 | |
4723351a CC |
4365 | if (begin == 0 && end == 0) |
4366 | { | |
4367 | printf (_("<End of list>\n")); | |
4368 | break; | |
4369 | } | |
4370 | ||
4371 | /* Check base address specifiers. */ | |
4372 | if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1) | |
4373 | { | |
4374 | base_address = end; | |
4375 | print_dwarf_vma (begin, pointer_size); | |
4376 | print_dwarf_vma (end, pointer_size); | |
4377 | printf (_("(base address)\n")); | |
4378 | continue; | |
4379 | } | |
4380 | ||
4381 | if (start + 2 > section_end) | |
4382 | { | |
4383 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
4384 | offset); | |
4385 | break; | |
4386 | } | |
4387 | ||
0c588247 | 4388 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
4389 | |
4390 | if (start + length > section_end) | |
4391 | { | |
4392 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
4393 | offset); | |
4394 | break; | |
4395 | } | |
4396 | ||
4397 | print_dwarf_vma (begin + base_address, pointer_size); | |
4398 | print_dwarf_vma (end + base_address, pointer_size); | |
4399 | ||
4400 | putchar ('('); | |
4401 | need_frame_base = decode_location_expression (start, | |
4402 | pointer_size, | |
4403 | offset_size, | |
4404 | dwarf_version, | |
4405 | length, | |
4406 | cu_offset, section); | |
4407 | putchar (')'); | |
4408 | ||
4409 | if (need_frame_base && !has_frame_base) | |
4410 | printf (_(" [without DW_AT_frame_base]")); | |
4411 | ||
4412 | if (begin == end) | |
4413 | fputs (_(" (start == end)"), stdout); | |
4414 | else if (begin > end) | |
4415 | fputs (_(" (start > end)"), stdout); | |
4416 | ||
4417 | putchar ('\n'); | |
4418 | ||
4419 | start += length; | |
4420 | } | |
4421 | ||
4422 | *start_ptr = start; | |
4423 | } | |
4424 | ||
fab128ef CC |
4425 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
4426 | right-adjusted in a field of length LEN, and followed by a space. */ | |
4427 | ||
4428 | static void | |
4429 | print_addr_index (unsigned int idx, unsigned int len) | |
4430 | { | |
4431 | static char buf[15]; | |
4432 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 4433 | printf ("%*s ", len, buf); |
fab128ef CC |
4434 | } |
4435 | ||
4723351a CC |
4436 | /* Display a location list from a .dwo section. It uses address indexes rather |
4437 | than embedded addresses. This code closely follows display_loc_list, but the | |
4438 | two are sufficiently different that combining things is very ugly. */ | |
4439 | ||
4440 | static void | |
4441 | display_loc_list_dwo (struct dwarf_section *section, | |
4442 | unsigned char **start_ptr, | |
82b1b41b | 4443 | unsigned int debug_info_entry, |
4723351a CC |
4444 | unsigned long offset, |
4445 | int has_frame_base) | |
4446 | { | |
4447 | unsigned char *start = *start_ptr; | |
4448 | unsigned char *section_end = section->start + section->size; | |
82b1b41b NC |
4449 | unsigned long cu_offset; |
4450 | unsigned int pointer_size; | |
4451 | unsigned int offset_size; | |
4452 | int dwarf_version; | |
4723351a CC |
4453 | int entry_type; |
4454 | unsigned short length; | |
4455 | int need_frame_base; | |
fab128ef | 4456 | unsigned int idx; |
4723351a CC |
4457 | unsigned int bytes_read; |
4458 | ||
82b1b41b NC |
4459 | if (debug_info_entry >= num_debug_info_entries) |
4460 | { | |
4461 | warn (_("No debug information for loc lists of entry: %u\n"), | |
4462 | debug_info_entry); | |
4463 | return; | |
4464 | } | |
4465 | ||
4466 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
4467 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
4468 | offset_size = debug_information [debug_info_entry].offset_size; | |
4469 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
4470 | ||
f41e4712 NC |
4471 | if (pointer_size < 2 || pointer_size > 8) |
4472 | { | |
4473 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
4474 | pointer_size, debug_info_entry); | |
4475 | return; | |
4476 | } | |
4477 | ||
4723351a CC |
4478 | while (1) |
4479 | { | |
fab128ef | 4480 | printf (" %8.8lx ", offset + (start - *start_ptr)); |
4723351a | 4481 | |
fab128ef | 4482 | if (start >= section_end) |
4723351a CC |
4483 | { |
4484 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
4485 | offset); | |
4486 | break; | |
4487 | } | |
4488 | ||
0c588247 | 4489 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
4723351a CC |
4490 | switch (entry_type) |
4491 | { | |
4492 | case 0: /* A terminating entry. */ | |
4723351a | 4493 | *start_ptr = start; |
fab128ef | 4494 | printf (_("<End of list>\n")); |
4723351a CC |
4495 | return; |
4496 | case 1: /* A base-address entry. */ | |
f6f0e17b | 4497 | idx = read_uleb128 (start, &bytes_read, section_end); |
4723351a | 4498 | start += bytes_read; |
fab128ef CC |
4499 | print_addr_index (idx, 8); |
4500 | printf (" "); | |
4501 | printf (_("(base address selection entry)\n")); | |
4723351a | 4502 | continue; |
fab128ef | 4503 | case 2: /* A start/end entry. */ |
f6f0e17b | 4504 | idx = read_uleb128 (start, &bytes_read, section_end); |
fab128ef CC |
4505 | start += bytes_read; |
4506 | print_addr_index (idx, 8); | |
f6f0e17b | 4507 | idx = read_uleb128 (start, &bytes_read, section_end); |
4723351a | 4508 | start += bytes_read; |
fab128ef CC |
4509 | print_addr_index (idx, 8); |
4510 | break; | |
4511 | case 3: /* A start/length entry. */ | |
f6f0e17b | 4512 | idx = read_uleb128 (start, &bytes_read, section_end); |
4723351a | 4513 | start += bytes_read; |
fab128ef | 4514 | print_addr_index (idx, 8); |
0c588247 | 4515 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); |
fab128ef CC |
4516 | printf ("%08x ", idx); |
4517 | break; | |
4518 | case 4: /* An offset pair entry. */ | |
0c588247 | 4519 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); |
fab128ef | 4520 | printf ("%08x ", idx); |
0c588247 | 4521 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); |
fab128ef | 4522 | printf ("%08x ", idx); |
4723351a CC |
4523 | break; |
4524 | default: | |
fab128ef | 4525 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); |
4723351a CC |
4526 | *start_ptr = start; |
4527 | return; | |
4528 | } | |
4529 | ||
4530 | if (start + 2 > section_end) | |
4531 | { | |
4532 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
4533 | offset); | |
4534 | break; | |
4535 | } | |
4536 | ||
0c588247 | 4537 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
4538 | if (start + length > section_end) |
4539 | { | |
4540 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
4541 | offset); | |
4542 | break; | |
4543 | } | |
4544 | ||
4545 | putchar ('('); | |
4546 | need_frame_base = decode_location_expression (start, | |
4547 | pointer_size, | |
4548 | offset_size, | |
4549 | dwarf_version, | |
4550 | length, | |
4551 | cu_offset, section); | |
4552 | putchar (')'); | |
4553 | ||
4554 | if (need_frame_base && !has_frame_base) | |
4555 | printf (_(" [without DW_AT_frame_base]")); | |
4556 | ||
4557 | putchar ('\n'); | |
4558 | ||
4559 | start += length; | |
4560 | } | |
4561 | ||
4562 | *start_ptr = start; | |
4563 | } | |
4564 | ||
51d0d03f JJ |
4565 | /* Sort array of indexes in ascending order of loc_offsets[idx]. */ |
4566 | ||
4567 | static dwarf_vma *loc_offsets; | |
4568 | ||
4569 | static int | |
4570 | loc_offsets_compar (const void *ap, const void *bp) | |
4571 | { | |
4572 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
4573 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
4574 | ||
4575 | return (a > b) - (b > a); | |
4576 | } | |
4577 | ||
19e6b90e L |
4578 | static int |
4579 | display_debug_loc (struct dwarf_section *section, void *file) | |
4580 | { | |
4581 | unsigned char *start = section->start; | |
19e6b90e L |
4582 | unsigned long bytes; |
4583 | unsigned char *section_begin = start; | |
4584 | unsigned int num_loc_list = 0; | |
4585 | unsigned long last_offset = 0; | |
4586 | unsigned int first = 0; | |
4587 | unsigned int i; | |
4588 | unsigned int j; | |
51d0d03f | 4589 | unsigned int k; |
19e6b90e | 4590 | int seen_first_offset = 0; |
51d0d03f | 4591 | int locs_sorted = 1; |
19e6b90e | 4592 | unsigned char *next; |
51d0d03f | 4593 | unsigned int *array = NULL; |
4723351a CC |
4594 | const char *suffix = strrchr (section->name, '.'); |
4595 | int is_dwo = 0; | |
4596 | ||
4597 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
4598 | is_dwo = 1; | |
19e6b90e L |
4599 | |
4600 | bytes = section->size; | |
19e6b90e L |
4601 | |
4602 | if (bytes == 0) | |
4603 | { | |
4604 | printf (_("\nThe %s section is empty.\n"), section->name); | |
4605 | return 0; | |
4606 | } | |
4607 | ||
1febe64d NC |
4608 | if (load_debug_info (file) == 0) |
4609 | { | |
4610 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
4611 | section->name); | |
4612 | return 0; | |
4613 | } | |
19e6b90e L |
4614 | |
4615 | /* Check the order of location list in .debug_info section. If | |
4616 | offsets of location lists are in the ascending order, we can | |
4617 | use `debug_information' directly. */ | |
4618 | for (i = 0; i < num_debug_info_entries; i++) | |
4619 | { | |
4620 | unsigned int num; | |
4621 | ||
4622 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
4623 | if (num > num_loc_list) |
4624 | num_loc_list = num; | |
19e6b90e L |
4625 | |
4626 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 4627 | if (locs_sorted && num != 0) |
19e6b90e L |
4628 | { |
4629 | if (!seen_first_offset) | |
4630 | { | |
4631 | /* This is the first location list. */ | |
4632 | last_offset = debug_information [i].loc_offsets [0]; | |
4633 | first = i; | |
4634 | seen_first_offset = 1; | |
4635 | j = 1; | |
4636 | } | |
4637 | else | |
4638 | j = 0; | |
4639 | ||
4640 | for (; j < num; j++) | |
4641 | { | |
4642 | if (last_offset > | |
4643 | debug_information [i].loc_offsets [j]) | |
4644 | { | |
51d0d03f | 4645 | locs_sorted = 0; |
19e6b90e L |
4646 | break; |
4647 | } | |
4648 | last_offset = debug_information [i].loc_offsets [j]; | |
4649 | } | |
4650 | } | |
4651 | } | |
4652 | ||
19e6b90e L |
4653 | if (!seen_first_offset) |
4654 | error (_("No location lists in .debug_info section!\n")); | |
4655 | ||
d4bfc77b | 4656 | if (debug_information [first].num_loc_offsets > 0 |
d493b283 | 4657 | && debug_information [first].loc_offsets [0] != 0) |
47704ddf KT |
4658 | warn (_("Location lists in %s section start at 0x%s\n"), |
4659 | section->name, | |
4660 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 4661 | |
51d0d03f JJ |
4662 | if (!locs_sorted) |
4663 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
19e6b90e | 4664 | printf (_("Contents of the %s section:\n\n"), section->name); |
fab128ef | 4665 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
4666 | |
4667 | seen_first_offset = 0; | |
4668 | for (i = first; i < num_debug_info_entries; i++) | |
4669 | { | |
19e6b90e | 4670 | unsigned long offset; |
19e6b90e | 4671 | unsigned long base_address; |
19e6b90e L |
4672 | int has_frame_base; |
4673 | ||
51d0d03f JJ |
4674 | if (!locs_sorted) |
4675 | { | |
4676 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
4677 | array[k] = k; | |
4678 | loc_offsets = debug_information [i].loc_offsets; | |
4679 | qsort (array, debug_information [i].num_loc_offsets, | |
4680 | sizeof (*array), loc_offsets_compar); | |
4681 | } | |
19e6b90e | 4682 | |
51d0d03f | 4683 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 4684 | { |
51d0d03f JJ |
4685 | j = locs_sorted ? k : array[k]; |
4686 | if (k | |
4687 | && debug_information [i].loc_offsets [locs_sorted | |
4688 | ? k - 1 : array [k - 1]] | |
4689 | == debug_information [i].loc_offsets [j]) | |
4690 | continue; | |
19e6b90e | 4691 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 4692 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e L |
4693 | next = section_begin + offset; |
4694 | base_address = debug_information [i].base_address; | |
4695 | ||
4696 | if (!seen_first_offset) | |
4697 | seen_first_offset = 1; | |
4698 | else | |
4699 | { | |
4700 | if (start < next) | |
4701 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e AM |
4702 | (unsigned long) (start - section_begin), |
4703 | (unsigned long) (next - section_begin)); | |
19e6b90e L |
4704 | else if (start > next) |
4705 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e AM |
4706 | (unsigned long) (start - section_begin), |
4707 | (unsigned long) (next - section_begin)); | |
19e6b90e L |
4708 | } |
4709 | start = next; | |
4710 | ||
4711 | if (offset >= bytes) | |
4712 | { | |
4713 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
4714 | offset); | |
4715 | continue; | |
4716 | } | |
4717 | ||
4723351a CC |
4718 | if (is_dwo) |
4719 | display_loc_list_dwo (section, &start, i, offset, has_frame_base); | |
4720 | else | |
4721 | display_loc_list (section, &start, i, offset, base_address, | |
4722 | has_frame_base); | |
19e6b90e L |
4723 | } |
4724 | } | |
031cd65f | 4725 | |
4723351a | 4726 | if (start < section->start + section->size) |
031cd65f | 4727 | warn (_("There are %ld unused bytes at the end of section %s\n"), |
4723351a | 4728 | (long) (section->start + section->size - start), section->name); |
98fb390a | 4729 | putchar ('\n'); |
51d0d03f | 4730 | free (array); |
19e6b90e L |
4731 | return 1; |
4732 | } | |
4733 | ||
4734 | static int | |
4735 | display_debug_str (struct dwarf_section *section, | |
4736 | void *file ATTRIBUTE_UNUSED) | |
4737 | { | |
4738 | unsigned char *start = section->start; | |
4739 | unsigned long bytes = section->size; | |
4740 | dwarf_vma addr = section->address; | |
4741 | ||
4742 | if (bytes == 0) | |
4743 | { | |
4744 | printf (_("\nThe %s section is empty.\n"), section->name); | |
4745 | return 0; | |
4746 | } | |
4747 | ||
4748 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4749 | ||
4750 | while (bytes) | |
4751 | { | |
4752 | int j; | |
4753 | int k; | |
4754 | int lbytes; | |
4755 | ||
4756 | lbytes = (bytes > 16 ? 16 : bytes); | |
4757 | ||
4758 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
4759 | ||
4760 | for (j = 0; j < 16; j++) | |
4761 | { | |
4762 | if (j < lbytes) | |
4763 | printf ("%2.2x", start[j]); | |
4764 | else | |
4765 | printf (" "); | |
4766 | ||
4767 | if ((j & 3) == 3) | |
4768 | printf (" "); | |
4769 | } | |
4770 | ||
4771 | for (j = 0; j < lbytes; j++) | |
4772 | { | |
4773 | k = start[j]; | |
4774 | if (k >= ' ' && k < 0x80) | |
4775 | printf ("%c", k); | |
4776 | else | |
4777 | printf ("."); | |
4778 | } | |
4779 | ||
4780 | putchar ('\n'); | |
4781 | ||
4782 | start += lbytes; | |
4783 | addr += lbytes; | |
4784 | bytes -= lbytes; | |
4785 | } | |
4786 | ||
4787 | putchar ('\n'); | |
4788 | ||
4789 | return 1; | |
4790 | } | |
4791 | ||
19e6b90e L |
4792 | static int |
4793 | display_debug_info (struct dwarf_section *section, void *file) | |
4794 | { | |
4723351a | 4795 | return process_debug_info (section, file, section->abbrev_sec, 0, 0); |
19e6b90e L |
4796 | } |
4797 | ||
2b6f5997 CC |
4798 | static int |
4799 | display_debug_types (struct dwarf_section *section, void *file) | |
4800 | { | |
4723351a | 4801 | return process_debug_info (section, file, section->abbrev_sec, 0, 1); |
6f875884 TG |
4802 | } |
4803 | ||
4804 | static int | |
4805 | display_trace_info (struct dwarf_section *section, void *file) | |
4806 | { | |
4723351a | 4807 | return process_debug_info (section, file, section->abbrev_sec, 0, 0); |
2b6f5997 | 4808 | } |
19e6b90e L |
4809 | |
4810 | static int | |
4811 | display_debug_aranges (struct dwarf_section *section, | |
4812 | void *file ATTRIBUTE_UNUSED) | |
4813 | { | |
4814 | unsigned char *start = section->start; | |
4815 | unsigned char *end = start + section->size; | |
4816 | ||
80c35038 | 4817 | printf (_("Contents of the %s section:\n\n"), section->name); |
19e6b90e | 4818 | |
6e3d6dc1 NC |
4819 | /* It does not matter if this load fails, |
4820 | we test for that later on. */ | |
4821 | load_debug_info (file); | |
4822 | ||
19e6b90e L |
4823 | while (start < end) |
4824 | { | |
4825 | unsigned char *hdrptr; | |
4826 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 4827 | unsigned char *addr_ranges; |
2d9472a2 NC |
4828 | dwarf_vma length; |
4829 | dwarf_vma address; | |
53b8873b | 4830 | unsigned char address_size; |
19e6b90e | 4831 | int excess; |
bf5117e3 NC |
4832 | unsigned int offset_size; |
4833 | unsigned int initial_length_size; | |
19e6b90e L |
4834 | |
4835 | hdrptr = start; | |
4836 | ||
0c588247 | 4837 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
4838 | if (arange.ar_length == 0xffffffff) |
4839 | { | |
0c588247 | 4840 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
4841 | offset_size = 8; |
4842 | initial_length_size = 12; | |
4843 | } | |
4844 | else | |
4845 | { | |
4846 | offset_size = 4; | |
4847 | initial_length_size = 4; | |
4848 | } | |
4849 | ||
0c588247 NC |
4850 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
4851 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 4852 | |
6e3d6dc1 NC |
4853 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
4854 | && num_debug_info_entries > 0 | |
4855 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
4856 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 4857 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 4858 | |
0c588247 NC |
4859 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
4860 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
4861 | |
4862 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
4863 | { | |
4864 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
4865 | break; | |
4866 | } | |
4867 | ||
47704ddf KT |
4868 | printf (_(" Length: %ld\n"), |
4869 | (long) arange.ar_length); | |
19e6b90e | 4870 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
4871 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
4872 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
4873 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
4874 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
4875 | ||
53b8873b NC |
4876 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
4877 | ||
f41e4712 NC |
4878 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
4879 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
4880 | { |
4881 | error (_("Invalid address size in %s section!\n"), | |
4882 | section->name); | |
4883 | break; | |
4884 | } | |
4885 | ||
53b8873b NC |
4886 | /* The DWARF spec does not require that the address size be a power |
4887 | of two, but we do. This will have to change if we ever encounter | |
4888 | an uneven architecture. */ | |
4889 | if ((address_size & (address_size - 1)) != 0) | |
4890 | { | |
4891 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
4892 | break; | |
4893 | } | |
cecf136e | 4894 | |
209c9a13 NC |
4895 | if (address_size > 4) |
4896 | printf (_("\n Address Length\n")); | |
4897 | else | |
4898 | printf (_("\n Address Length\n")); | |
19e6b90e | 4899 | |
91d6fa6a | 4900 | addr_ranges = hdrptr; |
19e6b90e | 4901 | |
53b8873b NC |
4902 | /* Must pad to an alignment boundary that is twice the address size. */ |
4903 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 4904 | if (excess) |
91d6fa6a | 4905 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 4906 | |
1617e571 AM |
4907 | start += arange.ar_length + initial_length_size; |
4908 | ||
91d6fa6a | 4909 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 4910 | { |
0c588247 NC |
4911 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
4912 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 4913 | |
80c35038 | 4914 | printf (" "); |
2d9472a2 NC |
4915 | print_dwarf_vma (address, address_size); |
4916 | print_dwarf_vma (length, address_size); | |
4917 | putchar ('\n'); | |
19e6b90e | 4918 | } |
19e6b90e L |
4919 | } |
4920 | ||
4921 | printf ("\n"); | |
4922 | ||
4923 | return 1; | |
4924 | } | |
4925 | ||
4723351a CC |
4926 | /* Comparison function for qsort. */ |
4927 | static int | |
4928 | comp_addr_base (const void * v0, const void * v1) | |
4929 | { | |
4930 | debug_info * info0 = (debug_info *) v0; | |
4931 | debug_info * info1 = (debug_info *) v1; | |
4932 | return info0->addr_base - info1->addr_base; | |
4933 | } | |
4934 | ||
4935 | /* Display the debug_addr section. */ | |
4936 | static int | |
4937 | display_debug_addr (struct dwarf_section *section, | |
4938 | void *file) | |
4939 | { | |
4940 | debug_info **debug_addr_info; | |
4941 | unsigned char *entry; | |
4942 | unsigned char *end; | |
4943 | unsigned int i; | |
4944 | unsigned int count; | |
4945 | ||
4946 | if (section->size == 0) | |
4947 | { | |
4948 | printf (_("\nThe %s section is empty.\n"), section->name); | |
4949 | return 0; | |
4950 | } | |
4951 | ||
4952 | if (load_debug_info (file) == 0) | |
4953 | { | |
4954 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
4955 | section->name); | |
4956 | return 0; | |
4957 | } | |
4958 | ||
4959 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4960 | ||
1306a742 NC |
4961 | /* PR 17531: file: cf38d01b. |
4962 | We use xcalloc because a corrupt file may not have initialised all of the | |
4963 | fields in the debug_info structure, which means that the sort below might | |
4964 | try to move uninitialised data. */ | |
4965 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
4966 | sizeof (debug_info *)); | |
4723351a CC |
4967 | |
4968 | count = 0; | |
4969 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 4970 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
4971 | { |
4972 | /* PR 17531: file: cf38d01b. */ | |
4973 | if (debug_information[i].addr_base >= section->size) | |
4974 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
4975 | (unsigned long) debug_information[i].addr_base, i); | |
4976 | else | |
4977 | debug_addr_info [count++] = debug_information + i; | |
4978 | } | |
4723351a CC |
4979 | |
4980 | /* Add a sentinel to make iteration convenient. */ | |
4981 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
4982 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 4983 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 4984 | |
4723351a CC |
4985 | for (i = 0; i < count; i++) |
4986 | { | |
4987 | unsigned int idx; | |
fab128ef | 4988 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
4989 | |
4990 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
4991 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); | |
4992 | ||
fab128ef | 4993 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
4994 | entry = section->start + debug_addr_info [i]->addr_base; |
4995 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
4996 | idx = 0; | |
4997 | while (entry < end) | |
4998 | { | |
fab128ef CC |
4999 | dwarf_vma base = byte_get (entry, address_size); |
5000 | printf (_("\t%d:\t"), idx); | |
5001 | print_dwarf_vma (base, address_size); | |
5002 | printf ("\n"); | |
5003 | entry += address_size; | |
4723351a CC |
5004 | idx++; |
5005 | } | |
5006 | } | |
5007 | printf ("\n"); | |
5008 | ||
5009 | free (debug_addr_info); | |
5010 | return 1; | |
5011 | } | |
5012 | ||
5013 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
5014 | static int | |
5015 | display_debug_str_offsets (struct dwarf_section *section, | |
5016 | void *file ATTRIBUTE_UNUSED) | |
5017 | { | |
5018 | if (section->size == 0) | |
5019 | { | |
5020 | printf (_("\nThe %s section is empty.\n"), section->name); | |
5021 | return 0; | |
5022 | } | |
5023 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
5024 | what the offset size is for this section. */ | |
5025 | return 1; | |
5026 | } | |
5027 | ||
01a8f077 JK |
5028 | /* Each debug_information[x].range_lists[y] gets this representation for |
5029 | sorting purposes. */ | |
5030 | ||
5031 | struct range_entry | |
467c65bc NC |
5032 | { |
5033 | /* The debug_information[x].range_lists[y] value. */ | |
5034 | unsigned long ranges_offset; | |
01a8f077 | 5035 | |
467c65bc NC |
5036 | /* Original debug_information to find parameters of the data. */ |
5037 | debug_info *debug_info_p; | |
5038 | }; | |
01a8f077 JK |
5039 | |
5040 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
5041 | ||
5042 | static int | |
5043 | range_entry_compar (const void *ap, const void *bp) | |
5044 | { | |
3f5e193b NC |
5045 | const struct range_entry *a_re = (const struct range_entry *) ap; |
5046 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
01a8f077 JK |
5047 | const unsigned long a = a_re->ranges_offset; |
5048 | const unsigned long b = b_re->ranges_offset; | |
5049 | ||
5050 | return (a > b) - (b > a); | |
5051 | } | |
5052 | ||
19e6b90e L |
5053 | static int |
5054 | display_debug_ranges (struct dwarf_section *section, | |
5055 | void *file ATTRIBUTE_UNUSED) | |
5056 | { | |
5057 | unsigned char *start = section->start; | |
a2ff7a4b | 5058 | unsigned char *last_start = start; |
f6f0e17b | 5059 | unsigned long bytes = section->size; |
19e6b90e | 5060 | unsigned char *section_begin = start; |
f6f0e17b | 5061 | unsigned char *finish = start + bytes; |
01a8f077 JK |
5062 | unsigned int num_range_list, i; |
5063 | struct range_entry *range_entries, *range_entry_fill; | |
19e6b90e | 5064 | |
19e6b90e L |
5065 | if (bytes == 0) |
5066 | { | |
5067 | printf (_("\nThe %s section is empty.\n"), section->name); | |
5068 | return 0; | |
5069 | } | |
5070 | ||
1febe64d NC |
5071 | if (load_debug_info (file) == 0) |
5072 | { | |
5073 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
5074 | section->name); | |
5075 | return 0; | |
5076 | } | |
19e6b90e | 5077 | |
01a8f077 | 5078 | num_range_list = 0; |
19e6b90e | 5079 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 5080 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 5081 | |
01a8f077 | 5082 | if (num_range_list == 0) |
4723351a CC |
5083 | { |
5084 | /* This can happen when the file was compiled with -gsplit-debug | |
5085 | which removes references to range lists from the primary .o file. */ | |
5086 | printf (_("No range lists in .debug_info section.\n")); | |
5087 | return 1; | |
5088 | } | |
19e6b90e | 5089 | |
3f5e193b NC |
5090 | range_entries = (struct range_entry *) |
5091 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 5092 | range_entry_fill = range_entries; |
19e6b90e | 5093 | |
01a8f077 JK |
5094 | for (i = 0; i < num_debug_info_entries; i++) |
5095 | { | |
5096 | debug_info *debug_info_p = &debug_information[i]; | |
5097 | unsigned int j; | |
5098 | ||
5099 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
5100 | { | |
5101 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
5102 | range_entry_fill->debug_info_p = debug_info_p; | |
5103 | range_entry_fill++; | |
19e6b90e L |
5104 | } |
5105 | } | |
5106 | ||
01a8f077 JK |
5107 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
5108 | range_entry_compar); | |
19e6b90e | 5109 | |
d493b283 | 5110 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 5111 | warn (_("Range lists in %s section start at 0x%lx\n"), |
01a8f077 | 5112 | section->name, range_entries[0].ranges_offset); |
19e6b90e L |
5113 | |
5114 | printf (_("Contents of the %s section:\n\n"), section->name); | |
5115 | printf (_(" Offset Begin End\n")); | |
5116 | ||
01a8f077 | 5117 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 5118 | { |
01a8f077 JK |
5119 | struct range_entry *range_entry = &range_entries[i]; |
5120 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 5121 | unsigned int pointer_size; |
01a8f077 JK |
5122 | unsigned long offset; |
5123 | unsigned char *next; | |
19e6b90e L |
5124 | unsigned long base_address; |
5125 | ||
01a8f077 | 5126 | pointer_size = debug_info_p->pointer_size; |
d493b283 | 5127 | offset = range_entry->ranges_offset; |
01a8f077 JK |
5128 | next = section_begin + offset; |
5129 | base_address = debug_info_p->base_address; | |
cecf136e | 5130 | |
f41e4712 NC |
5131 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
5132 | if (pointer_size < 2 || pointer_size > 8) | |
5133 | { | |
5134 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
5135 | pointer_size, offset); | |
5136 | continue; | |
5137 | } | |
5138 | ||
4723351a | 5139 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 5140 | { |
01a8f077 JK |
5141 | if (start < next) |
5142 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
5143 | (unsigned long) (start - section_begin), | |
5144 | (unsigned long) (next - section_begin), section->name); | |
5145 | else if (start > next) | |
a2ff7a4b AM |
5146 | { |
5147 | if (next == last_start) | |
5148 | continue; | |
5149 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
5150 | (unsigned long) (start - section_begin), | |
5151 | (unsigned long) (next - section_begin), section->name); | |
5152 | } | |
01a8f077 JK |
5153 | } |
5154 | start = next; | |
a2ff7a4b | 5155 | last_start = next; |
19e6b90e | 5156 | |
f6f0e17b | 5157 | while (start < finish) |
01a8f077 JK |
5158 | { |
5159 | dwarf_vma begin; | |
5160 | dwarf_vma end; | |
5161 | ||
5162 | /* Note: we use sign extension here in order to be sure that | |
5163 | we can detect the -1 escape value. Sign extension into the | |
5164 | top 32 bits of a 32-bit address will not affect the values | |
5165 | that we display since we always show hex values, and always | |
5166 | the bottom 32-bits. */ | |
0c588247 | 5167 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); |
f6f0e17b NC |
5168 | if (start >= finish) |
5169 | break; | |
0c588247 | 5170 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); |
01a8f077 JK |
5171 | |
5172 | printf (" %8.8lx ", offset); | |
5173 | ||
5174 | if (begin == 0 && end == 0) | |
19e6b90e | 5175 | { |
01a8f077 JK |
5176 | printf (_("<End of list>\n")); |
5177 | break; | |
19e6b90e | 5178 | } |
19e6b90e | 5179 | |
01a8f077 JK |
5180 | /* Check base address specifiers. */ |
5181 | if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1) | |
19e6b90e | 5182 | { |
01a8f077 JK |
5183 | base_address = end; |
5184 | print_dwarf_vma (begin, pointer_size); | |
5185 | print_dwarf_vma (end, pointer_size); | |
5186 | printf ("(base address)\n"); | |
5187 | continue; | |
5188 | } | |
19e6b90e | 5189 | |
01a8f077 JK |
5190 | print_dwarf_vma (begin + base_address, pointer_size); |
5191 | print_dwarf_vma (end + base_address, pointer_size); | |
4a149252 | 5192 | |
01a8f077 JK |
5193 | if (begin == end) |
5194 | fputs (_("(start == end)"), stdout); | |
5195 | else if (begin > end) | |
5196 | fputs (_("(start > end)"), stdout); | |
19e6b90e | 5197 | |
01a8f077 | 5198 | putchar ('\n'); |
19e6b90e L |
5199 | } |
5200 | } | |
5201 | putchar ('\n'); | |
01a8f077 JK |
5202 | |
5203 | free (range_entries); | |
5204 | ||
19e6b90e L |
5205 | return 1; |
5206 | } | |
5207 | ||
5208 | typedef struct Frame_Chunk | |
5209 | { | |
5210 | struct Frame_Chunk *next; | |
5211 | unsigned char *chunk_start; | |
a1165289 | 5212 | unsigned int ncols; |
19e6b90e L |
5213 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
5214 | short int *col_type; | |
5215 | int *col_offset; | |
5216 | char *augmentation; | |
5217 | unsigned int code_factor; | |
5218 | int data_factor; | |
bf5117e3 NC |
5219 | dwarf_vma pc_begin; |
5220 | dwarf_vma pc_range; | |
19e6b90e L |
5221 | int cfa_reg; |
5222 | int cfa_offset; | |
a1165289 | 5223 | unsigned int ra; |
19e6b90e L |
5224 | unsigned char fde_encoding; |
5225 | unsigned char cfa_exp; | |
604282a7 JJ |
5226 | unsigned char ptr_size; |
5227 | unsigned char segment_size; | |
19e6b90e L |
5228 | } |
5229 | Frame_Chunk; | |
5230 | ||
665ce1f6 L |
5231 | static const char *const *dwarf_regnames; |
5232 | static unsigned int dwarf_regnames_count; | |
5233 | ||
19e6b90e L |
5234 | /* A marker for a col_type that means this column was never referenced |
5235 | in the frame info. */ | |
5236 | #define DW_CFA_unreferenced (-1) | |
5237 | ||
a1165289 | 5238 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
5239 | -1 for invalid reg. */ |
5240 | ||
5241 | static int | |
5242 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 5243 | { |
a1165289 | 5244 | unsigned int prev = fc->ncols; |
19e6b90e | 5245 | |
665ce1f6 L |
5246 | if (reg < (unsigned int) fc->ncols) |
5247 | return 0; | |
5248 | ||
5249 | if (dwarf_regnames_count | |
5250 | && reg > dwarf_regnames_count) | |
5251 | return -1; | |
19e6b90e L |
5252 | |
5253 | fc->ncols = reg + 1; | |
a1165289 NC |
5254 | /* PR 17512: file: 10450-2643-0.004. |
5255 | If reg == -1 then this can happen... */ | |
5256 | if (fc->ncols == 0) | |
5257 | return -1; | |
5258 | ||
06614111 NC |
5259 | /* PR 17512: file: 2844a11d. */ |
5260 | if (fc->ncols > 1024) | |
5261 | { | |
5262 | error (_("Unfeasibly large register number: %u\n"), reg); | |
5263 | fc->ncols = 0; | |
5264 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
5265 | we ever encounter a valid binary that exceeds it. */ | |
5266 | return -1; | |
5267 | } | |
5268 | ||
3f5e193b NC |
5269 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
5270 | sizeof (short int)); | |
5271 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); | |
041830e0 NC |
5272 | /* PR 17512: file:002-10025-0.005. */ |
5273 | if (fc->col_type == NULL || fc->col_offset == NULL) | |
5274 | { | |
5275 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
5276 | fc->ncols); | |
5277 | fc->ncols = 0; | |
5278 | return -1; | |
5279 | } | |
19e6b90e L |
5280 | |
5281 | while (prev < fc->ncols) | |
5282 | { | |
5283 | fc->col_type[prev] = DW_CFA_unreferenced; | |
5284 | fc->col_offset[prev] = 0; | |
5285 | prev++; | |
5286 | } | |
665ce1f6 | 5287 | return 1; |
19e6b90e L |
5288 | } |
5289 | ||
2dc4cec1 L |
5290 | static const char *const dwarf_regnames_i386[] = |
5291 | { | |
43234a1e L |
5292 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
5293 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
5294 | "eip", "eflags", NULL, /* 8 - 10 */ | |
5295 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
5296 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
5297 | NULL, NULL, /* 19 - 20 */ | |
5298 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
5299 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
5300 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
5301 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
5302 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
5303 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
5304 | "tr", "ldtr", /* 48 - 49 */ | |
5305 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
5306 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
5307 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
5308 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
5309 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
5310 | NULL, NULL, NULL, /* 90 - 92 */ | |
5311 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
5312 | }; |
5313 | ||
b129eb0e RH |
5314 | void |
5315 | init_dwarf_regnames_i386 (void) | |
5316 | { | |
5317 | dwarf_regnames = dwarf_regnames_i386; | |
5318 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
5319 | } | |
5320 | ||
2dc4cec1 L |
5321 | static const char *const dwarf_regnames_x86_64[] = |
5322 | { | |
5323 | "rax", "rdx", "rcx", "rbx", | |
5324 | "rsi", "rdi", "rbp", "rsp", | |
5325 | "r8", "r9", "r10", "r11", | |
5326 | "r12", "r13", "r14", "r15", | |
5327 | "rip", | |
5328 | "xmm0", "xmm1", "xmm2", "xmm3", | |
5329 | "xmm4", "xmm5", "xmm6", "xmm7", | |
5330 | "xmm8", "xmm9", "xmm10", "xmm11", | |
5331 | "xmm12", "xmm13", "xmm14", "xmm15", | |
5332 | "st0", "st1", "st2", "st3", | |
5333 | "st4", "st5", "st6", "st7", | |
5334 | "mm0", "mm1", "mm2", "mm3", | |
5335 | "mm4", "mm5", "mm6", "mm7", | |
5336 | "rflags", | |
5337 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
5338 | "fs.base", "gs.base", NULL, NULL, | |
5339 | "tr", "ldtr", | |
43234a1e L |
5340 | "mxcsr", "fcw", "fsw", |
5341 | "xmm16", "xmm17", "xmm18", "xmm19", | |
5342 | "xmm20", "xmm21", "xmm22", "xmm23", | |
5343 | "xmm24", "xmm25", "xmm26", "xmm27", | |
5344 | "xmm28", "xmm29", "xmm30", "xmm31", | |
5345 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
5346 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
5347 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
5348 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
5349 | NULL, NULL, NULL, /* 115 - 117 */ | |
5350 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
5351 | }; |
5352 | ||
b129eb0e RH |
5353 | void |
5354 | init_dwarf_regnames_x86_64 (void) | |
5355 | { | |
5356 | dwarf_regnames = dwarf_regnames_x86_64; | |
5357 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
5358 | } | |
5359 | ||
4ee22035 RH |
5360 | static const char *const dwarf_regnames_aarch64[] = |
5361 | { | |
5362 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", | |
5363 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
5364 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", | |
5365 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
5366 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
5367 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
5368 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
5369 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
5370 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", | |
5371 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
5372 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", | |
5373 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
5374 | }; | |
5375 | ||
5376 | void | |
5377 | init_dwarf_regnames_aarch64 (void) | |
5378 | { | |
5379 | dwarf_regnames = dwarf_regnames_aarch64; | |
5380 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
5381 | } | |
5382 | ||
2dc4cec1 L |
5383 | void |
5384 | init_dwarf_regnames (unsigned int e_machine) | |
5385 | { | |
5386 | switch (e_machine) | |
5387 | { | |
5388 | case EM_386: | |
5389 | case EM_486: | |
b129eb0e | 5390 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
5391 | break; |
5392 | ||
5393 | case EM_X86_64: | |
7f502d6c | 5394 | case EM_L1OM: |
7a9068fe | 5395 | case EM_K1OM: |
b129eb0e | 5396 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
5397 | break; |
5398 | ||
4ee22035 RH |
5399 | case EM_AARCH64: |
5400 | init_dwarf_regnames_aarch64 (); | |
5401 | break; | |
5402 | ||
2dc4cec1 L |
5403 | default: |
5404 | break; | |
5405 | } | |
5406 | } | |
5407 | ||
5408 | static const char * | |
5409 | regname (unsigned int regno, int row) | |
5410 | { | |
5411 | static char reg[64]; | |
5412 | if (dwarf_regnames | |
5413 | && regno < dwarf_regnames_count | |
5414 | && dwarf_regnames [regno] != NULL) | |
5415 | { | |
5416 | if (row) | |
5417 | return dwarf_regnames [regno]; | |
5418 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, | |
5419 | dwarf_regnames [regno]); | |
5420 | } | |
5421 | else | |
5422 | snprintf (reg, sizeof (reg), "r%d", regno); | |
5423 | return reg; | |
5424 | } | |
5425 | ||
19e6b90e | 5426 | static void |
a1165289 | 5427 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 5428 | { |
a1165289 | 5429 | unsigned int r; |
19e6b90e L |
5430 | char tmp[100]; |
5431 | ||
5432 | if (*max_regs < fc->ncols) | |
5433 | *max_regs = fc->ncols; | |
5434 | ||
5435 | if (*need_col_headers) | |
5436 | { | |
91d6fa6a | 5437 | static const char *sloc = " LOC"; |
2dc4cec1 | 5438 | |
19e6b90e L |
5439 | *need_col_headers = 0; |
5440 | ||
91d6fa6a | 5441 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
5442 | |
5443 | for (r = 0; r < *max_regs; r++) | |
5444 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
5445 | { | |
5446 | if (r == fc->ra) | |
2dc4cec1 | 5447 | printf ("ra "); |
19e6b90e | 5448 | else |
2dc4cec1 | 5449 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
5450 | } |
5451 | ||
5452 | printf ("\n"); | |
5453 | } | |
5454 | ||
bf5117e3 | 5455 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
5456 | if (fc->cfa_exp) |
5457 | strcpy (tmp, "exp"); | |
5458 | else | |
2dc4cec1 | 5459 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset); |
19e6b90e L |
5460 | printf ("%-8s ", tmp); |
5461 | ||
5462 | for (r = 0; r < fc->ncols; r++) | |
5463 | { | |
5464 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
5465 | { | |
5466 | switch (fc->col_type[r]) | |
5467 | { | |
5468 | case DW_CFA_undefined: | |
5469 | strcpy (tmp, "u"); | |
5470 | break; | |
5471 | case DW_CFA_same_value: | |
5472 | strcpy (tmp, "s"); | |
5473 | break; | |
5474 | case DW_CFA_offset: | |
5475 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
5476 | break; | |
12eae2d3 JJ |
5477 | case DW_CFA_val_offset: |
5478 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
5479 | break; | |
19e6b90e | 5480 | case DW_CFA_register: |
2dc4cec1 | 5481 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
5482 | break; |
5483 | case DW_CFA_expression: | |
5484 | strcpy (tmp, "exp"); | |
5485 | break; | |
12eae2d3 JJ |
5486 | case DW_CFA_val_expression: |
5487 | strcpy (tmp, "vexp"); | |
5488 | break; | |
19e6b90e L |
5489 | default: |
5490 | strcpy (tmp, "n/a"); | |
5491 | break; | |
5492 | } | |
2dc4cec1 | 5493 | printf ("%-5s ", tmp); |
19e6b90e L |
5494 | } |
5495 | } | |
5496 | printf ("\n"); | |
5497 | } | |
5498 | ||
49727e46 | 5499 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
f6f0e17b NC |
5500 | #define LEB() read_uleb128 (start, & length_return, end); start += length_return |
5501 | #define SLEB() read_sleb128 (start, & length_return, end); start += length_return | |
19e6b90e | 5502 | |
49727e46 AM |
5503 | static unsigned char * |
5504 | read_cie (unsigned char *start, unsigned char *end, | |
5505 | Frame_Chunk **p_cie, int *p_version, | |
5506 | unsigned long *p_aug_len, unsigned char **p_aug) | |
5507 | { | |
5508 | int version; | |
5509 | Frame_Chunk *fc; | |
5510 | unsigned int length_return; | |
5511 | unsigned char *augmentation_data = NULL; | |
5512 | unsigned long augmentation_data_len = 0; | |
5513 | ||
041830e0 | 5514 | * p_cie = NULL; |
f41e4712 NC |
5515 | /* PR 17512: file: 001-228113-0.004. */ |
5516 | if (start >= end) | |
5517 | return end; | |
5518 | ||
49727e46 AM |
5519 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
5520 | memset (fc, 0, sizeof (Frame_Chunk)); | |
5521 | ||
5522 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
5523 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
5524 | ||
5525 | version = *start++; | |
5526 | ||
5527 | fc->augmentation = (char *) start; | |
f41e4712 NC |
5528 | /* PR 17512: file: 001-228113-0.004. |
5529 | Skip past augmentation name, but avoid running off the end of the data. */ | |
5530 | while (start < end) | |
5531 | if (* start ++ == '\0') | |
5532 | break; | |
5533 | if (start == end) | |
5534 | { | |
5535 | warn (_("No terminator for augmentation name\n")); | |
5536 | return start; | |
5537 | } | |
49727e46 AM |
5538 | |
5539 | if (strcmp (fc->augmentation, "eh") == 0) | |
5540 | start += eh_addr_size; | |
5541 | ||
5542 | if (version >= 4) | |
5543 | { | |
5544 | GET (fc->ptr_size, 1); | |
5545 | GET (fc->segment_size, 1); | |
5546 | eh_addr_size = fc->ptr_size; | |
5547 | } | |
5548 | else | |
5549 | { | |
5550 | fc->ptr_size = eh_addr_size; | |
5551 | fc->segment_size = 0; | |
5552 | } | |
5553 | fc->code_factor = LEB (); | |
5554 | fc->data_factor = SLEB (); | |
5555 | if (version == 1) | |
5556 | { | |
5557 | GET (fc->ra, 1); | |
5558 | } | |
5559 | else | |
5560 | { | |
5561 | fc->ra = LEB (); | |
5562 | } | |
5563 | ||
5564 | if (fc->augmentation[0] == 'z') | |
5565 | { | |
5566 | augmentation_data_len = LEB (); | |
5567 | augmentation_data = start; | |
5568 | start += augmentation_data_len; | |
a1165289 NC |
5569 | /* PR 17512: file: 11042-2589-0.004. */ |
5570 | if (start > end) | |
5571 | { | |
1306a742 | 5572 | warn (_("Augmentation data too long: 0x%lx\n"), augmentation_data_len); |
a1165289 NC |
5573 | return end; |
5574 | } | |
49727e46 AM |
5575 | } |
5576 | ||
5577 | if (augmentation_data_len) | |
5578 | { | |
058037d3 NC |
5579 | unsigned char *p; |
5580 | unsigned char *q; | |
5581 | unsigned char *qend; | |
5582 | ||
49727e46 AM |
5583 | p = (unsigned char *) fc->augmentation + 1; |
5584 | q = augmentation_data; | |
058037d3 NC |
5585 | qend = q + augmentation_data_len; |
5586 | ||
5587 | /* PR 17531: file: 015adfaa. */ | |
5588 | if (qend < q) | |
5589 | { | |
5590 | warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len); | |
5591 | augmentation_data_len = 0; | |
5592 | } | |
49727e46 | 5593 | |
a1165289 | 5594 | while (p < end && q < augmentation_data + augmentation_data_len) |
49727e46 AM |
5595 | { |
5596 | if (*p == 'L') | |
5597 | q++; | |
5598 | else if (*p == 'P') | |
5599 | q += 1 + size_of_encoded_value (*q); | |
5600 | else if (*p == 'R') | |
5601 | fc->fde_encoding = *q++; | |
5602 | else if (*p == 'S') | |
5603 | ; | |
5604 | else | |
5605 | break; | |
5606 | p++; | |
5607 | } | |
c361b9ac NC |
5608 | /* Note - it is OK if this loop terminates with q < qend. |
5609 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
5610 | } |
5611 | ||
5612 | *p_cie = fc; | |
5613 | if (p_version) | |
5614 | *p_version = version; | |
5615 | if (p_aug_len) | |
5616 | { | |
5617 | *p_aug_len = augmentation_data_len; | |
5618 | *p_aug = augmentation_data; | |
5619 | } | |
5620 | return start; | |
5621 | } | |
5622 | ||
19e6b90e L |
5623 | static int |
5624 | display_debug_frames (struct dwarf_section *section, | |
5625 | void *file ATTRIBUTE_UNUSED) | |
5626 | { | |
5627 | unsigned char *start = section->start; | |
5628 | unsigned char *end = start + section->size; | |
5629 | unsigned char *section_start = start; | |
49727e46 | 5630 | Frame_Chunk *chunks = 0, *forward_refs = 0; |
19e6b90e L |
5631 | Frame_Chunk *remembered_state = 0; |
5632 | Frame_Chunk *rs; | |
5633 | int is_eh = strcmp (section->name, ".eh_frame") == 0; | |
5634 | unsigned int length_return; | |
a1165289 | 5635 | unsigned int max_regs = 0; |
665ce1f6 | 5636 | const char *bad_reg = _("bad register: "); |
604282a7 | 5637 | int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 5638 | |
80c35038 | 5639 | printf (_("Contents of the %s section:\n"), section->name); |
19e6b90e L |
5640 | |
5641 | while (start < end) | |
5642 | { | |
5643 | unsigned char *saved_start; | |
5644 | unsigned char *block_end; | |
bf5117e3 NC |
5645 | dwarf_vma length; |
5646 | dwarf_vma cie_id; | |
19e6b90e L |
5647 | Frame_Chunk *fc; |
5648 | Frame_Chunk *cie; | |
5649 | int need_col_headers = 1; | |
5650 | unsigned char *augmentation_data = NULL; | |
5651 | unsigned long augmentation_data_len = 0; | |
bf5117e3 NC |
5652 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
5653 | unsigned int offset_size; | |
5654 | unsigned int initial_length_size; | |
19e6b90e L |
5655 | |
5656 | saved_start = start; | |
19e6b90e | 5657 | |
0c588247 | 5658 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 5659 | |
19e6b90e L |
5660 | if (length == 0) |
5661 | { | |
5662 | printf ("\n%08lx ZERO terminator\n\n", | |
5663 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
5664 | /* Skip any zero terminators that directly follow. |
5665 | A corrupt section size could have loaded a whole | |
5666 | slew of zero filled memory bytes. eg | |
5667 | PR 17512: file: 070-19381-0.004. */ | |
5668 | while (start < end && * start == 0) | |
5669 | ++ start; | |
b758e50f | 5670 | continue; |
19e6b90e L |
5671 | } |
5672 | ||
5673 | if (length == 0xffffffff) | |
5674 | { | |
0c588247 | 5675 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
5676 | offset_size = 8; |
5677 | initial_length_size = 12; | |
5678 | } | |
5679 | else | |
5680 | { | |
5681 | offset_size = 4; | |
5682 | initial_length_size = 4; | |
5683 | } | |
5684 | ||
5685 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 5686 | if (block_end > end || block_end < start) |
53b8873b | 5687 | { |
bf5117e3 NC |
5688 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
5689 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
5690 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
5691 | block_end = end; |
5692 | } | |
0c588247 NC |
5693 | |
5694 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 5695 | |
846a11e4 NC |
5696 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
5697 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
5698 | { |
5699 | int version; | |
a1165289 | 5700 | unsigned int mreg; |
19e6b90e | 5701 | |
49727e46 AM |
5702 | start = read_cie (start, end, &cie, &version, |
5703 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
5704 | /* PR 17512: file: 027-135133-0.005. */ |
5705 | if (cie == NULL) | |
5706 | break; | |
a1165289 | 5707 | |
49727e46 | 5708 | fc = cie; |
19e6b90e L |
5709 | fc->next = chunks; |
5710 | chunks = fc; | |
5711 | fc->chunk_start = saved_start; | |
a1165289 | 5712 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
5713 | if (mreg < fc->ra) |
5714 | mreg = fc->ra; | |
06614111 NC |
5715 | if (frame_need_space (fc, mreg) < 0) |
5716 | break; | |
49727e46 AM |
5717 | if (fc->fde_encoding) |
5718 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 5719 | |
bf5117e3 NC |
5720 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
5721 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 5722 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 5723 | |
19e6b90e | 5724 | if (do_debug_frames_interp) |
bf5117e3 NC |
5725 | { |
5726 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
5727 | fc->code_factor, fc->data_factor, fc->ra); | |
5728 | } | |
19e6b90e L |
5729 | else |
5730 | { | |
bf5117e3 | 5731 | printf ("CIE\n"); |
19e6b90e L |
5732 | printf (" Version: %d\n", version); |
5733 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
5734 | if (version >= 4) |
5735 | { | |
5736 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
5737 | printf (" Segment Size: %u\n", fc->segment_size); | |
5738 | } | |
19e6b90e L |
5739 | printf (" Code alignment factor: %u\n", fc->code_factor); |
5740 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
5741 | printf (" Return address column: %d\n", fc->ra); | |
5742 | ||
5743 | if (augmentation_data_len) | |
5744 | { | |
5745 | unsigned long i; | |
a1165289 | 5746 | |
19e6b90e L |
5747 | printf (" Augmentation data: "); |
5748 | for (i = 0; i < augmentation_data_len; ++i) | |
a1165289 NC |
5749 | /* FIXME: If do_wide is FALSE, then we should |
5750 | add carriage returns at 80 columns... */ | |
19e6b90e L |
5751 | printf (" %02x", augmentation_data[i]); |
5752 | putchar ('\n'); | |
5753 | } | |
5754 | putchar ('\n'); | |
5755 | } | |
19e6b90e L |
5756 | } |
5757 | else | |
5758 | { | |
5759 | unsigned char *look_for; | |
5760 | static Frame_Chunk fde_fc; | |
604282a7 | 5761 | unsigned long segment_selector; |
19e6b90e | 5762 | |
49727e46 AM |
5763 | if (is_eh) |
5764 | { | |
5765 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
5766 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
5767 | } | |
5768 | else | |
5769 | look_for = section_start + cie_id; | |
19e6b90e | 5770 | |
49727e46 AM |
5771 | if (look_for <= saved_start) |
5772 | { | |
5773 | for (cie = chunks; cie ; cie = cie->next) | |
5774 | if (cie->chunk_start == look_for) | |
5775 | break; | |
5776 | } | |
5777 | else | |
5778 | { | |
5779 | for (cie = forward_refs; cie ; cie = cie->next) | |
5780 | if (cie->chunk_start == look_for) | |
5781 | break; | |
5782 | if (!cie) | |
5783 | { | |
5784 | unsigned int off_size; | |
5785 | unsigned char *cie_scan; | |
19e6b90e | 5786 | |
49727e46 AM |
5787 | cie_scan = look_for; |
5788 | off_size = 4; | |
5789 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
5790 | if (length == 0xffffffff) | |
5791 | { | |
5792 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
5793 | off_size = 8; | |
5794 | } | |
5795 | if (length != 0) | |
5796 | { | |
5797 | dwarf_vma c_id; | |
5798 | ||
5799 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
5800 | if (is_eh | |
5801 | ? c_id == 0 | |
5802 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
5803 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
5804 | { | |
5805 | int version; | |
a1165289 | 5806 | unsigned int mreg; |
49727e46 AM |
5807 | |
5808 | read_cie (cie_scan, end, &cie, &version, | |
5809 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
5810 | /* PR 17512: file: 3450-2098-0.004. */ |
5811 | if (cie == NULL) | |
5812 | { | |
5813 | warn (_("Failed to read CIE information\n")); | |
5814 | break; | |
5815 | } | |
49727e46 AM |
5816 | cie->next = forward_refs; |
5817 | forward_refs = cie; | |
5818 | cie->chunk_start = look_for; | |
a1165289 | 5819 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
5820 | if (mreg < cie->ra) |
5821 | mreg = cie->ra; | |
06614111 NC |
5822 | if (frame_need_space (cie, mreg) < 0) |
5823 | { | |
5824 | warn (_("Invalid max register\n")); | |
5825 | break; | |
5826 | } | |
49727e46 AM |
5827 | if (cie->fde_encoding) |
5828 | encoded_ptr_size | |
5829 | = size_of_encoded_value (cie->fde_encoding); | |
5830 | } | |
5831 | } | |
5832 | } | |
5833 | } | |
5834 | ||
5835 | fc = &fde_fc; | |
5836 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
5837 | |
5838 | if (!cie) | |
5839 | { | |
bf5117e3 NC |
5840 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
5841 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
5842 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 5843 | fc->ncols = 0; |
3f5e193b NC |
5844 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
5845 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
5846 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
5847 | { | |
5848 | warn (_("Invalid max register\n")); | |
5849 | break; | |
5850 | } | |
19e6b90e L |
5851 | cie = fc; |
5852 | fc->augmentation = ""; | |
5853 | fc->fde_encoding = 0; | |
604282a7 JJ |
5854 | fc->ptr_size = eh_addr_size; |
5855 | fc->segment_size = 0; | |
19e6b90e L |
5856 | } |
5857 | else | |
5858 | { | |
5859 | fc->ncols = cie->ncols; | |
3f5e193b NC |
5860 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
5861 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
5862 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
5863 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
5864 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
5865 | fc->ptr_size = cie->ptr_size; |
5866 | eh_addr_size = cie->ptr_size; | |
5867 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
5868 | fc->code_factor = cie->code_factor; |
5869 | fc->data_factor = cie->data_factor; | |
5870 | fc->cfa_reg = cie->cfa_reg; | |
5871 | fc->cfa_offset = cie->cfa_offset; | |
5872 | fc->ra = cie->ra; | |
06614111 NC |
5873 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
5874 | { | |
5875 | warn (_("Invalid max register\n")); | |
5876 | break; | |
5877 | } | |
19e6b90e L |
5878 | fc->fde_encoding = cie->fde_encoding; |
5879 | } | |
5880 | ||
5881 | if (fc->fde_encoding) | |
5882 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
5883 | ||
604282a7 JJ |
5884 | segment_selector = 0; |
5885 | if (fc->segment_size) | |
041830e0 NC |
5886 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); |
5887 | ||
5888 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 5889 | |
0c588247 NC |
5890 | /* FIXME: It appears that sometimes the final pc_range value is |
5891 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
5892 | run of the "objcopy on compressed debug sections" test for an | |
5893 | example of this. */ | |
5894 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 5895 | |
19e6b90e L |
5896 | if (cie->augmentation[0] == 'z') |
5897 | { | |
5898 | augmentation_data_len = LEB (); | |
5899 | augmentation_data = start; | |
5900 | start += augmentation_data_len; | |
0a9d414a | 5901 | /* PR 17512: file: 722-8446-0.004. */ |
53774b7e | 5902 | if (start >= end || ((signed long) augmentation_data_len) < 0) |
0a9d414a NC |
5903 | { |
5904 | warn (_("Corrupt augmentation data length: %lx\n"), | |
5905 | augmentation_data_len); | |
5906 | start = end; | |
5907 | augmentation_data = NULL; | |
5908 | augmentation_data_len = 0; | |
5909 | } | |
19e6b90e L |
5910 | } |
5911 | ||
bf5117e3 NC |
5912 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
5913 | (unsigned long)(saved_start - section_start), | |
5914 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 5915 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 5916 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 5917 | |
604282a7 JJ |
5918 | if (fc->segment_size) |
5919 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
5920 | |
5921 | printf ("%s..%s\n", | |
5922 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
5923 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
5924 | ||
19e6b90e L |
5925 | if (! do_debug_frames_interp && augmentation_data_len) |
5926 | { | |
5927 | unsigned long i; | |
5928 | ||
5929 | printf (" Augmentation data: "); | |
5930 | for (i = 0; i < augmentation_data_len; ++i) | |
5931 | printf (" %02x", augmentation_data[i]); | |
5932 | putchar ('\n'); | |
5933 | putchar ('\n'); | |
5934 | } | |
5935 | } | |
5936 | ||
5937 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
5938 | we're about to interpret instructions for the chunk. */ | |
5939 | /* ??? At present we need to do this always, since this sizes the | |
5940 | fc->col_type and fc->col_offset arrays, which we write into always. | |
5941 | We should probably split the interpreted and non-interpreted bits | |
5942 | into two different routines, since there's so much that doesn't | |
5943 | really overlap between them. */ | |
5944 | if (1 || do_debug_frames_interp) | |
5945 | { | |
5946 | /* Start by making a pass over the chunk, allocating storage | |
5947 | and taking note of what registers are used. */ | |
5948 | unsigned char *tmp = start; | |
5949 | ||
5950 | while (start < block_end) | |
5951 | { | |
041830e0 NC |
5952 | unsigned int reg, op, opa; |
5953 | unsigned long temp; | |
5929c344 | 5954 | unsigned char * new_start; |
19e6b90e L |
5955 | |
5956 | op = *start++; | |
5957 | opa = op & 0x3f; | |
5958 | if (op & 0xc0) | |
5959 | op &= 0xc0; | |
5960 | ||
5961 | /* Warning: if you add any more cases to this switch, be | |
5962 | sure to add them to the corresponding switch below. */ | |
5963 | switch (op) | |
5964 | { | |
5965 | case DW_CFA_advance_loc: | |
5966 | break; | |
5967 | case DW_CFA_offset: | |
5968 | LEB (); | |
665ce1f6 L |
5969 | if (frame_need_space (fc, opa) >= 0) |
5970 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
5971 | break; |
5972 | case DW_CFA_restore: | |
665ce1f6 L |
5973 | if (frame_need_space (fc, opa) >= 0) |
5974 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
5975 | break; |
5976 | case DW_CFA_set_loc: | |
5977 | start += encoded_ptr_size; | |
5978 | break; | |
5979 | case DW_CFA_advance_loc1: | |
5980 | start += 1; | |
5981 | break; | |
5982 | case DW_CFA_advance_loc2: | |
5983 | start += 2; | |
5984 | break; | |
5985 | case DW_CFA_advance_loc4: | |
5986 | start += 4; | |
5987 | break; | |
5988 | case DW_CFA_offset_extended: | |
12eae2d3 | 5989 | case DW_CFA_val_offset: |
19e6b90e | 5990 | reg = LEB (); LEB (); |
665ce1f6 L |
5991 | if (frame_need_space (fc, reg) >= 0) |
5992 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
5993 | break; |
5994 | case DW_CFA_restore_extended: | |
5995 | reg = LEB (); | |
665ce1f6 L |
5996 | if (frame_need_space (fc, reg) >= 0) |
5997 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
5998 | break; |
5999 | case DW_CFA_undefined: | |
6000 | reg = LEB (); | |
665ce1f6 L |
6001 | if (frame_need_space (fc, reg) >= 0) |
6002 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
6003 | break; |
6004 | case DW_CFA_same_value: | |
6005 | reg = LEB (); | |
665ce1f6 L |
6006 | if (frame_need_space (fc, reg) >= 0) |
6007 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
6008 | break; |
6009 | case DW_CFA_register: | |
6010 | reg = LEB (); LEB (); | |
665ce1f6 L |
6011 | if (frame_need_space (fc, reg) >= 0) |
6012 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
6013 | break; |
6014 | case DW_CFA_def_cfa: | |
6015 | LEB (); LEB (); | |
6016 | break; | |
6017 | case DW_CFA_def_cfa_register: | |
6018 | LEB (); | |
6019 | break; | |
6020 | case DW_CFA_def_cfa_offset: | |
6021 | LEB (); | |
6022 | break; | |
6023 | case DW_CFA_def_cfa_expression: | |
91d6fa6a | 6024 | temp = LEB (); |
5929c344 NC |
6025 | new_start = start + temp; |
6026 | if (new_start < start) | |
041830e0 NC |
6027 | { |
6028 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
6029 | start = block_end; | |
6030 | } | |
6031 | else | |
5929c344 | 6032 | start = new_start; |
19e6b90e L |
6033 | break; |
6034 | case DW_CFA_expression: | |
12eae2d3 | 6035 | case DW_CFA_val_expression: |
19e6b90e | 6036 | reg = LEB (); |
91d6fa6a | 6037 | temp = LEB (); |
5929c344 NC |
6038 | new_start = start + temp; |
6039 | if (new_start < start) | |
041830e0 NC |
6040 | { |
6041 | /* PR 17512: file:306-192417-0.005. */ | |
6042 | warn (_("Corrupt CFA expression value: %lu\n"), temp); | |
6043 | start = block_end; | |
6044 | } | |
6045 | else | |
5929c344 | 6046 | start = new_start; |
665ce1f6 L |
6047 | if (frame_need_space (fc, reg) >= 0) |
6048 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
6049 | break; |
6050 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 6051 | case DW_CFA_val_offset_sf: |
19e6b90e | 6052 | reg = LEB (); SLEB (); |
665ce1f6 L |
6053 | if (frame_need_space (fc, reg) >= 0) |
6054 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
6055 | break; |
6056 | case DW_CFA_def_cfa_sf: | |
6057 | LEB (); SLEB (); | |
6058 | break; | |
6059 | case DW_CFA_def_cfa_offset_sf: | |
6060 | SLEB (); | |
6061 | break; | |
6062 | case DW_CFA_MIPS_advance_loc8: | |
6063 | start += 8; | |
6064 | break; | |
6065 | case DW_CFA_GNU_args_size: | |
6066 | LEB (); | |
6067 | break; | |
6068 | case DW_CFA_GNU_negative_offset_extended: | |
6069 | reg = LEB (); LEB (); | |
665ce1f6 L |
6070 | if (frame_need_space (fc, reg) >= 0) |
6071 | fc->col_type[reg] = DW_CFA_undefined; | |
6072 | break; | |
19e6b90e L |
6073 | default: |
6074 | break; | |
6075 | } | |
6076 | } | |
6077 | start = tmp; | |
6078 | } | |
6079 | ||
6080 | /* Now we know what registers are used, make a second pass over | |
6081 | the chunk, this time actually printing out the info. */ | |
6082 | ||
6083 | while (start < block_end) | |
6084 | { | |
6085 | unsigned op, opa; | |
6086 | unsigned long ul, reg, roffs; | |
bf5117e3 NC |
6087 | long l; |
6088 | dwarf_vma ofs; | |
19e6b90e | 6089 | dwarf_vma vma; |
665ce1f6 | 6090 | const char *reg_prefix = ""; |
19e6b90e L |
6091 | |
6092 | op = *start++; | |
6093 | opa = op & 0x3f; | |
6094 | if (op & 0xc0) | |
6095 | op &= 0xc0; | |
6096 | ||
6097 | /* Warning: if you add any more cases to this switch, be | |
6098 | sure to add them to the corresponding switch above. */ | |
6099 | switch (op) | |
6100 | { | |
6101 | case DW_CFA_advance_loc: | |
6102 | if (do_debug_frames_interp) | |
6103 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6104 | else | |
bf5117e3 | 6105 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 6106 | opa * fc->code_factor, |
bf5117e3 NC |
6107 | dwarf_vmatoa_1 (NULL, |
6108 | fc->pc_begin + opa * fc->code_factor, | |
6109 | fc->ptr_size)); | |
19e6b90e L |
6110 | fc->pc_begin += opa * fc->code_factor; |
6111 | break; | |
6112 | ||
6113 | case DW_CFA_offset: | |
6114 | roffs = LEB (); | |
665ce1f6 L |
6115 | if (opa >= (unsigned int) fc->ncols) |
6116 | reg_prefix = bad_reg; | |
6117 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6118 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
6119 | reg_prefix, regname (opa, 0), | |
6120 | roffs * fc->data_factor); | |
6121 | if (*reg_prefix == '\0') | |
6122 | { | |
6123 | fc->col_type[opa] = DW_CFA_offset; | |
6124 | fc->col_offset[opa] = roffs * fc->data_factor; | |
6125 | } | |
19e6b90e L |
6126 | break; |
6127 | ||
6128 | case DW_CFA_restore: | |
665ce1f6 L |
6129 | if (opa >= (unsigned int) cie->ncols |
6130 | || opa >= (unsigned int) fc->ncols) | |
6131 | reg_prefix = bad_reg; | |
6132 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6133 | printf (" DW_CFA_restore: %s%s\n", | |
6134 | reg_prefix, regname (opa, 0)); | |
6135 | if (*reg_prefix == '\0') | |
6136 | { | |
6137 | fc->col_type[opa] = cie->col_type[opa]; | |
6138 | fc->col_offset[opa] = cie->col_offset[opa]; | |
b3f5b73b ILT |
6139 | if (do_debug_frames_interp |
6140 | && fc->col_type[opa] == DW_CFA_unreferenced) | |
6141 | fc->col_type[opa] = DW_CFA_undefined; | |
665ce1f6 | 6142 | } |
19e6b90e L |
6143 | break; |
6144 | ||
6145 | case DW_CFA_set_loc: | |
6937bb54 | 6146 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
6147 | if (do_debug_frames_interp) |
6148 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6149 | else | |
bf5117e3 NC |
6150 | printf (" DW_CFA_set_loc: %s\n", |
6151 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
6152 | fc->pc_begin = vma; |
6153 | break; | |
6154 | ||
6155 | case DW_CFA_advance_loc1: | |
0c588247 | 6156 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
6157 | if (do_debug_frames_interp) |
6158 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6159 | else | |
bf5117e3 NC |
6160 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
6161 | (unsigned long) (ofs * fc->code_factor), | |
6162 | dwarf_vmatoa_1 (NULL, | |
6163 | fc->pc_begin + ofs * fc->code_factor, | |
6164 | fc->ptr_size)); | |
19e6b90e L |
6165 | fc->pc_begin += ofs * fc->code_factor; |
6166 | break; | |
6167 | ||
6168 | case DW_CFA_advance_loc2: | |
6937bb54 | 6169 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
6170 | if (do_debug_frames_interp) |
6171 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6172 | else | |
bf5117e3 NC |
6173 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
6174 | (unsigned long) (ofs * fc->code_factor), | |
6175 | dwarf_vmatoa_1 (NULL, | |
6176 | fc->pc_begin + ofs * fc->code_factor, | |
6177 | fc->ptr_size)); | |
19e6b90e L |
6178 | fc->pc_begin += ofs * fc->code_factor; |
6179 | break; | |
6180 | ||
6181 | case DW_CFA_advance_loc4: | |
6937bb54 | 6182 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
6183 | if (do_debug_frames_interp) |
6184 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6185 | else | |
bf5117e3 NC |
6186 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
6187 | (unsigned long) (ofs * fc->code_factor), | |
6188 | dwarf_vmatoa_1 (NULL, | |
6189 | fc->pc_begin + ofs * fc->code_factor, | |
6190 | fc->ptr_size)); | |
19e6b90e L |
6191 | fc->pc_begin += ofs * fc->code_factor; |
6192 | break; | |
6193 | ||
6194 | case DW_CFA_offset_extended: | |
6195 | reg = LEB (); | |
6196 | roffs = LEB (); | |
665ce1f6 L |
6197 | if (reg >= (unsigned int) fc->ncols) |
6198 | reg_prefix = bad_reg; | |
6199 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6200 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
6201 | reg_prefix, regname (reg, 0), | |
6202 | roffs * fc->data_factor); | |
6203 | if (*reg_prefix == '\0') | |
6204 | { | |
6205 | fc->col_type[reg] = DW_CFA_offset; | |
6206 | fc->col_offset[reg] = roffs * fc->data_factor; | |
6207 | } | |
19e6b90e L |
6208 | break; |
6209 | ||
12eae2d3 JJ |
6210 | case DW_CFA_val_offset: |
6211 | reg = LEB (); | |
6212 | roffs = LEB (); | |
665ce1f6 L |
6213 | if (reg >= (unsigned int) fc->ncols) |
6214 | reg_prefix = bad_reg; | |
6215 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6216 | printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n", | |
6217 | reg_prefix, regname (reg, 0), | |
6218 | roffs * fc->data_factor); | |
6219 | if (*reg_prefix == '\0') | |
6220 | { | |
6221 | fc->col_type[reg] = DW_CFA_val_offset; | |
6222 | fc->col_offset[reg] = roffs * fc->data_factor; | |
6223 | } | |
12eae2d3 JJ |
6224 | break; |
6225 | ||
19e6b90e L |
6226 | case DW_CFA_restore_extended: |
6227 | reg = LEB (); | |
665ce1f6 L |
6228 | if (reg >= (unsigned int) cie->ncols |
6229 | || reg >= (unsigned int) fc->ncols) | |
6230 | reg_prefix = bad_reg; | |
6231 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6232 | printf (" DW_CFA_restore_extended: %s%s\n", | |
6233 | reg_prefix, regname (reg, 0)); | |
6234 | if (*reg_prefix == '\0') | |
6235 | { | |
6236 | fc->col_type[reg] = cie->col_type[reg]; | |
6237 | fc->col_offset[reg] = cie->col_offset[reg]; | |
6238 | } | |
19e6b90e L |
6239 | break; |
6240 | ||
6241 | case DW_CFA_undefined: | |
6242 | reg = LEB (); | |
665ce1f6 L |
6243 | if (reg >= (unsigned int) fc->ncols) |
6244 | reg_prefix = bad_reg; | |
6245 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6246 | printf (" DW_CFA_undefined: %s%s\n", | |
6247 | reg_prefix, regname (reg, 0)); | |
6248 | if (*reg_prefix == '\0') | |
6249 | { | |
6250 | fc->col_type[reg] = DW_CFA_undefined; | |
6251 | fc->col_offset[reg] = 0; | |
6252 | } | |
19e6b90e L |
6253 | break; |
6254 | ||
6255 | case DW_CFA_same_value: | |
6256 | reg = LEB (); | |
665ce1f6 L |
6257 | if (reg >= (unsigned int) fc->ncols) |
6258 | reg_prefix = bad_reg; | |
6259 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6260 | printf (" DW_CFA_same_value: %s%s\n", | |
6261 | reg_prefix, regname (reg, 0)); | |
6262 | if (*reg_prefix == '\0') | |
6263 | { | |
6264 | fc->col_type[reg] = DW_CFA_same_value; | |
6265 | fc->col_offset[reg] = 0; | |
6266 | } | |
19e6b90e L |
6267 | break; |
6268 | ||
6269 | case DW_CFA_register: | |
6270 | reg = LEB (); | |
6271 | roffs = LEB (); | |
665ce1f6 L |
6272 | if (reg >= (unsigned int) fc->ncols) |
6273 | reg_prefix = bad_reg; | |
6274 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 6275 | { |
665ce1f6 L |
6276 | printf (" DW_CFA_register: %s%s in ", |
6277 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
6278 | puts (regname (roffs, 0)); |
6279 | } | |
665ce1f6 L |
6280 | if (*reg_prefix == '\0') |
6281 | { | |
6282 | fc->col_type[reg] = DW_CFA_register; | |
6283 | fc->col_offset[reg] = roffs; | |
6284 | } | |
19e6b90e L |
6285 | break; |
6286 | ||
6287 | case DW_CFA_remember_state: | |
6288 | if (! do_debug_frames_interp) | |
6289 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 6290 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
d71ad7fc RC |
6291 | rs->cfa_offset = fc->cfa_offset; |
6292 | rs->cfa_reg = fc->cfa_reg; | |
6293 | rs->ra = fc->ra; | |
6294 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 6295 | rs->ncols = fc->ncols; |
3f5e193b | 6296 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
d71ad7fc RC |
6297 | sizeof (* rs->col_type)); |
6298 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); | |
6299 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
6300 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
6301 | rs->next = remembered_state; |
6302 | remembered_state = rs; | |
6303 | break; | |
6304 | ||
6305 | case DW_CFA_restore_state: | |
6306 | if (! do_debug_frames_interp) | |
6307 | printf (" DW_CFA_restore_state\n"); | |
6308 | rs = remembered_state; | |
6309 | if (rs) | |
6310 | { | |
6311 | remembered_state = rs->next; | |
d71ad7fc RC |
6312 | fc->cfa_offset = rs->cfa_offset; |
6313 | fc->cfa_reg = rs->cfa_reg; | |
6314 | fc->ra = rs->ra; | |
6315 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
6316 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
6317 | { | |
1306a742 | 6318 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
6319 | fc->ncols = 0; |
6320 | break; | |
6321 | } | |
d71ad7fc | 6322 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 6323 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 6324 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
6325 | free (rs->col_type); |
6326 | free (rs->col_offset); | |
6327 | free (rs); | |
6328 | } | |
6329 | else if (do_debug_frames_interp) | |
6330 | printf ("Mismatched DW_CFA_restore_state\n"); | |
6331 | break; | |
6332 | ||
6333 | case DW_CFA_def_cfa: | |
6334 | fc->cfa_reg = LEB (); | |
6335 | fc->cfa_offset = LEB (); | |
6336 | fc->cfa_exp = 0; | |
6337 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
6338 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
6339 | regname (fc->cfa_reg, 0), fc->cfa_offset); | |
19e6b90e L |
6340 | break; |
6341 | ||
6342 | case DW_CFA_def_cfa_register: | |
6343 | fc->cfa_reg = LEB (); | |
6344 | fc->cfa_exp = 0; | |
6345 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
6346 | printf (" DW_CFA_def_cfa_register: %s\n", |
6347 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
6348 | break; |
6349 | ||
6350 | case DW_CFA_def_cfa_offset: | |
6351 | fc->cfa_offset = LEB (); | |
6352 | if (! do_debug_frames_interp) | |
6353 | printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset); | |
6354 | break; | |
6355 | ||
6356 | case DW_CFA_nop: | |
6357 | if (! do_debug_frames_interp) | |
6358 | printf (" DW_CFA_nop\n"); | |
6359 | break; | |
6360 | ||
6361 | case DW_CFA_def_cfa_expression: | |
6362 | ul = LEB (); | |
06614111 | 6363 | if (start >= block_end || start + ul > block_end || start + ul < start) |
6937bb54 | 6364 | { |
a1165289 | 6365 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
6366 | break; |
6367 | } | |
19e6b90e L |
6368 | if (! do_debug_frames_interp) |
6369 | { | |
6370 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
6371 | decode_location_expression (start, eh_addr_size, 0, -1, |
6372 | ul, 0, section); | |
19e6b90e L |
6373 | printf (")\n"); |
6374 | } | |
6375 | fc->cfa_exp = 1; | |
6376 | start += ul; | |
6377 | break; | |
6378 | ||
6379 | case DW_CFA_expression: | |
6380 | reg = LEB (); | |
6381 | ul = LEB (); | |
665ce1f6 L |
6382 | if (reg >= (unsigned int) fc->ncols) |
6383 | reg_prefix = bad_reg; | |
6937bb54 | 6384 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 NC |
6385 | /* PR 17512: file: 98c02eb4. */ |
6386 | if (start >= block_end || start + ul > block_end || start + ul < start) | |
6937bb54 | 6387 | { |
a1165289 | 6388 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
6389 | break; |
6390 | } | |
665ce1f6 | 6391 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 6392 | { |
665ce1f6 L |
6393 | printf (" DW_CFA_expression: %s%s (", |
6394 | reg_prefix, regname (reg, 0)); | |
b7807392 | 6395 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 6396 | ul, 0, section); |
19e6b90e L |
6397 | printf (")\n"); |
6398 | } | |
665ce1f6 L |
6399 | if (*reg_prefix == '\0') |
6400 | fc->col_type[reg] = DW_CFA_expression; | |
19e6b90e L |
6401 | start += ul; |
6402 | break; | |
6403 | ||
12eae2d3 JJ |
6404 | case DW_CFA_val_expression: |
6405 | reg = LEB (); | |
6406 | ul = LEB (); | |
665ce1f6 L |
6407 | if (reg >= (unsigned int) fc->ncols) |
6408 | reg_prefix = bad_reg; | |
06614111 | 6409 | if (start >= block_end || start + ul > block_end || start + ul < start) |
6937bb54 | 6410 | { |
a1165289 | 6411 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
6412 | break; |
6413 | } | |
665ce1f6 | 6414 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 6415 | { |
665ce1f6 L |
6416 | printf (" DW_CFA_val_expression: %s%s (", |
6417 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
6418 | decode_location_expression (start, eh_addr_size, 0, -1, |
6419 | ul, 0, section); | |
12eae2d3 JJ |
6420 | printf (")\n"); |
6421 | } | |
665ce1f6 L |
6422 | if (*reg_prefix == '\0') |
6423 | fc->col_type[reg] = DW_CFA_val_expression; | |
12eae2d3 JJ |
6424 | start += ul; |
6425 | break; | |
6426 | ||
19e6b90e L |
6427 | case DW_CFA_offset_extended_sf: |
6428 | reg = LEB (); | |
6429 | l = SLEB (); | |
665ce1f6 L |
6430 | if (frame_need_space (fc, reg) < 0) |
6431 | reg_prefix = bad_reg; | |
6432 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6433 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
6434 | reg_prefix, regname (reg, 0), | |
6435 | l * fc->data_factor); | |
6436 | if (*reg_prefix == '\0') | |
6437 | { | |
6438 | fc->col_type[reg] = DW_CFA_offset; | |
6439 | fc->col_offset[reg] = l * fc->data_factor; | |
6440 | } | |
19e6b90e L |
6441 | break; |
6442 | ||
12eae2d3 JJ |
6443 | case DW_CFA_val_offset_sf: |
6444 | reg = LEB (); | |
6445 | l = SLEB (); | |
665ce1f6 L |
6446 | if (frame_need_space (fc, reg) < 0) |
6447 | reg_prefix = bad_reg; | |
6448 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6449 | printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n", | |
6450 | reg_prefix, regname (reg, 0), | |
6451 | l * fc->data_factor); | |
6452 | if (*reg_prefix == '\0') | |
6453 | { | |
6454 | fc->col_type[reg] = DW_CFA_val_offset; | |
6455 | fc->col_offset[reg] = l * fc->data_factor; | |
6456 | } | |
12eae2d3 JJ |
6457 | break; |
6458 | ||
19e6b90e L |
6459 | case DW_CFA_def_cfa_sf: |
6460 | fc->cfa_reg = LEB (); | |
6461 | fc->cfa_offset = SLEB (); | |
6462 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; | |
6463 | fc->cfa_exp = 0; | |
6464 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
6465 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
6466 | regname (fc->cfa_reg, 0), fc->cfa_offset); | |
19e6b90e L |
6467 | break; |
6468 | ||
6469 | case DW_CFA_def_cfa_offset_sf: | |
6470 | fc->cfa_offset = SLEB (); | |
6471 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; | |
6472 | if (! do_debug_frames_interp) | |
6473 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset); | |
6474 | break; | |
6475 | ||
6476 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 6477 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
6478 | if (do_debug_frames_interp) |
6479 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6480 | else | |
bf5117e3 NC |
6481 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
6482 | (unsigned long) (ofs * fc->code_factor), | |
6483 | dwarf_vmatoa_1 (NULL, | |
6484 | fc->pc_begin + ofs * fc->code_factor, | |
6485 | fc->ptr_size)); | |
19e6b90e L |
6486 | fc->pc_begin += ofs * fc->code_factor; |
6487 | break; | |
6488 | ||
6489 | case DW_CFA_GNU_window_save: | |
6490 | if (! do_debug_frames_interp) | |
6491 | printf (" DW_CFA_GNU_window_save\n"); | |
6492 | break; | |
6493 | ||
6494 | case DW_CFA_GNU_args_size: | |
6495 | ul = LEB (); | |
6496 | if (! do_debug_frames_interp) | |
6497 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
6498 | break; | |
6499 | ||
6500 | case DW_CFA_GNU_negative_offset_extended: | |
6501 | reg = LEB (); | |
6502 | l = - LEB (); | |
665ce1f6 L |
6503 | if (frame_need_space (fc, reg) < 0) |
6504 | reg_prefix = bad_reg; | |
6505 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6506 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
6507 | reg_prefix, regname (reg, 0), | |
6508 | l * fc->data_factor); | |
6509 | if (*reg_prefix == '\0') | |
6510 | { | |
6511 | fc->col_type[reg] = DW_CFA_offset; | |
6512 | fc->col_offset[reg] = l * fc->data_factor; | |
6513 | } | |
19e6b90e L |
6514 | break; |
6515 | ||
6516 | default: | |
53b8873b NC |
6517 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
6518 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
6519 | else | |
f41e4712 | 6520 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
6521 | start = block_end; |
6522 | } | |
6523 | } | |
6524 | ||
6525 | if (do_debug_frames_interp) | |
6526 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6527 | ||
6528 | start = block_end; | |
604282a7 | 6529 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
6530 | } |
6531 | ||
6532 | printf ("\n"); | |
6533 | ||
6534 | return 1; | |
6535 | } | |
6536 | ||
6537 | #undef GET | |
6538 | #undef LEB | |
6539 | #undef SLEB | |
6540 | ||
5bbdf3d5 DE |
6541 | static int |
6542 | display_gdb_index (struct dwarf_section *section, | |
6543 | void *file ATTRIBUTE_UNUSED) | |
6544 | { | |
6545 | unsigned char *start = section->start; | |
6546 | uint32_t version; | |
6547 | uint32_t cu_list_offset, tu_list_offset; | |
6548 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
6549 | unsigned int cu_list_elements, tu_list_elements; | |
6550 | unsigned int address_table_size, symbol_table_slots; | |
6551 | unsigned char *cu_list, *tu_list; | |
6552 | unsigned char *address_table, *symbol_table, *constant_pool; | |
6553 | unsigned int i; | |
6554 | ||
6555 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
6556 | ||
6557 | printf (_("Contents of the %s section:\n"), section->name); | |
6558 | ||
6559 | if (section->size < 6 * sizeof (uint32_t)) | |
6560 | { | |
6561 | warn (_("Truncated header in the %s section.\n"), section->name); | |
6562 | return 0; | |
6563 | } | |
6564 | ||
6565 | version = byte_get_little_endian (start, 4); | |
da88a764 | 6566 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
6567 | |
6568 | /* Prior versions are obsolete, and future versions may not be | |
6569 | backwards compatible. */ | |
aa170720 | 6570 | if (version < 3 || version > 8) |
5bbdf3d5 | 6571 | { |
da88a764 | 6572 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
6573 | return 0; |
6574 | } | |
8d6eee87 TT |
6575 | if (version < 4) |
6576 | warn (_("The address table data in version 3 may be wrong.\n")); | |
6577 | if (version < 5) | |
6578 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
6579 | if (version < 6) | |
6580 | warn (_("Version 5 does not include inlined functions.\n")); | |
6581 | if (version < 7) | |
6582 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
6583 | /* Version 7 indices generated by Gold have bad type unit references, |
6584 | PR binutils/15021. But we don't know if the index was generated by | |
6585 | Gold or not, so to avoid worrying users with gdb-generated indices | |
6586 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
6587 | |
6588 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
6589 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
6590 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
6591 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
6592 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
6593 | ||
6594 | if (cu_list_offset > section->size | |
6595 | || tu_list_offset > section->size | |
6596 | || address_table_offset > section->size | |
6597 | || symbol_table_offset > section->size | |
6598 | || constant_pool_offset > section->size) | |
6599 | { | |
6600 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
6601 | return 0; | |
6602 | } | |
6603 | ||
53774b7e NC |
6604 | /* PR 17531: file: 418d0a8a. */ |
6605 | if (tu_list_offset < cu_list_offset) | |
6606 | { | |
6607 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
6608 | tu_list_offset, cu_list_offset); | |
6609 | return 0; | |
6610 | } | |
6611 | ||
5bbdf3d5 | 6612 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
6613 | |
6614 | if (address_table_offset < tu_list_offset) | |
6615 | { | |
6616 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
6617 | address_table_offset, tu_list_offset); | |
6618 | return 0; | |
6619 | } | |
6620 | ||
5bbdf3d5 | 6621 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
6622 | |
6623 | /* PR 17531: file: 18a47d3d. */ | |
6624 | if (symbol_table_offset < address_table_offset) | |
6625 | { | |
acff9664 | 6626 | warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"), |
53774b7e NC |
6627 | symbol_table_offset, address_table_offset); |
6628 | return 0; | |
6629 | } | |
6630 | ||
5bbdf3d5 | 6631 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
6632 | |
6633 | if (constant_pool_offset < symbol_table_offset) | |
6634 | { | |
6635 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
6636 | constant_pool_offset, symbol_table_offset); | |
6637 | return 0; | |
6638 | } | |
6639 | ||
5bbdf3d5 DE |
6640 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
6641 | ||
6642 | cu_list = start + cu_list_offset; | |
6643 | tu_list = start + tu_list_offset; | |
6644 | address_table = start + address_table_offset; | |
6645 | symbol_table = start + symbol_table_offset; | |
6646 | constant_pool = start + constant_pool_offset; | |
6647 | ||
acff9664 NC |
6648 | if (address_table + address_table_size * (2 + 8 + 4) > section->start + section->size) |
6649 | { | |
1306a742 | 6650 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
6651 | return 0; |
6652 | } | |
6653 | ||
5bbdf3d5 DE |
6654 | printf (_("\nCU table:\n")); |
6655 | for (i = 0; i < cu_list_elements; i += 2) | |
6656 | { | |
6657 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
6658 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
6659 | ||
6660 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
6661 | (unsigned long) cu_offset, | |
6662 | (unsigned long) (cu_offset + cu_length - 1)); | |
6663 | } | |
6664 | ||
6665 | printf (_("\nTU table:\n")); | |
6666 | for (i = 0; i < tu_list_elements; i += 3) | |
6667 | { | |
6668 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
6669 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
6670 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
6671 | ||
6672 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
6673 | (unsigned long) tu_offset, | |
6674 | (unsigned long) type_offset); | |
6675 | print_dwarf_vma (signature, 8); | |
6676 | printf ("\n"); | |
6677 | } | |
6678 | ||
6679 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
6680 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
6681 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
6682 | { |
6683 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
6684 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
6685 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
6686 | ||
6687 | print_dwarf_vma (low, 8); | |
6688 | print_dwarf_vma (high, 8); | |
da88a764 | 6689 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
6690 | } |
6691 | ||
6692 | printf (_("\nSymbol table:\n")); | |
6693 | for (i = 0; i < symbol_table_slots; ++i) | |
6694 | { | |
6695 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
6696 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
6697 | uint32_t num_cus, cu; | |
6698 | ||
6699 | if (name_offset != 0 | |
6700 | || cu_vector_offset != 0) | |
6701 | { | |
6702 | unsigned int j; | |
6703 | ||
53774b7e NC |
6704 | /* PR 17531: file: 5b7b07ad. */ |
6705 | if (constant_pool + name_offset < constant_pool | |
6706 | || constant_pool + name_offset >= section->start + section->size) | |
6707 | { | |
6708 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
6709 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
6710 | name_offset, i); | |
6711 | } | |
6712 | else | |
acff9664 NC |
6713 | printf ("[%3u] %.*s:", i, |
6714 | (int) (section->size - (constant_pool_offset + name_offset)), | |
6715 | constant_pool + name_offset); | |
53774b7e NC |
6716 | |
6717 | if (constant_pool + cu_vector_offset < constant_pool | |
57028622 | 6718 | || constant_pool + cu_vector_offset >= section->start + section->size - 3) |
53774b7e NC |
6719 | { |
6720 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
6721 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
6722 | cu_vector_offset, i); | |
6723 | continue; | |
6724 | } | |
57028622 NC |
6725 | |
6726 | num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4); | |
53774b7e | 6727 | |
acff9664 | 6728 | if (num_cus * 4 < num_cus |
57028622 | 6729 | || constant_pool + cu_vector_offset + 4 + num_cus * 4 |
f3853b34 NC |
6730 | >= section->start + section->size |
6731 | || (constant_pool + cu_vector_offset + 4 + num_cus * 4) < constant_pool) | |
53774b7e NC |
6732 | { |
6733 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 6734 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
6735 | num_cus, i); |
6736 | continue; | |
6737 | } | |
6738 | ||
8d6eee87 TT |
6739 | if (num_cus > 1) |
6740 | printf ("\n"); | |
f3853b34 | 6741 | |
5bbdf3d5 DE |
6742 | for (j = 0; j < num_cus; ++j) |
6743 | { | |
7c1cef97 | 6744 | int is_static; |
8d6eee87 TT |
6745 | gdb_index_symbol_kind kind; |
6746 | ||
5bbdf3d5 | 6747 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 6748 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
6749 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
6750 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 6751 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 6752 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
6753 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
6754 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 6755 | else |
8d6eee87 TT |
6756 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
6757 | ||
459d52c8 DE |
6758 | printf (" [%s, %s]", |
6759 | is_static ? _("static") : _("global"), | |
6760 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
6761 | if (num_cus > 1) |
6762 | printf ("\n"); | |
5bbdf3d5 | 6763 | } |
8d6eee87 TT |
6764 | if (num_cus <= 1) |
6765 | printf ("\n"); | |
5bbdf3d5 DE |
6766 | } |
6767 | } | |
6768 | ||
6769 | return 1; | |
6770 | } | |
6771 | ||
657d0d47 CC |
6772 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
6773 | ||
6774 | static void | |
6775 | prealloc_cu_tu_list (unsigned int nshndx) | |
6776 | { | |
6777 | if (shndx_pool == NULL) | |
6778 | { | |
6779 | shndx_pool_size = nshndx; | |
6780 | shndx_pool_used = 0; | |
6781 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
6782 | sizeof (unsigned int)); | |
6783 | } | |
6784 | else | |
6785 | { | |
6786 | shndx_pool_size = shndx_pool_used + nshndx; | |
6787 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
6788 | sizeof (unsigned int)); | |
6789 | } | |
6790 | } | |
6791 | ||
6792 | static void | |
6793 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
6794 | { | |
6795 | if (shndx_pool_used >= shndx_pool_size) | |
6796 | { | |
6797 | error (_("Internal error: out of space in the shndx pool.\n")); | |
6798 | return; | |
6799 | } | |
6800 | shndx_pool [shndx_pool_used++] = shndx; | |
6801 | } | |
6802 | ||
6803 | static void | |
6804 | end_cu_tu_entry (void) | |
6805 | { | |
6806 | if (shndx_pool_used >= shndx_pool_size) | |
6807 | { | |
6808 | error (_("Internal error: out of space in the shndx pool.\n")); | |
6809 | return; | |
6810 | } | |
6811 | shndx_pool [shndx_pool_used++] = 0; | |
6812 | } | |
6813 | ||
341f9135 CC |
6814 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
6815 | ||
6816 | static const char * | |
6817 | get_DW_SECT_short_name (unsigned int dw_sect) | |
6818 | { | |
6819 | static char buf[16]; | |
6820 | ||
6821 | switch (dw_sect) | |
6822 | { | |
6823 | case DW_SECT_INFO: | |
6824 | return "info"; | |
6825 | case DW_SECT_TYPES: | |
6826 | return "types"; | |
6827 | case DW_SECT_ABBREV: | |
6828 | return "abbrev"; | |
6829 | case DW_SECT_LINE: | |
6830 | return "line"; | |
6831 | case DW_SECT_LOC: | |
6832 | return "loc"; | |
6833 | case DW_SECT_STR_OFFSETS: | |
6834 | return "str_off"; | |
6835 | case DW_SECT_MACINFO: | |
6836 | return "macinfo"; | |
6837 | case DW_SECT_MACRO: | |
6838 | return "macro"; | |
6839 | default: | |
6840 | break; | |
6841 | } | |
6842 | ||
6843 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
6844 | return buf; | |
6845 | } | |
6846 | ||
6847 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
6848 | These sections are extensions for Fission. | |
6849 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
6850 | |
6851 | static int | |
6852 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
6853 | { | |
6854 | unsigned char *phdr = section->start; | |
6855 | unsigned char *limit = phdr + section->size; | |
6856 | unsigned char *phash; | |
6857 | unsigned char *pindex; | |
6858 | unsigned char *ppool; | |
6859 | unsigned int version; | |
341f9135 | 6860 | unsigned int ncols = 0; |
657d0d47 CC |
6861 | unsigned int nused; |
6862 | unsigned int nslots; | |
6863 | unsigned int i; | |
341f9135 CC |
6864 | unsigned int j; |
6865 | dwarf_vma signature_high; | |
6866 | dwarf_vma signature_low; | |
6867 | char buf[64]; | |
657d0d47 | 6868 | |
6937bb54 NC |
6869 | /* PR 17512: file: 002-168123-0.004. */ |
6870 | if (phdr == NULL) | |
6871 | { | |
6872 | warn (_("Section %s is empty\n"), section->name); | |
6873 | return 0; | |
6874 | } | |
6875 | /* PR 17512: file: 002-376-0.004. */ | |
6876 | if (section->size < 24) | |
6877 | { | |
72c61a0d | 6878 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
6879 | section->name); |
6880 | return 0; | |
6881 | } | |
6882 | ||
6883 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 6884 | if (version >= 2) |
6937bb54 NC |
6885 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
6886 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
6887 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
6888 | ||
657d0d47 CC |
6889 | phash = phdr + 16; |
6890 | pindex = phash + nslots * 8; | |
6891 | ppool = pindex + nslots * 4; | |
6892 | ||
57028622 NC |
6893 | /* PR 17531: file: 45d69832. */ |
6894 | if (pindex < phash || ppool < phdr) | |
6895 | { | |
6896 | warn (_("Section %s is too small for %d slots\n"), | |
6897 | section->name, nslots); | |
6898 | return 0; | |
6899 | } | |
6900 | ||
657d0d47 CC |
6901 | if (do_display) |
6902 | { | |
6903 | printf (_("Contents of the %s section:\n\n"), section->name); | |
6904 | printf (_(" Version: %d\n"), version); | |
341f9135 CC |
6905 | if (version >= 2) |
6906 | printf (_(" Number of columns: %d\n"), ncols); | |
657d0d47 CC |
6907 | printf (_(" Number of used entries: %d\n"), nused); |
6908 | printf (_(" Number of slots: %d\n\n"), nslots); | |
6909 | } | |
6910 | ||
6911 | if (ppool > limit) | |
6912 | { | |
6913 | warn (_("Section %s too small for %d hash table entries\n"), | |
6914 | section->name, nslots); | |
6915 | return 0; | |
6916 | } | |
6917 | ||
341f9135 | 6918 | if (version == 1) |
657d0d47 | 6919 | { |
341f9135 CC |
6920 | if (!do_display) |
6921 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
6922 | for (i = 0; i < nslots; i++) | |
657d0d47 | 6923 | { |
341f9135 CC |
6924 | unsigned char *shndx_list; |
6925 | unsigned int shndx; | |
6926 | ||
6937bb54 | 6927 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 6928 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 6929 | { |
6937bb54 | 6930 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 6931 | shndx_list = ppool + j * 4; |
f3853b34 NC |
6932 | /* PR 17531: file: 705e010d. */ |
6933 | if (shndx_list < ppool) | |
6934 | { | |
6935 | warn (_("Section index pool located before start of section\n")); | |
6936 | return 0; | |
6937 | } | |
6938 | ||
341f9135 CC |
6939 | if (do_display) |
6940 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
6941 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
6942 | buf, sizeof (buf))); | |
6943 | for (;;) | |
657d0d47 | 6944 | { |
341f9135 CC |
6945 | if (shndx_list >= limit) |
6946 | { | |
6947 | warn (_("Section %s too small for shndx pool\n"), | |
6948 | section->name); | |
6949 | return 0; | |
6950 | } | |
6937bb54 | 6951 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
6952 | if (shndx == 0) |
6953 | break; | |
6954 | if (do_display) | |
6955 | printf (" %d", shndx); | |
6956 | else | |
6957 | add_shndx_to_cu_tu_entry (shndx); | |
6958 | shndx_list += 4; | |
657d0d47 | 6959 | } |
657d0d47 | 6960 | if (do_display) |
341f9135 | 6961 | printf ("\n"); |
657d0d47 | 6962 | else |
341f9135 CC |
6963 | end_cu_tu_entry (); |
6964 | } | |
6965 | phash += 8; | |
6966 | pindex += 4; | |
6967 | } | |
6968 | } | |
6969 | else if (version == 2) | |
6970 | { | |
6971 | unsigned int val; | |
6972 | unsigned int dw_sect; | |
6973 | unsigned char *ph = phash; | |
6974 | unsigned char *pi = pindex; | |
6975 | unsigned char *poffsets = ppool + ncols * 4; | |
6976 | unsigned char *psizes = poffsets + nused * ncols * 4; | |
6977 | unsigned char *pend = psizes + nused * ncols * 4; | |
6978 | bfd_boolean is_tu_index; | |
6979 | struct cu_tu_set *this_set = NULL; | |
6980 | unsigned int row; | |
6981 | unsigned char *prow; | |
6982 | ||
6983 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
6984 | ||
6985 | if (pend > limit) | |
6986 | { | |
6987 | warn (_("Section %s too small for offset and size tables\n"), | |
6988 | section->name); | |
6989 | return 0; | |
6990 | } | |
6991 | ||
6992 | if (do_display) | |
6993 | { | |
6994 | printf (_(" Offset table\n")); | |
6995 | printf (" slot %-16s ", | |
6996 | is_tu_index ? _("signature") : _("dwo_id")); | |
6997 | } | |
6998 | else | |
6999 | { | |
7000 | if (is_tu_index) | |
7001 | { | |
7002 | tu_count = nused; | |
72c61a0d | 7003 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 7004 | this_set = tu_sets; |
657d0d47 | 7005 | } |
657d0d47 | 7006 | else |
341f9135 CC |
7007 | { |
7008 | cu_count = nused; | |
72c61a0d | 7009 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
7010 | this_set = cu_sets; |
7011 | } | |
7012 | } | |
6937bb54 | 7013 | |
341f9135 CC |
7014 | if (do_display) |
7015 | { | |
7016 | for (j = 0; j < ncols; j++) | |
7017 | { | |
6937bb54 | 7018 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
7019 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
7020 | } | |
7021 | printf ("\n"); | |
7022 | } | |
6937bb54 | 7023 | |
341f9135 CC |
7024 | for (i = 0; i < nslots; i++) |
7025 | { | |
6937bb54 NC |
7026 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
7027 | ||
7028 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
7029 | if (row != 0) |
7030 | { | |
591f7597 | 7031 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 7032 | if (row > nused) |
591f7597 NC |
7033 | { |
7034 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
7035 | row, nused); | |
7036 | return 0; | |
7037 | } | |
7038 | ||
341f9135 CC |
7039 | if (!do_display) |
7040 | memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t)); | |
6937bb54 | 7041 | |
341f9135 | 7042 | prow = poffsets + (row - 1) * ncols * 4; |
6937bb54 | 7043 | |
341f9135 CC |
7044 | if (do_display) |
7045 | printf (_(" [%3d] 0x%s"), | |
7046 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
7047 | buf, sizeof (buf))); | |
7048 | for (j = 0; j < ncols; j++) | |
7049 | { | |
6937bb54 | 7050 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
7051 | if (do_display) |
7052 | printf (" %8d", val); | |
7053 | else | |
7054 | { | |
6937bb54 | 7055 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
7056 | |
7057 | /* PR 17531: file: 10796eb3. */ | |
7058 | if (dw_sect >= DW_SECT_MAX) | |
7059 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
7060 | else | |
7061 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
7062 | } |
7063 | } | |
6937bb54 | 7064 | |
341f9135 CC |
7065 | if (do_display) |
7066 | printf ("\n"); | |
7067 | } | |
7068 | ph += 8; | |
7069 | pi += 4; | |
7070 | } | |
7071 | ||
7072 | ph = phash; | |
7073 | pi = pindex; | |
7074 | if (do_display) | |
7075 | { | |
7076 | printf ("\n"); | |
7077 | printf (_(" Size table\n")); | |
7078 | printf (" slot %-16s ", | |
7079 | is_tu_index ? _("signature") : _("dwo_id")); | |
7080 | } | |
6937bb54 | 7081 | |
341f9135 CC |
7082 | for (j = 0; j < ncols; j++) |
7083 | { | |
6937bb54 | 7084 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
7085 | if (do_display) |
7086 | printf (" %8s", get_DW_SECT_short_name (val)); | |
7087 | } | |
6937bb54 | 7088 | |
341f9135 CC |
7089 | if (do_display) |
7090 | printf ("\n"); | |
6937bb54 | 7091 | |
341f9135 CC |
7092 | for (i = 0; i < nslots; i++) |
7093 | { | |
6937bb54 NC |
7094 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
7095 | ||
7096 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
7097 | if (row != 0) |
7098 | { | |
7099 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 7100 | |
341f9135 CC |
7101 | if (do_display) |
7102 | printf (_(" [%3d] 0x%s"), | |
7103 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
7104 | buf, sizeof (buf))); | |
6937bb54 | 7105 | |
341f9135 CC |
7106 | for (j = 0; j < ncols; j++) |
7107 | { | |
6937bb54 | 7108 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
7109 | if (do_display) |
7110 | printf (" %8d", val); | |
7111 | else | |
7112 | { | |
6937bb54 | 7113 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
7114 | if (dw_sect >= DW_SECT_MAX) |
7115 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
7116 | else | |
341f9135 CC |
7117 | this_set [row - 1].section_sizes [dw_sect] = val; |
7118 | } | |
7119 | } | |
6937bb54 | 7120 | |
341f9135 CC |
7121 | if (do_display) |
7122 | printf ("\n"); | |
7123 | } | |
6937bb54 | 7124 | |
341f9135 CC |
7125 | ph += 8; |
7126 | pi += 4; | |
657d0d47 | 7127 | } |
657d0d47 | 7128 | } |
341f9135 | 7129 | else if (do_display) |
6937bb54 | 7130 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
7131 | |
7132 | if (do_display) | |
7133 | printf ("\n"); | |
7134 | ||
7135 | return 1; | |
7136 | } | |
7137 | ||
7138 | /* Load the CU and TU indexes if present. This will build a list of | |
7139 | section sets that we can use to associate a .debug_info.dwo section | |
7140 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
7141 | ||
7142 | static void | |
7143 | load_cu_tu_indexes (void *file) | |
7144 | { | |
7145 | /* If we have already loaded (or tried to load) the CU and TU indexes | |
7146 | then do not bother to repeat the task. */ | |
7147 | if (cu_tu_indexes_read) | |
7148 | return; | |
7149 | ||
7150 | if (load_debug_section (dwp_cu_index, file)) | |
7151 | process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0); | |
7152 | ||
7153 | if (load_debug_section (dwp_tu_index, file)) | |
7154 | process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0); | |
7155 | ||
7156 | cu_tu_indexes_read = 1; | |
7157 | } | |
7158 | ||
7159 | /* Find the set of sections that includes section SHNDX. */ | |
7160 | ||
7161 | unsigned int * | |
7162 | find_cu_tu_set (void *file, unsigned int shndx) | |
7163 | { | |
7164 | unsigned int i; | |
7165 | ||
7166 | load_cu_tu_indexes (file); | |
7167 | ||
7168 | /* Find SHNDX in the shndx pool. */ | |
7169 | for (i = 0; i < shndx_pool_used; i++) | |
7170 | if (shndx_pool [i] == shndx) | |
7171 | break; | |
7172 | ||
7173 | if (i >= shndx_pool_used) | |
7174 | return NULL; | |
7175 | ||
7176 | /* Now backup to find the first entry in the set. */ | |
7177 | while (i > 0 && shndx_pool [i - 1] != 0) | |
7178 | i--; | |
7179 | ||
7180 | return shndx_pool + i; | |
7181 | } | |
7182 | ||
7183 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
7184 | ||
7185 | static int | |
7186 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
7187 | { | |
7188 | return process_cu_tu_index (section, 1); | |
7189 | } | |
7190 | ||
19e6b90e L |
7191 | static int |
7192 | display_debug_not_supported (struct dwarf_section *section, | |
7193 | void *file ATTRIBUTE_UNUSED) | |
7194 | { | |
7195 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
7196 | section->name); | |
7197 | ||
7198 | return 1; | |
7199 | } | |
7200 | ||
1306a742 NC |
7201 | /* Like malloc, but takes two parameters like calloc. |
7202 | Verifies that the first parameter is not too large. | |
82b1b41b | 7203 | Note: does *not* initialise the allocated memory to zero. */ |
19e6b90e L |
7204 | void * |
7205 | cmalloc (size_t nmemb, size_t size) | |
7206 | { | |
7207 | /* Check for overflow. */ | |
7208 | if (nmemb >= ~(size_t) 0 / size) | |
7209 | return NULL; | |
82b1b41b NC |
7210 | |
7211 | return xmalloc (nmemb * size); | |
19e6b90e L |
7212 | } |
7213 | ||
1306a742 NC |
7214 | /* Like xmalloc, but takes two parameters like calloc. |
7215 | Verifies that the first parameter is not too large. | |
7216 | Note: does *not* initialise the allocated memory to zero. */ | |
72c61a0d | 7217 | void * |
1306a742 | 7218 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
7219 | { |
7220 | /* Check for overflow. */ | |
7221 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
7222 | { |
7223 | fprintf (stderr, | |
7224 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
7225 | (long) nmemb); | |
7226 | xexit (1); | |
7227 | } | |
72c61a0d | 7228 | |
1306a742 | 7229 | return xmalloc (nmemb * size); |
72c61a0d NC |
7230 | } |
7231 | ||
1306a742 NC |
7232 | /* Like xrealloc, but takes three parameters. |
7233 | Verifies that the second parameter is not too large. | |
7234 | Note: does *not* initialise any new memory to zero. */ | |
19e6b90e | 7235 | void * |
1306a742 | 7236 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
7237 | { |
7238 | /* Check for overflow. */ | |
7239 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
7240 | { |
7241 | fprintf (stderr, | |
7242 | _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), | |
7243 | (long) nmemb); | |
7244 | xexit (1); | |
7245 | } | |
82b1b41b | 7246 | |
1306a742 | 7247 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
7248 | } |
7249 | ||
1306a742 | 7250 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
19e6b90e | 7251 | void * |
1306a742 | 7252 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
7253 | { |
7254 | /* Check for overflow. */ | |
7255 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
7256 | { |
7257 | fprintf (stderr, | |
7258 | _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), | |
7259 | (long) nmemb); | |
7260 | xexit (1); | |
7261 | } | |
82b1b41b | 7262 | |
1306a742 | 7263 | return xcalloc (nmemb, size); |
19e6b90e L |
7264 | } |
7265 | ||
19e6b90e L |
7266 | void |
7267 | free_debug_memory (void) | |
7268 | { | |
3f5e193b | 7269 | unsigned int i; |
19e6b90e L |
7270 | |
7271 | free_abbrevs (); | |
7272 | ||
7273 | for (i = 0; i < max; i++) | |
3f5e193b | 7274 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 7275 | |
cc86f28f | 7276 | if (debug_information != NULL) |
19e6b90e | 7277 | { |
cc86f28f | 7278 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 7279 | { |
cc86f28f | 7280 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 7281 | { |
cc86f28f NC |
7282 | if (!debug_information [i].max_loc_offsets) |
7283 | { | |
7284 | free (debug_information [i].loc_offsets); | |
7285 | free (debug_information [i].have_frame_base); | |
7286 | } | |
7287 | if (!debug_information [i].max_range_lists) | |
7288 | free (debug_information [i].range_lists); | |
19e6b90e | 7289 | } |
19e6b90e L |
7290 | } |
7291 | free (debug_information); | |
7292 | debug_information = NULL; | |
82b1b41b | 7293 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 7294 | } |
19e6b90e L |
7295 | } |
7296 | ||
4cb93e3b TG |
7297 | void |
7298 | dwarf_select_sections_by_names (const char *names) | |
7299 | { | |
7300 | typedef struct | |
7301 | { | |
7302 | const char * option; | |
7303 | int * variable; | |
f9f0e732 | 7304 | int val; |
4cb93e3b TG |
7305 | } |
7306 | debug_dump_long_opts; | |
7307 | ||
7308 | static const debug_dump_long_opts opts_table [] = | |
7309 | { | |
7310 | /* Please keep this table alpha- sorted. */ | |
7311 | { "Ranges", & do_debug_ranges, 1 }, | |
7312 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 7313 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 7314 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
7315 | { "cu_index", & do_debug_cu_index, 1 }, |
7316 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
4cb93e3b TG |
7317 | { "frames", & do_debug_frames, 1 }, |
7318 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
7319 | /* The special .gdb_index section. */ |
7320 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
7321 | { "info", & do_debug_info, 1 }, |
7322 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
4cb93e3b TG |
7323 | { "loc", & do_debug_loc, 1 }, |
7324 | { "macro", & do_debug_macinfo, 1 }, | |
7325 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 7326 | { "pubtypes", & do_debug_pubtypes, 1 }, |
4cb93e3b TG |
7327 | /* This entry is for compatability |
7328 | with earlier versions of readelf. */ | |
7329 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 7330 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 7331 | { "str", & do_debug_str, 1 }, |
6f875884 TG |
7332 | /* These trace_* sections are used by Itanium VMS. */ |
7333 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
7334 | { "trace_aranges", & do_trace_aranges, 1 }, | |
7335 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
7336 | { NULL, NULL, 0 } |
7337 | }; | |
7338 | ||
7339 | const char *p; | |
467c65bc | 7340 | |
4cb93e3b TG |
7341 | p = names; |
7342 | while (*p) | |
7343 | { | |
7344 | const debug_dump_long_opts * entry; | |
467c65bc | 7345 | |
4cb93e3b TG |
7346 | for (entry = opts_table; entry->option; entry++) |
7347 | { | |
7348 | size_t len = strlen (entry->option); | |
467c65bc | 7349 | |
4cb93e3b TG |
7350 | if (strncmp (p, entry->option, len) == 0 |
7351 | && (p[len] == ',' || p[len] == '\0')) | |
7352 | { | |
7353 | * entry->variable |= entry->val; | |
467c65bc | 7354 | |
4cb93e3b TG |
7355 | /* The --debug-dump=frames-interp option also |
7356 | enables the --debug-dump=frames option. */ | |
7357 | if (do_debug_frames_interp) | |
7358 | do_debug_frames = 1; | |
7359 | ||
7360 | p += len; | |
7361 | break; | |
7362 | } | |
7363 | } | |
467c65bc | 7364 | |
4cb93e3b TG |
7365 | if (entry->option == NULL) |
7366 | { | |
7367 | warn (_("Unrecognized debug option '%s'\n"), p); | |
7368 | p = strchr (p, ','); | |
7369 | if (p == NULL) | |
7370 | break; | |
7371 | } | |
467c65bc | 7372 | |
4cb93e3b TG |
7373 | if (*p == ',') |
7374 | p++; | |
7375 | } | |
7376 | } | |
7377 | ||
7378 | void | |
7379 | dwarf_select_sections_by_letters (const char *letters) | |
7380 | { | |
91d6fa6a | 7381 | unsigned int lindex = 0; |
4cb93e3b | 7382 | |
91d6fa6a NC |
7383 | while (letters[lindex]) |
7384 | switch (letters[lindex++]) | |
4cb93e3b TG |
7385 | { |
7386 | case 'i': | |
7387 | do_debug_info = 1; | |
7388 | break; | |
467c65bc | 7389 | |
4cb93e3b TG |
7390 | case 'a': |
7391 | do_debug_abbrevs = 1; | |
7392 | break; | |
467c65bc | 7393 | |
4cb93e3b TG |
7394 | case 'l': |
7395 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
7396 | break; | |
467c65bc | 7397 | |
4cb93e3b TG |
7398 | case 'L': |
7399 | do_debug_lines |= FLAG_DEBUG_LINES_DECODED; | |
7400 | break; | |
467c65bc | 7401 | |
4cb93e3b TG |
7402 | case 'p': |
7403 | do_debug_pubnames = 1; | |
7404 | break; | |
467c65bc | 7405 | |
f9f0e732 NC |
7406 | case 't': |
7407 | do_debug_pubtypes = 1; | |
7408 | break; | |
467c65bc | 7409 | |
4cb93e3b TG |
7410 | case 'r': |
7411 | do_debug_aranges = 1; | |
7412 | break; | |
467c65bc | 7413 | |
4cb93e3b TG |
7414 | case 'R': |
7415 | do_debug_ranges = 1; | |
7416 | break; | |
467c65bc | 7417 | |
4cb93e3b TG |
7418 | case 'F': |
7419 | do_debug_frames_interp = 1; | |
7420 | case 'f': | |
7421 | do_debug_frames = 1; | |
7422 | break; | |
467c65bc | 7423 | |
4cb93e3b TG |
7424 | case 'm': |
7425 | do_debug_macinfo = 1; | |
7426 | break; | |
467c65bc | 7427 | |
4cb93e3b TG |
7428 | case 's': |
7429 | do_debug_str = 1; | |
7430 | break; | |
467c65bc | 7431 | |
4cb93e3b TG |
7432 | case 'o': |
7433 | do_debug_loc = 1; | |
7434 | break; | |
467c65bc | 7435 | |
4cb93e3b | 7436 | default: |
7cc78d07 | 7437 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
7438 | break; |
7439 | } | |
7440 | } | |
7441 | ||
7442 | void | |
7443 | dwarf_select_sections_all (void) | |
7444 | { | |
7445 | do_debug_info = 1; | |
7446 | do_debug_abbrevs = 1; | |
7447 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
7448 | do_debug_pubnames = 1; | |
f9f0e732 | 7449 | do_debug_pubtypes = 1; |
4cb93e3b TG |
7450 | do_debug_aranges = 1; |
7451 | do_debug_ranges = 1; | |
7452 | do_debug_frames = 1; | |
7453 | do_debug_macinfo = 1; | |
7454 | do_debug_str = 1; | |
7455 | do_debug_loc = 1; | |
5bbdf3d5 | 7456 | do_gdb_index = 1; |
6f875884 TG |
7457 | do_trace_info = 1; |
7458 | do_trace_abbrevs = 1; | |
7459 | do_trace_aranges = 1; | |
657d0d47 CC |
7460 | do_debug_addr = 1; |
7461 | do_debug_cu_index = 1; | |
4cb93e3b TG |
7462 | } |
7463 | ||
19e6b90e L |
7464 | struct dwarf_section_display debug_displays[] = |
7465 | { | |
06614111 | 7466 | { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7467 | display_debug_abbrev, &do_debug_abbrevs, 0 }, |
06614111 | 7468 | { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7469 | display_debug_aranges, &do_debug_aranges, 1 }, |
06614111 | 7470 | { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7471 | display_debug_frames, &do_debug_frames, 1 }, |
06614111 | 7472 | { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL }, |
4723351a | 7473 | display_debug_info, &do_debug_info, 1 }, |
06614111 | 7474 | { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7475 | display_debug_lines, &do_debug_lines, 1 }, |
06614111 | 7476 | { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7477 | display_debug_pubnames, &do_debug_pubnames, 0 }, |
06614111 | 7478 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL }, |
459d52c8 | 7479 | display_debug_gnu_pubnames, &do_debug_pubnames, 0 }, |
06614111 | 7480 | { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7481 | display_debug_frames, &do_debug_frames, 1 }, |
06614111 | 7482 | { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7483 | display_debug_macinfo, &do_debug_macinfo, 0 }, |
06614111 | 7484 | { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7485 | display_debug_macro, &do_debug_macinfo, 1 }, |
06614111 | 7486 | { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7487 | display_debug_str, &do_debug_str, 0 }, |
06614111 | 7488 | { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7489 | display_debug_loc, &do_debug_loc, 1 }, |
06614111 | 7490 | { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7491 | display_debug_pubnames, &do_debug_pubtypes, 0 }, |
06614111 | 7492 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL }, |
459d52c8 | 7493 | display_debug_gnu_pubnames, &do_debug_pubtypes, 0 }, |
06614111 | 7494 | { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7495 | display_debug_ranges, &do_debug_ranges, 1 }, |
06614111 | 7496 | { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7497 | display_debug_not_supported, NULL, 0 }, |
06614111 | 7498 | { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7499 | display_debug_not_supported, NULL, 0 }, |
06614111 | 7500 | { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL }, |
4723351a | 7501 | display_debug_types, &do_debug_info, 1 }, |
06614111 | 7502 | { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7503 | display_debug_not_supported, NULL, 0 }, |
06614111 | 7504 | { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7505 | display_gdb_index, &do_gdb_index, 0 }, |
06614111 | 7506 | { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL }, |
657d0d47 | 7507 | display_trace_info, &do_trace_info, 1 }, |
06614111 | 7508 | { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7509 | display_debug_abbrev, &do_trace_abbrevs, 0 }, |
06614111 | 7510 | { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7511 | display_debug_aranges, &do_trace_aranges, 0 }, |
06614111 | 7512 | { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL }, |
657d0d47 | 7513 | display_debug_info, &do_debug_info, 1 }, |
06614111 | 7514 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7515 | display_debug_abbrev, &do_debug_abbrevs, 0 }, |
06614111 | 7516 | { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL }, |
657d0d47 | 7517 | display_debug_types, &do_debug_info, 1 }, |
06614111 | 7518 | { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7519 | display_debug_lines, &do_debug_lines, 1 }, |
06614111 | 7520 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7521 | display_debug_loc, &do_debug_loc, 1 }, |
06614111 | 7522 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7523 | display_debug_macro, &do_debug_macinfo, 1 }, |
06614111 | 7524 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7525 | display_debug_macinfo, &do_debug_macinfo, 0 }, |
06614111 | 7526 | { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7527 | display_debug_str, &do_debug_str, 1 }, |
06614111 | 7528 | { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7529 | display_debug_str_offsets, NULL, 0 }, |
06614111 | 7530 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7531 | display_debug_str_offsets, NULL, 0 }, |
06614111 | 7532 | { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7533 | display_debug_addr, &do_debug_addr, 1 }, |
06614111 | 7534 | { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7535 | display_cu_index, &do_debug_cu_index, 0 }, |
06614111 | 7536 | { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7537 | display_cu_index, &do_debug_cu_index, 0 }, |
19e6b90e | 7538 | }; |