1
0
mirror of https://github.com/golang/go synced 2024-11-17 17:24:45 -07:00

runtime: fix prettyprinting of parametric types in gdb

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>
This commit is contained in:
Alessandro Arzilli 2021-09-17 13:48:39 +02:00 committed by David Chase
parent 6602c86a38
commit 6d02ce8584

View File

@ -219,6 +219,9 @@ class ChanTypePrinter:
yield ('[{0}]'.format(i), (ptr + j).dereference()) 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. # Register all the *Printer classes above.
# #
@ -228,6 +231,8 @@ def makematcher(klass):
try: try:
if klass.pattern.match(str(val.type)): if klass.pattern.match(str(val.type)):
return klass(val) return klass(val)
elif paramtypematch(val.type, klass.pattern):
return klass(val.cast(val.type.target()))
except Exception: except Exception:
pass pass
return matcher return matcher
@ -387,7 +392,7 @@ class GoLenFunc(gdb.Function):
def invoke(self, obj): def invoke(self, obj):
typename = str(obj.type) typename = str(obj.type)
for klass, fld in self.how: 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] return obj[fld]
@ -402,7 +407,7 @@ class GoCapFunc(gdb.Function):
def invoke(self, obj): def invoke(self, obj):
typename = str(obj.type) typename = str(obj.type)
for klass, fld in self.how: 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] return obj[fld]