debug_prompt.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import urllib
  2. import urllib2
  3. import threading
  4. import subprocess
  5. import os
  6. import sys
  7. import json
  8. def local_print(string):
  9. if os.name == "posix":
  10. # Nicer colour output when using posix (and thus supporting colour)
  11. string = "\033[92m%s\033[0m" % string
  12. print(string)
  13. def remote_print(string):
  14. if os.name == "posix":
  15. # Nicer colour output when using posix (and thus supporting colour)
  16. string = "\033[94m%s\033[0m" % string
  17. print(string)
  18. local_print("Welcome to the debugging shell!")
  19. local_print("Please specify Modelverse location (default: 127.0.0.1:8001)")
  20. location = raw_input()
  21. if location == "":
  22. address = "http://127.0.0.1:8001/"
  23. local_print("Please specify task name (default: test)")
  24. taskname = raw_input()
  25. if location == "":
  26. taskname = "test"
  27. local_print("Switching context to Modelverse: all data is piped.")
  28. local_print("Available commands: 'attach_debugger', 'detach_debugger', 'pause', 'resume', 'line_step', 'big_step', 'small_step', 'step_into', 'read_symbols'")
  29. local_print("To quit: execute command 'quit'")
  30. while 1:
  31. inp = raw_input().split(" ")
  32. action = inp[0]
  33. if action == "quit":
  34. local_print("Received quit: breaking connection to Modelverse immediately!")
  35. break
  36. elif action not in set(["attach_debugger", "detach_debugger", "pause", "resume", "line_step", "big_step", "small_step", "step_into", "read_symbols"]):
  37. local_print("Invalid action %s" % action)
  38. continue
  39. reply = json.loads(urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": action, "taskname": taskname}))).read())
  40. print "RES: %s" % reply['result']
  41. if 'state' in reply:
  42. print "STATE: %s" % reply['state']
  43. if 'stack' in reply:
  44. print "STACK:\n\t%s" % '\n\t'.join(["%s. %s" % item for item in list(enumerate(reply['stack']))])
  45. if 'instruction' in reply:
  46. print "INST: %s" % reply['instruction']
  47. if 'phase' in reply:
  48. print "PHASE: %s" % reply['phase']
  49. if 'symbols' in reply:
  50. print "SYMB: %s" % reply['symbols']