Skip to content

Commit e0a4876

Browse files
authored
Fix nim-gdb.py script (#24824)
Script wasn't working on my machine with GDB 16.2 Main issues - `gdb.types` wasn't imported, leading to import error on initial load - dollar function didn't work with the new mangling scheme Fixes them, also updates the test script to work with some new mangling changes. Test evidence ![image](https://github.com/user-attachments/assets/450b020f-1665-4ed2-9073-d02537150914)
1 parent ecdcffe commit e0a4876

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

tests/untestable/gdb/gdb_pretty_printer_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
'seq(3, 3) = {1, 2, 3}',
2828
'seq(3, 3) = {"one", "two", "three"}',
2929
'Table(3, 64) = {[4] = "four", [5] = "five", [6] = "six"}',
30-
'Table(3, 8) = {["two"] = 2, ["three"] = 3, ["one"] = 1}',
30+
'Table(3, 8) = {["three"] = 3, ["one"] = 1, ["two"] = 2}',
3131
'{a = 1, b = "some string"}',
3232
'("hello", 42)'
3333
]
3434

35-
argRegex = re.compile("^.* = (?:No suitable Nim \$ operator found for type: \w+\s*)*(.*)$")
35+
argRegex = re.compile(r"^.* = (?:No suitable Nim \$ operator found for type: \w+\s*)*(.*)$")
3636
# Remove this error message which can pop up
37-
noSuitableRegex = re.compile("(No suitable Nim \$ operator found for type: \w+\s*)")
37+
noSuitableRegex = re.compile(r"(No suitable Nim \$ operator found for type: \w+\s*)")
3838

3939
for i, expected in enumerate(outputs):
4040
gdb.write(f"\x1b[38;5;105m{i+1}) expecting: {expected}: \x1b[0m", gdb.STDLOG)
@@ -46,11 +46,11 @@
4646
if i == 6:
4747
# myArray is passed as pointer to int to myDebug. I look up myArray up in the stack
4848
gdb.execute("up")
49-
raw = gdb.parse_and_eval("myArray")
49+
raw = gdb.parse_and_eval("myArray_1")
5050
elif i == 9:
5151
# myOtherArray is passed as pointer to int to myDebug. I look up myOtherArray up in the stack
5252
gdb.execute("up")
53-
raw = gdb.parse_and_eval("myOtherArray")
53+
raw = gdb.parse_and_eval("myOtherArray_1")
5454
else:
5555
rawArg = re.sub(noSuitableRegex, "", gdb.execute("info args", to_string = True))
5656
raw = rawArg.split("=", 1)[-1].strip()

tools/debug/nim-gdb.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import gdb
2+
import gdb.types
23
import re
34
import sys
45
import traceback
@@ -151,8 +152,8 @@ class DollarPrintFunction (gdb.Function):
151152
"Nim's equivalent of $ operator as a gdb function, available in expressions `print $dollar(myvalue)"
152153

153154
dollar_functions = re.findall(
154-
r'(?:NimStringDesc \*|NimStringV2)\s?(dollar__[A-z0-9_]+?)\(([^,)]*)\);',
155-
gdb.execute("info functions dollar__", True, True)
155+
r'(?:NimStringDesc \*|NimStringV2)\s?([A-z0-9_]+?dollar_[A-z0-9_]+?)\(([^,)]*)\);',
156+
gdb.execute("info functions dollar_", True, True)
156157
)
157158

158159
def __init__ (self):

0 commit comments

Comments
 (0)