From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 667AD3858D1E; Wed, 9 Nov 2022 15:40:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 667AD3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668008448; bh=wMrSN6KTsfQTrqGpL2qBnzr4Ap3Veno/EaG6b39ty+M=; h=From:To:Subject:Date:From; b=wQjTNfGcDjde1t9ri2xva+JLU7SnMK9xI2q+o1qTxDEiRLpTHPAotjLH5a90JMvEq 2KNDRGLQLAtty2jmmXyCyq7jocz0DY6gMA181St2SNOZRIreuHN7wrwIogKbFnDD80 Hic6/PP3XQQTL/9yrOE8iqcxiBvOaF/QuyYT5LJk= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Allow 'ptype/o' for assembly X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: c2264c8f78f353daebce3086ae52b3c1cf2f0a8d X-Git-Newrev: 97e20099d3b02baafe244e975aebe09020d2ab34 Message-Id: <20221109154048.667AD3858D1E@sourceware.org> Date: Wed, 9 Nov 2022 15:40:48 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D97e20099d3b0= 2baafe244e975aebe09020d2ab34 commit 97e20099d3b02baafe244e975aebe09020d2ab34 Author: Tom Tromey Date: Mon Nov 7 11:12:35 2022 -0700 Allow 'ptype/o' for assembly =20 PR exp/28359 points out that 'ptype/o' does not work when the current language is "asm". =20 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. =20 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). =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D28359 Approved-By: Andrew Burgess Approved-By: Keith Seitz Diff: --- 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 @@ public: =20 /* See language.h. */ =20 + 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 @@ public: =20 /* See language.h. */ =20 + 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 @@ public: =20 /* See language.h. */ =20 + 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 @@ public: =20 /* See language.h. */ =20 + 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 @@ public: =20 /* See language.h. */ =20 + 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; } =20 + /* 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 @@ public: =20 /* See language.h. */ =20 + 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 @@ public: =20 /* See language.h. */ =20 + 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 @@ public: =20 /* See language.h. */ =20 + 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.b= ase/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 =3D 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 =3D=3D language_c - || current_language->la_language =3D=3D language_cplus - || current_language->la_language =3D=3D language_rust)) + && current_language->can_print_type_offsets ()) { flags.print_offsets =3D 1; flags.print_typedefs =3D 0;