DebugStdio.hx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package cpp.vm;
  2. import haxe.Stack;
  3. import cpp.vm.DebugBase;
  4. class DebugStdio extends DebugBase
  5. {
  6. var input:haxe.io.Input;
  7. public function new(inCreateStooped:Bool=false)
  8. {
  9. super();
  10. init();
  11. if (inCreateStooped && stillDebugging)
  12. Debugger.breakBad();
  13. }
  14. function init()
  15. {
  16. input = Sys.stdin();
  17. }
  18. override function getNextCommand() : String
  19. {
  20. Sys.print("debug>");
  21. return input.readLine();
  22. }
  23. function sendOutput(inString:String)
  24. {
  25. Sys.println(inString);
  26. }
  27. function sendStatus(inString:String)
  28. {
  29. sendOutput(inString);
  30. }
  31. override function onRunning()
  32. {
  33. sendStatus("running");
  34. }
  35. override function onStopped()
  36. {
  37. sendStatus("stopped.");
  38. }
  39. override function showWhere()
  40. {
  41. var idx = 0;
  42. for(item in stack)
  43. {
  44. idx++;
  45. sendOutput((idx==frame ? "*" : " ") + idx + ":" + item);
  46. }
  47. }
  48. override function showFiles()
  49. {
  50. if (files!=null)
  51. for(idx in 0...files.length)
  52. sendOutput("file " + idx + " : " + files[idx] );
  53. }
  54. override function showBreakpoints()
  55. {
  56. var bps = Debugger.getBreakpoints();
  57. if (bps!=null)
  58. for(idx in 0...bps.length)
  59. sendOutput("breakpoint " + idx + " : " + bps[idx] );
  60. }
  61. override function onPrint(result:String)
  62. {
  63. sendOutput(result);
  64. }
  65. override function onResult(inResult:String)
  66. {
  67. sendOutput(inResult);
  68. }
  69. override function onHelp()
  70. {
  71. sendOutput("help - print this message");
  72. sendOutput("break [file line] - pause execution of one thread [when at certain point]");
  73. sendOutput("breakpoints - list breakpoints");
  74. sendOutput("delete N - delete breakpoint N");
  75. sendOutput("cont - continue execution");
  76. sendOutput("where - print call stack");
  77. sendOutput("files - print file list that may be used with breakpoints");
  78. sendOutput("vars - print local vars for frame");
  79. sendOutput("exit - exit programme");
  80. sendOutput("bye - stop debugging, keep running");
  81. }
  82. }