[PATCH 07/20] Remove DW_BLOCK

Tom Tromey
2020-03-28T19:22:12Z

This removes the DW_BLOCK accessor in favor of methods on struct
attribute. The methods, unlike the access, check the form.

Note that DW_FORM_data16 had to be handled by form_is_block, because
in practice that is how we store values of this form.

2020-03-28 Tom Tromey <tom@tromey.com>

* dwarf2/read.c (read_call_site_scope)
(handle_data_member_location, dwarf2_add_member_fn)
(mark_common_block_symbol_computed, attr_to_dynamic_prop)
(partial_die_info::read, read_attribute_value)
(var_decode_location, dwarf2_const_value_attr, dump_die_shallow)
(dwarf2_fetch_die_loc_sect_off, dwarf2_fetch_constant_bytes)
(dwarf2_symbol_mark_computed): Update.
* dwarf2/attribute.h (struct attribute) <block, set_block>: New
methods.
(DW_BLOCK): Remove.
* dwarf2/attribute.c (attribute::form_is_block): Add
DW_FORM_data16.
---
gdb/ChangeLog | 15 ++++++
gdb/dwarf2/attribute.c | 3 +-
gdb/dwarf2/attribute.h | 15 +++++-
gdb/dwarf2/read.c | 102 ++++++++++++++++++++---------------------
4 files changed, 82 insertions(+), 53 deletions(-)

diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index 06b3245e4b2..fdf202033e9 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -94,7 +94,8 @@ attribute::form_is_block () const
|| form == DW_FORM_block2
|| form == DW_FORM_block4
|| form == DW_FORM_block
- || form == DW_FORM_exprloc);
+ || form == DW_FORM_exprloc
+ || form == DW_FORM_data16);
}

/* See attribute.h. */
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index 49989211018..f59986f78a3 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -50,6 +50,13 @@ struct attribute
otherwise return NULL. */
const char *string () const;

+ /* Return the block value. The attribute must have block form. */
+ dwarf_block *block () const
+ {
+ gdb_assert (form_is_block ());
+ return u.blk;
+ }
+
/* Return non-zero if ATTR's value is a section offset --- classes
lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
You may use DW_UNSND (attr) to retrieve such offsets.
@@ -125,6 +132,13 @@ struct attribute
string_is_canonical = 1;
}

+ /* Set the block value for this attribute. */
+ void set_block (dwarf_block *blk)
+ {
+ gdb_assert (form_is_block ());
+ u.blk = blk;
+ }
+

ENUM_BITFIELD(dwarf_attribute) name : 16;
ENUM_BITFIELD(dwarf_form) form : 15;
@@ -149,7 +163,6 @@ struct attribute
/* Get at parts of an attribute structure. */

#define DW_UNSND(attr) ((attr)->u.unsnd)
-#define DW_BLOCK(attr) ((attr)->u.blk)
#define DW_SND(attr) ((attr)->u.snd)
#define DW_ADDR(attr) ((attr)->u.addr)
#define DW_SIGNATURE(attr) ((attr)->u.signature)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index e3223e92d43..87bce7e51a9 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -13127,15 +13127,15 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
}
SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
- if (!attr || (attr->form_is_block () && DW_BLOCK (attr)->size == 0))
+ if (!attr || (attr->form_is_block () && attr->block ()->size == 0))
/* Keep NULL DWARF_BLOCK. */;
else if (attr->form_is_block ())
{
struct dwarf2_locexpr_baton *dlbaton;

dlbaton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton);
- dlbaton->data = DW_BLOCK (attr)->data;
- dlbaton->size = DW_BLOCK (attr)->size;
+ dlbaton->data = attr->block ()->data;
+ dlbaton->size = attr->block ()->size;
dlbaton->per_cu = cu->per_cu;

SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
@@ -13244,11 +13244,11 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
else
{
parameter->u.dwarf_reg = dwarf_block_to_dwarf_reg
- (DW_BLOCK (loc)->data, &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size]);
+ (loc->block ()->data, &loc->block ()->data[loc->block ()->size]);
if (parameter->u.dwarf_reg != -1)
parameter->kind = CALL_SITE_PARAMETER_DWARF_REG;
- else if (dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (loc)->data,
- &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size],
+ else if (dwarf_block_to_sp_offset (gdbarch, loc->block ()->data,
+ &loc->block ()->data[loc->block ()->size],
&parameter->u.fb_offset))
parameter->kind = CALL_SITE_PARAMETER_FB_OFFSET;
else
@@ -13274,8 +13274,8 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
objfile_name (objfile));
continue;
}
- parameter->value = DW_BLOCK (attr)->data;
- parameter->value_size = DW_BLOCK (attr)->size;
+ parameter->value = attr->block ()->data;
+ parameter->value_size = attr->block ()->size;

