]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix prettyprinting of parametric types in gdb
authorAlessandro Arzilli <alessandro.arzilli@gmail.com>
Fri, 17 Sep 2021 11:48:39 +0000 (13:48 +0200)
committerDavid Chase <drchase@google.com>
Fri, 17 Sep 2021 15:07:28 +0000 (15:07 +0000)
golang.org/cl/344929 broke the minimal functionality that the python
pretty printer for GDB had, this change restores it to its status prior
to that CL.

Change-Id: I4c7141d4ff726d224a074ecc533d0f896fc0052c
Reviewed-on: https://go-review.googlesource.com/c/go/+/350529
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Trust: Than McIntosh <thanm@google.com>

src/runtime/runtime-gdb.py

index 8d96dfb6094ae077734592528db84afcc36d1feb..5bb605cc37b567abfd90457b24be15718fb27b6a 100644 (file)
@@ -219,6 +219,9 @@ class ChanTypePrinter:
                        yield ('[{0}]'.format(i), (ptr + j).dereference())
 
 
+def paramtypematch(t, pattern):
+       return t.code == gdb.TYPE_CODE_TYPEDEF and str(t).startswith(".param") and pattern.match(str(t.target()))
+
 #
 #  Register all the *Printer classes above.
 #
@@ -228,6 +231,8 @@ def makematcher(klass):
                try:
                        if klass.pattern.match(str(val.type)):
                                return klass(val)
+                       elif paramtypematch(val.type, klass.pattern):
+                               return klass(val.cast(val.type.target()))
                except Exception:
                        pass
        return matcher
@@ -387,7 +392,7 @@ class GoLenFunc(gdb.Function):
        def invoke(self, obj):
                typename = str(obj.type)
                for klass, fld in self.how:
-                       if klass.pattern.match(typename):
+                       if klass.pattern.match(typename) or paramtypematch(obj.type, klass.pattern):
                                return obj[fld]
 
 
@@ -402,7 +407,7 @@ class GoCapFunc(gdb.Function):
        def invoke(self, obj):
                typename = str(obj.type)
                for klass, fld in self.how:
-                       if klass.pattern.match(typename):
+                       if klass.pattern.match(typename) or paramtypematch(obj.type, klass.pattern):
                                return obj[fld]