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]
This commit is contained in:
parent
bdc850916f
commit
e54d3cc418
3 changed files with 28 additions and 5 deletions
|
|
@ -28,7 +28,8 @@ outputs = [
|
||||||
'seq(3, 3) = {"one", "two", "three"}',
|
'seq(3, 3) = {"one", "two", "three"}',
|
||||||
'Table(3, 64) = {[4] = "four", [5] = "five", [6] = "six"}',
|
'Table(3, 64) = {[4] = "four", [5] = "five", [6] = "six"}',
|
||||||
'Table(3, 8) = {["two"] = 2, ["three"] = 3, ["one"] = 1}',
|
'Table(3, 8) = {["two"] = 2, ["three"] = 3, ["one"] = 1}',
|
||||||
'{a = 1, b = "some string"}'
|
'{a = 1, b = "some string"}',
|
||||||
|
'("hello", 42)'
|
||||||
]
|
]
|
||||||
|
|
||||||
argRegex = re.compile("^.* = (?:No suitable Nim \$ operator found for type: \w+\s*)*(.*)$")
|
argRegex = re.compile("^.* = (?:No suitable Nim \$ operator found for type: \w+\s*)*(.*)$")
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,10 @@ proc testProc(): void =
|
||||||
var obj = MyObj(a: 1, b: "some string")
|
var obj = MyObj(a: 1, b: "some string")
|
||||||
myDebug(obj) #15
|
myDebug(obj) #15
|
||||||
|
|
||||||
assert counter == 15
|
var tup = ("hello", 42)
|
||||||
|
myDebug(tup) # 16
|
||||||
|
|
||||||
|
assert counter == 16
|
||||||
|
|
||||||
|
|
||||||
testProc()
|
testProc()
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,12 @@ class NimTypeRecognizer:
|
||||||
result = self.type_map_static.get(tname, None)
|
result = self.type_map_static.get(tname, None)
|
||||||
if result:
|
if result:
|
||||||
return 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)
|
rti = getNimRti(tname)
|
||||||
if rti:
|
if rti:
|
||||||
|
|
@ -154,7 +160,7 @@ class DollarPrintFunction (gdb.Function):
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@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:
|
if arg.type.code == gdb.TYPE_CODE_PTR and arg.type.target().name in NIM_STRING_TYPES:
|
||||||
return arg
|
return arg
|
||||||
argTypeName = str(arg.type)
|
argTypeName = str(arg.type)
|
||||||
|
|
@ -169,8 +175,8 @@ class DollarPrintFunction (gdb.Function):
|
||||||
func_value = gdb.lookup_global_symbol(func, gdb.SYMBOL_FUNCTIONS_DOMAIN).value()
|
func_value = gdb.lookup_global_symbol(func, gdb.SYMBOL_FUNCTIONS_DOMAIN).value()
|
||||||
return func_value(arg.address)
|
return func_value(arg.address)
|
||||||
|
|
||||||
|
if not ignore_errors:
|
||||||
debugPrint(f"No suitable Nim $ operator found for type: {getNimName(argTypeName)}\n")
|
debugPrint(f"No suitable Nim $ operator found for type: {getNimName(argTypeName)}\n")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def invoke(self, arg):
|
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:
|
class NimFrameFilter:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = "nim-frame-filter"
|
self.name = "nim-frame-filter"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue