aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2020-06-03 14:21:18 -0400
committerDavid Chase <drchase@google.com>2020-06-03 22:07:42 +0000
commit429d2c548d8fcceff95c29ea5074aab9498fa0c3 (patch)
tree66201facf725957736430ac11d1165e5cbcfb7cd
parent23dcee64643fef66663272cd123dc7b42dfa67c9 (diff)
downloadgo-429d2c548d8fcceff95c29ea5074aab9498fa0c3.tar.gz
go-429d2c548d8fcceff95c29ea5074aab9498fa0c3.zip
runtime: make runtime-gdb.py tolerant of creatively-named gdb versions
"Fedora" and "Red Hat" are not numbers, it turns out. Don't rely on version numbers, instead use a regexp to handle variation across the 2 patterns thus far observed for gdb-generated Go type names. Change-Id: I18c81aa2848265a47daf1180d8f6678566ae3f19 Reviewed-on: https://go-review.googlesource.com/c/go/+/236280 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/runtime/runtime-gdb.py29
1 files changed, 7 insertions, 22 deletions
diff --git a/src/runtime/runtime-gdb.py b/src/runtime/runtime-gdb.py
index 7b5ba71832..8d96dfb609 100644
--- a/src/runtime/runtime-gdb.py
+++ b/src/runtime/runtime-gdb.py
@@ -28,24 +28,6 @@ if sys.version > '3':
goobjfile = gdb.current_objfile() or gdb.objfiles()[0]
goobjfile.pretty_printers = []
-# A bit of hand optimization since oldnew is used for slice printing
-splitgdbversion = gdb.VERSION.split('.')
-majorgdbversion = int(splitgdbversion[0])
-
-# Older gdb renders some types differently.
-def oldnew(old, new):
- if majorgdbversion < 8:
- return old
- if majorgdbversion > 8:
- return new
- try:
- # Minor versions need not be actual numbers, e.g., 7.3a.
- if int(splitgdbversion[1]) < 2:
- return old
- except Exception:
- return new # All the existing gdb 8.minor versions are numbers, so if it is not a number, it is new.
- return new
-
# G state (runtime2.go)
def read_runtime_const(varname, default):
@@ -117,11 +99,11 @@ class SliceValue:
# Pretty Printers
#
-
+# The patterns for matching types are permissive because gdb 8.2 switched to matching on (we think) typedef names instead of C syntax names.
class StringTypePrinter:
"Pretty print Go strings."
- pattern = re.compile(oldnew(r'^struct string( \*)?$',r'^string$'))
+ pattern = re.compile(r'^(struct string( \*)?|string)$')
def __init__(self, val):
self.val = val
@@ -137,7 +119,7 @@ class StringTypePrinter:
class SliceTypePrinter:
"Pretty print slices."
- pattern = re.compile(oldnew(r'^struct \[\]',r'^\[\]'))
+ pattern = re.compile(r'^(struct \[\]|\[\])')
def __init__(self, val):
self.val = val
@@ -146,7 +128,10 @@ class SliceTypePrinter:
return 'array'
def to_string(self):
- return str(self.val.type)[oldnew(6,0):] # skip 'struct ' for old gdb
+ t = str(self.val.type)
+ if (t.startswith("struct ")):
+ return t[len("struct "):]
+ return t
def children(self):
sval = SliceValue(self.val)