From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 4F9BF3853802 for ; Tue, 4 Oct 2022 15:11:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4F9BF3853802 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 235D9219B6 for ; Tue, 4 Oct 2022 15:11:01 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 12DFB139EF for ; Tue, 4 Oct 2022 15:11:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id LM+QAwVNPGMECwAAMHmgww (envelope-from ) for ; Tue, 04 Oct 2022 15:11:01 +0000 Date: Tue, 4 Oct 2022 17:10:59 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/symtab] Factor out have_complaint Message-ID: <20221004151058.GA20304@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Tue, 04 Oct 2022 15:12:14 -0000 Hi, After committing 8ba677d3560 ("[gdb/symtab] Don't complain about function decls") I noticed that quite a bit of code in read_func_scope is used to decide whether to issue the "cannot get low and high bounds for subprogram DIE at $hex" complaint, which executes unnecessarily if we have the default "set complaints 0". Fix this by (NFC): - factoring out new static function have_complaint from macro complaint, and - using it to wrap the relevant code in read_func_scope. Tested on x86_64-linux. Any comments? Thanks, - Tom [gdb/symtab] Factor out have_complaint --- gdb/complaints.h | 11 ++++++++++- gdb/dwarf2/read.c | 31 +++++++++++++++++-------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/gdb/complaints.h b/gdb/complaints.h index 68c79bd6d0a..3ba2db76b0b 100644 --- a/gdb/complaints.h +++ b/gdb/complaints.h @@ -31,6 +31,15 @@ extern void complaint_internal (const char *fmt, ...) extern int stop_whining; +/* Return true if complaints are enabled. This can be used to guard code + that is used only to decide whether to issue a complaint. */ + +static bool +have_complaint () +{ + return stop_whining > 0; +} + /* Register a complaint. This is a macro around complaint_internal to avoid computing complaint's arguments when complaints are disabled. Running FMT via gettext [i.e., _(FMT)] can be quite expensive, for @@ -38,7 +47,7 @@ extern int stop_whining; #define complaint(FMT, ...) \ do \ { \ - if (stop_whining > 0) \ + if (have_complaints ()) \ complaint_internal (FMT, ##__VA_ARGS__); \ } \ while (0) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 8e42c0f4d8d..78f4cc1f60d 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -12043,20 +12043,23 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) if (dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, nullptr, nullptr) <= PC_BOUNDS_INVALID) { - attr = dwarf2_attr (die, DW_AT_external, cu); - bool external_p = attr != nullptr && attr->as_boolean (); - attr = dwarf2_attr (die, DW_AT_inline, cu); - bool inlined_p - = (attr != nullptr - && attr->is_nonnegative () - && (attr->as_nonnegative () == DW_INL_inlined - || attr->as_nonnegative () == DW_INL_declared_inlined)); - attr = dwarf2_attr (die, DW_AT_declaration, cu); - bool decl_p = attr != nullptr && attr->as_boolean (); - if (!external_p && !inlined_p && !decl_p) - complaint (_("cannot get low and high bounds " - "for subprogram DIE at %s"), - sect_offset_str (die->sect_off)); + if (have_complaint ()) + { + attr = dwarf2_attr (die, DW_AT_external, cu); + bool external_p = attr != nullptr && attr->as_boolean (); + attr = dwarf2_attr (die, DW_AT_inline, cu); + bool inlined_p + = (attr != nullptr + && attr->is_nonnegative () + && (attr->as_nonnegative () == DW_INL_inlined + || attr->as_nonnegative () == DW_INL_declared_inlined)); + attr = dwarf2_attr (die, DW_AT_declaration, cu); + bool decl_p = attr != nullptr && attr->as_boolean (); + if (!external_p && !inlined_p && !decl_p) + complaint (_("cannot get low and high bounds " + "for subprogram DIE at %s"), + sect_offset_str (die->sect_off)); + } return; }