gdb_pretty_printer_test.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import gdb
  2. # this test should test the gdb pretty printers of the nim
  3. # library. But be aware this test is not complete. It only tests the
  4. # command line version of gdb. It does not test anything for the
  5. # machine interface of gdb. This means if if this test passes gdb
  6. # frontends might still be broken.
  7. gdb.execute("source ../../../tools/nim-gdb.py")
  8. # debug all instances of the generic function `myDebug`, should be 14
  9. gdb.execute("rbreak myDebug")
  10. gdb.execute("run")
  11. outputs = [
  12. 'meTwo',
  13. '""',
  14. '"meTwo"',
  15. '{meOne, meThree}',
  16. 'MyOtherEnum(1)',
  17. '5',
  18. 'array = {1, 2, 3, 4, 5}',
  19. 'seq(0, 0)',
  20. 'seq(0, 10)',
  21. 'array = {"one", "two"}',
  22. 'seq(3, 3) = {1, 2, 3}',
  23. 'seq(3, 3) = {"one", "two", "three"}',
  24. 'Table(3, 64) = {[4] = "four", [5] = "five", [6] = "six"}',
  25. 'Table(3, 8) = {["two"] = 2, ["three"] = 3, ["one"] = 1}',
  26. '{a = 1, b = "some string"}'
  27. ]
  28. for i, expected in enumerate(outputs):
  29. gdb.write(f"{i+1}) expecting: {expected}: ", gdb.STDLOG)
  30. gdb.flush()
  31. functionSymbol = gdb.selected_frame().block().function
  32. assert functionSymbol.line == 41, str(functionSymbol.line)
  33. if i == 6:
  34. # myArray is passed as pointer to int to myDebug. I look up myArray up in the stack
  35. gdb.execute("up")
  36. raw = gdb.parse_and_eval("myArray")
  37. elif i == 9:
  38. # myOtherArray is passed as pointer to int to myDebug. I look up myOtherArray up in the stack
  39. gdb.execute("up")
  40. raw = gdb.parse_and_eval("myOtherArray")
  41. else:
  42. raw = gdb.parse_and_eval("arg")
  43. output = str(raw)
  44. assert output == expected, "{0} : output: ({1}) != expected: ({2})".format(i, output, expected)
  45. gdb.write(f"passed\n", gdb.STDLOG)
  46. gdb.execute("continue")