gdb pretty printer survive reload

This commit is contained in:
Arne Döring 2019-01-21 14:22:16 +01:00
commit ea0c1811c5

View file

@ -1,4 +1,3 @@
import gdb import gdb
import re import re
import sys import sys
@ -16,8 +15,6 @@ def printErrorOnce(id, message):
errorSet.add(id) errorSet.add(id)
gdb.write(message, gdb.STDERR) gdb.write(message, gdb.STDERR)
nimobjfile = gdb.current_objfile() or gdb.objfiles()[0]
nimobjfile.type_printers = []
################################################################################ ################################################################################
##### Type pretty printers ##### Type pretty printers
@ -121,9 +118,6 @@ class NimTypePrinter:
def instantiate(self): def instantiate(self):
return NimTypeRecognizer() return NimTypeRecognizer()
nimobjfile.type_printers = [NimTypePrinter()]
################################################################################ ################################################################################
##### GDB Function, equivalent of Nim's $ operator ##### GDB Function, equivalent of Nim's $ operator
################################################################################ ################################################################################
@ -528,5 +522,11 @@ def makematcher(klass):
printErrorOnce(typeName, "No matcher for type '" + typeName + "': " + str(e) + "\n") printErrorOnce(typeName, "No matcher for type '" + typeName + "': " + str(e) + "\n")
return matcher return matcher
nimobjfile.pretty_printers = [] def new_object_handler(event):
nimobjfile.pretty_printers.extend([makematcher(var) for var in list(vars().values()) if hasattr(var, 'pattern')]) nimobjfile = gdb.current_objfile() or gdb.objfiles()[0]
nimobjfile.type_printers = []
nimobjfile.type_printers = [NimTypePrinter()]
nimobjfile.pretty_printers = []
nimobjfile.pretty_printers.extend([makematcher(var) for var in list(globals().values()) if hasattr(var, 'pattern')])
gdb.events.new_objfile.connect(new_object_handler)