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