From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id BEE113858D37; Fri, 5 Aug 2022 06:10:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEE113858D37 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] Add debug_{exp,val} X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 701821154b110230f52a0367e120ecc51f490e56 X-Git-Newrev: 731d2cc1d5106c077584bd83e96dbba4f7e11118 Message-Id: <20220805061001.BEE113858D37@sourceware.org> Date: Fri, 5 Aug 2022 06:10:01 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Aug 2022 06:10:02 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D731d2cc1d510= 6c077584bd83e96dbba4f7e11118 commit 731d2cc1d5106c077584bd83e96dbba4f7e11118 Author: Tom de Vries Date: Fri Aug 5 08:09:57 2022 +0200 [gdb] Add debug_{exp,val} =20 When debugging cc1 I heavily rely on simple one-parameter debug functio= ns 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. =20 Add functions to dump variables of types 'value' and 'expression': - debug_exp, and - debug_val. =20 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) ... Diff: --- 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 u= i_file *stream) exp->op->dump (stream, 0); } =20 +/* 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 { =20 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 *stre= am, current_language->value_print (val, stream, options); } =20 +/* 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 =20 +#if (GCC_VERSION > 4000) +#define ATTRIBUTE_USED __attribute__ ((__used__)) +#else +#define ATTRIBUTE_USED +#endif + #include "libiberty.h" #include "pathmax.h" #include "gdb/signals.h"