Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Minor 'debug_*' function improvements
@ 2026-08-05 19:24 Tom Tromey
  2026-08-06  6:58 ` Tom de Vries
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2026-08-05 19:24 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I wanted to get a summary of a type in gdb and then realized I had
forgotten the function name, so I had to dig around to find it.  This
made me think that perhaps renaming the debug_* functions to all just
be named 'debug' would be an improvement, since it's easier to
remember.

Then I noticed that debug_type and debug_val don't print a trailing
newline.

Finally, I needed to be able to see the contents of a gdb_mpz.
---
 gdb/expprint.c  |  4 ++--
 gdb/gmp-utils.c | 12 ++++++++++++
 gdb/typeprint.c |  5 +++--
 gdb/valprint.c  |  5 +++--
 4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/gdb/expprint.c b/gdb/expprint.c
index bc1929b1a1b..4859d48f6a4 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -35,13 +35,13 @@
 
 
 /* Meant to be used in debug sessions, so don't export it in a header file.  */
-extern void ATTRIBUTE_USED debug_exp (struct expression *exp);
+extern void ATTRIBUTE_USED debug (struct expression *exp);
 
 /* Print EXP.  */
 
 void
 ATTRIBUTE_USED
-debug_exp (struct expression *exp)
+debug (struct expression *exp)
 {
   exp->dump (gdb_stdlog);
   gdb_flush (gdb_stdlog);
diff --git a/gdb/gmp-utils.c b/gdb/gmp-utils.c
index 168479c50df..f681752a956 100644
--- a/gdb/gmp-utils.c
+++ b/gdb/gmp-utils.c
@@ -39,6 +39,18 @@ gmp_string_printf (const char *fmt, ...)
   return str;
 }
 
+/* Meant to be used in debug sessions, so don't export it in a header file.  */
+extern void ATTRIBUTE_UNUSED debug (const gdb_mpz &);
+
+/* Print VAL.  */
+
+void ATTRIBUTE_UNUSED
+debug (const gdb_mpz &val)
+{
+  gdb_printf (gdb_stdlog, "%s\n", val.str ().c_str ());
+  gdb_flush (gdb_stdlog);
+}
+
 /* See gmp-utils.h.  */
 
 void
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 31a9c1814a3..9177f5808f7 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -516,14 +516,15 @@ ptype_command (const char *type_name, int from_tty)
 }
 
 /* Meant to be used in debug sessions, so don't export it in a header file.  */
-extern void ATTRIBUTE_UNUSED debug_type (struct type *type);
+extern void ATTRIBUTE_UNUSED debug (struct type *type);
 
 /* Print TYPE.  */
 
 void ATTRIBUTE_UNUSED
-debug_type (struct type *type)
+debug (struct type *type)
 {
   type_print (type, "", gdb_stdlog, 1);
+  gdb_printf (gdb_stdlog, "\n");
   gdb_flush (gdb_stdlog);
 }
 
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 50a4663ca3b..dbfcbf8fad4 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1232,14 +1232,15 @@ value_print (struct value *val, struct ui_file *stream,
 }
 
 /* Meant to be used in debug sessions, so don't export it in a header file.  */
-extern void ATTRIBUTE_UNUSED debug_val (struct value *val);
+extern void ATTRIBUTE_UNUSED debug (struct value *val);
 
 /* Print VAL.  */
 
 void ATTRIBUTE_UNUSED
-debug_val (struct value *val)
+debug (struct value *val)
 {
   value_print (val, gdb_stdlog, &user_print_options);
+  gdb_printf (gdb_stdlog, "\n");
   gdb_flush (gdb_stdlog);
 }
 

base-commit: b7da195b94b423e5cfd27a14c636ffe9f7380cdd
-- 
2.55.0


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

* Re: [PATCH] Minor 'debug_*' function improvements
  2026-08-05 19:24 [PATCH] Minor 'debug_*' function improvements Tom Tromey
@ 2026-08-06  6:58 ` Tom de Vries
  2026-08-06 20:27   ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2026-08-06  6:58 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 8/5/26 9:24 PM, Tom Tromey wrote:
> I wanted to get a summary of a type in gdb and then realized I had
> forgotten the function name, so I had to dig around to find it.  This
> made me think that perhaps renaming the debug_* functions to all just
> be named 'debug' would be an improvement, since it's easier to
> remember.
> 
> Then I noticed that debug_type and debug_val don't print a trailing
> newline.
> 
> Finally, I needed to be able to see the contents of a gdb_mpz.

Hi,

this LGTM.

FWIW, I did a Claude Code review that pointed out that there's an 
inconsistency in using ATTRIBUTE_USED vs. ATTRIBUTE_UNUSED (which I 
introduced).

It recommended ATTRIBUTE_UNUSED (which just suppresses a warning), but 
the way I intended this originally fits ATTRIBUTE_USED better: "When 
attached to a function, this attribute means that code must be emitted 
for the function even if it appears that the function is not 
referenced".  So perhaps it would be a good moment to fix this as well.

