From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 19/20] Add attribute::boolean method
Date: Sat, 28 Mar 2020 13:22:07 -0600 [thread overview]
Message-ID: <20200328192208.11324-20-tom@tromey.com> (raw)
In-Reply-To: <20200328192208.11324-1-tom@tromey.com>
This adds a new attribute::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.
2020-03-28 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) <boolean>: Declare.
* dwarf2/attribute.c (attribute::boolean): New method.
---
gdb/ChangeLog | 9 +++++++++
gdb/dwarf2/attribute.c | 12 ++++++++++++
gdb/dwarf2/attribute.h | 4 ++++
gdb/dwarf2/read.c | 30 +++++++++++++++---------------
4 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index 7f428279757..db01f8ac0ca 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -261,3 +261,15 @@ attribute::virtuality () const
plongest (value));
return DW_VIRTUALITY_none;
}
+
+/* See attribute.h. */
+
+bool
+attribute::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;
+}
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index 7c0ce1615cf..20947a11642 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -242,6 +242,10 @@ struct attribute
issue a complaint and return DW_VIRTUALITY_none. */
dwarf_virtuality_attribute virtuality () const;
+ /* Return the attribute's value as a boolean. An unrecognized form
+ will issue a complaint and return false. */
+ bool boolean () const;
+
ENUM_BITFIELD(dwarf_attribute) name : 15;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 66a508c95ea..cf4a2a333ef 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -12768,7 +12768,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->boolean ())
complaint (_("cannot get low and high bounds "
"for subprogram DIE at %s"),
sect_offset_str (die->sect_off));
@@ -14583,7 +14583,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->boolean ())
fnp->is_artificial = 1;
/* Check for defaulted methods. */
@@ -14593,7 +14593,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->boolean ())
fnp->is_deleted = 1;
fnp->is_constructor = dwarf2_is_constructor (die, cu);
@@ -16486,7 +16486,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->boolean ())
return 1;
/* The DWARF standard implies that the DW_AT_prototyped attribute
@@ -16555,7 +16555,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->boolean ())
TYPE_NO_RETURN (ftype) = 1;
/* We need to add the subroutine type to the die immediately so
@@ -16612,7 +16612,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->boolean ();
else
TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
arg_type = die_type (child_die, cu);
@@ -17906,10 +17906,10 @@ partial_die_info::read (const struct die_reader_specs *reader,
}
break;
case DW_AT_external:
- is_external = DW_UNSND (&attr);
+ is_external = attr.boolean ();
break;
case DW_AT_declaration:
- is_declaration = DW_UNSND (&attr);
+ is_declaration = attr.boolean ();
break;
case DW_AT_type:
has_type = 1;
@@ -17982,7 +17982,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.boolean ();
break;
case DW_AT_ranges:
@@ -18954,7 +18954,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->boolean ();
}
static int
@@ -20064,7 +20064,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->boolean ())
|| cu->language == language_ada
|| cu->language == language_fortran)
{
@@ -20116,7 +20116,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->boolean ())
list_to_add = cu->get_builder ()->get_global_symbols ();
else
list_to_add = cu->list_in_scope;
@@ -20144,7 +20144,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->boolean ())
{
if (SYMBOL_CLASS (sym) == LOC_STATIC
&& (objfile->flags & OBJF_MAINLINE) == 0
@@ -20193,7 +20193,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->boolean ()
&& dwarf2_attr (die, DW_AT_type, cu) != NULL)
{
/* A variable with DW_AT_external is never static, but it
@@ -21379,7 +21379,7 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
die->attrs[i].canonical_p () ? "is" : "not");
break;
case DW_FORM_flag:
- if (DW_UNSND (&die->attrs[i]))
+ if (die->attrs[i].boolean ())
fprintf_unfiltered (f, "flag: TRUE");
else
fprintf_unfiltered (f, "flag: FALSE");
--
2.17.2
next prev parent reply other threads:[~2020-03-28 19:22 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-28 19:21 [PATCH 00/20] Make DWARF attribute references safe Tom Tromey
2020-03-28 19:21 ` [PATCH 01/20] Add attribute::value_as_string method Tom Tromey
2020-03-28 19:21 ` [PATCH 02/20] Rename struct attribute accessors Tom Tromey
2020-03-30 8:58 ` Aktemur, Tankut Baris
2020-03-30 23:39 ` Tom Tromey
2020-03-30 14:45 ` Simon Marchi
2020-03-30 23:39 ` Tom Tromey
2020-03-28 19:21 ` [PATCH 03/20] Avoid using DW_* macros in dwarf2/attribute.c Tom Tromey
2020-03-28 19:21 ` [PATCH 04/20] Change some uses of DW_STRING to string method Tom Tromey
2020-03-30 14:56 ` Simon Marchi
2020-03-30 23:53 ` Tom Tromey
2020-03-28 19:21 ` [PATCH 05/20] Remove some uses of DW_STRING_IS_CANONICAL Tom Tromey
2020-03-30 15:02 ` Simon Marchi
2020-03-31 0:01 ` Tom Tromey
2020-03-28 19:21 ` [PATCH 06/20] Remove DW_STRING and DW_STRING_IS_CANONICAL Tom Tromey
2020-03-30 15:10 ` Simon Marchi
2020-03-31 0:23 ` Tom Tromey
2020-03-28 19:21 ` [PATCH 07/20] Remove DW_BLOCK Tom Tromey
2020-03-30 15:13 ` Simon Marchi
2020-03-28 19:21 ` [PATCH 08/20] Remove DW_SIGNATURE Tom Tromey
2020-03-28 19:21 ` [PATCH 09/20] Remove DW_SND Tom Tromey
2020-03-28 19:21 ` [PATCH 10/20] Use setter for attribute's unsigned value Tom Tromey
2020-03-28 19:21 ` [PATCH 11/20] Add reprocessing flag to struct attribute Tom Tromey
2020-03-30 15:32 ` Simon Marchi
2020-04-04 14:02 ` Tom Tromey
2020-03-28 19:22 ` [PATCH 12/20] Remove DW_ADDR Tom Tromey
2020-03-30 15:40 ` Simon Marchi
2020-04-04 14:05 ` Tom Tromey
2020-03-28 19:22 ` [PATCH 13/20] Change how reprocessing is done Tom Tromey
2020-03-30 15:46 ` Simon Marchi
2020-04-04 14:14 ` Tom Tromey
2020-03-28 19:22 ` [PATCH 14/20] Change how accessibility is handled in dwarf2/read.c Tom Tromey
2020-03-30 15:50 ` Simon Marchi
2020-03-28 19:22 ` [PATCH 15/20] Add attribute::get_unsigned method Tom Tromey
2020-03-30 15:57 ` Simon Marchi
2020-04-04 14:17 ` Tom Tromey
2020-03-28 19:22 ` [PATCH 16/20] Change is_valid_DW_AT_defaulted to a method on attribute Tom Tromey
2020-03-30 16:00 ` Simon Marchi
2020-04-04 14:23 ` Tom Tromey
2020-03-28 19:22 ` [PATCH 17/20] Change die_info methods to check the attribute's form Tom Tromey
2020-03-30 16:02 ` Simon Marchi
2020-03-30 19:04 ` Tom Tromey
2020-03-30 20:18 ` Simon Marchi
2020-03-30 20:26 ` Tom Tromey
2020-03-28 19:22 ` [PATCH 18/20] Add attribute::virtuality method Tom Tromey
2020-03-28 19:22 ` Tom Tromey [this message]
2020-03-28 19:22 ` [PATCH 20/20] Remove DW_UNSND Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200328192208.11324-20-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox