dwarf.c 188 KB
Newer Older
1
/* dwarf.c -- display DWARF contents of a BFD binary file
Nick Clifton's avatar
Nick Clifton committed
2
   Copyright 2005-2013 Free Software Foundation, Inc.
3 4 5 6 7

   This file is part of GNU Binutils.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 3 of the License, or
9 10 11 12 13 14 15 16 17 18 19 20
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
   02110-1301, USA.  */

Alan Modra's avatar
 
Alan Modra committed
21
#include "sysdep.h"
22
#include "libiberty.h"
Alan Modra's avatar
 
Alan Modra committed
23
#include "bfd.h"
24
#include "bfd_stdint.h"
Alan Modra's avatar
 
Alan Modra committed
25
#include "bucomm.h"
H.J. Lu's avatar
H.J. Lu committed
26
#include "elfcomm.h"
H.J. Lu's avatar
H.J. Lu committed
27
#include "elf/common.h"
Tom Tromey's avatar
bfd  
Tom Tromey committed
28
#include "dwarf2.h"
Alan Modra's avatar
 
Alan Modra committed
29
#include "dwarf.h"
30
#include "gdb/gdb-index.h"
31

Alan Modra's avatar
Alan Modra committed
32 33 34 35
#if !HAVE_DECL_STRNLEN
size_t strnlen (const char *, size_t);
#endif

Jan Kratochvil's avatar
Jan Kratochvil committed
36 37
static const char *regname (unsigned int regno, int row);

38 39 40 41 42 43 44 45
static int have_frame_base;
static int need_base_address;

static unsigned int last_pointer_size = 0;
static int warned_about_missing_comp_units = FALSE;

static unsigned int num_debug_info_entries = 0;
static debug_info *debug_information = NULL;
46 47 48
/* Special value for num_debug_info_entries to indicate
   that the .debug_info section could not be loaded/parsed.  */
#define DEBUG_INFO_UNAVAILABLE  (unsigned int) -1
49

H.J. Lu's avatar
H.J. Lu committed
50
int eh_addr_size;
51 52 53 54 55

int do_debug_info;
int do_debug_abbrevs;
int do_debug_lines;
int do_debug_pubnames;
Nick Clifton's avatar
Nick Clifton committed
56
int do_debug_pubtypes;
57 58 59 60 61 62 63
int do_debug_aranges;
int do_debug_ranges;
int do_debug_frames;
int do_debug_frames_interp;
int do_debug_macinfo;
int do_debug_str;
int do_debug_loc;
64
int do_gdb_index;
65 66 67
int do_trace_info;
int do_trace_abbrevs;
int do_trace_aranges;
Cary Coutant's avatar
Cary Coutant committed
68 69
int do_debug_addr;
int do_debug_cu_index;
70
int do_wide;
71

72 73 74
int dwarf_cutoff_level = -1;
unsigned long dwarf_start_die;

75 76
int dwarf_check = 0;

Cary Coutant's avatar
Cary Coutant committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
/* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
   sections.  For version 1 package files, each set is stored in SHNDX_POOL
   as a zero-terminated list of section indexes comprising one set of debug
   sections from a .dwo file.  */

static int cu_tu_indexes_read = 0;
static unsigned int *shndx_pool = NULL;
static unsigned int shndx_pool_size = 0;
static unsigned int shndx_pool_used = 0;

/* For version 2 package files, each set contains an array of section offsets
   and an array of section sizes, giving the offset and size of the
   contribution from a CU or TU within one of the debug sections.
   When displaying debug info from a package file, we need to use these
   tables to locate the corresponding contributions to each section.  */

struct cu_tu_set
{
  uint64_t signature;
  dwarf_vma section_offsets[DW_SECT_MAX];
  size_t section_sizes[DW_SECT_MAX];
};

static int cu_count = 0;
static int tu_count = 0;
static struct cu_tu_set *cu_sets = NULL;
static struct cu_tu_set *tu_sets = NULL;

static void load_cu_tu_indexes (void *file);

107 108 109 110
/* Values for do_debug_lines.  */
#define FLAG_DEBUG_LINES_RAW	 1
#define FLAG_DEBUG_LINES_DECODED 2

Richard Henderson's avatar
Richard Henderson committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124
static int
size_of_encoded_value (int encoding)
{
  switch (encoding & 0x7)
    {
    default:	/* ??? */
    case 0:	return eh_addr_size;
    case 2:	return 2;
    case 3:	return 4;
    case 4:	return 8;
    }
}

static dwarf_vma
125 126 127
get_encoded_value (unsigned char *data,
		   int encoding,
		   struct dwarf_section *section)
Richard Henderson's avatar
Richard Henderson committed
128 129
{
  int size = size_of_encoded_value (encoding);
130
  dwarf_vma val;
Richard Henderson's avatar
Richard Henderson committed
131 132

  if (encoding & DW_EH_PE_signed)
133
    val = byte_get_signed (data, size);
Richard Henderson's avatar
Richard Henderson committed
134
  else
135 136 137 138 139
    val = byte_get (data, size);

  if ((encoding & 0x70) == DW_EH_PE_pcrel)
    val += section->address + (data - section->start);
  return val;
Richard Henderson's avatar
Richard Henderson committed
140 141
}

142
#if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
143
#ifndef __MINGW32__
144 145
#define  DWARF_VMA_FMT       "ll"
#define  DWARF_VMA_FMT_LONG  "%16.16llx"
146
#else
147 148
#define  DWARF_VMA_FMT       "I64"
#define  DWARF_VMA_FMT_LONG  "%016I64x"
149
#endif
150
#else
151 152
#define  DWARF_VMA_FMT       "l"
#define  DWARF_VMA_FMT_LONG  "%16.16lx"
153 154
#endif

155 156 157 158 159
/* Convert a dwarf vma value into a string.  Returns a pointer to a static
   buffer containing the converted VALUE.  The value is converted according
   to the printf formating character FMTCH.  If NUM_BYTES is non-zero then
   it specifies the maximum number of bytes to be displayed in the converted
   value and FMTCH is ignored - hex is always used.  */
160

