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