--- a/Debugger/DebuggerInterfacePython3.py Fri Sep 02 19:14:41 2016 +0200 +++ b/Debugger/DebuggerInterfacePython3.py Fri Sep 02 19:50:20 2016 +0200 @@ -19,7 +19,6 @@ from E5Gui.E5Application import e5App from E5Gui import E5MessageBox -##from . import DebugProtocol from . import DebugClientCapabilities import Preferences @@ -29,7 +28,6 @@ ClientDefaultCapabilities = DebugClientCapabilities.HasAll -##EOT = '>EOT<\n' class DebuggerInterfacePython3(QObject): @@ -405,7 +403,6 @@ self.qsock.readyRead.disconnect(self.__parseClientLine) # close down socket, and shut down client as well. -## self.__sendCommand('{0}\n'.format(DebugProtocol.RequestShutdown)) self.__sendJsonCommand("RequestShutdown", {}) self.qsock.flush() @@ -429,8 +426,6 @@ @param env environment settings (dictionary) """ -## self.__sendCommand('{0}{1}\n'.format( -## DebugProtocol.RequestEnv, str(env))) self.__sendJsonCommand("RequestEnvironment", {"environment": env}) def remoteLoad(self, fn, argv, wd, traceInterpreter=False, @@ -454,12 +449,6 @@ 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.__sendJsonCommand("RequestLoad", { "workdir": wd, "filename": fn, @@ -484,11 +473,6 @@ 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}\n'.format( -## DebugProtocol.RequestRun, wd, fn, -## str(Utilities.parseOptionString(argv)))) self.__sendJsonCommand("RequestRun", { "workdir": wd, "filename": fn, @@ -511,10 +495,6 @@ wd = self.translate(wd, False) fn = self.translate(os.path.abspath(fn), False) -## self.__sendCommand('{0}{1}@@{2}@@{3}@@{4:d}\n'.format( -## DebugProtocol.RequestCoverage, wd, fn, -## str(Utilities.parseOptionString(argv)), -## erase)) self.__sendJsonCommand("RequestCoverage", { "workdir": wd, "filename": fn, @@ -536,9 +516,6 @@ wd = self.translate(wd, False) fn = self.translate(os.path.abspath(fn), False) -## self.__sendCommand('{0}{1}|{2}|{3}|{4:d}\n'.format( -## DebugProtocol.RequestProfile, wd, fn, -## str(Utilities.parseOptionString(argv)), erase)) self.__sendJsonCommand("RequestProfile", { "workdir": wd, "filename": fn, @@ -553,8 +530,6 @@ @param stmt the Python statement to execute (string). It should not have a trailing newline. """ -## self.__sendCommand('{0}\n'.format(stmt)) -## self.__sendCommand(DebugProtocol.RequestOK + '\n') self.__sendJsonCommand("ExecuteStatement", { "statement": stmt, }) @@ -563,28 +538,24 @@ """ Public method to single step the debugged program. """ -## self.__sendCommand(DebugProtocol.RequestStep + '\n') self.__sendJsonCommand("RequestStep", {}) def remoteStepOver(self): """ Public method to step over the debugged program. """ -## self.__sendCommand(DebugProtocol.RequestStepOver + '\n') self.__sendJsonCommand("RequestStepOver", {}) def remoteStepOut(self): """ Public method to step out the debugged program. """ -## self.__sendCommand(DebugProtocol.RequestStepOut + '\n') self.__sendJsonCommand("RequestStepOut", {}) def remoteStepQuit(self): """ Public method to stop the debugged program. """ -## self.__sendCommand(DebugProtocol.RequestStepQuit + '\n') self.__sendJsonCommand("RequestStepQuit", {}) def remoteContinue(self, special=False): @@ -593,8 +564,6 @@ @param special flag indicating a special continue operation """ -## self.__sendCommand('{0}{1:d}\n'.format( -## DebugProtocol.RequestContinue, special)) self.__sendJsonCommand("RequestContinue", { "special": special, }) @@ -610,9 +579,6 @@ @param cond condition of the breakpoint (string) @param temp flag indicating a temporary breakpoint (boolean) """ -## fn = self.translate(fn, False) -## self.__sendCommand('{0}{1}@@{2:d}@@{3:d}@@{4:d}@@{5}\n'.format( -## DebugProtocol.RequestBreak, fn, line, temp, set, cond)) self.__sendJsonCommand("RequestBreakpoint", { "filename": self.translate(fn, False), "line": line, @@ -630,9 +596,6 @@ @param enable flag indicating enabling or disabling a breakpoint (boolean) """ -## fn = self.translate(fn, False) -## self.__sendCommand('{0}{1},{2:d},{3:d}\n'.format( -## DebugProtocol.RequestBreakEnable, fn, line, enable)) self.__sendJsonCommand("RequestBreakpointEnable", { "filename": self.translate(fn, False), "line": line, @@ -647,9 +610,6 @@ @param line linenumber of the breakpoint (int) @param count number of occurrences to ignore (int) """ -## fn = self.translate(fn, False) -## self.__sendCommand('{0}{1},{2:d},{3:d}\n'.format( -## DebugProtocol.RequestBreakIgnore, fn, line, count)) self.__sendJsonCommand("RequestBreakpointIgnore", { "filename": self.translate(fn, False), "line": line, @@ -666,8 +626,6 @@ @param temp flag indicating a temporary watch expression (boolean) """ # cond is combination of cond and special (s. watch expression viewer) -## self.__sendCommand('{0}{1}@@{2:d}@@{3:d}\n'.format( -## DebugProtocol.RequestWatch, cond, temp, set)) self.__sendJsonCommand("RequestWatch", { "temporary": temp, "setWatch": setWatch, @@ -683,8 +641,6 @@ (boolean) """ # cond is combination of cond and special (s. watch expression viewer) -## self.__sendCommand('{0}{1},{2:d}\n'.format( -## DebugProtocol.RequestWatchEnable, cond, enable)) self.__sendJsonCommand("RequestWatchEnable", { "condition": cond, "enable": enable, @@ -699,8 +655,6 @@ @param count number of occurrences to ignore (int) """ # cond is combination of cond and special (s. watch expression viewer) -## self.__sendCommand('{0}{1},{2:d}\n'.format( -## DebugProtocol.RequestWatchIgnore, cond, count)) self.__sendJsonCommand("RequestWatchIgnore", { "condition": cond, "count": count, @@ -712,7 +666,6 @@ @param s the raw input (string) """ -## self.__sendCommand(s + '\n') self.__sendJsonCommand("RawInput", { "input": s, }) @@ -721,7 +674,6 @@ """ Public method to request the list of threads from the client. """ -## self.__sendCommand('{0}\n'.format(DebugProtocol.RequestThreadList)) self.__sendJsonCommand("RequestThreadList", {}) def remoteSetThread(self, tid): @@ -730,8 +682,6 @@ @param tid id of the thread (integer) """ -## self.__sendCommand('{0}{1:d}\n'.format( -## DebugProtocol.RequestThreadSet, tid)) self.__sendJsonCommand("RequestThreadSet", { "threadID": tid, }) @@ -744,8 +694,6 @@ @param filter list of variable types to filter out (list of int) @param framenr framenumber of the variables to retrieve (int) """ -## self.__sendCommand('{0}{1:d}, {2:d}, {3}\n'.format( -## DebugProtocol.RequestVariables, framenr, scope, str(filter))) self.__sendJsonCommand("RequestVariables", { "frameNumber": framenr, "scope": scope, @@ -761,9 +709,6 @@ @param var list encoded name of variable to retrieve (string) @param framenr framenumber of the variables to retrieve (int) """ -## self.__sendCommand('{0}{1}, {2:d}, {3:d}, {4}\n'.format( -## DebugProtocol.RequestVariable, str(var), framenr, scope, -## str(filter))) self.__sendJsonCommand("RequestVariable", { "variable": var, "frameNumber": framenr, @@ -778,8 +723,6 @@ @param scope the scope of the variables (0 = local, 1 = global) @param filter regexp string for variable names to filter out (string) """ -## self.__sendCommand('{0}{1:d}, "{2}"\n'.format( -## DebugProtocol.RequestSetFilter, scope, filter)) self.__sendJsonCommand("RequestSetFilter", { "scope": scope, "filter": filter, @@ -791,49 +734,20 @@ @param on flag indicating to enable the call trace function (boolean) """ -## if on: -## cmd = "on" -## else: -## cmd = "off" -## self.__sendCommand('{0}{1}\n'.format( -## DebugProtocol.RequestCallTrace, cmd)) self.__sendJsonCommand("RequestCallTrace", { "enable": on, }) -## def remoteEval(self, arg): -## """ -## Public method to evaluate arg in the current context of the debugged -## program. -## -## @param arg the arguments to evaluate (string) -## """ -#### self.__sendCommand('{0}{1}\n'.format(DebugProtocol.RequestEval, arg)) -## self.__sendJsonCommand("RequestEval", { -## "argument": arg, -## }) -## -## def remoteExec(self, stmt): -## """ -## Public method to execute stmt in the current context of the debugged -## program. -## -## @param stmt statement to execute (string) -## """ -## self.__sendCommand('{0}{1}\n'.format(DebugProtocol.RequestExec, stmt)) -## def remoteBanner(self): """ Public slot to get the banner info of the remote client. """ -## 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.__sendJsonCommand("RequestCapabilities", {}) def remoteCompletion(self, text): @@ -843,8 +757,6 @@ @param text the text to be completed (string) """ -## self.__sendCommand("{0}{1}\n".format( -## DebugProtocol.RequestCompletion, text)) self.__sendJsonCommand("RequestCompletion", { "text": text, }) @@ -868,9 +780,6 @@ self.__scriptName = os.path.abspath(fn) fn = self.translate(os.path.abspath(fn), False) -## self.__sendCommand('{0}{1}|{2}|{3}|{4}|{5:d}|{6}|{7:d}\n'.format( -## DebugProtocol.RequestUTPrepare, fn, tn, tfn, str(failed), -## cov, covname, coverase)) self.__sendJsonCommand("RequestUTPrepare", { "filename": fn, "testname": tn, @@ -885,14 +794,12 @@ """ Public method to start a unittest run. """ -## self.__sendCommand('{0}\n'.format(DebugProtocol.RequestUTRun)) self.__sendJsonCommand("RequestUTRun", {}) def remoteUTStop(self): """ Public method to stop a unittest run. """ -## self.__sendCommand('{0}\n'.format(DebugProtocol.RequestUTStop)) self.__sendJsonCommand("RequestUTStop", {}) def __askForkTo(self): @@ -908,12 +815,10 @@ selections, 0, False) if not ok or res == selections[0]: -## self.__sendCommand(DebugProtocol.ResponseForkTo + 'parent\n') self.__sendJsonCommand("ResponseForkTo", { "target": "parent", }) else: -## self.__sendCommand(DebugProtocol.ResponseForkTo + 'child\n') self.__sendJsonCommand("ResponseForkTo", { "target": "child", }) @@ -928,263 +833,20 @@ line = self.codec.toUnicode(qs) else: line = bytes(qs).decode() -## if line.endswith(EOT): -## line = line[:-len(EOT)] -## if not line: -## continue ## 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 -## # or stderr, but not line terminated and we stepped over the -## # write call, in that case the >line< will not be the first -## # string read from the socket... -## boc = line.find('>') -## if boc > 0 and eoc > boc: -## self.debugServer.signalClientOutput(line[:boc]) -## line = line[boc:] -## eoc = line.find('<') + 1 -## boc = line.find('>') -## -## self.debugServer.signalClientOutput(line) -## if boc >= 0 and eoc > boc: -## resp = line[boc:eoc] -## -## if resp == DebugProtocol.ResponseLine or \ -## resp == DebugProtocol.ResponseStack: -## stack = eval(line[eoc:-1]) -## for s in stack: -## s[0] = self.translate(s[0], True) -## cf = stack[0] -## if self.__autoContinue: -## self.__autoContinue = False -## QTimer.singleShot(0, self.remoteContinue) -## else: -## self.debugServer.signalClientLine( -## cf[0], int(cf[1]), -## resp == DebugProtocol.ResponseStack) -## self.debugServer.signalClientStack(stack) -## continue -## -## if resp == DebugProtocol.CallTrace: -## event, fromStr, toStr = line[eoc:-1].split("@@") -## isCall = event.lower() == "c" -## fromFile, fromLineno, fromFunc = fromStr.rsplit(":", 2) -## toFile, toLineno, toFunc = toStr.rsplit(":", 2) -## self.debugServer.signalClientCallTrace( -## isCall, -## fromFile, fromLineno, fromFunc, -## toFile, toLineno, toFunc) -## continue -## -## if resp == DebugProtocol.ResponseThreadList: -## currentId, threadList = eval(line[eoc:-1]) -## self.debugServer.signalClientThreadList( -## currentId, threadList) -## continue -## -## if resp == DebugProtocol.ResponseThreadSet: -## self.debugServer.signalClientThreadSet() -## continue -## -## if resp == DebugProtocol.ResponseVariables: -## vlist = eval(line[eoc:-1]) -## scope = vlist[0] -## try: -## variables = vlist[1:] -## except IndexError: -## variables = [] -## self.debugServer.signalClientVariables(scope, variables) -## continue -## -## if resp == DebugProtocol.ResponseVariable: -## vlist = eval(line[eoc:-1]) -## scope = vlist[0] -## try: -## variables = vlist[1:] -## except IndexError: -## variables = [] -## self.debugServer.signalClientVariable(scope, variables) -## continue -## -## if resp == DebugProtocol.ResponseOK: -## self.debugServer.signalClientStatement(False) -## continue -## -## if resp == DebugProtocol.ResponseContinue: -## self.debugServer.signalClientStatement(True) -## continue -## -## if resp == DebugProtocol.ResponseException: -## exc = line[eoc:-1] -## exc = self.translate(exc, True) -## try: -## exclist = eval(exc) -## exctype = exclist[0] -## excmessage = exclist[1] -## stack = exclist[2:] -## if stack and stack[0] and stack[0][0] == "<string>": -## for stackEntry in stack: -## if stackEntry[0] == "<string>": -## stackEntry[0] = self.__scriptName -## else: -## break -## except (IndexError, ValueError, SyntaxError): -## exctype = None -## excmessage = '' -## stack = [] -## self.debugServer.signalClientException( -## exctype, excmessage, stack) -## continue -## -## if resp == DebugProtocol.ResponseSyntax: -## exc = line[eoc:-1] -## exc = self.translate(exc, True) -## try: -## message, (fn, ln, cn) = eval(exc) -## if fn is None: -## fn = '' -## except (IndexError, ValueError): -## message = None -## fn = '' -## ln = 0 -## cn = 0 -## if cn is None: -## cn = 0 -## self.debugServer.signalClientSyntaxError( -## message, fn, ln, cn) -## continue -## -## if resp == DebugProtocol.ResponseSignal: -## sig = line[eoc:-1] -## sig = self.translate(sig, True) -## message, (fn, ln, func, args) = eval(sig) -## self.debugServer.signalClientSignal( -## message, fn, ln, func, args) -## continue -## -## if resp == DebugProtocol.ResponseExit: -## self.__scriptName = "" -## self.debugServer.signalClientExit(line[eoc:-1]) -## continue -## -## if resp == DebugProtocol.ResponseClearBreak: -## fn, lineno = line[eoc:-1].split(',') -## lineno = int(lineno) -## fn = self.translate(fn, True) -## self.debugServer.signalClientClearBreak(fn, lineno) -## continue -## -## if resp == DebugProtocol.ResponseBPConditionError: -## fn, lineno = line[eoc:-1].split(',') -## lineno = int(lineno) -## fn = self.translate(fn, True) -## self.debugServer.signalClientBreakConditionError( -## fn, lineno) -## continue -## -## if resp == DebugProtocol.ResponseClearWatch: -## cond = line[eoc:-1] -## self.debugServer.signalClientClearWatch(cond) -## continue -## -## if resp == DebugProtocol.ResponseWPConditionError: -## cond = line[eoc:-1] -## self.debugServer.signalClientWatchConditionError(cond) -## continue -## -## if resp == DebugProtocol.ResponseRaw: -## prompt, echo = eval(line[eoc:-1]) -## 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.ResponseCompletion: -## clstring, text = line[eoc:-1].split('||') -## cl = eval(clstring) -## self.debugServer.signalClientCompletionList(cl, text) -## continue -## -## if resp == DebugProtocol.PassiveStartup: -## fn, exc = line[eoc:-1].split('|') -## exc = bool(exc) -## fn = self.translate(fn, True) -## self.debugServer.passiveStartUp(fn, exc) -## continue -## -## if resp == DebugProtocol.ResponseUTPrepared: -## res, exc_type, exc_value = eval(line[eoc:-1]) -## self.debugServer.clientUtPrepared(res, exc_type, exc_value) -## continue -## -## if resp == DebugProtocol.ResponseUTStartTest: -## testname, doc = eval(line[eoc:-1]) -## self.debugServer.clientUtStartTest(testname, doc) -## continue -## -## if resp == DebugProtocol.ResponseUTStopTest: -## self.debugServer.clientUtStopTest() -## continue -## -## if resp == DebugProtocol.ResponseUTTestFailed: -## testname, traceback, id = eval(line[eoc:-1]) -## self.debugServer.clientUtTestFailed( -## testname, traceback, id) -## continue -## -## if resp == DebugProtocol.ResponseUTTestErrored: -## testname, traceback, id = eval(line[eoc:-1]) -## self.debugServer.clientUtTestErrored( -## testname, traceback, id) -## continue -## -## if resp == DebugProtocol.ResponseUTTestSkipped: -## testname, reason, id = eval(line[eoc:-1]) -## self.debugServer.clientUtTestSkipped(testname, reason, id) -## continue -## -## if resp == DebugProtocol.ResponseUTTestFailedExpected: -## testname, traceback, id = eval(line[eoc:-1]) -## self.debugServer.clientUtTestFailedExpected( -## testname, traceback, id) -## continue -## -## if resp == DebugProtocol.ResponseUTTestSucceededUnexpected: -## testname, id = eval(line[eoc:-1]) -## self.debugServer.clientUtTestSucceededUnexpected( -## testname, id) -## continue -## -## if resp == DebugProtocol.ResponseUTFinished: -## self.debugServer.clientUtFinished() -## continue -## -## if resp == DebugProtocol.RequestForkTo: -## self.__askForkTo() -## continue -## -## self.debugServer.signalClientOutput(line) def __handleJsonCommand(self, jsonStr): """ - Private method to handle a command serialized as a JSON string. + Private method to handle a command or response serialized as a + JSON string. + + @param jsonStr string containing the command or response received + from the debug backend + @type str """ import json @@ -1192,7 +854,7 @@ commandDict = json.loads(jsonStr.strip()) except json.JSONDecodeError as err: # TODO: implement real error handling -## print(str(err)) + ##print(str(err)) return method = commandDict["method"]