From patchwork Thu Apr 27 14:31:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68376 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3F8E385842C for ; Thu, 27 Apr 2023 14:32:11 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from gproxy3-pub.mail.unifiedlayer.com (gproxy3-pub.mail.unifiedlayer.com [69.89.30.42]) by sourceware.org (Postfix) with ESMTPS id B87F9385772C for ; Thu, 27 Apr 2023 14:31:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B87F9385772C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw11.mail.unifiedlayer.com (unknown [10.0.90.126]) by progateway5.mail.pro1.eigbox.com (Postfix) with ESMTP id 04025100406C9 for ; Thu, 27 Apr 2023 14:31:56 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id s2f5pcut4b56is2f5pdNol; Thu, 27 Apr 2023 14:31:56 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=QJ+t+iHL c=1 sm=1 tr=0 ts=644a875c a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=dKHAf1wccvYA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=wd5UjG2SHZ71tlQjt3kA:9 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=0j2+37HYjUlVysn7lBhoe0q+VmIrjKFC48Jy2A3NWg0=; b=m6XweKcHazNddke+1rO2ERxvh7 ceiAP2l7a4a8hArnNQNyw0YEo8kQkgw2a449SVeBe6IdOLpIQ129km84Ov0eSFKq3wzBsFhdZ/OSG oqPzFAFpLjf/RucUvXR009tjH; Received: from 71-211-191-82.hlrn.qwest.net ([71.211.191.82]:32958 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1ps2f5-000eJ9-Io; Thu, 27 Apr 2023 08:31:55 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Allow pretty-print of static members Date: Thu, 27 Apr 2023 08:31:45 -0600 Message-Id: <20230427143145.1800596-1-tom@tromey.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.191.82 X-Source-L: No X-Exim-ID: 1ps2f5-000eJ9-Io X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-191-82.hlrn.qwest.net (localhost.localdomain) [71.211.191.82]:32958 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3025.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Python pretty-printers haven't applied to static members for quite some time. I tracked this down to the call to cp_print_value_fields in cp_print_static_field -- it doesn't let pretty-printers have a chance to print the value. This patch fixes the problem. The way that static members are handled is very weird to me. I tend to think this should be done more globally, like in value_print. However, I haven't made any big change. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30057 Reviewed-by: Keith Seitz Tested-by: Keith Seitz --- gdb/cp-valprint.c | 47 ++++++++++++++------- gdb/testsuite/gdb.python/py-prettyprint.c | 11 +++++ gdb/testsuite/gdb.python/py-prettyprint.exp | 5 +++ 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index 167cf0314af..71bff16e3e6 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -381,6 +381,32 @@ cp_print_value_fields (struct value *val, struct ui_file *stream, gdb_printf (stream, "}"); } +/* A wrapper for cp_print_value_fields that tries to apply a + pretty-printer first. */ + +static void +cp_print_value_fields_pp (struct value *val, + struct ui_file *stream, + int recurse, + const struct value_print_options *options, + struct type **dont_print_vb, + int dont_print_statmem) +{ + int result = 0; + + /* Attempt to run an extension language pretty-printer if + possible. */ + if (!options->raw) + result + = apply_ext_lang_val_pretty_printer (val, stream, + recurse, options, + current_language); + + if (!result) + cp_print_value_fields (val, stream, recurse, options, dont_print_vb, + dont_print_statmem); +} + /* Special val_print routine to avoid printing multiple copies of virtual baseclasses. */ @@ -493,27 +519,16 @@ cp_print_value (struct value *val, struct ui_file *stream, val_print_invalid_address (stream); else { - int result = 0; - if (!val_print_check_max_depth (stream, recurse, options, current_language)) { struct value *baseclass_val = val->primitive_field (0, i, type); - /* Attempt to run an extension language pretty-printer on the - baseclass if possible. */ - if (!options->raw) - result - = apply_ext_lang_val_pretty_printer (baseclass_val, stream, - recurse, options, - current_language); - - if (!result) - cp_print_value_fields (baseclass_val, stream, recurse, options, - ((struct type **) - obstack_base (&dont_print_vb_obstack)), - 0); + cp_print_value_fields_pp + (baseclass_val, stream, recurse, options, + (struct type **) obstack_base (&dont_print_vb_obstack), + 0); } } gdb_puts (", ", stream); @@ -581,7 +596,7 @@ cp_print_static_field (struct type *type, obstack_grow (&dont_print_statmem_obstack, (char *) &addr, sizeof (CORE_ADDR)); - cp_print_value_fields (val, stream, recurse, options, NULL, 1); + cp_print_value_fields_pp (val, stream, recurse, options, nullptr, 1); return; } diff --git a/gdb/testsuite/gdb.python/py-prettyprint.c b/gdb/testsuite/gdb.python/py-prettyprint.c index 0832f4b545b..7697a5312a8 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.c +++ b/gdb/testsuite/gdb.python/py-prettyprint.c @@ -110,6 +110,14 @@ class Fake { } }; + +struct has_static_member +{ + static s global; +}; + +s has_static_member::global; + #endif struct to_string_returns_value_inner @@ -356,6 +364,9 @@ main () Derived derived; Fake fake (42); + + init_s (&has_static_member::global, 23); + has_static_member has_member; #endif add_item (&c, 23); /* MI breakpoint here */ diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp index b7661ff14ed..05507cba9c9 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.exp +++ b/gdb/testsuite/gdb.python/py-prettyprint.exp @@ -82,6 +82,11 @@ proc run_lang_tests {exefile lang} { gdb_test "print ns" "embedded\\\\000n\.\.\.." \ "print ns with element limit of 10" gdb_test_no_output "set print elements 200" + + gdb_test "print has_member" \ + "= a=<23> b=<$hex >.*" + gdb_test "print has_static_member::global" \ + "= a=<23> b=<$hex >" } if { ![is_address_zero_readable] } {