Files
Nim/tests/untestable/gdb/gdb_pretty_printer_test_program.nim
Saem Ghani 84a7544988 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
2020-12-30 15:02:51 +01:00

81 lines
1.4 KiB
Nim

import tables
type
MyEnum = enum
meOne,
meTwo,
meThree,
meFour,
MyOtherEnum = enum
moOne,
moTwo,
moThree,
moFoure,
var counter = 0
proc myDebug[T](arg: T): void =
counter += 1
proc testProc(): void =
var myEnum = meTwo
myDebug(myEnum) #1
# create a string, but don't allocate it
var myString: string
myDebug(myString) #2
# create a string object but also make the NTI for MyEnum is generated
myString = $myEnum
myDebug(myString) #3
var mySet = {meOne,meThree}
myDebug(mySet) #4
# for MyOtherEnum there is no NTI. This tests the fallback for the pretty printer.
var moEnum = moTwo
myDebug(moEnum) #5
var moSet = {moOne,moThree}
myDebug(moSet) #6
let myArray = [1,2,3,4,5]
myDebug(myArray) #7
# implicitly initialized seq test
var mySeq: seq[string]
myDebug(mySeq) #8
# len not equal to capacity
let myOtherSeq = newSeqOfCap[string](10)
myDebug(myOtherSeq) #9
let myOtherArray = ["one","two"]
myDebug(myOtherArray) #10
# numeric sec
var mySeq3 = @[1,2,3]
myDebug(mySeq3) #11
# seq had to grow
var mySeq4 = @["one","two","three"]
myDebug(mySeq4) #12
var myTable = initTable[int, string]()
myTable[4] = "four"
myTable[5] = "five"
myTable[6] = "six"
myDebug(myTable) #13
var myOtherTable = {"one": 1, "two": 2, "three": 3}.toTable
myDebug(myOtherTable) #14
echo(counter)
testProc()