dwarf: Make sect_offset 64-bits

Message ID 1514692098-8054-1-git-send-email-simon.marchi@ericsson.com
State New, archived
Headers

Commit Message

Simon Marchi Dec. 31, 2017, 3:48 a.m. UTC
  Compiling with Clang 6 shows these errors:

/home/emaisin/src/binutils-gdb/gdb/dwarf2read.c:26610:43: error: result of comparison of constant 4294967296 with expression of type 'typename std::underlying_type<sect_offset>::type' (a
ka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
      if (to_underlying (per_cu.sect_off) >= (static_cast<uint64_t> (1) << 32))
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/emaisin/src/binutils-gdb/gdb/dwarf2read.c:26618:43: error: result of comparison of constant 4294967296 with expression of type 'typename std::underlying_type<sect_offset>::type' (a
ka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
      if (to_underlying (per_cu.sect_off) >= (static_cast<uint64_t> (1) << 32))
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The code in question checks if there is any offset exceeding 32 bits,
and therefore if we need to use the 64-bit DWARF format when writing the
.debug_names section.  The type we use currently to represent section
offsets is an unsigned int (32-bits), which means a value of this type
will never exceed 32 bits, hence the errors above.

There are many signs that we want to support 64-bits DWARF (although I
haven't tested), such as:

 - We correctly read initial length fields (read_initial_length)
 - We take that into account when reading offsets (read_offset_1)
 - The check_dwarf64_offsets function

However, I don't see how it can work if sect_offset is a 32-bits type.
Every time we record a section offset, we risk truncating the value.
And if a file uses the 64-bit DWARF format, it's most likely because
there are such offset values that overflow 32 bits.

Because of this, I think the way forward is to change sect_offset to be
a uint64_t.  It will be able to represent any offset, regardless of the
bitness of the DWARF info.

This patch was regtested on the buildbot.

gdb/ChangeLog:

	* gdbtypes.h (sect_offset): Change type to uint64_t.
	(sect_offset_str): New function.
	* dwarf2read.c (create_addrmap_from_aranges): Use
	sect_offset_str.
	(error_check_comp_unit_head): Likewise.
	(create_debug_type_hash_table): Likewise.
	(read_cutu_die_from_dwo): Likewise.
	(init_cutu_and_read_dies): Likewise.
	(init_cutu_and_read_dies_no_follow): Likewise.
	(process_psymtab_comp_unit_reader): Likewise.
	(partial_die_parent_scope): Likewise.
	(peek_die_abbrev): Likewise.
	(process_queue): Likewise.
	(dwarf2_physname): Likewise.
	(read_namespace_alias): Likewise.
	(read_import_statement): Likewise.
	(create_dwo_cu_reader): Likewise.
	(create_cus_hash_table): Likewise.
	(lookup_dwo_cutu): Likewise.
	(inherit_abstract_dies): Likewise.
	(read_func_scope): Likewise.
	(read_call_site_scope): Likewise.
	(dwarf2_add_member_fn): Likewise.
	(read_common_block): Likewise.
	(read_module_type): Likewise.
	(read_typedef): Likewise.
	(read_subrange_type): Likewise.
	(load_partial_dies): Likewise.
	(read_partial_die): Likewise.
	(find_partial_die): Likewise.
	(read_str_index): Likewise.
	(dwarf2_string_attr): Likewise.
	(build_error_marker_type): Likewise.
	(lookup_die_type): Likewise.
	(dump_die_shallow): Likewise.
	(follow_die_ref): Likewise.
	(dwarf2_fetch_die_loc_sect_off): Likewise.
	(dwarf2_fetch_constant_bytes): Likewise.
	(follow_die_sig): Likewise.
	(get_signatured_type): Likewise.
	(get_DW_AT_signature_type): Likewise.
	(dwarf2_find_containing_comp_unit): Likewise.
	(set_die_type): Likewise.
---
 gdb/dwarf2read.c | 332 ++++++++++++++++++++++++++++---------------------------
 gdb/gdbtypes.h   |  10 +-
 2 files changed, 177 insertions(+), 165 deletions(-)
  

Patch

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index fcd5e99..d3e641b 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3440,8 +3440,8 @@  create_addrmap_from_aranges (struct objfile *objfile,
       if (!insertpair.second)
 	{
 	  warning (_("Section .debug_aranges in %s has duplicate "
-		     "debug_info_offset %u, ignoring .debug_aranges."),
-		   objfile_name (objfile), to_underlying (per_cu->sect_off));
+		     "debug_info_offset %s, ignoring .debug_aranges."),
+		   objfile_name (objfile), sect_offset_str (per_cu->sect_off));
 	  return;
 	}
     }
@@ -6719,10 +6719,10 @@  error_check_comp_unit_head (struct comp_unit_head *header,
 
   if (to_underlying (header->abbrev_sect_off)
       >= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section))
-    error (_("Dwarf Error: bad offset (0x%x) in compilation unit header "
-	   "(offset 0x%x + 6) [in module %s]"),
-	   to_underlying (header->abbrev_sect_off),
-	   to_underlying (header->sect_off),
+    error (_("Dwarf Error: bad offset (%s) in compilation unit header "
+	   "(offset %s + 6) [in module %s]"),
+	   sect_offset_str (header->abbrev_sect_off),
+	   sect_offset_str (header->sect_off),
 	   filename);
 
   /* Cast to ULONGEST to use 64-bit arithmetic when possible to
@@ -6730,8 +6730,8 @@  error_check_comp_unit_head (struct comp_unit_head *header,
   if (((ULONGEST) header->sect_off + get_cu_length (header))
       > section->size)
     error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
-	   "(offset 0x%x + 0) [in module %s]"),
-	   header->length, to_underlying (header->sect_off),
+	   "(offset %s + 0) [in module %s]"),
+	   header->length, sect_offset_str (header->sect_off),
 	   filename);
 }
 
@@ -7023,16 +7023,16 @@  create_debug_type_hash_table (struct dwo_file *dwo_file,
 	    }
 
 	  complaint (&symfile_complaints,
-		     _("debug type entry at offset 0x%x is duplicate to"
-		       " the entry at offset 0x%x, signature %s"),
-		     to_underlying (sect_off), to_underlying (dup_sect_off),
+		     _("debug type entry at offset %s is duplicate to"
+		       " the entry at offset %s, signature %s"),
+		     sect_offset_str (sect_off), sect_offset_str (dup_sect_off),
 		     hex_string (header.signature));
 	}
       *slot = dwo_file ? (void *) dwo_tu : (void *) sig_type;
 
       if (dwarf_read_debug > 1)
-	fprintf_unfiltered (gdb_stdlog, "  offset 0x%x, signature %s\n",
-			    to_underlying (sect_off),
+	fprintf_unfiltered (gdb_stdlog, "  offset %s, signature %s\n",
+			    sect_offset_str (sect_off),
 			    hex_string (header.signature));
 
       info_ptr += length;
@@ -7468,10 +7468,10 @@  read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
       if (sig_type->signature != cu->header.signature)
 	{
 	  error (_("Dwarf Error: signature mismatch %s vs %s while reading"
-		   " TU at offset 0x%x [in module %s]"),
+		   " TU at offset %s [in module %s]"),
 		 hex_string (sig_type->signature),
 		 hex_string (cu->header.signature),
-		 to_underlying (dwo_unit->sect_off),
+		 sect_offset_str (dwo_unit->sect_off),
 		 bfd_get_filename (abfd));
 	}
       gdb_assert (dwo_unit->sect_off == cu->header.sect_off);
@@ -7747,9 +7747,9 @@  init_cutu_and_read_dies (struct dwarf2_per_cu_data *this_cu,
   int rereading_dwo_cu = 0;
 
   if (dwarf_die_debug)
-    fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n",
+    fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset %s\n",
 			this_cu->is_debug_types ? "type" : "comp",
-			to_underlying (this_cu->sect_off));
+			sect_offset_str (this_cu->sect_off));
 
   if (use_existing_cu)
     gdb_assert (keep);
@@ -7890,8 +7890,9 @@  init_cutu_and_read_dies (struct dwarf2_per_cu_data *this_cu,
 	{
 	  complaint (&symfile_complaints,
 		     _("compilation unit with DW_AT_GNU_dwo_name"
-		       " has children (offset 0x%x) [in module %s]"),
-		     to_underlying (this_cu->sect_off), bfd_get_filename (abfd));
+		       " has children (offset %s) [in module %s]"),
+		     sect_offset_str (this_cu->sect_off),
+		     bfd_get_filename (abfd));
 	}
       dwo_unit = lookup_dwo_unit (this_cu, comp_unit_die);
       if (dwo_unit != NULL)
@@ -7979,9 +7980,9 @@  init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data *this_cu,
   int has_children;
 
   if (dwarf_die_debug)
-    fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n",
+    fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset %s\n",
 			this_cu->is_debug_types ? "type" : "comp",
-			to_underlying (this_cu->sect_off));
+			sect_offset_str (this_cu->sect_off));
 
   gdb_assert (this_cu->cu == NULL);
 
@@ -8353,10 +8354,10 @@  process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
       struct gdbarch *gdbarch = get_objfile_arch (objfile);
 
       fprintf_unfiltered (gdb_stdlog,
-			  "Psymtab for %s unit @0x%x: %s - %s"
+			  "Psymtab for %s unit @%s: %s - %s"
 			  ", %d global, %d static syms\n",
 			  per_cu->is_debug_types ? "type" : "comp",
-			  to_underlying (per_cu->sect_off),
+			  sect_offset_str (per_cu->sect_off),
 			  paddress (gdbarch, pst->textlow),
 			  paddress (gdbarch, pst->texthigh),
 			  pst->n_global_syms, pst->n_static_syms);
@@ -9128,8 +9129,8 @@  partial_die_parent_scope (struct partial_die_info *pdi,
 	 function-local names?  For partial symbols, we should probably be
 	 ignoring them.  */
       complaint (&symfile_complaints,
-		 _("unhandled containing DIE tag %d for DIE at %d"),
-		 parent->tag, to_underlying (pdi->sect_off));
+		 _("unhandled containing DIE tag %d for DIE at %s"),
+		 parent->tag, sect_offset_str (pdi->sect_off));
       parent->scope = grandparent_scope;
     }
 
