284 d["id"] = -1 |
284 d["id"] = -1 |
285 d["name"] = "MainThread" |
285 d["name"] = "MainThread" |
286 d["broken"] = self.isBroken() |
286 d["broken"] = self.isBroken() |
287 threadList.append(d) |
287 threadList.append(d) |
288 |
288 |
289 self.write("{0}{1!r}\n".format(ResponseThreadList, (currentId, threadList))) |
289 self.write("{0}{1!r}\n".format(DebugProtocol.ResponseThreadList, |
|
290 (currentId, threadList))) |
290 |
291 |
291 def input(self, prompt, echo=True): |
292 def input(self, prompt, echo=True): |
292 """ |
293 """ |
293 Public method to implement input() using the event loop. |
294 Public method to implement input() using the event loop. |
294 |
295 |
295 @param prompt the prompt to be shown (string) |
296 @param prompt the prompt to be shown (string) |
296 @param echo Flag indicating echoing of the input (boolean) |
297 @param echo Flag indicating echoing of the input (boolean) |
297 @return the entered string |
298 @return the entered string |
298 """ |
299 """ |
299 self.write("{0}{1!r}\n".format(ResponseRaw, (prompt, echo))) |
300 self.write("{0}{1!r}\n".format(DebugProtocol.ResponseRaw, (prompt, echo))) |
300 self.inRawMode = True |
301 self.inRawMode = True |
301 self.eventLoop(True) |
302 self.eventLoop(True) |
302 return self.rawLine |
303 return self.rawLine |
303 |
304 |
304 def __exceptionRaised(self): |
305 def __exceptionRaised(self): |
305 """ |
306 """ |
306 Private method called in the case of an exception |
307 Private method called in the case of an exception |
307 |
308 |
308 It ensures that the debug server is informed of the raised exception. |
309 It ensures that the debug server is informed of the raised exception. |
309 """ |
310 """ |
310 self.pendingResponse = ResponseException |
311 self.pendingResponse = DebugProtocol.ResponseException |
311 |
312 |
312 def sessionClose(self, exit=True): |
313 def sessionClose(self, exit=True): |
313 """ |
314 """ |
314 Public method to close the session with the debugger and optionally terminate. |
315 Public method to close the session with the debugger and optionally terminate. |
315 |
316 |
382 if eoc >= 0 and line[0] == '>': |
383 if eoc >= 0 and line[0] == '>': |
383 # Get the command part and any argument. |
384 # Get the command part and any argument. |
384 cmd = line[:eoc + 1] |
385 cmd = line[:eoc + 1] |
385 arg = line[eoc + 1:] |
386 arg = line[eoc + 1:] |
386 |
387 |
387 if cmd == RequestVariables: |
388 if cmd == DebugProtocol.RequestVariables: |
388 frmnr, scope, filter = eval(arg.replace("u'", "'")) |
389 frmnr, scope, filter = eval(arg.replace("u'", "'")) |
389 self.__dumpVariables(int(frmnr), int(scope), filter) |
390 self.__dumpVariables(int(frmnr), int(scope), filter) |
390 return |
391 return |
391 |
392 |
392 if cmd == RequestVariable: |
393 if cmd == DebugProtocol.RequestVariable: |
393 var, frmnr, scope, filter = eval(arg.replace("u'", "'")) |
394 var, frmnr, scope, filter = eval(arg.replace("u'", "'")) |
394 self.__dumpVariable(var, int(frmnr), int(scope), filter) |
395 self.__dumpVariable(var, int(frmnr), int(scope), filter) |
395 return |
396 return |
396 |
397 |
397 if cmd == RequestThreadList: |
398 if cmd == DebugProtocol.RequestThreadList: |
398 self.__dumpThreadList() |
399 self.__dumpThreadList() |
399 return |
400 return |
400 |
401 |
401 if cmd == RequestThreadSet: |
402 if cmd == DebugProtocol.RequestThreadSet: |
402 tid = eval(arg) |
403 tid = eval(arg) |
403 if tid in self.threads: |
404 if tid in self.threads: |
404 self.setCurrentThread(tid) |
405 self.setCurrentThread(tid) |
405 self.write(ResponseThreadSet + '\n') |
406 self.write(DebugProtocol.ResponseThreadSet + '\n') |
406 stack = self.currentThread.getStack() |
407 stack = self.currentThread.getStack() |
407 self.write('{0}{1!r}\n'.format(ResponseStack, stack)) |
408 self.write('{0}{1!r}\n'.format(DebugProtocol.ResponseStack, stack)) |
408 return |
409 return |
409 |
410 |
410 if cmd == RequestStep: |
411 if cmd == DebugProtocol.RequestStep: |
411 self.currentThread.step(True) |
412 self.currentThread.step(True) |
412 self.eventExit = True |
413 self.eventExit = True |
413 return |
414 return |
414 |
415 |
415 if cmd == RequestStepOver: |
416 if cmd == DebugProtocol.RequestStepOver: |
416 self.currentThread.step(False) |
417 self.currentThread.step(False) |
417 self.eventExit = True |
418 self.eventExit = True |
418 return |
419 return |
419 |
420 |
420 if cmd == RequestStepOut: |
421 if cmd == DebugProtocol.RequestStepOut: |
421 self.currentThread.stepOut() |
422 self.currentThread.stepOut() |
422 self.eventExit = True |
423 self.eventExit = True |
423 return |
424 return |
424 |
425 |
425 if cmd == RequestStepQuit: |
426 if cmd == DebugProtocol.RequestStepQuit: |
426 if self.passive: |
427 if self.passive: |
427 self.progTerminated(42) |
428 self.progTerminated(42) |
428 else: |
429 else: |
429 self.set_quit() |
430 self.set_quit() |
430 self.eventExit = True |
431 self.eventExit = True |
431 return |
432 return |
432 |
433 |
433 if cmd == RequestContinue: |
434 if cmd == DebugProtocol.RequestContinue: |
434 special = int(arg) |
435 special = int(arg) |
435 self.currentThread.go(special) |
436 self.currentThread.go(special) |
436 self.eventExit = True |
437 self.eventExit = True |
437 return |
438 return |
438 |
439 |
439 if cmd == RequestOK: |
440 if cmd == DebugProtocol.RequestOK: |
440 self.write(self.pendingResponse + '\n') |
441 self.write(self.pendingResponse + '\n') |
441 self.pendingResponse = ResponseOK |
442 self.pendingResponse = DebugProtocol.ResponseOK |
442 return |
443 return |
443 |
444 |
444 if cmd == RequestEnv: |
445 if cmd == DebugProtocol.RequestEnv: |
445 env = eval(arg.replace("u'", "'")) |
446 env = eval(arg.replace("u'", "'")) |
446 for key, value in env.items(): |
447 for key, value in env.items(): |
447 if key.endswith("+"): |
448 if key.endswith("+"): |
448 if key[:-1] in os.environ: |
449 if key[:-1] in os.environ: |
449 os.environ[key[:-1]] += value |
450 os.environ[key[:-1]] += value |
616 else: |
617 else: |
617 try: |
618 try: |
618 compile(cond, '<string>', 'eval') |
619 compile(cond, '<string>', 'eval') |
619 except SyntaxError: |
620 except SyntaxError: |
620 self.write('{0}{1},{2:d}\n'.format( |
621 self.write('{0}{1},{2:d}\n'.format( |
621 ResponseBPConditionError, fn, line)) |
622 DebugProtocol.ResponseBPConditionError, fn, line)) |
622 return |
623 return |
623 self.mainThread.set_break(fn, line, temporary, cond) |
624 self.mainThread.set_break(fn, line, temporary, cond) |
624 else: |
625 else: |
625 self.mainThread.clear_break(fn, line) |
626 self.mainThread.clear_break(fn, line) |
626 |
627 |
627 return |
628 return |
628 |
629 |
629 if cmd == RequestBreakEnable: |
630 if cmd == DebugProtocol.RequestBreakEnable: |
630 fn, line, enable = arg.split(',') |
631 fn, line, enable = arg.split(',') |
631 line = int(line) |
632 line = int(line) |
632 enable = int(enable) |
633 enable = int(enable) |
633 |
634 |
634 bp = self.mainThread.get_break(fn, line) |
635 bp = self.mainThread.get_break(fn, line) |
638 else: |
639 else: |
639 bp.disable() |
640 bp.disable() |
640 |
641 |
641 return |
642 return |
642 |
643 |
643 if cmd == RequestBreakIgnore: |
644 if cmd == DebugProtocol.RequestBreakIgnore: |
644 fn, line, count = arg.split(',') |
645 fn, line, count = arg.split(',') |
645 line = int(line) |
646 line = int(line) |
646 count = int(count) |
647 count = int(count) |
647 |
648 |
648 bp = self.mainThread.get_break(fn, line) |
649 bp = self.mainThread.get_break(fn, line) |
649 if bp is not None: |
650 if bp is not None: |
650 bp.ignore = count |
651 bp.ignore = count |
651 |
652 |
652 return |
653 return |
653 |
654 |
654 if cmd == RequestWatch: |
655 if cmd == DebugProtocol.RequestWatch: |
655 cond, temporary, set = arg.split('@@') |
656 cond, temporary, set = arg.split('@@') |
656 set = int(set) |
657 set = int(set) |
657 temporary = int(temporary) |
658 temporary = int(temporary) |
658 |
659 |
659 if set: |
660 if set: |
660 if not cond.endswith('??created??') and \ |
661 if not cond.endswith('??created??') and \ |
661 not cond.endswith('??changed??'): |
662 not cond.endswith('??changed??'): |
662 try: |
663 try: |
663 compile(cond, '<string>', 'eval') |
664 compile(cond, '<string>', 'eval') |
664 except SyntaxError: |
665 except SyntaxError: |
665 self.write('{0}{1}\n'.format(ResponseWPConditionError, cond)) |
666 self.write('{0}{1}\n'.format( |
|
667 DebugProtocol.ResponseWPConditionError, cond)) |
666 return |
668 return |
667 self.mainThread.set_watch(cond, temporary) |
669 self.mainThread.set_watch(cond, temporary) |
668 else: |
670 else: |
669 self.mainThread.clear_watch(cond) |
671 self.mainThread.clear_watch(cond) |
670 |
672 |
671 return |
673 return |
672 |
674 |
673 if cmd == RequestWatchEnable: |
675 if cmd == DebugProtocol.RequestWatchEnable: |
674 cond, enable = arg.split(',') |
676 cond, enable = arg.split(',') |
675 enable = int(enable) |
677 enable = int(enable) |
676 |
678 |
677 bp = self.mainThread.get_watch(cond) |
679 bp = self.mainThread.get_watch(cond) |
678 if bp is not None: |
680 if bp is not None: |
715 tblist = tb = None |
717 tblist = tb = None |
716 |
718 |
717 for l in list: |
719 for l in list: |
718 self.write(l) |
720 self.write(l) |
719 |
721 |
720 self.write(ResponseException + '\n') |
722 self.write(DebugProtocol.ResponseException + '\n') |
721 |
723 |
722 else: |
724 else: |
723 self.write(str(value) + '\n') |
725 self.write(str(value) + '\n') |
724 self.write(ResponseOK + '\n') |
726 self.write(DebugProtocol.ResponseOK + '\n') |
725 |
727 |
726 return |
728 return |
727 |
729 |
728 if cmd == RequestExec: |
730 if cmd == DebugProtocol.RequestExec: |
729 _globals = self.currentThread.getCurrentFrame().f_globals |
731 _globals = self.currentThread.getCurrentFrame().f_globals |
730 _locals = self.currentThread.getCurrentFrameLocals() |
732 _locals = self.currentThread.getCurrentFrameLocals() |
731 try: |
733 try: |
732 code = compile(arg + '\n', '<stdin>', 'single') |
734 code = compile(arg + '\n', '<stdin>', 'single') |
733 exec(code, _globals, _locals) |
735 exec(code, _globals, _locals) |
749 tblist = tb = None |
751 tblist = tb = None |
750 |
752 |
751 for l in list: |
753 for l in list: |
752 self.write(l) |
754 self.write(l) |
753 |
755 |
754 self.write(ResponseException + '\n') |
756 self.write(DebugProtocol.ResponseException + '\n') |
755 |
757 |
756 return |
758 return |
757 |
759 |
758 if cmd == RequestBanner: |
760 if cmd == DebugProtocol.RequestBanner: |
759 self.write('{0}{1}\n'.format(ResponseBanner, |
761 self.write('{0}{1}\n'.format(DebugProtocol.ResponseBanner, |
760 str(("Python {0}".format(sys.version), |
762 str(("Python {0}".format(sys.version), |
761 socket.gethostname(), self.variant)))) |
763 socket.gethostname(), self.variant)))) |
762 return |
764 return |
763 |
765 |
764 if cmd == RequestCapabilities: |
766 if cmd == DebugProtocol.RequestCapabilities: |
765 self.write('{0}{1:d}, "Python3"\n'.format(ResponseCapabilities, |
767 self.write('{0}{1:d}, "Python3"\n'.format( |
|
768 DebugProtocol.ResponseCapabilities, |
766 self.__clientCapabilities())) |
769 self.__clientCapabilities())) |
767 return |
770 return |
768 |
771 |
769 if cmd == RequestCompletion: |
772 if cmd == DebugProtocol.RequestCompletion: |
770 self.__completionList(arg.replace("u'", "'")) |
773 self.__completionList(arg.replace("u'", "'")) |
771 return |
774 return |
772 |
775 |
773 if cmd == RequestSetFilter: |
776 if cmd == DebugProtocol.RequestSetFilter: |
774 scope, filterString = eval(arg.replace("u'", "'")) |
777 scope, filterString = eval(arg.replace("u'", "'")) |
775 self.__generateFilterObjects(int(scope), filterString) |
778 self.__generateFilterObjects(int(scope), filterString) |
776 return |
779 return |
777 |
780 |
778 if cmd == RequestUTPrepare: |
781 if cmd == DebugProtocol.RequestUTPrepare: |
779 fn, tn, tfn, cov, covname, erase = arg.split('|') |
782 fn, tn, tfn, cov, covname, erase = arg.split('|') |
780 sys.path.insert(0, os.path.dirname(os.path.abspath(fn))) |
783 sys.path.insert(0, os.path.dirname(os.path.abspath(fn))) |
781 os.chdir(sys.path[0]) |
784 os.chdir(sys.path[0]) |
782 |
785 |
783 # set the system exception handling function to ensure, that |
786 # set the system exception handling function to ensure, that |
793 except AttributeError: |
796 except AttributeError: |
794 self.test = unittest.defaultTestLoader\ |
797 self.test = unittest.defaultTestLoader\ |
795 .loadTestsFromModule(utModule) |
798 .loadTestsFromModule(utModule) |
796 except: |
799 except: |
797 exc_type, exc_value, exc_tb = sys.exc_info() |
800 exc_type, exc_value, exc_tb = sys.exc_info() |
798 self.write('{0}{1}\n'.format(ResponseUTPrepared, |
801 self.write('{0}{1}\n'.format(DebugProtocol.ResponseUTPrepared, |
799 str((0, str(exc_type), str(exc_value))))) |
802 str((0, str(exc_type), str(exc_value))))) |
800 self.__exceptionRaised() |
803 self.__exceptionRaised() |
801 return |
804 return |
802 |
805 |
803 # generate a coverage object |
806 # generate a coverage object |
809 if int(erase): |
812 if int(erase): |
810 self.cover.erase() |
813 self.cover.erase() |
811 else: |
814 else: |
812 self.cover = None |
815 self.cover = None |
813 |
816 |
814 self.write('{0}{1}\n'.format(ResponseUTPrepared, |
817 self.write('{0}{1}\n'.format(DebugProtocol.ResponseUTPrepared, |
815 str((self.test.countTestCases(), "", "")))) |
818 str((self.test.countTestCases(), "", "")))) |
816 return |
819 return |
817 |
820 |
818 if cmd == RequestUTRun: |
821 if cmd == DebugProtocol.RequestUTRun: |
819 from DCTestResult import DCTestResult |
822 from DCTestResult import DCTestResult |
820 self.testResult = DCTestResult(self) |
823 self.testResult = DCTestResult(self) |
821 if self.cover: |
824 if self.cover: |
822 self.cover.start() |
825 self.cover.start() |
823 self.test.run(self.testResult) |
826 self.test.run(self.testResult) |
824 if self.cover: |
827 if self.cover: |
825 self.cover.stop() |
828 self.cover.stop() |
826 self.cover.save() |
829 self.cover.save() |
827 self.write('{0}\n'.format(ResponseUTFinished)) |
830 self.write('{0}\n'.format(DebugProtocol.ResponseUTFinished)) |
828 return |
831 return |
829 |
832 |
830 if cmd == RequestUTStop: |
833 if cmd == DebugProtocol.RequestUTStop: |
831 self.testResult.stop() |
834 self.testResult.stop() |
832 return |
835 return |
833 |
836 |
834 if cmd == ResponseForkTo: |
837 if cmd == DebugProtocol.ResponseForkTo: |
835 # this results from a separate event loop |
838 # this results from a separate event loop |
836 self.fork_child = (arg == 'child') |
839 self.fork_child = (arg == 'child') |
837 self.eventExit = True |
840 self.eventExit = True |
838 return |
841 return |
839 |
842 |
840 if cmd == RequestForkMode: |
843 if cmd == DebugProtocol.RequestForkMode: |
841 self.fork_auto, self.fork_child = eval(arg) |
844 self.fork_auto, self.fork_child = eval(arg) |
842 return |
845 return |
843 |
846 |
844 # If we are handling raw mode input then reset the mode and break out |
847 # If we are handling raw mode input then reset the mode and break out |
845 # of the current event loop. |
848 # of the current event loop. |
1055 @param remoteAddress the network address of the debug server host (string) |
1058 @param remoteAddress the network address of the debug server host (string) |
1056 @param redirect flag indicating redirection of stdin, stdout and stderr (boolean) |
1059 @param redirect flag indicating redirection of stdin, stdout and stderr (boolean) |
1057 """ |
1060 """ |
1058 if remoteAddress is None: # default: 127.0.0.1 |
1061 if remoteAddress is None: # default: 127.0.0.1 |
1059 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
1062 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
1060 sock.connect((DebugAddress, port)) |
1063 sock.connect((DebugProtocol.DebugAddress, port)) |
1061 elif ":" in remoteAddress: # IPv6 |
1064 elif ":" in remoteAddress: # IPv6 |
1062 sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) |
1065 sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) |
1063 sock.connect((remoteAddress, port)) |
1066 sock.connect((remoteAddress, port)) |
1064 else: # IPv4 |
1067 else: # IPv4 |
1065 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
1068 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
1209 keylist = dict.keys() |
1212 keylist = dict.keys() |
1210 |
1213 |
1211 vlist = self.__formatVariablesList(keylist, dict, scope, filter) |
1214 vlist = self.__formatVariablesList(keylist, dict, scope, filter) |
1212 varlist.extend(vlist) |
1215 varlist.extend(vlist) |
1213 |
1216 |
1214 self.write('{0}{1}\n'.format(ResponseVariables, str(varlist))) |
1217 self.write('{0}{1}\n'.format(DebugProtocol.ResponseVariables, str(varlist))) |
1215 |
1218 |
1216 def __dumpVariable(self, var, frmnr, scope, filter): |
1219 def __dumpVariable(self, var, frmnr, scope, filter): |
1217 """ |
1220 """ |
1218 Private method to return the variables of a frame to the debug server. |
1221 Private method to return the variables of a frame to the debug server. |
1219 |
1222 |
1413 elif repr(obj).startswith('['): |
1416 elif repr(obj).startswith('['): |
1414 varlist.append(('...', 'list', "{0:d}".format(len(obj)))) |
1417 varlist.append(('...', 'list', "{0:d}".format(len(obj)))) |
1415 elif repr(obj).startswith('('): |
1418 elif repr(obj).startswith('('): |
1416 varlist.append(('...', 'tuple', "{0:d}".format(len(obj)))) |
1419 varlist.append(('...', 'tuple', "{0:d}".format(len(obj)))) |
1417 |
1420 |
1418 self.write('{0}{1}\n'.format(ResponseVariable, str(varlist))) |
1421 self.write('{0}{1}\n'.format(DebugProtocol.ResponseVariable, str(varlist))) |
1419 |
1422 |
1420 def __formatQt4Variable(self, value, vtype): |
1423 def __formatQt4Variable(self, value, vtype): |
1421 """ |
1424 """ |
1422 Private method to produce a formatted output of a simple Qt4 type. |
1425 Private method to produce a formatted output of a simple Qt4 type. |
1423 |
1426 |
1678 try: |
1681 try: |
1679 comp = self.complete(text, state) |
1682 comp = self.complete(text, state) |
1680 except: |
1683 except: |
1681 comp = None |
1684 comp = None |
1682 |
1685 |
1683 self.write("{0}{1}||{2}\n".format(ResponseCompletion, str(completions), text)) |
1686 self.write("{0}{1}||{2}\n".format(DebugProtocol.ResponseCompletion, |
|
1687 str(completions), text)) |
1684 |
1688 |
1685 def startDebugger(self, filename=None, host=None, port=None, |
1689 def startDebugger(self, filename=None, host=None, port=None, |
1686 enableTrace=True, exceptions=True, tracePython=False, redirect=True): |
1690 enableTrace=True, exceptions=True, tracePython=False, redirect=True): |
1687 """ |
1691 """ |
1688 Public method used to start the remote debugger. |
1692 Public method used to start the remote debugger. |