public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 6/7] Handle typedefs in no-op pretty printers
Date: Thu, 22 Jun 2023 10:19:32 -0600	[thread overview]
Message-ID: <20230614-dap-frame-decor-v2-6-10628dfa6b60@adacore.com> (raw)
In-Reply-To: <20230614-dap-frame-decor-v2-0-10628dfa6b60@adacore.com>

The no-ops pretty-printers that were introduced for DAP have a classic
gdb bug: they neglect to call check_typedef.  This will cause some
strange behavior; for example not showing the children of a variable
whose type is a typedef of a structure type.  This patch fixes the
oversight.
---
 gdb/python/lib/gdb/printing.py | 23 ++++++++++++-----------
 gdb/testsuite/gdb.dap/scopes.c |  6 +++---
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/gdb/python/lib/gdb/printing.py b/gdb/python/lib/gdb/printing.py
index 353427d000a..a668bd0e3fc 100644
--- a/gdb/python/lib/gdb/printing.py
+++ b/gdb/python/lib/gdb/printing.py
@@ -282,9 +282,9 @@ class NoOpScalarPrinter:
 class NoOpArrayPrinter:
     """A no-op pretty printer that wraps an array value."""
 
-    def __init__(self, value):
+    def __init__(self, ty, value):
         self.value = value
-        (low, high) = self.value.type.range()
+        (low, high) = ty.range()
         self.low = low
         self.high = high
         # This is a convenience to the DAP code and perhaps other
@@ -305,14 +305,15 @@ class NoOpArrayPrinter:
 class NoOpStructPrinter:
     """A no-op pretty printer that wraps a struct or union value."""
 
-    def __init__(self, value):
+    def __init__(self, ty, value):
+        self.ty = ty
         self.value = value
 
     def to_string(self):
         return ""
 
     def children(self):
-        for field in self.value.type.fields():
+        for field in self.ty.fields():
             if field.name is not None:
                 yield (field.name, self.value[field])
 
@@ -327,14 +328,14 @@ def make_visualizer(value):
     if result is not None:
         # Found a pretty-printer.
         pass
-    elif value.type.code == gdb.TYPE_CODE_ARRAY:
-        result = gdb.printing.NoOpArrayPrinter(value)
-        (low, high) = value.type.range()
-        result.n_children = high - low + 1
-    elif value.type.code in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION):
-        result = gdb.printing.NoOpStructPrinter(value)
     else:
-        result = gdb.printing.NoOpScalarPrinter(value)
+        ty = value.type.strip_typedefs()
+        if ty.code == gdb.TYPE_CODE_ARRAY:
+            result = gdb.printing.NoOpArrayPrinter(ty, value)
+        elif ty.code in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION):
+            result = gdb.printing.NoOpStructPrinter(ty, value)
+        else:
+            result = gdb.printing.NoOpScalarPrinter(value)
     return result
 
 
diff --git a/gdb/testsuite/gdb.dap/scopes.c b/gdb/testsuite/gdb.dap/scopes.c
index ce87db1f13d..8f17c0d9039 100644
--- a/gdb/testsuite/gdb.dap/scopes.c
+++ b/gdb/testsuite/gdb.dap/scopes.c
@@ -17,13 +17,13 @@
 
 int main ()
 {
-  struct dei_struct
+  typedef struct dei_struct
   {
     int x;
     int more[5];
-  };
+  } dei_type;
 
-  struct dei_struct dei = { 2, { 3, 5, 7, 11, 13 } };
+  dei_type dei = { 2, { 3, 5, 7, 11, 13 } };
 
   static int scalar = 23;
 

-- 
2.40.1


  parent reply	other threads:[~2023-06-22 16:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-22 16:19 [PATCH v2 0/7] Reimplement DAP backtrace using frame filters Tom Tromey
2023-06-22 16:19 ` [PATCH v2 1/7] Fix execute_frame_filters doc string Tom Tromey
2023-06-22 16:19 ` [PATCH v2 2/7] Add new interface to frame filter iteration Tom Tromey
2023-06-22 16:19 ` [PATCH v2 3/7] Fix oversights in frame decorator code Tom Tromey
2023-06-22 16:19 ` [PATCH v2 4/7] Simplify FrameVars Tom Tromey
2023-06-26 15:02   ` Tom Tromey
2023-06-22 16:19 ` [PATCH v2 5/7] Reimplement DAP stack traces using frame filters Tom Tromey
2023-06-22 16:19 ` Tom Tromey [this message]
2023-06-22 16:19 ` [PATCH v2 7/7] Add Ada scope test for DAP Tom Tromey
2023-06-26 15:07 ` [PATCH v2 0/7] Reimplement DAP backtrace using frame filters Tom Tromey
2023-07-10 19:14 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230614-dap-frame-decor-v2-6-10628dfa6b60@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).