From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 80AC1389942A; Thu, 6 Oct 2022 12:54:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80AC1389942A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665060854; bh=mzx+YyJu9ZpD0XwGV4PiYUVVrflubNjDbDWDP8ESO2s=; h=From:To:Subject:Date:From; b=pA+R6WM5n3LJNApqd/ingwmfaxcLqFc45pJ2FBIhm6KlrrD22C7Ugio8aCEk5e/Sx 0amdFjT1nKbA3HC67fF/9oh2ASVehJICE+t1Y0M03youfqlLseJ2UntxlrUSZOL+aW yoCYsuvNFQpPKrHF0yZH+AOChoSFYM1qLujGxNl0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/symtab] Factor out have_complaint X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 80e0c6dc91f52fad32c3ff3cf20da889d77013ac X-Git-Newrev: ca10a126c67f03e4e56dbbb6966c1682014912d8 Message-Id: <20221006125414.80AC1389942A@sourceware.org> Date: Thu, 6 Oct 2022 12:54:14 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dca10a126c67f= 03e4e56dbbb6966c1682014912d8 commit ca10a126c67f03e4e56dbbb6966c1682014912d8 Author: Tom de Vries Date: Thu Oct 6 14:53:07 2022 +0200 [gdb/symtab] Factor out have_complaint =20 After committing 8ba677d3560 ("[gdb/symtab] Don't complain about functi= on decls") I noticed that quite a bit of code in read_func_scope is used t= o 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". =20 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. =20 Tested on x86_64-linux. Diff: --- 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..02c8c2c558b 100644 --- a/gdb/complaints.h +++ b/gdb/complaints.h @@ -31,6 +31,15 @@ extern void complaint_internal (const char *fmt, ...) =20 extern int stop_whining; =20 +/* 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 inline 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_complaint ()) \ 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 dwa= rf2_cu *cu) if (dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, nullptr, nullptr) <=3D PC_BOUNDS_INVALID) { - attr =3D dwarf2_attr (die, DW_AT_external, cu); - bool external_p =3D attr !=3D nullptr && attr->as_boolean (); - attr =3D dwarf2_attr (die, DW_AT_inline, cu); - bool inlined_p - =3D (attr !=3D nullptr - && attr->is_nonnegative () - && (attr->as_nonnegative () =3D=3D DW_INL_inlined - || attr->as_nonnegative () =3D=3D DW_INL_declared_inlined)); - attr =3D dwarf2_attr (die, DW_AT_declaration, cu); - bool decl_p =3D attr !=3D 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 =3D dwarf2_attr (die, DW_AT_external, cu); + bool external_p =3D attr !=3D nullptr && attr->as_boolean (); + attr =3D dwarf2_attr (die, DW_AT_inline, cu); + bool inlined_p + =3D (attr !=3D nullptr + && attr->is_nonnegative () + && (attr->as_nonnegative () =3D=3D DW_INL_inlined + || attr->as_nonnegative () =3D=3D DW_INL_declared_inlined)); + attr =3D dwarf2_attr (die, DW_AT_declaration, cu); + bool decl_p =3D attr !=3D 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; }