@@ -9521,9 +9522,9 @@  peek_die_abbrev (const gdb_byte *info_ptr, unsigned int *bytes_read,
   if (!abbrev)
     {
       error (_("Dwarf Error: Could not find abbrev number %d in %s"
-	       " at offset 0x%x [in module %s]"),
+	       " at offset %s [in module %s]"),
 	     abbrev_number, cu->per_cu->is_debug_types ? "TU" : "CU",
-	     to_underlying (cu->header.sect_off), bfd_get_filename (abfd));
+	     sect_offset_str (cu->header.sect_off), bfd_get_filename (abfd));
     }
 
   return abbrev;
@@ -9866,17 +9867,17 @@  process_queue (void)
 	      struct signatured_type *sig_type =
 		(struct signatured_type *) per_cu;
 
-	      sprintf (buf, "TU %s at offset 0x%x",
+	      sprintf (buf, "TU %s at offset %s",
 		       hex_string (sig_type->signature),
-		       to_underlying (per_cu->sect_off));
+		       sect_offset_str (per_cu->sect_off));
 	      /* There can be 100s of TUs.
 		 Only print them in verbose mode.  */
 	      debug_print_threshold = 2;
 	    }
 	  else
 	    {
-	      sprintf (buf, "CU at offset 0x%x",
-		       to_underlying (per_cu->sect_off));
+	      sprintf (buf, "CU at offset %s",
+		       sect_offset_str (per_cu->sect_off));
 	      debug_print_threshold = 1;
 	    }
 
