| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import urllib
- import urllib2
- import threading
- import subprocess
- import os
- import sys
- import json
- def local_print(string):
- if os.name == "posix":
- # Nicer colour output when using posix (and thus supporting colour)
- string = "\033[92m%s\033[0m" % string
- print(string)
- def remote_print(string):
- if os.name == "posix":
- # Nicer colour output when using posix (and thus supporting colour)
- string = "\033[94m%s\033[0m" % string
- print(string)
- local_print("Welcome to the debugging shell!")
- local_print("Please specify Modelverse location (default: 127.0.0.1:8001)")
- location = raw_input()
- if location == "":
- address = "http://127.0.0.1:8001/"
-
- local_print("Please specify task name (default: test)")
- taskname = raw_input()
- if location == "":
- taskname = "test"
- local_print("Switching context to Modelverse: all data is piped.")
- local_print("Available commands: 'attach_debugger', 'detach_debugger', 'pause', 'resume', 'line_step', 'big_step', 'small_step', 'step_into', 'read_symbols'")
- local_print("To quit: execute command 'quit'")
- while 1:
- inp = raw_input().split(" ")
- action = inp[0]
- if action == "quit":
- local_print("Received quit: breaking connection to Modelverse immediately!")
- break
- elif action not in set(["attach_debugger", "detach_debugger", "pause", "resume", "line_step", "big_step", "small_step", "step_into", "read_symbols"]):
- local_print("Invalid action %s" % action)
- continue
- reply = json.loads(urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": action, "taskname": taskname}))).read())
- print "RES: %s" % reply['result']
- if 'state' in reply:
- print "STATE: %s" % reply['state']
- if 'stack' in reply:
- print "STACK:\n\t%s" % '\n\t'.join(["%s. %s" % item for item in list(enumerate(reply['stack']))])
- if 'instruction' in reply:
- print "INST: %s" % reply['instruction']
- if 'phase' in reply:
- print "PHASE: %s" % reply['phase']
- if 'symbols' in reply:
- print "SYMB: %s" % reply['symbols']
|