Gdb reload (#10408)
* gdb pretty printer survive reload * precise printer injection
This commit is contained in:
commit
a0e8d4a93f
1 changed files with 17 additions and 8 deletions
|
|
@ -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,20 @@ 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 register_nim_pretty_printers_for_object(objfile):
|
||||||
nimobjfile.pretty_printers.extend([makematcher(var) for var in list(vars().values()) if hasattr(var, 'pattern')])
|
nimMainSym = gdb.lookup_global_symbol("NimMain", gdb.SYMBOL_FUNCTIONS_DOMAIN)
|
||||||
|
if nimMainSym and nimMainSym.symtab.objfile == objfile:
|
||||||
|
print("set Nim pretty printers for ", objfile.filename)
|
||||||
|
|
||||||
|
objfile.type_printers = [NimTypePrinter()]
|
||||||
|
objfile.pretty_printers = [makematcher(var) for var in list(globals().values()) if hasattr(var, 'pattern')]
|
||||||
|
|
||||||
|
# Register pretty printers for all objfiles that are already loaded.
|
||||||
|
for old_objfile in gdb.objfiles():
|
||||||
|
register_nim_pretty_printers_for_object(old_objfile)
|
||||||
|
|
||||||
|
# Register an event handler to register nim pretty printers for all future objfiles.
|
||||||
|
def new_object_handler(event):
|
||||||
|
register_nim_pretty_printers_for_object(event.new_objfile)
|
||||||
|
|
||||||
|
gdb.events.new_objfile.connect(new_object_handler)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue