Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFC][gdb] Add debug_{exp,val}
@ 2022-08-03 13:57 Tom de Vries via Gdb-patches
  2022-08-04 13:07 ` Luis Machado via Gdb-patches
  2022-08-04 17:55 ` Tom Tromey
  0 siblings, 2 replies; 3+ messages in thread
From: Tom de Vries via Gdb-patches @ 2022-08-03 13:57 UTC (permalink / raw)
  To: gdb-patches

Hi,

When debugging cc1 I heavily rely on simple one-parameter debug functions
that allow me to inspect a variable of a common type, like:
- debug_generic_expr
- debug_gimple_stmt
- debug_rtx
and I miss similar function in gdb.

Add functions to dump variables of types 'value' and 'expression':
- debug_exp, and
- debug_val.

Tested on x86_64-linux, by breaking on varobj_create, and doing:
...
(gdb) call debug_exp (var->root->exp.get ())
&"Operation: OP_VAR_VALUE\n"
&" Block symbol:\n"
&"  Symbol: aaa\n"
&"  Block: 0x2d064f0\n"
(gdb)
...
and:
...
(gdb) call debug_val (value)
&"5"
(gdb)
...

Any comments?

Thanks,
- Tom

[gdb] Add debug_{exp,val}

---
 gdb/expprint.c           | 13 +++++++++++++
 gdb/valprint.c           | 12 ++++++++++++
 gdbsupport/common-defs.h |  6 ++++++
 3 files changed, 31 insertions(+)

diff --git a/gdb/expprint.c b/gdb/expprint.c
index cef6ffb3566..8534d2ac443 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -65,6 +65,19 @@ dump_prefix_expression (struct expression *exp, struct ui_file *stream)
   exp->op->dump (stream, 0);
 }
 
