+2020-09-29 Tom Tromey <tom@tromey.com>
+
+ * dwarf2/read.c (read_cutu_die_from_dwo)
+ (read_attribute_reprocess, read_attribute_value, read_attribute)
+ (dwarf2_const_value_attr, dwarf2_name, dump_die_shallow)
+ (dwarf2_fetch_constant_bytes): Update.
+ * dwarf2/attribute.h (struct attribute) <form_is_string>: Declare.
+ <set_string_noncanonical, set_string_canonical>: New methods.
+ <string_is_canonical>: Update comment.
+ <canonical_string_p>: Add assert.
+ (DW_STRING, DW_STRING_IS_CANONICAL): Remove.
+ * dwarf2/attribute.c (attribute::form_is_string): New method.
+ (attribute::string): Use it.
+
2020-09-29 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (anonymous_struct_prefix, dwarf2_name)
/* See attribute.h. */
+bool
+attribute::form_is_string () const
+{
+ return (form == DW_FORM_strp || form == DW_FORM_line_strp
+ || form == DW_FORM_string
+ || form == DW_FORM_strx
+ || form == DW_FORM_strx1
+ || form == DW_FORM_strx2
+ || form == DW_FORM_strx3
+ || form == DW_FORM_strx4
+ || form == DW_FORM_GNU_str_index
+ || form == DW_FORM_GNU_strp_alt);
+}
+
+/* See attribute.h. */
+
const char *
attribute::as_string () const
{
- if (form == DW_FORM_strp || form == DW_FORM_line_strp
- || form == DW_FORM_string
- || form == DW_FORM_strx
- || form == DW_FORM_strx1
- || form == DW_FORM_strx2
- || form == DW_FORM_strx3
- || form == DW_FORM_strx4
- || form == DW_FORM_GNU_str_index
- || form == DW_FORM_GNU_strp_alt)
+ if (form_is_string ())
return u.str;
return nullptr;
}
bool form_is_block () const;
+ /* Check if the attribute's form is a string form. */
+ bool form_is_string () const;
+
/* Return DIE offset of this attribute. Return 0 with complaint if
the attribute is not of the required kind. */
flag indicates whether the value has been canonicalized. */
bool canonical_string_p () const
{
+ gdb_assert (form_is_string ());
return string_is_canonical;
}
+ /* Initialize this attribute to hold a non-canonical string
+ value. */
+ void set_string_noncanonical (const char *str)
+ {
+ gdb_assert (form_is_string ());
+ u.str = str;
+ string_is_canonical = 0;
+ }
+
+ /* Set the canonical string value for this attribute. */
+ void set_string_canonical (const char *str)
+ {
+ gdb_assert (form_is_string ());
+ u.str = str;
+ string_is_canonical = 1;
+ }
+
ENUM_BITFIELD(dwarf_attribute) name : 16;
ENUM_BITFIELD(dwarf_form) form : 15;
- /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
- field should be in u.str (existing only for DW_STRING) but it is kept
- here for better struct attribute alignment. */
+ /* Has u.str already been updated by dwarf2_canonicalize_name? This
+ field should be in u.str but it is kept here for better struct
+ attribute alignment. */
unsigned int string_is_canonical : 1;
union
/* Get at parts of an attribute structure. */
-#define DW_STRING(attr) ((attr)->u.str)
-#define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
#define DW_UNSND(attr) ((attr)->u.unsnd)
#define DW_BLOCK(attr) ((attr)->u.blk)
#define DW_SND(attr) ((attr)->u.snd)
comp_dir = XOBNEW (&cu->comp_unit_obstack, struct attribute);
comp_dir->name = DW_AT_comp_dir;
comp_dir->form = DW_FORM_string;
- DW_STRING_IS_CANONICAL (comp_dir) = 0;
- DW_STRING (comp_dir) = stub_comp_dir;
+ comp_dir->set_string_noncanonical (stub_comp_dir);
}
/* Set up for reading the DWO CU/TU. */
case DW_FORM_GNU_str_index:
{
unsigned int str_index = DW_UNSND (attr);
+ gdb_assert (!attr->canonical_string_p ());
if (reader->dwo_file != NULL)
- {
- DW_STRING (attr) = read_dwo_str_index (reader, str_index);
- DW_STRING_IS_CANONICAL (attr) = 0;
- }
+ attr->set_string_noncanonical (read_dwo_str_index (reader,
+ str_index));
else
- {
- DW_STRING (attr) = read_stub_str_index (cu, str_index);
- DW_STRING_IS_CANONICAL (attr) = 0;
- }
+ attr->set_string_noncanonical (read_stub_str_index (cu,
+ str_index));
break;
}
default:
}
break;
case DW_FORM_string:
- DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
- DW_STRING_IS_CANONICAL (attr) = 0;
+ attr->set_string_noncanonical (read_direct_string (abfd, info_ptr,
+ &bytes_read));
info_ptr += bytes_read;
break;
case DW_FORM_strp:
if (!cu->per_cu->is_dwz)
{
- DW_STRING (attr) = read_indirect_string (per_objfile,
- abfd, info_ptr, cu_header,
- &bytes_read);
- DW_STRING_IS_CANONICAL (attr) = 0;
+ attr->set_string_noncanonical
+ (read_indirect_string (per_objfile,
+ abfd, info_ptr, cu_header,
+ &bytes_read));
info_ptr += bytes_read;
break;
}
case DW_FORM_line_strp:
if (!cu->per_cu->is_dwz)
{
- DW_STRING (attr) = per_objfile->read_line_string (info_ptr, cu_header,
- &bytes_read);
- DW_STRING_IS_CANONICAL (attr) = 0;
+ attr->set_string_noncanonical
+ (per_objfile->read_line_string (info_ptr, cu_header,
+ &bytes_read));
info_ptr += bytes_read;
break;
}
LONGEST str_offset = cu_header->read_offset (abfd, info_ptr,
&bytes_read);
- DW_STRING (attr) = dwz->read_string (objfile, str_offset);
- DW_STRING_IS_CANONICAL (attr) = 0;
+ attr->set_string_noncanonical
+ (dwz->read_string (objfile, str_offset));
info_ptr += bytes_read;
}
break;
const gdb_byte *info_ptr, bool *need_reprocess)
{
attr->name = abbrev->name;
+ attr->string_is_canonical = 0;
return read_attribute_value (reader, attr, abbrev->form,
abbrev->implicit_const, info_ptr,
need_reprocess);
case DW_FORM_strx:
case DW_FORM_GNU_str_index:
case DW_FORM_GNU_strp_alt:
- /* DW_STRING is already allocated on the objfile obstack, point
+ /* The string is already allocated on the objfile obstack, point
directly to it. */
*bytes = (const gdb_byte *) attr->as_string ();
break;
if (demangled == nullptr)
return nullptr;
- DW_STRING (attr) = objfile->intern (demangled.get ());
- DW_STRING_IS_CANONICAL (attr) = 1;
+ attr->set_string_canonical (objfile->intern (demangled.get ()));
}
/* Strip any leading namespaces/classes, keep only the
}
if (!attr->canonical_string_p ())
- {
- DW_STRING (attr) = dwarf2_canonicalize_name (attr_name, cu,
- objfile);
- DW_STRING_IS_CANONICAL (attr) = 1;
- }
-
- /* We might have changed it just above. */
+ attr->set_string_canonical (dwarf2_canonicalize_name (attr_name, cu,
+ objfile));
return attr->as_string ();
}
case DW_FORM_GNU_str_index:
case DW_FORM_GNU_strp_alt:
fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
- DW_STRING (&die->attrs[i])
- ? DW_STRING (&die->attrs[i]) : "",
- die->attrs[i].canonical_string_p () ? "is" : "not");
+ die->attrs[i].as_string ()
+ ? die->attrs[i].as_string () : "",
+ die->attrs[i].canonical_string_p () ? "is" : "not");
break;
case DW_FORM_flag:
if (DW_UNSND (&die->attrs[i]))
case DW_FORM_strx:
case DW_FORM_GNU_str_index:
case DW_FORM_GNU_strp_alt:
- /* DW_STRING is already allocated on the objfile obstack, point
+ /* The string is already allocated on the objfile obstack, point
directly to it. */
{
const char *attr_name = attr->as_string ();