]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - binutils/dwarf.c
i686-w64-mingw32-objdump -WL returns incorrect file paths
[thirdparty/binutils-gdb.git] / binutils / dwarf.c
index 84200ae4078008010036b330f1093d127738f8de..f90f4efac5b96f9fa2ed8317304a139cd0beb29d 100644 (file)
@@ -76,7 +76,7 @@ typedef struct dwo_info
 {
   dwo_type          type;
   const char *      value;
-  dwarf_vma         cu_offset;
+  uint64_t          cu_offset;
   struct dwo_info * next;
 } dwo_info;
 
@@ -119,10 +119,6 @@ unsigned long dwarf_start_die;
 
 int dwarf_check = 0;
 
-/* Convenient constant, to avoid having to cast -1 to dwarf_vma when
-   testing whether e.g. a locview list is present.  */
-static const dwarf_vma vm1 = -1;
-
 /* 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
@@ -140,9 +136,9 @@ static unsigned int shndx_pool_used = 0;
 
 struct cu_tu_set
 {
-  uint64_t   signature;
-  dwarf_vma  section_offsets[DW_SECT_MAX];
-  size_t     section_sizes[DW_SECT_MAX];
+  uint64_t signature;
+  uint64_t section_offsets[DW_SECT_MAX];
+  size_t   section_sizes[DW_SECT_MAX];
 };
 
 static int cu_count = 0;
@@ -175,7 +171,7 @@ size_of_encoded_value (int encoding)
     }
 }
 
-static dwarf_vma
+static uint64_t
 get_encoded_value (unsigned char **pdata,
                   int encoding,
                   struct dwarf_section *section,
@@ -183,7 +179,7 @@ get_encoded_value (unsigned char **pdata,
 {
   unsigned char * data = * pdata;
   unsigned int size = size_of_encoded_value (encoding);
-  dwarf_vma val;
+  uint64_t val;
 
   if (data >= end || size > (size_t) (end - data))
     {
@@ -220,98 +216,43 @@ get_encoded_value (unsigned char **pdata,
   return val;
 }
 
-#if SIZEOF_LONG_LONG > SIZEOF_LONG
-# ifndef __MINGW32__
-#  define DWARF_VMA_FMT                "ll"
-#  define DWARF_VMA_FMT_LONG   "%16.16llx"
-# else
-#  define DWARF_VMA_FMT                "I64"
-#  define DWARF_VMA_FMT_LONG   "%016I64x"
-# endif
-#else
-# define DWARF_VMA_FMT         "l"
-# define DWARF_VMA_FMT_LONG    "%16.16lx"
-#endif
-
-/* 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.  */
+/* Print a uint64_t value (typically an address, offset or length) in
+   hexadecimal format, followed by a space.  The precision displayed is
+   determined by the NUM_BYTES parameter.  */
 
-static const char *
-dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
+static void
+print_hex (uint64_t value, unsigned num_bytes)
 {
-  /* As dwarf_vmatoa is used more then once in a printf call
-     for output, we are cycling through a fixed array of pointers
-     for return address.  */
-  static int buf_pos = 0;
-  static struct dwarf_vmatoa_buf
-  {
-    char place[64];
-  } buf[16];
-  char *ret;
-
-  ret = buf[buf_pos++].place;
-  buf_pos %= ARRAY_SIZE (buf);
-
-  if (num_bytes)
-    {
-      /* Printf does not have a way of specifying 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];
+  if (num_bytes == 0)
+    num_bytes = 2;
 
-      if (fmtch)
-       sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
-      else
-       sprintf (fmt, "%%%s", DWARF_VMA_FMT);
-      snprintf (ret, sizeof (buf[0].place), fmt, value);
-      return ret;
-    }
+  printf ("%0*" PRIx64 " ", num_bytes * 2,
+         value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4));
 }
 
-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.  */
+/* Like print_hex, but no trailing space.  */
 
 static void
-print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
+print_hex_ns (uint64_t value, unsigned num_bytes)
 {
-  printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
+  if (num_bytes == 0)
+    num_bytes = 2;
+
+  printf ("%0*" PRIx64, num_bytes * 2,
+         value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4));
 }
 
-/* Print a view number in hexadecimal value, with the same width
-   print_dwarf_vma would have printed it with the same num_bytes.
-   Print blanks for zero view, unless force is nonzero.  */
+/* Print a view number in hexadecimal value, with the same width as
+   print_hex would have printed it.  */
 
 static void
-print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force)
+print_view (uint64_t value, unsigned num_bytes)
 {
-  int len;
-  if (!num_bytes)
-    len = 4;
-  else
-    len = num_bytes * 2;
+  if (num_bytes == 0)
+    num_bytes = 2;
 
-  assert (value == (unsigned long) value);
-  if (value || force)
-    printf ("v%0*lx ", len - 1, (unsigned long) value);
-  else
-    printf ("%*s", len + 1, "");
+  printf ("v%0*" PRIx64 " ", num_bytes * 2 - 1,
+         value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4));
 }
 
 /* Read in a LEB128 encoded value starting at address DATA.
@@ -319,17 +260,17 @@ print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force)
    If LENGTH_RETURN is not NULL, return in it the number of bytes read.
    If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
    terminating byte was not found and with bit 1 set if the value
-   overflows a dwarf_vma.
+   overflows a uint64_t.
    No bytes will be read at address END or beyond.  */
 
