nim-gdb.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. import gdb
  2. import re
  3. import sys
  4. import traceback
  5. # some feedback that the nim runtime support is loading, isn't a bad
  6. # thing at all.
  7. gdb.write("Loading Nim Runtime support.\n", gdb.STDERR)
  8. # When error occure they occur regularly. This 'caches' known errors
  9. # and prevents them from being reprinted over and over again.
  10. errorSet = set()
  11. def printErrorOnce(id, message):
  12. global errorSet
  13. if id not in errorSet:
  14. errorSet.add(id)
  15. gdb.write("printErrorOnce: " + message, gdb.STDERR)
  16. def debugPrint(x):
  17. gdb.write(str(x) + "\n", gdb.STDERR)
  18. NIM_STRING_TYPES = ["NimStringDesc", "NimStringV2"]
  19. ################################################################################
  20. ##### Type pretty printers
  21. ################################################################################
  22. type_hash_regex = re.compile("^([A-Za-z0-9]*)_([A-Za-z0-9]*)_+([A-Za-z0-9]*)$")
  23. def getNimName(typ):
  24. if m := type_hash_regex.match(typ):
  25. return m.group(2)
  26. return f"unknown <{typ}>"
  27. def getNimRti(type_name):
  28. """ Return a ``gdb.Value`` object for the Nim Runtime Information of ``type_name``. """
  29. # Get static const TNimType variable. This should be available for
  30. # every non trivial Nim type.
  31. m = type_hash_regex.match(type_name)
  32. if m:
  33. lookups = [
  34. "NTI" + m.group(2).lower() + "__" + m.group(3) + "_",
  35. "NTI" + "__" + m.group(3) + "_",
  36. "NTI" + m.group(2).replace("colon", "58").lower() + "__" + m.group(3) + "_"
  37. ]
  38. for l in lookups:
  39. try:
  40. return gdb.parse_and_eval(l)
  41. except:
  42. pass
  43. None
  44. def getNameFromNimRti(rti):
  45. """ Return name (or None) given a Nim RTI ``gdb.Value`` """
  46. try:
  47. # sometimes there isn't a name field -- example enums
  48. return rti['name'].string(encoding="utf-8", errors="ignore")
  49. except:
  50. return None
  51. class NimTypeRecognizer:
  52. # this type map maps from types that are generated in the C files to
  53. # how they are called in nim. To not mix up the name ``int`` from
  54. # system.nim with the name ``int`` that could still appear in
  55. # generated code, ``NI`` is mapped to ``system.int`` and not just
  56. # ``int``.
  57. type_map_static = {
  58. 'NI': 'system.int', 'NI8': 'int8', 'NI16': 'int16', 'NI32': 'int32',
  59. 'NI64': 'int64',
  60. 'NU': 'uint', 'NU8': 'uint8','NU16': 'uint16', 'NU32': 'uint32',
  61. 'NU64': 'uint64',
  62. 'NF': 'float', 'NF32': 'float32', 'NF64': 'float64',
  63. 'NIM_BOOL': 'bool',
  64. 'NIM_CHAR': 'char', 'NCSTRING': 'cstring', 'NimStringDesc': 'string', 'NimStringV2': 'string'
  65. }
  66. # object_type_pattern = re.compile("^(\w*):ObjectType$")
  67. def recognize(self, type_obj):
  68. # skip things we can't handle like functions
  69. if type_obj.code in [gdb.TYPE_CODE_FUNC, gdb.TYPE_CODE_VOID]:
  70. return None
  71. tname = None
  72. if type_obj.tag is not None:
  73. tname = type_obj.tag
  74. elif type_obj.name is not None:
  75. tname = type_obj.name
  76. # handle pointer types
  77. if not tname:
  78. target_type = type_obj
  79. if type_obj.code in [gdb.TYPE_CODE_PTR]:
  80. target_type = type_obj.target()
  81. if target_type.name:
  82. # visualize 'string' as non pointer type (unpack pointer type).
  83. if target_type.name == "NimStringDesc":
  84. tname = target_type.name # could also just return 'string'
  85. else:
  86. rti = getNimRti(target_type.name)
  87. if rti:
  88. return getNameFromNimRti(rti)
  89. if tname:
  90. result = self.type_map_static.get(tname, None)
  91. if result:
  92. return result
  93. elif tname.startswith("tyEnum_"):
  94. return getNimName(tname)
  95. elif tname.startswith("tyTuple__"):
  96. # We make the name be the field types (Just like in Nim)
  97. fields = ", ".join([self.recognize(field.type) for field in type_obj.fields()])
  98. return f"({fields})"
  99. rti = getNimRti(tname)
  100. if rti:
  101. return getNameFromNimRti(rti)
  102. return None
  103. class NimTypePrinter:
  104. """Nim type printer. One printer for all Nim types."""
  105. # enabling and disabling of type printers can be done with the
  106. # following gdb commands:
  107. #
  108. # enable type-printer NimTypePrinter
  109. # disable type-printer NimTypePrinter
  110. # relevant docs: https://sourceware.org/gdb/onlinedocs/gdb/Type-Printing-API.html
  111. name = "NimTypePrinter"
  112. def __init__(self):
  113. self.enabled = True
  114. def instantiate(self):
  115. return NimTypeRecognizer()
  116. ################################################################################
  117. ##### GDB Function, equivalent of Nim's $ operator
  118. ################################################################################
  119. class DollarPrintFunction (gdb.Function):
  120. "Nim's equivalent of $ operator as a gdb function, available in expressions `print $dollar(myvalue)"
  121. dollar_functions = re.findall(
  122. r'(?:NimStringDesc \*|NimStringV2)\s?(dollar__[A-z0-9_]+?)\(([^,)]*)\);',
  123. gdb.execute("info functions dollar__", True, True)
  124. )
  125. def __init__ (self):
  126. super (DollarPrintFunction, self).__init__("dollar")
  127. @staticmethod
  128. def invoke_static(arg, ignore_errors = False):
  129. if arg.type.code == gdb.TYPE_CODE_PTR and arg.type.target().name in NIM_STRING_TYPES:
  130. return arg
  131. argTypeName = str(arg.type)
  132. for func, arg_typ in DollarPrintFunction.dollar_functions:
  133. # this way of overload resolution cannot deal with type aliases,
  134. # therefore it won't find all overloads.
  135. if arg_typ == argTypeName:
  136. func_value = gdb.lookup_global_symbol(func, gdb.SYMBOL_FUNCTION_DOMAIN).value()
  137. return func_value(arg)
  138. elif arg_typ == argTypeName + " *":
  139. func_value = gdb.lookup_global_symbol(func, gdb.SYMBOL_FUNCTION_DOMAIN).value()
  140. return func_value(arg.address)
  141. if not ignore_errors:
  142. debugPrint(f"No suitable Nim $ operator found for type: {getNimName(argTypeName)}\n")
  143. return None
  144. def invoke(self, arg):
  145. return self.invoke_static(arg)
  146. DollarPrintFunction()
  147. ################################################################################
  148. ##### GDB Function, Nim string comparison
  149. ################################################################################
  150. class NimStringEqFunction (gdb.Function):
  151. """Compare Nim strings for example in conditionals for breakpoints."""
  152. def __init__ (self):
  153. super (NimStringEqFunction, self).__init__("nimstreq")
  154. @staticmethod
  155. def invoke_static(arg1,arg2):
  156. if arg1.type.code == gdb.TYPE_CODE_PTR and arg1.type.target().name in NIM_STRING_TYPES:
  157. str1 = NimStringPrinter(arg1).to_string()
  158. else:
  159. str1 = arg1.string()
  160. if arg2.type.code == gdb.TYPE_CODE_PTR and arg2.type.target().name in NIM_STRING_TYPES:
  161. str2 = NimStringPrinter(arg1).to_string()
  162. else:
  163. str2 = arg2.string()
  164. return str1 == str2
  165. def invoke(self, arg1, arg2):
  166. return self.invoke_static(arg1, arg2)
  167. NimStringEqFunction()
  168. ################################################################################
  169. ##### GDB Command, equivalent of Nim's $ operator
  170. ################################################################################
  171. class DollarPrintCmd (gdb.Command):
  172. """Dollar print command for Nim, `$ expr` will invoke Nim's $ operator and print the result."""
  173. def __init__ (self):
  174. super (DollarPrintCmd, self).__init__ ("$", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION)
  175. def invoke(self, arg, from_tty):
  176. param = gdb.parse_and_eval(arg)
  177. strValue = DollarPrintFunction.invoke_static(param)
  178. if strValue:
  179. gdb.write(
  180. str(NimStringPrinter(strValue)) + "\n",
  181. gdb.STDOUT
  182. )
  183. # could not find a suitable dollar overload. This here is the
  184. # fallback to get sensible output of basic types anyway.
  185. elif param.type.code == gdb.TYPE_CODE_ARRAY and param.type.target().name == "char":
  186. gdb.write(param.string("utf-8", "ignore") + "\n", gdb.STDOUT)
  187. elif param.type.code == gdb.TYPE_CODE_INT:
  188. gdb.write(str(int(param)) + "\n", gdb.STDOUT)
  189. elif param.type.name == "NIM_BOOL":
  190. if int(param) != 0:
  191. gdb.write("true\n", gdb.STDOUT)
  192. else:
  193. gdb.write("false\n", gdb.STDOUT)
  194. DollarPrintCmd()
  195. ################################################################################
  196. ##### GDB Commands to invoke common nim tools.
  197. ################################################################################
  198. import subprocess, os
  199. class KochCmd (gdb.Command):
  200. """Command that invokes ``koch'', the build tool for the compiler."""
  201. def __init__ (self):
  202. super (KochCmd, self).__init__ ("koch",
  203. gdb.COMMAND_USER, gdb.COMPLETE_FILENAME)
  204. self.binary = os.path.join(
  205. os.path.dirname(os.path.dirname(__file__)), "koch")
  206. def invoke(self, argument, from_tty):
  207. subprocess.run([self.binary] + gdb.string_to_argv(argument))
  208. KochCmd()
  209. class NimCmd (gdb.Command):
  210. """Command that invokes ``nim'', the nim compiler."""
  211. def __init__ (self):
  212. super (NimCmd, self).__init__ ("nim",
  213. gdb.COMMAND_USER, gdb.COMPLETE_FILENAME)
  214. self.binary = os.path.join(
  215. os.path.dirname(os.path.dirname(__file__)), "bin/nim")
  216. def invoke(self, argument, from_tty):
  217. subprocess.run([self.binary] + gdb.string_to_argv(argument))
  218. NimCmd()
  219. class NimbleCmd (gdb.Command):
  220. """Command that invokes ``nimble'', the nim package manager and build tool."""
  221. def __init__ (self):
  222. super (NimbleCmd, self).__init__ ("nimble",
  223. gdb.COMMAND_USER, gdb.COMPLETE_FILENAME)
  224. self.binary = os.path.join(
  225. os.path.dirname(os.path.dirname(__file__)), "bin/nimble")
  226. def invoke(self, argument, from_tty):
  227. subprocess.run([self.binary] + gdb.string_to_argv(argument))
  228. NimbleCmd()
  229. ################################################################################
  230. ##### Value pretty printers
  231. ################################################################################
  232. class NimBoolPrinter:
  233. pattern = re.compile(r'^NIM_BOOL$')
  234. def __init__(self, val):
  235. self.val = val
  236. def to_string(self):
  237. if self.val == 0:
  238. return "false"
  239. else:
  240. return "true"
  241. ################################################################################
  242. def strFromLazy(strVal):
  243. if isinstance(strVal, str):
  244. return strVal
  245. else:
  246. return strVal.value().string("utf-8")
  247. class NimStringPrinter:
  248. pattern = re.compile(r'^(NimStringDesc \*|NimStringV2)$')
  249. def __init__(self, val):
  250. self.val = val
  251. def display_hint(self):
  252. return 'string'
  253. def to_string(self):
  254. if self.val:
  255. if self.val.type.name == "NimStringV2":
  256. l = int(self.val["len"])
  257. data = self.val["p"]["data"]
  258. else:
  259. l = int(self.val['Sup']['len'])
  260. data = self.val["data"]
  261. return data.lazy_string(encoding="utf-8", length=l)
  262. else:
  263. return ""
  264. def __str__(self):
  265. return strFromLazy(self.to_string())
  266. class NimRopePrinter:
  267. pattern = re.compile(r'^tyObject_RopeObj__([A-Za-z0-9]*) \*$')
  268. def __init__(self, val):
  269. self.val = val
  270. def display_hint(self):
  271. return 'string'
  272. def to_string(self):
  273. if self.val:
  274. left = NimRopePrinter(self.val["left"]).to_string()
  275. data = NimStringPrinter(self.val["data"]).to_string()
  276. right = NimRopePrinter(self.val["right"]).to_string()
  277. return left + data + right
  278. else:
  279. return ""
  280. ################################################################################
  281. def reprEnum(e, typ):
  282. # Casts the value to the enum type and then calls the enum printer
  283. e = int(e)
  284. val = gdb.Value(e).cast(typ)
  285. return strFromLazy(NimEnumPrinter(val).to_string())
  286. def enumNti(typeNimName, idString):
  287. typeInfoName = "NTI" + typeNimName.lower() + "__" + idString + "_"
  288. nti = gdb.lookup_global_symbol(typeInfoName)
  289. if nti is None:
  290. typeInfoName = "NTI" + "__" + idString + "_"
  291. nti = gdb.lookup_global_symbol(typeInfoName)
  292. return (typeInfoName, nti)
  293. class NimEnumPrinter:
  294. pattern = re.compile(r'^tyEnum_([A-Za-z0-9]+)__([A-Za-z0-9]*)$')
  295. enumReprProc = gdb.lookup_global_symbol("reprEnum", gdb.SYMBOL_FUNCTION_DOMAIN)
  296. def __init__(self, val):
  297. self.val = val
  298. typeName = self.val.type.name
  299. match = self.pattern.match(typeName)
  300. self.typeNimName = match.group(1)
  301. typeInfoName, self.nti = enumNti(self.typeNimName, match.group(2))
  302. def to_string(self):
  303. if NimEnumPrinter.enumReprProc and self.nti:
  304. # Use the old runtimes enumRepr function.
  305. # We call the Nim proc itself so that the implementation is correct
  306. f = gdb.newest_frame()
  307. # We need to strip the quotes so it looks like an enum instead of a string
  308. reprProc = NimEnumPrinter.enumReprProc.value()
  309. return str(reprProc(self.val, self.nti.value(f).address)).strip('"')
  310. elif dollarResult := DollarPrintFunction.invoke_static(self.val):
  311. # New runtime doesn't use enumRepr so we instead try and call the
  312. # dollar function for it
  313. return str(NimStringPrinter(dollarResult))
  314. else:
  315. return self.typeNimName + "(" + str(int(self.val)) + ")"
  316. ################################################################################
  317. class NimSetPrinter:
  318. ## the set printer is limited to sets that fit in an integer. Other
  319. ## sets are compiled to `NU8 *` (ptr uint8) and are invisible to
  320. ## gdb (currently).
  321. pattern = re.compile(r'^tySet_tyEnum_([A-Za-z0-9]+)__([A-Za-z0-9]*)$')
  322. def __init__(self, val):
  323. self.val = val
  324. typeName = self.val.type.name
  325. match = self.pattern.match(typeName)
  326. self.typeNimName = match.group(1)
  327. def to_string(self):
  328. # Remove the tySet from the type name
  329. typ = gdb.lookup_type(self.val.type.name[6:])
  330. enumStrings = []
  331. val = int(self.val)
  332. i = 0
  333. while val > 0:
  334. if (val & 1) == 1:
  335. enumStrings.append(reprEnum(i, typ))
  336. val = val >> 1
  337. i += 1
  338. return '{' + ', '.join(enumStrings) + '}'
  339. ################################################################################
  340. class NimHashSetPrinter:
  341. pattern = re.compile(r'^tyObject_(HashSet)__([A-Za-z0-9]*)$')
  342. def __init__(self, val):
  343. self.val = val
  344. def display_hint(self):
  345. return 'array'
  346. def to_string(self):
  347. counter = 0
  348. capacity = 0
  349. if self.val:
  350. counter = int(self.val['counter'])
  351. if self.val['data']:
  352. capacity = int(self.val['data']['Sup']['len'])
  353. return 'HashSet({0}, {1})'.format(counter, capacity)
  354. def children(self):
  355. if self.val:
  356. data = NimSeqPrinter(self.val['data'])
  357. for idxStr, entry in data.children():
  358. if int(entry['Field0']) > 0:
  359. yield ("data." + idxStr + ".Field1", str(entry['Field1']))
  360. ################################################################################
  361. class NimSeq:
  362. # Wrapper around sequences.
  363. # This handles the differences between old and new runtime
  364. def __init__(self, val):
  365. self.val = val
  366. # new runtime has sequences on stack, old has them on heap
  367. self.new = val.type.code != gdb.TYPE_CODE_PTR
  368. if self.new:
  369. # Some seqs are just the content and to save repeating ourselves we do
  370. # handle them here. Only thing that needs to check this is the len/data getters
  371. self.isContent = val.type.name.endswith("Content")
  372. def __bool__(self):
  373. if self.new:
  374. return self.val is not None
  375. else:
  376. return bool(self.val)
  377. def __len__(self):
  378. if not self:
  379. return 0
  380. if self.new:
  381. if self.isContent:
  382. return int(self.val["cap"])
  383. else:
  384. return int(self.val["len"])
  385. else:
  386. return self.val["Sup"]["len"]
  387. @property
  388. def data(self):
  389. if self.new:
  390. if self.isContent:
  391. return self.val["data"]
  392. elif self.val["p"]:
  393. return self.val["p"]["data"]
  394. else:
  395. return self.val["data"]
  396. @property
  397. def cap(self):
  398. if not self:
  399. return 0
  400. if self.new:
  401. if self.isContent:
  402. return int(self.val["cap"])
  403. elif self.val["p"]:
  404. return int(self.val["p"]["cap"])
  405. else:
  406. return 0
  407. return int(self.val['Sup']['reserved'])
  408. class NimSeqPrinter:
  409. pattern = re.compile(r'^tySequence_\w*\s?\*?$')
  410. def __init__(self, val):
  411. self.val = NimSeq(val)
  412. def display_hint(self):
  413. return 'array'
  414. def to_string(self):
  415. return f'seq({len(self.val)}, {self.val.cap})'
  416. def children(self):
  417. if self.val:
  418. val = self.val
  419. length = len(val)
  420. if length <= 0:
  421. return
  422. data = val.data
  423. inaccessible = False
  424. for i in range(length):
  425. if inaccessible:
  426. return
  427. try:
  428. str(data[i])
  429. yield "data[{0}]".format(i), data[i]
  430. except RuntimeError:
  431. inaccessible = True
  432. yield "data[{0}]".format(i), "inaccessible"
  433. ################################################################################
  434. class NimArrayPrinter:
  435. pattern = re.compile(r'^tyArray_\w*$')
  436. def __init__(self, val):
  437. self.val = val
  438. def display_hint(self):
  439. return 'array'
  440. def to_string(self):
  441. return 'array'
  442. def children(self):
  443. length = self.val.type.sizeof // self.val[0].type.sizeof
  444. align = len(str(length-1))
  445. for i in range(length):
  446. yield ("[{0:>{1}}]".format(i, align), self.val[i])
  447. ################################################################################
  448. class NimStringTablePrinter:
  449. pattern = re.compile(r'^tyObject_(StringTableObj)__([A-Za-z0-9]*)(:? \*)?$')
  450. def __init__(self, val):
  451. self.val = val
  452. def display_hint(self):
  453. return 'map'
  454. def to_string(self):
  455. counter = 0
  456. capacity = 0
  457. if self.val:
  458. counter = int(self.val['counter'])
  459. if self.val['data']:
  460. capacity = int(self.val['data']['Sup']['len'])
  461. return 'StringTableObj({0}, {1})'.format(counter, capacity)
  462. def children(self):
  463. if self.val:
  464. data = NimSeqPrinter(self.val['data'].referenced_value())
  465. for idxStr, entry in data.children():
  466. if int(entry['Field0']) != 0:
  467. yield (idxStr + ".Field0", entry['Field0'])
  468. yield (idxStr + ".Field1", entry['Field1'])
  469. ################################################################
  470. class NimTablePrinter:
  471. pattern = re.compile(r'^tyObject_(Table)__([A-Za-z0-9]*)(:? \*)?$')
  472. def __init__(self, val):
  473. self.val = val
  474. def display_hint(self):
  475. return 'map'
  476. def to_string(self):
  477. counter = 0
  478. capacity = 0
  479. if self.val:
  480. counter = int(self.val['counter'])
  481. if self.val['data']:
  482. capacity = NimSeq(self.val["data"]).cap
  483. return 'Table({0}, {1})'.format(counter, capacity)
  484. def children(self):
  485. if self.val:
  486. data = NimSeqPrinter(self.val['data'])
  487. for idxStr, entry in data.children():
  488. if int(entry['Field0']) != 0:
  489. yield (idxStr + '.Field1', entry['Field1'])
  490. yield (idxStr + '.Field2', entry['Field2'])
  491. ################################################################################
  492. class NimTuplePrinter:
  493. pattern = re.compile(r"^tyTuple__([A-Za-z0-9]*)")
  494. def __init__(self, val):
  495. self.val = val
  496. def to_string(self):
  497. # We don't have field names so just print out the tuple as if it was anonymous
  498. tupleValues = [str(self.val[field.name]) for field in self.val.type.fields()]
  499. return f"({', '.join(tupleValues)})"
  500. ################################################################################
  501. class NimFrameFilter:
  502. def __init__(self):
  503. self.name = "nim-frame-filter"
  504. self.enabled = True
  505. self.priority = 100
  506. self.hidden = {"NimMainInner","NimMain", "main"}
  507. def filter(self, iterator):
  508. for framedecorator in iterator:
  509. if framedecorator.function() not in self.hidden:
  510. yield framedecorator
  511. ################################################################################
  512. def makematcher(klass):
  513. def matcher(val):
  514. typeName = str(val.type)
  515. try:
  516. if hasattr(klass, 'pattern') and hasattr(klass, '__name__'):
  517. # print(typeName + " <> " + klass.__name__)
  518. if klass.pattern.match(typeName):
  519. return klass(val)
  520. except Exception as e:
  521. print(klass)
  522. printErrorOnce(typeName, "No matcher for type '" + typeName + "': " + str(e) + "\n")
  523. return matcher
  524. def register_nim_pretty_printers_for_object(objfile):
  525. nimMainSym = gdb.lookup_global_symbol("NimMain", gdb.SYMBOL_FUNCTION_DOMAIN)
  526. if nimMainSym and nimMainSym.symtab.objfile == objfile:
  527. print("set Nim pretty printers for ", objfile.filename)
  528. gdb.types.register_type_printer(objfile, NimTypePrinter())
  529. objfile.pretty_printers = [makematcher(var) for var in list(globals().values()) if hasattr(var, 'pattern')]
  530. # Register pretty printers for all objfiles that are already loaded.
  531. for old_objfile in gdb.objfiles():
  532. register_nim_pretty_printers_for_object(old_objfile)
  533. # Register an event handler to register nim pretty printers for all future objfiles.
  534. def new_object_handler(event):
  535. register_nim_pretty_printers_for_object(event.new_objfile)
  536. gdb.events.new_objfile.connect(new_object_handler)
  537. gdb.frame_filters = {"nim-frame-filter": NimFrameFilter()}