Kai Tietz's avatar
Kai Tietz committed
161
static const char *
162
dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
Kai Tietz's avatar
Kai Tietz committed
163 164 165 166 167
{
  /* As dwarf_vmatoa is used more then once in a printf call
     for output, we are cycling through an fixed array of pointers
     for return address.  */
  static int buf_pos = 0;
168 169
  static struct dwarf_vmatoa_buf
  {
Kai Tietz's avatar
Kai Tietz committed
170 171 172 173 174
    char place[64];
  } buf[16];
  char *ret;

  ret = buf[buf_pos++].place;
175
  buf_pos %= ARRAY_SIZE (buf);
Kai Tietz's avatar
Kai Tietz committed
176

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
  if (num_bytes)
    {
      /* Printf does not have a way of specifiying a maximum field width for an
	 integer value, so we print the full value into a buffer and then select
	 the precision we need.  */
      snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
      if (num_bytes > 8)
	num_bytes = 8;
      return ret + (16 - 2 * num_bytes);
    }
  else
    {
      char fmt[32];

      sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
      snprintf (ret, sizeof (buf[0].place), fmt, value);
      return ret;
    }
}
Kai Tietz's avatar
Kai Tietz committed
196

197 198 199 200 201 202 203 204 205 206 207 208 209 210
static inline const char *
dwarf_vmatoa (const char * fmtch, dwarf_vma value)
{
  return dwarf_vmatoa_1 (fmtch, value, 0);
}

/* Print a dwarf_vma value (typically an address, offset or length) in
   hexadecimal format, followed by a space.  The length of the VALUE (and
   hence the precision displayed) is determined by the NUM_BYTES parameter.  */

static void
print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
{
  printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
Kai Tietz's avatar
Kai Tietz committed
211 212
}

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
/* Format a 64-bit value, given as two 32-bit values, in hex.
   For reentrancy, this uses a buffer provided by the caller.  */

static const char *
dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
		unsigned int buf_len)
{
  int len = 0;

  if (hvalue == 0)
    snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
  else
    {
      len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
      snprintf (buf + len, buf_len - len,
		"%08" DWARF_VMA_FMT "x", lvalue);
    }

  return buf;
}

Nick Clifton's avatar
Nick Clifton committed
234 235 236 237 238
/* Read in a LEB128 encoded value starting at address DATA.
   If SIGN is true, return a signed LEB128 value.
   If LENGTH_RETURN is not NULL, return in it the number of bytes read.
   No bytes will be read at address END or beyond.  */

239
dwarf_vma
Nick Clifton's avatar
Nick Clifton committed
240 241 242 243
read_leb128 (unsigned char *data,
	     unsigned int *length_return,
	     bfd_boolean sign,
	     const unsigned char * const end)
244
{
245
  dwarf_vma result = 0;
246 247
  unsigned int num_read = 0;
  unsigned int shift = 0;
Nick Clifton's avatar
Nick Clifton committed
248
  unsigned char byte = 0;
249

Nick Clifton's avatar
Nick Clifton committed
250
  while (data < end)
251 252 253 254
    {
      byte = *data++;
      num_read++;

255
      result |= ((dwarf_vma) (byte & 0x7f)) << shift;
256 257

      shift += 7;
Nick Clifton's avatar
Nick Clifton committed
258 259
      if ((byte & 0x80) == 0)
	break;
260 261 262 263 264 265
    }

  if (length_return != NULL)
    *length_return = num_read;

  if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
266
    result |= -1UL << shift;
267 268 269 270

  return result;
}

271
/* Create a signed version to avoid painful typecasts.  */
Nick Clifton's avatar
Nick Clifton committed
272 273 274 275 276 277 278 279 280 281 282 283
static inline dwarf_signed_vma
read_sleb128 (unsigned char * data,
	      unsigned int *  length_return,
	      const unsigned char * const end)
{
  return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
}

static inline dwarf_vma
read_uleb128 (unsigned char * data,
	      unsigned int *  length_return,
	      const unsigned char * const end)
284
{
Nick Clifton's avatar
Nick Clifton committed
285
  return read_leb128 (data, length_return, FALSE, end);
286 287
}

Nick Clifton's avatar
Nick Clifton committed
288 289 290
#define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END)	\
  do						\
    {						\
291
      int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \
Nick Clifton's avatar
Nick Clifton committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
      unsigned int amount = (AMOUNT);		\
      if (((PTR) + amount) >= (END))		\
	{					\
	  if ((PTR) < (END))			\
	    amount = (END) - (PTR);		\
	  else					\
	    amount = 0;				\
	}					\
      if (amount)				\
	VAL = byte_get ((PTR), amount);		\
      else					\
	VAL = 0;				\
    }						\
  while (0)

#define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END)	\
  do							\
    {							\
      SAFE_BYTE_GET (VAL, PTR, AMOUNT, END);		\
      PTR += AMOUNT;					\
    }							\
  while (0)

#define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END)	\
  do							\
    {							\
      unsigned int amount = (AMOUNT);			\
      if (((PTR) + amount) >= (END))			\
	{						\
	  if ((PTR) < (END))				\
	    amount = (END) - (PTR);			\
	  else						\
	    amount = 0;					\
	}						\
      if (amount)					\
	VAL = byte_get_signed ((PTR), amount);		\
      else						\
	VAL = 0;					\
    }							\
  while (0)

#define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END)	\
  do								\
    {								\
      SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END);		\
      PTR += AMOUNT;						\
    }								\
  while (0)

#define SAFE_BYTE_GET64(PTR, HIGH, LOW, END)		\
  do							\
    {							\
Cary Coutant's avatar
Cary Coutant committed
344
      if (((PTR) + 8) <= (END))				\
Nick Clifton's avatar
Nick Clifton committed
345 346 347 348 349 350 351 352 353 354
	{						\
	  byte_get_64 ((PTR), (HIGH), (LOW));		\
	}						\
      else						\
	{						\
	  * (LOW) = * (HIGH) = 0;			\
	}						\
    }							\
  while (0)

