]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Allow 'ptype/o' for assembly
authorTom Tromey <tromey@adacore.com>
Mon, 7 Nov 2022 18:12:35 +0000 (11:12 -0700)
committerTom Tromey <tromey@adacore.com>
Wed, 9 Nov 2022 15:37:25 +0000 (08:37 -0700)
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).

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28359
Approved-By: Andrew Burgess <aburgess@redhat.com>
Approved-By: Keith Seitz <keiths@redhat.com>
gdb/c-lang.c
gdb/d-lang.c
gdb/language.h
gdb/objc-lang.c
gdb/opencl-lang.c
gdb/rust-lang.h
gdb/testsuite/gdb.base/ptype-offsets.exp
gdb/typeprint.c

index 36b4d1ae3ddddfdbf0e2880bcc2ddc13430abb0e..e15541f81759ee344478649563bba500dacda040 100644 (file)
@@ -816,6 +816,13 @@ public:
 
   /* 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 @@ public:
 
   /* 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 @@ public:
 
   /* 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 @@ public:
 
   /* 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
index d9591997c876f508956223bd72527a4289d44659..bb48af6d7c6891b12358db3b0251c940ea78ac61 100644 (file)
@@ -144,6 +144,13 @@ public:
 
   /* 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
index 871b00b3c94996ffc8a253943626c1da2333d81c..c1c735ad9ae2e4e236c99af733c249e3b492d3c4 100644 (file)
@@ -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
index 1a1d621547586aee7b0a264c640887667973201f..3c2cbf401f0bad4fa32e1389f27c274d131a41b2 100644 (file)
@@ -266,6 +266,13 @@ public:
 
   /* 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
index e41db3dcbbaa58fec38fbaf238feea6ecf5509f9..f7cf00c6919606bc03a40073b07bcd4d37ef021e 100644 (file)
@@ -953,6 +953,13 @@ public:
 
   /* 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
index f4c7b7fc1c8005be33becdfad3beb9cc7ffd0648..a1d10263feb3ffc355ad983de1600d7399d0c2c5 100644 (file)
@@ -107,6 +107,13 @@ public:
 
   /* 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;
index eb41bafb3e6a96fed9bc79b43405a07641fc034f..b42fa4dac436999767f12177477f444b1bc2e4a6 100644 (file)
@@ -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 */" \
+  "                             \}"]]
index 79043122b174d8d710351440bcfd8c1e6f919d28..7a7ac6c314ecf824d6261d65b160414f3198947b 100644 (file)
@@ -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;