diff -r d07dd3cf0dc3 -r 1ba8ee313b57 Debugger/DebuggerInterfacePython3.py --- a/Debugger/DebuggerInterfacePython3.py Thu Sep 01 18:28:27 2016 +0200 +++ b/Debugger/DebuggerInterfacePython3.py Thu Sep 01 19:00:46 2016 +0200 @@ -404,7 +404,8 @@ self.qsock.readyRead.disconnect(self.__parseClientLine) # close down socket, and shut down client as well. - self.__sendCommand('{0}\n'.format(DebugProtocol.RequestShutdown)) +## self.__sendCommand('{0}\n'.format(DebugProtocol.RequestShutdown)) + self.__sendJsonCommand("RequestShutdown", {}) self.qsock.flush() self.qsock.close() @@ -597,19 +598,27 @@ "special": special, }) - def remoteBreakpoint(self, fn, line, set, cond=None, temp=False): + def remoteBreakpoint(self, fn, line, setBreakpoint, cond=None, temp=False): """ Public method to set or clear a breakpoint. @param fn filename the breakpoint belongs to (string) @param line linenumber of the breakpoint (int) - @param set flag indicating setting or resetting a breakpoint (boolean) + @param setBreakpoint flag indicating setting or resetting a + breakpoint (boolean) @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)) +## 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, + "temporary": temp, + "setBreakpoint": setBreakpoint, + "condition": cond, + }) def remoteBreakpointEnable(self, fn, line, enable): """ @@ -620,9 +629,14 @@ @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)) +## 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, + "enable": enable, + }) def remoteBreakpointIgnore(self, fn, line, count): """ @@ -632,22 +646,32 @@ @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)) +## 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, + "count": count, + }) - def remoteWatchpoint(self, cond, set, temp=False): + def remoteWatchpoint(self, cond, setWatch, temp=False): """ Public method to set or clear a watch expression. @param cond expression of the watch expression (string) - @param set flag indicating setting or resetting a watch expression + @param setWatch flag indicating setting or resetting a watch expression (boolean) @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.__sendCommand('{0}{1}@@{2:d}@@{3:d}\n'.format( +## DebugProtocol.RequestWatch, cond, temp, set)) + self.__sendJsonCommand("RequestWatch", { + "temporary": temp, + "setWatch": setWatch, + "condition": cond, + }) def remoteWatchpointEnable(self, cond, enable): """ @@ -658,8 +682,12 @@ (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.__sendCommand('{0}{1},{2:d}\n'.format( +## DebugProtocol.RequestWatchEnable, cond, enable)) + self.__sendJsonCommand("RequestWatchEnable", { + "condition": cond, + "enable": enable, + }) def remoteWatchpointIgnore(self, cond, count): """ @@ -670,8 +698,12 @@ @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.__sendCommand('{0}{1},{2:d}\n'.format( +## DebugProtocol.RequestWatchIgnore, cond, count)) + self.__sendJsonCommand("RequestWatchIgnore", { + "condition": cond, + "count": count, + }) def remoteRawInput(self, s): """ @@ -688,7 +720,8 @@ """ Public method to request the list of threads from the client. """ - self.__sendCommand('{0}\n'.format(DebugProtocol.RequestThreadList)) +## self.__sendCommand('{0}\n'.format(DebugProtocol.RequestThreadList)) + self.__sendJsonCommand("RequestThreadList", {}) def remoteSetThread(self, tid): """ @@ -696,8 +729,11 @@ @param tid id of the thread (integer) """ - self.__sendCommand('{0}{1:d}\n'.format( - DebugProtocol.RequestThreadSet, tid)) +## self.__sendCommand('{0}{1:d}\n'.format( +## DebugProtocol.RequestThreadSet, tid)) + self.__sendJsonCommand("RequestThreadSet", { + "threadID": tid, + }) def remoteClientVariables(self, scope, filter, framenr=0): """ @@ -707,8 +743,13 @@ @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.__sendCommand('{0}{1:d}, {2:d}, {3}\n'.format( +## DebugProtocol.RequestVariables, framenr, scope, str(filter))) + self.__sendJsonCommand("RequestVariables", { + "frameNumber": framenr, + "scope": scope, + "filters": filter, + }) def remoteClientVariable(self, scope, filter, var, framenr=0): """ @@ -719,9 +760,15 @@ @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.__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, + "scope": scope, + "filters": filter, + }) def remoteClientSetFilter(self, scope, filter): """ @@ -730,8 +777,12 @@ @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.__sendCommand('{0}{1:d}, "{2}"\n'.format( +## DebugProtocol.RequestSetFilter, scope, filter)) + self.__sendJsonCommand("RequestSetFilter", { + "scope": scope, + "filter": filter, + }) def setCallTraceEnabled(self, on): """ @@ -739,31 +790,37 @@ @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)) +## 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)) - - 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 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. @@ -785,8 +842,11 @@ @param text the text to be completed (string) """ - self.__sendCommand("{0}{1}\n".format( - DebugProtocol.RequestCompletion, text)) +## self.__sendCommand("{0}{1}\n".format( +## DebugProtocol.RequestCompletion, text)) + self.__sendJsonCommand("RequestCompletion", { + "text": text, + }) def remoteUTPrepare(self, fn, tn, tfn, failed, cov, covname, coverase): """ @@ -877,63 +937,63 @@ 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.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 @@ -942,84 +1002,84 @@ ## 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.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) @@ -1037,19 +1097,19 @@ ## 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.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) @@ -1112,12 +1172,56 @@ try: commandDict = json.loads(jsonStr.strip()) except json.JSONDecodeError as err: + # TODO: implement real error handling print(str(err)) return method = commandDict["method"] params = commandDict["params"] + if method in ["ResponseLine", "ResponseStack"]: + for s in params["stack"]: + s[0] = self.translate(s[0], True) + cf = params["stack"][0] + if self.__autoContinue: + self.__autoContinue = False + QTimer.singleShot(0, self.remoteContinue) + else: + self.debugServer.signalClientLine( + cf[0], int(cf[1]), + method == "ResponseStack") + self.debugServer.signalClientStack(params["stack"]) + return + + if method == "CallTrace": + isCall = params["event"].lower() == "c" + fromFile, fromLineno, fromFunc = params["from"].rsplit(":", 2) + toFile, toLineno, toFunc = params["to"].rsplit(":", 2) + self.debugServer.signalClientCallTrace( + isCall, + fromFile, fromLineno, fromFunc, + toFile, toLineno, toFunc) + return + + if method == "ResponseVariables": + self.debugServer.signalClientVariables( + params["scope"], params["variables"]) + return + + if method == "ResponseVariable": + self.debugServer.signalClientVariable( + params["scope"], [params["variable"]] + params["variables"]) + return + + if method == "ResponseThreadList": + self.debugServer.signalClientThreadList( + params["currentID"], params["threadList"]) + return + + if method == "ResponseThreadSet": + self.debugServer.signalClientThreadSet() + return + if method == "ResponseCapabilities": self.clientCapabilities = params["capabilities"] self.debugServer.signalClientCapabilities( @@ -1143,6 +1247,79 @@ self.debugServer.signalClientRawInput( params["prompt"], params["echo"]) return + + if method == "ResponseBPConditionError": + params["filename"] = self.translate(params["filename"], True) + self.debugServer.signalClientBreakConditionError( + params["filename"], params["line"]) + return + + if method == "ResponseClearBreakpoint": + params["filename"] = self.translate(params["filename"], True) + self.debugServer.signalClientClearBreak( + params["filename"], params["line"]) + return + + if method == "ResponseWatchConditionError": + self.debugServer.signalClientWatchConditionError( + params["condition"]) + return + + if method == "ResponseClearWatch": + self.debugServer.signalClientClearWatch(params["condition"]) + return + + if method == "ResponseException": + if params: + exctype = params["type"] + excmessage = params["message"] + stack = params["stack"] + if stack: + for stackEntry in stack: + stackEntry[0] = self.translate(stackEntry[0], True) + if stack[0] and stack[0][0] == "<string>": + for stackEntry in stack: + if stackEntry[0] == "<string>": + stackEntry[0] = self.__scriptName + else: + break + else: + exctype = None + excmessage = '' + stack = [] + + self.debugServer.signalClientException( + exctype, excmessage, stack) + return + + if method == "ResponseSyntax": + self.debugServer.signalClientSyntaxError( + params["message"], self.translate(params["filename"], True), + params["linenumber"], params["characternumber"]) + return + + if method == "ResponseSignal": + self.debugServer.signalClientSignal( + params["message"], self.translate(params["filename"], True), + params["linenumber"], params["function"], params["arguments"]) + return + + if method == "ResponseExit": + self.__scriptName = "" + self.debugServer.signalClientExit(params["status"]) + return + + if method == "PassiveStartup": + self.debugServer.passiveStartUp( + self.translate(params["filename"], True), params["exceptions"]) + return + + if method == "ResponseCompletion": +## clstring, text = line[eoc:-1].split('||') +## cl = eval(clstring) + self.debugServer.signalClientCompletionList( + params["completions"], params["text"]) + return def __sendCommand(self, cmd): """