355 356
typedef struct State_Machine_Registers
{
357
  dwarf_vma address;
358 359 360 361 362
  unsigned int file;
  unsigned int line;
  unsigned int column;
  int is_stmt;
  int basic_block;
Jakub Jelinek's avatar
Jakub Jelinek committed
363 364
  unsigned char op_index;
  unsigned char end_sequence;
365 366 367 368 369 370 371 372 373 374 375
/* This variable hold the number of the last entry seen
   in the File Table.  */
  unsigned int last_file_entry;
} SMR;

static SMR state_machine_regs;

static void
reset_state_machine (int is_stmt)
{
  state_machine_regs.address = 0;
Jakub Jelinek's avatar
Jakub Jelinek committed
376
  state_machine_regs.op_index = 0;
377 378 379 380 381 382 383 384 385 386 387 388 389
  state_machine_regs.file = 1;
  state_machine_regs.line = 1;
  state_machine_regs.column = 0;
  state_machine_regs.is_stmt = is_stmt;
  state_machine_regs.basic_block = 0;
  state_machine_regs.end_sequence = 0;
  state_machine_regs.last_file_entry = 0;
}

/* Handled an extend line op.
   Returns the number of bytes read.  */

static int
Nick Clifton's avatar
Nick Clifton committed
390 391 392
process_extended_line_op (unsigned char * data,
			  int is_stmt,
			  unsigned char * end)
393 394 395 396 397
{
  unsigned char op_code;
  unsigned int bytes_read;
  unsigned int len;
  unsigned char *name;
398
  unsigned char *orig_data = data;
Nick Clifton's avatar
Nick Clifton committed
399
  dwarf_vma adr;
400

Nick Clifton's avatar
Nick Clifton committed
401
  len = read_uleb128 (data, & bytes_read, end);
402 403
  data += bytes_read;

Nick Clifton's avatar
Nick Clifton committed
404
  if (len == 0 || data == end)
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
    {
      warn (_("badly formed extended line op encountered!\n"));
      return bytes_read;
    }

  len += bytes_read;
  op_code = *data++;

  printf (_("  Extended opcode %d: "), op_code);

  switch (op_code)
    {
    case DW_LNE_end_sequence:
      printf (_("End of Sequence\n\n"));
      reset_state_machine (is_stmt);
      break;

    case DW_LNE_set_address:
Nick Clifton's avatar
Nick Clifton committed
423
      SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
Kai Tietz's avatar
Kai Tietz committed
424
      printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
425
      state_machine_regs.address = adr;
Jakub Jelinek's avatar
Jakub Jelinek committed
426
      state_machine_regs.op_index = 0;
427 428 429
      break;

    case DW_LNE_define_file:
430
      printf (_("define new File Table entry\n"));
431
      printf (_("  Entry\tDir\tTime\tSize\tName\n"));
432
      printf ("   %d\t", ++state_machine_regs.last_file_entry);
Nick Clifton's avatar
Nick Clifton committed
433

434
      name = data;
Nick Clifton's avatar
Nick Clifton committed
435
      data += strnlen ((char *) data, end - data) + 1;
Nick Clifton's avatar
Nick Clifton committed
436
      printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
437
      data += bytes_read;
Nick Clifton's avatar
Nick Clifton committed
438
      printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
439
      data += bytes_read;
Nick Clifton's avatar
Nick Clifton committed
440
      printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
441
      data += bytes_read;
Nick Clifton's avatar
Nick Clifton committed
442 443 444 445
      printf ("%s\n\n", name);

      if (((unsigned int) (data - orig_data) != len) || data == end)
        warn (_("DW_LNE_define_file: Bad opcode length\n"));
446 447
      break;

Cary Coutant's avatar
Cary Coutant committed
448
    case DW_LNE_set_discriminator:
Kai Tietz's avatar
Kai Tietz committed
449
      printf (_("set Discriminator to %s\n"),
Nick Clifton's avatar
Nick Clifton committed
450
	      dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
Cary Coutant's avatar
Cary Coutant committed
451 452
      break;

453 454
    /* HP extensions.  */
    case DW_LNE_HP_negate_is_UV_update:
Cary Coutant's avatar
Cary Coutant committed
455
      printf ("DW_LNE_HP_negate_is_UV_update\n");
456 457
      break;
    case DW_LNE_HP_push_context:
Cary Coutant's avatar
Cary Coutant committed
458
      printf ("DW_LNE_HP_push_context\n");
459 460
      break;
    case DW_LNE_HP_pop_context:
Cary Coutant's avatar
Cary Coutant committed
461
      printf ("DW_LNE_HP_pop_context\n");
462 463
      break;
    case DW_LNE_HP_set_file_line_column:
Cary Coutant's avatar
Cary Coutant committed
464
      printf ("DW_LNE_HP_set_file_line_column\n");
465 466
      break;
    case DW_LNE_HP_set_routine_name:
Cary Coutant's avatar
Cary Coutant committed
467
      printf ("DW_LNE_HP_set_routine_name\n");
468 469
      break;
    case DW_LNE_HP_set_sequence:
Cary Coutant's avatar
Cary Coutant committed
470
      printf ("DW_LNE_HP_set_sequence\n");
471 472
      break;
    case DW_LNE_HP_negate_post_semantics:
Cary Coutant's avatar
Cary Coutant committed
473
      printf ("DW_LNE_HP_negate_post_semantics\n");
474 475
      break;
    case DW_LNE_HP_negate_function_exit:
Cary Coutant's avatar
Cary Coutant committed
476
      printf ("DW_LNE_HP_negate_function_exit\n");
477 478
      break;
    case DW_LNE_HP_negate_front_end_logical:
Cary Coutant's avatar
Cary Coutant committed
479
      printf ("DW_LNE_HP_negate_front_end_logical\n");
480 481
      break;
    case DW_LNE_HP_define_proc:
Cary Coutant's avatar
Cary Coutant committed
482
      printf ("DW_LNE_HP_define_proc\n");
483
      break;
484 485 486 487 488 489 490 491 492 493
    case DW_LNE_HP_source_file_correlation:
      {
        unsigned char *edata = data + len - bytes_read - 1;

        printf ("DW_LNE_HP_source_file_correlation\n");

        while (data < edata)
          {
            unsigned int opc;

Nick Clifton's avatar
Nick Clifton committed
494
            opc = read_uleb128 (data, & bytes_read, edata);
495 496 497 498 499 500 501 502 503 504
            data += bytes_read;

            switch (opc)
              {
              case DW_LNE_HP_SFC_formfeed:
                printf ("    DW_LNE_HP_SFC_formfeed\n");
                break;
              case DW_LNE_HP_SFC_set_listing_line:
                printf ("    DW_LNE_HP_SFC_set_listing_line (%s)\n",
                        dwarf_vmatoa ("u",
Nick Clifton's avatar
Nick Clifton committed
505
                                      read_uleb128 (data, & bytes_read, edata)));
506 507 508 509
                data += bytes_read;
                break;
              case DW_LNE_HP_SFC_associate:
                printf ("    DW_LNE_HP_SFC_associate ");
510
                printf ("(%s",
511
                        dwarf_vmatoa ("u",
Nick Clifton's avatar
Nick Clifton committed
512
                                      read_uleb128 (data, & bytes_read, edata)));
513
                data += bytes_read;
514
                printf (",%s",
515
                        dwarf_vmatoa ("u",
Nick Clifton's avatar
Nick Clifton committed
516
                                      read_uleb128 (data, & bytes_read, edata)));
517
                data += bytes_read;
518
                printf (",%s)\n",
519
                        dwarf_vmatoa ("u",
Nick Clifton's avatar
Nick Clifton committed
520
                                      read_uleb128 (data, & bytes_read, edata)));
521 522 523
                data += bytes_read;
                break;
              default:
524
                printf (_("    UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
525 526 527 528 529 530
                data = edata;
                break;
              }
          }
      }
      break;
531

532
    default:
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
      {
        unsigned int rlen = len - bytes_read - 1;

        if (op_code >= DW_LNE_lo_user
            /* The test against DW_LNW_hi_user is redundant due to
               the limited range of the unsigned char data type used
               for op_code.  */
            /*&& op_code <= DW_LNE_hi_user*/)
          printf (_("user defined: "));
        else
          printf (_("UNKNOWN: "));
        printf (_("length %d ["), rlen);
        for (; rlen; rlen--)
          printf (" %02x", *data++);
        printf ("]\n");
      }
549 550 551 552 553 554
      break;
    }

  return len;
}

Nick Clifton's avatar
Nick Clifton committed
555
static const unsigned char *
556
fetch_indirect_string (dwarf_vma offset)
557 558 559 560
{
  struct dwarf_section *section = &debug_displays [str].section;

  if (section->start == NULL)
Nick Clifton's avatar
Nick Clifton committed
561
    return (const unsigned char *) _("<no .debug_str section>");
562

563 564
  /* DWARF sections under Mach-O have non-zero addresses.  */
  offset -= section->address;
565 566
  if (offset > section->size)
    {
567 568
      warn (_("DW_FORM_strp offset too big: %s\n"),
	    dwarf_vmatoa ("x", offset));
Nick Clifton's avatar
Nick Clifton committed
569
      return (const unsigned char *) _("<offset is too big>");
570 571
    }

Nick Clifton's avatar
Nick Clifton committed
572
  return (const unsigned char *) section->start + offset;
573 574
}

575
static const char *
Cary Coutant's avatar
Cary Coutant committed
576 577
fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
		      dwarf_vma offset_size, int dwo)
578 579 580 581 582 583 584 585 586 587 588 589 590 591
{
  enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
  enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
  struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
  struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
  dwarf_vma index_offset = idx * offset_size;
  dwarf_vma str_offset;

  if (index_section->start == NULL)
    return (dwo ? _("<no .debug_str_offsets.dwo section>")
		: _("<no .debug_str_offsets section>"));

  /* DWARF sections under Mach-O have non-zero addresses.  */
  index_offset -= index_section->address;
Cary Coutant's avatar
Cary Coutant committed
592 593
  if (this_set != NULL)
    index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
  if (index_offset > index_section->size)
    {
      warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
	    dwarf_vmatoa ("x", index_offset));
      return _("<index offset is too big>");
    }

  if (str_section->start == NULL)
    return (dwo ? _("<no .debug_str.dwo section>")
		: _("<no .debug_str section>"));

  str_offset = byte_get (index_section->start + index_offset, offset_size);
  str_offset -= str_section->address;
  if (str_offset > str_section->size)
    {
      warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
	    dwarf_vmatoa ("x", str_offset));
      return _("<indirect index offset is too big>");
    }

  return (const char *) str_section->start + str_offset;
}

static const char *
fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
{
  struct dwarf_section *section = &debug_displays [debug_addr].section;

  if (section->start == NULL)
    return (_("<no .debug_addr section>"));

  if (offset + bytes > section->size)
    {
      warn (_("Offset into section %s too big: %s\n"),
            section->name, dwarf_vmatoa ("x", offset));
      return "<offset too big>";
    }

  return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
}


636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
/* FIXME:  There are better and more efficient ways to handle
   these structures.  For now though, I just want something that
   is simple to implement.  */
typedef struct abbrev_attr
{
  unsigned long attribute;
  unsigned long form;
  struct abbrev_attr *next;
}
abbrev_attr;

typedef struct abbrev_entry
{
  unsigned long entry;
  unsigned long tag;
  int children;
  struct abbrev_attr *first_attr;
  struct abbrev_attr *last_attr;
  struct abbrev_entry *next;
}
abbrev_entry;

static abbrev_entry *first_abbrev = NULL;
static abbrev_entry *last_abbrev = NULL;

static void
free_abbrevs (void)
{
664
  abbrev_entry *abbrv;
665

666
  for (abbrv = first_abbrev; abbrv;)
667
    {
668
      abbrev_entry *next_abbrev = abbrv->next;
669 670
      abbrev_attr *attr;

671
      for (attr = abbrv->first_attr; attr;)
672
	{
673
	  abbrev_attr *next_attr = attr->next;
674 675

	  free (attr);
676
	  attr = next_attr;
677 678
	}

679 680
      free (abbrv);
      abbrv = next_abbrev;
681 682 683 684 685 686 687 688 689 690
    }

  last_abbrev = first_abbrev = NULL;
}

