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