From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [192.185.150.24]) by sourceware.org (Postfix) with ESMTPS id 3E685385E02C for ; Sat, 4 Apr 2020 14:43:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3E685385E02C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway30.websitewelcome.com (Postfix) with ESMTP id E62CB61A4 for ; Sat, 4 Apr 2020 09:43:28 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id Kk1AjG8yB8vkBKk1Aj4Lra; Sat, 04 Apr 2020 09:43:28 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=XmPXW/lbcluZIPgowpO4cbNH+3IUgjtf/NnDozdKQkI=; b=XHxcf9ZOF0r2J7dP27GzrlQBjn K8y4OTLHXH0//r7dnhVXE+XT62OGM1i+4uG+OM2/fG7sakKPGXBe+uwTV4mSDI7edJ6yjHguylwuZ uZ5Zr4uxRem7x3ZjyPe9XGZKk; Received: from 174-16-110-145.hlrn.qwest.net ([174.16.110.145]:58434 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1jKk1A-003j51-NG; Sat, 04 Apr 2020 08:43:28 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 19/20] Add attribute::as_boolean method Date: Sat, 4 Apr 2020 08:43:19 -0600 Message-Id: <20200404144320.18851-20-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200404144320.18851-1-tom@tromey.com> References: <20200404144320.18851-1-tom@tromey.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 174.16.110.145 X-Source-L: No X-Exim-ID: 1jKk1A-003j51-NG X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-110-145.hlrn.qwest.net (bapiya.Home) [174.16.110.145]:58434 X-Source-Auth: tom+tromey.com X-Email-Count: 30 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-17.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, JMQ_SPF_NEUTRAL, KAM_STOCKGEN, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Apr 2020 14:43:31 -0000 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-04-04 Tom Tromey * 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) : Declare. * dwarf2/attribute.c (attribute::as_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 0737c27ab75..0bb2c276aaa 100644 --- a/gdb/dwarf2/attribute.c +++ b/gdb/dwarf2/attribute.c @@ -268,3 +268,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; +} diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h index 0d242af09d5..f2a6efdcb93 100644 --- a/gdb/dwarf2/attribute.h +++ b/gdb/dwarf2/attribute.h @@ -248,6 +248,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 diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 4a3458ab4f7..cb0202a617f 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -12796,7 +12796,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)); @@ -14618,7 +14618,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. */ @@ -14628,7 +14628,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); @@ -16526,7 +16526,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 @@ -16595,7 +16595,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 @@ -16652,7 +16652,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); @@ -17947,10 +17947,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; @@ -18023,7 +18023,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: @@ -19000,7 +19000,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 @@ -20114,7 +20114,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) { @@ -20166,7 +20166,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; @@ -20194,7 +20194,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 @@ -20243,7 +20243,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 @@ -21432,7 +21432,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"); -- 2.17.2