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 299

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

powered by: WebSVN 2.1.0

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