-dwarf_vma
+uint64_t
 read_leb128 (unsigned char *data,
             const unsigned char *const end,
             bool sign,
             unsigned int *length_return,
             int *status_return)
 {
-  dwarf_vma result = 0;
+  uint64_t result = 0;
   unsigned int num_read = 0;
   unsigned int shift = 0;
   int status = 1;
@@ -343,11 +284,11 @@ read_leb128 (unsigned char *data,
 
       if (shift < CHAR_BIT * sizeof (result))
        {
-         result |= ((dwarf_vma) (byte & 0x7f)) << shift;
+         result |= ((uint64_t) (byte & 0x7f)) << shift;
          /* These bits overflowed.  */
          lost = byte ^ (result >> shift);
          /* And this is the mask of possible overflow bits.  */
-         mask = 0x7f ^ ((dwarf_vma) 0x7f << shift >> shift);
+         mask = 0x7f ^ ((uint64_t) 0x7f << shift >> shift);
          shift += 7;
        }
       else
@@ -355,14 +296,14 @@ read_leb128 (unsigned char *data,
          lost = byte;
          mask = 0x7f;
        }
-      if ((lost & mask) != (sign && (dwarf_signed_vma) result < 0 ? mask : 0))
+      if ((lost & mask) != (sign && (int64_t) result < 0 ? mask : 0))
        status |= 2;
 
       if ((byte & 0x80) == 0)
        {
          status &= ~1;
          if (sign && shift < CHAR_BIT * sizeof (result) && (byte & 0x40))
-           result |= -((dwarf_vma) 1 << shift);
+           result |= -((uint64_t) 1 << shift);
          break;
        }
     }
@@ -427,7 +368,7 @@ read_leb128 (unsigned char *data,
 
 typedef struct State_Machine_Registers
 {
-  dwarf_vma address;
+  uint64_t address;
   unsigned int view;
   unsigned int file;
   unsigned int line;
@@ -470,7 +411,7 @@ process_extended_line_op (unsigned char * data,
   size_t len, header_len;
   unsigned char *name;
   unsigned char *orig_data = data;
-  dwarf_vma adr, val;
+  uint64_t adr, val;
 
   READ_ULEB (len, data, end);
   header_len = data - orig_data;
@@ -496,13 +437,13 @@ process_extended_line_op (unsigned char * data,
       /* PR 17512: file: 002-100480-0.004.  */
       if (len - 1 > 8)
        {
-         warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
-               (unsigned long) len - 1);
+         warn (_("Length (%zu) of DW_LNE_set_address op is too long\n"),
+               len - 1);
          adr = 0;
        }
       else
        SAFE_BYTE_GET (adr, data, len - 1, end);
-      printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
+      printf (_("set Address to %#" PRIx64 "\n"), adr);
       state_machine_regs.address = adr;
       state_machine_regs.view = 0;
       state_machine_regs.op_index = 0;
@@ -522,11 +463,11 @@ process_extended_line_op (unsigned char * data,
        if (data < end)
          data++;
        READ_ULEB (val, data, end);
-       printf ("%s\t", dwarf_vmatoa ("u", val));
+       printf ("%" PRIu64 "\t", val);
        READ_ULEB (val, data, end);
-       printf ("%s\t", dwarf_vmatoa ("u", val));
+       printf ("%" PRIu64 "\t", val);
        READ_ULEB (val, data, end);
-       printf ("%s\t", dwarf_vmatoa ("u", val));
+       printf ("%" PRIu64 "\t", val);
        printf ("%.*s\n\n", (int) l, name);
       }
 
@@ -536,7 +477,7 @@ process_extended_line_op (unsigned char * data,
 
     case DW_LNE_set_discriminator:
       READ_ULEB (val, data, end);
-      printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val));
+      printf (_("set Discriminator to %" PRIu64 "\n"), val);
       break;
 
     /* HP extensions.  */
@@ -589,17 +530,17 @@ process_extended_line_op (unsigned char * data,
                break;
              case DW_LNE_HP_SFC_set_listing_line:
                READ_ULEB (val, data, edata);
-               printf ("    DW_LNE_HP_SFC_set_listing_line (%s)\n",
-                       dwarf_vmatoa ("u", val));
+               printf ("    DW_LNE_HP_SFC_set_listing_line (%" PRIu64 ")\n",
+                       val);
                break;
              case DW_LNE_HP_SFC_associate:
                printf ("    DW_LNE_HP_SFC_associate ");
                READ_ULEB (val, data, edata);
-               printf ("(%s", dwarf_vmatoa ("u", val));
+               printf ("(%" PRIu64 , val);
                READ_ULEB (val, data, edata);
-               printf (",%s", dwarf_vmatoa ("u", val));
+               printf (",%" PRIu64, val);
                READ_ULEB (val, data, edata);
-               printf (",%s)\n", dwarf_vmatoa ("u", val));
+               printf (",%" PRIu64 ")\n", val);
                break;
              default:
                printf (_("    UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
@@ -634,7 +575,7 @@ process_extended_line_op (unsigned char * data,
 }
 
 static const unsigned char *
-fetch_indirect_string (dwarf_vma offset)
+fetch_indirect_string (uint64_t offset)
 {
   struct dwarf_section *section = &debug_displays [str].section;
   const unsigned char * ret;
@@ -644,8 +585,7 @@ fetch_indirect_string (dwarf_vma offset)
 
   if (offset >= section->size)
     {
-      warn (_("DW_FORM_strp offset too big: 0x%s\n"),
-           dwarf_vmatoa ("x", offset));
+      warn (_("DW_FORM_strp offset too big: %#" PRIx64 "\n"), offset);
       return (const unsigned char *) _("<offset is too big>");
     }
 
@@ -662,7 +602,7 @@ fetch_indirect_string (dwarf_vma offset)
 }
 
 static const unsigned char *
-fetch_indirect_line_string (dwarf_vma offset)
+fetch_indirect_line_string (uint64_t offset)
 {
   struct dwarf_section *section = &debug_displays [line_str].section;
   const unsigned char * ret;
@@ -672,8 +612,7 @@ fetch_indirect_line_string (dwarf_vma offset)
 
   if (offset >= section->size)
     {
-      warn (_("DW_FORM_line_strp offset too big: 0x%s\n"),
-           dwarf_vmatoa ("x", offset));
+      warn (_("DW_FORM_line_strp offset too big: %#" PRIx64 "\n"), offset);
       return (const unsigned char *) _("<offset is too big>");
     }
 
@@ -690,18 +629,18 @@ fetch_indirect_line_string (dwarf_vma offset)
 }
 
 static const char *
-fetch_indexed_string (dwarf_vma           idx,
-                     struct cu_tu_set *  this_set,
-                     dwarf_vma           offset_size,
-                     bool                dwo,
-                     dwarf_vma           str_offsets_base)
+fetch_indexed_string (uint64_t idx,
+                     struct cu_tu_set *this_set,
+                     uint64_t offset_size,
+                     bool dwo,
+                     uint64_t str_offsets_base)
 {
   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;
-  dwarf_vma str_offset;
+  uint64_t index_offset;
+  uint64_t str_offset;
   const char * ret;
 
   if (index_section->start == NULL)
@@ -721,10 +660,9 @@ fetch_indexed_string (dwarf_vma           idx,
 
   if (index_offset + offset_size > index_section->size)
     {
-      warn (_("string index of %s converts to an offset of 0x%s which is too big for section %s"),
-           dwarf_vmatoa ("d", idx),
-           dwarf_vmatoa ("x", index_offset),
-           str_section->name);
+      warn (_("string index of %" PRIu64 " converts to an offset of %#" PRIx64
+             " which is too big for section %s"),
+           idx, index_offset, str_section->name);
 
       return _("<string index too big>");
     }
@@ -739,8 +677,7 @@ fetch_indexed_string (dwarf_vma           idx,
   str_offset -= str_section->address;
   if (str_offset >= str_section->size)
     {
-      warn (_("indirect offset too big: 0x%s\n"),
-           dwarf_vmatoa ("x", str_offset));
+      warn (_("indirect offset too big: %#" PRIx64 "\n"), str_offset);
       return _("<indirect index offset is too big>");
     }
 
@@ -756,8 +693,8 @@ fetch_indexed_string (dwarf_vma           idx,
   return ret;
 }
 
-static dwarf_vma
-fetch_indexed_addr (dwarf_vma offset, uint32_t num_bytes)
+static uint64_t
+fetch_indexed_addr (uint64_t offset, uint32_t num_bytes)
 {
   struct dwarf_section *section = &debug_displays [debug_addr].section;
 
@@ -769,8 +706,8 @@ fetch_indexed_addr (dwarf_vma offset, uint32_t num_bytes)
 
   if (offset + num_bytes > section->size)
     {
-      warn (_("Offset into section %s too big: 0x%s\n"),
-           section->name, dwarf_vmatoa ("x", offset));
+      warn (_("Offset into section %s too big: %#" PRIx64 "\n"),
+           section->name, offset);
       return 0;
     }
 
@@ -779,19 +716,19 @@ fetch_indexed_addr (dwarf_vma offset, uint32_t num_bytes)
 
 /* Fetch a value from a debug section that has been indexed by
    something in another section (eg DW_FORM_loclistx or DW_FORM_rnglistx).
-   Returns 0 if the value could not be found.  */
+   Returns -1 if the value could not be found.  */
 
-static dwarf_vma
-fetch_indexed_value (dwarf_vma idx,
+static uint64_t
+fetch_indexed_value (uint64_t idx,
                     enum dwarf_section_display_enum sec_enum,
-                    dwarf_vma base_address)
+                    uint64_t base_address)
 {
   struct dwarf_section *section = &debug_displays [sec_enum].section;
 
   if (section->start == NULL)
     {
       warn (_("Unable to locate %s section\n"), section->uncompressed_name);
-      return 0;
+      return -1;
     }
 
   uint32_t pointer_size, bias;
@@ -806,8 +743,8 @@ fetch_indexed_value (dwarf_vma idx,
       pointer_size = 4;
       bias = 12;
     }
-  dwarf_vma offset = idx * pointer_size;
+
+  uint64_t offset = idx * pointer_size;
 
   /* Offsets are biased by the size of the section header
      or base address.  */
@@ -818,9 +755,9 @@ fetch_indexed_value (dwarf_vma idx,
 
   if (offset + pointer_size > section->size)
     {
-      warn (_("Offset into section %s too big: 0x%s\n"),
-           section->name, dwarf_vmatoa ("x", offset));
-      return 0;
+      warn (_("Offset into section %s too big: %#" PRIx64 "\n"),
+           section->name, offset);
+      return -1;
     }
 
   return byte_get (section->start + offset, pointer_size);
@@ -832,10 +769,10 @@ fetch_indexed_value (dwarf_vma idx,
 /* Records a single attribute in an abbrev.  */
 typedef struct abbrev_attr
 {
-  unsigned long          attribute;
-  unsigned long          form;
-  dwarf_signed_vma       implicit_const;
-  struct abbrev_attr *   next;
+  unsigned long attribute;
+  unsigned long form;
+  int64_t implicit_const;
+  struct abbrev_attr *next;
 }
 abbrev_attr;
 
@@ -856,8 +793,7 @@ typedef struct abbrev_list
 {
   abbrev_entry *        first_abbrev;
   abbrev_entry *        last_abbrev;
-  dwarf_vma             abbrev_base;
-  dwarf_vma             abbrev_offset;
+  unsigned char *       raw;
   struct abbrev_list *  next;
   unsigned char *       start_of_next_abbrevs;
 }
@@ -868,9 +804,9 @@ static struct abbrev_list * abbrev_lists = NULL;
 
 typedef struct abbrev_map
 {
-  dwarf_vma      start;
-  dwarf_vma      end;
-  abbrev_list *  list;
+  uint64_t start;
+  uint64_t end;
+  abbrev_list *list;
 } abbrev_map;
 
 /* Maps between CU offsets and abbrev sets.  */
@@ -882,8 +818,15 @@ static unsigned long  next_free_abbrev_map_entry = 0;
 #define ABBREV_MAP_ENTRIES_INCREMENT   8
 
 static void
-record_abbrev_list_for_cu (dwarf_vma start, dwarf_vma end, abbrev_list * list)
+record_abbrev_list_for_cu (uint64_t start, uint64_t end,
+                          abbrev_list *list, abbrev_list *free_list)
 {
+  if (free_list != NULL)
+    {
+      list->next = abbrev_lists;
+      abbrev_lists = list;
+    }
+
   if (cu_abbrev_map == NULL)
     {
       num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES;
@@ -901,63 +844,50 @@ record_abbrev_list_for_cu (dwarf_vma start, dwarf_vma end, abbrev_list * list)
   next_free_abbrev_map_entry ++;
 }
 
-static void
-free_all_abbrevs (void)
+static abbrev_list *
+free_abbrev_list (abbrev_list *list)
 {
-  abbrev_list *  list;
+  abbrev_entry *abbrv = list->first_abbrev;
 
-  for (list = abbrev_lists; list != NULL;)
+  while (abbrv)
     {
-      abbrev_list *   next = list->next;
-      abbrev_entry *  abbrv;
+      abbrev_attr *attr = abbrv->first_attr;
 
-      for (abbrv = list->first_abbrev; abbrv != NULL;)
+      while (attr)
        {
-         abbrev_entry *  next_abbrev = abbrv->next;
-         abbrev_attr *   attr;
-
-         for (attr = abbrv->first_attr; attr;)
-           {
-             abbrev_attr *next_attr = attr->next;
-
-             free (attr);
-             attr = next_attr;
-           }
-
-         free (abbrv);
-         abbrv = next_abbrev;
+         abbrev_attr *next_attr = attr->next;
+         free (attr);
+         attr = next_attr;
        }
 
-      free (list);
-      list = next;
+      abbrev_entry *next_abbrev = abbrv->next;
+      free (abbrv);
+      abbrv = next_abbrev;
     }
 
-  abbrev_lists = NULL;
+  abbrev_list *next = list->next;
+  free (list);
+  return next;
 }
 
-static abbrev_list *
-new_abbrev_list (dwarf_vma abbrev_base, dwarf_vma abbrev_offset)
+static void
+free_all_abbrevs (void)
 {
-  abbrev_list * list = (abbrev_list *) xcalloc (sizeof * list, 1);
-
-  list->abbrev_base = abbrev_base;
-  list->abbrev_offset = abbrev_offset;
+  while (abbrev_lists)
+    abbrev_lists = free_abbrev_list (abbrev_lists);
 
-  list->next = abbrev_lists;
-  abbrev_lists = list;
-
-  return list;
+  free (cu_abbrev_map);
+  cu_abbrev_map = NULL;
+  next_free_abbrev_map_entry = 0;
 }
 
 static abbrev_list *
-find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base,
-                                  dwarf_vma abbrev_offset)
+find_abbrev_list_by_raw_abbrev (unsigned char *raw)
 {
   abbrev_list * list;
 
   for (list = abbrev_lists; list != NULL; list = list->next)
-    if (list->abbrev_base == abbrev_base
-       && list->abbrev_offset == abbrev_offset)
+    if (list->raw == raw)
       return list;
 
   return NULL;
@@ -966,10 +896,10 @@ find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base,
 /* Find the abbreviation map for the CU that includes OFFSET.
    OFFSET is an absolute offset from the start of the .debug_info section.  */
 /* FIXME: This function is going to slow down readelf & objdump.
-   Consider using a better algorithm to mitigate this effect.  */
+   Not caching abbrevs is likely the answer.  */
 
 static  abbrev_map *
-find_abbrev_map_by_offset (dwarf_vma offset)
+find_abbrev_map_by_offset (uint64_t offset)
 {
   unsigned long i;
 
@@ -978,7 +908,7 @@ find_abbrev_map_by_offset (dwarf_vma offset)
        && cu_abbrev_map[i].end > offset)
       return cu_abbrev_map + i;
 
-  return NULL; 
+  return NULL;
 }
 
 static void
@@ -1009,10 +939,10 @@ add_abbrev (unsigned long  number,
 }
 
 static void
-add_abbrev_attr (unsigned long    attribute,
-                unsigned long    form,
-                dwarf_signed_vma implicit_const,
-                abbrev_list *    list)
+add_abbrev_attr (unsigned long attribute,
+                unsigned long form,
+                int64_t implicit_const,
+                abbrev_list *list)
 {
   abbrev_attr *attr;
 
@@ -1033,40 +963,19 @@ add_abbrev_attr (unsigned long    attribute,
   list->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.  */
+/* Return processed (partial) contents of a .debug_abbrev section.
+   Returns NULL on errors.  */
 
-static unsigned char *
+static abbrev_list *
 process_abbrev_set (struct dwarf_section *section,
-                   dwarf_vma abbrev_base,
-                   dwarf_vma abbrev_size,
-                   dwarf_vma abbrev_offset,
-                   abbrev_list *list)
+                   unsigned char *start,
+                   unsigned char *end)
 {
-  if (abbrev_base >= section->size
-      || abbrev_size > section->size - abbrev_base)
-    {
-      /* PR 17531: file:4bcd9ce9.  */
-      warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
-             "abbrev section size (%lx)\n"),
-             (unsigned long) (abbrev_base + abbrev_size),
-             (unsigned long) section->size);
-      return NULL;
-    }
-  if (abbrev_offset >= abbrev_size)
-    {
-      warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than "
-             "abbrev section size (%lx)\n"),
-           (unsigned long) abbrev_offset,
-           (unsigned long) abbrev_size);
-      return NULL;
-    }
+  abbrev_list *list = xmalloc (sizeof (*list));
+  list->first_abbrev = NULL;
+  list->last_abbrev = NULL;
+  list->raw = start;
 
-  unsigned char *start = section->start + abbrev_base;
-  unsigned char *end = start + abbrev_size;
-  start += abbrev_offset;
   while (start < end)
     {
       unsigned long entry;
@@ -1079,14 +988,19 @@ process_abbrev_set (struct dwarf_section *section,
       /* A single zero is supposed to end the set according
         to the standard.  If there's more, then signal that to
         the caller.  */
-      if (start == end)
-       return NULL;
-      if (entry == 0)
-       return start;
+      if (start == end || entry == 0)
+       {
+         list->next = NULL;
+         list->start_of_next_abbrevs = start != end ? start : NULL;
+         return list;
+       }
 
       READ_ULEB (tag, start, end);
       if (start == end)
-       return NULL;
+       {
+         free (list);
+         return NULL;
+       }
 
       children = *start++;
 
@@ -1096,7 +1010,7 @@ process_abbrev_set (struct dwarf_section *section,
        {
          unsigned long form;
          /* Initialize it due to a false compiler warning.  */
-         dwarf_signed_vma implicit_const = -1;
+         int64_t implicit_const = -1;
 
          READ_ULEB (attribute, start, end);
          if (start == end)
@@ -1119,24 +1033,78 @@ process_abbrev_set (struct dwarf_section *section,
     }
 
   /* Report the missing single zero which ends the section.  */
-  error (_(".debug_abbrev section not zero terminated\n"));
+  error (_("%s section not zero terminated\n"), section->name);
 
+  free (list);
   return NULL;
 }
 
+/* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE
+   plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE.
+   If FREE_LIST is non-NULL search the already decoded abbrevs on
+   abbrev_lists first and if found set *FREE_LIST to NULL.  If
+   searching doesn't find a matching abbrev, set *FREE_LIST to the
+   newly allocated list.  If FREE_LIST is NULL, no search is done and
+   the returned abbrev_list is always newly allocated.  */
+
+static abbrev_list *
+find_and_process_abbrev_set (struct dwarf_section *section,
+                            uint64_t abbrev_base,
+                            uint64_t abbrev_size,
+                            uint64_t abbrev_offset,
+                            abbrev_list **free_list)
+{
+  if (free_list)
+    *free_list = NULL;
+
+  if (abbrev_base >= section->size
+      || abbrev_size > section->size - abbrev_base)
+    {
+      /* PR 17531: file:4bcd9ce9.  */
+      warn (_("Debug info is corrupted, abbrev size (%#" PRIx64 ")"
+             " is larger than abbrev section size (%#" PRIx64 ")\n"),
+             abbrev_base + abbrev_size, section->size);
+      return NULL;
+    }
+  if (abbrev_offset >= abbrev_size)
+    {
+      warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64 ")"
+             " is larger than abbrev section size (%#" PRIx64 ")\n"),
+           abbrev_offset, abbrev_size);
+      return NULL;
+    }
+
+  unsigned char *start = section->start + abbrev_base + abbrev_offset;
+  unsigned char *end = section->start + abbrev_base + abbrev_size;
+  abbrev_list *list = NULL;
+  if (free_list)
+    list = find_abbrev_list_by_raw_abbrev (start);
+  if (list == NULL)
+    {
+      list = process_abbrev_set (section, start, end);
+      if (free_list)
+       *free_list = list;
+    }
+  return list;
+}
+
 static const char *
-get_TAG_name (unsigned long tag)
+get_TAG_name (uint64_t tag)
 {
-  const char *name = get_DW_TAG_name ((unsigned int) tag);
+  const char *name = NULL;
 
+  if ((unsigned int) tag == tag)
+    name = get_DW_TAG_name ((unsigned int) tag);
   if (name == NULL)
     {
       static char buffer[100];
 
       if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user)
-       snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag);
+       snprintf (buffer, sizeof (buffer),
+                 _("User TAG value: %#" PRIx64), tag);
       else
-       snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag);
+       snprintf (buffer, sizeof (buffer),
+                 _("Unknown TAG value: %#" PRIx64), tag);
       return buffer;
     }
 
@@ -1146,12 +1114,13 @@ get_TAG_name (unsigned long tag)
 static const char *
 get_FORM_name (unsigned long form)
 {
-  const char *name;
+  const char *name = NULL;
 
   if (form == 0)
     return "DW_FORM value: 0";
 
-  name = get_DW_FORM_name (form);
+  if ((unsigned int) form == form)
+    name = get_DW_FORM_name ((unsigned int) form);
   if (name == NULL)
     {
       static char buffer[100];
@@ -1166,8 +1135,10 @@ get_FORM_name (unsigned long form)
 static const char *
 get_IDX_name (unsigned long idx)
 {
-  const char *name = get_DW_IDX_name ((unsigned int) idx);
+  const char *name = NULL;
 
+  if ((unsigned int) idx == idx)
+    name = get_DW_IDX_name ((unsigned int) idx);
   if (name == NULL)
     {
       static char buffer[100];
@@ -1181,20 +1152,20 @@ get_IDX_name (unsigned long idx)
 
 static unsigned char *
 display_block (unsigned char *data,
-              dwarf_vma length,
+              uint64_t length,
               const unsigned char * const end, char delimiter)
 {
-  dwarf_vma maxlen;
+  size_t maxlen;
 
-  printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length));
+  printf (_("%c%" PRIu64 " byte block: "), delimiter, length);
   if (data > end)
     return (unsigned char *) end;
 
-  maxlen = (dwarf_vma) (end - data);
+  maxlen = end - data;
   length = length > maxlen ? maxlen : length;
 
   while (length --)
-    printf ("%lx ", (unsigned long) byte_get (data++, 1));
+    printf ("%" PRIx64 " ", byte_get (data++, 1));
 
   return data;
 }
@@ -1204,13 +1175,13 @@ decode_location_expression (unsigned char * data,
                            unsigned int pointer_size,
                            unsigned int offset_size,
                            int dwarf_version,
-                           dwarf_vma length,
-                           dwarf_vma cu_offset,
+                           uint64_t length,
+                           uint64_t cu_offset,
                            struct dwarf_section * section)
 {
   unsigned op;
-  dwarf_vma uvalue;
-  dwarf_signed_vma svalue;
+  uint64_t uvalue;
+  int64_t svalue;
   unsigned char *end = data + length;
   int need_frame_base = 0;
 
@@ -1222,54 +1193,50 @@ decode_location_expression (unsigned char * data,
        {
        case DW_OP_addr:
          SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
-         printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
+         printf ("DW_OP_addr: %" PRIx64, uvalue);
          break;
        case DW_OP_deref:
          printf ("DW_OP_deref");
          break;
        case DW_OP_const1u:
          SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
-         printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
+         printf ("DW_OP_const1u: %" PRIu64, uvalue);
          break;
        case DW_OP_const1s:
          SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
-         printf ("DW_OP_const1s: %ld", (long) svalue);
+         printf ("DW_OP_const1s: %" PRId64, svalue);
          break;
        case DW_OP_const2u:
          SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
-         printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
+         printf ("DW_OP_const2u: %" PRIu64, uvalue);
          break;
        case DW_OP_const2s:
          SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
-         printf ("DW_OP_const2s: %ld", (long) svalue);
+         printf ("DW_OP_const2s: %" PRId64, svalue);
          break;
        case DW_OP_const4u:
          SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
-         printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
+         printf ("DW_OP_const4u: %" PRIu64, uvalue);
          break;
        case DW_OP_const4s:
          SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
-         printf ("DW_OP_const4s: %ld", (long) svalue);
+         printf ("DW_OP_const4s: %" PRId64, svalue);
          break;
        case DW_OP_const8u:
-         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);
+         SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end);
+         printf ("DW_OP_const8u: %" PRIu64, uvalue);
          break;
        case DW_OP_const8s:
-         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);
+         SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 8, end);
+         printf ("DW_OP_const8s: %" PRId64, svalue);
          break;
        case DW_OP_constu:
          READ_ULEB (uvalue, data, end);
-         printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue));
+         printf ("DW_OP_constu: %" PRIu64, uvalue);
          break;
        case DW_OP_consts:
          READ_SLEB (svalue, data, end);
-         printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue));
+         printf ("DW_OP_consts: %" PRId64, svalue);
          break;
        case DW_OP_dup:
          printf ("DW_OP_dup");
@@ -1282,7 +1249,7 @@ decode_location_expression (unsigned char * data,
          break;
        case DW_OP_pick:
          SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
-         printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
+         printf ("DW_OP_pick: %" PRIu64, uvalue);
          break;
        case DW_OP_swap:
          printf ("DW_OP_swap");
@@ -1325,7 +1292,7 @@ decode_location_expression (unsigned char * data,
          break;
        case DW_OP_plus_uconst:
          READ_ULEB (uvalue, data, end);
-         printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue));
+         printf ("DW_OP_plus_uconst: %" PRIu64, uvalue);
          break;
        case DW_OP_shl:
          printf ("DW_OP_shl");
@@ -1341,7 +1308,7 @@ decode_location_expression (unsigned char * data,
          break;
        case DW_OP_bra:
          SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
-         printf ("DW_OP_bra: %ld", (long) svalue);
+         printf ("DW_OP_bra: %" PRId64, svalue);
          break;
        case DW_OP_eq:
          printf ("DW_OP_eq");
@@ -1363,7 +1330,7 @@ decode_location_expression (unsigned char * data,
          break;
        case DW_OP_skip:
          SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
-         printf ("DW_OP_skip: %ld", (long) svalue);
+         printf ("DW_OP_skip: %" PRId64, svalue);
          break;
 
        case DW_OP_lit0:
@@ -1470,38 +1437,37 @@ decode_location_expression (unsigned char * data,
        case DW_OP_breg30:
        case DW_OP_breg31:
          READ_SLEB (svalue, data, end);
-         printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0,
-                 regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue));
+         printf ("DW_OP_breg%d (%s): %" PRId64,
+                 op - DW_OP_breg0, regname (op - DW_OP_breg0, 1), svalue);
          break;
 
        case DW_OP_regx:
          READ_ULEB (uvalue, data, end);
-         printf ("DW_OP_regx: %s (%s)",
-                 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
+         printf ("DW_OP_regx: %" PRIu64 " (%s)",
+                 uvalue, regname (uvalue, 1));
          break;
        case DW_OP_fbreg:
          need_frame_base = 1;
          READ_SLEB (svalue, data, end);
-         printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue));
+         printf ("DW_OP_fbreg: %" PRId64, svalue);
          break;
        case DW_OP_bregx:
          READ_ULEB (uvalue, data, end);
          READ_SLEB (svalue, data, end);
-         printf ("DW_OP_bregx: %s (%s) %s",
-                 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
-                 dwarf_vmatoa ("d", svalue));
+         printf ("DW_OP_bregx: %" PRIu64 " (%s) %" PRId64,
+                 uvalue, regname (uvalue, 1), svalue);
          break;
        case DW_OP_piece:
          READ_ULEB (uvalue, data, end);
-         printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue));
+         printf ("DW_OP_piece: %" PRIu64, uvalue);
          break;
        case DW_OP_deref_size:
          SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
-         printf ("DW_OP_deref_size: %ld", (long) uvalue);
+         printf ("DW_OP_deref_size: %" PRIu64, uvalue);
          break;
        case DW_OP_xderef_size:
          SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
-         printf ("DW_OP_xderef_size: %ld", (long) uvalue);
+         printf ("DW_OP_xderef_size: %" PRIu64, uvalue);
          break;
        case DW_OP_nop:
          printf ("DW_OP_nop");
@@ -1515,15 +1481,13 @@ decode_location_expression (unsigned char * data,
          /* FIXME: Strictly speaking for 64-bit DWARF3 files
             this ought to be an 8-byte wide computation.  */
          SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
-         printf ("DW_OP_call2: <0x%s>",
-                 dwarf_vmatoa ("x", svalue + cu_offset));
+         printf ("DW_OP_call2: <%#" PRIx64 ">", svalue + cu_offset);
          break;
        case DW_OP_call4:
          /* FIXME: Strictly speaking for 64-bit DWARF3 files
             this ought to be an 8-byte wide computation.  */
          SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
-         printf ("DW_OP_call4: <0x%s>",
-                 dwarf_vmatoa ("x", svalue + cu_offset));
+         printf ("DW_OP_call4: <%#" PRIx64 ">", svalue + cu_offset);
          break;
        case DW_OP_call_ref:
          /* FIXME: Strictly speaking for 64-bit DWARF3 files
@@ -1542,7 +1506,7 @@ decode_location_expression (unsigned char * data,
            {
              SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
            }
-         printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
+         printf ("DW_OP_call_ref: <%#" PRIx64 ">", uvalue);
          break;
        case DW_OP_form_tls_address:
          printf ("DW_OP_form_tls_address");
@@ -1553,9 +1517,9 @@ decode_location_expression (unsigned char * data,
        case DW_OP_bit_piece:
          printf ("DW_OP_bit_piece: ");
          READ_ULEB (uvalue, data, end);
-         printf (_("size: %s "), dwarf_vmatoa ("u", uvalue));
+         printf (_("size: %" PRIu64 " "), uvalue);
          READ_ULEB (uvalue, data, end);
-         printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue));
+         printf (_("offset: %" PRIu64 " "), uvalue);
          break;
 
          /* DWARF 4 extensions.  */
@@ -1580,14 +1544,14 @@ decode_location_expression (unsigned char * data,
        case DW_OP_GNU_encoded_addr:
          {
            int encoding = 0;
-           dwarf_vma addr;
+           uint64_t addr;
 
            if (data < end)
              encoding = *data++;
            addr = get_encoded_value (&data, encoding, section, end);
 
            printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
-           print_dwarf_vma (addr, pointer_size);
+           print_hex_ns (addr, pointer_size);
          }
          break;
        case DW_OP_implicit_pointer:
@@ -1612,17 +1576,16 @@ decode_location_expression (unsigned char * data,
              SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
            }
          READ_SLEB (svalue, data, end);
-         printf ("%s: <0x%s> %s",
+         printf ("%s: <%#" PRIx64 "> %" PRId64,
                  (op == DW_OP_implicit_pointer
                   ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
-                 dwarf_vmatoa ("x", uvalue),
-                 dwarf_vmatoa ("d", svalue));
+                 uvalue, svalue);
          break;
        case DW_OP_entry_value:
        case DW_OP_GNU_entry_value:
          READ_ULEB (uvalue, data, end);
          /* PR 17531: file: 0cc9cd00.  */
-         if (uvalue > (dwarf_vma) (end - data))
+         if (uvalue > (size_t) (end - data))
            uvalue = end - data;
          printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value"
                                                    : "DW_OP_GNU_entry_value"));
@@ -1636,64 +1599,64 @@ decode_location_expression (unsigned char * data,
        case DW_OP_const_type:
        case DW_OP_GNU_const_type:
          READ_ULEB (uvalue, data, end);
-         printf ("%s: <0x%s> ",
+         printf ("%s: <%#" PRIx64 "> ",
                  (op == DW_OP_const_type ? "DW_OP_const_type"
                                          : "DW_OP_GNU_const_type"),
-                 dwarf_vmatoa ("x", cu_offset + uvalue));
+                 cu_offset + uvalue);
          SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
          data = display_block (data, uvalue, end, ' ');
          break;
        case DW_OP_regval_type:
        case DW_OP_GNU_regval_type:
          READ_ULEB (uvalue, data, end);
-         printf ("%s: %s (%s)",
+         printf ("%s: %" PRIu64 " (%s)",
                  (op == DW_OP_regval_type ? "DW_OP_regval_type"
                                           : "DW_OP_GNU_regval_type"),
-                 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
+                 uvalue, regname (uvalue, 1));
          READ_ULEB (uvalue, data, end);
-         printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
+         printf (" <%#" PRIx64 ">", cu_offset + uvalue);
          break;
        case DW_OP_deref_type:
        case DW_OP_GNU_deref_type:
          SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
-         printf ("%s: %ld",
+         printf ("%s: %" PRId64,
                  (op == DW_OP_deref_type ? "DW_OP_deref_type"
                                          : "DW_OP_GNU_deref_type"),
-                 (long) uvalue);
+                 uvalue);
          READ_ULEB (uvalue, data, end);
-         printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
+         printf (" <%#" PRIx64 ">", cu_offset + uvalue);
          break;
        case DW_OP_convert:
        case DW_OP_GNU_convert:
          READ_ULEB (uvalue, data, end);
-         printf ("%s <0x%s>",
+         printf ("%s <%#" PRIx64 ">",
                  (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
-                 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
+                 uvalue ? cu_offset + uvalue : uvalue);
          break;
        case DW_OP_reinterpret:
        case DW_OP_GNU_reinterpret:
          READ_ULEB (uvalue, data, end);
-         printf ("%s <0x%s>",
+         printf ("%s <%#" PRIx64 ">",
                  (op == DW_OP_reinterpret ? "DW_OP_reinterpret"
                                           : "DW_OP_GNU_reinterpret"),
-                 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
+                 uvalue ? cu_offset + uvalue : uvalue);
          break;
        case DW_OP_GNU_parameter_ref:
          SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
-         printf ("DW_OP_GNU_parameter_ref: <0x%s>",
-                 dwarf_vmatoa ("x", cu_offset + uvalue));
+         printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64 ">",
+                 cu_offset + uvalue);
          break;
        case DW_OP_addrx:
          READ_ULEB (uvalue, data, end);
-         printf ("DW_OP_addrx <0x%s>", dwarf_vmatoa ("x", uvalue));
+         printf ("DW_OP_addrx <%#" PRIx64 ">", uvalue);
          break;
        case DW_OP_GNU_addr_index:
          READ_ULEB (uvalue, data, end);
-         printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
+         printf ("DW_OP_GNU_addr_index <%#" PRIx64 ">", uvalue);
          break;
        case DW_OP_GNU_const_index:
          READ_ULEB (uvalue, data, end);
-         printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
+         printf ("DW_OP_GNU_const_index <%#" PRIx64 ">", uvalue);
          break;
        case DW_OP_GNU_variable_value:
          /* FIXME: Strictly speaking for 64-bit DWARF3 files
@@ -1712,7 +1675,7 @@ decode_location_expression (unsigned char * data,
            {
              SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
            }
-         printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue));
+         printf ("DW_OP_GNU_variable_value: <%#" PRIx64 ">", uvalue);
          break;
 
          /* HP extensions.  */
@@ -1753,9 +1716,9 @@ decode_location_expression (unsigned char * data,
        default:
          if (op >= DW_OP_lo_user
              && op <= DW_OP_hi_user)
-           printf (_("(User defined location op 0x%x)"), op);
+           printf (_("(User defined location op %#x)"), op);
          else
-           printf (_("(Unknown location op 0x%x)"), op);
+           printf (_("(Unknown location op %#x)"), op);
          /* No way to tell where the next op is, so just bail.  */
          return need_frame_base;
        }
@@ -1772,7 +1735,7 @@ decode_location_expression (unsigned char * data,
    This is used for DWARF package files.  */
 
 static struct cu_tu_set *
-find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
+find_cu_tu_set_v2 (uint64_t cu_offset, int do_types)
 {
   struct cu_tu_set *p;
   unsigned int nsets;
@@ -1801,7 +1764,7 @@ find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
 }
 
 static const char *
-fetch_alt_indirect_string (dwarf_vma offset)
+fetch_alt_indirect_string (uint64_t offset)
 {
   separate_info * i;
 
@@ -1838,11 +1801,11 @@ fetch_alt_indirect_string (dwarf_vma offset)
       return ret;
     }
 
-  warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
-       dwarf_vmatoa ("x", offset));
+  warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64 ")"
+         " too big or no string sections available\n"), offset);
   return _("<offset is too big>");
 }
-       
+
 static const char *
 get_AT_name (unsigned long attribute)
 {
@@ -1870,7 +1833,7 @@ get_AT_name (unsigned long attribute)
 }
 
 static void
-add_dwo_info (const char * value, dwarf_vma cu_offset, dwo_type type)
+add_dwo_info (const char * value, uint64_t cu_offset, dwo_type type)
 {
   dwo_info * dwinfo = xmalloc (sizeof * dwinfo);
 
@@ -1882,19 +1845,19 @@ add_dwo_info (const char * value, dwarf_vma cu_offset, dwo_type type)
 }
 
 static void
-add_dwo_name (const char * name, dwarf_vma cu_offset)
+add_dwo_name (const char * name, uint64_t cu_offset)
 {
   add_dwo_info (name, cu_offset, DWO_NAME);
 }
 
 static void
-add_dwo_dir (const char * dir, dwarf_vma cu_offset)
+add_dwo_dir (const char * dir, uint64_t cu_offset)
 {
   add_dwo_info (dir, cu_offset, DWO_DIR);
 }
 
 static void
-add_dwo_id (const char * id, dwarf_vma cu_offset)
+add_dwo_id (const char * id, uint64_t cu_offset)
 {
   add_dwo_info (id, cu_offset, DWO_ID);
 }
@@ -1916,18 +1879,18 @@ free_dwo_info (void)
 /* Ensure that START + UVALUE is less than END.
    Return an adjusted UVALUE if necessary to ensure this relationship.  */
 
-static inline dwarf_vma
-check_uvalue (const unsigned char * start,
-             dwarf_vma             uvalue,
-             const unsigned char * end)
+static inline uint64_t
+check_uvalue (const unsigned char *start,
+             uint64_t uvalue,
+             const unsigned char *end)
 {
-  dwarf_vma max_uvalue = end - start;
+  uint64_t max_uvalue = end - start;
 
   /* See PR 17512: file: 008-103549-0.001:0.1.
      and PR 24829 for examples of where these tests are triggered.  */
   if (uvalue > max_uvalue)
     {
-      warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
+      warn (_("Corrupt attribute block length: %#" PRIx64 "\n"), uvalue);
       uvalue = max_uvalue;
     }
 
@@ -1938,14 +1901,14 @@ static unsigned char *
 skip_attr_bytes (unsigned long form,
                 unsigned char *data,
                 unsigned char *end,
-                dwarf_vma pointer_size,
-                dwarf_vma offset_size,
+                uint64_t pointer_size,
+                uint64_t offset_size,
                 int dwarf_version,
-                dwarf_vma *value_return)
+                uint64_t *value_return)
 {
-  dwarf_signed_vma svalue;
-  dwarf_vma uvalue = 0;
-  dwarf_vma inc = 0;
+  int64_t svalue;
+  uint64_t uvalue = 0;
+  uint64_t inc = 0;
 
   * value_return = 0;
 
@@ -2069,7 +2032,7 @@ skip_attr_bytes (unsigned long form,
     }
 
   * value_return = uvalue;
-  if (inc <= (dwarf_vma) (end - data))
+  if (inc <= (size_t) (end - data))
     data += inc;
   else
     data = end;
@@ -2082,7 +2045,7 @@ skip_attr_bytes (unsigned long form,
 static abbrev_entry *
 get_type_abbrev_from_form (unsigned long form,
                           unsigned long uvalue,
-                          dwarf_vma cu_offset,
+                          uint64_t cu_offset,
                           unsigned char *cu_end,
                           const struct dwarf_section *section,
                           unsigned long *abbrev_num_return,
@@ -2109,8 +2072,9 @@ get_type_abbrev_from_form (unsigned long form,
     case DW_FORM_ref_addr:
       if (uvalue >= section->size)
        {
-         warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
-               uvalue, (long) section->size, section->name);
+         warn (_("Unable to resolve ref_addr form: uvalue %lx "
+                 "> section size %" PRIx64 " (%s)\n"),
+               uvalue, section->size, section->name);
          return NULL;
        }
       break;
@@ -2124,10 +2088,12 @@ get_type_abbrev_from_form (unsigned long form,
     case DW_FORM_ref4:
     case DW_FORM_ref8:
     case DW_FORM_ref_udata:
-      if (uvalue + cu_offset > (size_t) (cu_end - section->start))
+      if (uvalue + cu_offset < uvalue
+         || uvalue + cu_offset > (size_t) (cu_end - section->start))
        {
-         warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > CU size %lx\n"),
-               uvalue, (long) cu_offset, (long) (cu_end - section->start));
+         warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %" PRIx64
+                 " > CU size %tx\n"),
+               uvalue, cu_offset, cu_end - section->start);
          return NULL;
        }
       uvalue += cu_offset;
@@ -2161,7 +2127,7 @@ get_type_abbrev_from_form (unsigned long form,
       else
        *map_return = NULL;
     }
-       
+
   READ_ULEB (abbrev_number, data, section->start + section->size);
 
   for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next)
@@ -2189,9 +2155,9 @@ get_type_signedness (abbrev_entry *entry,
                     const struct dwarf_section *section,
                     unsigned char *data,
                     unsigned char *end,
-                    dwarf_vma cu_offset,
-                    dwarf_vma pointer_size,
-                    dwarf_vma offset_size,
+                    uint64_t cu_offset,
+                    uint64_t pointer_size,
+                    uint64_t offset_size,
                     int dwarf_version,
                     bool *is_signed,
                     unsigned int nesting)
@@ -2213,7 +2179,7 @@ get_type_signedness (abbrev_entry *entry,
        attr = attr->next)
     {
       unsigned char * orig_data = data;
-      dwarf_vma uvalue = 0;
+      uint64_t uvalue = 0;
 
       data = skip_attr_bytes (attr->form, data, end, pointer_size,
                              offset_size, dwarf_version, & uvalue);
@@ -2295,18 +2261,20 @@ read_and_print_leb128 (unsigned char *data,
                       bool is_signed)
 {
   int status;
-  dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status);
+  uint64_t val = read_leb128 (data, end, is_signed, bytes_read, &status);
   if (status != 0)
     report_leb_status (status);
+  else if (is_signed)
+    printf ("%" PRId64, val);
   else
-    printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val));
+    printf ("%" PRIu64, val);
 }
 
 static void
-display_discr_list (unsigned long          form,
-                   dwarf_vma              uvalue,
-                   unsigned char *        data,
-                   int                    level)
+display_discr_list (unsigned long form,
+                   uint64_t uvalue,
+                   unsigned char *data,
+                   int level)
 {
   unsigned char *end = data;
 
@@ -2385,26 +2353,26 @@ display_discr_list (unsigned long          form,
 }
 
 static unsigned char *
-read_and_display_attr_value (unsigned long           attribute,
-                            unsigned long           form,
-                            dwarf_signed_vma        implicit_const,
-                            unsigned char *         start,
-                            unsigned char *         data,
-                            unsigned char *         end,
-                            dwarf_vma               cu_offset,
-                            dwarf_vma               pointer_size,
-                            dwarf_vma               offset_size,
-                            int                     dwarf_version,
-                            debug_info *            debug_info_p,
-                            int                     do_loc,
-                            struct dwarf_section *  section,
-                            struct cu_tu_set *      this_set,
-                            char                    delimiter,
-                            int                     level)
-{
-  dwarf_signed_vma svalue;
-  dwarf_vma uvalue = 0;
-  dwarf_vma uvalue_hi = 0;
+read_and_display_attr_value (unsigned long attribute,
+                            unsigned long form,
+                            int64_t implicit_const,
+                            unsigned char *start,
+                            unsigned char *data,
+                            unsigned char *end,
+                            uint64_t cu_offset,
+                            uint64_t pointer_size,
+                            uint64_t offset_size,
+                            int dwarf_version,
+                            debug_info *debug_info_p,
+                            int do_loc,
+                            struct dwarf_section *section,
+                            struct cu_tu_set *this_set,
+                            char delimiter,
+                            int level)
+{
+  int64_t svalue;
+  uint64_t uvalue = 0;
+  uint64_t uvalue_hi = 0;
   unsigned char *block_start = NULL;
   unsigned char *orig_data = data;
 
@@ -2493,7 +2461,7 @@ read_and_display_attr_value (unsigned long           attribute,
       SAFE_BYTE_GET_AND_INC (uvalue_hi, data, 8, end);
       if (byte_get != byte_get_little_endian)
        {
-         dwarf_vma utmp = uvalue;
+         uint64_t utmp = uvalue;
          uvalue = uvalue_hi;
          uvalue_hi = utmp;
        }
@@ -2540,7 +2508,7 @@ read_and_display_attr_value (unsigned long           attribute,
     {
     case DW_FORM_ref_addr:
       if (!do_loc)
-       printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue));
+       printf ("%c<%#" PRIx64 ">", delimiter, uvalue);
       break;
 
     case DW_FORM_GNU_ref_alt:
@@ -2548,9 +2516,9 @@ read_and_display_attr_value (unsigned long           attribute,
        {
          if (do_wide)
            /* We have already printed the form name.  */
-           printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue));
+           printf ("%c<%#" PRIx64 ">", delimiter, uvalue);
          else
-           printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x", uvalue));
+           printf ("%c<alt %#" PRIx64 ">", delimiter, uvalue);
        }
       /* FIXME: Follow the reference...  */
       break;
@@ -2561,14 +2529,14 @@ read_and_display_attr_value (unsigned long           attribute,
     case DW_FORM_ref_sup4:
     case DW_FORM_ref_udata:
       if (!do_loc)
-       printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
+       printf ("%c<%#" PRIx64 ">", delimiter, uvalue + cu_offset);
       break;
 
     case DW_FORM_data4:
     case DW_FORM_addr:
     case DW_FORM_sec_offset:
       if (!do_loc)
-       printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue));
+       printf ("%c%#" PRIx64, delimiter, uvalue);
       break;
 
     case DW_FORM_flag_present:
@@ -2577,17 +2545,17 @@ read_and_display_attr_value (unsigned long           attribute,
     case DW_FORM_data2:
     case DW_FORM_sdata:
       if (!do_loc)
-       printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
+       printf ("%c%" PRId64, delimiter, uvalue);
       break;
 
     case DW_FORM_udata:
       if (!do_loc)
-       printf ("%c%s", delimiter, dwarf_vmatoa ("u", uvalue));
+       printf ("%c%" PRIu64, delimiter, uvalue);
       break;
 
     case DW_FORM_implicit_const:
       if (!do_loc)
-       printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
+       printf ("%c%" PRId64, delimiter, implicit_const);
       break;
 
     case DW_FORM_ref_sup8:
@@ -2595,18 +2563,21 @@ read_and_display_attr_value (unsigned long           attribute,
     case DW_FORM_data8:
       if (!do_loc)
        {
-         dwarf_vma utmp = uvalue;
+         uint64_t utmp = uvalue;
          if (form == DW_FORM_ref8)
            utmp += cu_offset;
-         printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", utmp));
+         printf ("%c%#" PRIx64, delimiter, utmp);
        }
       break;
 
     case DW_FORM_data16:
       if (!do_loc)
-       printf (" 0x%s%s",
-               uvalue_hi == 0 ? "" : dwarf_vmatoa ("x", uvalue_hi),
-               dwarf_vmatoa_1 ("x", uvalue, uvalue_hi == 0 ? 0 : 8));
+       {
+         if (uvalue_hi == 0)
+           printf (" %#" PRIx64, uvalue);
+         else
+           printf (" %#" PRIx64 "%016" PRIx64, uvalue_hi, uvalue);
+       }
       break;
 
     case DW_FORM_string:
@@ -2659,13 +2630,11 @@ read_and_display_attr_value (unsigned long           attribute,
        {
          if (do_wide)
            /* We have already displayed the form name.  */
-           printf (_("%c(offset: 0x%s): %s"), delimiter,
-                   dwarf_vmatoa ("x", uvalue),
-                   fetch_indirect_string (uvalue));
+           printf (_("%c(offset: %#" PRIx64 "): %s"),
+                   delimiter, uvalue, fetch_indirect_string (uvalue));
          else
-           printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
-                   dwarf_vmatoa ("x", uvalue),
-                   fetch_indirect_string (uvalue));
+           printf (_("%c(indirect string, offset: %#" PRIx64 "): %s"),
+                   delimiter, uvalue, fetch_indirect_string (uvalue));
        }
       break;
 
@@ -2674,13 +2643,11 @@ read_and_display_attr_value (unsigned long           attribute,
        {
          if (do_wide)
            /* We have already displayed the form name.  */
-           printf (_("%c(offset: 0x%s): %s"), delimiter,
-                   dwarf_vmatoa ("x", uvalue),
-                   fetch_indirect_line_string (uvalue));
+           printf (_("%c(offset: %#" PRIx64 "): %s"),
+                   delimiter, uvalue, fetch_indirect_line_string (uvalue));
          else
-           printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
-                   dwarf_vmatoa ("x", uvalue),
-                   fetch_indirect_line_string (uvalue));
+           printf (_("%c(indirect line string, offset: %#" PRIx64 "): %s"),
+                   delimiter, uvalue, fetch_indirect_line_string (uvalue));
        }
       break;
 
@@ -2700,11 +2667,11 @@ read_and_display_attr_value (unsigned long           attribute,
                                        debug_info_p ? debug_info_p->str_offsets_base : 0);
          if (do_wide)
            /* We have already displayed the form name.  */
-           printf (_("%c(offset: 0x%s): %s"), delimiter,
-                   dwarf_vmatoa ("x", uvalue), strng);
+           printf (_("%c(offset: %#" PRIx64 "): %s"),
+                   delimiter, uvalue, strng);
          else
-           printf (_("%c(indexed string: 0x%s): %s"), delimiter,
-                   dwarf_vmatoa ("x", uvalue), strng);
+           printf (_("%c(indexed string: %#" PRIx64 "): %s"),
+                   delimiter, uvalue, strng);
        }
       break;
 
@@ -2713,13 +2680,11 @@ read_and_display_attr_value (unsigned long           attribute,
        {
          if (do_wide)
            /* We have already displayed the form name.  */
-           printf (_("%c(offset: 0x%s) %s"), delimiter,
-                   dwarf_vmatoa ("x", uvalue),
-                   fetch_alt_indirect_string (uvalue));
+           printf (_("%c(offset: %#" PRIx64 ") %s"),
+                   delimiter, uvalue, fetch_alt_indirect_string (uvalue));
          else
-           printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter,
-                   dwarf_vmatoa ("x", uvalue),
-                   fetch_alt_indirect_string (uvalue));
+           printf (_("%c(alt indirect string, offset: %#" PRIx64 ") %s"),
+                   delimiter, uvalue, fetch_alt_indirect_string (uvalue));
        }
       break;
 
@@ -2729,8 +2694,8 @@ read_and_display_attr_value (unsigned long           attribute,
 
     case DW_FORM_ref_sig8:
       if (!do_loc)
-       printf ("%c%s: 0x%s", delimiter, do_wide ? "" : "signature",
-               dwarf_vmatoa ("x", uvalue));
+       printf ("%c%s: %#" PRIx64, delimiter, do_wide ? "" : "signature",
+               uvalue);
       break;
 
     case DW_FORM_GNU_addr_index:
@@ -2743,34 +2708,58 @@ read_and_display_attr_value (unsigned long           attribute,
     case DW_FORM_rnglistx:
       if (!do_loc)
        {
-         dwarf_vma base, index;
+         uint64_t base, idx;
+         const char *suffix = strrchr (section->name, '.');
+         bool dwo = suffix && strcmp (suffix, ".dwo") == 0;
 
          if (form == DW_FORM_loclistx)
            {
-             if (debug_info_p == NULL)
+             if (dwo)
                {
-                 index = fetch_indexed_value (uvalue, loclists, 0);
+                 idx = fetch_indexed_value (uvalue, loclists_dwo, 0);
+                 if (idx != (uint64_t) -1)
+                   idx += (offset_size == 8) ? 20 : 12;
+               }
+             else if (debug_info_p == NULL)
+               {
+                 idx = fetch_indexed_value (uvalue, loclists, 0);
                }
              else
                {
                  /* We want to compute:
-                      index = fetch_indexed_value (uvalue, loclists, debug_info_p->loclists_base);
-                      index += debug_info_p->loclists_base;
+                      idx = fetch_indexed_value (uvalue, loclists, debug_info_p->loclists_base);
+                      idx += debug_info_p->loclists_base;
                      Fortunately we already have that sum cached in the
                      loc_offsets array.  */
-                 index = debug_info_p->loc_offsets [uvalue];
+                 if (uvalue < debug_info_p->num_loc_offsets)
+                   idx = debug_info_p->loc_offsets [uvalue];
+                 else
+                   {
+                     warn (_("loc_offset %" PRIu64 " too big\n"), uvalue);
+                     idx = -1;
+                   }
                }
            }
          else if (form == DW_FORM_rnglistx)
            {
-             if (debug_info_p == NULL)
-               base = 0;
+             if (dwo)
+               {
+                 idx = fetch_indexed_value (uvalue, rnglists_dwo, 0);
+                 if (idx != (uint64_t) -1)
+                   idx += (offset_size == 8) ? 20 : 12;
+               }
              else
-               base = debug_info_p->rnglists_base;
-             /* We do not have a cached value this time, so we perform the
-                computation manually.  */
-             index = fetch_indexed_value (uvalue, rnglists, base);
-             index += base;
+               {
+                 if (debug_info_p == NULL)
+                   base = 0;
+                 else
+                   base = debug_info_p->rnglists_base;
+                 /* We do not have a cached value this time, so we perform the
+                    computation manually.  */
+                 idx = fetch_indexed_value (uvalue, rnglists, base);
+                 if (idx != (uint64_t) -1)
+                   idx += base;
+               }
            }
          else
            {
@@ -2782,23 +2771,23 @@ read_and_display_attr_value (unsigned long           attribute,
                base = debug_info_p->addr_base;
 
              base += uvalue * pointer_size;
-             index = fetch_indexed_addr (base, pointer_size);
+             idx = fetch_indexed_addr (base, pointer_size);
            }
 
          /* We have already displayed the form name.  */
-         printf (_("%c(index: 0x%s): %s"), delimiter,
-                 dwarf_vmatoa ("x", uvalue),
-                 dwarf_vmatoa ("x", index));
+         if (idx != (uint64_t) -1)
+           printf (_("%c(index: %#" PRIx64 "): %#" PRIx64),
+                   delimiter, uvalue, idx);
        }
       break;
 
     case DW_FORM_strp_sup:
       if (!do_loc)
-       printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
+       printf ("%c<%#" PRIx64 ">", delimiter, uvalue + cu_offset);
       break;
-      
+
     default:
-      warn (_("Unrecognized form: 0x%lx\n"), form);
+      warn (_("Unrecognized form: %#lx\n"), form);
       /* What to do?  Consume a byte maybe?  */
       ++data;
       break;
@@ -2812,26 +2801,26 @@ read_and_display_attr_value (unsigned long           attribute,
        {
        case DW_AT_loclists_base:
          if (debug_info_p->loclists_base)
-           warn (_("CU @ 0x%s has multiple loclists_base values (0x%s and 0x%s)"),
-                 dwarf_vmatoa ("x", debug_info_p->cu_offset),
-                 dwarf_vmatoa ("x", debug_info_p->loclists_base),
-                 dwarf_vmatoa ("x", uvalue));
+           warn (_("CU @ %#" PRIx64 " has multiple loclists_base values "
+                   "(%#" PRIx64 " and %#" PRIx64 ")"),
+                 debug_info_p->cu_offset,
+                 debug_info_p->loclists_base, uvalue);
          debug_info_p->loclists_base = uvalue;
          break;
        case DW_AT_rnglists_base:
          if (debug_info_p->rnglists_base)
-           warn (_("CU @ 0x%s has multiple rnglists_base values (0x%s and 0x%s)"),
-                 dwarf_vmatoa ("x", debug_info_p->cu_offset),
-                 dwarf_vmatoa ("x", debug_info_p->rnglists_base),
-                 dwarf_vmatoa ("x", uvalue));
+           warn (_("CU @ %#" PRIx64 " has multiple rnglists_base values "
+                   "(%#" PRIx64 " and %#" PRIx64 ")"),
+                 debug_info_p->cu_offset,
+                 debug_info_p->rnglists_base, uvalue);
          debug_info_p->rnglists_base = uvalue;
          break;
        case DW_AT_str_offsets_base:
          if (debug_info_p->str_offsets_base)
-           warn (_("CU @ 0x%s has multiple str_offsets_base values (0x%s and 0x%s)"),
-                 dwarf_vmatoa ("x", debug_info_p->cu_offset),
-                 dwarf_vmatoa ("x", debug_info_p->str_offsets_base),
-                 dwarf_vmatoa ("x", uvalue));
+           warn (_("CU @ %#" PRIx64 " has multiple str_offsets_base values "
+                   "%#" PRIx64 " and %#" PRIx64 ")"),
+                 debug_info_p->cu_offset,
+                 debug_info_p->str_offsets_base, uvalue);
          debug_info_p->str_offsets_base = uvalue;
          break;
 
@@ -2867,10 +2856,10 @@ read_and_display_attr_value (unsigned long           attribute,
              if (lmax == 0 || num >= lmax)
                {
                  lmax += 1024;
-                 debug_info_p->loc_offsets = (dwarf_vma *)
+                 debug_info_p->loc_offsets = (uint64_t *)
                    xcrealloc (debug_info_p->loc_offsets,
                               lmax, sizeof (*debug_info_p->loc_offsets));
-                 debug_info_p->loc_views = (dwarf_vma *)
+                 debug_info_p->loc_views = (uint64_t *)
                    xcrealloc (debug_info_p->loc_views,
                               lmax, sizeof (*debug_info_p->loc_views));
                  debug_info_p->have_frame_base = (int *)
@@ -2941,7 +2930,7 @@ read_and_display_attr_value (unsigned long           attribute,
              if (lmax == 0 || num >= lmax)
                {
                  lmax += 1024;
-                 debug_info_p->range_lists = (dwarf_vma *)
+                 debug_info_p->range_lists = (uint64_t *)
                    xcrealloc (debug_info_p->range_lists,
                               lmax, sizeof (*debug_info_p->range_lists));
                  debug_info_p->max_range_lists = lmax;
@@ -2973,7 +2962,7 @@ read_and_display_attr_value (unsigned long           attribute,
              case DW_FORM_strx3:
              case DW_FORM_strx4:
                add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, false,
-                                                   debug_info_p->str_offsets_base),
+                                                   debug_info_p->str_offsets_base),
                              cu_offset);
                break;
              case DW_FORM_string:
@@ -3007,7 +2996,7 @@ read_and_display_attr_value (unsigned long           attribute,
              case DW_FORM_strx3:
              case DW_FORM_strx4:
                add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false,
-                                                  debug_info_p->str_offsets_base),
+                                                  debug_info_p->str_offsets_base),
                             cu_offset);
                break;
              case DW_FORM_string:
@@ -3088,8 +3077,8 @@ read_and_display_attr_value (unsigned long           attribute,
          printf (_("(declared as inline and inlined)"));
          break;
        default:
-         printf (_("  (Unknown inline attribute value: %s)"),
-                 dwarf_vmatoa ("x", uvalue));
+         printf (_("  (Unknown inline attribute value: %#" PRIx64 ")"),
+                 uvalue);
          break;
        }
       break;
@@ -3145,10 +3134,9 @@ read_and_display_attr_value (unsigned long           attribute,
        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)"),
-                   dwarf_vmatoa ("x", uvalue));
+           printf (_("(implementation defined: %#" PRIx64 ")"), uvalue);
          else
-           printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
+           printf (_("(unknown: %#" PRIx64 ")"), uvalue);
          break;
        }
       break;
@@ -3361,6 +3349,7 @@ read_and_display_attr_value (unsigned long           attribute,
     case DW_AT_stride:
     case DW_AT_upper_bound:
     case DW_AT_lower_bound:
+    case DW_AT_rank:
       if (block_start)
        {
          int need_frame_base;
@@ -3404,9 +3393,9 @@ read_and_display_attr_value (unsigned long           attribute,
        if (entry == NULL)
          {
            if (form != DW_FORM_GNU_ref_alt)
-             warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
-                   dwarf_vmatoa ("x", uvalue),
-                   (unsigned long) (orig_data - section->start));
+             warn (_("Offset %#" PRIx64 " used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"),
+                   uvalue,
+                   orig_data - section->start);
          }
        else
          {
@@ -3425,21 +3414,21 @@ read_and_display_attr_value (unsigned long           attribute,
 }
 
 static unsigned char *
-read_and_display_attr (unsigned long           attribute,
-                      unsigned long           form,
-                      dwarf_signed_vma        implicit_const,
-                      unsigned char *         start,
-                      unsigned char *         data,
-                      unsigned char *         end,
-                      dwarf_vma               cu_offset,
-                      dwarf_vma               pointer_size,
-                      dwarf_vma               offset_size,
-                      int                     dwarf_version,
-                      debug_info *            debug_info_p,
-                      int                     do_loc,
-                      struct dwarf_section *  section,
-                      struct cu_tu_set *      this_set,
-                      int                     level)
+read_and_display_attr (unsigned long attribute,
+                      unsigned long form,
+                      int64_t implicit_const,
+                      unsigned char *start,
+                      unsigned char *data,
+                      unsigned char *end,
+                      uint64_t cu_offset,
+                      uint64_t pointer_size,
+                      uint64_t offset_size,
+                      int dwarf_version,
+                      debug_info *debug_info_p,
+                      int do_loc,
+                      struct dwarf_section *section,
+                      struct cu_tu_set *this_set,
+                      int level)
 {
   if (!do_loc)
     printf ("   %-18s:", get_AT_name (attribute));
@@ -3520,6 +3509,21 @@ introduce (struct dwarf_section * section, bool raw)
     }
 }
 
+/* Free memory allocated for one unit in debug_information.  */
+
+static void
+free_debug_information (debug_info *ent)
+{
+  if (ent->max_loc_offsets)
+    {
+      free (ent->loc_offsets);
+      free (ent->loc_views);
+      free (ent->have_frame_base);
+    }
+  if (ent->max_range_lists)
+    free (ent->range_lists);
+}
+
 /* Process the contents of a .debug_info section.
    If do_loc is TRUE then we are scanning for location lists and dwo tags
    and we do not want to display anything to the user.
@@ -3548,7 +3552,7 @@ process_debug_info (struct dwarf_section * section,
   for (section_begin = start, num_units = 0; section_begin < end;
        num_units ++)
     {
-      dwarf_vma length;
+      uint64_t length;
 
       /* Read the first 4 bytes.  For a 32-bit DWARF section, this
         will be the length.  For a 64-bit DWARF section, it'll be
@@ -3559,8 +3563,8 @@ process_debug_info (struct dwarf_section * section,
        SAFE_BYTE_GET_AND_INC (length, section_begin, 8, end);
       else if (length >= 0xfffffff0 && length < 0xffffffff)
        {
-         warn (_("Reserved length value (0x%s) found in section %s\n"),
-               dwarf_vmatoa ("x", length), section->name);
+         warn (_("Reserved length value (%#" PRIx64 ") found in section %s\n"),
+               length, section->name);
          return false;
        }
 
@@ -3569,10 +3573,9 @@ process_debug_info (struct dwarf_section * section,
         relocations to an object file, or if the file is corrupt.  */
       if (length > (size_t) (end - section_begin))
        {
-         warn (_("Corrupt unit length (got 0x%s expected at most 0x%s) in section %s\n"),
-               dwarf_vmatoa ("x", length),
-               dwarf_vmatoa ("x", end - section_begin),
-               section->name);
+         warn (_("Corrupt unit length (got %#" PRIx64
+                 " expected at most %#tx) in section %s\n"),
+               length, end - section_begin, section->name);
          return false;
        }
       section_begin += length;
@@ -3623,7 +3626,9 @@ process_debug_info (struct dwarf_section * section,
   load_debug_section_with_follow (abbrev_sec, file);
   load_debug_section_with_follow (loclists, file);
   load_debug_section_with_follow (rnglists, file);
-  
+  load_debug_section_with_follow (loclists_dwo, file);
+  load_debug_section_with_follow (rnglists_dwo, file);
+
   if (debug_displays [abbrev_sec].section.start == NULL)
     {
       warn (_("Unable to locate %s section!\n"),
@@ -3635,24 +3640,20 @@ process_debug_info (struct dwarf_section * section,
     introduce (section, false);
 
   free_all_abbrevs ();
-  free (cu_abbrev_map);
-  cu_abbrev_map = NULL;
-  next_free_abbrev_map_entry = 0;
 
-  /* In order to be able to resolve DW_FORM_ref_attr forms we need
+  /* In order to be able to resolve DW_FORM_ref_addr forms we need
      to load *all* of the abbrevs for all CUs in this .debug_info
      section.  This does effectively mean that we (partially) read
      every CU header twice.  */
   for (section_begin = start; start < end;)
     {
-      DWARF2_Internal_CompUnit  compunit;
-      unsigned char *           hdrptr;
-      dwarf_vma                 abbrev_base;
-      size_t                    abbrev_size;
-      dwarf_vma                 cu_offset;
-      unsigned int              offset_size;
-      struct cu_tu_set *        this_set;
-      abbrev_list *             list;
+      DWARF2_Internal_CompUnit compunit;
+      unsigned char *hdrptr;
+      uint64_t abbrev_base;
+      size_t abbrev_size;
+      uint64_t cu_offset;
+      unsigned int offset_size;
+      struct cu_tu_set *this_set;
       unsigned char *end_cu;
 
       hdrptr = start;
@@ -3708,22 +3709,18 @@ process_debug_info (struct dwarf_section * section,
          abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
        }
 
-      list = find_abbrev_list_by_abbrev_offset (abbrev_base,
-                                               compunit.cu_abbrev_offset);
-      if (list == NULL)
-       {
-         unsigned char *  next;
-
-         list = new_abbrev_list (abbrev_base,
-                                 compunit.cu_abbrev_offset);
-         next = process_abbrev_set (&debug_displays[abbrev_sec].section,
-                                    abbrev_base, abbrev_size,
-                                    compunit.cu_abbrev_offset, list);
-         list->start_of_next_abbrevs = next;
-       }
-
+      abbrev_list *list;
+      abbrev_list *free_list;
+      list = find_and_process_abbrev_set (&debug_displays[abbrev_sec].section,
+                                         abbrev_base, abbrev_size,
+                                         compunit.cu_abbrev_offset,
+                                         &free_list);
       start = end_cu;
-      record_abbrev_list_for_cu (cu_offset, start - section_begin, list);
+      if (list != NULL && list->first_abbrev != NULL)
+       record_abbrev_list_for_cu (cu_offset, start - section_begin,
+                                  list, free_list);
+      else if (free_list != NULL)
+       free_abbrev_list (free_list);
     }
 
   for (start = section_begin, unit = 0; start < end; unit++)
@@ -3732,14 +3729,13 @@ process_debug_info (struct dwarf_section * section,
       unsigned char *hdrptr;
       unsigned char *tags;
       int level, last_level, saved_level;
-      dwarf_vma cu_offset;
+      uint64_t cu_offset;
       unsigned int offset_size;
-      dwarf_vma signature = 0;
-      dwarf_vma type_offset = 0;
+      uint64_t signature = 0;
+      uint64_t type_offset = 0;
       struct cu_tu_set *this_set;
-      dwarf_vma abbrev_base;
+      uint64_t abbrev_base;
       size_t abbrev_size;
-      abbrev_list * list = NULL;
       unsigned char *end_cu;
 
       hdrptr = start;
@@ -3824,33 +3820,22 @@ process_debug_info (struct dwarf_section * section,
          && alloc_num_debug_info_entries > unit
          && ! do_types)
        {
-         debug_information [unit].cu_offset = cu_offset;
-         debug_information [unit].pointer_size
-           = compunit.cu_pointer_size;
-         debug_information [unit].offset_size = offset_size;
-         debug_information [unit].dwarf_version = compunit.cu_version;
-         debug_information [unit].base_address = 0;
-         debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
-         debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
-         debug_information [unit].rnglists_base = 0;
-         debug_information [unit].loc_offsets = NULL;
-         debug_information [unit].have_frame_base = NULL;
-         debug_information [unit].max_loc_offsets = 0;
-         debug_information [unit].num_loc_offsets = 0;
-         debug_information [unit].loclists_base = 0;
-         debug_information [unit].range_lists = NULL;
-         debug_information [unit].max_range_lists= 0;
-         debug_information [unit].num_range_lists = 0;
-         debug_information [unit].rnglists_base = 0;
-         debug_information [unit].str_offsets_base = 0;
+         free_debug_information (&debug_information[unit]);
+         memset (&debug_information[unit], 0, sizeof (*debug_information));
+         debug_information[unit].pointer_size = compunit.cu_pointer_size;
+         debug_information[unit].offset_size = offset_size;
+         debug_information[unit].dwarf_version = compunit.cu_version;
+         debug_information[unit].cu_offset = cu_offset;
+         debug_information[unit].addr_base = DEBUG_INFO_UNAVAILABLE;
+         debug_information[unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
        }
 
       if (!do_loc && dwarf_start_die == 0)
        {
-         printf (_("  Compilation Unit @ offset 0x%s:\n"),
-                 dwarf_vmatoa ("x", cu_offset));
-         printf (_("   Length:        0x%s (%s)\n"),
-                 dwarf_vmatoa ("x", compunit.cu_length),
+         printf (_("  Compilation Unit @ offset %#" PRIx64 ":\n"),
+                 cu_offset);
+         printf (_("   Length:        %#" PRIx64 " (%s)\n"),
+                 compunit.cu_length,
                  offset_size == 8 ? "64-bit" : "32-bit");
          printf (_("   Version:       %d\n"), compunit.cu_version);
          if (compunit.cu_version >= 5)
@@ -3861,36 +3846,30 @@ process_debug_info (struct dwarf_section * section,
                      name ? name : "???",
                      compunit.cu_unit_type);
            }
-         printf (_("   Abbrev Offset: 0x%s\n"),
-                 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
+         printf (_("   Abbrev Offset: %#" PRIx64 "\n"),
+                 compunit.cu_abbrev_offset);
          printf (_("   Pointer Size:  %d\n"), compunit.cu_pointer_size);
          if (do_types)
            {
-             printf (_("   Signature:     0x%s\n"),
-                     dwarf_vmatoa ("x", signature));
-             printf (_("   Type Offset:   0x%s\n"),
-                     dwarf_vmatoa ("x", type_offset));
+             printf (_("   Signature:     %#" PRIx64 "\n"), signature);
+             printf (_("   Type Offset:   %#" PRIx64 "\n"), type_offset);
            }
          if (do_dwo_id)
-           printf (_("   DWO ID:        0x%s\n"), dwarf_vmatoa ("x", dwo_id));
+           printf (_("   DWO ID:        %#" PRIx64 "\n"), dwo_id);
          if (this_set != NULL)
            {
-             dwarf_vma *offsets = this_set->section_offsets;
+             uint64_t *offsets = this_set->section_offsets;
              size_t *sizes = this_set->section_sizes;
 
              printf (_("   Section contributions:\n"));
-             printf (_("    .debug_abbrev.dwo:       0x%s  0x%s\n"),
-                     dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
-                     dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
-             printf (_("    .debug_line.dwo:         0x%s  0x%s\n"),
-                     dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
-                     dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
-             printf (_("    .debug_loc.dwo:          0x%s  0x%s\n"),
-                     dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
-                     dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
-             printf (_("    .debug_str_offsets.dwo:  0x%s  0x%s\n"),
-                     dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
-                     dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
+             printf (_("    .debug_abbrev.dwo:       %#" PRIx64 "  %#zx\n"),
+                     offsets[DW_SECT_ABBREV], sizes[DW_SECT_ABBREV]);
+             printf (_("    .debug_line.dwo:         %#" PRIx64 "  %#zx\n"),
+                     offsets[DW_SECT_LINE], sizes[DW_SECT_LINE]);
+             printf (_("    .debug_loc.dwo:          %#" PRIx64 "  %#zx\n"),
+                     offsets[DW_SECT_LOC], sizes[DW_SECT_LOC]);
+             printf (_("    .debug_str_offsets.dwo:  %#" PRIx64 "  %#zx\n"),
+                     offsets[DW_SECT_STR_OFFSETS], sizes[DW_SECT_STR_OFFSETS]);
            }
        }
 
@@ -3899,9 +3878,9 @@ process_debug_info (struct dwarf_section * section,
 
       if (compunit.cu_version < 2 || compunit.cu_version > 5)
        {
-         warn (_("CU at offset %s contains corrupt or "
+         warn (_("CU at offset %#" PRIx64 " contains corrupt or "
                  "unsupported version number: %d.\n"),
-               dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
+               cu_offset, compunit.cu_version);
          continue;
        }
 
@@ -3911,27 +3890,17 @@ process_debug_info (struct dwarf_section * section,
          && compunit.cu_unit_type != DW_UT_split_compile
          && compunit.cu_unit_type != DW_UT_skeleton)
        {
-         warn (_("CU at offset %s contains corrupt or "
+         warn (_("CU at offset %#" PRIx64 " contains corrupt or "
                  "unsupported unit type: %d.\n"),
-               dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
+               cu_offset, compunit.cu_unit_type);
          continue;
        }
 
       /* Process the abbrevs used by this compilation unit.  */
-      list = find_abbrev_list_by_abbrev_offset (abbrev_base,
-                                               compunit.cu_abbrev_offset);
-      if (list == NULL)
-       {
-         unsigned char *next;
-
-         list = new_abbrev_list (abbrev_base,
-                                 compunit.cu_abbrev_offset);
-         next = process_abbrev_set (&debug_displays[abbrev_sec].section,
-                                    abbrev_base, abbrev_size,
-                                    compunit.cu_abbrev_offset, list);
-         list->start_of_next_abbrevs = next;
-       }
-
+      abbrev_list *list;
+      list = find_and_process_abbrev_set (&debug_displays[abbrev_sec].section,
+                                         abbrev_base, abbrev_size,
+                                         compunit.cu_abbrev_offset, NULL);
       level = 0;
       last_level = level;
       saved_level = -1;
@@ -4010,12 +3979,11 @@ process_debug_info (struct dwarf_section * section,
 
          /* Scan through the abbreviation list until we reach the
             correct entry.  */
-         if (list == NULL)
-           continue;
-
-         for (entry = list->first_abbrev; entry != NULL; entry = entry->next)
-           if (entry->number == abbrev_number)
-             break;
+         entry = NULL;
+         if (list != NULL)
+           for (entry = list->first_abbrev; entry != NULL; entry = entry->next)
+             if (entry->number == abbrev_number)
+               break;
 
          if (entry == NULL)
            {
@@ -4024,7 +3992,7 @@ process_debug_info (struct dwarf_section * section,
                  printf ("\n");
                  fflush (stdout);
                }
-             warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
+             warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"),
                    die_offset, abbrev_number);
              return false;
            }
@@ -4038,7 +4006,8 @@ process_debug_info (struct dwarf_section * section,
              need_base_address = 0;
              break;
            case DW_TAG_compile_unit:
-             need_base_address = 1;    
+           case DW_TAG_skeleton_unit:
+             need_base_address = 1;
              need_dwo_info = do_loc;
              break;
            case DW_TAG_entry_point:
@@ -4063,7 +4032,7 @@ process_debug_info (struct dwarf_section * section,
            {
              if (! do_loc && do_printing)
                /* Show the offset from where the tag was extracted.  */
-               printf ("    <%lx>", (unsigned long)(tags - section_begin));
+               printf ("    <%tx>", tags - section_begin);
              tags = read_and_display_attr (attr->attribute,
                                            attr->form,
                                            attr->implicit_const,
@@ -4088,7 +4057,7 @@ process_debug_info (struct dwarf_section * section,
            switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views)
              {
              case 1:
-               debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1;
+               debug_info_p->loc_views [debug_info_p->num_loc_views] = -1;
                debug_info_p->num_loc_views++;
                assert (debug_info_p->num_loc_views
                        == debug_info_p->num_loc_offsets);
@@ -4109,6 +4078,8 @@ process_debug_info (struct dwarf_section * section,
          if (entry->children)
            ++level;
        }
+      if (list != NULL)
+       free_abbrev_list (list);
     }
 
   /* Set num_debug_info_entries here so that it can be used to check if
@@ -4207,8 +4178,10 @@ read_debug_line_header (struct dwarf_section * section,
        }
       else
        {
-         warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
-               (long) linfo->li_length);
+         warn (_("The length field (%#" PRIx64 ")"
+                 " in the debug_line header is wrong"
+                 " - the section is too small\n"),
+               linfo->li_length);
          return NULL;
        }
     }
@@ -4276,7 +4249,7 @@ display_formatted_table (unsigned char *data,
                         bool is_dir)
 {
   unsigned char *format_start, format_count, *format, formati;
-  dwarf_vma data_count, datai;
+  uint64_t data_count, datai;
   unsigned int namepass, last_entry = 0;
   const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table");
 
@@ -4305,8 +4278,8 @@ display_formatted_table (unsigned char *data,
     }
   else if (data >= end)
     {
-      warn (_("%s: Corrupt entry count - expected %s but none found\n"),
-           table_name, dwarf_vmatoa ("x", data_count));
+      warn (_("%s: Corrupt entry count - expected %#" PRIx64
+             " but none found\n"), table_name, data_count);
       return data;
     }
 
@@ -4317,9 +4290,8 @@ display_formatted_table (unsigned char *data,
       return end;
     }
 
-  printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
-         table_name, (long) (data - start), dwarf_vmatoa ("u", data_count),
-         format_count);
+  printf (_("\n The %s (offset %#tx, lines %" PRIu64 ", columns %u):\n"),
+         table_name, data - start, data_count, format_count);
 
   printf (_("  Entry"));
   /* Delay displaying name as the last entry for better screen layout.  */
@@ -4328,7 +4300,7 @@ display_formatted_table (unsigned char *data,
       format = format_start;
       for (formati = 0; formati < format_count; formati++)
        {
-         dwarf_vma content_type;
+         uint64_t content_type;
 
          READ_ULEB (content_type, format, end);
          if ((content_type == DW_LNCT_path) == (namepass == 1))
@@ -4350,8 +4322,8 @@ display_formatted_table (unsigned char *data,
                printf (_("\tMD5\t\t\t"));
                break;
              default:
-               printf (_("\t(Unknown format content type %s)"),
-                       dwarf_vmatoa ("u", content_type));
+               printf (_("\t(Unknown format content type %" PRIu64 ")"),
+                       content_type);
              }
          SKIP_ULEB (format, end);
        }
@@ -4370,7 +4342,7 @@ display_formatted_table (unsigned char *data,
          data = datapass;
          for (formati = 0; formati < format_count; formati++)
            {
-             dwarf_vma content_type, form;
+             uint64_t content_type, form;
 
              READ_ULEB (content_type, format, end);
              READ_ULEB (form, format, end);
@@ -4404,7 +4376,7 @@ display_debug_sup (struct dwarf_section *  section,
   size_t sup_filename_len;
   unsigned int num_read;
   int status;
-  dwarf_vma checksum_len;
+  uint64_t checksum_len;
 
 
   introduce (section, true);
@@ -4421,7 +4393,7 @@ display_debug_sup (struct dwarf_section *  section,
 
   SAFE_BYTE_GET_AND_INC (is_supplementary, start, 1, end);
   if (is_supplementary != 0 && is_supplementary != 1)
-    warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));    
+    warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
 
   sup_filename = start;
   if (is_supplementary && sup_filename[0] != 0)
@@ -4442,21 +4414,22 @@ display_debug_sup (struct dwarf_section *  section,
       checksum_len = 0;
     }
   start += num_read;
-  if (checksum_len > (dwarf_vma) (end - start))
+  if (checksum_len > (size_t) (end - start))
     {
       error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
       checksum_len = end - start;
     }
-  else if (checksum_len < (dwarf_vma) (end - start))
+  else if (checksum_len < (size_t) (end - start))
     {
-      warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
-           (long) ((end - start) - checksum_len));
+      warn (_("corrupt .debug_sup section: there are %#" PRIx64
+             " extra, unused bytes at the end of the section\n"),
+           (end - start) - checksum_len);
     }
 
   printf (_("  Version:      %u\n"), version);
   printf (_("  Is Supp:      %u\n"), is_supplementary);
   printf (_("  Filename:     %s\n"), sup_filename);
-  printf (_("  Checksum Len: %lu\n"), (long) checksum_len);
+  printf (_("  Checksum Len: %" PRIu64 "\n"), checksum_len);
   if (checksum_len > 0)
     {
       printf (_("  Checksum:     "));
@@ -4520,8 +4493,8 @@ display_debug_lines_raw (struct dwarf_section *  section,
                                                & end_of_sequence)) == NULL)
            return 0;
 
-         printf (_("  Offset:                      0x%lx\n"), (long)(data - start));
-         printf (_("  Length:                      %ld\n"), (long) linfo.li_length);
+         printf (_("  Offset:                      %#tx\n"), data - start);
+         printf (_("  Length:                      %" PRId64 "\n"), linfo.li_length);
          printf (_("  DWARF Version:               %d\n"), linfo.li_version);
          if (linfo.li_version >= 5)
            {
@@ -4584,8 +4557,8 @@ display_debug_lines_raw (struct dwarf_section *  section,
                {
                  unsigned int last_dir_entry = 0;
 
-                 printf (_("\n The Directory Table (offset 0x%lx):\n"),
-                         (long)(data - start));
+                 printf (_("\n The Directory Table (offset %#tx):\n"),
+                         data - start);
 
                  while (data < end && *data != 0)
                    {
@@ -4610,14 +4583,14 @@ display_debug_lines_raw (struct dwarf_section *  section,
                printf (_("\n The File Name Table is empty.\n"));
              else
                {
-                 printf (_("\n The File Name Table (offset 0x%lx):\n"),
-                         (long)(data - start));
+                 printf (_("\n The File Name Table (offset %#tx):\n"),
+                         data - start);
                  printf (_("  Entry\tDir\tTime\tSize\tName\n"));
 
                  while (data < end && *data != 0)
                    {
                      unsigned char *name;
-                     dwarf_vma val;
+                     uint64_t val;
 
                      printf ("  %d\t", ++state_machine_regs.last_file_entry);
                      name = data;
@@ -4626,11 +4599,11 @@ display_debug_lines_raw (struct dwarf_section *  section,
                        data++;
 
                      READ_ULEB (val, data, end);
-                     printf ("%s\t", dwarf_vmatoa ("u", val));
+                     printf ("%" PRIu64 "\t", val);
                      READ_ULEB (val, data, end);
-                     printf ("%s\t", dwarf_vmatoa ("u", val));
+                     printf ("%" PRIu64 "\t", val);
                      READ_ULEB (val, data, end);
-                     printf ("%s\t", dwarf_vmatoa ("u", val));
+                     printf ("%" PRIu64 "\t", val);
                      printf ("%.*s\n", (int)(end - name), name);
 
                      if (data >= end)
@@ -4660,10 +4633,10 @@ display_debug_lines_raw (struct dwarf_section *  section,
          while (data < end_of_sequence)
            {
              unsigned char op_code;
-             dwarf_signed_vma adv;
-             dwarf_vma uladv;
+             int64_t adv;
+             uint64_t uladv;
 
-             printf ("  [0x%08lx]", (long)(data - start));
+             printf ("  [0x%08tx]", data - start);
 
              op_code = *data++;
 
@@ -4678,9 +4651,9 @@ display_debug_lines_raw (struct dwarf_section *  section,
                      if (uladv)
                        state_machine_regs.view = 0;
                      printf (_("  Special opcode %d: "
-                               "advance Address by %s to 0x%s%s"),
-                             op_code, dwarf_vmatoa ("u", uladv),
-                             dwarf_vmatoa ("x", state_machine_regs.address),
+                               "advance Address by %" PRIu64
+                               " to %#" PRIx64 "%s"),
+                             op_code, uladv, state_machine_regs.address,
                              verbose_view && uladv
                              ? _(" (reset view)") : "");
                    }
@@ -4698,17 +4671,17 @@ display_debug_lines_raw (struct dwarf_section *  section,
                      if (addrdelta)
                        state_machine_regs.view = 0;
                      printf (_("  Special opcode %d: "
-                               "advance Address by %s to 0x%s[%d]%s"),
-                             op_code, dwarf_vmatoa ("u", uladv),
-                             dwarf_vmatoa ("x", state_machine_regs.address),
+                               "advance Address by %" PRIu64
+                               " to %#" PRIx64 "[%d]%s"),
+                             op_code, uladv, state_machine_regs.address,
                              state_machine_regs.op_index,
                              verbose_view && addrdelta
                              ? _(" (reset view)") : "");
                    }
                  adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
                  state_machine_regs.line += adv;
-                 printf (_(" and Line by %s to %d"),
-                         dwarf_vmatoa ("d", adv), state_machine_regs.line);
+                 printf (_(" and Line by %" PRId64 " to %d"),
+                         adv, state_machine_regs.line);
                  if (verbose_view || state_machine_regs.view)
                    printf (_(" (view %u)\n"), state_machine_regs.view);
                  else
@@ -4741,9 +4714,9 @@ display_debug_lines_raw (struct dwarf_section *  section,
                        state_machine_regs.address += uladv;
                        if (uladv)
                          state_machine_regs.view = 0;
-                       printf (_("  Advance PC by %s to 0x%s%s\n"),
-                               dwarf_vmatoa ("u", uladv),
-                               dwarf_vmatoa ("x", state_machine_regs.address),
+                       printf (_("  Advance PC by %" PRIu64
+                                 " to %#" PRIx64 "%s\n"),
+                               uladv, state_machine_regs.address,
                                verbose_view && uladv
                                ? _(" (reset view)") : "");
                      }
@@ -4760,9 +4733,9 @@ display_debug_lines_raw (struct dwarf_section *  section,
                          % linfo.li_max_ops_per_insn;
                        if (addrdelta)
                          state_machine_regs.view = 0;
-                       printf (_("  Advance PC by %s to 0x%s[%d]%s\n"),
-                               dwarf_vmatoa ("u", uladv),
-                               dwarf_vmatoa ("x", state_machine_regs.address),
+                       printf (_("  Advance PC by %" PRIu64
+                                 " to %#" PRIx64 "[%d]%s\n"),
+                               uladv, state_machine_regs.address,
                                state_machine_regs.op_index,
                                verbose_view && addrdelta
                                ? _(" (reset view)") : "");
@@ -4772,29 +4745,27 @@ display_debug_lines_raw (struct dwarf_section *  section,
                  case DW_LNS_advance_line:
                    READ_SLEB (adv, data, end);
                    state_machine_regs.line += adv;
-                   printf (_("  Advance Line by %s to %d\n"),
-                           dwarf_vmatoa ("d", adv),
-                           state_machine_regs.line);
+                   printf (_("  Advance Line by %" PRId64 " to %d\n"),
+                           adv, state_machine_regs.line);
                    break;
 
                  case DW_LNS_set_file:
                    READ_ULEB (uladv, data, end);
-                   printf (_("  Set File Name to entry %s in the File Name Table\n"),
-                           dwarf_vmatoa ("u", uladv));
+                   printf (_("  Set File Name to entry %" PRIu64
+                             " in the File Name Table\n"), uladv);
                    state_machine_regs.file = uladv;
                    break;
 
                  case DW_LNS_set_column:
                    READ_ULEB (uladv, data, end);
-                   printf (_("  Set column to %s\n"),
-                           dwarf_vmatoa ("u", uladv));
+                   printf (_("  Set column to %" PRIu64 "\n"), uladv);
                    state_machine_regs.column = uladv;
                    break;
 
                  case DW_LNS_negate_stmt:
                    adv = state_machine_regs.is_stmt;
                    adv = ! adv;
-                   printf (_("  Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
+                   printf (_("  Set is_stmt to %" PRId64 "\n"), adv);
                    state_machine_regs.is_stmt = adv;
                    break;
 
@@ -4811,9 +4782,9 @@ display_debug_lines_raw (struct dwarf_section *  section,
                        state_machine_regs.address += uladv;
                        if (uladv)
                          state_machine_regs.view = 0;
-                       printf (_("  Advance PC by constant %s to 0x%s%s\n"),
-                               dwarf_vmatoa ("u", uladv),
-                               dwarf_vmatoa ("x", state_machine_regs.address),
+                       printf (_("  Advance PC by constant %" PRIu64
+                                 " to %#" PRIx64 "%s\n"),
+                               uladv, state_machine_regs.address,
                                verbose_view && uladv
                                ? _(" (reset view)") : "");
                      }
@@ -4830,9 +4801,9 @@ display_debug_lines_raw (struct dwarf_section *  section,
                          % linfo.li_max_ops_per_insn;
                        if (addrdelta)
                          state_machine_regs.view = 0;
-                       printf (_("  Advance PC by constant %s to 0x%s[%d]%s\n"),
-                               dwarf_vmatoa ("u", uladv),
-                               dwarf_vmatoa ("x", state_machine_regs.address),
+                       printf (_("  Advance PC by constant %" PRIu64
+                                 " to %#" PRIx64 "[%d]%s\n"),
+                               uladv, state_machine_regs.address,
                                state_machine_regs.op_index,
                                verbose_view && addrdelta
                                ? _(" (reset view)") : "");
@@ -4843,9 +4814,9 @@ display_debug_lines_raw (struct dwarf_section *  section,
                    SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
                    state_machine_regs.address += uladv;
                    state_machine_regs.op_index = 0;
-                   printf (_("  Advance PC by fixed size amount %s to 0x%s\n"),
-                           dwarf_vmatoa ("u", uladv),
-                           dwarf_vmatoa ("x", state_machine_regs.address));
+                   printf (_("  Advance PC by fixed size amount %" PRIu64
+                             " to %#" PRIx64 "\n"),
+                           uladv, state_machine_regs.address);
                    /* Do NOT reset view.  */
                    break;
 
@@ -4859,7 +4830,7 @@ display_debug_lines_raw (struct dwarf_section *  section,
 
                  case DW_LNS_set_isa:
                    READ_ULEB (uladv, data, end);
-                   printf (_("  Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
+                   printf (_("  Set ISA to %" PRIu64 "\n"), uladv);
                    break;
 
                  default:
@@ -4869,8 +4840,7 @@ display_debug_lines_raw (struct dwarf_section *  section,
                      for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
                        {
                          READ_ULEB (uladv, data, end);
-                         printf ("0x%s%s", dwarf_vmatoa ("x", uladv),
-                                 i == 1 ? "" : ", ");
+                         printf ("%#" PRIx64 "%s", uladv, i == 1 ? "" : ", ");
                        }
                    putchar ('\n');
                    break;
@@ -4914,7 +4884,7 @@ display_debug_lines_decoded (struct dwarf_section *  section,
       File_Entry *file_table = NULL;
       unsigned int n_files = 0;
       unsigned char **directory_table = NULL;
-      dwarf_vma n_directories = 0;
+      uint64_t n_directories = 0;
 
       if (startswith (section->name, ".debug_line.")
          /* Note: the following does not apply to .debug_line.dwo sections.
@@ -4965,7 +4935,7 @@ display_debug_lines_decoded (struct dwarf_section *  section,
          if (linfo.li_version >= 5)
            {
              unsigned char *format_start, format_count, *format;
-             dwarf_vma formati, entryi;
+             uint64_t formati, entryi;
 
              load_debug_section_with_follow (line_str, fileptr);
 
@@ -5001,8 +4971,8 @@ display_debug_lines_decoded (struct dwarf_section *  section,
                  format = format_start;
                  for (formati = 0; formati < format_count; formati++)
                    {
-                     dwarf_vma content_type, form;
-                     dwarf_vma uvalue;
+                     uint64_t content_type, form;
+                     uint64_t uvalue;
 
                      READ_ULEB (content_type, format, end);
                      READ_ULEB (form, format, end);
@@ -5075,8 +5045,8 @@ display_debug_lines_decoded (struct dwarf_section *  section,
                  format = format_start;
                  for (formati = 0; formati < format_count; formati++)
                    {
-                     dwarf_vma content_type, form;
-                     dwarf_vma uvalue;
+                     uint64_t content_type, form;
+                     uint64_t uvalue;
                      unsigned char *tmp;
 
                      READ_ULEB (content_type, format, end);
@@ -5241,10 +5211,12 @@ display_debug_lines_decoded (struct dwarf_section *  section,
                directory = _("<unknown>");
              else if (ix > n_directories)
                {
-                 warn (_("directory index %u > number of directories %s\n"),
-                       ix, dwarf_vmatoa ("u", n_directories));
+                 warn (_("directory index %u > number of directories %" PRIu64 "\n"),
+                       ix, n_directories);
                  directory = _("<corrupt>");
                }
+             else if (linfo.li_version >= 5)
+               directory = (char *) directory_table[ix];
              else
                directory = (char *) directory_table[ix - 1];
 
@@ -5415,6 +5387,7 @@ display_debug_lines_decoded (struct dwarf_section *  section,
 
                  if (linfo.li_version < 5)
                    --file;
+
                  if (file_table == NULL || n_files == 0)
                    printf (_("\n [Use file table entry %d]\n"), file);
                  /* PR 20439 */
@@ -5432,10 +5405,14 @@ display_debug_lines_decoded (struct dwarf_section *  section,
                  /* PR 20439 */
                  else if (dir > n_directories)
                    {
-                     warn (_("directory index %u > number of directories %s\n"),
-                           dir, dwarf_vmatoa ("u", n_directories));
+                     warn (_("directory index %u > number of directories %" PRIu64 "\n"),
+                           dir, n_directories);
                      printf (_("\n <over large directory table entry %u>\n"), dir);
                    }
+                 else if (linfo.li_version >= 5)
+                   printf ("\n%s/%s:\n",
+                           /* The directory index starts counting at 0.  */
+                           directory_table[dir], file_table[file].name);
                  else
                    printf ("\n%s/%s:\n",
                            /* The directory index starts counting at 1.  */
@@ -5507,11 +5484,10 @@ display_debug_lines_decoded (struct dwarf_section *  section,
                if (standard_opcodes != NULL)
                  for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
                    {
-                     dwarf_vma val;
+                     uint64_t val;
 
                      READ_ULEB (val, data, end);
-                     printf ("0x%s%s", dwarf_vmatoa ("x", val),
-                             i == 1 ? "" : ", ");
+                     printf ("%#" PRIx64 "%s", val, i == 1 ? "" : ", ");
                    }
                putchar ('\n');
                break;
@@ -5566,23 +5542,23 @@ display_debug_lines_decoded (struct dwarf_section *  section,
                  if (linfo.li_max_ops_per_insn == 1)
                    {
                      if (xop == -DW_LNE_end_sequence)
-                       printf ("%-35s  %11s  %#18" DWARF_VMA_FMT "x",
+                       printf ("%-35s  %11s  %#18" PRIx64,
                                newFileName, "-",
                                state_machine_regs.address);
                      else
-                       printf ("%-35s  %11d  %#18" DWARF_VMA_FMT "x",
+                       printf ("%-35s  %11d  %#18" PRIx64,
                                newFileName, state_machine_regs.line,
                                state_machine_regs.address);
                    }
                  else
                    {
                      if (xop == -DW_LNE_end_sequence)
-                       printf ("%-35s  %11s  %#18" DWARF_VMA_FMT "x[%d]",
+                       printf ("%-35s  %11s  %#18" PRIx64 "[%d]",
                                newFileName, "-",
                                state_machine_regs.address,
                                state_machine_regs.op_index);
                      else
-                       printf ("%-35s  %11d  %#18" DWARF_VMA_FMT "x[%d]",
+                       printf ("%-35s  %11d  %#18" PRIx64 "[%d]",
                                newFileName, state_machine_regs.line,
                                state_machine_regs.address,
                                state_machine_regs.op_index);
@@ -5593,23 +5569,23 @@ display_debug_lines_decoded (struct dwarf_section *  section,
                  if (linfo.li_max_ops_per_insn == 1)
                    {
                      if (xop == -DW_LNE_end_sequence)
-                       printf ("%s  %11s  %#18" DWARF_VMA_FMT "x",
+                       printf ("%s  %11s  %#18" PRIx64,
                                newFileName, "-",
                                state_machine_regs.address);
                      else
-                       printf ("%s  %11d  %#18" DWARF_VMA_FMT "x",
+                       printf ("%s  %11d  %#18" PRIx64,
                                newFileName, state_machine_regs.line,
                                state_machine_regs.address);
-                   }                   
+                   }
                  else
                    {
                      if (xop == -DW_LNE_end_sequence)
-                       printf ("%s  %11s  %#18" DWARF_VMA_FMT "x[%d]",
+                       printf ("%s  %11s  %#18" PRIx64 "[%d]",
                                newFileName, "-",
                                state_machine_regs.address,
                                state_machine_regs.op_index);
                      else
-                       printf ("%s  %11d  %#18" DWARF_VMA_FMT "x[%d]",
+                       printf ("%s  %11d  %#18" PRIx64 "[%d]",
                                newFileName, state_machine_regs.line,
                                state_machine_regs.address,
                                state_machine_regs.op_index);
@@ -5685,7 +5661,7 @@ display_debug_lines (struct dwarf_section *section, void *file)
 }
 
 static debug_info *
-find_debug_info_for_offset (dwarf_vma offset)
+find_debug_info_for_offset (uint64_t offset)
 {
   unsigned int i;
 
@@ -5750,10 +5726,9 @@ display_debug_pubnames_worker (struct dwarf_section *section,
 
       if (names.pn_length > (size_t) (end - start))
        {
-         warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
-               section->name,
-               sec_off,
-               dwarf_vmatoa ("x", names.pn_length));
+         warn (_("Debug info is corrupted, "
+                 "%s header at %#lx has length %#" PRIx64 "\n"),
+               section->name, sec_off, names.pn_length);
          break;
        }
 
@@ -5766,19 +5741,20 @@ display_debug_pubnames_worker (struct dwarf_section *section,
       if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
          && num_debug_info_entries > 0
          && find_debug_info_for_offset (names.pn_offset) == NULL)
-       warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
-             (unsigned long) names.pn_offset, section->name);
+       warn (_(".debug_info offset of %#" PRIx64
+               " in %s section does not point to a CU header.\n"),
+             names.pn_offset, section->name);
 
       SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, start);
 
-      printf (_("  Length:                              %ld\n"),
-             (long) names.pn_length);
+      printf (_("  Length:                              %" PRId64 "\n"),
+             names.pn_length);
       printf (_("  Version:                             %d\n"),
              names.pn_version);
-      printf (_("  Offset into .debug_info section:     0x%lx\n"),
-             (unsigned long) names.pn_offset);
-      printf (_("  Size of area in .debug_info section: %ld\n"),
-             (long) names.pn_size);
+      printf (_("  Offset into .debug_info section:     %#" PRIx64 "\n"),
+             names.pn_offset);
+      printf (_("  Size of area in .debug_info section: %" PRId64 "\n"),
+             names.pn_size);
 
       if (names.pn_version != 2 && names.pn_version != 3)
        {
@@ -5800,8 +5776,8 @@ display_debug_pubnames_worker (struct dwarf_section *section,
 
       while (1)
        {
-         bfd_size_type maxprint;
-         dwarf_vma offset;
+         size_t maxprint;
+         uint64_t offset;
 
          SAFE_BYTE_GET_AND_INC (offset, data, offset_size, start);
 
@@ -5829,13 +5805,13 @@ display_debug_pubnames_worker (struct dwarf_section *section,
              kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
              kind_name = get_gdb_index_symbol_kind_name (kind);
              is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
-             printf ("    %-6lx  %s,%-10s  %.*s\n",
-                     (unsigned long) offset, is_static ? _("s") : _("g"),
+             printf ("    %-6" PRIx64 "  %s,%-10s  %.*s\n",
+                     offset, is_static ? _("s") : _("g"),
                      kind_name, (int) maxprint, data);
            }
          else
-           printf ("    %-6lx\t%.*s\n",
-                   (unsigned long) offset, (int) maxprint, data);
+           printf ("    %-6" PRIx64 "\t%.*s\n",
+                   offset, (int) maxprint, data);
 
          data += strnlen ((char *) data, maxprint);
          if (data < start)
@@ -5941,15 +5917,15 @@ display_debug_macinfo (struct dwarf_section *section,
    FILEIDX.  Return NULL on failure.  */
 
 static unsigned char *
-get_line_filename_and_dirname (dwarf_vma line_offset,
-                              dwarf_vma fileidx,
+get_line_filename_and_dirname (uint64_t line_offset,
+                              uint64_t fileidx,
                               unsigned char **dir_name)
 {
   struct dwarf_section *section = &debug_displays [line].section;
   unsigned char *hdrptr, *dirtable, *file_name;
   unsigned int offset_size;
   unsigned int version, opcode_base;
-  dwarf_vma length, diridx;
+  uint64_t length, diridx;
   const unsigned char * end;
 
   *dir_name = NULL;
@@ -6054,7 +6030,7 @@ display_debug_macro (struct dwarf_section *section,
   load_debug_section_with_follow (str, file);
   load_debug_section_with_follow (line, file);
   load_debug_section_with_follow (str_index, file);
-  
+
   introduce (section, false);
 
   while (curr < end)
@@ -6062,7 +6038,7 @@ display_debug_macro (struct dwarf_section *section,
       unsigned int lineno, version, flags;
       unsigned int offset_size;
       const unsigned char *string;
-      dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
+      uint64_t line_offset = 0, sec_offset = curr - start, offset;
       unsigned char **extended_ops = NULL;
 
       SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
@@ -6075,20 +6051,19 @@ display_debug_macro (struct dwarf_section *section,
 
       SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
       offset_size = (flags & 1) ? 8 : 4;
-      printf (_("  Offset:                      0x%lx\n"),
-             (unsigned long) sec_offset);
+      printf (_("  Offset:                      %#" PRIx64 "\n"), sec_offset);
       printf (_("  Version:                     %d\n"), version);
       printf (_("  Offset size:                 %d\n"), offset_size);
       if (flags & 2)
        {
          SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
-         printf (_("  Offset into .debug_line:     0x%lx\n"),
-                 (unsigned long) line_offset);
+         printf (_("  Offset into .debug_line:     %#" PRIx64 "\n"),
+                 line_offset);
        }
       if (flags & 4)
        {
          unsigned int i, count, op;
-         dwarf_vma nargs, n;
+         uint64_t nargs, n;
 
          SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
 
@@ -6232,28 +6207,30 @@ display_debug_macro (struct dwarf_section *section,
 
            case DW_MACRO_import:
              SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
-             printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
-                     (unsigned long) offset);
+             printf (_(" DW_MACRO_import - offset : %#" PRIx64 "\n"),
+                     offset);
              break;
 
            case DW_MACRO_define_sup:
              READ_ULEB (lineno, curr, end);
              SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
-             printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
-                     lineno, (unsigned long) offset);
+             printf (_(" DW_MACRO_define_sup - lineno : %d"
+                       " macro offset : %#" PRIx64 "\n"),
+                     lineno, offset);
              break;
 
            case DW_MACRO_undef_sup:
              READ_ULEB (lineno, curr, end);
              SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
-             printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
-                     lineno, (unsigned long) offset);
+             printf (_(" DW_MACRO_undef_sup - lineno : %d"
+                       " macro offset : %#" PRIx64 "\n"),
+                     lineno, offset);
              break;
 
            case DW_MACRO_import_sup:
              SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
-             printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
-                     (unsigned long) offset);
+             printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64 "\n"),
+                     offset);
              break;
 
            case DW_MACRO_define_strx:
@@ -6267,7 +6244,7 @@ display_debug_macro (struct dwarf_section *section,
              else
                printf (" DW_MACRO_undef_strx ");
              if (do_wide)
-               printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset));
+               printf (_("(with offset %#" PRIx64 ") "), offset);
              printf (_("lineno : %d macro : %s\n"),
                      lineno, string);
              break;
@@ -6287,7 +6264,7 @@ display_debug_macro (struct dwarf_section *section,
              else
                {
                  /* Skip over unhandled opcodes.  */
-                 dwarf_vma nargs, n;
+                 uint64_t nargs, n;
                  unsigned char *desc = extended_ops[op];
                  READ_ULEB (nargs, desc, end);
                  if (nargs == 0)
@@ -6334,24 +6311,15 @@ display_debug_abbrev (struct dwarf_section *section,
 
   do
     {
-      abbrev_list *    list;
-      dwarf_vma        offset;
-
-      offset = start - section->start;
-      list = find_abbrev_list_by_abbrev_offset (0, offset);
+      uint64_t offset = start - section->start;
+      abbrev_list *list = find_and_process_abbrev_set (section, 0,
+                                                      section->size, offset,
+                                                      NULL);
       if (list == NULL)
-       {
-         list = new_abbrev_list (0, offset);
-         start = process_abbrev_set (section, 0, section->size, offset, list);
-         list->start_of_next_abbrevs = start;
-       }
-      else
-       start = list->start_of_next_abbrevs;
-
-      if (list->first_abbrev == NULL)
-       continue;
+       break;
 
-      printf (_("  Number TAG (0x%lx)\n"), (long) offset);
+      if (list->first_abbrev)
+       printf (_("  Number TAG (%#" PRIx64 ")\n"), offset);
 
       for (entry = list->first_abbrev; entry; entry = entry->next)
        {
@@ -6368,10 +6336,12 @@ display_debug_abbrev (struct dwarf_section *section,
                      get_AT_name (attr->attribute),
                      get_FORM_name (attr->form));
              if (attr->form == DW_FORM_implicit_const)
-               printf (": %s", dwarf_vmatoa ("d", attr->implicit_const));
+               printf (": %" PRId64, attr->implicit_const);
              putchar ('\n');
            }
        }
+      start = list->start_of_next_abbrevs;
+      free_abbrev_list (list);
     }
   while (start);
 
@@ -6384,9 +6354,9 @@ display_debug_abbrev (struct dwarf_section *section,
    POINTER_SIZE bytes long.  */
 
 static bool
-is_max_address (dwarf_vma addr, unsigned int pointer_size)
+is_max_address (uint64_t addr, unsigned int pointer_size)
 {
-  dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
+  uint64_t mask = ~(~(uint64_t) 0 << 1 << (pointer_size * 8 - 1));
   return ((addr & mask) == mask);
 }
 
@@ -6410,18 +6380,18 @@ display_view_pair_list (struct dwarf_section *section,
 
   while (vstart < section_end)
     {
-      dwarf_vma off = vstart - section->start;
-      dwarf_vma vbegin, vend;
+      uint64_t off = vstart - section->start;
+      uint64_t vbegin, vend;
 
       READ_ULEB (vbegin, vstart, section_end);
       if (vstart == section_end)
        break;
 
       READ_ULEB (vend, vstart, section_end);
-      printf ("    %8.8lx ", (unsigned long) off);
+      printf ("    %8.8" PRIx64 " ", off);
 
-      print_dwarf_view (vbegin, pointer_size, 1);
-      print_dwarf_view (vend, pointer_size, 1);
+      print_view (vbegin, pointer_size);
+      print_view (vend, pointer_size);
       printf (_("location view pair\n"));
     }
 
@@ -6435,19 +6405,19 @@ static void
 display_loc_list (struct dwarf_section *section,
                  unsigned char **start_ptr,
                  unsigned int debug_info_entry,
-                 dwarf_vma offset,
-                 dwarf_vma base_address,
+                 uint64_t offset,
+                 uint64_t base_address,
                  unsigned char **vstart_ptr,
                  int has_frame_base)
 {
   unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
   unsigned char *section_end = section->start + section->size;
-  dwarf_vma    cu_offset;
+  uint64_t cu_offset;
   unsigned int pointer_size;
   unsigned int offset_size;
   int dwarf_version;
-  dwarf_vma begin;
-  dwarf_vma end;
+  uint64_t begin;
+  uint64_t end;
   unsigned short length;
   int need_frame_base;
 
@@ -6472,18 +6442,18 @@ display_loc_list (struct dwarf_section *section,
 
   while (1)
     {
-      dwarf_vma off = offset + (start - *start_ptr);
-      dwarf_vma vbegin = vm1, vend = vm1;
+      uint64_t off = offset + (start - *start_ptr);
+      uint64_t vbegin = -1, vend = -1;
 
       if (2 * pointer_size > (size_t) (section_end - start))
        {
-         warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
-               (unsigned long) offset);
+         warn (_("Location list starting at offset %#" PRIx64
+                 " is not terminated.\n"), offset);
          break;
        }
 
       printf ("    ");
-      print_dwarf_vma (off, 4);
+      print_hex (off, 4);
 
       SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
       SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
@@ -6506,11 +6476,11 @@ display_loc_list (struct dwarf_section *section,
 
       /* Check base address specifiers.  */
       if (is_max_address (begin, pointer_size)
-          && !is_max_address (end, pointer_size))
+         && !is_max_address (end, pointer_size))
        {
          base_address = end;
-         print_dwarf_vma (begin, pointer_size);
-         print_dwarf_vma (end, pointer_size);
+         print_hex (begin, pointer_size);
+         print_hex (end, pointer_size);
          printf (_("(base address)\n"));
          continue;
        }
@@ -6520,19 +6490,18 @@ display_loc_list (struct dwarf_section *section,
          off = offset + (vstart - *start_ptr);
 
          READ_ULEB (vbegin, vstart, section_end);
-         print_dwarf_view (vbegin, pointer_size, 1);
+         print_view (vbegin, pointer_size);
 
          READ_ULEB (vend, vstart, section_end);
-         print_dwarf_view (vend, pointer_size, 1);
+         print_view (vend, pointer_size);
 
-         printf (_("views at %8.8lx for:\n    %*s "),
-                 (unsigned long) off, 8, "");
+         printf (_("views at %8.8" PRIx64 " for:\n    %*s "), off, 8, "");
        }
 
       if (2 > (size_t) (section_end - start))
        {
-         warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
-               (unsigned long) offset);
+         warn (_("Location list starting at offset %#" PRIx64
+                 " is not terminated.\n"), offset);
          break;
        }
 
@@ -6540,13 +6509,13 @@ display_loc_list (struct dwarf_section *section,
 
       if (length > (size_t) (section_end - start))
        {
-         warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
-               (unsigned long) offset);
+         warn (_("Location list starting at offset %#" PRIx64
+                 " is not terminated.\n"), offset);
          break;
        }
 
-      print_dwarf_vma (begin + base_address, pointer_size);
-      print_dwarf_vma (end + base_address, pointer_size);
+      print_hex (begin + base_address, pointer_size);
+      print_hex (end + base_address, pointer_size);
 
       putchar ('(');
       need_frame_base = decode_location_expression (start,
@@ -6580,23 +6549,23 @@ static void
 display_loclists_list (struct dwarf_section *  section,
                       unsigned char **        start_ptr,
                       unsigned int            debug_info_entry,
-                      dwarf_vma               offset,
-                      dwarf_vma               base_address,
+                      uint64_t                offset,
+                      uint64_t                base_address,
                       unsigned char **        vstart_ptr,
                       int                     has_frame_base)
 {
-  unsigned char *  start = *start_ptr;
-  unsigned char *  vstart = *vstart_ptr;
-  unsigned char *  section_end = section->start + section->size;
-  dwarf_vma        cu_offset;
-  unsigned int     pointer_size;
-  unsigned int     offset_size;
-  unsigned int     dwarf_version;
+  unsigned char *start = *start_ptr;
+  unsigned char *vstart = *vstart_ptr;
+  unsigned char *section_end = section->start + section->size;
+  uint64_t cu_offset;
+  unsigned int pointer_size;
+  unsigned int offset_size;
+  unsigned int dwarf_version;
 
   /* Initialize it due to a false compiler warning.  */
-  dwarf_vma begin = -1, vbegin = -1;
-  dwarf_vma end = -1, vend = -1;
-  dwarf_vma length;
+  uint64_t begin = -1, vbegin = -1;
+  uint64_t end = -1, vend = -1;
+  uint64_t length;
   int need_frame_base;
 
   if (debug_info_entry >= num_debug_info_entries)
@@ -6621,18 +6590,18 @@ display_loclists_list (struct dwarf_section *  section,
 
   while (1)
     {
-      dwarf_vma off = offset + (start - *start_ptr);
+      uint64_t off = offset + (start - *start_ptr);
       enum dwarf_location_list_entry_type llet;
 
       if (start + 1 > section_end)
        {
-         warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
-               (unsigned long) offset);
+         warn (_("Location list starting at offset %#" PRIx64
+                 " is not terminated.\n"), offset);
          break;
        }
 
       printf ("    ");
-      print_dwarf_vma (off, 4);
+      print_hex (off, 4);
 
       SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
 
@@ -6643,13 +6612,12 @@ display_loclists_list (struct dwarf_section *  section,
          off = offset + (vstart - *start_ptr);
 
          READ_ULEB (vbegin, vstart, section_end);
-         print_dwarf_view (vbegin, pointer_size, 1);
+         print_view (vbegin, pointer_size);
 
          READ_ULEB (vend, vstart, section_end);
-         print_dwarf_view (vend, pointer_size, 1);
+         print_view (vend, pointer_size);
 
-         printf (_("views at %8.8lx for:\n    %*s "),
-                 (unsigned long) off, 8, "");
+         printf (_("views at %8.8" PRIx64 " for:\n    %*s "), off, 8, "");
        }
 
       switch (llet)
@@ -6660,10 +6628,10 @@ display_loclists_list (struct dwarf_section *  section,
 
        case DW_LLE_base_addressx:
          READ_ULEB (base_address, start, section_end);
-         print_dwarf_vma (base_address, pointer_size);
+         print_hex (base_address, pointer_size);
          printf (_("(index into .debug_addr) "));
          base_address = fetch_indexed_addr (base_address, pointer_size);
-         print_dwarf_vma (base_address, pointer_size);
+         print_hex (base_address, pointer_size);
          printf (_("(base address)\n"));
          break;
 
@@ -6684,7 +6652,7 @@ display_loclists_list (struct dwarf_section *  section,
        case DW_LLE_default_location:
          begin = end = 0;
          break;
-         
+
        case DW_LLE_offset_pair:
          READ_ULEB (begin, start, section_end);
          begin += base_address;
@@ -6695,7 +6663,7 @@ display_loclists_list (struct dwarf_section *  section,
        case DW_LLE_base_address:
          SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
                                 section_end);
-         print_dwarf_vma (base_address, pointer_size);
+         print_hex (base_address, pointer_size);
          printf (_("(base address)\n"));
          break;
 
@@ -6715,10 +6683,10 @@ display_loclists_list (struct dwarf_section *  section,
          if (vstart)
            printf (_("View pair entry in loclist with locviews attribute\n"));
          READ_ULEB (vbegin, start, section_end);
-         print_dwarf_view (vbegin, pointer_size, 1);
+         print_view (vbegin, pointer_size);
 
          READ_ULEB (vend, start, section_end);
-         print_dwarf_view (vend, pointer_size, 1);
+         print_view (vend, pointer_size);
 
          printf (_("views for:\n"));
          continue;
@@ -6738,21 +6706,21 @@ display_loclists_list (struct dwarf_section *  section,
 
       if (start == section_end)
        {
-         warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
-               (unsigned long) offset);
+         warn (_("Location list starting at offset %#" PRIx64
+                 " is not terminated.\n"), offset);
          break;
        }
       READ_ULEB (length, start, section_end);
 
       if (length > (size_t) (section_end - start))
        {
-         warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
-               (unsigned long) offset);
+         warn (_("Location list starting at offset %#" PRIx64
+                 " is not terminated.\n"), offset);
          break;
        }
 
-      print_dwarf_vma (begin, pointer_size);
-      print_dwarf_vma (end, pointer_size);
+      print_hex (begin, pointer_size);
+      print_hex (end, pointer_size);
 
       putchar ('(');
       need_frame_base = decode_location_expression (start,
@@ -6777,7 +6745,7 @@ display_loclists_list (struct dwarf_section *  section,
       vbegin = vend = -1;
     }
 
-  if (vbegin != vm1 || vend != vm1)
+  if (vbegin != (uint64_t) -1 || vend != (uint64_t) -1)
     printf (_("Trailing view pair not used in a range"));
 
   *start_ptr = start;
@@ -6803,13 +6771,13 @@ static void
 display_loc_list_dwo (struct dwarf_section *section,
                      unsigned char **start_ptr,
                      unsigned int debug_info_entry,
-                     dwarf_vma offset,
+                     uint64_t offset,
                      unsigned char **vstart_ptr,
                      int has_frame_base)
 {
   unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
   unsigned char *section_end = section->start + section->size;
-  dwarf_vma    cu_offset;
+  uint64_t cu_offset;
   unsigned int pointer_size;
   unsigned int offset_size;
   int dwarf_version;
@@ -6840,12 +6808,12 @@ display_loc_list_dwo (struct dwarf_section *section,
   while (1)
     {
       printf ("    ");
-      print_dwarf_vma (offset + (start - *start_ptr), 4);
+      print_hex (offset + (start - *start_ptr), 4);
 
       if (start >= section_end)
        {
-         warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
-               (unsigned long) offset);
+         warn (_("Location list starting at offset %#" PRIx64
+                 " is not terminated.\n"), offset);
          break;
        }
 
@@ -6861,17 +6829,16 @@ display_loc_list_dwo (struct dwarf_section *section,
          case 3:
          case 4:
            {
-             dwarf_vma view;
-             dwarf_vma off = offset + (vstart - *start_ptr);
+             uint64_t view;
+             uint64_t off = offset + (vstart - *start_ptr);
 
              READ_ULEB (view, vstart, section_end);
-             print_dwarf_view (view, 8, 1);
+             print_view (view, 8);
 
              READ_ULEB (view, vstart, section_end);
-             print_dwarf_view (view, 8, 1);
+             print_view (view, 8);
 
-             printf (_("views at %8.8lx for:\n    %*s "),
-                     (unsigned long) off, 8, "");
+             printf (_("views at %8.8" PRIx64 " for:\n    %*s "), off, 8, "");
 
            }
            break;
@@ -6917,16 +6884,16 @@ display_loc_list_dwo (struct dwarf_section *section,
 
       if (2 > (size_t) (section_end - start))
        {
-         warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
-               (unsigned long) offset);
+         warn (_("Location list starting at offset %#" PRIx64
+                 " is not terminated.\n"), offset);
          break;
        }
 
       SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
       if (length > (size_t) (section_end - start))
        {
-         warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
-               (unsigned long) offset);
+         warn (_("Location list starting at offset %#" PRIx64
+                 " is not terminated.\n"), offset);
          break;
        }
 
@@ -6954,13 +6921,13 @@ display_loc_list_dwo (struct dwarf_section *section,
 /* Sort array of indexes in ascending order of loc_offsets[idx] and
    loc_views.  */
 
-static dwarf_vma *loc_offsets, *loc_views;
+static uint64_t *loc_offsets, *loc_views;
 
 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];
+  uint64_t a = loc_offsets[*(const unsigned int *) ap];
+  uint64_t b = loc_offsets[*(const unsigned int *) bp];
 
   int ret = (a > b) - (b > a);
   if (ret)
@@ -6980,19 +6947,19 @@ display_offset_entry_loclists (struct dwarf_section *section)
   unsigned char *  start = section->start;
   unsigned char * const end = start + section->size;
 
-  introduce (section, false);  
+  introduce (section, false);
 
   do
     {
-      dwarf_vma        length;
-      unsigned short   version;
-      unsigned char    address_size;
-      unsigned char    segment_selector_size;
-      uint32_t         offset_entry_count;
-      uint32_t         i;
-      bool             is_64bit;
+      uint64_t length;
+      unsigned short version;
+      unsigned char address_size;
+      unsigned char segment_selector_size;
+      uint32_t offset_entry_count;
+      uint32_t i;
+      bool is_64bit;
 
-      printf (_("Table at Offset 0x%lx\n"), (long)(start - section->start));
+      printf (_("Table at Offset %#tx\n"), start - section->start);
 
       SAFE_BYTE_GET_AND_INC (length, start, 4, end);
       if (length == 0xffffffff)
@@ -7008,7 +6975,7 @@ display_offset_entry_loclists (struct dwarf_section *section)
       SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, end);
       SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, end);
 
-      printf (_("  Length:          0x%s\n"), dwarf_vmatoa ("x", length));
+      printf (_("  Length:          %#" PRIx64 "\n"), length);
       printf (_("  DWARF version:   %u\n"), version);
       printf (_("  Address size:    %u\n"), address_size);
       printf (_("  Segment size:    %u\n"), segment_selector_size);
@@ -7029,36 +6996,23 @@ display_offset_entry_loclists (struct dwarf_section *section)
                section->name, segment_selector_size);
          return 0;
        }
-      
+
       if (offset_entry_count == 0)
        {
          warn (_("The %s section contains a table without offset\n"),
                section->name);
          return 0;
        }
-  
-      printf (_("\n   Offset Entries starting at 0x%lx:\n"),
-             (long)(start - section->start));
 
-      if (is_64bit)
-       {
-         for (i = 0; i < offset_entry_count; i++)
-           {
-             dwarf_vma entry;
+      printf (_("\n   Offset Entries starting at %#tx:\n"),
+             start - section->start);
 
-             SAFE_BYTE_GET_AND_INC (entry, start, 8, end);
-             printf (_("    [%6u] 0x%s\n"), i, dwarf_vmatoa ("x", entry));
-           }
-       }
-      else
+      for (i = 0; i < offset_entry_count; i++)
        {
-         for (i = 0; i < offset_entry_count; i++)
-           {
-             uint32_t entry;
+         uint64_t entry;
 
-             SAFE_BYTE_GET_AND_INC (entry, start, 4, end);
-             printf (_("    [%6u] 0x%x\n"), i, entry);
-           }
+         SAFE_BYTE_GET_AND_INC (entry, start, is_64bit ? 8 : 4, end);
+         printf (_("    [%6u] %#" PRIx64 "\n"), i, entry);
        }
 
       putchar ('\n');
@@ -7067,11 +7021,11 @@ display_offset_entry_loclists (struct dwarf_section *section)
 
       for (j = 1, i = 0; i < offset_entry_count;)
        {
-         unsigned char  lle;
-         dwarf_vma      base_address = 0;
-         dwarf_vma      begin;
-         dwarf_vma      finish;
-         dwarf_vma      off = start - section->start;
+         unsigned char lle;
+         uint64_t base_address = 0;
+         uint64_t begin;
+         uint64_t finish;
+         uint64_t off = start - section->start;
 
          if (j != i)
            {
@@ -7080,7 +7034,7 @@ display_offset_entry_loclists (struct dwarf_section *section)
            }
 
          printf ("    ");
-         print_dwarf_vma (off, 4);
+         print_hex (off, 4);
 
          SAFE_BYTE_GET_AND_INC (lle, start, 1, end);
 
@@ -7093,10 +7047,10 @@ display_offset_entry_loclists (struct dwarf_section *section)
 
            case DW_LLE_base_addressx:
              READ_ULEB (base_address, start, end);
-             print_dwarf_vma (base_address, address_size);
+             print_hex (base_address, address_size);
              printf (_("(index into .debug_addr) "));
              base_address = fetch_indexed_addr (base_address, address_size);
-             print_dwarf_vma (base_address, address_size);
+             print_hex (base_address, address_size);
              printf (_("(base address)\n"));
              continue;
 
@@ -7127,7 +7081,7 @@ display_offset_entry_loclists (struct dwarf_section *section)
 
            case DW_LLE_base_address:
              SAFE_BYTE_GET_AND_INC (base_address, start, address_size, end);
-             print_dwarf_vma (base_address, address_size);
+             print_hex (base_address, address_size);
              printf (_("(base address)\n"));
              continue;
 
@@ -7149,30 +7103,29 @@ display_offset_entry_loclists (struct dwarf_section *section)
 
          if (start == end)
            {
-             warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
-                   (unsigned long) off);
+             warn (_("Location list starting at offset %#" PRIx64
+                     " is not terminated.\n"), off);
              break;
            }
 
-         print_dwarf_vma (begin, address_size);
-         print_dwarf_vma (finish, address_size);
+         print_hex (begin, address_size);
+         print_hex (finish, address_size);
 
          if (begin == finish)
-           fputs (_(" (start == end)"), stdout);
+           fputs (_("(start == end)"), stdout);
          else if (begin > finish)
-           fputs (_(" (start > end)"), stdout);
+           fputs (_("(start > end)"), stdout);
 
          /* Read the counted location descriptions.  */
          READ_ULEB (length, start, end);
 
          if (length > (size_t) (end - start))
            {
-             warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
-                   (unsigned long) off);
+             warn (_("Location list starting at offset %#" PRIx64
+                     " is not terminated.\n"), off);
              break;
            }
 
-         putchar (' ');
          (void) decode_location_expression (start, address_size, address_size,
                                             version, length, 0, section);
          start += length;
@@ -7190,11 +7143,11 @@ static int
 display_debug_loc (struct dwarf_section *section, void *file)
 {
   unsigned char *start = section->start, *vstart = NULL;
-  dwarf_vma bytes;
+  uint64_t bytes;
   unsigned char *section_begin = start;
   unsigned int num_loc_list = 0;
-  dwarf_vma last_offset = 0;
-  dwarf_vma last_view = 0;
+  uint64_t last_offset = 0;
+  uint64_t last_view = 0;
   unsigned int first = 0;
   unsigned int i;
   unsigned int j;
@@ -7205,7 +7158,7 @@ display_debug_loc (struct dwarf_section *section, void *file)
   const char *suffix = strrchr (section->name, '.');
   bool is_dwo = false;
   int is_loclists = strstr (section->name, "debug_loclists") != NULL;
-  dwarf_vma expected_start = 0;
+  uint64_t expected_start = 0;
 
   if (suffix && strcmp (suffix, ".dwo") == 0)
     is_dwo = true;
@@ -7221,7 +7174,7 @@ display_debug_loc (struct dwarf_section *section, void *file)
   if (is_loclists)
     {
       unsigned char *hdrptr = section_begin;
-      dwarf_vma ll_length;
+      uint64_t ll_length;
       unsigned short ll_version;
       unsigned char *end = section_begin + section->size;
       unsigned char address_size, segment_selector_size;
@@ -7314,10 +7267,10 @@ display_debug_loc (struct dwarf_section *section, void *file)
   if (debug_information [first].num_loc_offsets > 0
       && debug_information [first].loc_offsets [0] != expected_start
       && debug_information [first].loc_views [0] != expected_start)
-    warn (_("Location lists in %s section start at 0x%s rather than 0x%s\n"),
-         section->name,
-         dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]),
-         dwarf_vmatoa ("x", expected_start));
+    warn (_("Location lists in %s section start at %#" PRIx64
+           " rather than %#" PRIx64 "\n"),
+         section->name, debug_information [first].loc_offsets [0],
+         expected_start);
 
   if (!locs_sorted)
     array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
@@ -7332,8 +7285,8 @@ display_debug_loc (struct dwarf_section *section, void *file)
   seen_first_offset = 0;
   for (i = first; i < num_debug_info_entries; i++)
     {
-      dwarf_vma offset, voffset;
-      dwarf_vma base_address;
+      uint64_t offset, voffset;
+      uint64_t base_address;
       unsigned int k;
       int has_frame_base;
 
@@ -7363,7 +7316,7 @@ display_debug_loc (struct dwarf_section *section, void *file)
          offset = debug_information [i].loc_offsets [j];
          next = section_begin + offset;
          voffset = debug_information [i].loc_views [j];
-         if (voffset != vm1)
+         if (voffset != (uint64_t) -1)
            vnext = section_begin + voffset;
          else
            vnext = NULL;
@@ -7382,32 +7335,28 @@ display_debug_loc (struct dwarf_section *section, void *file)
          else
            {
              if (start < next)
-               warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
-                     (unsigned long) (start - section_begin),
-                     (unsigned long) offset,
-                     section->name);
+               warn (_("There is a hole [%#tx - %#" PRIx64 "]"
+                       " in %s section.\n"),
+                     start - section_begin, offset, section->name);
              else if (start > next)
-               warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
-                     (unsigned long) (start - section_begin),
-                     (unsigned long) offset,
-                     section->name);
+               warn (_("There is an overlap [%#tx - %#" PRIx64 "]"
+                       " in %s section.\n"),
+                     start - section_begin, offset, section->name);
            }
          start = next;
          vstart = vnext;
 
          if (offset >= bytes)
            {
-             warn (_("Offset 0x%lx is bigger than %s section size.\n"),
-                   (unsigned long) offset,
-                   section->name);
+             warn (_("Offset %#" PRIx64 " is bigger than %s section size.\n"),
+                   offset, section->name);
              continue;
            }
 
          if (vnext && voffset >= bytes)
            {
-             warn (_("View Offset 0x%lx is bigger than %s section size.\n"),
-                   (unsigned long) voffset,
-                   section->name);
+             warn (_("View Offset %#" PRIx64 " is bigger than %s section size.\n"),
+                   voffset, section->name);
              continue;
            }
 
@@ -7463,8 +7412,8 @@ display_debug_str (struct dwarf_section *section,
                   void *file ATTRIBUTE_UNUSED)
 {
   unsigned char *start = section->start;
-  dwarf_vma bytes = section->size;
-  dwarf_vma addr = section->address;
+  uint64_t bytes = section->size;
+  uint64_t addr = section->address;
 
   if (bytes == 0)
     {
@@ -7482,7 +7431,7 @@ display_debug_str (struct dwarf_section *section,
 
       lbytes = (bytes > 16 ? 16 : bytes);
 
-      printf ("  0x%8.8lx ", (unsigned long) addr);
+      printf ("  0x%8.8" PRIx64 " ", addr);
 
       for (j = 0; j < 16; j++)
        {
@@ -7552,11 +7501,11 @@ display_debug_aranges (struct dwarf_section *section,
       unsigned char *hdrptr;
       DWARF2_Internal_ARange arange;
       unsigned char *addr_ranges;
-      dwarf_vma length;
-      dwarf_vma address;
-      dwarf_vma     sec_off;
+      uint64_t length;
+      uint64_t address;
+      uint64_t sec_off;
       unsigned char address_size;
-      unsigned int  offset_size;
+      unsigned int offset_size;
       unsigned char *end_ranges;
 
       hdrptr = start;
@@ -7573,10 +7522,9 @@ display_debug_aranges (struct dwarf_section *section,
 
       if (arange.ar_length > (size_t) (end - hdrptr))
        {
-         warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
-               section->name,
-               (unsigned long) sec_off,
-               dwarf_vmatoa ("x", arange.ar_length));
+         warn (_("Debug info is corrupted, %s header at %#" PRIx64
+                 " has length %#" PRIx64 "\n"),
+               section->name, sec_off, arange.ar_length);
          break;
        }
       end_ranges = hdrptr + arange.ar_length;
@@ -7588,8 +7536,9 @@ display_debug_aranges (struct dwarf_section *section,
       if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
          && num_debug_info_entries > 0
          && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
-       warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
-             (unsigned long) arange.ar_info_offset, section->name);
+       warn (_(".debug_info offset of %#" PRIx64
+               " in %s section does not point to a CU header.\n"),
+             arange.ar_info_offset, section->name);
 
       SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end_ranges);
       SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end_ranges);
@@ -7605,11 +7554,10 @@ display_debug_aranges (struct dwarf_section *section,
          break;
        }
 
-      printf (_("  Length:                   %ld\n"),
-             (long) arange.ar_length);
+      printf (_("  Length:                   %" PRId64 "\n"), arange.ar_length);
       printf (_("  Version:                  %d\n"), arange.ar_version);
-      printf (_("  Offset into .debug_info:  0x%lx\n"),
-             (unsigned long) arange.ar_info_offset);
+      printf (_("  Offset into .debug_info:  %#" PRIx64 "\n"),
+             arange.ar_info_offset);
       printf (_("  Pointer Size:             %d\n"), arange.ar_pointer_size);
       printf (_("  Segment Size:             %d\n"), arange.ar_segment_size);
 
@@ -7650,8 +7598,8 @@ display_debug_aranges (struct dwarf_section *section,
          SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size,
                                 end_ranges);
          printf ("    ");
-         print_dwarf_vma (address, address_size);
-         print_dwarf_vma (length, address_size);
+         print_hex (address, address_size);
+         print_hex_ns (length, address_size);
          putchar ('\n');
        }
 
@@ -7712,8 +7660,9 @@ display_debug_addr (struct dwarf_section *section,
       {
        /* PR 17531: file: cf38d01b.  */
        if (debug_information[i].addr_base >= section->size)
-         warn (_("Corrupt address base (%lx) found in debug section %u\n"),
-               (unsigned long) debug_information[i].addr_base, i);
+         warn (_("Corrupt address base (%#" PRIx64 ")"
+                 " found in debug section %u\n"),
+               debug_information[i].addr_base, i);
        else
          debug_addr_info [count++] = debug_information + i;
       }
@@ -7729,23 +7678,23 @@ display_debug_addr (struct dwarf_section *section,
       unsigned int idx;
       unsigned int address_size = debug_addr_info [i]->pointer_size;
 
-      printf (_("  For compilation unit at offset 0x%s:\n"),
-             dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
+      printf (_("  For compilation unit at offset %#" PRIx64 ":\n"),
+             debug_addr_info [i]->cu_offset);
 
       printf (_("\tIndex\tAddress\n"));
       entry = section->start + debug_addr_info [i]->addr_base;
       if (debug_addr_info [i]->dwarf_version >= 5)
        {
-         size_t           header_size = entry - header;
-         unsigned char *  curr_header = header;
-         dwarf_vma        length;
-         int              version;
-         int              segment_selector_size;
+         size_t header_size = entry - header;
+         unsigned char *curr_header = header;
+         uint64_t length;
+         int version;
+         int segment_selector_size;
 
          if (header_size != 8 && header_size != 16)
            {
-             warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
-                   section->name, (long) header_size);
+             warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"),
+                   section->name, header_size);
              return 0;
            }
 
@@ -7769,9 +7718,9 @@ display_debug_addr (struct dwarf_section *section,
       idx = 0;
       while (entry < end)
        {
-         dwarf_vma base = byte_get (entry, address_size);
+         uint64_t base = byte_get (entry, address_size);
          printf (_("\t%d:\t"), idx);
-         print_dwarf_vma (base, address_size);
+         print_hex_ns (base, address_size);
          printf ("\n");
          entry += address_size;
          idx++;
@@ -7800,6 +7749,7 @@ display_debug_str_offsets (struct dwarf_section *section,
   unsigned char *start = section->start;
   unsigned char *end = start + section->size;
   unsigned char *curr = start;
+  uint64_t debug_str_offsets_hdr_len;
 
   const char *suffix = strrchr (section->name, '.');
   bool dwo = suffix && strcmp (suffix, ".dwo") == 0;
@@ -7813,8 +7763,8 @@ display_debug_str_offsets (struct dwarf_section *section,
 
   while (curr < end)
     {
-      dwarf_vma length;
-      dwarf_vma entry_length;
+      uint64_t length;
+      uint64_t entry_length;
 
       SAFE_BYTE_GET_AND_INC (length, curr, 4, end);
       /* FIXME: We assume that this means 64-bit DWARF is being used.  */
@@ -7822,9 +7772,13 @@ display_debug_str_offsets (struct dwarf_section *section,
        {
          SAFE_BYTE_GET_AND_INC (length, curr, 8, end);
          entry_length = 8;
+         debug_str_offsets_hdr_len = 16;
        }
       else
-       entry_length = 4;
+       {
+         entry_length = 4;
+         debug_str_offsets_hdr_len = 8;
+       }
 
       unsigned char *entries_end;
       if (length == 0)
@@ -7835,17 +7789,17 @@ display_debug_str_offsets (struct dwarf_section *section,
          curr   = section->start;
          entries_end = end;
 
-         printf (_("    Length: %#lx\n"), (unsigned long) length);
+         printf (_("    Length: %#" PRIx64 "\n"), length);
          printf (_("       Index   Offset [String]\n"));
        }
       else
        {
-         if (length <= (dwarf_vma) (end - curr))
+         if (length <= (size_t) (end - curr))
            entries_end = curr + length;
          else
            {
-             warn (_("Section %s is too small %#lx\n"),
-                   section->name, (unsigned long) section->size);
+             warn (_("Section %s is too small %#" PRIx64 "\n"),
+                   section->name, section->size);
              entries_end = end;
            }
 
@@ -7859,29 +7813,30 @@ display_debug_str_offsets (struct dwarf_section *section,
          if (padding != 0)
            warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding);
 
-         printf (_("    Length: %#lx\n"), (unsigned long) length);
-         printf (_("    Version: %#lx\n"), (unsigned long) version);
+         printf (_("    Length: %#" PRIx64 "\n"), length);
+         printf (_("    Version: %#x\n"), version);
          printf (_("       Index   Offset [String]\n"));
        }
 
       for (idx = 0; curr < entries_end; idx++)
        {
-         dwarf_vma offset;
+         uint64_t offset;
          const unsigned char * string;
 
-         if ((dwarf_vma) (entries_end - curr) < entry_length)
+         if ((size_t) (entries_end - curr) < entry_length)
            /* Not enough space to read one entry_length, give up.  */
            return 0;
 
          SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, entries_end);
          if (dwo)
            string = (const unsigned char *)
-             fetch_indexed_string (idx, NULL, entry_length, dwo, 0);
+             fetch_indexed_string (idx, NULL, entry_length, dwo, debug_str_offsets_hdr_len);
          else
            string = fetch_indirect_string (offset);
 
-         printf ("    %8lu %8s %s\n", idx, dwarf_vmatoa ("x", offset),
-                 string);
+         printf ("    %8lu ", idx);
+         print_hex (offset, entry_length);
+         printf (" %s\n", string);
        }
     }
 
@@ -7894,7 +7849,7 @@ display_debug_str_offsets (struct dwarf_section *section,
 struct range_entry
 {
   /* The debug_information[x].range_lists[y] value.  */
-  dwarf_vma ranges_offset;
+  uint64_t ranges_offset;
 
   /* Original debug_information to find parameters of the data.  */
   debug_info *debug_info_p;
@@ -7907,8 +7862,8 @@ range_entry_compar (const void *ap, const void *bp)
 {
   const struct range_entry *a_re = (const struct range_entry *) ap;
   const struct range_entry *b_re = (const struct range_entry *) bp;
-  const dwarf_vma a = a_re->ranges_offset;
-  const dwarf_vma b = b_re->ranges_offset;
+  const uint64_t a = a_re->ranges_offset;
+  const uint64_t b = b_re->ranges_offset;
 
   return (a > b) - (b > a);
 }
@@ -7917,13 +7872,13 @@ static void
 display_debug_ranges_list (unsigned char *  start,
                           unsigned char *  finish,
                           unsigned int     pointer_size,
-                          dwarf_vma        offset,
-                          dwarf_vma        base_address)
+                          uint64_t         offset,
+                          uint64_t         base_address)
 {
   while (start < finish)
     {
-      dwarf_vma begin;
-      dwarf_vma end;
+      uint64_t begin;
+      uint64_t end;
 
       SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
       if (start >= finish)
@@ -7931,7 +7886,7 @@ display_debug_ranges_list (unsigned char *  start,
       SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
 
       printf ("    ");
-      print_dwarf_vma (offset, 4);
+      print_hex (offset, 4);
 
       if (begin == 0 && end == 0)
        {
@@ -7944,19 +7899,19 @@ display_debug_ranges_list (unsigned char *  start,
          && !is_max_address (end, pointer_size))
        {
          base_address = end;
-         print_dwarf_vma (begin, pointer_size);
-         print_dwarf_vma (end, pointer_size);
+         print_hex (begin, pointer_size);
+         print_hex (end, pointer_size);
          printf ("(base address)\n");
          continue;
        }
 
-      print_dwarf_vma (begin + base_address, pointer_size);
-      print_dwarf_vma (end + base_address, pointer_size);
+      print_hex (begin + base_address, pointer_size);
+      print_hex_ns (end + base_address, pointer_size);
 
       if (begin == end)
-       fputs (_("(start == end)"), stdout);
+       fputs (_(" (start == end)"), stdout);
       else if (begin > end)
-       fputs (_("(start > end)"), stdout);
+       fputs (_(" (start > end)"), stdout);
 
       putchar ('\n');
     }
@@ -7966,8 +7921,8 @@ static unsigned char *
 display_debug_rnglists_list (unsigned char * start,
                             unsigned char * finish,
                             unsigned int    pointer_size,
-                            dwarf_vma       offset,
-                            dwarf_vma       base_address,
+                            uint64_t        offset,
+                            uint64_t        base_address,
                             unsigned int    offset_size)
 {
   unsigned char *next = start;
@@ -7980,20 +7935,20 @@ display_debug_rnglists_list (unsigned char * start,
 
   while (1)
     {
-      dwarf_vma off = offset + (start - next);
+      uint64_t off = offset + (start - next);
       enum dwarf_range_list_entry rlet;
       /* Initialize it due to a false compiler warning.  */
-      dwarf_vma begin = -1, length, end = -1;
+      uint64_t begin = -1, length, end = -1;
 
       if (start >= finish)
        {
-         warn (_("Range list starting at offset 0x%s is not terminated.\n"),
-               dwarf_vmatoa ("x", offset));
+         warn (_("Range list starting at offset %#" PRIx64
+                 " is not terminated.\n"), offset);
          break;
        }
 
       printf ("    ");
-      print_dwarf_vma (off, 4);
+      print_hex (off, 4);
 
       SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
 
@@ -8004,11 +7959,11 @@ display_debug_rnglists_list (unsigned char * start,
          break;
        case DW_RLE_base_addressx:
          READ_ULEB (base_address, start, finish);
-         print_dwarf_vma (base_address, pointer_size);
+         print_hex (base_address, pointer_size);
          printf (_("(base address index) "));
          base_address = fetch_indexed_addr ((base_address * pointer_size)
                                             + debug_addr_section_hdr_len, pointer_size);
-         print_dwarf_vma (base_address, pointer_size);
+         print_hex (base_address, pointer_size);
          printf (_("(base address)\n"));
          break;
        case DW_RLE_startx_endx:
@@ -8032,7 +7987,7 @@ display_debug_rnglists_list (unsigned char * start,
          break;
        case DW_RLE_base_address:
          SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
-         print_dwarf_vma (base_address, pointer_size);
+         print_hex (base_address, pointer_size);
          printf (_("(base address)\n"));
          break;
        case DW_RLE_start_end:
@@ -8062,13 +8017,13 @@ display_debug_rnglists_list (unsigned char * start,
          end += base_address;
        }
 
-      print_dwarf_vma (begin, pointer_size);
-      print_dwarf_vma (end, pointer_size);
+      print_hex (begin, pointer_size);
+      print_hex (end, pointer_size);
 
       if (begin == end)
-       fputs (_("(start == end)"), stdout);
+       fputs (_(" (start == end)"), stdout);
       else if (begin > end)
-       fputs (_("(start > end)"), stdout);
+       fputs (_(" (start > end)"), stdout);
 
       putchar ('\n');
     }
@@ -8079,21 +8034,21 @@ display_debug_rnglists_list (unsigned char * start,
 static int
 display_debug_rnglists (struct dwarf_section *section)
 {
-  unsigned char *       start = section->start;
-  unsigned char *       finish = start + section->size;
+  unsigned char *start = section->start;
+  unsigned char *finish = start + section->size;
 
   while (start < finish)
     {
-      unsigned char * table_start;
-      dwarf_vma       offset = start - section->start;
-      unsigned char * end;
-      dwarf_vma       initial_length;
-      unsigned char   segment_selector_size;
-      unsigned int    offset_entry_count;
-      unsigned int    i;
-      unsigned short  version;
-      unsigned char   address_size = 0;
-      unsigned char   offset_size;
+      unsigned char *table_start;
+      uint64_t offset = start - section->start;
+      unsigned char *end;
+      uint64_t initial_length;
+      unsigned char segment_selector_size;
+      unsigned int offset_entry_count;
+      unsigned int i;
+      unsigned short version;
+      unsigned char address_size = 0;
+      unsigned char offset_size;
 
       /* Get and check the length of the block.  */
       SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
@@ -8116,8 +8071,10 @@ display_debug_rnglists (struct dwarf_section *section)
            initial_length = finish - start;
          else
            {
-             warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
-                   (long) initial_length);
+             warn (_("The length field (%#" PRIx64
+                     ") in the debug_rnglists header is wrong"
+                     " - the section is too small\n"),
+                   initial_length);
              return 0;
            }
        }
@@ -8130,8 +8087,8 @@ display_debug_rnglists (struct dwarf_section *section)
       SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
       SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
 
-      printf (_(" Table at Offset: 0x%s:\n"), dwarf_vmatoa ("x", offset));
-      printf (_("  Length:          0x%s\n"), dwarf_vmatoa ("x", initial_length));
+      printf (_(" Table at Offset: %#" PRIx64 ":\n"), offset);
+      printf (_("  Length:          %#" PRIx64 "\n"), initial_length);
       printf (_("  DWARF version:   %u\n"), version);
       printf (_("  Address size:    %u\n"), address_size);
       printf (_("  Segment size:    %u\n"), segment_selector_size);
@@ -8157,26 +8114,15 @@ display_debug_rnglists (struct dwarf_section *section)
 
       if (offset_entry_count != 0)
        {
-         printf (_("\n   Offsets starting at 0x%lx:\n"), (long)(start - section->start));
-         if (offset_size == 8)
-           {
-             for (i = 0; i < offset_entry_count; i++)
-               {
-                 dwarf_vma entry;
+         printf (_("\n   Offsets starting at %#tx:\n"),
+                 start - section->start);
 
-                 SAFE_BYTE_GET_AND_INC (entry, start, 8, finish);
-                 printf (_("    [%6u] 0x%s\n"), i, dwarf_vmatoa ("x", entry));
-               }
-           }
-         else
+         for (i = 0; i < offset_entry_count; i++)
            {
-             for (i = 0; i < offset_entry_count; i++)
-               {
-                 uint32_t entry;
+             uint64_t entry;
 
-                 SAFE_BYTE_GET_AND_INC (entry, start, 4, finish);
-                 printf (_("    [%6u] 0x%x\n"), i, entry);
-               }
+             SAFE_BYTE_GET_AND_INC (entry, start, offset_size, finish);
+             printf (_("    [%6u] %#" PRIx64 "\n"), i, entry);
            }
        }
       else
@@ -8184,16 +8130,16 @@ display_debug_rnglists (struct dwarf_section *section)
 
       for (i = 0; i < offset_entry_count; i++)
        {
-         dwarf_vma indx = start - table_start;
+         uint64_t indx = start - table_start;
 
          offset = start - section->start;
-         printf (_("\n  Offset: %lx, Index: 0x%s\n"),
-                 (long) offset, dwarf_vmatoa ("x", indx));
+         printf (_("\n  Offset: %#" PRIx64 ", Index: %#" PRIx64 "\n"),
+                 offset, indx);
          printf (_("    Offset   Begin    End\n"));
          start = display_debug_rnglists_list
            (start, end, address_size, offset, 0, offset_size);
          if (start >= end)
-           break;        
+           break;
        }
 
       start = end;
@@ -8202,6 +8148,7 @@ display_debug_rnglists (struct dwarf_section *section)
        putchar ('\n');
     }
 
+  putchar ('\n');
   return 1;
 }
 
@@ -8209,18 +8156,18 @@ static int
 display_debug_ranges (struct dwarf_section *section,
                      void *file ATTRIBUTE_UNUSED)
 {
-  unsigned char *       start = section->start;
-  unsigned char *       last_start = start;
-  dwarf_vma             bytes = section->size;
-  unsigned char *       section_begin = start;
-  unsigned char *       finish = start + bytes;
-  unsigned int          num_range_list, i;
-  struct range_entry *  range_entries;
-  struct range_entry *  range_entry_fill;
-  int                   is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
+  unsigned char *start = section->start;
+  unsigned char *last_start = start;
+  uint64_t bytes = section->size;
+  unsigned char *section_begin = start;
+  unsigned char *finish = start + bytes;
+  unsigned int num_range_list, i;
+  struct range_entry *range_entries;
+  struct range_entry *range_entry_fill;
+  int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
   /* Initialize it due to a false compiler warning.  */
-  unsigned char         address_size = 0;
-  dwarf_vma             last_offset = 0;
+  unsigned char address_size = 0;
+  uint64_t last_offset = 0;
 
   if (bytes == 0)
     {
@@ -8273,8 +8220,8 @@ display_debug_ranges (struct dwarf_section *section,
         range_entry_compar);
 
   if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
-    warn (_("Range lists in %s section start at 0x%lx\n"),
-         section->name, (unsigned long) range_entries[0].ranges_offset);
+    warn (_("Range lists in %s section start at %#" PRIx64 "\n"),
+         section->name, range_entries[0].ranges_offset);
 
   putchar ('\n');
   printf (_("    Offset   Begin    End\n"));
@@ -8284,9 +8231,9 @@ display_debug_ranges (struct dwarf_section *section,
       struct range_entry *range_entry = &range_entries[i];
       debug_info *debug_info_p = range_entry->debug_info_p;
       unsigned int pointer_size;
-      dwarf_vma offset;
+      uint64_t offset;
       unsigned char *next;
-      dwarf_vma base_address;
+      uint64_t base_address;
 
       pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
       offset = range_entry->ranges_offset;
@@ -8295,42 +8242,40 @@ display_debug_ranges (struct dwarf_section *section,
       /* PR 17512: file: 001-101485-0.001:0.1.  */
       if (pointer_size < 2 || pointer_size > 8)
        {
-         warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
-               pointer_size, (unsigned long) offset);
+         warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64 "\n"),
+               pointer_size, offset);
          continue;
        }
 
       if (offset > (size_t) (finish - section_begin))
        {
-         warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
-               (unsigned long) offset, i);
+         warn (_("Corrupt offset (%#" PRIx64 ") in range entry %u\n"),
+               offset, i);
          continue;
        }
 
       next = section_begin + offset + debug_info_p->rnglists_base;
 
       /* If multiple DWARF entities reference the same range then we will
-         have multiple entries in the `range_entries' list for the same
-         offset.  Thanks to the sort above these will all be consecutive in
-         the `range_entries' list, so we can easily ignore duplicates
-         here.  */
+        have multiple entries in the `range_entries' list for the same
+        offset.  Thanks to the sort above these will all be consecutive in
+        the `range_entries' list, so we can easily ignore duplicates
+        here.  */
       if (i > 0 && last_offset == offset)
-        continue;
+       continue;
       last_offset = offset;
 
       if (dwarf_check != 0 && i > 0)
        {
          if (start < next)
-           warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
-                 (unsigned long) (start - section_begin),
-                 (unsigned long) (next - section_begin), section->name);
+           warn (_("There is a hole [%#tx - %#tx] in %s section.\n"),
+                 start - section_begin, next - section_begin, section->name);
          else if (start > next)
            {
              if (next == last_start)
                continue;
-             warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
-                   (unsigned long) (start - section_begin),
-                   (unsigned long) (next - section_begin), section->name);
+             warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"),
+                   start - section_begin, next - section_begin, section->name);
            }
        }
 
@@ -8358,10 +8303,10 @@ typedef struct Frame_Chunk
   char *augmentation;
   unsigned int code_factor;
   int data_factor;
-  dwarf_vma pc_begin;
-  dwarf_vma pc_range;
+  uint64_t pc_begin;
+  uint64_t pc_range;
   unsigned int cfa_reg;
-  dwarf_vma cfa_offset;
+  uint64_t cfa_offset;
   unsigned int ra;
   unsigned char fde_encoding;
   unsigned char cfa_exp;
@@ -8374,7 +8319,7 @@ typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int);
 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func;
 static const char *const *dwarf_regnames;
 static unsigned int dwarf_regnames_count;
-
+static bool is_aarch64;
 
 /* A marker for a col_type that means this column was never referenced
    in the frame info.  */
@@ -8493,6 +8438,12 @@ init_dwarf_regnames_iamcu (void)
   dwarf_regnames_lookup_func = regname_internal_by_table_only;
 }
 
+static const char *const DW_CFA_GNU_window_save_name[] =
+{
+  "DW_CFA_GNU_window_save",
+  "DW_CFA_AARCH64_negate_ra_state"
+};
+
 static const char *const dwarf_regnames_x86_64[] =
 {
   "rax", "rdx", "rcx", "rbx",
@@ -8559,6 +8510,7 @@ init_dwarf_regnames_aarch64 (void)
   dwarf_regnames = dwarf_regnames_aarch64;
   dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
   dwarf_regnames_lookup_func = regname_internal_by_table_only;
+  is_aarch64 = true;
 }
 
 static const char *const dwarf_regnames_s390[] =
@@ -8648,6 +8600,7 @@ void
 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine)
 {
   dwarf_regnames_lookup_func = NULL;
+  is_aarch64 = false;
 
   switch (e_machine)
     {
@@ -8690,6 +8643,7 @@ init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch,
                                          unsigned long mach)
 {
   dwarf_regnames_lookup_func = NULL;
+  is_aarch64 = false;
 
   switch (arch)
     {
@@ -8789,7 +8743,7 @@ frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_reg
       printf ("\n");
     }
 
-  print_dwarf_vma (fc->pc_begin, eh_addr_size);
+  print_hex (fc->pc_begin, eh_addr_size);
   if (fc->cfa_exp)
     strcpy (tmp, "exp");
   else
@@ -8838,12 +8792,12 @@ frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_reg
 static unsigned char *
 read_cie (unsigned char *start, unsigned char *end,
          Frame_Chunk **p_cie, int *p_version,
-         bfd_size_type *p_aug_len, unsigned char **p_aug)
+         uint64_t *p_aug_len, unsigned char **p_aug)
 {
   int version;
   Frame_Chunk *fc;
   unsigned char *augmentation_data = NULL;
-  bfd_size_type augmentation_data_len = 0;
+  uint64_t augmentation_data_len = 0;
 
   * p_cie = NULL;
   /* PR 17512: file: 001-228113-0.004.  */
@@ -8926,11 +8880,11 @@ read_cie (unsigned char *start, unsigned char *end,
       READ_ULEB (augmentation_data_len, start, end);
       augmentation_data = start;
       /* PR 17512: file: 11042-2589-0.004.  */
-      if (augmentation_data_len > (bfd_size_type) (end - start))
+      if (augmentation_data_len > (size_t) (end - start))
        {
-         warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
-               dwarf_vmatoa ("x", augmentation_data_len),
-               (unsigned long) (end - start));
+         warn (_("Augmentation data too long: %#" PRIx64
+                 ", expected at most %#tx\n"),
+               augmentation_data_len, end - start);
          goto fail;
        }
       start += augmentation_data_len;
@@ -8989,9 +8943,7 @@ read_cie (unsigned char *start, unsigned char *end,
    output line.  */
 
 static void
-display_data (bfd_size_type          printed,
-             const unsigned char *  data,
-             const bfd_size_type    len)
+display_data (size_t printed, const unsigned char *data, size_t len)
 {
   if (do_wide || len < ((80 - printed) / 3))
     for (printed = 0; printed < len; ++printed)
@@ -9011,9 +8963,9 @@ display_data (bfd_size_type          printed,
    If do_wide is not enabled, then formats the output to fit into 80 columns.  */
 
 static void
-display_augmentation_data (const unsigned char * data, const bfd_size_type len)
+display_augmentation_data (const unsigned char * data, uint64_t len)
 {
-  bfd_size_type i;
+  size_t i;
 
   i = printf (_("  Augmentation data:    "));
   display_data (i, data, len);
@@ -9040,13 +8992,13 @@ display_debug_frames (struct dwarf_section *section,
     {
       unsigned char *saved_start;
       unsigned char *block_end;
-      dwarf_vma length;
-      dwarf_vma cie_id;
+      uint64_t length;
+      uint64_t cie_id;
       Frame_Chunk *fc;
       Frame_Chunk *cie;
       int need_col_headers = 1;
       unsigned char *augmentation_data = NULL;
-      bfd_size_type augmentation_data_len = 0;
+      uint64_t augmentation_data_len = 0;
       unsigned int encoded_ptr_size = saved_eh_addr_size;
       unsigned int offset_size;
       bool all_nops;
@@ -9058,8 +9010,8 @@ display_debug_frames (struct dwarf_section *section,
 
       if (length == 0)
        {
-         printf ("\n%08lx ZERO terminator\n\n",
-                   (unsigned long)(saved_start - section_start));
+         printf ("\n%08tx ZERO terminator\n\n",
+                   saved_start - section_start);
          /* Skip any zero terminators that directly follow.
             A corrupt section size could have loaded a whole
             slew of zero filled memory bytes.  eg
@@ -9079,9 +9031,8 @@ display_debug_frames (struct dwarf_section *section,
 
       if (length > (size_t) (end - start))
        {
-         warn ("Invalid length 0x%s in FDE at %#08lx\n",
-               dwarf_vmatoa_1 (NULL, length, offset_size),
-               (unsigned long) (saved_start - section_start));
+         warn ("Invalid length %#" PRIx64 " in FDE at %#tx\n",
+               length, saved_start - section_start);
          block_end = end;
        }
       else
@@ -9113,9 +9064,9 @@ display_debug_frames (struct dwarf_section *section,
          if (fc->fde_encoding)
            encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
 
-         printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
-         print_dwarf_vma (length, fc->ptr_size);
-         print_dwarf_vma (cie_id, offset_size);
+         printf ("\n%08tx ", saved_start - section_start);
+         print_hex (length, fc->ptr_size);
+         print_hex (cie_id, offset_size);
 
          if (do_debug_frames_interp)
            {
@@ -9146,18 +9097,18 @@ display_debug_frames (struct dwarf_section *section,
        {
          unsigned char *look_for;
          unsigned long segment_selector;
-         dwarf_vma cie_off;
+         uint64_t cie_off;
 
          cie_off = cie_id;
          if (is_eh)
            {
-             dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
+             uint64_t sign = (uint64_t) 1 << (offset_size * 8 - 1);
              cie_off = (cie_off ^ sign) - sign;
              cie_off = start - 4 - section_start - cie_off;
            }
 
          look_for = section_start + cie_off;
-         if (cie_off <= (dwarf_vma) (saved_start - section_start))
+         if (cie_off <= (size_t) (saved_start - section_start))
            {
              for (cie = chunks; cie ; cie = cie->next)
                if (cie->chunk_start == look_for)
@@ -9185,7 +9136,7 @@ display_debug_frames (struct dwarf_section *section,
                    }
                  if (length != 0 && length <= (size_t) (end - cie_scan))
                    {
-                     dwarf_vma c_id;
+                     uint64_t c_id;
                      unsigned char *cie_end = cie_scan + length;
 
                      SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size,
@@ -9299,12 +9250,11 @@ display_debug_frames (struct dwarf_section *section,
              READ_ULEB (augmentation_data_len, start, block_end);
              augmentation_data = start;
              /* PR 17512 file: 722-8446-0.004 and PR 22386.  */
-             if (augmentation_data_len > (bfd_size_type) (block_end - start))
+             if (augmentation_data_len > (size_t) (block_end - start))
                {
-                 warn (_("Augmentation data too long: 0x%s, "
-                         "expected at most %#lx\n"),
-                       dwarf_vmatoa ("x", augmentation_data_len),
-                       (unsigned long) (block_end - start));
+                 warn (_("Augmentation data too long: %#" PRIx64 ", "
+                         "expected at most %#tx\n"),
+                       augmentation_data_len, block_end - start);
                  start = block_end;
                  augmentation_data = NULL;
                  augmentation_data_len = 0;
@@ -9312,14 +9262,13 @@ display_debug_frames (struct dwarf_section *section,
              start += augmentation_data_len;
            }
 
-         printf ("\n%08lx %s %s FDE ",
-                 (unsigned long)(saved_start - section_start),
-                 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
-                 dwarf_vmatoa_1 (NULL, cie_id, offset_size));
+         printf ("\n%08tx ", saved_start - section_start);
+         print_hex (length, fc->ptr_size);
+         print_hex (cie_id, offset_size);
+         printf ("FDE ");
 
          if (cie->chunk_start)
-           printf ("cie=%08lx",
-                   (unsigned long) (cie->chunk_start - section_start));
+           printf ("cie=%08tx", cie->chunk_start - section_start);
          else
            /* Ideally translate "invalid " to 8 chars, trailing space
               is optional.  */
@@ -9329,9 +9278,10 @@ display_debug_frames (struct dwarf_section *section,
          if (fc->segment_size)
            printf ("%04lx:", segment_selector);
 
-         printf ("%s..%s\n",
-                 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
-                 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
+         print_hex_ns (fc->pc_begin, fc->ptr_size);
+         printf ("..");
+         print_hex_ns (fc->pc_begin + fc->pc_range, fc->ptr_size);
+         printf ("\n");
 
          if (! do_debug_frames_interp && augmentation_data_len)
            {
@@ -9501,9 +9451,9 @@ display_debug_frames (struct dwarf_section *section,
             are various functions, notably frame_space_needed() that assume that
             reg is an unsigned int.  */
          unsigned int reg;
-         dwarf_signed_vma l;
-         dwarf_vma ofs;
-         dwarf_vma vma;
+         int64_t l;
+         uint64_t ofs;
+         uint64_t vma;
          const char *reg_prefix = "";
 
          op = *start++;
@@ -9523,11 +9473,13 @@ display_debug_frames (struct dwarf_section *section,
              if (do_debug_frames_interp)
                frame_display_row (fc, &need_col_headers, &max_regs);
              else
-               printf ("  DW_CFA_advance_loc: %d to %s\n",
-                       opa * fc->code_factor,
-                       dwarf_vmatoa_1 (NULL,
-                                       fc->pc_begin + opa * fc->code_factor,
-                                       fc->ptr_size));
+               {
+                 printf ("  DW_CFA_advance_loc: %d to ",
+                       opa * fc->code_factor);
+                 print_hex_ns (fc->pc_begin + opa * fc->code_factor,
+                               fc->ptr_size);
+                 printf ("\n");
+               }
              fc->pc_begin += opa * fc->code_factor;
              break;
 
@@ -9574,8 +9526,11 @@ display_debug_frames (struct dwarf_section *section,
              if (do_debug_frames_interp)
                frame_display_row (fc, &need_col_headers, &max_regs);
              else
-               printf ("  DW_CFA_set_loc: %s\n",
-                       dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
+               {
+                 printf ("  DW_CFA_set_loc: ");
+                 print_hex_ns (vma, fc->ptr_size);
+                 printf ("\n");
+               }
              fc->pc_begin = vma;
              break;
 
@@ -9584,11 +9539,13 @@ display_debug_frames (struct dwarf_section *section,
              if (do_debug_frames_interp)
                frame_display_row (fc, &need_col_headers, &max_regs);
              else
-               printf ("  DW_CFA_advance_loc1: %ld to %s\n",
-                       (unsigned long) (ofs * fc->code_factor),
-                       dwarf_vmatoa_1 (NULL,
-                                       fc->pc_begin + ofs * fc->code_factor,
-                                       fc->ptr_size));
+               {
+                 printf ("  DW_CFA_advance_loc1: %" PRId64 " to ",
+                         ofs * fc->code_factor);
+                 print_hex_ns (fc->pc_begin + ofs * fc->code_factor,
+                               fc->ptr_size);
+                 printf ("\n");
+               }
              fc->pc_begin += ofs * fc->code_factor;
              break;
 
@@ -9597,11 +9554,13 @@ display_debug_frames (struct dwarf_section *section,
              if (do_debug_frames_interp)
                frame_display_row (fc, &need_col_headers, &max_regs);
              else
-               printf ("  DW_CFA_advance_loc2: %ld to %s\n",
-                       (unsigned long) (ofs * fc->code_factor),
-                       dwarf_vmatoa_1 (NULL,
-                                       fc->pc_begin + ofs * fc->code_factor,
-                                       fc->ptr_size));
+               {
+                 printf ("  DW_CFA_advance_loc2: %" PRId64 " to ",
+                         ofs * fc->code_factor);
+                 print_hex_ns (fc->pc_begin + ofs * fc->code_factor,
+                               fc->ptr_size);
+                 printf ("\n");
+               }
              fc->pc_begin += ofs * fc->code_factor;
              break;
 
@@ -9610,11 +9569,13 @@ display_debug_frames (struct dwarf_section *section,
              if (do_debug_frames_interp)
                frame_display_row (fc, &need_col_headers, &max_regs);
              else
-               printf ("  DW_CFA_advance_loc4: %ld to %s\n",
-                       (unsigned long) (ofs * fc->code_factor),
-                       dwarf_vmatoa_1 (NULL,
-                                       fc->pc_begin + ofs * fc->code_factor,
-                                       fc->ptr_size));
+               {
+                 printf ("  DW_CFA_advance_loc4: %" PRId64 " to ",
+                         ofs * fc->code_factor);
+                 print_hex_ns (fc->pc_begin + ofs * fc->code_factor,
+                               fc->ptr_size);
+                 printf ("\n");
+               }
              fc->pc_begin += ofs * fc->code_factor;
              break;
 
@@ -9865,9 +9826,9 @@ display_debug_frames (struct dwarf_section *section,
              if (reg >= fc->ncols)
                reg_prefix = bad_reg;
              if (! do_debug_frames_interp || *reg_prefix != '\0')
-               printf ("  DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
+               printf ("  DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64 "\n",
                        reg_prefix, regname (reg, 0),
-                       (long)(l * fc->data_factor));
+                       l * fc->data_factor);
              if (*reg_prefix == '\0')
                {
                  fc->col_type[reg] = DW_CFA_offset;
@@ -9881,9 +9842,9 @@ display_debug_frames (struct dwarf_section *section,
              if (reg >= fc->ncols)
                reg_prefix = bad_reg;
              if (! do_debug_frames_interp || *reg_prefix != '\0')
-               printf ("  DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
+               printf ("  DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64 "\n",
                        reg_prefix, regname (reg, 0),
-                       (long)(l * fc->data_factor));
+                       l * fc->data_factor);
              if (*reg_prefix == '\0')
                {
                  fc->col_type[reg] = DW_CFA_val_offset;
@@ -9898,8 +9859,8 @@ display_debug_frames (struct dwarf_section *section,
              fc->cfa_offset = l;
              fc->cfa_exp = 0;
              if (! do_debug_frames_interp)
-               printf ("  DW_CFA_def_cfa_sf: %s ofs %ld\n",
-                       regname (fc->cfa_reg, 0), (long) l);
+               printf ("  DW_CFA_def_cfa_sf: %s ofs %" PRId64 "\n",
+                       regname (fc->cfa_reg, 0), l);
              break;
 
            case DW_CFA_def_cfa_offset_sf:
@@ -9907,7 +9868,7 @@ display_debug_frames (struct dwarf_section *section,
              l *= fc->data_factor;
              fc->cfa_offset = l;
              if (! do_debug_frames_interp)
-               printf ("  DW_CFA_def_cfa_offset_sf: %ld\n", (long) l);
+               printf ("  DW_CFA_def_cfa_offset_sf: %" PRId64 "\n", l);
              break;
 
            case DW_CFA_MIPS_advance_loc8:
@@ -9915,17 +9876,19 @@ display_debug_frames (struct dwarf_section *section,
              if (do_debug_frames_interp)
                frame_display_row (fc, &need_col_headers, &max_regs);
              else
-               printf ("  DW_CFA_MIPS_advance_loc8: %ld to %s\n",
-                       (unsigned long) (ofs * fc->code_factor),
-                       dwarf_vmatoa_1 (NULL,
-                                       fc->pc_begin + ofs * fc->code_factor,
-                                       fc->ptr_size));
+               {
+                 printf ("  DW_CFA_MIPS_advance_loc8: %" PRId64 " to ",
+                         ofs * fc->code_factor);
+                 print_hex_ns (fc->pc_begin + ofs * fc->code_factor,
+                               fc->ptr_size);
+                 printf ("\n");
+               }
              fc->pc_begin += ofs * fc->code_factor;
              break;
 
            case DW_CFA_GNU_window_save:
              if (! do_debug_frames_interp)
-               printf ("  DW_CFA_GNU_window_save\n");
+               printf ("  %s\n", DW_CFA_GNU_window_save_name[is_aarch64]);
              break;
 
            case DW_CFA_GNU_args_size:
@@ -9941,9 +9904,10 @@ display_debug_frames (struct dwarf_section *section,
              if (reg >= fc->ncols)
                reg_prefix = bad_reg;
              if (! do_debug_frames_interp || *reg_prefix != '\0')
-               printf ("  DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
+               printf ("  DW_CFA_GNU_negative_offset_extended: %s%s "
+                       "at cfa%+" PRId64 "\n",
                        reg_prefix, regname (reg, 0),
-                       (long)(l * fc->data_factor));
+                       l * fc->data_factor);
              if (*reg_prefix == '\0')
                {
                  fc->col_type[reg] = DW_CFA_offset;
@@ -10020,7 +9984,7 @@ static int
 display_debug_names (struct dwarf_section *section, void *file)
 {
   unsigned char *hdrptr = section->start;
-  dwarf_vma unit_length;
+  uint64_t unit_length;
   unsigned char *unit_start;
   const unsigned char *const section_end = section->start + section->size;
   unsigned char *unit_end;
@@ -10059,17 +10023,16 @@ display_debug_names (struct dwarf_section *section, void *file)
          || unit_length < 2 + 2 + 4 * 7)
        {
        too_short:
-         warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
-               section->name,
-               (unsigned long) (unit_start - section->start),
-               dwarf_vmatoa ("x", unit_length));
+         warn (_("Debug info is corrupted, %s header at %#tx"
+                 " has length %#" PRIx64 "\n"),
+               section->name, unit_start - section->start, unit_length);
          return 0;
        }
       unit_end = hdrptr + unit_length;
 
       /* Get and check the version number.  */
       SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end);
-      printf (_("Version %ld\n"), (long) dwarf_version);
+      printf (_("Version %d\n"), (int) dwarf_version);
 
       /* Prior versions did not exist, and future versions may not be
         backwards compatible.  */
@@ -10142,7 +10105,7 @@ display_debug_names (struct dwarf_section *section, void *file)
          uint64_t cu_offset;
 
          SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end);
-         printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset);
+         printf ("[%3u] %#" PRIx64 "\n", i, cu_offset);
        }
       putchar ('\n');
 
@@ -10155,7 +10118,7 @@ display_debug_names (struct dwarf_section *section, void *file)
          uint64_t tu_offset;
 
          SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end);
-         printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset);
+         printf ("[%3u] %#" PRIx64 "\n", i, tu_offset);
        }
       putchar ('\n');
 
@@ -10169,7 +10132,7 @@ display_debug_names (struct dwarf_section *section, void *file)
 
          SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end);
          printf (_("[%3u] "), i);
-         print_dwarf_vma (signature, 8);
+         print_hex_ns (signature, 8);
          putchar ('\n');
        }
       putchar ('\n');
@@ -10179,11 +10142,9 @@ display_debug_names (struct dwarf_section *section, void *file)
                       + abbrev_table_size);
       if (xtra > (size_t) (unit_end - hdrptr))
        {
-         warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
-                 "for unit 0x%lx in the debug_names\n"),
-               (long) xtra,
-               (long) (unit_end - unit_start),
-               (long) (unit_start - section->start));
+         warn (_("Entry pool offset (%#" PRIx64 ") exceeds unit size %#tx "
+                 "for unit %#tx in the debug_names\n"),
+               xtra, unit_end - unit_start, unit_start - section->start);
          return 0;
        }
       const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr;
@@ -10210,7 +10171,7 @@ display_debug_names (struct dwarf_section *section, void *file)
        }
       printf (ngettext ("Used %zu of %lu bucket.\n",
                        "Used %zu of %lu buckets.\n",
-                       bucket_count),
+                       (unsigned long) bucket_count),
              buckets_filled, (unsigned long) bucket_count);
 
       if (bucket_count != 0)
@@ -10237,20 +10198,20 @@ display_debug_names (struct dwarf_section *section, void *file)
                }
              hash_prev = hash_this;
            }
-         printf (_("Out of %lu items there are %zu bucket clashes"
+         printf (_("Out of %" PRIu64 " items there are %zu bucket clashes"
                    " (longest of %zu entries).\n"),
-                 (unsigned long) name_count, hash_clash_count, longest_clash);
-         
+                 name_count, hash_clash_count, longest_clash);
+
          if (name_count != buckets_filled + hash_clash_count)
-           warn (_("The name_count (%lu) is not the same as the used bucket_count (%lu) + the hash clash count (%lu)"),
-                 (unsigned long) name_count,
-                 (unsigned long) buckets_filled,
-                 (unsigned long) hash_clash_count);
+           warn (_("The name_count (%" PRIu64 ")"
+                   " is not the same as the used bucket_count"
+                   " (%zu) + the hash clash count (%zu)"),
+                 name_count, buckets_filled, hash_clash_count);
        }
 
       struct abbrev_lookup_entry
       {
-       dwarf_vma abbrev_tag;
+       uint64_t abbrev_tag;
        unsigned char *abbrev_lookup_ptr;
       };
       struct abbrev_lookup_entry *abbrev_lookup = NULL;
@@ -10260,7 +10221,7 @@ display_debug_names (struct dwarf_section *section, void *file)
       unsigned char *abbrevptr = abbrev_table;
       for (;;)
        {
-         dwarf_vma abbrev_tag;
+         uint64_t abbrev_tag;
 
          READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end);
          if (abbrev_tag == 0)
@@ -10280,9 +10241,9 @@ display_debug_names (struct dwarf_section *section, void *file)
               entry++)
            if (entry->abbrev_tag == abbrev_tag)
              {
-               warn (_("Duplicate abbreviation tag %lu "
-                       "in unit 0x%lx in the debug_names\n"),
-                     (long) abbrev_tag, (long) (unit_start - section->start));
+               warn (_("Duplicate abbreviation tag %" PRIu64
+                       " in unit %#tx in the debug_names section\n"),
+                     abbrev_tag, unit_start - section->start);
                break;
              }
          entry = &abbrev_lookup[abbrev_lookup_used++];
@@ -10293,7 +10254,7 @@ display_debug_names (struct dwarf_section *section, void *file)
          SKIP_ULEB (abbrevptr, abbrev_table_end);
          for (;;)
            {
-             dwarf_vma xindex, form;
+             uint64_t xindex, form;
 
              READ_ULEB (xindex, abbrevptr, abbrev_table_end);
              READ_ULEB (form, abbrevptr, abbrev_table_end);
@@ -10325,11 +10286,11 @@ display_debug_names (struct dwarf_section *section, void *file)
             first entry for real printing etc.  */
          int tagno = -2;
          /* Initialize it due to a false compiler warning.  */
-         dwarf_vma second_abbrev_tag = -1;
+         uint64_t second_abbrev_tag = -1;
          for (;;)
            {
-             dwarf_vma abbrev_tag;
-             dwarf_vma dwarf_tag;
+             uint64_t abbrev_tag;
+             uint64_t dwarf_tag;
              const struct abbrev_lookup_entry *entry;
 
              READ_ULEB (abbrev_tag, entryptr, unit_end);
@@ -10343,9 +10304,9 @@ display_debug_names (struct dwarf_section *section, void *file)
              if (abbrev_tag == 0)
                break;
              if (tagno >= 0)
-               printf ("%s<%lu>",
-                       (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
-                       (unsigned long) abbrev_tag);
+               printf ("%s<%" PRIu64 ">",
+                       (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
+                       abbrev_tag);
 
              for (entry = abbrev_lookup;
                   entry < abbrev_lookup + abbrev_lookup_used;
@@ -10354,10 +10315,10 @@ display_debug_names (struct dwarf_section *section, void *file)
                  break;
              if (entry >= abbrev_lookup + abbrev_lookup_used)
                {
-                 warn (_("Undefined abbreviation tag %lu "
-                         "in unit 0x%lx in the debug_names\n"),
-                       (long) abbrev_tag,
-                       (long) (unit_start - section->start));
+                 warn (_("Undefined abbreviation tag %" PRId64
+                         " in unit %#tx in the debug_names section\n"),
+                       abbrev_tag,
+                       unit_start - section->start);
                  break;
                }
              abbrevptr = entry->abbrev_lookup_ptr;
@@ -10366,7 +10327,7 @@ display_debug_names (struct dwarf_section *section, void *file)
                printf (" %s", get_TAG_name (dwarf_tag));
              for (;;)
                {
-                 dwarf_vma xindex, form;
+                 uint64_t xindex, form;
 
                  READ_ULEB (xindex, abbrevptr, abbrev_table_end);
                  READ_ULEB (form, abbrevptr, abbrev_table_end);
@@ -10442,25 +10403,26 @@ display_debug_links (struct dwarf_section *  section,
 
       if (crc_offset + 4 < section->size)
        {
-         warn (_("There are %#lx extraneous bytes at the end of the section\n"),
-               (long)(section->size - (crc_offset + 4)));
+         warn (_("There are %#" PRIx64
+                 " extraneous bytes at the end of the section\n"),
+               section->size - (crc_offset + 4));
          return 0;
        }
     }
   else /* startswith (section->name, ".gnu_debugaltlink") */
     {
-      const unsigned char * build_id = section->start + filelen + 1;
-      bfd_size_type         build_id_len = section->size - (filelen + 1);
-      bfd_size_type         printed;
+      const unsigned char *build_id = section->start + filelen + 1;
+      size_t build_id_len = section->size - (filelen + 1);
+      size_t printed;
 
       /* FIXME: Should we support smaller build-id notes ?  */
       if (build_id_len < 0x14)
        {
-         warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len);
+         warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len);
          return 0;
        }
 
-      printed = printf (_("  Build-ID (%#lx bytes):"), (long) build_id_len);
+      printed = printf (_("  Build-ID (%#zx bytes):"), build_id_len);
       display_data (printed, build_id, build_id_len);
       putchar ('\n');
     }
@@ -10494,7 +10456,7 @@ display_gdb_index (struct dwarf_section *section,
     }
 
   version = byte_get_little_endian (start, 4);
-  printf (_("Version %ld\n"), (long) version);
+  printf (_("Version %lu\n"), (unsigned long) version);
 
   /* Prior versions are obsolete, and future versions may not be
      backwards compatible.  */
@@ -10553,9 +10515,8 @@ display_gdb_index (struct dwarf_section *section,
       uint64_t cu_offset = byte_get_little_endian (cu_list + i * 16, 8);
       uint64_t cu_length = byte_get_little_endian (cu_list + i * 16 + 8, 8);
 
-      printf (_("[%3u] 0x%lx - 0x%lx\n"), i,
-             (unsigned long) cu_offset,
-             (unsigned long) (cu_offset + cu_length - 1));
+      printf ("[%3u] %#" PRIx64 " - %#" PRIx64 "\n",
+             i, cu_offset, cu_offset + cu_length - 1);
     }
 
   printf (_("\nTU table:\n"));
@@ -10565,10 +10526,9 @@ display_gdb_index (struct dwarf_section *section,
       uint64_t type_offset = byte_get_little_endian (tu_list + i * 24 + 8, 8);
       uint64_t signature = byte_get_little_endian (tu_list + i * 24 + 16, 8);
 
-      printf (_("[%3u] 0x%lx 0x%lx "), i,
-             (unsigned long) tu_offset,
-             (unsigned long) type_offset);
-      print_dwarf_vma (signature, 8);
+      printf ("[%3u] %#" PRIx64 " %#" PRIx64 " ",
+             i, tu_offset, type_offset);
+      print_hex_ns (signature, 8);
       printf ("\n");
     }
 
@@ -10579,9 +10539,9 @@ display_gdb_index (struct dwarf_section *section,
       uint64_t high = byte_get_little_endian (address_table + i * 20 + 8, 8);
       uint32_t cu_index = byte_get_little_endian (address_table + i + 20 + 16, 4);
 
-      print_dwarf_vma (low, 8);
-      print_dwarf_vma (high, 8);
-      printf (_("%lu\n"), (unsigned long) cu_index);
+      print_hex (low, 8);
+      print_hex (high, 8);
+      printf ("%" PRIu32 "\n", cu_index);
     }
 
   printf (_("\nSymbol table:\n"));
@@ -10641,9 +10601,9 @@ display_gdb_index (struct dwarf_section *section,
              kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
              cu = GDB_INDEX_CU_VALUE (cu);
              /* Convert to TU number if it's for a type unit.  */
-             if (cu >= cu_list_elements / 2)
+             if (cu >= cu_list_elements)
                printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
-                       (unsigned long) (cu - cu_list_elements / 2));
+                       (unsigned long) cu - cu_list_elements);
              else
                printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
 
@@ -10754,7 +10714,7 @@ process_cu_tu_index (struct dwarf_section *section, int do_display)
   unsigned int nslots;
   unsigned int i;
   unsigned int j;
-  dwarf_vma signature;
+  uint64_t signature;
   size_t total;
 
   /* PR 17512: file: 002-168123-0.004.  */
@@ -10825,8 +10785,8 @@ process_cu_tu_index (struct dwarf_section *section, int do_display)
                }
 
              if (do_display)
-               printf (_("  [%3d] Signature:  0x%s  Sections: "),
-                       i, dwarf_vmatoa ("x", signature));
+               printf (_("  [%3d] Signature:  %#" PRIx64 "  Sections: "),
+                       i, signature);
              for (;;)
                {
                  if (shndx_list >= limit)
@@ -10873,7 +10833,7 @@ process_cu_tu_index (struct dwarf_section *section, int do_display)
         Check for integer overflow (can occur when size_t is 32-bit)
         with overlarge ncols or nused values.  */
       if (nused == -1u
-         || _mul_overflow ((size_t) ncols, 4, &temp)     
+         || _mul_overflow ((size_t) ncols, 4, &temp)
          || _mul_overflow ((size_t) nused + 1, temp, &total)
          || total > (size_t) (limit - ppool))
        {
@@ -10881,7 +10841,7 @@ process_cu_tu_index (struct dwarf_section *section, int do_display)
                section->name);
          return 0;
        }
-      
+
       if (do_display)
        {
          printf (_("  Offset table\n"));
@@ -10939,8 +10899,7 @@ process_cu_tu_index (struct dwarf_section *section, int do_display)
 
              prow = poffsets + (row - 1) * ncols * 4;
              if (do_display)
-               printf (_("  [%3d] 0x%s"),
-                       i, dwarf_vmatoa ("x", signature));
+               printf ("  [%3d] %#" PRIx64, i, signature);
              for (j = 0; j < ncols; j++)
                {
                  unsigned char *p = prow + j * 4;
@@ -10998,8 +10957,7 @@ process_cu_tu_index (struct dwarf_section *section, int do_display)
              prow = psizes + (row - 1) * ncols * 4;
 
              if (do_display)
-               printf (_("  [%3d] 0x%s"),
-                       i, dwarf_vmatoa ("x", signature));
+               printf ("  [%3d] %#" PRIx64, i, signature);
 
              for (j = 0; j < ncols; j++)
                {
@@ -11144,8 +11102,8 @@ xcmalloc (size_t nmemb, size_t size)
   if (nmemb >= ~(size_t) 0 / size)
     {
       fprintf (stderr,
-              _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
-              (long) nmemb);
+              _("Attempt to allocate an array with an excessive number of elements: %#zx\n"),
+              nmemb);
       xexit (1);
     }
 
@@ -11162,8 +11120,8 @@ xcrealloc (void *ptr, size_t nmemb, size_t size)
   /* Check for overflow.  */
   if (nmemb >= ~(size_t) 0 / size)
     {
-      error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
-            (long) nmemb);
+      error (_("Attempt to re-allocate an array with an excessive number of elements: %#zx\n"),
+            nmemb);
       xexit (1);
     }
 
@@ -11178,8 +11136,8 @@ xcalloc2 (size_t nmemb, size_t size)
   /* Check for overflow.  */
   if (nmemb >= ~(size_t) 0 / size)
     {
-      error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
-            (long) nmemb);
+      error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#zx\n"),
+            nmemb);
       xexit (1);
     }
 
@@ -11187,9 +11145,9 @@ xcalloc2 (size_t nmemb, size_t size)
 }
 
 static unsigned long
-calc_gnu_debuglink_crc32 (unsigned long          crc,
-                         const unsigned char *  buf,
-                         bfd_size_type          len)
+calc_gnu_debuglink_crc32 (unsigned long crc,
+                         const unsigned char *buf,
+                         size_t len)
 {
   static const unsigned long crc32_table[256] =
     {
@@ -11260,11 +11218,11 @@ typedef const char *(* parse_func_type) (struct dwarf_section *, void *);
 static bool
 check_gnu_debuglink (const char * pathname, void * crc_pointer)
 {
-  static unsigned char buffer [8 * 1024];
-  FILE *         f;
-  bfd_size_type  count;
-  unsigned long  crc = 0;
-  void *         sep_data;
+  static unsigned char buffer[8 * 1024];
+  FILE *f;
+  size_t count;
+  unsigned long crc = 0;
+  void *sep_data;
 
   sep_data = open_debug_file (pathname);
   if (sep_data == NULL)
@@ -11334,17 +11292,17 @@ check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED)
 
 typedef struct build_id_data
 {
-  bfd_size_type          len;
-  const unsigned char *  data;
+  size_t len;
+  const unsigned char *data;
 } Build_id_data;
 
 static const char *
 parse_gnu_debugaltlink (struct dwarf_section * section, void * data)
 {
-  const char *     name;
-  bfd_size_type    namelen;
-  bfd_size_type    id_len;
-  Build_id_data *  build_id_data;
+  const char *name;
+  size_t namelen;
+  size_t id_len;
+  Build_id_data *build_id_data;
 
   /* The name is first.
      The build-id follows immediately, with no padding, up to the section's end.  */
@@ -11385,8 +11343,8 @@ add_separate_debug_file (const char * filename, void * handle)
 
 static bool
 debuginfod_fetch_separate_debug_info (struct dwarf_section * section,
-                                      char ** filename,
-                                      void * file)
+                                     char ** filename,
+                                     void * file)
 {
   size_t build_id_len;
   unsigned char * build_id;
@@ -11404,14 +11362,14 @@ debuginfod_fetch_separate_debug_info (struct dwarf_section * section,
 
       filelen = strnlen ((const char *)section->start, section->size);
       if (filelen == section->size)
-        /* Corrupt debugaltlink.  */
-        return false;
+       /* Corrupt debugaltlink.  */
+       return false;
 
       build_id = section->start + filelen + 1;
       build_id_len = section->size - (filelen + 1);
 
       if (build_id_len == 0)
-        return false;
+       return false;
     }
   else
     return false;
@@ -11423,25 +11381,25 @@ debuginfod_fetch_separate_debug_info (struct dwarf_section * section,
 
       client = debuginfod_begin ();
       if (client == NULL)
-        return false;
+       return false;
 
       /* Query debuginfod servers for the target file. If found its path
-         will be stored in filename.  */
+        will be stored in filename.  */
       fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename);
       debuginfod_end (client);
 
       /* Only free build_id if we allocated space for a hex string
-         in get_build_id ().  */
+        in get_build_id ().  */
       if (build_id_len == 0)
-        free (build_id);
+       free (build_id);
 
       if (fd >= 0)
-        {
-          /* File successfully retrieved. Close fd since we want to
-             use open_debug_file () on filename instead.  */
-          close (fd);
-          return true;
-        }
+       {
+         /* File successfully retrieved. Close fd since we want to
+            use open_debug_file () on filename instead.  */
+         close (fd);
+         return true;
+       }
     }
 
   return false;
@@ -11454,7 +11412,7 @@ load_separate_debug_info (const char *            main_filename,
                          parse_func_type         parse_func,
                          check_func_type         check_func,
                          void *                  func_data,
-                          void *                  file ATTRIBUTE_UNUSED)
+                         void *                  file ATTRIBUTE_UNUSED)
 {
   const char *   separate_filename;
   char *         debug_filename;
@@ -11570,11 +11528,11 @@ load_separate_debug_info (const char *            main_filename,
                                                 & tmp_filename,
                                                 file))
       {
-        /* File successfully downloaded from server, replace
-           debug_filename with the file's path.  */
-        free (debug_filename);
-        debug_filename = tmp_filename;
-        goto found;
+       /* File successfully downloaded from server, replace
+          debug_filename with the file's path.  */
+       free (debug_filename);
+       debug_filename = tmp_filename;
+       goto found;
       }
   }
 #endif
@@ -11741,12 +11699,12 @@ load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED, void * ma
   /* In theory we should extract the contents of the section into
      a note structure and then check the fields.  For now though
      just use hard coded offsets instead:
-     
+
        Field  Bytes    Contents
        NSize  0...3   4
        DSize  4...7   8+
        Type   8..11   3  (NT_GNU_BUILD_ID)
-        Name   12.15   GNU\0
+       Name   12.15   GNU\0
        Data   16....   */
 
   /* FIXME: Check the name size, name and type fields.  */
@@ -11758,7 +11716,7 @@ load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED, void * ma
       warn (_(".note.gnu.build-id data size is too small\n"));
       return;
     }
-  
+
   if (build_id_size > (section->size - 16))
     {
       warn (_(".note.gnu.build-id data size is too bug\n"));
@@ -11952,6 +11910,10 @@ load_separate_debug_files (void * file, const char * filename)
       load_debug_section (debug_addr, file);
       /* Load the .debug_str_offsets section, if it exists.  */
       load_debug_section (str_index, file);
+      /* Load the .debug_loclists section, if it exists.  */
+      load_debug_section (loclists, file);
+      /* Load the .debug_rnglists section, if it exists.  */
+      load_debug_section (rnglists, file);
 
       free_dwo_info ();
 
@@ -12012,7 +11974,7 @@ load_separate_debug_files (void * file, const char * filename)
                      printf (_("  Directory: %s\n"), dir ? dir : _("<not-found>"));
                      if (id != NULL)
                        display_data (printf (_("  ID:       ")), (unsigned char *) id, 8);
-                     else
+                     else if (debug_information[0].dwarf_version != 5)
                        printf (_("  ID:        <not specified>\n"));
                      printf ("\n\n");
                    }
@@ -12050,10 +12012,6 @@ free_debug_memory (void)
 
   free_all_abbrevs ();
 
-  free (cu_abbrev_map);
-  cu_abbrev_map = NULL;
-  next_free_abbrev_map_entry = 0;
-
   free (shndx_pool);
   shndx_pool = NULL;
   shndx_pool_size = 0;
@@ -12074,15 +12032,7 @@ free_debug_memory (void)
   if (debug_information != NULL)
     {
       for (i = 0; i < alloc_num_debug_info_entries; i++)
-       {
-         if (debug_information [i].max_loc_offsets)
-           {
-             free (debug_information [i].loc_offsets);
-             free (debug_information [i].have_frame_base);
-           }
-         if (debug_information [i].max_range_lists)
-           free (debug_information [i].range_lists);
-       }
+       free_debug_information (&debug_information[i]);
       free (debug_information);
       debug_information = NULL;
       alloc_num_debug_info_entries = num_debug_info_entries = 0;
@@ -12169,7 +12119,10 @@ dwarf_select_sections_by_names (const char *names)
          if (strncmp (p, entry->option, len) == 0
              && (p[len] == ',' || p[len] == '\0'))
            {
-             * entry->variable = entry->val;
+             if (entry->val == 0)
+               * entry->variable = 0;
+             else
+               * entry->variable = entry->val;
              result |= entry->val;
 
              p += len;
@@ -12213,7 +12166,10 @@ dwarf_select_sections_by_letters (const char *letters)
        {
          if (entry->letter == * letters)
            {
-             * entry->variable |= entry->val;
+             if (entry->val == 0)
+               * entry->variable = 0;
+             else
+               * entry->variable |= entry->val;
              result |= entry->val;
              break;
            }
@@ -12279,10 +12235,12 @@ struct dwarf_section_display debug_displays[] =
   { { ".debug_line_str",    ".zdebug_line_str",             "",         NO_ABBREVS },      display_debug_str,      &do_debug_str,      false },
   { { ".debug_loc",        ".zdebug_loc",           ".dwloc",   NO_ABBREVS },      display_debug_loc,      &do_debug_loc,      true },
   { { ".debug_loclists",    ".zdebug_loclists",             "",         NO_ABBREVS },      display_debug_loc,      &do_debug_loc,      true },
+  { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "",         NO_ABBREVS },      display_debug_loc,      &do_debug_loc,      true },
   { { ".debug_pubtypes",    ".zdebug_pubtypes",             ".dwpbtyp", NO_ABBREVS },      display_debug_pubnames, &do_debug_pubtypes, false },
   { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "",        NO_ABBREVS },      display_debug_gnu_pubnames, &do_debug_pubtypes, false },
   { { ".debug_ranges",     ".zdebug_ranges",        ".dwrnges", NO_ABBREVS },      display_debug_ranges,   &do_debug_ranges,   true },
   { { ".debug_rnglists",    ".zdebug_rnglists",             "",         NO_ABBREVS },      display_debug_ranges,   &do_debug_ranges,   true },
+  { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "",         NO_ABBREVS },      display_debug_ranges,   &do_debug_ranges,   true },
   { { ".debug_static_func", ".zdebug_static_func",   "",        NO_ABBREVS },      display_debug_not_supported, NULL,          false },
   { { ".debug_static_vars", ".zdebug_static_vars",   "",        NO_ABBREVS },      display_debug_not_supported, NULL,          false },
   { { ".debug_types",      ".zdebug_types",         "",         ABBREV (abbrev) }, display_debug_types,    &do_debug_info,     true },