diff -r 4a79a6153485 -r 80bd41498eef Debugger/DebuggerInterfacePython3.py --- a/Debugger/DebuggerInterfacePython3.py Wed Aug 31 18:30:40 2016 +0200 +++ b/Debugger/DebuggerInterfacePython3.py Wed Aug 31 18:31:57 2016 +0200 @@ -427,8 +427,9 @@ @param env environment settings (dictionary) """ - self.__sendCommand('{0}{1}\n'.format( - DebugProtocol.RequestEnv, str(env))) +## self.__sendCommand('{0}{1}\n'.format( +## DebugProtocol.RequestEnv, str(env))) + self.__sendJsonCommand("RequestEnvironment", {"environment": env}) def remoteLoad(self, fn, argv, wd, traceInterpreter=False, autoContinue=True, autoFork=False, forkChild=False): @@ -451,12 +452,20 @@ wd = self.translate(wd, False) fn = self.translate(os.path.abspath(fn), False) - self.__sendCommand('{0}{1}\n'.format( - DebugProtocol.RequestForkMode, repr((autoFork, forkChild)))) - self.__sendCommand('{0}{1}|{2}|{3}|{4:d}\n'.format( - DebugProtocol.RequestLoad, wd, fn, - str(Utilities.parseOptionString(argv)), - traceInterpreter)) +## self.__sendCommand('{0}{1}\n'.format( +## DebugProtocol.RequestForkMode, repr((autoFork, forkChild)))) +## self.__sendCommand('{0}{1}|{2}|{3}|{4:d}\n'.format( +## DebugProtocol.RequestLoad, wd, fn, +## str(Utilities.parseOptionString(argv)), +## traceInterpreter)) + self.__sendJsonCommand("RequestLoad", { + "workdir": wd, + "filename": fn, + "argv": Utilities.parseOptionString(argv), + "traceInterpreter": traceInterpreter, + "autofork": autoFork, + "forkChild": forkChild, + }) def remoteRun(self, fn, argv, wd, autoFork=False, forkChild=False): """ @@ -727,13 +736,15 @@ """ Public slot to get the banner info of the remote client. """ - self.__sendCommand(DebugProtocol.RequestBanner + '\n') +## self.__sendCommand(DebugProtocol.RequestBanner + '\n') + self.__sendJsonCommand("RequestBanner", {}) def remoteCapabilities(self): """ Public slot to get the debug clients capabilities. """ - self.__sendCommand(DebugProtocol.RequestCapabilities + '\n') +## self.__sendCommand(DebugProtocol.RequestCapabilities + '\n') + self.__sendJsonCommand("RequestCapabilities", {}) def remoteCompletion(self, text): """ @@ -814,6 +825,10 @@ ## print("Server: ", line) ##debug + if line.startswith("{") and "jsonrpc" in line: + self.__handleJsonCommand(line) + continue + eoc = line.find('<') + 1 # Deal with case where user has written directly to stdout @@ -978,18 +993,18 @@ self.debugServer.signalClientRawInput(prompt, echo) continue - if resp == DebugProtocol.ResponseBanner: - version, platform, dbgclient = eval(line[eoc:-1]) - self.debugServer.signalClientBanner( - version, platform, dbgclient) - continue - - if resp == DebugProtocol.ResponseCapabilities: - cap, clType = eval(line[eoc:-1]) - self.clientCapabilities = cap - self.debugServer.signalClientCapabilities(cap, clType) - continue - +## if resp == DebugProtocol.ResponseBanner: +## version, platform, dbgclient = eval(line[eoc:-1]) +## self.debugServer.signalClientBanner( +## version, platform, dbgclient) +## continue +## +## if resp == DebugProtocol.ResponseCapabilities: +## cap, clType = eval(line[eoc:-1]) +## self.clientCapabilities = cap +## self.debugServer.signalClientCapabilities(cap, clType) +## continue +## if resp == DebugProtocol.ResponseCompletion: clstring, text = line[eoc:-1].split('||') cl = eval(clstring) @@ -1055,7 +1070,35 @@ continue self.debugServer.signalClientOutput(line) - + + def __handleJsonCommand(self, jsonStr): + """ + Private method to handle a command serialized as a JSON string. + """ + import json + + try: + commandDict = json.loads(jsonStr.strip()) + except json.JSONDecodeError as err: + print(str(err)) + return + + method = commandDict["method"] + params = commandDict["params"] + + if method == "ResponseCapabilities": + self.clientCapabilities = params["capabilities"] + self.debugServer.signalClientCapabilities( + params["capabilities"], params["clientType"]) + return + + if method == "ResponseBanner": + self.debugServer.signalClientBanner( + params["version"], + params["platform"], + params["dbgclient"]) + return + def __sendCommand(self, cmd): """ Private method to send a single line command to the client. @@ -1067,6 +1110,28 @@ else: self.queue.append(cmd) + def __sendJsonCommand(self, command, params): + """ + Private method to send a single command to the client. + + @param command command name to be sent + @type str + @param params dictionary of named parameters for the command + @type dict + """ + import json + + commandDict = { + "jsonrpc": "2.0", + "method": command, + "params": params, + } + cmd = json.dumps(commandDict) + '\n' + if self.qsock is not None: + self.qsock.write(cmd.encode('utf8', 'backslashreplace')) + else: + self.queue.append(cmd) + def createDebuggerInterfacePython3(debugServer, passive): """