@@ -11135,8 +11136,8 @@  dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
 
 	  complaint (&symfile_complaints,
 		     _("Computed physname <%s> does not match demangled <%s> "
-		       "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
-		     physname, canon, mangled, to_underlying (die->sect_off),
+		       "(from linkage <%s>) - DIE at %s [in module %s]"),
+		     physname, canon, mangled, sect_offset_str (die->sect_off),
 		     objfile_name (objfile));
 
 	  /* Prefer DW_AT_linkage_name (in the CANON form) - when it
@@ -11198,8 +11199,8 @@  read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu)
       if (num == MAX_NESTED_IMPORTED_DECLARATIONS)
 	{
 	  complaint (&symfile_complaints,
-		     _("DIE at 0x%x has too many recursively imported "
-		       "declarations"), to_underlying (d->sect_off));
+		     _("DIE at %s has too many recursively imported "
+		       "declarations"), sect_offset_str (d->sect_off));
 	  return 0;
 	}
 
@@ -11342,8 +11343,9 @@  read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
 	  {
 	    complaint (&symfile_complaints,
 		       _("child DW_TAG_imported_declaration expected "
-			 "- DIE at 0x%x [in module %s]"),
-		       to_underlying (child_die->sect_off), objfile_name (objfile));
+			 "- DIE at %s [in module %s]"),
+		       sect_offset_str (child_die->sect_off),
+		       objfile_name (objfile));
 	    continue;
 	  }
 
@@ -11363,8 +11365,9 @@  read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
 	  {
 	    complaint (&symfile_complaints,
 		       _("child DW_TAG_imported_declaration has unknown "
-			 "imported name - DIE at 0x%x [in module %s]"),
-		       to_underlying (child_die->sect_off), objfile_name (objfile));
+			 "imported name - DIE at %s [in module %s]"),
+		       sect_offset_str (child_die->sect_off),
+		       objfile_name (objfile));
 	    continue;
 	  }
 
@@ -11901,9 +11904,9 @@  create_dwo_cu_reader (const struct die_reader_specs *reader,
   if (attr == NULL)
     {
       complaint (&symfile_complaints,
-		 _("Dwarf Error: debug entry at offset 0x%x is missing"
+		 _("Dwarf Error: debug entry at offset %s is missing"
 		   " its dwo_id [in module %s]"),
-		 to_underlying (sect_off), dwo_file->dwo_name);
+		 sect_offset_str (sect_off), dwo_file->dwo_name);
       return;
     }
 
@@ -11914,8 +11917,8 @@  create_dwo_cu_reader (const struct die_reader_specs *reader,
   dwo_unit->length = cu->per_cu->length;
 
   if (dwarf_read_debug)
-    fprintf_unfiltered (gdb_stdlog, "  offset 0x%x, dwo_id %s\n",
-			to_underlying (sect_off),
+    fprintf_unfiltered (gdb_stdlog, "  offset %s, dwo_id %s\n",
+			sect_offset_str (sect_off),
 			hex_string (dwo_unit->signature));
 }
 
@@ -11981,9 +11984,9 @@  create_cus_hash_table (struct dwo_file &dwo_file, dwarf2_section_info &section,
 	  sect_offset dup_sect_off = dup_cu->sect_off;
 
 	  complaint (&symfile_complaints,
-		     _("debug cu entry at offset 0x%x is duplicate to"
-		       " the entry at offset 0x%x, signature %s"),
-		     to_underlying (sect_off), to_underlying (dup_sect_off),
+		     _("debug cu entry at offset %s is duplicate to"
+		       " the entry at offset %s, signature %s"),
+		     sect_offset_str (sect_off), sect_offset_str (dup_sect_off),
 		     hex_string (dwo_unit->signature));
 	}
       *slot = (void *)dwo_unit;
@@ -13398,12 +13401,12 @@  lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit,
       dwp_text = string_printf (" [in DWP file %s]",
 				lbasename (dwp_file->name));
 
-    warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
+    warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
 	       " [in module %s]"),
 	     kind, dwo_name, hex_string (signature),
 	     dwp_text.c_str (),
 	     this_unit->is_debug_types ? "TU" : "CU",
-	     to_underlying (this_unit->sect_off), objfile_name (objfile));
+	     sect_offset_str (this_unit->sect_off), objfile_name (objfile));
   }
   return NULL;
 }
@@ -13563,9 +13566,9 @@  inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
       && !(die->tag == DW_TAG_inlined_subroutine
 	   && origin_die->tag == DW_TAG_subprogram))
     complaint (&symfile_complaints,
-	       _("DIE 0x%x and its abstract origin 0x%x have different tags"),
-	       to_underlying (die->sect_off),
-	       to_underlying (origin_die->sect_off));
+	       _("DIE %s and its abstract origin %s have different tags"),
+	       sect_offset_str (die->sect_off),
+	       sect_offset_str (origin_die->sect_off));
 
   std::vector<sect_offset> offsets;
 
@@ -13610,16 +13613,16 @@  inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
 	      && !(child_die->tag == DW_TAG_inlined_subroutine
 		   && child_origin_die->tag == DW_TAG_subprogram))
 	    complaint (&symfile_complaints,
-		       _("Child DIE 0x%x and its abstract origin 0x%x have "
+		       _("Child DIE %s and its abstract origin %s have "
 			 "different tags"),
-		       to_underlying (child_die->sect_off),
-		       to_underlying (child_origin_die->sect_off));
+		       sect_offset_str (child_die->sect_off),
+		       sect_offset_str (child_origin_die->sect_off));
 	  if (child_origin_die->parent != origin_die)
 	    complaint (&symfile_complaints,
-		       _("Child DIE 0x%x and its abstract origin 0x%x have "
+		       _("Child DIE %s and its abstract origin %s have "
 			 "different parents"),
-		       to_underlying (child_die->sect_off),
-		       to_underlying (child_origin_die->sect_off));
+		       sect_offset_str (child_die->sect_off),
+		       sect_offset_str (child_origin_die->sect_off));
 	  else
 	    offsets.push_back (child_origin_die->sect_off);
 	}
@@ -13629,9 +13632,9 @@  inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
   for (offsetp = offsets.data () + 1; offsetp < offsets_end; offsetp++)
     if (offsetp[-1] == *offsetp)
       complaint (&symfile_complaints,
-		 _("Multiple children of DIE 0x%x refer "
-		   "to DIE 0x%x as their abstract origin"),
-		 to_underlying (die->sect_off), to_underlying (*offsetp));
+		 _("Multiple children of DIE %s refer "
+		   "to DIE %s as their abstract origin"),
+		 sect_offset_str (die->sect_off), sect_offset_str (*offsetp));
 
   offsetp = offsets.data ();
   origin_child_die = origin_die->child;
@@ -13696,8 +13699,8 @@  read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
   if (name == NULL)
     {
       complaint (&symfile_complaints,
-		 _("missing name for subprogram DIE at %d"),
-		 to_underlying (die->sect_off));
+		 _("missing name for subprogram DIE at %s"),
+		 sect_offset_str (die->sect_off));
       return;
     }
 
@@ -13709,8 +13712,8 @@  read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
       if (!attr || !DW_UNSND (attr))
 	complaint (&symfile_complaints,
 		   _("cannot get low and high bounds "
-		     "for subprogram DIE at %d"),
-		   to_underlying (die->sect_off));
+		     "for subprogram DIE at %s"),
+		   sect_offset_str (die->sect_off));
       return;
     }
 
@@ -13943,8 +13946,8 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
     {
       complaint (&symfile_complaints,
 		 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
-		   "DIE 0x%x [in module %s]"),
-		 to_underlying (die->sect_off), objfile_name (objfile));
+		   "DIE %s [in module %s]"),
+		 sect_offset_str (die->sect_off), objfile_name (objfile));
       return;
     }
   pc = attr_value_as_address (attr) + baseaddr;
@@ -13960,8 +13963,8 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
     {
       complaint (&symfile_complaints,
 		 _("Duplicate PC %s for DW_TAG_call_site "
-		   "DIE 0x%x [in module %s]"),
-		 paddress (gdbarch, pc), to_underlying (die->sect_off),
+		   "DIE %s [in module %s]"),
+		 paddress (gdbarch, pc), sect_offset_str (die->sect_off),
 		 objfile_name (objfile));
       return;
     }
@@ -13977,8 +13980,8 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	{
 	  complaint (&symfile_complaints,
 		     _("Tag %d is not DW_TAG_call_site_parameter in "
-		       "DW_TAG_call_site child DIE 0x%x [in module %s]"),
-		     child_die->tag, to_underlying (child_die->sect_off),
+		       "DW_TAG_call_site child DIE %s [in module %s]"),
+		     child_die->tag, sect_offset_str (child_die->sect_off),
 		     objfile_name (objfile));
 	  continue;
 	}
@@ -14040,8 +14043,8 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	  else
 	    complaint (&symfile_complaints,
 		       _("Cannot find function owning DW_TAG_call_site "
-			 "DIE 0x%x [in module %s]"),
-		       to_underlying (die->sect_off), objfile_name (objfile));
+			 "DIE %s [in module %s]"),
+		       sect_offset_str (die->sect_off), objfile_name (objfile));
 	}
     }
 
@@ -14087,8 +14090,8 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	  if (target_physname == NULL)
 	    complaint (&symfile_complaints,
 		       _("DW_AT_call_target target DIE has invalid "
-		         "physname, for referencing DIE 0x%x [in module %s]"),
-		       to_underlying (die->sect_off), objfile_name (objfile));
+		         "physname, for referencing DIE %s [in module %s]"),
+		       sect_offset_str (die->sect_off), objfile_name (objfile));
 	  else
 	    SET_FIELD_PHYSNAME (call_site->target, target_physname);
 	}
@@ -14101,8 +14104,8 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	      <= PC_BOUNDS_INVALID)
 	    complaint (&symfile_complaints,
 		       _("DW_AT_call_target target DIE has invalid "
-		         "low pc, for referencing DIE 0x%x [in module %s]"),
-		       to_underlying (die->sect_off), objfile_name (objfile));
+		         "low pc, for referencing DIE %s [in module %s]"),
+		       sect_offset_str (die->sect_off), objfile_name (objfile));
 	  else
 	    {
 	      lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
@@ -14113,8 +14116,8 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
   else
     complaint (&symfile_complaints,
 	       _("DW_TAG_call_site DW_AT_call_target is neither "
-		 "block nor reference, for DIE 0x%x [in module %s]"),
-	       to_underlying (die->sect_off), objfile_name (objfile));
+		 "block nor reference, for DIE %s [in module %s]"),
+	       sect_offset_str (die->sect_off), objfile_name (objfile));
 
   call_site->per_cu = cu->per_cu;
 
@@ -14160,8 +14163,8 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 		 therefore cannot be even moved to DW_TAG_partial_unit.  */
 	      complaint (&symfile_complaints,
 			 _("DW_AT_call_parameter offset is not in CU for "
-			   "DW_TAG_call_site child DIE 0x%x [in module %s]"),
-			 to_underlying (child_die->sect_off),
+			   "DW_TAG_call_site child DIE %s [in module %s]"),
+			 sect_offset_str (child_die->sect_off),
 			 objfile_name (objfile));
 	      continue;
 	    }
