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 8AC5C3858D28 for ; Wed, 9 Nov 2022 14:47:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8AC5C3858D28 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=1668005259; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6hQ1gaZThySKe48Tr9zAHb6Vz4HLteDEKT2e96Ts5X8=; b=hSYqN7nF8i2j+pQcYNNW7VYqjEKeWcfiO0fsKeea1VlY9Afm/J2PbXNTwbrxTFjPrNk81g y2IT2k+6An2XBUwbCzeuHpQYC/7/1yDRRdOq2syPgLoBpzb0pyxxkbId5CDjq0eOF/06A5 gKdvwT7rg3OCvYD/cfjvlN/CvBVpPb8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-551-o_TMXR72M-eL8NKM3gitZw-1; Wed, 09 Nov 2022 09:47:38 -0500 X-MC-Unique: o_TMXR72M-eL8NKM3gitZw-1 Received: by mail-wm1-f69.google.com with SMTP id bg25-20020a05600c3c9900b003cf3ed7e27bso8194321wmb.4 for ; Wed, 09 Nov 2022 06:47:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6hQ1gaZThySKe48Tr9zAHb6Vz4HLteDEKT2e96Ts5X8=; b=XD7NFCxHMIv5PSWwQ5SvuPIrgG37MVEVlEy07JV18zkCUyLQHgP2ykxUCoWgBTpJo3 E/eiz6G2313TnP32oz6PK1n25Sq7+k//scP+LzhOzeHkD3BdZDdLZLHFMRgMSUd3Rbpr cMyNpYeah42lSyeKw9CuKW3rxPzrHYskhPzBhEc2jaEih8xtt7M6Cx+49WPj90PI5otR ds9F9GlnyG8aKqQal8kHPWBuHpf6JclKmRnIsF3ao+kmQnOEiVKi3FON7Yugj2wVZaim gJz0qO5E3Hgr6u7rHlFQBjPayRb8as7oxUbjrPVb7pocyjHBXF2OZ5WDT2sA5O3gcCxZ Ax0g== X-Gm-Message-State: ACrzQf0zDcVXetYEbsAvUCDlI6J1tbc6FX5gPquQDsaSZ0AOKPFHgGul GIhXAHPxg4iPkK3v/XMZ/SjZRu16sArToViYoUmXHuCGXFsMmGW7wA8ae1GD17wgsEQ8MK8kohg eAdrXIgDihaKXnV4HYRlAgr+Dq/Lm3jlrEAOo9ErlA1k5kZvNtwA+Y3oOj+WRZcx6UXPHvK13pQ == X-Received: by 2002:a5d:6942:0:b0:23a:4e9d:c72c with SMTP id r2-20020a5d6942000000b0023a4e9dc72cmr19339945wrw.404.1668005257264; Wed, 09 Nov 2022 06:47:37 -0800 (PST) X-Google-Smtp-Source: AMsMyM7F4ya/K8fifyro/jemrcWW4rUlRQJ4to87XOKZB3NbntHSThXRaCHWO9MiDN4UAkW2Fm9GvA== X-Received: by 2002:a5d:6942:0:b0:23a:4e9d:c72c with SMTP id r2-20020a5d6942000000b0023a4e9dc72cmr19339927wrw.404.1668005256890; Wed, 09 Nov 2022 06:47:36 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id o39-20020a05600c33a700b003b47e75b401sm1681175wmp.37.2022.11.09.06.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 06:47:36 -0800 (PST) From: Andrew Burgess To: Tom Tromey via Gdb-patches , gdb-patches@sourceware.org Cc: Tom Tromey Subject: Re: [PATCH] Allow 'ptype/o' for assembly In-Reply-To: <20221108201452.1255047-1-tromey@adacore.com> References: <20221108201452.1255047-1-tromey@adacore.com> Date: Wed, 09 Nov 2022 14:47:34 +0000 Message-ID: <87zgd09oc9.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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: Tom Tromey via Gdb-patches writes: > PR exp/28359 points out that 'ptype/o' does not work when the current > language is "asm". > > I tracked this down to a hard-coded list of languages in typeprint.c. > This patch replaces this list with a method on 'language_defn' > instead. If all languages are ever updated to have this feature, the > method could be removed; but in the meantime this lets each language > control what happens. > > I looked at having each print_type method simply modify the flags > itself, but this doesn't work very well with the feature that disables > method-printing by default (but allows it via a flag). LGTM. Thanks, Andrew > --- > gdb/c-lang.c | 28 ++++++++++++++++++++++++ > gdb/d-lang.c | 7 ++++++ > gdb/language.h | 7 ++++++ > gdb/objc-lang.c | 7 ++++++ > gdb/opencl-lang.c | 7 ++++++ > gdb/rust-lang.h | 7 ++++++ > gdb/testsuite/gdb.base/ptype-offsets.exp | 13 +++++++++++ > gdb/typeprint.c | 4 +--- > 8 files changed, 77 insertions(+), 3 deletions(-) > > diff --git a/gdb/c-lang.c b/gdb/c-lang.c > index 36b4d1ae3dd..e15541f8175 100644 > --- a/gdb/c-lang.c > +++ b/gdb/c-lang.c > @@ -816,6 +816,13 @@ class c_language : public language_defn > > /* See language.h. */ > > + bool can_print_type_offsets () const override > + { > + return true; > + } > + > + /* See language.h. */ > + > void print_type (struct type *type, const char *varstring, > struct ui_file *stream, int show, int level, > const struct type_print_options *flags) const override > @@ -966,6 +973,13 @@ class cplus_language : public language_defn > > /* See language.h. */ > > + bool can_print_type_offsets () const override > + { > + return true; > + } > + > + /* See language.h. */ > + > void print_type (struct type *type, const char *varstring, > struct ui_file *stream, int show, int level, > const struct type_print_options *flags) const override > @@ -1066,6 +1080,13 @@ class asm_language : public language_defn > > /* See language.h. */ > > + bool can_print_type_offsets () const override > + { > + return true; > + } > + > + /* See language.h. */ > + > void print_type (struct type *type, const char *varstring, > struct ui_file *stream, int show, int level, > const struct type_print_options *flags) const override > @@ -1118,6 +1139,13 @@ class minimal_language : public language_defn > > /* See language.h. */ > > + bool can_print_type_offsets () const override > + { > + return true; > + } > + > + /* See language.h. */ > + > void print_type (struct type *type, const char *varstring, > struct ui_file *stream, int show, int level, > const struct type_print_options *flags) const override > diff --git a/gdb/d-lang.c b/gdb/d-lang.c > index d9591997c87..bb48af6d7c6 100644 > --- a/gdb/d-lang.c > +++ b/gdb/d-lang.c > @@ -144,6 +144,13 @@ class d_language : public language_defn > > /* See language.h. */ > > + bool can_print_type_offsets () const override > + { > + return true; > + } > + > + /* See language.h. */ > + > void print_type (struct type *type, const char *varstring, > struct ui_file *stream, int show, int level, > const struct type_print_options *flags) const override > diff --git a/gdb/language.h b/gdb/language.h > index 871b00b3c94..c1c735ad9ae 100644 > --- a/gdb/language.h > +++ b/gdb/language.h > @@ -451,6 +451,13 @@ struct language_defn > return nullptr; > } > > + /* Return true if this class' implementation of print_type can > + handle the /o modifier. */ > + virtual bool can_print_type_offsets () const > + { > + return false; > + } > + > /* Print TYPE to STREAM using syntax appropriate for this language. > LEVEL is the depth to indent lines by. VARSTRING, if not NULL or the > empty string, is the name of a variable and TYPE should be printed in > diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c > index 1a1d6215475..3c2cbf401f0 100644 > --- a/gdb/objc-lang.c > +++ b/gdb/objc-lang.c > @@ -266,6 +266,13 @@ class objc_language : public language_defn > > /* See language.h. */ > > + bool can_print_type_offsets () const override > + { > + return true; > + } > + > + /* See language.h. */ > + > void print_type (struct type *type, const char *varstring, > struct ui_file *stream, int show, int level, > const struct type_print_options *flags) const override > diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c > index e41db3dcbba..f7cf00c6919 100644 > --- a/gdb/opencl-lang.c > +++ b/gdb/opencl-lang.c > @@ -953,6 +953,13 @@ class opencl_language : public language_defn > > /* See language.h. */ > > + bool can_print_type_offsets () const override > + { > + return true; > + } > + > + /* See language.h. */ > + > void print_type (struct type *type, const char *varstring, > struct ui_file *stream, int show, int level, > const struct type_print_options *flags) const override > diff --git a/gdb/rust-lang.h b/gdb/rust-lang.h > index f4c7b7fc1c8..a1d10263feb 100644 > --- a/gdb/rust-lang.h > +++ b/gdb/rust-lang.h > @@ -107,6 +107,13 @@ class rust_language : public language_defn > > /* See language.h. */ > > + bool can_print_type_offsets () const override > + { > + return true; > + } > + > + /* See language.h. */ > + > void print_type (struct type *type, const char *varstring, > struct ui_file *stream, int show, int level, > const struct type_print_options *flags) const override; > diff --git a/gdb/testsuite/gdb.base/ptype-offsets.exp b/gdb/testsuite/gdb.base/ptype-offsets.exp > index eb41bafb3e6..b42fa4dac43 100644 > --- a/gdb/testsuite/gdb.base/ptype-offsets.exp > +++ b/gdb/testsuite/gdb.base/ptype-offsets.exp > @@ -469,3 +469,16 @@ with_test_prefix "with_hex_default" { > # restore > gdb_test_no_output "set print type hex off" > } > + > +gdb_test_no_output "set language asm" > +gdb_test "ptype/o struct tuv" \ > + [string_to_regexp [multi_line \ > + "/* offset | size */ type = struct tuv \{" \ > + "/* 0 | 4 */ int a1;" \ > + "/* XXX 4-byte hole */" \ > + "/* 8 | 8 */ signed char *a2;" \ > + "/* 16 | 4 */ int a3;" \ > + "/* XXX 4-byte padding */" \ > + "" \ > + " /* total size (bytes): 24 */" \ > + " \}"]] > diff --git a/gdb/typeprint.c b/gdb/typeprint.c > index 79043122b17..7a7ac6c314e 100644 > --- a/gdb/typeprint.c > +++ b/gdb/typeprint.c > @@ -478,9 +478,7 @@ whatis_exp (const char *exp, int show) > /* Filter out languages which don't implement the > feature. */ > if (show > 0 > - && (current_language->la_language == language_c > - || current_language->la_language == language_cplus > - || current_language->la_language == language_rust)) > + && current_language->can_print_type_offsets ()) > { > flags.print_offsets = 1; > flags.print_typedefs = 0; > -- > 2.34.3