mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 21:40:32 +00:00
Gdb reload (#10408)
* gdb pretty printer survive reload * precise printer injection
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import gdb
|
||||
import re
|
||||
import sys
|
||||
@@ -16,8 +15,6 @@ def printErrorOnce(id, message):
|
||||
errorSet.add(id)
|
||||
gdb.write(message, gdb.STDERR)
|
||||
|
||||
nimobjfile = gdb.current_objfile() or gdb.objfiles()[0]
|
||||
nimobjfile.type_printers = []
|
||||
|
||||
################################################################################
|
||||
##### Type pretty printers
|
||||
@@ -121,9 +118,6 @@ class NimTypePrinter:
|
||||
def instantiate(self):
|
||||
return NimTypeRecognizer()
|
||||
|
||||
|
||||
nimobjfile.type_printers = [NimTypePrinter()]
|
||||
|
||||
################################################################################
|
||||
##### GDB Function, equivalent of Nim's $ operator
|
||||
################################################################################
|
||||
@@ -528,5 +522,20 @@ def makematcher(klass):
|
||||
printErrorOnce(typeName, "No matcher for type '" + typeName + "': " + str(e) + "\n")
|
||||
return matcher
|
||||
|
||||
nimobjfile.pretty_printers = []
|
||||
nimobjfile.pretty_printers.extend([makematcher(var) for var in list(vars().values()) if hasattr(var, 'pattern')])
|
||||
def register_nim_pretty_printers_for_object(objfile):
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user