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):
# 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
class SliceTypePrinter:
"Pretty print slices."
- pattern = re.compile(oldnew(r'^struct \[\]',r'^\[\]'))
+ pattern = re.compile(r'^(struct \[\]|\[\])')
def __init__(self, val):
self.val = val
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)