mirror of
https://github.com/nim-lang/Nim.git
synced 2026-09-18 11:04:53 +00:00
Gdb pretty printers (#8263)
This commit is contained in:
committed by
Andreas Rumpf
parent
217a2cf098
commit
97d37aeb0b
33
tests/untestable/gdb/gdb_pretty_printer_test.py
Normal file
33
tests/untestable/gdb/gdb_pretty_printer_test.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import gdb
|
||||
# this test should test the gdb pretty printers of the nim
|
||||
# library. But be aware this test is not complete. It only tests the
|
||||
# command line version of gdb. It does not test anything for the
|
||||
# machine interface of gdb. This means if if this test passes gdb
|
||||
# frontends might still be broken.
|
||||
|
||||
gdb.execute("source ../../../tools/nim-gdb.py")
|
||||
# debug all instances of the generic function `myDebug`, should be 8
|
||||
gdb.execute("rbreak myDebug")
|
||||
gdb.execute("run")
|
||||
|
||||
outputs = [
|
||||
'meTwo',
|
||||
'"meTwo"',
|
||||
'{meOne, meThree}',
|
||||
'MyOtherEnum(1)',
|
||||
'5',
|
||||
'array = {1, 2, 3, 4, 5}',
|
||||
'seq(3, 3) = {"one", "two", "three"}',
|
||||
'Table(3, 64) = {["two"] = 2, ["three"] = 3, ["one"] = 1}',
|
||||
]
|
||||
|
||||
for i, expected in enumerate(outputs):
|
||||
if i == 5:
|
||||
# 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"))
|
||||
else:
|
||||
output = str(gdb.parse_and_eval("arg"))
|
||||
|
||||
assert output == expected, output + " != " + expected
|
||||
gdb.execute("continue")
|
||||
3
tests/untestable/gdb/gdb_pretty_printer_test_output.txt
Normal file
3
tests/untestable/gdb/gdb_pretty_printer_test_output.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
Loading Nim Runtime support.
|
||||
NimEnumPrinter: lookup global symbol 'NTI_z9cu80OJCfNgw9bUdzn5ZEzw_ failed for tyEnum_MyOtherEnum_z9cu80OJCfNgw9bUdzn5ZEzw.
|
||||
8
|
||||
53
tests/untestable/gdb/gdb_pretty_printer_test_program.nim
Normal file
53
tests/untestable/gdb/gdb_pretty_printer_test_program.nim
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
|
||||
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)
|
||||
# create a string object but also make the NTI for MyEnum is generated
|
||||
var myString = $myEnum
|
||||
myDebug(myString)
|
||||
var mySet = {meOne,meThree}
|
||||
myDebug(mySet)
|
||||
|
||||
# for MyOtherEnum there is no NTI. This tests the fallback for the pretty printer.
|
||||
var moEnum = moTwo
|
||||
myDebug(moEnum)
|
||||
var moSet = {moOne,moThree}
|
||||
myDebug(moSet)
|
||||
|
||||
let myArray = [1,2,3,4,5]
|
||||
myDebug(myArray)
|
||||
let mySeq = @["one","two","three"]
|
||||
myDebug(mySeq)
|
||||
|
||||
var myTable = initTable[string, int]()
|
||||
myTable["one"] = 1
|
||||
myTable["two"] = 2
|
||||
myTable["three"] = 3
|
||||
myDebug(myTable)
|
||||
|
||||
echo(counter)
|
||||
|
||||
|
||||
testProc()
|
||||
15
tests/untestable/gdb/gdb_pretty_printer_test_run.sh
Executable file
15
tests/untestable/gdb/gdb_pretty_printer_test_run.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
# Exit if anything fails
|
||||
set -e
|
||||
#!/usr/bin/env bash
|
||||
# Compile the test project with fresh debug information.
|
||||
nim c --debugger:native gdb_pretty_printer_test_program.nim &> /dev/null
|
||||
# 2>&1 redirects stderr to stdout (all output in stdout)
|
||||
# <(...) is a bash feature that makes the output of a command into a
|
||||
# file handle.
|
||||
# diff compares the two files, the expected output, and the file
|
||||
# handle that is created by the execution of gdb.
|
||||
diff ./gdb_pretty_printer_test_output.txt <(gdb -x gdb_pretty_printer_test.py --batch-silent --args gdb_pretty_printer_test_program 2>&1)
|
||||
# The exit code of diff is forwarded as the exit code of this
|
||||
# script. So when the comparison fails, the exit code of this script
|
||||
# won't be 0. So this script should be embeddable in a test suite.
|
||||
Reference in New Issue
Block a user