+2020-09-29  Tom Tromey  <tom@tromey.com>
+
+       * dwarf2/read.c (anonymous_struct_prefix, dwarf2_name)
+       (dump_die_shallow): Use canonical_string_p.
+       * dwarf2/attribute.h (struct attribute) <canonical_string_p>: New
+       method.
+
 2020-09-29  Tom Tromey  <tom@tromey.com>
 
        * dwarf2/read.c (partial_die_info::read)
 
 
   LONGEST constant_value (int default_value) const;
 
+  /* Return true if this attribute holds a canonical string.  In some
+     cases, like C++ names, gdb will rewrite the name of a DIE to a
+     canonical form.  This makes lookups robust when a name can be
+     spelled different ways (e.g., "signed" or "signed int").  This
+     flag indicates whether the value has been canonicalized.  */
+  bool canonical_string_p () const
+  {
+    return string_is_canonical;
+  }
+
 
   ENUM_BITFIELD(dwarf_attribute) name : 16;
   ENUM_BITFIELD(dwarf_form) form : 15;
 
     return NULL;
 
   /* dwarf2_name had to be already called.  */
-  gdb_assert (DW_STRING_IS_CANONICAL (attr));
+  gdb_assert (attr->canonical_string_p ());
 
   /* Strip the base name, keep any leading namespaces/classes.  */
   base = strrchr (attr_name, ':');
 
          /* Avoid demangling attr_name the second time on a second
             call for the same DIE.  */
-         if (!DW_STRING_IS_CANONICAL (attr))
+         if (!attr->canonical_string_p ())
            {
              gdb::unique_xmalloc_ptr<char> demangled
                (gdb_demangle (attr_name, DMGL_TYPES));
       break;
     }
 
-  if (!DW_STRING_IS_CANONICAL (attr))
+  if (!attr->canonical_string_p ())
     {
       DW_STRING (attr) = dwarf2_canonicalize_name (attr_name, cu,
                                                   objfile);
          fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
                   DW_STRING (&die->attrs[i])
                   ? DW_STRING (&die->attrs[i]) : "",
-                  DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
+                  die->attrs[i].canonical_string_p () ? "is" : "not");
          break;
        case DW_FORM_flag:
          if (DW_UNSND (&die->attrs[i]))