public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][gdb/symtab] Factor out have_complaint
@ 2022-10-04 15:10 Tom de Vries
  2022-10-04 15:51 ` Tom de Vries
  0 siblings, 1 reply; 4+ messages in thread
From: Tom de Vries @ 2022-10-04 15:10 UTC (permalink / raw)
  To: gdb-patches

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;
     }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][gdb/symtab] Factor out have_complaint
  2022-10-04 15:10 [PATCH][gdb/symtab] Factor out have_complaint Tom de Vries
@ 2022-10-04 15:51 ` Tom de Vries
  2022-10-04 16:43   ` Tom de Vries
  0 siblings, 1 reply; 4+ messages in thread
From: Tom de Vries @ 2022-10-04 15:51 UTC (permalink / raw)
  To: gdb-patches

On 10/4/22 17:10, Tom de Vries via Gdb-patches wrote:
> 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?
> 

Well, I didn't check properly, this doesn't even build, I'll repost once 
I got a properly build & tested version.

Sorry for the noise.

Thanks,
- Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][gdb/symtab] Factor out have_complaint
  2022-10-04 15:51 ` Tom de Vries
@ 2022-10-04 16:43   ` Tom de Vries
  2022-10-05  9:43     ` Bruno Larsen
  0 siblings, 1 reply; 4+ messages in thread
From: Tom de Vries @ 2022-10-04 16:43 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 820 bytes --]

On 10/4/22 17:51, Tom de Vries wrote:
> On 10/4/22 17:10, Tom de Vries via Gdb-patches wrote:
>> 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?
>>
> 
> Well, I didn't check properly, this doesn't even build, I'll repost once 
> I got a properly build & tested version.

And here it is.

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-symtab-Factor-out-have_complaint.patch --]
[-- Type: text/x-patch, Size: 3305 bytes --]

[gdb/symtab] Factor out have_complaint

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.

---
 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, ...)
 
 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 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 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;
     }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][gdb/symtab] Factor out have_complaint
  2022-10-04 16:43   ` Tom de Vries
@ 2022-10-05  9:43     ` Bruno Larsen
  0 siblings, 0 replies; 4+ messages in thread
From: Bruno Larsen @ 2022-10-05  9:43 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

On 04/10/2022 18:43, Tom de Vries via Gdb-patches wrote:
> On 10/4/22 17:51, Tom de Vries wrote:
>> On 10/4/22 17:10, Tom de Vries via Gdb-patches wrote:
>>> 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?
>>>
>>
>> Well, I didn't check properly, this doesn't even build, I'll repost 
>> once I got a properly build & tested version.
>
> And here it is.
I tested this locally and it introduces no regressions. And the changes 
themselves look contained enough, so I recommend you approve your patch!

Cheers,
Bruno

>
> Thanks,
> - Tom


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-05  9:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-04 15:10 [PATCH][gdb/symtab] Factor out have_complaint Tom de Vries
2022-10-04 15:51 ` Tom de Vries
2022-10-04 16:43   ` Tom de Vries
2022-10-05  9:43     ` Bruno Larsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).