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