@@ -14172,8 +14175,8 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	{
 	  complaint (&symfile_complaints,
 		     _("No DW_FORM_block* DW_AT_location for "
-		       "DW_TAG_call_site child DIE 0x%x [in module %s]"),
-		     to_underlying (child_die->sect_off), objfile_name (objfile));
+		       "DW_TAG_call_site child DIE %s [in module %s]"),
+		     sect_offset_str (child_die->sect_off), objfile_name (objfile));
 	  continue;
 	}
       else
@@ -14191,9 +14194,9 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	      complaint (&symfile_complaints,
 			 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
 			   "for DW_FORM_block* DW_AT_location is supported for "
-			   "DW_TAG_call_site child DIE 0x%x "
+			   "DW_TAG_call_site child DIE %s "
 			   "[in module %s]"),
-			 to_underlying (child_die->sect_off),
+			 sect_offset_str (child_die->sect_off),
 			 objfile_name (objfile));
 	      continue;
 	    }
@@ -14206,8 +14209,8 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	{
 	  complaint (&symfile_complaints,
 		     _("No DW_FORM_block* DW_AT_call_value for "
-		       "DW_TAG_call_site child DIE 0x%x [in module %s]"),
-		     to_underlying (child_die->sect_off),
+		       "DW_TAG_call_site child DIE %s [in module %s]"),
+		     sect_offset_str (child_die->sect_off),
 		     objfile_name (objfile));
 	  continue;
 	}
