From e0a4876981746713186811de293fb7abcd992dec Mon Sep 17 00:00:00 2001 From: Jake Leahy Date: Sat, 29 Mar 2025 23:28:28 +1100 Subject: [PATCH] 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) --- tests/untestable/gdb/gdb_pretty_printer_test.py | 10 +++++----- tools/debug/nim-gdb.py | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/untestable/gdb/gdb_pretty_printer_test.py b/tests/untestable/gdb/gdb_pretty_printer_test.py index aed0cfeb0b..8035a95ff6 100644 --- a/tests/untestable/gdb/gdb_pretty_printer_test.py +++ b/tests/untestable/gdb/gdb_pretty_printer_test.py @@ -27,14 +27,14 @@ outputs = [ 'seq(3, 3) = {1, 2, 3}', 'seq(3, 3) = {"one", "two", "three"}', 'Table(3, 64) = {[4] = "four", [5] = "five", [6] = "six"}', - 'Table(3, 8) = {["two"] = 2, ["three"] = 3, ["one"] = 1}', + 'Table(3, 8) = {["three"] = 3, ["one"] = 1, ["two"] = 2}', '{a = 1, b = "some string"}', '("hello", 42)' ] -argRegex = re.compile("^.* = (?:No suitable Nim \$ operator found for type: \w+\s*)*(.*)$") +argRegex = re.compile(r"^.* = (?:No suitable Nim \$ operator found for type: \w+\s*)*(.*)$") # Remove this error message which can pop up -noSuitableRegex = re.compile("(No suitable Nim \$ operator found for type: \w+\s*)") +noSuitableRegex = re.compile(r"(No suitable Nim \$ operator found for type: \w+\s*)") for i, expected in enumerate(outputs): gdb.write(f"\x1b[38;5;105m{i+1}) expecting: {expected}: \x1b[0m", gdb.STDLOG) @@ -46,11 +46,11 @@ for i, expected in enumerate(outputs): if i == 6: # myArray is passed as pointer to int to myDebug. I look up myArray up in the stack gdb.execute("up") - raw = gdb.parse_and_eval("myArray") + raw = gdb.parse_and_eval("myArray_1") elif i == 9: # myOtherArray is passed as pointer to int to myDebug. I look up myOtherArray up in the stack gdb.execute("up") - raw = gdb.parse_and_eval("myOtherArray") + raw = gdb.parse_and_eval("myOtherArray_1") else: rawArg = re.sub(noSuitableRegex, "", gdb.execute("info args", to_string = True)) raw = rawArg.split("=", 1)[-1].strip() diff --git a/tools/debug/nim-gdb.py b/tools/debug/nim-gdb.py index 8c9854bdad..59e6ee99ce 100644 --- a/tools/debug/nim-gdb.py +++ b/tools/debug/nim-gdb.py @@ -1,4 +1,5 @@ import gdb +import gdb.types import re import sys import traceback @@ -151,8 +152,8 @@ class DollarPrintFunction (gdb.Function): "Nim's equivalent of $ operator as a gdb function, available in expressions `print $dollar(myvalue)" dollar_functions = re.findall( - r'(?:NimStringDesc \*|NimStringV2)\s?(dollar__[A-z0-9_]+?)\(([^,)]*)\);', - gdb.execute("info functions dollar__", True, True) + r'(?:NimStringDesc \*|NimStringV2)\s?([A-z0-9_]+?dollar_[A-z0-9_]+?)\(([^,)]*)\);', + gdb.execute("info functions dollar_", True, True) ) def __init__ (self):