21. PikaDebug debugger

The PikaDebug debugger module provides features such as breakpoint debugging.

21.1. Install

  1. Add the dependency of PikaStdLib to requestment.txt. The version number of PikaStdLib should be the same as the version number of the kernel.
  1. PikaStdLib==v1.6.1
  1. Run pikaPackage.exe

21.2. class Debuger():

The Debuger class provides the debugger function. By creating an object of the Debuger class, a debugger can be created.

21.2.1. Debuger class methods

  1. class Debuger(TinyObj):
  2. def __init__(self):
  3. pass
  4. def set_trace(self):
  5. pass

The __init__() method is the method executed when the object is created, and the user does not need to know about it. The set_trace() method can place a breakpoint in the code. When the code execution reaches the breakpoint, it will stop and open the (pika-debug) terminal. The user can enter commands in the terminal (c : continue running, q : to end debugging), or a python interactive call ( printf(i), i = 10). ​

Example:

  1. import PikaDebug
  2. pkdb = PikaDebug.Debuger()
  3. i = 0
  4. while i < 10:
  5. i = i + 1
  6. print('i:' + str(i))
  7. # set a breakpoint here
  8. pkdb.set_trace()

Command example: n: (next) continue to run to the next breakpoint. q: (quit) to exit debug mode and continue running. p: (print) print variable, p i means print variable i. Interactive run: Directly execute interactive commands, such as print(i), i = 2, etc.

  1. # Debug logging example
  2. i : 1
  3. (pika-debug) n
  4. i : 2
  5. (pika-debug) n
  6. i : 3
  7. (pika-debug) n
  8. i : 4
  9. (pika-debug) p i
  10. 4
  11. (pika-debug) print(i)
  12. 4
  13. (pika-debug) i = 2
  14. (pika-debug) n
  15. i : 3
  16. (pika-debug) n
  17. i : 4
  18. (pika-debug) i = 9
  19. (pika-debug) n
  20. i : 10
  21. (pika-debug) i = 2
  22. (pika-debug) n
  23. i : 3
  24. (pika-debug) q
  25. i : 4
  26. i : 5
  27. i:6
  28. i : 7
  29. i :8
  30. i :9
  31. i : 10