Approved-By: Tom de Vries <tdevries@suse.de>

Thanks,
- Tom


> ---
>   gdb/expprint.c  |  4 ++--
>   gdb/gmp-utils.c | 12 ++++++++++++
>   gdb/typeprint.c |  5 +++--
>   gdb/valprint.c  |  5 +++--
>   4 files changed, 20 insertions(+), 6 deletions(-)
> 
> diff --git a/gdb/expprint.c b/gdb/expprint.c
> index bc1929b1a1b..4859d48f6a4 100644
> --- a/gdb/expprint.c
> +++ b/gdb/expprint.c
> @@ -35,13 +35,13 @@
>   
>   
>   /* Meant to be used in debug sessions, so don't export it in a header file.  */
> -extern void ATTRIBUTE_USED debug_exp (struct expression *exp);
> +extern void ATTRIBUTE_USED debug (struct expression *exp);
>   
>   /* Print EXP.  */
>   
>   void
>   ATTRIBUTE_USED
> -debug_exp (struct expression *exp)
> +debug (struct expression *exp)
>   {
>     exp->dump (gdb_stdlog);
>     gdb_flush (gdb_stdlog);
> diff --git a/gdb/gmp-utils.c b/gdb/gmp-utils.c
> index 168479c50df..f681752a956 100644
> --- a/gdb/gmp-utils.c
> +++ b/gdb/gmp-utils.c
> @@ -39,6 +39,18 @@ gmp_string_printf (const char *fmt, ...)
>     return str;
>   }
>   
> +/* Meant to be used in debug sessions, so don't export it in a header file.  */
> +extern void ATTRIBUTE_UNUSED debug (const gdb_mpz &);
> +
> +/* Print VAL.  */
> +
> +void ATTRIBUTE_UNUSED
> +debug (const gdb_mpz &val)
> +{
> +  gdb_printf (gdb_stdlog, "%s\n", val.str ().c_str ());
> +  gdb_flush (gdb_stdlog);
> +}
> +
>   /* See gmp-utils.h.  */
>   
>   void
> diff --git a/gdb/typeprint.c b/gdb/typeprint.c
> index 31a9c1814a3..9177f5808f7 100644
> --- a/gdb/typeprint.c
> +++ b/gdb/typeprint.c
> @@ -516,14 +516,15 @@ ptype_command (const char *type_name, int from_tty)
>   }
>   
>   /* Meant to be used in debug sessions, so don't export it in a header file.  */
> -extern void ATTRIBUTE_UNUSED debug_type (struct type *type);
> +extern void ATTRIBUTE_UNUSED debug (struct type *type);
>   
>   /* Print TYPE.  */
>   
>   void ATTRIBUTE_UNUSED
> -debug_type (struct type *type)
> +debug (struct type *type)
>   {
>     type_print (type, "", gdb_stdlog, 1);
> +  gdb_printf (gdb_stdlog, "\n");
>     gdb_flush (gdb_stdlog);
>   }
>   
> diff --git a/gdb/valprint.c b/gdb/valprint.c
> index 50a4663ca3b..dbfcbf8fad4 100644
> --- a/gdb/valprint.c
> +++ b/gdb/valprint.c
> @@ -1232,14 +1232,15 @@ value_print (struct value *val, struct ui_file *stream,
>   }
>   
>   /* Meant to be used in debug sessions, so don't export it in a header file.  */
> -extern void ATTRIBUTE_UNUSED debug_val (struct value *val);
> +extern void ATTRIBUTE_UNUSED debug (struct value *val);
>   
>   /* Print VAL.  */
>   
>   void ATTRIBUTE_UNUSED
> -debug_val (struct value *val)
> +debug (struct value *val)
>   {
>     value_print (val, gdb_stdlog, &user_print_options);
> +  gdb_printf (gdb_stdlog, "\n");
>     gdb_flush (gdb_stdlog);
>   }
>   
> 
> base-commit: b7da195b94b423e5cfd27a14c636ffe9f7380cdd


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

* Re: [PATCH] Minor 'debug_*' function improvements
  2026-08-06  6:58 ` Tom de Vries
@ 2026-08-06 20:27   ` Tom Tromey
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2026-08-06 20:27 UTC (permalink / raw)
  To: Tom de Vries; +Cc: Tom Tromey, gdb-patches

>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> It recommended ATTRIBUTE_UNUSED (which just suppresses a warning), but
Tom> the way I intended this originally fits ATTRIBUTE_USED better: "When
Tom> attached to a function, this attribute means that code must be emitted
Tom> for the function even if it appears that the function is not
Tom> referenced".  So perhaps it would be a good moment to fix this as
Tom> well.

I'll send a v2 shortly.

Tom

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

end of thread, other threads:[~2026-08-06 20:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-05 19:24 [PATCH] Minor 'debug_*' function improvements Tom Tromey
2026-08-06  6:58 ` Tom de Vries
2026-08-06 20:27   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox