Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
2571583a | 2 | Copyright (C) 2005-2017 Free Software Foundation, Inc. |
19e6b90e L |
3 | |
4 | This file is part of GNU Binutils. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
32866df7 | 8 | the Free Software Foundation; either version 3 of the License, or |
19e6b90e L |
9 | (at your option) any later version. |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA | |
19 | 02110-1301, USA. */ | |
20 | ||
3db64b00 | 21 | #include "sysdep.h" |
19e6b90e | 22 | #include "libiberty.h" |
3db64b00 | 23 | #include "bfd.h" |
5bbdf3d5 | 24 | #include "bfd_stdint.h" |
3db64b00 | 25 | #include "bucomm.h" |
3284fe0c | 26 | #include "elfcomm.h" |
2dc4cec1 | 27 | #include "elf/common.h" |
fa8f86ff | 28 | #include "dwarf2.h" |
3db64b00 | 29 | #include "dwarf.h" |
8d6eee87 | 30 | #include "gdb/gdb-index.h" |
61364358 JK |
31 | #include <assert.h> |
32 | ||
33 | #undef MAX | |
34 | #undef MIN | |
35 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
36 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
19e6b90e | 37 | |
18464d4d JK |
38 | static const char *regname (unsigned int regno, int row); |
39 | ||
19e6b90e L |
40 | static int have_frame_base; |
41 | static int need_base_address; | |
42 | ||
43 | static unsigned int last_pointer_size = 0; | |
44 | static int warned_about_missing_comp_units = FALSE; | |
45 | ||
46 | static unsigned int num_debug_info_entries = 0; | |
82b1b41b | 47 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 48 | static debug_info *debug_information = NULL; |
cc86f28f NC |
49 | /* Special value for num_debug_info_entries to indicate |
50 | that the .debug_info section could not be loaded/parsed. */ | |
51 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 52 | |
77ef8654 | 53 | unsigned int eh_addr_size; |
19e6b90e L |
54 | |
55 | int do_debug_info; | |
56 | int do_debug_abbrevs; | |
57 | int do_debug_lines; | |
58 | int do_debug_pubnames; | |
f9f0e732 | 59 | int do_debug_pubtypes; |
19e6b90e L |
60 | int do_debug_aranges; |
61 | int do_debug_ranges; | |
62 | int do_debug_frames; | |
63 | int do_debug_frames_interp; | |
64 | int do_debug_macinfo; | |
65 | int do_debug_str; | |
66 | int do_debug_loc; | |
5bbdf3d5 | 67 | int do_gdb_index; |
6f875884 TG |
68 | int do_trace_info; |
69 | int do_trace_abbrevs; | |
70 | int do_trace_aranges; | |
657d0d47 CC |
71 | int do_debug_addr; |
72 | int do_debug_cu_index; | |
a262ae96 | 73 | int do_wide; |
19e6b90e | 74 | |
fd2f0033 TT |
75 | int dwarf_cutoff_level = -1; |
76 | unsigned long dwarf_start_die; | |
77 | ||
4723351a CC |
78 | int dwarf_check = 0; |
79 | ||
341f9135 CC |
80 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
81 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
82 | as a zero-terminated list of section indexes comprising one set of debug | |
83 | sections from a .dwo file. */ | |
84 | ||
341f9135 CC |
85 | static unsigned int *shndx_pool = NULL; |
86 | static unsigned int shndx_pool_size = 0; | |
87 | static unsigned int shndx_pool_used = 0; | |
88 | ||
89 | /* For version 2 package files, each set contains an array of section offsets | |
90 | and an array of section sizes, giving the offset and size of the | |
91 | contribution from a CU or TU within one of the debug sections. | |
92 | When displaying debug info from a package file, we need to use these | |
93 | tables to locate the corresponding contributions to each section. */ | |
94 | ||
95 | struct cu_tu_set | |
96 | { | |
97 | uint64_t signature; | |
98 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
99 | size_t section_sizes[DW_SECT_MAX]; | |
100 | }; | |
101 | ||
102 | static int cu_count = 0; | |
103 | static int tu_count = 0; | |
104 | static struct cu_tu_set *cu_sets = NULL; | |
105 | static struct cu_tu_set *tu_sets = NULL; | |
106 | ||
43a444f9 | 107 | static bfd_boolean load_cu_tu_indexes (void *); |
341f9135 | 108 | |
4cb93e3b TG |
109 | /* Values for do_debug_lines. */ |
110 | #define FLAG_DEBUG_LINES_RAW 1 | |
111 | #define FLAG_DEBUG_LINES_DECODED 2 | |
112 | ||
77ef8654 | 113 | static unsigned int |
f1c4cc75 RH |
114 | size_of_encoded_value (int encoding) |
115 | { | |
116 | switch (encoding & 0x7) | |
117 | { | |
118 | default: /* ??? */ | |
119 | case 0: return eh_addr_size; | |
120 | case 2: return 2; | |
121 | case 3: return 4; | |
122 | case 4: return 8; | |
123 | } | |
124 | } | |
125 | ||
126 | static dwarf_vma | |
041830e0 | 127 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 128 | int encoding, |
041830e0 NC |
129 | struct dwarf_section *section, |
130 | unsigned char * end) | |
f1c4cc75 | 131 | { |
041830e0 | 132 | unsigned char * data = * pdata; |
6937bb54 | 133 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 134 | dwarf_vma val; |
f1c4cc75 | 135 | |
041830e0 NC |
136 | if (data + size >= end) |
137 | { | |
138 | warn (_("Encoded value extends past end of section\n")); | |
139 | * pdata = end; | |
140 | return 0; | |
141 | } | |
142 | ||
6937bb54 NC |
143 | /* PR 17512: file: 002-829853-0.004. */ |
144 | if (size > 8) | |
145 | { | |
146 | warn (_("Encoded size of %d is too large to read\n"), size); | |
147 | * pdata = end; | |
148 | return 0; | |
149 | } | |
150 | ||
0a9d414a NC |
151 | /* PR 17512: file: 1085-5603-0.004. */ |
152 | if (size == 0) | |
153 | { | |
154 | warn (_("Encoded size of 0 is too small to read\n")); | |
155 | * pdata = end; | |
156 | return 0; | |
157 | } | |
158 | ||
f1c4cc75 | 159 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 160 | val = byte_get_signed (data, size); |
f1c4cc75 | 161 | else |
bad62cf5 AM |
162 | val = byte_get (data, size); |
163 | ||
164 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
165 | val += section->address + (data - section->start); | |
041830e0 NC |
166 | |
167 | * pdata = data + size; | |
bad62cf5 | 168 | return val; |
f1c4cc75 RH |
169 | } |
170 | ||
4c219c2e AM |
171 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
172 | # ifndef __MINGW32__ | |
173 | # define DWARF_VMA_FMT "ll" | |
174 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
175 | # else | |
176 | # define DWARF_VMA_FMT "I64" | |
177 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
178 | # endif | |
2e14fae2 | 179 | #else |
4c219c2e AM |
180 | # define DWARF_VMA_FMT "l" |
181 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
182 | #endif |
183 | ||
bf5117e3 NC |
184 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
185 | buffer containing the converted VALUE. The value is converted according | |
186 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
187 | it specifies the maximum number of bytes to be displayed in the converted | |
188 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 189 | |
47704ddf | 190 | static const char * |
bf5117e3 | 191 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
192 | { |
193 | /* As dwarf_vmatoa is used more then once in a printf call | |
194 | for output, we are cycling through an fixed array of pointers | |
195 | for return address. */ | |
196 | static int buf_pos = 0; | |
467c65bc NC |
197 | static struct dwarf_vmatoa_buf |
198 | { | |
47704ddf KT |
199 | char place[64]; |
200 | } buf[16]; | |
47704ddf KT |
201 | char *ret; |
202 | ||
47704ddf | 203 | ret = buf[buf_pos++].place; |
467c65bc | 204 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 205 | |
bf5117e3 NC |
206 | if (num_bytes) |
207 | { | |
222c2bf0 | 208 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
209 | integer value, so we print the full value into a buffer and then select |
210 | the precision we need. */ | |
211 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
212 | if (num_bytes > 8) | |
213 | num_bytes = 8; | |
214 | return ret + (16 - 2 * num_bytes); | |
215 | } | |
216 | else | |
217 | { | |
218 | char fmt[32]; | |
219 | ||
220 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
221 | snprintf (ret, sizeof (buf[0].place), fmt, value); | |
222 | return ret; | |
223 | } | |
224 | } | |
47704ddf | 225 | |
bf5117e3 NC |
226 | static inline const char * |
227 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
228 | { | |
229 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
230 | } | |
231 | ||
232 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
233 | hexadecimal format, followed by a space. The length of the VALUE (and | |
234 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
235 | ||
236 | static void | |
237 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
238 | { | |
239 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
240 | } |
241 | ||
74bc6052 CC |
242 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
243 | For reentrancy, this uses a buffer provided by the caller. */ | |
244 | ||
245 | static const char * | |
246 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
247 | unsigned int buf_len) | |
248 | { | |
249 | int len = 0; | |
250 | ||
251 | if (hvalue == 0) | |
252 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
253 | else | |
254 | { | |
255 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
256 | snprintf (buf + len, buf_len - len, | |
257 | "%08" DWARF_VMA_FMT "x", lvalue); | |
258 | } | |
259 | ||
260 | return buf; | |
261 | } | |
262 | ||
f6f0e17b NC |
263 | /* Read in a LEB128 encoded value starting at address DATA. |
264 | If SIGN is true, return a signed LEB128 value. | |
265 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
266 | No bytes will be read at address END or beyond. */ | |
267 | ||
467c65bc | 268 | dwarf_vma |
f6f0e17b NC |
269 | read_leb128 (unsigned char *data, |
270 | unsigned int *length_return, | |
271 | bfd_boolean sign, | |
272 | const unsigned char * const end) | |
19e6b90e | 273 | { |
467c65bc | 274 | dwarf_vma result = 0; |
19e6b90e L |
275 | unsigned int num_read = 0; |
276 | unsigned int shift = 0; | |
f6f0e17b | 277 | unsigned char byte = 0; |
19e6b90e | 278 | |
f6f0e17b | 279 | while (data < end) |
19e6b90e L |
280 | { |
281 | byte = *data++; | |
282 | num_read++; | |
283 | ||
467c65bc | 284 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
19e6b90e L |
285 | |
286 | shift += 7; | |
f6f0e17b NC |
287 | if ((byte & 0x80) == 0) |
288 | break; | |
77ef8654 NC |
289 | |
290 | /* PR 17512: file: 0ca183b8. | |
291 | FIXME: Should we signal this error somehow ? */ | |
f641dd96 | 292 | if (shift >= sizeof (result) * 8) |
77ef8654 | 293 | break; |
19e6b90e | 294 | } |
19e6b90e L |
295 | |
296 | if (length_return != NULL) | |
297 | *length_return = num_read; | |
298 | ||
299 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
c4e0beac | 300 | result |= -((dwarf_vma) 1 << shift); |
19e6b90e L |
301 | |
302 | return result; | |
303 | } | |
304 | ||
467c65bc | 305 | /* Create a signed version to avoid painful typecasts. */ |
f6f0e17b NC |
306 | static inline dwarf_signed_vma |
307 | read_sleb128 (unsigned char * data, | |
308 | unsigned int * length_return, | |
309 | const unsigned char * const end) | |
310 | { | |
311 | return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end); | |
312 | } | |
313 | ||
314 | static inline dwarf_vma | |
315 | read_uleb128 (unsigned char * data, | |
316 | unsigned int * length_return, | |
317 | const unsigned char * const end) | |
467c65bc | 318 | { |
f6f0e17b | 319 | return read_leb128 (data, length_return, FALSE, end); |
467c65bc NC |
320 | } |
321 | ||
7f2c8a1d NC |
322 | #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return |
323 | #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return | |
324 | ||
325 | #define READ_ULEB(var) \ | |
326 | do \ | |
327 | { \ | |
328 | dwarf_vma _val; \ | |
329 | \ | |
330 | (var) = _val = read_uleb128 (start, &length_return, end); \ | |
331 | if ((var) != _val) \ | |
19474787 | 332 | error (_("Internal error: %s%d: LEB value (%#" DWARF_VMA_FMT "x) too large for containing variable\n"), \ |
7f2c8a1d NC |
333 | __FILE__, __LINE__, _val); \ |
334 | start += length_return; \ | |
335 | } \ | |
336 | while (0) | |
337 | ||
338 | #define READ_SLEB(var) \ | |
339 | do \ | |
340 | { \ | |
341 | dwarf_signed_vma _val; \ | |
342 | \ | |
343 | (var) = _val = read_sleb128 (start, &length_return, end); \ | |
344 | if ((var) != _val) \ | |
19474787 | 345 | error (_("Internal error: %s%d: LEB value (%#" DWARF_VMA_FMT "x) too large for containing variable\n"), \ |
7f2c8a1d NC |
346 | __FILE__, __LINE__, _val); \ |
347 | start += length_return; \ | |
348 | } \ | |
349 | while (0) | |
350 | ||
0c588247 NC |
351 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
352 | do \ | |
353 | { \ | |
354 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
355 | if (sizeof (VAL) < amount) \ |
356 | { \ | |
357 | error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\ | |
358 | amount, (int) sizeof (VAL)); \ | |
359 | amount = sizeof (VAL); \ | |
360 | } \ | |
0c588247 NC |
361 | if (((PTR) + amount) >= (END)) \ |
362 | { \ | |
363 | if ((PTR) < (END)) \ | |
364 | amount = (END) - (PTR); \ | |
365 | else \ | |
366 | amount = 0; \ | |
367 | } \ | |
6937bb54 | 368 | if (amount == 0 || amount > 8) \ |
0c588247 | 369 | VAL = 0; \ |
6937bb54 NC |
370 | else \ |
371 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
372 | } \ |
373 | while (0) | |
374 | ||
375 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ | |
376 | do \ | |
377 | { \ | |
378 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
379 | PTR += AMOUNT; \ | |
380 | } \ | |
381 | while (0) | |
382 | ||
383 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ | |
384 | do \ | |
385 | { \ | |
386 | unsigned int amount = (AMOUNT); \ | |
387 | if (((PTR) + amount) >= (END)) \ | |
388 | { \ | |
389 | if ((PTR) < (END)) \ | |
390 | amount = (END) - (PTR); \ | |
391 | else \ | |
392 | amount = 0; \ | |
393 | } \ | |
394 | if (amount) \ | |
395 | VAL = byte_get_signed ((PTR), amount); \ | |
396 | else \ | |
397 | VAL = 0; \ | |
398 | } \ | |
399 | while (0) | |
400 | ||
401 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ | |
402 | do \ | |
403 | { \ | |
404 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
405 | PTR += AMOUNT; \ | |
406 | } \ | |
407 | while (0) | |
408 | ||
409 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
410 | do \ | |
411 | { \ | |
87bc83b3 | 412 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
413 | { \ |
414 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
415 | } \ | |
416 | else \ | |
417 | { \ | |
0c588247 NC |
418 | * (LOW) = * (HIGH) = 0; \ |
419 | } \ | |
420 | } \ | |
421 | while (0) | |
422 | ||
19e6b90e L |
423 | typedef struct State_Machine_Registers |
424 | { | |
467c65bc | 425 | dwarf_vma address; |
19e6b90e L |
426 | unsigned int file; |
427 | unsigned int line; | |
428 | unsigned int column; | |
429 | int is_stmt; | |
430 | int basic_block; | |
a233b20c JJ |
431 | unsigned char op_index; |
432 | unsigned char end_sequence; | |
19e6b90e L |
433 | /* This variable hold the number of the last entry seen |
434 | in the File Table. */ | |
435 | unsigned int last_file_entry; | |
436 | } SMR; | |
437 | ||
438 | static SMR state_machine_regs; | |
439 | ||
440 | static void | |
441 | reset_state_machine (int is_stmt) | |
442 | { | |
443 | state_machine_regs.address = 0; | |
a233b20c | 444 | state_machine_regs.op_index = 0; |
19e6b90e L |
445 | state_machine_regs.file = 1; |
446 | state_machine_regs.line = 1; | |
447 | state_machine_regs.column = 0; | |
448 | state_machine_regs.is_stmt = is_stmt; | |
449 | state_machine_regs.basic_block = 0; | |
450 | state_machine_regs.end_sequence = 0; | |
451 | state_machine_regs.last_file_entry = 0; | |
452 | } | |
453 | ||
454 | /* Handled an extend line op. | |
455 | Returns the number of bytes read. */ | |
456 | ||
457 | static int | |
f6f0e17b NC |
458 | process_extended_line_op (unsigned char * data, |
459 | int is_stmt, | |
460 | unsigned char * end) | |
19e6b90e L |
461 | { |
462 | unsigned char op_code; | |
463 | unsigned int bytes_read; | |
464 | unsigned int len; | |
465 | unsigned char *name; | |
143a3db0 | 466 | unsigned char *orig_data = data; |
f6f0e17b | 467 | dwarf_vma adr; |
19e6b90e | 468 | |
f6f0e17b | 469 | len = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
470 | data += bytes_read; |
471 | ||
e44c58ce | 472 | if (len == 0 || data == end || len > (uintptr_t) (end - data)) |
19e6b90e | 473 | { |
f41e4712 | 474 | warn (_("Badly formed extended line op encountered!\n")); |
19e6b90e L |
475 | return bytes_read; |
476 | } | |
477 | ||
478 | len += bytes_read; | |
479 | op_code = *data++; | |
480 | ||
481 | printf (_(" Extended opcode %d: "), op_code); | |
482 | ||
483 | switch (op_code) | |
484 | { | |
485 | case DW_LNE_end_sequence: | |
486 | printf (_("End of Sequence\n\n")); | |
487 | reset_state_machine (is_stmt); | |
488 | break; | |
489 | ||
490 | case DW_LNE_set_address: | |
6937bb54 NC |
491 | /* PR 17512: file: 002-100480-0.004. */ |
492 | if (len - bytes_read - 1 > 8) | |
77ef8654 NC |
493 | { |
494 | warn (_("Length (%d) of DW_LNE_set_address op is too long\n"), | |
495 | len - bytes_read - 1); | |
496 | adr = 0; | |
497 | } | |
498 | else | |
499 | SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end); | |
47704ddf | 500 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 501 | state_machine_regs.address = adr; |
a233b20c | 502 | state_machine_regs.op_index = 0; |
19e6b90e L |
503 | break; |
504 | ||
505 | case DW_LNE_define_file: | |
143a3db0 | 506 | printf (_("define new File Table entry\n")); |
19e6b90e | 507 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 508 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 509 | |
d949ff56 NC |
510 | { |
511 | size_t l; | |
512 | ||
513 | name = data; | |
514 | l = strnlen ((char *) data, end - data); | |
515 | data += len + 1; | |
516 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
517 | data += bytes_read; | |
518 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
519 | data += bytes_read; | |
520 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
521 | data += bytes_read; | |
522 | printf ("%.*s\n\n", (int) l, name); | |
523 | } | |
f6f0e17b NC |
524 | |
525 | if (((unsigned int) (data - orig_data) != len) || data == end) | |
b4eb7656 | 526 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
527 | break; |
528 | ||
ed4a4bdf | 529 | case DW_LNE_set_discriminator: |
47704ddf | 530 | printf (_("set Discriminator to %s\n"), |
f6f0e17b | 531 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
ed4a4bdf CC |
532 | break; |
533 | ||
e2a0d921 NC |
534 | /* HP extensions. */ |
535 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 536 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
537 | break; |
538 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 539 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
540 | break; |
541 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 542 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
543 | break; |
544 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 545 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
546 | break; |
547 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 548 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
549 | break; |
550 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 551 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
552 | break; |
553 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 554 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
555 | break; |
556 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 557 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
558 | break; |
559 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 560 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
561 | break; |
562 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 563 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 564 | break; |
43294ab7 TG |
565 | case DW_LNE_HP_source_file_correlation: |
566 | { | |
b4eb7656 AM |
567 | unsigned char *edata = data + len - bytes_read - 1; |
568 | ||
569 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
570 | ||
571 | while (data < edata) | |
572 | { | |
573 | unsigned int opc; | |
574 | ||
575 | opc = read_uleb128 (data, & bytes_read, edata); | |
576 | data += bytes_read; | |
577 | ||
578 | switch (opc) | |
579 | { | |
580 | case DW_LNE_HP_SFC_formfeed: | |
581 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
582 | break; | |
583 | case DW_LNE_HP_SFC_set_listing_line: | |
584 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", | |
585 | dwarf_vmatoa ("u", | |
586 | read_uleb128 (data, & bytes_read, edata))); | |
587 | data += bytes_read; | |
588 | break; | |
589 | case DW_LNE_HP_SFC_associate: | |
590 | printf (" DW_LNE_HP_SFC_associate "); | |
591 | printf ("(%s", | |
592 | dwarf_vmatoa ("u", | |
593 | read_uleb128 (data, & bytes_read, edata))); | |
594 | data += bytes_read; | |
595 | printf (",%s", | |
596 | dwarf_vmatoa ("u", | |
597 | read_uleb128 (data, & bytes_read, edata))); | |
598 | data += bytes_read; | |
599 | printf (",%s)\n", | |
600 | dwarf_vmatoa ("u", | |
601 | read_uleb128 (data, & bytes_read, edata))); | |
602 | data += bytes_read; | |
603 | break; | |
604 | default: | |
605 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
606 | data = edata; | |
607 | break; | |
608 | } | |
609 | } | |
43294ab7 TG |
610 | } |
611 | break; | |
cecf136e | 612 | |
19e6b90e | 613 | default: |
7e665af3 | 614 | { |
b4eb7656 AM |
615 | unsigned int rlen = len - bytes_read - 1; |
616 | ||
617 | if (op_code >= DW_LNE_lo_user | |
618 | /* The test against DW_LNW_hi_user is redundant due to | |
619 | the limited range of the unsigned char data type used | |
620 | for op_code. */ | |
621 | /*&& op_code <= DW_LNE_hi_user*/) | |
622 | printf (_("user defined: ")); | |
623 | else | |
624 | printf (_("UNKNOWN: ")); | |
625 | printf (_("length %d ["), rlen); | |
626 | for (; rlen; rlen--) | |
627 | printf (" %02x", *data++); | |
628 | printf ("]\n"); | |
7e665af3 | 629 | } |
19e6b90e L |
630 | break; |
631 | } | |
632 | ||
633 | return len; | |
634 | } | |
635 | ||
0c588247 | 636 | static const unsigned char * |
467c65bc | 637 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
638 | { |
639 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 640 | const unsigned char * ret; |
19e6b90e L |
641 | |
642 | if (section->start == NULL) | |
0c588247 | 643 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 644 | |
d949ff56 | 645 | if (offset >= section->size) |
19e6b90e | 646 | { |
467c65bc NC |
647 | warn (_("DW_FORM_strp offset too big: %s\n"), |
648 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 649 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
650 | } |
651 | ||
d949ff56 NC |
652 | ret = section->start + offset; |
653 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
654 | NUL byte. Since our caller is expecting to receive a well formed C | |
655 | string we test for the lack of a terminating byte here. */ | |
656 | if (strnlen ((const char *) ret, section->size - offset) | |
657 | == section->size - offset) | |
658 | ret = (const unsigned char *) | |
659 | _("<no NUL byte at end of .debug_str section>"); | |
660 | ||
661 | return ret; | |
19e6b90e L |
662 | } |
663 | ||
77145576 JK |
664 | static const unsigned char * |
665 | fetch_indirect_line_string (dwarf_vma offset) | |
666 | { | |
667 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 668 | const unsigned char * ret; |
77145576 JK |
669 | |
670 | if (section->start == NULL) | |
671 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
672 | ||
d949ff56 | 673 | if (offset >= section->size) |
77145576 JK |
674 | { |
675 | warn (_("DW_FORM_line_strp offset too big: %s\n"), | |
676 | dwarf_vmatoa ("x", offset)); | |
677 | return (const unsigned char *) _("<offset is too big>"); | |
678 | } | |
679 | ||
d949ff56 NC |
680 | ret = section->start + offset; |
681 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
682 | with a NUL byte. Since our caller is expecting to receive a well formed | |
683 | C string we test for the lack of a terminating byte here. */ | |
684 | if (strnlen ((const char *) ret, section->size - offset) | |
685 | == section->size - offset) | |
686 | ret = (const unsigned char *) | |
687 | _("<no NUL byte at end of .debug_line_str section>"); | |
688 | ||
689 | return ret; | |
77145576 JK |
690 | } |
691 | ||
4723351a | 692 | static const char * |
341f9135 CC |
693 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
694 | dwarf_vma offset_size, int dwo) | |
4723351a CC |
695 | { |
696 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
697 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
698 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
699 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
700 | dwarf_vma index_offset = idx * offset_size; | |
701 | dwarf_vma str_offset; | |
d949ff56 | 702 | const char * ret; |
4723351a CC |
703 | |
704 | if (index_section->start == NULL) | |
705 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
706 | : _("<no .debug_str_offsets section>")); | |
707 | ||
341f9135 CC |
708 | if (this_set != NULL) |
709 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
d949ff56 | 710 | if (index_offset >= index_section->size) |
4723351a CC |
711 | { |
712 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), | |
713 | dwarf_vmatoa ("x", index_offset)); | |
714 | return _("<index offset is too big>"); | |
715 | } | |
716 | ||
717 | if (str_section->start == NULL) | |
718 | return (dwo ? _("<no .debug_str.dwo section>") | |
719 | : _("<no .debug_str section>")); | |
720 | ||
721 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
722 | str_offset -= str_section->address; | |
d949ff56 | 723 | if (str_offset >= str_section->size) |
4723351a CC |
724 | { |
725 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
726 | dwarf_vmatoa ("x", str_offset)); | |
727 | return _("<indirect index offset is too big>"); | |
728 | } | |
729 | ||
d949ff56 NC |
730 | ret = (const char *) str_section->start + str_offset; |
731 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
732 | Since our caller is expecting to receive a well formed C string we test | |
733 | for the lack of a terminating byte here. */ | |
734 | if (strnlen (ret, str_section->size - str_offset) | |
735 | == str_section->size - str_offset) | |
736 | ret = (const char *) _("<no NUL byte at end of section>"); | |
737 | ||
738 | return ret; | |
4723351a CC |
739 | } |
740 | ||
741 | static const char * | |
742 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
743 | { | |
744 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
745 | ||
746 | if (section->start == NULL) | |
747 | return (_("<no .debug_addr section>")); | |
748 | ||
749 | if (offset + bytes > section->size) | |
750 | { | |
751 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 752 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
753 | return "<offset too big>"; |
754 | } | |
755 | ||
756 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
757 | } | |
758 | ||
759 | ||
19e6b90e L |
760 | /* FIXME: There are better and more efficient ways to handle |
761 | these structures. For now though, I just want something that | |
762 | is simple to implement. */ | |
763 | typedef struct abbrev_attr | |
764 | { | |
765 | unsigned long attribute; | |
766 | unsigned long form; | |
77145576 | 767 | bfd_signed_vma implicit_const; |
19e6b90e L |
768 | struct abbrev_attr *next; |
769 | } | |
770 | abbrev_attr; | |
771 | ||
772 | typedef struct abbrev_entry | |
773 | { | |
774 | unsigned long entry; | |
775 | unsigned long tag; | |
776 | int children; | |
777 | struct abbrev_attr *first_attr; | |
778 | struct abbrev_attr *last_attr; | |
779 | struct abbrev_entry *next; | |
780 | } | |
781 | abbrev_entry; | |
782 | ||
783 | static abbrev_entry *first_abbrev = NULL; | |
784 | static abbrev_entry *last_abbrev = NULL; | |
785 | ||
786 | static void | |
787 | free_abbrevs (void) | |
788 | { | |
91d6fa6a | 789 | abbrev_entry *abbrv; |
19e6b90e | 790 | |
91d6fa6a | 791 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 792 | { |
91d6fa6a | 793 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
794 | abbrev_attr *attr; |
795 | ||
91d6fa6a | 796 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 797 | { |
91d6fa6a | 798 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
799 | |
800 | free (attr); | |
91d6fa6a | 801 | attr = next_attr; |
19e6b90e L |
802 | } |
803 | ||
91d6fa6a NC |
804 | free (abbrv); |
805 | abbrv = next_abbrev; | |
19e6b90e L |
806 | } |
807 | ||
808 | last_abbrev = first_abbrev = NULL; | |
809 | } | |
810 | ||
811 | static void | |
812 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
813 | { | |
814 | abbrev_entry *entry; | |
815 | ||
3f5e193b | 816 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
817 | if (entry == NULL) |
818 | /* ugg */ | |
819 | return; | |
820 | ||
821 | entry->entry = number; | |
822 | entry->tag = tag; | |
823 | entry->children = children; | |
824 | entry->first_attr = NULL; | |
825 | entry->last_attr = NULL; | |
826 | entry->next = NULL; | |
827 | ||
828 | if (first_abbrev == NULL) | |
829 | first_abbrev = entry; | |
830 | else | |
831 | last_abbrev->next = entry; | |
832 | ||
833 | last_abbrev = entry; | |
834 | } | |
835 | ||
836 | static void | |
77145576 JK |
837 | add_abbrev_attr (unsigned long attribute, unsigned long form, |
838 | bfd_signed_vma implicit_const) | |
19e6b90e L |
839 | { |
840 | abbrev_attr *attr; | |
841 | ||
3f5e193b | 842 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
843 | if (attr == NULL) |
844 | /* ugg */ | |
845 | return; | |
846 | ||
847 | attr->attribute = attribute; | |
848 | attr->form = form; | |
77145576 | 849 | attr->implicit_const = implicit_const; |
19e6b90e L |
850 | attr->next = NULL; |
851 | ||
852 | if (last_abbrev->first_attr == NULL) | |
853 | last_abbrev->first_attr = attr; | |
854 | else | |
855 | last_abbrev->last_attr->next = attr; | |
856 | ||
857 | last_abbrev->last_attr = attr; | |
858 | } | |
859 | ||
860 | /* Processes the (partial) contents of a .debug_abbrev section. | |
861 | Returns NULL if the end of the section was encountered. | |
862 | Returns the address after the last byte read if the end of | |
863 | an abbreviation set was found. */ | |
864 | ||
865 | static unsigned char * | |
866 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
867 | { | |
868 | if (first_abbrev != NULL) | |
869 | return NULL; | |
870 | ||
871 | while (start < end) | |
872 | { | |
873 | unsigned int bytes_read; | |
874 | unsigned long entry; | |
875 | unsigned long tag; | |
876 | unsigned long attribute; | |
877 | int children; | |
878 | ||
f6f0e17b | 879 | entry = read_uleb128 (start, & bytes_read, end); |
19e6b90e L |
880 | start += bytes_read; |
881 | ||
882 | /* A single zero is supposed to end the section according | |
883 | to the standard. If there's more, then signal that to | |
884 | the caller. */ | |
f6f0e17b NC |
885 | if (start == end) |
886 | return NULL; | |
19e6b90e | 887 | if (entry == 0) |
f6f0e17b | 888 | return start; |
19e6b90e | 889 | |
f6f0e17b | 890 | tag = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 891 | start += bytes_read; |
f6f0e17b NC |
892 | if (start == end) |
893 | return NULL; | |
19e6b90e L |
894 | |
895 | children = *start++; | |
896 | ||
897 | add_abbrev (entry, tag, children); | |
898 | ||
899 | do | |
900 | { | |
901 | unsigned long form; | |
77145576 JK |
902 | /* Initialize it due to a false compiler warning. */ |
903 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 904 | |
f6f0e17b | 905 | attribute = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 906 | start += bytes_read; |
f6f0e17b NC |
907 | if (start == end) |
908 | break; | |
19e6b90e | 909 | |
f6f0e17b | 910 | form = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 911 | start += bytes_read; |
f6f0e17b NC |
912 | if (start == end) |
913 | break; | |
19e6b90e | 914 | |
77145576 JK |
915 | if (form == DW_FORM_implicit_const) |
916 | { | |
917 | implicit_const = read_sleb128 (start, & bytes_read, end); | |
918 | start += bytes_read; | |
919 | if (start == end) | |
920 | break; | |
921 | } | |
922 | ||
923 | add_abbrev_attr (attribute, form, implicit_const); | |
19e6b90e L |
924 | } |
925 | while (attribute != 0); | |
926 | } | |
927 | ||
399c99f7 L |
928 | /* Report the missing single zero which ends the section. */ |
929 | error (_(".debug_abbrev section not zero terminated\n")); | |
930 | ||
19e6b90e L |
931 | return NULL; |
932 | } | |
933 | ||
a19c41a7 | 934 | static const char * |
19e6b90e L |
935 | get_TAG_name (unsigned long tag) |
936 | { | |
b9c361e0 | 937 | const char *name = get_DW_TAG_name ((unsigned int)tag); |
a19c41a7 TT |
938 | |
939 | if (name == NULL) | |
19e6b90e | 940 | { |
a19c41a7 | 941 | static char buffer[100]; |
19e6b90e | 942 | |
a19c41a7 TT |
943 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag); |
944 | return buffer; | |
19e6b90e | 945 | } |
a19c41a7 TT |
946 | |
947 | return name; | |
19e6b90e L |
948 | } |
949 | ||
a19c41a7 | 950 | static const char * |
19e6b90e L |
951 | get_FORM_name (unsigned long form) |
952 | { | |
399c99f7 | 953 | const char *name; |
bf5117e3 | 954 | |
399c99f7 L |
955 | if (form == 0) |
956 | return "DW_FORM value: 0"; | |
a19c41a7 | 957 | |
399c99f7 | 958 | name = get_DW_FORM_name (form); |
a19c41a7 | 959 | if (name == NULL) |
19e6b90e | 960 | { |
a19c41a7 | 961 | static char buffer[100]; |
19e6b90e | 962 | |
a19c41a7 TT |
963 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
964 | return buffer; | |
19e6b90e | 965 | } |
a19c41a7 TT |
966 | |
967 | return name; | |
19e6b90e L |
968 | } |
969 | ||
61364358 JK |
970 | static const char * |
971 | get_IDX_name (unsigned long idx) | |
972 | { | |
973 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
974 | ||
975 | if (name == NULL) | |
976 | { | |
977 | static char buffer[100]; | |
978 | ||
979 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
980 | return buffer; | |
981 | } | |
982 | ||
983 | return name; | |
984 | } | |
985 | ||
19e6b90e | 986 | static unsigned char * |
0c588247 NC |
987 | display_block (unsigned char *data, |
988 | dwarf_vma length, | |
ef0b5f1c | 989 | const unsigned char * const end, char delimiter) |
19e6b90e | 990 | { |
0c588247 NC |
991 | dwarf_vma maxlen; |
992 | ||
ef0b5f1c | 993 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
994 | if (data > end) |
995 | return (unsigned char *) end; | |
19e6b90e | 996 | |
0c588247 NC |
997 | maxlen = (dwarf_vma) (end - data); |
998 | length = length > maxlen ? maxlen : length; | |
999 | ||
19e6b90e L |
1000 | while (length --) |
1001 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1002 | ||
1003 | return data; | |
1004 | } | |
1005 | ||
1006 | static int | |
1007 | decode_location_expression (unsigned char * data, | |
1008 | unsigned int pointer_size, | |
b7807392 JJ |
1009 | unsigned int offset_size, |
1010 | int dwarf_version, | |
467c65bc NC |
1011 | dwarf_vma length, |
1012 | dwarf_vma cu_offset, | |
f1c4cc75 | 1013 | struct dwarf_section * section) |
19e6b90e L |
1014 | { |
1015 | unsigned op; | |
1016 | unsigned int bytes_read; | |
467c65bc | 1017 | dwarf_vma uvalue; |
0c588247 | 1018 | dwarf_signed_vma svalue; |
19e6b90e L |
1019 | unsigned char *end = data + length; |
1020 | int need_frame_base = 0; | |
1021 | ||
1022 | while (data < end) | |
1023 | { | |
1024 | op = *data++; | |
1025 | ||
1026 | switch (op) | |
1027 | { | |
1028 | case DW_OP_addr: | |
0c588247 NC |
1029 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1030 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1031 | break; |
1032 | case DW_OP_deref: | |
1033 | printf ("DW_OP_deref"); | |
1034 | break; | |
1035 | case DW_OP_const1u: | |
0c588247 NC |
1036 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1037 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1038 | break; |
1039 | case DW_OP_const1s: | |
0c588247 NC |
1040 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1041 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1042 | break; |
1043 | case DW_OP_const2u: | |
87bc83b3 | 1044 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1045 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1046 | break; |
1047 | case DW_OP_const2s: | |
0c588247 NC |
1048 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1049 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1050 | break; |
1051 | case DW_OP_const4u: | |
0c588247 NC |
1052 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1053 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1054 | break; |
1055 | case DW_OP_const4s: | |
0c588247 NC |
1056 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1057 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1058 | break; |
1059 | case DW_OP_const8u: | |
0c588247 NC |
1060 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1061 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1062 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1063 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1064 | break; |
1065 | case DW_OP_const8s: | |
0c588247 NC |
1066 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1067 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1068 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1069 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1070 | break; |
1071 | case DW_OP_constu: | |
467c65bc | 1072 | printf ("DW_OP_constu: %s", |
f6f0e17b | 1073 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1074 | data += bytes_read; |
1075 | break; | |
1076 | case DW_OP_consts: | |
467c65bc | 1077 | printf ("DW_OP_consts: %s", |
f6f0e17b | 1078 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1079 | data += bytes_read; |
1080 | break; | |
1081 | case DW_OP_dup: | |
1082 | printf ("DW_OP_dup"); | |
1083 | break; | |
1084 | case DW_OP_drop: | |
1085 | printf ("DW_OP_drop"); | |
1086 | break; | |
1087 | case DW_OP_over: | |
1088 | printf ("DW_OP_over"); | |
1089 | break; | |
1090 | case DW_OP_pick: | |
0c588247 NC |
1091 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1092 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1093 | break; |
1094 | case DW_OP_swap: | |
1095 | printf ("DW_OP_swap"); | |
1096 | break; | |
1097 | case DW_OP_rot: | |
1098 | printf ("DW_OP_rot"); | |
1099 | break; | |
1100 | case DW_OP_xderef: | |
1101 | printf ("DW_OP_xderef"); | |
1102 | break; | |
1103 | case DW_OP_abs: | |
1104 | printf ("DW_OP_abs"); | |
1105 | break; | |
1106 | case DW_OP_and: | |
1107 | printf ("DW_OP_and"); | |
1108 | break; | |
1109 | case DW_OP_div: | |
1110 | printf ("DW_OP_div"); | |
1111 | break; | |
1112 | case DW_OP_minus: | |
1113 | printf ("DW_OP_minus"); | |
1114 | break; | |
1115 | case DW_OP_mod: | |
1116 | printf ("DW_OP_mod"); | |
1117 | break; | |
1118 | case DW_OP_mul: | |
1119 | printf ("DW_OP_mul"); | |
1120 | break; | |
1121 | case DW_OP_neg: | |
1122 | printf ("DW_OP_neg"); | |
1123 | break; | |
1124 | case DW_OP_not: | |
1125 | printf ("DW_OP_not"); | |
1126 | break; | |
1127 | case DW_OP_or: | |
1128 | printf ("DW_OP_or"); | |
1129 | break; | |
1130 | case DW_OP_plus: | |
1131 | printf ("DW_OP_plus"); | |
1132 | break; | |
1133 | case DW_OP_plus_uconst: | |
467c65bc | 1134 | printf ("DW_OP_plus_uconst: %s", |
f6f0e17b | 1135 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1136 | data += bytes_read; |
1137 | break; | |
1138 | case DW_OP_shl: | |
1139 | printf ("DW_OP_shl"); | |
1140 | break; | |
1141 | case DW_OP_shr: | |
1142 | printf ("DW_OP_shr"); | |
1143 | break; | |
1144 | case DW_OP_shra: | |
1145 | printf ("DW_OP_shra"); | |
1146 | break; | |
1147 | case DW_OP_xor: | |
1148 | printf ("DW_OP_xor"); | |
1149 | break; | |
1150 | case DW_OP_bra: | |
0c588247 NC |
1151 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1152 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1153 | break; |
1154 | case DW_OP_eq: | |
1155 | printf ("DW_OP_eq"); | |
1156 | break; | |
1157 | case DW_OP_ge: | |
1158 | printf ("DW_OP_ge"); | |
1159 | break; | |
1160 | case DW_OP_gt: | |
1161 | printf ("DW_OP_gt"); | |
1162 | break; | |
1163 | case DW_OP_le: | |
1164 | printf ("DW_OP_le"); | |
1165 | break; | |
1166 | case DW_OP_lt: | |
1167 | printf ("DW_OP_lt"); | |
1168 | break; | |
1169 | case DW_OP_ne: | |
1170 | printf ("DW_OP_ne"); | |
1171 | break; | |
1172 | case DW_OP_skip: | |
0c588247 NC |
1173 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1174 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1175 | break; |
1176 | ||
1177 | case DW_OP_lit0: | |
1178 | case DW_OP_lit1: | |
1179 | case DW_OP_lit2: | |
1180 | case DW_OP_lit3: | |
1181 | case DW_OP_lit4: | |
1182 | case DW_OP_lit5: | |
1183 | case DW_OP_lit6: | |
1184 | case DW_OP_lit7: | |
1185 | case DW_OP_lit8: | |
1186 | case DW_OP_lit9: | |
1187 | case DW_OP_lit10: | |
1188 | case DW_OP_lit11: | |
1189 | case DW_OP_lit12: | |
1190 | case DW_OP_lit13: | |
1191 | case DW_OP_lit14: | |
1192 | case DW_OP_lit15: | |
1193 | case DW_OP_lit16: | |
1194 | case DW_OP_lit17: | |
1195 | case DW_OP_lit18: | |
1196 | case DW_OP_lit19: | |
1197 | case DW_OP_lit20: | |
1198 | case DW_OP_lit21: | |
1199 | case DW_OP_lit22: | |
1200 | case DW_OP_lit23: | |
1201 | case DW_OP_lit24: | |
1202 | case DW_OP_lit25: | |
1203 | case DW_OP_lit26: | |
1204 | case DW_OP_lit27: | |
1205 | case DW_OP_lit28: | |
1206 | case DW_OP_lit29: | |
1207 | case DW_OP_lit30: | |
1208 | case DW_OP_lit31: | |
1209 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1210 | break; | |
1211 | ||
1212 | case DW_OP_reg0: | |
1213 | case DW_OP_reg1: | |
1214 | case DW_OP_reg2: | |
1215 | case DW_OP_reg3: | |
1216 | case DW_OP_reg4: | |
1217 | case DW_OP_reg5: | |
1218 | case DW_OP_reg6: | |
1219 | case DW_OP_reg7: | |
1220 | case DW_OP_reg8: | |
1221 | case DW_OP_reg9: | |
1222 | case DW_OP_reg10: | |
1223 | case DW_OP_reg11: | |
1224 | case DW_OP_reg12: | |
1225 | case DW_OP_reg13: | |
1226 | case DW_OP_reg14: | |
1227 | case DW_OP_reg15: | |
1228 | case DW_OP_reg16: | |
1229 | case DW_OP_reg17: | |
1230 | case DW_OP_reg18: | |
1231 | case DW_OP_reg19: | |
1232 | case DW_OP_reg20: | |
1233 | case DW_OP_reg21: | |
1234 | case DW_OP_reg22: | |
1235 | case DW_OP_reg23: | |
1236 | case DW_OP_reg24: | |
1237 | case DW_OP_reg25: | |
1238 | case DW_OP_reg26: | |
1239 | case DW_OP_reg27: | |
1240 | case DW_OP_reg28: | |
1241 | case DW_OP_reg29: | |
1242 | case DW_OP_reg30: | |
1243 | case DW_OP_reg31: | |
18464d4d JK |
1244 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1245 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1246 | break; |
1247 | ||
1248 | case DW_OP_breg0: | |
1249 | case DW_OP_breg1: | |
1250 | case DW_OP_breg2: | |
1251 | case DW_OP_breg3: | |
1252 | case DW_OP_breg4: | |
1253 | case DW_OP_breg5: | |
1254 | case DW_OP_breg6: | |
1255 | case DW_OP_breg7: | |
1256 | case DW_OP_breg8: | |
1257 | case DW_OP_breg9: | |
1258 | case DW_OP_breg10: | |
1259 | case DW_OP_breg11: | |
1260 | case DW_OP_breg12: | |
1261 | case DW_OP_breg13: | |
1262 | case DW_OP_breg14: | |
1263 | case DW_OP_breg15: | |
1264 | case DW_OP_breg16: | |
1265 | case DW_OP_breg17: | |
1266 | case DW_OP_breg18: | |
1267 | case DW_OP_breg19: | |
1268 | case DW_OP_breg20: | |
1269 | case DW_OP_breg21: | |
1270 | case DW_OP_breg22: | |
1271 | case DW_OP_breg23: | |
1272 | case DW_OP_breg24: | |
1273 | case DW_OP_breg25: | |
1274 | case DW_OP_breg26: | |
1275 | case DW_OP_breg27: | |
1276 | case DW_OP_breg28: | |
1277 | case DW_OP_breg29: | |
1278 | case DW_OP_breg30: | |
1279 | case DW_OP_breg31: | |
467c65bc | 1280 | printf ("DW_OP_breg%d (%s): %s", |
47704ddf | 1281 | op - DW_OP_breg0, |
18464d4d | 1282 | regname (op - DW_OP_breg0, 1), |
f6f0e17b | 1283 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1284 | data += bytes_read; |
1285 | break; | |
1286 | ||
1287 | case DW_OP_regx: | |
f6f0e17b | 1288 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1289 | data += bytes_read; |
467c65bc NC |
1290 | printf ("DW_OP_regx: %s (%s)", |
1291 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1292 | break; |
1293 | case DW_OP_fbreg: | |
1294 | need_frame_base = 1; | |
467c65bc | 1295 | printf ("DW_OP_fbreg: %s", |
f6f0e17b | 1296 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1297 | data += bytes_read; |
1298 | break; | |
1299 | case DW_OP_bregx: | |
f6f0e17b | 1300 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1301 | data += bytes_read; |
467c65bc NC |
1302 | printf ("DW_OP_bregx: %s (%s) %s", |
1303 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
f6f0e17b | 1304 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1305 | data += bytes_read; |
1306 | break; | |
1307 | case DW_OP_piece: | |
467c65bc | 1308 | printf ("DW_OP_piece: %s", |
f6f0e17b | 1309 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1310 | data += bytes_read; |
1311 | break; | |
1312 | case DW_OP_deref_size: | |
0c588247 NC |
1313 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1314 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1315 | break; |
1316 | case DW_OP_xderef_size: | |
0c588247 NC |
1317 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1318 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1319 | break; |
1320 | case DW_OP_nop: | |
1321 | printf ("DW_OP_nop"); | |
1322 | break; | |
1323 | ||
1324 | /* DWARF 3 extensions. */ | |
1325 | case DW_OP_push_object_address: | |
1326 | printf ("DW_OP_push_object_address"); | |
1327 | break; | |
1328 | case DW_OP_call2: | |
1329 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1330 | this ought to be an 8-byte wide computation. */ | |
0c588247 | 1331 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1332 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1333 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1334 | break; |
1335 | case DW_OP_call4: | |
1336 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1337 | this ought to be an 8-byte wide computation. */ | |
0c588247 | 1338 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1339 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1340 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1341 | break; |
1342 | case DW_OP_call_ref: | |
e2a0d921 NC |
1343 | /* XXX: Strictly speaking for 64-bit DWARF3 files |
1344 | this ought to be an 8-byte wide computation. */ | |
b7807392 JJ |
1345 | if (dwarf_version == -1) |
1346 | { | |
1347 | printf (_("(DW_OP_call_ref in frame info)")); | |
1348 | /* No way to tell where the next op is, so just bail. */ | |
1349 | return need_frame_base; | |
1350 | } | |
1351 | if (dwarf_version == 2) | |
1352 | { | |
0c588247 | 1353 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1354 | } |
1355 | else | |
1356 | { | |
0c588247 | 1357 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1358 | } |
0c588247 | 1359 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1360 | break; |
a87b0a59 NS |
1361 | case DW_OP_form_tls_address: |
1362 | printf ("DW_OP_form_tls_address"); | |
1363 | break; | |
e2a0d921 NC |
1364 | case DW_OP_call_frame_cfa: |
1365 | printf ("DW_OP_call_frame_cfa"); | |
1366 | break; | |
1367 | case DW_OP_bit_piece: | |
1368 | printf ("DW_OP_bit_piece: "); | |
9cf03b7e | 1369 | printf (_("size: %s "), |
f6f0e17b | 1370 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 | 1371 | data += bytes_read; |
9cf03b7e | 1372 | printf (_("offset: %s "), |
f6f0e17b | 1373 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 NC |
1374 | data += bytes_read; |
1375 | break; | |
19e6b90e | 1376 | |
3244e8f5 JJ |
1377 | /* DWARF 4 extensions. */ |
1378 | case DW_OP_stack_value: | |
1379 | printf ("DW_OP_stack_value"); | |
1380 | break; | |
1381 | ||
1382 | case DW_OP_implicit_value: | |
1383 | printf ("DW_OP_implicit_value"); | |
f6f0e17b | 1384 | uvalue = read_uleb128 (data, &bytes_read, end); |
3244e8f5 | 1385 | data += bytes_read; |
ef0b5f1c | 1386 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1387 | break; |
1388 | ||
19e6b90e L |
1389 | /* GNU extensions. */ |
1390 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1391 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1392 | break; |
1393 | case DW_OP_GNU_uninit: | |
1394 | printf ("DW_OP_GNU_uninit"); | |
1395 | /* FIXME: Is there data associated with this OP ? */ | |
1396 | break; | |
f1c4cc75 RH |
1397 | case DW_OP_GNU_encoded_addr: |
1398 | { | |
6937bb54 | 1399 | int encoding = 0; |
f1c4cc75 | 1400 | dwarf_vma addr; |
467c65bc | 1401 | |
6937bb54 NC |
1402 | if (data < end) |
1403 | encoding = *data++; | |
041830e0 | 1404 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1405 | |
1406 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1407 | print_dwarf_vma (addr, pointer_size); | |
1408 | } | |
1409 | break; | |
bc0a77d2 | 1410 | case DW_OP_implicit_pointer: |
b7807392 JJ |
1411 | case DW_OP_GNU_implicit_pointer: |
1412 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1413 | this ought to be an 8-byte wide computation. */ | |
1414 | if (dwarf_version == -1) | |
1415 | { | |
bc0a77d2 JK |
1416 | printf (_("(%s in frame info)"), |
1417 | (op == DW_OP_implicit_pointer | |
1418 | ? "DW_OP_implicit_pointer" | |
1419 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1420 | /* No way to tell where the next op is, so just bail. */ |
1421 | return need_frame_base; | |
1422 | } | |
1423 | if (dwarf_version == 2) | |
1424 | { | |
0c588247 | 1425 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1426 | } |
1427 | else | |
1428 | { | |
0c588247 | 1429 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1430 | } |
bc0a77d2 JK |
1431 | printf ("%s: <0x%s> %s", |
1432 | (op == DW_OP_implicit_pointer | |
1433 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 NC |
1434 | dwarf_vmatoa ("x", uvalue), |
1435 | dwarf_vmatoa ("d", read_sleb128 (data, | |
1436 | &bytes_read, end))); | |
1437 | data += bytes_read; | |
b7807392 | 1438 | break; |
77145576 | 1439 | case DW_OP_entry_value: |
0892011d | 1440 | case DW_OP_GNU_entry_value: |
f6f0e17b | 1441 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1442 | data += bytes_read; |
058037d3 NC |
1443 | /* PR 17531: file: 0cc9cd00. */ |
1444 | if (uvalue > (dwarf_vma) (end - data)) | |
1445 | uvalue = end - data; | |
77145576 JK |
1446 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1447 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1448 | if (decode_location_expression (data, pointer_size, offset_size, |
1449 | dwarf_version, uvalue, | |
1450 | cu_offset, section)) | |
1451 | need_frame_base = 1; | |
1452 | putchar (')'); | |
1453 | data += uvalue; | |
6937bb54 NC |
1454 | if (data > end) |
1455 | data = end; | |
0892011d | 1456 | break; |
bc0a77d2 | 1457 | case DW_OP_const_type: |
0892011d | 1458 | case DW_OP_GNU_const_type: |
f6f0e17b | 1459 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1460 | data += bytes_read; |
bc0a77d2 JK |
1461 | printf ("%s: <0x%s> ", |
1462 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1463 | : "DW_OP_GNU_const_type"), | |
0892011d | 1464 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1465 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1466 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1467 | break; |
bc0a77d2 | 1468 | case DW_OP_regval_type: |
0892011d | 1469 | case DW_OP_GNU_regval_type: |
f6f0e17b | 1470 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1471 | data += bytes_read; |
bc0a77d2 JK |
1472 | printf ("%s: %s (%s)", |
1473 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1474 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1475 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
f6f0e17b | 1476 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1477 | data += bytes_read; |
1478 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1479 | break; | |
bc0a77d2 | 1480 | case DW_OP_deref_type: |
0892011d | 1481 | case DW_OP_GNU_deref_type: |
0c588247 | 1482 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1483 | printf ("%s: %ld", |
1484 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1485 | : "DW_OP_GNU_deref_type"), | |
1486 | (long) uvalue); | |
f6f0e17b | 1487 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1488 | data += bytes_read; |
1489 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1490 | break; | |
bc0a77d2 | 1491 | case DW_OP_convert: |
0892011d | 1492 | case DW_OP_GNU_convert: |
f6f0e17b | 1493 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1494 | data += bytes_read; |
bc0a77d2 JK |
1495 | printf ("%s <0x%s>", |
1496 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1497 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1498 | break; |
bc0a77d2 | 1499 | case DW_OP_reinterpret: |
0892011d | 1500 | case DW_OP_GNU_reinterpret: |
f6f0e17b | 1501 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1502 | data += bytes_read; |
bc0a77d2 JK |
1503 | printf ("%s <0x%s>", |
1504 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1505 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1506 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1507 | break; | |
1508 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1509 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1510 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1511 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1512 | break; |
b4eb7656 AM |
1513 | case DW_OP_GNU_addr_index: |
1514 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1515 | data += bytes_read; | |
1516 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1517 | break; | |
1518 | case DW_OP_GNU_const_index: | |
1519 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1520 | data += bytes_read; | |
1521 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1522 | break; | |
e2a0d921 NC |
1523 | |
1524 | /* HP extensions. */ | |
1525 | case DW_OP_HP_is_value: | |
1526 | printf ("DW_OP_HP_is_value"); | |
1527 | /* FIXME: Is there data associated with this OP ? */ | |
1528 | break; | |
1529 | case DW_OP_HP_fltconst4: | |
1530 | printf ("DW_OP_HP_fltconst4"); | |
1531 | /* FIXME: Is there data associated with this OP ? */ | |
1532 | break; | |
1533 | case DW_OP_HP_fltconst8: | |
1534 | printf ("DW_OP_HP_fltconst8"); | |
1535 | /* FIXME: Is there data associated with this OP ? */ | |
1536 | break; | |
1537 | case DW_OP_HP_mod_range: | |
1538 | printf ("DW_OP_HP_mod_range"); | |
1539 | /* FIXME: Is there data associated with this OP ? */ | |
1540 | break; | |
1541 | case DW_OP_HP_unmod_range: | |
1542 | printf ("DW_OP_HP_unmod_range"); | |
1543 | /* FIXME: Is there data associated with this OP ? */ | |
1544 | break; | |
1545 | case DW_OP_HP_tls: | |
1546 | printf ("DW_OP_HP_tls"); | |
1547 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1548 | break; |
1549 | ||
35d60fe4 NC |
1550 | /* PGI (STMicroelectronics) extensions. */ |
1551 | case DW_OP_PGI_omp_thread_num: | |
1552 | /* Pushes the thread number for the current thread as it would be | |
1553 | returned by the standard OpenMP library function: | |
1554 | omp_get_thread_num(). The "current thread" is the thread for | |
1555 | which the expression is being evaluated. */ | |
1556 | printf ("DW_OP_PGI_omp_thread_num"); | |
1557 | break; | |
1558 | ||
19e6b90e L |
1559 | default: |
1560 | if (op >= DW_OP_lo_user | |
1561 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1562 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1563 | else |
0502a2b4 | 1564 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1565 | /* No way to tell where the next op is, so just bail. */ |
1566 | return need_frame_base; | |
1567 | } | |
1568 | ||
1569 | /* Separate the ops. */ | |
1570 | if (data < end) | |
1571 | printf ("; "); | |
1572 | } | |
1573 | ||
1574 | return need_frame_base; | |
1575 | } | |
1576 | ||
341f9135 CC |
1577 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1578 | This is used for DWARF package files. */ | |
1579 | ||
1580 | static struct cu_tu_set * | |
1581 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1582 | { | |
1583 | struct cu_tu_set *p; | |
1584 | unsigned int nsets; | |
1585 | unsigned int dw_sect; | |
1586 | ||
1587 | if (do_types) | |
1588 | { | |
1589 | p = tu_sets; | |
1590 | nsets = tu_count; | |
1591 | dw_sect = DW_SECT_TYPES; | |
1592 | } | |
1593 | else | |
1594 | { | |
1595 | p = cu_sets; | |
1596 | nsets = cu_count; | |
1597 | dw_sect = DW_SECT_INFO; | |
1598 | } | |
1599 | while (nsets > 0) | |
1600 | { | |
1601 | if (p->section_offsets [dw_sect] == cu_offset) | |
1602 | return p; | |
1603 | p++; | |
1604 | nsets--; | |
1605 | } | |
1606 | return NULL; | |
1607 | } | |
1608 | ||
a69c4772 NC |
1609 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1610 | static void | |
1611 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1612 | { | |
1613 | dwarf_vma tmp = * low_bits; | |
1614 | ||
1615 | tmp += inc; | |
1616 | ||
1617 | /* FIXME: There is probably a better way of handling this: | |
1618 | ||
1619 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1620 | type. Plus regardless of its size LOW_BITS is meant to | |
1621 | only hold 32-bits, so if there is overflow or wrap around | |
1622 | we must propagate into HIGH_BITS. */ | |
1623 | if (tmp < * low_bits) | |
1624 | { | |
1625 | ++ * high_bits; | |
1626 | } | |
1627 | else if (sizeof (tmp) > 8 | |
1628 | && (tmp >> 31) > 1) | |
1629 | { | |
1630 | ++ * high_bits; | |
1631 | tmp &= 0xFFFFFFFF; | |
1632 | } | |
1633 | ||
1634 | * low_bits = tmp; | |
1635 | } | |
1636 | ||
19e6b90e | 1637 | static unsigned char * |
6e3d6dc1 NC |
1638 | read_and_display_attr_value (unsigned long attribute, |
1639 | unsigned long form, | |
77145576 | 1640 | dwarf_signed_vma implicit_const, |
ec4d4525 | 1641 | unsigned char * data, |
f6f0e17b | 1642 | unsigned char * end, |
467c65bc NC |
1643 | dwarf_vma cu_offset, |
1644 | dwarf_vma pointer_size, | |
1645 | dwarf_vma offset_size, | |
6e3d6dc1 NC |
1646 | int dwarf_version, |
1647 | debug_info * debug_info_p, | |
1648 | int do_loc, | |
341f9135 | 1649 | struct dwarf_section * section, |
ef0b5f1c | 1650 | struct cu_tu_set * this_set, char delimiter) |
19e6b90e | 1651 | { |
467c65bc | 1652 | dwarf_vma uvalue = 0; |
19e6b90e | 1653 | unsigned char *block_start = NULL; |
6e3d6dc1 | 1654 | unsigned char * orig_data = data; |
19e6b90e L |
1655 | unsigned int bytes_read; |
1656 | ||
f41e4712 | 1657 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 1658 | { |
f41e4712 | 1659 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
1660 | return data; |
1661 | } | |
1662 | ||
19e6b90e L |
1663 | switch (form) |
1664 | { | |
1665 | default: | |
1666 | break; | |
1667 | ||
1668 | case DW_FORM_ref_addr: | |
1669 | if (dwarf_version == 2) | |
0c588247 | 1670 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
932fd279 | 1671 | else if (dwarf_version == 3 || dwarf_version == 4) |
0c588247 | 1672 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 1673 | else |
467c65bc NC |
1674 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
1675 | ||
19e6b90e L |
1676 | break; |
1677 | ||
1678 | case DW_FORM_addr: | |
0c588247 | 1679 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
1680 | break; |
1681 | ||
1682 | case DW_FORM_strp: | |
77145576 | 1683 | case DW_FORM_line_strp: |
932fd279 | 1684 | case DW_FORM_sec_offset: |
a081f3cd JJ |
1685 | case DW_FORM_GNU_ref_alt: |
1686 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 1687 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
1688 | break; |
1689 | ||
932fd279 JJ |
1690 | case DW_FORM_flag_present: |
1691 | uvalue = 1; | |
1692 | break; | |
1693 | ||
19e6b90e L |
1694 | case DW_FORM_ref1: |
1695 | case DW_FORM_flag: | |
1696 | case DW_FORM_data1: | |
0c588247 | 1697 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
1698 | break; |
1699 | ||
1700 | case DW_FORM_ref2: | |
1701 | case DW_FORM_data2: | |
0c588247 | 1702 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
1703 | break; |
1704 | ||
1705 | case DW_FORM_ref4: | |
1706 | case DW_FORM_data4: | |
0c588247 | 1707 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
1708 | break; |
1709 | ||
1710 | case DW_FORM_sdata: | |
f6f0e17b | 1711 | uvalue = read_sleb128 (data, & bytes_read, end); |
19e6b90e L |
1712 | data += bytes_read; |
1713 | break; | |
1714 | ||
4723351a | 1715 | case DW_FORM_GNU_str_index: |
f6f0e17b | 1716 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1717 | data += bytes_read; |
1718 | break; | |
1719 | ||
19e6b90e L |
1720 | case DW_FORM_ref_udata: |
1721 | case DW_FORM_udata: | |
f6f0e17b | 1722 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1723 | data += bytes_read; |
1724 | break; | |
1725 | ||
1726 | case DW_FORM_indirect: | |
f6f0e17b | 1727 | form = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1728 | data += bytes_read; |
1729 | if (!do_loc) | |
ef0b5f1c | 1730 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 JK |
1731 | if (form == DW_FORM_implicit_const) |
1732 | { | |
1733 | implicit_const = read_sleb128 (data, & bytes_read, end); | |
1734 | data += bytes_read; | |
1735 | } | |
1736 | return read_and_display_attr_value (attribute, form, implicit_const, data, | |
1737 | end, cu_offset, pointer_size, | |
19e6b90e | 1738 | offset_size, dwarf_version, |
ec4d4525 | 1739 | debug_info_p, do_loc, |
ef0b5f1c | 1740 | section, this_set, delimiter); |
4723351a | 1741 | case DW_FORM_GNU_addr_index: |
f6f0e17b | 1742 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1743 | data += bytes_read; |
1744 | break; | |
19e6b90e L |
1745 | } |
1746 | ||
1747 | switch (form) | |
1748 | { | |
1749 | case DW_FORM_ref_addr: | |
1750 | if (!do_loc) | |
ef0b5f1c | 1751 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
1752 | break; |
1753 | ||
a081f3cd JJ |
1754 | case DW_FORM_GNU_ref_alt: |
1755 | if (!do_loc) | |
ef0b5f1c | 1756 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
a081f3cd JJ |
1757 | break; |
1758 | ||
19e6b90e L |
1759 | case DW_FORM_ref1: |
1760 | case DW_FORM_ref2: | |
1761 | case DW_FORM_ref4: | |
1762 | case DW_FORM_ref_udata: | |
1763 | if (!do_loc) | |
ef0b5f1c | 1764 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
1765 | break; |
1766 | ||
1767 | case DW_FORM_data4: | |
1768 | case DW_FORM_addr: | |
932fd279 | 1769 | case DW_FORM_sec_offset: |
19e6b90e | 1770 | if (!do_loc) |
ef0b5f1c | 1771 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
1772 | break; |
1773 | ||
932fd279 | 1774 | case DW_FORM_flag_present: |
19e6b90e L |
1775 | case DW_FORM_flag: |
1776 | case DW_FORM_data1: | |
1777 | case DW_FORM_data2: | |
1778 | case DW_FORM_sdata: | |
1779 | case DW_FORM_udata: | |
1780 | if (!do_loc) | |
ef0b5f1c | 1781 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
1782 | break; |
1783 | ||
77145576 JK |
1784 | case DW_FORM_implicit_const: |
1785 | if (!do_loc) | |
1786 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
1787 | break; | |
1788 | ||
19e6b90e L |
1789 | case DW_FORM_ref8: |
1790 | case DW_FORM_data8: | |
2bc8690c | 1791 | if (!do_loc) |
19e6b90e | 1792 | { |
74bc6052 | 1793 | dwarf_vma high_bits; |
a69c4772 | 1794 | dwarf_vma utmp; |
74bc6052 CC |
1795 | char buf[64]; |
1796 | ||
0c588247 | 1797 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
1798 | utmp = uvalue; |
1799 | if (form == DW_FORM_ref8) | |
1800 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 1801 | printf ("%c0x%s", delimiter, |
a69c4772 | 1802 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 1803 | } |
0c588247 | 1804 | |
19e6b90e L |
1805 | if ((do_loc || do_debug_loc || do_debug_ranges) |
1806 | && num_debug_info_entries == 0) | |
1807 | { | |
1808 | if (sizeof (uvalue) == 8) | |
0c588247 | 1809 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 1810 | else |
467c65bc | 1811 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 1812 | } |
0c588247 | 1813 | |
19e6b90e L |
1814 | data += 8; |
1815 | break; | |
1816 | ||
2f6cd591 JK |
1817 | case DW_FORM_data16: |
1818 | if (!do_loc) | |
1819 | { | |
1820 | dwarf_vma left_high_bits, left_low_bits; | |
1821 | dwarf_vma right_high_bits, right_low_bits; | |
1822 | ||
1823 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
1824 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
1825 | if (byte_get == byte_get_little_endian) | |
1826 | { | |
1827 | /* Swap them. */ | |
1828 | left_high_bits ^= right_high_bits; | |
1829 | right_high_bits ^= left_high_bits; | |
1830 | left_high_bits ^= right_high_bits; | |
1831 | left_low_bits ^= right_low_bits; | |
1832 | right_low_bits ^= left_low_bits; | |
1833 | left_low_bits ^= right_low_bits; | |
1834 | } | |
1835 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
1836 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
1837 | left_high_bits, left_low_bits, right_high_bits, | |
1838 | right_low_bits); | |
1839 | } | |
1840 | data += 16; | |
1841 | break; | |
1842 | ||
19e6b90e L |
1843 | case DW_FORM_string: |
1844 | if (!do_loc) | |
ef0b5f1c | 1845 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 1846 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
1847 | break; |
1848 | ||
1849 | case DW_FORM_block: | |
932fd279 | 1850 | case DW_FORM_exprloc: |
f6f0e17b | 1851 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e | 1852 | block_start = data + bytes_read; |
a1165289 NC |
1853 | if (block_start >= end) |
1854 | { | |
1855 | warn (_("Block ends prematurely\n")); | |
1856 | uvalue = 0; | |
1857 | block_start = end; | |
1858 | } | |
f3853b34 NC |
1859 | /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with |
1860 | gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute | |
1861 | block_start + uvalue here. */ | |
1862 | data = block_start + uvalue; | |
f41e4712 | 1863 | /* PR 17512: file: 008-103549-0.001:0.1. */ |
f3853b34 | 1864 | if (block_start + uvalue > end || data < block_start) |
f41e4712 NC |
1865 | { |
1866 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1867 | uvalue = end - block_start; | |
1868 | } | |
19e6b90e L |
1869 | if (do_loc) |
1870 | data = block_start + uvalue; | |
1871 | else | |
ef0b5f1c | 1872 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
1873 | break; |
1874 | ||
1875 | case DW_FORM_block1: | |
0c588247 | 1876 | SAFE_BYTE_GET (uvalue, data, 1, end); |
19e6b90e | 1877 | block_start = data + 1; |
a1165289 NC |
1878 | if (block_start >= end) |
1879 | { | |
1880 | warn (_("Block ends prematurely\n")); | |
1881 | uvalue = 0; | |
1882 | block_start = end; | |
1883 | } | |
f3853b34 NC |
1884 | data = block_start + uvalue; |
1885 | if (block_start + uvalue > end || data < block_start) | |
f41e4712 NC |
1886 | { |
1887 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1888 | uvalue = end - block_start; | |
1889 | } | |
19e6b90e L |
1890 | if (do_loc) |
1891 | data = block_start + uvalue; | |
1892 | else | |
ef0b5f1c | 1893 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
1894 | break; |
1895 | ||
1896 | case DW_FORM_block2: | |
0c588247 | 1897 | SAFE_BYTE_GET (uvalue, data, 2, end); |
19e6b90e | 1898 | block_start = data + 2; |
a1165289 NC |
1899 | if (block_start >= end) |
1900 | { | |
1901 | warn (_("Block ends prematurely\n")); | |
1902 | uvalue = 0; | |
1903 | block_start = end; | |
1904 | } | |
f3853b34 NC |
1905 | data = block_start + uvalue; |
1906 | if (block_start + uvalue > end || data < block_start) | |
f41e4712 NC |
1907 | { |
1908 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1909 | uvalue = end - block_start; | |
1910 | } | |
19e6b90e L |
1911 | if (do_loc) |
1912 | data = block_start + uvalue; | |
1913 | else | |
ef0b5f1c | 1914 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
1915 | break; |
1916 | ||
1917 | case DW_FORM_block4: | |
0c588247 | 1918 | SAFE_BYTE_GET (uvalue, data, 4, end); |
19e6b90e | 1919 | block_start = data + 4; |
a1165289 NC |
1920 | /* PR 17512: file: 3371-3907-0.004. */ |
1921 | if (block_start >= end) | |
1922 | { | |
1923 | warn (_("Block ends prematurely\n")); | |
1924 | uvalue = 0; | |
1925 | block_start = end; | |
1926 | } | |
f3853b34 NC |
1927 | data = block_start + uvalue; |
1928 | if (block_start + uvalue > end | |
b4eb7656 | 1929 | /* PR 17531: file: 5b5f0592. */ |
f3853b34 | 1930 | || data < block_start) |
f41e4712 NC |
1931 | { |
1932 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1933 | uvalue = end - block_start; | |
1934 | } | |
19e6b90e L |
1935 | if (do_loc) |
1936 | data = block_start + uvalue; | |
1937 | else | |
ef0b5f1c | 1938 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
1939 | break; |
1940 | ||
1941 | case DW_FORM_strp: | |
1942 | if (!do_loc) | |
ef0b5f1c | 1943 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
1944 | dwarf_vmatoa ("x", uvalue), |
1945 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
1946 | break; |
1947 | ||
77145576 JK |
1948 | case DW_FORM_line_strp: |
1949 | if (!do_loc) | |
1950 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
1951 | dwarf_vmatoa ("x", uvalue), | |
1952 | fetch_indirect_line_string (uvalue)); | |
1953 | break; | |
1954 | ||
4723351a CC |
1955 | case DW_FORM_GNU_str_index: |
1956 | if (!do_loc) | |
b4eb7656 AM |
1957 | { |
1958 | const char *suffix = strrchr (section->name, '.'); | |
1959 | int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0; | |
1960 | ||
ef0b5f1c | 1961 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
1962 | dwarf_vmatoa ("x", uvalue), |
1963 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
1964 | } | |
4723351a CC |
1965 | break; |
1966 | ||
a081f3cd JJ |
1967 | case DW_FORM_GNU_strp_alt: |
1968 | if (!do_loc) | |
ef0b5f1c | 1969 | printf (_("%c(alt indirect string, offset: 0x%s)"), delimiter, |
a081f3cd JJ |
1970 | dwarf_vmatoa ("x", uvalue)); |
1971 | break; | |
1972 | ||
19e6b90e L |
1973 | case DW_FORM_indirect: |
1974 | /* Handled above. */ | |
1975 | break; | |
1976 | ||
2b6f5997 CC |
1977 | case DW_FORM_ref_sig8: |
1978 | if (!do_loc) | |
1979 | { | |
74bc6052 CC |
1980 | dwarf_vma high_bits; |
1981 | char buf[64]; | |
1982 | ||
0c588247 | 1983 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 1984 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 1985 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 1986 | } |
74bc6052 | 1987 | data += 8; |
2b6f5997 CC |
1988 | break; |
1989 | ||
4723351a CC |
1990 | case DW_FORM_GNU_addr_index: |
1991 | if (!do_loc) | |
ef0b5f1c | 1992 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
1993 | dwarf_vmatoa ("x", uvalue), |
1994 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
1995 | break; |
1996 | ||
19e6b90e L |
1997 | default: |
1998 | warn (_("Unrecognized form: %lu\n"), form); | |
1999 | break; | |
2000 | } | |
2001 | ||
19e6b90e | 2002 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2003 | && num_debug_info_entries == 0 |
2004 | && debug_info_p != NULL) | |
19e6b90e L |
2005 | { |
2006 | switch (attribute) | |
2007 | { | |
2008 | case DW_AT_frame_base: | |
2009 | have_frame_base = 1; | |
1a0670f3 | 2010 | /* Fall through. */ |
19e6b90e | 2011 | case DW_AT_location: |
e2a0d921 NC |
2012 | case DW_AT_string_length: |
2013 | case DW_AT_return_addr: | |
19e6b90e L |
2014 | case DW_AT_data_member_location: |
2015 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2016 | case DW_AT_segment: |
2017 | case DW_AT_static_link: | |
2018 | case DW_AT_use_location: | |
bc0a77d2 | 2019 | case DW_AT_call_value: |
629e7ca8 | 2020 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2021 | case DW_AT_call_data_value: |
629e7ca8 | 2022 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2023 | case DW_AT_call_target: |
629e7ca8 | 2024 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2025 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2026 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2027 | if ((dwarf_version < 4 |
212b6063 | 2028 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2029 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2030 | { |
2031 | /* Process location list. */ | |
91d6fa6a | 2032 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2033 | unsigned int num = debug_info_p->num_loc_offsets; |
2034 | ||
91d6fa6a | 2035 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2036 | { |
91d6fa6a | 2037 | lmax += 1024; |
467c65bc | 2038 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2039 | xcrealloc (debug_info_p->loc_offsets, |
2040 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
3f5e193b | 2041 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2042 | xcrealloc (debug_info_p->have_frame_base, |
2043 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2044 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2045 | } |
341f9135 | 2046 | if (this_set != NULL) |
b4eb7656 | 2047 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e L |
2048 | debug_info_p->loc_offsets [num] = uvalue; |
2049 | debug_info_p->have_frame_base [num] = have_frame_base; | |
2050 | debug_info_p->num_loc_offsets++; | |
2051 | } | |
2052 | break; | |
e2a0d921 | 2053 | |
19e6b90e L |
2054 | case DW_AT_low_pc: |
2055 | if (need_base_address) | |
2056 | debug_info_p->base_address = uvalue; | |
2057 | break; | |
2058 | ||
4723351a | 2059 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2060 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2061 | break; |
2062 | ||
2063 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2064 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2065 | break; |
2066 | ||
19e6b90e | 2067 | case DW_AT_ranges: |
b4eb7656 | 2068 | if ((dwarf_version < 4 |
212b6063 | 2069 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2070 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2071 | { |
2072 | /* Process range list. */ | |
91d6fa6a | 2073 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2074 | unsigned int num = debug_info_p->num_range_lists; |
2075 | ||
91d6fa6a | 2076 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2077 | { |
91d6fa6a | 2078 | lmax += 1024; |
467c65bc | 2079 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2080 | xcrealloc (debug_info_p->range_lists, |
2081 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2082 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2083 | } |
2084 | debug_info_p->range_lists [num] = uvalue; | |
2085 | debug_info_p->num_range_lists++; | |
2086 | } | |
2087 | break; | |
2088 | ||
2089 | default: | |
2090 | break; | |
2091 | } | |
2092 | } | |
2093 | ||
4ccf1e31 | 2094 | if (do_loc || attribute == 0) |
19e6b90e L |
2095 | return data; |
2096 | ||
ec4d4525 | 2097 | /* For some attributes we can display further information. */ |
19e6b90e L |
2098 | switch (attribute) |
2099 | { | |
2100 | case DW_AT_inline: | |
2e9e81a8 | 2101 | printf ("\t"); |
19e6b90e L |
2102 | switch (uvalue) |
2103 | { | |
2104 | case DW_INL_not_inlined: | |
2105 | printf (_("(not inlined)")); | |
2106 | break; | |
2107 | case DW_INL_inlined: | |
2108 | printf (_("(inlined)")); | |
2109 | break; | |
2110 | case DW_INL_declared_not_inlined: | |
2111 | printf (_("(declared as inline but ignored)")); | |
2112 | break; | |
2113 | case DW_INL_declared_inlined: | |
2114 | printf (_("(declared as inline and inlined)")); | |
2115 | break; | |
2116 | default: | |
47704ddf KT |
2117 | printf (_(" (Unknown inline attribute value: %s)"), |
2118 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2119 | break; |
2120 | } | |
2121 | break; | |
2122 | ||
2123 | case DW_AT_language: | |
2e9e81a8 | 2124 | printf ("\t"); |
19e6b90e L |
2125 | switch (uvalue) |
2126 | { | |
4b78141a | 2127 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2128 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2129 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2130 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2131 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2132 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2133 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2134 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2135 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2136 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2137 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2138 | /* DWARF 2.1 values. */ |
4b78141a | 2139 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2140 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2141 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2142 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2143 | /* DWARF 3 values. */ |
2144 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2145 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2146 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2147 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2148 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2149 | /* DWARF 4 values. */ |
2150 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 ILT |
2151 | /* DWARF 5 values. */ |
2152 | case DW_LANG_Go: printf ("(Go)"); break; | |
8bc10620 | 2153 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
6ddfe5b4 | 2154 | case DW_LANG_C11: printf ("(C11)"); break; |
8bc10620 | 2155 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2156 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2157 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
19e6b90e L |
2158 | /* MIPS extension. */ |
2159 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2160 | /* UPC extension. */ | |
2161 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2162 | default: | |
4b78141a | 2163 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2164 | printf (_("(implementation defined: %s)"), |
467c65bc | 2165 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2166 | else |
9cf03b7e | 2167 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2168 | break; |
2169 | } | |
2170 | break; | |
2171 | ||
2172 | case DW_AT_encoding: | |
2e9e81a8 | 2173 | printf ("\t"); |
19e6b90e L |
2174 | switch (uvalue) |
2175 | { | |
2176 | case DW_ATE_void: printf ("(void)"); break; | |
2177 | case DW_ATE_address: printf ("(machine address)"); break; | |
2178 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2179 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2180 | case DW_ATE_float: printf ("(float)"); break; | |
2181 | case DW_ATE_signed: printf ("(signed)"); break; | |
2182 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2183 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2184 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2185 | /* DWARF 2.1 values: */ |
19e6b90e L |
2186 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2187 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2188 | /* DWARF 3 values: */ |
2189 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2190 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2191 | case DW_ATE_edited: printf ("(edited)"); break; | |
2192 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2193 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
2194 | /* HP extensions: */ | |
2195 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2196 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2197 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2198 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2199 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2200 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2201 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
153a2776 NC |
2202 | /* DWARF 4 values: */ |
2203 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
e2a0d921 | 2204 | |
19e6b90e L |
2205 | default: |
2206 | if (uvalue >= DW_ATE_lo_user | |
2207 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2208 | printf (_("(user defined type)")); |
19e6b90e | 2209 | else |
9cf03b7e | 2210 | printf (_("(unknown type)")); |
19e6b90e L |
2211 | break; |
2212 | } | |
2213 | break; | |
2214 | ||
2215 | case DW_AT_accessibility: | |
2e9e81a8 | 2216 | printf ("\t"); |
19e6b90e L |
2217 | switch (uvalue) |
2218 | { | |
2219 | case DW_ACCESS_public: printf ("(public)"); break; | |
2220 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2221 | case DW_ACCESS_private: printf ("(private)"); break; | |
2222 | default: | |
9cf03b7e | 2223 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2224 | break; |
2225 | } | |
2226 | break; | |
2227 | ||
2228 | case DW_AT_visibility: | |
2e9e81a8 | 2229 | printf ("\t"); |
19e6b90e L |
2230 | switch (uvalue) |
2231 | { | |
2232 | case DW_VIS_local: printf ("(local)"); break; | |
2233 | case DW_VIS_exported: printf ("(exported)"); break; | |
2234 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2235 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2236 | } |
2237 | break; | |
2238 | ||
2239 | case DW_AT_virtuality: | |
2e9e81a8 | 2240 | printf ("\t"); |
19e6b90e L |
2241 | switch (uvalue) |
2242 | { | |
2243 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2244 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2245 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2246 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2247 | } |
2248 | break; | |
2249 | ||
2250 | case DW_AT_identifier_case: | |
2e9e81a8 | 2251 | printf ("\t"); |
19e6b90e L |
2252 | switch (uvalue) |
2253 | { | |
2254 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2255 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2256 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2257 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2258 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2259 | } |
2260 | break; | |
2261 | ||
2262 | case DW_AT_calling_convention: | |
2e9e81a8 | 2263 | printf ("\t"); |
19e6b90e L |
2264 | switch (uvalue) |
2265 | { | |
2266 | case DW_CC_normal: printf ("(normal)"); break; | |
2267 | case DW_CC_program: printf ("(program)"); break; | |
2268 | case DW_CC_nocall: printf ("(nocall)"); break; | |
2269 | default: | |
2270 | if (uvalue >= DW_CC_lo_user | |
2271 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2272 | printf (_("(user defined)")); |
19e6b90e | 2273 | else |
9cf03b7e | 2274 | printf (_("(unknown convention)")); |
19e6b90e L |
2275 | } |
2276 | break; | |
2277 | ||
2278 | case DW_AT_ordering: | |
2e9e81a8 | 2279 | printf ("\t"); |
19e6b90e L |
2280 | switch (uvalue) |
2281 | { | |
9cf03b7e | 2282 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2283 | case 0: printf ("(row major)"); break; |
2284 | case 1: printf ("(column major)"); break; | |
2285 | } | |
2286 | break; | |
2287 | ||
2288 | case DW_AT_frame_base: | |
2289 | have_frame_base = 1; | |
1a0670f3 | 2290 | /* Fall through. */ |
19e6b90e | 2291 | case DW_AT_location: |
e2a0d921 NC |
2292 | case DW_AT_string_length: |
2293 | case DW_AT_return_addr: | |
19e6b90e L |
2294 | case DW_AT_data_member_location: |
2295 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2296 | case DW_AT_segment: |
2297 | case DW_AT_static_link: | |
2298 | case DW_AT_use_location: | |
bc0a77d2 | 2299 | case DW_AT_call_value: |
629e7ca8 | 2300 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2301 | case DW_AT_call_data_value: |
629e7ca8 | 2302 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2303 | case DW_AT_call_target: |
629e7ca8 | 2304 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2305 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2306 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 2307 | if ((dwarf_version < 4 |
b4eb7656 | 2308 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2309 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 2310 | printf (_(" (location list)")); |
e2a0d921 | 2311 | /* Fall through. */ |
19e6b90e L |
2312 | case DW_AT_allocated: |
2313 | case DW_AT_associated: | |
2314 | case DW_AT_data_location: | |
2315 | case DW_AT_stride: | |
2316 | case DW_AT_upper_bound: | |
cecf136e | 2317 | case DW_AT_lower_bound: |
19e6b90e L |
2318 | if (block_start) |
2319 | { | |
2320 | int need_frame_base; | |
2321 | ||
2e9e81a8 | 2322 | printf ("\t("); |
19e6b90e L |
2323 | need_frame_base = decode_location_expression (block_start, |
2324 | pointer_size, | |
b7807392 JJ |
2325 | offset_size, |
2326 | dwarf_version, | |
19e6b90e | 2327 | uvalue, |
f1c4cc75 | 2328 | cu_offset, section); |
19e6b90e L |
2329 | printf (")"); |
2330 | if (need_frame_base && !have_frame_base) | |
2331 | printf (_(" [without DW_AT_frame_base]")); | |
2332 | } | |
19e6b90e L |
2333 | break; |
2334 | ||
ec4d4525 NC |
2335 | case DW_AT_import: |
2336 | { | |
a081f3cd JJ |
2337 | if (form == DW_FORM_ref_sig8 |
2338 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 2339 | break; |
2b6f5997 | 2340 | |
ec4d4525 NC |
2341 | if (form == DW_FORM_ref1 |
2342 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
2343 | || form == DW_FORM_ref4 |
2344 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
2345 | uvalue += cu_offset; |
2346 | ||
6e3d6dc1 | 2347 | if (uvalue >= section->size) |
f3853b34 | 2348 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
2349 | dwarf_vmatoa ("x", uvalue), |
2350 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
2351 | else |
2352 | { | |
2353 | unsigned long abbrev_number; | |
2354 | abbrev_entry * entry; | |
2355 | ||
f6f0e17b | 2356 | abbrev_number = read_uleb128 (section->start + uvalue, NULL, end); |
cecf136e | 2357 | |
2e9e81a8 | 2358 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
2359 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
2360 | use different abbrev table, and we don't track .debug_info chunks | |
2361 | yet. */ | |
2362 | if (form != DW_FORM_ref_addr) | |
2363 | { | |
2364 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
2365 | if (entry->entry == abbrev_number) | |
2366 | break; | |
2367 | if (entry != NULL) | |
2368 | printf (" (%s)", get_TAG_name (entry->tag)); | |
2369 | } | |
6e3d6dc1 NC |
2370 | printf ("]"); |
2371 | } | |
ec4d4525 NC |
2372 | } |
2373 | break; | |
2374 | ||
19e6b90e L |
2375 | default: |
2376 | break; | |
2377 | } | |
2378 | ||
2379 | return data; | |
2380 | } | |
2381 | ||
a19c41a7 | 2382 | static const char * |
19e6b90e L |
2383 | get_AT_name (unsigned long attribute) |
2384 | { | |
a19c41a7 | 2385 | const char *name; |
e2a0d921 | 2386 | |
399c99f7 L |
2387 | if (attribute == 0) |
2388 | return "DW_AT value: 0"; | |
2389 | ||
a19c41a7 TT |
2390 | /* One value is shared by the MIPS and HP extensions: */ |
2391 | if (attribute == DW_AT_MIPS_fde) | |
2392 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
19e6b90e | 2393 | |
a19c41a7 TT |
2394 | name = get_DW_AT_name (attribute); |
2395 | ||
2396 | if (name == NULL) | |
2397 | { | |
2398 | static char buffer[100]; | |
2399 | ||
2400 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
2401 | attribute); | |
2402 | return buffer; | |
19e6b90e | 2403 | } |
a19c41a7 TT |
2404 | |
2405 | return name; | |
19e6b90e L |
2406 | } |
2407 | ||
2408 | static unsigned char * | |
6e3d6dc1 NC |
2409 | read_and_display_attr (unsigned long attribute, |
2410 | unsigned long form, | |
77145576 | 2411 | dwarf_signed_vma implicit_const, |
ec4d4525 | 2412 | unsigned char * data, |
f6f0e17b | 2413 | unsigned char * end, |
467c65bc NC |
2414 | dwarf_vma cu_offset, |
2415 | dwarf_vma pointer_size, | |
2416 | dwarf_vma offset_size, | |
6e3d6dc1 NC |
2417 | int dwarf_version, |
2418 | debug_info * debug_info_p, | |
2419 | int do_loc, | |
341f9135 CC |
2420 | struct dwarf_section * section, |
2421 | struct cu_tu_set * this_set) | |
19e6b90e L |
2422 | { |
2423 | if (!do_loc) | |
750f03b7 | 2424 | printf (" %-18s:", get_AT_name (attribute)); |
77145576 | 2425 | data = read_and_display_attr_value (attribute, form, implicit_const, data, end, |
f6f0e17b | 2426 | cu_offset, pointer_size, offset_size, |
19e6b90e | 2427 | dwarf_version, debug_info_p, |
ef0b5f1c | 2428 | do_loc, section, this_set, ' '); |
19e6b90e L |
2429 | if (!do_loc) |
2430 | printf ("\n"); | |
2431 | return data; | |
2432 | } | |
2433 | ||
19e6b90e L |
2434 | /* Process the contents of a .debug_info section. If do_loc is non-zero |
2435 | then we are scanning for location lists and we do not want to display | |
2b6f5997 CC |
2436 | anything to the user. If do_types is non-zero, we are processing |
2437 | a .debug_types section instead of a .debug_info section. */ | |
19e6b90e L |
2438 | |
2439 | static int | |
6e3d6dc1 NC |
2440 | process_debug_info (struct dwarf_section *section, |
2441 | void *file, | |
b4eb7656 | 2442 | enum dwarf_section_display_enum abbrev_sec, |
2b6f5997 CC |
2443 | int do_loc, |
2444 | int do_types) | |
19e6b90e L |
2445 | { |
2446 | unsigned char *start = section->start; | |
2447 | unsigned char *end = start + section->size; | |
2448 | unsigned char *section_begin; | |
2449 | unsigned int unit; | |
2450 | unsigned int num_units = 0; | |
2451 | ||
2452 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2453 | && num_debug_info_entries == 0 |
2454 | && ! do_types) | |
19e6b90e | 2455 | { |
767221a9 | 2456 | dwarf_vma length; |
19e6b90e L |
2457 | |
2458 | /* First scan the section to get the number of comp units. */ | |
2459 | for (section_begin = start, num_units = 0; section_begin < end; | |
2460 | num_units ++) | |
2461 | { | |
2462 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
2463 | will be the length. For a 64-bit DWARF section, it'll be | |
2464 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 2465 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
2466 | |
2467 | if (length == 0xffffffff) | |
2468 | { | |
0c588247 | 2469 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
2470 | section_begin += length + 12; |
2471 | } | |
ec4d4525 NC |
2472 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
2473 | { | |
767221a9 NC |
2474 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
2475 | dwarf_vmatoa ("x", length), section->name); | |
ec4d4525 NC |
2476 | return 0; |
2477 | } | |
19e6b90e L |
2478 | else |
2479 | section_begin += length + 4; | |
aca88567 NC |
2480 | |
2481 | /* Negative values are illegal, they may even cause infinite | |
2482 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
2483 | relocations to an object file, or if the file is corrupt. */ |
2484 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 2485 | { |
767221a9 NC |
2486 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
2487 | dwarf_vmatoa ("x", length), section->name); | |
aca88567 NC |
2488 | return 0; |
2489 | } | |
19e6b90e L |
2490 | } |
2491 | ||
2492 | if (num_units == 0) | |
2493 | { | |
f41e4712 | 2494 | error (_("No comp units in %s section ?\n"), section->name); |
19e6b90e L |
2495 | return 0; |
2496 | } | |
2497 | ||
2498 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 2499 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 2500 | sizeof (* debug_information)); |
19e6b90e L |
2501 | if (debug_information == NULL) |
2502 | { | |
f41e4712 | 2503 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 2504 | num_units); |
82b1b41b | 2505 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e L |
2506 | return 0; |
2507 | } | |
03a91817 NC |
2508 | /* PR 17531: file: 92ca3797. |
2509 | We cannot rely upon the debug_information array being initialised | |
2510 | before it is used. A corrupt file could easily contain references | |
2511 | to a unit for which information has not been made available. So | |
2512 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
2513 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
2514 | ||
82b1b41b | 2515 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
2516 | } |
2517 | ||
2518 | if (!do_loc) | |
2519 | { | |
fd2f0033 TT |
2520 | if (dwarf_start_die == 0) |
2521 | printf (_("Contents of the %s section:\n\n"), section->name); | |
19e6b90e L |
2522 | |
2523 | load_debug_section (str, file); | |
77145576 | 2524 | load_debug_section (line_str, file); |
4723351a CC |
2525 | load_debug_section (str_dwo, file); |
2526 | load_debug_section (str_index, file); | |
2527 | load_debug_section (str_index_dwo, file); | |
2528 | load_debug_section (debug_addr, file); | |
19e6b90e L |
2529 | } |
2530 | ||
6f875884 TG |
2531 | load_debug_section (abbrev_sec, file); |
2532 | if (debug_displays [abbrev_sec].section.start == NULL) | |
19e6b90e L |
2533 | { |
2534 | warn (_("Unable to locate %s section!\n"), | |
6f875884 | 2535 | debug_displays [abbrev_sec].section.name); |
19e6b90e L |
2536 | return 0; |
2537 | } | |
2538 | ||
2539 | for (section_begin = start, unit = 0; start < end; unit++) | |
2540 | { | |
2541 | DWARF2_Internal_CompUnit compunit; | |
2542 | unsigned char *hdrptr; | |
19e6b90e | 2543 | unsigned char *tags; |
fd2f0033 | 2544 | int level, last_level, saved_level; |
467c65bc | 2545 | dwarf_vma cu_offset; |
bf5117e3 | 2546 | unsigned int offset_size; |
19e6b90e | 2547 | int initial_length_size; |
74bc6052 CC |
2548 | dwarf_vma signature_high = 0; |
2549 | dwarf_vma signature_low = 0; | |
767221a9 | 2550 | dwarf_vma type_offset = 0; |
341f9135 CC |
2551 | struct cu_tu_set *this_set; |
2552 | dwarf_vma abbrev_base; | |
2553 | size_t abbrev_size; | |
19e6b90e L |
2554 | |
2555 | hdrptr = start; | |
2556 | ||
0c588247 | 2557 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
2558 | |
2559 | if (compunit.cu_length == 0xffffffff) | |
2560 | { | |
0c588247 | 2561 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
2562 | offset_size = 8; |
2563 | initial_length_size = 12; | |
2564 | } | |
2565 | else | |
2566 | { | |
2567 | offset_size = 4; | |
2568 | initial_length_size = 4; | |
2569 | } | |
2570 | ||
0c588247 | 2571 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
2572 | |
2573 | cu_offset = start - section_begin; | |
19e6b90e | 2574 | |
341f9135 CC |
2575 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
2576 | ||
77145576 JK |
2577 | if (compunit.cu_version < 5) |
2578 | { | |
2579 | compunit.cu_unit_type = DW_UT_compile; | |
2580 | /* Initialize it due to a false compiler warning. */ | |
2581 | compunit.cu_pointer_size = -1; | |
2582 | } | |
2583 | else | |
2584 | { | |
2585 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
2586 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
2587 | ||
2588 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
2589 | } | |
2590 | ||
0c588247 | 2591 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 2592 | |
341f9135 CC |
2593 | if (this_set == NULL) |
2594 | { | |
2595 | abbrev_base = 0; | |
2596 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
2597 | } | |
2598 | else | |
2599 | { | |
2600 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
2601 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
2602 | } | |
2603 | ||
77145576 JK |
2604 | if (compunit.cu_version < 5) |
2605 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
2606 | ||
f41e4712 NC |
2607 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
2608 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
2609 | { | |
2610 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
2611 | compunit.cu_pointer_size, offset_size); | |
2612 | compunit.cu_pointer_size = offset_size; | |
2613 | } | |
2b6f5997 CC |
2614 | |
2615 | if (do_types) | |
b4eb7656 | 2616 | { |
0c588247 | 2617 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 2618 | hdrptr += 8; |
0c588247 | 2619 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 2620 | } |
2b6f5997 | 2621 | |
19e6b90e | 2622 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
2623 | && num_debug_info_entries == 0 |
2624 | && ! do_types) | |
19e6b90e L |
2625 | { |
2626 | debug_information [unit].cu_offset = cu_offset; | |
2627 | debug_information [unit].pointer_size | |
2628 | = compunit.cu_pointer_size; | |
b7807392 JJ |
2629 | debug_information [unit].offset_size = offset_size; |
2630 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 2631 | debug_information [unit].base_address = 0; |
4723351a CC |
2632 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
2633 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
2634 | debug_information [unit].loc_offsets = NULL; |
2635 | debug_information [unit].have_frame_base = NULL; | |
2636 | debug_information [unit].max_loc_offsets = 0; | |
2637 | debug_information [unit].num_loc_offsets = 0; | |
2638 | debug_information [unit].range_lists = NULL; | |
2639 | debug_information [unit].max_range_lists= 0; | |
2640 | debug_information [unit].num_range_lists = 0; | |
2641 | } | |
2642 | ||
fd2f0033 | 2643 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 2644 | { |
47704ddf KT |
2645 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
2646 | dwarf_vmatoa ("x", cu_offset)); | |
2647 | printf (_(" Length: 0x%s (%s)\n"), | |
2648 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 2649 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 2650 | printf (_(" Version: %d\n"), compunit.cu_version); |
7282333f AM |
2651 | printf (_(" Abbrev Offset: 0x%s\n"), |
2652 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 2653 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
2654 | if (do_types) |
2655 | { | |
74bc6052 CC |
2656 | char buf[64]; |
2657 | ||
2658 | printf (_(" Signature: 0x%s\n"), | |
2659 | dwarf_vmatoa64 (signature_high, signature_low, | |
2660 | buf, sizeof (buf))); | |
2661 | printf (_(" Type Offset: 0x%s\n"), | |
2662 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 2663 | } |
341f9135 CC |
2664 | if (this_set != NULL) |
2665 | { | |
2666 | dwarf_vma *offsets = this_set->section_offsets; | |
2667 | size_t *sizes = this_set->section_sizes; | |
2668 | ||
2669 | printf (_(" Section contributions:\n")); | |
2670 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
2671 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
2672 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
2673 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
2674 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
2675 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
2676 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
2677 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
2678 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
2679 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
2680 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
2681 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
2682 | } | |
19e6b90e L |
2683 | } |
2684 | ||
460c89ff NS |
2685 | if (cu_offset + compunit.cu_length + initial_length_size |
2686 | > section->size) | |
2687 | { | |
47704ddf | 2688 | warn (_("Debug info is corrupted, length of CU at %s" |
b4eb7656 | 2689 | " extends beyond end of section (length = %s)\n"), |
47704ddf KT |
2690 | dwarf_vmatoa ("x", cu_offset), |
2691 | dwarf_vmatoa ("x", compunit.cu_length)); | |
57028622 | 2692 | num_units = unit; |
460c89ff NS |
2693 | break; |
2694 | } | |
2695 | tags = hdrptr; | |
2696 | start += compunit.cu_length + initial_length_size; | |
2697 | ||
57028622 NC |
2698 | if (start > end) |
2699 | { | |
2700 | warn (_("Debug info is corrupt. CU at %s extends beyond end of section"), | |
2701 | dwarf_vmatoa ("x", cu_offset)); | |
2702 | start = end; | |
2703 | } | |
2704 | ||
77145576 | 2705 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 2706 | { |
47704ddf KT |
2707 | warn (_("CU at offset %s contains corrupt or " |
2708 | "unsupported version number: %d.\n"), | |
2709 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
2710 | continue; |
2711 | } | |
2712 | ||
77145576 JK |
2713 | if (compunit.cu_unit_type != DW_UT_compile |
2714 | && compunit.cu_unit_type != DW_UT_type) | |
2715 | { | |
2716 | warn (_("CU at offset %s contains corrupt or " | |
2717 | "unsupported unit type: %d.\n"), | |
2718 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
2719 | continue; | |
2720 | } | |
2721 | ||
19e6b90e L |
2722 | free_abbrevs (); |
2723 | ||
d493b283 | 2724 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 2725 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
2726 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
2727 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 2728 | (unsigned long) abbrev_size); |
b4eb7656 | 2729 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
2730 | else if ((abbrev_base + abbrev_size) |
2731 | > debug_displays [abbrev_sec].section.size) | |
2732 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
2733 | (unsigned long) abbrev_base + abbrev_size, | |
2734 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
2735 | else |
2736 | process_abbrev_section | |
341f9135 CC |
2737 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
2738 | + abbrev_base + compunit.cu_abbrev_offset), | |
2739 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
2740 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
2741 | |
2742 | level = 0; | |
fd2f0033 TT |
2743 | last_level = level; |
2744 | saved_level = -1; | |
19e6b90e L |
2745 | while (tags < start) |
2746 | { | |
2747 | unsigned int bytes_read; | |
2748 | unsigned long abbrev_number; | |
ec4d4525 | 2749 | unsigned long die_offset; |
19e6b90e L |
2750 | abbrev_entry *entry; |
2751 | abbrev_attr *attr; | |
fd2f0033 | 2752 | int do_printing = 1; |
19e6b90e | 2753 | |
ec4d4525 NC |
2754 | die_offset = tags - section_begin; |
2755 | ||
f6f0e17b | 2756 | abbrev_number = read_uleb128 (tags, & bytes_read, start); |
19e6b90e L |
2757 | tags += bytes_read; |
2758 | ||
eb7cc021 JK |
2759 | /* A null DIE marks the end of a list of siblings or it may also be |
2760 | a section padding. */ | |
19e6b90e L |
2761 | if (abbrev_number == 0) |
2762 | { | |
eb7cc021 JK |
2763 | /* Check if it can be a section padding for the last CU. */ |
2764 | if (level == 0 && start == end) | |
2765 | { | |
2766 | unsigned char *chk; | |
2767 | ||
2768 | for (chk = tags; chk < start; chk++) | |
2769 | if (*chk != 0) | |
2770 | break; | |
2771 | if (chk == start) | |
2772 | break; | |
2773 | } | |
2774 | ||
4337774f TT |
2775 | if (!do_loc && die_offset >= dwarf_start_die |
2776 | && (dwarf_cutoff_level == -1 | |
2777 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
2778 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
2779 | level, die_offset); | |
2780 | ||
19e6b90e | 2781 | --level; |
ec4d4525 NC |
2782 | if (level < 0) |
2783 | { | |
2784 | static unsigned num_bogus_warns = 0; | |
2785 | ||
2786 | if (num_bogus_warns < 3) | |
2787 | { | |
4723351a CC |
2788 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
2789 | die_offset, section->name); | |
ec4d4525 NC |
2790 | num_bogus_warns ++; |
2791 | if (num_bogus_warns == 3) | |
2792 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
2793 | } | |
2794 | } | |
fd2f0033 TT |
2795 | if (dwarf_start_die != 0 && level < saved_level) |
2796 | return 1; | |
19e6b90e L |
2797 | continue; |
2798 | } | |
2799 | ||
4b78141a | 2800 | if (!do_loc) |
fd2f0033 TT |
2801 | { |
2802 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
2803 | do_printing = 0; | |
2804 | else | |
2805 | { | |
2806 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
2807 | saved_level = level; | |
2808 | do_printing = (dwarf_cutoff_level == -1 | |
2809 | || level < dwarf_cutoff_level); | |
2810 | if (do_printing) | |
2811 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
2812 | level, die_offset, abbrev_number); | |
2813 | else if (dwarf_cutoff_level == -1 | |
2814 | || last_level < dwarf_cutoff_level) | |
2815 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
2816 | last_level = level; | |
2817 | } | |
2818 | } | |
cecf136e | 2819 | |
19e6b90e L |
2820 | /* Scan through the abbreviation list until we reach the |
2821 | correct entry. */ | |
2822 | for (entry = first_abbrev; | |
2823 | entry && entry->entry != abbrev_number; | |
2824 | entry = entry->next) | |
2825 | continue; | |
2826 | ||
2827 | if (entry == NULL) | |
2828 | { | |
fd2f0033 | 2829 | if (!do_loc && do_printing) |
4b78141a NC |
2830 | { |
2831 | printf ("\n"); | |
2832 | fflush (stdout); | |
2833 | } | |
f3853b34 | 2834 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 2835 | die_offset, abbrev_number); |
19e6b90e L |
2836 | return 0; |
2837 | } | |
2838 | ||
fd2f0033 | 2839 | if (!do_loc && do_printing) |
cc5914eb | 2840 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 2841 | |
19e6b90e L |
2842 | switch (entry->tag) |
2843 | { | |
2844 | default: | |
2845 | need_base_address = 0; | |
2846 | break; | |
2847 | case DW_TAG_compile_unit: | |
2848 | need_base_address = 1; | |
2849 | break; | |
2850 | case DW_TAG_entry_point: | |
19e6b90e L |
2851 | case DW_TAG_subprogram: |
2852 | need_base_address = 0; | |
2853 | /* Assuming that there is no DW_AT_frame_base. */ | |
2854 | have_frame_base = 0; | |
2855 | break; | |
2856 | } | |
2857 | ||
399c99f7 L |
2858 | for (attr = entry->first_attr; |
2859 | attr && attr->attribute; | |
2860 | attr = attr->next) | |
4b78141a | 2861 | { |
fd2f0033 TT |
2862 | debug_info *arg; |
2863 | ||
2864 | if (! do_loc && do_printing) | |
4b78141a | 2865 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 TT |
2866 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
2867 | ||
82b1b41b NC |
2868 | if (debug_information && unit < alloc_num_debug_info_entries) |
2869 | arg = debug_information + unit; | |
2870 | else | |
2871 | arg = NULL; | |
f3853b34 | 2872 | |
4b78141a NC |
2873 | tags = read_and_display_attr (attr->attribute, |
2874 | attr->form, | |
77145576 | 2875 | attr->implicit_const, |
341f9135 | 2876 | tags, |
f6f0e17b | 2877 | end, |
341f9135 | 2878 | cu_offset, |
4b78141a NC |
2879 | compunit.cu_pointer_size, |
2880 | offset_size, | |
2881 | compunit.cu_version, | |
fd2f0033 | 2882 | arg, |
341f9135 CC |
2883 | do_loc || ! do_printing, |
2884 | section, | |
2885 | this_set); | |
4b78141a | 2886 | } |
cecf136e | 2887 | |
b4eb7656 AM |
2888 | if (entry->children) |
2889 | ++level; | |
2890 | } | |
19e6b90e | 2891 | } |
cecf136e | 2892 | |
19e6b90e L |
2893 | /* Set num_debug_info_entries here so that it can be used to check if |
2894 | we need to process .debug_loc and .debug_ranges sections. */ | |
2895 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2896 | && num_debug_info_entries == 0 |
2897 | && ! do_types) | |
82b1b41b | 2898 | { |
b4eb7656 | 2899 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
2900 | num_debug_info_entries = alloc_num_debug_info_entries; |
2901 | else | |
2902 | num_debug_info_entries = num_units; | |
2903 | } | |
cecf136e | 2904 | |
19e6b90e | 2905 | if (!do_loc) |
467c65bc | 2906 | printf ("\n"); |
cecf136e | 2907 | |
19e6b90e L |
2908 | return 1; |
2909 | } | |
2910 | ||
2911 | /* Locate and scan the .debug_info section in the file and record the pointer | |
2912 | sizes and offsets for the compilation units in it. Usually an executable | |
2913 | will have just one pointer size, but this is not guaranteed, and so we try | |
2914 | not to make any assumptions. Returns zero upon failure, or the number of | |
2915 | compilation units upon success. */ | |
2916 | ||
2917 | static unsigned int | |
2918 | load_debug_info (void * file) | |
2919 | { | |
2920 | /* Reset the last pointer size so that we can issue correct error | |
2921 | messages if we are displaying the contents of more than one section. */ | |
2922 | last_pointer_size = 0; | |
2923 | warned_about_missing_comp_units = FALSE; | |
2924 | ||
1febe64d | 2925 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 2926 | section then do not bother to repeat the task. */ |
cc86f28f | 2927 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
2928 | return 0; |
2929 | ||
19e6b90e L |
2930 | /* If we already have the information there is nothing else to do. */ |
2931 | if (num_debug_info_entries > 0) | |
2932 | return num_debug_info_entries; | |
2933 | ||
341f9135 | 2934 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 2935 | (void) load_cu_tu_indexes (file); |
341f9135 | 2936 | |
19e6b90e | 2937 | if (load_debug_section (info, file) |
6f875884 | 2938 | && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0)) |
19e6b90e | 2939 | return num_debug_info_entries; |
82b1b41b NC |
2940 | |
2941 | if (load_debug_section (info_dwo, file) | |
2942 | && process_debug_info (&debug_displays [info_dwo].section, file, | |
2943 | abbrev_dwo, 1, 0)) | |
4723351a | 2944 | return num_debug_info_entries; |
1febe64d | 2945 | |
cc86f28f | 2946 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 2947 | return 0; |
19e6b90e L |
2948 | } |
2949 | ||
b40bf0a2 NC |
2950 | /* Read a DWARF .debug_line section header starting at DATA. |
2951 | Upon success returns an updated DATA pointer and the LINFO | |
2952 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
2953 | Otherwise returns NULL. */ | |
19e6b90e | 2954 | |
b40bf0a2 NC |
2955 | static unsigned char * |
2956 | read_debug_line_header (struct dwarf_section * section, | |
2957 | unsigned char * data, | |
2958 | unsigned char * end, | |
2959 | DWARF2_Internal_LineInfo * linfo, | |
2960 | unsigned char ** end_of_sequence) | |
2961 | { | |
2962 | unsigned char *hdrptr; | |
b40bf0a2 | 2963 | unsigned int initial_length_size; |
77145576 | 2964 | unsigned char address_size, segment_selector_size; |
19e6b90e | 2965 | |
b40bf0a2 NC |
2966 | /* Extract information from the Line Number Program Header. |
2967 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 2968 | hdrptr = data; |
19e6b90e | 2969 | |
b40bf0a2 NC |
2970 | /* Get and check the length of the block. */ |
2971 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 2972 | |
b40bf0a2 | 2973 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
2974 | { |
2975 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 2976 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 2977 | linfo->li_offset_size = 8; |
f41e4712 NC |
2978 | initial_length_size = 12; |
2979 | } | |
2980 | else | |
2981 | { | |
77145576 | 2982 | linfo->li_offset_size = 4; |
f41e4712 NC |
2983 | initial_length_size = 4; |
2984 | } | |
19e6b90e | 2985 | |
b40bf0a2 | 2986 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 2987 | { |
8fcc61b4 NC |
2988 | /* If the length field has a relocation against it, then we should |
2989 | not complain if it is inaccurate (and probably negative). This | |
2990 | happens in object files when the .debug_line section is actually | |
2991 | comprised of several different .debug_line.* sections, (some of | |
2992 | which may be removed by linker garbage collection), and a relocation | |
2993 | is used to compute the correct length once that is done. */ | |
77145576 | 2994 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 2995 | { |
8fcc61b4 | 2996 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
2997 | } |
2998 | else | |
2999 | { | |
8fcc61b4 NC |
3000 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
3001 | (long) linfo->li_length); | |
b40bf0a2 NC |
3002 | return NULL; |
3003 | } | |
f41e4712 | 3004 | } |
19e6b90e | 3005 | |
b40bf0a2 NC |
3006 | /* Get and check the version number. */ |
3007 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
3008 | ||
3009 | if (linfo->li_version != 2 | |
3010 | && linfo->li_version != 3 | |
77145576 JK |
3011 | && linfo->li_version != 4 |
3012 | && linfo->li_version != 5) | |
f41e4712 | 3013 | { |
77145576 JK |
3014 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
3015 | "is currently supported.\n")); | |
b40bf0a2 | 3016 | return NULL; |
f41e4712 | 3017 | } |
19e6b90e | 3018 | |
77145576 JK |
3019 | if (linfo->li_version >= 5) |
3020 | { | |
3021 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
3022 | ||
3023 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
3024 | if (segment_selector_size != 0) | |
3025 | { | |
3026 | warn (_("The %s section contains " | |
3027 | "unsupported segment selector size: %d.\n"), | |
3028 | section->name, segment_selector_size); | |
3029 | return 0; | |
3030 | } | |
3031 | } | |
3032 | ||
3033 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
3034 | linfo->li_offset_size, end); | |
b40bf0a2 | 3035 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 3036 | |
b40bf0a2 | 3037 | if (linfo->li_version >= 4) |
f41e4712 | 3038 | { |
b40bf0a2 | 3039 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 3040 | |
b40bf0a2 | 3041 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
3042 | { |
3043 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 3044 | return NULL; |
a233b20c | 3045 | } |
f41e4712 NC |
3046 | } |
3047 | else | |
b40bf0a2 | 3048 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 3049 | |
b40bf0a2 | 3050 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 3051 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
3052 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
3053 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 3054 | |
b40bf0a2 | 3055 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 3056 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
3057 | if (* end_of_sequence > end) |
3058 | { | |
4c219c2e AM |
3059 | warn (_("Line length %s extends beyond end of section\n"), |
3060 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
3061 | * end_of_sequence = end; |
3062 | return NULL; | |
3063 | } | |
3064 | ||
b40bf0a2 NC |
3065 | return hdrptr; |
3066 | } | |
19e6b90e | 3067 | |
77145576 JK |
3068 | static unsigned char * |
3069 | display_formatted_table (unsigned char *data, | |
3070 | unsigned char *start, unsigned char *end, | |
3071 | const DWARF2_Internal_LineInfo *linfo, | |
3072 | struct dwarf_section *section, const char *what) | |
3073 | { | |
3074 | unsigned char *format_start, format_count, *format, formati; | |
3075 | dwarf_vma data_count, datai; | |
3076 | unsigned int bytes_read, namepass, last_entry = 0; | |
3077 | ||
3078 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3079 | format_start = data; | |
3080 | for (formati = 0; formati < format_count; formati++) | |
3081 | { | |
3082 | read_uleb128 (data, & bytes_read, end); | |
3083 | data += bytes_read; | |
3084 | read_uleb128 (data, & bytes_read, end); | |
3085 | data += bytes_read; | |
3086 | if (data == end) | |
3087 | { | |
3088 | warn (_("Corrupt %s entry format table entry\n"), what); | |
3089 | return data; | |
3090 | } | |
3091 | } | |
3092 | ||
3093 | data_count = read_uleb128 (data, & bytes_read, end); | |
3094 | data += bytes_read; | |
3095 | if (data == end) | |
3096 | { | |
3097 | warn (_("Corrupt %s list\n"), what); | |
3098 | return data; | |
3099 | } | |
3100 | ||
3101 | if (data_count == 0) | |
3102 | { | |
3103 | printf (_("\n The %s Table is empty.\n"), what); | |
3104 | return data; | |
3105 | } | |
3106 | ||
3107 | printf (_("\n The %s Table (offset 0x%lx):\n"), what, | |
3108 | (long)(data - start)); | |
3109 | ||
3110 | printf (_(" Entry")); | |
3111 | /* Delay displaying name as the last entry for better screen layout. */ | |
3112 | for (namepass = 0; namepass < 2; namepass++) | |
3113 | { | |
3114 | format = format_start; | |
3115 | for (formati = 0; formati < format_count; formati++) | |
3116 | { | |
3117 | dwarf_vma content_type; | |
3118 | ||
3119 | content_type = read_uleb128 (format, & bytes_read, end); | |
3120 | format += bytes_read; | |
3121 | if ((content_type == DW_LNCT_path) == (namepass == 1)) | |
3122 | switch (content_type) | |
3123 | { | |
3124 | case DW_LNCT_path: | |
3125 | printf (_("\tName")); | |
3126 | break; | |
3127 | case DW_LNCT_directory_index: | |
3128 | printf (_("\tDir")); | |
3129 | break; | |
3130 | case DW_LNCT_timestamp: | |
3131 | printf (_("\tTime")); | |
3132 | break; | |
3133 | case DW_LNCT_size: | |
3134 | printf (_("\tSize")); | |
3135 | break; | |
3136 | case DW_LNCT_MD5: | |
3137 | printf (_("\tMD5")); | |
3138 | break; | |
3139 | default: | |
3140 | printf (_("\t(Unknown format content type %s)"), | |
3141 | dwarf_vmatoa ("u", content_type)); | |
3142 | } | |
3143 | read_uleb128 (format, & bytes_read, end); | |
3144 | format += bytes_read; | |
3145 | } | |
3146 | } | |
3147 | putchar ('\n'); | |
3148 | ||
3149 | for (datai = 0; datai < data_count; datai++) | |
3150 | { | |
3151 | unsigned char *datapass = data; | |
3152 | ||
3153 | printf (" %d", last_entry++); | |
3154 | /* Delay displaying name as the last entry for better screen layout. */ | |
3155 | for (namepass = 0; namepass < 2; namepass++) | |
3156 | { | |
3157 | format = format_start; | |
3158 | data = datapass; | |
3159 | for (formati = 0; formati < format_count; formati++) | |
3160 | { | |
3161 | dwarf_vma content_type, form; | |
3162 | ||
3163 | content_type = read_uleb128 (format, & bytes_read, end); | |
3164 | format += bytes_read; | |
3165 | form = read_uleb128 (format, & bytes_read, end); | |
3166 | format += bytes_read; | |
3167 | data = read_and_display_attr_value (0, form, 0, data, end, 0, 0, | |
3168 | linfo->li_offset_size, | |
3169 | linfo->li_version, NULL, | |
3170 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
3171 | section, NULL, '\t'); | |
3172 | } | |
3173 | } | |
3174 | if (data == end) | |
3175 | { | |
3176 | warn (_("Corrupt %s entries list\n"), what); | |
3177 | return data; | |
3178 | } | |
3179 | putchar ('\n'); | |
3180 | } | |
3181 | return data; | |
3182 | } | |
3183 | ||
b40bf0a2 NC |
3184 | static int |
3185 | display_debug_lines_raw (struct dwarf_section *section, | |
3186 | unsigned char *data, | |
77145576 | 3187 | unsigned char *end, void *file) |
b40bf0a2 NC |
3188 | { |
3189 | unsigned char *start = section->start; | |
19e6b90e | 3190 | |
b40bf0a2 | 3191 | printf (_("Raw dump of debug contents of section %s:\n\n"), |
b4eb7656 | 3192 | section->name); |
19e6b90e | 3193 | |
b40bf0a2 NC |
3194 | while (data < end) |
3195 | { | |
3196 | static DWARF2_Internal_LineInfo saved_linfo; | |
3197 | DWARF2_Internal_LineInfo linfo; | |
3198 | unsigned char *standard_opcodes; | |
3199 | unsigned char *end_of_sequence; | |
fe59e83d | 3200 | int i; |
19e6b90e | 3201 | |
4925cdd7 NC |
3202 | if (const_strneq (section->name, ".debug_line.") |
3203 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3204 | These are full debug_line sections. */ | |
3205 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 3206 | { |
b40bf0a2 NC |
3207 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
3208 | section containing just the Line Number Statements. They are | |
3209 | created by the assembler and intended to be used alongside gcc's | |
3210 | -ffunction-sections command line option. When the linker's | |
3211 | garbage collection decides to discard a .text.<foo> section it | |
3212 | can then also discard the line number information in .debug_line.<foo>. | |
3213 | ||
4925cdd7 | 3214 | Since the section is a fragment it does not have the details |
b40bf0a2 | 3215 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 3216 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
3217 | end_of_sequence = end; |
3218 | standard_opcodes = NULL; | |
3219 | linfo = saved_linfo; | |
058037d3 NC |
3220 | /* PR 17531: file: 0522b371. */ |
3221 | if (linfo.li_line_range == 0) | |
3222 | { | |
1306a742 | 3223 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3224 | return 0; |
3225 | } | |
b40bf0a2 | 3226 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3227 | } |
19e6b90e L |
3228 | else |
3229 | { | |
b40bf0a2 | 3230 | unsigned char * hdrptr; |
19e6b90e | 3231 | |
b40bf0a2 NC |
3232 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3233 | & end_of_sequence)) == NULL) | |
3234 | return 0; | |
19e6b90e | 3235 | |
b40bf0a2 NC |
3236 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
3237 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
3238 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
77ef8654 | 3239 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
3240 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
3241 | if (linfo.li_version >= 4) | |
3242 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
3243 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
3244 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
3245 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
3246 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 3247 | |
0a9d414a NC |
3248 | /* PR 17512: file: 1665-6428-0.004. */ |
3249 | if (linfo.li_line_range == 0) | |
3250 | { | |
3251 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
3252 | linfo.li_line_range = 1; | |
3253 | } | |
77ef8654 | 3254 | |
b40bf0a2 | 3255 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3256 | |
b40bf0a2 NC |
3257 | /* Display the contents of the Opcodes table. */ |
3258 | standard_opcodes = hdrptr; | |
19e6b90e | 3259 | |
6937bb54 NC |
3260 | /* PR 17512: file: 002-417945-0.004. */ |
3261 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
3262 | { | |
3263 | warn (_("Line Base extends beyond end of section\n")); | |
3264 | return 0; | |
3265 | } | |
3266 | ||
b40bf0a2 | 3267 | printf (_("\n Opcodes:\n")); |
19e6b90e | 3268 | |
b40bf0a2 NC |
3269 | for (i = 1; i < linfo.li_opcode_base; i++) |
3270 | printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); | |
19e6b90e | 3271 | |
b40bf0a2 NC |
3272 | /* Display the contents of the Directory table. */ |
3273 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 3274 | |
77145576 | 3275 | if (linfo.li_version >= 5) |
b40bf0a2 | 3276 | { |
77145576 | 3277 | load_debug_section (line_str, file); |
19e6b90e | 3278 | |
77145576 JK |
3279 | data = display_formatted_table (data, start, end, &linfo, section, |
3280 | _("Directory")); | |
3281 | data = display_formatted_table (data, start, end, &linfo, section, | |
3282 | _("File name")); | |
3283 | } | |
3284 | else | |
3285 | { | |
3286 | if (*data == 0) | |
3287 | printf (_("\n The Directory Table is empty.\n")); | |
3288 | else | |
a233b20c | 3289 | { |
77145576 | 3290 | unsigned int last_dir_entry = 0; |
6937bb54 | 3291 | |
77145576 JK |
3292 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
3293 | (long)(data - start)); | |
19e6b90e | 3294 | |
77145576 JK |
3295 | while (data < end && *data != 0) |
3296 | { | |
3297 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 3298 | |
77145576 JK |
3299 | data += strnlen ((char *) data, end - data) + 1; |
3300 | } | |
19e6b90e | 3301 | |
77145576 JK |
3302 | /* PR 17512: file: 002-132094-0.004. */ |
3303 | if (data >= end - 1) | |
3304 | break; | |
3305 | } | |
19e6b90e | 3306 | |
77145576 JK |
3307 | /* Skip the NUL at the end of the table. */ |
3308 | data++; | |
19e6b90e | 3309 | |
77145576 JK |
3310 | /* Display the contents of the File Name table. */ |
3311 | if (*data == 0) | |
3312 | printf (_("\n The File Name Table is empty.\n")); | |
3313 | else | |
3314 | { | |
3315 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3316 | (long)(data - start)); | |
3317 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 3318 | |
77145576 | 3319 | while (data < end && *data != 0) |
b40bf0a2 | 3320 | { |
77145576 JK |
3321 | unsigned char *name; |
3322 | unsigned int bytes_read; | |
3323 | ||
3324 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
3325 | name = data; | |
3326 | data += strnlen ((char *) data, end - data) + 1; | |
3327 | ||
3328 | printf ("%s\t", | |
3329 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3330 | data += bytes_read; | |
3331 | printf ("%s\t", | |
3332 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3333 | data += bytes_read; | |
3334 | printf ("%s\t", | |
3335 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3336 | data += bytes_read; | |
3337 | printf ("%.*s\n", (int)(end - name), name); | |
3338 | ||
3339 | if (data == end) | |
3340 | { | |
3341 | warn (_("Corrupt file name table entry\n")); | |
3342 | break; | |
3343 | } | |
b40bf0a2 | 3344 | } |
a233b20c | 3345 | } |
77145576 JK |
3346 | |
3347 | /* Skip the NUL at the end of the table. */ | |
3348 | data++; | |
b40bf0a2 | 3349 | } |
19e6b90e | 3350 | |
b40bf0a2 NC |
3351 | putchar ('\n'); |
3352 | saved_linfo = linfo; | |
3353 | } | |
19e6b90e | 3354 | |
b40bf0a2 NC |
3355 | /* Now display the statements. */ |
3356 | if (data >= end_of_sequence) | |
3357 | printf (_(" No Line Number Statements.\n")); | |
3358 | else | |
3359 | { | |
3360 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 3361 | |
b40bf0a2 NC |
3362 | while (data < end_of_sequence) |
3363 | { | |
3364 | unsigned char op_code; | |
3365 | dwarf_signed_vma adv; | |
3366 | dwarf_vma uladv; | |
3367 | unsigned int bytes_read; | |
19e6b90e | 3368 | |
fe59e83d CC |
3369 | printf (" [0x%08lx]", (long)(data - start)); |
3370 | ||
b40bf0a2 | 3371 | op_code = *data++; |
19e6b90e | 3372 | |
b40bf0a2 | 3373 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 3374 | { |
b40bf0a2 NC |
3375 | op_code -= linfo.li_opcode_base; |
3376 | uladv = (op_code / linfo.li_line_range); | |
3377 | if (linfo.li_max_ops_per_insn == 1) | |
3378 | { | |
3379 | uladv *= linfo.li_min_insn_length; | |
3380 | state_machine_regs.address += uladv; | |
3381 | printf (_(" Special opcode %d: " | |
3382 | "advance Address by %s to 0x%s"), | |
3383 | op_code, dwarf_vmatoa ("u", uladv), | |
3384 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
3385 | } | |
3386 | else | |
3387 | { | |
3388 | state_machine_regs.address | |
3389 | += ((state_machine_regs.op_index + uladv) | |
3390 | / linfo.li_max_ops_per_insn) | |
3391 | * linfo.li_min_insn_length; | |
3392 | state_machine_regs.op_index | |
3393 | = (state_machine_regs.op_index + uladv) | |
3394 | % linfo.li_max_ops_per_insn; | |
3395 | printf (_(" Special opcode %d: " | |
3396 | "advance Address by %s to 0x%s[%d]"), | |
3397 | op_code, dwarf_vmatoa ("u", uladv), | |
3398 | dwarf_vmatoa ("x", state_machine_regs.address), | |
3399 | state_machine_regs.op_index); | |
3400 | } | |
3401 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
3402 | state_machine_regs.line += adv; | |
3403 | printf (_(" and Line by %s to %d\n"), | |
3404 | dwarf_vmatoa ("d", adv), state_machine_regs.line); | |
19e6b90e | 3405 | } |
b40bf0a2 NC |
3406 | else switch (op_code) |
3407 | { | |
3408 | case DW_LNS_extended_op: | |
3409 | data += process_extended_line_op (data, linfo.li_default_is_stmt, end); | |
3410 | break; | |
3411 | ||
3412 | case DW_LNS_copy: | |
3413 | printf (_(" Copy\n")); | |
3414 | break; | |
3415 | ||
3416 | case DW_LNS_advance_pc: | |
3417 | uladv = read_uleb128 (data, & bytes_read, end); | |
3418 | data += bytes_read; | |
3419 | if (linfo.li_max_ops_per_insn == 1) | |
3420 | { | |
3421 | uladv *= linfo.li_min_insn_length; | |
3422 | state_machine_regs.address += uladv; | |
3423 | printf (_(" Advance PC by %s to 0x%s\n"), | |
3424 | dwarf_vmatoa ("u", uladv), | |
3425 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
3426 | } | |
3427 | else | |
3428 | { | |
3429 | state_machine_regs.address | |
3430 | += ((state_machine_regs.op_index + uladv) | |
3431 | / linfo.li_max_ops_per_insn) | |
3432 | * linfo.li_min_insn_length; | |
3433 | state_machine_regs.op_index | |
3434 | = (state_machine_regs.op_index + uladv) | |
3435 | % linfo.li_max_ops_per_insn; | |
3436 | printf (_(" Advance PC by %s to 0x%s[%d]\n"), | |
3437 | dwarf_vmatoa ("u", uladv), | |
3438 | dwarf_vmatoa ("x", state_machine_regs.address), | |
3439 | state_machine_regs.op_index); | |
3440 | } | |
3441 | break; | |
3442 | ||
3443 | case DW_LNS_advance_line: | |
3444 | adv = read_sleb128 (data, & bytes_read, end); | |
3445 | data += bytes_read; | |
3446 | state_machine_regs.line += adv; | |
3447 | printf (_(" Advance Line by %s to %d\n"), | |
3448 | dwarf_vmatoa ("d", adv), | |
3449 | state_machine_regs.line); | |
3450 | break; | |
3451 | ||
3452 | case DW_LNS_set_file: | |
3453 | adv = read_uleb128 (data, & bytes_read, end); | |
3454 | data += bytes_read; | |
3455 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
3456 | dwarf_vmatoa ("d", adv)); | |
3457 | state_machine_regs.file = adv; | |
3458 | break; | |
3459 | ||
3460 | case DW_LNS_set_column: | |
3461 | uladv = read_uleb128 (data, & bytes_read, end); | |
3462 | data += bytes_read; | |
3463 | printf (_(" Set column to %s\n"), | |
3464 | dwarf_vmatoa ("u", uladv)); | |
3465 | state_machine_regs.column = uladv; | |
3466 | break; | |
3467 | ||
3468 | case DW_LNS_negate_stmt: | |
3469 | adv = state_machine_regs.is_stmt; | |
3470 | adv = ! adv; | |
3471 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
3472 | state_machine_regs.is_stmt = adv; | |
3473 | break; | |
3474 | ||
3475 | case DW_LNS_set_basic_block: | |
3476 | printf (_(" Set basic block\n")); | |
3477 | state_machine_regs.basic_block = 1; | |
3478 | break; | |
3479 | ||
3480 | case DW_LNS_const_add_pc: | |
3481 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
3482 | if (linfo.li_max_ops_per_insn) | |
3483 | { | |
3484 | uladv *= linfo.li_min_insn_length; | |
3485 | state_machine_regs.address += uladv; | |
3486 | printf (_(" Advance PC by constant %s to 0x%s\n"), | |
3487 | dwarf_vmatoa ("u", uladv), | |
3488 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
3489 | } | |
3490 | else | |
3491 | { | |
3492 | state_machine_regs.address | |
3493 | += ((state_machine_regs.op_index + uladv) | |
3494 | / linfo.li_max_ops_per_insn) | |
3495 | * linfo.li_min_insn_length; | |
3496 | state_machine_regs.op_index | |
3497 | = (state_machine_regs.op_index + uladv) | |
3498 | % linfo.li_max_ops_per_insn; | |
3499 | printf (_(" Advance PC by constant %s to 0x%s[%d]\n"), | |
3500 | dwarf_vmatoa ("u", uladv), | |
3501 | dwarf_vmatoa ("x", state_machine_regs.address), | |
3502 | state_machine_regs.op_index); | |
3503 | } | |
3504 | break; | |
3505 | ||
3506 | case DW_LNS_fixed_advance_pc: | |
3507 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
3508 | state_machine_regs.address += uladv; | |
3509 | state_machine_regs.op_index = 0; | |
3510 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
3511 | dwarf_vmatoa ("u", uladv), | |
3512 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
3513 | break; | |
3514 | ||
3515 | case DW_LNS_set_prologue_end: | |
3516 | printf (_(" Set prologue_end to true\n")); | |
3517 | break; | |
3518 | ||
3519 | case DW_LNS_set_epilogue_begin: | |
3520 | printf (_(" Set epilogue_begin to true\n")); | |
3521 | break; | |
3522 | ||
3523 | case DW_LNS_set_isa: | |
3524 | uladv = read_uleb128 (data, & bytes_read, end); | |
3525 | data += bytes_read; | |
3526 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
3527 | break; | |
3528 | ||
3529 | default: | |
3530 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
3531 | ||
3532 | if (standard_opcodes != NULL) | |
3533 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
3534 | { | |
3535 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
3536 | &bytes_read, end)), | |
3537 | i == 1 ? "" : ", "); | |
3538 | data += bytes_read; | |
3539 | } | |
3540 | putchar ('\n'); | |
3541 | break; | |
3542 | } | |
19e6b90e | 3543 | } |
b40bf0a2 | 3544 | putchar ('\n'); |
19e6b90e | 3545 | } |
19e6b90e L |
3546 | } |
3547 | ||
3548 | return 1; | |
3549 | } | |
3550 | ||
a262ae96 NC |
3551 | typedef struct |
3552 | { | |
467c65bc NC |
3553 | unsigned char *name; |
3554 | unsigned int directory_index; | |
3555 | unsigned int modification_date; | |
3556 | unsigned int length; | |
a262ae96 NC |
3557 | } File_Entry; |
3558 | ||
3559 | /* Output a decoded representation of the .debug_line section. */ | |
3560 | ||
3561 | static int | |
3562 | display_debug_lines_decoded (struct dwarf_section *section, | |
3563 | unsigned char *data, | |
77145576 | 3564 | unsigned char *end, void *fileptr) |
a262ae96 | 3565 | { |
b40bf0a2 NC |
3566 | static DWARF2_Internal_LineInfo saved_linfo; |
3567 | ||
a262ae96 | 3568 | printf (_("Decoded dump of debug contents of section %s:\n\n"), |
b4eb7656 | 3569 | section->name); |
a262ae96 NC |
3570 | |
3571 | while (data < end) | |
3572 | { | |
3573 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 3574 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
3575 | unsigned char *standard_opcodes; |
3576 | unsigned char *end_of_sequence; | |
a262ae96 NC |
3577 | int i; |
3578 | File_Entry *file_table = NULL; | |
143a3db0 | 3579 | unsigned int n_files = 0; |
a262ae96 | 3580 | unsigned char **directory_table = NULL; |
77145576 | 3581 | dwarf_vma n_directories = 0; |
a262ae96 | 3582 | |
4925cdd7 NC |
3583 | if (const_strneq (section->name, ".debug_line.") |
3584 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3585 | These are full debug_line sections. */ | |
3586 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 3587 | { |
4925cdd7 | 3588 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
3589 | end_of_sequence = end; |
3590 | standard_opcodes = NULL; | |
3591 | linfo = saved_linfo; | |
058037d3 NC |
3592 | /* PR 17531: file: 0522b371. */ |
3593 | if (linfo.li_line_range == 0) | |
3594 | { | |
1306a742 | 3595 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3596 | return 0; |
3597 | } | |
b40bf0a2 | 3598 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 3599 | } |
a262ae96 | 3600 | else |
b4eb7656 | 3601 | { |
b40bf0a2 | 3602 | unsigned char *hdrptr; |
a262ae96 | 3603 | |
b40bf0a2 NC |
3604 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3605 | & end_of_sequence)) == NULL) | |
a233b20c | 3606 | return 0; |
0c588247 | 3607 | |
058037d3 NC |
3608 | /* PR 17531: file: 0522b371. */ |
3609 | if (linfo.li_line_range == 0) | |
3610 | { | |
3611 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
3612 | linfo.li_line_range = 1; | |
3613 | } | |
b40bf0a2 | 3614 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 3615 | |
b40bf0a2 NC |
3616 | /* Save a pointer to the contents of the Opcodes table. */ |
3617 | standard_opcodes = hdrptr; | |
a262ae96 | 3618 | |
b40bf0a2 NC |
3619 | /* Traverse the Directory table just to count entries. */ |
3620 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
3621 | /* PR 20440 */ |
3622 | if (data >= end) | |
3623 | { | |
3624 | warn (_("opcode base of %d extends beyond end of section\n"), | |
3625 | linfo.li_opcode_base); | |
3626 | return 0; | |
3627 | } | |
3628 | ||
77145576 | 3629 | if (linfo.li_version >= 5) |
b40bf0a2 | 3630 | { |
77145576 JK |
3631 | unsigned char *format_start, format_count, *format; |
3632 | dwarf_vma formati, entryi; | |
3633 | unsigned int bytes_read; | |
a262ae96 | 3634 | |
77145576 JK |
3635 | load_debug_section (line_str, fileptr); |
3636 | ||
3637 | /* Skip directories format. */ | |
3638 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3639 | format_start = data; | |
3640 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 3641 | { |
77145576 JK |
3642 | read_uleb128 (data, & bytes_read, end); |
3643 | data += bytes_read; | |
3644 | read_uleb128 (data, & bytes_read, end); | |
3645 | data += bytes_read; | |
b40bf0a2 | 3646 | } |
a262ae96 | 3647 | |
77145576 JK |
3648 | n_directories = read_uleb128 (data, & bytes_read, end); |
3649 | data += bytes_read; | |
3650 | if (data == end) | |
d8024a91 | 3651 | { |
77145576 | 3652 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
3653 | break; |
3654 | } | |
3655 | ||
b40bf0a2 NC |
3656 | directory_table = (unsigned char **) |
3657 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 3658 | |
77145576 | 3659 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 3660 | { |
77145576 | 3661 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 3662 | |
77145576 JK |
3663 | format = format_start; |
3664 | for (formati = 0; formati < format_count; formati++) | |
3665 | { | |
3666 | dwarf_vma content_type, form; | |
3667 | dwarf_vma uvalue; | |
3668 | ||
3669 | content_type = read_uleb128 (format, & bytes_read, end); | |
3670 | format += bytes_read; | |
3671 | form = read_uleb128 (format, & bytes_read, end); | |
3672 | format += bytes_read; | |
3673 | if (data == end) | |
3674 | { | |
3675 | warn (_("Corrupt directories list\n")); | |
3676 | break; | |
3677 | } | |
3678 | switch (content_type) | |
3679 | { | |
3680 | case DW_LNCT_path: | |
3681 | switch (form) | |
3682 | { | |
3683 | case DW_FORM_string: | |
3684 | *pathp = data; | |
3685 | break; | |
3686 | case DW_FORM_line_strp: | |
3687 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
3688 | end); | |
3689 | /* Remove const by the cast. */ | |
3690 | *pathp = (unsigned char *) | |
3691 | fetch_indirect_line_string (uvalue); | |
3692 | break; | |
3693 | } | |
3694 | break; | |
3695 | } | |
3696 | data = read_and_display_attr_value (0, form, 0, data, end, | |
3697 | 0, 0, | |
3698 | linfo.li_offset_size, | |
3699 | linfo.li_version, | |
3700 | NULL, 1, section, | |
3701 | NULL, '\t'); | |
3702 | } | |
3703 | if (data == end) | |
3704 | { | |
3705 | warn (_("Corrupt directories list\n")); | |
3706 | break; | |
3707 | } | |
3708 | } | |
a262ae96 | 3709 | |
77145576 JK |
3710 | /* Skip files format. */ |
3711 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3712 | format_start = data; | |
3713 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 3714 | { |
b40bf0a2 NC |
3715 | read_uleb128 (data, & bytes_read, end); |
3716 | data += bytes_read; | |
3717 | read_uleb128 (data, & bytes_read, end); | |
3718 | data += bytes_read; | |
b40bf0a2 | 3719 | } |
a262ae96 | 3720 | |
77145576 JK |
3721 | n_files = read_uleb128 (data, & bytes_read, end); |
3722 | data += bytes_read; | |
3723 | if (data == end) | |
d8024a91 | 3724 | { |
77145576 | 3725 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
3726 | break; |
3727 | } | |
3728 | ||
77145576 JK |
3729 | file_table = (File_Entry *) xcalloc (1, n_files |
3730 | * sizeof (File_Entry)); | |
a262ae96 | 3731 | |
77145576 | 3732 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 3733 | { |
77145576 | 3734 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 3735 | |
77145576 JK |
3736 | format = format_start; |
3737 | for (formati = 0; formati < format_count; formati++) | |
3738 | { | |
3739 | dwarf_vma content_type, form; | |
3740 | dwarf_vma uvalue; | |
3741 | ||
3742 | content_type = read_uleb128 (format, & bytes_read, end); | |
3743 | format += bytes_read; | |
3744 | form = read_uleb128 (format, & bytes_read, end); | |
3745 | format += bytes_read; | |
3746 | if (data == end) | |
3747 | { | |
3748 | warn (_("Corrupt file name list\n")); | |
3749 | break; | |
3750 | } | |
3751 | switch (content_type) | |
3752 | { | |
3753 | case DW_LNCT_path: | |
3754 | switch (form) | |
3755 | { | |
3756 | case DW_FORM_string: | |
3757 | file->name = data; | |
3758 | break; | |
3759 | case DW_FORM_line_strp: | |
3760 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
3761 | end); | |
3762 | /* Remove const by the cast. */ | |
3763 | file->name = (unsigned char *) | |
3764 | fetch_indirect_line_string (uvalue); | |
3765 | break; | |
3766 | } | |
3767 | break; | |
3768 | case DW_LNCT_directory_index: | |
3769 | switch (form) | |
3770 | { | |
3771 | case DW_FORM_data1: | |
3772 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
3773 | end); | |
3774 | break; | |
3775 | case DW_FORM_data2: | |
3776 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
3777 | end); | |
3778 | break; | |
3779 | case DW_FORM_udata: | |
3780 | file->directory_index = read_uleb128 (data, NULL, | |
3781 | end); | |
3782 | break; | |
3783 | } | |
3784 | break; | |
3785 | } | |
3786 | data = read_and_display_attr_value (0, form, 0, data, end, | |
3787 | 0, 0, | |
3788 | linfo.li_offset_size, | |
3789 | linfo.li_version, | |
3790 | NULL, 1, section, | |
3791 | NULL, '\t'); | |
3792 | } | |
3793 | if (data == end) | |
3794 | { | |
3795 | warn (_("Corrupt file name list\n")); | |
3796 | break; | |
3797 | } | |
3798 | } | |
3799 | } | |
3800 | else | |
3801 | { | |
3802 | if (*data != 0) | |
b40bf0a2 | 3803 | { |
77145576 JK |
3804 | unsigned char *ptr_directory_table = data; |
3805 | ||
3806 | while (data < end && *data != 0) | |
3807 | { | |
3808 | data += strnlen ((char *) data, end - data) + 1; | |
3809 | n_directories++; | |
3810 | } | |
3811 | ||
3812 | /* PR 20440 */ | |
3813 | if (data >= end) | |
3814 | { | |
3815 | warn (_("directory table ends unexpectedly\n")); | |
3816 | n_directories = 0; | |
3817 | break; | |
3818 | } | |
3819 | ||
3820 | /* Go through the directory table again to save the directories. */ | |
3821 | directory_table = (unsigned char **) | |
3822 | xmalloc (n_directories * sizeof (unsigned char *)); | |
3823 | ||
3824 | i = 0; | |
3825 | while (*ptr_directory_table != 0) | |
3826 | { | |
3827 | directory_table[i] = ptr_directory_table; | |
3828 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
3829 | ptr_directory_table - end) + 1; | |
3830 | i++; | |
3831 | } | |
b40bf0a2 | 3832 | } |
77145576 JK |
3833 | /* Skip the NUL at the end of the table. */ |
3834 | data++; | |
3835 | ||
3836 | /* Traverse the File Name table just to count the entries. */ | |
3837 | if (data < end && *data != 0) | |
b40bf0a2 | 3838 | { |
77145576 JK |
3839 | unsigned char *ptr_file_name_table = data; |
3840 | ||
3841 | while (data < end && *data != 0) | |
db9537d2 | 3842 | { |
77145576 JK |
3843 | unsigned int bytes_read; |
3844 | ||
3845 | /* Skip Name, directory index, last modification time and length | |
3846 | of file. */ | |
3847 | data += strnlen ((char *) data, end - data) + 1; | |
3848 | read_uleb128 (data, & bytes_read, end); | |
3849 | data += bytes_read; | |
3850 | read_uleb128 (data, & bytes_read, end); | |
3851 | data += bytes_read; | |
3852 | read_uleb128 (data, & bytes_read, end); | |
3853 | data += bytes_read; | |
3854 | ||
3855 | n_files++; | |
db9537d2 | 3856 | } |
a262ae96 | 3857 | |
77145576 JK |
3858 | if (data >= end) |
3859 | { | |
3860 | warn (_("file table ends unexpectedly\n")); | |
3861 | n_files = 0; | |
3862 | break; | |
3863 | } | |
3864 | ||
3865 | /* Go through the file table again to save the strings. */ | |
3866 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 3867 | |
77145576 JK |
3868 | i = 0; |
3869 | while (*ptr_file_name_table != 0) | |
3870 | { | |
3871 | unsigned int bytes_read; | |
3872 | ||
3873 | file_table[i].name = ptr_file_name_table; | |
3874 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
3875 | end - ptr_file_name_table) + 1; | |
3876 | ||
3877 | /* We are not interested in directory, time or size. */ | |
3878 | file_table[i].directory_index = read_uleb128 (ptr_file_name_table, | |
3879 | & bytes_read, end); | |
3880 | ptr_file_name_table += bytes_read; | |
3881 | file_table[i].modification_date = read_uleb128 (ptr_file_name_table, | |
3882 | & bytes_read, end); | |
3883 | ptr_file_name_table += bytes_read; | |
3884 | file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end); | |
3885 | ptr_file_name_table += bytes_read; | |
3886 | i++; | |
3887 | } | |
3888 | i = 0; | |
b40bf0a2 | 3889 | } |
77145576 JK |
3890 | |
3891 | /* Skip the NUL at the end of the table. */ | |
3892 | data++; | |
b40bf0a2 | 3893 | } |
cc5914eb | 3894 | |
77145576 | 3895 | /* Print the Compilation Unit's name and a header. */ |
f082820d AM |
3896 | if (file_table == NULL) |
3897 | ; | |
3898 | else if (directory_table == NULL) | |
3899 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
3900 | else |
3901 | { | |
3902 | unsigned int ix = file_table[0].directory_index; | |
3903 | const char *directory; | |
3904 | ||
3905 | if (ix == 0) | |
3906 | directory = "."; | |
3907 | /* PR 20439 */ | |
3908 | else if (n_directories == 0) | |
3909 | directory = _("<unknown>"); | |
3910 | else if (ix > n_directories) | |
3911 | { | |
3912 | warn (_("directory index %u > number of directories %s\n"), | |
3913 | ix, dwarf_vmatoa ("u", n_directories)); | |
3914 | directory = _("<corrupt>"); | |
3915 | } | |
3916 | else | |
3917 | directory = (char *) directory_table[ix - 1]; | |
3918 | ||
3919 | if (do_wide || strlen (directory) < 76) | |
3920 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
3921 | else | |
3922 | printf ("%s:\n", file_table[0].name); | |
77145576 | 3923 | } |
a262ae96 | 3924 | |
f082820d | 3925 | printf (_("File name Line number Starting address\n")); |
b40bf0a2 NC |
3926 | saved_linfo = linfo; |
3927 | } | |
a262ae96 NC |
3928 | |
3929 | /* This loop iterates through the Dwarf Line Number Program. */ | |
3930 | while (data < end_of_sequence) | |
b4eb7656 | 3931 | { |
a262ae96 | 3932 | unsigned char op_code; |
b4eb7656 AM |
3933 | int adv; |
3934 | unsigned long int uladv; | |
3935 | unsigned int bytes_read; | |
3936 | int is_special_opcode = 0; | |
a262ae96 | 3937 | |
b4eb7656 | 3938 | op_code = *data++; |
a262ae96 | 3939 | |
b4eb7656 | 3940 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 3941 | { |
91d6fa6a | 3942 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
3943 | uladv = (op_code / linfo.li_line_range); |
3944 | if (linfo.li_max_ops_per_insn == 1) | |
3945 | { | |
3946 | uladv *= linfo.li_min_insn_length; | |
3947 | state_machine_regs.address += uladv; | |
3948 | } | |
3949 | else | |
3950 | { | |
3951 | state_machine_regs.address | |
3952 | += ((state_machine_regs.op_index + uladv) | |
3953 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 3954 | * linfo.li_min_insn_length; |
a233b20c JJ |
3955 | state_machine_regs.op_index |
3956 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 3957 | % linfo.li_max_ops_per_insn; |
a233b20c | 3958 | } |
a262ae96 | 3959 | |
b4eb7656 AM |
3960 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
3961 | state_machine_regs.line += adv; | |
3962 | is_special_opcode = 1; | |
3963 | } | |
3964 | else switch (op_code) | |
b40bf0a2 NC |
3965 | { |
3966 | case DW_LNS_extended_op: | |
3967 | { | |
3968 | unsigned int ext_op_code_len; | |
3969 | unsigned char ext_op_code; | |
3970 | unsigned char *op_code_data = data; | |
3971 | ||
3972 | ext_op_code_len = read_uleb128 (op_code_data, &bytes_read, | |
3973 | end_of_sequence); | |
3974 | op_code_data += bytes_read; | |
3975 | ||
3976 | if (ext_op_code_len == 0) | |
3977 | { | |
f41e4712 | 3978 | warn (_("Badly formed extended line op encountered!\n")); |
b40bf0a2 NC |
3979 | break; |
3980 | } | |
3981 | ext_op_code_len += bytes_read; | |
3982 | ext_op_code = *op_code_data++; | |
3983 | ||
3984 | switch (ext_op_code) | |
3985 | { | |
3986 | case DW_LNE_end_sequence: | |
3987 | reset_state_machine (linfo.li_default_is_stmt); | |
3988 | break; | |
3989 | case DW_LNE_set_address: | |
3990 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
87bc83b3 CC |
3991 | op_code_data, |
3992 | ext_op_code_len - bytes_read - 1, | |
b40bf0a2 NC |
3993 | end); |
3994 | state_machine_regs.op_index = 0; | |
3995 | break; | |
3996 | case DW_LNE_define_file: | |
3997 | { | |
3998 | file_table = (File_Entry *) xrealloc | |
3999 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
4000 | ||
4001 | ++state_machine_regs.last_file_entry; | |
4002 | /* Source file name. */ | |
4003 | file_table[n_files].name = op_code_data; | |
4004 | op_code_data += strlen ((char *) op_code_data) + 1; | |
4005 | /* Directory index. */ | |
4006 | file_table[n_files].directory_index = | |
4007 | read_uleb128 (op_code_data, & bytes_read, | |
4008 | end_of_sequence); | |
4009 | op_code_data += bytes_read; | |
4010 | /* Last modification time. */ | |
4011 | file_table[n_files].modification_date = | |
4012 | read_uleb128 (op_code_data, & bytes_read, | |
4013 | end_of_sequence); | |
4014 | op_code_data += bytes_read; | |
4015 | /* File length. */ | |
4016 | file_table[n_files].length = | |
4017 | read_uleb128 (op_code_data, & bytes_read, | |
4018 | end_of_sequence); | |
4019 | ||
4020 | n_files++; | |
4021 | break; | |
4022 | } | |
4023 | case DW_LNE_set_discriminator: | |
4024 | case DW_LNE_HP_set_sequence: | |
4025 | /* Simply ignored. */ | |
4026 | break; | |
4027 | ||
4028 | default: | |
4029 | printf (_("UNKNOWN (%u): length %d\n"), | |
4030 | ext_op_code, ext_op_code_len - bytes_read); | |
4031 | break; | |
4032 | } | |
4033 | data += ext_op_code_len; | |
4034 | break; | |
4035 | } | |
4036 | case DW_LNS_copy: | |
4037 | break; | |
4038 | ||
4039 | case DW_LNS_advance_pc: | |
4040 | uladv = read_uleb128 (data, & bytes_read, end); | |
4041 | data += bytes_read; | |
4042 | if (linfo.li_max_ops_per_insn == 1) | |
4043 | { | |
4044 | uladv *= linfo.li_min_insn_length; | |
4045 | state_machine_regs.address += uladv; | |
4046 | } | |
4047 | else | |
4048 | { | |
4049 | state_machine_regs.address | |
4050 | += ((state_machine_regs.op_index + uladv) | |
4051 | / linfo.li_max_ops_per_insn) | |
4052 | * linfo.li_min_insn_length; | |
4053 | state_machine_regs.op_index | |
4054 | = (state_machine_regs.op_index + uladv) | |
4055 | % linfo.li_max_ops_per_insn; | |
4056 | } | |
4057 | break; | |
4058 | ||
4059 | case DW_LNS_advance_line: | |
4060 | adv = read_sleb128 (data, & bytes_read, end); | |
4061 | data += bytes_read; | |
4062 | state_machine_regs.line += adv; | |
4063 | break; | |
4064 | ||
4065 | case DW_LNS_set_file: | |
4066 | adv = read_uleb128 (data, & bytes_read, end); | |
4067 | data += bytes_read; | |
4068 | state_machine_regs.file = adv; | |
4069 | ||
db9537d2 NC |
4070 | { |
4071 | unsigned file = state_machine_regs.file - 1; | |
4072 | unsigned dir; | |
4073 | ||
4074 | if (file_table == NULL || n_files == 0) | |
4075 | printf (_("\n [Use file table entry %d]\n"), file); | |
4076 | /* PR 20439 */ | |
4077 | else if (file >= n_files) | |
4078 | { | |
4079 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
4080 | printf (_("\n <over large file table index %u>"), file); | |
4081 | } | |
4082 | else if ((dir = file_table[file].directory_index) == 0) | |
4083 | /* If directory index is 0, that means current directory. */ | |
4084 | printf ("\n./%s:[++]\n", file_table[file].name); | |
4085 | else if (directory_table == NULL || n_directories == 0) | |
4086 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
4087 | file_table[file].name, dir); | |
4088 | /* PR 20439 */ | |
4089 | else if (dir > n_directories) | |
4090 | { | |
77145576 JK |
4091 | warn (_("directory index %u > number of directories %s\n"), |
4092 | dir, dwarf_vmatoa ("u", n_directories)); | |
db9537d2 NC |
4093 | printf (_("\n <over large directory table entry %u>\n"), dir); |
4094 | } | |
4095 | else | |
4096 | printf ("\n%s/%s:\n", | |
4097 | /* The directory index starts counting at 1. */ | |
4098 | directory_table[dir - 1], file_table[file].name); | |
4099 | } | |
b40bf0a2 NC |
4100 | break; |
4101 | ||
4102 | case DW_LNS_set_column: | |
4103 | uladv = read_uleb128 (data, & bytes_read, end); | |
4104 | data += bytes_read; | |
4105 | state_machine_regs.column = uladv; | |
4106 | break; | |
4107 | ||
4108 | case DW_LNS_negate_stmt: | |
4109 | adv = state_machine_regs.is_stmt; | |
4110 | adv = ! adv; | |
4111 | state_machine_regs.is_stmt = adv; | |
4112 | break; | |
4113 | ||
4114 | case DW_LNS_set_basic_block: | |
4115 | state_machine_regs.basic_block = 1; | |
4116 | break; | |
4117 | ||
4118 | case DW_LNS_const_add_pc: | |
4119 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4120 | if (linfo.li_max_ops_per_insn == 1) | |
4121 | { | |
4122 | uladv *= linfo.li_min_insn_length; | |
4123 | state_machine_regs.address += uladv; | |
4124 | } | |
4125 | else | |
4126 | { | |
4127 | state_machine_regs.address | |
4128 | += ((state_machine_regs.op_index + uladv) | |
4129 | / linfo.li_max_ops_per_insn) | |
4130 | * linfo.li_min_insn_length; | |
4131 | state_machine_regs.op_index | |
4132 | = (state_machine_regs.op_index + uladv) | |
4133 | % linfo.li_max_ops_per_insn; | |
4134 | } | |
4135 | break; | |
4136 | ||
4137 | case DW_LNS_fixed_advance_pc: | |
4138 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4139 | state_machine_regs.address += uladv; | |
4140 | state_machine_regs.op_index = 0; | |
4141 | break; | |
4142 | ||
4143 | case DW_LNS_set_prologue_end: | |
4144 | break; | |
4145 | ||
4146 | case DW_LNS_set_epilogue_begin: | |
4147 | break; | |
4148 | ||
4149 | case DW_LNS_set_isa: | |
4150 | uladv = read_uleb128 (data, & bytes_read, end); | |
4151 | data += bytes_read; | |
4152 | printf (_(" Set ISA to %lu\n"), uladv); | |
4153 | break; | |
4154 | ||
4155 | default: | |
4156 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4157 | ||
4158 | if (standard_opcodes != NULL) | |
4159 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4160 | { | |
4161 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
4162 | &bytes_read, end)), | |
4163 | i == 1 ? "" : ", "); | |
4164 | data += bytes_read; | |
4165 | } | |
4166 | putchar ('\n'); | |
4167 | break; | |
4168 | } | |
a262ae96 | 4169 | |
b4eb7656 AM |
4170 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
4171 | to the DWARF address/line matrix. */ | |
4172 | if ((is_special_opcode) || (op_code == DW_LNE_end_sequence) | |
a262ae96 | 4173 | || (op_code == DW_LNS_copy)) |
b4eb7656 AM |
4174 | { |
4175 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
4176 | char *fileName; | |
4177 | char *newFileName = NULL; | |
4178 | size_t fileNameLength; | |
b40bf0a2 NC |
4179 | |
4180 | if (file_table) | |
db9537d2 NC |
4181 | { |
4182 | unsigned indx = state_machine_regs.file - 1; | |
4183 | /* PR 20439 */ | |
4184 | if (indx >= n_files) | |
4185 | { | |
4186 | warn (_("corrupt file index %u encountered\n"), indx); | |
4187 | fileName = _("<corrupt>"); | |
4188 | } | |
4189 | else | |
4190 | fileName = (char *) file_table[indx].name; | |
4191 | } | |
b40bf0a2 | 4192 | else |
db9537d2 | 4193 | fileName = _("<unknown>"); |
b40bf0a2 NC |
4194 | |
4195 | fileNameLength = strlen (fileName); | |
a262ae96 | 4196 | |
b4eb7656 AM |
4197 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
4198 | { | |
4199 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
4200 | /* Truncate file name */ | |
4201 | strncpy (newFileName, | |
4202 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
4203 | MAX_FILENAME_LENGTH + 1); | |
4204 | } | |
4205 | else | |
4206 | { | |
4207 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
4208 | strncpy (newFileName, fileName, fileNameLength + 1); | |
4209 | } | |
4210 | ||
4211 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
4212 | { | |
a233b20c | 4213 | if (linfo.li_max_ops_per_insn == 1) |
467c65bc NC |
4214 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n", |
4215 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
4216 | state_machine_regs.address); |
4217 | else | |
467c65bc NC |
4218 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n", |
4219 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
4220 | state_machine_regs.address, |
4221 | state_machine_regs.op_index); | |
b4eb7656 AM |
4222 | } |
4223 | else | |
4224 | { | |
a233b20c | 4225 | if (linfo.li_max_ops_per_insn == 1) |
467c65bc NC |
4226 | printf ("%s %11d %#18" DWARF_VMA_FMT "x\n", |
4227 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
4228 | state_machine_regs.address); |
4229 | else | |
467c65bc NC |
4230 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n", |
4231 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
4232 | state_machine_regs.address, |
4233 | state_machine_regs.op_index); | |
b4eb7656 | 4234 | } |
a262ae96 | 4235 | |
b4eb7656 | 4236 | if (op_code == DW_LNE_end_sequence) |
a262ae96 NC |
4237 | printf ("\n"); |
4238 | ||
b4eb7656 AM |
4239 | free (newFileName); |
4240 | } | |
4241 | } | |
b40bf0a2 NC |
4242 | |
4243 | if (file_table) | |
4244 | { | |
4245 | free (file_table); | |
4246 | file_table = NULL; | |
4247 | n_files = 0; | |
4248 | } | |
4249 | ||
4250 | if (directory_table) | |
4251 | { | |
4252 | free (directory_table); | |
4253 | directory_table = NULL; | |
4254 | n_directories = 0; | |
4255 | } | |
4256 | ||
a262ae96 NC |
4257 | putchar ('\n'); |
4258 | } | |
4259 | ||
4260 | return 1; | |
4261 | } | |
4262 | ||
4263 | static int | |
77145576 | 4264 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
4265 | { |
4266 | unsigned char *data = section->start; | |
4267 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
4268 | int retValRaw = 1; |
4269 | int retValDecoded = 1; | |
a262ae96 | 4270 | |
008f4c78 NC |
4271 | if (do_debug_lines == 0) |
4272 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
4273 | ||
4cb93e3b | 4274 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 4275 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 4276 | |
4cb93e3b | 4277 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
77145576 | 4278 | retValDecoded = display_debug_lines_decoded (section, data, end, file); |
a262ae96 | 4279 | |
4cb93e3b | 4280 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
4281 | return 0; |
4282 | ||
4283 | return 1; | |
4284 | } | |
4285 | ||
6e3d6dc1 NC |
4286 | static debug_info * |
4287 | find_debug_info_for_offset (unsigned long offset) | |
4288 | { | |
4289 | unsigned int i; | |
4290 | ||
4291 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
4292 | return NULL; | |
4293 | ||
4294 | for (i = 0; i < num_debug_info_entries; i++) | |
4295 | if (debug_information[i].cu_offset == offset) | |
4296 | return debug_information + i; | |
4297 | ||
4298 | return NULL; | |
4299 | } | |
4300 | ||
459d52c8 DE |
4301 | static const char * |
4302 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
4303 | { | |
4304 | /* See gdb/gdb-index.h. */ | |
4305 | static const char * const kinds[] = | |
4306 | { | |
4307 | N_ ("no info"), | |
4308 | N_ ("type"), | |
4309 | N_ ("variable"), | |
4310 | N_ ("function"), | |
4311 | N_ ("other"), | |
4312 | N_ ("unused5"), | |
4313 | N_ ("unused6"), | |
4314 | N_ ("unused7") | |
4315 | }; | |
4316 | ||
4317 | return _ (kinds[kind]); | |
4318 | } | |
4319 | ||
19e6b90e | 4320 | static int |
459d52c8 DE |
4321 | display_debug_pubnames_worker (struct dwarf_section *section, |
4322 | void *file ATTRIBUTE_UNUSED, | |
4323 | int is_gnu) | |
19e6b90e | 4324 | { |
91d6fa6a | 4325 | DWARF2_Internal_PubNames names; |
19e6b90e L |
4326 | unsigned char *start = section->start; |
4327 | unsigned char *end = start + section->size; | |
4328 | ||
6e3d6dc1 NC |
4329 | /* It does not matter if this load fails, |
4330 | we test for that later on. */ | |
4331 | load_debug_info (file); | |
4332 | ||
19e6b90e L |
4333 | printf (_("Contents of the %s section:\n\n"), section->name); |
4334 | ||
4335 | while (start < end) | |
4336 | { | |
4337 | unsigned char *data; | |
362beea4 | 4338 | unsigned char *adr; |
834f871c | 4339 | dwarf_vma offset; |
bf5117e3 | 4340 | unsigned int offset_size, initial_length_size; |
19e6b90e L |
4341 | |
4342 | data = start; | |
4343 | ||
0c588247 | 4344 | SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end); |
91d6fa6a | 4345 | if (names.pn_length == 0xffffffff) |
19e6b90e | 4346 | { |
0c588247 | 4347 | SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end); |
19e6b90e L |
4348 | offset_size = 8; |
4349 | initial_length_size = 12; | |
4350 | } | |
4351 | else | |
4352 | { | |
4353 | offset_size = 4; | |
4354 | initial_length_size = 4; | |
4355 | } | |
4356 | ||
0c588247 NC |
4357 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
4358 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
4359 | |
4360 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
4361 | && num_debug_info_entries > 0 | |
91d6fa6a | 4362 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 4363 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 4364 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 4365 | |
0c588247 | 4366 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 4367 | |
362beea4 | 4368 | adr = start + names.pn_length + initial_length_size; |
058037d3 | 4369 | /* PR 17531: file: 7615b6b2. */ |
57028622 NC |
4370 | if ((dwarf_signed_vma) names.pn_length < 0 |
4371 | /* PR 17531: file: a5dbeaa7. */ | |
362beea4 | 4372 | || adr < start) |
058037d3 NC |
4373 | { |
4374 | warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length); | |
4375 | start = end; | |
4376 | } | |
4377 | else | |
362beea4 | 4378 | start = adr; |
b4eb7656 | 4379 | |
058037d3 NC |
4380 | printf (_(" Length: %ld\n"), |
4381 | (long) names.pn_length); | |
4382 | printf (_(" Version: %d\n"), | |
4383 | names.pn_version); | |
4384 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
4385 | (unsigned long) names.pn_offset); | |
4386 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
4387 | (long) names.pn_size); | |
19e6b90e | 4388 | |
91d6fa6a | 4389 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
4390 | { |
4391 | static int warned = 0; | |
4392 | ||
4393 | if (! warned) | |
4394 | { | |
4395 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
4396 | warned = 1; | |
4397 | } | |
4398 | ||
4399 | continue; | |
4400 | } | |
4401 | ||
459d52c8 DE |
4402 | if (is_gnu) |
4403 | printf (_("\n Offset Kind Name\n")); | |
4404 | else | |
4405 | printf (_("\n Offset\tName\n")); | |
19e6b90e L |
4406 | |
4407 | do | |
4408 | { | |
f41e4712 NC |
4409 | bfd_size_type maxprint; |
4410 | ||
0c588247 | 4411 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e L |
4412 | |
4413 | if (offset != 0) | |
4414 | { | |
4415 | data += offset_size; | |
f41e4712 NC |
4416 | if (data >= end) |
4417 | break; | |
4418 | maxprint = (end - data) - 1; | |
b4eb7656 | 4419 | |
459d52c8 DE |
4420 | if (is_gnu) |
4421 | { | |
4422 | unsigned int kind_data; | |
4423 | gdb_index_symbol_kind kind; | |
4424 | const char *kind_name; | |
4425 | int is_static; | |
4426 | ||
4427 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
4428 | data++; | |
f41e4712 | 4429 | maxprint --; |
459d52c8 DE |
4430 | /* GCC computes the kind as the upper byte in the CU index |
4431 | word, and then right shifts it by the CU index size. | |
4432 | Left shift KIND to where the gdb-index.h accessor macros | |
4433 | can use it. */ | |
4434 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
4435 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
4436 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
4437 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
f41e4712 | 4438 | printf (" %-6lx %s,%-10s %.*s\n", |
834f871c | 4439 | (unsigned long) offset, is_static ? _("s") : _("g"), |
f41e4712 | 4440 | kind_name, (int) maxprint, data); |
459d52c8 DE |
4441 | } |
4442 | else | |
b4eb7656 AM |
4443 | printf (" %-6lx\t%.*s\n", |
4444 | (unsigned long) offset, (int) maxprint, data); | |
f41e4712 NC |
4445 | |
4446 | data += strnlen ((char *) data, maxprint) + 1; | |
4447 | if (data >= end) | |
4448 | break; | |
19e6b90e L |
4449 | } |
4450 | } | |
4451 | while (offset != 0); | |
4452 | } | |
4453 | ||
4454 | printf ("\n"); | |
4455 | return 1; | |
4456 | } | |
4457 | ||
459d52c8 DE |
4458 | static int |
4459 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
4460 | { | |
4461 | return display_debug_pubnames_worker (section, file, 0); | |
4462 | } | |
4463 | ||
4464 | static int | |
4465 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
4466 | { | |
4467 | return display_debug_pubnames_worker (section, file, 1); | |
4468 | } | |
4469 | ||
19e6b90e L |
4470 | static int |
4471 | display_debug_macinfo (struct dwarf_section *section, | |
4472 | void *file ATTRIBUTE_UNUSED) | |
4473 | { | |
4474 | unsigned char *start = section->start; | |
4475 | unsigned char *end = start + section->size; | |
4476 | unsigned char *curr = start; | |
4477 | unsigned int bytes_read; | |
4478 | enum dwarf_macinfo_record_type op; | |
4479 | ||
4480 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4481 | ||
4482 | while (curr < end) | |
4483 | { | |
4484 | unsigned int lineno; | |
0c588247 | 4485 | const unsigned char *string; |
19e6b90e | 4486 | |
3f5e193b | 4487 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
4488 | curr++; |
4489 | ||
4490 | switch (op) | |
4491 | { | |
4492 | case DW_MACINFO_start_file: | |
4493 | { | |
4494 | unsigned int filenum; | |
4495 | ||
f6f0e17b | 4496 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 4497 | curr += bytes_read; |
f6f0e17b | 4498 | filenum = read_uleb128 (curr, & bytes_read, end); |
19e6b90e L |
4499 | curr += bytes_read; |
4500 | ||
4501 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
4502 | lineno, filenum); | |
4503 | } | |
4504 | break; | |
4505 | ||
4506 | case DW_MACINFO_end_file: | |
4507 | printf (_(" DW_MACINFO_end_file\n")); | |
4508 | break; | |
4509 | ||
4510 | case DW_MACINFO_define: | |
f6f0e17b | 4511 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 4512 | curr += bytes_read; |
0c588247 NC |
4513 | string = curr; |
4514 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
4515 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
4516 | lineno, string); | |
4517 | break; | |
4518 | ||
4519 | case DW_MACINFO_undef: | |
f6f0e17b | 4520 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 4521 | curr += bytes_read; |
0c588247 NC |
4522 | string = curr; |
4523 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
4524 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
4525 | lineno, string); | |
4526 | break; | |
4527 | ||
4528 | case DW_MACINFO_vendor_ext: | |
4529 | { | |
4530 | unsigned int constant; | |
4531 | ||
f6f0e17b | 4532 | constant = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 4533 | curr += bytes_read; |
0c588247 NC |
4534 | string = curr; |
4535 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
4536 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
4537 | constant, string); | |
4538 | } | |
4539 | break; | |
4540 | } | |
4541 | } | |
4542 | ||
4543 | return 1; | |
4544 | } | |
4545 | ||
4ccf1e31 JJ |
4546 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
4547 | filename and dirname corresponding to file name table entry with index | |
4548 | FILEIDX. Return NULL on failure. */ | |
4549 | ||
4550 | static unsigned char * | |
f6f0e17b NC |
4551 | get_line_filename_and_dirname (dwarf_vma line_offset, |
4552 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
4553 | unsigned char **dir_name) |
4554 | { | |
4555 | struct dwarf_section *section = &debug_displays [line].section; | |
4556 | unsigned char *hdrptr, *dirtable, *file_name; | |
4557 | unsigned int offset_size, initial_length_size; | |
4558 | unsigned int version, opcode_base, bytes_read; | |
4559 | dwarf_vma length, diridx; | |
f6f0e17b | 4560 | const unsigned char * end; |
4ccf1e31 JJ |
4561 | |
4562 | *dir_name = NULL; | |
4563 | if (section->start == NULL | |
4564 | || line_offset >= section->size | |
4565 | || fileidx == 0) | |
4566 | return NULL; | |
4567 | ||
4568 | hdrptr = section->start + line_offset; | |
f6f0e17b | 4569 | end = section->start + section->size; |
0c588247 NC |
4570 | |
4571 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
4572 | if (length == 0xffffffff) |
4573 | { | |
4574 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 4575 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
4576 | offset_size = 8; |
4577 | initial_length_size = 12; | |
4578 | } | |
4579 | else | |
4580 | { | |
4581 | offset_size = 4; | |
4582 | initial_length_size = 4; | |
4583 | } | |
4584 | if (length + initial_length_size > section->size) | |
4585 | return NULL; | |
0c588247 NC |
4586 | |
4587 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
4588 | if (version != 2 && version != 3 && version != 4) |
4589 | return NULL; | |
4590 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
4591 | if (version >= 4) | |
4592 | hdrptr++; /* Skip max_ops_per_insn. */ | |
4593 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
4594 | |
4595 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
4596 | if (opcode_base == 0) |
4597 | return NULL; | |
0c588247 | 4598 | |
4ccf1e31 JJ |
4599 | hdrptr += opcode_base - 1; |
4600 | dirtable = hdrptr; | |
4601 | /* Skip over dirname table. */ | |
4602 | while (*hdrptr != '\0') | |
0c588247 | 4603 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
4ccf1e31 JJ |
4604 | hdrptr++; /* Skip the NUL at the end of the table. */ |
4605 | /* Now skip over preceding filename table entries. */ | |
4606 | for (; *hdrptr != '\0' && fileidx > 1; fileidx--) | |
4607 | { | |
0c588247 | 4608 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 4609 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 4610 | hdrptr += bytes_read; |
f6f0e17b | 4611 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 4612 | hdrptr += bytes_read; |
f6f0e17b | 4613 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
4614 | hdrptr += bytes_read; |
4615 | } | |
f6f0e17b | 4616 | if (hdrptr == end || *hdrptr == '\0') |
4ccf1e31 JJ |
4617 | return NULL; |
4618 | file_name = hdrptr; | |
0c588247 | 4619 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 4620 | diridx = read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
4621 | if (diridx == 0) |
4622 | return file_name; | |
4623 | for (; *dirtable != '\0' && diridx > 1; diridx--) | |
0c588247 | 4624 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
4ccf1e31 JJ |
4625 | if (*dirtable == '\0') |
4626 | return NULL; | |
4627 | *dir_name = dirtable; | |
4628 | return file_name; | |
4629 | } | |
4630 | ||
4631 | static int | |
4632 | display_debug_macro (struct dwarf_section *section, | |
4633 | void *file) | |
4634 | { | |
4635 | unsigned char *start = section->start; | |
4636 | unsigned char *end = start + section->size; | |
4637 | unsigned char *curr = start; | |
4638 | unsigned char *extended_op_buf[256]; | |
4639 | unsigned int bytes_read; | |
4640 | ||
4641 | load_debug_section (str, file); | |
4642 | load_debug_section (line, file); | |
4643 | ||
4644 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4645 | ||
4646 | while (curr < end) | |
4647 | { | |
4648 | unsigned int lineno, version, flags; | |
4649 | unsigned int offset_size = 4; | |
0c588247 | 4650 | const unsigned char *string; |
4ccf1e31 JJ |
4651 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
4652 | unsigned char **extended_ops = NULL; | |
4653 | ||
0c588247 | 4654 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 4655 | if (version != 4 && version != 5) |
4ccf1e31 | 4656 | { |
7a7e1061 | 4657 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
4658 | section->name); |
4659 | return 0; | |
4660 | } | |
4661 | ||
0c588247 | 4662 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
4663 | if (flags & 1) |
4664 | offset_size = 8; | |
4665 | printf (_(" Offset: 0x%lx\n"), | |
4666 | (unsigned long) sec_offset); | |
4667 | printf (_(" Version: %d\n"), version); | |
4668 | printf (_(" Offset size: %d\n"), offset_size); | |
4669 | if (flags & 2) | |
4670 | { | |
0c588247 | 4671 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
4672 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
4673 | (unsigned long) line_offset); | |
4674 | } | |
4675 | if (flags & 4) | |
4676 | { | |
0c588247 | 4677 | unsigned int i, count, op; |
4ccf1e31 | 4678 | dwarf_vma nargs, n; |
0c588247 NC |
4679 | |
4680 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 4681 | |
4ccf1e31 JJ |
4682 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
4683 | extended_ops = extended_op_buf; | |
4684 | if (count) | |
4685 | { | |
4686 | printf (_(" Extension opcode arguments:\n")); | |
4687 | for (i = 0; i < count; i++) | |
4688 | { | |
0c588247 | 4689 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 4690 | extended_ops[op] = curr; |
f6f0e17b | 4691 | nargs = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
4692 | curr += bytes_read; |
4693 | if (nargs == 0) | |
7a7e1061 | 4694 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
4695 | else |
4696 | { | |
7a7e1061 | 4697 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
4698 | for (n = 0; n < nargs; n++) |
4699 | { | |
0c588247 NC |
4700 | unsigned int form; |
4701 | ||
4702 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
4703 | printf ("%s%s", get_FORM_name (form), |
4704 | n == nargs - 1 ? "\n" : ", "); | |
4705 | switch (form) | |
4706 | { | |
4707 | case DW_FORM_data1: | |
4708 | case DW_FORM_data2: | |
4709 | case DW_FORM_data4: | |
4710 | case DW_FORM_data8: | |
4711 | case DW_FORM_sdata: | |
4712 | case DW_FORM_udata: | |
4713 | case DW_FORM_block: | |
4714 | case DW_FORM_block1: | |
4715 | case DW_FORM_block2: | |
4716 | case DW_FORM_block4: | |
4717 | case DW_FORM_flag: | |
4718 | case DW_FORM_string: | |
4719 | case DW_FORM_strp: | |
4720 | case DW_FORM_sec_offset: | |
4721 | break; | |
4722 | default: | |
4723 | error (_("Invalid extension opcode form %s\n"), | |
4724 | get_FORM_name (form)); | |
4725 | return 0; | |
4726 | } | |
4727 | } | |
4728 | } | |
4729 | } | |
4730 | } | |
4731 | } | |
4732 | printf ("\n"); | |
4733 | ||
4734 | while (1) | |
4735 | { | |
4736 | unsigned int op; | |
4737 | ||
4738 | if (curr >= end) | |
4739 | { | |
4740 | error (_(".debug_macro section not zero terminated\n")); | |
4741 | return 0; | |
4742 | } | |
4743 | ||
0c588247 | 4744 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
4745 | if (op == 0) |
4746 | break; | |
4747 | ||
4748 | switch (op) | |
4749 | { | |
7a7e1061 | 4750 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
4751 | { |
4752 | unsigned int filenum; | |
4753 | unsigned char *file_name = NULL, *dir_name = NULL; | |
4754 | ||
f6f0e17b | 4755 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4756 | curr += bytes_read; |
f6f0e17b | 4757 | filenum = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
4758 | curr += bytes_read; |
4759 | ||
4760 | if ((flags & 2) == 0) | |
7a7e1061 | 4761 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
4762 | else |
4763 | file_name | |
4764 | = get_line_filename_and_dirname (line_offset, filenum, | |
4765 | &dir_name); | |
4766 | if (file_name == NULL) | |
7a7e1061 | 4767 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
4768 | lineno, filenum); |
4769 | else | |
7a7e1061 | 4770 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
4771 | lineno, filenum, |
4772 | dir_name != NULL ? (const char *) dir_name : "", | |
4773 | dir_name != NULL ? "/" : "", file_name); | |
4774 | } | |
4775 | break; | |
4776 | ||
7a7e1061 JK |
4777 | case DW_MACRO_end_file: |
4778 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
4779 | break; |
4780 | ||
7a7e1061 | 4781 | case DW_MACRO_define: |
f6f0e17b | 4782 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4783 | curr += bytes_read; |
0c588247 NC |
4784 | string = curr; |
4785 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 4786 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
4787 | lineno, string); |
4788 | break; | |
4789 | ||
7a7e1061 | 4790 | case DW_MACRO_undef: |
f6f0e17b | 4791 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4792 | curr += bytes_read; |
0c588247 NC |
4793 | string = curr; |
4794 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 4795 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
4796 | lineno, string); |
4797 | break; | |
4798 | ||
7a7e1061 | 4799 | case DW_MACRO_define_strp: |
f6f0e17b | 4800 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4801 | curr += bytes_read; |
0c588247 | 4802 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 4803 | string = fetch_indirect_string (offset); |
7a7e1061 | 4804 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
4805 | lineno, string); |
4806 | break; | |
4807 | ||
7a7e1061 | 4808 | case DW_MACRO_undef_strp: |
f6f0e17b | 4809 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4810 | curr += bytes_read; |
0c588247 | 4811 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 4812 | string = fetch_indirect_string (offset); |
7a7e1061 | 4813 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
4814 | lineno, string); |
4815 | break; | |
4816 | ||
7a7e1061 | 4817 | case DW_MACRO_import: |
0c588247 | 4818 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 4819 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
4820 | (unsigned long) offset); |
4821 | break; | |
4822 | ||
7a7e1061 | 4823 | case DW_MACRO_define_sup: |
f6f0e17b | 4824 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 4825 | curr += bytes_read; |
0c588247 | 4826 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 4827 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
4828 | lineno, (unsigned long) offset); |
4829 | break; | |
4830 | ||
7a7e1061 | 4831 | case DW_MACRO_undef_sup: |
f6f0e17b | 4832 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 4833 | curr += bytes_read; |
0c588247 | 4834 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 4835 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
4836 | lineno, (unsigned long) offset); |
4837 | break; | |
4838 | ||
7a7e1061 | 4839 | case DW_MACRO_import_sup: |
0c588247 | 4840 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 4841 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
4842 | (unsigned long) offset); |
4843 | break; | |
4844 | ||
4ccf1e31 JJ |
4845 | default: |
4846 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
4847 | { | |
4848 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
4849 | return 0; | |
4850 | } | |
4851 | else | |
4852 | { | |
4853 | /* Skip over unhandled opcodes. */ | |
4854 | dwarf_vma nargs, n; | |
4855 | unsigned char *desc = extended_ops[op]; | |
f6f0e17b | 4856 | nargs = read_uleb128 (desc, &bytes_read, end); |
4ccf1e31 JJ |
4857 | desc += bytes_read; |
4858 | if (nargs == 0) | |
4859 | { | |
7a7e1061 | 4860 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
4861 | break; |
4862 | } | |
7a7e1061 | 4863 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
4864 | for (n = 0; n < nargs; n++) |
4865 | { | |
0c588247 NC |
4866 | int val; |
4867 | ||
77145576 | 4868 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 4869 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 4870 | curr |
77145576 | 4871 | = read_and_display_attr_value (0, val, 0, |
f6f0e17b | 4872 | curr, end, 0, 0, offset_size, |
341f9135 | 4873 | version, NULL, 0, NULL, |
ef0b5f1c | 4874 | NULL, ' '); |
4ccf1e31 JJ |
4875 | if (n != nargs - 1) |
4876 | printf (","); | |
4877 | } | |
4878 | printf ("\n"); | |
4879 | } | |
4880 | break; | |
4881 | } | |
4882 | } | |
4883 | ||
4884 | printf ("\n"); | |
b4eb7656 | 4885 | } |
4ccf1e31 JJ |
4886 | |
4887 | return 1; | |
4888 | } | |
4889 | ||
19e6b90e L |
4890 | static int |
4891 | display_debug_abbrev (struct dwarf_section *section, | |
4892 | void *file ATTRIBUTE_UNUSED) | |
4893 | { | |
4894 | abbrev_entry *entry; | |
4895 | unsigned char *start = section->start; | |
4896 | unsigned char *end = start + section->size; | |
4897 | ||
4898 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4899 | ||
4900 | do | |
4901 | { | |
7282333f AM |
4902 | unsigned char *last; |
4903 | ||
19e6b90e L |
4904 | free_abbrevs (); |
4905 | ||
7282333f | 4906 | last = start; |
19e6b90e L |
4907 | start = process_abbrev_section (start, end); |
4908 | ||
4909 | if (first_abbrev == NULL) | |
4910 | continue; | |
4911 | ||
7282333f | 4912 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
4913 | |
4914 | for (entry = first_abbrev; entry; entry = entry->next) | |
4915 | { | |
4916 | abbrev_attr *attr; | |
4917 | ||
cc5914eb | 4918 | printf (" %ld %s [%s]\n", |
19e6b90e L |
4919 | entry->entry, |
4920 | get_TAG_name (entry->tag), | |
4921 | entry->children ? _("has children") : _("no children")); | |
4922 | ||
4923 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
4924 | { |
4925 | printf (" %-18s %s", | |
4926 | get_AT_name (attr->attribute), | |
4927 | get_FORM_name (attr->form)); | |
4928 | if (attr->form == DW_FORM_implicit_const) | |
4929 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
4930 | putchar ('\n'); | |
4931 | } | |
19e6b90e L |
4932 | } |
4933 | } | |
4934 | while (start); | |
4935 | ||
4936 | printf ("\n"); | |
4937 | ||
4938 | return 1; | |
4939 | } | |
4940 | ||
42bcef4a AB |
4941 | /* Return true when ADDR is the maximum address, when addresses are |
4942 | POINTER_SIZE bytes long. */ | |
4943 | ||
4944 | static bfd_boolean | |
4945 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
4946 | { | |
4947 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
4948 | return ((addr & mask) == mask); | |
4949 | } | |
4950 | ||
4723351a CC |
4951 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
4952 | ||
4953 | static void | |
4954 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
4955 | unsigned char **start_ptr, |
4956 | unsigned int debug_info_entry, | |
359ca075 JK |
4957 | dwarf_vma offset, |
4958 | dwarf_vma base_address, | |
b4eb7656 | 4959 | int has_frame_base) |
4723351a CC |
4960 | { |
4961 | unsigned char *start = *start_ptr; | |
4962 | unsigned char *section_end = section->start + section->size; | |
82b1b41b NC |
4963 | unsigned long cu_offset; |
4964 | unsigned int pointer_size; | |
4965 | unsigned int offset_size; | |
4966 | int dwarf_version; | |
4723351a CC |
4967 | |
4968 | dwarf_vma begin; | |
4969 | dwarf_vma end; | |
4970 | unsigned short length; | |
4971 | int need_frame_base; | |
4972 | ||
82b1b41b NC |
4973 | if (debug_info_entry >= num_debug_info_entries) |
4974 | { | |
4975 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
4976 | debug_info_entry); | |
4977 | return; | |
4978 | } | |
b4eb7656 | 4979 | |
82b1b41b NC |
4980 | cu_offset = debug_information [debug_info_entry].cu_offset; |
4981 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
4982 | offset_size = debug_information [debug_info_entry].offset_size; | |
4983 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 4984 | |
f41e4712 NC |
4985 | if (pointer_size < 2 || pointer_size > 8) |
4986 | { | |
4987 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
4988 | pointer_size, debug_info_entry); | |
4989 | return; | |
4990 | } | |
4991 | ||
4723351a CC |
4992 | while (1) |
4993 | { | |
359ca075 | 4994 | dwarf_vma off = offset + (start - *start_ptr); |
d1c4b12b | 4995 | |
4723351a | 4996 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
4997 | { |
4998 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 4999 | (unsigned long) offset); |
b4eb7656 AM |
5000 | break; |
5001 | } | |
4723351a | 5002 | |
359ca075 | 5003 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 5004 | |
0c588247 NC |
5005 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
5006 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 5007 | |
4723351a | 5008 | if (begin == 0 && end == 0) |
b4eb7656 | 5009 | { |
d1c4b12b NC |
5010 | /* PR 18374: In a object file we can have a location list that |
5011 | starts with a begin and end of 0 because there are relocations | |
5012 | that need to be applied to the addresses. Actually applying | |
5013 | the relocations now does not help as they will probably resolve | |
5014 | to 0, since the object file has not been fully linked. Real | |
5015 | end of list markers will not have any relocations against them. */ | |
5016 | if (! reloc_at (section, off) | |
5017 | && ! reloc_at (section, off + pointer_size)) | |
5018 | { | |
5019 | printf (_("<End of list>\n")); | |
5020 | break; | |
5021 | } | |
b4eb7656 | 5022 | } |
4723351a CC |
5023 | |
5024 | /* Check base address specifiers. */ | |
42bcef4a AB |
5025 | if (is_max_address (begin, pointer_size) |
5026 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
5027 | { |
5028 | base_address = end; | |
5029 | print_dwarf_vma (begin, pointer_size); | |
5030 | print_dwarf_vma (end, pointer_size); | |
5031 | printf (_("(base address)\n")); | |
5032 | continue; | |
5033 | } | |
4723351a CC |
5034 | |
5035 | if (start + 2 > section_end) | |
b4eb7656 AM |
5036 | { |
5037 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5038 | (unsigned long) offset); |
b4eb7656 AM |
5039 | break; |
5040 | } | |
4723351a | 5041 | |
0c588247 | 5042 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
5043 | |
5044 | if (start + length > section_end) | |
b4eb7656 AM |
5045 | { |
5046 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5047 | (unsigned long) offset); |
b4eb7656 AM |
5048 | break; |
5049 | } | |
4723351a CC |
5050 | |
5051 | print_dwarf_vma (begin + base_address, pointer_size); | |
5052 | print_dwarf_vma (end + base_address, pointer_size); | |
5053 | ||
5054 | putchar ('('); | |
5055 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5056 | pointer_size, |
5057 | offset_size, | |
5058 | dwarf_version, | |
5059 | length, | |
5060 | cu_offset, section); | |
4723351a CC |
5061 | putchar (')'); |
5062 | ||
5063 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5064 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
5065 | |
5066 | if (begin == end) | |
b4eb7656 | 5067 | fputs (_(" (start == end)"), stdout); |
4723351a | 5068 | else if (begin > end) |
b4eb7656 | 5069 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
5070 | |
5071 | putchar ('\n'); | |
5072 | ||
5073 | start += length; | |
5074 | } | |
5075 | ||
5076 | *start_ptr = start; | |
5077 | } | |
5078 | ||
77145576 JK |
5079 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
5080 | ||
5081 | static void | |
5082 | display_loclists_list (struct dwarf_section *section, | |
5083 | unsigned char **start_ptr, | |
5084 | unsigned int debug_info_entry, | |
5085 | dwarf_vma offset, | |
5086 | dwarf_vma base_address, | |
5087 | int has_frame_base) | |
5088 | { | |
5089 | unsigned char *start = *start_ptr; | |
5090 | unsigned char *section_end = section->start + section->size; | |
5091 | unsigned long cu_offset; | |
5092 | unsigned int pointer_size; | |
5093 | unsigned int offset_size; | |
5094 | int dwarf_version; | |
5095 | unsigned int bytes_read; | |
5096 | ||
9dfd0db9 JK |
5097 | /* Initialize it due to a false compiler warning. */ |
5098 | dwarf_vma begin = -1; | |
5099 | dwarf_vma end = -1; | |
77145576 JK |
5100 | dwarf_vma length; |
5101 | int need_frame_base; | |
5102 | ||
5103 | if (debug_info_entry >= num_debug_info_entries) | |
5104 | { | |
5105 | warn (_("No debug information available for " | |
5106 | "loclists lists of entry: %u\n"), | |
5107 | debug_info_entry); | |
5108 | return; | |
5109 | } | |
5110 | ||
5111 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5112 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5113 | offset_size = debug_information [debug_info_entry].offset_size; | |
5114 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5115 | ||
5116 | if (pointer_size < 2 || pointer_size > 8) | |
5117 | { | |
5118 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5119 | pointer_size, debug_info_entry); | |
5120 | return; | |
5121 | } | |
5122 | ||
5123 | while (1) | |
5124 | { | |
5125 | dwarf_vma off = offset + (start - *start_ptr); | |
5126 | enum dwarf_location_list_entry_type llet; | |
5127 | ||
5128 | if (start + 1 > section_end) | |
5129 | { | |
5130 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5131 | (unsigned long) offset); | |
5132 | break; | |
5133 | } | |
5134 | ||
5135 | printf (" %8.8lx ", (unsigned long) off); | |
5136 | ||
5137 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
5138 | ||
5139 | switch (llet) | |
5140 | { | |
5141 | case DW_LLE_end_of_list: | |
5142 | printf (_("<End of list>\n")); | |
5143 | break; | |
5144 | case DW_LLE_offset_pair: | |
5145 | begin = read_uleb128 (start, &bytes_read, section_end); | |
5146 | start += bytes_read; | |
5147 | end = read_uleb128 (start, &bytes_read, section_end); | |
5148 | start += bytes_read; | |
5149 | break; | |
5150 | case DW_LLE_base_address: | |
5151 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
5152 | section_end); | |
5153 | print_dwarf_vma (base_address, pointer_size); | |
5154 | printf (_("(base address)\n")); | |
5155 | break; | |
5156 | default: | |
5157 | error (_("Invalid location list entry type %d\n"), llet); | |
5158 | return; | |
5159 | } | |
5160 | if (llet == DW_LLE_end_of_list) | |
5161 | break; | |
5162 | if (llet != DW_LLE_offset_pair) | |
5163 | continue; | |
5164 | ||
5165 | if (start + 2 > section_end) | |
5166 | { | |
5167 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5168 | (unsigned long) offset); | |
5169 | break; | |
5170 | } | |
5171 | ||
5172 | length = read_uleb128 (start, &bytes_read, section_end); | |
5173 | start += bytes_read; | |
5174 | ||
5175 | print_dwarf_vma (begin + base_address, pointer_size); | |
5176 | print_dwarf_vma (end + base_address, pointer_size); | |
5177 | ||
5178 | putchar ('('); | |
5179 | need_frame_base = decode_location_expression (start, | |
5180 | pointer_size, | |
5181 | offset_size, | |
5182 | dwarf_version, | |
5183 | length, | |
5184 | cu_offset, section); | |
5185 | putchar (')'); | |
5186 | ||
5187 | if (need_frame_base && !has_frame_base) | |
5188 | printf (_(" [without DW_AT_frame_base]")); | |
5189 | ||
5190 | if (begin == end) | |
5191 | fputs (_(" (start == end)"), stdout); | |
5192 | else if (begin > end) | |
5193 | fputs (_(" (start > end)"), stdout); | |
5194 | ||
5195 | putchar ('\n'); | |
5196 | ||
5197 | start += length; | |
5198 | } | |
5199 | ||
5200 | *start_ptr = start; | |
5201 | } | |
5202 | ||
fab128ef CC |
5203 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
5204 | right-adjusted in a field of length LEN, and followed by a space. */ | |
5205 | ||
5206 | static void | |
5207 | print_addr_index (unsigned int idx, unsigned int len) | |
5208 | { | |
5209 | static char buf[15]; | |
5210 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 5211 | printf ("%*s ", len, buf); |
fab128ef CC |
5212 | } |
5213 | ||
4723351a CC |
5214 | /* Display a location list from a .dwo section. It uses address indexes rather |
5215 | than embedded addresses. This code closely follows display_loc_list, but the | |
5216 | two are sufficiently different that combining things is very ugly. */ | |
5217 | ||
5218 | static void | |
5219 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
5220 | unsigned char **start_ptr, |
5221 | unsigned int debug_info_entry, | |
359ca075 | 5222 | dwarf_vma offset, |
b4eb7656 | 5223 | int has_frame_base) |
4723351a CC |
5224 | { |
5225 | unsigned char *start = *start_ptr; | |
5226 | unsigned char *section_end = section->start + section->size; | |
82b1b41b NC |
5227 | unsigned long cu_offset; |
5228 | unsigned int pointer_size; | |
5229 | unsigned int offset_size; | |
5230 | int dwarf_version; | |
4723351a CC |
5231 | int entry_type; |
5232 | unsigned short length; | |
5233 | int need_frame_base; | |
fab128ef | 5234 | unsigned int idx; |
4723351a CC |
5235 | unsigned int bytes_read; |
5236 | ||
82b1b41b NC |
5237 | if (debug_info_entry >= num_debug_info_entries) |
5238 | { | |
5239 | warn (_("No debug information for loc lists of entry: %u\n"), | |
5240 | debug_info_entry); | |
5241 | return; | |
5242 | } | |
5243 | ||
5244 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5245 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5246 | offset_size = debug_information [debug_info_entry].offset_size; | |
5247 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5248 | ||
f41e4712 NC |
5249 | if (pointer_size < 2 || pointer_size > 8) |
5250 | { | |
5251 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5252 | pointer_size, debug_info_entry); | |
5253 | return; | |
5254 | } | |
5255 | ||
4723351a CC |
5256 | while (1) |
5257 | { | |
359ca075 | 5258 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 5259 | |
fab128ef | 5260 | if (start >= section_end) |
b4eb7656 AM |
5261 | { |
5262 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5263 | (unsigned long) offset); |
b4eb7656 AM |
5264 | break; |
5265 | } | |
4723351a | 5266 | |
0c588247 | 5267 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
4723351a | 5268 | switch (entry_type) |
b4eb7656 AM |
5269 | { |
5270 | case 0: /* A terminating entry. */ | |
5271 | *start_ptr = start; | |
5272 | printf (_("<End of list>\n")); | |
5273 | return; | |
5274 | case 1: /* A base-address entry. */ | |
5275 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5276 | start += bytes_read; | |
5277 | print_addr_index (idx, 8); | |
5278 | printf (" "); | |
5279 | printf (_("(base address selection entry)\n")); | |
5280 | continue; | |
5281 | case 2: /* A start/end entry. */ | |
5282 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5283 | start += bytes_read; | |
5284 | print_addr_index (idx, 8); | |
5285 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5286 | start += bytes_read; | |
5287 | print_addr_index (idx, 8); | |
5288 | break; | |
5289 | case 3: /* A start/length entry. */ | |
5290 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5291 | start += bytes_read; | |
5292 | print_addr_index (idx, 8); | |
5293 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
5294 | printf ("%08x ", idx); | |
5295 | break; | |
5296 | case 4: /* An offset pair entry. */ | |
5297 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
5298 | printf ("%08x ", idx); | |
5299 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
5300 | printf ("%08x ", idx); | |
5301 | break; | |
5302 | default: | |
5303 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
5304 | *start_ptr = start; | |
5305 | return; | |
5306 | } | |
4723351a CC |
5307 | |
5308 | if (start + 2 > section_end) | |
b4eb7656 AM |
5309 | { |
5310 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5311 | (unsigned long) offset); |
b4eb7656 AM |
5312 | break; |
5313 | } | |
4723351a | 5314 | |
0c588247 | 5315 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 5316 | if (start + length > section_end) |
b4eb7656 AM |
5317 | { |
5318 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5319 | (unsigned long) offset); |
b4eb7656 AM |
5320 | break; |
5321 | } | |
4723351a CC |
5322 | |
5323 | putchar ('('); | |
5324 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5325 | pointer_size, |
5326 | offset_size, | |
5327 | dwarf_version, | |
5328 | length, | |
5329 | cu_offset, section); | |
4723351a CC |
5330 | putchar (')'); |
5331 | ||
5332 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5333 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
5334 | |
5335 | putchar ('\n'); | |
5336 | ||
5337 | start += length; | |
5338 | } | |
5339 | ||
5340 | *start_ptr = start; | |
5341 | } | |
5342 | ||
51d0d03f JJ |
5343 | /* Sort array of indexes in ascending order of loc_offsets[idx]. */ |
5344 | ||
5345 | static dwarf_vma *loc_offsets; | |
5346 | ||
5347 | static int | |
5348 | loc_offsets_compar (const void *ap, const void *bp) | |
5349 | { | |
5350 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
5351 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
5352 | ||
5353 | return (a > b) - (b > a); | |
5354 | } | |
5355 | ||
19e6b90e L |
5356 | static int |
5357 | display_debug_loc (struct dwarf_section *section, void *file) | |
5358 | { | |
5359 | unsigned char *start = section->start; | |
19e6b90e L |
5360 | unsigned long bytes; |
5361 | unsigned char *section_begin = start; | |
5362 | unsigned int num_loc_list = 0; | |
5363 | unsigned long last_offset = 0; | |
5364 | unsigned int first = 0; | |
5365 | unsigned int i; | |
5366 | unsigned int j; | |
5367 | int seen_first_offset = 0; | |
51d0d03f | 5368 | int locs_sorted = 1; |
19e6b90e | 5369 | unsigned char *next; |
51d0d03f | 5370 | unsigned int *array = NULL; |
4723351a CC |
5371 | const char *suffix = strrchr (section->name, '.'); |
5372 | int is_dwo = 0; | |
77145576 JK |
5373 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
5374 | dwarf_vma expected_start = 0; | |
4723351a CC |
5375 | |
5376 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
5377 | is_dwo = 1; | |
19e6b90e L |
5378 | |
5379 | bytes = section->size; | |
19e6b90e L |
5380 | |
5381 | if (bytes == 0) | |
5382 | { | |
5383 | printf (_("\nThe %s section is empty.\n"), section->name); | |
5384 | return 0; | |
5385 | } | |
5386 | ||
77145576 JK |
5387 | if (is_loclists) |
5388 | { | |
5389 | unsigned char *hdrptr = section_begin; | |
5390 | dwarf_vma ll_length; | |
5391 | unsigned short ll_version; | |
5392 | unsigned char *end = section_begin + section->size; | |
5393 | unsigned char address_size, segment_selector_size; | |
5394 | uint32_t offset_entry_count; | |
5395 | ||
5396 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
5397 | if (ll_length == 0xffffffff) | |
5398 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
5399 | ||
5400 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
5401 | if (ll_version != 5) | |
5402 | { | |
5403 | warn (_("The %s section contains corrupt or " | |
5404 | "unsupported version number: %d.\n"), | |
5405 | section->name, ll_version); | |
5406 | return 0; | |
5407 | } | |
5408 | ||
5409 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
5410 | ||
5411 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
5412 | if (segment_selector_size != 0) | |
5413 | { | |
5414 | warn (_("The %s section contains " | |
5415 | "unsupported segment selector size: %d.\n"), | |
5416 | section->name, segment_selector_size); | |
5417 | return 0; | |
5418 | } | |
5419 | ||
5420 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
5421 | if (offset_entry_count != 0) | |
5422 | { | |
5423 | warn (_("The %s section contains " | |
5424 | "unsupported offset entry count: %d.\n"), | |
5425 | section->name, offset_entry_count); | |
5426 | return 0; | |
5427 | } | |
5428 | ||
5429 | expected_start = hdrptr - section_begin; | |
5430 | } | |
5431 | ||
1febe64d NC |
5432 | if (load_debug_info (file) == 0) |
5433 | { | |
5434 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
5435 | section->name); | |
5436 | return 0; | |
5437 | } | |
19e6b90e L |
5438 | |
5439 | /* Check the order of location list in .debug_info section. If | |
5440 | offsets of location lists are in the ascending order, we can | |
5441 | use `debug_information' directly. */ | |
5442 | for (i = 0; i < num_debug_info_entries; i++) | |
5443 | { | |
5444 | unsigned int num; | |
5445 | ||
5446 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
5447 | if (num > num_loc_list) |
5448 | num_loc_list = num; | |
19e6b90e L |
5449 | |
5450 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 5451 | if (locs_sorted && num != 0) |
19e6b90e L |
5452 | { |
5453 | if (!seen_first_offset) | |
5454 | { | |
5455 | /* This is the first location list. */ | |
5456 | last_offset = debug_information [i].loc_offsets [0]; | |
5457 | first = i; | |
5458 | seen_first_offset = 1; | |
5459 | j = 1; | |
5460 | } | |
5461 | else | |
5462 | j = 0; | |
5463 | ||
5464 | for (; j < num; j++) | |
5465 | { | |
5466 | if (last_offset > | |
5467 | debug_information [i].loc_offsets [j]) | |
5468 | { | |
51d0d03f | 5469 | locs_sorted = 0; |
19e6b90e L |
5470 | break; |
5471 | } | |
5472 | last_offset = debug_information [i].loc_offsets [j]; | |
5473 | } | |
5474 | } | |
5475 | } | |
5476 | ||
19e6b90e L |
5477 | if (!seen_first_offset) |
5478 | error (_("No location lists in .debug_info section!\n")); | |
5479 | ||
d4bfc77b | 5480 | if (debug_information [first].num_loc_offsets > 0 |
77145576 | 5481 | && debug_information [first].loc_offsets [0] != expected_start) |
47704ddf KT |
5482 | warn (_("Location lists in %s section start at 0x%s\n"), |
5483 | section->name, | |
5484 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 5485 | |
51d0d03f JJ |
5486 | if (!locs_sorted) |
5487 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
19e6b90e | 5488 | printf (_("Contents of the %s section:\n\n"), section->name); |
d1c4b12b NC |
5489 | if (reloc_at (section, 0)) |
5490 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
5491 | printf (_(" Offset Begin End Expression\n")); | |
19e6b90e L |
5492 | |
5493 | seen_first_offset = 0; | |
5494 | for (i = first; i < num_debug_info_entries; i++) | |
5495 | { | |
359ca075 JK |
5496 | dwarf_vma offset; |
5497 | dwarf_vma base_address; | |
d1c4b12b | 5498 | unsigned int k; |
19e6b90e L |
5499 | int has_frame_base; |
5500 | ||
51d0d03f JJ |
5501 | if (!locs_sorted) |
5502 | { | |
5503 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
5504 | array[k] = k; | |
5505 | loc_offsets = debug_information [i].loc_offsets; | |
5506 | qsort (array, debug_information [i].num_loc_offsets, | |
5507 | sizeof (*array), loc_offsets_compar); | |
5508 | } | |
19e6b90e | 5509 | |
51d0d03f | 5510 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 5511 | { |
51d0d03f JJ |
5512 | j = locs_sorted ? k : array[k]; |
5513 | if (k | |
5514 | && debug_information [i].loc_offsets [locs_sorted | |
5515 | ? k - 1 : array [k - 1]] | |
5516 | == debug_information [i].loc_offsets [j]) | |
5517 | continue; | |
19e6b90e | 5518 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 5519 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e L |
5520 | next = section_begin + offset; |
5521 | base_address = debug_information [i].base_address; | |
5522 | ||
5523 | if (!seen_first_offset) | |
5524 | seen_first_offset = 1; | |
5525 | else | |
5526 | { | |
5527 | if (start < next) | |
5528 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 5529 | (unsigned long) (start - section_begin), |
c8071705 | 5530 | (unsigned long) offset); |
19e6b90e L |
5531 | else if (start > next) |
5532 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 5533 | (unsigned long) (start - section_begin), |
c8071705 | 5534 | (unsigned long) offset); |
19e6b90e L |
5535 | } |
5536 | start = next; | |
5537 | ||
5538 | if (offset >= bytes) | |
5539 | { | |
5540 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 5541 | (unsigned long) offset); |
19e6b90e L |
5542 | continue; |
5543 | } | |
5544 | ||
77145576 JK |
5545 | if (!is_loclists) |
5546 | { | |
5547 | if (is_dwo) | |
5548 | display_loc_list_dwo (section, &start, i, offset, | |
5549 | has_frame_base); | |
5550 | else | |
5551 | display_loc_list (section, &start, i, offset, base_address, | |
5552 | has_frame_base); | |
5553 | } | |
b4eb7656 | 5554 | else |
77145576 JK |
5555 | { |
5556 | if (is_dwo) | |
5557 | warn (_("DWO is not yet supported.\n")); | |
5558 | else | |
5559 | display_loclists_list (section, &start, i, offset, base_address, | |
5560 | has_frame_base); | |
5561 | } | |
19e6b90e L |
5562 | } |
5563 | } | |
031cd65f | 5564 | |
4723351a | 5565 | if (start < section->start + section->size) |
031cd65f | 5566 | warn (_("There are %ld unused bytes at the end of section %s\n"), |
4723351a | 5567 | (long) (section->start + section->size - start), section->name); |
98fb390a | 5568 | putchar ('\n'); |
51d0d03f | 5569 | free (array); |
19e6b90e L |
5570 | return 1; |
5571 | } | |
5572 | ||
5573 | static int | |
5574 | display_debug_str (struct dwarf_section *section, | |
5575 | void *file ATTRIBUTE_UNUSED) | |
5576 | { | |
5577 | unsigned char *start = section->start; | |
5578 | unsigned long bytes = section->size; | |
5579 | dwarf_vma addr = section->address; | |
5580 | ||
5581 | if (bytes == 0) | |
5582 | { | |
5583 | printf (_("\nThe %s section is empty.\n"), section->name); | |
5584 | return 0; | |
5585 | } | |
5586 | ||
5587 | printf (_("Contents of the %s section:\n\n"), section->name); | |
5588 | ||
5589 | while (bytes) | |
5590 | { | |
5591 | int j; | |
5592 | int k; | |
5593 | int lbytes; | |
5594 | ||
5595 | lbytes = (bytes > 16 ? 16 : bytes); | |
5596 | ||
5597 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
5598 | ||
5599 | for (j = 0; j < 16; j++) | |
5600 | { | |
5601 | if (j < lbytes) | |
5602 | printf ("%2.2x", start[j]); | |
5603 | else | |
5604 | printf (" "); | |
5605 | ||
5606 | if ((j & 3) == 3) | |
5607 | printf (" "); | |
5608 | } | |
5609 | ||
5610 | for (j = 0; j < lbytes; j++) | |
5611 | { | |
5612 | k = start[j]; | |
5613 | if (k >= ' ' && k < 0x80) | |
5614 | printf ("%c", k); | |
5615 | else | |
5616 | printf ("."); | |
5617 | } | |
5618 | ||
5619 | putchar ('\n'); | |
5620 | ||
5621 | start += lbytes; | |
5622 | addr += lbytes; | |
5623 | bytes -= lbytes; | |
5624 | } | |
5625 | ||
5626 | putchar ('\n'); | |
5627 | ||
5628 | return 1; | |
5629 | } | |
5630 | ||
19e6b90e L |
5631 | static int |
5632 | display_debug_info (struct dwarf_section *section, void *file) | |
5633 | { | |
4723351a | 5634 | return process_debug_info (section, file, section->abbrev_sec, 0, 0); |
19e6b90e L |
5635 | } |
5636 | ||
2b6f5997 CC |
5637 | static int |
5638 | display_debug_types (struct dwarf_section *section, void *file) | |
5639 | { | |
4723351a | 5640 | return process_debug_info (section, file, section->abbrev_sec, 0, 1); |
6f875884 TG |
5641 | } |
5642 | ||
5643 | static int | |
5644 | display_trace_info (struct dwarf_section *section, void *file) | |
5645 | { | |
4723351a | 5646 | return process_debug_info (section, file, section->abbrev_sec, 0, 0); |
2b6f5997 | 5647 | } |
19e6b90e L |
5648 | |
5649 | static int | |
5650 | display_debug_aranges (struct dwarf_section *section, | |
5651 | void *file ATTRIBUTE_UNUSED) | |
5652 | { | |
5653 | unsigned char *start = section->start; | |
5654 | unsigned char *end = start + section->size; | |
5655 | ||
80c35038 | 5656 | printf (_("Contents of the %s section:\n\n"), section->name); |
19e6b90e | 5657 | |
6e3d6dc1 NC |
5658 | /* It does not matter if this load fails, |
5659 | we test for that later on. */ | |
5660 | load_debug_info (file); | |
5661 | ||
19e6b90e L |
5662 | while (start < end) |
5663 | { | |
5664 | unsigned char *hdrptr; | |
5665 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 5666 | unsigned char *addr_ranges; |
2d9472a2 NC |
5667 | dwarf_vma length; |
5668 | dwarf_vma address; | |
53b8873b | 5669 | unsigned char address_size; |
19e6b90e | 5670 | int excess; |
bf5117e3 NC |
5671 | unsigned int offset_size; |
5672 | unsigned int initial_length_size; | |
19e6b90e L |
5673 | |
5674 | hdrptr = start; | |
5675 | ||
0c588247 | 5676 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
5677 | if (arange.ar_length == 0xffffffff) |
5678 | { | |
0c588247 | 5679 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
5680 | offset_size = 8; |
5681 | initial_length_size = 12; | |
5682 | } | |
5683 | else | |
5684 | { | |
5685 | offset_size = 4; | |
5686 | initial_length_size = 4; | |
5687 | } | |
5688 | ||
0c588247 NC |
5689 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
5690 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 5691 | |
6e3d6dc1 NC |
5692 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
5693 | && num_debug_info_entries > 0 | |
5694 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
5695 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 5696 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 5697 | |
0c588247 NC |
5698 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
5699 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
5700 | |
5701 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
5702 | { | |
67f101ee NC |
5703 | /* PR 19872: A version number of 0 probably means that there is |
5704 | padding at the end of the .debug_aranges section. Gold puts | |
5705 | it there when performing an incremental link, for example. | |
5706 | So do not generate a warning in this case. */ | |
5707 | if (arange.ar_version) | |
5708 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
5709 | break; |
5710 | } | |
5711 | ||
47704ddf KT |
5712 | printf (_(" Length: %ld\n"), |
5713 | (long) arange.ar_length); | |
19e6b90e | 5714 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
5715 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
5716 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
5717 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
5718 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
5719 | ||
53b8873b NC |
5720 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
5721 | ||
f41e4712 NC |
5722 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
5723 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
5724 | { |
5725 | error (_("Invalid address size in %s section!\n"), | |
5726 | section->name); | |
5727 | break; | |
5728 | } | |
5729 | ||
53b8873b NC |
5730 | /* The DWARF spec does not require that the address size be a power |
5731 | of two, but we do. This will have to change if we ever encounter | |
5732 | an uneven architecture. */ | |
5733 | if ((address_size & (address_size - 1)) != 0) | |
5734 | { | |
5735 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
5736 | break; | |
5737 | } | |
cecf136e | 5738 | |
209c9a13 NC |
5739 | if (address_size > 4) |
5740 | printf (_("\n Address Length\n")); | |
5741 | else | |
5742 | printf (_("\n Address Length\n")); | |
19e6b90e | 5743 | |
91d6fa6a | 5744 | addr_ranges = hdrptr; |
19e6b90e | 5745 | |
53b8873b NC |
5746 | /* Must pad to an alignment boundary that is twice the address size. */ |
5747 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 5748 | if (excess) |
91d6fa6a | 5749 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 5750 | |
ffc0f143 NC |
5751 | hdrptr = start + arange.ar_length + initial_length_size; |
5752 | if (hdrptr < start || hdrptr > end) | |
5753 | { | |
5754 | error (_("Excessive header length: %lx\n"), (long) arange.ar_length); | |
5755 | break; | |
5756 | } | |
5757 | start = hdrptr; | |
1617e571 | 5758 | |
91d6fa6a | 5759 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 5760 | { |
0c588247 NC |
5761 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
5762 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 5763 | |
80c35038 | 5764 | printf (" "); |
2d9472a2 NC |
5765 | print_dwarf_vma (address, address_size); |
5766 | print_dwarf_vma (length, address_size); | |
5767 | putchar ('\n'); | |
19e6b90e | 5768 | } |
19e6b90e L |
5769 | } |
5770 | ||
5771 | printf ("\n"); | |
5772 | ||
5773 | return 1; | |
5774 | } | |
5775 | ||
4723351a CC |
5776 | /* Comparison function for qsort. */ |
5777 | static int | |
5778 | comp_addr_base (const void * v0, const void * v1) | |
5779 | { | |
5780 | debug_info * info0 = (debug_info *) v0; | |
5781 | debug_info * info1 = (debug_info *) v1; | |
5782 | return info0->addr_base - info1->addr_base; | |
5783 | } | |
5784 | ||
5785 | /* Display the debug_addr section. */ | |
5786 | static int | |
5787 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 5788 | void *file) |
4723351a CC |
5789 | { |
5790 | debug_info **debug_addr_info; | |
5791 | unsigned char *entry; | |
5792 | unsigned char *end; | |
5793 | unsigned int i; | |
5794 | unsigned int count; | |
5795 | ||
5796 | if (section->size == 0) | |
5797 | { | |
5798 | printf (_("\nThe %s section is empty.\n"), section->name); | |
5799 | return 0; | |
5800 | } | |
5801 | ||
5802 | if (load_debug_info (file) == 0) | |
5803 | { | |
5804 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
5805 | section->name); | |
5806 | return 0; | |
5807 | } | |
5808 | ||
5809 | printf (_("Contents of the %s section:\n\n"), section->name); | |
5810 | ||
1306a742 NC |
5811 | /* PR 17531: file: cf38d01b. |
5812 | We use xcalloc because a corrupt file may not have initialised all of the | |
5813 | fields in the debug_info structure, which means that the sort below might | |
5814 | try to move uninitialised data. */ | |
5815 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 5816 | sizeof (debug_info *)); |
4723351a CC |
5817 | |
5818 | count = 0; | |
5819 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 5820 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
5821 | { |
5822 | /* PR 17531: file: cf38d01b. */ | |
5823 | if (debug_information[i].addr_base >= section->size) | |
5824 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
5825 | (unsigned long) debug_information[i].addr_base, i); | |
5826 | else | |
5827 | debug_addr_info [count++] = debug_information + i; | |
5828 | } | |
4723351a CC |
5829 | |
5830 | /* Add a sentinel to make iteration convenient. */ | |
5831 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
5832 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 5833 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 5834 | |
4723351a CC |
5835 | for (i = 0; i < count; i++) |
5836 | { | |
5837 | unsigned int idx; | |
fab128ef | 5838 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
5839 | |
5840 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 5841 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 5842 | |
fab128ef | 5843 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
5844 | entry = section->start + debug_addr_info [i]->addr_base; |
5845 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
5846 | idx = 0; | |
5847 | while (entry < end) | |
b4eb7656 AM |
5848 | { |
5849 | dwarf_vma base = byte_get (entry, address_size); | |
5850 | printf (_("\t%d:\t"), idx); | |
5851 | print_dwarf_vma (base, address_size); | |
5852 | printf ("\n"); | |
5853 | entry += address_size; | |
5854 | idx++; | |
5855 | } | |
4723351a CC |
5856 | } |
5857 | printf ("\n"); | |
5858 | ||
5859 | free (debug_addr_info); | |
5860 | return 1; | |
5861 | } | |
5862 | ||
5863 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
5864 | static int | |
5865 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 5866 | void *file ATTRIBUTE_UNUSED) |
4723351a CC |
5867 | { |
5868 | if (section->size == 0) | |
5869 | { | |
5870 | printf (_("\nThe %s section is empty.\n"), section->name); | |
5871 | return 0; | |
5872 | } | |
5873 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
5874 | what the offset size is for this section. */ | |
5875 | return 1; | |
5876 | } | |
5877 | ||
01a8f077 JK |
5878 | /* Each debug_information[x].range_lists[y] gets this representation for |
5879 | sorting purposes. */ | |
5880 | ||
5881 | struct range_entry | |
467c65bc NC |
5882 | { |
5883 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 5884 | dwarf_vma ranges_offset; |
01a8f077 | 5885 | |
467c65bc NC |
5886 | /* Original debug_information to find parameters of the data. */ |
5887 | debug_info *debug_info_p; | |
5888 | }; | |
01a8f077 JK |
5889 | |
5890 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
5891 | ||
5892 | static int | |
5893 | range_entry_compar (const void *ap, const void *bp) | |
5894 | { | |
3f5e193b NC |
5895 | const struct range_entry *a_re = (const struct range_entry *) ap; |
5896 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
5897 | const dwarf_vma a = a_re->ranges_offset; |
5898 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
5899 | |
5900 | return (a > b) - (b > a); | |
5901 | } | |
5902 | ||
77145576 JK |
5903 | static void |
5904 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
5905 | unsigned int pointer_size, unsigned long offset, | |
5906 | unsigned long base_address) | |
5907 | { | |
5908 | while (start < finish) | |
5909 | { | |
5910 | dwarf_vma begin; | |
5911 | dwarf_vma end; | |
5912 | ||
5913 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
5914 | if (start >= finish) | |
5915 | break; | |
5916 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
5917 | ||
5918 | printf (" %8.8lx ", offset); | |
5919 | ||
5920 | if (begin == 0 && end == 0) | |
5921 | { | |
5922 | printf (_("<End of list>\n")); | |
5923 | break; | |
5924 | } | |
5925 | ||
5926 | /* Check base address specifiers. */ | |
5927 | if (is_max_address (begin, pointer_size) | |
5928 | && !is_max_address (end, pointer_size)) | |
5929 | { | |
5930 | base_address = end; | |
5931 | print_dwarf_vma (begin, pointer_size); | |
5932 | print_dwarf_vma (end, pointer_size); | |
5933 | printf ("(base address)\n"); | |
5934 | continue; | |
5935 | } | |
5936 | ||
5937 | print_dwarf_vma (begin + base_address, pointer_size); | |
5938 | print_dwarf_vma (end + base_address, pointer_size); | |
5939 | ||
5940 | if (begin == end) | |
5941 | fputs (_("(start == end)"), stdout); | |
5942 | else if (begin > end) | |
5943 | fputs (_("(start > end)"), stdout); | |
5944 | ||
5945 | putchar ('\n'); | |
5946 | } | |
5947 | } | |
5948 | ||
5949 | static void | |
5950 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
5951 | unsigned int pointer_size, unsigned long offset, | |
5952 | unsigned long base_address) | |
5953 | { | |
5954 | unsigned char *next = start; | |
5955 | ||
5956 | while (1) | |
5957 | { | |
5958 | unsigned long off = offset + (start - next); | |
5959 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
5960 | /* Initialize it due to a false compiler warning. */ |
5961 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
5962 | unsigned int bytes_read; |
5963 | ||
5964 | if (start + 1 > finish) | |
5965 | { | |
5966 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
5967 | offset); | |
5968 | break; | |
5969 | } | |
5970 | ||
5971 | printf (" %8.8lx ", off); | |
5972 | ||
5973 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
5974 | ||
5975 | switch (rlet) | |
5976 | { | |
5977 | case DW_RLE_end_of_list: | |
5978 | printf (_("<End of list>\n")); | |
5979 | break; | |
5980 | case DW_RLE_base_address: | |
5981 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
5982 | print_dwarf_vma (base_address, pointer_size); | |
5983 | printf (_("(base address)\n")); | |
5984 | break; | |
5985 | case DW_RLE_start_length: | |
5986 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
5987 | length = read_uleb128 (start, &bytes_read, finish); | |
5988 | start += bytes_read; | |
5989 | end = begin + length; | |
5990 | break; | |
5991 | case DW_RLE_offset_pair: | |
5992 | begin = read_uleb128 (start, &bytes_read, finish); | |
5993 | start += bytes_read; | |
5994 | end = read_uleb128 (start, &bytes_read, finish); | |
5995 | start += bytes_read; | |
5996 | break; | |
5997 | case DW_RLE_start_end: | |
5998 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
5999 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6000 | break; | |
6001 | default: | |
6002 | error (_("Invalid range list entry type %d\n"), rlet); | |
6003 | rlet = DW_RLE_end_of_list; | |
6004 | break; | |
6005 | } | |
6006 | if (rlet == DW_RLE_end_of_list) | |
6007 | break; | |
6008 | if (rlet == DW_RLE_base_address) | |
6009 | continue; | |
6010 | ||
6011 | print_dwarf_vma (begin + base_address, pointer_size); | |
6012 | print_dwarf_vma (end + base_address, pointer_size); | |
6013 | ||
6014 | if (begin == end) | |
6015 | fputs (_("(start == end)"), stdout); | |
6016 | else if (begin > end) | |
6017 | fputs (_("(start > end)"), stdout); | |
6018 | ||
6019 | putchar ('\n'); | |
6020 | } | |
6021 | } | |
6022 | ||
19e6b90e L |
6023 | static int |
6024 | display_debug_ranges (struct dwarf_section *section, | |
6025 | void *file ATTRIBUTE_UNUSED) | |
6026 | { | |
6027 | unsigned char *start = section->start; | |
a2ff7a4b | 6028 | unsigned char *last_start = start; |
f6f0e17b | 6029 | unsigned long bytes = section->size; |
19e6b90e | 6030 | unsigned char *section_begin = start; |
f6f0e17b | 6031 | unsigned char *finish = start + bytes; |
01a8f077 JK |
6032 | unsigned int num_range_list, i; |
6033 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
6034 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
6035 | /* Initialize it due to a false compiler warning. */ | |
6036 | unsigned char address_size = 0; | |
19e6b90e | 6037 | |
19e6b90e L |
6038 | if (bytes == 0) |
6039 | { | |
6040 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6041 | return 0; | |
6042 | } | |
6043 | ||
77145576 JK |
6044 | if (is_rnglists) |
6045 | { | |
6046 | dwarf_vma initial_length; | |
6047 | unsigned int initial_length_size; | |
6048 | unsigned char segment_selector_size; | |
6049 | unsigned int offset_size, offset_entry_count; | |
6050 | unsigned short version; | |
6051 | ||
6052 | /* Get and check the length of the block. */ | |
6053 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
6054 | ||
6055 | if (initial_length == 0xffffffff) | |
6056 | { | |
6057 | /* This section is 64-bit DWARF 3. */ | |
6058 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
6059 | offset_size = 8; | |
6060 | initial_length_size = 12; | |
6061 | } | |
6062 | else | |
6063 | { | |
6064 | offset_size = 4; | |
6065 | initial_length_size = 4; | |
6066 | } | |
6067 | ||
6068 | if (initial_length + initial_length_size > section->size) | |
6069 | { | |
6070 | /* If the length field has a relocation against it, then we should | |
6071 | not complain if it is inaccurate (and probably negative). | |
6072 | It is copied from .debug_line handling code. */ | |
6073 | if (reloc_at (section, (start - section->start) - offset_size)) | |
6074 | { | |
6075 | initial_length = (finish - start) - initial_length_size; | |
6076 | } | |
6077 | else | |
6078 | { | |
6079 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
6080 | (long) initial_length); | |
6081 | return 0; | |
6082 | } | |
6083 | } | |
6084 | ||
6085 | /* Get and check the version number. */ | |
6086 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
6087 | ||
6088 | if (version != 5) | |
6089 | { | |
6090 | warn (_("Only DWARF version 5 debug_rnglists info " | |
6091 | "is currently supported.\n")); | |
6092 | return 0; | |
6093 | } | |
6094 | ||
6095 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
6096 | ||
6097 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
6098 | if (segment_selector_size != 0) | |
6099 | { | |
6100 | warn (_("The %s section contains " | |
6101 | "unsupported segment selector size: %d.\n"), | |
6102 | section->name, segment_selector_size); | |
6103 | return 0; | |
6104 | } | |
6105 | ||
6106 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
6107 | if (offset_entry_count != 0) | |
6108 | { | |
6109 | warn (_("The %s section contains " | |
6110 | "unsupported offset entry count: %u.\n"), | |
6111 | section->name, offset_entry_count); | |
6112 | return 0; | |
6113 | } | |
6114 | } | |
6115 | ||
1febe64d NC |
6116 | if (load_debug_info (file) == 0) |
6117 | { | |
6118 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6119 | section->name); | |
6120 | return 0; | |
6121 | } | |
19e6b90e | 6122 | |
01a8f077 | 6123 | num_range_list = 0; |
19e6b90e | 6124 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 6125 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 6126 | |
01a8f077 | 6127 | if (num_range_list == 0) |
4723351a CC |
6128 | { |
6129 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 6130 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
6131 | printf (_("No range lists in .debug_info section.\n")); |
6132 | return 1; | |
6133 | } | |
19e6b90e | 6134 | |
3f5e193b NC |
6135 | range_entries = (struct range_entry *) |
6136 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 6137 | range_entry_fill = range_entries; |
19e6b90e | 6138 | |
01a8f077 JK |
6139 | for (i = 0; i < num_debug_info_entries; i++) |
6140 | { | |
6141 | debug_info *debug_info_p = &debug_information[i]; | |
6142 | unsigned int j; | |
6143 | ||
6144 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
6145 | { | |
6146 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
6147 | range_entry_fill->debug_info_p = debug_info_p; | |
6148 | range_entry_fill++; | |
19e6b90e L |
6149 | } |
6150 | } | |
6151 | ||
01a8f077 JK |
6152 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
6153 | range_entry_compar); | |
19e6b90e | 6154 | |
d493b283 | 6155 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 6156 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 6157 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e L |
6158 | |
6159 | printf (_("Contents of the %s section:\n\n"), section->name); | |
6160 | printf (_(" Offset Begin End\n")); | |
6161 | ||
01a8f077 | 6162 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 6163 | { |
01a8f077 JK |
6164 | struct range_entry *range_entry = &range_entries[i]; |
6165 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 6166 | unsigned int pointer_size; |
359ca075 | 6167 | dwarf_vma offset; |
01a8f077 | 6168 | unsigned char *next; |
359ca075 | 6169 | dwarf_vma base_address; |
19e6b90e | 6170 | |
77145576 | 6171 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 6172 | offset = range_entry->ranges_offset; |
01a8f077 JK |
6173 | next = section_begin + offset; |
6174 | base_address = debug_info_p->base_address; | |
cecf136e | 6175 | |
f41e4712 NC |
6176 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
6177 | if (pointer_size < 2 || pointer_size > 8) | |
6178 | { | |
6179 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 6180 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
6181 | continue; |
6182 | } | |
b4eb7656 | 6183 | |
4723351a | 6184 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 6185 | { |
01a8f077 JK |
6186 | if (start < next) |
6187 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
6188 | (unsigned long) (start - section_begin), | |
6189 | (unsigned long) (next - section_begin), section->name); | |
6190 | else if (start > next) | |
a2ff7a4b AM |
6191 | { |
6192 | if (next == last_start) | |
6193 | continue; | |
6194 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
6195 | (unsigned long) (start - section_begin), | |
6196 | (unsigned long) (next - section_begin), section->name); | |
6197 | } | |
01a8f077 JK |
6198 | } |
6199 | start = next; | |
a2ff7a4b | 6200 | last_start = next; |
19e6b90e | 6201 | |
77145576 JK |
6202 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
6203 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
6204 | } |
6205 | putchar ('\n'); | |
01a8f077 JK |
6206 | |
6207 | free (range_entries); | |
6208 | ||
19e6b90e L |
6209 | return 1; |
6210 | } | |
6211 | ||
6212 | typedef struct Frame_Chunk | |
6213 | { | |
6214 | struct Frame_Chunk *next; | |
6215 | unsigned char *chunk_start; | |
a1165289 | 6216 | unsigned int ncols; |
19e6b90e L |
6217 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
6218 | short int *col_type; | |
6219 | int *col_offset; | |
6220 | char *augmentation; | |
6221 | unsigned int code_factor; | |
6222 | int data_factor; | |
bf5117e3 NC |
6223 | dwarf_vma pc_begin; |
6224 | dwarf_vma pc_range; | |
19e6b90e | 6225 | int cfa_reg; |
c8071705 | 6226 | dwarf_vma cfa_offset; |
a1165289 | 6227 | unsigned int ra; |
19e6b90e L |
6228 | unsigned char fde_encoding; |
6229 | unsigned char cfa_exp; | |
604282a7 JJ |
6230 | unsigned char ptr_size; |
6231 | unsigned char segment_size; | |
19e6b90e L |
6232 | } |
6233 | Frame_Chunk; | |
6234 | ||
665ce1f6 L |
6235 | static const char *const *dwarf_regnames; |
6236 | static unsigned int dwarf_regnames_count; | |
6237 | ||
19e6b90e L |
6238 | /* A marker for a col_type that means this column was never referenced |
6239 | in the frame info. */ | |
6240 | #define DW_CFA_unreferenced (-1) | |
6241 | ||
a1165289 | 6242 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
6243 | -1 for invalid reg. */ |
6244 | ||
6245 | static int | |
6246 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 6247 | { |
a1165289 | 6248 | unsigned int prev = fc->ncols; |
19e6b90e | 6249 | |
665ce1f6 L |
6250 | if (reg < (unsigned int) fc->ncols) |
6251 | return 0; | |
6252 | ||
6253 | if (dwarf_regnames_count | |
6254 | && reg > dwarf_regnames_count) | |
6255 | return -1; | |
19e6b90e L |
6256 | |
6257 | fc->ncols = reg + 1; | |
a1165289 NC |
6258 | /* PR 17512: file: 10450-2643-0.004. |
6259 | If reg == -1 then this can happen... */ | |
6260 | if (fc->ncols == 0) | |
6261 | return -1; | |
6262 | ||
06614111 NC |
6263 | /* PR 17512: file: 2844a11d. */ |
6264 | if (fc->ncols > 1024) | |
6265 | { | |
6266 | error (_("Unfeasibly large register number: %u\n"), reg); | |
6267 | fc->ncols = 0; | |
6268 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
6269 | we ever encounter a valid binary that exceeds it. */ | |
6270 | return -1; | |
6271 | } | |
6272 | ||
3f5e193b | 6273 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 6274 | sizeof (short int)); |
3f5e193b | 6275 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 6276 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
6277 | if (fc->col_type == NULL || fc->col_offset == NULL) |
6278 | { | |
6279 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
6280 | fc->ncols); | |
6281 | fc->ncols = 0; | |
6282 | return -1; | |
6283 | } | |
19e6b90e L |
6284 | |
6285 | while (prev < fc->ncols) | |
6286 | { | |
6287 | fc->col_type[prev] = DW_CFA_unreferenced; | |
6288 | fc->col_offset[prev] = 0; | |
6289 | prev++; | |
6290 | } | |
665ce1f6 | 6291 | return 1; |
19e6b90e L |
6292 | } |
6293 | ||
2dc4cec1 L |
6294 | static const char *const dwarf_regnames_i386[] = |
6295 | { | |
43234a1e L |
6296 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
6297 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
6298 | "eip", "eflags", NULL, /* 8 - 10 */ | |
6299 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
6300 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
6301 | NULL, NULL, /* 19 - 20 */ | |
6302 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
6303 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
6304 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
6305 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
6306 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
6307 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
6308 | "tr", "ldtr", /* 48 - 49 */ | |
6309 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
6310 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
6311 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
6312 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
6313 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
6314 | NULL, NULL, NULL, /* 90 - 92 */ | |
6315 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
6316 | }; |
6317 | ||
3d875af5 L |
6318 | static const char *const dwarf_regnames_iamcu[] = |
6319 | { | |
6320 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
6321 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
6322 | "eip", "eflags", NULL, /* 8 - 10 */ | |
6323 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
6324 | NULL, NULL, /* 19 - 20 */ | |
6325 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
6326 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
6327 | NULL, NULL, NULL, /* 37 - 39 */ | |
6328 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
6329 | "tr", "ldtr", /* 48 - 49 */ | |
6330 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
6331 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
6332 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
6333 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
6334 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
6335 | NULL, NULL, NULL, /* 90 - 92 */ | |
6336 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
6337 | }; | |
6338 | ||
b129eb0e RH |
6339 | void |
6340 | init_dwarf_regnames_i386 (void) | |
6341 | { | |
6342 | dwarf_regnames = dwarf_regnames_i386; | |
6343 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
6344 | } | |
6345 | ||
3d875af5 L |
6346 | void |
6347 | init_dwarf_regnames_iamcu (void) | |
6348 | { | |
6349 | dwarf_regnames = dwarf_regnames_iamcu; | |
6350 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
6351 | } | |
6352 | ||
2dc4cec1 L |
6353 | static const char *const dwarf_regnames_x86_64[] = |
6354 | { | |
6355 | "rax", "rdx", "rcx", "rbx", | |
6356 | "rsi", "rdi", "rbp", "rsp", | |
6357 | "r8", "r9", "r10", "r11", | |
6358 | "r12", "r13", "r14", "r15", | |
6359 | "rip", | |
6360 | "xmm0", "xmm1", "xmm2", "xmm3", | |
6361 | "xmm4", "xmm5", "xmm6", "xmm7", | |
6362 | "xmm8", "xmm9", "xmm10", "xmm11", | |
6363 | "xmm12", "xmm13", "xmm14", "xmm15", | |
6364 | "st0", "st1", "st2", "st3", | |
6365 | "st4", "st5", "st6", "st7", | |
6366 | "mm0", "mm1", "mm2", "mm3", | |
6367 | "mm4", "mm5", "mm6", "mm7", | |
6368 | "rflags", | |
6369 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
6370 | "fs.base", "gs.base", NULL, NULL, | |
6371 | "tr", "ldtr", | |
43234a1e L |
6372 | "mxcsr", "fcw", "fsw", |
6373 | "xmm16", "xmm17", "xmm18", "xmm19", | |
6374 | "xmm20", "xmm21", "xmm22", "xmm23", | |
6375 | "xmm24", "xmm25", "xmm26", "xmm27", | |
6376 | "xmm28", "xmm29", "xmm30", "xmm31", | |
6377 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
6378 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
6379 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
6380 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
6381 | NULL, NULL, NULL, /* 115 - 117 */ | |
6382 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
6383 | }; |
6384 | ||
b129eb0e RH |
6385 | void |
6386 | init_dwarf_regnames_x86_64 (void) | |
6387 | { | |
6388 | dwarf_regnames = dwarf_regnames_x86_64; | |
6389 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
6390 | } | |
6391 | ||
4ee22035 RH |
6392 | static const char *const dwarf_regnames_aarch64[] = |
6393 | { | |
b4eb7656 AM |
6394 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
6395 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
6396 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
6397 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
6398 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
6399 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
6400 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
6401 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
b4eb7656 AM |
6402 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
6403 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
6404 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
6405 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
6406 | }; | |
6407 | ||
6408 | void | |
6409 | init_dwarf_regnames_aarch64 (void) | |
6410 | { | |
6411 | dwarf_regnames = dwarf_regnames_aarch64; | |
6412 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
6413 | } | |
6414 | ||
d6bb17b0 AA |
6415 | static const char *const dwarf_regnames_s390[] = |
6416 | { | |
6417 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
6418 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
6419 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
6420 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
6421 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
6422 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
6423 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
6424 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
6425 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
6426 | "pswm", "pswa", | |
6427 | NULL, NULL, | |
6428 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
6429 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
6430 | }; | |
6431 | ||
6432 | void | |
6433 | init_dwarf_regnames_s390 (void) | |
6434 | { | |
6435 | dwarf_regnames = dwarf_regnames_s390; | |
6436 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
6437 | } | |
6438 | ||
2dc4cec1 L |
6439 | void |
6440 | init_dwarf_regnames (unsigned int e_machine) | |
6441 | { | |
6442 | switch (e_machine) | |
6443 | { | |
6444 | case EM_386: | |
b129eb0e | 6445 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
6446 | break; |
6447 | ||
3d875af5 L |
6448 | case EM_IAMCU: |
6449 | init_dwarf_regnames_iamcu (); | |
6450 | break; | |
6451 | ||
2dc4cec1 | 6452 | case EM_X86_64: |
7f502d6c | 6453 | case EM_L1OM: |
7a9068fe | 6454 | case EM_K1OM: |
b129eb0e | 6455 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
6456 | break; |
6457 | ||
4ee22035 RH |
6458 | case EM_AARCH64: |
6459 | init_dwarf_regnames_aarch64 (); | |
6460 | break; | |
6461 | ||
d6bb17b0 AA |
6462 | case EM_S390: |
6463 | init_dwarf_regnames_s390 (); | |
6464 | break; | |
6465 | ||
2dc4cec1 L |
6466 | default: |
6467 | break; | |
6468 | } | |
6469 | } | |
6470 | ||
6471 | static const char * | |
6472 | regname (unsigned int regno, int row) | |
6473 | { | |
6474 | static char reg[64]; | |
7f2c8a1d | 6475 | |
2dc4cec1 L |
6476 | if (dwarf_regnames |
6477 | && regno < dwarf_regnames_count | |
6478 | && dwarf_regnames [regno] != NULL) | |
6479 | { | |
6480 | if (row) | |
6481 | return dwarf_regnames [regno]; | |
6482 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, | |
6483 | dwarf_regnames [regno]); | |
6484 | } | |
6485 | else | |
6486 | snprintf (reg, sizeof (reg), "r%d", regno); | |
6487 | return reg; | |
6488 | } | |
6489 | ||
19e6b90e | 6490 | static void |
a1165289 | 6491 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 6492 | { |
a1165289 | 6493 | unsigned int r; |
19e6b90e L |
6494 | char tmp[100]; |
6495 | ||
d8024a91 | 6496 | if (*max_regs != fc->ncols) |
19e6b90e L |
6497 | *max_regs = fc->ncols; |
6498 | ||
6499 | if (*need_col_headers) | |
6500 | { | |
91d6fa6a | 6501 | static const char *sloc = " LOC"; |
2dc4cec1 | 6502 | |
19e6b90e L |
6503 | *need_col_headers = 0; |
6504 | ||
91d6fa6a | 6505 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
6506 | |
6507 | for (r = 0; r < *max_regs; r++) | |
6508 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
6509 | { | |
6510 | if (r == fc->ra) | |
50751e18 | 6511 | printf ("ra "); |
19e6b90e | 6512 | else |
2dc4cec1 | 6513 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
6514 | } |
6515 | ||
6516 | printf ("\n"); | |
6517 | } | |
6518 | ||
bf5117e3 | 6519 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
6520 | if (fc->cfa_exp) |
6521 | strcpy (tmp, "exp"); | |
6522 | else | |
c8071705 | 6523 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
6524 | printf ("%-8s ", tmp); |
6525 | ||
6526 | for (r = 0; r < fc->ncols; r++) | |
6527 | { | |
6528 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
6529 | { | |
6530 | switch (fc->col_type[r]) | |
6531 | { | |
6532 | case DW_CFA_undefined: | |
6533 | strcpy (tmp, "u"); | |
6534 | break; | |
6535 | case DW_CFA_same_value: | |
6536 | strcpy (tmp, "s"); | |
6537 | break; | |
6538 | case DW_CFA_offset: | |
6539 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
6540 | break; | |
12eae2d3 JJ |
6541 | case DW_CFA_val_offset: |
6542 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
6543 | break; | |
19e6b90e | 6544 | case DW_CFA_register: |
2dc4cec1 | 6545 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
6546 | break; |
6547 | case DW_CFA_expression: | |
6548 | strcpy (tmp, "exp"); | |
6549 | break; | |
12eae2d3 JJ |
6550 | case DW_CFA_val_expression: |
6551 | strcpy (tmp, "vexp"); | |
6552 | break; | |
19e6b90e L |
6553 | default: |
6554 | strcpy (tmp, "n/a"); | |
6555 | break; | |
6556 | } | |
2dc4cec1 | 6557 | printf ("%-5s ", tmp); |
19e6b90e L |
6558 | } |
6559 | } | |
6560 | printf ("\n"); | |
6561 | } | |
6562 | ||
49727e46 | 6563 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 6564 | |
49727e46 AM |
6565 | static unsigned char * |
6566 | read_cie (unsigned char *start, unsigned char *end, | |
6567 | Frame_Chunk **p_cie, int *p_version, | |
6568 | unsigned long *p_aug_len, unsigned char **p_aug) | |
6569 | { | |
6570 | int version; | |
6571 | Frame_Chunk *fc; | |
6572 | unsigned int length_return; | |
6573 | unsigned char *augmentation_data = NULL; | |
6574 | unsigned long augmentation_data_len = 0; | |
6575 | ||
041830e0 | 6576 | * p_cie = NULL; |
f41e4712 NC |
6577 | /* PR 17512: file: 001-228113-0.004. */ |
6578 | if (start >= end) | |
6579 | return end; | |
6580 | ||
49727e46 AM |
6581 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
6582 | memset (fc, 0, sizeof (Frame_Chunk)); | |
6583 | ||
6584 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
6585 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
6586 | ||
6587 | version = *start++; | |
6588 | ||
6589 | fc->augmentation = (char *) start; | |
f41e4712 NC |
6590 | /* PR 17512: file: 001-228113-0.004. |
6591 | Skip past augmentation name, but avoid running off the end of the data. */ | |
6592 | while (start < end) | |
6593 | if (* start ++ == '\0') | |
6594 | break; | |
6595 | if (start == end) | |
6596 | { | |
6597 | warn (_("No terminator for augmentation name\n")); | |
6598 | return start; | |
6599 | } | |
49727e46 AM |
6600 | |
6601 | if (strcmp (fc->augmentation, "eh") == 0) | |
6602 | start += eh_addr_size; | |
6603 | ||
6604 | if (version >= 4) | |
6605 | { | |
6606 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
6607 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
6608 | { | |
6609 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
6610 | return end; | |
6611 | } | |
6612 | ||
49727e46 | 6613 | GET (fc->segment_size, 1); |
77ef8654 NC |
6614 | /* PR 17512: file: e99d2804. */ |
6615 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
6616 | { | |
6617 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
6618 | return end; | |
6619 | } | |
6620 | ||
49727e46 AM |
6621 | eh_addr_size = fc->ptr_size; |
6622 | } | |
6623 | else | |
6624 | { | |
6625 | fc->ptr_size = eh_addr_size; | |
6626 | fc->segment_size = 0; | |
6627 | } | |
7f2c8a1d NC |
6628 | READ_ULEB (fc->code_factor); |
6629 | READ_SLEB (fc->data_factor); | |
49727e46 AM |
6630 | if (version == 1) |
6631 | { | |
6632 | GET (fc->ra, 1); | |
6633 | } | |
6634 | else | |
6635 | { | |
7f2c8a1d | 6636 | READ_ULEB (fc->ra); |
49727e46 AM |
6637 | } |
6638 | ||
6639 | if (fc->augmentation[0] == 'z') | |
6640 | { | |
7f2c8a1d | 6641 | READ_ULEB (augmentation_data_len); |
49727e46 AM |
6642 | augmentation_data = start; |
6643 | start += augmentation_data_len; | |
a1165289 NC |
6644 | /* PR 17512: file: 11042-2589-0.004. */ |
6645 | if (start > end) | |
6646 | { | |
7f2c8a1d NC |
6647 | warn (_("Augmentation data too long: %#lx, expected at most %#lx\n"), |
6648 | augmentation_data_len, (long)((end - start) + augmentation_data_len)); | |
a1165289 NC |
6649 | return end; |
6650 | } | |
49727e46 AM |
6651 | } |
6652 | ||
6653 | if (augmentation_data_len) | |
6654 | { | |
058037d3 NC |
6655 | unsigned char *p; |
6656 | unsigned char *q; | |
6657 | unsigned char *qend; | |
b4eb7656 | 6658 | |
49727e46 AM |
6659 | p = (unsigned char *) fc->augmentation + 1; |
6660 | q = augmentation_data; | |
058037d3 NC |
6661 | qend = q + augmentation_data_len; |
6662 | ||
6663 | /* PR 17531: file: 015adfaa. */ | |
6664 | if (qend < q) | |
6665 | { | |
6666 | warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len); | |
6667 | augmentation_data_len = 0; | |
6668 | } | |
49727e46 | 6669 | |
a1165289 | 6670 | while (p < end && q < augmentation_data + augmentation_data_len) |
49727e46 AM |
6671 | { |
6672 | if (*p == 'L') | |
6673 | q++; | |
6674 | else if (*p == 'P') | |
6675 | q += 1 + size_of_encoded_value (*q); | |
6676 | else if (*p == 'R') | |
6677 | fc->fde_encoding = *q++; | |
6678 | else if (*p == 'S') | |
6679 | ; | |
6680 | else | |
6681 | break; | |
6682 | p++; | |
6683 | } | |
c361b9ac NC |
6684 | /* Note - it is OK if this loop terminates with q < qend. |
6685 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
6686 | } |
6687 | ||
6688 | *p_cie = fc; | |
6689 | if (p_version) | |
6690 | *p_version = version; | |
6691 | if (p_aug_len) | |
6692 | { | |
6693 | *p_aug_len = augmentation_data_len; | |
6694 | *p_aug = augmentation_data; | |
6695 | } | |
6696 | return start; | |
6697 | } | |
6698 | ||
19e6b90e L |
6699 | static int |
6700 | display_debug_frames (struct dwarf_section *section, | |
6701 | void *file ATTRIBUTE_UNUSED) | |
6702 | { | |
6703 | unsigned char *start = section->start; | |
6704 | unsigned char *end = start + section->size; | |
6705 | unsigned char *section_start = start; | |
49727e46 | 6706 | Frame_Chunk *chunks = 0, *forward_refs = 0; |
19e6b90e L |
6707 | Frame_Chunk *remembered_state = 0; |
6708 | Frame_Chunk *rs; | |
6709 | int is_eh = strcmp (section->name, ".eh_frame") == 0; | |
6710 | unsigned int length_return; | |
a1165289 | 6711 | unsigned int max_regs = 0; |
665ce1f6 | 6712 | const char *bad_reg = _("bad register: "); |
77ef8654 | 6713 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 6714 | |
80c35038 | 6715 | printf (_("Contents of the %s section:\n"), section->name); |
19e6b90e L |
6716 | |
6717 | while (start < end) | |
6718 | { | |
6719 | unsigned char *saved_start; | |
6720 | unsigned char *block_end; | |
bf5117e3 NC |
6721 | dwarf_vma length; |
6722 | dwarf_vma cie_id; | |
19e6b90e L |
6723 | Frame_Chunk *fc; |
6724 | Frame_Chunk *cie; | |
6725 | int need_col_headers = 1; | |
6726 | unsigned char *augmentation_data = NULL; | |
6727 | unsigned long augmentation_data_len = 0; | |
bf5117e3 NC |
6728 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
6729 | unsigned int offset_size; | |
6730 | unsigned int initial_length_size; | |
5b6312fd | 6731 | bfd_boolean all_nops; |
19e6b90e L |
6732 | |
6733 | saved_start = start; | |
19e6b90e | 6734 | |
0c588247 | 6735 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 6736 | |
19e6b90e L |
6737 | if (length == 0) |
6738 | { | |
6739 | printf ("\n%08lx ZERO terminator\n\n", | |
6740 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
6741 | /* Skip any zero terminators that directly follow. |
6742 | A corrupt section size could have loaded a whole | |
6743 | slew of zero filled memory bytes. eg | |
6744 | PR 17512: file: 070-19381-0.004. */ | |
6745 | while (start < end && * start == 0) | |
6746 | ++ start; | |
b758e50f | 6747 | continue; |
19e6b90e L |
6748 | } |
6749 | ||
6750 | if (length == 0xffffffff) | |
6751 | { | |
0c588247 | 6752 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
6753 | offset_size = 8; |
6754 | initial_length_size = 12; | |
6755 | } | |
6756 | else | |
6757 | { | |
6758 | offset_size = 4; | |
6759 | initial_length_size = 4; | |
6760 | } | |
6761 | ||
6762 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 6763 | if (block_end > end || block_end < start) |
53b8873b | 6764 | { |
bf5117e3 NC |
6765 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
6766 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
6767 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
6768 | block_end = end; |
6769 | } | |
0c588247 NC |
6770 | |
6771 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 6772 | |
846a11e4 NC |
6773 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
6774 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
6775 | { |
6776 | int version; | |
a1165289 | 6777 | unsigned int mreg; |
19e6b90e | 6778 | |
49727e46 AM |
6779 | start = read_cie (start, end, &cie, &version, |
6780 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
6781 | /* PR 17512: file: 027-135133-0.005. */ |
6782 | if (cie == NULL) | |
6783 | break; | |
a1165289 | 6784 | |
49727e46 | 6785 | fc = cie; |
19e6b90e L |
6786 | fc->next = chunks; |
6787 | chunks = fc; | |
6788 | fc->chunk_start = saved_start; | |
a1165289 | 6789 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
6790 | if (mreg < fc->ra) |
6791 | mreg = fc->ra; | |
06614111 NC |
6792 | if (frame_need_space (fc, mreg) < 0) |
6793 | break; | |
49727e46 AM |
6794 | if (fc->fde_encoding) |
6795 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 6796 | |
bf5117e3 NC |
6797 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
6798 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 6799 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 6800 | |
19e6b90e | 6801 | if (do_debug_frames_interp) |
bf5117e3 NC |
6802 | { |
6803 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
6804 | fc->code_factor, fc->data_factor, fc->ra); | |
6805 | } | |
19e6b90e L |
6806 | else |
6807 | { | |
bf5117e3 | 6808 | printf ("CIE\n"); |
19e6b90e L |
6809 | printf (" Version: %d\n", version); |
6810 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
6811 | if (version >= 4) |
6812 | { | |
6813 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
6814 | printf (" Segment Size: %u\n", fc->segment_size); | |
6815 | } | |
19e6b90e L |
6816 | printf (" Code alignment factor: %u\n", fc->code_factor); |
6817 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
6818 | printf (" Return address column: %d\n", fc->ra); | |
6819 | ||
6820 | if (augmentation_data_len) | |
6821 | { | |
6822 | unsigned long i; | |
a1165289 | 6823 | |
19e6b90e L |
6824 | printf (" Augmentation data: "); |
6825 | for (i = 0; i < augmentation_data_len; ++i) | |
a1165289 NC |
6826 | /* FIXME: If do_wide is FALSE, then we should |
6827 | add carriage returns at 80 columns... */ | |
19e6b90e L |
6828 | printf (" %02x", augmentation_data[i]); |
6829 | putchar ('\n'); | |
6830 | } | |
6831 | putchar ('\n'); | |
6832 | } | |
19e6b90e L |
6833 | } |
6834 | else | |
6835 | { | |
6836 | unsigned char *look_for; | |
6837 | static Frame_Chunk fde_fc; | |
604282a7 | 6838 | unsigned long segment_selector; |
19e6b90e | 6839 | |
49727e46 AM |
6840 | if (is_eh) |
6841 | { | |
6842 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
6843 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
6844 | } | |
6845 | else | |
6846 | look_for = section_start + cie_id; | |
19e6b90e | 6847 | |
49727e46 AM |
6848 | if (look_for <= saved_start) |
6849 | { | |
6850 | for (cie = chunks; cie ; cie = cie->next) | |
6851 | if (cie->chunk_start == look_for) | |
6852 | break; | |
6853 | } | |
6854 | else | |
6855 | { | |
6856 | for (cie = forward_refs; cie ; cie = cie->next) | |
6857 | if (cie->chunk_start == look_for) | |
6858 | break; | |
6859 | if (!cie) | |
6860 | { | |
6861 | unsigned int off_size; | |
6862 | unsigned char *cie_scan; | |
19e6b90e | 6863 | |
49727e46 AM |
6864 | cie_scan = look_for; |
6865 | off_size = 4; | |
6866 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
6867 | if (length == 0xffffffff) | |
6868 | { | |
6869 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
6870 | off_size = 8; | |
6871 | } | |
6872 | if (length != 0) | |
6873 | { | |
6874 | dwarf_vma c_id; | |
6875 | ||
6876 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
6877 | if (is_eh | |
6878 | ? c_id == 0 | |
6879 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
6880 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
6881 | { | |
6882 | int version; | |
a1165289 | 6883 | unsigned int mreg; |
49727e46 AM |
6884 | |
6885 | read_cie (cie_scan, end, &cie, &version, | |
6886 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
6887 | /* PR 17512: file: 3450-2098-0.004. */ |
6888 | if (cie == NULL) | |
6889 | { | |
6890 | warn (_("Failed to read CIE information\n")); | |
6891 | break; | |
6892 | } | |
49727e46 AM |
6893 | cie->next = forward_refs; |
6894 | forward_refs = cie; | |
6895 | cie->chunk_start = look_for; | |
a1165289 | 6896 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
6897 | if (mreg < cie->ra) |
6898 | mreg = cie->ra; | |
06614111 NC |
6899 | if (frame_need_space (cie, mreg) < 0) |
6900 | { | |
6901 | warn (_("Invalid max register\n")); | |
6902 | break; | |
6903 | } | |
49727e46 AM |
6904 | if (cie->fde_encoding) |
6905 | encoded_ptr_size | |
6906 | = size_of_encoded_value (cie->fde_encoding); | |
6907 | } | |
6908 | } | |
6909 | } | |
6910 | } | |
6911 | ||
6912 | fc = &fde_fc; | |
6913 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
6914 | |
6915 | if (!cie) | |
6916 | { | |
bf5117e3 NC |
6917 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
6918 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
6919 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 6920 | fc->ncols = 0; |
3f5e193b NC |
6921 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
6922 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
6923 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
6924 | { | |
6925 | warn (_("Invalid max register\n")); | |
6926 | break; | |
6927 | } | |
19e6b90e L |
6928 | cie = fc; |
6929 | fc->augmentation = ""; | |
6930 | fc->fde_encoding = 0; | |
604282a7 JJ |
6931 | fc->ptr_size = eh_addr_size; |
6932 | fc->segment_size = 0; | |
19e6b90e L |
6933 | } |
6934 | else | |
6935 | { | |
6936 | fc->ncols = cie->ncols; | |
3f5e193b NC |
6937 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
6938 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
6939 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
6940 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
6941 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
6942 | fc->ptr_size = cie->ptr_size; |
6943 | eh_addr_size = cie->ptr_size; | |
6944 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
6945 | fc->code_factor = cie->code_factor; |
6946 | fc->data_factor = cie->data_factor; | |
6947 | fc->cfa_reg = cie->cfa_reg; | |
6948 | fc->cfa_offset = cie->cfa_offset; | |
6949 | fc->ra = cie->ra; | |
06614111 NC |
6950 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
6951 | { | |
6952 | warn (_("Invalid max register\n")); | |
6953 | break; | |
6954 | } | |
19e6b90e L |
6955 | fc->fde_encoding = cie->fde_encoding; |
6956 | } | |
6957 | ||
6958 | if (fc->fde_encoding) | |
6959 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
6960 | ||
604282a7 JJ |
6961 | segment_selector = 0; |
6962 | if (fc->segment_size) | |
c8071705 NC |
6963 | { |
6964 | if (fc->segment_size > sizeof (segment_selector)) | |
6965 | { | |
6966 | /* PR 17512: file: 9e196b3e. */ | |
6967 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
6968 | fc->segment_size = 4; | |
6969 | } | |
6970 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
6971 | } | |
041830e0 NC |
6972 | |
6973 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 6974 | |
0c588247 NC |
6975 | /* FIXME: It appears that sometimes the final pc_range value is |
6976 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
6977 | run of the "objcopy on compressed debug sections" test for an | |
6978 | example of this. */ | |
6979 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 6980 | |
19e6b90e L |
6981 | if (cie->augmentation[0] == 'z') |
6982 | { | |
7f2c8a1d | 6983 | READ_ULEB (augmentation_data_len); |
19e6b90e L |
6984 | augmentation_data = start; |
6985 | start += augmentation_data_len; | |
0a9d414a | 6986 | /* PR 17512: file: 722-8446-0.004. */ |
53774b7e | 6987 | if (start >= end || ((signed long) augmentation_data_len) < 0) |
0a9d414a NC |
6988 | { |
6989 | warn (_("Corrupt augmentation data length: %lx\n"), | |
6990 | augmentation_data_len); | |
6991 | start = end; | |
6992 | augmentation_data = NULL; | |
6993 | augmentation_data_len = 0; | |
6994 | } | |
19e6b90e L |
6995 | } |
6996 | ||
bf5117e3 NC |
6997 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
6998 | (unsigned long)(saved_start - section_start), | |
6999 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 7000 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 7001 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 7002 | |
604282a7 JJ |
7003 | if (fc->segment_size) |
7004 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
7005 | |
7006 | printf ("%s..%s\n", | |
7007 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
7008 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
7009 | ||
19e6b90e L |
7010 | if (! do_debug_frames_interp && augmentation_data_len) |
7011 | { | |
7012 | unsigned long i; | |
7013 | ||
7014 | printf (" Augmentation data: "); | |
7015 | for (i = 0; i < augmentation_data_len; ++i) | |
7016 | printf (" %02x", augmentation_data[i]); | |
7017 | putchar ('\n'); | |
7018 | putchar ('\n'); | |
7019 | } | |
7020 | } | |
7021 | ||
7022 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
7023 | we're about to interpret instructions for the chunk. */ | |
7024 | /* ??? At present we need to do this always, since this sizes the | |
7025 | fc->col_type and fc->col_offset arrays, which we write into always. | |
7026 | We should probably split the interpreted and non-interpreted bits | |
7027 | into two different routines, since there's so much that doesn't | |
7028 | really overlap between them. */ | |
7029 | if (1 || do_debug_frames_interp) | |
7030 | { | |
7031 | /* Start by making a pass over the chunk, allocating storage | |
7032 | and taking note of what registers are used. */ | |
7033 | unsigned char *tmp = start; | |
7034 | ||
7035 | while (start < block_end) | |
7036 | { | |
041830e0 NC |
7037 | unsigned int reg, op, opa; |
7038 | unsigned long temp; | |
5929c344 | 7039 | unsigned char * new_start; |
19e6b90e L |
7040 | |
7041 | op = *start++; | |
7042 | opa = op & 0x3f; | |
7043 | if (op & 0xc0) | |
7044 | op &= 0xc0; | |
7045 | ||
7046 | /* Warning: if you add any more cases to this switch, be | |
7047 | sure to add them to the corresponding switch below. */ | |
7048 | switch (op) | |
7049 | { | |
7050 | case DW_CFA_advance_loc: | |
7051 | break; | |
7052 | case DW_CFA_offset: | |
7f2c8a1d | 7053 | SKIP_ULEB (); |
665ce1f6 L |
7054 | if (frame_need_space (fc, opa) >= 0) |
7055 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
7056 | break; |
7057 | case DW_CFA_restore: | |
665ce1f6 L |
7058 | if (frame_need_space (fc, opa) >= 0) |
7059 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
7060 | break; |
7061 | case DW_CFA_set_loc: | |
7062 | start += encoded_ptr_size; | |
7063 | break; | |
7064 | case DW_CFA_advance_loc1: | |
7065 | start += 1; | |
7066 | break; | |
7067 | case DW_CFA_advance_loc2: | |
7068 | start += 2; | |
7069 | break; | |
7070 | case DW_CFA_advance_loc4: | |
7071 | start += 4; | |
7072 | break; | |
7073 | case DW_CFA_offset_extended: | |
12eae2d3 | 7074 | case DW_CFA_val_offset: |
7f2c8a1d NC |
7075 | READ_ULEB (reg); |
7076 | SKIP_ULEB (); | |
665ce1f6 L |
7077 | if (frame_need_space (fc, reg) >= 0) |
7078 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7079 | break; |
7080 | case DW_CFA_restore_extended: | |
7f2c8a1d | 7081 | READ_ULEB (reg); |
665ce1f6 L |
7082 | if (frame_need_space (fc, reg) >= 0) |
7083 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7084 | break; |
7085 | case DW_CFA_undefined: | |
7f2c8a1d | 7086 | READ_ULEB (reg); |
665ce1f6 L |
7087 | if (frame_need_space (fc, reg) >= 0) |
7088 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7089 | break; |
7090 | case DW_CFA_same_value: | |
7f2c8a1d | 7091 | READ_ULEB (reg); |
665ce1f6 L |
7092 | if (frame_need_space (fc, reg) >= 0) |
7093 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7094 | break; |
7095 | case DW_CFA_register: | |
7f2c8a1d NC |
7096 | READ_ULEB (reg); |
7097 | SKIP_ULEB (); | |
665ce1f6 L |
7098 | if (frame_need_space (fc, reg) >= 0) |
7099 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7100 | break; |
7101 | case DW_CFA_def_cfa: | |
7f2c8a1d NC |
7102 | SKIP_ULEB (); |
7103 | SKIP_ULEB (); | |
19e6b90e L |
7104 | break; |
7105 | case DW_CFA_def_cfa_register: | |
7f2c8a1d | 7106 | SKIP_ULEB (); |
19e6b90e L |
7107 | break; |
7108 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 7109 | SKIP_ULEB (); |
19e6b90e L |
7110 | break; |
7111 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 7112 | READ_ULEB (temp); |
5929c344 NC |
7113 | new_start = start + temp; |
7114 | if (new_start < start) | |
041830e0 NC |
7115 | { |
7116 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
7117 | start = block_end; | |
7118 | } | |
7119 | else | |
5929c344 | 7120 | start = new_start; |
19e6b90e L |
7121 | break; |
7122 | case DW_CFA_expression: | |
12eae2d3 | 7123 | case DW_CFA_val_expression: |
7f2c8a1d NC |
7124 | READ_ULEB (reg); |
7125 | READ_ULEB (temp); | |
5929c344 NC |
7126 | new_start = start + temp; |
7127 | if (new_start < start) | |
041830e0 | 7128 | { |
b4eb7656 | 7129 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
7130 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
7131 | start = block_end; | |
7132 | } | |
7133 | else | |
5929c344 | 7134 | start = new_start; |
665ce1f6 L |
7135 | if (frame_need_space (fc, reg) >= 0) |
7136 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7137 | break; |
7138 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 7139 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
7140 | READ_ULEB (reg); |
7141 | SKIP_SLEB (); | |
665ce1f6 L |
7142 | if (frame_need_space (fc, reg) >= 0) |
7143 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7144 | break; |
7145 | case DW_CFA_def_cfa_sf: | |
7f2c8a1d NC |
7146 | SKIP_ULEB (); |
7147 | SKIP_SLEB (); | |
19e6b90e L |
7148 | break; |
7149 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 7150 | SKIP_SLEB (); |
19e6b90e L |
7151 | break; |
7152 | case DW_CFA_MIPS_advance_loc8: | |
7153 | start += 8; | |
7154 | break; | |
7155 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 7156 | SKIP_ULEB (); |
19e6b90e L |
7157 | break; |
7158 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
7159 | READ_ULEB (reg); |
7160 | SKIP_ULEB (); | |
665ce1f6 L |
7161 | if (frame_need_space (fc, reg) >= 0) |
7162 | fc->col_type[reg] = DW_CFA_undefined; | |
7163 | break; | |
19e6b90e L |
7164 | default: |
7165 | break; | |
7166 | } | |
7167 | } | |
7168 | start = tmp; | |
7169 | } | |
7170 | ||
5b6312fd NC |
7171 | all_nops = TRUE; |
7172 | ||
19e6b90e L |
7173 | /* Now we know what registers are used, make a second pass over |
7174 | the chunk, this time actually printing out the info. */ | |
7175 | ||
7176 | while (start < block_end) | |
7177 | { | |
362beea4 | 7178 | unsigned char * tmp; |
19e6b90e | 7179 | unsigned op, opa; |
7f2c8a1d NC |
7180 | unsigned long ul, roffs; |
7181 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
7182 | are various functions, notably frame_space_needed() that assume that | |
7183 | reg is an unsigned int. */ | |
7184 | unsigned int reg; | |
7185 | dwarf_signed_vma l; | |
bf5117e3 | 7186 | dwarf_vma ofs; |
19e6b90e | 7187 | dwarf_vma vma; |
665ce1f6 | 7188 | const char *reg_prefix = ""; |
19e6b90e L |
7189 | |
7190 | op = *start++; | |
7191 | opa = op & 0x3f; | |
7192 | if (op & 0xc0) | |
7193 | op &= 0xc0; | |
7194 | ||
5b6312fd NC |
7195 | /* Make a note if something other than DW_CFA_nop happens. */ |
7196 | if (op != DW_CFA_nop) | |
7197 | all_nops = FALSE; | |
7198 | ||
19e6b90e L |
7199 | /* Warning: if you add any more cases to this switch, be |
7200 | sure to add them to the corresponding switch above. */ | |
7201 | switch (op) | |
7202 | { | |
7203 | case DW_CFA_advance_loc: | |
7204 | if (do_debug_frames_interp) | |
7205 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7206 | else | |
bf5117e3 | 7207 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 7208 | opa * fc->code_factor, |
b4eb7656 | 7209 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
7210 | fc->pc_begin + opa * fc->code_factor, |
7211 | fc->ptr_size)); | |
19e6b90e L |
7212 | fc->pc_begin += opa * fc->code_factor; |
7213 | break; | |
7214 | ||
7215 | case DW_CFA_offset: | |
7f2c8a1d | 7216 | READ_ULEB (roffs); |
665ce1f6 L |
7217 | if (opa >= (unsigned int) fc->ncols) |
7218 | reg_prefix = bad_reg; | |
7219 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7220 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
7221 | reg_prefix, regname (opa, 0), | |
7222 | roffs * fc->data_factor); | |
7223 | if (*reg_prefix == '\0') | |
7224 | { | |
7225 | fc->col_type[opa] = DW_CFA_offset; | |
7226 | fc->col_offset[opa] = roffs * fc->data_factor; | |
7227 | } | |
19e6b90e L |
7228 | break; |
7229 | ||
7230 | case DW_CFA_restore: | |
50751e18 | 7231 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
7232 | reg_prefix = bad_reg; |
7233 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7234 | printf (" DW_CFA_restore: %s%s\n", | |
7235 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
7236 | if (*reg_prefix != '\0') |
7237 | break; | |
7238 | ||
7239 | if (opa >= (unsigned int) cie->ncols | |
7240 | || (do_debug_frames_interp | |
7241 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
7242 | { | |
7243 | fc->col_type[opa] = DW_CFA_undefined; | |
7244 | fc->col_offset[opa] = 0; | |
7245 | } | |
7246 | else | |
665ce1f6 L |
7247 | { |
7248 | fc->col_type[opa] = cie->col_type[opa]; | |
7249 | fc->col_offset[opa] = cie->col_offset[opa]; | |
7250 | } | |
19e6b90e L |
7251 | break; |
7252 | ||
7253 | case DW_CFA_set_loc: | |
6937bb54 | 7254 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
7255 | if (do_debug_frames_interp) |
7256 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7257 | else | |
bf5117e3 NC |
7258 | printf (" DW_CFA_set_loc: %s\n", |
7259 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
7260 | fc->pc_begin = vma; |
7261 | break; | |
7262 | ||
7263 | case DW_CFA_advance_loc1: | |
0c588247 | 7264 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
7265 | if (do_debug_frames_interp) |
7266 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7267 | else | |
bf5117e3 NC |
7268 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
7269 | (unsigned long) (ofs * fc->code_factor), | |
7270 | dwarf_vmatoa_1 (NULL, | |
7271 | fc->pc_begin + ofs * fc->code_factor, | |
7272 | fc->ptr_size)); | |
19e6b90e L |
7273 | fc->pc_begin += ofs * fc->code_factor; |
7274 | break; | |
7275 | ||
7276 | case DW_CFA_advance_loc2: | |
6937bb54 | 7277 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
7278 | if (do_debug_frames_interp) |
7279 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7280 | else | |
bf5117e3 NC |
7281 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
7282 | (unsigned long) (ofs * fc->code_factor), | |
7283 | dwarf_vmatoa_1 (NULL, | |
7284 | fc->pc_begin + ofs * fc->code_factor, | |
7285 | fc->ptr_size)); | |
19e6b90e L |
7286 | fc->pc_begin += ofs * fc->code_factor; |
7287 | break; | |
7288 | ||
7289 | case DW_CFA_advance_loc4: | |
6937bb54 | 7290 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
7291 | if (do_debug_frames_interp) |
7292 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7293 | else | |
bf5117e3 NC |
7294 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
7295 | (unsigned long) (ofs * fc->code_factor), | |
7296 | dwarf_vmatoa_1 (NULL, | |
7297 | fc->pc_begin + ofs * fc->code_factor, | |
7298 | fc->ptr_size)); | |
19e6b90e L |
7299 | fc->pc_begin += ofs * fc->code_factor; |
7300 | break; | |
7301 | ||
7302 | case DW_CFA_offset_extended: | |
7f2c8a1d NC |
7303 | READ_ULEB (reg); |
7304 | READ_ULEB (roffs); | |
665ce1f6 L |
7305 | if (reg >= (unsigned int) fc->ncols) |
7306 | reg_prefix = bad_reg; | |
7307 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7308 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
7309 | reg_prefix, regname (reg, 0), | |
7310 | roffs * fc->data_factor); | |
7311 | if (*reg_prefix == '\0') | |
7312 | { | |
7313 | fc->col_type[reg] = DW_CFA_offset; | |
7314 | fc->col_offset[reg] = roffs * fc->data_factor; | |
7315 | } | |
19e6b90e L |
7316 | break; |
7317 | ||
12eae2d3 | 7318 | case DW_CFA_val_offset: |
7f2c8a1d NC |
7319 | READ_ULEB (reg); |
7320 | READ_ULEB (roffs); | |
665ce1f6 L |
7321 | if (reg >= (unsigned int) fc->ncols) |
7322 | reg_prefix = bad_reg; | |
7323 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 7324 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
7325 | reg_prefix, regname (reg, 0), |
7326 | roffs * fc->data_factor); | |
7327 | if (*reg_prefix == '\0') | |
7328 | { | |
7329 | fc->col_type[reg] = DW_CFA_val_offset; | |
7330 | fc->col_offset[reg] = roffs * fc->data_factor; | |
7331 | } | |
12eae2d3 JJ |
7332 | break; |
7333 | ||
19e6b90e | 7334 | case DW_CFA_restore_extended: |
7f2c8a1d | 7335 | READ_ULEB (reg); |
50751e18 | 7336 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
7337 | reg_prefix = bad_reg; |
7338 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7339 | printf (" DW_CFA_restore_extended: %s%s\n", | |
7340 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
7341 | if (*reg_prefix != '\0') |
7342 | break; | |
7343 | ||
7344 | if (reg >= (unsigned int) cie->ncols) | |
7345 | { | |
7346 | fc->col_type[reg] = DW_CFA_undefined; | |
7347 | fc->col_offset[reg] = 0; | |
7348 | } | |
7349 | else | |
665ce1f6 L |
7350 | { |
7351 | fc->col_type[reg] = cie->col_type[reg]; | |
7352 | fc->col_offset[reg] = cie->col_offset[reg]; | |
7353 | } | |
19e6b90e L |
7354 | break; |
7355 | ||
7356 | case DW_CFA_undefined: | |
7f2c8a1d | 7357 | READ_ULEB (reg); |
665ce1f6 L |
7358 | if (reg >= (unsigned int) fc->ncols) |
7359 | reg_prefix = bad_reg; | |
7360 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7361 | printf (" DW_CFA_undefined: %s%s\n", | |
7362 | reg_prefix, regname (reg, 0)); | |
7363 | if (*reg_prefix == '\0') | |
7364 | { | |
7365 | fc->col_type[reg] = DW_CFA_undefined; | |
7366 | fc->col_offset[reg] = 0; | |
7367 | } | |
19e6b90e L |
7368 | break; |
7369 | ||
7370 | case DW_CFA_same_value: | |
7f2c8a1d | 7371 | READ_ULEB (reg); |
665ce1f6 L |
7372 | if (reg >= (unsigned int) fc->ncols) |
7373 | reg_prefix = bad_reg; | |
7374 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7375 | printf (" DW_CFA_same_value: %s%s\n", | |
7376 | reg_prefix, regname (reg, 0)); | |
7377 | if (*reg_prefix == '\0') | |
7378 | { | |
7379 | fc->col_type[reg] = DW_CFA_same_value; | |
7380 | fc->col_offset[reg] = 0; | |
7381 | } | |
19e6b90e L |
7382 | break; |
7383 | ||
7384 | case DW_CFA_register: | |
7f2c8a1d NC |
7385 | READ_ULEB (reg); |
7386 | READ_ULEB (roffs); | |
665ce1f6 L |
7387 | if (reg >= (unsigned int) fc->ncols) |
7388 | reg_prefix = bad_reg; | |
7389 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 7390 | { |
665ce1f6 L |
7391 | printf (" DW_CFA_register: %s%s in ", |
7392 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
7393 | puts (regname (roffs, 0)); |
7394 | } | |
665ce1f6 L |
7395 | if (*reg_prefix == '\0') |
7396 | { | |
7397 | fc->col_type[reg] = DW_CFA_register; | |
7398 | fc->col_offset[reg] = roffs; | |
7399 | } | |
19e6b90e L |
7400 | break; |
7401 | ||
7402 | case DW_CFA_remember_state: | |
7403 | if (! do_debug_frames_interp) | |
7404 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 7405 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 7406 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
7407 | rs->cfa_reg = fc->cfa_reg; |
7408 | rs->ra = fc->ra; | |
7409 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 7410 | rs->ncols = fc->ncols; |
3f5e193b | 7411 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 7412 | sizeof (* rs->col_type)); |
d71ad7fc RC |
7413 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
7414 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
7415 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
7416 | rs->next = remembered_state; |
7417 | remembered_state = rs; | |
7418 | break; | |
7419 | ||
7420 | case DW_CFA_restore_state: | |
7421 | if (! do_debug_frames_interp) | |
7422 | printf (" DW_CFA_restore_state\n"); | |
7423 | rs = remembered_state; | |
7424 | if (rs) | |
7425 | { | |
7426 | remembered_state = rs->next; | |
d71ad7fc RC |
7427 | fc->cfa_offset = rs->cfa_offset; |
7428 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
7429 | fc->ra = rs->ra; |
7430 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
7431 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
7432 | { | |
1306a742 | 7433 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
7434 | fc->ncols = 0; |
7435 | break; | |
7436 | } | |
d71ad7fc | 7437 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 7438 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 7439 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
7440 | free (rs->col_type); |
7441 | free (rs->col_offset); | |
7442 | free (rs); | |
7443 | } | |
7444 | else if (do_debug_frames_interp) | |
7445 | printf ("Mismatched DW_CFA_restore_state\n"); | |
7446 | break; | |
7447 | ||
7448 | case DW_CFA_def_cfa: | |
7f2c8a1d NC |
7449 | READ_SLEB (fc->cfa_reg); |
7450 | READ_ULEB (fc->cfa_offset); | |
19e6b90e L |
7451 | fc->cfa_exp = 0; |
7452 | if (! do_debug_frames_interp) | |
2dc4cec1 | 7453 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 7454 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
7455 | break; |
7456 | ||
7457 | case DW_CFA_def_cfa_register: | |
7f2c8a1d | 7458 | READ_SLEB (fc->cfa_reg); |
19e6b90e L |
7459 | fc->cfa_exp = 0; |
7460 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
7461 | printf (" DW_CFA_def_cfa_register: %s\n", |
7462 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
7463 | break; |
7464 | ||
7465 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 7466 | READ_ULEB (fc->cfa_offset); |
19e6b90e | 7467 | if (! do_debug_frames_interp) |
c8071705 | 7468 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
7469 | break; |
7470 | ||
7471 | case DW_CFA_nop: | |
7472 | if (! do_debug_frames_interp) | |
7473 | printf (" DW_CFA_nop\n"); | |
7474 | break; | |
7475 | ||
7476 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 7477 | READ_ULEB (ul); |
7460c0ab | 7478 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 7479 | { |
a1165289 | 7480 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
7481 | break; |
7482 | } | |
19e6b90e L |
7483 | if (! do_debug_frames_interp) |
7484 | { | |
7485 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
7486 | decode_location_expression (start, eh_addr_size, 0, -1, |
7487 | ul, 0, section); | |
19e6b90e L |
7488 | printf (")\n"); |
7489 | } | |
7490 | fc->cfa_exp = 1; | |
7491 | start += ul; | |
7492 | break; | |
7493 | ||
7494 | case DW_CFA_expression: | |
7f2c8a1d NC |
7495 | READ_ULEB (reg); |
7496 | READ_ULEB (ul); | |
665ce1f6 L |
7497 | if (reg >= (unsigned int) fc->ncols) |
7498 | reg_prefix = bad_reg; | |
6937bb54 | 7499 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 7500 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
7501 | tmp = start + ul; |
7502 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 7503 | { |
a1165289 | 7504 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
7505 | break; |
7506 | } | |
665ce1f6 | 7507 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 7508 | { |
665ce1f6 L |
7509 | printf (" DW_CFA_expression: %s%s (", |
7510 | reg_prefix, regname (reg, 0)); | |
b7807392 | 7511 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 7512 | ul, 0, section); |
19e6b90e L |
7513 | printf (")\n"); |
7514 | } | |
665ce1f6 L |
7515 | if (*reg_prefix == '\0') |
7516 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 7517 | start = tmp; |
19e6b90e L |
7518 | break; |
7519 | ||
12eae2d3 | 7520 | case DW_CFA_val_expression: |
7f2c8a1d NC |
7521 | READ_ULEB (reg); |
7522 | READ_ULEB (ul); | |
665ce1f6 L |
7523 | if (reg >= (unsigned int) fc->ncols) |
7524 | reg_prefix = bad_reg; | |
362beea4 NC |
7525 | tmp = start + ul; |
7526 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 7527 | { |
a1165289 | 7528 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
7529 | break; |
7530 | } | |
665ce1f6 | 7531 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 7532 | { |
665ce1f6 L |
7533 | printf (" DW_CFA_val_expression: %s%s (", |
7534 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
7535 | decode_location_expression (start, eh_addr_size, 0, -1, |
7536 | ul, 0, section); | |
12eae2d3 JJ |
7537 | printf (")\n"); |
7538 | } | |
665ce1f6 L |
7539 | if (*reg_prefix == '\0') |
7540 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 7541 | start = tmp; |
12eae2d3 JJ |
7542 | break; |
7543 | ||
19e6b90e | 7544 | case DW_CFA_offset_extended_sf: |
7f2c8a1d NC |
7545 | READ_ULEB (reg); |
7546 | READ_SLEB (l); | |
665ce1f6 L |
7547 | if (frame_need_space (fc, reg) < 0) |
7548 | reg_prefix = bad_reg; | |
7549 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7550 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
7551 | reg_prefix, regname (reg, 0), | |
c8071705 | 7552 | (long)(l * fc->data_factor)); |
665ce1f6 L |
7553 | if (*reg_prefix == '\0') |
7554 | { | |
7555 | fc->col_type[reg] = DW_CFA_offset; | |
7556 | fc->col_offset[reg] = l * fc->data_factor; | |
7557 | } | |
19e6b90e L |
7558 | break; |
7559 | ||
12eae2d3 | 7560 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
7561 | READ_ULEB (reg); |
7562 | READ_SLEB (l); | |
665ce1f6 L |
7563 | if (frame_need_space (fc, reg) < 0) |
7564 | reg_prefix = bad_reg; | |
7565 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 7566 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 7567 | reg_prefix, regname (reg, 0), |
c8071705 | 7568 | (long)(l * fc->data_factor)); |
665ce1f6 L |
7569 | if (*reg_prefix == '\0') |
7570 | { | |
7571 | fc->col_type[reg] = DW_CFA_val_offset; | |
7572 | fc->col_offset[reg] = l * fc->data_factor; | |
7573 | } | |
12eae2d3 JJ |
7574 | break; |
7575 | ||
19e6b90e | 7576 | case DW_CFA_def_cfa_sf: |
7f2c8a1d NC |
7577 | READ_SLEB (fc->cfa_reg); |
7578 | READ_ULEB (fc->cfa_offset); | |
19e6b90e L |
7579 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
7580 | fc->cfa_exp = 0; | |
7581 | if (! do_debug_frames_interp) | |
2dc4cec1 | 7582 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 7583 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
7584 | break; |
7585 | ||
7586 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 7587 | READ_ULEB (fc->cfa_offset); |
c8071705 | 7588 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 7589 | if (! do_debug_frames_interp) |
c8071705 | 7590 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
7591 | break; |
7592 | ||
7593 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 7594 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
7595 | if (do_debug_frames_interp) |
7596 | frame_display_row (fc, &need_col_headers, &max_regs); | |
7597 | else | |
bf5117e3 NC |
7598 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
7599 | (unsigned long) (ofs * fc->code_factor), | |
7600 | dwarf_vmatoa_1 (NULL, | |
7601 | fc->pc_begin + ofs * fc->code_factor, | |
7602 | fc->ptr_size)); | |
19e6b90e L |
7603 | fc->pc_begin += ofs * fc->code_factor; |
7604 | break; | |
7605 | ||
7606 | case DW_CFA_GNU_window_save: | |
7607 | if (! do_debug_frames_interp) | |
7608 | printf (" DW_CFA_GNU_window_save\n"); | |
7609 | break; | |
7610 | ||
7611 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 7612 | READ_ULEB (ul); |
19e6b90e L |
7613 | if (! do_debug_frames_interp) |
7614 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
7615 | break; | |
7616 | ||
7617 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
7618 | READ_ULEB (reg); |
7619 | READ_SLEB (l); | |
7620 | l = - l; | |
665ce1f6 L |
7621 | if (frame_need_space (fc, reg) < 0) |
7622 | reg_prefix = bad_reg; | |
7623 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
7624 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
7625 | reg_prefix, regname (reg, 0), | |
c8071705 | 7626 | (long)(l * fc->data_factor)); |
665ce1f6 L |
7627 | if (*reg_prefix == '\0') |
7628 | { | |
7629 | fc->col_type[reg] = DW_CFA_offset; | |
7630 | fc->col_offset[reg] = l * fc->data_factor; | |
7631 | } | |
19e6b90e L |
7632 | break; |
7633 | ||
7634 | default: | |
53b8873b NC |
7635 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
7636 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
7637 | else | |
f41e4712 | 7638 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
7639 | start = block_end; |
7640 | } | |
7641 | } | |
7642 | ||
5b6312fd NC |
7643 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
7644 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
7645 | frame_display_row (fc, &need_col_headers, &max_regs); |
7646 | ||
7647 | start = block_end; | |
604282a7 | 7648 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
7649 | } |
7650 | ||
7651 | printf ("\n"); | |
7652 | ||
7653 | return 1; | |
7654 | } | |
7655 | ||
7656 | #undef GET | |
19e6b90e | 7657 | |
61364358 JK |
7658 | static int |
7659 | display_debug_names (struct dwarf_section *section, void *file) | |
7660 | { | |
7661 | unsigned char *hdrptr = section->start; | |
7662 | dwarf_vma unit_length; | |
7663 | unsigned char *unit_start; | |
7664 | const unsigned char *const section_end = section->start + section->size; | |
7665 | unsigned char *unit_end; | |
7666 | ||
7667 | printf (_("Contents of the %s section:\n"), section->name); | |
7668 | ||
7669 | load_debug_section (str, file); | |
7670 | ||
7671 | for (; hdrptr < section_end; hdrptr = unit_end) | |
7672 | { | |
7673 | unsigned int offset_size; | |
7674 | uint16_t dwarf_version, padding; | |
7675 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
7676 | uint32_t bucket_count, name_count, abbrev_table_size; | |
7677 | uint32_t augmentation_string_size; | |
7678 | unsigned int i; | |
7679 | ||
7680 | unit_start = hdrptr; | |
7681 | ||
7682 | /* Get and check the length of the block. */ | |
7683 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
7684 | ||
7685 | if (unit_length == 0xffffffff) | |
7686 | { | |
7687 | /* This section is 64-bit DWARF. */ | |
7688 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
7689 | offset_size = 8; | |
7690 | } | |
7691 | else | |
7692 | offset_size = 4; | |
7693 | unit_end = hdrptr + unit_length; | |
7694 | ||
7695 | if ((hdrptr - section->start) + unit_length > section->size) | |
7696 | { | |
7697 | warn (_("The length field (0x%lx) for unit 0x%lx in the debug_names " | |
7698 | "header is wrong - the section is too small\n"), | |
7699 | (long) unit_length, (long) (unit_start - section->start)); | |
7700 | return 0; | |
7701 | } | |
7702 | ||
7703 | /* Get and check the version number. */ | |
7704 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
7705 | printf (_("Version %ld\n"), (long) dwarf_version); | |
7706 | ||
7707 | /* Prior versions did not exist, and future versions may not be | |
7708 | backwards compatible. */ | |
7709 | if (dwarf_version != 5) | |
7710 | { | |
7711 | warn (_("Only DWARF version 5 .debug_names " | |
7712 | "is currently supported.\n")); | |
7713 | return 0; | |
7714 | } | |
7715 | ||
7716 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
7717 | if (padding != 0) | |
7718 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
7719 | padding); | |
7720 | ||
7721 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
7722 | if (comp_unit_count == 0) | |
7723 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
7724 | ||
7725 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
7726 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
7727 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
7728 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
7729 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
7730 | ||
7731 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
7732 | if (augmentation_string_size % 4 != 0) | |
7733 | { | |
7734 | warn (_("Augmentation string length %u must be rounded up " | |
7735 | "to a multiple of 4 in .debug_names.\n"), | |
7736 | augmentation_string_size); | |
7737 | augmentation_string_size += (-augmentation_string_size) & 3; | |
7738 | } | |
7739 | printf (_("Augmentation string:")); | |
7740 | for (i = 0; i < augmentation_string_size; i++) | |
7741 | { | |
7742 | unsigned char uc; | |
7743 | ||
7744 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
7745 | printf (" %02x", uc); | |
7746 | } | |
7747 | putchar ('\n'); | |
7748 | putchar ('\n'); | |
7749 | ||
7750 | printf (_("CU table:\n")); | |
7751 | for (i = 0; i < comp_unit_count; i++) | |
7752 | { | |
7753 | uint64_t cu_offset; | |
7754 | ||
7755 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
7756 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
7757 | } | |
7758 | putchar ('\n'); | |
7759 | ||
7760 | printf (_("TU table:\n")); | |
7761 | for (i = 0; i < local_type_unit_count; i++) | |
7762 | { | |
7763 | uint64_t tu_offset; | |
7764 | ||
7765 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
7766 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
7767 | } | |
7768 | putchar ('\n'); | |
7769 | ||
7770 | printf (_("Foreign TU table:\n")); | |
7771 | for (i = 0; i < foreign_type_unit_count; i++) | |
7772 | { | |
7773 | uint64_t signature; | |
7774 | ||
7775 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
7776 | printf (_("[%3u] "), i); | |
7777 | print_dwarf_vma (signature, 8); | |
7778 | putchar ('\n'); | |
7779 | } | |
7780 | putchar ('\n'); | |
7781 | ||
7782 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
7783 | hdrptr += bucket_count * sizeof (uint32_t); | |
7784 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
7785 | hdrptr += name_count * sizeof (uint32_t); | |
7786 | unsigned char *const name_table_string_offsets = hdrptr; | |
7787 | hdrptr += name_count * offset_size; | |
7788 | unsigned char *const name_table_entry_offsets = hdrptr; | |
7789 | hdrptr += name_count * offset_size; | |
7790 | unsigned char *const abbrev_table = hdrptr; | |
7791 | hdrptr += abbrev_table_size; | |
7792 | const unsigned char *const abbrev_table_end = hdrptr; | |
7793 | unsigned char *const entry_pool = hdrptr; | |
7794 | if (hdrptr > unit_end) | |
7795 | { | |
7796 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
7797 | "for unit 0x%lx in the debug_names\n"), | |
7798 | (long) (hdrptr - section->start), | |
7799 | (long) (unit_end - section->start), | |
7800 | (long) (unit_start - section->start)); | |
7801 | return 0; | |
7802 | } | |
7803 | ||
7804 | size_t buckets_filled = 0; | |
7805 | size_t bucketi; | |
7806 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
7807 | { | |
7808 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
7809 | ||
7810 | if (bucket != 0) | |
7811 | ++buckets_filled; | |
7812 | } | |
7813 | printf (_("Used %zu of %lu buckets.\n"), buckets_filled, | |
7814 | (unsigned long) bucket_count); | |
7815 | ||
7816 | uint32_t hash_prev; | |
7817 | size_t hash_clash_count = 0; | |
7818 | size_t longest_clash = 0; | |
7819 | size_t this_length = 0; | |
7820 | size_t hashi; | |
7821 | for (hashi = 0; hashi < name_count; hashi++) | |
7822 | { | |
7823 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
7824 | ||
7825 | if (hashi > 0) | |
7826 | { | |
7827 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
7828 | { | |
7829 | ++hash_clash_count; | |
7830 | ++this_length; | |
7831 | longest_clash = MAX (longest_clash, this_length); | |
7832 | } | |
7833 | else | |
7834 | this_length = 0; | |
7835 | } | |
7836 | hash_prev = hash_this; | |
7837 | } | |
7838 | printf (_("Out of %lu items there are %zu bucket clashes" | |
7839 | " (longest of %zu entries).\n"), | |
7840 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
7841 | assert (name_count == buckets_filled + hash_clash_count); | |
7842 | ||
7843 | struct abbrev_lookup_entry | |
7844 | { | |
7845 | dwarf_vma abbrev_tag; | |
7846 | unsigned char *abbrev_lookup_ptr; | |
7847 | }; | |
7848 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
7849 | size_t abbrev_lookup_used = 0; | |
7850 | size_t abbrev_lookup_allocated = 0; | |
7851 | ||
7852 | unsigned char *abbrevptr = abbrev_table; | |
7853 | for (;;) | |
7854 | { | |
7855 | unsigned int bytes_read; | |
7856 | const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read, | |
7857 | abbrev_table_end); | |
7858 | abbrevptr += bytes_read; | |
7859 | if (abbrev_tag == 0) | |
7860 | break; | |
7861 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
7862 | { | |
7863 | abbrev_lookup_allocated = MAX (0x100, | |
7864 | abbrev_lookup_allocated * 2); | |
7865 | abbrev_lookup = xrealloc (abbrev_lookup, | |
7866 | (abbrev_lookup_allocated | |
7867 | * sizeof (*abbrev_lookup))); | |
7868 | } | |
7869 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
7870 | struct abbrev_lookup_entry *entry; | |
7871 | for (entry = abbrev_lookup; | |
7872 | entry < abbrev_lookup + abbrev_lookup_used; | |
7873 | entry++) | |
7874 | if (entry->abbrev_tag == abbrev_tag) | |
7875 | { | |
7876 | warn (_("Duplicate abbreviation tag %lu " | |
7877 | "in unit 0x%lx in the debug_names\n"), | |
7878 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
7879 | break; | |
7880 | } | |
7881 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
7882 | entry->abbrev_tag = abbrev_tag; | |
7883 | entry->abbrev_lookup_ptr = abbrevptr; | |
7884 | ||
7885 | /* Skip DWARF tag. */ | |
7886 | read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end); | |
7887 | abbrevptr += bytes_read; | |
7888 | for (;;) | |
7889 | { | |
7890 | const dwarf_vma index = read_uleb128 (abbrevptr, &bytes_read, | |
7891 | abbrev_table_end); | |
7892 | abbrevptr += bytes_read; | |
7893 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
7894 | abbrev_table_end); | |
7895 | abbrevptr += bytes_read; | |
7896 | if (index == 0 && form == 0) | |
7897 | break; | |
7898 | } | |
7899 | } | |
7900 | ||
7901 | printf (_("\nSymbol table:\n")); | |
7902 | uint32_t namei; | |
7903 | for (namei = 0; namei < name_count; ++namei) | |
7904 | { | |
7905 | uint64_t string_offset, entry_offset; | |
7906 | ||
7907 | SAFE_BYTE_GET (string_offset, | |
7908 | name_table_string_offsets + namei * offset_size, | |
7909 | offset_size, unit_end); | |
7910 | SAFE_BYTE_GET (entry_offset, | |
7911 | name_table_entry_offsets + namei * offset_size, | |
7912 | offset_size, unit_end); | |
7913 | ||
7914 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
7915 | fetch_indirect_string (string_offset)); | |
7916 | ||
7917 | unsigned char *entryptr = entry_pool + entry_offset; | |
7918 | ||
7919 | // We need to scan first whether there is a single or multiple | |
7920 | // entries. TAGNO is -2 for the first entry, it is -1 for the | |
7921 | // initial tag read of the second entry, then it becomes 0 for the | |
7922 | // first entry for real printing etc. | |
7923 | int tagno = -2; | |
7924 | /* Initialize it due to a false compiler warning. */ | |
7925 | dwarf_vma second_abbrev_tag = -1; | |
7926 | for (;;) | |
7927 | { | |
7928 | unsigned int bytes_read; | |
7929 | const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read, | |
7930 | unit_end); | |
7931 | entryptr += bytes_read; | |
7932 | if (tagno == -1) | |
7933 | { | |
7934 | second_abbrev_tag = abbrev_tag; | |
7935 | tagno = 0; | |
7936 | entryptr = entry_pool + entry_offset; | |
7937 | continue; | |
7938 | } | |
7939 | if (abbrev_tag == 0) | |
7940 | break; | |
7941 | if (tagno >= 0) | |
7942 | printf ("%s<%lu>", | |
7943 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
7944 | (unsigned long) abbrev_tag); | |
7945 | ||
7946 | const struct abbrev_lookup_entry *entry; | |
7947 | for (entry = abbrev_lookup; | |
7948 | entry < abbrev_lookup + abbrev_lookup_used; | |
7949 | entry++) | |
7950 | if (entry->abbrev_tag == abbrev_tag) | |
7951 | break; | |
7952 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
7953 | { | |
7954 | warn (_("Undefined abbreviation tag %lu " | |
7955 | "in unit 0x%lx in the debug_names\n"), | |
7956 | (long) abbrev_tag, | |
7957 | (long) (unit_start - section->start)); | |
7958 | break; | |
7959 | } | |
7960 | abbrevptr = entry->abbrev_lookup_ptr; | |
7961 | const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read, | |
7962 | abbrev_table_end); | |
7963 | abbrevptr += bytes_read; | |
7964 | if (tagno >= 0) | |
7965 | printf (" %s", get_TAG_name (dwarf_tag)); | |
7966 | for (;;) | |
7967 | { | |
7968 | const dwarf_vma index = read_uleb128 (abbrevptr, &bytes_read, | |
7969 | abbrev_table_end); | |
7970 | abbrevptr += bytes_read; | |
7971 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
7972 | abbrev_table_end); | |
7973 | abbrevptr += bytes_read; | |
7974 | if (index == 0 && form == 0) | |
7975 | break; | |
7976 | ||
7977 | if (tagno >= 0) | |
7978 | printf (" %s", get_IDX_name (index)); | |
7979 | entryptr = read_and_display_attr_value (0, form, 0, entryptr, | |
7980 | unit_end, 0, 0, | |
7981 | offset_size, | |
7982 | dwarf_version, NULL, | |
7983 | (tagno < 0), NULL, | |
7984 | NULL, '='); | |
7985 | } | |
7986 | ++tagno; | |
7987 | } | |
7988 | if (tagno <= 0) | |
7989 | printf (_(" <no entries>")); | |
7990 | putchar ('\n'); | |
7991 | } | |
7992 | ||
7993 | free (abbrev_lookup); | |
7994 | } | |
7995 | ||
7996 | return 1; | |
7997 | } | |
7998 | ||
5bbdf3d5 DE |
7999 | static int |
8000 | display_gdb_index (struct dwarf_section *section, | |
8001 | void *file ATTRIBUTE_UNUSED) | |
8002 | { | |
8003 | unsigned char *start = section->start; | |
8004 | uint32_t version; | |
8005 | uint32_t cu_list_offset, tu_list_offset; | |
8006 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
8007 | unsigned int cu_list_elements, tu_list_elements; | |
8008 | unsigned int address_table_size, symbol_table_slots; | |
8009 | unsigned char *cu_list, *tu_list; | |
8010 | unsigned char *address_table, *symbol_table, *constant_pool; | |
8011 | unsigned int i; | |
8012 | ||
8013 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
8014 | ||
8015 | printf (_("Contents of the %s section:\n"), section->name); | |
8016 | ||
8017 | if (section->size < 6 * sizeof (uint32_t)) | |
8018 | { | |
8019 | warn (_("Truncated header in the %s section.\n"), section->name); | |
8020 | return 0; | |
8021 | } | |
8022 | ||
8023 | version = byte_get_little_endian (start, 4); | |
da88a764 | 8024 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
8025 | |
8026 | /* Prior versions are obsolete, and future versions may not be | |
8027 | backwards compatible. */ | |
aa170720 | 8028 | if (version < 3 || version > 8) |
5bbdf3d5 | 8029 | { |
da88a764 | 8030 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
8031 | return 0; |
8032 | } | |
8d6eee87 TT |
8033 | if (version < 4) |
8034 | warn (_("The address table data in version 3 may be wrong.\n")); | |
8035 | if (version < 5) | |
8036 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
8037 | if (version < 6) | |
8038 | warn (_("Version 5 does not include inlined functions.\n")); | |
8039 | if (version < 7) | |
8040 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
8041 | /* Version 7 indices generated by Gold have bad type unit references, |
8042 | PR binutils/15021. But we don't know if the index was generated by | |
8043 | Gold or not, so to avoid worrying users with gdb-generated indices | |
8044 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
8045 | |
8046 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
8047 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
8048 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
8049 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
8050 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
8051 | ||
8052 | if (cu_list_offset > section->size | |
8053 | || tu_list_offset > section->size | |
8054 | || address_table_offset > section->size | |
8055 | || symbol_table_offset > section->size | |
8056 | || constant_pool_offset > section->size) | |
8057 | { | |
8058 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
8059 | return 0; | |
8060 | } | |
8061 | ||
53774b7e NC |
8062 | /* PR 17531: file: 418d0a8a. */ |
8063 | if (tu_list_offset < cu_list_offset) | |
8064 | { | |
8065 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
8066 | tu_list_offset, cu_list_offset); | |
8067 | return 0; | |
8068 | } | |
8069 | ||
5bbdf3d5 | 8070 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
8071 | |
8072 | if (address_table_offset < tu_list_offset) | |
8073 | { | |
8074 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
8075 | address_table_offset, tu_list_offset); | |
8076 | return 0; | |
8077 | } | |
8078 | ||
5bbdf3d5 | 8079 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
8080 | |
8081 | /* PR 17531: file: 18a47d3d. */ | |
8082 | if (symbol_table_offset < address_table_offset) | |
8083 | { | |
acff9664 | 8084 | warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"), |
53774b7e NC |
8085 | symbol_table_offset, address_table_offset); |
8086 | return 0; | |
8087 | } | |
8088 | ||
5bbdf3d5 | 8089 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
8090 | |
8091 | if (constant_pool_offset < symbol_table_offset) | |
8092 | { | |
8093 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
8094 | constant_pool_offset, symbol_table_offset); | |
8095 | return 0; | |
8096 | } | |
8097 | ||
5bbdf3d5 DE |
8098 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
8099 | ||
8100 | cu_list = start + cu_list_offset; | |
8101 | tu_list = start + tu_list_offset; | |
8102 | address_table = start + address_table_offset; | |
8103 | symbol_table = start + symbol_table_offset; | |
8104 | constant_pool = start + constant_pool_offset; | |
8105 | ||
28d909e5 | 8106 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 8107 | { |
1306a742 | 8108 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
8109 | return 0; |
8110 | } | |
b4eb7656 | 8111 | |
5bbdf3d5 DE |
8112 | printf (_("\nCU table:\n")); |
8113 | for (i = 0; i < cu_list_elements; i += 2) | |
8114 | { | |
8115 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
8116 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
8117 | ||
8118 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
8119 | (unsigned long) cu_offset, | |
8120 | (unsigned long) (cu_offset + cu_length - 1)); | |
8121 | } | |
8122 | ||
8123 | printf (_("\nTU table:\n")); | |
8124 | for (i = 0; i < tu_list_elements; i += 3) | |
8125 | { | |
8126 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
8127 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
8128 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
8129 | ||
8130 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
8131 | (unsigned long) tu_offset, | |
8132 | (unsigned long) type_offset); | |
8133 | print_dwarf_vma (signature, 8); | |
8134 | printf ("\n"); | |
8135 | } | |
8136 | ||
8137 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
8138 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
8139 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
8140 | { |
8141 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
8142 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
8143 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
8144 | ||
8145 | print_dwarf_vma (low, 8); | |
8146 | print_dwarf_vma (high, 8); | |
da88a764 | 8147 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
8148 | } |
8149 | ||
8150 | printf (_("\nSymbol table:\n")); | |
8151 | for (i = 0; i < symbol_table_slots; ++i) | |
8152 | { | |
8153 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
8154 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
8155 | uint32_t num_cus, cu; | |
8156 | ||
8157 | if (name_offset != 0 | |
8158 | || cu_vector_offset != 0) | |
8159 | { | |
8160 | unsigned int j; | |
362beea4 | 8161 | unsigned char * adr; |
5bbdf3d5 | 8162 | |
362beea4 | 8163 | adr = constant_pool + name_offset; |
53774b7e | 8164 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 8165 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
8166 | { |
8167 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
8168 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
8169 | name_offset, i); | |
8170 | } | |
8171 | else | |
acff9664 NC |
8172 | printf ("[%3u] %.*s:", i, |
8173 | (int) (section->size - (constant_pool_offset + name_offset)), | |
8174 | constant_pool + name_offset); | |
53774b7e | 8175 | |
362beea4 NC |
8176 | adr = constant_pool + cu_vector_offset; |
8177 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
8178 | { |
8179 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
8180 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
8181 | cu_vector_offset, i); | |
8182 | continue; | |
8183 | } | |
57028622 | 8184 | |
362beea4 | 8185 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 8186 | |
362beea4 | 8187 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 8188 | if (num_cus * 4 < num_cus |
362beea4 NC |
8189 | || adr >= section->start + section->size |
8190 | || adr < constant_pool) | |
53774b7e NC |
8191 | { |
8192 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 8193 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
8194 | num_cus, i); |
8195 | continue; | |
8196 | } | |
8197 | ||
8d6eee87 TT |
8198 | if (num_cus > 1) |
8199 | printf ("\n"); | |
f3853b34 | 8200 | |
5bbdf3d5 DE |
8201 | for (j = 0; j < num_cus; ++j) |
8202 | { | |
7c1cef97 | 8203 | int is_static; |
8d6eee87 TT |
8204 | gdb_index_symbol_kind kind; |
8205 | ||
5bbdf3d5 | 8206 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 8207 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
8208 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
8209 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 8210 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 8211 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
8212 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
8213 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 8214 | else |
8d6eee87 TT |
8215 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
8216 | ||
459d52c8 DE |
8217 | printf (" [%s, %s]", |
8218 | is_static ? _("static") : _("global"), | |
8219 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
8220 | if (num_cus > 1) |
8221 | printf ("\n"); | |
5bbdf3d5 | 8222 | } |
8d6eee87 TT |
8223 | if (num_cus <= 1) |
8224 | printf ("\n"); | |
5bbdf3d5 DE |
8225 | } |
8226 | } | |
8227 | ||
8228 | return 1; | |
8229 | } | |
8230 | ||
657d0d47 CC |
8231 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
8232 | ||
8233 | static void | |
8234 | prealloc_cu_tu_list (unsigned int nshndx) | |
8235 | { | |
8236 | if (shndx_pool == NULL) | |
8237 | { | |
8238 | shndx_pool_size = nshndx; | |
8239 | shndx_pool_used = 0; | |
8240 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
8241 | sizeof (unsigned int)); | |
8242 | } | |
8243 | else | |
8244 | { | |
8245 | shndx_pool_size = shndx_pool_used + nshndx; | |
8246 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
8247 | sizeof (unsigned int)); | |
8248 | } | |
8249 | } | |
8250 | ||
8251 | static void | |
8252 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
8253 | { | |
8254 | if (shndx_pool_used >= shndx_pool_size) | |
8255 | { | |
8256 | error (_("Internal error: out of space in the shndx pool.\n")); | |
8257 | return; | |
8258 | } | |
8259 | shndx_pool [shndx_pool_used++] = shndx; | |
8260 | } | |
8261 | ||
8262 | static void | |
8263 | end_cu_tu_entry (void) | |
8264 | { | |
8265 | if (shndx_pool_used >= shndx_pool_size) | |
8266 | { | |
8267 | error (_("Internal error: out of space in the shndx pool.\n")); | |
8268 | return; | |
8269 | } | |
8270 | shndx_pool [shndx_pool_used++] = 0; | |
8271 | } | |
8272 | ||
341f9135 CC |
8273 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
8274 | ||
8275 | static const char * | |
8276 | get_DW_SECT_short_name (unsigned int dw_sect) | |
8277 | { | |
8278 | static char buf[16]; | |
8279 | ||
8280 | switch (dw_sect) | |
8281 | { | |
8282 | case DW_SECT_INFO: | |
8283 | return "info"; | |
8284 | case DW_SECT_TYPES: | |
8285 | return "types"; | |
8286 | case DW_SECT_ABBREV: | |
8287 | return "abbrev"; | |
8288 | case DW_SECT_LINE: | |
8289 | return "line"; | |
8290 | case DW_SECT_LOC: | |
8291 | return "loc"; | |
8292 | case DW_SECT_STR_OFFSETS: | |
8293 | return "str_off"; | |
8294 | case DW_SECT_MACINFO: | |
8295 | return "macinfo"; | |
8296 | case DW_SECT_MACRO: | |
8297 | return "macro"; | |
8298 | default: | |
b4eb7656 | 8299 | break; |
341f9135 CC |
8300 | } |
8301 | ||
8302 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
8303 | return buf; | |
8304 | } | |
8305 | ||
8306 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
8307 | These sections are extensions for Fission. | |
8308 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
8309 | |
8310 | static int | |
8311 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
8312 | { | |
8313 | unsigned char *phdr = section->start; | |
8314 | unsigned char *limit = phdr + section->size; | |
8315 | unsigned char *phash; | |
8316 | unsigned char *pindex; | |
8317 | unsigned char *ppool; | |
8318 | unsigned int version; | |
341f9135 | 8319 | unsigned int ncols = 0; |
657d0d47 CC |
8320 | unsigned int nused; |
8321 | unsigned int nslots; | |
8322 | unsigned int i; | |
341f9135 CC |
8323 | unsigned int j; |
8324 | dwarf_vma signature_high; | |
8325 | dwarf_vma signature_low; | |
8326 | char buf[64]; | |
657d0d47 | 8327 | |
6937bb54 NC |
8328 | /* PR 17512: file: 002-168123-0.004. */ |
8329 | if (phdr == NULL) | |
8330 | { | |
8331 | warn (_("Section %s is empty\n"), section->name); | |
8332 | return 0; | |
8333 | } | |
8334 | /* PR 17512: file: 002-376-0.004. */ | |
8335 | if (section->size < 24) | |
8336 | { | |
72c61a0d | 8337 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
8338 | section->name); |
8339 | return 0; | |
8340 | } | |
8341 | ||
8342 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 8343 | if (version >= 2) |
6937bb54 NC |
8344 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
8345 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
8346 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
8347 | ||
657d0d47 CC |
8348 | phash = phdr + 16; |
8349 | pindex = phash + nslots * 8; | |
8350 | ppool = pindex + nslots * 4; | |
8351 | ||
57028622 | 8352 | /* PR 17531: file: 45d69832. */ |
03a91817 | 8353 | if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0)) |
57028622 NC |
8354 | { |
8355 | warn (_("Section %s is too small for %d slots\n"), | |
8356 | section->name, nslots); | |
8357 | return 0; | |
8358 | } | |
8359 | ||
657d0d47 CC |
8360 | if (do_display) |
8361 | { | |
8362 | printf (_("Contents of the %s section:\n\n"), section->name); | |
8363 | printf (_(" Version: %d\n"), version); | |
341f9135 CC |
8364 | if (version >= 2) |
8365 | printf (_(" Number of columns: %d\n"), ncols); | |
657d0d47 CC |
8366 | printf (_(" Number of used entries: %d\n"), nused); |
8367 | printf (_(" Number of slots: %d\n\n"), nslots); | |
8368 | } | |
8369 | ||
03a91817 | 8370 | if (ppool > limit || ppool < phdr) |
657d0d47 CC |
8371 | { |
8372 | warn (_("Section %s too small for %d hash table entries\n"), | |
8373 | section->name, nslots); | |
8374 | return 0; | |
8375 | } | |
8376 | ||
341f9135 | 8377 | if (version == 1) |
657d0d47 | 8378 | { |
341f9135 CC |
8379 | if (!do_display) |
8380 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
8381 | for (i = 0; i < nslots; i++) | |
657d0d47 | 8382 | { |
341f9135 CC |
8383 | unsigned char *shndx_list; |
8384 | unsigned int shndx; | |
8385 | ||
6937bb54 | 8386 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 8387 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 8388 | { |
6937bb54 | 8389 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 8390 | shndx_list = ppool + j * 4; |
f3853b34 NC |
8391 | /* PR 17531: file: 705e010d. */ |
8392 | if (shndx_list < ppool) | |
8393 | { | |
8394 | warn (_("Section index pool located before start of section\n")); | |
8395 | return 0; | |
8396 | } | |
8397 | ||
341f9135 CC |
8398 | if (do_display) |
8399 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
8400 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
8401 | buf, sizeof (buf))); | |
8402 | for (;;) | |
657d0d47 | 8403 | { |
341f9135 CC |
8404 | if (shndx_list >= limit) |
8405 | { | |
8406 | warn (_("Section %s too small for shndx pool\n"), | |
8407 | section->name); | |
8408 | return 0; | |
8409 | } | |
6937bb54 | 8410 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
8411 | if (shndx == 0) |
8412 | break; | |
8413 | if (do_display) | |
8414 | printf (" %d", shndx); | |
8415 | else | |
8416 | add_shndx_to_cu_tu_entry (shndx); | |
8417 | shndx_list += 4; | |
657d0d47 | 8418 | } |
657d0d47 | 8419 | if (do_display) |
341f9135 | 8420 | printf ("\n"); |
657d0d47 | 8421 | else |
341f9135 CC |
8422 | end_cu_tu_entry (); |
8423 | } | |
8424 | phash += 8; | |
8425 | pindex += 4; | |
8426 | } | |
8427 | } | |
8428 | else if (version == 2) | |
8429 | { | |
8430 | unsigned int val; | |
8431 | unsigned int dw_sect; | |
8432 | unsigned char *ph = phash; | |
8433 | unsigned char *pi = pindex; | |
8434 | unsigned char *poffsets = ppool + ncols * 4; | |
8435 | unsigned char *psizes = poffsets + nused * ncols * 4; | |
8436 | unsigned char *pend = psizes + nused * ncols * 4; | |
8437 | bfd_boolean is_tu_index; | |
8438 | struct cu_tu_set *this_set = NULL; | |
8439 | unsigned int row; | |
8440 | unsigned char *prow; | |
8441 | ||
8442 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
8443 | ||
362beea4 | 8444 | /* PR 17531: file: 0dd159bf. |
b4eb7656 | 8445 | Check for wraparound with an overlarge ncols value. */ |
c8071705 | 8446 | if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols) |
362beea4 NC |
8447 | { |
8448 | warn (_("Overlarge number of columns: %x\n"), ncols); | |
8449 | return 0; | |
8450 | } | |
8451 | ||
341f9135 CC |
8452 | if (pend > limit) |
8453 | { | |
8454 | warn (_("Section %s too small for offset and size tables\n"), | |
8455 | section->name); | |
8456 | return 0; | |
8457 | } | |
8458 | ||
8459 | if (do_display) | |
8460 | { | |
8461 | printf (_(" Offset table\n")); | |
8462 | printf (" slot %-16s ", | |
8463 | is_tu_index ? _("signature") : _("dwo_id")); | |
8464 | } | |
8465 | else | |
8466 | { | |
8467 | if (is_tu_index) | |
8468 | { | |
8469 | tu_count = nused; | |
72c61a0d | 8470 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 8471 | this_set = tu_sets; |
657d0d47 | 8472 | } |
657d0d47 | 8473 | else |
341f9135 CC |
8474 | { |
8475 | cu_count = nused; | |
72c61a0d | 8476 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
8477 | this_set = cu_sets; |
8478 | } | |
8479 | } | |
6937bb54 | 8480 | |
341f9135 CC |
8481 | if (do_display) |
8482 | { | |
8483 | for (j = 0; j < ncols; j++) | |
8484 | { | |
6937bb54 | 8485 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
8486 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
8487 | } | |
8488 | printf ("\n"); | |
8489 | } | |
6937bb54 | 8490 | |
341f9135 CC |
8491 | for (i = 0; i < nslots; i++) |
8492 | { | |
6937bb54 NC |
8493 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
8494 | ||
8495 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
8496 | if (row != 0) |
8497 | { | |
591f7597 | 8498 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 8499 | if (row > nused) |
591f7597 NC |
8500 | { |
8501 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
8502 | row, nused); | |
8503 | return 0; | |
8504 | } | |
8505 | ||
341f9135 CC |
8506 | if (!do_display) |
8507 | memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t)); | |
6937bb54 | 8508 | |
341f9135 | 8509 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
8510 | /* PR 17531: file: b8ce60a8. */ |
8511 | if (prow < poffsets || prow > limit) | |
8512 | { | |
8513 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
8514 | row, ncols); | |
8515 | return 0; | |
8516 | } | |
3aade688 | 8517 | |
341f9135 CC |
8518 | if (do_display) |
8519 | printf (_(" [%3d] 0x%s"), | |
8520 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
8521 | buf, sizeof (buf))); | |
8522 | for (j = 0; j < ncols; j++) | |
8523 | { | |
6937bb54 | 8524 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
8525 | if (do_display) |
8526 | printf (" %8d", val); | |
8527 | else | |
8528 | { | |
6937bb54 | 8529 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
8530 | |
8531 | /* PR 17531: file: 10796eb3. */ | |
8532 | if (dw_sect >= DW_SECT_MAX) | |
8533 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
8534 | else | |
8535 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
8536 | } |
8537 | } | |
6937bb54 | 8538 | |
341f9135 CC |
8539 | if (do_display) |
8540 | printf ("\n"); | |
8541 | } | |
8542 | ph += 8; | |
8543 | pi += 4; | |
8544 | } | |
8545 | ||
8546 | ph = phash; | |
8547 | pi = pindex; | |
8548 | if (do_display) | |
b4eb7656 | 8549 | { |
341f9135 CC |
8550 | printf ("\n"); |
8551 | printf (_(" Size table\n")); | |
8552 | printf (" slot %-16s ", | |
8553 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 8554 | } |
6937bb54 | 8555 | |
341f9135 CC |
8556 | for (j = 0; j < ncols; j++) |
8557 | { | |
6937bb54 | 8558 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
8559 | if (do_display) |
8560 | printf (" %8s", get_DW_SECT_short_name (val)); | |
8561 | } | |
6937bb54 | 8562 | |
341f9135 CC |
8563 | if (do_display) |
8564 | printf ("\n"); | |
6937bb54 | 8565 | |
341f9135 CC |
8566 | for (i = 0; i < nslots; i++) |
8567 | { | |
6937bb54 NC |
8568 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
8569 | ||
8570 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
8571 | if (row != 0) |
8572 | { | |
8573 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 8574 | |
341f9135 CC |
8575 | if (do_display) |
8576 | printf (_(" [%3d] 0x%s"), | |
8577 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
8578 | buf, sizeof (buf))); | |
6937bb54 | 8579 | |
341f9135 CC |
8580 | for (j = 0; j < ncols; j++) |
8581 | { | |
6937bb54 | 8582 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
8583 | if (do_display) |
8584 | printf (" %8d", val); | |
8585 | else | |
8586 | { | |
6937bb54 | 8587 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
8588 | if (dw_sect >= DW_SECT_MAX) |
8589 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
8590 | else | |
341f9135 CC |
8591 | this_set [row - 1].section_sizes [dw_sect] = val; |
8592 | } | |
8593 | } | |
6937bb54 | 8594 | |
341f9135 CC |
8595 | if (do_display) |
8596 | printf ("\n"); | |
8597 | } | |
6937bb54 | 8598 | |
341f9135 CC |
8599 | ph += 8; |
8600 | pi += 4; | |
657d0d47 | 8601 | } |
657d0d47 | 8602 | } |
341f9135 | 8603 | else if (do_display) |
6937bb54 | 8604 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
8605 | |
8606 | if (do_display) | |
8607 | printf ("\n"); | |
8608 | ||
8609 | return 1; | |
8610 | } | |
8611 | ||
8612 | /* Load the CU and TU indexes if present. This will build a list of | |
8613 | section sets that we can use to associate a .debug_info.dwo section | |
8614 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
8615 | ||
43a444f9 | 8616 | static bfd_boolean |
657d0d47 CC |
8617 | load_cu_tu_indexes (void *file) |
8618 | { | |
43a444f9 NC |
8619 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
8620 | ||
657d0d47 CC |
8621 | /* If we have already loaded (or tried to load) the CU and TU indexes |
8622 | then do not bother to repeat the task. */ | |
43a444f9 NC |
8623 | if (cu_tu_indexes_read == -1) |
8624 | { | |
8625 | cu_tu_indexes_read = TRUE; | |
8626 | ||
8627 | if (load_debug_section (dwp_cu_index, file)) | |
8628 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) | |
8629 | cu_tu_indexes_read = FALSE; | |
8630 | ||
8631 | if (load_debug_section (dwp_tu_index, file)) | |
8632 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) | |
8633 | cu_tu_indexes_read = FALSE; | |
8634 | } | |
657d0d47 | 8635 | |
43a444f9 | 8636 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
8637 | } |
8638 | ||
8639 | /* Find the set of sections that includes section SHNDX. */ | |
8640 | ||
8641 | unsigned int * | |
8642 | find_cu_tu_set (void *file, unsigned int shndx) | |
8643 | { | |
8644 | unsigned int i; | |
8645 | ||
43a444f9 NC |
8646 | if (! load_cu_tu_indexes (file)) |
8647 | return NULL; | |
657d0d47 CC |
8648 | |
8649 | /* Find SHNDX in the shndx pool. */ | |
8650 | for (i = 0; i < shndx_pool_used; i++) | |
8651 | if (shndx_pool [i] == shndx) | |
8652 | break; | |
8653 | ||
8654 | if (i >= shndx_pool_used) | |
8655 | return NULL; | |
8656 | ||
8657 | /* Now backup to find the first entry in the set. */ | |
8658 | while (i > 0 && shndx_pool [i - 1] != 0) | |
8659 | i--; | |
8660 | ||
8661 | return shndx_pool + i; | |
8662 | } | |
8663 | ||
8664 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
8665 | ||
8666 | static int | |
8667 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
8668 | { | |
8669 | return process_cu_tu_index (section, 1); | |
8670 | } | |
8671 | ||
19e6b90e L |
8672 | static int |
8673 | display_debug_not_supported (struct dwarf_section *section, | |
8674 | void *file ATTRIBUTE_UNUSED) | |
8675 | { | |
8676 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
8677 | section->name); | |
8678 | ||
8679 | return 1; | |
8680 | } | |
8681 | ||
1306a742 NC |
8682 | /* Like malloc, but takes two parameters like calloc. |
8683 | Verifies that the first parameter is not too large. | |
82b1b41b | 8684 | Note: does *not* initialise the allocated memory to zero. */ |
19e6b90e L |
8685 | void * |
8686 | cmalloc (size_t nmemb, size_t size) | |
8687 | { | |
8688 | /* Check for overflow. */ | |
8689 | if (nmemb >= ~(size_t) 0 / size) | |
8690 | return NULL; | |
82b1b41b NC |
8691 | |
8692 | return xmalloc (nmemb * size); | |
19e6b90e L |
8693 | } |
8694 | ||
1306a742 NC |
8695 | /* Like xmalloc, but takes two parameters like calloc. |
8696 | Verifies that the first parameter is not too large. | |
8697 | Note: does *not* initialise the allocated memory to zero. */ | |
72c61a0d | 8698 | void * |
1306a742 | 8699 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
8700 | { |
8701 | /* Check for overflow. */ | |
8702 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
8703 | { |
8704 | fprintf (stderr, | |
8705 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
8706 | (long) nmemb); | |
8707 | xexit (1); | |
8708 | } | |
72c61a0d | 8709 | |
1306a742 | 8710 | return xmalloc (nmemb * size); |
72c61a0d NC |
8711 | } |
8712 | ||
1306a742 NC |
8713 | /* Like xrealloc, but takes three parameters. |
8714 | Verifies that the second parameter is not too large. | |
8715 | Note: does *not* initialise any new memory to zero. */ | |
19e6b90e | 8716 | void * |
1306a742 | 8717 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
8718 | { |
8719 | /* Check for overflow. */ | |
8720 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
8721 | { |
8722 | fprintf (stderr, | |
8723 | _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), | |
8724 | (long) nmemb); | |
8725 | xexit (1); | |
8726 | } | |
82b1b41b | 8727 | |
1306a742 | 8728 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
8729 | } |
8730 | ||
1306a742 | 8731 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
19e6b90e | 8732 | void * |
1306a742 | 8733 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
8734 | { |
8735 | /* Check for overflow. */ | |
8736 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
8737 | { |
8738 | fprintf (stderr, | |
8739 | _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), | |
8740 | (long) nmemb); | |
8741 | xexit (1); | |
8742 | } | |
82b1b41b | 8743 | |
1306a742 | 8744 | return xcalloc (nmemb, size); |
19e6b90e L |
8745 | } |
8746 | ||
19e6b90e L |
8747 | void |
8748 | free_debug_memory (void) | |
8749 | { | |
3f5e193b | 8750 | unsigned int i; |
19e6b90e L |
8751 | |
8752 | free_abbrevs (); | |
8753 | ||
8754 | for (i = 0; i < max; i++) | |
3f5e193b | 8755 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 8756 | |
cc86f28f | 8757 | if (debug_information != NULL) |
19e6b90e | 8758 | { |
cc86f28f | 8759 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 8760 | { |
cc86f28f | 8761 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 8762 | { |
cc86f28f NC |
8763 | if (!debug_information [i].max_loc_offsets) |
8764 | { | |
8765 | free (debug_information [i].loc_offsets); | |
8766 | free (debug_information [i].have_frame_base); | |
8767 | } | |
8768 | if (!debug_information [i].max_range_lists) | |
8769 | free (debug_information [i].range_lists); | |
19e6b90e | 8770 | } |
19e6b90e L |
8771 | } |
8772 | free (debug_information); | |
8773 | debug_information = NULL; | |
82b1b41b | 8774 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 8775 | } |
19e6b90e L |
8776 | } |
8777 | ||
4cb93e3b TG |
8778 | void |
8779 | dwarf_select_sections_by_names (const char *names) | |
8780 | { | |
8781 | typedef struct | |
8782 | { | |
8783 | const char * option; | |
8784 | int * variable; | |
f9f0e732 | 8785 | int val; |
4cb93e3b TG |
8786 | } |
8787 | debug_dump_long_opts; | |
8788 | ||
8789 | static const debug_dump_long_opts opts_table [] = | |
8790 | { | |
8791 | /* Please keep this table alpha- sorted. */ | |
8792 | { "Ranges", & do_debug_ranges, 1 }, | |
8793 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 8794 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 8795 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
8796 | { "cu_index", & do_debug_cu_index, 1 }, |
8797 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
4cb93e3b TG |
8798 | { "frames", & do_debug_frames, 1 }, |
8799 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
8800 | /* The special .gdb_index section. */ |
8801 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
8802 | { "info", & do_debug_info, 1 }, |
8803 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
4cb93e3b TG |
8804 | { "loc", & do_debug_loc, 1 }, |
8805 | { "macro", & do_debug_macinfo, 1 }, | |
8806 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 8807 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 8808 | /* This entry is for compatibility |
4cb93e3b TG |
8809 | with earlier versions of readelf. */ |
8810 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 8811 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 8812 | { "str", & do_debug_str, 1 }, |
6f875884 TG |
8813 | /* These trace_* sections are used by Itanium VMS. */ |
8814 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
8815 | { "trace_aranges", & do_trace_aranges, 1 }, | |
8816 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
8817 | { NULL, NULL, 0 } |
8818 | }; | |
8819 | ||
8820 | const char *p; | |
467c65bc | 8821 | |
4cb93e3b TG |
8822 | p = names; |
8823 | while (*p) | |
8824 | { | |
8825 | const debug_dump_long_opts * entry; | |
467c65bc | 8826 | |
4cb93e3b TG |
8827 | for (entry = opts_table; entry->option; entry++) |
8828 | { | |
8829 | size_t len = strlen (entry->option); | |
467c65bc | 8830 | |
4cb93e3b TG |
8831 | if (strncmp (p, entry->option, len) == 0 |
8832 | && (p[len] == ',' || p[len] == '\0')) | |
8833 | { | |
8834 | * entry->variable |= entry->val; | |
467c65bc | 8835 | |
4cb93e3b TG |
8836 | /* The --debug-dump=frames-interp option also |
8837 | enables the --debug-dump=frames option. */ | |
8838 | if (do_debug_frames_interp) | |
8839 | do_debug_frames = 1; | |
8840 | ||
8841 | p += len; | |
8842 | break; | |
8843 | } | |
8844 | } | |
467c65bc | 8845 | |
4cb93e3b TG |
8846 | if (entry->option == NULL) |
8847 | { | |
8848 | warn (_("Unrecognized debug option '%s'\n"), p); | |
8849 | p = strchr (p, ','); | |
8850 | if (p == NULL) | |
8851 | break; | |
8852 | } | |
467c65bc | 8853 | |
4cb93e3b TG |
8854 | if (*p == ',') |
8855 | p++; | |
8856 | } | |
8857 | } | |
8858 | ||
8859 | void | |
8860 | dwarf_select_sections_by_letters (const char *letters) | |
8861 | { | |
91d6fa6a | 8862 | unsigned int lindex = 0; |
4cb93e3b | 8863 | |
91d6fa6a NC |
8864 | while (letters[lindex]) |
8865 | switch (letters[lindex++]) | |
4cb93e3b TG |
8866 | { |
8867 | case 'i': | |
8868 | do_debug_info = 1; | |
8869 | break; | |
467c65bc | 8870 | |
4cb93e3b TG |
8871 | case 'a': |
8872 | do_debug_abbrevs = 1; | |
8873 | break; | |
467c65bc | 8874 | |
4cb93e3b TG |
8875 | case 'l': |
8876 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
8877 | break; | |
467c65bc | 8878 | |
4cb93e3b TG |
8879 | case 'L': |
8880 | do_debug_lines |= FLAG_DEBUG_LINES_DECODED; | |
8881 | break; | |
467c65bc | 8882 | |
4cb93e3b TG |
8883 | case 'p': |
8884 | do_debug_pubnames = 1; | |
8885 | break; | |
467c65bc | 8886 | |
f9f0e732 NC |
8887 | case 't': |
8888 | do_debug_pubtypes = 1; | |
8889 | break; | |
467c65bc | 8890 | |
4cb93e3b TG |
8891 | case 'r': |
8892 | do_debug_aranges = 1; | |
8893 | break; | |
467c65bc | 8894 | |
4cb93e3b TG |
8895 | case 'R': |
8896 | do_debug_ranges = 1; | |
8897 | break; | |
467c65bc | 8898 | |
4cb93e3b TG |
8899 | case 'F': |
8900 | do_debug_frames_interp = 1; | |
1a0670f3 | 8901 | /* Fall through. */ |
4cb93e3b TG |
8902 | case 'f': |
8903 | do_debug_frames = 1; | |
8904 | break; | |
467c65bc | 8905 | |
4cb93e3b TG |
8906 | case 'm': |
8907 | do_debug_macinfo = 1; | |
8908 | break; | |
467c65bc | 8909 | |
4cb93e3b TG |
8910 | case 's': |
8911 | do_debug_str = 1; | |
8912 | break; | |
467c65bc | 8913 | |
4cb93e3b TG |
8914 | case 'o': |
8915 | do_debug_loc = 1; | |
8916 | break; | |
467c65bc | 8917 | |
4cb93e3b | 8918 | default: |
7cc78d07 | 8919 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
8920 | break; |
8921 | } | |
8922 | } | |
8923 | ||
8924 | void | |
8925 | dwarf_select_sections_all (void) | |
8926 | { | |
8927 | do_debug_info = 1; | |
8928 | do_debug_abbrevs = 1; | |
8929 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
8930 | do_debug_pubnames = 1; | |
f9f0e732 | 8931 | do_debug_pubtypes = 1; |
4cb93e3b TG |
8932 | do_debug_aranges = 1; |
8933 | do_debug_ranges = 1; | |
8934 | do_debug_frames = 1; | |
8935 | do_debug_macinfo = 1; | |
8936 | do_debug_str = 1; | |
8937 | do_debug_loc = 1; | |
5bbdf3d5 | 8938 | do_gdb_index = 1; |
6f875884 TG |
8939 | do_trace_info = 1; |
8940 | do_trace_abbrevs = 1; | |
8941 | do_trace_aranges = 1; | |
657d0d47 CC |
8942 | do_debug_addr = 1; |
8943 | do_debug_cu_index = 1; | |
4cb93e3b TG |
8944 | } |
8945 | ||
19e6b90e L |
8946 | struct dwarf_section_display debug_displays[] = |
8947 | { | |
d1c4b12b NC |
8948 | { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
8949 | display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
8950 | { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8951 | display_debug_aranges, &do_debug_aranges, TRUE }, | |
8952 | { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8953 | display_debug_frames, &do_debug_frames, TRUE }, | |
8954 | { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL }, | |
8955 | display_debug_info, &do_debug_info, TRUE }, | |
8956 | { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8957 | display_debug_lines, &do_debug_lines, TRUE }, | |
8958 | { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8959 | display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
8960 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8961 | display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
8962 | { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8963 | display_debug_frames, &do_debug_frames, TRUE }, | |
8964 | { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8965 | display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
8966 | { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8967 | display_debug_macro, &do_debug_macinfo, TRUE }, | |
8968 | { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8969 | display_debug_str, &do_debug_str, FALSE }, | |
77145576 JK |
8970 | { { ".debug_line_str", ".zdebug_line_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
8971 | display_debug_str, &do_debug_str, FALSE }, | |
d1c4b12b NC |
8972 | { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
8973 | display_debug_loc, &do_debug_loc, TRUE }, | |
77145576 JK |
8974 | { { ".debug_loclists", ".zdebug_loclists", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
8975 | display_debug_loc, &do_debug_loc, TRUE }, | |
d1c4b12b NC |
8976 | { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
8977 | display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
8978 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8979 | display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
8980 | { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8981 | display_debug_ranges, &do_debug_ranges, TRUE }, | |
77145576 JK |
8982 | { { ".debug_rnglists", ".zdebug_rnglists", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
8983 | display_debug_ranges, &do_debug_ranges, TRUE }, | |
d1c4b12b NC |
8984 | { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
8985 | display_debug_not_supported, NULL, FALSE }, | |
8986 | { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8987 | display_debug_not_supported, NULL, FALSE }, | |
8988 | { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL }, | |
8989 | display_debug_types, &do_debug_info, TRUE }, | |
8990 | { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8991 | display_debug_not_supported, NULL, FALSE }, | |
8992 | { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8993 | display_gdb_index, &do_gdb_index, FALSE }, | |
61364358 JK |
8994 | { { ".debug_names", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, |
8995 | display_debug_names, &do_gdb_index, FALSE }, | |
d1c4b12b NC |
8996 | { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL, 0, NULL }, |
8997 | display_trace_info, &do_trace_info, TRUE }, | |
8998 | { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
8999 | display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
9000 | { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9001 | display_debug_aranges, &do_trace_aranges, FALSE }, | |
9002 | { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL }, | |
9003 | display_debug_info, &do_debug_info, TRUE }, | |
9004 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9005 | display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
9006 | { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL }, | |
9007 | display_debug_types, &do_debug_info, TRUE }, | |
9008 | { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9009 | display_debug_lines, &do_debug_lines, TRUE }, | |
9010 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9011 | display_debug_loc, &do_debug_loc, TRUE }, | |
9012 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9013 | display_debug_macro, &do_debug_macinfo, TRUE }, | |
9014 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9015 | display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
9016 | { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9017 | display_debug_str, &do_debug_str, TRUE }, | |
9018 | { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9019 | display_debug_str_offsets, NULL, FALSE }, | |
9020 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9021 | display_debug_str_offsets, NULL, FALSE }, | |
9022 | { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9023 | display_debug_addr, &do_debug_addr, TRUE }, | |
9024 | { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9025 | display_cu_index, &do_debug_cu_index, FALSE }, | |
9026 | { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
9027 | display_cu_index, &do_debug_cu_index, FALSE }, | |
19e6b90e | 9028 | }; |
b451e98a JK |
9029 | |
9030 | /* A static assertion. */ | |
9031 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |