* Makefile.am (check-DEJAGNU): Clear LC_COLLATE, LC_ALL and LANG.
[deliverable/binutils-gdb.git] / binutils / dwarf.c
index 5102aec27e83fc61e79c67445010669b9d4b8289..def71fb3270661b5df532f9651c7ad894324dce6 100644 (file)
@@ -1,5 +1,5 @@
 /* dwarf.c -- display DWARF contents of a BFD binary file
-   Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
@@ -129,7 +129,7 @@ print_dwarf_vma (dwarf_vma val, unsigned byte_size)
       if (byte_size > 0 && byte_size <= 8)
        offset = 16 - 2 * byte_size;
       else
-       error ("Wrong size in print_dwarf_vma");
+       error (_("Wrong size in print_dwarf_vma"));
     }
 
   fputs (buff + offset, stdout);
@@ -169,6 +169,27 @@ dwarf_vmatoa (const char *fmtch, dwarf_vma value)
   return ret;
 }
 
+/* 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;
+}
+
 dwarf_vma
 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
 {
@@ -247,6 +268,7 @@ process_extended_line_op (unsigned char *data, int is_stmt)
   unsigned int len;
   unsigned char *name;
   dwarf_vma adr;
+  unsigned char *orig_data = data;
 
   len = read_leb128 (data, & bytes_read, 0);
   data += bytes_read;
@@ -277,7 +299,7 @@ process_extended_line_op (unsigned char *data, int is_stmt)
       break;
 
     case DW_LNE_define_file:
-      printf (_("  define new File Table entry\n"));
+      printf (_("define new File Table entry\n"));
       printf (_("  Entry\tDir\tTime\tSize\tName\n"));
 
       printf ("   %d\t", ++state_machine_regs.last_file_entry);
@@ -288,7 +310,11 @@ process_extended_line_op (unsigned char *data, int is_stmt)
       printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
       data += bytes_read;
       printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
-      printf ("%s\n\n", name);
+      data += bytes_read;
+      printf ("%s", name);
+      if ((unsigned int) (data - orig_data) != len)
+        printf (_(" [Bad opcode length]"));
+      printf ("\n\n");
       break;
 
     case DW_LNE_set_discriminator:
@@ -353,21 +379,21 @@ process_extended_line_op (unsigned char *data, int is_stmt)
                 break;
               case DW_LNE_HP_SFC_associate:
                 printf ("    DW_LNE_HP_SFC_associate ");
-                printf (_("(%s"),
+                printf ("(%s",
                         dwarf_vmatoa ("u",
                                       read_leb128 (data, & bytes_read, 0)));
                 data += bytes_read;
-                printf (_(",%s"),
+                printf (",%s",
                         dwarf_vmatoa ("u",
                                       read_leb128 (data, & bytes_read, 0)));
                 data += bytes_read;
-                printf (_(",%s)\n"),
+                printf (",%s)\n",
                         dwarf_vmatoa ("u",
                                       read_leb128 (data, & bytes_read, 0)));
                 data += bytes_read;
                 break;
               default:
-                printf ("    UNKNOW DW_LNE_HP_SFC opcode (%u)\n", opc);
+                printf (_("    UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
                 data = edata;
                 break;
               }
@@ -1072,10 +1098,10 @@ decode_location_expression (unsigned char * data,
          break;
        case DW_OP_bit_piece:
          printf ("DW_OP_bit_piece: ");
-         printf ("size: %s ",
+         printf (_("size: %s "),
                  dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
          data += bytes_read;
-         printf ("offset: %s ",
+         printf (_("offset: %s "),
                  dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
          data += bytes_read;
          break;
@@ -1095,7 +1121,7 @@ decode_location_expression (unsigned char * data,
 
          /* GNU extensions.  */
        case DW_OP_GNU_push_tls_address:
-         printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
+         printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
          break;
        case DW_OP_GNU_uninit:
          printf ("DW_OP_GNU_uninit");
@@ -1179,13 +1205,18 @@ decode_location_expression (unsigned char * data,
          uvalue = read_leb128 (data, &bytes_read, 0);
          data += bytes_read;
          printf ("DW_OP_GNU_convert <0x%s>",
-                 dwarf_vmatoa ("x", cu_offset + uvalue));
+                 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
          break;
        case DW_OP_GNU_reinterpret:
          uvalue = read_leb128 (data, &bytes_read, 0);
          data += bytes_read;
          printf ("DW_OP_GNU_reinterpret <0x%s>",
-                 dwarf_vmatoa ("x", cu_offset + uvalue));
+                 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
+         break;
+       case DW_OP_GNU_parameter_ref:
+         printf ("DW_OP_GNU_parameter_ref: <0x%s>",
+                 dwarf_vmatoa ("x", cu_offset + byte_get (data, 4)));
+         data += 4;
          break;
 
          /* HP extensions.  */
@@ -1371,9 +1402,12 @@ read_and_display_attr_value (unsigned long attribute,
     case DW_FORM_data8:
       if (!do_loc)
        {
-         uvalue = byte_get (data, 4);
-         printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
-         printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
+         dwarf_vma high_bits;
+         char buf[64];
+
+         byte_get_64 (data, &high_bits, &uvalue);
+         printf (" 0x%s",
+                 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
        }
       if ((do_loc || do_debug_loc || do_debug_ranges)
          && num_debug_info_entries == 0)
@@ -1443,16 +1477,14 @@ read_and_display_attr_value (unsigned long attribute,
     case DW_FORM_ref_sig8:
       if (!do_loc)
        {
-         int i;
-         printf (" signature: ");
-         for (i = 0; i < 8; i++)
-           {
-             printf ("%02x", (unsigned) byte_get (data, 1));
-             data += 1;
-           }
+         dwarf_vma high_bits;
+         char buf[64];
+
+         byte_get_64 (data, &high_bits, &uvalue);
+         printf (" signature: 0x%s",
+                 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
        }
-      else
-        data += 8;
+      data += 8;
       break;
 
     default:
@@ -1480,8 +1512,8 @@ read_and_display_attr_value (unsigned long attribute,
        case DW_AT_GNU_call_site_data_value:
        case DW_AT_GNU_call_site_target:
        case DW_AT_GNU_call_site_target_clobbered:
-         if (form == DW_FORM_data4
-             || form == DW_FORM_data8
+         if ((dwarf_version < 4
+              && (form == DW_FORM_data4 || form == DW_FORM_data8))
              || form == DW_FORM_sec_offset)
            {
              /* Process location list.  */
@@ -1511,8 +1543,8 @@ read_and_display_attr_value (unsigned long attribute,
          break;
 
        case DW_AT_ranges:
-         if (form == DW_FORM_data4
-             || form == DW_FORM_data8
+         if ((dwarf_version < 4
+              && (form == DW_FORM_data4 || form == DW_FORM_data8))
              || form == DW_FORM_sec_offset)
            {
              /* Process range list.  */
@@ -1537,7 +1569,7 @@ read_and_display_attr_value (unsigned long attribute,
        }
     }
 
-  if (do_loc)
+  if (do_loc || attribute == 0)
     return data;
 
   /* For some attributes we can display further information.  */
@@ -1594,16 +1626,18 @@ read_and_display_attr_value (unsigned long attribute,
        case DW_LANG_D:                 printf ("(D)"); break;
          /* DWARF 4 values.  */
        case DW_LANG_Python:            printf ("(Python)"); break;
+         /* DWARF 5 values.  */
+       case DW_LANG_Go:                printf ("(Go)"); break;
          /* MIPS extension.  */
        case DW_LANG_Mips_Assembler:    printf ("(MIPS assembler)"); break;
          /* UPC extension.  */
        case DW_LANG_Upc:               printf ("(Unified Parallel C)"); break;
        default:
          if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
-           printf ("(implementation defined: %s)",
+           printf (_("(implementation defined: %s)"),
                    dwarf_vmatoa ("x", uvalue));
          else
-           printf ("(Unknown: %s)", dwarf_vmatoa ("x", uvalue));
+           printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
          break;
        }
       break;
@@ -1641,9 +1675,9 @@ read_and_display_attr_value (unsigned long attribute,
        default:
          if (uvalue >= DW_ATE_lo_user
              && uvalue <= DW_ATE_hi_user)
-           printf ("(user defined type)");
+           printf (_("(user defined type)"));
          else
-           printf ("(unknown type)");
+           printf (_("(unknown type)"));
          break;
        }
       break;
@@ -1655,7 +1689,7 @@ read_and_display_attr_value (unsigned long attribute,
        case DW_ACCESS_protected:       printf ("(protected)"); break;
        case DW_ACCESS_private:         printf ("(private)"); break;
        default:
-         printf ("(unknown accessibility)");
+         printf (_("(unknown accessibility)"));
          break;
        }
       break;
@@ -1666,7 +1700,7 @@ read_and_display_attr_value (unsigned long attribute,
        case DW_VIS_local:              printf ("(local)"); break;
        case DW_VIS_exported:           printf ("(exported)"); break;
        case DW_VIS_qualified:          printf ("(qualified)"); break;
-       default:                        printf ("(unknown visibility)"); break;
+       default:                        printf (_("(unknown visibility)")); break;
        }
       break;
 
@@ -1676,7 +1710,7 @@ read_and_display_attr_value (unsigned long attribute,
        case DW_VIRTUALITY_none:        printf ("(none)"); break;
        case DW_VIRTUALITY_virtual:     printf ("(virtual)"); break;
        case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
-       default:                        printf ("(unknown virtuality)"); break;
+       default:                        printf (_("(unknown virtuality)")); break;
        }
       break;
 
@@ -1687,7 +1721,7 @@ read_and_display_attr_value (unsigned long attribute,
        case DW_ID_up_case:             printf ("(up_case)"); break;
        case DW_ID_down_case:           printf ("(down_case)"); break;
        case DW_ID_case_insensitive:    printf ("(case_insensitive)"); break;
-       default:                        printf ("(unknown case)"); break;
+       default:                        printf (_("(unknown case)")); break;
        }
       break;
 
@@ -1700,16 +1734,16 @@ read_and_display_attr_value (unsigned long attribute,
        default:
          if (uvalue >= DW_CC_lo_user
              && uvalue <= DW_CC_hi_user)
-           printf ("(user defined)");
+           printf (_("(user defined)"));
          else
-           printf ("(unknown convention)");
+           printf (_("(unknown convention)"));
        }
       break;
 
     case DW_AT_ordering:
       switch (uvalue)
        {
-       case -1: printf ("(undefined)"); break;
+       case -1: printf (_("(undefined)")); break;
        case 0:  printf ("(row major)"); break;
        case 1:  printf ("(column major)"); break;
        }
@@ -1729,8 +1763,8 @@ read_and_display_attr_value (unsigned long attribute,
     case DW_AT_GNU_call_site_data_value:
     case DW_AT_GNU_call_site_target:
     case DW_AT_GNU_call_site_target_clobbered:
-      if (form == DW_FORM_data4
-         || form == DW_FORM_data8
+      if ((dwarf_version < 4
+           && (form == DW_FORM_data4 || form == DW_FORM_data8))
          || form == DW_FORM_sec_offset)
        printf (_("(location list)"));
       /* Fall through.  */
@@ -1764,7 +1798,8 @@ read_and_display_attr_value (unsigned long attribute,
 
        if (form == DW_FORM_ref1
            || form == DW_FORM_ref2
-           || form == DW_FORM_ref4)
+           || form == DW_FORM_ref4
+           || form == DW_FORM_ref_udata)
          uvalue += cu_offset;
 
        if (uvalue >= section->size)
@@ -1778,7 +1813,7 @@ read_and_display_attr_value (unsigned long attribute,
 
            abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
 
-           printf ("[Abbrev Number: %ld", abbrev_number);
+           printf (_("[Abbrev Number: %ld"), abbrev_number);
            for (entry = first_abbrev; entry != NULL; entry = entry->next)
              if (entry->entry == abbrev_number)
                break;
@@ -1955,6 +1990,7 @@ get_AT_name (unsigned long attribute)
     case DW_AT_GNU_all_tail_call_sites:                return "DW_AT_GNU_all_tail_call_sites";
     case DW_AT_GNU_all_call_sites:             return "DW_AT_GNU_all_call_sites";
     case DW_AT_GNU_all_source_call_sites:      return "DW_AT_GNU_all_source_call_sites";
+    case DW_AT_GNU_macros:                     return "DW_AT_GNU_macros";
 
       /* UPC extension.  */
     case DW_AT_upc_threads_scaled:     return "DW_AT_upc_threads_scaled";
@@ -2099,7 +2135,8 @@ process_debug_info (struct dwarf_section *section,
       dwarf_vma cu_offset;
       int offset_size;
       int initial_length_size;
-      unsigned char signature[8] = { 0 };
+      dwarf_vma signature_high = 0;
+      dwarf_vma signature_low = 0;
       dwarf_vma type_offset = 0;
 
       hdrptr = start;
@@ -2133,14 +2170,8 @@ process_debug_info (struct dwarf_section *section,
 
       if (do_types)
         {
-          int i;
-
-          for (i = 0; i < 8; i++)
-            {
-              signature[i] = byte_get (hdrptr, 1);
-              hdrptr += 1;
-            }
-
+          byte_get_64 (hdrptr, &signature_high, &signature_low);
+          hdrptr += 8;
           type_offset = byte_get (hdrptr, offset_size);
           hdrptr += offset_size;
         }
@@ -2177,13 +2208,13 @@ process_debug_info (struct dwarf_section *section,
          printf (_("   Pointer Size:  %d\n"), compunit.cu_pointer_size);
          if (do_types)
            {
-             int i;
-             printf (_("   Signature:     "));
-             for (i = 0; i < 8; i++)
-               printf ("%02x", signature[i]);
-             printf ("\n");
-             printf (_("   Type Offset:   0x%s\n"),
-                     dwarf_vmatoa ("x", type_offset));
+             char buf[64];
+
+             printf (_("   Signature:     0x%s\n"),
+                     dwarf_vmatoa64 (signature_high, signature_low,
+                                     buf, sizeof (buf)));
+             printf (_("   Type Offset:   0x%s\n"),
+                     dwarf_vmatoa ("x", type_offset));
            }
        }
 
@@ -2791,7 +2822,9 @@ display_debug_lines_decoded (struct dwarf_section *section,
       int offset_size;
       int i;
       File_Entry *file_table = NULL;
+      unsigned int n_files = 0;
       unsigned char **directory_table = NULL;
+      unsigned int n_directories = 0;
 
       hdrptr = data;
 
@@ -2876,7 +2909,6 @@ display_debug_lines_decoded (struct dwarf_section *section,
       data = standard_opcodes + linfo.li_opcode_base - 1;
       if (*data != 0)
         {
-          unsigned int n_directories = 0;
           unsigned char *ptr_directory_table = data;
 
          while (*data != 0)
@@ -2903,7 +2935,6 @@ display_debug_lines_decoded (struct dwarf_section *section,
       /* Traverse the File Name table just to count the entries.  */
       if (*data != 0)
         {
-          unsigned int n_files = 0;
           unsigned char *ptr_file_name_table = data;
 
           while (*data != 0)
@@ -2955,9 +2986,10 @@ display_debug_lines_decoded (struct dwarf_section *section,
             }
           else
             {
-              if (do_wide || strlen ((char *) directory_table[0]) < 76)
-               printf (_("CU: %s/%s:\n"), directory_table[0],
-                       file_table[0].name);
+              unsigned int ix = file_table[0].directory_index;
+              const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
+              if (do_wide || strlen (directory) < 76)
+               printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
               else
                printf ("%s:\n", file_table[0].name);
 
@@ -3034,21 +3066,36 @@ display_debug_lines_decoded (struct dwarf_section *section,
                     break;
                   case DW_LNE_define_file:
                     {
-                      unsigned int dir_index = 0;
+                      file_table = (File_Entry *) xrealloc
+                        (file_table, (n_files + 1) * sizeof (File_Entry));
 
                       ++state_machine_regs.last_file_entry;
+                      /* Source file name.  */
+                      file_table[n_files].name = op_code_data;
                       op_code_data += strlen ((char *) op_code_data) + 1;
-                      dir_index = read_leb128 (op_code_data, & bytes_read, 0);
+                      /* Directory index.  */
+                      file_table[n_files].directory_index =
+                        read_leb128 (op_code_data, & bytes_read, 0);
                       op_code_data += bytes_read;
-                      read_leb128 (op_code_data, & bytes_read, 0);
+                      /* Last modification time.  */
+                      file_table[n_files].modification_date =
+                        read_leb128 (op_code_data, & bytes_read, 0);
                       op_code_data += bytes_read;
-                      read_leb128 (op_code_data, & bytes_read, 0);
+                      /* File length.  */
+                      file_table[n_files].length =
+                        read_leb128 (op_code_data, & bytes_read, 0);
 
-                      printf ("%s:\n", directory_table[dir_index]);
+                      n_files++;
                       break;
                     }
+                  case DW_LNE_set_discriminator:
+                  case DW_LNE_HP_set_sequence:
+                    /* Simply ignored.  */
+                    break;
+
                   default:
-                    printf (_("UNKNOWN: length %d\n"), ext_op_code_len - bytes_read);
+                    printf (_("UNKNOWN (%u): length %d\n"),
+                            ext_op_code, ext_op_code_len - bytes_read);
                     break;
                   }
                 data += ext_op_code_len;
@@ -3445,6 +3492,321 @@ display_debug_macinfo (struct dwarf_section *section,
   return 1;
 }
 
+/* Given LINE_OFFSET into the .debug_line section, attempt to return
+   filename and dirname corresponding to file name table entry with index
+   FILEIDX.  Return NULL on failure.  */
+
+static unsigned char *
+get_line_filename_and_dirname (dwarf_vma line_offset, dwarf_vma fileidx,
+                              unsigned char **dir_name)
+{
+  struct dwarf_section *section = &debug_displays [line].section;
+  unsigned char *hdrptr, *dirtable, *file_name;
+  unsigned int offset_size, initial_length_size;
+  unsigned int version, opcode_base, bytes_read;
+  dwarf_vma length, diridx;
+
+  *dir_name = NULL;
+  if (section->start == NULL
+      || line_offset >= section->size
+      || fileidx == 0)
+    return NULL;
+
+  hdrptr = section->start + line_offset;
+  length = byte_get (hdrptr, 4);
+  hdrptr += 4;
+  if (length == 0xffffffff)
+    {
+      /* This section is 64-bit DWARF 3.  */
+      length = byte_get (hdrptr, 8);
+      hdrptr += 8;
+      offset_size = 8;
+      initial_length_size = 12;
+    }
+  else
+    {
+      offset_size = 4;
+      initial_length_size = 4;
+    }
+  if (length + initial_length_size > section->size)
+    return NULL;
+  version = byte_get (hdrptr, 2);
+  hdrptr += 2;
+  if (version != 2 && version != 3 && version != 4)
+    return NULL;
+  hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length.  */
+  if (version >= 4)
+    hdrptr++;              /* Skip max_ops_per_insn.  */
+  hdrptr += 3;             /* Skip default_is_stmt, line_base, line_range.  */
+  opcode_base = byte_get (hdrptr, 1);
+  if (opcode_base == 0)
+    return NULL;
+  hdrptr++;
+  hdrptr += opcode_base - 1;
+  dirtable = hdrptr;
+  /* Skip over dirname table.  */
+  while (*hdrptr != '\0')
+    hdrptr += strlen ((char *) hdrptr) + 1;
+  hdrptr++;                /* Skip the NUL at the end of the table.  */
+  /* Now skip over preceding filename table entries.  */
+  for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
+    {
+      hdrptr += strlen ((char *) hdrptr) + 1;
+      read_leb128 (hdrptr, &bytes_read, 0);
+      hdrptr += bytes_read;
+      read_leb128 (hdrptr, &bytes_read, 0);
+      hdrptr += bytes_read;
+      read_leb128 (hdrptr, &bytes_read, 0);
+      hdrptr += bytes_read;
+    }
+  if (*hdrptr == '\0')
+    return NULL;
+  file_name = hdrptr;
+  hdrptr += strlen ((char *) hdrptr) + 1;
+  diridx = read_leb128 (hdrptr, &bytes_read, 0);
+  if (diridx == 0)
+    return file_name;
+  for (; *dirtable != '\0' && diridx > 1; diridx--)
+    dirtable += strlen ((char *) dirtable) + 1;
+  if (*dirtable == '\0')
+    return NULL;
+  *dir_name = dirtable;
+  return file_name;
+}
+
+static int
+display_debug_macro (struct dwarf_section *section,
+                    void *file)
+{
+  unsigned char *start = section->start;
+  unsigned char *end = start + section->size;
+  unsigned char *curr = start;
+  unsigned char *extended_op_buf[256];
+  unsigned int bytes_read;
+
+  load_debug_section (str, file);
+  load_debug_section (line, file);
+
+  printf (_("Contents of the %s section:\n\n"), section->name);
+
+  while (curr < end)
+    {
+      unsigned int lineno, version, flags;
+      unsigned int offset_size = 4;
+      const char *string;
+      dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
+      unsigned char **extended_ops = NULL;
+
+      version = byte_get (curr, 2);
+      curr += 2;
+
+      if (version != 4)
+       {
+         error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
+                section->name);
+         return 0;
+       }
+
+      flags = byte_get (curr++, 1);
+      if (flags & 1)
+       offset_size = 8;
+      printf (_("  Offset:                      0x%lx\n"),
+             (unsigned long) sec_offset);
+      printf (_("  Version:                     %d\n"), version);
+      printf (_("  Offset size:                 %d\n"), offset_size);
+      if (flags & 2)
+       {
+         line_offset = byte_get (curr, offset_size);
+         curr += offset_size;
+         printf (_("  Offset into .debug_line:     0x%lx\n"),
+                 (unsigned long) line_offset);
+       }
+      if (flags & 4)
+       {
+         unsigned int i, count = byte_get (curr++, 1), op;
+         dwarf_vma nargs, n;
+         memset (extended_op_buf, 0, sizeof (extended_op_buf));
+         extended_ops = extended_op_buf;
+         if (count)
+           {
+             printf (_("  Extension opcode arguments:\n"));
+             for (i = 0; i < count; i++)
+               {
+                 op = byte_get (curr++, 1);
+                 extended_ops[op] = curr;
+                 nargs = read_leb128 (curr, &bytes_read, 0);
+                 curr += bytes_read;
+                 if (nargs == 0)
+                   printf (_("    DW_MACRO_GNU_%02x has no arguments\n"), op);
+                 else
+                   {
+                     printf (_("    DW_MACRO_GNU_%02x arguments: "), op);
+                     for (n = 0; n < nargs; n++)
+                       {
+                         unsigned int form = byte_get (curr++, 1);
+                         printf ("%s%s", get_FORM_name (form),
+                                 n == nargs - 1 ? "\n" : ", ");
+                         switch (form)
+                           {
+                           case DW_FORM_data1:
+                           case DW_FORM_data2:
+                           case DW_FORM_data4:
+                           case DW_FORM_data8:
+                           case DW_FORM_sdata:
+                           case DW_FORM_udata:
+                           case DW_FORM_block:
+                           case DW_FORM_block1:
+                           case DW_FORM_block2:
+                           case DW_FORM_block4:
+                           case DW_FORM_flag:
+                           case DW_FORM_string:
+                           case DW_FORM_strp:
+                           case DW_FORM_sec_offset:
+                             break;
+                           default:
+                             error (_("Invalid extension opcode form %s\n"),
+                                    get_FORM_name (form));
+                             return 0;
+                           }
+                       }
+                   }
+               }
+           }
+       }
+      printf ("\n");
+
+      while (1)
+       {
+         unsigned int op;
+
+         if (curr >= end)
+           {
+             error (_(".debug_macro section not zero terminated\n"));
+             return 0;
+           }
+
+         op = byte_get (curr++, 1);
+         if (op == 0)
+           break;
+
+         switch (op)
+           {
+           case DW_MACRO_GNU_start_file:
+             {
+               unsigned int filenum;
+               unsigned char *file_name = NULL, *dir_name = NULL;
+
+               lineno = read_leb128 (curr, &bytes_read, 0);
+               curr += bytes_read;
+               filenum = read_leb128 (curr, &bytes_read, 0);
+               curr += bytes_read;
+
+               if ((flags & 2) == 0)
+                 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
+               else
+                 file_name
+                   = get_line_filename_and_dirname (line_offset, filenum,
+                                                    &dir_name);
+               if (file_name == NULL)
+                 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
+                         lineno, filenum);
+               else
+                 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
+                         lineno, filenum,
+                         dir_name != NULL ? (const char *) dir_name : "",
+                         dir_name != NULL ? "/" : "", file_name);
+             }
+             break;
+
+           case DW_MACRO_GNU_end_file:
+             printf (_(" DW_MACRO_GNU_end_file\n"));
+             break;
+
+           case DW_MACRO_GNU_define:
+             lineno = read_leb128 (curr, &bytes_read, 0);
+             curr += bytes_read;
+             string = (char *) curr;
+             curr += strlen (string) + 1;
+             printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
+                     lineno, string);
+             break;
+
+           case DW_MACRO_GNU_undef:
+             lineno = read_leb128 (curr, &bytes_read, 0);
+             curr += bytes_read;
+             string = (char *) curr;
+             curr += strlen (string) + 1;
+             printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
+                     lineno, string);
+             break;
+
+           case DW_MACRO_GNU_define_indirect:
+             lineno = read_leb128 (curr, &bytes_read, 0);
+             curr += bytes_read;
+             offset = byte_get (curr, offset_size);
+             curr += offset_size;
+             string = fetch_indirect_string (offset);
+             printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
+                     lineno, string);
+             break;
+
+           case DW_MACRO_GNU_undef_indirect:
+             lineno = read_leb128 (curr, &bytes_read, 0);
+             curr += bytes_read;
+             offset = byte_get (curr, offset_size);
+             curr += offset_size;
+             string = fetch_indirect_string (offset);
+             printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
+                     lineno, string);
+             break;
+
+           case DW_MACRO_GNU_transparent_include:
+             offset = byte_get (curr, offset_size);
+             curr += offset_size;
+             printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
+                     (unsigned long) offset);
+             break;
+
+           default:
+             if (extended_ops == NULL || extended_ops[op] == NULL)
+               {
+                 error (_(" Unknown macro opcode %02x seen\n"), op);
+                 return 0;
+               }
+             else
+               {
+                 /* Skip over unhandled opcodes.  */
+                 dwarf_vma nargs, n;
+                 unsigned char *desc = extended_ops[op];
+                 nargs = read_leb128 (desc, &bytes_read, 0);
+                 desc += bytes_read;
+                 if (nargs == 0)
+                   {
+                     printf (_(" DW_MACRO_GNU_%02x\n"), op);
+                     break;
+                   }
+                 printf (_(" DW_MACRO_GNU_%02x -"), op);
+                 for (n = 0; n < nargs; n++)
+                   {
+                     curr
+                       = read_and_display_attr_value (0, byte_get (desc++, 1),
+                                                      curr, 0, 0, offset_size,
+                                                      version, NULL, 0, NULL);
+                     if (n != nargs - 1)
+                       printf (",");
+                   }
+                 printf ("\n");
+               }
+             break;
+           }
+       }
+
+      printf ("\n");
+    }  
+
+  return 1;
+}
+
 static int
 display_debug_abbrev (struct dwarf_section *section,
                      void *file ATTRIBUTE_UNUSED)
@@ -3488,6 +3850,19 @@ display_debug_abbrev (struct dwarf_section *section,
   return 1;
 }
 
+/* Sort array of indexes in ascending order of loc_offsets[idx].  */
+
+static dwarf_vma *loc_offsets;
+
+static int
+loc_offsets_compar (const void *ap, const void *bp)
+{
+  dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
+  dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
+
+  return (a > b) - (b > a);
+}
+
 static int
 display_debug_loc (struct dwarf_section *section, void *file)
 {
@@ -3500,9 +3875,11 @@ display_debug_loc (struct dwarf_section *section, void *file)
   unsigned int first = 0;
   unsigned int i;
   unsigned int j;
+  unsigned int k;
   int seen_first_offset = 0;
-  int use_debug_info = 1;
+  int locs_sorted = 1;
   unsigned char *next;
+  unsigned int *array = NULL;
 
   bytes = section->size;
   section_end = start + bytes;
@@ -3528,10 +3905,11 @@ display_debug_loc (struct dwarf_section *section, void *file)
       unsigned int num;
 
       num = debug_information [i].num_loc_offsets;
-      num_loc_list += num;
+      if (num > num_loc_list)
+       num_loc_list = num;
 
       /* Check if we can use `debug_information' directly.  */
-      if (use_debug_info && num != 0)
+      if (locs_sorted && num != 0)
        {
          if (!seen_first_offset)
            {
@@ -3549,7 +3927,7 @@ display_debug_loc (struct dwarf_section *section, void *file)
              if (last_offset >
                  debug_information [i].loc_offsets [j])
                {
-                 use_debug_info = 0;
+                 locs_sorted = 0;
                  break;
                }
              last_offset = debug_information [i].loc_offsets [j];
@@ -3557,10 +3935,6 @@ display_debug_loc (struct dwarf_section *section, void *file)
        }
     }
 
-  if (!use_debug_info)
-    /* FIXME: Should we handle this case?  */
-    error (_("Location lists in .debug_info section aren't in ascending order!\n"));
-
   if (!seen_first_offset)
     error (_("No location lists in .debug_info section!\n"));
 
@@ -3571,6 +3945,8 @@ display_debug_loc (struct dwarf_section *section, void *file)
          section->name,
          dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
 
+  if (!locs_sorted)
+    array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
   printf (_("Contents of the %s section:\n\n"), section->name);
   printf (_("    Offset   Begin    End      Expression\n"));
 
@@ -3593,9 +3969,23 @@ display_debug_loc (struct dwarf_section *section, void *file)
       cu_offset = debug_information [i].cu_offset;
       offset_size = debug_information [i].offset_size;
       dwarf_version = debug_information [i].dwarf_version;
+      if (!locs_sorted)
+       {
+         for (k = 0; k < debug_information [i].num_loc_offsets; k++)
+           array[k] = k;
+         loc_offsets = debug_information [i].loc_offsets;
+         qsort (array, debug_information [i].num_loc_offsets,
+                sizeof (*array), loc_offsets_compar);
+       }
 
-      for (j = 0; j < debug_information [i].num_loc_offsets; j++)
+      for (k = 0; k < debug_information [i].num_loc_offsets; k++)
        {
+         j = locs_sorted ? k : array[k];
+         if (k
+             && debug_information [i].loc_offsets [locs_sorted
+                                                   ? k - 1 : array [k - 1]]
+                == debug_information [i].loc_offsets [j])
+           continue;
          has_frame_base = debug_information [i].have_frame_base [j];
          /* DWARF sections under Mach-O have non-zero addresses.  */
          offset = debug_information [i].loc_offsets [j] - section->address;
@@ -3709,6 +4099,7 @@ display_debug_loc (struct dwarf_section *section, void *file)
     warn (_("There are %ld unused bytes at the end of section %s\n"),
          (long) (section_end - start), section->name);
   putchar ('\n');
+  free (array);
   return 1;
 }
 
@@ -3865,6 +4256,13 @@ display_debug_aranges (struct dwarf_section *section,
 
       address_size = arange.ar_pointer_size + arange.ar_segment_size;
 
+      if (address_size == 0)
+       {
+         error (_("Invalid address size in %s section!\n"),
+                section->name);
+         break;
+       }
+
       /* The DWARF spec does not require that the address size be a power
         of two, but we do.  This will have to change if we ever encounter
         an uneven architecture.  */
@@ -4199,6 +4597,7 @@ init_dwarf_regnames (unsigned int e_machine)
 
     case EM_X86_64:
     case EM_L1OM:
+    case EM_K1OM:
       init_dwarf_regnames_x86_64 ();
       break;
 
@@ -4750,6 +5149,9 @@ display_debug_frames (struct dwarf_section *section,
                {
                  fc->col_type[opa] = cie->col_type[opa];
                  fc->col_offset[opa] = cie->col_offset[opa];
+                 if (do_debug_frames_interp
+                     && fc->col_type[opa] == DW_CFA_unreferenced)
+                   fc->col_type[opa] = DW_CFA_undefined;
                }
              break;
 
@@ -5149,6 +5551,9 @@ display_gdb_index (struct dwarf_section *section,
       warn (_("Version 4 does not support case insensitive lookups.\n"));
       break;
     case 5:
+      warn (_("Version 5 does not include inlined functions.\n"));
+      break;
+    case 6:
       break;
     default:
       warn (_("Unsupported version %lu.\n"), (unsigned long) version);
@@ -5237,8 +5642,8 @@ display_gdb_index (struct dwarf_section *section,
            {
              cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
              /* Convert to TU number if it's for a type unit.  */
-             if (cu >= cu_list_elements)
-               printf (" T%lu", (unsigned long) (cu - cu_list_elements));
+             if (cu >= cu_list_elements / 2)
+               printf (" T%lu", (unsigned long) (cu - cu_list_elements / 2));
              else
                printf (" %lu", (unsigned long) cu);
            }
@@ -5502,6 +5907,8 @@ struct dwarf_section_display debug_displays[] =
     display_debug_frames,              &do_debug_frames,       1 },
   { { ".debug_macinfo",                ".zdebug_macinfo",      NULL, NULL, 0, 0 },
     display_debug_macinfo,             &do_debug_macinfo,      0 },
+  { { ".debug_macro",          ".zdebug_macro",        NULL, NULL, 0, 0 },
+    display_debug_macro,               &do_debug_macinfo,      1 },
   { { ".debug_str",            ".zdebug_str",          NULL, NULL, 0, 0 },
     display_debug_str,                 &do_debug_str,          0 },
   { { ".debug_loc",            ".zdebug_loc",          NULL, NULL, 0, 0 },
This page took 0.036399 seconds and 4 git commands to generate.