From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 3DFE83858D35 for ; Fri, 5 May 2023 18:38:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3DFE83858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683311930; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5UpL/pAuROckLry18PwekxjFmTEk/fErAMuemRX++L4=; b=PJHAy/X+ciD0+idxzmrRkx505IGdVPmbfck4Lw/bo/8LCgH1LV4hwcGcJi/pLu3iNsrGFC LUyuNgr8PjAOotwCeuTYsVCBdKjmcgt10Yr/JIrQyFteJR6TA4MlezFQcbW1QJ3AvptEtr z7ElHPeEH6eyF1oSHNAwO2zDlFihQnI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-499-2Epdkg1XMFa7etHMLakJnA-1; Fri, 05 May 2023 14:38:49 -0400 X-MC-Unique: 2Epdkg1XMFa7etHMLakJnA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8F16C185A790; Fri, 5 May 2023 18:38:49 +0000 (UTC) Received: from [10.22.9.236] (unknown [10.22.9.236]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3BAD41121331; Fri, 5 May 2023 18:38:49 +0000 (UTC) Message-ID: Date: Fri, 5 May 2023 11:38:48 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH] Allow pretty-print of static members To: Tom Tromey , gdb-patches@sourceware.org References: <20230427143145.1800596-1-tom@tromey.com> From: Keith Seitz In-Reply-To: <20230427143145.1800596-1-tom@tromey.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 List-Id: On 4/27/23 07:31, Tom Tromey wrote: > 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. I never noticed, either, and it LGTM. Reviewed-by: Keith Seitz Tested-by: Keith Seitz > 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. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Yet? ;-) Keith > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30057 > --- > 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] } {