+/* 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);
+
+/* Print EXP.  */
+
+void
+ATTRIBUTE_USED
+debug_exp (struct expression *exp)
+{
+  exp->op->dump (gdb_stdlog, 0);
+  gdb_flush (gdb_stdlog);
+}
+
 namespace expr
 {
 
diff --git a/gdb/valprint.c b/gdb/valprint.c
index f873e12d0ca..3ad4c0cd357 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1190,6 +1190,18 @@ value_print (struct value *val, struct ui_file *stream,
   current_language->value_print (val, stream, options);
 }
 
+/* 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);
+
+/* Print VAL.  */
+
+void ATTRIBUTE_UNUSED
+debug_val (struct value *val)
+{
+  value_print (val, gdb_stdlog, &user_print_options);
+  gdb_flush (gdb_stdlog);
+}
+
 static void
 val_print_type_code_flags (struct type *type, struct value *original_value,
 			   int embedded_offset, struct ui_file *stream)
diff --git a/gdbsupport/common-defs.h b/gdbsupport/common-defs.h
index eed364a48ce..e4985332e3f 100644
--- a/gdbsupport/common-defs.h
+++ b/gdbsupport/common-defs.h
@@ -191,6 +191,12 @@
 #define ATTRIBUTE_UNUSED_RESULT
 #endif
 
+#if (GCC_VERSION > 4000)
+#define ATTRIBUTE_USED __attribute__ ((__used__))
+#else
+#define ATTRIBUTE_USED
+#endif
+
 #include "libiberty.h"
 #include "pathmax.h"
 #include "gdb/signals.h"

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

* Re: [RFC][gdb] Add debug_{exp,val}
  2022-08-03 13:57 [RFC][gdb] Add debug_{exp,val} Tom de Vries via Gdb-patches
@ 2022-08-04 13:07 ` Luis Machado via Gdb-patches
  2022-08-04 17:55 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Luis Machado via Gdb-patches @ 2022-08-04 13:07 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

On 8/3/22 14:57, Tom de Vries via Gdb-patches wrote:
> Hi,
> 
> When debugging cc1 I heavily rely on simple one-parameter debug functions
> that allow me to inspect a variable of a common type, like:
> - debug_generic_expr
> - debug_gimple_stmt
> - debug_rtx
> and I miss similar function in gdb.
> 
> Add functions to dump variables of types 'value' and 'expression':
> - debug_exp, and
> - debug_val.
> 
> Tested on x86_64-linux, by breaking on varobj_create, and doing:
> ...
> (gdb) call debug_exp (var->root->exp.get ())
> &"Operation: OP_VAR_VALUE\n"
> &" Block symbol:\n"
> &"  Symbol: aaa\n"
> &"  Block: 0x2d064f0\n"
> (gdb)
> ...
> and:
> ...
> (gdb) call debug_val (value)
> &"5"
> (gdb)
> ...
> 
> Any comments?
> 
> Thanks,
> - Tom
> 
> [gdb] Add debug_{exp,val}
> 
> ---
>   gdb/expprint.c           | 13 +++++++++++++
>   gdb/valprint.c           | 12 ++++++++++++
>   gdbsupport/common-defs.h |  6 ++++++
>   3 files changed, 31 insertions(+)
> 
> diff --git a/gdb/expprint.c b/gdb/expprint.c
> index cef6ffb3566..8534d2ac443 100644
> --- a/gdb/expprint.c
> +++ b/gdb/expprint.c
> @@ -65,6 +65,19 @@ dump_prefix_expression (struct expression *exp, struct ui_file *stream)
>     exp->op->dump (stream, 0);
>   }
>   
> +/* 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);
> +
> +/* Print EXP.  */
> +
> +void
> +ATTRIBUTE_USED
> +debug_exp (struct expression *exp)
> +{
> +  exp->op->dump (gdb_stdlog, 0);
> +  gdb_flush (gdb_stdlog);
> +}
> +
>   namespace expr
>   {
>   
> diff --git a/gdb/valprint.c b/gdb/valprint.c
> index f873e12d0ca..3ad4c0cd357 100644
> --- a/gdb/valprint.c
> +++ b/gdb/valprint.c
> @@ -1190,6 +1190,18 @@ value_print (struct value *val, struct ui_file *stream,
>     current_language->value_print (val, stream, options);
>   }
>   
> +/* 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);
> +
> +/* Print VAL.  */
> +
> +void ATTRIBUTE_UNUSED
> +debug_val (struct value *val)
> +{
> +  value_print (val, gdb_stdlog, &user_print_options);
> +  gdb_flush (gdb_stdlog);
> +}
> +
>   static void
>   val_print_type_code_flags (struct type *type, struct value *original_value,
>   			   int embedded_offset, struct ui_file *stream)
> diff --git a/gdbsupport/common-defs.h b/gdbsupport/common-defs.h
> index eed364a48ce..e4985332e3f 100644
> --- a/gdbsupport/common-defs.h
> +++ b/gdbsupport/common-defs.h
> @@ -191,6 +191,12 @@
>   #define ATTRIBUTE_UNUSED_RESULT
>   #endif
>   
> +#if (GCC_VERSION > 4000)
> +#define ATTRIBUTE_USED __attribute__ ((__used__))
> +#else
> +#define ATTRIBUTE_USED
> +#endif
> +
>   #include "libiberty.h"
>   #include "pathmax.h"
>   #include "gdb/signals.h"

Nice. I print these by hand all the time. I think it's a great addition.

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

* Re: [RFC][gdb] Add debug_{exp,val}
  2022-08-03 13:57 [RFC][gdb] Add debug_{exp,val} Tom de Vries via Gdb-patches
  2022-08-04 13:07 ` Luis Machado via Gdb-patches
@ 2022-08-04 17:55 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2022-08-04 17:55 UTC (permalink / raw)
  To: Tom de Vries via Gdb-patches

>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> Hi,
Tom> When debugging cc1 I heavily rely on simple one-parameter debug functions
Tom> that allow me to inspect a variable of a common type, like:
Tom> - debug_generic_expr
Tom> - debug_gimple_stmt
Tom> - debug_rtx
Tom> and I miss similar function in gdb.

Tom> Add functions to dump variables of types 'value' and 'expression':
Tom> - debug_exp, and
Tom> - debug_val.

Seems fine to me.
Thanks.

Tom

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

end of thread, other threads:[~2022-08-04 17:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-03 13:57 [RFC][gdb] Add debug_{exp,val} Tom de Vries via Gdb-patches
2022-08-04 13:07 ` Luis Machado via Gdb-patches
2022-08-04 17:55 ` Tom Tromey

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