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