@@ -14227,8 +14230,8 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	  if (!attr_form_is_block (attr))
 	    complaint (&symfile_complaints,
 		       _("No DW_FORM_block* DW_AT_call_data_value for "
-			 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
-		       to_underlying (child_die->sect_off),
+			 "DW_TAG_call_site child DIE %s [in module %s]"),
+		       sect_offset_str (child_die->sect_off),
 		       objfile_name (objfile));
 	  else
 	    {
@@ -15567,8 +15570,8 @@  dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
 		{
 		  complaint (&symfile_complaints,
 			     _("cannot determine context for virtual member "
-			       "function \"%s\" (offset %d)"),
-			     fieldname, to_underlying (die->sect_off));
+			       "function \"%s\" (offset %s)"),
+			     fieldname, sect_offset_str (die->sect_off));
 		}
 	      else
 		{
@@ -15594,9 +15597,9 @@  dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
 	{
 	  /* GCC does this, as of 2008-08-25; PR debug/37237.  */
 	  complaint (&symfile_complaints,
-		     _("Member function \"%s\" (offset %d) is virtual "
+		     _("Member function \"%s\" (offset %s) is virtual "
 		       "but the vtable offset is not specified"),
-		     fieldname, to_underlying (die->sect_off));
+		     fieldname, sect_offset_str (die->sect_off));
 	  ALLOCATE_CPLUS_STRUCT_TYPE (type);
 	  TYPE_CPLUS_DYNAMIC (type) = 1;
 	}
@@ -16622,8 +16625,8 @@  read_common_block (struct die_info *die, struct dwarf2_cu *cu)
 		  complaint (&symfile_complaints,
 			     _("Variable in common block has "
 			       "DW_AT_data_member_location "
-			       "- DIE at 0x%x [in module %s]"),
-			     to_underlying (child_die->sect_off),
+			       "- DIE at %s [in module %s]"),
+			     sect_offset_str (child_die->sect_off),
 			     objfile_name (cu->objfile));
 
 		  if (attr_form_is_section_offset (member_loc))
@@ -16743,8 +16746,8 @@  read_module_type (struct die_info *die, struct dwarf2_cu *cu)
   module_name = dwarf2_name (die, cu);
   if (!module_name)
     complaint (&symfile_complaints,
-	       _("DW_TAG_module has no name, offset 0x%x"),
-               to_underlying (die->sect_off));
+	       _("DW_TAG_module has no name, offset %s"),
+               sect_offset_str (die->sect_off));
   type = init_type (objfile, TYPE_CODE_MODULE, 0, module_name);
 
   /* determine_prefix uses TYPE_TAG_NAME.  */
@@ -17286,8 +17289,8 @@  read_typedef (struct die_info *die, struct dwarf2_cu *cu)
 	 spec and cause infinite loops in GDB.  */
       complaint (&symfile_complaints,
 		 _("Self-referential DW_TAG_typedef "
-		   "- DIE at 0x%x [in module %s]"),
-		 to_underlying (die->sect_off), objfile_name (objfile));
+		   "- DIE at %s [in module %s]"),
+		 sect_offset_str (die->sect_off), objfile_name (objfile));
       TYPE_TARGET_TYPE (this_type) = NULL;
     }
   return this_type;
@@ -17592,8 +17595,8 @@  read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
     attr_to_dynamic_prop (attr, die, cu, &low);
   else if (!low_default_is_valid)
     complaint (&symfile_complaints, _("Missing DW_AT_lower_bound "
-				      "- DIE at 0x%x [in module %s]"),
-	       to_underlying (die->sect_off), objfile_name (cu->objfile));
+				      "- DIE at %s [in module %s]"),
+	       sect_offset_str (die->sect_off), objfile_name (cu->objfile));
 
   attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
   if (!attr_to_dynamic_prop (attr, die, cu, &high))
