summary refs log tree commit diff stats
path: root/tools/nim-gdb.py
diff options
context:
space:
mode:
authorJake Leahy <jake@leahy.dev>2023-02-21 22:02:42 +1100
committerGitHub <noreply@github.com>2023-02-21 12:02:42 +0100
commite54d3cc418f9eab750563aa771070374d559fe57 (patch)
treeefd4ab704eb9d6dcfadfe6ec4309ff35131b3842 /tools/nim-gdb.py
parentbdc850916fb5d23fa4b9282309985e0fdfb0db36 (diff)
downloadNim-e54d3cc418f9eab750563aa771070374d559fe57.tar.gz
Support tuples in nim-gdb (#21410)
* Support for printing tuple types

* Add test of printing a tuple

* Add support for printing tuples in GDB

* Forgot to [skip ci]
Diffstat (limited to 'tools/nim-gdb.py')
-rw-r--r--tools/nim-gdb.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/tools/nim-gdb.py b/tools/nim-gdb.py
index e3af0dde6..1050197c9 100644
--- a/tools/nim-gdb.py
+++ b/tools/nim-gdb.py
@@ -112,6 +112,12 @@ class NimTypeRecognizer:
       result = self.type_map_static.get(tname, None)
       if result:
         return result
+      elif tname.startswith("tyEnum_"):
+        return getNimName(tname)
+      elif tname.startswith("tyTuple__"):
+        # We make the name be the field types (Just like in Nim)
+        fields = ", ".join([self.recognize(field.type) for field in type_obj.fields()])
+        return f"({fields})"
 
       rti = getNimRti(tname)
       if rti:
@@ -154,7 +160,7 @@ class DollarPrintFunction (gdb.Function):
 
 
   @staticmethod
-  def invoke_static(arg):
+  def invoke_static(arg, ignore_errors = False):
     if arg.type.code == gdb.TYPE_CODE_PTR and arg.type.target().name in NIM_STRING_TYPES:
       return arg
     argTypeName = str(arg.type)
@@ -169,8 +175,8 @@ class DollarPrintFunction (gdb.Function):
         func_value = gdb.lookup_global_symbol(func, gdb.SYMBOL_FUNCTIONS_DOMAIN).value()
         return func_value(arg.address)
 
-
-    debugPrint(f"No suitable Nim $ operator found for type: {getNimName(argTypeName)}\n")
+    if not ignore_errors:
+      debugPrint(f"No suitable Nim $ operator found for type: {getNimName(argTypeName)}\n")
     return None
 
   def invoke(self, arg):
@@ -630,6 +636,19 @@ class NimTablePrinter:
 
 ################################################################################
 
+class NimTuplePrinter:
+  pattern = re.compile(r"^tyTuple__([A-Za-z0-9]*)")
+
+  def __init__(self, val):
+    self.val = val
+
+  def to_string(self):
+    # We don't have field names so just print out the tuple as if it was anonymous
+    tupleValues = [str(self.val[field.name]) for field in self.val.type.fields()]
+    return f"({', '.join(tupleValues)})"
+
+################################################################################
+
 class NimFrameFilter:
   def __init__(self):
     self.name = "nim-frame-filter"