Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
fe4eaaf4 | 2 | Copyright 2005, 2006, 2007, 2008 |
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 AM |
24 | #include "bfd.h" |
25 | #include "bucomm.h" | |
2dc4cec1 | 26 | #include "elf/common.h" |
3db64b00 AM |
27 | #include "elf/dwarf2.h" |
28 | #include "dwarf.h" | |
19e6b90e L |
29 | |
30 | static int have_frame_base; | |
31 | static int need_base_address; | |
32 | ||
33 | static unsigned int last_pointer_size = 0; | |
34 | static int warned_about_missing_comp_units = FALSE; | |
35 | ||
36 | static unsigned int num_debug_info_entries = 0; | |
37 | static debug_info *debug_information = NULL; | |
cc86f28f NC |
38 | /* Special value for num_debug_info_entries to indicate |
39 | that the .debug_info section could not be loaded/parsed. */ | |
40 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 41 | |
2dc4cec1 | 42 | int eh_addr_size; |
19e6b90e L |
43 | |
44 | int do_debug_info; | |
45 | int do_debug_abbrevs; | |
46 | int do_debug_lines; | |
47 | int do_debug_pubnames; | |
48 | int do_debug_aranges; | |
49 | int do_debug_ranges; | |
50 | int do_debug_frames; | |
51 | int do_debug_frames_interp; | |
52 | int do_debug_macinfo; | |
53 | int do_debug_str; | |
54 | int do_debug_loc; | |
55 | ||
56 | dwarf_vma (*byte_get) (unsigned char *, int); | |
57 | ||
58 | dwarf_vma | |
59 | byte_get_little_endian (unsigned char *field, int size) | |
60 | { | |
61 | switch (size) | |
62 | { | |
63 | case 1: | |
64 | return *field; | |
65 | ||
66 | case 2: | |
67 | return ((unsigned int) (field[0])) | |
68 | | (((unsigned int) (field[1])) << 8); | |
69 | ||
70 | case 4: | |
71 | return ((unsigned long) (field[0])) | |
72 | | (((unsigned long) (field[1])) << 8) | |
73 | | (((unsigned long) (field[2])) << 16) | |
74 | | (((unsigned long) (field[3])) << 24); | |
75 | ||
76 | case 8: | |
77 | if (sizeof (dwarf_vma) == 8) | |
78 | return ((dwarf_vma) (field[0])) | |
79 | | (((dwarf_vma) (field[1])) << 8) | |
80 | | (((dwarf_vma) (field[2])) << 16) | |
81 | | (((dwarf_vma) (field[3])) << 24) | |
82 | | (((dwarf_vma) (field[4])) << 32) | |
83 | | (((dwarf_vma) (field[5])) << 40) | |
84 | | (((dwarf_vma) (field[6])) << 48) | |
85 | | (((dwarf_vma) (field[7])) << 56); | |
86 | else if (sizeof (dwarf_vma) == 4) | |
87 | /* We want to extract data from an 8 byte wide field and | |
88 | place it into a 4 byte wide field. Since this is a little | |
89 | endian source we can just use the 4 byte extraction code. */ | |
90 | return ((unsigned long) (field[0])) | |
91 | | (((unsigned long) (field[1])) << 8) | |
92 | | (((unsigned long) (field[2])) << 16) | |
93 | | (((unsigned long) (field[3])) << 24); | |
94 | ||
95 | default: | |
96 | error (_("Unhandled data length: %d\n"), size); | |
97 | abort (); | |
98 | } | |
99 | } | |
100 | ||
101 | dwarf_vma | |
102 | byte_get_big_endian (unsigned char *field, int size) | |
103 | { | |
104 | switch (size) | |
105 | { | |
106 | case 1: | |
107 | return *field; | |
108 | ||
109 | case 2: | |
110 | return ((unsigned int) (field[1])) | (((int) (field[0])) << 8); | |
111 | ||
112 | case 4: | |
113 | return ((unsigned long) (field[3])) | |
114 | | (((unsigned long) (field[2])) << 8) | |
115 | | (((unsigned long) (field[1])) << 16) | |
116 | | (((unsigned long) (field[0])) << 24); | |
117 | ||
118 | case 8: | |
119 | if (sizeof (dwarf_vma) == 8) | |
120 | return ((dwarf_vma) (field[7])) | |
121 | | (((dwarf_vma) (field[6])) << 8) | |
122 | | (((dwarf_vma) (field[5])) << 16) | |
123 | | (((dwarf_vma) (field[4])) << 24) | |
124 | | (((dwarf_vma) (field[3])) << 32) | |
125 | | (((dwarf_vma) (field[2])) << 40) | |
126 | | (((dwarf_vma) (field[1])) << 48) | |
127 | | (((dwarf_vma) (field[0])) << 56); | |
128 | else if (sizeof (dwarf_vma) == 4) | |
129 | { | |
130 | /* Although we are extracing data from an 8 byte wide field, | |
131 | we are returning only 4 bytes of data. */ | |
132 | field += 4; | |
133 | return ((unsigned long) (field[3])) | |
134 | | (((unsigned long) (field[2])) << 8) | |
135 | | (((unsigned long) (field[1])) << 16) | |
136 | | (((unsigned long) (field[0])) << 24); | |
137 | } | |
138 | ||
139 | default: | |
140 | error (_("Unhandled data length: %d\n"), size); | |
141 | abort (); | |
142 | } | |
143 | } | |
144 | ||
145 | static dwarf_vma | |
146 | byte_get_signed (unsigned char *field, int size) | |
147 | { | |
148 | dwarf_vma x = byte_get (field, size); | |
149 | ||
150 | switch (size) | |
151 | { | |
152 | case 1: | |
153 | return (x ^ 0x80) - 0x80; | |
154 | case 2: | |
155 | return (x ^ 0x8000) - 0x8000; | |
156 | case 4: | |
157 | return (x ^ 0x80000000) - 0x80000000; | |
158 | case 8: | |
159 | return x; | |
160 | default: | |
161 | abort (); | |
162 | } | |
163 | } | |
164 | ||
2d9472a2 NC |
165 | /* Print a dwarf_vma value (typically an address, offset or length) in |
166 | hexadecimal format, followed by a space. The length of the value (and | |
167 | hence the precision displayed) is determined by the byte_size parameter. */ | |
168 | ||
169 | static void | |
170 | print_dwarf_vma (dwarf_vma val, unsigned byte_size) | |
171 | { | |
172 | static char buff[18]; | |
173 | ||
174 | /* Printf does not have a way of specifiying a maximum field width for an | |
175 | integer value, so we print the full value into a buffer and then select | |
176 | the precision we need. */ | |
177 | #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2) | |
178 | snprintf (buff, sizeof (buff), "%16.16llx ", val); | |
179 | #else | |
180 | snprintf (buff, sizeof (buff), "%16.16lx ", val); | |
181 | #endif | |
182 | ||
183 | printf (buff + (byte_size == 4 ? 8 : 0)); | |
184 | } | |
185 | ||
19e6b90e L |
186 | static unsigned long int |
187 | read_leb128 (unsigned char *data, unsigned int *length_return, int sign) | |
188 | { | |
189 | unsigned long int result = 0; | |
190 | unsigned int num_read = 0; | |
191 | unsigned int shift = 0; | |
192 | unsigned char byte; | |
193 | ||
194 | do | |
195 | { | |
196 | byte = *data++; | |
197 | num_read++; | |
198 | ||
199 | result |= ((unsigned long int) (byte & 0x7f)) << shift; | |
200 | ||
201 | shift += 7; | |
202 | ||
203 | } | |
204 | while (byte & 0x80); | |
205 | ||
206 | if (length_return != NULL) | |
207 | *length_return = num_read; | |
208 | ||
209 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
210 | result |= -1L << shift; | |
211 | ||
212 | return result; | |
213 | } | |
214 | ||
215 | typedef struct State_Machine_Registers | |
216 | { | |
217 | unsigned long address; | |
218 | unsigned int file; | |
219 | unsigned int line; | |
220 | unsigned int column; | |
221 | int is_stmt; | |
222 | int basic_block; | |
223 | int end_sequence; | |
224 | /* This variable hold the number of the last entry seen | |
225 | in the File Table. */ | |
226 | unsigned int last_file_entry; | |
227 | } SMR; | |
228 | ||
229 | static SMR state_machine_regs; | |
230 | ||
231 | static void | |
232 | reset_state_machine (int is_stmt) | |
233 | { | |
234 | state_machine_regs.address = 0; | |
235 | state_machine_regs.file = 1; | |
236 | state_machine_regs.line = 1; | |
237 | state_machine_regs.column = 0; | |
238 | state_machine_regs.is_stmt = is_stmt; | |
239 | state_machine_regs.basic_block = 0; | |
240 | state_machine_regs.end_sequence = 0; | |
241 | state_machine_regs.last_file_entry = 0; | |
242 | } | |
243 | ||
244 | /* Handled an extend line op. | |
245 | Returns the number of bytes read. */ | |
246 | ||
247 | static int | |
1617e571 | 248 | process_extended_line_op (unsigned char *data, int is_stmt) |
19e6b90e L |
249 | { |
250 | unsigned char op_code; | |
251 | unsigned int bytes_read; | |
252 | unsigned int len; | |
253 | unsigned char *name; | |
254 | unsigned long adr; | |
255 | ||
256 | len = read_leb128 (data, & bytes_read, 0); | |
257 | data += bytes_read; | |
258 | ||
259 | if (len == 0) | |
260 | { | |
261 | warn (_("badly formed extended line op encountered!\n")); | |
262 | return bytes_read; | |
263 | } | |
264 | ||
265 | len += bytes_read; | |
266 | op_code = *data++; | |
267 | ||
268 | printf (_(" Extended opcode %d: "), op_code); | |
269 | ||
270 | switch (op_code) | |
271 | { | |
272 | case DW_LNE_end_sequence: | |
273 | printf (_("End of Sequence\n\n")); | |
274 | reset_state_machine (is_stmt); | |
275 | break; | |
276 | ||
277 | case DW_LNE_set_address: | |
1617e571 | 278 | adr = byte_get (data, len - bytes_read - 1); |
19e6b90e L |
279 | printf (_("set Address to 0x%lx\n"), adr); |
280 | state_machine_regs.address = adr; | |
281 | break; | |
282 | ||
283 | case DW_LNE_define_file: | |
284 | printf (_(" define new File Table entry\n")); | |
285 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
286 | ||
287 | printf (_(" %d\t"), ++state_machine_regs.last_file_entry); | |
288 | name = data; | |
289 | data += strlen ((char *) data) + 1; | |
290 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
291 | data += bytes_read; | |
292 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
293 | data += bytes_read; | |
294 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
295 | printf (_("%s\n\n"), name); | |
296 | break; | |
297 | ||
e2a0d921 NC |
298 | /* HP extensions. */ |
299 | case DW_LNE_HP_negate_is_UV_update: | |
300 | printf ("DW_LNE_HP_negate_is_UV_update"); | |
301 | break; | |
302 | case DW_LNE_HP_push_context: | |
303 | printf ("DW_LNE_HP_push_context"); | |
304 | break; | |
305 | case DW_LNE_HP_pop_context: | |
306 | printf ("DW_LNE_HP_pop_context"); | |
307 | break; | |
308 | case DW_LNE_HP_set_file_line_column: | |
309 | printf ("DW_LNE_HP_set_file_line_column"); | |
310 | break; | |
311 | case DW_LNE_HP_set_routine_name: | |
312 | printf ("DW_LNE_HP_set_routine_name"); | |
313 | break; | |
314 | case DW_LNE_HP_set_sequence: | |
315 | printf ("DW_LNE_HP_set_sequence"); | |
316 | break; | |
317 | case DW_LNE_HP_negate_post_semantics: | |
318 | printf ("DW_LNE_HP_negate_post_semantics"); | |
319 | break; | |
320 | case DW_LNE_HP_negate_function_exit: | |
321 | printf ("DW_LNE_HP_negate_function_exit"); | |
322 | break; | |
323 | case DW_LNE_HP_negate_front_end_logical: | |
324 | printf ("DW_LNE_HP_negate_front_end_logical"); | |
325 | break; | |
326 | case DW_LNE_HP_define_proc: | |
327 | printf ("DW_LNE_HP_define_proc"); | |
328 | break; | |
329 | ||
19e6b90e | 330 | default: |
e2a0d921 NC |
331 | if (op_code >= DW_LNE_lo_user |
332 | /* The test against DW_LNW_hi_user is redundant due to | |
333 | the limited range of the unsigned char data type used | |
334 | for op_code. */ | |
335 | /*&& op_code <= DW_LNE_hi_user*/) | |
336 | printf (_("user defined: length %d\n"), len - bytes_read); | |
337 | else | |
338 | printf (_("UNKNOWN: length %d\n"), len - bytes_read); | |
19e6b90e L |
339 | break; |
340 | } | |
341 | ||
342 | return len; | |
343 | } | |
344 | ||
345 | static const char * | |
346 | fetch_indirect_string (unsigned long offset) | |
347 | { | |
348 | struct dwarf_section *section = &debug_displays [str].section; | |
349 | ||
350 | if (section->start == NULL) | |
351 | return _("<no .debug_str section>"); | |
352 | ||
bfe2612a L |
353 | /* DWARF sections under Mach-O have non-zero addresses. */ |
354 | offset -= section->address; | |
19e6b90e L |
355 | if (offset > section->size) |
356 | { | |
357 | warn (_("DW_FORM_strp offset too big: %lx\n"), offset); | |
358 | return _("<offset is too big>"); | |
359 | } | |
360 | ||
361 | return (const char *) section->start + offset; | |
362 | } | |
363 | ||
364 | /* FIXME: There are better and more efficient ways to handle | |
365 | these structures. For now though, I just want something that | |
366 | is simple to implement. */ | |
367 | typedef struct abbrev_attr | |
368 | { | |
369 | unsigned long attribute; | |
370 | unsigned long form; | |
371 | struct abbrev_attr *next; | |
372 | } | |
373 | abbrev_attr; | |
374 | ||
375 | typedef struct abbrev_entry | |
376 | { | |
377 | unsigned long entry; | |
378 | unsigned long tag; | |
379 | int children; | |
380 | struct abbrev_attr *first_attr; | |
381 | struct abbrev_attr *last_attr; | |
382 | struct abbrev_entry *next; | |
383 | } | |
384 | abbrev_entry; | |
385 | ||
386 | static abbrev_entry *first_abbrev = NULL; | |
387 | static abbrev_entry *last_abbrev = NULL; | |
388 | ||
389 | static void | |
390 | free_abbrevs (void) | |
391 | { | |
392 | abbrev_entry *abbrev; | |
393 | ||
394 | for (abbrev = first_abbrev; abbrev;) | |
395 | { | |
396 | abbrev_entry *next = abbrev->next; | |
397 | abbrev_attr *attr; | |
398 | ||
399 | for (attr = abbrev->first_attr; attr;) | |
400 | { | |
401 | abbrev_attr *next = attr->next; | |
402 | ||
403 | free (attr); | |
404 | attr = next; | |
405 | } | |
406 | ||
407 | free (abbrev); | |
408 | abbrev = next; | |
409 | } | |
410 | ||
411 | last_abbrev = first_abbrev = NULL; | |
412 | } | |
413 | ||
414 | static void | |
415 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
416 | { | |
417 | abbrev_entry *entry; | |
418 | ||
419 | entry = malloc (sizeof (*entry)); | |
420 | ||
421 | if (entry == NULL) | |
422 | /* ugg */ | |
423 | return; | |
424 | ||
425 | entry->entry = number; | |
426 | entry->tag = tag; | |
427 | entry->children = children; | |
428 | entry->first_attr = NULL; | |
429 | entry->last_attr = NULL; | |
430 | entry->next = NULL; | |
431 | ||
432 | if (first_abbrev == NULL) | |
433 | first_abbrev = entry; | |
434 | else | |
435 | last_abbrev->next = entry; | |
436 | ||
437 | last_abbrev = entry; | |
438 | } | |
439 | ||
440 | static void | |
441 | add_abbrev_attr (unsigned long attribute, unsigned long form) | |
442 | { | |
443 | abbrev_attr *attr; | |
444 | ||
445 | attr = malloc (sizeof (*attr)); | |
446 | ||
447 | if (attr == NULL) | |
448 | /* ugg */ | |
449 | return; | |
450 | ||
451 | attr->attribute = attribute; | |
452 | attr->form = form; | |
453 | attr->next = NULL; | |
454 | ||
455 | if (last_abbrev->first_attr == NULL) | |
456 | last_abbrev->first_attr = attr; | |
457 | else | |
458 | last_abbrev->last_attr->next = attr; | |
459 | ||
460 | last_abbrev->last_attr = attr; | |
461 | } | |
462 | ||
463 | /* Processes the (partial) contents of a .debug_abbrev section. | |
464 | Returns NULL if the end of the section was encountered. | |
465 | Returns the address after the last byte read if the end of | |
466 | an abbreviation set was found. */ | |
467 | ||
468 | static unsigned char * | |
469 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
470 | { | |
471 | if (first_abbrev != NULL) | |
472 | return NULL; | |
473 | ||
474 | while (start < end) | |
475 | { | |
476 | unsigned int bytes_read; | |
477 | unsigned long entry; | |
478 | unsigned long tag; | |
479 | unsigned long attribute; | |
480 | int children; | |
481 | ||
482 | entry = read_leb128 (start, & bytes_read, 0); | |
483 | start += bytes_read; | |
484 | ||
485 | /* A single zero is supposed to end the section according | |
486 | to the standard. If there's more, then signal that to | |
487 | the caller. */ | |
488 | if (entry == 0) | |
489 | return start == end ? NULL : start; | |
490 | ||
491 | tag = read_leb128 (start, & bytes_read, 0); | |
492 | start += bytes_read; | |
493 | ||
494 | children = *start++; | |
495 | ||
496 | add_abbrev (entry, tag, children); | |
497 | ||
498 | do | |
499 | { | |
500 | unsigned long form; | |
501 | ||
502 | attribute = read_leb128 (start, & bytes_read, 0); | |
503 | start += bytes_read; | |
504 | ||
505 | form = read_leb128 (start, & bytes_read, 0); | |
506 | start += bytes_read; | |
507 | ||
508 | if (attribute != 0) | |
509 | add_abbrev_attr (attribute, form); | |
510 | } | |
511 | while (attribute != 0); | |
512 | } | |
513 | ||
514 | return NULL; | |
515 | } | |
516 | ||
517 | static char * | |
518 | get_TAG_name (unsigned long tag) | |
519 | { | |
520 | switch (tag) | |
521 | { | |
522 | case DW_TAG_padding: return "DW_TAG_padding"; | |
523 | case DW_TAG_array_type: return "DW_TAG_array_type"; | |
524 | case DW_TAG_class_type: return "DW_TAG_class_type"; | |
525 | case DW_TAG_entry_point: return "DW_TAG_entry_point"; | |
526 | case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type"; | |
527 | case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter"; | |
528 | case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration"; | |
529 | case DW_TAG_label: return "DW_TAG_label"; | |
530 | case DW_TAG_lexical_block: return "DW_TAG_lexical_block"; | |
531 | case DW_TAG_member: return "DW_TAG_member"; | |
532 | case DW_TAG_pointer_type: return "DW_TAG_pointer_type"; | |
533 | case DW_TAG_reference_type: return "DW_TAG_reference_type"; | |
534 | case DW_TAG_compile_unit: return "DW_TAG_compile_unit"; | |
535 | case DW_TAG_string_type: return "DW_TAG_string_type"; | |
536 | case DW_TAG_structure_type: return "DW_TAG_structure_type"; | |
537 | case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type"; | |
538 | case DW_TAG_typedef: return "DW_TAG_typedef"; | |
539 | case DW_TAG_union_type: return "DW_TAG_union_type"; | |
540 | case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters"; | |
541 | case DW_TAG_variant: return "DW_TAG_variant"; | |
542 | case DW_TAG_common_block: return "DW_TAG_common_block"; | |
543 | case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion"; | |
544 | case DW_TAG_inheritance: return "DW_TAG_inheritance"; | |
545 | case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine"; | |
546 | case DW_TAG_module: return "DW_TAG_module"; | |
547 | case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type"; | |
548 | case DW_TAG_set_type: return "DW_TAG_set_type"; | |
549 | case DW_TAG_subrange_type: return "DW_TAG_subrange_type"; | |
550 | case DW_TAG_with_stmt: return "DW_TAG_with_stmt"; | |
551 | case DW_TAG_access_declaration: return "DW_TAG_access_declaration"; | |
552 | case DW_TAG_base_type: return "DW_TAG_base_type"; | |
553 | case DW_TAG_catch_block: return "DW_TAG_catch_block"; | |
554 | case DW_TAG_const_type: return "DW_TAG_const_type"; | |
555 | case DW_TAG_constant: return "DW_TAG_constant"; | |
556 | case DW_TAG_enumerator: return "DW_TAG_enumerator"; | |
557 | case DW_TAG_file_type: return "DW_TAG_file_type"; | |
558 | case DW_TAG_friend: return "DW_TAG_friend"; | |
559 | case DW_TAG_namelist: return "DW_TAG_namelist"; | |
560 | case DW_TAG_namelist_item: return "DW_TAG_namelist_item"; | |
561 | case DW_TAG_packed_type: return "DW_TAG_packed_type"; | |
562 | case DW_TAG_subprogram: return "DW_TAG_subprogram"; | |
563 | case DW_TAG_template_type_param: return "DW_TAG_template_type_param"; | |
564 | case DW_TAG_template_value_param: return "DW_TAG_template_value_param"; | |
565 | case DW_TAG_thrown_type: return "DW_TAG_thrown_type"; | |
566 | case DW_TAG_try_block: return "DW_TAG_try_block"; | |
567 | case DW_TAG_variant_part: return "DW_TAG_variant_part"; | |
568 | case DW_TAG_variable: return "DW_TAG_variable"; | |
569 | case DW_TAG_volatile_type: return "DW_TAG_volatile_type"; | |
570 | case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop"; | |
571 | case DW_TAG_format_label: return "DW_TAG_format_label"; | |
572 | case DW_TAG_function_template: return "DW_TAG_function_template"; | |
573 | case DW_TAG_class_template: return "DW_TAG_class_template"; | |
574 | /* DWARF 2.1 values. */ | |
575 | case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure"; | |
576 | case DW_TAG_restrict_type: return "DW_TAG_restrict_type"; | |
577 | case DW_TAG_interface_type: return "DW_TAG_interface_type"; | |
578 | case DW_TAG_namespace: return "DW_TAG_namespace"; | |
579 | case DW_TAG_imported_module: return "DW_TAG_imported_module"; | |
580 | case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type"; | |
581 | case DW_TAG_partial_unit: return "DW_TAG_partial_unit"; | |
582 | case DW_TAG_imported_unit: return "DW_TAG_imported_unit"; | |
583 | /* UPC values. */ | |
584 | case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type"; | |
585 | case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type"; | |
586 | case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type"; | |
587 | default: | |
588 | { | |
589 | static char buffer[100]; | |
590 | ||
591 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag); | |
592 | return buffer; | |
593 | } | |
594 | } | |
595 | } | |
596 | ||
597 | static char * | |
598 | get_FORM_name (unsigned long form) | |
599 | { | |
600 | switch (form) | |
601 | { | |
602 | case DW_FORM_addr: return "DW_FORM_addr"; | |
603 | case DW_FORM_block2: return "DW_FORM_block2"; | |
604 | case DW_FORM_block4: return "DW_FORM_block4"; | |
605 | case DW_FORM_data2: return "DW_FORM_data2"; | |
606 | case DW_FORM_data4: return "DW_FORM_data4"; | |
607 | case DW_FORM_data8: return "DW_FORM_data8"; | |
608 | case DW_FORM_string: return "DW_FORM_string"; | |
609 | case DW_FORM_block: return "DW_FORM_block"; | |
610 | case DW_FORM_block1: return "DW_FORM_block1"; | |
611 | case DW_FORM_data1: return "DW_FORM_data1"; | |
612 | case DW_FORM_flag: return "DW_FORM_flag"; | |
613 | case DW_FORM_sdata: return "DW_FORM_sdata"; | |
614 | case DW_FORM_strp: return "DW_FORM_strp"; | |
615 | case DW_FORM_udata: return "DW_FORM_udata"; | |
616 | case DW_FORM_ref_addr: return "DW_FORM_ref_addr"; | |
617 | case DW_FORM_ref1: return "DW_FORM_ref1"; | |
618 | case DW_FORM_ref2: return "DW_FORM_ref2"; | |
619 | case DW_FORM_ref4: return "DW_FORM_ref4"; | |
620 | case DW_FORM_ref8: return "DW_FORM_ref8"; | |
621 | case DW_FORM_ref_udata: return "DW_FORM_ref_udata"; | |
622 | case DW_FORM_indirect: return "DW_FORM_indirect"; | |
623 | default: | |
624 | { | |
625 | static char buffer[100]; | |
626 | ||
627 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); | |
628 | return buffer; | |
629 | } | |
630 | } | |
631 | } | |
632 | ||
633 | static unsigned char * | |
634 | display_block (unsigned char *data, unsigned long length) | |
635 | { | |
636 | printf (_(" %lu byte block: "), length); | |
637 | ||
638 | while (length --) | |
639 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
640 | ||
641 | return data; | |
642 | } | |
643 | ||
644 | static int | |
645 | decode_location_expression (unsigned char * data, | |
646 | unsigned int pointer_size, | |
647 | unsigned long length, | |
648 | unsigned long cu_offset) | |
649 | { | |
650 | unsigned op; | |
651 | unsigned int bytes_read; | |
652 | unsigned long uvalue; | |
653 | unsigned char *end = data + length; | |
654 | int need_frame_base = 0; | |
655 | ||
656 | while (data < end) | |
657 | { | |
658 | op = *data++; | |
659 | ||
660 | switch (op) | |
661 | { | |
662 | case DW_OP_addr: | |
663 | printf ("DW_OP_addr: %lx", | |
664 | (unsigned long) byte_get (data, pointer_size)); | |
665 | data += pointer_size; | |
666 | break; | |
667 | case DW_OP_deref: | |
668 | printf ("DW_OP_deref"); | |
669 | break; | |
670 | case DW_OP_const1u: | |
671 | printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1)); | |
672 | break; | |
673 | case DW_OP_const1s: | |
674 | printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1)); | |
675 | break; | |
676 | case DW_OP_const2u: | |
677 | printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2)); | |
678 | data += 2; | |
679 | break; | |
680 | case DW_OP_const2s: | |
681 | printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2)); | |
682 | data += 2; | |
683 | break; | |
684 | case DW_OP_const4u: | |
685 | printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4)); | |
686 | data += 4; | |
687 | break; | |
688 | case DW_OP_const4s: | |
689 | printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4)); | |
690 | data += 4; | |
691 | break; | |
692 | case DW_OP_const8u: | |
693 | printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4), | |
694 | (unsigned long) byte_get (data + 4, 4)); | |
695 | data += 8; | |
696 | break; | |
697 | case DW_OP_const8s: | |
698 | printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4), | |
699 | (long) byte_get (data + 4, 4)); | |
700 | data += 8; | |
701 | break; | |
702 | case DW_OP_constu: | |
703 | printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0)); | |
704 | data += bytes_read; | |
705 | break; | |
706 | case DW_OP_consts: | |
707 | printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1)); | |
708 | data += bytes_read; | |
709 | break; | |
710 | case DW_OP_dup: | |
711 | printf ("DW_OP_dup"); | |
712 | break; | |
713 | case DW_OP_drop: | |
714 | printf ("DW_OP_drop"); | |
715 | break; | |
716 | case DW_OP_over: | |
717 | printf ("DW_OP_over"); | |
718 | break; | |
719 | case DW_OP_pick: | |
720 | printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1)); | |
721 | break; | |
722 | case DW_OP_swap: | |
723 | printf ("DW_OP_swap"); | |
724 | break; | |
725 | case DW_OP_rot: | |
726 | printf ("DW_OP_rot"); | |
727 | break; | |
728 | case DW_OP_xderef: | |
729 | printf ("DW_OP_xderef"); | |
730 | break; | |
731 | case DW_OP_abs: | |
732 | printf ("DW_OP_abs"); | |
733 | break; | |
734 | case DW_OP_and: | |
735 | printf ("DW_OP_and"); | |
736 | break; | |
737 | case DW_OP_div: | |
738 | printf ("DW_OP_div"); | |
739 | break; | |
740 | case DW_OP_minus: | |
741 | printf ("DW_OP_minus"); | |
742 | break; | |
743 | case DW_OP_mod: | |
744 | printf ("DW_OP_mod"); | |
745 | break; | |
746 | case DW_OP_mul: | |
747 | printf ("DW_OP_mul"); | |
748 | break; | |
749 | case DW_OP_neg: | |
750 | printf ("DW_OP_neg"); | |
751 | break; | |
752 | case DW_OP_not: | |
753 | printf ("DW_OP_not"); | |
754 | break; | |
755 | case DW_OP_or: | |
756 | printf ("DW_OP_or"); | |
757 | break; | |
758 | case DW_OP_plus: | |
759 | printf ("DW_OP_plus"); | |
760 | break; | |
761 | case DW_OP_plus_uconst: | |
762 | printf ("DW_OP_plus_uconst: %lu", | |
763 | read_leb128 (data, &bytes_read, 0)); | |
764 | data += bytes_read; | |
765 | break; | |
766 | case DW_OP_shl: | |
767 | printf ("DW_OP_shl"); | |
768 | break; | |
769 | case DW_OP_shr: | |
770 | printf ("DW_OP_shr"); | |
771 | break; | |
772 | case DW_OP_shra: | |
773 | printf ("DW_OP_shra"); | |
774 | break; | |
775 | case DW_OP_xor: | |
776 | printf ("DW_OP_xor"); | |
777 | break; | |
778 | case DW_OP_bra: | |
779 | printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2)); | |
780 | data += 2; | |
781 | break; | |
782 | case DW_OP_eq: | |
783 | printf ("DW_OP_eq"); | |
784 | break; | |
785 | case DW_OP_ge: | |
786 | printf ("DW_OP_ge"); | |
787 | break; | |
788 | case DW_OP_gt: | |
789 | printf ("DW_OP_gt"); | |
790 | break; | |
791 | case DW_OP_le: | |
792 | printf ("DW_OP_le"); | |
793 | break; | |
794 | case DW_OP_lt: | |
795 | printf ("DW_OP_lt"); | |
796 | break; | |
797 | case DW_OP_ne: | |
798 | printf ("DW_OP_ne"); | |
799 | break; | |
800 | case DW_OP_skip: | |
801 | printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2)); | |
802 | data += 2; | |
803 | break; | |
804 | ||
805 | case DW_OP_lit0: | |
806 | case DW_OP_lit1: | |
807 | case DW_OP_lit2: | |
808 | case DW_OP_lit3: | |
809 | case DW_OP_lit4: | |
810 | case DW_OP_lit5: | |
811 | case DW_OP_lit6: | |
812 | case DW_OP_lit7: | |
813 | case DW_OP_lit8: | |
814 | case DW_OP_lit9: | |
815 | case DW_OP_lit10: | |
816 | case DW_OP_lit11: | |
817 | case DW_OP_lit12: | |
818 | case DW_OP_lit13: | |
819 | case DW_OP_lit14: | |
820 | case DW_OP_lit15: | |
821 | case DW_OP_lit16: | |
822 | case DW_OP_lit17: | |
823 | case DW_OP_lit18: | |
824 | case DW_OP_lit19: | |
825 | case DW_OP_lit20: | |
826 | case DW_OP_lit21: | |
827 | case DW_OP_lit22: | |
828 | case DW_OP_lit23: | |
829 | case DW_OP_lit24: | |
830 | case DW_OP_lit25: | |
831 | case DW_OP_lit26: | |
832 | case DW_OP_lit27: | |
833 | case DW_OP_lit28: | |
834 | case DW_OP_lit29: | |
835 | case DW_OP_lit30: | |
836 | case DW_OP_lit31: | |
837 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
838 | break; | |
839 | ||
840 | case DW_OP_reg0: | |
841 | case DW_OP_reg1: | |
842 | case DW_OP_reg2: | |
843 | case DW_OP_reg3: | |
844 | case DW_OP_reg4: | |
845 | case DW_OP_reg5: | |
846 | case DW_OP_reg6: | |
847 | case DW_OP_reg7: | |
848 | case DW_OP_reg8: | |
849 | case DW_OP_reg9: | |
850 | case DW_OP_reg10: | |
851 | case DW_OP_reg11: | |
852 | case DW_OP_reg12: | |
853 | case DW_OP_reg13: | |
854 | case DW_OP_reg14: | |
855 | case DW_OP_reg15: | |
856 | case DW_OP_reg16: | |
857 | case DW_OP_reg17: | |
858 | case DW_OP_reg18: | |
859 | case DW_OP_reg19: | |
860 | case DW_OP_reg20: | |
861 | case DW_OP_reg21: | |
862 | case DW_OP_reg22: | |
863 | case DW_OP_reg23: | |
864 | case DW_OP_reg24: | |
865 | case DW_OP_reg25: | |
866 | case DW_OP_reg26: | |
867 | case DW_OP_reg27: | |
868 | case DW_OP_reg28: | |
869 | case DW_OP_reg29: | |
870 | case DW_OP_reg30: | |
871 | case DW_OP_reg31: | |
872 | printf ("DW_OP_reg%d", op - DW_OP_reg0); | |
873 | break; | |
874 | ||
875 | case DW_OP_breg0: | |
876 | case DW_OP_breg1: | |
877 | case DW_OP_breg2: | |
878 | case DW_OP_breg3: | |
879 | case DW_OP_breg4: | |
880 | case DW_OP_breg5: | |
881 | case DW_OP_breg6: | |
882 | case DW_OP_breg7: | |
883 | case DW_OP_breg8: | |
884 | case DW_OP_breg9: | |
885 | case DW_OP_breg10: | |
886 | case DW_OP_breg11: | |
887 | case DW_OP_breg12: | |
888 | case DW_OP_breg13: | |
889 | case DW_OP_breg14: | |
890 | case DW_OP_breg15: | |
891 | case DW_OP_breg16: | |
892 | case DW_OP_breg17: | |
893 | case DW_OP_breg18: | |
894 | case DW_OP_breg19: | |
895 | case DW_OP_breg20: | |
896 | case DW_OP_breg21: | |
897 | case DW_OP_breg22: | |
898 | case DW_OP_breg23: | |
899 | case DW_OP_breg24: | |
900 | case DW_OP_breg25: | |
901 | case DW_OP_breg26: | |
902 | case DW_OP_breg27: | |
903 | case DW_OP_breg28: | |
904 | case DW_OP_breg29: | |
905 | case DW_OP_breg30: | |
906 | case DW_OP_breg31: | |
907 | printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0, | |
908 | read_leb128 (data, &bytes_read, 1)); | |
909 | data += bytes_read; | |
910 | break; | |
911 | ||
912 | case DW_OP_regx: | |
913 | printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0)); | |
914 | data += bytes_read; | |
915 | break; | |
916 | case DW_OP_fbreg: | |
917 | need_frame_base = 1; | |
918 | printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1)); | |
919 | data += bytes_read; | |
920 | break; | |
921 | case DW_OP_bregx: | |
922 | uvalue = read_leb128 (data, &bytes_read, 0); | |
923 | data += bytes_read; | |
924 | printf ("DW_OP_bregx: %lu %ld", uvalue, | |
925 | read_leb128 (data, &bytes_read, 1)); | |
926 | data += bytes_read; | |
927 | break; | |
928 | case DW_OP_piece: | |
929 | printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0)); | |
930 | data += bytes_read; | |
931 | break; | |
932 | case DW_OP_deref_size: | |
933 | printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1)); | |
934 | break; | |
935 | case DW_OP_xderef_size: | |
936 | printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1)); | |
937 | break; | |
938 | case DW_OP_nop: | |
939 | printf ("DW_OP_nop"); | |
940 | break; | |
941 | ||
942 | /* DWARF 3 extensions. */ | |
943 | case DW_OP_push_object_address: | |
944 | printf ("DW_OP_push_object_address"); | |
945 | break; | |
946 | case DW_OP_call2: | |
947 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
948 | this ought to be an 8-byte wide computation. */ | |
949 | printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2) + cu_offset); | |
950 | data += 2; | |
951 | break; | |
952 | case DW_OP_call4: | |
953 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
954 | this ought to be an 8-byte wide computation. */ | |
955 | printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4) + cu_offset); | |
956 | data += 4; | |
957 | break; | |
958 | case DW_OP_call_ref: | |
e2a0d921 NC |
959 | /* XXX: Strictly speaking for 64-bit DWARF3 files |
960 | this ought to be an 8-byte wide computation. */ | |
961 | printf ("DW_OP_call_ref: <%lx>", (long) byte_get (data, 4) + cu_offset); | |
962 | data += 4; | |
19e6b90e | 963 | break; |
a87b0a59 NS |
964 | case DW_OP_form_tls_address: |
965 | printf ("DW_OP_form_tls_address"); | |
966 | break; | |
e2a0d921 NC |
967 | case DW_OP_call_frame_cfa: |
968 | printf ("DW_OP_call_frame_cfa"); | |
969 | break; | |
970 | case DW_OP_bit_piece: | |
971 | printf ("DW_OP_bit_piece: "); | |
972 | printf ("size: %lu ", read_leb128 (data, &bytes_read, 0)); | |
973 | data += bytes_read; | |
974 | printf ("offset: %lu ", read_leb128 (data, &bytes_read, 0)); | |
975 | data += bytes_read; | |
976 | break; | |
19e6b90e L |
977 | |
978 | /* GNU extensions. */ | |
979 | case DW_OP_GNU_push_tls_address: | |
e2a0d921 NC |
980 | printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"); |
981 | break; | |
982 | case DW_OP_GNU_uninit: | |
983 | printf ("DW_OP_GNU_uninit"); | |
984 | /* FIXME: Is there data associated with this OP ? */ | |
985 | break; | |
986 | ||
987 | /* HP extensions. */ | |
988 | case DW_OP_HP_is_value: | |
989 | printf ("DW_OP_HP_is_value"); | |
990 | /* FIXME: Is there data associated with this OP ? */ | |
991 | break; | |
992 | case DW_OP_HP_fltconst4: | |
993 | printf ("DW_OP_HP_fltconst4"); | |
994 | /* FIXME: Is there data associated with this OP ? */ | |
995 | break; | |
996 | case DW_OP_HP_fltconst8: | |
997 | printf ("DW_OP_HP_fltconst8"); | |
998 | /* FIXME: Is there data associated with this OP ? */ | |
999 | break; | |
1000 | case DW_OP_HP_mod_range: | |
1001 | printf ("DW_OP_HP_mod_range"); | |
1002 | /* FIXME: Is there data associated with this OP ? */ | |
1003 | break; | |
1004 | case DW_OP_HP_unmod_range: | |
1005 | printf ("DW_OP_HP_unmod_range"); | |
1006 | /* FIXME: Is there data associated with this OP ? */ | |
1007 | break; | |
1008 | case DW_OP_HP_tls: | |
1009 | printf ("DW_OP_HP_tls"); | |
1010 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1011 | break; |
1012 | ||
1013 | default: | |
1014 | if (op >= DW_OP_lo_user | |
1015 | && op <= DW_OP_hi_user) | |
1016 | printf (_("(User defined location op)")); | |
1017 | else | |
1018 | printf (_("(Unknown location op)")); | |
1019 | /* No way to tell where the next op is, so just bail. */ | |
1020 | return need_frame_base; | |
1021 | } | |
1022 | ||
1023 | /* Separate the ops. */ | |
1024 | if (data < end) | |
1025 | printf ("; "); | |
1026 | } | |
1027 | ||
1028 | return need_frame_base; | |
1029 | } | |
1030 | ||
1031 | static unsigned char * | |
6e3d6dc1 NC |
1032 | read_and_display_attr_value (unsigned long attribute, |
1033 | unsigned long form, | |
ec4d4525 | 1034 | unsigned char * data, |
6e3d6dc1 NC |
1035 | unsigned long cu_offset, |
1036 | unsigned long pointer_size, | |
1037 | unsigned long offset_size, | |
1038 | int dwarf_version, | |
1039 | debug_info * debug_info_p, | |
1040 | int do_loc, | |
1041 | struct dwarf_section * section) | |
19e6b90e L |
1042 | { |
1043 | unsigned long uvalue = 0; | |
1044 | unsigned char *block_start = NULL; | |
6e3d6dc1 | 1045 | unsigned char * orig_data = data; |
19e6b90e L |
1046 | unsigned int bytes_read; |
1047 | ||
1048 | switch (form) | |
1049 | { | |
1050 | default: | |
1051 | break; | |
1052 | ||
1053 | case DW_FORM_ref_addr: | |
1054 | if (dwarf_version == 2) | |
1055 | { | |
1056 | uvalue = byte_get (data, pointer_size); | |
1057 | data += pointer_size; | |
1058 | } | |
1059 | else if (dwarf_version == 3) | |
1060 | { | |
1061 | uvalue = byte_get (data, offset_size); | |
1062 | data += offset_size; | |
1063 | } | |
1064 | else | |
1065 | { | |
1066 | error (_("Internal error: DWARF version is not 2 or 3.\n")); | |
1067 | } | |
1068 | break; | |
1069 | ||
1070 | case DW_FORM_addr: | |
1071 | uvalue = byte_get (data, pointer_size); | |
1072 | data += pointer_size; | |
1073 | break; | |
1074 | ||
1075 | case DW_FORM_strp: | |
1076 | uvalue = byte_get (data, offset_size); | |
1077 | data += offset_size; | |
1078 | break; | |
1079 | ||
1080 | case DW_FORM_ref1: | |
1081 | case DW_FORM_flag: | |
1082 | case DW_FORM_data1: | |
1083 | uvalue = byte_get (data++, 1); | |
1084 | break; | |
1085 | ||
1086 | case DW_FORM_ref2: | |
1087 | case DW_FORM_data2: | |
1088 | uvalue = byte_get (data, 2); | |
1089 | data += 2; | |
1090 | break; | |
1091 | ||
1092 | case DW_FORM_ref4: | |
1093 | case DW_FORM_data4: | |
1094 | uvalue = byte_get (data, 4); | |
1095 | data += 4; | |
1096 | break; | |
1097 | ||
1098 | case DW_FORM_sdata: | |
1099 | uvalue = read_leb128 (data, & bytes_read, 1); | |
1100 | data += bytes_read; | |
1101 | break; | |
1102 | ||
1103 | case DW_FORM_ref_udata: | |
1104 | case DW_FORM_udata: | |
1105 | uvalue = read_leb128 (data, & bytes_read, 0); | |
1106 | data += bytes_read; | |
1107 | break; | |
1108 | ||
1109 | case DW_FORM_indirect: | |
1110 | form = read_leb128 (data, & bytes_read, 0); | |
1111 | data += bytes_read; | |
1112 | if (!do_loc) | |
1113 | printf (" %s", get_FORM_name (form)); | |
1114 | return read_and_display_attr_value (attribute, form, data, | |
1115 | cu_offset, pointer_size, | |
1116 | offset_size, dwarf_version, | |
ec4d4525 | 1117 | debug_info_p, do_loc, |
6e3d6dc1 | 1118 | section); |
19e6b90e L |
1119 | } |
1120 | ||
1121 | switch (form) | |
1122 | { | |
1123 | case DW_FORM_ref_addr: | |
1124 | if (!do_loc) | |
ec4d4525 | 1125 | printf (" <0x%lx>", uvalue); |
19e6b90e L |
1126 | break; |
1127 | ||
1128 | case DW_FORM_ref1: | |
1129 | case DW_FORM_ref2: | |
1130 | case DW_FORM_ref4: | |
1131 | case DW_FORM_ref_udata: | |
1132 | if (!do_loc) | |
ec4d4525 | 1133 | printf (" <0x%lx>", uvalue + cu_offset); |
19e6b90e L |
1134 | break; |
1135 | ||
1136 | case DW_FORM_data4: | |
1137 | case DW_FORM_addr: | |
1138 | if (!do_loc) | |
ec4d4525 | 1139 | printf (" 0x%lx", uvalue); |
19e6b90e L |
1140 | break; |
1141 | ||
1142 | case DW_FORM_flag: | |
1143 | case DW_FORM_data1: | |
1144 | case DW_FORM_data2: | |
1145 | case DW_FORM_sdata: | |
1146 | case DW_FORM_udata: | |
1147 | if (!do_loc) | |
1148 | printf (" %ld", uvalue); | |
1149 | break; | |
1150 | ||
1151 | case DW_FORM_ref8: | |
1152 | case DW_FORM_data8: | |
1153 | if (!do_loc) | |
1154 | { | |
1155 | uvalue = byte_get (data, 4); | |
ec4d4525 NC |
1156 | printf (" 0x%lx", uvalue); |
1157 | printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4)); | |
19e6b90e L |
1158 | } |
1159 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
1160 | && num_debug_info_entries == 0) | |
1161 | { | |
1162 | if (sizeof (uvalue) == 8) | |
1163 | uvalue = byte_get (data, 8); | |
1164 | else | |
1165 | error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n")); | |
1166 | } | |
1167 | data += 8; | |
1168 | break; | |
1169 | ||
1170 | case DW_FORM_string: | |
1171 | if (!do_loc) | |
1172 | printf (" %s", data); | |
1173 | data += strlen ((char *) data) + 1; | |
1174 | break; | |
1175 | ||
1176 | case DW_FORM_block: | |
1177 | uvalue = read_leb128 (data, & bytes_read, 0); | |
1178 | block_start = data + bytes_read; | |
1179 | if (do_loc) | |
1180 | data = block_start + uvalue; | |
1181 | else | |
1182 | data = display_block (block_start, uvalue); | |
1183 | break; | |
1184 | ||
1185 | case DW_FORM_block1: | |
1186 | uvalue = byte_get (data, 1); | |
1187 | block_start = data + 1; | |
1188 | if (do_loc) | |
1189 | data = block_start + uvalue; | |
1190 | else | |
1191 | data = display_block (block_start, uvalue); | |
1192 | break; | |
1193 | ||
1194 | case DW_FORM_block2: | |
1195 | uvalue = byte_get (data, 2); | |
1196 | block_start = data + 2; | |
1197 | if (do_loc) | |
1198 | data = block_start + uvalue; | |
1199 | else | |
1200 | data = display_block (block_start, uvalue); | |
1201 | break; | |
1202 | ||
1203 | case DW_FORM_block4: | |
1204 | uvalue = byte_get (data, 4); | |
1205 | block_start = data + 4; | |
1206 | if (do_loc) | |
1207 | data = block_start + uvalue; | |
1208 | else | |
1209 | data = display_block (block_start, uvalue); | |
1210 | break; | |
1211 | ||
1212 | case DW_FORM_strp: | |
1213 | if (!do_loc) | |
1214 | printf (_(" (indirect string, offset: 0x%lx): %s"), | |
1215 | uvalue, fetch_indirect_string (uvalue)); | |
1216 | break; | |
1217 | ||
1218 | case DW_FORM_indirect: | |
1219 | /* Handled above. */ | |
1220 | break; | |
1221 | ||
1222 | default: | |
1223 | warn (_("Unrecognized form: %lu\n"), form); | |
1224 | break; | |
1225 | } | |
1226 | ||
19e6b90e L |
1227 | if ((do_loc || do_debug_loc || do_debug_ranges) |
1228 | && num_debug_info_entries == 0) | |
1229 | { | |
1230 | switch (attribute) | |
1231 | { | |
1232 | case DW_AT_frame_base: | |
1233 | have_frame_base = 1; | |
1234 | case DW_AT_location: | |
e2a0d921 NC |
1235 | case DW_AT_string_length: |
1236 | case DW_AT_return_addr: | |
19e6b90e L |
1237 | case DW_AT_data_member_location: |
1238 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
1239 | case DW_AT_segment: |
1240 | case DW_AT_static_link: | |
1241 | case DW_AT_use_location: | |
1242 | if (form == DW_FORM_data4 || form == DW_FORM_data8) | |
19e6b90e L |
1243 | { |
1244 | /* Process location list. */ | |
1245 | unsigned int max = debug_info_p->max_loc_offsets; | |
1246 | unsigned int num = debug_info_p->num_loc_offsets; | |
1247 | ||
1248 | if (max == 0 || num >= max) | |
1249 | { | |
1250 | max += 1024; | |
1251 | debug_info_p->loc_offsets | |
1252 | = xcrealloc (debug_info_p->loc_offsets, | |
1253 | max, sizeof (*debug_info_p->loc_offsets)); | |
1254 | debug_info_p->have_frame_base | |
1255 | = xcrealloc (debug_info_p->have_frame_base, | |
1256 | max, sizeof (*debug_info_p->have_frame_base)); | |
1257 | debug_info_p->max_loc_offsets = max; | |
1258 | } | |
1259 | debug_info_p->loc_offsets [num] = uvalue; | |
1260 | debug_info_p->have_frame_base [num] = have_frame_base; | |
1261 | debug_info_p->num_loc_offsets++; | |
1262 | } | |
1263 | break; | |
e2a0d921 | 1264 | |
19e6b90e L |
1265 | case DW_AT_low_pc: |
1266 | if (need_base_address) | |
1267 | debug_info_p->base_address = uvalue; | |
1268 | break; | |
1269 | ||
1270 | case DW_AT_ranges: | |
1271 | if (form == DW_FORM_data4 || form == DW_FORM_data8) | |
1272 | { | |
1273 | /* Process range list. */ | |
1274 | unsigned int max = debug_info_p->max_range_lists; | |
1275 | unsigned int num = debug_info_p->num_range_lists; | |
1276 | ||
1277 | if (max == 0 || num >= max) | |
1278 | { | |
1279 | max += 1024; | |
1280 | debug_info_p->range_lists | |
1281 | = xcrealloc (debug_info_p->range_lists, | |
1282 | max, sizeof (*debug_info_p->range_lists)); | |
1283 | debug_info_p->max_range_lists = max; | |
1284 | } | |
1285 | debug_info_p->range_lists [num] = uvalue; | |
1286 | debug_info_p->num_range_lists++; | |
1287 | } | |
1288 | break; | |
1289 | ||
1290 | default: | |
1291 | break; | |
1292 | } | |
1293 | } | |
1294 | ||
1295 | if (do_loc) | |
1296 | return data; | |
1297 | ||
ec4d4525 | 1298 | /* For some attributes we can display further information. */ |
19e6b90e L |
1299 | printf ("\t"); |
1300 | ||
1301 | switch (attribute) | |
1302 | { | |
1303 | case DW_AT_inline: | |
1304 | switch (uvalue) | |
1305 | { | |
1306 | case DW_INL_not_inlined: | |
1307 | printf (_("(not inlined)")); | |
1308 | break; | |
1309 | case DW_INL_inlined: | |
1310 | printf (_("(inlined)")); | |
1311 | break; | |
1312 | case DW_INL_declared_not_inlined: | |
1313 | printf (_("(declared as inline but ignored)")); | |
1314 | break; | |
1315 | case DW_INL_declared_inlined: | |
1316 | printf (_("(declared as inline and inlined)")); | |
1317 | break; | |
1318 | default: | |
1319 | printf (_(" (Unknown inline attribute value: %lx)"), uvalue); | |
1320 | break; | |
1321 | } | |
1322 | break; | |
1323 | ||
1324 | case DW_AT_language: | |
1325 | switch (uvalue) | |
1326 | { | |
4b78141a | 1327 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 1328 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
1329 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
1330 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 1331 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
1332 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
1333 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
1334 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
1335 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 1336 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 1337 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 1338 | /* DWARF 2.1 values. */ |
4b78141a | 1339 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
1340 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
1341 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
1342 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
1343 | /* DWARF 3 values. */ |
1344 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
1345 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
1346 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
1347 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
1348 | case DW_LANG_D: printf ("(D)"); break; | |
19e6b90e L |
1349 | /* MIPS extension. */ |
1350 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
1351 | /* UPC extension. */ | |
1352 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
1353 | default: | |
4b78141a NC |
1354 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
1355 | printf ("(implementation defined: %lx)", uvalue); | |
1356 | else | |
1357 | printf ("(Unknown: %lx)", uvalue); | |
19e6b90e L |
1358 | break; |
1359 | } | |
1360 | break; | |
1361 | ||
1362 | case DW_AT_encoding: | |
1363 | switch (uvalue) | |
1364 | { | |
1365 | case DW_ATE_void: printf ("(void)"); break; | |
1366 | case DW_ATE_address: printf ("(machine address)"); break; | |
1367 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
1368 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
1369 | case DW_ATE_float: printf ("(float)"); break; | |
1370 | case DW_ATE_signed: printf ("(signed)"); break; | |
1371 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
1372 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
1373 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 1374 | /* DWARF 2.1 values: */ |
19e6b90e L |
1375 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
1376 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
1377 | /* DWARF 3 values: */ |
1378 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
1379 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
1380 | case DW_ATE_edited: printf ("(edited)"); break; | |
1381 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
1382 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
1383 | /* HP extensions: */ | |
1384 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
1385 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
1386 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
1387 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
1388 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
1389 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
1390 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
1391 | ||
19e6b90e L |
1392 | default: |
1393 | if (uvalue >= DW_ATE_lo_user | |
1394 | && uvalue <= DW_ATE_hi_user) | |
1395 | printf ("(user defined type)"); | |
1396 | else | |
1397 | printf ("(unknown type)"); | |
1398 | break; | |
1399 | } | |
1400 | break; | |
1401 | ||
1402 | case DW_AT_accessibility: | |
1403 | switch (uvalue) | |
1404 | { | |
1405 | case DW_ACCESS_public: printf ("(public)"); break; | |
1406 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
1407 | case DW_ACCESS_private: printf ("(private)"); break; | |
1408 | default: | |
1409 | printf ("(unknown accessibility)"); | |
1410 | break; | |
1411 | } | |
1412 | break; | |
1413 | ||
1414 | case DW_AT_visibility: | |
1415 | switch (uvalue) | |
1416 | { | |
1417 | case DW_VIS_local: printf ("(local)"); break; | |
1418 | case DW_VIS_exported: printf ("(exported)"); break; | |
1419 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
1420 | default: printf ("(unknown visibility)"); break; | |
1421 | } | |
1422 | break; | |
1423 | ||
1424 | case DW_AT_virtuality: | |
1425 | switch (uvalue) | |
1426 | { | |
1427 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
1428 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
1429 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
1430 | default: printf ("(unknown virtuality)"); break; | |
1431 | } | |
1432 | break; | |
1433 | ||
1434 | case DW_AT_identifier_case: | |
1435 | switch (uvalue) | |
1436 | { | |
1437 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
1438 | case DW_ID_up_case: printf ("(up_case)"); break; | |
1439 | case DW_ID_down_case: printf ("(down_case)"); break; | |
1440 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
1441 | default: printf ("(unknown case)"); break; | |
1442 | } | |
1443 | break; | |
1444 | ||
1445 | case DW_AT_calling_convention: | |
1446 | switch (uvalue) | |
1447 | { | |
1448 | case DW_CC_normal: printf ("(normal)"); break; | |
1449 | case DW_CC_program: printf ("(program)"); break; | |
1450 | case DW_CC_nocall: printf ("(nocall)"); break; | |
1451 | default: | |
1452 | if (uvalue >= DW_CC_lo_user | |
1453 | && uvalue <= DW_CC_hi_user) | |
1454 | printf ("(user defined)"); | |
1455 | else | |
1456 | printf ("(unknown convention)"); | |
1457 | } | |
1458 | break; | |
1459 | ||
1460 | case DW_AT_ordering: | |
1461 | switch (uvalue) | |
1462 | { | |
1463 | case -1: printf ("(undefined)"); break; | |
1464 | case 0: printf ("(row major)"); break; | |
1465 | case 1: printf ("(column major)"); break; | |
1466 | } | |
1467 | break; | |
1468 | ||
1469 | case DW_AT_frame_base: | |
1470 | have_frame_base = 1; | |
1471 | case DW_AT_location: | |
e2a0d921 NC |
1472 | case DW_AT_string_length: |
1473 | case DW_AT_return_addr: | |
19e6b90e L |
1474 | case DW_AT_data_member_location: |
1475 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
1476 | case DW_AT_segment: |
1477 | case DW_AT_static_link: | |
1478 | case DW_AT_use_location: | |
1479 | if (form == DW_FORM_data4 || form == DW_FORM_data8) | |
1480 | printf (_("(location list)")); | |
1481 | /* Fall through. */ | |
19e6b90e L |
1482 | case DW_AT_allocated: |
1483 | case DW_AT_associated: | |
1484 | case DW_AT_data_location: | |
1485 | case DW_AT_stride: | |
1486 | case DW_AT_upper_bound: | |
e2a0d921 | 1487 | case DW_AT_lower_bound: |
19e6b90e L |
1488 | if (block_start) |
1489 | { | |
1490 | int need_frame_base; | |
1491 | ||
1492 | printf ("("); | |
1493 | need_frame_base = decode_location_expression (block_start, | |
1494 | pointer_size, | |
1495 | uvalue, | |
1496 | cu_offset); | |
1497 | printf (")"); | |
1498 | if (need_frame_base && !have_frame_base) | |
1499 | printf (_(" [without DW_AT_frame_base]")); | |
1500 | } | |
19e6b90e L |
1501 | break; |
1502 | ||
ec4d4525 NC |
1503 | case DW_AT_import: |
1504 | { | |
ec4d4525 NC |
1505 | if (form == DW_FORM_ref1 |
1506 | || form == DW_FORM_ref2 | |
1507 | || form == DW_FORM_ref4) | |
1508 | uvalue += cu_offset; | |
1509 | ||
6e3d6dc1 NC |
1510 | if (uvalue >= section->size) |
1511 | warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"), | |
1512 | uvalue, (long int)(orig_data - section->start)); | |
1513 | else | |
1514 | { | |
1515 | unsigned long abbrev_number; | |
1516 | abbrev_entry * entry; | |
1517 | ||
1518 | abbrev_number = read_leb128 (section->start + uvalue, NULL, 0); | |
ec4d4525 | 1519 | |
6e3d6dc1 NC |
1520 | printf ("[Abbrev Number: %ld", abbrev_number); |
1521 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
1522 | if (entry->entry == abbrev_number) | |
1523 | break; | |
1524 | if (entry != NULL) | |
1525 | printf (" (%s)", get_TAG_name (entry->tag)); | |
1526 | printf ("]"); | |
1527 | } | |
ec4d4525 NC |
1528 | } |
1529 | break; | |
1530 | ||
19e6b90e L |
1531 | default: |
1532 | break; | |
1533 | } | |
1534 | ||
1535 | return data; | |
1536 | } | |
1537 | ||
1538 | static char * | |
1539 | get_AT_name (unsigned long attribute) | |
1540 | { | |
1541 | switch (attribute) | |
1542 | { | |
1543 | case DW_AT_sibling: return "DW_AT_sibling"; | |
1544 | case DW_AT_location: return "DW_AT_location"; | |
1545 | case DW_AT_name: return "DW_AT_name"; | |
1546 | case DW_AT_ordering: return "DW_AT_ordering"; | |
1547 | case DW_AT_subscr_data: return "DW_AT_subscr_data"; | |
1548 | case DW_AT_byte_size: return "DW_AT_byte_size"; | |
1549 | case DW_AT_bit_offset: return "DW_AT_bit_offset"; | |
1550 | case DW_AT_bit_size: return "DW_AT_bit_size"; | |
1551 | case DW_AT_element_list: return "DW_AT_element_list"; | |
1552 | case DW_AT_stmt_list: return "DW_AT_stmt_list"; | |
1553 | case DW_AT_low_pc: return "DW_AT_low_pc"; | |
1554 | case DW_AT_high_pc: return "DW_AT_high_pc"; | |
1555 | case DW_AT_language: return "DW_AT_language"; | |
1556 | case DW_AT_member: return "DW_AT_member"; | |
1557 | case DW_AT_discr: return "DW_AT_discr"; | |
1558 | case DW_AT_discr_value: return "DW_AT_discr_value"; | |
1559 | case DW_AT_visibility: return "DW_AT_visibility"; | |
1560 | case DW_AT_import: return "DW_AT_import"; | |
1561 | case DW_AT_string_length: return "DW_AT_string_length"; | |
1562 | case DW_AT_common_reference: return "DW_AT_common_reference"; | |
1563 | case DW_AT_comp_dir: return "DW_AT_comp_dir"; | |
1564 | case DW_AT_const_value: return "DW_AT_const_value"; | |
1565 | case DW_AT_containing_type: return "DW_AT_containing_type"; | |
1566 | case DW_AT_default_value: return "DW_AT_default_value"; | |
1567 | case DW_AT_inline: return "DW_AT_inline"; | |
1568 | case DW_AT_is_optional: return "DW_AT_is_optional"; | |
1569 | case DW_AT_lower_bound: return "DW_AT_lower_bound"; | |
1570 | case DW_AT_producer: return "DW_AT_producer"; | |
1571 | case DW_AT_prototyped: return "DW_AT_prototyped"; | |
1572 | case DW_AT_return_addr: return "DW_AT_return_addr"; | |
1573 | case DW_AT_start_scope: return "DW_AT_start_scope"; | |
1574 | case DW_AT_stride_size: return "DW_AT_stride_size"; | |
1575 | case DW_AT_upper_bound: return "DW_AT_upper_bound"; | |
1576 | case DW_AT_abstract_origin: return "DW_AT_abstract_origin"; | |
1577 | case DW_AT_accessibility: return "DW_AT_accessibility"; | |
1578 | case DW_AT_address_class: return "DW_AT_address_class"; | |
1579 | case DW_AT_artificial: return "DW_AT_artificial"; | |
1580 | case DW_AT_base_types: return "DW_AT_base_types"; | |
1581 | case DW_AT_calling_convention: return "DW_AT_calling_convention"; | |
1582 | case DW_AT_count: return "DW_AT_count"; | |
1583 | case DW_AT_data_member_location: return "DW_AT_data_member_location"; | |
1584 | case DW_AT_decl_column: return "DW_AT_decl_column"; | |
1585 | case DW_AT_decl_file: return "DW_AT_decl_file"; | |
1586 | case DW_AT_decl_line: return "DW_AT_decl_line"; | |
1587 | case DW_AT_declaration: return "DW_AT_declaration"; | |
1588 | case DW_AT_discr_list: return "DW_AT_discr_list"; | |
1589 | case DW_AT_encoding: return "DW_AT_encoding"; | |
1590 | case DW_AT_external: return "DW_AT_external"; | |
1591 | case DW_AT_frame_base: return "DW_AT_frame_base"; | |
1592 | case DW_AT_friend: return "DW_AT_friend"; | |
1593 | case DW_AT_identifier_case: return "DW_AT_identifier_case"; | |
1594 | case DW_AT_macro_info: return "DW_AT_macro_info"; | |
1595 | case DW_AT_namelist_items: return "DW_AT_namelist_items"; | |
1596 | case DW_AT_priority: return "DW_AT_priority"; | |
1597 | case DW_AT_segment: return "DW_AT_segment"; | |
1598 | case DW_AT_specification: return "DW_AT_specification"; | |
1599 | case DW_AT_static_link: return "DW_AT_static_link"; | |
1600 | case DW_AT_type: return "DW_AT_type"; | |
1601 | case DW_AT_use_location: return "DW_AT_use_location"; | |
1602 | case DW_AT_variable_parameter: return "DW_AT_variable_parameter"; | |
1603 | case DW_AT_virtuality: return "DW_AT_virtuality"; | |
1604 | case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location"; | |
1605 | /* DWARF 2.1 values. */ | |
1606 | case DW_AT_allocated: return "DW_AT_allocated"; | |
1607 | case DW_AT_associated: return "DW_AT_associated"; | |
1608 | case DW_AT_data_location: return "DW_AT_data_location"; | |
1609 | case DW_AT_stride: return "DW_AT_stride"; | |
1610 | case DW_AT_entry_pc: return "DW_AT_entry_pc"; | |
1611 | case DW_AT_use_UTF8: return "DW_AT_use_UTF8"; | |
1612 | case DW_AT_extension: return "DW_AT_extension"; | |
1613 | case DW_AT_ranges: return "DW_AT_ranges"; | |
1614 | case DW_AT_trampoline: return "DW_AT_trampoline"; | |
1615 | case DW_AT_call_column: return "DW_AT_call_column"; | |
1616 | case DW_AT_call_file: return "DW_AT_call_file"; | |
1617 | case DW_AT_call_line: return "DW_AT_call_line"; | |
e2a0d921 NC |
1618 | case DW_AT_description: return "DW_AT_description"; |
1619 | case DW_AT_binary_scale: return "DW_AT_binary_scale"; | |
1620 | case DW_AT_decimal_scale: return "DW_AT_decimal_scale"; | |
1621 | case DW_AT_small: return "DW_AT_small"; | |
1622 | case DW_AT_decimal_sign: return "DW_AT_decimal_sign"; | |
1623 | case DW_AT_digit_count: return "DW_AT_digit_count"; | |
1624 | case DW_AT_picture_string: return "DW_AT_picture_string"; | |
1625 | case DW_AT_mutable: return "DW_AT_mutable"; | |
1626 | case DW_AT_threads_scaled: return "DW_AT_threads_scaled"; | |
1627 | case DW_AT_explicit: return "DW_AT_explicit"; | |
1628 | case DW_AT_object_pointer: return "DW_AT_object_pointer"; | |
1629 | case DW_AT_endianity: return "DW_AT_endianity"; | |
1630 | case DW_AT_elemental: return "DW_AT_elemental"; | |
1631 | case DW_AT_pure: return "DW_AT_pure"; | |
1632 | case DW_AT_recursive: return "DW_AT_recursive"; | |
1633 | ||
1634 | /* HP and SGI/MIPS extensions. */ | |
1635 | case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin"; | |
1636 | case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin"; | |
1637 | case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin"; | |
1638 | case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor"; | |
1639 | case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth"; | |
1640 | case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name"; | |
1641 | case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride"; | |
1642 | case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name"; | |
1643 | case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin"; | |
1644 | case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines"; | |
1645 | ||
1646 | /* HP Extensions. */ | |
1647 | case DW_AT_HP_block_index: return "DW_AT_HP_block_index"; | |
1648 | case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list"; | |
1649 | case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section"; | |
1650 | case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr"; | |
1651 | case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference"; | |
1652 | case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level"; | |
1653 | case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id"; | |
1654 | case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags"; | |
1655 | case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc"; | |
1656 | case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc"; | |
1657 | case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable"; | |
1658 | case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name"; | |
1659 | case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags"; | |
1660 | ||
1661 | /* One value is shared by the MIPS and HP extensions: */ | |
1662 | case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1663 | ||
19e6b90e L |
1664 | /* GNU extensions. */ |
1665 | case DW_AT_sf_names: return "DW_AT_sf_names"; | |
1666 | case DW_AT_src_info: return "DW_AT_src_info"; | |
1667 | case DW_AT_mac_info: return "DW_AT_mac_info"; | |
1668 | case DW_AT_src_coords: return "DW_AT_src_coords"; | |
1669 | case DW_AT_body_begin: return "DW_AT_body_begin"; | |
1670 | case DW_AT_body_end: return "DW_AT_body_end"; | |
1671 | case DW_AT_GNU_vector: return "DW_AT_GNU_vector"; | |
e2a0d921 | 1672 | |
19e6b90e L |
1673 | /* UPC extension. */ |
1674 | case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled"; | |
e2a0d921 NC |
1675 | |
1676 | /* PGI (STMicroelectronics) extensions. */ | |
1677 | case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase"; | |
1678 | case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset"; | |
1679 | case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride"; | |
1680 | ||
19e6b90e L |
1681 | default: |
1682 | { | |
1683 | static char buffer[100]; | |
1684 | ||
1685 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1686 | attribute); | |
1687 | return buffer; | |
1688 | } | |
1689 | } | |
1690 | } | |
1691 | ||
1692 | static unsigned char * | |
6e3d6dc1 NC |
1693 | read_and_display_attr (unsigned long attribute, |
1694 | unsigned long form, | |
ec4d4525 | 1695 | unsigned char * data, |
6e3d6dc1 NC |
1696 | unsigned long cu_offset, |
1697 | unsigned long pointer_size, | |
1698 | unsigned long offset_size, | |
1699 | int dwarf_version, | |
1700 | debug_info * debug_info_p, | |
1701 | int do_loc, | |
1702 | struct dwarf_section * section) | |
19e6b90e L |
1703 | { |
1704 | if (!do_loc) | |
750f03b7 | 1705 | printf (" %-18s:", get_AT_name (attribute)); |
19e6b90e L |
1706 | data = read_and_display_attr_value (attribute, form, data, cu_offset, |
1707 | pointer_size, offset_size, | |
1708 | dwarf_version, debug_info_p, | |
6e3d6dc1 | 1709 | do_loc, section); |
19e6b90e L |
1710 | if (!do_loc) |
1711 | printf ("\n"); | |
1712 | return data; | |
1713 | } | |
1714 | ||
1715 | ||
1716 | /* Process the contents of a .debug_info section. If do_loc is non-zero | |
1717 | then we are scanning for location lists and we do not want to display | |
1718 | anything to the user. */ | |
1719 | ||
1720 | static int | |
6e3d6dc1 NC |
1721 | process_debug_info (struct dwarf_section *section, |
1722 | void *file, | |
19e6b90e L |
1723 | int do_loc) |
1724 | { | |
1725 | unsigned char *start = section->start; | |
1726 | unsigned char *end = start + section->size; | |
1727 | unsigned char *section_begin; | |
1728 | unsigned int unit; | |
1729 | unsigned int num_units = 0; | |
1730 | ||
1731 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
1732 | && num_debug_info_entries == 0) | |
1733 | { | |
1734 | unsigned long length; | |
1735 | ||
1736 | /* First scan the section to get the number of comp units. */ | |
1737 | for (section_begin = start, num_units = 0; section_begin < end; | |
1738 | num_units ++) | |
1739 | { | |
1740 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
1741 | will be the length. For a 64-bit DWARF section, it'll be | |
1742 | the escape code 0xffffffff followed by an 8 byte length. */ | |
1743 | length = byte_get (section_begin, 4); | |
1744 | ||
1745 | if (length == 0xffffffff) | |
1746 | { | |
1747 | length = byte_get (section_begin + 4, 8); | |
1748 | section_begin += length + 12; | |
1749 | } | |
ec4d4525 NC |
1750 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
1751 | { | |
1752 | warn (_("Reserved length value (%lx) found in section %s\n"), length, section->name); | |
1753 | return 0; | |
1754 | } | |
19e6b90e L |
1755 | else |
1756 | section_begin += length + 4; | |
aca88567 NC |
1757 | |
1758 | /* Negative values are illegal, they may even cause infinite | |
1759 | looping. This can happen if we can't accurately apply | |
1760 | relocations to an object file. */ | |
1761 | if ((signed long) length <= 0) | |
1762 | { | |
1763 | warn (_("Corrupt unit length (%lx) found in section %s\n"), length, section->name); | |
1764 | return 0; | |
1765 | } | |
19e6b90e L |
1766 | } |
1767 | ||
1768 | if (num_units == 0) | |
1769 | { | |
1770 | error (_("No comp units in %s section ?"), section->name); | |
1771 | return 0; | |
1772 | } | |
1773 | ||
1774 | /* Then allocate an array to hold the information. */ | |
1775 | debug_information = cmalloc (num_units, | |
1776 | sizeof (* debug_information)); | |
1777 | if (debug_information == NULL) | |
1778 | { | |
1779 | error (_("Not enough memory for a debug info array of %u entries"), | |
1780 | num_units); | |
1781 | return 0; | |
1782 | } | |
1783 | } | |
1784 | ||
1785 | if (!do_loc) | |
1786 | { | |
1787 | printf (_("The section %s contains:\n\n"), section->name); | |
1788 | ||
1789 | load_debug_section (str, file); | |
1790 | } | |
1791 | ||
1792 | load_debug_section (abbrev, file); | |
1793 | if (debug_displays [abbrev].section.start == NULL) | |
1794 | { | |
1795 | warn (_("Unable to locate %s section!\n"), | |
1796 | debug_displays [abbrev].section.name); | |
1797 | return 0; | |
1798 | } | |
1799 | ||
1800 | for (section_begin = start, unit = 0; start < end; unit++) | |
1801 | { | |
1802 | DWARF2_Internal_CompUnit compunit; | |
1803 | unsigned char *hdrptr; | |
1804 | unsigned char *cu_abbrev_offset_ptr; | |
1805 | unsigned char *tags; | |
1806 | int level; | |
1807 | unsigned long cu_offset; | |
1808 | int offset_size; | |
1809 | int initial_length_size; | |
1810 | ||
1811 | hdrptr = start; | |
1812 | ||
1813 | compunit.cu_length = byte_get (hdrptr, 4); | |
1814 | hdrptr += 4; | |
1815 | ||
1816 | if (compunit.cu_length == 0xffffffff) | |
1817 | { | |
1818 | compunit.cu_length = byte_get (hdrptr, 8); | |
1819 | hdrptr += 8; | |
1820 | offset_size = 8; | |
1821 | initial_length_size = 12; | |
1822 | } | |
1823 | else | |
1824 | { | |
1825 | offset_size = 4; | |
1826 | initial_length_size = 4; | |
1827 | } | |
1828 | ||
1829 | compunit.cu_version = byte_get (hdrptr, 2); | |
1830 | hdrptr += 2; | |
1831 | ||
1832 | cu_offset = start - section_begin; | |
19e6b90e L |
1833 | |
1834 | cu_abbrev_offset_ptr = hdrptr; | |
1835 | compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size); | |
1836 | hdrptr += offset_size; | |
1837 | ||
1838 | compunit.cu_pointer_size = byte_get (hdrptr, 1); | |
1839 | hdrptr += 1; | |
1840 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
1841 | && num_debug_info_entries == 0) | |
1842 | { | |
1843 | debug_information [unit].cu_offset = cu_offset; | |
1844 | debug_information [unit].pointer_size | |
1845 | = compunit.cu_pointer_size; | |
1846 | debug_information [unit].base_address = 0; | |
1847 | debug_information [unit].loc_offsets = NULL; | |
1848 | debug_information [unit].have_frame_base = NULL; | |
1849 | debug_information [unit].max_loc_offsets = 0; | |
1850 | debug_information [unit].num_loc_offsets = 0; | |
1851 | debug_information [unit].range_lists = NULL; | |
1852 | debug_information [unit].max_range_lists= 0; | |
1853 | debug_information [unit].num_range_lists = 0; | |
1854 | } | |
1855 | ||
19e6b90e L |
1856 | if (!do_loc) |
1857 | { | |
1858 | printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset); | |
cc86f28f NC |
1859 | printf (_(" Length: 0x%lx (%s)\n"), compunit.cu_length, |
1860 | initial_length_size == 8 ? "64-bit" : "32-bit"); | |
19e6b90e L |
1861 | printf (_(" Version: %d\n"), compunit.cu_version); |
1862 | printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset); | |
1863 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); | |
1864 | } | |
1865 | ||
460c89ff NS |
1866 | if (cu_offset + compunit.cu_length + initial_length_size |
1867 | > section->size) | |
1868 | { | |
ec4d4525 NC |
1869 | warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"), |
1870 | cu_offset, compunit.cu_length); | |
460c89ff NS |
1871 | break; |
1872 | } | |
1873 | tags = hdrptr; | |
1874 | start += compunit.cu_length + initial_length_size; | |
1875 | ||
19e6b90e L |
1876 | if (compunit.cu_version != 2 && compunit.cu_version != 3) |
1877 | { | |
1febe64d NC |
1878 | warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"), |
1879 | cu_offset, compunit.cu_version); | |
19e6b90e L |
1880 | continue; |
1881 | } | |
1882 | ||
1883 | free_abbrevs (); | |
1884 | ||
bfe2612a L |
1885 | /* Process the abbrevs used by this compilation unit. DWARF |
1886 | sections under Mach-O have non-zero addresses. */ | |
460c89ff | 1887 | if (compunit.cu_abbrev_offset >= debug_displays [abbrev].section.size) |
ec4d4525 NC |
1888 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
1889 | (unsigned long) compunit.cu_abbrev_offset, | |
1890 | (unsigned long) debug_displays [abbrev].section.size); | |
460c89ff NS |
1891 | else |
1892 | process_abbrev_section | |
1893 | ((unsigned char *) debug_displays [abbrev].section.start | |
1894 | + compunit.cu_abbrev_offset - debug_displays [abbrev].section.address, | |
1895 | (unsigned char *) debug_displays [abbrev].section.start | |
1896 | + debug_displays [abbrev].section.size); | |
19e6b90e L |
1897 | |
1898 | level = 0; | |
1899 | while (tags < start) | |
1900 | { | |
1901 | unsigned int bytes_read; | |
1902 | unsigned long abbrev_number; | |
ec4d4525 | 1903 | unsigned long die_offset; |
19e6b90e L |
1904 | abbrev_entry *entry; |
1905 | abbrev_attr *attr; | |
1906 | ||
ec4d4525 NC |
1907 | die_offset = tags - section_begin; |
1908 | ||
19e6b90e L |
1909 | abbrev_number = read_leb128 (tags, & bytes_read, 0); |
1910 | tags += bytes_read; | |
1911 | ||
ec4d4525 | 1912 | /* A null DIE marks the end of a list of siblings. */ |
19e6b90e L |
1913 | if (abbrev_number == 0) |
1914 | { | |
1915 | --level; | |
ec4d4525 NC |
1916 | if (level < 0) |
1917 | { | |
1918 | static unsigned num_bogus_warns = 0; | |
1919 | ||
1920 | if (num_bogus_warns < 3) | |
1921 | { | |
1922 | warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"), | |
1923 | die_offset); | |
1924 | num_bogus_warns ++; | |
1925 | if (num_bogus_warns == 3) | |
1926 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
1927 | } | |
1928 | } | |
19e6b90e L |
1929 | continue; |
1930 | } | |
1931 | ||
4b78141a NC |
1932 | if (!do_loc) |
1933 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
ec4d4525 | 1934 | level, die_offset, abbrev_number); |
4b78141a | 1935 | |
19e6b90e L |
1936 | /* Scan through the abbreviation list until we reach the |
1937 | correct entry. */ | |
1938 | for (entry = first_abbrev; | |
1939 | entry && entry->entry != abbrev_number; | |
1940 | entry = entry->next) | |
1941 | continue; | |
1942 | ||
1943 | if (entry == NULL) | |
1944 | { | |
4b78141a NC |
1945 | if (!do_loc) |
1946 | { | |
1947 | printf ("\n"); | |
1948 | fflush (stdout); | |
1949 | } | |
cc86f28f NC |
1950 | warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"), |
1951 | die_offset, abbrev_number); | |
19e6b90e L |
1952 | return 0; |
1953 | } | |
1954 | ||
1955 | if (!do_loc) | |
4b78141a | 1956 | printf (_(" (%s)\n"), get_TAG_name (entry->tag)); |
19e6b90e L |
1957 | |
1958 | switch (entry->tag) | |
1959 | { | |
1960 | default: | |
1961 | need_base_address = 0; | |
1962 | break; | |
1963 | case DW_TAG_compile_unit: | |
1964 | need_base_address = 1; | |
1965 | break; | |
1966 | case DW_TAG_entry_point: | |
19e6b90e L |
1967 | case DW_TAG_subprogram: |
1968 | need_base_address = 0; | |
1969 | /* Assuming that there is no DW_AT_frame_base. */ | |
1970 | have_frame_base = 0; | |
1971 | break; | |
1972 | } | |
1973 | ||
1974 | for (attr = entry->first_attr; attr; attr = attr->next) | |
4b78141a NC |
1975 | { |
1976 | if (! do_loc) | |
1977 | /* Show the offset from where the tag was extracted. */ | |
750f03b7 | 1978 | printf (" <%2lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
1979 | |
1980 | tags = read_and_display_attr (attr->attribute, | |
1981 | attr->form, | |
1982 | tags, cu_offset, | |
1983 | compunit.cu_pointer_size, | |
1984 | offset_size, | |
1985 | compunit.cu_version, | |
ec4d4525 | 1986 | debug_information + unit, |
6e3d6dc1 | 1987 | do_loc, section); |
4b78141a | 1988 | } |
19e6b90e L |
1989 | |
1990 | if (entry->children) | |
1991 | ++level; | |
1992 | } | |
1993 | } | |
1994 | ||
1995 | /* Set num_debug_info_entries here so that it can be used to check if | |
1996 | we need to process .debug_loc and .debug_ranges sections. */ | |
1997 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
1998 | && num_debug_info_entries == 0) | |
1999 | num_debug_info_entries = num_units; | |
2000 | ||
2001 | if (!do_loc) | |
2002 | { | |
2003 | printf ("\n"); | |
2004 | } | |
2005 | ||
2006 | return 1; | |
2007 | } | |
2008 | ||
2009 | /* Locate and scan the .debug_info section in the file and record the pointer | |
2010 | sizes and offsets for the compilation units in it. Usually an executable | |
2011 | will have just one pointer size, but this is not guaranteed, and so we try | |
2012 | not to make any assumptions. Returns zero upon failure, or the number of | |
2013 | compilation units upon success. */ | |
2014 | ||
2015 | static unsigned int | |
2016 | load_debug_info (void * file) | |
2017 | { | |
2018 | /* Reset the last pointer size so that we can issue correct error | |
2019 | messages if we are displaying the contents of more than one section. */ | |
2020 | last_pointer_size = 0; | |
2021 | warned_about_missing_comp_units = FALSE; | |
2022 | ||
1febe64d NC |
2023 | /* If we have already tried and failed to load the .debug_info |
2024 | section then do not bother to repear the task. */ | |
cc86f28f | 2025 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
2026 | return 0; |
2027 | ||
19e6b90e L |
2028 | /* If we already have the information there is nothing else to do. */ |
2029 | if (num_debug_info_entries > 0) | |
2030 | return num_debug_info_entries; | |
2031 | ||
2032 | if (load_debug_section (info, file) | |
2033 | && process_debug_info (&debug_displays [info].section, file, 1)) | |
2034 | return num_debug_info_entries; | |
1febe64d | 2035 | |
cc86f28f | 2036 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 2037 | return 0; |
19e6b90e L |
2038 | } |
2039 | ||
19e6b90e L |
2040 | static int |
2041 | display_debug_lines (struct dwarf_section *section, void *file) | |
2042 | { | |
2043 | unsigned char *start = section->start; | |
2044 | unsigned char *data = start; | |
2045 | unsigned char *end = start + section->size; | |
19e6b90e L |
2046 | |
2047 | printf (_("\nDump of debug contents of section %s:\n\n"), | |
2048 | section->name); | |
2049 | ||
1febe64d NC |
2050 | if (load_debug_info (file) == 0) |
2051 | { | |
2052 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
2053 | section->name); | |
2054 | return 0; | |
2055 | } | |
19e6b90e L |
2056 | |
2057 | while (data < end) | |
2058 | { | |
2059 | DWARF2_Internal_LineInfo info; | |
2060 | unsigned char *standard_opcodes; | |
2061 | unsigned char *end_of_sequence; | |
2062 | unsigned char *hdrptr; | |
6523721c | 2063 | unsigned long hdroff; |
19e6b90e L |
2064 | int initial_length_size; |
2065 | int offset_size; | |
2066 | int i; | |
2067 | ||
2068 | hdrptr = data; | |
6523721c | 2069 | hdroff = hdrptr - start; |
19e6b90e L |
2070 | |
2071 | /* Check the length of the block. */ | |
2072 | info.li_length = byte_get (hdrptr, 4); | |
2073 | hdrptr += 4; | |
2074 | ||
2075 | if (info.li_length == 0xffffffff) | |
2076 | { | |
2077 | /* This section is 64-bit DWARF 3. */ | |
2078 | info.li_length = byte_get (hdrptr, 8); | |
2079 | hdrptr += 8; | |
2080 | offset_size = 8; | |
2081 | initial_length_size = 12; | |
2082 | } | |
2083 | else | |
2084 | { | |
2085 | offset_size = 4; | |
2086 | initial_length_size = 4; | |
2087 | } | |
2088 | ||
2089 | if (info.li_length + initial_length_size > section->size) | |
2090 | { | |
2091 | warn | |
2092 | (_("The line info appears to be corrupt - the section is too small\n")); | |
2093 | return 0; | |
2094 | } | |
2095 | ||
2096 | /* Check its version number. */ | |
2097 | info.li_version = byte_get (hdrptr, 2); | |
2098 | hdrptr += 2; | |
2099 | if (info.li_version != 2 && info.li_version != 3) | |
2100 | { | |
2101 | warn (_("Only DWARF version 2 and 3 line info is currently supported.\n")); | |
2102 | return 0; | |
2103 | } | |
2104 | ||
2105 | info.li_prologue_length = byte_get (hdrptr, offset_size); | |
2106 | hdrptr += offset_size; | |
2107 | info.li_min_insn_length = byte_get (hdrptr, 1); | |
2108 | hdrptr++; | |
2109 | info.li_default_is_stmt = byte_get (hdrptr, 1); | |
2110 | hdrptr++; | |
2111 | info.li_line_base = byte_get (hdrptr, 1); | |
2112 | hdrptr++; | |
2113 | info.li_line_range = byte_get (hdrptr, 1); | |
2114 | hdrptr++; | |
2115 | info.li_opcode_base = byte_get (hdrptr, 1); | |
2116 | hdrptr++; | |
2117 | ||
2118 | /* Sign extend the line base field. */ | |
2119 | info.li_line_base <<= 24; | |
2120 | info.li_line_base >>= 24; | |
2121 | ||
6523721c | 2122 | printf (_(" Offset: 0x%lx\n"), hdroff); |
19e6b90e L |
2123 | printf (_(" Length: %ld\n"), info.li_length); |
2124 | printf (_(" DWARF Version: %d\n"), info.li_version); | |
2125 | printf (_(" Prologue Length: %d\n"), info.li_prologue_length); | |
2126 | printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length); | |
2127 | printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt); | |
2128 | printf (_(" Line Base: %d\n"), info.li_line_base); | |
2129 | printf (_(" Line Range: %d\n"), info.li_line_range); | |
2130 | printf (_(" Opcode Base: %d\n"), info.li_opcode_base); | |
19e6b90e L |
2131 | |
2132 | end_of_sequence = data + info.li_length + initial_length_size; | |
2133 | ||
2134 | reset_state_machine (info.li_default_is_stmt); | |
2135 | ||
2136 | /* Display the contents of the Opcodes table. */ | |
2137 | standard_opcodes = hdrptr; | |
2138 | ||
2139 | printf (_("\n Opcodes:\n")); | |
2140 | ||
2141 | for (i = 1; i < info.li_opcode_base; i++) | |
2142 | printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); | |
2143 | ||
2144 | /* Display the contents of the Directory table. */ | |
2145 | data = standard_opcodes + info.li_opcode_base - 1; | |
2146 | ||
2147 | if (*data == 0) | |
2148 | printf (_("\n The Directory Table is empty.\n")); | |
2149 | else | |
2150 | { | |
2151 | printf (_("\n The Directory Table:\n")); | |
2152 | ||
2153 | while (*data != 0) | |
2154 | { | |
2155 | printf (_(" %s\n"), data); | |
2156 | ||
2157 | data += strlen ((char *) data) + 1; | |
2158 | } | |
2159 | } | |
2160 | ||
2161 | /* Skip the NUL at the end of the table. */ | |
2162 | data++; | |
2163 | ||
2164 | /* Display the contents of the File Name table. */ | |
2165 | if (*data == 0) | |
2166 | printf (_("\n The File Name Table is empty.\n")); | |
2167 | else | |
2168 | { | |
2169 | printf (_("\n The File Name Table:\n")); | |
2170 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
2171 | ||
2172 | while (*data != 0) | |
2173 | { | |
2174 | unsigned char *name; | |
2175 | unsigned int bytes_read; | |
2176 | ||
2177 | printf (_(" %d\t"), ++state_machine_regs.last_file_entry); | |
2178 | name = data; | |
2179 | ||
2180 | data += strlen ((char *) data) + 1; | |
2181 | ||
2182 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
2183 | data += bytes_read; | |
2184 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
2185 | data += bytes_read; | |
2186 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
2187 | data += bytes_read; | |
2188 | printf (_("%s\n"), name); | |
2189 | } | |
2190 | } | |
2191 | ||
2192 | /* Skip the NUL at the end of the table. */ | |
2193 | data++; | |
2194 | ||
2195 | /* Now display the statements. */ | |
2196 | printf (_("\n Line Number Statements:\n")); | |
2197 | ||
2198 | while (data < end_of_sequence) | |
2199 | { | |
2200 | unsigned char op_code; | |
2201 | int adv; | |
2202 | unsigned long int uladv; | |
2203 | unsigned int bytes_read; | |
2204 | ||
2205 | op_code = *data++; | |
2206 | ||
2207 | if (op_code >= info.li_opcode_base) | |
2208 | { | |
2209 | op_code -= info.li_opcode_base; | |
2210 | uladv = (op_code / info.li_line_range) * info.li_min_insn_length; | |
2211 | state_machine_regs.address += uladv; | |
2212 | printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"), | |
2213 | op_code, uladv, state_machine_regs.address); | |
2214 | adv = (op_code % info.li_line_range) + info.li_line_base; | |
2215 | state_machine_regs.line += adv; | |
2216 | printf (_(" and Line by %d to %d\n"), | |
2217 | adv, state_machine_regs.line); | |
2218 | } | |
2219 | else switch (op_code) | |
2220 | { | |
2221 | case DW_LNS_extended_op: | |
1617e571 | 2222 | data += process_extended_line_op (data, info.li_default_is_stmt); |
19e6b90e L |
2223 | break; |
2224 | ||
2225 | case DW_LNS_copy: | |
2226 | printf (_(" Copy\n")); | |
2227 | break; | |
2228 | ||
2229 | case DW_LNS_advance_pc: | |
2230 | uladv = read_leb128 (data, & bytes_read, 0); | |
2231 | uladv *= info.li_min_insn_length; | |
2232 | data += bytes_read; | |
2233 | state_machine_regs.address += uladv; | |
2234 | printf (_(" Advance PC by %lu to 0x%lx\n"), uladv, | |
2235 | state_machine_regs.address); | |
2236 | break; | |
2237 | ||
2238 | case DW_LNS_advance_line: | |
2239 | adv = read_leb128 (data, & bytes_read, 1); | |
2240 | data += bytes_read; | |
2241 | state_machine_regs.line += adv; | |
2242 | printf (_(" Advance Line by %d to %d\n"), adv, | |
2243 | state_machine_regs.line); | |
2244 | break; | |
2245 | ||
2246 | case DW_LNS_set_file: | |
2247 | adv = read_leb128 (data, & bytes_read, 0); | |
2248 | data += bytes_read; | |
2249 | printf (_(" Set File Name to entry %d in the File Name Table\n"), | |
2250 | adv); | |
2251 | state_machine_regs.file = adv; | |
2252 | break; | |
2253 | ||
2254 | case DW_LNS_set_column: | |
2255 | uladv = read_leb128 (data, & bytes_read, 0); | |
2256 | data += bytes_read; | |
2257 | printf (_(" Set column to %lu\n"), uladv); | |
2258 | state_machine_regs.column = uladv; | |
2259 | break; | |
2260 | ||
2261 | case DW_LNS_negate_stmt: | |
2262 | adv = state_machine_regs.is_stmt; | |
2263 | adv = ! adv; | |
2264 | printf (_(" Set is_stmt to %d\n"), adv); | |
2265 | state_machine_regs.is_stmt = adv; | |
2266 | break; | |
2267 | ||
2268 | case DW_LNS_set_basic_block: | |
2269 | printf (_(" Set basic block\n")); | |
2270 | state_machine_regs.basic_block = 1; | |
2271 | break; | |
2272 | ||
2273 | case DW_LNS_const_add_pc: | |
2274 | uladv = (((255 - info.li_opcode_base) / info.li_line_range) | |
2275 | * info.li_min_insn_length); | |
2276 | state_machine_regs.address += uladv; | |
2277 | printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv, | |
2278 | state_machine_regs.address); | |
2279 | break; | |
2280 | ||
2281 | case DW_LNS_fixed_advance_pc: | |
2282 | uladv = byte_get (data, 2); | |
2283 | data += 2; | |
2284 | state_machine_regs.address += uladv; | |
2285 | printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"), | |
2286 | uladv, state_machine_regs.address); | |
2287 | break; | |
2288 | ||
2289 | case DW_LNS_set_prologue_end: | |
2290 | printf (_(" Set prologue_end to true\n")); | |
2291 | break; | |
2292 | ||
2293 | case DW_LNS_set_epilogue_begin: | |
2294 | printf (_(" Set epilogue_begin to true\n")); | |
2295 | break; | |
2296 | ||
2297 | case DW_LNS_set_isa: | |
2298 | uladv = read_leb128 (data, & bytes_read, 0); | |
2299 | data += bytes_read; | |
2300 | printf (_(" Set ISA to %lu\n"), uladv); | |
2301 | break; | |
2302 | ||
2303 | default: | |
2304 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
2305 | ||
2306 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
2307 | { | |
2308 | printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0), | |
2309 | i == 1 ? "" : ", "); | |
2310 | data += bytes_read; | |
2311 | } | |
2312 | putchar ('\n'); | |
2313 | break; | |
2314 | } | |
2315 | } | |
2316 | putchar ('\n'); | |
2317 | } | |
2318 | ||
2319 | return 1; | |
2320 | } | |
2321 | ||
6e3d6dc1 NC |
2322 | static debug_info * |
2323 | find_debug_info_for_offset (unsigned long offset) | |
2324 | { | |
2325 | unsigned int i; | |
2326 | ||
2327 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
2328 | return NULL; | |
2329 | ||
2330 | for (i = 0; i < num_debug_info_entries; i++) | |
2331 | if (debug_information[i].cu_offset == offset) | |
2332 | return debug_information + i; | |
2333 | ||
2334 | return NULL; | |
2335 | } | |
2336 | ||
19e6b90e L |
2337 | static int |
2338 | display_debug_pubnames (struct dwarf_section *section, | |
2339 | void *file ATTRIBUTE_UNUSED) | |
2340 | { | |
2341 | DWARF2_Internal_PubNames pubnames; | |
2342 | unsigned char *start = section->start; | |
2343 | unsigned char *end = start + section->size; | |
2344 | ||
6e3d6dc1 NC |
2345 | /* It does not matter if this load fails, |
2346 | we test for that later on. */ | |
2347 | load_debug_info (file); | |
2348 | ||
19e6b90e L |
2349 | printf (_("Contents of the %s section:\n\n"), section->name); |
2350 | ||
2351 | while (start < end) | |
2352 | { | |
2353 | unsigned char *data; | |
2354 | unsigned long offset; | |
2355 | int offset_size, initial_length_size; | |
2356 | ||
2357 | data = start; | |
2358 | ||
2359 | pubnames.pn_length = byte_get (data, 4); | |
2360 | data += 4; | |
2361 | if (pubnames.pn_length == 0xffffffff) | |
2362 | { | |
2363 | pubnames.pn_length = byte_get (data, 8); | |
2364 | data += 8; | |
2365 | offset_size = 8; | |
2366 | initial_length_size = 12; | |
2367 | } | |
2368 | else | |
2369 | { | |
2370 | offset_size = 4; | |
2371 | initial_length_size = 4; | |
2372 | } | |
2373 | ||
2374 | pubnames.pn_version = byte_get (data, 2); | |
2375 | data += 2; | |
6e3d6dc1 | 2376 | |
19e6b90e L |
2377 | pubnames.pn_offset = byte_get (data, offset_size); |
2378 | data += offset_size; | |
6e3d6dc1 NC |
2379 | |
2380 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
2381 | && num_debug_info_entries > 0 | |
2382 | && find_debug_info_for_offset (pubnames.pn_offset) == NULL) | |
2383 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
2384 | pubnames.pn_offset, section->name); | |
2385 | ||
19e6b90e L |
2386 | pubnames.pn_size = byte_get (data, offset_size); |
2387 | data += offset_size; | |
2388 | ||
2389 | start += pubnames.pn_length + initial_length_size; | |
2390 | ||
2391 | if (pubnames.pn_version != 2 && pubnames.pn_version != 3) | |
2392 | { | |
2393 | static int warned = 0; | |
2394 | ||
2395 | if (! warned) | |
2396 | { | |
2397 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
2398 | warned = 1; | |
2399 | } | |
2400 | ||
2401 | continue; | |
2402 | } | |
2403 | ||
2404 | printf (_(" Length: %ld\n"), | |
2405 | pubnames.pn_length); | |
2406 | printf (_(" Version: %d\n"), | |
2407 | pubnames.pn_version); | |
6e3d6dc1 | 2408 | printf (_(" Offset into .debug_info section: 0x%lx\n"), |
19e6b90e L |
2409 | pubnames.pn_offset); |
2410 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
2411 | pubnames.pn_size); | |
2412 | ||
2413 | printf (_("\n Offset\tName\n")); | |
2414 | ||
2415 | do | |
2416 | { | |
2417 | offset = byte_get (data, offset_size); | |
2418 | ||
2419 | if (offset != 0) | |
2420 | { | |
2421 | data += offset_size; | |
2422 | printf (" %-6ld\t\t%s\n", offset, data); | |
2423 | data += strlen ((char *) data) + 1; | |
2424 | } | |
2425 | } | |
2426 | while (offset != 0); | |
2427 | } | |
2428 | ||
2429 | printf ("\n"); | |
2430 | return 1; | |
2431 | } | |
2432 | ||
2433 | static int | |
2434 | display_debug_macinfo (struct dwarf_section *section, | |
2435 | void *file ATTRIBUTE_UNUSED) | |
2436 | { | |
2437 | unsigned char *start = section->start; | |
2438 | unsigned char *end = start + section->size; | |
2439 | unsigned char *curr = start; | |
2440 | unsigned int bytes_read; | |
2441 | enum dwarf_macinfo_record_type op; | |
2442 | ||
2443 | printf (_("Contents of the %s section:\n\n"), section->name); | |
2444 | ||
2445 | while (curr < end) | |
2446 | { | |
2447 | unsigned int lineno; | |
2448 | const char *string; | |
2449 | ||
2450 | op = *curr; | |
2451 | curr++; | |
2452 | ||
2453 | switch (op) | |
2454 | { | |
2455 | case DW_MACINFO_start_file: | |
2456 | { | |
2457 | unsigned int filenum; | |
2458 | ||
2459 | lineno = read_leb128 (curr, & bytes_read, 0); | |
2460 | curr += bytes_read; | |
2461 | filenum = read_leb128 (curr, & bytes_read, 0); | |
2462 | curr += bytes_read; | |
2463 | ||
2464 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
2465 | lineno, filenum); | |
2466 | } | |
2467 | break; | |
2468 | ||
2469 | case DW_MACINFO_end_file: | |
2470 | printf (_(" DW_MACINFO_end_file\n")); | |
2471 | break; | |
2472 | ||
2473 | case DW_MACINFO_define: | |
2474 | lineno = read_leb128 (curr, & bytes_read, 0); | |
2475 | curr += bytes_read; | |
2476 | string = (char *) curr; | |
2477 | curr += strlen (string) + 1; | |
2478 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), | |
2479 | lineno, string); | |
2480 | break; | |
2481 | ||
2482 | case DW_MACINFO_undef: | |
2483 | lineno = read_leb128 (curr, & bytes_read, 0); | |
2484 | curr += bytes_read; | |
2485 | string = (char *) curr; | |
2486 | curr += strlen (string) + 1; | |
2487 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), | |
2488 | lineno, string); | |
2489 | break; | |
2490 | ||
2491 | case DW_MACINFO_vendor_ext: | |
2492 | { | |
2493 | unsigned int constant; | |
2494 | ||
2495 | constant = read_leb128 (curr, & bytes_read, 0); | |
2496 | curr += bytes_read; | |
2497 | string = (char *) curr; | |
2498 | curr += strlen (string) + 1; | |
2499 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), | |
2500 | constant, string); | |
2501 | } | |
2502 | break; | |
2503 | } | |
2504 | } | |
2505 | ||
2506 | return 1; | |
2507 | } | |
2508 | ||
2509 | static int | |
2510 | display_debug_abbrev (struct dwarf_section *section, | |
2511 | void *file ATTRIBUTE_UNUSED) | |
2512 | { | |
2513 | abbrev_entry *entry; | |
2514 | unsigned char *start = section->start; | |
2515 | unsigned char *end = start + section->size; | |
2516 | ||
2517 | printf (_("Contents of the %s section:\n\n"), section->name); | |
2518 | ||
2519 | do | |
2520 | { | |
2521 | free_abbrevs (); | |
2522 | ||
2523 | start = process_abbrev_section (start, end); | |
2524 | ||
2525 | if (first_abbrev == NULL) | |
2526 | continue; | |
2527 | ||
2528 | printf (_(" Number TAG\n")); | |
2529 | ||
2530 | for (entry = first_abbrev; entry; entry = entry->next) | |
2531 | { | |
2532 | abbrev_attr *attr; | |
2533 | ||
2534 | printf (_(" %ld %s [%s]\n"), | |
2535 | entry->entry, | |
2536 | get_TAG_name (entry->tag), | |
2537 | entry->children ? _("has children") : _("no children")); | |
2538 | ||
2539 | for (attr = entry->first_attr; attr; attr = attr->next) | |
2540 | printf (_(" %-18s %s\n"), | |
2541 | get_AT_name (attr->attribute), | |
2542 | get_FORM_name (attr->form)); | |
2543 | } | |
2544 | } | |
2545 | while (start); | |
2546 | ||
2547 | printf ("\n"); | |
2548 | ||
2549 | return 1; | |
2550 | } | |
2551 | ||
2552 | static int | |
2553 | display_debug_loc (struct dwarf_section *section, void *file) | |
2554 | { | |
2555 | unsigned char *start = section->start; | |
2556 | unsigned char *section_end; | |
2557 | unsigned long bytes; | |
2558 | unsigned char *section_begin = start; | |
2559 | unsigned int num_loc_list = 0; | |
2560 | unsigned long last_offset = 0; | |
2561 | unsigned int first = 0; | |
2562 | unsigned int i; | |
2563 | unsigned int j; | |
2564 | int seen_first_offset = 0; | |
2565 | int use_debug_info = 1; | |
2566 | unsigned char *next; | |
2567 | ||
2568 | bytes = section->size; | |
2569 | section_end = start + bytes; | |
2570 | ||
2571 | if (bytes == 0) | |
2572 | { | |
2573 | printf (_("\nThe %s section is empty.\n"), section->name); | |
2574 | return 0; | |
2575 | } | |
2576 | ||
1febe64d NC |
2577 | if (load_debug_info (file) == 0) |
2578 | { | |
2579 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
2580 | section->name); | |
2581 | return 0; | |
2582 | } | |
19e6b90e L |
2583 | |
2584 | /* Check the order of location list in .debug_info section. If | |
2585 | offsets of location lists are in the ascending order, we can | |
2586 | use `debug_information' directly. */ | |
2587 | for (i = 0; i < num_debug_info_entries; i++) | |
2588 | { | |
2589 | unsigned int num; | |
2590 | ||
2591 | num = debug_information [i].num_loc_offsets; | |
2592 | num_loc_list += num; | |
2593 | ||
2594 | /* Check if we can use `debug_information' directly. */ | |
2595 | if (use_debug_info && num != 0) | |
2596 | { | |
2597 | if (!seen_first_offset) | |
2598 | { | |
2599 | /* This is the first location list. */ | |
2600 | last_offset = debug_information [i].loc_offsets [0]; | |
2601 | first = i; | |
2602 | seen_first_offset = 1; | |
2603 | j = 1; | |
2604 | } | |
2605 | else | |
2606 | j = 0; | |
2607 | ||
2608 | for (; j < num; j++) | |
2609 | { | |
2610 | if (last_offset > | |
2611 | debug_information [i].loc_offsets [j]) | |
2612 | { | |
2613 | use_debug_info = 0; | |
2614 | break; | |
2615 | } | |
2616 | last_offset = debug_information [i].loc_offsets [j]; | |
2617 | } | |
2618 | } | |
2619 | } | |
2620 | ||
2621 | if (!use_debug_info) | |
2622 | /* FIXME: Should we handle this case? */ | |
2623 | error (_("Location lists in .debug_info section aren't in ascending order!\n")); | |
2624 | ||
2625 | if (!seen_first_offset) | |
2626 | error (_("No location lists in .debug_info section!\n")); | |
2627 | ||
bfe2612a | 2628 | /* DWARF sections under Mach-O have non-zero addresses. */ |
d4bfc77b AS |
2629 | if (debug_information [first].num_loc_offsets > 0 |
2630 | && debug_information [first].loc_offsets [0] != section->address) | |
19e6b90e L |
2631 | warn (_("Location lists in %s section start at 0x%lx\n"), |
2632 | section->name, debug_information [first].loc_offsets [0]); | |
2633 | ||
2634 | printf (_("Contents of the %s section:\n\n"), section->name); | |
2635 | printf (_(" Offset Begin End Expression\n")); | |
2636 | ||
2637 | seen_first_offset = 0; | |
2638 | for (i = first; i < num_debug_info_entries; i++) | |
2639 | { | |
2d9472a2 NC |
2640 | dwarf_vma begin; |
2641 | dwarf_vma end; | |
19e6b90e L |
2642 | unsigned short length; |
2643 | unsigned long offset; | |
2644 | unsigned int pointer_size; | |
2645 | unsigned long cu_offset; | |
2646 | unsigned long base_address; | |
2647 | int need_frame_base; | |
2648 | int has_frame_base; | |
2649 | ||
2650 | pointer_size = debug_information [i].pointer_size; | |
2651 | cu_offset = debug_information [i].cu_offset; | |
2652 | ||
2653 | for (j = 0; j < debug_information [i].num_loc_offsets; j++) | |
2654 | { | |
2655 | has_frame_base = debug_information [i].have_frame_base [j]; | |
bfe2612a L |
2656 | /* DWARF sections under Mach-O have non-zero addresses. */ |
2657 | offset = debug_information [i].loc_offsets [j] - section->address; | |
19e6b90e L |
2658 | next = section_begin + offset; |
2659 | base_address = debug_information [i].base_address; | |
2660 | ||
2661 | if (!seen_first_offset) | |
2662 | seen_first_offset = 1; | |
2663 | else | |
2664 | { | |
2665 | if (start < next) | |
2666 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
2667 | (long)(start - section_begin), (long)(next - section_begin)); | |
2668 | else if (start > next) | |
2669 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
2670 | (long)(start - section_begin), (long)(next - section_begin)); | |
2671 | } | |
2672 | start = next; | |
2673 | ||
2674 | if (offset >= bytes) | |
2675 | { | |
2676 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
2677 | offset); | |
2678 | continue; | |
2679 | } | |
2680 | ||
2681 | while (1) | |
2682 | { | |
2683 | if (start + 2 * pointer_size > section_end) | |
2684 | { | |
2685 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
2686 | offset); | |
2687 | break; | |
2688 | } | |
2689 | ||
2d9472a2 NC |
2690 | /* Note: we use sign extension here in order to be sure that |
2691 | we can detect the -1 escape value. Sign extension into the | |
2692 | top 32 bits of a 32-bit address will not affect the values | |
2693 | that we display since we always show hex values, and always | |
2694 | the bottom 32-bits. */ | |
2695 | begin = byte_get_signed (start, pointer_size); | |
19e6b90e | 2696 | start += pointer_size; |
2d9472a2 | 2697 | end = byte_get_signed (start, pointer_size); |
19e6b90e L |
2698 | start += pointer_size; |
2699 | ||
2d9472a2 NC |
2700 | printf (" %8.8lx ", offset); |
2701 | ||
19e6b90e L |
2702 | if (begin == 0 && end == 0) |
2703 | { | |
2d9472a2 | 2704 | printf (_("<End of list>\n")); |
19e6b90e L |
2705 | break; |
2706 | } | |
2707 | ||
2708 | /* Check base address specifiers. */ | |
2d9472a2 | 2709 | if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1) |
19e6b90e L |
2710 | { |
2711 | base_address = end; | |
2d9472a2 NC |
2712 | print_dwarf_vma (begin, pointer_size); |
2713 | print_dwarf_vma (end, pointer_size); | |
2714 | printf (_("(base address)\n")); | |
19e6b90e L |
2715 | continue; |
2716 | } | |
2717 | ||
2718 | if (start + 2 > section_end) | |
2719 | { | |
2720 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
2721 | offset); | |
2722 | break; | |
2723 | } | |
2724 | ||
2725 | length = byte_get (start, 2); | |
2726 | start += 2; | |
2727 | ||
2728 | if (start + length > section_end) | |
2729 | { | |
2730 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
2731 | offset); | |
2732 | break; | |
2733 | } | |
2734 | ||
2d9472a2 NC |
2735 | print_dwarf_vma (begin + base_address, pointer_size); |
2736 | print_dwarf_vma (end + base_address, pointer_size); | |
2737 | ||
2738 | putchar ('('); | |
19e6b90e L |
2739 | need_frame_base = decode_location_expression (start, |
2740 | pointer_size, | |
2741 | length, | |
2742 | cu_offset); | |
2743 | putchar (')'); | |
2744 | ||
2745 | if (need_frame_base && !has_frame_base) | |
2746 | printf (_(" [without DW_AT_frame_base]")); | |
2747 | ||
2748 | if (begin == end) | |
2749 | fputs (_(" (start == end)"), stdout); | |
2750 | else if (begin > end) | |
2751 | fputs (_(" (start > end)"), stdout); | |
2752 | ||
2753 | putchar ('\n'); | |
2754 | ||
2755 | start += length; | |
2756 | } | |
2757 | } | |
2758 | } | |
031cd65f NC |
2759 | |
2760 | if (start < section_end) | |
2761 | warn (_("There are %ld unused bytes at the end of section %s\n"), | |
0eb090cb | 2762 | (long) (section_end - start), section->name); |
19e6b90e L |
2763 | return 1; |
2764 | } | |
2765 | ||
2766 | static int | |
2767 | display_debug_str (struct dwarf_section *section, | |
2768 | void *file ATTRIBUTE_UNUSED) | |
2769 | { | |
2770 | unsigned char *start = section->start; | |
2771 | unsigned long bytes = section->size; | |
2772 | dwarf_vma addr = section->address; | |
2773 | ||
2774 | if (bytes == 0) | |
2775 | { | |
2776 | printf (_("\nThe %s section is empty.\n"), section->name); | |
2777 | return 0; | |
2778 | } | |
2779 | ||
2780 | printf (_("Contents of the %s section:\n\n"), section->name); | |
2781 | ||
2782 | while (bytes) | |
2783 | { | |
2784 | int j; | |
2785 | int k; | |
2786 | int lbytes; | |
2787 | ||
2788 | lbytes = (bytes > 16 ? 16 : bytes); | |
2789 | ||
2790 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
2791 | ||
2792 | for (j = 0; j < 16; j++) | |
2793 | { | |
2794 | if (j < lbytes) | |
2795 | printf ("%2.2x", start[j]); | |
2796 | else | |
2797 | printf (" "); | |
2798 | ||
2799 | if ((j & 3) == 3) | |
2800 | printf (" "); | |
2801 | } | |
2802 | ||
2803 | for (j = 0; j < lbytes; j++) | |
2804 | { | |
2805 | k = start[j]; | |
2806 | if (k >= ' ' && k < 0x80) | |
2807 | printf ("%c", k); | |
2808 | else | |
2809 | printf ("."); | |
2810 | } | |
2811 | ||
2812 | putchar ('\n'); | |
2813 | ||
2814 | start += lbytes; | |
2815 | addr += lbytes; | |
2816 | bytes -= lbytes; | |
2817 | } | |
2818 | ||
2819 | putchar ('\n'); | |
2820 | ||
2821 | return 1; | |
2822 | } | |
2823 | ||
19e6b90e L |
2824 | static int |
2825 | display_debug_info (struct dwarf_section *section, void *file) | |
2826 | { | |
2827 | return process_debug_info (section, file, 0); | |
2828 | } | |
2829 | ||
2830 | ||
2831 | static int | |
2832 | display_debug_aranges (struct dwarf_section *section, | |
2833 | void *file ATTRIBUTE_UNUSED) | |
2834 | { | |
2835 | unsigned char *start = section->start; | |
2836 | unsigned char *end = start + section->size; | |
2837 | ||
2838 | printf (_("The section %s contains:\n\n"), section->name); | |
2839 | ||
6e3d6dc1 NC |
2840 | /* It does not matter if this load fails, |
2841 | we test for that later on. */ | |
2842 | load_debug_info (file); | |
2843 | ||
19e6b90e L |
2844 | while (start < end) |
2845 | { | |
2846 | unsigned char *hdrptr; | |
2847 | DWARF2_Internal_ARange arange; | |
2848 | unsigned char *ranges; | |
2d9472a2 NC |
2849 | dwarf_vma length; |
2850 | dwarf_vma address; | |
53b8873b | 2851 | unsigned char address_size; |
19e6b90e L |
2852 | int excess; |
2853 | int offset_size; | |
2854 | int initial_length_size; | |
2855 | ||
2856 | hdrptr = start; | |
2857 | ||
2858 | arange.ar_length = byte_get (hdrptr, 4); | |
2859 | hdrptr += 4; | |
2860 | ||
2861 | if (arange.ar_length == 0xffffffff) | |
2862 | { | |
2863 | arange.ar_length = byte_get (hdrptr, 8); | |
2864 | hdrptr += 8; | |
2865 | offset_size = 8; | |
2866 | initial_length_size = 12; | |
2867 | } | |
2868 | else | |
2869 | { | |
2870 | offset_size = 4; | |
2871 | initial_length_size = 4; | |
2872 | } | |
2873 | ||
2874 | arange.ar_version = byte_get (hdrptr, 2); | |
2875 | hdrptr += 2; | |
2876 | ||
2877 | arange.ar_info_offset = byte_get (hdrptr, offset_size); | |
2878 | hdrptr += offset_size; | |
2879 | ||
6e3d6dc1 NC |
2880 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
2881 | && num_debug_info_entries > 0 | |
2882 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
2883 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
2884 | arange.ar_info_offset, section->name); | |
2885 | ||
19e6b90e L |
2886 | arange.ar_pointer_size = byte_get (hdrptr, 1); |
2887 | hdrptr += 1; | |
2888 | ||
2889 | arange.ar_segment_size = byte_get (hdrptr, 1); | |
2890 | hdrptr += 1; | |
2891 | ||
2892 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
2893 | { | |
2894 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
2895 | break; | |
2896 | } | |
2897 | ||
2898 | printf (_(" Length: %ld\n"), arange.ar_length); | |
2899 | printf (_(" Version: %d\n"), arange.ar_version); | |
6e3d6dc1 | 2900 | printf (_(" Offset into .debug_info: 0x%lx\n"), arange.ar_info_offset); |
19e6b90e L |
2901 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
2902 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
2903 | ||
53b8873b NC |
2904 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
2905 | ||
2906 | /* The DWARF spec does not require that the address size be a power | |
2907 | of two, but we do. This will have to change if we ever encounter | |
2908 | an uneven architecture. */ | |
2909 | if ((address_size & (address_size - 1)) != 0) | |
2910 | { | |
2911 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
2912 | break; | |
2913 | } | |
2914 | ||
209c9a13 NC |
2915 | if (address_size > 4) |
2916 | printf (_("\n Address Length\n")); | |
2917 | else | |
2918 | printf (_("\n Address Length\n")); | |
19e6b90e L |
2919 | |
2920 | ranges = hdrptr; | |
2921 | ||
53b8873b NC |
2922 | /* Must pad to an alignment boundary that is twice the address size. */ |
2923 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 2924 | if (excess) |
53b8873b | 2925 | ranges += (2 * address_size) - excess; |
19e6b90e | 2926 | |
1617e571 AM |
2927 | start += arange.ar_length + initial_length_size; |
2928 | ||
53b8873b | 2929 | while (ranges + 2 * address_size <= start) |
19e6b90e | 2930 | { |
53b8873b | 2931 | address = byte_get (ranges, address_size); |
19e6b90e | 2932 | |
53b8873b | 2933 | ranges += address_size; |
19e6b90e | 2934 | |
53b8873b | 2935 | length = byte_get (ranges, address_size); |
19e6b90e | 2936 | |
53b8873b | 2937 | ranges += address_size; |
19e6b90e | 2938 | |
2d9472a2 NC |
2939 | print_dwarf_vma (address, address_size); |
2940 | print_dwarf_vma (length, address_size); | |
2941 | putchar ('\n'); | |
19e6b90e | 2942 | } |
19e6b90e L |
2943 | } |
2944 | ||
2945 | printf ("\n"); | |
2946 | ||
2947 | return 1; | |
2948 | } | |
2949 | ||
2950 | static int | |
2951 | display_debug_ranges (struct dwarf_section *section, | |
2952 | void *file ATTRIBUTE_UNUSED) | |
2953 | { | |
2954 | unsigned char *start = section->start; | |
2955 | unsigned char *section_end; | |
2956 | unsigned long bytes; | |
2957 | unsigned char *section_begin = start; | |
2958 | unsigned int num_range_list = 0; | |
2959 | unsigned long last_offset = 0; | |
2960 | unsigned int first = 0; | |
2961 | unsigned int i; | |
2962 | unsigned int j; | |
2963 | int seen_first_offset = 0; | |
2964 | int use_debug_info = 1; | |
2965 | unsigned char *next; | |
2966 | ||
2967 | bytes = section->size; | |
2968 | section_end = start + bytes; | |
2969 | ||
2970 | if (bytes == 0) | |
2971 | { | |
2972 | printf (_("\nThe %s section is empty.\n"), section->name); | |
2973 | return 0; | |
2974 | } | |
2975 | ||
1febe64d NC |
2976 | if (load_debug_info (file) == 0) |
2977 | { | |
2978 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
2979 | section->name); | |
2980 | return 0; | |
2981 | } | |
19e6b90e L |
2982 | |
2983 | /* Check the order of range list in .debug_info section. If | |
2984 | offsets of range lists are in the ascending order, we can | |
2985 | use `debug_information' directly. */ | |
2986 | for (i = 0; i < num_debug_info_entries; i++) | |
2987 | { | |
2988 | unsigned int num; | |
2989 | ||
2990 | num = debug_information [i].num_range_lists; | |
2991 | num_range_list += num; | |
2992 | ||
2993 | /* Check if we can use `debug_information' directly. */ | |
2994 | if (use_debug_info && num != 0) | |
2995 | { | |
2996 | if (!seen_first_offset) | |
2997 | { | |
2998 | /* This is the first range list. */ | |
2999 | last_offset = debug_information [i].range_lists [0]; | |
3000 | first = i; | |
3001 | seen_first_offset = 1; | |
3002 | j = 1; | |
3003 | } | |
3004 | else | |
3005 | j = 0; | |
3006 | ||
3007 | for (; j < num; j++) | |
3008 | { | |
3009 | if (last_offset > | |
3010 | debug_information [i].range_lists [j]) | |
3011 | { | |
3012 | use_debug_info = 0; | |
3013 | break; | |
3014 | } | |
3015 | last_offset = debug_information [i].range_lists [j]; | |
3016 | } | |
3017 | } | |
3018 | } | |
3019 | ||
3020 | if (!use_debug_info) | |
3021 | /* FIXME: Should we handle this case? */ | |
3022 | error (_("Range lists in .debug_info section aren't in ascending order!\n")); | |
3023 | ||
3024 | if (!seen_first_offset) | |
3025 | error (_("No range lists in .debug_info section!\n")); | |
3026 | ||
bfe2612a | 3027 | /* DWARF sections under Mach-O have non-zero addresses. */ |
d4bfc77b AS |
3028 | if (debug_information [first].num_range_lists > 0 |
3029 | && debug_information [first].range_lists [0] != section->address) | |
19e6b90e L |
3030 | warn (_("Range lists in %s section start at 0x%lx\n"), |
3031 | section->name, debug_information [first].range_lists [0]); | |
3032 | ||
3033 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3034 | printf (_(" Offset Begin End\n")); | |
3035 | ||
3036 | seen_first_offset = 0; | |
3037 | for (i = first; i < num_debug_info_entries; i++) | |
3038 | { | |
2d9472a2 NC |
3039 | dwarf_vma begin; |
3040 | dwarf_vma end; | |
19e6b90e L |
3041 | unsigned long offset; |
3042 | unsigned int pointer_size; | |
3043 | unsigned long base_address; | |
3044 | ||
3045 | pointer_size = debug_information [i].pointer_size; | |
2d9472a2 | 3046 | |
19e6b90e L |
3047 | for (j = 0; j < debug_information [i].num_range_lists; j++) |
3048 | { | |
bfe2612a L |
3049 | /* DWARF sections under Mach-O have non-zero addresses. */ |
3050 | offset = debug_information [i].range_lists [j] - section->address; | |
19e6b90e L |
3051 | next = section_begin + offset; |
3052 | base_address = debug_information [i].base_address; | |
3053 | ||
3054 | if (!seen_first_offset) | |
3055 | seen_first_offset = 1; | |
3056 | else | |
3057 | { | |
3058 | if (start < next) | |
3059 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
3060 | (long)(start - section_begin), | |
3061 | (long)(next - section_begin), section->name); | |
3062 | else if (start > next) | |
3063 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
3064 | (long)(start - section_begin), | |
3065 | (long)(next - section_begin), section->name); | |
3066 | } | |
3067 | start = next; | |
3068 | ||
3069 | while (1) | |
3070 | { | |
2d9472a2 NC |
3071 | /* Note: we use sign extension here in order to be sure that |
3072 | we can detect the -1 escape value. Sign extension into the | |
3073 | top 32 bits of a 32-bit address will not affect the values | |
3074 | that we display since we always show hex values, and always | |
3075 | the bottom 32-bits. */ | |
3076 | begin = byte_get_signed (start, pointer_size); | |
19e6b90e | 3077 | start += pointer_size; |
2d9472a2 | 3078 | end = byte_get_signed (start, pointer_size); |
19e6b90e L |
3079 | start += pointer_size; |
3080 | ||
2d9472a2 NC |
3081 | printf (" %8.8lx ", offset); |
3082 | ||
19e6b90e L |
3083 | if (begin == 0 && end == 0) |
3084 | { | |
2d9472a2 | 3085 | printf (_("<End of list>\n")); |
19e6b90e L |
3086 | break; |
3087 | } | |
3088 | ||
2d9472a2 NC |
3089 | print_dwarf_vma (begin, pointer_size); |
3090 | print_dwarf_vma (end, pointer_size); | |
3091 | ||
19e6b90e | 3092 | /* Check base address specifiers. */ |
2d9472a2 | 3093 | if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1) |
19e6b90e L |
3094 | { |
3095 | base_address = end; | |
2d9472a2 | 3096 | printf ("(base address)\n"); |
19e6b90e L |
3097 | continue; |
3098 | } | |
3099 | ||
19e6b90e | 3100 | if (begin == end) |
2d9472a2 | 3101 | fputs (_("(start == end)"), stdout); |
19e6b90e | 3102 | else if (begin > end) |
2d9472a2 | 3103 | fputs (_("(start > end)"), stdout); |
19e6b90e L |
3104 | |
3105 | putchar ('\n'); | |
3106 | } | |
3107 | } | |
3108 | } | |
3109 | putchar ('\n'); | |
3110 | return 1; | |
3111 | } | |
3112 | ||
3113 | typedef struct Frame_Chunk | |
3114 | { | |
3115 | struct Frame_Chunk *next; | |
3116 | unsigned char *chunk_start; | |
3117 | int ncols; | |
3118 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ | |
3119 | short int *col_type; | |
3120 | int *col_offset; | |
3121 | char *augmentation; | |
3122 | unsigned int code_factor; | |
3123 | int data_factor; | |
3124 | unsigned long pc_begin; | |
3125 | unsigned long pc_range; | |
3126 | int cfa_reg; | |
3127 | int cfa_offset; | |
3128 | int ra; | |
3129 | unsigned char fde_encoding; | |
3130 | unsigned char cfa_exp; | |
3131 | } | |
3132 | Frame_Chunk; | |
3133 | ||
3134 | /* A marker for a col_type that means this column was never referenced | |
3135 | in the frame info. */ | |
3136 | #define DW_CFA_unreferenced (-1) | |
3137 | ||
3138 | static void | |
3139 | frame_need_space (Frame_Chunk *fc, int reg) | |
3140 | { | |
3141 | int prev = fc->ncols; | |
3142 | ||
3143 | if (reg < fc->ncols) | |
3144 | return; | |
3145 | ||
3146 | fc->ncols = reg + 1; | |
3147 | fc->col_type = xcrealloc (fc->col_type, fc->ncols, sizeof (short int)); | |
3148 | fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); | |
3149 | ||
3150 | while (prev < fc->ncols) | |
3151 | { | |
3152 | fc->col_type[prev] = DW_CFA_unreferenced; | |
3153 | fc->col_offset[prev] = 0; | |
3154 | prev++; | |
3155 | } | |
3156 | } | |
3157 | ||
2dc4cec1 L |
3158 | static const char *const dwarf_regnames_i386[] = |
3159 | { | |
3160 | "eax", "ecx", "edx", "ebx", | |
3161 | "esp", "ebp", "esi", "edi", | |
3162 | "eip", "eflags", NULL, | |
3163 | "st0", "st1", "st2", "st3", | |
3164 | "st4", "st5", "st6", "st7", | |
3165 | NULL, NULL, | |
3166 | "xmm0", "xmm1", "xmm2", "xmm3", | |
3167 | "xmm4", "xmm5", "xmm6", "xmm7", | |
3168 | "mm0", "mm1", "mm2", "mm3", | |
3169 | "mm4", "mm5", "mm6", "mm7", | |
3170 | "fcw", "fsw", "mxcsr", | |
3171 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
3172 | "tr", "ldtr" | |
3173 | }; | |
3174 | ||
3175 | static const char *const dwarf_regnames_x86_64[] = | |
3176 | { | |
3177 | "rax", "rdx", "rcx", "rbx", | |
3178 | "rsi", "rdi", "rbp", "rsp", | |
3179 | "r8", "r9", "r10", "r11", | |
3180 | "r12", "r13", "r14", "r15", | |
3181 | "rip", | |
3182 | "xmm0", "xmm1", "xmm2", "xmm3", | |
3183 | "xmm4", "xmm5", "xmm6", "xmm7", | |
3184 | "xmm8", "xmm9", "xmm10", "xmm11", | |
3185 | "xmm12", "xmm13", "xmm14", "xmm15", | |
3186 | "st0", "st1", "st2", "st3", | |
3187 | "st4", "st5", "st6", "st7", | |
3188 | "mm0", "mm1", "mm2", "mm3", | |
3189 | "mm4", "mm5", "mm6", "mm7", | |
3190 | "rflags", | |
3191 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
3192 | "fs.base", "gs.base", NULL, NULL, | |
3193 | "tr", "ldtr", | |
3194 | "mxcsr", "fcw", "fsw" | |
3195 | }; | |
3196 | ||
3197 | static const char *const *dwarf_regnames; | |
3198 | static unsigned int dwarf_regnames_count; | |
3199 | ||
3200 | void | |
3201 | init_dwarf_regnames (unsigned int e_machine) | |
3202 | { | |
3203 | switch (e_machine) | |
3204 | { | |
3205 | case EM_386: | |
3206 | case EM_486: | |
3207 | dwarf_regnames = dwarf_regnames_i386; | |
3208 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
3209 | break; | |
3210 | ||
3211 | case EM_X86_64: | |
3212 | dwarf_regnames = dwarf_regnames_x86_64; | |
3213 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
3214 | break; | |
3215 | ||
3216 | default: | |
3217 | break; | |
3218 | } | |
3219 | } | |
3220 | ||
3221 | static const char * | |
3222 | regname (unsigned int regno, int row) | |
3223 | { | |
3224 | static char reg[64]; | |
3225 | if (dwarf_regnames | |
3226 | && regno < dwarf_regnames_count | |
3227 | && dwarf_regnames [regno] != NULL) | |
3228 | { | |
3229 | if (row) | |
3230 | return dwarf_regnames [regno]; | |
3231 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, | |
3232 | dwarf_regnames [regno]); | |
3233 | } | |
3234 | else | |
3235 | snprintf (reg, sizeof (reg), "r%d", regno); | |
3236 | return reg; | |
3237 | } | |
3238 | ||
19e6b90e L |
3239 | static void |
3240 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs) | |
3241 | { | |
3242 | int r; | |
3243 | char tmp[100]; | |
3244 | ||
3245 | if (*max_regs < fc->ncols) | |
3246 | *max_regs = fc->ncols; | |
3247 | ||
3248 | if (*need_col_headers) | |
3249 | { | |
2dc4cec1 L |
3250 | static const char *loc = " LOC"; |
3251 | ||
19e6b90e L |
3252 | *need_col_headers = 0; |
3253 | ||
2dc4cec1 | 3254 | printf ("%-*s CFA ", eh_addr_size * 2, loc); |
19e6b90e L |
3255 | |
3256 | for (r = 0; r < *max_regs; r++) | |
3257 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
3258 | { | |
3259 | if (r == fc->ra) | |
2dc4cec1 | 3260 | printf ("ra "); |
19e6b90e | 3261 | else |
2dc4cec1 | 3262 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
3263 | } |
3264 | ||
3265 | printf ("\n"); | |
3266 | } | |
3267 | ||
2dc4cec1 | 3268 | printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin); |
19e6b90e L |
3269 | if (fc->cfa_exp) |
3270 | strcpy (tmp, "exp"); | |
3271 | else | |
2dc4cec1 | 3272 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset); |
19e6b90e L |
3273 | printf ("%-8s ", tmp); |
3274 | ||
3275 | for (r = 0; r < fc->ncols; r++) | |
3276 | { | |
3277 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
3278 | { | |
3279 | switch (fc->col_type[r]) | |
3280 | { | |
3281 | case DW_CFA_undefined: | |
3282 | strcpy (tmp, "u"); | |
3283 | break; | |
3284 | case DW_CFA_same_value: | |
3285 | strcpy (tmp, "s"); | |
3286 | break; | |
3287 | case DW_CFA_offset: | |
3288 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
3289 | break; | |
12eae2d3 JJ |
3290 | case DW_CFA_val_offset: |
3291 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
3292 | break; | |
19e6b90e | 3293 | case DW_CFA_register: |
2dc4cec1 | 3294 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
3295 | break; |
3296 | case DW_CFA_expression: | |
3297 | strcpy (tmp, "exp"); | |
3298 | break; | |
12eae2d3 JJ |
3299 | case DW_CFA_val_expression: |
3300 | strcpy (tmp, "vexp"); | |
3301 | break; | |
19e6b90e L |
3302 | default: |
3303 | strcpy (tmp, "n/a"); | |
3304 | break; | |
3305 | } | |
2dc4cec1 | 3306 | printf ("%-5s ", tmp); |
19e6b90e L |
3307 | } |
3308 | } | |
3309 | printf ("\n"); | |
3310 | } | |
3311 | ||
3312 | static int | |
3313 | size_of_encoded_value (int encoding) | |
3314 | { | |
3315 | switch (encoding & 0x7) | |
3316 | { | |
3317 | default: /* ??? */ | |
3318 | case 0: return eh_addr_size; | |
3319 | case 2: return 2; | |
3320 | case 3: return 4; | |
3321 | case 4: return 8; | |
3322 | } | |
3323 | } | |
3324 | ||
3325 | static dwarf_vma | |
3326 | get_encoded_value (unsigned char *data, int encoding) | |
3327 | { | |
3328 | int size = size_of_encoded_value (encoding); | |
53b8873b | 3329 | |
19e6b90e L |
3330 | if (encoding & DW_EH_PE_signed) |
3331 | return byte_get_signed (data, size); | |
3332 | else | |
3333 | return byte_get (data, size); | |
3334 | } | |
3335 | ||
3336 | #define GET(N) byte_get (start, N); start += N | |
3337 | #define LEB() read_leb128 (start, & length_return, 0); start += length_return | |
3338 | #define SLEB() read_leb128 (start, & length_return, 1); start += length_return | |
3339 | ||
3340 | static int | |
3341 | display_debug_frames (struct dwarf_section *section, | |
3342 | void *file ATTRIBUTE_UNUSED) | |
3343 | { | |
3344 | unsigned char *start = section->start; | |
3345 | unsigned char *end = start + section->size; | |
3346 | unsigned char *section_start = start; | |
3347 | Frame_Chunk *chunks = 0; | |
3348 | Frame_Chunk *remembered_state = 0; | |
3349 | Frame_Chunk *rs; | |
3350 | int is_eh = strcmp (section->name, ".eh_frame") == 0; | |
3351 | unsigned int length_return; | |
3352 | int max_regs = 0; | |
3353 | ||
3354 | printf (_("The section %s contains:\n"), section->name); | |
3355 | ||
3356 | while (start < end) | |
3357 | { | |
3358 | unsigned char *saved_start; | |
3359 | unsigned char *block_end; | |
3360 | unsigned long length; | |
3361 | unsigned long cie_id; | |
3362 | Frame_Chunk *fc; | |
3363 | Frame_Chunk *cie; | |
3364 | int need_col_headers = 1; | |
3365 | unsigned char *augmentation_data = NULL; | |
3366 | unsigned long augmentation_data_len = 0; | |
3367 | int encoded_ptr_size = eh_addr_size; | |
3368 | int offset_size; | |
3369 | int initial_length_size; | |
3370 | ||
3371 | saved_start = start; | |
3372 | length = byte_get (start, 4); start += 4; | |
3373 | ||
3374 | if (length == 0) | |
3375 | { | |
3376 | printf ("\n%08lx ZERO terminator\n\n", | |
3377 | (unsigned long)(saved_start - section_start)); | |
b758e50f | 3378 | continue; |
19e6b90e L |
3379 | } |
3380 | ||
3381 | if (length == 0xffffffff) | |
3382 | { | |
3383 | length = byte_get (start, 8); | |
3384 | start += 8; | |
3385 | offset_size = 8; | |
3386 | initial_length_size = 12; | |
3387 | } | |
3388 | else | |
3389 | { | |
3390 | offset_size = 4; | |
3391 | initial_length_size = 4; | |
3392 | } | |
3393 | ||
3394 | block_end = saved_start + length + initial_length_size; | |
53b8873b NC |
3395 | if (block_end > end) |
3396 | { | |
3397 | warn ("Invalid length %#08lx in FDE at %#08lx\n", | |
3398 | length, (unsigned long)(saved_start - section_start)); | |
3399 | block_end = end; | |
3400 | } | |
19e6b90e L |
3401 | cie_id = byte_get (start, offset_size); start += offset_size; |
3402 | ||
3403 | if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID)) | |
3404 | { | |
3405 | int version; | |
3406 | ||
3407 | fc = xmalloc (sizeof (Frame_Chunk)); | |
3408 | memset (fc, 0, sizeof (Frame_Chunk)); | |
3409 | ||
3410 | fc->next = chunks; | |
3411 | chunks = fc; | |
3412 | fc->chunk_start = saved_start; | |
3413 | fc->ncols = 0; | |
3414 | fc->col_type = xmalloc (sizeof (short int)); | |
3415 | fc->col_offset = xmalloc (sizeof (int)); | |
cc86f28f | 3416 | frame_need_space (fc, max_regs - 1); |
19e6b90e L |
3417 | |
3418 | version = *start++; | |
3419 | ||
3420 | fc->augmentation = (char *) start; | |
3421 | start = (unsigned char *) strchr ((char *) start, '\0') + 1; | |
3422 | ||
3423 | if (fc->augmentation[0] == 'z') | |
3424 | { | |
3425 | fc->code_factor = LEB (); | |
3426 | fc->data_factor = SLEB (); | |
3427 | if (version == 1) | |
3428 | { | |
3429 | fc->ra = GET (1); | |
3430 | } | |
3431 | else | |
3432 | { | |
3433 | fc->ra = LEB (); | |
3434 | } | |
3435 | augmentation_data_len = LEB (); | |
3436 | augmentation_data = start; | |
3437 | start += augmentation_data_len; | |
3438 | } | |
3439 | else if (strcmp (fc->augmentation, "eh") == 0) | |
3440 | { | |
3441 | start += eh_addr_size; | |
3442 | fc->code_factor = LEB (); | |
3443 | fc->data_factor = SLEB (); | |
3444 | if (version == 1) | |
3445 | { | |
3446 | fc->ra = GET (1); | |
3447 | } | |
3448 | else | |
3449 | { | |
3450 | fc->ra = LEB (); | |
3451 | } | |
3452 | } | |
3453 | else | |
3454 | { | |
3455 | fc->code_factor = LEB (); | |
3456 | fc->data_factor = SLEB (); | |
3457 | if (version == 1) | |
3458 | { | |
3459 | fc->ra = GET (1); | |
3460 | } | |
3461 | else | |
3462 | { | |
3463 | fc->ra = LEB (); | |
3464 | } | |
3465 | } | |
3466 | cie = fc; | |
3467 | ||
3468 | if (do_debug_frames_interp) | |
3469 | printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n", | |
3470 | (unsigned long)(saved_start - section_start), length, cie_id, | |
3471 | fc->augmentation, fc->code_factor, fc->data_factor, | |
3472 | fc->ra); | |
3473 | else | |
3474 | { | |
3475 | printf ("\n%08lx %08lx %08lx CIE\n", | |
3476 | (unsigned long)(saved_start - section_start), length, cie_id); | |
3477 | printf (" Version: %d\n", version); | |
3478 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
3479 | printf (" Code alignment factor: %u\n", fc->code_factor); | |
3480 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
3481 | printf (" Return address column: %d\n", fc->ra); | |
3482 | ||
3483 | if (augmentation_data_len) | |
3484 | { | |
3485 | unsigned long i; | |
3486 | printf (" Augmentation data: "); | |
3487 | for (i = 0; i < augmentation_data_len; ++i) | |
3488 | printf (" %02x", augmentation_data[i]); | |
3489 | putchar ('\n'); | |
3490 | } | |
3491 | putchar ('\n'); | |
3492 | } | |
3493 | ||
3494 | if (augmentation_data_len) | |
3495 | { | |
3496 | unsigned char *p, *q; | |
3497 | p = (unsigned char *) fc->augmentation + 1; | |
3498 | q = augmentation_data; | |
3499 | ||
3500 | while (1) | |
3501 | { | |
3502 | if (*p == 'L') | |
3503 | q++; | |
3504 | else if (*p == 'P') | |
3505 | q += 1 + size_of_encoded_value (*q); | |
3506 | else if (*p == 'R') | |
3507 | fc->fde_encoding = *q++; | |
3508 | else | |
3509 | break; | |
3510 | p++; | |
3511 | } | |
3512 | ||
3513 | if (fc->fde_encoding) | |
3514 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
3515 | } | |
3516 | ||
3517 | frame_need_space (fc, fc->ra); | |
3518 | } | |
3519 | else | |
3520 | { | |
3521 | unsigned char *look_for; | |
3522 | static Frame_Chunk fde_fc; | |
3523 | ||
3524 | fc = & fde_fc; | |
3525 | memset (fc, 0, sizeof (Frame_Chunk)); | |
3526 | ||
3527 | look_for = is_eh ? start - 4 - cie_id : section_start + cie_id; | |
3528 | ||
3529 | for (cie = chunks; cie ; cie = cie->next) | |
3530 | if (cie->chunk_start == look_for) | |
3531 | break; | |
3532 | ||
3533 | if (!cie) | |
3534 | { | |
53b8873b | 3535 | warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n", |
1617e571 | 3536 | cie_id, (unsigned long)(saved_start - section_start)); |
19e6b90e L |
3537 | fc->ncols = 0; |
3538 | fc->col_type = xmalloc (sizeof (short int)); | |
3539 | fc->col_offset = xmalloc (sizeof (int)); | |
3540 | frame_need_space (fc, max_regs - 1); | |
3541 | cie = fc; | |
3542 | fc->augmentation = ""; | |
3543 | fc->fde_encoding = 0; | |
3544 | } | |
3545 | else | |
3546 | { | |
3547 | fc->ncols = cie->ncols; | |
3548 | fc->col_type = xcmalloc (fc->ncols, sizeof (short int)); | |
3549 | fc->col_offset = xcmalloc (fc->ncols, sizeof (int)); | |
3550 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); | |
3551 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
3552 | fc->augmentation = cie->augmentation; | |
3553 | fc->code_factor = cie->code_factor; | |
3554 | fc->data_factor = cie->data_factor; | |
3555 | fc->cfa_reg = cie->cfa_reg; | |
3556 | fc->cfa_offset = cie->cfa_offset; | |
3557 | fc->ra = cie->ra; | |
cc86f28f | 3558 | frame_need_space (fc, max_regs - 1); |
19e6b90e L |
3559 | fc->fde_encoding = cie->fde_encoding; |
3560 | } | |
3561 | ||
3562 | if (fc->fde_encoding) | |
3563 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
3564 | ||
3565 | fc->pc_begin = get_encoded_value (start, fc->fde_encoding); | |
41e92641 | 3566 | if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel) |
19e6b90e L |
3567 | fc->pc_begin += section->address + (start - section_start); |
3568 | start += encoded_ptr_size; | |
3569 | fc->pc_range = byte_get (start, encoded_ptr_size); | |
3570 | start += encoded_ptr_size; | |
3571 | ||
3572 | if (cie->augmentation[0] == 'z') | |
3573 | { | |
3574 | augmentation_data_len = LEB (); | |
3575 | augmentation_data = start; | |
3576 | start += augmentation_data_len; | |
3577 | } | |
3578 | ||
3579 | printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n", | |
3580 | (unsigned long)(saved_start - section_start), length, cie_id, | |
3581 | (unsigned long)(cie->chunk_start - section_start), | |
3582 | fc->pc_begin, fc->pc_begin + fc->pc_range); | |
3583 | if (! do_debug_frames_interp && augmentation_data_len) | |
3584 | { | |
3585 | unsigned long i; | |
3586 | ||
3587 | printf (" Augmentation data: "); | |
3588 | for (i = 0; i < augmentation_data_len; ++i) | |
3589 | printf (" %02x", augmentation_data[i]); | |
3590 | putchar ('\n'); | |
3591 | putchar ('\n'); | |
3592 | } | |
3593 | } | |
3594 | ||
3595 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
3596 | we're about to interpret instructions for the chunk. */ | |
3597 | /* ??? At present we need to do this always, since this sizes the | |
3598 | fc->col_type and fc->col_offset arrays, which we write into always. | |
3599 | We should probably split the interpreted and non-interpreted bits | |
3600 | into two different routines, since there's so much that doesn't | |
3601 | really overlap between them. */ | |
3602 | if (1 || do_debug_frames_interp) | |
3603 | { | |
3604 | /* Start by making a pass over the chunk, allocating storage | |
3605 | and taking note of what registers are used. */ | |
3606 | unsigned char *tmp = start; | |
3607 | ||
3608 | while (start < block_end) | |
3609 | { | |
3610 | unsigned op, opa; | |
3611 | unsigned long reg, tmp; | |
3612 | ||
3613 | op = *start++; | |
3614 | opa = op & 0x3f; | |
3615 | if (op & 0xc0) | |
3616 | op &= 0xc0; | |
3617 | ||
3618 | /* Warning: if you add any more cases to this switch, be | |
3619 | sure to add them to the corresponding switch below. */ | |
3620 | switch (op) | |
3621 | { | |
3622 | case DW_CFA_advance_loc: | |
3623 | break; | |
3624 | case DW_CFA_offset: | |
3625 | LEB (); | |
3626 | frame_need_space (fc, opa); | |
3627 | fc->col_type[opa] = DW_CFA_undefined; | |
3628 | break; | |
3629 | case DW_CFA_restore: | |
3630 | frame_need_space (fc, opa); | |
3631 | fc->col_type[opa] = DW_CFA_undefined; | |
3632 | break; | |
3633 | case DW_CFA_set_loc: | |
3634 | start += encoded_ptr_size; | |
3635 | break; | |
3636 | case DW_CFA_advance_loc1: | |
3637 | start += 1; | |
3638 | break; | |
3639 | case DW_CFA_advance_loc2: | |
3640 | start += 2; | |
3641 | break; | |
3642 | case DW_CFA_advance_loc4: | |
3643 | start += 4; | |
3644 | break; | |
3645 | case DW_CFA_offset_extended: | |
12eae2d3 | 3646 | case DW_CFA_val_offset: |
19e6b90e L |
3647 | reg = LEB (); LEB (); |
3648 | frame_need_space (fc, reg); | |
3649 | fc->col_type[reg] = DW_CFA_undefined; | |
3650 | break; | |
3651 | case DW_CFA_restore_extended: | |
3652 | reg = LEB (); | |
3653 | frame_need_space (fc, reg); | |
3654 | fc->col_type[reg] = DW_CFA_undefined; | |
3655 | break; | |
3656 | case DW_CFA_undefined: | |
3657 | reg = LEB (); | |
3658 | frame_need_space (fc, reg); | |
3659 | fc->col_type[reg] = DW_CFA_undefined; | |
3660 | break; | |
3661 | case DW_CFA_same_value: | |
3662 | reg = LEB (); | |
3663 | frame_need_space (fc, reg); | |
3664 | fc->col_type[reg] = DW_CFA_undefined; | |
3665 | break; | |
3666 | case DW_CFA_register: | |
3667 | reg = LEB (); LEB (); | |
3668 | frame_need_space (fc, reg); | |
3669 | fc->col_type[reg] = DW_CFA_undefined; | |
3670 | break; | |
3671 | case DW_CFA_def_cfa: | |
3672 | LEB (); LEB (); | |
3673 | break; | |
3674 | case DW_CFA_def_cfa_register: | |
3675 | LEB (); | |
3676 | break; | |
3677 | case DW_CFA_def_cfa_offset: | |
3678 | LEB (); | |
3679 | break; | |
3680 | case DW_CFA_def_cfa_expression: | |
3681 | tmp = LEB (); | |
3682 | start += tmp; | |
3683 | break; | |
3684 | case DW_CFA_expression: | |
12eae2d3 | 3685 | case DW_CFA_val_expression: |
19e6b90e L |
3686 | reg = LEB (); |
3687 | tmp = LEB (); | |
3688 | start += tmp; | |
3689 | frame_need_space (fc, reg); | |
3690 | fc->col_type[reg] = DW_CFA_undefined; | |
3691 | break; | |
3692 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 3693 | case DW_CFA_val_offset_sf: |
19e6b90e L |
3694 | reg = LEB (); SLEB (); |
3695 | frame_need_space (fc, reg); | |
3696 | fc->col_type[reg] = DW_CFA_undefined; | |
3697 | break; | |
3698 | case DW_CFA_def_cfa_sf: | |
3699 | LEB (); SLEB (); | |
3700 | break; | |
3701 | case DW_CFA_def_cfa_offset_sf: | |
3702 | SLEB (); | |
3703 | break; | |
3704 | case DW_CFA_MIPS_advance_loc8: | |
3705 | start += 8; | |
3706 | break; | |
3707 | case DW_CFA_GNU_args_size: | |
3708 | LEB (); | |
3709 | break; | |
3710 | case DW_CFA_GNU_negative_offset_extended: | |
3711 | reg = LEB (); LEB (); | |
3712 | frame_need_space (fc, reg); | |
3713 | fc->col_type[reg] = DW_CFA_undefined; | |
3714 | ||
3715 | default: | |
3716 | break; | |
3717 | } | |
3718 | } | |
3719 | start = tmp; | |
3720 | } | |
3721 | ||
3722 | /* Now we know what registers are used, make a second pass over | |
3723 | the chunk, this time actually printing out the info. */ | |
3724 | ||
3725 | while (start < block_end) | |
3726 | { | |
3727 | unsigned op, opa; | |
3728 | unsigned long ul, reg, roffs; | |
3729 | long l, ofs; | |
3730 | dwarf_vma vma; | |
3731 | ||
3732 | op = *start++; | |
3733 | opa = op & 0x3f; | |
3734 | if (op & 0xc0) | |
3735 | op &= 0xc0; | |
3736 | ||
3737 | /* Warning: if you add any more cases to this switch, be | |
3738 | sure to add them to the corresponding switch above. */ | |
3739 | switch (op) | |
3740 | { | |
3741 | case DW_CFA_advance_loc: | |
3742 | if (do_debug_frames_interp) | |
3743 | frame_display_row (fc, &need_col_headers, &max_regs); | |
3744 | else | |
3745 | printf (" DW_CFA_advance_loc: %d to %08lx\n", | |
3746 | opa * fc->code_factor, | |
3747 | fc->pc_begin + opa * fc->code_factor); | |
3748 | fc->pc_begin += opa * fc->code_factor; | |
3749 | break; | |
3750 | ||
3751 | case DW_CFA_offset: | |
3752 | roffs = LEB (); | |
3753 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
3754 | printf (" DW_CFA_offset: %s at cfa%+ld\n", |
3755 | regname (opa, 0), roffs * fc->data_factor); | |
19e6b90e L |
3756 | fc->col_type[opa] = DW_CFA_offset; |
3757 | fc->col_offset[opa] = roffs * fc->data_factor; | |
3758 | break; | |
3759 | ||
3760 | case DW_CFA_restore: | |
3761 | if (! do_debug_frames_interp) | |
2dc4cec1 | 3762 | printf (" DW_CFA_restore: %s\n", regname (opa, 0)); |
19e6b90e L |
3763 | fc->col_type[opa] = cie->col_type[opa]; |
3764 | fc->col_offset[opa] = cie->col_offset[opa]; | |
3765 | break; | |
3766 | ||
3767 | case DW_CFA_set_loc: | |
3768 | vma = get_encoded_value (start, fc->fde_encoding); | |
41e92641 | 3769 | if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel) |
19e6b90e L |
3770 | vma += section->address + (start - section_start); |
3771 | start += encoded_ptr_size; | |
3772 | if (do_debug_frames_interp) | |
3773 | frame_display_row (fc, &need_col_headers, &max_regs); | |
3774 | else | |
3775 | printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma); | |
3776 | fc->pc_begin = vma; | |
3777 | break; | |
3778 | ||
3779 | case DW_CFA_advance_loc1: | |
3780 | ofs = byte_get (start, 1); start += 1; | |
3781 | if (do_debug_frames_interp) | |
3782 | frame_display_row (fc, &need_col_headers, &max_regs); | |
3783 | else | |
3784 | printf (" DW_CFA_advance_loc1: %ld to %08lx\n", | |
3785 | ofs * fc->code_factor, | |
3786 | fc->pc_begin + ofs * fc->code_factor); | |
3787 | fc->pc_begin += ofs * fc->code_factor; | |
3788 | break; | |
3789 | ||
3790 | case DW_CFA_advance_loc2: | |
3791 | ofs = byte_get (start, 2); start += 2; | |
3792 | if (do_debug_frames_interp) | |
3793 | frame_display_row (fc, &need_col_headers, &max_regs); | |
3794 | else | |
3795 | printf (" DW_CFA_advance_loc2: %ld to %08lx\n", | |
3796 | ofs * fc->code_factor, | |
3797 | fc->pc_begin + ofs * fc->code_factor); | |
3798 | fc->pc_begin += ofs * fc->code_factor; | |
3799 | break; | |
3800 | ||
3801 | case DW_CFA_advance_loc4: | |
3802 | ofs = byte_get (start, 4); start += 4; | |
3803 | if (do_debug_frames_interp) | |
3804 | frame_display_row (fc, &need_col_headers, &max_regs); | |
3805 | else | |
3806 | printf (" DW_CFA_advance_loc4: %ld to %08lx\n", | |
3807 | ofs * fc->code_factor, | |
3808 | fc->pc_begin + ofs * fc->code_factor); | |
3809 | fc->pc_begin += ofs * fc->code_factor; | |
3810 | break; | |
3811 | ||
3812 | case DW_CFA_offset_extended: | |
3813 | reg = LEB (); | |
3814 | roffs = LEB (); | |
3815 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
3816 | printf (" DW_CFA_offset_extended: %s at cfa%+ld\n", |
3817 | regname (reg, 0), roffs * fc->data_factor); | |
19e6b90e L |
3818 | fc->col_type[reg] = DW_CFA_offset; |
3819 | fc->col_offset[reg] = roffs * fc->data_factor; | |
3820 | break; | |
3821 | ||
12eae2d3 JJ |
3822 | case DW_CFA_val_offset: |
3823 | reg = LEB (); | |
3824 | roffs = LEB (); | |
3825 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
3826 | printf (" DW_CFA_val_offset: %s at cfa%+ld\n", |
3827 | regname (reg, 0), roffs * fc->data_factor); | |
12eae2d3 JJ |
3828 | fc->col_type[reg] = DW_CFA_val_offset; |
3829 | fc->col_offset[reg] = roffs * fc->data_factor; | |
3830 | break; | |
3831 | ||
19e6b90e L |
3832 | case DW_CFA_restore_extended: |
3833 | reg = LEB (); | |
3834 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
3835 | printf (" DW_CFA_restore_extended: %s\n", |
3836 | regname (reg, 0)); | |
19e6b90e L |
3837 | fc->col_type[reg] = cie->col_type[reg]; |
3838 | fc->col_offset[reg] = cie->col_offset[reg]; | |
3839 | break; | |
3840 | ||
3841 | case DW_CFA_undefined: | |
3842 | reg = LEB (); | |
3843 | if (! do_debug_frames_interp) | |
2dc4cec1 | 3844 | printf (" DW_CFA_undefined: %s\n", regname (reg, 0)); |
19e6b90e L |
3845 | fc->col_type[reg] = DW_CFA_undefined; |
3846 | fc->col_offset[reg] = 0; | |
3847 | break; | |
3848 | ||
3849 | case DW_CFA_same_value: | |
3850 | reg = LEB (); | |
3851 | if (! do_debug_frames_interp) | |
2dc4cec1 | 3852 | printf (" DW_CFA_same_value: %s\n", regname (reg, 0)); |
19e6b90e L |
3853 | fc->col_type[reg] = DW_CFA_same_value; |
3854 | fc->col_offset[reg] = 0; | |
3855 | break; | |
3856 | ||
3857 | case DW_CFA_register: | |
3858 | reg = LEB (); | |
3859 | roffs = LEB (); | |
3860 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
3861 | { |
3862 | printf (" DW_CFA_register: %s in ", | |
3863 | regname (reg, 0)); | |
3864 | puts (regname (roffs, 0)); | |
3865 | } | |
19e6b90e L |
3866 | fc->col_type[reg] = DW_CFA_register; |
3867 | fc->col_offset[reg] = roffs; | |
3868 | break; | |
3869 | ||
3870 | case DW_CFA_remember_state: | |
3871 | if (! do_debug_frames_interp) | |
3872 | printf (" DW_CFA_remember_state\n"); | |
3873 | rs = xmalloc (sizeof (Frame_Chunk)); | |
3874 | rs->ncols = fc->ncols; | |
3875 | rs->col_type = xcmalloc (rs->ncols, sizeof (short int)); | |
3876 | rs->col_offset = xcmalloc (rs->ncols, sizeof (int)); | |
3877 | memcpy (rs->col_type, fc->col_type, rs->ncols); | |
3878 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int)); | |
3879 | rs->next = remembered_state; | |
3880 | remembered_state = rs; | |
3881 | break; | |
3882 | ||
3883 | case DW_CFA_restore_state: | |
3884 | if (! do_debug_frames_interp) | |
3885 | printf (" DW_CFA_restore_state\n"); | |
3886 | rs = remembered_state; | |
3887 | if (rs) | |
3888 | { | |
3889 | remembered_state = rs->next; | |
cc86f28f | 3890 | frame_need_space (fc, rs->ncols - 1); |
19e6b90e L |
3891 | memcpy (fc->col_type, rs->col_type, rs->ncols); |
3892 | memcpy (fc->col_offset, rs->col_offset, | |
3893 | rs->ncols * sizeof (int)); | |
3894 | free (rs->col_type); | |
3895 | free (rs->col_offset); | |
3896 | free (rs); | |
3897 | } | |
3898 | else if (do_debug_frames_interp) | |
3899 | printf ("Mismatched DW_CFA_restore_state\n"); | |
3900 | break; | |
3901 | ||
3902 | case DW_CFA_def_cfa: | |
3903 | fc->cfa_reg = LEB (); | |
3904 | fc->cfa_offset = LEB (); | |
3905 | fc->cfa_exp = 0; | |
3906 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
3907 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
3908 | regname (fc->cfa_reg, 0), fc->cfa_offset); | |
19e6b90e L |
3909 | break; |
3910 | ||
3911 | case DW_CFA_def_cfa_register: | |
3912 | fc->cfa_reg = LEB (); | |
3913 | fc->cfa_exp = 0; | |
3914 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
3915 | printf (" DW_CFA_def_cfa_register: %s\n", |
3916 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
3917 | break; |
3918 | ||
3919 | case DW_CFA_def_cfa_offset: | |
3920 | fc->cfa_offset = LEB (); | |
3921 | if (! do_debug_frames_interp) | |
3922 | printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset); | |
3923 | break; | |
3924 | ||
3925 | case DW_CFA_nop: | |
3926 | if (! do_debug_frames_interp) | |
3927 | printf (" DW_CFA_nop\n"); | |
3928 | break; | |
3929 | ||
3930 | case DW_CFA_def_cfa_expression: | |
3931 | ul = LEB (); | |
3932 | if (! do_debug_frames_interp) | |
3933 | { | |
3934 | printf (" DW_CFA_def_cfa_expression ("); | |
3935 | decode_location_expression (start, eh_addr_size, ul, 0); | |
3936 | printf (")\n"); | |
3937 | } | |
3938 | fc->cfa_exp = 1; | |
3939 | start += ul; | |
3940 | break; | |
3941 | ||
3942 | case DW_CFA_expression: | |
3943 | reg = LEB (); | |
3944 | ul = LEB (); | |
3945 | if (! do_debug_frames_interp) | |
3946 | { | |
2dc4cec1 L |
3947 | printf (" DW_CFA_expression: %s (", |
3948 | regname (reg, 0)); | |
3949 | decode_location_expression (start, eh_addr_size, | |
3950 | ul, 0); | |
19e6b90e L |
3951 | printf (")\n"); |
3952 | } | |
3953 | fc->col_type[reg] = DW_CFA_expression; | |
3954 | start += ul; | |
3955 | break; | |
3956 | ||
12eae2d3 JJ |
3957 | case DW_CFA_val_expression: |
3958 | reg = LEB (); | |
3959 | ul = LEB (); | |
3960 | if (! do_debug_frames_interp) | |
3961 | { | |
2dc4cec1 L |
3962 | printf (" DW_CFA_val_expression: %s (", |
3963 | regname (reg, 0)); | |
12eae2d3 JJ |
3964 | decode_location_expression (start, eh_addr_size, ul, 0); |
3965 | printf (")\n"); | |
3966 | } | |
3967 | fc->col_type[reg] = DW_CFA_val_expression; | |
3968 | start += ul; | |
3969 | break; | |
3970 | ||
19e6b90e L |
3971 | case DW_CFA_offset_extended_sf: |
3972 | reg = LEB (); | |
3973 | l = SLEB (); | |
3974 | frame_need_space (fc, reg); | |
3975 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
3976 | printf (" DW_CFA_offset_extended_sf: %s at cfa%+ld\n", |
3977 | regname (reg, 0), l * fc->data_factor); | |
19e6b90e L |
3978 | fc->col_type[reg] = DW_CFA_offset; |
3979 | fc->col_offset[reg] = l * fc->data_factor; | |
3980 | break; | |
3981 | ||
12eae2d3 JJ |
3982 | case DW_CFA_val_offset_sf: |
3983 | reg = LEB (); | |
3984 | l = SLEB (); | |
3985 | frame_need_space (fc, reg); | |
3986 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
3987 | printf (" DW_CFA_val_offset_sf: %s at cfa%+ld\n", |
3988 | regname (reg, 0), l * fc->data_factor); | |
12eae2d3 JJ |
3989 | fc->col_type[reg] = DW_CFA_val_offset; |
3990 | fc->col_offset[reg] = l * fc->data_factor; | |
3991 | break; | |
3992 | ||
19e6b90e L |
3993 | case DW_CFA_def_cfa_sf: |
3994 | fc->cfa_reg = LEB (); | |
3995 | fc->cfa_offset = SLEB (); | |
3996 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; | |
3997 | fc->cfa_exp = 0; | |
3998 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
3999 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
4000 | regname (fc->cfa_reg, 0), fc->cfa_offset); | |
19e6b90e L |
4001 | break; |
4002 | ||
4003 | case DW_CFA_def_cfa_offset_sf: | |
4004 | fc->cfa_offset = SLEB (); | |
4005 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; | |
4006 | if (! do_debug_frames_interp) | |
4007 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset); | |
4008 | break; | |
4009 | ||
4010 | case DW_CFA_MIPS_advance_loc8: | |
4011 | ofs = byte_get (start, 8); start += 8; | |
4012 | if (do_debug_frames_interp) | |
4013 | frame_display_row (fc, &need_col_headers, &max_regs); | |
4014 | else | |
4015 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n", | |
4016 | ofs * fc->code_factor, | |
4017 | fc->pc_begin + ofs * fc->code_factor); | |
4018 | fc->pc_begin += ofs * fc->code_factor; | |
4019 | break; | |
4020 | ||
4021 | case DW_CFA_GNU_window_save: | |
4022 | if (! do_debug_frames_interp) | |
4023 | printf (" DW_CFA_GNU_window_save\n"); | |
4024 | break; | |
4025 | ||
4026 | case DW_CFA_GNU_args_size: | |
4027 | ul = LEB (); | |
4028 | if (! do_debug_frames_interp) | |
4029 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
4030 | break; | |
4031 | ||
4032 | case DW_CFA_GNU_negative_offset_extended: | |
4033 | reg = LEB (); | |
4034 | l = - LEB (); | |
4035 | frame_need_space (fc, reg); | |
4036 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
4037 | printf (" DW_CFA_GNU_negative_offset_extended: %s at cfa%+ld\n", |
4038 | regname (reg, 0), l * fc->data_factor); | |
19e6b90e L |
4039 | fc->col_type[reg] = DW_CFA_offset; |
4040 | fc->col_offset[reg] = l * fc->data_factor; | |
4041 | break; | |
4042 | ||
4043 | default: | |
53b8873b NC |
4044 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
4045 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
4046 | else | |
4047 | warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); | |
19e6b90e L |
4048 | start = block_end; |
4049 | } | |
4050 | } | |
4051 | ||
4052 | if (do_debug_frames_interp) | |
4053 | frame_display_row (fc, &need_col_headers, &max_regs); | |
4054 | ||
4055 | start = block_end; | |
4056 | } | |
4057 | ||
4058 | printf ("\n"); | |
4059 | ||
4060 | return 1; | |
4061 | } | |
4062 | ||
4063 | #undef GET | |
4064 | #undef LEB | |
4065 | #undef SLEB | |
4066 | ||
4067 | static int | |
4068 | display_debug_not_supported (struct dwarf_section *section, | |
4069 | void *file ATTRIBUTE_UNUSED) | |
4070 | { | |
4071 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
4072 | section->name); | |
4073 | ||
4074 | return 1; | |
4075 | } | |
4076 | ||
4077 | void * | |
4078 | cmalloc (size_t nmemb, size_t size) | |
4079 | { | |
4080 | /* Check for overflow. */ | |
4081 | if (nmemb >= ~(size_t) 0 / size) | |
4082 | return NULL; | |
4083 | else | |
4084 | return malloc (nmemb * size); | |
4085 | } | |
4086 | ||
4087 | void * | |
4088 | xcmalloc (size_t nmemb, size_t size) | |
4089 | { | |
4090 | /* Check for overflow. */ | |
4091 | if (nmemb >= ~(size_t) 0 / size) | |
4092 | return NULL; | |
4093 | else | |
4094 | return xmalloc (nmemb * size); | |
4095 | } | |
4096 | ||
4097 | void * | |
4098 | xcrealloc (void *ptr, size_t nmemb, size_t size) | |
4099 | { | |
4100 | /* Check for overflow. */ | |
4101 | if (nmemb >= ~(size_t) 0 / size) | |
4102 | return NULL; | |
4103 | else | |
4104 | return xrealloc (ptr, nmemb * size); | |
4105 | } | |
4106 | ||
4107 | void | |
4108 | error (const char *message, ...) | |
4109 | { | |
4110 | va_list args; | |
4111 | ||
4112 | va_start (args, message); | |
4113 | fprintf (stderr, _("%s: Error: "), program_name); | |
4114 | vfprintf (stderr, message, args); | |
4115 | va_end (args); | |
4116 | } | |
4117 | ||
4118 | void | |
4119 | warn (const char *message, ...) | |
4120 | { | |
4121 | va_list args; | |
4122 | ||
4123 | va_start (args, message); | |
4124 | fprintf (stderr, _("%s: Warning: "), program_name); | |
4125 | vfprintf (stderr, message, args); | |
4126 | va_end (args); | |
4127 | } | |
4128 | ||
4129 | void | |
4130 | free_debug_memory (void) | |
4131 | { | |
4132 | enum dwarf_section_display_enum i; | |
4133 | ||
4134 | free_abbrevs (); | |
4135 | ||
4136 | for (i = 0; i < max; i++) | |
4137 | free_debug_section (i); | |
4138 | ||
cc86f28f | 4139 | if (debug_information != NULL) |
19e6b90e | 4140 | { |
cc86f28f | 4141 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 4142 | { |
cc86f28f | 4143 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 4144 | { |
cc86f28f NC |
4145 | if (!debug_information [i].max_loc_offsets) |
4146 | { | |
4147 | free (debug_information [i].loc_offsets); | |
4148 | free (debug_information [i].have_frame_base); | |
4149 | } | |
4150 | if (!debug_information [i].max_range_lists) | |
4151 | free (debug_information [i].range_lists); | |
19e6b90e | 4152 | } |
19e6b90e | 4153 | } |
cc86f28f | 4154 | |
19e6b90e L |
4155 | free (debug_information); |
4156 | debug_information = NULL; | |
4157 | num_debug_info_entries = 0; | |
4158 | } | |
19e6b90e L |
4159 | } |
4160 | ||
4161 | struct dwarf_section_display debug_displays[] = | |
4162 | { | |
4163 | { { ".debug_abbrev", NULL, 0, 0 }, | |
4164 | display_debug_abbrev, 0, 0 }, | |
4165 | { { ".debug_aranges", NULL, 0, 0 }, | |
4166 | display_debug_aranges, 0, 0 }, | |
4167 | { { ".debug_frame", NULL, 0, 0 }, | |
4168 | display_debug_frames, 1, 0 }, | |
4169 | { { ".debug_info", NULL, 0, 0 }, | |
4170 | display_debug_info, 1, 0 }, | |
4171 | { { ".debug_line", NULL, 0, 0 }, | |
4172 | display_debug_lines, 0, 0 }, | |
4173 | { { ".debug_pubnames", NULL, 0, 0 }, | |
4174 | display_debug_pubnames, 0, 0 }, | |
4175 | { { ".eh_frame", NULL, 0, 0 }, | |
4176 | display_debug_frames, 1, 1 }, | |
4177 | { { ".debug_macinfo", NULL, 0, 0 }, | |
4178 | display_debug_macinfo, 0, 0 }, | |
4179 | { { ".debug_str", NULL, 0, 0 }, | |
4180 | display_debug_str, 0, 0 }, | |
4181 | { { ".debug_loc", NULL, 0, 0 }, | |
4182 | display_debug_loc, 0, 0 }, | |
4183 | { { ".debug_pubtypes", NULL, 0, 0 }, | |
4184 | display_debug_pubnames, 0, 0 }, | |
4185 | { { ".debug_ranges", NULL, 0, 0 }, | |
4186 | display_debug_ranges, 0, 0 }, | |
4187 | { { ".debug_static_func", NULL, 0, 0 }, | |
4188 | display_debug_not_supported, 0, 0 }, | |
4189 | { { ".debug_static_vars", NULL, 0, 0 }, | |
4190 | display_debug_not_supported, 0, 0 }, | |
4191 | { { ".debug_types", NULL, 0, 0 }, | |
4192 | display_debug_not_supported, 0, 0 }, | |
4193 | { { ".debug_weaknames", NULL, 0, 0 }, | |
4194 | display_debug_not_supported, 0, 0 } | |
4195 | }; |