@@ -18282,8 +18285,8 @@  load_partial_dies (const struct die_reader_specs *reader,
       if (part_die->tag == DW_TAG_typedef && part_die->has_children)
 	complaint (&symfile_complaints,
 		   _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
-		     "- DIE at 0x%x [in module %s]"),
-		   to_underlying (part_die->sect_off), objfile_name (objfile));
+		     "- DIE at %s [in module %s]"),
+		   sect_offset_str (part_die->sect_off), objfile_name (objfile));
 
       /* If we're at the second level, and we're an enumerator, and
 	 our parent has no specification (meaning possibly lives in a
@@ -18603,9 +18606,10 @@  read_partial_die (const struct die_reader_specs *reader,
 
 	  complaint (&symfile_complaints,
 		     _("DW_AT_low_pc %s is zero "
-		       "for DIE at 0x%x [in module %s]"),
+		       "for DIE at %s [in module %s]"),
 		     paddress (gdbarch, part_die->lowpc),
-		     to_underlying (part_die->sect_off), objfile_name (objfile));
+		     sect_offset_str (part_die->sect_off),
+		     objfile_name (objfile));
 	}
       /* dwarf2_get_pc_bounds has also the strict low < high requirement.  */
       else if (part_die->lowpc >= part_die->highpc)
@@ -18614,10 +18618,10 @@  read_partial_die (const struct die_reader_specs *reader,
 
 	  complaint (&symfile_complaints,
 		     _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
-		       "for DIE at 0x%x [in module %s]"),
+		       "for DIE at %s [in module %s]"),
 		     paddress (gdbarch, part_die->lowpc),
 		     paddress (gdbarch, part_die->highpc),
-		     to_underlying (part_die->sect_off),
+		     sect_offset_str (part_die->sect_off),
 		     objfile_name (objfile));
 	}
       else
@@ -18670,9 +18674,9 @@  find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu)
       /* TUs don't reference other CUs/TUs (except via type signatures).  */
       if (cu->per_cu->is_debug_types)
 	{
-	  error (_("Dwarf Error: Type Unit at offset 0x%x contains"
-		   " external reference to offset 0x%x [in module %s].\n"),
-		 to_underlying (cu->header.sect_off), to_underlying (sect_off),
+	  error (_("Dwarf Error: Type Unit at offset %s contains"
+		   " external reference to offset %s [in module %s].\n"),
+		 sect_offset_str (cu->header.sect_off), sect_offset_str (sect_off),
 		 bfd_get_filename (objfile->obfd));
 	}
       per_cu = dwarf2_find_containing_comp_unit (sect_off, offset_in_dwz,
@@ -18705,9 +18709,9 @@  find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu)
 
   if (pd == NULL)
     internal_error (__FILE__, __LINE__,
-		    _("could not find partial DIE 0x%x "
+		    _("could not find partial DIE %s "
 		      "in cache [from module %s]\n"),
-		    to_underlying (sect_off), bfd_get_filename (objfile->obfd));
+		    sect_offset_str (sect_off), bfd_get_filename (objfile->obfd));
   return pd;
 }
 
@@ -19661,16 +19665,16 @@  read_str_index (const struct die_reader_specs *reader, ULONGEST str_index)
   dwarf2_read_section (objfile, str_offsets_section);
   if (str_section->buffer == NULL)
     error (_("%s used without .debug_str.dwo section"
-	     " in CU at offset 0x%x [in module %s]"),
-	   form_name, to_underlying (cu->header.sect_off), objf_name);
+	     " in CU at offset %s [in module %s]"),
+	   form_name, sect_offset_str (cu->header.sect_off), objf_name);
   if (str_offsets_section->buffer == NULL)
     error (_("%s used without .debug_str_offsets.dwo section"
-	     " in CU at offset 0x%x [in module %s]"),
-	   form_name, to_underlying (cu->header.sect_off), objf_name);
+	     " in CU at offset %s [in module %s]"),
+	   form_name, sect_offset_str (cu->header.sect_off), objf_name);
   if (str_index * cu->header.offset_size >= str_offsets_section->size)
     error (_("%s pointing outside of .debug_str_offsets.dwo"
-	     " section in CU at offset 0x%x [in module %s]"),
-	   form_name, to_underlying (cu->header.sect_off), objf_name);
+	     " section in CU at offset %s [in module %s]"),
+	   form_name, sect_offset_str (cu->header.sect_off), objf_name);
   info_ptr = (str_offsets_section->buffer
 	      + str_index * cu->header.offset_size);
   if (cu->header.offset_size == 4)
@@ -19679,8 +19683,8 @@  read_str_index (const struct die_reader_specs *reader, ULONGEST str_index)
     str_offset = bfd_get_64 (abfd, info_ptr);
   if (str_offset >= str_section->size)
     error (_("Offset from %s pointing outside of"
-	     " .debug_str.dwo section in CU at offset 0x%x [in module %s]"),
-	   form_name, to_underlying (cu->header.sect_off), objf_name);
+	     " .debug_str.dwo section in CU at offset %s [in module %s]"),
+	   form_name, sect_offset_str (cu->header.sect_off), objf_name);
   return (const char *) (str_section->buffer + str_offset);
 }
 
@@ -19827,8 +19831,8 @@  dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *c
       else
         complaint (&symfile_complaints,
 	           _("string type expected for attribute %s for "
-		     "DIE at 0x%x in module %s"),
-		   dwarf_attr_name (name), to_underlying (die->sect_off),
+		     "DIE at %s in module %s"),
+		   dwarf_attr_name (name), sect_offset_str (die->sect_off),
 		   objfile_name (cu->objfile));
     }
 
