Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
629e7ca8 | 2 | Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
19e6b90e L |
3 | Free Software Foundation, Inc. |
4 | ||
5 | This file is part of GNU Binutils. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
32866df7 | 9 | the Free Software Foundation; either version 3 of the License, or |
19e6b90e L |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA | |
20 | 02110-1301, USA. */ | |
21 | ||
3db64b00 | 22 | #include "sysdep.h" |
19e6b90e | 23 | #include "libiberty.h" |
3db64b00 | 24 | #include "bfd.h" |
5bbdf3d5 | 25 | #include "bfd_stdint.h" |
3db64b00 | 26 | #include "bucomm.h" |
3284fe0c | 27 | #include "elfcomm.h" |
2dc4cec1 | 28 | #include "elf/common.h" |
fa8f86ff | 29 | #include "dwarf2.h" |
3db64b00 | 30 | #include "dwarf.h" |
19e6b90e | 31 | |
18464d4d JK |
32 | static const char *regname (unsigned int regno, int row); |
33 | ||
19e6b90e L |
34 | static int have_frame_base; |
35 | static int need_base_address; | |
36 | ||
37 | static unsigned int last_pointer_size = 0; | |
38 | static int warned_about_missing_comp_units = FALSE; | |
39 | ||
40 | static unsigned int num_debug_info_entries = 0; | |
41 | static debug_info *debug_information = NULL; | |
cc86f28f NC |
42 | /* Special value for num_debug_info_entries to indicate |
43 | that the .debug_info section could not be loaded/parsed. */ | |
44 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 45 | |
2dc4cec1 | 46 | int eh_addr_size; |
19e6b90e L |
47 | |
48 | int do_debug_info; | |
49 | int do_debug_abbrevs; | |
50 | int do_debug_lines; | |
51 | int do_debug_pubnames; | |
f9f0e732 | 52 | int do_debug_pubtypes; |
19e6b90e L |
53 | int do_debug_aranges; |
54 | int do_debug_ranges; | |
55 | int do_debug_frames; | |
56 | int do_debug_frames_interp; | |
57 | int do_debug_macinfo; | |
58 | int do_debug_str; | |
59 | int do_debug_loc; | |
5bbdf3d5 | 60 | int do_gdb_index; |
6f875884 TG |
61 | int do_trace_info; |
62 | int do_trace_abbrevs; | |
63 | int do_trace_aranges; | |
a262ae96 | 64 | int do_wide; |
19e6b90e | 65 | |
4cb93e3b TG |
66 | /* Values for do_debug_lines. */ |
67 | #define FLAG_DEBUG_LINES_RAW 1 | |
68 | #define FLAG_DEBUG_LINES_DECODED 2 | |
69 | ||
f1c4cc75 RH |
70 | static int |
71 | size_of_encoded_value (int encoding) | |
72 | { | |
73 | switch (encoding & 0x7) | |
74 | { | |
75 | default: /* ??? */ | |
76 | case 0: return eh_addr_size; | |
77 | case 2: return 2; | |
78 | case 3: return 4; | |
79 | case 4: return 8; | |
80 | } | |
81 | } | |
82 | ||
83 | static dwarf_vma | |
bad62cf5 AM |
84 | get_encoded_value (unsigned char *data, |
85 | int encoding, | |
86 | struct dwarf_section *section) | |
f1c4cc75 RH |
87 | { |
88 | int size = size_of_encoded_value (encoding); | |
bad62cf5 | 89 | dwarf_vma val; |
f1c4cc75 RH |
90 | |
91 | if (encoding & DW_EH_PE_signed) | |
bad62cf5 | 92 | val = byte_get_signed (data, size); |
f1c4cc75 | 93 | else |
bad62cf5 AM |
94 | val = byte_get (data, size); |
95 | ||
96 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
97 | val += section->address + (data - section->start); | |
98 | return val; | |
f1c4cc75 RH |
99 | } |
100 | ||
2d9472a2 NC |
101 | /* Print a dwarf_vma value (typically an address, offset or length) in |
102 | hexadecimal format, followed by a space. The length of the value (and | |
103 | hence the precision displayed) is determined by the byte_size parameter. */ | |
cecf136e | 104 | |
2d9472a2 NC |
105 | static void |
106 | print_dwarf_vma (dwarf_vma val, unsigned byte_size) | |
107 | { | |
108 | static char buff[18]; | |
467c65bc | 109 | int offset = 0; |
2d9472a2 NC |
110 | |
111 | /* Printf does not have a way of specifiying a maximum field width for an | |
112 | integer value, so we print the full value into a buffer and then select | |
113 | the precision we need. */ | |
114 | #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2) | |
467c65bc | 115 | #ifndef __MINGW32__ |
2d9472a2 | 116 | snprintf (buff, sizeof (buff), "%16.16llx ", val); |
2e14fae2 NC |
117 | #else |
118 | snprintf (buff, sizeof (buff), "%016I64x ", val); | |
119 | #endif | |
2d9472a2 NC |
120 | #else |
121 | snprintf (buff, sizeof (buff), "%16.16lx ", val); | |
122 | #endif | |
123 | ||
467c65bc NC |
124 | if (byte_size != 0) |
125 | { | |
126 | if (byte_size > 0 && byte_size <= 8) | |
127 | offset = 16 - 2 * byte_size; | |
128 | else | |
129 | error ("Wrong size in print_dwarf_vma"); | |
130 | } | |
131 | ||
132 | fputs (buff + offset, stdout); | |
2d9472a2 NC |
133 | } |
134 | ||
467c65bc NC |
135 | #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2) |
136 | #ifndef __MINGW32__ | |
137 | #define DWARF_VMA_FMT "ll" | |
138 | #else | |
139 | #define DWARF_VMA_FMT "I64" | |
140 | #endif | |
141 | #else | |
142 | #define DWARF_VMA_FMT "l" | |
143 | #endif | |
144 | ||
47704ddf | 145 | static const char * |
467c65bc | 146 | dwarf_vmatoa (const char *fmtch, dwarf_vma value) |
47704ddf KT |
147 | { |
148 | /* As dwarf_vmatoa is used more then once in a printf call | |
149 | for output, we are cycling through an fixed array of pointers | |
150 | for return address. */ | |
151 | static int buf_pos = 0; | |
467c65bc NC |
152 | static struct dwarf_vmatoa_buf |
153 | { | |
47704ddf KT |
154 | char place[64]; |
155 | } buf[16]; | |
156 | char fmt[32]; | |
157 | char *ret; | |
158 | ||
467c65bc | 159 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); |
47704ddf KT |
160 | |
161 | ret = buf[buf_pos++].place; | |
467c65bc | 162 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf KT |
163 | |
164 | snprintf (ret, sizeof (buf[0].place), fmt, value); | |
165 | ||
166 | return ret; | |
167 | } | |
168 | ||
467c65bc | 169 | dwarf_vma |
19e6b90e L |
170 | read_leb128 (unsigned char *data, unsigned int *length_return, int sign) |
171 | { | |
467c65bc | 172 | dwarf_vma result = 0; |
19e6b90e L |
173 | unsigned int num_read = 0; |
174 | unsigned int shift = 0; | |
175 | unsigned char byte; | |
176 | ||
177 | do | |
178 | { | |
179 | byte = *data++; | |
180 | num_read++; | |
181 | ||
467c65bc | 182 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
19e6b90e L |
183 | |
184 | shift += 7; | |
185 | ||
186 | } | |
187 | while (byte & 0x80); | |
188 | ||
189 | if (length_return != NULL) | |
190 | *length_return = num_read; | |
191 | ||
192 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
193 | result |= -1L << shift; | |
194 | ||
195 | return result; | |
196 | } | |
197 | ||
467c65bc NC |
198 | /* Create a signed version to avoid painful typecasts. */ |
199 | static dwarf_signed_vma | |
200 | read_sleb128 (unsigned char *data, unsigned int *length_return) | |
201 | { | |
202 | return (dwarf_signed_vma) read_leb128 (data, length_return, 1); | |
203 | } | |
204 | ||
19e6b90e L |
205 | typedef struct State_Machine_Registers |
206 | { | |
467c65bc | 207 | dwarf_vma address; |
19e6b90e L |
208 | unsigned int file; |
209 | unsigned int line; | |
210 | unsigned int column; | |
211 | int is_stmt; | |
212 | int basic_block; | |
a233b20c JJ |
213 | unsigned char op_index; |
214 | unsigned char end_sequence; | |
19e6b90e L |
215 | /* This variable hold the number of the last entry seen |
216 | in the File Table. */ | |
217 | unsigned int last_file_entry; | |
218 | } SMR; | |
219 | ||
220 | static SMR state_machine_regs; | |
221 | ||
222 | static void | |
223 | reset_state_machine (int is_stmt) | |
224 | { | |
225 | state_machine_regs.address = 0; | |
a233b20c | 226 | state_machine_regs.op_index = 0; |
19e6b90e L |
227 | state_machine_regs.file = 1; |
228 | state_machine_regs.line = 1; | |
229 | state_machine_regs.column = 0; | |
230 | state_machine_regs.is_stmt = is_stmt; | |
231 | state_machine_regs.basic_block = 0; | |
232 | state_machine_regs.end_sequence = 0; | |
233 | state_machine_regs.last_file_entry = 0; | |
234 | } | |
235 | ||
236 | /* Handled an extend line op. | |
237 | Returns the number of bytes read. */ | |
238 | ||
239 | static int | |
1617e571 | 240 | process_extended_line_op (unsigned char *data, int is_stmt) |
19e6b90e L |
241 | { |
242 | unsigned char op_code; | |
243 | unsigned int bytes_read; | |
244 | unsigned int len; | |
245 | unsigned char *name; | |
467c65bc | 246 | dwarf_vma adr; |
19e6b90e L |
247 | |
248 | len = read_leb128 (data, & bytes_read, 0); | |
249 | data += bytes_read; | |
250 | ||
251 | if (len == 0) | |
252 | { | |
253 | warn (_("badly formed extended line op encountered!\n")); | |
254 | return bytes_read; | |
255 | } | |
256 | ||
257 | len += bytes_read; | |
258 | op_code = *data++; | |
259 | ||
260 | printf (_(" Extended opcode %d: "), op_code); | |
261 | ||
262 | switch (op_code) | |
263 | { | |
264 | case DW_LNE_end_sequence: | |
265 | printf (_("End of Sequence\n\n")); | |
266 | reset_state_machine (is_stmt); | |
267 | break; | |
268 | ||
269 | case DW_LNE_set_address: | |
1617e571 | 270 | adr = byte_get (data, len - bytes_read - 1); |
47704ddf | 271 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 272 | state_machine_regs.address = adr; |
a233b20c | 273 | state_machine_regs.op_index = 0; |
19e6b90e L |
274 | break; |
275 | ||
276 | case DW_LNE_define_file: | |
277 | printf (_(" define new File Table entry\n")); | |
278 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
279 | ||
cc5914eb | 280 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
19e6b90e L |
281 | name = data; |
282 | data += strlen ((char *) data) + 1; | |
467c65bc | 283 | printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); |
19e6b90e | 284 | data += bytes_read; |
467c65bc | 285 | printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); |
19e6b90e | 286 | data += bytes_read; |
467c65bc | 287 | printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); |
cc5914eb | 288 | printf ("%s\n\n", name); |
19e6b90e L |
289 | break; |
290 | ||
ed4a4bdf | 291 | case DW_LNE_set_discriminator: |
47704ddf | 292 | printf (_("set Discriminator to %s\n"), |
467c65bc | 293 | dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); |
ed4a4bdf CC |
294 | break; |
295 | ||
e2a0d921 NC |
296 | /* HP extensions. */ |
297 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 298 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
299 | break; |
300 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 301 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
302 | break; |
303 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 304 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
305 | break; |
306 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 307 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
308 | break; |
309 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 310 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
311 | break; |
312 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 313 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
314 | break; |
315 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 316 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
317 | break; |
318 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 319 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
320 | break; |
321 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 322 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
323 | break; |
324 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 325 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 326 | break; |
cecf136e | 327 | |
19e6b90e | 328 | default: |
e2a0d921 NC |
329 | if (op_code >= DW_LNE_lo_user |
330 | /* The test against DW_LNW_hi_user is redundant due to | |
331 | the limited range of the unsigned char data type used | |
332 | for op_code. */ | |
333 | /*&& op_code <= DW_LNE_hi_user*/) | |
334 | printf (_("user defined: length %d\n"), len - bytes_read); | |
335 | else | |
336 | printf (_("UNKNOWN: length %d\n"), len - bytes_read); | |
19e6b90e L |
337 | break; |
338 | } | |
339 | ||
340 | return len; | |
341 | } | |
342 | ||
343 | static const char * | |
467c65bc | 344 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
345 | { |
346 | struct dwarf_section *section = &debug_displays [str].section; | |
347 | ||
348 | if (section->start == NULL) | |
349 | return _("<no .debug_str section>"); | |
350 | ||
bfe2612a L |
351 | /* DWARF sections under Mach-O have non-zero addresses. */ |
352 | offset -= section->address; | |
19e6b90e L |
353 | if (offset > section->size) |
354 | { | |
467c65bc NC |
355 | warn (_("DW_FORM_strp offset too big: %s\n"), |
356 | dwarf_vmatoa ("x", offset)); | |
19e6b90e L |
357 | return _("<offset is too big>"); |
358 | } | |
359 | ||
360 | return (const char *) section->start + offset; | |
361 | } | |
362 | ||
363 | /* FIXME: There are better and more efficient ways to handle | |
364 | these structures. For now though, I just want something that | |
365 | is simple to implement. */ | |
366 | typedef struct abbrev_attr | |
367 | { | |
368 | unsigned long attribute; | |
369 | unsigned long form; | |
370 | struct abbrev_attr *next; | |
371 | } | |
372 | abbrev_attr; | |
373 | ||
374 | typedef struct abbrev_entry | |
375 | { | |
376 | unsigned long entry; | |
377 | unsigned long tag; | |
378 | int children; | |
379 | struct abbrev_attr *first_attr; | |
380 | struct abbrev_attr *last_attr; | |
381 | struct abbrev_entry *next; | |
382 | } | |
383 | abbrev_entry; | |
384 | ||
385 | static abbrev_entry *first_abbrev = NULL; | |
386 | static abbrev_entry *last_abbrev = NULL; | |
387 | ||
388 | static void | |
389 | free_abbrevs (void) | |
390 | { | |
91d6fa6a | 391 | abbrev_entry *abbrv; |
19e6b90e | 392 | |
91d6fa6a | 393 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 394 | { |
91d6fa6a | 395 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
396 | abbrev_attr *attr; |
397 | ||
91d6fa6a | 398 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 399 | { |
91d6fa6a | 400 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
401 | |
402 | free (attr); | |
91d6fa6a | 403 | attr = next_attr; |
19e6b90e L |
404 | } |
405 | ||
91d6fa6a NC |
406 | free (abbrv); |
407 | abbrv = next_abbrev; | |
19e6b90e L |
408 | } |
409 | ||
410 | last_abbrev = first_abbrev = NULL; | |
411 | } | |
412 | ||
413 | static void | |
414 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
415 | { | |
416 | abbrev_entry *entry; | |
417 | ||
3f5e193b | 418 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
419 | if (entry == NULL) |
420 | /* ugg */ | |
421 | return; | |
422 | ||
423 | entry->entry = number; | |
424 | entry->tag = tag; | |
425 | entry->children = children; | |
426 | entry->first_attr = NULL; | |
427 | entry->last_attr = NULL; | |
428 | entry->next = NULL; | |
429 | ||
430 | if (first_abbrev == NULL) | |
431 | first_abbrev = entry; | |
432 | else | |
433 | last_abbrev->next = entry; | |
434 | ||
435 | last_abbrev = entry; | |
436 | } | |
437 | ||
438 | static void | |
439 | add_abbrev_attr (unsigned long attribute, unsigned long form) | |
440 | { | |
441 | abbrev_attr *attr; | |
442 | ||
3f5e193b | 443 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
444 | if (attr == NULL) |
445 | /* ugg */ | |
446 | return; | |
447 | ||
448 | attr->attribute = attribute; | |
449 | attr->form = form; | |
450 | attr->next = NULL; | |
451 | ||
452 | if (last_abbrev->first_attr == NULL) | |
453 | last_abbrev->first_attr = attr; | |
454 | else | |
455 | last_abbrev->last_attr->next = attr; | |
456 | ||
457 | last_abbrev->last_attr = attr; | |
458 | } | |
459 | ||
460 | /* Processes the (partial) contents of a .debug_abbrev section. | |
461 | Returns NULL if the end of the section was encountered. | |
462 | Returns the address after the last byte read if the end of | |
463 | an abbreviation set was found. */ | |
464 | ||
465 | static unsigned char * | |
466 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
467 | { | |
468 | if (first_abbrev != NULL) | |
469 | return NULL; | |
470 | ||
471 | while (start < end) | |
472 | { | |
473 | unsigned int bytes_read; | |
474 | unsigned long entry; | |
475 | unsigned long tag; | |
476 | unsigned long attribute; | |
477 | int children; | |
478 | ||
479 | entry = read_leb128 (start, & bytes_read, 0); | |
480 | start += bytes_read; | |
481 | ||
482 | /* A single zero is supposed to end the section according | |
483 | to the standard. If there's more, then signal that to | |
484 | the caller. */ | |
485 | if (entry == 0) | |
486 | return start == end ? NULL : start; | |
487 | ||
488 | tag = read_leb128 (start, & bytes_read, 0); | |
489 | start += bytes_read; | |
490 | ||
491 | children = *start++; | |
492 | ||
493 | add_abbrev (entry, tag, children); | |
494 | ||
495 | do | |
496 | { | |
497 | unsigned long form; | |
498 | ||
499 | attribute = read_leb128 (start, & bytes_read, 0); | |
500 | start += bytes_read; | |
501 | ||
502 | form = read_leb128 (start, & bytes_read, 0); | |
503 | start += bytes_read; | |
504 | ||
505 | if (attribute != 0) | |
506 | add_abbrev_attr (attribute, form); | |
507 | } | |
508 | while (attribute != 0); | |
509 | } | |
510 | ||
511 | return NULL; | |
512 | } | |
513 | ||
514 | static char * | |
515 | get_TAG_name (unsigned long tag) | |
516 | { | |
517 | switch (tag) | |
518 | { | |
519 | case DW_TAG_padding: return "DW_TAG_padding"; | |
520 | case DW_TAG_array_type: return "DW_TAG_array_type"; | |
521 | case DW_TAG_class_type: return "DW_TAG_class_type"; | |
522 | case DW_TAG_entry_point: return "DW_TAG_entry_point"; | |
523 | case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type"; | |
524 | case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter"; | |
525 | case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration"; | |
526 | case DW_TAG_label: return "DW_TAG_label"; | |
527 | case DW_TAG_lexical_block: return "DW_TAG_lexical_block"; | |
528 | case DW_TAG_member: return "DW_TAG_member"; | |
529 | case DW_TAG_pointer_type: return "DW_TAG_pointer_type"; | |
530 | case DW_TAG_reference_type: return "DW_TAG_reference_type"; | |
531 | case DW_TAG_compile_unit: return "DW_TAG_compile_unit"; | |
532 | case DW_TAG_string_type: return "DW_TAG_string_type"; | |
533 | case DW_TAG_structure_type: return "DW_TAG_structure_type"; | |
534 | case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type"; | |
535 | case DW_TAG_typedef: return "DW_TAG_typedef"; | |
536 | case DW_TAG_union_type: return "DW_TAG_union_type"; | |
537 | case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters"; | |
538 | case DW_TAG_variant: return "DW_TAG_variant"; | |
539 | case DW_TAG_common_block: return "DW_TAG_common_block"; | |
540 | case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion"; | |
541 | case DW_TAG_inheritance: return "DW_TAG_inheritance"; | |
542 | case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine"; | |
543 | case DW_TAG_module: return "DW_TAG_module"; | |
544 | case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type"; | |
545 | case DW_TAG_set_type: return "DW_TAG_set_type"; | |
546 | case DW_TAG_subrange_type: return "DW_TAG_subrange_type"; | |
547 | case DW_TAG_with_stmt: return "DW_TAG_with_stmt"; | |
548 | case DW_TAG_access_declaration: return "DW_TAG_access_declaration"; | |
549 | case DW_TAG_base_type: return "DW_TAG_base_type"; | |
550 | case DW_TAG_catch_block: return "DW_TAG_catch_block"; | |
551 | case DW_TAG_const_type: return "DW_TAG_const_type"; | |
552 | case DW_TAG_constant: return "DW_TAG_constant"; | |
553 | case DW_TAG_enumerator: return "DW_TAG_enumerator"; | |
554 | case DW_TAG_file_type: return "DW_TAG_file_type"; | |
555 | case DW_TAG_friend: return "DW_TAG_friend"; | |
556 | case DW_TAG_namelist: return "DW_TAG_namelist"; | |
557 | case DW_TAG_namelist_item: return "DW_TAG_namelist_item"; | |
558 | case DW_TAG_packed_type: return "DW_TAG_packed_type"; | |
559 | case DW_TAG_subprogram: return "DW_TAG_subprogram"; | |
560 | case DW_TAG_template_type_param: return "DW_TAG_template_type_param"; | |
561 | case DW_TAG_template_value_param: return "DW_TAG_template_value_param"; | |
562 | case DW_TAG_thrown_type: return "DW_TAG_thrown_type"; | |
563 | case DW_TAG_try_block: return "DW_TAG_try_block"; | |
564 | case DW_TAG_variant_part: return "DW_TAG_variant_part"; | |
565 | case DW_TAG_variable: return "DW_TAG_variable"; | |
566 | case DW_TAG_volatile_type: return "DW_TAG_volatile_type"; | |
567 | case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop"; | |
568 | case DW_TAG_format_label: return "DW_TAG_format_label"; | |
569 | case DW_TAG_function_template: return "DW_TAG_function_template"; | |
570 | case DW_TAG_class_template: return "DW_TAG_class_template"; | |
571 | /* DWARF 2.1 values. */ | |
572 | case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure"; | |
573 | case DW_TAG_restrict_type: return "DW_TAG_restrict_type"; | |
574 | case DW_TAG_interface_type: return "DW_TAG_interface_type"; | |
575 | case DW_TAG_namespace: return "DW_TAG_namespace"; | |
576 | case DW_TAG_imported_module: return "DW_TAG_imported_module"; | |
577 | case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type"; | |
578 | case DW_TAG_partial_unit: return "DW_TAG_partial_unit"; | |
579 | case DW_TAG_imported_unit: return "DW_TAG_imported_unit"; | |
2b6f5997 CC |
580 | case DW_TAG_condition: return "DW_TAG_condition"; |
581 | case DW_TAG_shared_type: return "DW_TAG_shared_type"; | |
582 | /* DWARF 4 values. */ | |
583 | case DW_TAG_type_unit: return "DW_TAG_type_unit"; | |
584 | case DW_TAG_rvalue_reference_type: return "DW_TAG_rvalue_reference_type"; | |
585 | case DW_TAG_template_alias: return "DW_TAG_template_alias"; | |
19e6b90e L |
586 | /* UPC values. */ |
587 | case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type"; | |
588 | case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type"; | |
589 | case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type"; | |
629e7ca8 JJ |
590 | /* GNU values. */ |
591 | case DW_TAG_GNU_call_site: return "DW_TAG_GNU_call_site"; | |
592 | case DW_TAG_GNU_call_site_parameter:return "DW_TAG_GNU_call_site_parameter"; | |
19e6b90e L |
593 | default: |
594 | { | |
595 | static char buffer[100]; | |
596 | ||
597 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag); | |
598 | return buffer; | |
599 | } | |
600 | } | |
601 | } | |
602 | ||
603 | static char * | |
604 | get_FORM_name (unsigned long form) | |
605 | { | |
606 | switch (form) | |
607 | { | |
608 | case DW_FORM_addr: return "DW_FORM_addr"; | |
609 | case DW_FORM_block2: return "DW_FORM_block2"; | |
610 | case DW_FORM_block4: return "DW_FORM_block4"; | |
611 | case DW_FORM_data2: return "DW_FORM_data2"; | |
612 | case DW_FORM_data4: return "DW_FORM_data4"; | |
613 | case DW_FORM_data8: return "DW_FORM_data8"; | |
614 | case DW_FORM_string: return "DW_FORM_string"; | |
615 | case DW_FORM_block: return "DW_FORM_block"; | |
616 | case DW_FORM_block1: return "DW_FORM_block1"; | |
617 | case DW_FORM_data1: return "DW_FORM_data1"; | |
618 | case DW_FORM_flag: return "DW_FORM_flag"; | |
619 | case DW_FORM_sdata: return "DW_FORM_sdata"; | |
620 | case DW_FORM_strp: return "DW_FORM_strp"; | |
621 | case DW_FORM_udata: return "DW_FORM_udata"; | |
622 | case DW_FORM_ref_addr: return "DW_FORM_ref_addr"; | |
623 | case DW_FORM_ref1: return "DW_FORM_ref1"; | |
624 | case DW_FORM_ref2: return "DW_FORM_ref2"; | |
625 | case DW_FORM_ref4: return "DW_FORM_ref4"; | |
626 | case DW_FORM_ref8: return "DW_FORM_ref8"; | |
627 | case DW_FORM_ref_udata: return "DW_FORM_ref_udata"; | |
628 | case DW_FORM_indirect: return "DW_FORM_indirect"; | |
2b6f5997 CC |
629 | /* DWARF 4 values. */ |
630 | case DW_FORM_sec_offset: return "DW_FORM_sec_offset"; | |
631 | case DW_FORM_exprloc: return "DW_FORM_exprloc"; | |
632 | case DW_FORM_flag_present: return "DW_FORM_flag_present"; | |
633 | case DW_FORM_ref_sig8: return "DW_FORM_ref_sig8"; | |
19e6b90e L |
634 | default: |
635 | { | |
636 | static char buffer[100]; | |
637 | ||
638 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); | |
639 | return buffer; | |
640 | } | |
641 | } | |
642 | } | |
643 | ||
644 | static unsigned char * | |
467c65bc | 645 | display_block (unsigned char *data, dwarf_vma length) |
19e6b90e | 646 | { |
467c65bc | 647 | printf (_(" %s byte block: "), dwarf_vmatoa ("u", length)); |
19e6b90e L |
648 | |
649 | while (length --) | |
650 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
651 | ||
652 | return data; | |
653 | } | |
654 | ||
655 | static int | |
656 | decode_location_expression (unsigned char * data, | |
657 | unsigned int pointer_size, | |
b7807392 JJ |
658 | unsigned int offset_size, |
659 | int dwarf_version, | |
467c65bc NC |
660 | dwarf_vma length, |
661 | dwarf_vma cu_offset, | |
f1c4cc75 | 662 | struct dwarf_section * section) |
19e6b90e L |
663 | { |
664 | unsigned op; | |
665 | unsigned int bytes_read; | |
467c65bc | 666 | dwarf_vma uvalue; |
19e6b90e L |
667 | unsigned char *end = data + length; |
668 | int need_frame_base = 0; | |
669 | ||
670 | while (data < end) | |
671 | { | |
672 | op = *data++; | |
673 | ||
674 | switch (op) | |
675 | { | |
676 | case DW_OP_addr: | |
677 | printf ("DW_OP_addr: %lx", | |
678 | (unsigned long) byte_get (data, pointer_size)); | |
679 | data += pointer_size; | |
680 | break; | |
681 | case DW_OP_deref: | |
682 | printf ("DW_OP_deref"); | |
683 | break; | |
684 | case DW_OP_const1u: | |
685 | printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1)); | |
686 | break; | |
687 | case DW_OP_const1s: | |
688 | printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1)); | |
689 | break; | |
690 | case DW_OP_const2u: | |
691 | printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2)); | |
692 | data += 2; | |
693 | break; | |
694 | case DW_OP_const2s: | |
695 | printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2)); | |
696 | data += 2; | |
697 | break; | |
698 | case DW_OP_const4u: | |
699 | printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4)); | |
700 | data += 4; | |
701 | break; | |
702 | case DW_OP_const4s: | |
703 | printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4)); | |
704 | data += 4; | |
705 | break; | |
706 | case DW_OP_const8u: | |
707 | printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4), | |
708 | (unsigned long) byte_get (data + 4, 4)); | |
709 | data += 8; | |
710 | break; | |
711 | case DW_OP_const8s: | |
712 | printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4), | |
713 | (long) byte_get (data + 4, 4)); | |
714 | data += 8; | |
715 | break; | |
716 | case DW_OP_constu: | |
467c65bc NC |
717 | printf ("DW_OP_constu: %s", |
718 | dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0))); | |
19e6b90e L |
719 | data += bytes_read; |
720 | break; | |
721 | case DW_OP_consts: | |
467c65bc NC |
722 | printf ("DW_OP_consts: %s", |
723 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read))); | |
19e6b90e L |
724 | data += bytes_read; |
725 | break; | |
726 | case DW_OP_dup: | |
727 | printf ("DW_OP_dup"); | |
728 | break; | |
729 | case DW_OP_drop: | |
730 | printf ("DW_OP_drop"); | |
731 | break; | |
732 | case DW_OP_over: | |
733 | printf ("DW_OP_over"); | |
734 | break; | |
735 | case DW_OP_pick: | |
736 | printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1)); | |
737 | break; | |
738 | case DW_OP_swap: | |
739 | printf ("DW_OP_swap"); | |
740 | break; | |
741 | case DW_OP_rot: | |
742 | printf ("DW_OP_rot"); | |
743 | break; | |
744 | case DW_OP_xderef: | |
745 | printf ("DW_OP_xderef"); | |
746 | break; | |
747 | case DW_OP_abs: | |
748 | printf ("DW_OP_abs"); | |
749 | break; | |
750 | case DW_OP_and: | |
751 | printf ("DW_OP_and"); | |
752 | break; | |
753 | case DW_OP_div: | |
754 | printf ("DW_OP_div"); | |
755 | break; | |
756 | case DW_OP_minus: | |
757 | printf ("DW_OP_minus"); | |
758 | break; | |
759 | case DW_OP_mod: | |
760 | printf ("DW_OP_mod"); | |
761 | break; | |
762 | case DW_OP_mul: | |
763 | printf ("DW_OP_mul"); | |
764 | break; | |
765 | case DW_OP_neg: | |
766 | printf ("DW_OP_neg"); | |
767 | break; | |
768 | case DW_OP_not: | |
769 | printf ("DW_OP_not"); | |
770 | break; | |
771 | case DW_OP_or: | |
772 | printf ("DW_OP_or"); | |
773 | break; | |
774 | case DW_OP_plus: | |
775 | printf ("DW_OP_plus"); | |
776 | break; | |
777 | case DW_OP_plus_uconst: | |
467c65bc NC |
778 | printf ("DW_OP_plus_uconst: %s", |
779 | dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0))); | |
19e6b90e L |
780 | data += bytes_read; |
781 | break; | |
782 | case DW_OP_shl: | |
783 | printf ("DW_OP_shl"); | |
784 | break; | |
785 | case DW_OP_shr: | |
786 | printf ("DW_OP_shr"); | |
787 | break; | |
788 | case DW_OP_shra: | |
789 | printf ("DW_OP_shra"); | |
790 | break; | |
791 | case DW_OP_xor: | |
792 | printf ("DW_OP_xor"); | |
793 | break; | |
794 | case DW_OP_bra: | |
795 | printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2)); | |
796 | data += 2; | |
797 | break; | |
798 | case DW_OP_eq: | |
799 | printf ("DW_OP_eq"); | |
800 | break; | |
801 | case DW_OP_ge: | |
802 | printf ("DW_OP_ge"); | |
803 | break; | |
804 | case DW_OP_gt: | |
805 | printf ("DW_OP_gt"); | |
806 | break; | |
807 | case DW_OP_le: | |
808 | printf ("DW_OP_le"); | |
809 | break; | |
810 | case DW_OP_lt: | |
811 | printf ("DW_OP_lt"); | |
812 | break; | |
813 | case DW_OP_ne: | |
814 | printf ("DW_OP_ne"); | |
815 | break; | |
816 | case DW_OP_skip: | |
817 | printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2)); | |
818 | data += 2; | |
819 | break; | |
820 | ||
821 | case DW_OP_lit0: | |
822 | case DW_OP_lit1: | |
823 | case DW_OP_lit2: | |
824 | case DW_OP_lit3: | |
825 | case DW_OP_lit4: | |
826 | case DW_OP_lit5: | |
827 | case DW_OP_lit6: | |
828 | case DW_OP_lit7: | |
829 | case DW_OP_lit8: | |
830 | case DW_OP_lit9: | |
831 | case DW_OP_lit10: | |
832 | case DW_OP_lit11: | |
833 | case DW_OP_lit12: | |
834 | case DW_OP_lit13: | |
835 | case DW_OP_lit14: | |
836 | case DW_OP_lit15: | |
837 | case DW_OP_lit16: | |
838 | case DW_OP_lit17: | |
839 | case DW_OP_lit18: | |
840 | case DW_OP_lit19: | |
841 | case DW_OP_lit20: | |
842 | case DW_OP_lit21: | |
843 | case DW_OP_lit22: | |
844 | case DW_OP_lit23: | |
845 | case DW_OP_lit24: | |
846 | case DW_OP_lit25: | |
847 | case DW_OP_lit26: | |
848 | case DW_OP_lit27: | |
849 | case DW_OP_lit28: | |
850 | case DW_OP_lit29: | |
851 | case DW_OP_lit30: | |
852 | case DW_OP_lit31: | |
853 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
854 | break; | |
855 | ||
856 | case DW_OP_reg0: | |
857 | case DW_OP_reg1: | |
858 | case DW_OP_reg2: | |
859 | case DW_OP_reg3: | |
860 | case DW_OP_reg4: | |
861 | case DW_OP_reg5: | |
862 | case DW_OP_reg6: | |
863 | case DW_OP_reg7: | |
864 | case DW_OP_reg8: | |
865 | case DW_OP_reg9: | |
866 | case DW_OP_reg10: | |
867 | case DW_OP_reg11: | |
868 | case DW_OP_reg12: | |
869 | case DW_OP_reg13: | |
870 | case DW_OP_reg14: | |
871 | case DW_OP_reg15: | |
872 | case DW_OP_reg16: | |
873 | case DW_OP_reg17: | |
874 | case DW_OP_reg18: | |
875 | case DW_OP_reg19: | |
876 | case DW_OP_reg20: | |
877 | case DW_OP_reg21: | |
878 | case DW_OP_reg22: | |
879 | case DW_OP_reg23: | |
880 | case DW_OP_reg24: | |
881 | case DW_OP_reg25: | |
882 | case DW_OP_reg26: | |
883 | case DW_OP_reg27: | |
884 | case DW_OP_reg28: | |
885 | case DW_OP_reg29: | |
886 | case DW_OP_reg30: | |
887 | case DW_OP_reg31: | |
18464d4d JK |
888 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
889 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
890 | break; |
891 | ||
892 | case DW_OP_breg0: | |
893 | case DW_OP_breg1: | |
894 | case DW_OP_breg2: | |
895 | case DW_OP_breg3: | |
896 | case DW_OP_breg4: | |
897 | case DW_OP_breg5: | |
898 | case DW_OP_breg6: | |
899 | case DW_OP_breg7: | |
900 | case DW_OP_breg8: | |
901 | case DW_OP_breg9: | |
902 | case DW_OP_breg10: | |
903 | case DW_OP_breg11: | |
904 | case DW_OP_breg12: | |
905 | case DW_OP_breg13: | |
906 | case DW_OP_breg14: | |
907 | case DW_OP_breg15: | |
908 | case DW_OP_breg16: | |
909 | case DW_OP_breg17: | |
910 | case DW_OP_breg18: | |
911 | case DW_OP_breg19: | |
912 | case DW_OP_breg20: | |
913 | case DW_OP_breg21: | |
914 | case DW_OP_breg22: | |
915 | case DW_OP_breg23: | |
916 | case DW_OP_breg24: | |
917 | case DW_OP_breg25: | |
918 | case DW_OP_breg26: | |
919 | case DW_OP_breg27: | |
920 | case DW_OP_breg28: | |
921 | case DW_OP_breg29: | |
922 | case DW_OP_breg30: | |
923 | case DW_OP_breg31: | |
467c65bc | 924 | printf ("DW_OP_breg%d (%s): %s", |
47704ddf | 925 | op - DW_OP_breg0, |
18464d4d | 926 | regname (op - DW_OP_breg0, 1), |
467c65bc NC |
927 | dwarf_vmatoa ("d", (dwarf_signed_vma) |
928 | read_leb128 (data, &bytes_read, 1))); | |
19e6b90e L |
929 | data += bytes_read; |
930 | break; | |
931 | ||
932 | case DW_OP_regx: | |
18464d4d | 933 | uvalue = read_leb128 (data, &bytes_read, 0); |
19e6b90e | 934 | data += bytes_read; |
467c65bc NC |
935 | printf ("DW_OP_regx: %s (%s)", |
936 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
937 | break; |
938 | case DW_OP_fbreg: | |
939 | need_frame_base = 1; | |
467c65bc NC |
940 | printf ("DW_OP_fbreg: %s", |
941 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read))); | |
19e6b90e L |
942 | data += bytes_read; |
943 | break; | |
944 | case DW_OP_bregx: | |
945 | uvalue = read_leb128 (data, &bytes_read, 0); | |
946 | data += bytes_read; | |
467c65bc NC |
947 | printf ("DW_OP_bregx: %s (%s) %s", |
948 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
949 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read))); | |
19e6b90e L |
950 | data += bytes_read; |
951 | break; | |
952 | case DW_OP_piece: | |
467c65bc NC |
953 | printf ("DW_OP_piece: %s", |
954 | dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0))); | |
19e6b90e L |
955 | data += bytes_read; |
956 | break; | |
957 | case DW_OP_deref_size: | |
958 | printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1)); | |
959 | break; | |
960 | case DW_OP_xderef_size: | |
961 | printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1)); | |
962 | break; | |
963 | case DW_OP_nop: | |
964 | printf ("DW_OP_nop"); | |
965 | break; | |
966 | ||
967 | /* DWARF 3 extensions. */ | |
968 | case DW_OP_push_object_address: | |
969 | printf ("DW_OP_push_object_address"); | |
970 | break; | |
971 | case DW_OP_call2: | |
972 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
973 | this ought to be an 8-byte wide computation. */ | |
467c65bc NC |
974 | printf ("DW_OP_call2: <0x%s>", |
975 | dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 2) | |
976 | + cu_offset)); | |
19e6b90e L |
977 | data += 2; |
978 | break; | |
979 | case DW_OP_call4: | |
980 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
981 | this ought to be an 8-byte wide computation. */ | |
467c65bc NC |
982 | printf ("DW_OP_call4: <0x%s>", |
983 | dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 4) | |
984 | + cu_offset)); | |
19e6b90e L |
985 | data += 4; |
986 | break; | |
987 | case DW_OP_call_ref: | |
e2a0d921 NC |
988 | /* XXX: Strictly speaking for 64-bit DWARF3 files |
989 | this ought to be an 8-byte wide computation. */ | |
b7807392 JJ |
990 | if (dwarf_version == -1) |
991 | { | |
992 | printf (_("(DW_OP_call_ref in frame info)")); | |
993 | /* No way to tell where the next op is, so just bail. */ | |
994 | return need_frame_base; | |
995 | } | |
996 | if (dwarf_version == 2) | |
997 | { | |
467c65bc NC |
998 | printf ("DW_OP_call_ref: <0x%s>", |
999 | dwarf_vmatoa ("x", byte_get (data, pointer_size))); | |
b7807392 JJ |
1000 | data += pointer_size; |
1001 | } | |
1002 | else | |
1003 | { | |
467c65bc NC |
1004 | printf ("DW_OP_call_ref: <0x%s>", |
1005 | dwarf_vmatoa ("x", byte_get (data, offset_size))); | |
b7807392 JJ |
1006 | data += offset_size; |
1007 | } | |
19e6b90e | 1008 | break; |
a87b0a59 NS |
1009 | case DW_OP_form_tls_address: |
1010 | printf ("DW_OP_form_tls_address"); | |
1011 | break; | |
e2a0d921 NC |
1012 | case DW_OP_call_frame_cfa: |
1013 | printf ("DW_OP_call_frame_cfa"); | |
1014 | break; | |
1015 | case DW_OP_bit_piece: | |
1016 | printf ("DW_OP_bit_piece: "); | |
467c65bc NC |
1017 | printf ("size: %s ", |
1018 | dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0))); | |
e2a0d921 | 1019 | data += bytes_read; |
467c65bc NC |
1020 | printf ("offset: %s ", |
1021 | dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0))); | |
e2a0d921 NC |
1022 | data += bytes_read; |
1023 | break; | |
19e6b90e | 1024 | |
3244e8f5 JJ |
1025 | /* DWARF 4 extensions. */ |
1026 | case DW_OP_stack_value: | |
1027 | printf ("DW_OP_stack_value"); | |
1028 | break; | |
1029 | ||
1030 | case DW_OP_implicit_value: | |
1031 | printf ("DW_OP_implicit_value"); | |
1032 | uvalue = read_leb128 (data, &bytes_read, 0); | |
1033 | data += bytes_read; | |
1034 | display_block (data, uvalue); | |
1035 | data += uvalue; | |
1036 | break; | |
629e7ca8 JJ |
1037 | case DW_OP_GNU_entry_value: |
1038 | uvalue = read_leb128 (data, &bytes_read, 0); | |
1039 | data += bytes_read; | |
1040 | printf ("DW_OP_GNU_entry_value: ("); | |
1041 | if (decode_location_expression (data, pointer_size, offset_size, | |
1042 | dwarf_version, uvalue, | |
1043 | cu_offset, section)) | |
1044 | need_frame_base = 1; | |
1045 | putchar (')'); | |
1046 | data += uvalue; | |
1047 | break; | |
3244e8f5 | 1048 | |
19e6b90e L |
1049 | /* GNU extensions. */ |
1050 | case DW_OP_GNU_push_tls_address: | |
e2a0d921 NC |
1051 | printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"); |
1052 | break; | |
1053 | case DW_OP_GNU_uninit: | |
1054 | printf ("DW_OP_GNU_uninit"); | |
1055 | /* FIXME: Is there data associated with this OP ? */ | |
1056 | break; | |
f1c4cc75 RH |
1057 | case DW_OP_GNU_encoded_addr: |
1058 | { | |
1059 | int encoding; | |
1060 | dwarf_vma addr; | |
467c65bc | 1061 | |
f1c4cc75 | 1062 | encoding = *data++; |
bad62cf5 | 1063 | addr = get_encoded_value (data, encoding, section); |
f1c4cc75 RH |
1064 | data += size_of_encoded_value (encoding); |
1065 | ||
1066 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1067 | print_dwarf_vma (addr, pointer_size); | |
1068 | } | |
1069 | break; | |
b7807392 JJ |
1070 | case DW_OP_GNU_implicit_pointer: |
1071 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1072 | this ought to be an 8-byte wide computation. */ | |
1073 | if (dwarf_version == -1) | |
1074 | { | |
1075 | printf (_("(DW_OP_GNU_implicit_pointer in frame info)")); | |
1076 | /* No way to tell where the next op is, so just bail. */ | |
1077 | return need_frame_base; | |
1078 | } | |
1079 | if (dwarf_version == 2) | |
1080 | { | |
467c65bc NC |
1081 | printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s", |
1082 | dwarf_vmatoa ("x", byte_get (data, pointer_size)), | |
1083 | dwarf_vmatoa ("d", read_sleb128 (data + pointer_size, | |
1084 | &bytes_read))); | |
b7807392 JJ |
1085 | data += pointer_size + bytes_read; |
1086 | } | |
1087 | else | |
1088 | { | |
467c65bc NC |
1089 | printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s", |
1090 | dwarf_vmatoa ("x", byte_get (data, offset_size)), | |
1091 | dwarf_vmatoa ("d", read_sleb128 (data + offset_size, | |
1092 | &bytes_read))); | |
8383c696 | 1093 | data += offset_size + bytes_read; |
b7807392 JJ |
1094 | } |
1095 | break; | |
e2a0d921 NC |
1096 | |
1097 | /* HP extensions. */ | |
1098 | case DW_OP_HP_is_value: | |
1099 | printf ("DW_OP_HP_is_value"); | |
1100 | /* FIXME: Is there data associated with this OP ? */ | |
1101 | break; | |
1102 | case DW_OP_HP_fltconst4: | |
1103 | printf ("DW_OP_HP_fltconst4"); | |
1104 | /* FIXME: Is there data associated with this OP ? */ | |
1105 | break; | |
1106 | case DW_OP_HP_fltconst8: | |
1107 | printf ("DW_OP_HP_fltconst8"); | |
1108 | /* FIXME: Is there data associated with this OP ? */ | |
1109 | break; | |
1110 | case DW_OP_HP_mod_range: | |
1111 | printf ("DW_OP_HP_mod_range"); | |
1112 | /* FIXME: Is there data associated with this OP ? */ | |
1113 | break; | |
1114 | case DW_OP_HP_unmod_range: | |
1115 | printf ("DW_OP_HP_unmod_range"); | |
1116 | /* FIXME: Is there data associated with this OP ? */ | |
1117 | break; | |
1118 | case DW_OP_HP_tls: | |
1119 | printf ("DW_OP_HP_tls"); | |
1120 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1121 | break; |
1122 | ||
35d60fe4 NC |
1123 | /* PGI (STMicroelectronics) extensions. */ |
1124 | case DW_OP_PGI_omp_thread_num: | |
1125 | /* Pushes the thread number for the current thread as it would be | |
1126 | returned by the standard OpenMP library function: | |
1127 | omp_get_thread_num(). The "current thread" is the thread for | |
1128 | which the expression is being evaluated. */ | |
1129 | printf ("DW_OP_PGI_omp_thread_num"); | |
1130 | break; | |
1131 | ||
19e6b90e L |
1132 | default: |
1133 | if (op >= DW_OP_lo_user | |
1134 | && op <= DW_OP_hi_user) | |
1135 | printf (_("(User defined location op)")); | |
1136 | else | |
1137 | printf (_("(Unknown location op)")); | |
1138 | /* No way to tell where the next op is, so just bail. */ | |
1139 | return need_frame_base; | |
1140 | } | |
1141 | ||
1142 | /* Separate the ops. */ | |
1143 | if (data < end) | |
1144 | printf ("; "); | |
1145 | } | |
1146 | ||
1147 | return need_frame_base; | |
1148 | } | |
1149 | ||
1150 | static unsigned char * | |
6e3d6dc1 NC |
1151 | read_and_display_attr_value (unsigned long attribute, |
1152 | unsigned long form, | |
ec4d4525 | 1153 | unsigned char * data, |
467c65bc NC |
1154 | dwarf_vma cu_offset, |
1155 | dwarf_vma pointer_size, | |
1156 | dwarf_vma offset_size, | |
6e3d6dc1 NC |
1157 | int dwarf_version, |
1158 | debug_info * debug_info_p, | |
1159 | int do_loc, | |
1160 | struct dwarf_section * section) | |
19e6b90e | 1161 | { |
467c65bc | 1162 | dwarf_vma uvalue = 0; |
19e6b90e | 1163 | unsigned char *block_start = NULL; |
6e3d6dc1 | 1164 | unsigned char * orig_data = data; |
19e6b90e L |
1165 | unsigned int bytes_read; |
1166 | ||
1167 | switch (form) | |
1168 | { | |
1169 | default: | |
1170 | break; | |
1171 | ||
1172 | case DW_FORM_ref_addr: | |
1173 | if (dwarf_version == 2) | |
1174 | { | |
1175 | uvalue = byte_get (data, pointer_size); | |
1176 | data += pointer_size; | |
1177 | } | |
932fd279 | 1178 | else if (dwarf_version == 3 || dwarf_version == 4) |
19e6b90e L |
1179 | { |
1180 | uvalue = byte_get (data, offset_size); | |
1181 | data += offset_size; | |
1182 | } | |
1183 | else | |
467c65bc NC |
1184 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
1185 | ||
19e6b90e L |
1186 | break; |
1187 | ||
1188 | case DW_FORM_addr: | |
1189 | uvalue = byte_get (data, pointer_size); | |
1190 | data += pointer_size; | |
1191 | break; | |
1192 | ||
1193 | case DW_FORM_strp: | |
932fd279 | 1194 | case DW_FORM_sec_offset: |
19e6b90e L |
1195 | uvalue = byte_get (data, offset_size); |
1196 | data += offset_size; | |
1197 | break; | |
1198 | ||
932fd279 JJ |
1199 | case DW_FORM_flag_present: |
1200 | uvalue = 1; | |
1201 | break; | |
1202 | ||
19e6b90e L |
1203 | case DW_FORM_ref1: |
1204 | case DW_FORM_flag: | |
1205 | case DW_FORM_data1: | |
1206 | uvalue = byte_get (data++, 1); | |
1207 | break; | |
1208 | ||
1209 | case DW_FORM_ref2: | |
1210 | case DW_FORM_data2: | |
1211 | uvalue = byte_get (data, 2); | |
1212 | data += 2; | |
1213 | break; | |
1214 | ||
1215 | case DW_FORM_ref4: | |
1216 | case DW_FORM_data4: | |
1217 | uvalue = byte_get (data, 4); | |
1218 | data += 4; | |
1219 | break; | |
1220 | ||
1221 | case DW_FORM_sdata: | |
1222 | uvalue = read_leb128 (data, & bytes_read, 1); | |
1223 | data += bytes_read; | |
1224 | break; | |
1225 | ||
1226 | case DW_FORM_ref_udata: | |
1227 | case DW_FORM_udata: | |
1228 | uvalue = read_leb128 (data, & bytes_read, 0); | |
1229 | data += bytes_read; | |
1230 | break; | |
1231 | ||
1232 | case DW_FORM_indirect: | |
1233 | form = read_leb128 (data, & bytes_read, 0); | |
1234 | data += bytes_read; | |
1235 | if (!do_loc) | |
1236 | printf (" %s", get_FORM_name (form)); | |
1237 | return read_and_display_attr_value (attribute, form, data, | |
1238 | cu_offset, pointer_size, | |
1239 | offset_size, dwarf_version, | |
ec4d4525 | 1240 | debug_info_p, do_loc, |
6e3d6dc1 | 1241 | section); |
19e6b90e L |
1242 | } |
1243 | ||
1244 | switch (form) | |
1245 | { | |
1246 | case DW_FORM_ref_addr: | |
1247 | if (!do_loc) | |
467c65bc | 1248 | printf (" <0x%s>", dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
1249 | break; |
1250 | ||
1251 | case DW_FORM_ref1: | |
1252 | case DW_FORM_ref2: | |
1253 | case DW_FORM_ref4: | |
1254 | case DW_FORM_ref_udata: | |
1255 | if (!do_loc) | |
467c65bc | 1256 | printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
1257 | break; |
1258 | ||
1259 | case DW_FORM_data4: | |
1260 | case DW_FORM_addr: | |
932fd279 | 1261 | case DW_FORM_sec_offset: |
19e6b90e | 1262 | if (!do_loc) |
467c65bc | 1263 | printf (" 0x%s", dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
1264 | break; |
1265 | ||
932fd279 | 1266 | case DW_FORM_flag_present: |
19e6b90e L |
1267 | case DW_FORM_flag: |
1268 | case DW_FORM_data1: | |
1269 | case DW_FORM_data2: | |
1270 | case DW_FORM_sdata: | |
1271 | case DW_FORM_udata: | |
1272 | if (!do_loc) | |
467c65bc | 1273 | printf (" %s", dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
1274 | break; |
1275 | ||
1276 | case DW_FORM_ref8: | |
1277 | case DW_FORM_data8: | |
1278 | if (!do_loc) | |
1279 | { | |
1280 | uvalue = byte_get (data, 4); | |
467c65bc | 1281 | printf (" 0x%s", dwarf_vmatoa ("x", uvalue)); |
ec4d4525 | 1282 | printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4)); |
19e6b90e L |
1283 | } |
1284 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
1285 | && num_debug_info_entries == 0) | |
1286 | { | |
1287 | if (sizeof (uvalue) == 8) | |
1288 | uvalue = byte_get (data, 8); | |
1289 | else | |
467c65bc | 1290 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e L |
1291 | } |
1292 | data += 8; | |
1293 | break; | |
1294 | ||
1295 | case DW_FORM_string: | |
1296 | if (!do_loc) | |
1297 | printf (" %s", data); | |
1298 | data += strlen ((char *) data) + 1; | |
1299 | break; | |
1300 | ||
1301 | case DW_FORM_block: | |
932fd279 | 1302 | case DW_FORM_exprloc: |
19e6b90e L |
1303 | uvalue = read_leb128 (data, & bytes_read, 0); |
1304 | block_start = data + bytes_read; | |
1305 | if (do_loc) | |
1306 | data = block_start + uvalue; | |
1307 | else | |
1308 | data = display_block (block_start, uvalue); | |
1309 | break; | |
1310 | ||
1311 | case DW_FORM_block1: | |
1312 | uvalue = byte_get (data, 1); | |
1313 | block_start = data + 1; | |
1314 | if (do_loc) | |
1315 | data = block_start + uvalue; | |
1316 | else | |
1317 | data = display_block (block_start, uvalue); | |
1318 | break; | |
1319 | ||
1320 | case DW_FORM_block2: | |
1321 | uvalue = byte_get (data, 2); | |
1322 | block_start = data + 2; | |
1323 | if (do_loc) | |
1324 | data = block_start + uvalue; | |
1325 | else | |
1326 | data = display_block (block_start, uvalue); | |
1327 | break; | |
1328 | ||
1329 | case DW_FORM_block4: | |
1330 | uvalue = byte_get (data, 4); | |
1331 | block_start = data + 4; | |
1332 | if (do_loc) | |
1333 | data = block_start + uvalue; | |
1334 | else | |
1335 | data = display_block (block_start, uvalue); | |
1336 | break; | |
1337 | ||
1338 | case DW_FORM_strp: | |
1339 | if (!do_loc) | |
47704ddf KT |
1340 | printf (_(" (indirect string, offset: 0x%s): %s"), |
1341 | dwarf_vmatoa ("x", uvalue), | |
1342 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
1343 | break; |
1344 | ||
1345 | case DW_FORM_indirect: | |
1346 | /* Handled above. */ | |
1347 | break; | |
1348 | ||
2b6f5997 CC |
1349 | case DW_FORM_ref_sig8: |
1350 | if (!do_loc) | |
1351 | { | |
1352 | int i; | |
1353 | printf (" signature: "); | |
1354 | for (i = 0; i < 8; i++) | |
1355 | { | |
1356 | printf ("%02x", (unsigned) byte_get (data, 1)); | |
1357 | data += 1; | |
1358 | } | |
1359 | } | |
1360 | else | |
1361 | data += 8; | |
1362 | break; | |
1363 | ||
19e6b90e L |
1364 | default: |
1365 | warn (_("Unrecognized form: %lu\n"), form); | |
1366 | break; | |
1367 | } | |
1368 | ||
19e6b90e L |
1369 | if ((do_loc || do_debug_loc || do_debug_ranges) |
1370 | && num_debug_info_entries == 0) | |
1371 | { | |
1372 | switch (attribute) | |
1373 | { | |
1374 | case DW_AT_frame_base: | |
1375 | have_frame_base = 1; | |
1376 | case DW_AT_location: | |
e2a0d921 NC |
1377 | case DW_AT_string_length: |
1378 | case DW_AT_return_addr: | |
19e6b90e L |
1379 | case DW_AT_data_member_location: |
1380 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
1381 | case DW_AT_segment: |
1382 | case DW_AT_static_link: | |
1383 | case DW_AT_use_location: | |
629e7ca8 JJ |
1384 | case DW_AT_GNU_call_site_value: |
1385 | case DW_AT_GNU_call_site_data_value: | |
1386 | case DW_AT_GNU_call_site_target: | |
1387 | case DW_AT_GNU_call_site_target_clobbered: | |
932fd279 JJ |
1388 | if (form == DW_FORM_data4 |
1389 | || form == DW_FORM_data8 | |
1390 | || form == DW_FORM_sec_offset) | |
19e6b90e L |
1391 | { |
1392 | /* Process location list. */ | |
91d6fa6a | 1393 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
1394 | unsigned int num = debug_info_p->num_loc_offsets; |
1395 | ||
91d6fa6a | 1396 | if (lmax == 0 || num >= lmax) |
19e6b90e | 1397 | { |
91d6fa6a | 1398 | lmax += 1024; |
467c65bc | 1399 | debug_info_p->loc_offsets = (dwarf_vma *) |
3f5e193b | 1400 | xcrealloc (debug_info_p->loc_offsets, |
91d6fa6a | 1401 | lmax, sizeof (*debug_info_p->loc_offsets)); |
3f5e193b NC |
1402 | debug_info_p->have_frame_base = (int *) |
1403 | xcrealloc (debug_info_p->have_frame_base, | |
91d6fa6a NC |
1404 | lmax, sizeof (*debug_info_p->have_frame_base)); |
1405 | debug_info_p->max_loc_offsets = lmax; | |
19e6b90e L |
1406 | } |
1407 | debug_info_p->loc_offsets [num] = uvalue; | |
1408 | debug_info_p->have_frame_base [num] = have_frame_base; | |
1409 | debug_info_p->num_loc_offsets++; | |
1410 | } | |
1411 | break; | |
e2a0d921 | 1412 | |
19e6b90e L |
1413 | case DW_AT_low_pc: |
1414 | if (need_base_address) | |
1415 | debug_info_p->base_address = uvalue; | |
1416 | break; | |
1417 | ||
1418 | case DW_AT_ranges: | |
932fd279 JJ |
1419 | if (form == DW_FORM_data4 |
1420 | || form == DW_FORM_data8 | |
1421 | || form == DW_FORM_sec_offset) | |
19e6b90e L |
1422 | { |
1423 | /* Process range list. */ | |
91d6fa6a | 1424 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
1425 | unsigned int num = debug_info_p->num_range_lists; |
1426 | ||
91d6fa6a | 1427 | if (lmax == 0 || num >= lmax) |
19e6b90e | 1428 | { |
91d6fa6a | 1429 | lmax += 1024; |
467c65bc | 1430 | debug_info_p->range_lists = (dwarf_vma *) |
3f5e193b | 1431 | xcrealloc (debug_info_p->range_lists, |
91d6fa6a NC |
1432 | lmax, sizeof (*debug_info_p->range_lists)); |
1433 | debug_info_p->max_range_lists = lmax; | |
19e6b90e L |
1434 | } |
1435 | debug_info_p->range_lists [num] = uvalue; | |
1436 | debug_info_p->num_range_lists++; | |
1437 | } | |
1438 | break; | |
1439 | ||
1440 | default: | |
1441 | break; | |
1442 | } | |
1443 | } | |
1444 | ||
1445 | if (do_loc) | |
1446 | return data; | |
1447 | ||
ec4d4525 | 1448 | /* For some attributes we can display further information. */ |
19e6b90e L |
1449 | printf ("\t"); |
1450 | ||
1451 | switch (attribute) | |
1452 | { | |
1453 | case DW_AT_inline: | |
1454 | switch (uvalue) | |
1455 | { | |
1456 | case DW_INL_not_inlined: | |
1457 | printf (_("(not inlined)")); | |
1458 | break; | |
1459 | case DW_INL_inlined: | |
1460 | printf (_("(inlined)")); | |
1461 | break; | |
1462 | case DW_INL_declared_not_inlined: | |
1463 | printf (_("(declared as inline but ignored)")); | |
1464 | break; | |
1465 | case DW_INL_declared_inlined: | |
1466 | printf (_("(declared as inline and inlined)")); | |
1467 | break; | |
1468 | default: | |
47704ddf KT |
1469 | printf (_(" (Unknown inline attribute value: %s)"), |
1470 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1471 | break; |
1472 | } | |
1473 | break; | |
1474 | ||
1475 | case DW_AT_language: | |
1476 | switch (uvalue) | |
1477 | { | |
4b78141a | 1478 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 1479 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
1480 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
1481 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 1482 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
1483 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
1484 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
1485 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
1486 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 1487 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 1488 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 1489 | /* DWARF 2.1 values. */ |
4b78141a | 1490 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
1491 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
1492 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
1493 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
1494 | /* DWARF 3 values. */ |
1495 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
1496 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
1497 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
1498 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
1499 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
1500 | /* DWARF 4 values. */ |
1501 | case DW_LANG_Python: printf ("(Python)"); break; | |
19e6b90e L |
1502 | /* MIPS extension. */ |
1503 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
1504 | /* UPC extension. */ | |
1505 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
1506 | default: | |
4b78141a | 1507 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
467c65bc NC |
1508 | printf ("(implementation defined: %s)", |
1509 | dwarf_vmatoa ("x", uvalue)); | |
4b78141a | 1510 | else |
467c65bc | 1511 | printf ("(Unknown: %s)", dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
1512 | break; |
1513 | } | |
1514 | break; | |
1515 | ||
1516 | case DW_AT_encoding: | |
1517 | switch (uvalue) | |
1518 | { | |
1519 | case DW_ATE_void: printf ("(void)"); break; | |
1520 | case DW_ATE_address: printf ("(machine address)"); break; | |
1521 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
1522 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
1523 | case DW_ATE_float: printf ("(float)"); break; | |
1524 | case DW_ATE_signed: printf ("(signed)"); break; | |
1525 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
1526 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
1527 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 1528 | /* DWARF 2.1 values: */ |
19e6b90e L |
1529 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
1530 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
1531 | /* DWARF 3 values: */ |
1532 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
1533 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
1534 | case DW_ATE_edited: printf ("(edited)"); break; | |
1535 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
1536 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
1537 | /* HP extensions: */ | |
1538 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
1539 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
1540 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
1541 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
1542 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
1543 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
1544 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
1545 | ||
19e6b90e L |
1546 | default: |
1547 | if (uvalue >= DW_ATE_lo_user | |
1548 | && uvalue <= DW_ATE_hi_user) | |
1549 | printf ("(user defined type)"); | |
1550 | else | |
1551 | printf ("(unknown type)"); | |
1552 | break; | |
1553 | } | |
1554 | break; | |
1555 | ||
1556 | case DW_AT_accessibility: | |
1557 | switch (uvalue) | |
1558 | { | |
1559 | case DW_ACCESS_public: printf ("(public)"); break; | |
1560 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
1561 | case DW_ACCESS_private: printf ("(private)"); break; | |
1562 | default: | |
1563 | printf ("(unknown accessibility)"); | |
1564 | break; | |
1565 | } | |
1566 | break; | |
1567 | ||
1568 | case DW_AT_visibility: | |
1569 | switch (uvalue) | |
1570 | { | |
1571 | case DW_VIS_local: printf ("(local)"); break; | |
1572 | case DW_VIS_exported: printf ("(exported)"); break; | |
1573 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
1574 | default: printf ("(unknown visibility)"); break; | |
1575 | } | |
1576 | break; | |
1577 | ||
1578 | case DW_AT_virtuality: | |
1579 | switch (uvalue) | |
1580 | { | |
1581 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
1582 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
1583 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
1584 | default: printf ("(unknown virtuality)"); break; | |
1585 | } | |
1586 | break; | |
1587 | ||
1588 | case DW_AT_identifier_case: | |
1589 | switch (uvalue) | |
1590 | { | |
1591 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
1592 | case DW_ID_up_case: printf ("(up_case)"); break; | |
1593 | case DW_ID_down_case: printf ("(down_case)"); break; | |
1594 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
1595 | default: printf ("(unknown case)"); break; | |
1596 | } | |
1597 | break; | |
1598 | ||
1599 | case DW_AT_calling_convention: | |
1600 | switch (uvalue) | |
1601 | { | |
1602 | case DW_CC_normal: printf ("(normal)"); break; | |
1603 | case DW_CC_program: printf ("(program)"); break; | |
1604 | case DW_CC_nocall: printf ("(nocall)"); break; | |
1605 | default: | |
1606 | if (uvalue >= DW_CC_lo_user | |
1607 | && uvalue <= DW_CC_hi_user) | |
1608 | printf ("(user defined)"); | |
1609 | else | |
1610 | printf ("(unknown convention)"); | |
1611 | } | |
1612 | break; | |
1613 | ||
1614 | case DW_AT_ordering: | |
1615 | switch (uvalue) | |
1616 | { | |
1617 | case -1: printf ("(undefined)"); break; | |
1618 | case 0: printf ("(row major)"); break; | |
1619 | case 1: printf ("(column major)"); break; | |
1620 | } | |
1621 | break; | |
1622 | ||
1623 | case DW_AT_frame_base: | |
1624 | have_frame_base = 1; | |
1625 | case DW_AT_location: | |
e2a0d921 NC |
1626 | case DW_AT_string_length: |
1627 | case DW_AT_return_addr: | |
19e6b90e L |
1628 | case DW_AT_data_member_location: |
1629 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
1630 | case DW_AT_segment: |
1631 | case DW_AT_static_link: | |
1632 | case DW_AT_use_location: | |
629e7ca8 JJ |
1633 | case DW_AT_GNU_call_site_value: |
1634 | case DW_AT_GNU_call_site_data_value: | |
1635 | case DW_AT_GNU_call_site_target: | |
1636 | case DW_AT_GNU_call_site_target_clobbered: | |
932fd279 JJ |
1637 | if (form == DW_FORM_data4 |
1638 | || form == DW_FORM_data8 | |
1639 | || form == DW_FORM_sec_offset) | |
e2a0d921 NC |
1640 | printf (_("(location list)")); |
1641 | /* Fall through. */ | |
19e6b90e L |
1642 | case DW_AT_allocated: |
1643 | case DW_AT_associated: | |
1644 | case DW_AT_data_location: | |
1645 | case DW_AT_stride: | |
1646 | case DW_AT_upper_bound: | |
cecf136e | 1647 | case DW_AT_lower_bound: |
19e6b90e L |
1648 | if (block_start) |
1649 | { | |
1650 | int need_frame_base; | |
1651 | ||
1652 | printf ("("); | |
1653 | need_frame_base = decode_location_expression (block_start, | |
1654 | pointer_size, | |
b7807392 JJ |
1655 | offset_size, |
1656 | dwarf_version, | |
19e6b90e | 1657 | uvalue, |
f1c4cc75 | 1658 | cu_offset, section); |
19e6b90e L |
1659 | printf (")"); |
1660 | if (need_frame_base && !have_frame_base) | |
1661 | printf (_(" [without DW_AT_frame_base]")); | |
1662 | } | |
19e6b90e L |
1663 | break; |
1664 | ||
ec4d4525 NC |
1665 | case DW_AT_import: |
1666 | { | |
2b6f5997 CC |
1667 | if (form == DW_FORM_ref_sig8) |
1668 | break; | |
1669 | ||
ec4d4525 NC |
1670 | if (form == DW_FORM_ref1 |
1671 | || form == DW_FORM_ref2 | |
1672 | || form == DW_FORM_ref4) | |
1673 | uvalue += cu_offset; | |
1674 | ||
6e3d6dc1 | 1675 | if (uvalue >= section->size) |
47704ddf KT |
1676 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"), |
1677 | dwarf_vmatoa ("x", uvalue), | |
1678 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
1679 | else |
1680 | { | |
1681 | unsigned long abbrev_number; | |
1682 | abbrev_entry * entry; | |
1683 | ||
1684 | abbrev_number = read_leb128 (section->start + uvalue, NULL, 0); | |
cecf136e | 1685 | |
6e3d6dc1 NC |
1686 | printf ("[Abbrev Number: %ld", abbrev_number); |
1687 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
1688 | if (entry->entry == abbrev_number) | |
1689 | break; | |
1690 | if (entry != NULL) | |
1691 | printf (" (%s)", get_TAG_name (entry->tag)); | |
1692 | printf ("]"); | |
1693 | } | |
ec4d4525 NC |
1694 | } |
1695 | break; | |
1696 | ||
19e6b90e L |
1697 | default: |
1698 | break; | |
1699 | } | |
1700 | ||
1701 | return data; | |
1702 | } | |
1703 | ||
1704 | static char * | |
1705 | get_AT_name (unsigned long attribute) | |
1706 | { | |
1707 | switch (attribute) | |
1708 | { | |
1709 | case DW_AT_sibling: return "DW_AT_sibling"; | |
1710 | case DW_AT_location: return "DW_AT_location"; | |
1711 | case DW_AT_name: return "DW_AT_name"; | |
1712 | case DW_AT_ordering: return "DW_AT_ordering"; | |
1713 | case DW_AT_subscr_data: return "DW_AT_subscr_data"; | |
1714 | case DW_AT_byte_size: return "DW_AT_byte_size"; | |
1715 | case DW_AT_bit_offset: return "DW_AT_bit_offset"; | |
1716 | case DW_AT_bit_size: return "DW_AT_bit_size"; | |
1717 | case DW_AT_element_list: return "DW_AT_element_list"; | |
1718 | case DW_AT_stmt_list: return "DW_AT_stmt_list"; | |
1719 | case DW_AT_low_pc: return "DW_AT_low_pc"; | |
1720 | case DW_AT_high_pc: return "DW_AT_high_pc"; | |
1721 | case DW_AT_language: return "DW_AT_language"; | |
1722 | case DW_AT_member: return "DW_AT_member"; | |
1723 | case DW_AT_discr: return "DW_AT_discr"; | |
1724 | case DW_AT_discr_value: return "DW_AT_discr_value"; | |
1725 | case DW_AT_visibility: return "DW_AT_visibility"; | |
1726 | case DW_AT_import: return "DW_AT_import"; | |
1727 | case DW_AT_string_length: return "DW_AT_string_length"; | |
1728 | case DW_AT_common_reference: return "DW_AT_common_reference"; | |
1729 | case DW_AT_comp_dir: return "DW_AT_comp_dir"; | |
1730 | case DW_AT_const_value: return "DW_AT_const_value"; | |
1731 | case DW_AT_containing_type: return "DW_AT_containing_type"; | |
1732 | case DW_AT_default_value: return "DW_AT_default_value"; | |
1733 | case DW_AT_inline: return "DW_AT_inline"; | |
1734 | case DW_AT_is_optional: return "DW_AT_is_optional"; | |
1735 | case DW_AT_lower_bound: return "DW_AT_lower_bound"; | |
1736 | case DW_AT_producer: return "DW_AT_producer"; | |
1737 | case DW_AT_prototyped: return "DW_AT_prototyped"; | |
1738 | case DW_AT_return_addr: return "DW_AT_return_addr"; | |
1739 | case DW_AT_start_scope: return "DW_AT_start_scope"; | |
1740 | case DW_AT_stride_size: return "DW_AT_stride_size"; | |
1741 | case DW_AT_upper_bound: return "DW_AT_upper_bound"; | |
1742 | case DW_AT_abstract_origin: return "DW_AT_abstract_origin"; | |
1743 | case DW_AT_accessibility: return "DW_AT_accessibility"; | |
1744 | case DW_AT_address_class: return "DW_AT_address_class"; | |
1745 | case DW_AT_artificial: return "DW_AT_artificial"; | |
1746 | case DW_AT_base_types: return "DW_AT_base_types"; | |
1747 | case DW_AT_calling_convention: return "DW_AT_calling_convention"; | |
1748 | case DW_AT_count: return "DW_AT_count"; | |
1749 | case DW_AT_data_member_location: return "DW_AT_data_member_location"; | |
1750 | case DW_AT_decl_column: return "DW_AT_decl_column"; | |
1751 | case DW_AT_decl_file: return "DW_AT_decl_file"; | |
1752 | case DW_AT_decl_line: return "DW_AT_decl_line"; | |
1753 | case DW_AT_declaration: return "DW_AT_declaration"; | |
1754 | case DW_AT_discr_list: return "DW_AT_discr_list"; | |
1755 | case DW_AT_encoding: return "DW_AT_encoding"; | |
1756 | case DW_AT_external: return "DW_AT_external"; | |
1757 | case DW_AT_frame_base: return "DW_AT_frame_base"; | |
1758 | case DW_AT_friend: return "DW_AT_friend"; | |
1759 | case DW_AT_identifier_case: return "DW_AT_identifier_case"; | |
1760 | case DW_AT_macro_info: return "DW_AT_macro_info"; | |
1761 | case DW_AT_namelist_items: return "DW_AT_namelist_items"; | |
1762 | case DW_AT_priority: return "DW_AT_priority"; | |
1763 | case DW_AT_segment: return "DW_AT_segment"; | |
1764 | case DW_AT_specification: return "DW_AT_specification"; | |
1765 | case DW_AT_static_link: return "DW_AT_static_link"; | |
1766 | case DW_AT_type: return "DW_AT_type"; | |
1767 | case DW_AT_use_location: return "DW_AT_use_location"; | |
1768 | case DW_AT_variable_parameter: return "DW_AT_variable_parameter"; | |
1769 | case DW_AT_virtuality: return "DW_AT_virtuality"; | |
1770 | case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location"; | |
1771 | /* DWARF 2.1 values. */ | |
1772 | case DW_AT_allocated: return "DW_AT_allocated"; | |
1773 | case DW_AT_associated: return "DW_AT_associated"; | |
1774 | case DW_AT_data_location: return "DW_AT_data_location"; | |
1775 | case DW_AT_stride: return "DW_AT_stride"; | |
1776 | case DW_AT_entry_pc: return "DW_AT_entry_pc"; | |
1777 | case DW_AT_use_UTF8: return "DW_AT_use_UTF8"; | |
1778 | case DW_AT_extension: return "DW_AT_extension"; | |
1779 | case DW_AT_ranges: return "DW_AT_ranges"; | |
1780 | case DW_AT_trampoline: return "DW_AT_trampoline"; | |
1781 | case DW_AT_call_column: return "DW_AT_call_column"; | |
1782 | case DW_AT_call_file: return "DW_AT_call_file"; | |
1783 | case DW_AT_call_line: return "DW_AT_call_line"; | |
e2a0d921 NC |
1784 | case DW_AT_description: return "DW_AT_description"; |
1785 | case DW_AT_binary_scale: return "DW_AT_binary_scale"; | |
1786 | case DW_AT_decimal_scale: return "DW_AT_decimal_scale"; | |
1787 | case DW_AT_small: return "DW_AT_small"; | |
1788 | case DW_AT_decimal_sign: return "DW_AT_decimal_sign"; | |
1789 | case DW_AT_digit_count: return "DW_AT_digit_count"; | |
1790 | case DW_AT_picture_string: return "DW_AT_picture_string"; | |
1791 | case DW_AT_mutable: return "DW_AT_mutable"; | |
1792 | case DW_AT_threads_scaled: return "DW_AT_threads_scaled"; | |
1793 | case DW_AT_explicit: return "DW_AT_explicit"; | |
1794 | case DW_AT_object_pointer: return "DW_AT_object_pointer"; | |
1795 | case DW_AT_endianity: return "DW_AT_endianity"; | |
1796 | case DW_AT_elemental: return "DW_AT_elemental"; | |
1797 | case DW_AT_pure: return "DW_AT_pure"; | |
1798 | case DW_AT_recursive: return "DW_AT_recursive"; | |
2b6f5997 CC |
1799 | /* DWARF 4 values. */ |
1800 | case DW_AT_signature: return "DW_AT_signature"; | |
1801 | case DW_AT_main_subprogram: return "DW_AT_main_subprogram"; | |
1802 | case DW_AT_data_bit_offset: return "DW_AT_data_bit_offset"; | |
1803 | case DW_AT_const_expr: return "DW_AT_const_expr"; | |
1804 | case DW_AT_enum_class: return "DW_AT_enum_class"; | |
1805 | case DW_AT_linkage_name: return "DW_AT_linkage_name"; | |
e2a0d921 NC |
1806 | |
1807 | /* HP and SGI/MIPS extensions. */ | |
1808 | case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin"; | |
1809 | case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin"; | |
1810 | case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin"; | |
1811 | case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor"; | |
1812 | case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth"; | |
1813 | case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name"; | |
1814 | case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride"; | |
1815 | case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name"; | |
1816 | case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin"; | |
1817 | case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines"; | |
1818 | ||
1819 | /* HP Extensions. */ | |
cecf136e | 1820 | case DW_AT_HP_block_index: return "DW_AT_HP_block_index"; |
e2a0d921 NC |
1821 | case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list"; |
1822 | case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section"; | |
1823 | case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr"; | |
1824 | case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference"; | |
1825 | case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level"; | |
1826 | case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id"; | |
1827 | case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags"; | |
1828 | case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc"; | |
1829 | case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc"; | |
1830 | case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable"; | |
1831 | case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name"; | |
1832 | case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags"; | |
1833 | ||
1834 | /* One value is shared by the MIPS and HP extensions: */ | |
1835 | case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
cecf136e | 1836 | |
19e6b90e | 1837 | /* GNU extensions. */ |
2b6f5997 CC |
1838 | case DW_AT_sf_names: return "DW_AT_sf_names"; |
1839 | case DW_AT_src_info: return "DW_AT_src_info"; | |
1840 | case DW_AT_mac_info: return "DW_AT_mac_info"; | |
1841 | case DW_AT_src_coords: return "DW_AT_src_coords"; | |
1842 | case DW_AT_body_begin: return "DW_AT_body_begin"; | |
1843 | case DW_AT_body_end: return "DW_AT_body_end"; | |
1844 | case DW_AT_GNU_vector: return "DW_AT_GNU_vector"; | |
1845 | case DW_AT_GNU_guarded_by: return "DW_AT_GNU_guarded_by"; | |
1846 | case DW_AT_GNU_pt_guarded_by: return "DW_AT_GNU_pt_guarded_by"; | |
1847 | case DW_AT_GNU_guarded: return "DW_AT_GNU_guarded"; | |
1848 | case DW_AT_GNU_pt_guarded: return "DW_AT_GNU_pt_guarded"; | |
1849 | case DW_AT_GNU_locks_excluded: return "DW_AT_GNU_locks_excluded"; | |
1850 | case DW_AT_GNU_exclusive_locks_required: return "DW_AT_GNU_exclusive_locks_required"; | |
1851 | case DW_AT_GNU_shared_locks_required: return "DW_AT_GNU_shared_locks_required"; | |
1852 | case DW_AT_GNU_odr_signature: return "DW_AT_GNU_odr_signature"; | |
60a0e0e7 TG |
1853 | case DW_AT_use_GNAT_descriptive_type: return "DW_AT_use_GNAT_descriptive_type"; |
1854 | case DW_AT_GNAT_descriptive_type: return "DW_AT_GNAT_descriptive_type"; | |
629e7ca8 JJ |
1855 | case DW_AT_GNU_call_site_value: return "DW_AT_GNU_call_site_value"; |
1856 | case DW_AT_GNU_call_site_data_value: return "DW_AT_GNU_call_site_data_value"; | |
1857 | case DW_AT_GNU_call_site_target: return "DW_AT_GNU_call_site_target"; | |
1858 | case DW_AT_GNU_call_site_target_clobbered: return "DW_AT_GNU_call_site_target_clobbered"; | |
1859 | case DW_AT_GNU_tail_call: return "DW_AT_GNU_tail_call"; | |
1860 | case DW_AT_GNU_all_tail_call_sites: return "DW_AT_GNU_all_tail_call_sites"; | |
1861 | case DW_AT_GNU_all_call_sites: return "DW_AT_GNU_all_call_sites"; | |
1862 | case DW_AT_GNU_all_source_call_sites: return "DW_AT_GNU_all_source_call_sites"; | |
e2a0d921 | 1863 | |
19e6b90e L |
1864 | /* UPC extension. */ |
1865 | case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled"; | |
e2a0d921 NC |
1866 | |
1867 | /* PGI (STMicroelectronics) extensions. */ | |
1868 | case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase"; | |
1869 | case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset"; | |
1870 | case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride"; | |
1871 | ||
19e6b90e L |
1872 | default: |
1873 | { | |
1874 | static char buffer[100]; | |
1875 | ||
1876 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1877 | attribute); | |
1878 | return buffer; | |
1879 | } | |
1880 | } | |
1881 | } | |
1882 | ||
1883 | static unsigned char * | |
6e3d6dc1 NC |
1884 | read_and_display_attr (unsigned long attribute, |
1885 | unsigned long form, | |
ec4d4525 | 1886 | unsigned char * data, |
467c65bc NC |
1887 | dwarf_vma cu_offset, |
1888 | dwarf_vma pointer_size, | |
1889 | dwarf_vma offset_size, | |
6e3d6dc1 NC |
1890 | int dwarf_version, |
1891 | debug_info * debug_info_p, | |
1892 | int do_loc, | |
1893 | struct dwarf_section * section) | |
19e6b90e L |
1894 | { |
1895 | if (!do_loc) | |
750f03b7 | 1896 | printf (" %-18s:", get_AT_name (attribute)); |
19e6b90e L |
1897 | data = read_and_display_attr_value (attribute, form, data, cu_offset, |
1898 | pointer_size, offset_size, | |
1899 | dwarf_version, debug_info_p, | |
6e3d6dc1 | 1900 | do_loc, section); |
19e6b90e L |
1901 | if (!do_loc) |
1902 | printf ("\n"); | |
1903 | return data; | |
1904 | } | |
1905 | ||
1906 | ||
1907 | /* Process the contents of a .debug_info section. If do_loc is non-zero | |
1908 | then we are scanning for location lists and we do not want to display | |
2b6f5997 CC |
1909 | anything to the user. If do_types is non-zero, we are processing |
1910 | a .debug_types section instead of a .debug_info section. */ | |
19e6b90e L |
1911 | |
1912 | static int | |
6e3d6dc1 NC |
1913 | process_debug_info (struct dwarf_section *section, |
1914 | void *file, | |
6f875884 | 1915 | enum dwarf_section_display_enum abbrev_sec, |
2b6f5997 CC |
1916 | int do_loc, |
1917 | int do_types) | |
19e6b90e L |
1918 | { |
1919 | unsigned char *start = section->start; | |
1920 | unsigned char *end = start + section->size; | |
1921 | unsigned char *section_begin; | |
1922 | unsigned int unit; | |
1923 | unsigned int num_units = 0; | |
1924 | ||
1925 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
1926 | && num_debug_info_entries == 0 |
1927 | && ! do_types) | |
19e6b90e L |
1928 | { |
1929 | unsigned long length; | |
1930 | ||
1931 | /* First scan the section to get the number of comp units. */ | |
1932 | for (section_begin = start, num_units = 0; section_begin < end; | |
1933 | num_units ++) | |
1934 | { | |
1935 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
1936 | will be the length. For a 64-bit DWARF section, it'll be | |
1937 | the escape code 0xffffffff followed by an 8 byte length. */ | |
1938 | length = byte_get (section_begin, 4); | |
1939 | ||
1940 | if (length == 0xffffffff) | |
1941 | { | |
1942 | length = byte_get (section_begin + 4, 8); | |
1943 | section_begin += length + 12; | |
1944 | } | |
ec4d4525 NC |
1945 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
1946 | { | |
1947 | warn (_("Reserved length value (%lx) found in section %s\n"), length, section->name); | |
1948 | return 0; | |
1949 | } | |
19e6b90e L |
1950 | else |
1951 | section_begin += length + 4; | |
aca88567 NC |
1952 | |
1953 | /* Negative values are illegal, they may even cause infinite | |
1954 | looping. This can happen if we can't accurately apply | |
1955 | relocations to an object file. */ | |
1956 | if ((signed long) length <= 0) | |
1957 | { | |
1958 | warn (_("Corrupt unit length (%lx) found in section %s\n"), length, section->name); | |
1959 | return 0; | |
1960 | } | |
19e6b90e L |
1961 | } |
1962 | ||
1963 | if (num_units == 0) | |
1964 | { | |
1965 | error (_("No comp units in %s section ?"), section->name); | |
1966 | return 0; | |
1967 | } | |
1968 | ||
1969 | /* Then allocate an array to hold the information. */ | |
3f5e193b NC |
1970 | debug_information = (debug_info *) cmalloc (num_units, |
1971 | sizeof (* debug_information)); | |
19e6b90e L |
1972 | if (debug_information == NULL) |
1973 | { | |
1974 | error (_("Not enough memory for a debug info array of %u entries"), | |
1975 | num_units); | |
1976 | return 0; | |
1977 | } | |
1978 | } | |
1979 | ||
1980 | if (!do_loc) | |
1981 | { | |
80c35038 | 1982 | printf (_("Contents of the %s section:\n\n"), section->name); |
19e6b90e L |
1983 | |
1984 | load_debug_section (str, file); | |
1985 | } | |
1986 | ||
6f875884 TG |
1987 | load_debug_section (abbrev_sec, file); |
1988 | if (debug_displays [abbrev_sec].section.start == NULL) | |
19e6b90e L |
1989 | { |
1990 | warn (_("Unable to locate %s section!\n"), | |
6f875884 | 1991 | debug_displays [abbrev_sec].section.name); |
19e6b90e L |
1992 | return 0; |
1993 | } | |
1994 | ||
1995 | for (section_begin = start, unit = 0; start < end; unit++) | |
1996 | { | |
1997 | DWARF2_Internal_CompUnit compunit; | |
1998 | unsigned char *hdrptr; | |
19e6b90e L |
1999 | unsigned char *tags; |
2000 | int level; | |
467c65bc | 2001 | dwarf_vma cu_offset; |
19e6b90e L |
2002 | int offset_size; |
2003 | int initial_length_size; | |
1e70a64d | 2004 | unsigned char signature[8] = { 0 }; |
2b6f5997 | 2005 | unsigned long type_offset = 0; |
19e6b90e L |
2006 | |
2007 | hdrptr = start; | |
2008 | ||
2009 | compunit.cu_length = byte_get (hdrptr, 4); | |
2010 | hdrptr += 4; | |
2011 | ||
2012 | if (compunit.cu_length == 0xffffffff) | |
2013 | { | |
2014 | compunit.cu_length = byte_get (hdrptr, 8); | |
2015 | hdrptr += 8; | |
2016 | offset_size = 8; | |
2017 | initial_length_size = 12; | |
2018 | } | |
2019 | else | |
2020 | { | |
2021 | offset_size = 4; | |
2022 | initial_length_size = 4; | |
2023 | } | |
2024 | ||
2025 | compunit.cu_version = byte_get (hdrptr, 2); | |
2026 | hdrptr += 2; | |
2027 | ||
2028 | cu_offset = start - section_begin; | |
19e6b90e | 2029 | |
19e6b90e L |
2030 | compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size); |
2031 | hdrptr += offset_size; | |
2032 | ||
2033 | compunit.cu_pointer_size = byte_get (hdrptr, 1); | |
2034 | hdrptr += 1; | |
2b6f5997 CC |
2035 | |
2036 | if (do_types) | |
2037 | { | |
2038 | int i; | |
2039 | ||
2040 | for (i = 0; i < 8; i++) | |
2041 | { | |
2042 | signature[i] = byte_get (hdrptr, 1); | |
2043 | hdrptr += 1; | |
2044 | } | |
2045 | ||
2046 | type_offset = byte_get (hdrptr, offset_size); | |
2047 | hdrptr += offset_size; | |
2048 | } | |
2049 | ||
19e6b90e | 2050 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
2051 | && num_debug_info_entries == 0 |
2052 | && ! do_types) | |
19e6b90e L |
2053 | { |
2054 | debug_information [unit].cu_offset = cu_offset; | |
2055 | debug_information [unit].pointer_size | |
2056 | = compunit.cu_pointer_size; | |
b7807392 JJ |
2057 | debug_information [unit].offset_size = offset_size; |
2058 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e L |
2059 | debug_information [unit].base_address = 0; |
2060 | debug_information [unit].loc_offsets = NULL; | |
2061 | debug_information [unit].have_frame_base = NULL; | |
2062 | debug_information [unit].max_loc_offsets = 0; | |
2063 | debug_information [unit].num_loc_offsets = 0; | |
2064 | debug_information [unit].range_lists = NULL; | |
2065 | debug_information [unit].max_range_lists= 0; | |
2066 | debug_information [unit].num_range_lists = 0; | |
2067 | } | |
2068 | ||
19e6b90e L |
2069 | if (!do_loc) |
2070 | { | |
47704ddf KT |
2071 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
2072 | dwarf_vmatoa ("x", cu_offset)); | |
2073 | printf (_(" Length: 0x%s (%s)\n"), | |
2074 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 2075 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 2076 | printf (_(" Version: %d\n"), compunit.cu_version); |
47704ddf KT |
2077 | printf (_(" Abbrev Offset: %s\n"), |
2078 | dwarf_vmatoa ("d", compunit.cu_abbrev_offset)); | |
19e6b90e | 2079 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
2080 | if (do_types) |
2081 | { | |
2082 | int i; | |
2083 | printf (_(" Signature: ")); | |
2084 | for (i = 0; i < 8; i++) | |
2085 | printf ("%02x", signature[i]); | |
2086 | printf ("\n"); | |
2087 | printf (_(" Type Offset: 0x%lx\n"), type_offset); | |
2088 | } | |
19e6b90e L |
2089 | } |
2090 | ||
460c89ff NS |
2091 | if (cu_offset + compunit.cu_length + initial_length_size |
2092 | > section->size) | |
2093 | { | |
47704ddf KT |
2094 | warn (_("Debug info is corrupted, length of CU at %s" |
2095 | " extends beyond end of section (length = %s)\n"), | |
2096 | dwarf_vmatoa ("x", cu_offset), | |
2097 | dwarf_vmatoa ("x", compunit.cu_length)); | |
460c89ff NS |
2098 | break; |
2099 | } | |
2100 | tags = hdrptr; | |
2101 | start += compunit.cu_length + initial_length_size; | |
2102 | ||
932fd279 JJ |
2103 | if (compunit.cu_version != 2 |
2104 | && compunit.cu_version != 3 | |
2105 | && compunit.cu_version != 4) | |
19e6b90e | 2106 | { |
47704ddf KT |
2107 | warn (_("CU at offset %s contains corrupt or " |
2108 | "unsupported version number: %d.\n"), | |
2109 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
2110 | continue; |
2111 | } | |
2112 | ||
2113 | free_abbrevs (); | |
2114 | ||
bfe2612a L |
2115 | /* Process the abbrevs used by this compilation unit. DWARF |
2116 | sections under Mach-O have non-zero addresses. */ | |
6f875884 | 2117 | if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size) |
ec4d4525 NC |
2118 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
2119 | (unsigned long) compunit.cu_abbrev_offset, | |
6f875884 | 2120 | (unsigned long) debug_displays [abbrev_sec].section.size); |
460c89ff NS |
2121 | else |
2122 | process_abbrev_section | |
6f875884 | 2123 | ((unsigned char *) debug_displays [abbrev_sec].section.start |
0ac6fba0 | 2124 | + compunit.cu_abbrev_offset, |
6f875884 TG |
2125 | (unsigned char *) debug_displays [abbrev_sec].section.start |
2126 | + debug_displays [abbrev_sec].section.size); | |
19e6b90e L |
2127 | |
2128 | level = 0; | |
2129 | while (tags < start) | |
2130 | { | |
2131 | unsigned int bytes_read; | |
2132 | unsigned long abbrev_number; | |
ec4d4525 | 2133 | unsigned long die_offset; |
19e6b90e L |
2134 | abbrev_entry *entry; |
2135 | abbrev_attr *attr; | |
2136 | ||
ec4d4525 NC |
2137 | die_offset = tags - section_begin; |
2138 | ||
19e6b90e L |
2139 | abbrev_number = read_leb128 (tags, & bytes_read, 0); |
2140 | tags += bytes_read; | |
2141 | ||
eb7cc021 JK |
2142 | /* A null DIE marks the end of a list of siblings or it may also be |
2143 | a section padding. */ | |
19e6b90e L |
2144 | if (abbrev_number == 0) |
2145 | { | |
eb7cc021 JK |
2146 | /* Check if it can be a section padding for the last CU. */ |
2147 | if (level == 0 && start == end) | |
2148 | { | |
2149 | unsigned char *chk; | |
2150 | ||
2151 | for (chk = tags; chk < start; chk++) | |
2152 | if (*chk != 0) | |
2153 | break; | |
2154 | if (chk == start) | |
2155 | break; | |
2156 | } | |
2157 | ||
19e6b90e | 2158 | --level; |
ec4d4525 NC |
2159 | if (level < 0) |
2160 | { | |
2161 | static unsigned num_bogus_warns = 0; | |
2162 | ||
2163 | if (num_bogus_warns < 3) | |
2164 | { | |
2165 | warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"), | |
2166 | die_offset); | |
2167 | num_bogus_warns ++; | |
2168 | if (num_bogus_warns == 3) | |
2169 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
2170 | } | |
2171 | } | |
19e6b90e L |
2172 | continue; |
2173 | } | |
2174 | ||
4b78141a NC |
2175 | if (!do_loc) |
2176 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
ec4d4525 | 2177 | level, die_offset, abbrev_number); |
cecf136e | 2178 | |
19e6b90e L |
2179 | /* Scan through the abbreviation list until we reach the |
2180 | correct entry. */ | |
2181 | for (entry = first_abbrev; | |
2182 | entry && entry->entry != abbrev_number; | |
2183 | entry = entry->next) | |
2184 | continue; | |
2185 | ||
2186 | if (entry == NULL) | |
2187 | { | |
4b78141a NC |
2188 | if (!do_loc) |
2189 | { | |
2190 | printf ("\n"); | |
2191 | fflush (stdout); | |
2192 | } | |
cc86f28f NC |
2193 | warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"), |
2194 | die_offset, abbrev_number); | |
19e6b90e L |
2195 | return 0; |
2196 | } | |
2197 | ||
2198 | if (!do_loc) | |
cc5914eb | 2199 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 2200 | |
19e6b90e L |
2201 | switch (entry->tag) |
2202 | { | |
2203 | default: | |
2204 | need_base_address = 0; | |
2205 | break; | |
2206 | case DW_TAG_compile_unit: | |
2207 | need_base_address = 1; | |
2208 | break; | |
2209 | case DW_TAG_entry_point: | |
19e6b90e L |
2210 | case DW_TAG_subprogram: |
2211 | need_base_address = 0; | |
2212 | /* Assuming that there is no DW_AT_frame_base. */ | |
2213 | have_frame_base = 0; | |
2214 | break; | |
2215 | } | |
2216 | ||
2217 | for (attr = entry->first_attr; attr; attr = attr->next) | |
4b78141a NC |
2218 | { |
2219 | if (! do_loc) | |
2220 | /* Show the offset from where the tag was extracted. */ | |
750f03b7 | 2221 | printf (" <%2lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
2222 | |
2223 | tags = read_and_display_attr (attr->attribute, | |
2224 | attr->form, | |
2225 | tags, cu_offset, | |
2226 | compunit.cu_pointer_size, | |
2227 | offset_size, | |
2228 | compunit.cu_version, | |
ec4d4525 | 2229 | debug_information + unit, |
6e3d6dc1 | 2230 | do_loc, section); |
4b78141a | 2231 | } |
cecf136e | 2232 | |
19e6b90e L |
2233 | if (entry->children) |
2234 | ++level; | |
2235 | } | |
2236 | } | |
cecf136e | 2237 | |
19e6b90e L |
2238 | /* Set num_debug_info_entries here so that it can be used to check if |
2239 | we need to process .debug_loc and .debug_ranges sections. */ | |
2240 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2241 | && num_debug_info_entries == 0 |
2242 | && ! do_types) | |
19e6b90e | 2243 | num_debug_info_entries = num_units; |
cecf136e | 2244 | |
19e6b90e | 2245 | if (!do_loc) |
467c65bc | 2246 | printf ("\n"); |
cecf136e | 2247 | |
19e6b90e L |
2248 | return 1; |
2249 | } | |
2250 | ||
2251 | /* Locate and scan the .debug_info section in the file and record the pointer | |
2252 | sizes and offsets for the compilation units in it. Usually an executable | |
2253 | will have just one pointer size, but this is not guaranteed, and so we try | |
2254 | not to make any assumptions. Returns zero upon failure, or the number of | |
2255 | compilation units upon success. */ | |
2256 | ||
2257 | static unsigned int | |
2258 | load_debug_info (void * file) | |
2259 | { | |
2260 | /* Reset the last pointer size so that we can issue correct error | |
2261 | messages if we are displaying the contents of more than one section. */ | |
2262 | last_pointer_size = 0; | |
2263 | warned_about_missing_comp_units = FALSE; | |
2264 | ||
1febe64d NC |
2265 | /* If we have already tried and failed to load the .debug_info |
2266 | section then do not bother to repear the task. */ | |
cc86f28f | 2267 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
2268 | return 0; |
2269 | ||
19e6b90e L |
2270 | /* If we already have the information there is nothing else to do. */ |
2271 | if (num_debug_info_entries > 0) | |
2272 | return num_debug_info_entries; | |
2273 | ||
2274 | if (load_debug_section (info, file) | |
6f875884 | 2275 | && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0)) |
19e6b90e | 2276 | return num_debug_info_entries; |
1febe64d | 2277 | |
cc86f28f | 2278 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 2279 | return 0; |
19e6b90e L |
2280 | } |
2281 | ||
19e6b90e | 2282 | static int |
a262ae96 NC |
2283 | display_debug_lines_raw (struct dwarf_section *section, |
2284 | unsigned char *data, | |
2285 | unsigned char *end) | |
19e6b90e L |
2286 | { |
2287 | unsigned char *start = section->start; | |
19e6b90e | 2288 | |
a262ae96 NC |
2289 | printf (_("Raw dump of debug contents of section %s:\n\n"), |
2290 | section->name); | |
19e6b90e L |
2291 | |
2292 | while (data < end) | |
2293 | { | |
91d6fa6a | 2294 | DWARF2_Internal_LineInfo linfo; |
19e6b90e L |
2295 | unsigned char *standard_opcodes; |
2296 | unsigned char *end_of_sequence; | |
2297 | unsigned char *hdrptr; | |
6523721c | 2298 | unsigned long hdroff; |
19e6b90e L |
2299 | int initial_length_size; |
2300 | int offset_size; | |
2301 | int i; | |
2302 | ||
2303 | hdrptr = data; | |
6523721c | 2304 | hdroff = hdrptr - start; |
19e6b90e L |
2305 | |
2306 | /* Check the length of the block. */ | |
91d6fa6a | 2307 | linfo.li_length = byte_get (hdrptr, 4); |
19e6b90e L |
2308 | hdrptr += 4; |
2309 | ||
91d6fa6a | 2310 | if (linfo.li_length == 0xffffffff) |
19e6b90e L |
2311 | { |
2312 | /* This section is 64-bit DWARF 3. */ | |
91d6fa6a | 2313 | linfo.li_length = byte_get (hdrptr, 8); |
19e6b90e L |
2314 | hdrptr += 8; |
2315 | offset_size = 8; | |
2316 | initial_length_size = 12; | |
2317 | } | |
2318 | else | |
2319 | { | |
2320 | offset_size = 4; | |
2321 | initial_length_size = 4; | |
2322 | } | |
2323 | ||
91d6fa6a | 2324 | if (linfo.li_length + initial_length_size > section->size) |
19e6b90e L |
2325 | { |
2326 | warn | |
cf13d699 NC |
2327 | (_("The information in section %s appears to be corrupt - the section is too small\n"), |
2328 | section->name); | |
19e6b90e L |
2329 | return 0; |
2330 | } | |
2331 | ||
2332 | /* Check its version number. */ | |
91d6fa6a | 2333 | linfo.li_version = byte_get (hdrptr, 2); |
19e6b90e | 2334 | hdrptr += 2; |
932fd279 JJ |
2335 | if (linfo.li_version != 2 |
2336 | && linfo.li_version != 3 | |
2337 | && linfo.li_version != 4) | |
19e6b90e | 2338 | { |
932fd279 | 2339 | warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n")); |
19e6b90e L |
2340 | return 0; |
2341 | } | |
2342 | ||
91d6fa6a | 2343 | linfo.li_prologue_length = byte_get (hdrptr, offset_size); |
19e6b90e | 2344 | hdrptr += offset_size; |
91d6fa6a | 2345 | linfo.li_min_insn_length = byte_get (hdrptr, 1); |
19e6b90e | 2346 | hdrptr++; |
a233b20c JJ |
2347 | if (linfo.li_version >= 4) |
2348 | { | |
2349 | linfo.li_max_ops_per_insn = byte_get (hdrptr, 1); | |
2350 | hdrptr++; | |
2351 | if (linfo.li_max_ops_per_insn == 0) | |
2352 | { | |
2353 | warn (_("Invalid maximum operations per insn.\n")); | |
2354 | return 0; | |
2355 | } | |
2356 | } | |
2357 | else | |
2358 | linfo.li_max_ops_per_insn = 1; | |
91d6fa6a | 2359 | linfo.li_default_is_stmt = byte_get (hdrptr, 1); |
19e6b90e | 2360 | hdrptr++; |
91d6fa6a | 2361 | linfo.li_line_base = byte_get (hdrptr, 1); |
19e6b90e | 2362 | hdrptr++; |
91d6fa6a | 2363 | linfo.li_line_range = byte_get (hdrptr, 1); |
19e6b90e | 2364 | hdrptr++; |
91d6fa6a | 2365 | linfo.li_opcode_base = byte_get (hdrptr, 1); |
19e6b90e L |
2366 | hdrptr++; |
2367 | ||
2368 | /* Sign extend the line base field. */ | |
91d6fa6a NC |
2369 | linfo.li_line_base <<= 24; |
2370 | linfo.li_line_base >>= 24; | |
19e6b90e | 2371 | |
6523721c | 2372 | printf (_(" Offset: 0x%lx\n"), hdroff); |
47704ddf | 2373 | printf (_(" Length: %ld\n"), (long) linfo.li_length); |
91d6fa6a NC |
2374 | printf (_(" DWARF Version: %d\n"), linfo.li_version); |
2375 | printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length); | |
2376 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); | |
a233b20c JJ |
2377 | if (linfo.li_version >= 4) |
2378 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
91d6fa6a NC |
2379 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); |
2380 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
2381 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
2382 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 2383 | |
91d6fa6a | 2384 | end_of_sequence = data + linfo.li_length + initial_length_size; |
19e6b90e | 2385 | |
91d6fa6a | 2386 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e L |
2387 | |
2388 | /* Display the contents of the Opcodes table. */ | |
2389 | standard_opcodes = hdrptr; | |
2390 | ||
2391 | printf (_("\n Opcodes:\n")); | |
2392 | ||
91d6fa6a | 2393 | for (i = 1; i < linfo.li_opcode_base; i++) |
19e6b90e L |
2394 | printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); |
2395 | ||
2396 | /* Display the contents of the Directory table. */ | |
91d6fa6a | 2397 | data = standard_opcodes + linfo.li_opcode_base - 1; |
19e6b90e L |
2398 | |
2399 | if (*data == 0) | |
2400 | printf (_("\n The Directory Table is empty.\n")); | |
2401 | else | |
2402 | { | |
2403 | printf (_("\n The Directory Table:\n")); | |
2404 | ||
2405 | while (*data != 0) | |
2406 | { | |
cc5914eb | 2407 | printf (" %s\n", data); |
19e6b90e L |
2408 | |
2409 | data += strlen ((char *) data) + 1; | |
2410 | } | |
2411 | } | |
2412 | ||
2413 | /* Skip the NUL at the end of the table. */ | |
2414 | data++; | |
2415 | ||
2416 | /* Display the contents of the File Name table. */ | |
2417 | if (*data == 0) | |
2418 | printf (_("\n The File Name Table is empty.\n")); | |
2419 | else | |
2420 | { | |
2421 | printf (_("\n The File Name Table:\n")); | |
2422 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
2423 | ||
2424 | while (*data != 0) | |
2425 | { | |
2426 | unsigned char *name; | |
2427 | unsigned int bytes_read; | |
2428 | ||
cc5914eb | 2429 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
19e6b90e L |
2430 | name = data; |
2431 | ||
2432 | data += strlen ((char *) data) + 1; | |
2433 | ||
467c65bc NC |
2434 | printf ("%s\t", |
2435 | dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); | |
19e6b90e | 2436 | data += bytes_read; |
467c65bc NC |
2437 | printf ("%s\t", |
2438 | dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); | |
19e6b90e | 2439 | data += bytes_read; |
467c65bc NC |
2440 | printf ("%s\t", |
2441 | dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); | |
19e6b90e | 2442 | data += bytes_read; |
cc5914eb | 2443 | printf ("%s\n", name); |
19e6b90e L |
2444 | } |
2445 | } | |
2446 | ||
2447 | /* Skip the NUL at the end of the table. */ | |
2448 | data++; | |
2449 | ||
2450 | /* Now display the statements. */ | |
2451 | printf (_("\n Line Number Statements:\n")); | |
2452 | ||
2453 | while (data < end_of_sequence) | |
2454 | { | |
2455 | unsigned char op_code; | |
467c65bc NC |
2456 | dwarf_signed_vma adv; |
2457 | dwarf_vma uladv; | |
19e6b90e L |
2458 | unsigned int bytes_read; |
2459 | ||
2460 | op_code = *data++; | |
2461 | ||
91d6fa6a | 2462 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 2463 | { |
91d6fa6a | 2464 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
2465 | uladv = (op_code / linfo.li_line_range); |
2466 | if (linfo.li_max_ops_per_insn == 1) | |
2467 | { | |
2468 | uladv *= linfo.li_min_insn_length; | |
2469 | state_machine_regs.address += uladv; | |
467c65bc NC |
2470 | printf (_(" Special opcode %d: " |
2471 | "advance Address by %s to 0x%s"), | |
2472 | op_code, dwarf_vmatoa ("u", uladv), | |
2473 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
a233b20c JJ |
2474 | } |
2475 | else | |
2476 | { | |
2477 | state_machine_regs.address | |
2478 | += ((state_machine_regs.op_index + uladv) | |
2479 | / linfo.li_max_ops_per_insn) | |
2480 | * linfo.li_min_insn_length; | |
2481 | state_machine_regs.op_index | |
2482 | = (state_machine_regs.op_index + uladv) | |
2483 | % linfo.li_max_ops_per_insn; | |
467c65bc NC |
2484 | printf (_(" Special opcode %d: " |
2485 | "advance Address by %s to 0x%s[%d]"), | |
2486 | op_code, dwarf_vmatoa ("u", uladv), | |
2487 | dwarf_vmatoa ("x", state_machine_regs.address), | |
a233b20c JJ |
2488 | state_machine_regs.op_index); |
2489 | } | |
91d6fa6a | 2490 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
19e6b90e | 2491 | state_machine_regs.line += adv; |
467c65bc NC |
2492 | printf (_(" and Line by %s to %d\n"), |
2493 | dwarf_vmatoa ("d", adv), state_machine_regs.line); | |
19e6b90e L |
2494 | } |
2495 | else switch (op_code) | |
2496 | { | |
2497 | case DW_LNS_extended_op: | |
91d6fa6a | 2498 | data += process_extended_line_op (data, linfo.li_default_is_stmt); |
19e6b90e L |
2499 | break; |
2500 | ||
2501 | case DW_LNS_copy: | |
2502 | printf (_(" Copy\n")); | |
2503 | break; | |
2504 | ||
2505 | case DW_LNS_advance_pc: | |
2506 | uladv = read_leb128 (data, & bytes_read, 0); | |
19e6b90e | 2507 | data += bytes_read; |
a233b20c JJ |
2508 | if (linfo.li_max_ops_per_insn == 1) |
2509 | { | |
2510 | uladv *= linfo.li_min_insn_length; | |
2511 | state_machine_regs.address += uladv; | |
467c65bc NC |
2512 | printf (_(" Advance PC by %s to 0x%s\n"), |
2513 | dwarf_vmatoa ("u", uladv), | |
2514 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
a233b20c JJ |
2515 | } |
2516 | else | |
2517 | { | |
2518 | state_machine_regs.address | |
2519 | += ((state_machine_regs.op_index + uladv) | |
2520 | / linfo.li_max_ops_per_insn) | |
2521 | * linfo.li_min_insn_length; | |
2522 | state_machine_regs.op_index | |
2523 | = (state_machine_regs.op_index + uladv) | |
2524 | % linfo.li_max_ops_per_insn; | |
467c65bc NC |
2525 | printf (_(" Advance PC by %s to 0x%s[%d]\n"), |
2526 | dwarf_vmatoa ("u", uladv), | |
2527 | dwarf_vmatoa ("x", state_machine_regs.address), | |
a233b20c JJ |
2528 | state_machine_regs.op_index); |
2529 | } | |
19e6b90e L |
2530 | break; |
2531 | ||
2532 | case DW_LNS_advance_line: | |
467c65bc | 2533 | adv = read_sleb128 (data, & bytes_read); |
19e6b90e L |
2534 | data += bytes_read; |
2535 | state_machine_regs.line += adv; | |
467c65bc NC |
2536 | printf (_(" Advance Line by %s to %d\n"), |
2537 | dwarf_vmatoa ("d", adv), | |
2538 | state_machine_regs.line); | |
19e6b90e L |
2539 | break; |
2540 | ||
2541 | case DW_LNS_set_file: | |
2542 | adv = read_leb128 (data, & bytes_read, 0); | |
2543 | data += bytes_read; | |
467c65bc NC |
2544 | printf (_(" Set File Name to entry %s in the File Name Table\n"), |
2545 | dwarf_vmatoa ("d", adv)); | |
19e6b90e L |
2546 | state_machine_regs.file = adv; |
2547 | break; | |
2548 | ||
2549 | case DW_LNS_set_column: | |
2550 | uladv = read_leb128 (data, & bytes_read, 0); | |
2551 | data += bytes_read; | |
467c65bc NC |
2552 | printf (_(" Set column to %s\n"), |
2553 | dwarf_vmatoa ("u", uladv)); | |
19e6b90e L |
2554 | state_machine_regs.column = uladv; |
2555 | break; | |
2556 | ||
2557 | case DW_LNS_negate_stmt: | |
2558 | adv = state_machine_regs.is_stmt; | |
2559 | adv = ! adv; | |
467c65bc | 2560 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); |
19e6b90e L |
2561 | state_machine_regs.is_stmt = adv; |
2562 | break; | |
2563 | ||
2564 | case DW_LNS_set_basic_block: | |
2565 | printf (_(" Set basic block\n")); | |
2566 | state_machine_regs.basic_block = 1; | |
2567 | break; | |
2568 | ||
2569 | case DW_LNS_const_add_pc: | |
a233b20c JJ |
2570 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); |
2571 | if (linfo.li_max_ops_per_insn) | |
2572 | { | |
2573 | uladv *= linfo.li_min_insn_length; | |
2574 | state_machine_regs.address += uladv; | |
467c65bc NC |
2575 | printf (_(" Advance PC by constant %s to 0x%s\n"), |
2576 | dwarf_vmatoa ("u", uladv), | |
2577 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
a233b20c JJ |
2578 | } |
2579 | else | |
2580 | { | |
2581 | state_machine_regs.address | |
2582 | += ((state_machine_regs.op_index + uladv) | |
2583 | / linfo.li_max_ops_per_insn) | |
2584 | * linfo.li_min_insn_length; | |
2585 | state_machine_regs.op_index | |
2586 | = (state_machine_regs.op_index + uladv) | |
2587 | % linfo.li_max_ops_per_insn; | |
467c65bc NC |
2588 | printf (_(" Advance PC by constant %s to 0x%s[%d]\n"), |
2589 | dwarf_vmatoa ("u", uladv), | |
2590 | dwarf_vmatoa ("x", state_machine_regs.address), | |
a233b20c JJ |
2591 | state_machine_regs.op_index); |
2592 | } | |
19e6b90e L |
2593 | break; |
2594 | ||
2595 | case DW_LNS_fixed_advance_pc: | |
2596 | uladv = byte_get (data, 2); | |
2597 | data += 2; | |
2598 | state_machine_regs.address += uladv; | |
a233b20c | 2599 | state_machine_regs.op_index = 0; |
467c65bc NC |
2600 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), |
2601 | dwarf_vmatoa ("u", uladv), | |
2602 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
19e6b90e L |
2603 | break; |
2604 | ||
2605 | case DW_LNS_set_prologue_end: | |
2606 | printf (_(" Set prologue_end to true\n")); | |
2607 | break; | |
2608 | ||
2609 | case DW_LNS_set_epilogue_begin: | |
2610 | printf (_(" Set epilogue_begin to true\n")); | |
2611 | break; | |
2612 | ||
2613 | case DW_LNS_set_isa: | |
2614 | uladv = read_leb128 (data, & bytes_read, 0); | |
2615 | data += bytes_read; | |
467c65bc | 2616 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); |
19e6b90e L |
2617 | break; |
2618 | ||
2619 | default: | |
2620 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
2621 | ||
2622 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
2623 | { | |
467c65bc NC |
2624 | printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data, |
2625 | &bytes_read, 0)), | |
19e6b90e L |
2626 | i == 1 ? "" : ", "); |
2627 | data += bytes_read; | |
2628 | } | |
2629 | putchar ('\n'); | |
2630 | break; | |
2631 | } | |
2632 | } | |
2633 | putchar ('\n'); | |
2634 | } | |
2635 | ||
2636 | return 1; | |
2637 | } | |
2638 | ||
a262ae96 NC |
2639 | typedef struct |
2640 | { | |
467c65bc NC |
2641 | unsigned char *name; |
2642 | unsigned int directory_index; | |
2643 | unsigned int modification_date; | |
2644 | unsigned int length; | |
a262ae96 NC |
2645 | } File_Entry; |
2646 | ||
2647 | /* Output a decoded representation of the .debug_line section. */ | |
2648 | ||
2649 | static int | |
2650 | display_debug_lines_decoded (struct dwarf_section *section, | |
2651 | unsigned char *data, | |
2652 | unsigned char *end) | |
2653 | { | |
2654 | printf (_("Decoded dump of debug contents of section %s:\n\n"), | |
2655 | section->name); | |
2656 | ||
2657 | while (data < end) | |
2658 | { | |
2659 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 2660 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
2661 | unsigned char *standard_opcodes; |
2662 | unsigned char *end_of_sequence; | |
2663 | unsigned char *hdrptr; | |
2664 | int initial_length_size; | |
2665 | int offset_size; | |
2666 | int i; | |
2667 | File_Entry *file_table = NULL; | |
2668 | unsigned char **directory_table = NULL; | |
a262ae96 NC |
2669 | |
2670 | hdrptr = data; | |
2671 | ||
2672 | /* Extract information from the Line Number Program Header. | |
2673 | (section 6.2.4 in the Dwarf3 doc). */ | |
2674 | ||
2675 | /* Get the length of this CU's line number information block. */ | |
91d6fa6a | 2676 | linfo.li_length = byte_get (hdrptr, 4); |
a262ae96 NC |
2677 | hdrptr += 4; |
2678 | ||
91d6fa6a | 2679 | if (linfo.li_length == 0xffffffff) |
a262ae96 NC |
2680 | { |
2681 | /* This section is 64-bit DWARF 3. */ | |
91d6fa6a | 2682 | linfo.li_length = byte_get (hdrptr, 8); |
a262ae96 NC |
2683 | hdrptr += 8; |
2684 | offset_size = 8; | |
2685 | initial_length_size = 12; | |
2686 | } | |
2687 | else | |
2688 | { | |
2689 | offset_size = 4; | |
2690 | initial_length_size = 4; | |
2691 | } | |
2692 | ||
91d6fa6a | 2693 | if (linfo.li_length + initial_length_size > section->size) |
a262ae96 NC |
2694 | { |
2695 | warn (_("The line info appears to be corrupt - " | |
2696 | "the section is too small\n")); | |
2697 | return 0; | |
2698 | } | |
2699 | ||
2700 | /* Get this CU's Line Number Block version number. */ | |
91d6fa6a | 2701 | linfo.li_version = byte_get (hdrptr, 2); |
a262ae96 | 2702 | hdrptr += 2; |
932fd279 JJ |
2703 | if (linfo.li_version != 2 |
2704 | && linfo.li_version != 3 | |
2705 | && linfo.li_version != 4) | |
a262ae96 | 2706 | { |
932fd279 | 2707 | warn (_("Only DWARF version 2, 3 and 4 line info is currently " |
a262ae96 NC |
2708 | "supported.\n")); |
2709 | return 0; | |
2710 | } | |
2711 | ||
91d6fa6a | 2712 | linfo.li_prologue_length = byte_get (hdrptr, offset_size); |
a262ae96 | 2713 | hdrptr += offset_size; |
91d6fa6a | 2714 | linfo.li_min_insn_length = byte_get (hdrptr, 1); |
a262ae96 | 2715 | hdrptr++; |
a233b20c JJ |
2716 | if (linfo.li_version >= 4) |
2717 | { | |
2718 | linfo.li_max_ops_per_insn = byte_get (hdrptr, 1); | |
2719 | hdrptr++; | |
2720 | if (linfo.li_max_ops_per_insn == 0) | |
2721 | { | |
2722 | warn (_("Invalid maximum operations per insn.\n")); | |
2723 | return 0; | |
2724 | } | |
2725 | } | |
2726 | else | |
2727 | linfo.li_max_ops_per_insn = 1; | |
91d6fa6a | 2728 | linfo.li_default_is_stmt = byte_get (hdrptr, 1); |
a262ae96 | 2729 | hdrptr++; |
91d6fa6a | 2730 | linfo.li_line_base = byte_get (hdrptr, 1); |
a262ae96 | 2731 | hdrptr++; |
91d6fa6a | 2732 | linfo.li_line_range = byte_get (hdrptr, 1); |
a262ae96 | 2733 | hdrptr++; |
91d6fa6a | 2734 | linfo.li_opcode_base = byte_get (hdrptr, 1); |
a262ae96 NC |
2735 | hdrptr++; |
2736 | ||
2737 | /* Sign extend the line base field. */ | |
91d6fa6a NC |
2738 | linfo.li_line_base <<= 24; |
2739 | linfo.li_line_base >>= 24; | |
a262ae96 NC |
2740 | |
2741 | /* Find the end of this CU's Line Number Information Block. */ | |
91d6fa6a | 2742 | end_of_sequence = data + linfo.li_length + initial_length_size; |
a262ae96 | 2743 | |
91d6fa6a | 2744 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 NC |
2745 | |
2746 | /* Save a pointer to the contents of the Opcodes table. */ | |
2747 | standard_opcodes = hdrptr; | |
2748 | ||
2749 | /* Traverse the Directory table just to count entries. */ | |
91d6fa6a | 2750 | data = standard_opcodes + linfo.li_opcode_base - 1; |
a262ae96 NC |
2751 | if (*data != 0) |
2752 | { | |
2753 | unsigned int n_directories = 0; | |
2754 | unsigned char *ptr_directory_table = data; | |
a262ae96 NC |
2755 | |
2756 | while (*data != 0) | |
2757 | { | |
2758 | data += strlen ((char *) data) + 1; | |
2759 | n_directories++; | |
2760 | } | |
2761 | ||
2762 | /* Go through the directory table again to save the directories. */ | |
3f5e193b NC |
2763 | directory_table = (unsigned char **) |
2764 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 NC |
2765 | |
2766 | i = 0; | |
2767 | while (*ptr_directory_table != 0) | |
2768 | { | |
2769 | directory_table[i] = ptr_directory_table; | |
2770 | ptr_directory_table += strlen ((char *) ptr_directory_table) + 1; | |
2771 | i++; | |
2772 | } | |
2773 | } | |
2774 | /* Skip the NUL at the end of the table. */ | |
2775 | data++; | |
2776 | ||
2777 | /* Traverse the File Name table just to count the entries. */ | |
2778 | if (*data != 0) | |
2779 | { | |
2780 | unsigned int n_files = 0; | |
2781 | unsigned char *ptr_file_name_table = data; | |
a262ae96 NC |
2782 | |
2783 | while (*data != 0) | |
2784 | { | |
2785 | unsigned int bytes_read; | |
2786 | ||
2787 | /* Skip Name, directory index, last modification time and length | |
2788 | of file. */ | |
2789 | data += strlen ((char *) data) + 1; | |
2790 | read_leb128 (data, & bytes_read, 0); | |
2791 | data += bytes_read; | |
2792 | read_leb128 (data, & bytes_read, 0); | |
2793 | data += bytes_read; | |
2794 | read_leb128 (data, & bytes_read, 0); | |
2795 | data += bytes_read; | |
2796 | ||
2797 | n_files++; | |
2798 | } | |
2799 | ||
2800 | /* Go through the file table again to save the strings. */ | |
3f5e193b | 2801 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); |
a262ae96 NC |
2802 | |
2803 | i = 0; | |
2804 | while (*ptr_file_name_table != 0) | |
2805 | { | |
2806 | unsigned int bytes_read; | |
2807 | ||
2808 | file_table[i].name = ptr_file_name_table; | |
2809 | ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1; | |
2810 | ||
2811 | /* We are not interested in directory, time or size. */ | |
2812 | file_table[i].directory_index = read_leb128 (ptr_file_name_table, | |
2813 | & bytes_read, 0); | |
2814 | ptr_file_name_table += bytes_read; | |
2815 | file_table[i].modification_date = read_leb128 (ptr_file_name_table, | |
2816 | & bytes_read, 0); | |
2817 | ptr_file_name_table += bytes_read; | |
2818 | file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0); | |
2819 | ptr_file_name_table += bytes_read; | |
2820 | i++; | |
2821 | } | |
2822 | i = 0; | |
2823 | ||
2824 | /* Print the Compilation Unit's name and a header. */ | |
2825 | if (directory_table == NULL) | |
2826 | { | |
2827 | printf (_("CU: %s:\n"), file_table[0].name); | |
2828 | printf (_("File name Line number Starting address\n")); | |
2829 | } | |
2830 | else | |
2831 | { | |
2832 | if (do_wide || strlen ((char *) directory_table[0]) < 76) | |
cc5914eb AM |
2833 | printf (_("CU: %s/%s:\n"), directory_table[0], |
2834 | file_table[0].name); | |
a262ae96 | 2835 | else |
cc5914eb AM |
2836 | printf ("%s:\n", file_table[0].name); |
2837 | ||
a262ae96 NC |
2838 | printf (_("File name Line number Starting address\n")); |
2839 | } | |
2840 | } | |
2841 | ||
2842 | /* Skip the NUL at the end of the table. */ | |
2843 | data++; | |
2844 | ||
2845 | /* This loop iterates through the Dwarf Line Number Program. */ | |
2846 | while (data < end_of_sequence) | |
2847 | { | |
2848 | unsigned char op_code; | |
2849 | int adv; | |
2850 | unsigned long int uladv; | |
2851 | unsigned int bytes_read; | |
2852 | int is_special_opcode = 0; | |
2853 | ||
2854 | op_code = *data++; | |
a262ae96 | 2855 | |
91d6fa6a | 2856 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 2857 | { |
91d6fa6a | 2858 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
2859 | uladv = (op_code / linfo.li_line_range); |
2860 | if (linfo.li_max_ops_per_insn == 1) | |
2861 | { | |
2862 | uladv *= linfo.li_min_insn_length; | |
2863 | state_machine_regs.address += uladv; | |
2864 | } | |
2865 | else | |
2866 | { | |
2867 | state_machine_regs.address | |
2868 | += ((state_machine_regs.op_index + uladv) | |
2869 | / linfo.li_max_ops_per_insn) | |
2870 | * linfo.li_min_insn_length; | |
2871 | state_machine_regs.op_index | |
2872 | = (state_machine_regs.op_index + uladv) | |
2873 | % linfo.li_max_ops_per_insn; | |
2874 | } | |
a262ae96 | 2875 | |
91d6fa6a | 2876 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
a262ae96 NC |
2877 | state_machine_regs.line += adv; |
2878 | is_special_opcode = 1; | |
2879 | } | |
2880 | else switch (op_code) | |
2881 | { | |
2882 | case DW_LNS_extended_op: | |
2883 | { | |
2884 | unsigned int ext_op_code_len; | |
a262ae96 NC |
2885 | unsigned char ext_op_code; |
2886 | unsigned char *op_code_data = data; | |
2887 | ||
2888 | ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0); | |
2889 | op_code_data += bytes_read; | |
2890 | ||
2891 | if (ext_op_code_len == 0) | |
2892 | { | |
2893 | warn (_("badly formed extended line op encountered!\n")); | |
2894 | break; | |
2895 | } | |
2896 | ext_op_code_len += bytes_read; | |
2897 | ext_op_code = *op_code_data++; | |
2898 | ||
2899 | switch (ext_op_code) | |
2900 | { | |
2901 | case DW_LNE_end_sequence: | |
91d6fa6a | 2902 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 NC |
2903 | break; |
2904 | case DW_LNE_set_address: | |
2905 | state_machine_regs.address = | |
2906 | byte_get (op_code_data, ext_op_code_len - bytes_read - 1); | |
a233b20c | 2907 | state_machine_regs.op_index = 0; |
a262ae96 NC |
2908 | break; |
2909 | case DW_LNE_define_file: | |
2910 | { | |
2911 | unsigned int dir_index = 0; | |
2912 | ||
2913 | ++state_machine_regs.last_file_entry; | |
2914 | op_code_data += strlen ((char *) op_code_data) + 1; | |
2915 | dir_index = read_leb128 (op_code_data, & bytes_read, 0); | |
2916 | op_code_data += bytes_read; | |
2917 | read_leb128 (op_code_data, & bytes_read, 0); | |
2918 | op_code_data += bytes_read; | |
2919 | read_leb128 (op_code_data, & bytes_read, 0); | |
2920 | ||
cc5914eb | 2921 | printf ("%s:\n", directory_table[dir_index]); |
a262ae96 NC |
2922 | break; |
2923 | } | |
2924 | default: | |
2925 | printf (_("UNKNOWN: length %d\n"), ext_op_code_len - bytes_read); | |
2926 | break; | |
2927 | } | |
2928 | data += ext_op_code_len; | |
2929 | break; | |
2930 | } | |
2931 | case DW_LNS_copy: | |
2932 | break; | |
2933 | ||
2934 | case DW_LNS_advance_pc: | |
2935 | uladv = read_leb128 (data, & bytes_read, 0); | |
a262ae96 | 2936 | data += bytes_read; |
a233b20c JJ |
2937 | if (linfo.li_max_ops_per_insn == 1) |
2938 | { | |
2939 | uladv *= linfo.li_min_insn_length; | |
2940 | state_machine_regs.address += uladv; | |
2941 | } | |
2942 | else | |
2943 | { | |
2944 | state_machine_regs.address | |
2945 | += ((state_machine_regs.op_index + uladv) | |
2946 | / linfo.li_max_ops_per_insn) | |
2947 | * linfo.li_min_insn_length; | |
2948 | state_machine_regs.op_index | |
2949 | = (state_machine_regs.op_index + uladv) | |
2950 | % linfo.li_max_ops_per_insn; | |
2951 | } | |
a262ae96 NC |
2952 | break; |
2953 | ||
2954 | case DW_LNS_advance_line: | |
467c65bc | 2955 | adv = read_sleb128 (data, & bytes_read); |
a262ae96 NC |
2956 | data += bytes_read; |
2957 | state_machine_regs.line += adv; | |
2958 | break; | |
2959 | ||
2960 | case DW_LNS_set_file: | |
2961 | adv = read_leb128 (data, & bytes_read, 0); | |
2962 | data += bytes_read; | |
2963 | state_machine_regs.file = adv; | |
2964 | if (file_table[state_machine_regs.file - 1].directory_index == 0) | |
2965 | { | |
2966 | /* If directory index is 0, that means current directory. */ | |
cc5914eb | 2967 | printf ("\n./%s:[++]\n", |
a262ae96 NC |
2968 | file_table[state_machine_regs.file - 1].name); |
2969 | } | |
2970 | else | |
2971 | { | |
2972 | /* The directory index starts counting at 1. */ | |
cc5914eb | 2973 | printf ("\n%s/%s:\n", |
a262ae96 NC |
2974 | directory_table[file_table[state_machine_regs.file - 1].directory_index - 1], |
2975 | file_table[state_machine_regs.file - 1].name); | |
2976 | } | |
2977 | break; | |
2978 | ||
2979 | case DW_LNS_set_column: | |
2980 | uladv = read_leb128 (data, & bytes_read, 0); | |
2981 | data += bytes_read; | |
2982 | state_machine_regs.column = uladv; | |
2983 | break; | |
2984 | ||
2985 | case DW_LNS_negate_stmt: | |
2986 | adv = state_machine_regs.is_stmt; | |
2987 | adv = ! adv; | |
2988 | state_machine_regs.is_stmt = adv; | |
2989 | break; | |
2990 | ||
2991 | case DW_LNS_set_basic_block: | |
2992 | state_machine_regs.basic_block = 1; | |
2993 | break; | |
2994 | ||
2995 | case DW_LNS_const_add_pc: | |
a233b20c JJ |
2996 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); |
2997 | if (linfo.li_max_ops_per_insn == 1) | |
2998 | { | |
2999 | uladv *= linfo.li_min_insn_length; | |
3000 | state_machine_regs.address += uladv; | |
3001 | } | |
3002 | else | |
3003 | { | |
3004 | state_machine_regs.address | |
3005 | += ((state_machine_regs.op_index + uladv) | |
3006 | / linfo.li_max_ops_per_insn) | |
3007 | * linfo.li_min_insn_length; | |
3008 | state_machine_regs.op_index | |
3009 | = (state_machine_regs.op_index + uladv) | |
3010 | % linfo.li_max_ops_per_insn; | |
3011 | } | |
a262ae96 NC |
3012 | break; |
3013 | ||
3014 | case DW_LNS_fixed_advance_pc: | |
3015 | uladv = byte_get (data, 2); | |
3016 | data += 2; | |
3017 | state_machine_regs.address += uladv; | |
a233b20c | 3018 | state_machine_regs.op_index = 0; |
a262ae96 NC |
3019 | break; |
3020 | ||
3021 | case DW_LNS_set_prologue_end: | |
3022 | break; | |
3023 | ||
3024 | case DW_LNS_set_epilogue_begin: | |
3025 | break; | |
3026 | ||
3027 | case DW_LNS_set_isa: | |
3028 | uladv = read_leb128 (data, & bytes_read, 0); | |
3029 | data += bytes_read; | |
3030 | printf (_(" Set ISA to %lu\n"), uladv); | |
3031 | break; | |
3032 | ||
3033 | default: | |
3034 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
3035 | ||
3036 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
3037 | { | |
467c65bc NC |
3038 | printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data, |
3039 | &bytes_read, 0)), | |
a262ae96 NC |
3040 | i == 1 ? "" : ", "); |
3041 | data += bytes_read; | |
3042 | } | |
3043 | putchar ('\n'); | |
3044 | break; | |
3045 | } | |
3046 | ||
3047 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row | |
3048 | to the DWARF address/line matrix. */ | |
3049 | if ((is_special_opcode) || (op_code == DW_LNE_end_sequence) | |
3050 | || (op_code == DW_LNS_copy)) | |
3051 | { | |
3052 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
3053 | char *fileName = (char *)file_table[state_machine_regs.file - 1].name; | |
3054 | char *newFileName = NULL; | |
3055 | size_t fileNameLength = strlen (fileName); | |
3056 | ||
3057 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) | |
3058 | { | |
3f5e193b | 3059 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); |
a262ae96 NC |
3060 | /* Truncate file name */ |
3061 | strncpy (newFileName, | |
3062 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
3063 | MAX_FILENAME_LENGTH + 1); | |
3064 | } | |
3065 | else | |
3066 | { | |
3f5e193b | 3067 | newFileName = (char *) xmalloc (fileNameLength + 1); |
a262ae96 NC |
3068 | strncpy (newFileName, fileName, fileNameLength + 1); |
3069 | } | |
3070 | ||
3071 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
3072 | { | |
a233b20c | 3073 | if (linfo.li_max_ops_per_insn == 1) |
467c65bc NC |
3074 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n", |
3075 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3076 | state_machine_regs.address); |
3077 | else | |
467c65bc NC |
3078 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n", |
3079 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3080 | state_machine_regs.address, |
3081 | state_machine_regs.op_index); | |
a262ae96 NC |
3082 | } |
3083 | else | |
3084 | { | |
a233b20c | 3085 | if (linfo.li_max_ops_per_insn == 1) |
467c65bc NC |
3086 | printf ("%s %11d %#18" DWARF_VMA_FMT "x\n", |
3087 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3088 | state_machine_regs.address); |
3089 | else | |
467c65bc NC |
3090 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n", |
3091 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3092 | state_machine_regs.address, |
3093 | state_machine_regs.op_index); | |
a262ae96 NC |
3094 | } |
3095 | ||
3096 | if (op_code == DW_LNE_end_sequence) | |
3097 | printf ("\n"); | |
3098 | ||
3099 | free (newFileName); | |
3100 | } | |
3101 | } | |
3102 | free (file_table); | |
3103 | file_table = NULL; | |
3104 | free (directory_table); | |
3105 | directory_table = NULL; | |
3106 | putchar ('\n'); | |
3107 | } | |
3108 | ||
3109 | return 1; | |
3110 | } | |
3111 | ||
3112 | static int | |
1c4cc746 | 3113 | display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) |
a262ae96 NC |
3114 | { |
3115 | unsigned char *data = section->start; | |
3116 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
3117 | int retValRaw = 1; |
3118 | int retValDecoded = 1; | |
a262ae96 | 3119 | |
008f4c78 NC |
3120 | if (do_debug_lines == 0) |
3121 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
3122 | ||
4cb93e3b | 3123 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
a262ae96 NC |
3124 | retValRaw = display_debug_lines_raw (section, data, end); |
3125 | ||
4cb93e3b | 3126 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
a262ae96 NC |
3127 | retValDecoded = display_debug_lines_decoded (section, data, end); |
3128 | ||
4cb93e3b | 3129 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
3130 | return 0; |
3131 | ||
3132 | return 1; | |
3133 | } | |
3134 | ||
6e3d6dc1 NC |
3135 | static debug_info * |
3136 | find_debug_info_for_offset (unsigned long offset) | |
3137 | { | |
3138 | unsigned int i; | |
3139 | ||
3140 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
3141 | return NULL; | |
3142 | ||
3143 | for (i = 0; i < num_debug_info_entries; i++) | |
3144 | if (debug_information[i].cu_offset == offset) | |
3145 | return debug_information + i; | |
3146 | ||
3147 | return NULL; | |
3148 | } | |
3149 | ||
19e6b90e L |
3150 | static int |
3151 | display_debug_pubnames (struct dwarf_section *section, | |
3152 | void *file ATTRIBUTE_UNUSED) | |
3153 | { | |
91d6fa6a | 3154 | DWARF2_Internal_PubNames names; |
19e6b90e L |
3155 | unsigned char *start = section->start; |
3156 | unsigned char *end = start + section->size; | |
3157 | ||
6e3d6dc1 NC |
3158 | /* It does not matter if this load fails, |
3159 | we test for that later on. */ | |
3160 | load_debug_info (file); | |
3161 | ||
19e6b90e L |
3162 | printf (_("Contents of the %s section:\n\n"), section->name); |
3163 | ||
3164 | while (start < end) | |
3165 | { | |
3166 | unsigned char *data; | |
3167 | unsigned long offset; | |
3168 | int offset_size, initial_length_size; | |
3169 | ||
3170 | data = start; | |
3171 | ||
91d6fa6a | 3172 | names.pn_length = byte_get (data, 4); |
19e6b90e | 3173 | data += 4; |
91d6fa6a | 3174 | if (names.pn_length == 0xffffffff) |
19e6b90e | 3175 | { |
91d6fa6a | 3176 | names.pn_length = byte_get (data, 8); |
19e6b90e L |
3177 | data += 8; |
3178 | offset_size = 8; | |
3179 | initial_length_size = 12; | |
3180 | } | |
3181 | else | |
3182 | { | |
3183 | offset_size = 4; | |
3184 | initial_length_size = 4; | |
3185 | } | |
3186 | ||
91d6fa6a | 3187 | names.pn_version = byte_get (data, 2); |
19e6b90e | 3188 | data += 2; |
6e3d6dc1 | 3189 | |
91d6fa6a | 3190 | names.pn_offset = byte_get (data, offset_size); |
19e6b90e | 3191 | data += offset_size; |
6e3d6dc1 NC |
3192 | |
3193 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
3194 | && num_debug_info_entries > 0 | |
91d6fa6a | 3195 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 3196 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 3197 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 3198 | |
91d6fa6a | 3199 | names.pn_size = byte_get (data, offset_size); |
19e6b90e L |
3200 | data += offset_size; |
3201 | ||
91d6fa6a | 3202 | start += names.pn_length + initial_length_size; |
19e6b90e | 3203 | |
91d6fa6a | 3204 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
3205 | { |
3206 | static int warned = 0; | |
3207 | ||
3208 | if (! warned) | |
3209 | { | |
3210 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
3211 | warned = 1; | |
3212 | } | |
3213 | ||
3214 | continue; | |
3215 | } | |
3216 | ||
3217 | printf (_(" Length: %ld\n"), | |
47704ddf | 3218 | (long) names.pn_length); |
19e6b90e | 3219 | printf (_(" Version: %d\n"), |
91d6fa6a | 3220 | names.pn_version); |
6e3d6dc1 | 3221 | printf (_(" Offset into .debug_info section: 0x%lx\n"), |
47704ddf | 3222 | (unsigned long) names.pn_offset); |
19e6b90e | 3223 | printf (_(" Size of area in .debug_info section: %ld\n"), |
47704ddf | 3224 | (long) names.pn_size); |
19e6b90e L |
3225 | |
3226 | printf (_("\n Offset\tName\n")); | |
3227 | ||
3228 | do | |
3229 | { | |
3230 | offset = byte_get (data, offset_size); | |
3231 | ||
3232 | if (offset != 0) | |
3233 | { | |
3234 | data += offset_size; | |
80c35038 | 3235 | printf (" %-6lx\t%s\n", offset, data); |
19e6b90e L |
3236 | data += strlen ((char *) data) + 1; |
3237 | } | |
3238 | } | |
3239 | while (offset != 0); | |
3240 | } | |
3241 | ||
3242 | printf ("\n"); | |
3243 | return 1; | |
3244 | } | |
3245 | ||
3246 | static int | |
3247 | display_debug_macinfo (struct dwarf_section *section, | |
3248 | void *file ATTRIBUTE_UNUSED) | |
3249 | { | |
3250 | unsigned char *start = section->start; | |
3251 | unsigned char *end = start + section->size; | |
3252 | unsigned char *curr = start; | |
3253 | unsigned int bytes_read; | |
3254 | enum dwarf_macinfo_record_type op; | |
3255 | ||
3256 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3257 | ||
3258 | while (curr < end) | |
3259 | { | |
3260 | unsigned int lineno; | |
3261 | const char *string; | |
3262 | ||
3f5e193b | 3263 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
3264 | curr++; |
3265 | ||
3266 | switch (op) | |
3267 | { | |
3268 | case DW_MACINFO_start_file: | |
3269 | { | |
3270 | unsigned int filenum; | |
3271 | ||
3272 | lineno = read_leb128 (curr, & bytes_read, 0); | |
3273 | curr += bytes_read; | |
3274 | filenum = read_leb128 (curr, & bytes_read, 0); | |
3275 | curr += bytes_read; | |
3276 | ||
3277 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
3278 | lineno, filenum); | |
3279 | } | |
3280 | break; | |
3281 | ||
3282 | case DW_MACINFO_end_file: | |
3283 | printf (_(" DW_MACINFO_end_file\n")); | |
3284 | break; | |
3285 | ||
3286 | case DW_MACINFO_define: | |
3287 | lineno = read_leb128 (curr, & bytes_read, 0); | |
3288 | curr += bytes_read; | |
3289 | string = (char *) curr; | |
3290 | curr += strlen (string) + 1; | |
3291 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), | |
3292 | lineno, string); | |
3293 | break; | |
3294 | ||
3295 | case DW_MACINFO_undef: | |
3296 | lineno = read_leb128 (curr, & bytes_read, 0); | |
3297 | curr += bytes_read; | |
3298 | string = (char *) curr; | |
3299 | curr += strlen (string) + 1; | |
3300 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), | |
3301 | lineno, string); | |
3302 | break; | |
3303 | ||
3304 | case DW_MACINFO_vendor_ext: | |
3305 | { | |
3306 | unsigned int constant; | |
3307 | ||
3308 | constant = read_leb128 (curr, & bytes_read, 0); | |
3309 | curr += bytes_read; | |
3310 | string = (char *) curr; | |
3311 | curr += strlen (string) + 1; | |
3312 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), | |
3313 | constant, string); | |
3314 | } | |
3315 | break; | |
3316 | } | |
3317 | } | |
3318 | ||
3319 | return 1; | |
3320 | } | |
3321 | ||
3322 | static int | |
3323 | display_debug_abbrev (struct dwarf_section *section, | |
3324 | void *file ATTRIBUTE_UNUSED) | |
3325 | { | |
3326 | abbrev_entry *entry; | |
3327 | unsigned char *start = section->start; | |
3328 | unsigned char *end = start + section->size; | |
3329 | ||
3330 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3331 | ||
3332 | do | |
3333 | { | |
3334 | free_abbrevs (); | |
3335 | ||
3336 | start = process_abbrev_section (start, end); | |
3337 | ||
3338 | if (first_abbrev == NULL) | |
3339 | continue; | |
3340 | ||
3341 | printf (_(" Number TAG\n")); | |
3342 | ||
3343 | for (entry = first_abbrev; entry; entry = entry->next) | |
3344 | { | |
3345 | abbrev_attr *attr; | |
3346 | ||
cc5914eb | 3347 | printf (" %ld %s [%s]\n", |
19e6b90e L |
3348 | entry->entry, |
3349 | get_TAG_name (entry->tag), | |
3350 | entry->children ? _("has children") : _("no children")); | |
3351 | ||
3352 | for (attr = entry->first_attr; attr; attr = attr->next) | |
cc5914eb | 3353 | printf (" %-18s %s\n", |
19e6b90e L |
3354 | get_AT_name (attr->attribute), |
3355 | get_FORM_name (attr->form)); | |
3356 | } | |
3357 | } | |
3358 | while (start); | |
3359 | ||
3360 | printf ("\n"); | |
3361 | ||
3362 | return 1; | |
3363 | } | |
3364 | ||
3365 | static int | |
3366 | display_debug_loc (struct dwarf_section *section, void *file) | |
3367 | { | |
3368 | unsigned char *start = section->start; | |
3369 | unsigned char *section_end; | |
3370 | unsigned long bytes; | |
3371 | unsigned char *section_begin = start; | |
3372 | unsigned int num_loc_list = 0; | |
3373 | unsigned long last_offset = 0; | |
3374 | unsigned int first = 0; | |
3375 | unsigned int i; | |
3376 | unsigned int j; | |
3377 | int seen_first_offset = 0; | |
3378 | int use_debug_info = 1; | |
3379 | unsigned char *next; | |
3380 | ||
3381 | bytes = section->size; | |
3382 | section_end = start + bytes; | |
3383 | ||
3384 | if (bytes == 0) | |
3385 | { | |
3386 | printf (_("\nThe %s section is empty.\n"), section->name); | |
3387 | return 0; | |
3388 | } | |
3389 | ||
1febe64d NC |
3390 | if (load_debug_info (file) == 0) |
3391 | { | |
3392 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
3393 | section->name); | |
3394 | return 0; | |
3395 | } | |
19e6b90e L |
3396 | |
3397 | /* Check the order of location list in .debug_info section. If | |
3398 | offsets of location lists are in the ascending order, we can | |
3399 | use `debug_information' directly. */ | |
3400 | for (i = 0; i < num_debug_info_entries; i++) | |
3401 | { | |
3402 | unsigned int num; | |
3403 | ||
3404 | num = debug_information [i].num_loc_offsets; | |
3405 | num_loc_list += num; | |
3406 | ||
3407 | /* Check if we can use `debug_information' directly. */ | |
3408 | if (use_debug_info && num != 0) | |
3409 | { | |
3410 | if (!seen_first_offset) | |
3411 | { | |
3412 | /* This is the first location list. */ | |
3413 | last_offset = debug_information [i].loc_offsets [0]; | |
3414 | first = i; | |
3415 | seen_first_offset = 1; | |
3416 | j = 1; | |
3417 | } | |
3418 | else | |
3419 | j = 0; | |
3420 | ||
3421 | for (; j < num; j++) | |
3422 | { | |
3423 | if (last_offset > | |
3424 | debug_information [i].loc_offsets [j]) | |
3425 | { | |
3426 | use_debug_info = 0; | |
3427 | break; | |
3428 | } | |
3429 | last_offset = debug_information [i].loc_offsets [j]; | |
3430 | } | |
3431 | } | |
3432 | } | |
3433 | ||
3434 | if (!use_debug_info) | |
3435 | /* FIXME: Should we handle this case? */ | |
3436 | error (_("Location lists in .debug_info section aren't in ascending order!\n")); | |
3437 | ||
3438 | if (!seen_first_offset) | |
3439 | error (_("No location lists in .debug_info section!\n")); | |
3440 | ||
bfe2612a | 3441 | /* DWARF sections under Mach-O have non-zero addresses. */ |
d4bfc77b AS |
3442 | if (debug_information [first].num_loc_offsets > 0 |
3443 | && debug_information [first].loc_offsets [0] != section->address) | |
47704ddf KT |
3444 | warn (_("Location lists in %s section start at 0x%s\n"), |
3445 | section->name, | |
3446 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e L |
3447 | |
3448 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3449 | printf (_(" Offset Begin End Expression\n")); | |
3450 | ||
3451 | seen_first_offset = 0; | |
3452 | for (i = first; i < num_debug_info_entries; i++) | |
3453 | { | |
2d9472a2 NC |
3454 | dwarf_vma begin; |
3455 | dwarf_vma end; | |
19e6b90e L |
3456 | unsigned short length; |
3457 | unsigned long offset; | |
3458 | unsigned int pointer_size; | |
b7807392 JJ |
3459 | unsigned int offset_size; |
3460 | int dwarf_version; | |
19e6b90e L |
3461 | unsigned long cu_offset; |
3462 | unsigned long base_address; | |
3463 | int need_frame_base; | |
3464 | int has_frame_base; | |
3465 | ||
3466 | pointer_size = debug_information [i].pointer_size; | |
3467 | cu_offset = debug_information [i].cu_offset; | |
b7807392 JJ |
3468 | offset_size = debug_information [i].offset_size; |
3469 | dwarf_version = debug_information [i].dwarf_version; | |
19e6b90e L |
3470 | |
3471 | for (j = 0; j < debug_information [i].num_loc_offsets; j++) | |
3472 | { | |
3473 | has_frame_base = debug_information [i].have_frame_base [j]; | |
bfe2612a | 3474 | /* DWARF sections under Mach-O have non-zero addresses. */ |
cecf136e | 3475 | offset = debug_information [i].loc_offsets [j] - section->address; |
19e6b90e L |
3476 | next = section_begin + offset; |
3477 | base_address = debug_information [i].base_address; | |
3478 | ||
3479 | if (!seen_first_offset) | |
3480 | seen_first_offset = 1; | |
3481 | else | |
3482 | { | |
3483 | if (start < next) | |
3484 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e AM |
3485 | (unsigned long) (start - section_begin), |
3486 | (unsigned long) (next - section_begin)); | |
19e6b90e L |
3487 | else if (start > next) |
3488 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e AM |
3489 | (unsigned long) (start - section_begin), |
3490 | (unsigned long) (next - section_begin)); | |
19e6b90e L |
3491 | } |
3492 | start = next; | |
3493 | ||
3494 | if (offset >= bytes) | |
3495 | { | |
3496 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
3497 | offset); | |
3498 | continue; | |
3499 | } | |
3500 | ||
3501 | while (1) | |
3502 | { | |
3503 | if (start + 2 * pointer_size > section_end) | |
3504 | { | |
3505 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
3506 | offset); | |
3507 | break; | |
3508 | } | |
3509 | ||
2d9472a2 NC |
3510 | /* Note: we use sign extension here in order to be sure that |
3511 | we can detect the -1 escape value. Sign extension into the | |
3512 | top 32 bits of a 32-bit address will not affect the values | |
3513 | that we display since we always show hex values, and always | |
cecf136e | 3514 | the bottom 32-bits. */ |
2d9472a2 | 3515 | begin = byte_get_signed (start, pointer_size); |
19e6b90e | 3516 | start += pointer_size; |
2d9472a2 | 3517 | end = byte_get_signed (start, pointer_size); |
19e6b90e L |
3518 | start += pointer_size; |
3519 | ||
2d9472a2 NC |
3520 | printf (" %8.8lx ", offset); |
3521 | ||
19e6b90e L |
3522 | if (begin == 0 && end == 0) |
3523 | { | |
2d9472a2 | 3524 | printf (_("<End of list>\n")); |
19e6b90e L |
3525 | break; |
3526 | } | |
3527 | ||
3528 | /* Check base address specifiers. */ | |
2d9472a2 | 3529 | if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1) |
19e6b90e L |
3530 | { |
3531 | base_address = end; | |
2d9472a2 NC |
3532 | print_dwarf_vma (begin, pointer_size); |
3533 | print_dwarf_vma (end, pointer_size); | |
3534 | printf (_("(base address)\n")); | |
19e6b90e L |
3535 | continue; |
3536 | } | |
3537 | ||
3538 | if (start + 2 > section_end) | |
3539 | { | |
3540 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
3541 | offset); | |
3542 | break; | |
3543 | } | |
3544 | ||
3545 | length = byte_get (start, 2); | |
3546 | start += 2; | |
3547 | ||
3548 | if (start + length > section_end) | |
3549 | { | |
3550 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
3551 | offset); | |
3552 | break; | |
3553 | } | |
3554 | ||
2d9472a2 NC |
3555 | print_dwarf_vma (begin + base_address, pointer_size); |
3556 | print_dwarf_vma (end + base_address, pointer_size); | |
3557 | ||
3558 | putchar ('('); | |
19e6b90e L |
3559 | need_frame_base = decode_location_expression (start, |
3560 | pointer_size, | |
b7807392 JJ |
3561 | offset_size, |
3562 | dwarf_version, | |
19e6b90e | 3563 | length, |
f1c4cc75 | 3564 | cu_offset, section); |
19e6b90e L |
3565 | putchar (')'); |
3566 | ||
3567 | if (need_frame_base && !has_frame_base) | |
3568 | printf (_(" [without DW_AT_frame_base]")); | |
3569 | ||
3570 | if (begin == end) | |
3571 | fputs (_(" (start == end)"), stdout); | |
3572 | else if (begin > end) | |
3573 | fputs (_(" (start > end)"), stdout); | |
3574 | ||
3575 | putchar ('\n'); | |
3576 | ||
3577 | start += length; | |
3578 | } | |
3579 | } | |
3580 | } | |
031cd65f NC |
3581 | |
3582 | if (start < section_end) | |
3583 | warn (_("There are %ld unused bytes at the end of section %s\n"), | |
0eb090cb | 3584 | (long) (section_end - start), section->name); |
98fb390a | 3585 | putchar ('\n'); |
19e6b90e L |
3586 | return 1; |
3587 | } | |
3588 | ||
3589 | static int | |
3590 | display_debug_str (struct dwarf_section *section, | |
3591 | void *file ATTRIBUTE_UNUSED) | |
3592 | { | |
3593 | unsigned char *start = section->start; | |
3594 | unsigned long bytes = section->size; | |
3595 | dwarf_vma addr = section->address; | |
3596 | ||
3597 | if (bytes == 0) | |
3598 | { | |
3599 | printf (_("\nThe %s section is empty.\n"), section->name); | |
3600 | return 0; | |
3601 | } | |
3602 | ||
3603 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3604 | ||
3605 | while (bytes) | |
3606 | { | |
3607 | int j; | |
3608 | int k; | |
3609 | int lbytes; | |
3610 | ||
3611 | lbytes = (bytes > 16 ? 16 : bytes); | |
3612 | ||
3613 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
3614 | ||
3615 | for (j = 0; j < 16; j++) | |
3616 | { | |
3617 | if (j < lbytes) | |
3618 | printf ("%2.2x", start[j]); | |
3619 | else | |
3620 | printf (" "); | |
3621 | ||
3622 | if ((j & 3) == 3) | |
3623 | printf (" "); | |
3624 | } | |
3625 | ||
3626 | for (j = 0; j < lbytes; j++) | |
3627 | { | |
3628 | k = start[j]; | |
3629 | if (k >= ' ' && k < 0x80) | |
3630 | printf ("%c", k); | |
3631 | else | |
3632 | printf ("."); | |
3633 | } | |
3634 | ||
3635 | putchar ('\n'); | |
3636 | ||
3637 | start += lbytes; | |
3638 | addr += lbytes; | |
3639 | bytes -= lbytes; | |
3640 | } | |
3641 | ||
3642 | putchar ('\n'); | |
3643 | ||
3644 | return 1; | |
3645 | } | |
3646 | ||
19e6b90e L |
3647 | static int |
3648 | display_debug_info (struct dwarf_section *section, void *file) | |
3649 | { | |
6f875884 | 3650 | return process_debug_info (section, file, abbrev, 0, 0); |
19e6b90e L |
3651 | } |
3652 | ||
2b6f5997 CC |
3653 | static int |
3654 | display_debug_types (struct dwarf_section *section, void *file) | |
3655 | { | |
6f875884 TG |
3656 | return process_debug_info (section, file, abbrev, 0, 1); |
3657 | } | |
3658 | ||
3659 | static int | |
3660 | display_trace_info (struct dwarf_section *section, void *file) | |
3661 | { | |
3662 | return process_debug_info (section, file, trace_abbrev, 0, 0); | |
2b6f5997 | 3663 | } |
19e6b90e L |
3664 | |
3665 | static int | |
3666 | display_debug_aranges (struct dwarf_section *section, | |
3667 | void *file ATTRIBUTE_UNUSED) | |
3668 | { | |
3669 | unsigned char *start = section->start; | |
3670 | unsigned char *end = start + section->size; | |
3671 | ||
80c35038 | 3672 | printf (_("Contents of the %s section:\n\n"), section->name); |
19e6b90e | 3673 | |
6e3d6dc1 NC |
3674 | /* It does not matter if this load fails, |
3675 | we test for that later on. */ | |
3676 | load_debug_info (file); | |
3677 | ||
19e6b90e L |
3678 | while (start < end) |
3679 | { | |
3680 | unsigned char *hdrptr; | |
3681 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 3682 | unsigned char *addr_ranges; |
2d9472a2 NC |
3683 | dwarf_vma length; |
3684 | dwarf_vma address; | |
53b8873b | 3685 | unsigned char address_size; |
19e6b90e L |
3686 | int excess; |
3687 | int offset_size; | |
3688 | int initial_length_size; | |
3689 | ||
3690 | hdrptr = start; | |
3691 | ||
3692 | arange.ar_length = byte_get (hdrptr, 4); | |
3693 | hdrptr += 4; | |
3694 | ||
3695 | if (arange.ar_length == 0xffffffff) | |
3696 | { | |
3697 | arange.ar_length = byte_get (hdrptr, 8); | |
3698 | hdrptr += 8; | |
3699 | offset_size = 8; | |
3700 | initial_length_size = 12; | |
3701 | } | |
3702 | else | |
3703 | { | |
3704 | offset_size = 4; | |
3705 | initial_length_size = 4; | |
3706 | } | |
3707 | ||
3708 | arange.ar_version = byte_get (hdrptr, 2); | |
3709 | hdrptr += 2; | |
3710 | ||
3711 | arange.ar_info_offset = byte_get (hdrptr, offset_size); | |
3712 | hdrptr += offset_size; | |
3713 | ||
6e3d6dc1 NC |
3714 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
3715 | && num_debug_info_entries > 0 | |
3716 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
3717 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 3718 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 3719 | |
19e6b90e L |
3720 | arange.ar_pointer_size = byte_get (hdrptr, 1); |
3721 | hdrptr += 1; | |
3722 | ||
3723 | arange.ar_segment_size = byte_get (hdrptr, 1); | |
3724 | hdrptr += 1; | |
3725 | ||
3726 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
3727 | { | |
3728 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
3729 | break; | |
3730 | } | |
3731 | ||
47704ddf KT |
3732 | printf (_(" Length: %ld\n"), |
3733 | (long) arange.ar_length); | |
19e6b90e | 3734 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
3735 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
3736 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
3737 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
3738 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
3739 | ||
53b8873b NC |
3740 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
3741 | ||
3742 | /* The DWARF spec does not require that the address size be a power | |
3743 | of two, but we do. This will have to change if we ever encounter | |
3744 | an uneven architecture. */ | |
3745 | if ((address_size & (address_size - 1)) != 0) | |
3746 | { | |
3747 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
3748 | break; | |
3749 | } | |
cecf136e | 3750 | |
209c9a13 NC |
3751 | if (address_size > 4) |
3752 | printf (_("\n Address Length\n")); | |
3753 | else | |
3754 | printf (_("\n Address Length\n")); | |
19e6b90e | 3755 | |
91d6fa6a | 3756 | addr_ranges = hdrptr; |
19e6b90e | 3757 | |
53b8873b NC |
3758 | /* Must pad to an alignment boundary that is twice the address size. */ |
3759 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 3760 | if (excess) |
91d6fa6a | 3761 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 3762 | |
1617e571 AM |
3763 | start += arange.ar_length + initial_length_size; |
3764 | ||
91d6fa6a | 3765 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 3766 | { |
91d6fa6a | 3767 | address = byte_get (addr_ranges, address_size); |
19e6b90e | 3768 | |
91d6fa6a | 3769 | addr_ranges += address_size; |
19e6b90e | 3770 | |
91d6fa6a | 3771 | length = byte_get (addr_ranges, address_size); |
19e6b90e | 3772 | |
91d6fa6a | 3773 | addr_ranges += address_size; |
19e6b90e | 3774 | |
80c35038 | 3775 | printf (" "); |
2d9472a2 NC |
3776 | print_dwarf_vma (address, address_size); |
3777 | print_dwarf_vma (length, address_size); | |
3778 | putchar ('\n'); | |
19e6b90e | 3779 | } |
19e6b90e L |
3780 | } |
3781 | ||
3782 | printf ("\n"); | |
3783 | ||
3784 | return 1; | |
3785 | } | |
3786 | ||
01a8f077 JK |
3787 | /* Each debug_information[x].range_lists[y] gets this representation for |
3788 | sorting purposes. */ | |
3789 | ||
3790 | struct range_entry | |
467c65bc NC |
3791 | { |
3792 | /* The debug_information[x].range_lists[y] value. */ | |
3793 | unsigned long ranges_offset; | |
01a8f077 | 3794 | |
467c65bc NC |
3795 | /* Original debug_information to find parameters of the data. */ |
3796 | debug_info *debug_info_p; | |
3797 | }; | |
01a8f077 JK |
3798 | |
3799 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
3800 | ||
3801 | static int | |
3802 | range_entry_compar (const void *ap, const void *bp) | |
3803 | { | |
3f5e193b NC |
3804 | const struct range_entry *a_re = (const struct range_entry *) ap; |
3805 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
01a8f077 JK |
3806 | const unsigned long a = a_re->ranges_offset; |
3807 | const unsigned long b = b_re->ranges_offset; | |
3808 | ||
3809 | return (a > b) - (b > a); | |
3810 | } | |
3811 | ||
19e6b90e L |
3812 | static int |
3813 | display_debug_ranges (struct dwarf_section *section, | |
3814 | void *file ATTRIBUTE_UNUSED) | |
3815 | { | |
3816 | unsigned char *start = section->start; | |
19e6b90e L |
3817 | unsigned long bytes; |
3818 | unsigned char *section_begin = start; | |
01a8f077 JK |
3819 | unsigned int num_range_list, i; |
3820 | struct range_entry *range_entries, *range_entry_fill; | |
19e6b90e L |
3821 | |
3822 | bytes = section->size; | |
19e6b90e L |
3823 | |
3824 | if (bytes == 0) | |
3825 | { | |
3826 | printf (_("\nThe %s section is empty.\n"), section->name); | |
3827 | return 0; | |
3828 | } | |
3829 | ||
1febe64d NC |
3830 | if (load_debug_info (file) == 0) |
3831 | { | |
3832 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
3833 | section->name); | |
3834 | return 0; | |
3835 | } | |
19e6b90e | 3836 | |
01a8f077 | 3837 | num_range_list = 0; |
19e6b90e | 3838 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 3839 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 3840 | |
01a8f077 JK |
3841 | if (num_range_list == 0) |
3842 | error (_("No range lists in .debug_info section!\n")); | |
19e6b90e | 3843 | |
3f5e193b NC |
3844 | range_entries = (struct range_entry *) |
3845 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 3846 | range_entry_fill = range_entries; |
19e6b90e | 3847 | |
01a8f077 JK |
3848 | for (i = 0; i < num_debug_info_entries; i++) |
3849 | { | |
3850 | debug_info *debug_info_p = &debug_information[i]; | |
3851 | unsigned int j; | |
3852 | ||
3853 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
3854 | { | |
3855 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
3856 | range_entry_fill->debug_info_p = debug_info_p; | |
3857 | range_entry_fill++; | |
19e6b90e L |
3858 | } |
3859 | } | |
3860 | ||
01a8f077 JK |
3861 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
3862 | range_entry_compar); | |
19e6b90e | 3863 | |
bfe2612a | 3864 | /* DWARF sections under Mach-O have non-zero addresses. */ |
01a8f077 | 3865 | if (range_entries[0].ranges_offset != section->address) |
19e6b90e | 3866 | warn (_("Range lists in %s section start at 0x%lx\n"), |
01a8f077 | 3867 | section->name, range_entries[0].ranges_offset); |
19e6b90e L |
3868 | |
3869 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3870 | printf (_(" Offset Begin End\n")); | |
3871 | ||
01a8f077 | 3872 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 3873 | { |
01a8f077 JK |
3874 | struct range_entry *range_entry = &range_entries[i]; |
3875 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 3876 | unsigned int pointer_size; |
01a8f077 JK |
3877 | unsigned long offset; |
3878 | unsigned char *next; | |
19e6b90e L |
3879 | unsigned long base_address; |
3880 | ||
01a8f077 JK |
3881 | pointer_size = debug_info_p->pointer_size; |
3882 | ||
3883 | /* DWARF sections under Mach-O have non-zero addresses. */ | |
3884 | offset = range_entry->ranges_offset - section->address; | |
3885 | next = section_begin + offset; | |
3886 | base_address = debug_info_p->base_address; | |
cecf136e | 3887 | |
01a8f077 | 3888 | if (i > 0) |
19e6b90e | 3889 | { |
01a8f077 JK |
3890 | if (start < next) |
3891 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
3892 | (unsigned long) (start - section_begin), | |
3893 | (unsigned long) (next - section_begin), section->name); | |
3894 | else if (start > next) | |
3895 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
3896 | (unsigned long) (start - section_begin), | |
3897 | (unsigned long) (next - section_begin), section->name); | |
3898 | } | |
3899 | start = next; | |
19e6b90e | 3900 | |
01a8f077 JK |
3901 | while (1) |
3902 | { | |
3903 | dwarf_vma begin; | |
3904 | dwarf_vma end; | |
3905 | ||
3906 | /* Note: we use sign extension here in order to be sure that | |
3907 | we can detect the -1 escape value. Sign extension into the | |
3908 | top 32 bits of a 32-bit address will not affect the values | |
3909 | that we display since we always show hex values, and always | |
3910 | the bottom 32-bits. */ | |
3911 | begin = byte_get_signed (start, pointer_size); | |
3912 | start += pointer_size; | |
3913 | end = byte_get_signed (start, pointer_size); | |
3914 | start += pointer_size; | |
3915 | ||
3916 | printf (" %8.8lx ", offset); | |
3917 | ||
3918 | if (begin == 0 && end == 0) | |
19e6b90e | 3919 | { |
01a8f077 JK |
3920 | printf (_("<End of list>\n")); |
3921 | break; | |
19e6b90e | 3922 | } |
19e6b90e | 3923 | |
01a8f077 JK |
3924 | /* Check base address specifiers. */ |
3925 | if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1) | |
19e6b90e | 3926 | { |
01a8f077 JK |
3927 | base_address = end; |
3928 | print_dwarf_vma (begin, pointer_size); | |
3929 | print_dwarf_vma (end, pointer_size); | |
3930 | printf ("(base address)\n"); | |
3931 | continue; | |
3932 | } | |
19e6b90e | 3933 | |
01a8f077 JK |
3934 | print_dwarf_vma (begin + base_address, pointer_size); |
3935 | print_dwarf_vma (end + base_address, pointer_size); | |
4a149252 | 3936 | |
01a8f077 JK |
3937 | if (begin == end) |
3938 | fputs (_("(start == end)"), stdout); | |
3939 | else if (begin > end) | |
3940 | fputs (_("(start > end)"), stdout); | |
19e6b90e | 3941 | |
01a8f077 | 3942 | putchar ('\n'); |
19e6b90e L |
3943 | } |
3944 | } | |
3945 | putchar ('\n'); | |
01a8f077 JK |
3946 | |
3947 | free (range_entries); | |
3948 | ||
19e6b90e L |
3949 | return 1; |
3950 | } | |
3951 | ||
3952 | typedef struct Frame_Chunk | |
3953 | { | |
3954 | struct Frame_Chunk *next; | |
3955 | unsigned char *chunk_start; | |
3956 | int ncols; | |
3957 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ | |
3958 | short int *col_type; | |
3959 | int *col_offset; | |
3960 | char *augmentation; | |
3961 | unsigned int code_factor; | |
3962 | int data_factor; | |
3963 | unsigned long pc_begin; | |
3964 | unsigned long pc_range; | |
3965 | int cfa_reg; | |
3966 | int cfa_offset; | |
3967 | int ra; | |
3968 | unsigned char fde_encoding; | |
3969 | unsigned char cfa_exp; | |
604282a7 JJ |
3970 | unsigned char ptr_size; |
3971 | unsigned char segment_size; | |
19e6b90e L |
3972 | } |
3973 | Frame_Chunk; | |
3974 | ||
665ce1f6 L |
3975 | static const char *const *dwarf_regnames; |
3976 | static unsigned int dwarf_regnames_count; | |
3977 | ||
19e6b90e L |
3978 | /* A marker for a col_type that means this column was never referenced |
3979 | in the frame info. */ | |
3980 | #define DW_CFA_unreferenced (-1) | |
3981 | ||
665ce1f6 L |
3982 | /* Return 0 if not more space is needed, 1 if more space is needed, |
3983 | -1 for invalid reg. */ | |
3984 | ||
3985 | static int | |
3986 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e L |
3987 | { |
3988 | int prev = fc->ncols; | |
3989 | ||
665ce1f6 L |
3990 | if (reg < (unsigned int) fc->ncols) |
3991 | return 0; | |
3992 | ||
3993 | if (dwarf_regnames_count | |
3994 | && reg > dwarf_regnames_count) | |
3995 | return -1; | |
19e6b90e L |
3996 | |
3997 | fc->ncols = reg + 1; | |
3f5e193b NC |
3998 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
3999 | sizeof (short int)); | |
4000 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); | |
19e6b90e L |
4001 | |
4002 | while (prev < fc->ncols) | |
4003 | { | |
4004 | fc->col_type[prev] = DW_CFA_unreferenced; | |
4005 | fc->col_offset[prev] = 0; | |
4006 | prev++; | |
4007 | } | |
665ce1f6 | 4008 | return 1; |
19e6b90e L |
4009 | } |
4010 | ||
2dc4cec1 L |
4011 | static const char *const dwarf_regnames_i386[] = |
4012 | { | |
4013 | "eax", "ecx", "edx", "ebx", | |
4014 | "esp", "ebp", "esi", "edi", | |
4015 | "eip", "eflags", NULL, | |
4016 | "st0", "st1", "st2", "st3", | |
4017 | "st4", "st5", "st6", "st7", | |
4018 | NULL, NULL, | |
4019 | "xmm0", "xmm1", "xmm2", "xmm3", | |
4020 | "xmm4", "xmm5", "xmm6", "xmm7", | |
4021 | "mm0", "mm1", "mm2", "mm3", | |
4022 | "mm4", "mm5", "mm6", "mm7", | |
4023 | "fcw", "fsw", "mxcsr", | |
4024 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
a656ed5b | 4025 | "tr", "ldtr" |
2dc4cec1 L |
4026 | }; |
4027 | ||
b129eb0e RH |
4028 | void |
4029 | init_dwarf_regnames_i386 (void) | |
4030 | { | |
4031 | dwarf_regnames = dwarf_regnames_i386; | |
4032 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
4033 | } | |
4034 | ||
2dc4cec1 L |
4035 | static const char *const dwarf_regnames_x86_64[] = |
4036 | { | |
4037 | "rax", "rdx", "rcx", "rbx", | |
4038 | "rsi", "rdi", "rbp", "rsp", | |
4039 | "r8", "r9", "r10", "r11", | |
4040 | "r12", "r13", "r14", "r15", | |
4041 | "rip", | |
4042 | "xmm0", "xmm1", "xmm2", "xmm3", | |
4043 | "xmm4", "xmm5", "xmm6", "xmm7", | |
4044 | "xmm8", "xmm9", "xmm10", "xmm11", | |
4045 | "xmm12", "xmm13", "xmm14", "xmm15", | |
4046 | "st0", "st1", "st2", "st3", | |
4047 | "st4", "st5", "st6", "st7", | |
4048 | "mm0", "mm1", "mm2", "mm3", | |
4049 | "mm4", "mm5", "mm6", "mm7", | |
4050 | "rflags", | |
4051 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
4052 | "fs.base", "gs.base", NULL, NULL, | |
4053 | "tr", "ldtr", | |
a656ed5b | 4054 | "mxcsr", "fcw", "fsw" |
2dc4cec1 L |
4055 | }; |
4056 | ||
b129eb0e RH |
4057 | void |
4058 | init_dwarf_regnames_x86_64 (void) | |
4059 | { | |
4060 | dwarf_regnames = dwarf_regnames_x86_64; | |
4061 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
4062 | } | |
4063 | ||
2dc4cec1 L |
4064 | void |
4065 | init_dwarf_regnames (unsigned int e_machine) | |
4066 | { | |
4067 | switch (e_machine) | |
4068 | { | |
4069 | case EM_386: | |
4070 | case EM_486: | |
b129eb0e | 4071 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
4072 | break; |
4073 | ||
4074 | case EM_X86_64: | |
7f502d6c | 4075 | case EM_L1OM: |
b129eb0e | 4076 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
4077 | break; |
4078 | ||
4079 | default: | |
4080 | break; | |
4081 | } | |
4082 | } | |
4083 | ||
4084 | static const char * | |
4085 | regname (unsigned int regno, int row) | |
4086 | { | |
4087 | static char reg[64]; | |
4088 | if (dwarf_regnames | |
4089 | && regno < dwarf_regnames_count | |
4090 | && dwarf_regnames [regno] != NULL) | |
4091 | { | |
4092 | if (row) | |
4093 | return dwarf_regnames [regno]; | |
4094 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, | |
4095 | dwarf_regnames [regno]); | |
4096 | } | |
4097 | else | |
4098 | snprintf (reg, sizeof (reg), "r%d", regno); | |
4099 | return reg; | |
4100 | } | |
4101 | ||
19e6b90e L |
4102 | static void |
4103 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs) | |
4104 | { | |
4105 | int r; | |
4106 | char tmp[100]; | |
4107 | ||
4108 | if (*max_regs < fc->ncols) | |
4109 | *max_regs = fc->ncols; | |
4110 | ||
4111 | if (*need_col_headers) | |
4112 | { | |
91d6fa6a | 4113 | static const char *sloc = " LOC"; |
2dc4cec1 | 4114 | |
19e6b90e L |
4115 | *need_col_headers = 0; |
4116 | ||
91d6fa6a | 4117 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
4118 | |
4119 | for (r = 0; r < *max_regs; r++) | |
4120 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
4121 | { | |
4122 | if (r == fc->ra) | |
2dc4cec1 | 4123 | printf ("ra "); |
19e6b90e | 4124 | else |
2dc4cec1 | 4125 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
4126 | } |
4127 | ||
4128 | printf ("\n"); | |
4129 | } | |
4130 | ||
2dc4cec1 | 4131 | printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin); |
19e6b90e L |
4132 | if (fc->cfa_exp) |
4133 | strcpy (tmp, "exp"); | |
4134 | else | |
2dc4cec1 | 4135 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset); |
19e6b90e L |
4136 | printf ("%-8s ", tmp); |
4137 | ||
4138 | for (r = 0; r < fc->ncols; r++) | |
4139 | { | |
4140 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
4141 | { | |
4142 | switch (fc->col_type[r]) | |
4143 | { | |
4144 | case DW_CFA_undefined: | |
4145 | strcpy (tmp, "u"); | |
4146 | break; | |
4147 | case DW_CFA_same_value: | |
4148 | strcpy (tmp, "s"); | |
4149 | break; | |
4150 | case DW_CFA_offset: | |
4151 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
4152 | break; | |
12eae2d3 JJ |
4153 | case DW_CFA_val_offset: |
4154 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
4155 | break; | |
19e6b90e | 4156 | case DW_CFA_register: |
2dc4cec1 | 4157 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
4158 | break; |
4159 | case DW_CFA_expression: | |
4160 | strcpy (tmp, "exp"); | |
4161 | break; | |
12eae2d3 JJ |
4162 | case DW_CFA_val_expression: |
4163 | strcpy (tmp, "vexp"); | |
4164 | break; | |
19e6b90e L |
4165 | default: |
4166 | strcpy (tmp, "n/a"); | |
4167 | break; | |
4168 | } | |
2dc4cec1 | 4169 | printf ("%-5s ", tmp); |
19e6b90e L |
4170 | } |
4171 | } | |
4172 | printf ("\n"); | |
4173 | } | |
4174 | ||
19e6b90e L |
4175 | #define GET(N) byte_get (start, N); start += N |
4176 | #define LEB() read_leb128 (start, & length_return, 0); start += length_return | |
467c65bc | 4177 | #define SLEB() read_sleb128 (start, & length_return); start += length_return |
19e6b90e L |
4178 | |
4179 | static int | |
4180 | display_debug_frames (struct dwarf_section *section, | |
4181 | void *file ATTRIBUTE_UNUSED) | |
4182 | { | |
4183 | unsigned char *start = section->start; | |
4184 | unsigned char *end = start + section->size; | |
4185 | unsigned char *section_start = start; | |
4186 | Frame_Chunk *chunks = 0; | |
4187 | Frame_Chunk *remembered_state = 0; | |
4188 | Frame_Chunk *rs; | |
4189 | int is_eh = strcmp (section->name, ".eh_frame") == 0; | |
4190 | unsigned int length_return; | |
4191 | int max_regs = 0; | |
665ce1f6 | 4192 | const char *bad_reg = _("bad register: "); |
604282a7 | 4193 | int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 4194 | |
80c35038 | 4195 | printf (_("Contents of the %s section:\n"), section->name); |
19e6b90e L |
4196 | |
4197 | while (start < end) | |
4198 | { | |
4199 | unsigned char *saved_start; | |
4200 | unsigned char *block_end; | |
4201 | unsigned long length; | |
4202 | unsigned long cie_id; | |
4203 | Frame_Chunk *fc; | |
4204 | Frame_Chunk *cie; | |
4205 | int need_col_headers = 1; | |
4206 | unsigned char *augmentation_data = NULL; | |
4207 | unsigned long augmentation_data_len = 0; | |
604282a7 | 4208 | int encoded_ptr_size = saved_eh_addr_size; |
19e6b90e L |
4209 | int offset_size; |
4210 | int initial_length_size; | |
4211 | ||
4212 | saved_start = start; | |
4213 | length = byte_get (start, 4); start += 4; | |
4214 | ||
4215 | if (length == 0) | |
4216 | { | |
4217 | printf ("\n%08lx ZERO terminator\n\n", | |
4218 | (unsigned long)(saved_start - section_start)); | |
b758e50f | 4219 | continue; |
19e6b90e L |
4220 | } |
4221 | ||
4222 | if (length == 0xffffffff) | |
4223 | { | |
4224 | length = byte_get (start, 8); | |
4225 | start += 8; | |
4226 | offset_size = 8; | |
4227 | initial_length_size = 12; | |
4228 | } | |
4229 | else | |
4230 | { | |
4231 | offset_size = 4; | |
4232 | initial_length_size = 4; | |
4233 | } | |
4234 | ||
4235 | block_end = saved_start + length + initial_length_size; | |
53b8873b NC |
4236 | if (block_end > end) |
4237 | { | |
4238 | warn ("Invalid length %#08lx in FDE at %#08lx\n", | |
4239 | length, (unsigned long)(saved_start - section_start)); | |
4240 | block_end = end; | |
4241 | } | |
19e6b90e L |
4242 | cie_id = byte_get (start, offset_size); start += offset_size; |
4243 | ||
4244 | if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID)) | |
4245 | { | |
4246 | int version; | |
4247 | ||
3f5e193b | 4248 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
19e6b90e L |
4249 | memset (fc, 0, sizeof (Frame_Chunk)); |
4250 | ||
4251 | fc->next = chunks; | |
4252 | chunks = fc; | |
4253 | fc->chunk_start = saved_start; | |
4254 | fc->ncols = 0; | |
3f5e193b NC |
4255 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
4256 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
cc86f28f | 4257 | frame_need_space (fc, max_regs - 1); |
19e6b90e L |
4258 | |
4259 | version = *start++; | |
4260 | ||
4261 | fc->augmentation = (char *) start; | |
4262 | start = (unsigned char *) strchr ((char *) start, '\0') + 1; | |
4263 | ||
604282a7 JJ |
4264 | if (strcmp (fc->augmentation, "eh") == 0) |
4265 | start += eh_addr_size; | |
4266 | ||
4267 | if (version >= 4) | |
19e6b90e | 4268 | { |
604282a7 JJ |
4269 | fc->ptr_size = GET (1); |
4270 | fc->segment_size = GET (1); | |
4271 | eh_addr_size = fc->ptr_size; | |
19e6b90e | 4272 | } |
604282a7 | 4273 | else |
19e6b90e | 4274 | { |
604282a7 JJ |
4275 | fc->ptr_size = eh_addr_size; |
4276 | fc->segment_size = 0; | |
4277 | } | |
4278 | fc->code_factor = LEB (); | |
4279 | fc->data_factor = SLEB (); | |
4280 | if (version == 1) | |
4281 | { | |
4282 | fc->ra = GET (1); | |
19e6b90e L |
4283 | } |
4284 | else | |
4285 | { | |
604282a7 JJ |
4286 | fc->ra = LEB (); |
4287 | } | |
4288 | ||
4289 | if (fc->augmentation[0] == 'z') | |
4290 | { | |
4291 | augmentation_data_len = LEB (); | |
4292 | augmentation_data = start; | |
4293 | start += augmentation_data_len; | |
19e6b90e L |
4294 | } |
4295 | cie = fc; | |
4296 | ||
4297 | if (do_debug_frames_interp) | |
4298 | printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n", | |
4299 | (unsigned long)(saved_start - section_start), length, cie_id, | |
4300 | fc->augmentation, fc->code_factor, fc->data_factor, | |
4301 | fc->ra); | |
4302 | else | |
4303 | { | |
4304 | printf ("\n%08lx %08lx %08lx CIE\n", | |
4305 | (unsigned long)(saved_start - section_start), length, cie_id); | |
4306 | printf (" Version: %d\n", version); | |
4307 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
4308 | if (version >= 4) |
4309 | { | |
4310 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
4311 | printf (" Segment Size: %u\n", fc->segment_size); | |
4312 | } | |
19e6b90e L |
4313 | printf (" Code alignment factor: %u\n", fc->code_factor); |
4314 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
4315 | printf (" Return address column: %d\n", fc->ra); | |
4316 | ||
4317 | if (augmentation_data_len) | |
4318 | { | |
4319 | unsigned long i; | |
4320 | printf (" Augmentation data: "); | |
4321 | for (i = 0; i < augmentation_data_len; ++i) | |
4322 | printf (" %02x", augmentation_data[i]); | |
4323 | putchar ('\n'); | |
4324 | } | |
4325 | putchar ('\n'); | |
4326 | } | |
4327 | ||
4328 | if (augmentation_data_len) | |
4329 | { | |
4330 | unsigned char *p, *q; | |
4331 | p = (unsigned char *) fc->augmentation + 1; | |
4332 | q = augmentation_data; | |
4333 | ||
4334 | while (1) | |
4335 | { | |
4336 | if (*p == 'L') | |
4337 | q++; | |
4338 | else if (*p == 'P') | |
4339 | q += 1 + size_of_encoded_value (*q); | |
4340 | else if (*p == 'R') | |
4341 | fc->fde_encoding = *q++; | |
d80e8de2 JB |
4342 | else if (*p == 'S') |
4343 | ; | |
19e6b90e L |
4344 | else |
4345 | break; | |
4346 | p++; | |
4347 | } | |
4348 | ||
4349 | if (fc->fde_encoding) | |
4350 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
4351 | } | |
4352 | ||
4353 | frame_need_space (fc, fc->ra); | |
4354 | } | |
4355 | else | |
4356 | { | |
4357 | unsigned char *look_for; | |
4358 | static Frame_Chunk fde_fc; | |
604282a7 | 4359 | unsigned long segment_selector; |
19e6b90e L |
4360 | |
4361 | fc = & fde_fc; | |
4362 | memset (fc, 0, sizeof (Frame_Chunk)); | |
4363 | ||
4364 | look_for = is_eh ? start - 4 - cie_id : section_start + cie_id; | |
4365 | ||
4366 | for (cie = chunks; cie ; cie = cie->next) | |
4367 | if (cie->chunk_start == look_for) | |
4368 | break; | |
4369 | ||
4370 | if (!cie) | |
4371 | { | |
53b8873b | 4372 | warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n", |
1617e571 | 4373 | cie_id, (unsigned long)(saved_start - section_start)); |
19e6b90e | 4374 | fc->ncols = 0; |
3f5e193b NC |
4375 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
4376 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
19e6b90e L |
4377 | frame_need_space (fc, max_regs - 1); |
4378 | cie = fc; | |
4379 | fc->augmentation = ""; | |
4380 | fc->fde_encoding = 0; | |
604282a7 JJ |
4381 | fc->ptr_size = eh_addr_size; |
4382 | fc->segment_size = 0; | |
19e6b90e L |
4383 | } |
4384 | else | |
4385 | { | |
4386 | fc->ncols = cie->ncols; | |
3f5e193b NC |
4387 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
4388 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
4389 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
4390 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
4391 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
4392 | fc->ptr_size = cie->ptr_size; |
4393 | eh_addr_size = cie->ptr_size; | |
4394 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
4395 | fc->code_factor = cie->code_factor; |
4396 | fc->data_factor = cie->data_factor; | |
4397 | fc->cfa_reg = cie->cfa_reg; | |
4398 | fc->cfa_offset = cie->cfa_offset; | |
4399 | fc->ra = cie->ra; | |
cc86f28f | 4400 | frame_need_space (fc, max_regs - 1); |
19e6b90e L |
4401 | fc->fde_encoding = cie->fde_encoding; |
4402 | } | |
4403 | ||
4404 | if (fc->fde_encoding) | |
4405 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
4406 | ||
604282a7 JJ |
4407 | segment_selector = 0; |
4408 | if (fc->segment_size) | |
4409 | { | |
4410 | segment_selector = byte_get (start, fc->segment_size); | |
4411 | start += fc->segment_size; | |
4412 | } | |
bad62cf5 | 4413 | fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section); |
19e6b90e L |
4414 | start += encoded_ptr_size; |
4415 | fc->pc_range = byte_get (start, encoded_ptr_size); | |
4416 | start += encoded_ptr_size; | |
4417 | ||
4418 | if (cie->augmentation[0] == 'z') | |
4419 | { | |
4420 | augmentation_data_len = LEB (); | |
4421 | augmentation_data = start; | |
4422 | start += augmentation_data_len; | |
4423 | } | |
4424 | ||
604282a7 | 4425 | printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=", |
19e6b90e | 4426 | (unsigned long)(saved_start - section_start), length, cie_id, |
604282a7 JJ |
4427 | (unsigned long)(cie->chunk_start - section_start)); |
4428 | if (fc->segment_size) | |
4429 | printf ("%04lx:", segment_selector); | |
4430 | printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range); | |
19e6b90e L |
4431 | if (! do_debug_frames_interp && augmentation_data_len) |
4432 | { | |
4433 | unsigned long i; | |
4434 | ||
4435 | printf (" Augmentation data: "); | |
4436 | for (i = 0; i < augmentation_data_len; ++i) | |
4437 | printf (" %02x", augmentation_data[i]); | |
4438 | putchar ('\n'); | |
4439 | putchar ('\n'); | |
4440 | } | |
4441 | } | |
4442 | ||
4443 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
4444 | we're about to interpret instructions for the chunk. */ | |
4445 | /* ??? At present we need to do this always, since this sizes the | |
4446 | fc->col_type and fc->col_offset arrays, which we write into always. | |
4447 | We should probably split the interpreted and non-interpreted bits | |
4448 | into two different routines, since there's so much that doesn't | |
4449 | really overlap between them. */ | |
4450 | if (1 || do_debug_frames_interp) | |
4451 | { | |
4452 | /* Start by making a pass over the chunk, allocating storage | |
4453 | and taking note of what registers are used. */ | |
4454 | unsigned char *tmp = start; | |
4455 | ||
4456 | while (start < block_end) | |
4457 | { | |
4458 | unsigned op, opa; | |
91d6fa6a | 4459 | unsigned long reg, temp; |
19e6b90e L |
4460 | |
4461 | op = *start++; | |
4462 | opa = op & 0x3f; | |
4463 | if (op & 0xc0) | |
4464 | op &= 0xc0; | |
4465 | ||
4466 | /* Warning: if you add any more cases to this switch, be | |
4467 | sure to add them to the corresponding switch below. */ | |
4468 | switch (op) | |
4469 | { | |
4470 | case DW_CFA_advance_loc: | |
4471 | break; | |
4472 | case DW_CFA_offset: | |
4473 | LEB (); | |
665ce1f6 L |
4474 | if (frame_need_space (fc, opa) >= 0) |
4475 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
4476 | break; |
4477 | case DW_CFA_restore: | |
665ce1f6 L |
4478 | if (frame_need_space (fc, opa) >= 0) |
4479 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
4480 | break; |
4481 | case DW_CFA_set_loc: | |
4482 | start += encoded_ptr_size; | |
4483 | break; | |
4484 | case DW_CFA_advance_loc1: | |
4485 | start += 1; | |
4486 | break; | |
4487 | case DW_CFA_advance_loc2: | |
4488 | start += 2; | |
4489 | break; | |
4490 | case DW_CFA_advance_loc4: | |
4491 | start += 4; | |
4492 | break; | |
4493 | case DW_CFA_offset_extended: | |
12eae2d3 | 4494 | case DW_CFA_val_offset: |
19e6b90e | 4495 | reg = LEB (); LEB (); |
665ce1f6 L |
4496 | if (frame_need_space (fc, reg) >= 0) |
4497 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
4498 | break; |
4499 | case DW_CFA_restore_extended: | |
4500 | reg = LEB (); | |
4501 | frame_need_space (fc, reg); | |
665ce1f6 L |
4502 | if (frame_need_space (fc, reg) >= 0) |
4503 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
4504 | break; |
4505 | case DW_CFA_undefined: | |
4506 | reg = LEB (); | |
665ce1f6 L |
4507 | if (frame_need_space (fc, reg) >= 0) |
4508 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
4509 | break; |
4510 | case DW_CFA_same_value: | |
4511 | reg = LEB (); | |
665ce1f6 L |
4512 | if (frame_need_space (fc, reg) >= 0) |
4513 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
4514 | break; |
4515 | case DW_CFA_register: | |
4516 | reg = LEB (); LEB (); | |
665ce1f6 L |
4517 | if (frame_need_space (fc, reg) >= 0) |
4518 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
4519 | break; |
4520 | case DW_CFA_def_cfa: | |
4521 | LEB (); LEB (); | |
4522 | break; | |
4523 | case DW_CFA_def_cfa_register: | |
4524 | LEB (); | |
4525 | break; | |
4526 | case DW_CFA_def_cfa_offset: | |
4527 | LEB (); | |
4528 | break; | |
4529 | case DW_CFA_def_cfa_expression: | |
91d6fa6a NC |
4530 | temp = LEB (); |
4531 | start += temp; | |
19e6b90e L |
4532 | break; |
4533 | case DW_CFA_expression: | |
12eae2d3 | 4534 | case DW_CFA_val_expression: |
19e6b90e | 4535 | reg = LEB (); |
91d6fa6a NC |
4536 | temp = LEB (); |
4537 | start += temp; | |
665ce1f6 L |
4538 | if (frame_need_space (fc, reg) >= 0) |
4539 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
4540 | break; |
4541 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 4542 | case DW_CFA_val_offset_sf: |
19e6b90e | 4543 | reg = LEB (); SLEB (); |
665ce1f6 L |
4544 | if (frame_need_space (fc, reg) >= 0) |
4545 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
4546 | break; |
4547 | case DW_CFA_def_cfa_sf: | |
4548 | LEB (); SLEB (); | |
4549 | break; | |
4550 | case DW_CFA_def_cfa_offset_sf: | |
4551 | SLEB (); | |
4552 | break; | |
4553 | case DW_CFA_MIPS_advance_loc8: | |
4554 | start += 8; | |
4555 | break; | |
4556 | case DW_CFA_GNU_args_size: | |
4557 | LEB (); | |
4558 | break; | |
4559 | case DW_CFA_GNU_negative_offset_extended: | |
4560 | reg = LEB (); LEB (); | |
665ce1f6 L |
4561 | if (frame_need_space (fc, reg) >= 0) |
4562 | fc->col_type[reg] = DW_CFA_undefined; | |
4563 | break; | |
19e6b90e L |
4564 | default: |
4565 | break; | |
4566 | } | |
4567 | } | |
4568 | start = tmp; | |
4569 | } | |
4570 | ||
4571 | /* Now we know what registers are used, make a second pass over | |
4572 | the chunk, this time actually printing out the info. */ | |
4573 | ||
4574 | while (start < block_end) | |
4575 | { | |
4576 | unsigned op, opa; | |
4577 | unsigned long ul, reg, roffs; | |
4578 | long l, ofs; | |
4579 | dwarf_vma vma; | |
665ce1f6 | 4580 | const char *reg_prefix = ""; |
19e6b90e L |
4581 | |
4582 | op = *start++; | |
4583 | opa = op & 0x3f; | |
4584 | if (op & 0xc0) | |
4585 | op &= 0xc0; | |
4586 | ||
4587 | /* Warning: if you add any more cases to this switch, be | |
4588 | sure to add them to the corresponding switch above. */ | |
4589 | switch (op) | |
4590 | { | |
4591 | case DW_CFA_advance_loc: | |
4592 | if (do_debug_frames_interp) | |
4593 | frame_display_row (fc, &need_col_headers, &max_regs); | |
4594 | else | |
4595 | printf (" DW_CFA_advance_loc: %d to %08lx\n", | |
4596 | opa * fc->code_factor, | |
4597 | fc->pc_begin + opa * fc->code_factor); | |
4598 | fc->pc_begin += opa * fc->code_factor; | |
4599 | break; | |
4600 | ||
4601 | case DW_CFA_offset: | |
4602 | roffs = LEB (); | |
665ce1f6 L |
4603 | if (opa >= (unsigned int) fc->ncols) |
4604 | reg_prefix = bad_reg; | |
4605 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
4606 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
4607 | reg_prefix, regname (opa, 0), | |
4608 | roffs * fc->data_factor); | |
4609 | if (*reg_prefix == '\0') | |
4610 | { | |
4611 | fc->col_type[opa] = DW_CFA_offset; | |
4612 | fc->col_offset[opa] = roffs * fc->data_factor; | |
4613 | } | |
19e6b90e L |
4614 | break; |
4615 | ||
4616 | case DW_CFA_restore: | |
665ce1f6 L |
4617 | if (opa >= (unsigned int) cie->ncols |
4618 | || opa >= (unsigned int) fc->ncols) | |
4619 | reg_prefix = bad_reg; | |
4620 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
4621 | printf (" DW_CFA_restore: %s%s\n", | |
4622 | reg_prefix, regname (opa, 0)); | |
4623 | if (*reg_prefix == '\0') | |
4624 | { | |
4625 | fc->col_type[opa] = cie->col_type[opa]; | |
4626 | fc->col_offset[opa] = cie->col_offset[opa]; | |
4627 | } | |
19e6b90e L |
4628 | break; |
4629 | ||
4630 | case DW_CFA_set_loc: | |
bad62cf5 | 4631 | vma = get_encoded_value (start, fc->fde_encoding, section); |
19e6b90e L |
4632 | start += encoded_ptr_size; |
4633 | if (do_debug_frames_interp) | |
4634 | frame_display_row (fc, &need_col_headers, &max_regs); | |
4635 | else | |
4636 | printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma); | |
4637 | fc->pc_begin = vma; | |
4638 | break; | |
4639 | ||
4640 | case DW_CFA_advance_loc1: | |
4641 | ofs = byte_get (start, 1); start += 1; | |
4642 | if (do_debug_frames_interp) | |
4643 | frame_display_row (fc, &need_col_headers, &max_regs); | |
4644 | else | |
4645 | printf (" DW_CFA_advance_loc1: %ld to %08lx\n", | |
4646 | ofs * fc->code_factor, | |
4647 | fc->pc_begin + ofs * fc->code_factor); | |
4648 | fc->pc_begin += ofs * fc->code_factor; | |
4649 | break; | |
4650 | ||
4651 | case DW_CFA_advance_loc2: | |
4652 | ofs = byte_get (start, 2); start += 2; | |
4653 | if (do_debug_frames_interp) | |
4654 | frame_display_row (fc, &need_col_headers, &max_regs); | |
4655 | else | |
4656 | printf (" DW_CFA_advance_loc2: %ld to %08lx\n", | |
4657 | ofs * fc->code_factor, | |
4658 | fc->pc_begin + ofs * fc->code_factor); | |
4659 | fc->pc_begin += ofs * fc->code_factor; | |
4660 | break; | |
4661 | ||
4662 | case DW_CFA_advance_loc4: | |
4663 | ofs = byte_get (start, 4); start += 4; | |
4664 | if (do_debug_frames_interp) | |
4665 | frame_display_row (fc, &need_col_headers, &max_regs); | |
4666 | else | |
4667 | printf (" DW_CFA_advance_loc4: %ld to %08lx\n", | |
4668 | ofs * fc->code_factor, | |
4669 | fc->pc_begin + ofs * fc->code_factor); | |
4670 | fc->pc_begin += ofs * fc->code_factor; | |
4671 | break; | |
4672 | ||
4673 | case DW_CFA_offset_extended: | |
4674 | reg = LEB (); | |
4675 | roffs = LEB (); | |
665ce1f6 L |
4676 | if (reg >= (unsigned int) fc->ncols) |
4677 | reg_prefix = bad_reg; | |
4678 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
4679 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
4680 | reg_prefix, regname (reg, 0), | |
4681 | roffs * fc->data_factor); | |
4682 | if (*reg_prefix == '\0') | |
4683 | { | |
4684 | fc->col_type[reg] = DW_CFA_offset; | |
4685 | fc->col_offset[reg] = roffs * fc->data_factor; | |
4686 | } | |
19e6b90e L |
4687 | break; |
4688 | ||
12eae2d3 JJ |
4689 | case DW_CFA_val_offset: |
4690 | reg = LEB (); | |
4691 | roffs = LEB (); | |
665ce1f6 L |
4692 | if (reg >= (unsigned int) fc->ncols) |
4693 | reg_prefix = bad_reg; | |
4694 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
4695 | printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n", | |
4696 | reg_prefix, regname (reg, 0), | |
4697 | roffs * fc->data_factor); | |
4698 | if (*reg_prefix == '\0') | |
4699 | { | |
4700 | fc->col_type[reg] = DW_CFA_val_offset; | |
4701 | fc->col_offset[reg] = roffs * fc->data_factor; | |
4702 | } | |
12eae2d3 JJ |
4703 | break; |
4704 | ||
19e6b90e L |
4705 | case DW_CFA_restore_extended: |
4706 | reg = LEB (); | |
665ce1f6 L |
4707 | if (reg >= (unsigned int) cie->ncols |
4708 | || reg >= (unsigned int) fc->ncols) | |
4709 | reg_prefix = bad_reg; | |
4710 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
4711 | printf (" DW_CFA_restore_extended: %s%s\n", | |
4712 | reg_prefix, regname (reg, 0)); | |
4713 | if (*reg_prefix == '\0') | |
4714 | { | |
4715 | fc->col_type[reg] = cie->col_type[reg]; | |
4716 | fc->col_offset[reg] = cie->col_offset[reg]; | |
4717 | } | |
19e6b90e L |
4718 | break; |
4719 | ||
4720 | case DW_CFA_undefined: | |
4721 | reg = LEB (); | |
665ce1f6 L |
4722 | if (reg >= (unsigned int) fc->ncols) |
4723 | reg_prefix = bad_reg; | |
4724 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
4725 | printf (" DW_CFA_undefined: %s%s\n", | |
4726 | reg_prefix, regname (reg, 0)); | |
4727 | if (*reg_prefix == '\0') | |
4728 | { | |
4729 | fc->col_type[reg] = DW_CFA_undefined; | |
4730 | fc->col_offset[reg] = 0; | |
4731 | } | |
19e6b90e L |
4732 | break; |
4733 | ||
4734 | case DW_CFA_same_value: | |
4735 | reg = LEB (); | |
665ce1f6 L |
4736 | if (reg >= (unsigned int) fc->ncols) |
4737 | reg_prefix = bad_reg; | |
4738 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
4739 | printf (" DW_CFA_same_value: %s%s\n", | |
4740 | reg_prefix, regname (reg, 0)); | |
4741 | if (*reg_prefix == '\0') | |
4742 | { | |
4743 | fc->col_type[reg] = DW_CFA_same_value; | |
4744 | fc->col_offset[reg] = 0; | |
4745 | } | |
19e6b90e L |
4746 | break; |
4747 | ||
4748 | case DW_CFA_register: | |
4749 | reg = LEB (); | |
4750 | roffs = LEB (); | |
665ce1f6 L |
4751 | if (reg >= (unsigned int) fc->ncols) |
4752 | reg_prefix = bad_reg; | |
4753 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 4754 | { |
665ce1f6 L |
4755 | printf (" DW_CFA_register: %s%s in ", |
4756 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
4757 | puts (regname (roffs, 0)); |
4758 | } | |
665ce1f6 L |
4759 | if (*reg_prefix == '\0') |
4760 | { | |
4761 | fc->col_type[reg] = DW_CFA_register; | |
4762 | fc->col_offset[reg] = roffs; | |
4763 | } | |
19e6b90e L |
4764 | break; |
4765 | ||
4766 | case DW_CFA_remember_state: | |
4767 | if (! do_debug_frames_interp) | |
4768 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 4769 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
19e6b90e | 4770 | rs->ncols = fc->ncols; |
3f5e193b NC |
4771 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
4772 | sizeof (short int)); | |
4773 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int)); | |
19e6b90e L |
4774 | memcpy (rs->col_type, fc->col_type, rs->ncols); |
4775 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int)); | |
4776 | rs->next = remembered_state; | |
4777 | remembered_state = rs; | |
4778 | break; | |
4779 | ||
4780 | case DW_CFA_restore_state: | |
4781 | if (! do_debug_frames_interp) | |
4782 | printf (" DW_CFA_restore_state\n"); | |
4783 | rs = remembered_state; | |
4784 | if (rs) | |
4785 | { | |
4786 | remembered_state = rs->next; | |
cc86f28f | 4787 | frame_need_space (fc, rs->ncols - 1); |
19e6b90e L |
4788 | memcpy (fc->col_type, rs->col_type, rs->ncols); |
4789 | memcpy (fc->col_offset, rs->col_offset, | |
4790 | rs->ncols * sizeof (int)); | |
4791 | free (rs->col_type); | |
4792 | free (rs->col_offset); | |
4793 | free (rs); | |
4794 | } | |
4795 | else if (do_debug_frames_interp) | |
4796 | printf ("Mismatched DW_CFA_restore_state\n"); | |
4797 | break; | |
4798 | ||
4799 | case DW_CFA_def_cfa: | |
4800 | fc->cfa_reg = LEB (); | |
4801 | fc->cfa_offset = LEB (); | |
4802 | fc->cfa_exp = 0; | |
4803 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
4804 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
4805 | regname (fc->cfa_reg, 0), fc->cfa_offset); | |
19e6b90e L |
4806 | break; |
4807 | ||
4808 | case DW_CFA_def_cfa_register: | |
4809 | fc->cfa_reg = LEB (); | |
4810 | fc->cfa_exp = 0; | |
4811 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
4812 | printf (" DW_CFA_def_cfa_register: %s\n", |
4813 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
4814 | break; |
4815 | ||
4816 | case DW_CFA_def_cfa_offset: | |
4817 | fc->cfa_offset = LEB (); | |
4818 | if (! do_debug_frames_interp) | |
4819 | printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset); | |
4820 | break; | |
4821 | ||
4822 | case DW_CFA_nop: | |
4823 | if (! do_debug_frames_interp) | |
4824 | printf (" DW_CFA_nop\n"); | |
4825 | break; | |
4826 | ||
4827 | case DW_CFA_def_cfa_expression: | |
4828 | ul = LEB (); | |
4829 | if (! do_debug_frames_interp) | |
4830 | { | |
4831 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
4832 | decode_location_expression (start, eh_addr_size, 0, -1, |
4833 | ul, 0, section); | |
19e6b90e L |
4834 | printf (")\n"); |
4835 | } | |
4836 | fc->cfa_exp = 1; | |
4837 | start += ul; | |
4838 | break; | |
4839 | ||
4840 | case DW_CFA_expression: | |
4841 | reg = LEB (); | |
4842 | ul = LEB (); | |
665ce1f6 L |
4843 | if (reg >= (unsigned int) fc->ncols) |
4844 | reg_prefix = bad_reg; | |
4845 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
19e6b90e | 4846 | { |
665ce1f6 L |
4847 | printf (" DW_CFA_expression: %s%s (", |
4848 | reg_prefix, regname (reg, 0)); | |
b7807392 | 4849 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 4850 | ul, 0, section); |
19e6b90e L |
4851 | printf (")\n"); |
4852 | } | |
665ce1f6 L |
4853 | if (*reg_prefix == '\0') |
4854 | fc->col_type[reg] = DW_CFA_expression; | |
19e6b90e L |
4855 | start += ul; |
4856 | break; | |
4857 | ||
12eae2d3 JJ |
4858 | case DW_CFA_val_expression: |
4859 | reg = LEB (); | |
4860 | ul = LEB (); | |
665ce1f6 L |
4861 | if (reg >= (unsigned int) fc->ncols) |
4862 | reg_prefix = bad_reg; | |
4863 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
12eae2d3 | 4864 | { |
665ce1f6 L |
4865 | printf (" DW_CFA_val_expression: %s%s (", |
4866 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
4867 | decode_location_expression (start, eh_addr_size, 0, -1, |
4868 | ul, 0, section); | |
12eae2d3 JJ |
4869 | printf (")\n"); |
4870 | } | |
665ce1f6 L |
4871 | if (*reg_prefix == '\0') |
4872 | fc->col_type[reg] = DW_CFA_val_expression; | |
12eae2d3 JJ |
4873 | start += ul; |
4874 | break; | |
4875 | ||
19e6b90e L |
4876 | case DW_CFA_offset_extended_sf: |
4877 | reg = LEB (); | |
4878 | l = SLEB (); | |
665ce1f6 L |
4879 | if (frame_need_space (fc, reg) < 0) |
4880 | reg_prefix = bad_reg; | |
4881 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
4882 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
4883 | reg_prefix, regname (reg, 0), | |
4884 | l * fc->data_factor); | |
4885 | if (*reg_prefix == '\0') | |
4886 | { | |
4887 | fc->col_type[reg] = DW_CFA_offset; | |
4888 | fc->col_offset[reg] = l * fc->data_factor; | |
4889 | } | |
19e6b90e L |
4890 | break; |
4891 | ||
12eae2d3 JJ |
4892 | case DW_CFA_val_offset_sf: |
4893 | reg = LEB (); | |
4894 | l = SLEB (); | |
665ce1f6 L |
4895 | if (frame_need_space (fc, reg) < 0) |
4896 | reg_prefix = bad_reg; | |
4897 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
4898 | printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n", | |
4899 | reg_prefix, regname (reg, 0), | |
4900 | l * fc->data_factor); | |
4901 | if (*reg_prefix == '\0') | |
4902 | { | |
4903 | fc->col_type[reg] = DW_CFA_val_offset; | |
4904 | fc->col_offset[reg] = l * fc->data_factor; | |
4905 | } | |
12eae2d3 JJ |
4906 | break; |
4907 | ||
19e6b90e L |
4908 | case DW_CFA_def_cfa_sf: |
4909 | fc->cfa_reg = LEB (); | |
4910 | fc->cfa_offset = SLEB (); | |
4911 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; | |
4912 | fc->cfa_exp = 0; | |
4913 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
4914 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
4915 | regname (fc->cfa_reg, 0), fc->cfa_offset); | |
19e6b90e L |
4916 | break; |
4917 | ||
4918 | case DW_CFA_def_cfa_offset_sf: | |
4919 | fc->cfa_offset = SLEB (); | |
4920 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; | |
4921 | if (! do_debug_frames_interp) | |
4922 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset); | |
4923 | break; | |
4924 | ||
4925 | case DW_CFA_MIPS_advance_loc8: | |
4926 | ofs = byte_get (start, 8); start += 8; | |
4927 | if (do_debug_frames_interp) | |
4928 | frame_display_row (fc, &need_col_headers, &max_regs); | |
4929 | else | |
4930 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n", | |
4931 | ofs * fc->code_factor, | |
4932 | fc->pc_begin + ofs * fc->code_factor); | |
4933 | fc->pc_begin += ofs * fc->code_factor; | |
4934 | break; | |
4935 | ||
4936 | case DW_CFA_GNU_window_save: | |
4937 | if (! do_debug_frames_interp) | |
4938 | printf (" DW_CFA_GNU_window_save\n"); | |
4939 | break; | |
4940 | ||
4941 | case DW_CFA_GNU_args_size: | |
4942 | ul = LEB (); | |
4943 | if (! do_debug_frames_interp) | |
4944 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
4945 | break; | |
4946 | ||
4947 | case DW_CFA_GNU_negative_offset_extended: | |
4948 | reg = LEB (); | |
4949 | l = - LEB (); | |
665ce1f6 L |
4950 | if (frame_need_space (fc, reg) < 0) |
4951 | reg_prefix = bad_reg; | |
4952 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
4953 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
4954 | reg_prefix, regname (reg, 0), | |
4955 | l * fc->data_factor); | |
4956 | if (*reg_prefix == '\0') | |
4957 | { | |
4958 | fc->col_type[reg] = DW_CFA_offset; | |
4959 | fc->col_offset[reg] = l * fc->data_factor; | |
4960 | } | |
19e6b90e L |
4961 | break; |
4962 | ||
4963 | default: | |
53b8873b NC |
4964 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
4965 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
4966 | else | |
cecf136e | 4967 | warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
4968 | start = block_end; |
4969 | } | |
4970 | } | |
4971 | ||
4972 | if (do_debug_frames_interp) | |
4973 | frame_display_row (fc, &need_col_headers, &max_regs); | |
4974 | ||
4975 | start = block_end; | |
604282a7 | 4976 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
4977 | } |
4978 | ||
4979 | printf ("\n"); | |
4980 | ||
4981 | return 1; | |
4982 | } | |
4983 | ||
4984 | #undef GET | |
4985 | #undef LEB | |
4986 | #undef SLEB | |
4987 | ||
5bbdf3d5 DE |
4988 | static int |
4989 | display_gdb_index (struct dwarf_section *section, | |
4990 | void *file ATTRIBUTE_UNUSED) | |
4991 | { | |
4992 | unsigned char *start = section->start; | |
4993 | uint32_t version; | |
4994 | uint32_t cu_list_offset, tu_list_offset; | |
4995 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
4996 | unsigned int cu_list_elements, tu_list_elements; | |
4997 | unsigned int address_table_size, symbol_table_slots; | |
4998 | unsigned char *cu_list, *tu_list; | |
4999 | unsigned char *address_table, *symbol_table, *constant_pool; | |
5000 | unsigned int i; | |
5001 | ||
5002 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
5003 | ||
5004 | printf (_("Contents of the %s section:\n"), section->name); | |
5005 | ||
5006 | if (section->size < 6 * sizeof (uint32_t)) | |
5007 | { | |
5008 | warn (_("Truncated header in the %s section.\n"), section->name); | |
5009 | return 0; | |
5010 | } | |
5011 | ||
5012 | version = byte_get_little_endian (start, 4); | |
da88a764 | 5013 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
5014 | |
5015 | /* Prior versions are obsolete, and future versions may not be | |
5016 | backwards compatible. */ | |
6ec8b48e | 5017 | switch (version) |
5bbdf3d5 | 5018 | { |
6ec8b48e JK |
5019 | case 3: |
5020 | warn (_("The address table data in version 3 may be wrong.\n")); | |
5021 | break; | |
5022 | case 4: | |
5023 | break; | |
5024 | default: | |
da88a764 | 5025 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
5026 | return 0; |
5027 | } | |
5028 | ||
5029 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
5030 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
5031 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
5032 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
5033 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
5034 | ||
5035 | if (cu_list_offset > section->size | |
5036 | || tu_list_offset > section->size | |
5037 | || address_table_offset > section->size | |
5038 | || symbol_table_offset > section->size | |
5039 | || constant_pool_offset > section->size) | |
5040 | { | |
5041 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
5042 | return 0; | |
5043 | } | |
5044 | ||
5045 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; | |
5046 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; | |
5047 | address_table_size = symbol_table_offset - address_table_offset; | |
5048 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; | |
5049 | ||
5050 | cu_list = start + cu_list_offset; | |
5051 | tu_list = start + tu_list_offset; | |
5052 | address_table = start + address_table_offset; | |
5053 | symbol_table = start + symbol_table_offset; | |
5054 | constant_pool = start + constant_pool_offset; | |
5055 | ||
5056 | printf (_("\nCU table:\n")); | |
5057 | for (i = 0; i < cu_list_elements; i += 2) | |
5058 | { | |
5059 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
5060 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
5061 | ||
5062 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
5063 | (unsigned long) cu_offset, | |
5064 | (unsigned long) (cu_offset + cu_length - 1)); | |
5065 | } | |
5066 | ||
5067 | printf (_("\nTU table:\n")); | |
5068 | for (i = 0; i < tu_list_elements; i += 3) | |
5069 | { | |
5070 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
5071 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
5072 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
5073 | ||
5074 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
5075 | (unsigned long) tu_offset, | |
5076 | (unsigned long) type_offset); | |
5077 | print_dwarf_vma (signature, 8); | |
5078 | printf ("\n"); | |
5079 | } | |
5080 | ||
5081 | printf (_("\nAddress table:\n")); | |
5082 | for (i = 0; i < address_table_size; i += 2 * 8 + 4) | |
5083 | { | |
5084 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
5085 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
5086 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
5087 | ||
5088 | print_dwarf_vma (low, 8); | |
5089 | print_dwarf_vma (high, 8); | |
da88a764 | 5090 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
5091 | } |
5092 | ||
5093 | printf (_("\nSymbol table:\n")); | |
5094 | for (i = 0; i < symbol_table_slots; ++i) | |
5095 | { | |
5096 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
5097 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
5098 | uint32_t num_cus, cu; | |
5099 | ||
5100 | if (name_offset != 0 | |
5101 | || cu_vector_offset != 0) | |
5102 | { | |
5103 | unsigned int j; | |
5104 | ||
5105 | printf ("[%3u] %s:", i, constant_pool + name_offset); | |
5106 | num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4); | |
5107 | for (j = 0; j < num_cus; ++j) | |
5108 | { | |
5109 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); | |
5110 | /* Convert to TU number if it's for a type unit. */ | |
5111 | if (cu >= cu_list_elements) | |
da88a764 | 5112 | printf (" T%lu", (unsigned long) (cu - cu_list_elements)); |
5bbdf3d5 | 5113 | else |
da88a764 | 5114 | printf (" %lu", (unsigned long) cu); |
5bbdf3d5 DE |
5115 | } |
5116 | printf ("\n"); | |
5117 | } | |
5118 | } | |
5119 | ||
5120 | return 1; | |
5121 | } | |
5122 | ||
19e6b90e L |
5123 | static int |
5124 | display_debug_not_supported (struct dwarf_section *section, | |
5125 | void *file ATTRIBUTE_UNUSED) | |
5126 | { | |
5127 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
5128 | section->name); | |
5129 | ||
5130 | return 1; | |
5131 | } | |
5132 | ||
5133 | void * | |
5134 | cmalloc (size_t nmemb, size_t size) | |
5135 | { | |
5136 | /* Check for overflow. */ | |
5137 | if (nmemb >= ~(size_t) 0 / size) | |
5138 | return NULL; | |
5139 | else | |
5140 | return malloc (nmemb * size); | |
5141 | } | |
5142 | ||
5143 | void * | |
5144 | xcmalloc (size_t nmemb, size_t size) | |
5145 | { | |
5146 | /* Check for overflow. */ | |
5147 | if (nmemb >= ~(size_t) 0 / size) | |
5148 | return NULL; | |
5149 | else | |
5150 | return xmalloc (nmemb * size); | |
5151 | } | |
5152 | ||
5153 | void * | |
5154 | xcrealloc (void *ptr, size_t nmemb, size_t size) | |
5155 | { | |
5156 | /* Check for overflow. */ | |
5157 | if (nmemb >= ~(size_t) 0 / size) | |
5158 | return NULL; | |
5159 | else | |
5160 | return xrealloc (ptr, nmemb * size); | |
5161 | } | |
5162 | ||
19e6b90e L |
5163 | void |
5164 | free_debug_memory (void) | |
5165 | { | |
3f5e193b | 5166 | unsigned int i; |
19e6b90e L |
5167 | |
5168 | free_abbrevs (); | |
5169 | ||
5170 | for (i = 0; i < max; i++) | |
3f5e193b | 5171 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 5172 | |
cc86f28f | 5173 | if (debug_information != NULL) |
19e6b90e | 5174 | { |
cc86f28f | 5175 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 5176 | { |
cc86f28f | 5177 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 5178 | { |
cc86f28f NC |
5179 | if (!debug_information [i].max_loc_offsets) |
5180 | { | |
5181 | free (debug_information [i].loc_offsets); | |
5182 | free (debug_information [i].have_frame_base); | |
5183 | } | |
5184 | if (!debug_information [i].max_range_lists) | |
5185 | free (debug_information [i].range_lists); | |
19e6b90e | 5186 | } |
19e6b90e | 5187 | } |
cc86f28f | 5188 | |
19e6b90e L |
5189 | free (debug_information); |
5190 | debug_information = NULL; | |
5191 | num_debug_info_entries = 0; | |
5192 | } | |
19e6b90e L |
5193 | } |
5194 | ||
4cb93e3b TG |
5195 | void |
5196 | dwarf_select_sections_by_names (const char *names) | |
5197 | { | |
5198 | typedef struct | |
5199 | { | |
5200 | const char * option; | |
5201 | int * variable; | |
f9f0e732 | 5202 | int val; |
4cb93e3b TG |
5203 | } |
5204 | debug_dump_long_opts; | |
5205 | ||
5206 | static const debug_dump_long_opts opts_table [] = | |
5207 | { | |
5208 | /* Please keep this table alpha- sorted. */ | |
5209 | { "Ranges", & do_debug_ranges, 1 }, | |
5210 | { "abbrev", & do_debug_abbrevs, 1 }, | |
5211 | { "aranges", & do_debug_aranges, 1 }, | |
5212 | { "frames", & do_debug_frames, 1 }, | |
5213 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
5214 | { "info", & do_debug_info, 1 }, | |
5215 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
5216 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, | |
5217 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
5218 | { "loc", & do_debug_loc, 1 }, | |
5219 | { "macro", & do_debug_macinfo, 1 }, | |
5220 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 5221 | { "pubtypes", & do_debug_pubtypes, 1 }, |
4cb93e3b TG |
5222 | /* This entry is for compatability |
5223 | with earlier versions of readelf. */ | |
5224 | { "ranges", & do_debug_aranges, 1 }, | |
5225 | { "str", & do_debug_str, 1 }, | |
5bbdf3d5 DE |
5226 | /* The special .gdb_index section. */ |
5227 | { "gdb_index", & do_gdb_index, 1 }, | |
6f875884 TG |
5228 | /* These trace_* sections are used by Itanium VMS. */ |
5229 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
5230 | { "trace_aranges", & do_trace_aranges, 1 }, | |
5231 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
5232 | { NULL, NULL, 0 } |
5233 | }; | |
5234 | ||
5235 | const char *p; | |
467c65bc | 5236 | |
4cb93e3b TG |
5237 | p = names; |
5238 | while (*p) | |
5239 | { | |
5240 | const debug_dump_long_opts * entry; | |
467c65bc | 5241 | |
4cb93e3b TG |
5242 | for (entry = opts_table; entry->option; entry++) |
5243 | { | |
5244 | size_t len = strlen (entry->option); | |
467c65bc | 5245 | |
4cb93e3b TG |
5246 | if (strncmp (p, entry->option, len) == 0 |
5247 | && (p[len] == ',' || p[len] == '\0')) | |
5248 | { | |
5249 | * entry->variable |= entry->val; | |
467c65bc | 5250 | |
4cb93e3b TG |
5251 | /* The --debug-dump=frames-interp option also |
5252 | enables the --debug-dump=frames option. */ | |
5253 | if (do_debug_frames_interp) | |
5254 | do_debug_frames = 1; | |
5255 | ||
5256 | p += len; | |
5257 | break; | |
5258 | } | |
5259 | } | |
467c65bc | 5260 | |
4cb93e3b TG |
5261 | if (entry->option == NULL) |
5262 | { | |
5263 | warn (_("Unrecognized debug option '%s'\n"), p); | |
5264 | p = strchr (p, ','); | |
5265 | if (p == NULL) | |
5266 | break; | |
5267 | } | |
467c65bc | 5268 | |
4cb93e3b TG |
5269 | if (*p == ',') |
5270 | p++; | |
5271 | } | |
5272 | } | |
5273 | ||
5274 | void | |
5275 | dwarf_select_sections_by_letters (const char *letters) | |
5276 | { | |
91d6fa6a | 5277 | unsigned int lindex = 0; |
4cb93e3b | 5278 | |
91d6fa6a NC |
5279 | while (letters[lindex]) |
5280 | switch (letters[lindex++]) | |
4cb93e3b TG |
5281 | { |
5282 | case 'i': | |
5283 | do_debug_info = 1; | |
5284 | break; | |
467c65bc | 5285 | |
4cb93e3b TG |
5286 | case 'a': |
5287 | do_debug_abbrevs = 1; | |
5288 | break; | |
467c65bc | 5289 | |
4cb93e3b TG |
5290 | case 'l': |
5291 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5292 | break; | |
467c65bc | 5293 | |
4cb93e3b TG |
5294 | case 'L': |
5295 | do_debug_lines |= FLAG_DEBUG_LINES_DECODED; | |
5296 | break; | |
467c65bc | 5297 | |
4cb93e3b TG |
5298 | case 'p': |
5299 | do_debug_pubnames = 1; | |
5300 | break; | |
467c65bc | 5301 | |
f9f0e732 NC |
5302 | case 't': |
5303 | do_debug_pubtypes = 1; | |
5304 | break; | |
467c65bc | 5305 | |
4cb93e3b TG |
5306 | case 'r': |
5307 | do_debug_aranges = 1; | |
5308 | break; | |
467c65bc | 5309 | |
4cb93e3b TG |
5310 | case 'R': |
5311 | do_debug_ranges = 1; | |
5312 | break; | |
467c65bc | 5313 | |
4cb93e3b TG |
5314 | case 'F': |
5315 | do_debug_frames_interp = 1; | |
5316 | case 'f': | |
5317 | do_debug_frames = 1; | |
5318 | break; | |
467c65bc | 5319 | |
4cb93e3b TG |
5320 | case 'm': |
5321 | do_debug_macinfo = 1; | |
5322 | break; | |
467c65bc | 5323 | |
4cb93e3b TG |
5324 | case 's': |
5325 | do_debug_str = 1; | |
5326 | break; | |
467c65bc | 5327 | |
4cb93e3b TG |
5328 | case 'o': |
5329 | do_debug_loc = 1; | |
5330 | break; | |
467c65bc | 5331 | |
4cb93e3b TG |
5332 | default: |
5333 | warn (_("Unrecognized debug option '%s'\n"), optarg); | |
5334 | break; | |
5335 | } | |
5336 | } | |
5337 | ||
5338 | void | |
5339 | dwarf_select_sections_all (void) | |
5340 | { | |
5341 | do_debug_info = 1; | |
5342 | do_debug_abbrevs = 1; | |
5343 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
5344 | do_debug_pubnames = 1; | |
f9f0e732 | 5345 | do_debug_pubtypes = 1; |
4cb93e3b TG |
5346 | do_debug_aranges = 1; |
5347 | do_debug_ranges = 1; | |
5348 | do_debug_frames = 1; | |
5349 | do_debug_macinfo = 1; | |
5350 | do_debug_str = 1; | |
5351 | do_debug_loc = 1; | |
5bbdf3d5 | 5352 | do_gdb_index = 1; |
6f875884 TG |
5353 | do_trace_info = 1; |
5354 | do_trace_abbrevs = 1; | |
5355 | do_trace_aranges = 1; | |
4cb93e3b TG |
5356 | } |
5357 | ||
19e6b90e L |
5358 | struct dwarf_section_display debug_displays[] = |
5359 | { | |
6f875884 | 5360 | { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0 }, |
c8450da8 | 5361 | display_debug_abbrev, &do_debug_abbrevs, 0 }, |
6f875884 | 5362 | { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0 }, |
c8450da8 | 5363 | display_debug_aranges, &do_debug_aranges, 1 }, |
6f875884 | 5364 | { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0 }, |
c8450da8 | 5365 | display_debug_frames, &do_debug_frames, 1 }, |
6f875884 | 5366 | { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0 }, |
c8450da8 | 5367 | display_debug_info, &do_debug_info, 1 }, |
6f875884 | 5368 | { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0 }, |
c8450da8 | 5369 | display_debug_lines, &do_debug_lines, 1 }, |
6f875884 | 5370 | { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0 }, |
c8450da8 | 5371 | display_debug_pubnames, &do_debug_pubnames, 0 }, |
6f875884 | 5372 | { { ".eh_frame", "", NULL, NULL, 0, 0 }, |
c8450da8 | 5373 | display_debug_frames, &do_debug_frames, 1 }, |
6f875884 | 5374 | { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0 }, |
c8450da8 | 5375 | display_debug_macinfo, &do_debug_macinfo, 0 }, |
6f875884 | 5376 | { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0 }, |
c8450da8 | 5377 | display_debug_str, &do_debug_str, 0 }, |
6f875884 | 5378 | { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0 }, |
c8450da8 | 5379 | display_debug_loc, &do_debug_loc, 1 }, |
6f875884 | 5380 | { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0 }, |
f9f0e732 | 5381 | display_debug_pubnames, &do_debug_pubtypes, 0 }, |
6f875884 | 5382 | { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0 }, |
c8450da8 | 5383 | display_debug_ranges, &do_debug_ranges, 1 }, |
6f875884 | 5384 | { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0 }, |
c8450da8 | 5385 | display_debug_not_supported, NULL, 0 }, |
6f875884 | 5386 | { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0 }, |
c8450da8 | 5387 | display_debug_not_supported, NULL, 0 }, |
6f875884 | 5388 | { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0 }, |
2b6f5997 | 5389 | display_debug_types, &do_debug_info, 1 }, |
6f875884 TG |
5390 | { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0 }, |
5391 | display_debug_not_supported, NULL, 0 }, | |
5bbdf3d5 DE |
5392 | { { ".gdb_index", "", NULL, NULL, 0, 0 }, |
5393 | display_gdb_index, &do_gdb_index, 0 }, | |
6f875884 TG |
5394 | { { ".trace_info", "", NULL, NULL, 0, 0 }, |
5395 | display_trace_info, &do_trace_info, 1 }, | |
5396 | { { ".trace_abbrev", "", NULL, NULL, 0, 0 }, | |
5397 | display_debug_abbrev, &do_trace_abbrevs, 0 }, | |
5398 | { { ".trace_aranges", "", NULL, NULL, 0, 0 }, | |
5399 | display_debug_aranges, &do_trace_aranges, 0 } | |
19e6b90e | 5400 | }; |