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