/* Parameters are not pre-cleared by memset above. */
parameter->data_value = NULL;
@@ -13294,8 +13294,8 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
objfile_name (objfile));
else
{
- parameter->data_value = DW_BLOCK (attr)->data;
- parameter->data_value_size = DW_BLOCK (attr)->size;
+ parameter->data_value = attr->block ()->data;
+ parameter->data_value_size = attr->block ()->size;
}
}
}
@@ -14057,7 +14057,7 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
else if (attr->form_is_section_offset ())
dwarf2_complex_location_expr_complaint ();
else if (attr->form_is_block ())
- *offset = decode_locdesc (DW_BLOCK (attr), cu);
+ *offset = decode_locdesc (attr->block (), cu);
else
dwarf2_complex_location_expr_complaint ();

@@ -14632,19 +14632,19 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
if (attr != nullptr)
{
- if (attr->form_is_block () && DW_BLOCK (attr)->size > 0)
+ if (attr->form_is_block () && attr->block ()->size > 0)
{
- if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
+ if (attr->block ()->data[0] == DW_OP_constu)
{
/* Old-style GCC. */
- fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
+ fnp->voffset = decode_locdesc (attr->block (), cu) + 2;
}
- else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
- || (DW_BLOCK (attr)->size > 1
- && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
- && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
+ else if (attr->block ()->data[0] == DW_OP_deref
+ || (attr->block ()->size > 1
+ && attr->block ()->data[0] == DW_OP_deref_size
+ && attr->block ()->data[1] == cu->header.addr_size))
{
- fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
+ fnp->voffset = decode_locdesc (attr->block (), cu);
if ((fnp->voffset % cu->header.addr_size) != 0)
dwarf2_complex_location_expr_complaint ();
else
@@ -15858,7 +15858,7 @@ mark_common_block_symbol_computed (struct symbol *sym,
baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size;
}
else
- baton->size += DW_BLOCK (member_loc)->size;
+ baton->size += member_loc->block ()->size;

ptr = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, baton->size);
baton->data = ptr;
@@ -15878,8 +15878,8 @@ mark_common_block_symbol_computed (struct symbol *sym,
{
/* We have to copy the data here, because DW_OP_call4 will only
use a DW_AT_location attribute. */
- memcpy (ptr, DW_BLOCK (member_loc)->data, DW_BLOCK (member_loc)->size);
- ptr += DW_BLOCK (member_loc)->size;
+ memcpy (ptr, member_loc->block ()->data, member_loc->block ()->size);
+ ptr += member_loc->block ()->size;
}

*ptr++ = DW_OP_plus;
@@ -16971,8 +16971,8 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
baton = XOBNEW (obstack, struct dwarf2_property_baton);
baton->property_type = default_type;
baton->locexpr.per_cu = cu->per_cu;
- baton->locexpr.size = DW_BLOCK (attr)->size;
- baton->locexpr.data = DW_BLOCK (attr)->data;
+ baton->locexpr.size = attr->block ()->size;
+ baton->locexpr.data = attr->block ()->data;
switch (attr->name)
{
case DW_AT_string_length:
@@ -17017,8 +17017,8 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
baton = XOBNEW (obstack, struct dwarf2_property_baton);
baton->property_type = die_type (target_die, target_cu);
baton->locexpr.per_cu = cu->per_cu;
- baton->locexpr.size = DW_BLOCK (target_attr)->size;
- baton->locexpr.data = DW_BLOCK (target_attr)->data;
+ baton->locexpr.size = target_attr->block ()->size;
+ baton->locexpr.data = target_attr->block ()->data;
baton->locexpr.is_reference = true;
prop->data.baton = baton;
prop->kind = PROP_LOCEXPR;
@@ -17911,7 +17911,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
/* Support the .debug_loc offsets. */
if (attr.form_is_block ())
{
- d.locdesc = DW_BLOCK (&attr);
+ d.locdesc = attr.block ();
}
else if (attr.form_is_section_offset ())
{
@@ -18378,7 +18378,7 @@ read_attribute_value (const struct die_reader_specs *reader,
info_ptr += 2;
blk->data = read_n_bytes (abfd, info_ptr, blk->size);
info_ptr += blk->size;
- DW_BLOCK (attr) = blk;
+ attr->set_block (blk);
break;
case DW_FORM_block4:
blk = dwarf_alloc_block (cu);
@@ -18386,7 +18386,7 @@ read_attribute_value (const struct die_reader_specs *reader,
info_ptr += 4;
blk->data = read_n_bytes (abfd, info_ptr, blk->size);
info_ptr += blk->size;
- DW_BLOCK (attr) = blk;
+ attr->set_block (blk);
break;
case DW_FORM_data2:
DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
@@ -18405,7 +18405,7 @@ read_attribute_value (const struct die_reader_specs *reader,
blk->size = 16;
blk->data = read_n_bytes (abfd, info_ptr, 16);
info_ptr += 16;
- DW_BLOCK (attr) = blk;
+ attr->set_block (blk);
break;
case DW_FORM_sec_offset:
DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr, &bytes_read);
@@ -18452,7 +18452,7 @@ read_attribute_value (const struct die_reader_specs *reader,
info_ptr += bytes_read;
blk->data = read_n_bytes (abfd, info_ptr, blk->size);
info_ptr += blk->size;
- DW_BLOCK (attr) = blk;
+ attr->set_block (blk);
break;
case DW_FORM_block1:
blk = dwarf_alloc_block (cu);
@@ -18460,7 +18460,7 @@ read_attribute_value (const struct die_reader_specs *reader,
info_ptr += 1;
blk->data = read_n_bytes (abfd, info_ptr, blk->size);
info_ptr += blk->size;
- DW_BLOCK (attr) = blk;
+ attr->set_block (blk);
break;
case DW_FORM_data1:
DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
@@ -19920,7 +19920,7 @@ var_decode_location (struct attribute *attr, struct symbol *sym,

/* A DW_AT_location attribute with no contents indicates that a
variable has been optimized away. */
- if (attr->form_is_block () && DW_BLOCK (attr)->size == 0)
+ if (attr->form_is_block () && attr->block ()->size == 0)
{
SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
return;
@@ -19932,23 +19932,23 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */

if (attr->form_is_block ()
- && ((DW_BLOCK (attr)->data[0] == DW_OP_addr
- && DW_BLOCK (attr)->size == 1 + cu_header->addr_size)
- || ((DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index
- || DW_BLOCK (attr)->data[0] == DW_OP_addrx)
- && (DW_BLOCK (attr)->size
- == 1 + leb128_size (&DW_BLOCK (attr)->data[1])))))
+ && ((attr->block ()->data[0] == DW_OP_addr
+ && attr->block ()->size == 1 + cu_header->addr_size)
+ || ((attr->block ()->data[0] == DW_OP_GNU_addr_index
+ || attr->block ()->data[0] == DW_OP_addrx)
+ && (attr->block ()->size
+ == 1 + leb128_size (&attr->block ()->data[1])))))
{
unsigned int dummy;

- if (DW_BLOCK (attr)->data[0] == DW_OP_addr)
+ if (attr->block ()->data[0] == DW_OP_addr)
SET_SYMBOL_VALUE_ADDRESS
(sym, cu->header.read_address (objfile->obfd,
- DW_BLOCK (attr)->data + 1,
+ attr->block ()->data + 1,
&dummy));
else
SET_SYMBOL_VALUE_ADDRESS
- (sym, read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1,
+ (sym, read_addr_index_from_leb128 (cu, attr->block ()->data + 1,
&dummy));
SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
fixup_symbol_section (sym, objfile);
@@ -20481,7 +20481,7 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
case DW_FORM_block:
case DW_FORM_exprloc:
case DW_FORM_data16:
- blk = DW_BLOCK (attr);
+ blk = attr->block ();
if (TYPE_LENGTH (type) != blk->size)
dwarf2_const_value_length_mismatch_complaint (name, blk->size,
TYPE_LENGTH (type));
@@ -21343,11 +21343,11 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
case DW_FORM_block:
case DW_FORM_block1:
fprintf_unfiltered (f, "block: size %s",
- pulongest (DW_BLOCK (&die->attrs[i])->size));
+ pulongest (die->attrs[i].block ()->size));
break;
case DW_FORM_exprloc:
fprintf_unfiltered (f, "expression: size %s",
- pulongest (DW_BLOCK (&die->attrs[i])->size));
+ pulongest (die->attrs[i].block ()->size));
break;
case DW_FORM_data16:
fprintf_unfiltered (f, "constant of 16 bytes");
@@ -21685,8 +21685,8 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
"is neither DW_FORM_block* nor DW_FORM_exprloc"),
sect_offset_str (sect_off), objfile_name (objfile));

- retval.data = DW_BLOCK (attr)->data;
- retval.size = DW_BLOCK (attr)->size;
+ retval.data = attr->block ()->data;
+ retval.size = attr->block ()->size;
}
retval.per_cu = cu->per_cu;

@@ -21797,8 +21797,8 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off,
case DW_FORM_block:
case DW_FORM_exprloc:
case DW_FORM_data16:
- result = DW_BLOCK (attr)->data;
- *len = DW_BLOCK (attr)->size;
+ result = attr->block ()->data;
+ *len = attr->block ()->size;
break;

/* The DW_AT_const_value attributes are supposed to carry the
@@ -22578,8 +22578,8 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
info_buffer for SYM's objfile; right now we never release
that buffer, but when we do clean up properly this may
need to change. */
- baton->size = DW_BLOCK (attr)->size;
- baton->data = DW_BLOCK (attr)->data;
+ baton->size = attr->block ()->size;
+ baton->data = attr->block ()->data;
}
else
{
--
2.17.2