mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
Add attribute::as_boolean method
This adds a new attribute::as_boolean method, and updates the reader to use it. The main benefit of this change is that now the code will respect the attribute's form. gdb/ChangeLog 2020-09-29 Tom Tromey <tom@tromey.com> * dwarf2/read.c (read_func_scope, prototyped_function_p) (read_subroutine_type, partial_die_info::read) (dwarf2_flag_true_p, new_symbol, dump_die_shallow) (dwarf2_add_member_fn): Update. * dwarf2/attribute.h (struct attribute) <as_boolean>: Declare. * dwarf2/attribute.c (attribute::as_boolean): New method.
This commit is contained in:
parent
23dca5c3d7
commit
c45bc3f8ab
@ -1,3 +1,12 @@
|
||||
2020-09-29 Tom Tromey <tom@tromey.com>
|
||||
|
||||
* dwarf2/read.c (read_func_scope, prototyped_function_p)
|
||||
(read_subroutine_type, partial_die_info::read)
|
||||
(dwarf2_flag_true_p, new_symbol, dump_die_shallow)
|
||||
(dwarf2_add_member_fn): Update.
|
||||
* dwarf2/attribute.h (struct attribute) <as_boolean>: Declare.
|
||||
* dwarf2/attribute.c (attribute::as_boolean): New method.
|
||||
|
||||
2020-09-29 Tom Tromey <tom@tromey.com>
|
||||
|
||||
* dwarf2/read.c (dwarf2_add_field, dwarf2_add_member_fn): Update.
|
||||
|
@ -245,3 +245,15 @@ attribute::as_virtuality () const
|
||||
plongest (value));
|
||||
return DW_VIRTUALITY_none;
|
||||
}
|
||||
|
||||
/* See attribute.h. */
|
||||
|
||||
bool
|
||||
attribute::as_boolean () const
|
||||
{
|
||||
if (form == DW_FORM_flag_present)
|
||||
return true;
|
||||
else if (form == DW_FORM_flag)
|
||||
return u.unsnd != 0;
|
||||
return constant_value (0) != 0;
|
||||
}
|
||||
|
@ -263,6 +263,10 @@ struct attribute
|
||||
issue a complaint and return DW_VIRTUALITY_none. */
|
||||
dwarf_virtuality_attribute as_virtuality () const;
|
||||
|
||||
/* Return the attribute's value as a boolean. An unrecognized form
|
||||
will issue a complaint and return false. */
|
||||
bool as_boolean () const;
|
||||
|
||||
ENUM_BITFIELD(dwarf_attribute) name : 15;
|
||||
|
||||
/* A boolean that is used for forms that require reprocessing. A
|
||||
|
@ -13565,7 +13565,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
|
||||
<= PC_BOUNDS_INVALID)
|
||||
{
|
||||
attr = dwarf2_attr (die, DW_AT_external, cu);
|
||||
if (!attr || !DW_UNSND (attr))
|
||||
if (attr == nullptr || !attr->as_boolean ())
|
||||
complaint (_("cannot get low and high bounds "
|
||||
"for subprogram DIE at %s"),
|
||||
sect_offset_str (die->sect_off));
|
||||
@ -15642,7 +15642,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
|
||||
|
||||
/* Check for artificial methods. */
|
||||
attr = dwarf2_attr (die, DW_AT_artificial, cu);
|
||||
if (attr && DW_UNSND (attr) != 0)
|
||||
if (attr && attr->as_boolean ())
|
||||
fnp->is_artificial = 1;
|
||||
|
||||
/* Check for defaulted methods. */
|
||||
@ -15652,7 +15652,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
|
||||
|
||||
/* Check for deleted methods. */
|
||||
attr = dwarf2_attr (die, DW_AT_deleted, cu);
|
||||
if (attr != nullptr && DW_UNSND (attr) != 0)
|
||||
if (attr != nullptr && attr->as_boolean ())
|
||||
fnp->is_deleted = 1;
|
||||
|
||||
fnp->is_constructor = dwarf2_is_constructor (die, cu);
|
||||
@ -17591,7 +17591,7 @@ prototyped_function_p (struct die_info *die, struct dwarf2_cu *cu)
|
||||
struct attribute *attr;
|
||||
|
||||
attr = dwarf2_attr (die, DW_AT_prototyped, cu);
|
||||
if (attr && (DW_UNSND (attr) != 0))
|
||||
if (attr && attr->as_boolean ())
|
||||
return 1;
|
||||
|
||||
/* The DWARF standard implies that the DW_AT_prototyped attribute
|
||||
@ -17660,7 +17660,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
|
||||
/* Record whether the function returns normally to its caller or not
|
||||
if the DWARF producer set that information. */
|
||||
attr = dwarf2_attr (die, DW_AT_noreturn, cu);
|
||||
if (attr && (DW_UNSND (attr) != 0))
|
||||
if (attr && attr->as_boolean ())
|
||||
TYPE_NO_RETURN (ftype) = 1;
|
||||
|
||||
/* We need to add the subroutine type to the die immediately so
|
||||
@ -17718,7 +17718,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
|
||||
4.5 does not yet generate. */
|
||||
attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
|
||||
if (attr != nullptr)
|
||||
TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
|
||||
TYPE_FIELD_ARTIFICIAL (ftype, iparams) = attr->as_boolean ();
|
||||
else
|
||||
TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
|
||||
arg_type = die_type (child_die, cu);
|
||||
@ -19052,10 +19052,10 @@ partial_die_info::read (const struct die_reader_specs *reader,
|
||||
}
|
||||
break;
|
||||
case DW_AT_external:
|
||||
is_external = DW_UNSND (&attr);
|
||||
is_external = attr.as_boolean ();
|
||||
break;
|
||||
case DW_AT_declaration:
|
||||
is_declaration = DW_UNSND (&attr);
|
||||
is_declaration = attr.as_boolean ();
|
||||
break;
|
||||
case DW_AT_type:
|
||||
has_type = 1;
|
||||
@ -19128,7 +19128,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
|
||||
break;
|
||||
|
||||
case DW_AT_main_subprogram:
|
||||
main_subprogram = DW_UNSND (&attr);
|
||||
main_subprogram = attr.as_boolean ();
|
||||
break;
|
||||
|
||||
case DW_AT_ranges:
|
||||
@ -20301,7 +20301,7 @@ dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
|
||||
{
|
||||
struct attribute *attr = dwarf2_attr (die, name, cu);
|
||||
|
||||
return (attr && DW_UNSND (attr));
|
||||
return attr != nullptr && attr->as_boolean ();
|
||||
}
|
||||
|
||||
static int
|
||||
@ -21467,7 +21467,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
|
||||
finish_block. */
|
||||
SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
|
||||
attr2 = dwarf2_attr (die, DW_AT_external, cu);
|
||||
if ((attr2 && (DW_UNSND (attr2) != 0))
|
||||
if ((attr2 != nullptr && attr2->as_boolean ())
|
||||
|| cu->language == language_ada
|
||||
|| cu->language == language_fortran)
|
||||
{
|
||||
@ -21519,7 +21519,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
|
||||
attr2 = dwarf2_attr (die, DW_AT_external, cu);
|
||||
if (!suppress_add)
|
||||
{
|
||||
if (attr2 && (DW_UNSND (attr2) != 0))
|
||||
if (attr2 != nullptr && attr2->as_boolean ())
|
||||
list_to_add = cu->get_builder ()->get_global_symbols ();
|
||||
else
|
||||
list_to_add = cu->list_in_scope;
|
||||
@ -21547,7 +21547,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
|
||||
out, but the variable address is set to null;
|
||||
do not add such variables into symbol table. */
|
||||
}
|
||||
else if (attr2 && (DW_UNSND (attr2) != 0))
|
||||
else if (attr2 != nullptr && attr2->as_boolean ())
|
||||
{
|
||||
if (SYMBOL_CLASS (sym) == LOC_STATIC
|
||||
&& (objfile->flags & OBJF_MAINLINE) == 0
|
||||
@ -21596,7 +21596,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
|
||||
if (!suppress_add)
|
||||
list_to_add = cu->list_in_scope;
|
||||
}
|
||||
else if (attr2 && (DW_UNSND (attr2) != 0)
|
||||
else if (attr2 != nullptr && attr2->as_boolean ()
|
||||
&& dwarf2_attr (die, DW_AT_type, cu) != NULL)
|
||||
{
|
||||
/* A variable with DW_AT_external is never static, but it
|
||||
@ -22780,7 +22780,7 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
|
||||
die->attrs[i].canonical_string_p () ? "is" : "not");
|
||||
break;
|
||||
case DW_FORM_flag:
|
||||
if (DW_UNSND (&die->attrs[i]))
|
||||
if (die->attrs[i].as_boolean ())
|
||||
fprintf_unfiltered (f, "flag: TRUE");
|
||||
else
|
||||
fprintf_unfiltered (f, "flag: FALSE");
|
||||
|
Loading…
Reference in New Issue
Block a user