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