nim-gdb.py fixes mostly for nimsuggest debugging (#16479)

These fixes were primarily developed to assist in nimsuggest debugging. There
is nothing intentionally specific done for nimsuggest, but beyond the automated
tests all practical testing was done with nimsuggest. Undoubltedly these will
also assist in other debugging scenarios.

The current nim-dbg.py script was broken in a few ways:
- failed to provide detailed value information for common types (see below)
- was not passing existing tests
- could not produce type summary information

Broken types now working somewhat better:
- sequences with ref types like strings
- sequences with value types like ints
- arrays with ref types like strings
- tables with int or string keys

Other improvements:
- slightly more test coverage

Future considerations:
- this, data used by it, should be something the compiler can generates
- account for different memory layouts ([arc/orc differ](https://github.com/nim-lang/Nim/pull/16479#issuecomment-751469536))

Attempts at improving nim-gdb.py

More tests, few fixes for seq and type printing

Tables debugging fixed added further tests

Fixed type printing
This commit is contained in:
Saem Ghani 2020-12-30 06:02:51 -08:00 • committed by GitHub
commit 84a7544988
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 156 additions and 76 deletions

View file

@ -6,31 +6,47 @@ import gdb
# frontends might still be broken.
gdb.execute("source ../../../tools/nim-gdb.py")
# debug all instances of the generic function `myDebug`, should be 8
# debug all instances of the generic function `myDebug`, should be 14
gdb.execute("rbreak myDebug")
gdb.execute("run")
outputs = [
'meTwo',
'""',
'"meTwo"',
'{meOne, meThree}',
'MyOtherEnum(1)',
'5',
'array = {1, 2, 3, 4, 5}',
'seq(0, 0)',
'seq(0, 10)',
'array = {"one", "two"}',
'seq(3, 3) = {1, 2, 3}',
'seq(3, 3) = {"one", "two", "three"}',
'Table(3, 64) = {["two"] = 2, ["three"] = 3, ["one"] = 1}',
'Table(3, 64) = {[4] = "four", [5] = "five", [6] = "six"}',
'Table(3, 8) = {["two"] = 2, ["three"] = 3, ["one"] = 1}',
]
for i, expected in enumerate(outputs):
gdb.write(f"{i+1}) expecting: {expected}: ", gdb.STDLOG)
gdb.flush()
functionSymbol = gdb.selected_frame().block().function
assert functionSymbol.line == 21
if i == 5:
if i == 6:
# myArray is passed as pointer to int to myDebug. I look up myArray up in the stack
gdb.execute("up")
output = str(gdb.parse_and_eval("myArray"))
raw = gdb.parse_and_eval("myArray")
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")
else:
output = str(gdb.parse_and_eval("arg"))
raw = gdb.parse_and_eval("arg")
output = str(raw)
assert output == expected, output + " != " + expected
gdb.write(f"passed\n", gdb.STDLOG)
gdb.execute("continue")