static void
add_abbrev (unsigned long number, unsigned long tag, int children)
{
  abbrev_entry *entry;

691
  entry = (abbrev_entry *) malloc (sizeof (*entry));
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
  if (entry == NULL)
    /* ugg */
    return;

  entry->entry      = number;
  entry->tag        = tag;
  entry->children   = children;
  entry->first_attr = NULL;
  entry->last_attr  = NULL;
  entry->next       = NULL;

  if (first_abbrev == NULL)
    first_abbrev = entry;
  else
    last_abbrev->next = entry;

  last_abbrev = entry;
}

static void
add_abbrev_attr (unsigned long attribute, unsigned long form)
{
  abbrev_attr *attr;

716
  attr = (abbrev_attr *) malloc (sizeof (*attr));
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
  if (attr == NULL)
    /* ugg */
    return;

  attr->attribute = attribute;
  attr->form      = form;
  attr->next      = NULL;

  if (last_abbrev->first_attr == NULL)
    last_abbrev->first_attr = attr;
  else
    last_abbrev->last_attr->next = attr;

  last_abbrev->last_attr = attr;
}

/* Processes the (partial) contents of a .debug_abbrev section.
   Returns NULL if the end of the section was encountered.
   Returns the address after the last byte read if the end of
   an abbreviation set was found.  */

static unsigned char *
process_abbrev_section (unsigned char *start, unsigned char *end)
{
  if (first_abbrev != NULL)
    return NULL;

  while (start < end)
    {
      unsigned int bytes_read;
      unsigned long entry;
      unsigned long tag;
      unsigned long attribute;
      int children;

Nick Clifton's avatar
Nick Clifton committed
752
      entry = read_uleb128 (start, & bytes_read, end);
753 754 755 756 757
      start += bytes_read;

      /* A single zero is supposed to end the section according
	 to the standard.  If there's more, then signal that to
	 the caller.  */
Nick Clifton's avatar
Nick Clifton committed
758 759
      if (start == end)
	return NULL;
760
      if (entry == 0)
Nick Clifton's avatar
Nick Clifton committed
761
	return start;
762

Nick Clifton's avatar
Nick Clifton committed
763
      tag = read_uleb128 (start, & bytes_read, end);
764
      start += bytes_read;
Nick Clifton's avatar
Nick Clifton committed
765 766
      if (start == end)
	return NULL;
767 768 769 770 771 772 773 774 775

      children = *start++;

      add_abbrev (entry, tag, children);

      do
	{
	  unsigned long form;

Nick Clifton's avatar
Nick Clifton committed
776
	  attribute = read_uleb128 (start, & bytes_read, end);
777
	  start += bytes_read;
Nick Clifton's avatar
Nick Clifton committed
778 779
	  if (start == end)
	    break;
780

Nick Clifton's avatar
Nick Clifton committed
781
	  form = read_uleb128 (start, & bytes_read, end);
782
	  start += bytes_read;
Nick Clifton's avatar
Nick Clifton committed
783 784
	  if (start == end)
	    break;
785

786
	  add_abbrev_attr (attribute, form);
787 788 789 790
	}
      while (attribute != 0);
    }

791 792 793
  /* Report the missing single zero which ends the section.  */
  error (_(".debug_abbrev section not zero terminated\n"));

794 795 796
  return NULL;
}

797
static const char *
798 799
get_TAG_name (unsigned long tag)
{
James Lemke's avatar
 
James Lemke committed
800
  const char *name = get_DW_TAG_name ((unsigned int)tag);
801 802

  if (name == NULL)
803
    {
804
      static char buffer[100];
805

806 807
      snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
      return buffer;
808
    }
809 810

  return name;
811 812
}

813
static const char *
814 815
get_FORM_name (unsigned long form)
{
816
  const char *name;
817

818 819
  if (form == 0)
    return "DW_FORM value: 0";
820

821
  name = get_DW_FORM_name (form);
822
  if (name == NULL)
823
    {
824
      static char buffer[100];
825

826 827
      snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
      return buffer;
828
    }
829 830

  return name;
831 832 833
}

static unsigned char *
Nick Clifton's avatar
Nick Clifton committed
834 835 836
display_block (unsigned char *data,
	       dwarf_vma length,
	       const unsigned char * const end)
837
{
Nick Clifton's avatar
Nick Clifton committed
838 839
  dwarf_vma maxlen;

840
  printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
841

Nick Clifton's avatar
Nick Clifton committed
842 843 844
  maxlen = (dwarf_vma) (end - data);
  length = length > maxlen ? maxlen : length;

845 846 847 848 849 850 851 852 853
  while (length --)
    printf ("%lx ", (unsigned long) byte_get (data++, 1));

  return data;
}

static int
decode_location_expression (unsigned char * data,
			    unsigned int pointer_size,
854 855
			    unsigned int offset_size,
			    int dwarf_version,
856 857
			    dwarf_vma length,
			    dwarf_vma cu_offset,
Richard Henderson's avatar
Richard Henderson committed
858
			    struct dwarf_section * section)
