summary refs log tree commit diff stats
path: root/tests/untestable/gdb
diff options
context:
space:
mode:
authorArne Döring <arne.doering@gmx.net>2018-07-16 19:30:05 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-07-16 19:30:05 +0200
commit97d37aeb0bb1ed2997eddb3b7f8ef53cd04f10ef (patch)
tree889820d6b9e044d8d762543c50088893596453ea /tests/untestable/gdb
parent217a2cf0982302b9d89d2c06fc96eaf72f0518fe (diff)
downloadNim-97d37aeb0bb1ed2997eddb3b7f8ef53cd04f10ef.tar.gz
Gdb pretty printers (#8263)
Diffstat (limited to 'tests/untestable/gdb')
-rw-r--r--tests/untestable/gdb/gdb_pretty_printer_test.py33
-rw-r--r--tests/untestable/gdb/gdb_pretty_printer_test_output.txt3
-rw-r--r--tests/untestable/gdb/gdb_pretty_printer_test_program.nim53
-rwxr-xr-xtests/untestable/gdb/gdb_pretty_printer_test_run.sh15
4 files changed, 104 insertions, 0 deletions
diff --git a/tests/untestable/gdb/gdb_pretty_printer_test.py b/tests/untestable/gdb/gdb_pretty_printer_test.py
new file mode 100644
index 000000000..54af65d9a
--- /dev/null
+++ b/tests/untestable/gdb/gdb_pretty_printer_test.py
@@ -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")
diff --git a/tests/untestable/gdb/gdb_pretty_printer_test_output.txt b/tests/untestable/gdb/gdb_pretty_printer_test_output.txt
new file mode 100644
index 000000000..cbc9bde8d
--- /dev/null
+++ b/tests/untestable/gdb/gdb_pretty_printer_test_output.txt
@@ -0,0 +1,3 @@
+Loading Nim Runtime support.
+NimEnumPrinter: lookup global symbol 'NTI_z9cu80OJCfNgw9bUdzn5ZEzw_ failed for tyEnum_MyOtherEnum_z9cu80OJCfNgw9bUdzn5ZEzw.
+8
diff --git a/tests/untestable/gdb/gdb_pretty_printer_test_program.nim b/tests/untestable/gdb/gdb_pretty_printer_test_program.nim
new file mode 100644
index 000000000..458435c1a
--- /dev/null
+++ b/tests/untestable/gdb/gdb_pretty_printer_test_program.nim
@@ -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()
diff --git a/tests/untestable/gdb/gdb_pretty_printer_test_run.sh b/tests/untestable/gdb/gdb_pretty_printer_test_run.sh
new file mode 100755
index 000000000..525f54705
--- /dev/null
+++ b/tests/untestable/gdb/gdb_pretty_printer_test_run.sh
@@ -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.