316 d["id"] = -1 |
316 d["id"] = -1 |
317 d["name"] = "MainThread" |
317 d["name"] = "MainThread" |
318 d["broken"] = self.isBroken() |
318 d["broken"] = self.isBroken() |
319 threadList.append(d) |
319 threadList.append(d) |
320 |
320 |
321 self.write('%s%s\n' % (ResponseThreadList, unicode((currentId, threadList)))) |
321 self.write('%s%s\n' % (DebugProtocol.ResponseThreadList, |
|
322 unicode((currentId, threadList)))) |
322 |
323 |
323 def raw_input(self, prompt, echo): |
324 def raw_input(self, prompt, echo): |
324 """ |
325 """ |
325 Public method to implement raw_input() using the event loop. |
326 Public method to implement raw_input() using the event loop. |
326 |
327 |
327 @param prompt the prompt to be shown (string) |
328 @param prompt the prompt to be shown (string) |
328 @param echo Flag indicating echoing of the input (boolean) |
329 @param echo Flag indicating echoing of the input (boolean) |
329 @return the entered string |
330 @return the entered string |
330 """ |
331 """ |
331 self.write("%s%s\n" % (ResponseRaw, unicode((prompt, echo)))) |
332 self.write("%s%s\n" % (DebugProtocol.ResponseRaw, unicode((prompt, echo)))) |
332 self.inRawMode = 1 |
333 self.inRawMode = 1 |
333 self.eventLoop(True) |
334 self.eventLoop(True) |
334 return self.rawLine |
335 return self.rawLine |
335 |
336 |
336 def input(self, prompt): |
337 def input(self, prompt): |
396 if eoc >= 0 and line[0] == '>': |
397 if eoc >= 0 and line[0] == '>': |
397 # Get the command part and any argument. |
398 # Get the command part and any argument. |
398 cmd = line[:eoc + 1] |
399 cmd = line[:eoc + 1] |
399 arg = line[eoc + 1:] |
400 arg = line[eoc + 1:] |
400 |
401 |
401 if cmd == RequestVariables: |
402 if cmd == DebugProtocol.RequestVariables: |
402 frmnr, scope, filter = eval(arg) |
403 frmnr, scope, filter = eval(arg) |
403 self.__dumpVariables(int(frmnr), int(scope), filter) |
404 self.__dumpVariables(int(frmnr), int(scope), filter) |
404 return |
405 return |
405 |
406 |
406 if cmd == RequestVariable: |
407 if cmd == DebugProtocol.RequestVariable: |
407 var, frmnr, scope, filter = eval(arg) |
408 var, frmnr, scope, filter = eval(arg) |
408 self.__dumpVariable(var, int(frmnr), int(scope), filter) |
409 self.__dumpVariable(var, int(frmnr), int(scope), filter) |
409 return |
410 return |
410 |
411 |
411 if cmd == RequestThreadList: |
412 if cmd == DebugProtocol.RequestThreadList: |
412 self.__dumpThreadList() |
413 self.__dumpThreadList() |
413 return |
414 return |
414 |
415 |
415 if cmd == RequestThreadSet: |
416 if cmd == DebugProtocol.RequestThreadSet: |
416 tid = eval(arg) |
417 tid = eval(arg) |
417 if tid in self.threads: |
418 if tid in self.threads: |
418 self.setCurrentThread(tid) |
419 self.setCurrentThread(tid) |
419 self.write(ResponseThreadSet + '\n') |
420 self.write(DebugProtocol.ResponseThreadSet + '\n') |
420 stack = self.currentThread.getStack() |
421 stack = self.currentThread.getStack() |
421 self.write('%s%s\n' % (ResponseStack, unicode(stack))) |
422 self.write('%s%s\n' % (DebugProtocol.ResponseStack, unicode(stack))) |
422 return |
423 return |
423 |
424 |
424 if cmd == RequestStep: |
425 if cmd == DebugProtocol.RequestStep: |
425 self.currentThread.step(1) |
426 self.currentThread.step(1) |
426 self.eventExit = 1 |
427 self.eventExit = 1 |
427 return |
428 return |
428 |
429 |
429 if cmd == RequestStepOver: |
430 if cmd == DebugProtocol.RequestStepOver: |
430 self.currentThread.step(0) |
431 self.currentThread.step(0) |
431 self.eventExit = 1 |
432 self.eventExit = 1 |
432 return |
433 return |
433 |
434 |
434 if cmd == RequestStepOut: |
435 if cmd == DebugProtocol.RequestStepOut: |
435 self.currentThread.stepOut() |
436 self.currentThread.stepOut() |
436 self.eventExit = 1 |
437 self.eventExit = 1 |
437 return |
438 return |
438 |
439 |
439 if cmd == RequestStepQuit: |
440 if cmd == DebugProtocol.RequestStepQuit: |
440 if self.passive: |
441 if self.passive: |
441 self.progTerminated(42) |
442 self.progTerminated(42) |
442 else: |
443 else: |
443 self.set_quit() |
444 self.set_quit() |
444 self.eventExit = 1 |
445 self.eventExit = 1 |
445 return |
446 return |
446 |
447 |
447 if cmd == RequestContinue: |
448 if cmd == DebugProtocol.RequestContinue: |
448 special = int(arg) |
449 special = int(arg) |
449 self.currentThread.go(special) |
450 self.currentThread.go(special) |
450 self.eventExit = 1 |
451 self.eventExit = 1 |
451 return |
452 return |
452 |
453 |
453 if cmd == RequestOK: |
454 if cmd == DebugProtocol.RequestOK: |
454 self.write(self.pendingResponse + '\n') |
455 self.write(self.pendingResponse + '\n') |
455 self.pendingResponse = ResponseOK |
456 self.pendingResponse = DebugProtocol.ResponseOK |
456 return |
457 return |
457 |
458 |
458 if cmd == RequestEnv: |
459 if cmd == DebugProtocol.RequestEnv: |
459 env = eval(arg) |
460 env = eval(arg) |
460 for key, value in env.items(): |
461 for key, value in env.items(): |
461 if key.endswith("+"): |
462 if key.endswith("+"): |
462 if key[:-1] in os.environ: |
463 if key[:-1] in os.environ: |
463 os.environ[key[:-1]] += value |
464 os.environ[key[:-1]] += value |
540 sys.modules['__main__'] = self.debugMod |
541 sys.modules['__main__'] = self.debugMod |
541 execfile(sys.argv[0], self.debugMod.__dict__) |
542 execfile(sys.argv[0], self.debugMod.__dict__) |
542 self.writestream.flush() |
543 self.writestream.flush() |
543 return |
544 return |
544 |
545 |
545 if cmd == RequestCoverage: |
546 if cmd == DebugProtocol.RequestCoverage: |
546 from coverage import coverage |
547 from coverage import coverage |
547 sys.argv = [] |
548 sys.argv = [] |
548 wd, fn, args, erase = arg.split('@@') |
549 wd, fn, args, erase = arg.split('@@') |
549 self.__setCoding(fn) |
550 self.__setCoding(fn) |
550 sys.argv.append(fn) |
551 sys.argv.append(fn) |
621 else: |
622 else: |
622 try: |
623 try: |
623 compile(cond, '<string>', 'eval') |
624 compile(cond, '<string>', 'eval') |
624 except SyntaxError: |
625 except SyntaxError: |
625 self.write('%s%s,%d\n' % \ |
626 self.write('%s%s,%d\n' % \ |
626 (ResponseBPConditionError, fn, line)) |
627 (DebugProtocol.ResponseBPConditionError, fn, line)) |
627 return |
628 return |
628 self.mainThread.set_break(fn, line, temporary, cond) |
629 self.mainThread.set_break(fn, line, temporary, cond) |
629 else: |
630 else: |
630 self.mainThread.clear_break(fn, line) |
631 self.mainThread.clear_break(fn, line) |
631 |
632 |
632 return |
633 return |
633 |
634 |
634 if cmd == RequestBreakEnable: |
635 if cmd == DebugProtocol.RequestBreakEnable: |
635 fn, line, enable = arg.split(',') |
636 fn, line, enable = arg.split(',') |
636 line = int(line) |
637 line = int(line) |
637 enable = int(enable) |
638 enable = int(enable) |
638 |
639 |
639 bp = self.mainThread.get_break(fn, line) |
640 bp = self.mainThread.get_break(fn, line) |
643 else: |
644 else: |
644 bp.disable() |
645 bp.disable() |
645 |
646 |
646 return |
647 return |
647 |
648 |
648 if cmd == RequestBreakIgnore: |
649 if cmd == DebugProtocol.RequestBreakIgnore: |
649 fn, line, count = arg.split(',') |
650 fn, line, count = arg.split(',') |
650 line = int(line) |
651 line = int(line) |
651 count = int(count) |
652 count = int(count) |
652 |
653 |
653 bp = self.mainThread.get_break(fn, line) |
654 bp = self.mainThread.get_break(fn, line) |
654 if bp is not None: |
655 if bp is not None: |
655 bp.ignore = count |
656 bp.ignore = count |
656 |
657 |
657 return |
658 return |
658 |
659 |
659 if cmd == RequestWatch: |
660 if cmd == DebugProtocol.RequestWatch: |
660 cond, temporary, set = arg.split('@@') |
661 cond, temporary, set = arg.split('@@') |
661 set = int(set) |
662 set = int(set) |
662 temporary = int(temporary) |
663 temporary = int(temporary) |
663 |
664 |
664 if set: |
665 if set: |
665 if not cond.endswith('??created??') and \ |
666 if not cond.endswith('??created??') and \ |
666 not cond.endswith('??changed??'): |
667 not cond.endswith('??changed??'): |
667 try: |
668 try: |
668 compile(cond, '<string>', 'eval') |
669 compile(cond, '<string>', 'eval') |
669 except SyntaxError: |
670 except SyntaxError: |
670 self.write('%s%s\n' % (ResponseWPConditionError, cond)) |
671 self.write('%s%s\n' % ( |
|
672 DebugProtocol.ResponseWPConditionError, cond)) |
671 return |
673 return |
672 self.mainThread.set_watch(cond, temporary) |
674 self.mainThread.set_watch(cond, temporary) |
673 else: |
675 else: |
674 self.mainThread.clear_watch(cond) |
676 self.mainThread.clear_watch(cond) |
675 |
677 |
676 return |
678 return |
677 |
679 |
678 if cmd == RequestWatchEnable: |
680 if cmd == DebugProtocol.RequestWatchEnable: |
679 cond, enable = arg.split(',') |
681 cond, enable = arg.split(',') |
680 enable = int(enable) |
682 enable = int(enable) |
681 |
683 |
682 bp = self.mainThread.get_watch(cond) |
684 bp = self.mainThread.get_watch(cond) |
683 if bp is not None: |
685 if bp is not None: |
686 else: |
688 else: |
687 bp.disable() |
689 bp.disable() |
688 |
690 |
689 return |
691 return |
690 |
692 |
691 if cmd == RequestWatchIgnore: |
693 if cmd == DebugProtocol.RequestWatchIgnore: |
692 cond, count = arg.split(',') |
694 cond, count = arg.split(',') |
693 count = int(count) |
695 count = int(count) |
694 |
696 |
695 bp = self.mainThread.get_watch(cond) |
697 bp = self.mainThread.get_watch(cond) |
696 if bp is not None: |
698 if bp is not None: |
697 bp.ignore = count |
699 bp.ignore = count |
698 |
700 |
699 return |
701 return |
700 |
702 |
701 if cmd == RequestEval: |
703 if cmd == DebugProtocol.RequestEval: |
702 try: |
704 try: |
703 value = eval(arg, self.currentThread.getCurrentFrame().f_globals, |
705 value = eval(arg, self.currentThread.getCurrentFrame().f_globals, |
704 self.currentThread.getCurrentFrameLocals()) |
706 self.currentThread.getCurrentFrameLocals()) |
705 except: |
707 except: |
706 # Report the exception and the traceback |
708 # Report the exception and the traceback |
719 finally: |
721 finally: |
720 tblist = tb = None |
722 tblist = tb = None |
721 |
723 |
722 map(self.write, list) |
724 map(self.write, list) |
723 |
725 |
724 self.write(ResponseException + '\n') |
726 self.write(DebugProtocol.ResponseException + '\n') |
725 |
727 |
726 else: |
728 else: |
727 self.write(unicode(value) + '\n') |
729 self.write(unicode(value) + '\n') |
728 self.write(ResponseOK + '\n') |
730 self.write(DebugProtocol.ResponseOK + '\n') |
729 |
731 |
730 return |
732 return |
731 |
733 |
732 if cmd == RequestExec: |
734 if cmd == DebugProtocol.RequestExec: |
733 _globals = self.currentThread.getCurrentFrame().f_globals |
735 _globals = self.currentThread.getCurrentFrame().f_globals |
734 _locals = self.currentThread.getCurrentFrameLocals() |
736 _locals = self.currentThread.getCurrentFrameLocals() |
735 try: |
737 try: |
736 code = compile(arg + '\n', '<stdin>', 'single') |
738 code = compile(arg + '\n', '<stdin>', 'single') |
737 exec code in _globals, _locals |
739 exec code in _globals, _locals |
752 finally: |
754 finally: |
753 tblist = tb = None |
755 tblist = tb = None |
754 |
756 |
755 map(self.write, list) |
757 map(self.write, list) |
756 |
758 |
757 self.write(ResponseException + '\n') |
759 self.write(DebugProtocol.ResponseException + '\n') |
758 |
760 |
759 return |
761 return |
760 |
762 |
761 if cmd == RequestBanner: |
763 if cmd == DebugProtocol.RequestBanner: |
762 self.write('%s%s\n' % (ResponseBanner, |
764 self.write('%s%s\n' % (DebugProtocol.ResponseBanner, |
763 unicode(("Python %s" % sys.version, socket.gethostname(), |
765 unicode(("Python %s" % sys.version, socket.gethostname(), |
764 self.variant)))) |
766 self.variant)))) |
765 return |
767 return |
766 |
768 |
767 if cmd == RequestCapabilities: |
769 if cmd == DebugProtocol.RequestCapabilities: |
768 self.write('%s%d, "Python"\n' % (ResponseCapabilities, |
770 self.write('%s%d, "Python"\n' % (DebugProtocol.ResponseCapabilities, |
769 self.__clientCapabilities())) |
771 self.__clientCapabilities())) |
770 return |
772 return |
771 |
773 |
772 if cmd == RequestCompletion: |
774 if cmd == DebugProtocol.RequestCompletion: |
773 self.__completionList(arg) |
775 self.__completionList(arg) |
774 return |
776 return |
775 |
777 |
776 if cmd == RequestSetFilter: |
778 if cmd == DebugProtocol.RequestSetFilter: |
777 scope, filterString = eval(arg) |
779 scope, filterString = eval(arg) |
778 self.__generateFilterObjects(int(scope), filterString) |
780 self.__generateFilterObjects(int(scope), filterString) |
779 return |
781 return |
780 |
782 |
781 if cmd == RequestUTPrepare: |
783 if cmd == DebugProtocol.RequestUTPrepare: |
782 fn, tn, tfn, cov, covname, erase = arg.split('|') |
784 fn, tn, tfn, cov, covname, erase = arg.split('|') |
783 sys.path.insert(0, os.path.dirname(os.path.abspath(fn))) |
785 sys.path.insert(0, os.path.dirname(os.path.abspath(fn))) |
784 os.chdir(sys.path[0]) |
786 os.chdir(sys.path[0]) |
785 |
787 |
786 # set the system exception handling function to ensure, that |
788 # set the system exception handling function to ensure, that |
796 except AttributeError: |
798 except AttributeError: |
797 self.test = unittest.defaultTestLoader\ |
799 self.test = unittest.defaultTestLoader\ |
798 .loadTestsFromModule(utModule) |
800 .loadTestsFromModule(utModule) |
799 except: |
801 except: |
800 exc_type, exc_value, exc_tb = sys.exc_info() |
802 exc_type, exc_value, exc_tb = sys.exc_info() |
801 self.write('%s%s\n' % (ResponseUTPrepared, |
803 self.write('%s%s\n' % (DebugProtocol.ResponseUTPrepared, |
802 unicode((0, str(exc_type), str(exc_value))))) |
804 unicode((0, str(exc_type), str(exc_value))))) |
803 self.__exceptionRaised() |
805 self.__exceptionRaised() |
804 return |
806 return |
805 |
807 |
806 # generate a coverage object |
808 # generate a coverage object |
812 if int(erase): |
814 if int(erase): |
813 self.cover.erase() |
815 self.cover.erase() |
814 else: |
816 else: |
815 self.cover = None |
817 self.cover = None |
816 |
818 |
817 self.write('%s%s\n' % (ResponseUTPrepared, |
819 self.write('%s%s\n' % (DebugProtocol.ResponseUTPrepared, |
818 unicode((self.test.countTestCases(), "", "")))) |
820 unicode((self.test.countTestCases(), "", "")))) |
819 return |
821 return |
820 |
822 |
821 if cmd == RequestUTRun: |
823 if cmd == DebugProtocol.RequestUTRun: |
822 from DCTestResult import DCTestResult |
824 from DCTestResult import DCTestResult |
823 self.testResult = DCTestResult(self) |
825 self.testResult = DCTestResult(self) |
824 if self.cover: |
826 if self.cover: |
825 self.cover.start() |
827 self.cover.start() |
826 self.test.run(self.testResult) |
828 self.test.run(self.testResult) |
827 if self.cover: |
829 if self.cover: |
828 self.cover.stop() |
830 self.cover.stop() |
829 self.cover.save() |
831 self.cover.save() |
830 self.write('%s\n' % ResponseUTFinished) |
832 self.write('%s\n' % DebugProtocol.ResponseUTFinished) |
831 return |
833 return |
832 |
834 |
833 if cmd == RequestUTStop: |
835 if cmd == DebugProtocol.RequestUTStop: |
834 self.testResult.stop() |
836 self.testResult.stop() |
835 return |
837 return |
836 |
838 |
837 if cmd == ResponseForkTo: |
839 if cmd == DebugProtocol.ResponseForkTo: |
838 # this results from a separate event loop |
840 # this results from a separate event loop |
839 self.fork_child = (arg == 'child') |
841 self.fork_child = (arg == 'child') |
840 self.eventExit = 1 |
842 self.eventExit = 1 |
841 return |
843 return |
842 |
844 |
843 if cmd == RequestForkMode: |
845 if cmd == DebugProtocol.RequestForkMode: |
844 self.fork_auto, self.fork_child = eval(arg) |
846 self.fork_auto, self.fork_child = eval(arg) |
845 return |
847 return |
846 |
848 |
847 # If we are handling raw mode input then reset the mode and break out |
849 # If we are handling raw mode input then reset the mode and break out |
848 # of the current event loop. |
850 # of the current event loop. |
1056 @param remoteAddress the network address of the debug server host (string) |
1058 @param remoteAddress the network address of the debug server host (string) |
1057 @param redirect flag indicating redirection of stdin, stdout and stderr (boolean) |
1059 @param redirect flag indicating redirection of stdin, stdout and stderr (boolean) |
1058 """ |
1060 """ |
1059 if remoteAddress is None: # default: 127.0.0.1 |
1061 if remoteAddress is None: # default: 127.0.0.1 |
1060 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
1062 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
1061 sock.connect((DebugAddress, port)) |
1063 sock.connect((DebugProtocol.DebugAddress, port)) |
1062 elif ":" in remoteAddress: # IPv6 |
1064 elif ":" in remoteAddress: # IPv6 |
1063 sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) |
1065 sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) |
1064 sock.connect((remoteAddress, port)) |
1066 sock.connect((remoteAddress, port)) |
1065 else: # IPv4 |
1067 else: # IPv4 |
1066 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
1068 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
1210 keylist = dict.keys() |
1212 keylist = dict.keys() |
1211 |
1213 |
1212 vlist = self.__formatVariablesList(keylist, dict, scope, filter) |
1214 vlist = self.__formatVariablesList(keylist, dict, scope, filter) |
1213 varlist.extend(vlist) |
1215 varlist.extend(vlist) |
1214 |
1216 |
1215 self.write('%s%s\n' % (ResponseVariables, unicode(varlist))) |
1217 self.write('%s%s\n' % (DebugProtocol.ResponseVariables, unicode(varlist))) |
1216 |
1218 |
1217 def __dumpVariable(self, var, frmnr, scope, filter): |
1219 def __dumpVariable(self, var, frmnr, scope, filter): |
1218 """ |
1220 """ |
1219 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. |
1220 |
1222 |
1398 elif unicode(repr(obj)).startswith('['): |
1400 elif unicode(repr(obj)).startswith('['): |
1399 varlist.append(('...', 'list', "%d" % len(obj))) |
1401 varlist.append(('...', 'list', "%d" % len(obj))) |
1400 elif unicode(repr(obj)).startswith('('): |
1402 elif unicode(repr(obj)).startswith('('): |
1401 varlist.append(('...', 'tuple', "%d" % len(obj))) |
1403 varlist.append(('...', 'tuple', "%d" % len(obj))) |
1402 |
1404 |
1403 self.write('%s%s\n' % (ResponseVariable, unicode(varlist))) |
1405 self.write('%s%s\n' % (DebugProtocol.ResponseVariable, unicode(varlist))) |
1404 |
1406 |
1405 def __formatQt4Variable(self, value, vtype): |
1407 def __formatQt4Variable(self, value, vtype): |
1406 """ |
1408 """ |
1407 Private method to produce a formated output of a simple Qt4 type. |
1409 Private method to produce a formated output of a simple Qt4 type. |
1408 |
1410 |
1658 try: |
1660 try: |
1659 comp = self.complete(text, state) |
1661 comp = self.complete(text, state) |
1660 except: |
1662 except: |
1661 comp = None |
1663 comp = None |
1662 |
1664 |
1663 self.write("%s%s||%s\n" % (ResponseCompletion, unicode(completions), text)) |
1665 self.write("%s%s||%s\n" % (DebugProtocol.ResponseCompletion, |
|
1666 unicode(completions), text)) |
1664 |
1667 |
1665 def startDebugger(self, filename=None, host=None, port=None, |
1668 def startDebugger(self, filename=None, host=None, port=None, |
1666 enableTrace=1, exceptions=1, tracePython=0, redirect=1): |
1669 enableTrace=1, exceptions=1, tracePython=0, redirect=1): |
1667 """ |
1670 """ |
1668 Public method used to start the remote debugger. |
1671 Public method used to start the remote debugger. |