From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Qu3kJSx/6mLM2R8AWB0awg (envelope-from ) for ; Wed, 03 Aug 2022 09:59:08 -0400 Received: by simark.ca (Postfix, from userid 112) id 8CF6B1EA05; Wed, 3 Aug 2022 09:59:08 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Ar50u0Yb; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 3A0061E9EB for ; Wed, 3 Aug 2022 09:59:08 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 42B63385AC11 for ; Wed, 3 Aug 2022 13:59:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42B63385AC11 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1659535145; bh=gpJUzKR/vWaDkcknU7+aNlIAHla88qaPgJyaEtJn6a4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Ar50u0Ybdh4unaug26y5CSQ+fZf54PwMzRjydqNh1W6z/K6z9dBntdmZFFrpoF4lx caK+eBuFjGCtTmZhxB9dPl18vy5GCGP4EgAb2cBeA1z00Ac33px/w3b5Fv7n7686pR 2QU75ub06Uf4A7eAa6g2osX6mssAiP77647GNh4Y= Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 146383858439 for ; Wed, 3 Aug 2022 13:58:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 146383858439 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AB6A134A75 for ; Wed, 3 Aug 2022 13:58:00 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 89A8413A94 for ; Wed, 3 Aug 2022 13:58:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bBtwH+h+6mKXDQAAMHmgww (envelope-from ) for ; Wed, 03 Aug 2022 13:58:00 +0000 Date: Wed, 3 Aug 2022 15:57:53 +0200 To: gdb-patches@sourceware.org Subject: [RFC][gdb] Add debug_{exp,val} Message-ID: <20220803135752.GA8436@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "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"