From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway31.websitewelcome.com (gateway31.websitewelcome.com [192.185.143.43]) by sourceware.org (Postfix) with ESMTPS id 8430D389907B for ; Sat, 28 Mar 2020 19:22:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8430D389907B 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 cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 3055A4C82B for ; Sat, 28 Mar 2020 14:22:14 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id IH26jVDxPSl8qIH26j1uGD; Sat, 28 Mar 2020 14:22:14 -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=fTVfTelwocUQyuM3vWvtDN5Jzlplj+P1kZYnQf9R4oM=; b=TmLZouE4GXZUc0Zl4KAsdVJ692 KNlihGPiWBMwnXer/rv9ANUxySReBjOgQ02V5+JyoxZZlKs1tJd0pXCScSczvPMk8Dbe4LlqBZXxn mMVJzU1QUg3sJoOacGZfdMPcI; Received: from 97-118-117-21.hlrn.qwest.net ([97.118.117.21]:55190 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1jIH25-003oZR-Vi; Sat, 28 Mar 2020 13:22:14 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 19/20] Add attribute::boolean method Date: Sat, 28 Mar 2020 13:22:07 -0600 Message-Id: <20200328192208.11324-20-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200328192208.11324-1-tom@tromey.com> References: <20200328192208.11324-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: 97.118.117.21 X-Source-L: No X-Exim-ID: 1jIH25-003oZR-Vi X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-117-21.hlrn.qwest.net (bapiya.Home) [97.118.117.21]:55190 X-Source-Auth: tom+tromey.com X-Email-Count: 22 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-20.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, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, URIBL_CSS, URIBL_CSS_A 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, 28 Mar 2020 19:22:17 -0000 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 * 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::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