OSDN Git Service

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