859 860 861
{
  unsigned op;
  unsigned int bytes_read;
862
  dwarf_vma uvalue;
Nick Clifton's avatar
Nick Clifton committed
863
  dwarf_signed_vma svalue;
864 865 866 867 868 869 870 871 872 873
  unsigned char *end = data + length;
  int need_frame_base = 0;

  while (data < end)
    {
      op = *data++;

      switch (op)
	{
	case DW_OP_addr:
Nick Clifton's avatar
Nick Clifton committed
874 875
	  SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
	  printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
876 877 878 879 880
	  break;
	case DW_OP_deref:
	  printf ("DW_OP_deref");
	  break;
	case DW_OP_const1u:
Nick Clifton's avatar
Nick Clifton committed
881 882
	  SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
	  printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
883 884
	  break;
	case DW_OP_const1s:
Nick Clifton's avatar
Nick Clifton committed
885 886
	  SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
	  printf ("DW_OP_const1s: %ld", (long) svalue);
887 888
	  break;
	case DW_OP_const2u:
Cary Coutant's avatar
Cary Coutant committed
889
	  SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
Nick Clifton's avatar
Nick Clifton committed
890
	  printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
891 892
	  break;
	case DW_OP_const2s:
Nick Clifton's avatar
Nick Clifton committed
893 894
	  SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
	  printf ("DW_OP_const2s: %ld", (long) svalue);
895 896
	  break;
	case DW_OP_const4u:
Nick Clifton's avatar
Nick Clifton committed
897 898
	  SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
	  printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
899 900
	  break;
	case DW_OP_const4s:
Nick Clifton's avatar
Nick Clifton committed
901 902
	  SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
	  printf ("DW_OP_const4s: %ld", (long) svalue);
903 904
	  break;
	case DW_OP_const8u:
Nick Clifton's avatar
Nick Clifton committed
905 906 907 908
	  SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
	  printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
	  SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
	  printf ("%lu", (unsigned long) uvalue);
909 910
	  break;
	case DW_OP_const8s:
Nick Clifton's avatar
Nick Clifton committed
911 912 913 914
	  SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
	  printf ("DW_OP_const8s: %ld ", (long) svalue);
	  SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
	  printf ("%ld", (long) svalue);
915 916
	  break;
	case DW_OP_constu:
917
	  printf ("DW_OP_constu: %s",
Nick Clifton's avatar
Nick Clifton committed
918
		  dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
919 920 921
	  data += bytes_read;
	  break;
	case DW_OP_consts:
922
	  printf ("DW_OP_consts: %s",
Nick Clifton's avatar
Nick Clifton committed
923
		  dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
924 925 926 927 928 929 930 931 932 933 934 935
	  data += bytes_read;
	  break;
	case DW_OP_dup:
	  printf ("DW_OP_dup");
	  break;
	case DW_OP_drop:
	  printf ("DW_OP_drop");
	  break;
	case DW_OP_over:
	  printf ("DW_OP_over");
	  break;
	case DW_OP_pick:
Nick Clifton's avatar
Nick Clifton committed
936 937
	  SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
	  printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
	  break;
	case DW_OP_swap:
	  printf ("DW_OP_swap");
	  break;
	case DW_OP_rot:
	  printf ("DW_OP_rot");
	  break;
	case DW_OP_xderef:
	  printf ("DW_OP_xderef");
	  break;
	case DW_OP_abs:
	  printf ("DW_OP_abs");
	  break;
	case DW_OP_and:
	  printf ("DW_OP_and");
	  break;
	case DW_OP_div:
	  printf ("DW_OP_div");
	  break;
	case DW_OP_minus:
	  printf ("DW_OP_minus");
	  break;
	case DW_OP_mod:
	  printf ("DW_OP_mod");
	  break;
	case DW_OP_mul:
	  printf ("DW_OP_mul");
	  break;
	case DW_OP_neg:
	  printf ("DW_OP_neg");
	  break;
	case DW_OP_not:
	  printf ("DW_OP_not");
	  break;
	case DW_OP_or:
	  printf ("DW_OP_or");
	  break;
	case DW_OP_plus:
	  printf ("DW_OP_plus");
	  break;
	case DW_OP_plus_uconst:
979
	  printf ("DW_OP_plus_uconst: %s",
Nick Clifton's avatar
Nick Clifton committed
980
		  dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
	  data += bytes_read;
	  break;
	case DW_OP_shl:
	  printf ("DW_OP_shl");
	  break;
	case DW_OP_shr:
	  printf ("DW_OP_shr");
	  break;
	case DW_OP_shra:
	  printf ("DW_OP_shra");
	  break;
	case DW_OP_xor:
	  printf ("DW_OP_xor");
	  break;
	case DW_OP_bra:
Nick Clifton's avatar
Nick Clifton committed
996 997
	  SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
	  printf ("DW_OP_bra: %ld", (long) svalue);
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
	  break;
	case DW_OP_eq:
	  printf ("DW_OP_eq");
	  break;
	case DW_OP_ge:
	  printf ("DW_OP_ge");
	  break;
	case DW_OP_gt:
	  printf ("DW_OP_gt");
	  break;
	case DW_OP_le:
	  printf ("DW_OP_le");
	  break;
	case DW_OP_lt:
	  printf ("DW_OP_lt");
	  break;
	case DW_OP_ne:
	  printf ("DW_OP_ne");
	  break;
	case DW_OP_skip:
Nick Clifton's avatar
Nick Clifton committed
1018 1019
	  SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
	  printf ("DW_OP_skip: %ld", (long) svalue);
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
	  break;

	case DW_OP_lit0:
	case DW_OP_lit1:
	case DW_OP_lit2:
	case DW_OP_lit3:
	case DW_OP_lit4:
	case DW_OP_lit5:
	case DW_OP_lit6:
	case DW_OP_lit7:
	case DW_OP_lit8:
	case DW_OP_lit9:
	case DW_OP_lit10:
	case DW_OP_lit11:
	case DW_OP_lit12:
	case DW_OP_lit13:
	case DW_OP_lit14:
	case DW_OP_lit15:
	case DW_OP_lit16:
	case DW_OP_lit17:
	case DW_OP_lit18:
	case DW_OP_lit19:
	case DW_OP_lit20:
	case DW_OP_lit21:
	case DW_OP_lit22:
	case DW_OP_lit23:
	case DW_OP_lit24:
	case DW_OP_lit25:
	case DW_OP_lit26:
	case DW_OP_lit27:
	case DW_OP_lit28:
	case DW_OP_lit29:
	case DW_OP_lit30:
	case DW_OP_lit31:
	  printf ("DW_OP_lit%d", op - DW_OP_lit0);
	  break;

	case DW_OP_reg0:
	case DW_OP_reg1:
	case DW_OP_reg2:
	case DW_OP_reg3:
	case DW_OP_reg4:
	case DW_OP_reg5:
	case DW_OP_reg6:
	case DW_OP_reg7:
	case DW_OP_reg8:
	case DW_OP_reg9:
	case DW_OP_reg10:
	case DW_OP_reg11:
	case DW_OP_reg12:
	case DW_OP_reg13:
	case DW_OP_reg14:
	case DW_OP_reg15:
	case DW_OP_reg16:
	case DW_OP_reg17:
	case DW_OP_reg18:
	case DW_OP_reg19:
	case DW_OP_reg20:
	case DW_OP_reg21:
	case DW_OP_reg22:
	case DW_OP_reg23:
	case DW_OP_reg24:
	case DW_OP_reg25:
	case DW_OP_reg26:
	case DW_OP_reg27:
	case DW_OP_reg28:
	case DW_OP_reg29:
	case DW_OP_reg30:
	case DW_OP_reg31:
Jan Kratochvil's avatar
Jan Kratochvil committed
1089 1090
	  printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
		  regname (op - DW_OP_reg0, 1));
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
	  break;

	case DW_OP_breg0:
	case DW_OP_breg1:
	case DW_OP_breg2:
	case DW_OP_breg3:
	case DW_OP_breg4:
	case DW_OP_breg5:
	case DW_OP_breg6:
	case DW_OP_breg7:
	case DW_OP_breg8:
	case DW_OP_breg9:
	case DW_OP_breg10:
	case DW_OP_breg11:
	case DW_OP_breg12:
	case DW_OP_breg13:
	case DW_OP_breg14:
	case DW_OP_breg15:
	case DW_OP_breg16:
	case DW_OP_breg17:
	case DW_OP_breg18:
	case DW_OP_breg19:
	case DW_OP_breg20:
	case DW_OP_breg21:
	case DW_OP_breg22:
	case DW_OP_breg23:
	case DW_OP_breg24:
	case DW_OP_breg25:
	case DW_OP_breg26:
	case DW_OP_breg27:
	case DW_OP_breg28:
	case DW_OP_breg29:
	case DW_OP_breg30:
	case DW_OP_breg31:
1125
	  printf ("DW_OP_breg%d (%s): %s",
Kai Tietz's avatar
Kai Tietz committed
1126
		  op - DW_OP_breg0,
Jan Kratochvil's avatar
Jan Kratochvil committed
1127
		  regname (op - DW_OP_breg0, 1),
Nick Clifton's avatar
Nick Clifton committed
1128
		  dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1129 1130 1131 1132
	  data += bytes_read;
	  break;

	case DW_OP_regx:
Nick Clifton's avatar
Nick Clifton committed
1133
	  uvalue = read_uleb128 (data, &bytes_read, end);
1134
	  data += bytes_read;
1135 1136
	  printf ("DW_OP_regx: %s (%s)",
		  dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1137 1138 1139
	  break;
	case DW_OP_fbreg:
	  need_frame_base = 1;
1140
	  printf ("DW_OP_fbreg: %s",
Nick Clifton's avatar
Nick Clifton committed
1141
		  dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1142 1143 1144
	  data += bytes_read;
	  break;
	case DW_OP_bregx:
Nick Clifton's avatar
Nick Clifton committed
1145
	  uvalue = read_uleb128 (data, &bytes_read, end);
1146
	  data += bytes_read;
1147 1148
	  printf ("DW_OP_bregx: %s (%s) %s",
		  dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
Nick Clifton's avatar
Nick Clifton committed
1149
		  dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1150 1151 1152
	  data += bytes_read;
	  break;
	case DW_OP_piece:
1153
	  printf ("DW_OP_piece: %s",
Nick Clifton's avatar
Nick Clifton committed
1154
		  dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1155 1156 1157
	  data += bytes_read;
	  break;
	case DW_OP_deref_size:
Nick Clifton's avatar
Nick Clifton committed
1158 1159
	  SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
	  printf ("DW_OP_deref_size: %ld", (long) uvalue);
1160 1161
	  break;
	case DW_OP_xderef_size:
Nick Clifton's avatar
Nick Clifton committed
1162 1163
	  SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
	  printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
	  break;
	case DW_OP_nop:
	  printf ("DW_OP_nop");
	  break;

	  /* DWARF 3 extensions.  */
	case DW_OP_push_object_address:
	  printf ("DW_OP_push_object_address");
	  break;
	case DW_OP_call2:
	  /* XXX: Strictly speaking for 64-bit DWARF3 files
	     this ought to be an 8-byte wide computation.  */
Nick Clifton's avatar
Nick Clifton committed
1176
	  SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1177
	  printf ("DW_OP_call2: <0x%s>",
Nick Clifton's avatar
Nick Clifton committed
1178
		  dwarf_vmatoa ("x", svalue + cu_offset));
1179 1180 1181 1182
	  break;
	case DW_OP_call4:
	  /* XXX: Strictly speaking for 64-bit DWARF3 files
	     this ought to be an 8-byte wide computation.  */
Nick Clifton's avatar
Nick Clifton committed
1183
	  SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1184
	  printf ("DW_OP_call4: <0x%s>",
Nick Clifton's avatar
Nick Clifton committed
1185
		  dwarf_vmatoa ("x", svalue + cu_offset));
1186 1187
	  break;
	case DW_OP_call_ref:
1188 1189
	  /* XXX: Strictly speaking for 64-bit DWARF3 files
	     this ought to be an 8-byte wide computation.  */
1190 1191 1192 1193 1194 1195 1196 1197
	  if (dwarf_version == -1)
	    {
	      printf (_("(DW_OP_call_ref in frame info)"));
	      /* No way to tell where the next op is, so just bail.  */
	      return need_frame_base;
	    }
	  if (dwarf_version == 2)
	    {
Nick Clifton's avatar
Nick Clifton committed
1198
	      SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1199 1200 1201
	    }
	  else
	    {
Nick Clifton's avatar
Nick Clifton committed
1202
	      SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1203
	    }
Nick Clifton's avatar
Nick Clifton committed
1204
	  printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1205
	  break;
1206 1207 1208
	case DW_OP_form_tls_address:
	  printf ("DW_OP_form_tls_address");
	  break;
1209 1210 1211 1212 1213
	case DW_OP_call_frame_cfa:
	  printf ("DW_OP_call_frame_cfa");
	  break;
	case DW_OP_bit_piece:
	  printf ("DW_OP_bit_piece: ");
1214
	  printf (_("size: %s "),
Nick Clifton's avatar
Nick Clifton committed
1215
		  dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1216
	  data += bytes_read;
1217
	  printf (_("offset: %s "),
Nick Clifton's avatar
Nick Clifton committed
1218
		  dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1219 1220
	  data += bytes_read;
	  break;
1221

1222 1223 1224 1225 1226 1227 1228
	  /* DWARF 4 extensions.  */
	case DW_OP_stack_value:
	  printf ("DW_OP_stack_value");
	  break;

	case DW_OP_implicit_value:
	  printf ("DW_OP_implicit_value");
Nick Clifton's avatar
Nick Clifton committed
1229
	  uvalue = read_uleb128 (data, &bytes_read, end);
1230
	  data += bytes_read;
Nick Clifton's avatar
Nick Clifton committed
1231
	  display_block (data, uvalue, end);
1232 1233 1234
	  data += uvalue;
	  break;

1235 1236
	  /* GNU extensions.  */
	case DW_OP_GNU_push_tls_address:
1237
	  printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1238 1239 1240 1241 1242
	  break;
	case DW_OP_GNU_uninit:
	  printf ("DW_OP_GNU_uninit");
	  /* FIXME: Is there data associated with this OP ?  */
	  break;
Richard Henderson's avatar
Richard Henderson committed
1243 1244 1245 1246
	case DW_OP_GNU_encoded_addr:
	  {
	    int encoding;
	    dwarf_vma addr;
1247

Richard Henderson's avatar
Richard Henderson committed
1248
	    encoding = *data++;
1249
	    addr = get_encoded_value (data, encoding, section);
Richard Henderson's avatar
Richard Henderson committed
1250 1251 1252 1253 1254 1255
	    data += size_of_encoded_value (encoding);

	    printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
	    print_dwarf_vma (addr, pointer_size);
	  }
	  break;
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
	case DW_OP_GNU_implicit_pointer:
	  /* XXX: Strictly speaking for 64-bit DWARF3 files
	     this ought to be an 8-byte wide computation.  */
	  if (dwarf_version == -1)
	    {
	      printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
	      /* No way to tell where the next op is, so just bail.  */
	      return need_frame_base;
	    }
	  if (dwarf_version == 2)
	    {
Nick Clifton's avatar
Nick Clifton committed
1267
	      SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1268 1269 1270
	    }
	  else
	    {
Nick Clifton's avatar
Nick Clifton committed
1271
	      SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1272
	    }
Nick Clifton's avatar
Nick Clifton committed
1273 1274 1275 1276 1277
	  printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
		  dwarf_vmatoa ("x", uvalue),
		  dwarf_vmatoa ("d", read_sleb128 (data,
						   &bytes_read, end)));
	  data += bytes_read;
1278
	  break;
1279
	case DW_OP_GNU_entry_value:
Nick Clifton's avatar
Nick Clifton committed
1280
	  uvalue = read_uleb128 (data, &bytes_read, end);
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290
	  data += bytes_read;
	  printf ("DW_OP_GNU_entry_value: (");
	  if (decode_location_expression (data, pointer_size, offset_size,
					  dwarf_version, uvalue,
					  cu_offset, section))
	    need_frame_base = 1;
	  putchar (')');
	  data += uvalue;
	  break;
	case DW_OP_GNU_const_type:
Nick Clifton's avatar
Nick Clifton committed
1291
	  uvalue = read_uleb128 (data, &bytes_read, end);
1292 1293 1294
	  data += bytes_read;
	  printf ("DW_OP_GNU_const_type: <0x%s> ",
		  dwarf_vmatoa ("x", cu_offset + uvalue));
Nick Clifton's avatar
Nick Clifton committed
1295 1296
	  SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
	  display_block (data, uvalue, end);
1297 1298 1299
	  data += uvalue;
	  break;
	case DW_OP_GNU_regval_type:
Nick Clifton's avatar
Nick Clifton committed
1300
	  uvalue = read_uleb128 (data, &bytes_read, end);
1301 1302 1303
	  data += bytes_read;
	  printf ("DW_OP_GNU_regval_type: %s (%s)",
		  dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
Nick Clifton's avatar
Nick Clifton committed
1304
	  uvalue = read_uleb128 (data, &bytes_read, end);
1305 1306 1307 1308
	  data += bytes_read;
	  printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
	  break;
	case DW_OP_GNU_deref_type:
Nick Clifton's avatar
Nick Clifton committed
1309 1310
	  SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
	  printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue);
Nick Clifton's avatar
Nick Clifton committed
1311
	  uvalue = read_uleb128 (data, &bytes_read, end);
1312 1313 1314 1315
	  data += bytes_read;
	  printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
	  break;
	case DW_OP_GNU_convert:
Nick Clifton's avatar
Nick Clifton committed
1316
	  uvalue = read_uleb128 (data, &bytes_read, end);
1317 1318
	  data += bytes_read;
	  printf ("DW_OP_GNU_convert <0x%s>",
1319
		  dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1320 1321
	  break;
	case DW_OP_GNU_reinterpret:
Nick Clifton's avatar
Nick Clifton committed
1322
	  uvalue = read_uleb128 (data, &bytes_read, end);
1323 1324
	  data += bytes_read;
	  printf ("DW_OP_GNU_reinterpret <0x%s>",
1325 1326 1327
		  dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
	  break;
	case DW_OP_GNU_parameter_ref:
Nick Clifton's avatar
Nick Clifton committed
1328
	  SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1329
	  printf ("DW_OP_GNU_parameter_ref: <0x%s>",
Nick Clifton's avatar
Nick Clifton committed
1330
		  dwarf_vmatoa ("x", cu_offset + uvalue));
1331
	  break;
1332
        case DW_OP_GNU_addr_index:
Nick Clifton's avatar
Nick Clifton committed
1333
          uvalue = read_uleb128 (data, &bytes_read, end);
1334 1335 1336
          data += bytes_read;
          printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
          break;
1337
        case DW_OP_GNU_const_index:
Nick Clifton's avatar
Nick Clifton committed
1338
          uvalue = read_uleb128 (data, &bytes_read, end);
1339 1340 1341
          data += bytes_read;
          printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
          break;
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362