@@ -21815,10 +21819,10 @@  build_error_marker_type (struct dwarf2_cu *cu, struct die_info *die)
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   char *message, *saved;
 
-  message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
+  message = xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
 			objfile_name (objfile),
-			to_underlying (cu->header.sect_off),
-			to_underlying (die->sect_off));
+			sect_offset_str (cu->header.sect_off),
+			sect_offset_str (die->sect_off));
   saved = (char *) obstack_copy0 (&objfile->objfile_obstack,
 				  message, strlen (message));
   xfree (message);
@@ -21868,8 +21872,8 @@  lookup_die_type (struct die_info *die, const struct attribute *attr,
     {
       complaint (&symfile_complaints,
 		 _("Dwarf Error: Bad type attribute %s in DIE"
-		   " at 0x%x [in module %s]"),
-		 dwarf_attr_name (attr->name), to_underlying (die->sect_off),
+		   " at %s [in module %s]"),
+		 dwarf_attr_name (attr->name), sect_offset_str (die->sect_off),
 		 objfile_name (objfile));
       return build_error_marker_type (cu, die);
     }
@@ -22554,15 +22558,15 @@  dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
   unsigned int i;
 
   print_spaces (indent, f);
-  fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
+  fprintf_unfiltered (f, "Die: %s (abbrev %d, offset %s)\n",
 		      dwarf_tag_name (die->tag), die->abbrev,
-		      to_underlying (die->sect_off));
+		      sect_offset_str (die->sect_off));
 
   if (die->parent != NULL)
     {
       print_spaces (indent, f);
-      fprintf_unfiltered (f, "  parent at offset: 0x%x\n",
-			  to_underlying (die->parent->sect_off));
+      fprintf_unfiltered (f, "  parent at offset: %s\n",
+			  sect_offset_str (die->parent->sect_off));
     }
 
   print_spaces (indent, f);
@@ -22864,9 +22868,9 @@  follow_die_ref (struct die_info *src_die, const struct attribute *attr,
 			    || cu->per_cu->is_dwz),
 			   ref_cu);
   if (!die)
-    error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
-	   "at 0x%x [in module %s]"),
-	   to_underlying (sect_off), to_underlying (src_die->sect_off),
+    error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
+	   "at %s [in module %s]"),
+	   sect_offset_str (sect_off), sect_offset_str (src_die->sect_off),
 	   objfile_name (cu->objfile));
 
   return die;
@@ -22896,14 +22900,14 @@  dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
     {
       /* We shouldn't get here for a dummy CU, but don't crash on the user.
 	 Instead just throw an error, not much else we can do.  */
-      error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
-	     to_underlying (sect_off), objfile_name (per_cu->objfile));
+      error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
+	     sect_offset_str (sect_off), objfile_name (per_cu->objfile));
     }
 
   die = follow_die_offset (sect_off, per_cu->is_dwz, &cu);
   if (!die)
-    error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
-	   to_underlying (sect_off), objfile_name (per_cu->objfile));
+    error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
+	   sect_offset_str (sect_off), objfile_name (per_cu->objfile));
 
   attr = dwarf2_attr (die, DW_AT_location, cu);
   if (!attr)
@@ -22929,9 +22933,9 @@  dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
   else
     {
       if (!attr_form_is_block (attr))
-	error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
+	error (_("Dwarf Error: DIE at %s referenced in module %s "
 		 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
-	       to_underlying (sect_off), objfile_name (per_cu->objfile));
+	       sect_offset_str (sect_off), objfile_name (per_cu->objfile));
 
       retval.data = DW_BLOCK (attr)->data;
       retval.size = DW_BLOCK (attr)->size;
@@ -23004,14 +23008,14 @@  dwarf2_fetch_constant_bytes (sect_offset sect_off,
     {
       /* We shouldn't get here for a dummy CU, but don't crash on the user.
 	 Instead just throw an error, not much else we can do.  */
-      error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
-	     to_underlying (sect_off), objfile_name (per_cu->objfile));
+      error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
+	     sect_offset_str (sect_off), objfile_name (per_cu->objfile));
     }
 
   die = follow_die_offset (sect_off, per_cu->is_dwz, &cu);
   if (!die)
-    error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
-	   to_underlying (sect_off), objfile_name (per_cu->objfile));
+    error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
+	   sect_offset_str (sect_off), objfile_name (per_cu->objfile));
 
 
   attr = dwarf2_attr (die, DW_AT_const_value, cu);
@@ -23217,8 +23221,8 @@  follow_die_sig (struct die_info *src_die, const struct attribute *attr,
   if (sig_type == NULL)
     {
       error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
-               " from DIE at 0x%x [in module %s]"),
-             hex_string (signature), to_underlying (src_die->sect_off),
+               " from DIE at %s [in module %s]"),
+             hex_string (signature), sect_offset_str (src_die->sect_off),
 	     objfile_name ((*ref_cu)->objfile));
     }
 
@@ -23227,8 +23231,8 @@  follow_die_sig (struct die_info *src_die, const struct attribute *attr,
     {
       dump_die_for_error (src_die);
       error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
-	       " from DIE at 0x%x [in module %s]"),
-	     hex_string (signature), to_underlying (src_die->sect_off),
+	       " from DIE at %s [in module %s]"),
+	     hex_string (signature), sect_offset_str (src_die->sect_off),
 	     objfile_name ((*ref_cu)->objfile));
     }
 
