From 4fc6c0d5345d4268ae43b128a0be3d8cb30c4ab4 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 8 Feb 2020 13:40:54 -0700 Subject: [PATCH] Change attr_form_is_block to be a method This changes attr_form_is_block to be a method. This is done separately because, unlike the other attribute functions, attr_form_is_block had special handling for the case where the argument was NULL. This required auditing each call site; in most cases, NULL was already ruled out, but in a few spots, an additional check was needed. gdb/ChangeLog 2020-02-08 Tom Tromey * dwarf2read.c (read_call_site_scope) (handle_data_member_location, dwarf2_add_member_fn) (mark_common_block_symbol_computed, read_common_block) (attr_to_dynamic_prop, partial_die_info::read) (var_decode_location, dwarf2_fetch_die_loc_sect_off) (dwarf2_symbol_mark_computed, set_die_type): Update. * dwarf2/attribute.h (struct attribute) : Declare method. (attr_form_is_block): Don't declare. * dwarf2/attribute.c (attribute::form_is_block): Now a method. Change-Id: Idfb290c61d738301ab991666f43e0b9cf577b2ae --- gdb/ChangeLog | 13 +++++++++++++ gdb/dwarf2/attribute.c | 15 +++++++-------- gdb/dwarf2/attribute.h | 10 +++++----- gdb/dwarf2read.c | 40 ++++++++++++++++++++-------------------- 4 files changed, 45 insertions(+), 33 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 331fad46905..fc15d0d5e5b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +2020-02-08 Tom Tromey + + * dwarf2read.c (read_call_site_scope) + (handle_data_member_location, dwarf2_add_member_fn) + (mark_common_block_symbol_computed, read_common_block) + (attr_to_dynamic_prop, partial_die_info::read) + (var_decode_location, dwarf2_fetch_die_loc_sect_off) + (dwarf2_symbol_mark_computed, set_die_type): Update. + * dwarf2/attribute.h (struct attribute) : Declare + method. + (attr_form_is_block): Don't declare. + * dwarf2/attribute.c (attribute::form_is_block): Now a method. + 2020-02-08 Tom Tromey * dwarf2read.c (dwarf2_find_base_address, ) diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c index 6e51fff5362..6efff3e2c0a 100644 --- a/gdb/dwarf2/attribute.c +++ b/gdb/dwarf2/attribute.c @@ -59,15 +59,14 @@ attribute::value_as_address () const /* See attribute.h. */ -int -attr_form_is_block (const struct attribute *attr) +bool +attribute::form_is_block () const { - return (attr == NULL ? 0 : - attr->form == DW_FORM_block1 - || attr->form == DW_FORM_block2 - || attr->form == DW_FORM_block4 - || attr->form == DW_FORM_block - || attr->form == DW_FORM_exprloc); + return (form == DW_FORM_block1 + || form == DW_FORM_block2 + || form == DW_FORM_block4 + || form == DW_FORM_block + || form == DW_FORM_exprloc); } /* See attribute.h. */ diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h index 2e663f1560c..c2602310715 100644 --- a/gdb/dwarf2/attribute.h +++ b/gdb/dwarf2/attribute.h @@ -79,6 +79,11 @@ struct attribute bool form_is_ref () const; + /* Check if the attribute's form is a DW_FORM_block* + if so return true else false. */ + + bool form_is_block () const; + ENUM_BITFIELD(dwarf_attribute) name : 16; ENUM_BITFIELD(dwarf_form) form : 15; @@ -110,9 +115,4 @@ struct attribute #define DW_ADDR(attr) ((attr)->u.addr) #define DW_SIGNATURE(attr) ((attr)->u.signature) -/* Check if the attribute's form is a DW_FORM_block* - if so return true else false. */ - -extern int attr_form_is_block (const struct attribute *attr); - #endif /* GDB_DWARF2_ATTRIBUTE_H */ diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 0df5eef27c2..7a9de41e7d8 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -13693,9 +13693,9 @@ 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 (attr) && DW_BLOCK (attr)->size == 0)) + if (!attr || (attr->form_is_block () && DW_BLOCK (attr)->size == 0)) /* Keep NULL DWARF_BLOCK. */; - else if (attr_form_is_block (attr)) + else if (attr->form_is_block ()) { struct dwarf2_locexpr_baton *dlbaton; @@ -13801,7 +13801,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) parameter->u.param_cu_off = (cu_offset) (sect_off - cu->header.sect_off); } - else if (loc == NULL || origin != NULL || !attr_form_is_block (loc)) + else if (loc == NULL || origin != NULL || !loc->form_is_block ()) { complaint (_("No DW_FORM_block* DW_AT_location for " "DW_TAG_call_site child DIE %s [in module %s]"), @@ -13833,7 +13833,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) attr = dwarf2_attr (child_die, DW_AT_call_value, cu); if (attr == NULL) attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu); - if (!attr_form_is_block (attr)) + if (attr == NULL || !attr->form_is_block ()) { complaint (_("No DW_FORM_block* DW_AT_call_value for " "DW_TAG_call_site child DIE %s [in module %s]"), @@ -13854,7 +13854,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu); if (attr != nullptr) { - if (!attr_form_is_block (attr)) + if (!attr->form_is_block ()) complaint (_("No DW_FORM_block* DW_AT_call_data_value for " "DW_TAG_call_site child DIE %s [in module %s]"), sect_offset_str (child_die->sect_off), @@ -14627,7 +14627,7 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, *offset = dwarf2_get_attr_constant_value (attr, 0); else if (attr->form_is_section_offset ()) dwarf2_complex_location_expr_complaint (); - else if (attr_form_is_block (attr)) + else if (attr->form_is_block ()) *offset = decode_locdesc (DW_BLOCK (attr), cu); else dwarf2_complex_location_expr_complaint (); @@ -15205,7 +15205,7 @@ 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 (attr) && DW_BLOCK (attr)->size > 0) + if (attr->form_is_block () && DW_BLOCK (attr)->size > 0) { if (DW_BLOCK (attr)->data[0] == DW_OP_constu) { @@ -16416,8 +16416,8 @@ mark_common_block_symbol_computed (struct symbol *sym, LONGEST offset = 0; gdb_assert (common_loc && member_loc); - gdb_assert (attr_form_is_block (common_loc)); - gdb_assert (attr_form_is_block (member_loc) + gdb_assert (common_loc->form_is_block ()); + gdb_assert (member_loc->form_is_block () || member_loc->form_is_constant ()); baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton); @@ -16478,7 +16478,7 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu) if (attr != nullptr) { /* Support the .debug_loc offsets. */ - if (attr_form_is_block (attr)) + if (attr->form_is_block ()) { /* Ok. */ } @@ -16546,7 +16546,7 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu) if (member_loc->form_is_section_offset ()) dwarf2_complex_location_expr_complaint (); else if (member_loc->form_is_constant () - || attr_form_is_block (member_loc)) + || member_loc->form_is_block ()) { if (attr != nullptr) mark_common_block_symbol_computed (sym, die, attr, @@ -17530,7 +17530,7 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, if (attr == NULL || prop == NULL) return 0; - if (attr_form_is_block (attr)) + if (attr->form_is_block ()) { baton = XOBNEW (obstack, struct dwarf2_property_baton); baton->property_type = default_type; @@ -17576,7 +17576,7 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, prop->kind = PROP_LOCLIST; gdb_assert (prop->data.baton != NULL); } - else if (attr_form_is_block (target_attr)) + else if (target_attr->form_is_block ()) { baton = XOBNEW (obstack, struct dwarf2_property_baton); baton->property_type = die_type (target_die, target_cu); @@ -18486,7 +18486,7 @@ partial_die_info::read (const struct die_reader_specs *reader, break; case DW_AT_location: /* Support the .debug_loc offsets. */ - if (attr_form_is_block (&attr)) + if (attr.form_is_block ()) { d.locdesc = DW_BLOCK (&attr); } @@ -21131,7 +21131,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 (attr) && DW_BLOCK (attr)->size == 0) + if (attr->form_is_block () && DW_BLOCK (attr)->size == 0) { SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT; return; @@ -21142,7 +21142,7 @@ var_decode_location (struct attribute *attr, struct symbol *sym, specified. If this is just a DW_OP_addr, DW_OP_addrx, or DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */ - if (attr_form_is_block (attr) + 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 @@ -23057,7 +23057,7 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off, } else { - if (!attr_form_is_block (attr)) + if (!attr->form_is_block ()) error (_("Dwarf Error: DIE at %s referenced in module %s " "is neither DW_FORM_block* nor DW_FORM_exprloc"), sect_offset_str (sect_off), objfile_name (objfile)); @@ -24814,7 +24814,7 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym, baton->per_cu = cu->per_cu; gdb_assert (baton->per_cu); - if (attr_form_is_block (attr)) + if (attr->form_is_block ()) { /* Note that we're just copying the block's data pointer here, not the actual data. We're still pointing into the @@ -25212,7 +25212,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) /* Read DW_AT_allocated and set in type. */ attr = dwarf2_attr (die, DW_AT_allocated, cu); - if (attr_form_is_block (attr)) + if (attr != NULL && attr->form_is_block ()) { struct type *prop_type = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false); @@ -25228,7 +25228,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) /* Read DW_AT_associated and set in type. */ attr = dwarf2_attr (die, DW_AT_associated, cu); - if (attr_form_is_block (attr)) + if (attr != NULL && attr->form_is_block ()) { struct type *prop_type = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false); -- 2.30.2