OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [binutils/] [dwarf.c] - Blame information for rev 53

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.