@@ -23254,8 +23258,8 @@  get_signatured_type (struct die_info *die, ULONGEST signature,
     {
       complaint (&symfile_complaints,
 		 _("Dwarf Error: Cannot find signatured DIE %s referenced"
-		   " from DIE at 0x%x [in module %s]"),
-		 hex_string (signature), to_underlying (die->sect_off),
+		   " from DIE at %s [in module %s]"),
+		 hex_string (signature), sect_offset_str (die->sect_off),
 		 objfile_name (dwarf2_per_objfile->objfile));
       return build_error_marker_type (cu, die);
     }
@@ -23276,8 +23280,8 @@  get_signatured_type (struct die_info *die, ULONGEST signature,
 	{
 	  complaint (&symfile_complaints,
 		     _("Dwarf Error: Cannot build signatured type %s"
-		       " referenced from DIE at 0x%x [in module %s]"),
-		     hex_string (signature), to_underlying (die->sect_off),
+		       " referenced from DIE at %s [in module %s]"),
+		     hex_string (signature), sect_offset_str (die->sect_off),
 		     objfile_name (dwarf2_per_objfile->objfile));
 	  type = build_error_marker_type (cu, die);
 	}
@@ -23286,8 +23290,8 @@  get_signatured_type (struct die_info *die, ULONGEST signature,
     {
       complaint (&symfile_complaints,
 		 _("Dwarf Error: Problem reading signatured DIE %s referenced"
-		   " from DIE at 0x%x [in module %s]"),
-		 hex_string (signature), to_underlying (die->sect_off),
+		   " from DIE at %s [in module %s]"),
+		 hex_string (signature), sect_offset_str (die->sect_off),
 		 objfile_name (dwarf2_per_objfile->objfile));
       type = build_error_marker_type (cu, die);
     }
@@ -23319,8 +23323,8 @@  get_DW_AT_signature_type (struct die_info *die, const struct attribute *attr,
     {
       complaint (&symfile_complaints,
 		 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
-		   " at 0x%x [in module %s]"),
-		 dwarf_form_name (attr->form), to_underlying (die->sect_off),
+		   " at %s [in module %s]"),
+		 dwarf_form_name (attr->form), sect_offset_str (die->sect_off),
 		 objfile_name (dwarf2_per_objfile->objfile));
       return build_error_marker_type (cu, die);
     }
@@ -24922,8 +24926,8 @@  dwarf2_find_containing_comp_unit (sect_offset sect_off,
     {
       if (low == 0 || this_cu->is_dwz != offset_in_dwz)
 	error (_("Dwarf Error: could not find partial DIE containing "
-	       "offset 0x%x [in module %s]"),
-	       to_underlying (sect_off), bfd_get_filename (objfile->obfd));
+	       "offset %s [in module %s]"),
+	       sect_offset_str (sect_off), bfd_get_filename (objfile->obfd));
 
       gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->sect_off
 		  <= sect_off);
@@ -24934,7 +24938,7 @@  dwarf2_find_containing_comp_unit (sect_offset sect_off,
       this_cu = dwarf2_per_objfile->all_comp_units[low];
       if (low == dwarf2_per_objfile->n_comp_units - 1
 	  && sect_off >= this_cu->sect_off + this_cu->length)
-	error (_("invalid dwarf2 offset %u"), to_underlying (sect_off));
+	error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off));
       gdb_assert (sect_off < this_cu->sect_off + this_cu->length);
       return this_cu;
     }
@@ -25198,9 +25202,9 @@  set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
   else if (attr != NULL)
     {
       complaint (&symfile_complaints,
-		 _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"),
+		 _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
 		 (attr != NULL ? dwarf_form_name (attr->form) : "n/a"),
-		 to_underlying (die->sect_off));
+		 sect_offset_str (die->sect_off));
     }
 
   /* Read DW_AT_associated and set in type.  */
@@ -25213,9 +25217,9 @@  set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
   else if (attr != NULL)
     {
       complaint (&symfile_complaints,
-		 _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"),
+		 _("DW_AT_associated has the wrong form (%s) at DIE %s"),
 		 (attr != NULL ? dwarf_form_name (attr->form) : "n/a"),
-		 to_underlying (die->sect_off));
+		 sect_offset_str (die->sect_off));
     }
 
   /* Read DW_AT_data_location and set in type.  */
@@ -25242,8 +25246,8 @@  set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
     htab_find_slot (dwarf2_per_objfile->die_type_hash, &ofs, INSERT);
   if (*slot)
     complaint (&symfile_complaints,
-	       _("A problem internal to GDB: DIE 0x%x has type already set"),
-	       to_underlying (die->sect_off));
+	       _("A problem internal to GDB: DIE %s has type already set"),
+	       sect_offset_str (die->sect_off));
   *slot = XOBNEW (&objfile->objfile_obstack,
 		  struct dwarf2_per_cu_offset_and_type);
   **slot = ofs;
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 68ffaf8..8b35fc5 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -47,6 +47,8 @@ 
 #include "hashtab.h"
 #include "common/offset-type.h"
 #include "common/enum-flags.h"
+#include "common/underlying.h"
+#include "common/print-utils.h"
 
 /* Forward declarations for prototypes.  */
 struct field;
@@ -63,7 +65,13 @@  DEFINE_OFFSET_TYPE (cu_offset, unsigned int);
 
 /* * Offset relative to the start of its .debug_info or .debug_types
    section.  */
-DEFINE_OFFSET_TYPE (sect_offset, unsigned int);
+DEFINE_OFFSET_TYPE (sect_offset, uint64_t);
+
+static inline char *
+sect_offset_str (sect_offset offset)
+{
+  return hex_string (to_underlying (offset));
+}
 
 /* Some macros for char-based bitfields.  */