]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb] Add debug_{exp,val}
authorTom de Vries <tdevries@suse.de>
Fri, 5 Aug 2022 06:09:57 +0000 (08:09 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 5 Aug 2022 06:09:57 +0000 (08:09 +0200)
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 functions 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)
...

gdb/expprint.c
gdb/valprint.c
gdbsupport/common-defs.h

index cef6ffb35665aca9fcee3e9288bddf7f110cf7df..8534d2ac443a6aca134df47cab0c4a7898aea79d 100644 (file)
@@ -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
 {
 
index f873e12d0ca0797edaf1ee3bafea97b9f60dca71..3ad4c0cd35733daf389eb6315da27ef9356e09ed 100644 (file)
@@ -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)
index eed364a48ceff2865231d137b76982cab4145e96..e4985332e3f4016ccec2b2502dfe28bab16e2c92 100644 (file)
 #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"