432 stack = self.currentThread.getStack() |
436 stack = self.currentThread.getStack() |
433 self.write('{0}{1!r}\n'.format( |
437 self.write('{0}{1!r}\n'.format( |
434 DebugProtocol.ResponseStack, stack)) |
438 DebugProtocol.ResponseStack, stack)) |
435 return |
439 return |
436 |
440 |
437 if cmd == DebugProtocol.RequestStep: |
441 ## if cmd == DebugProtocol.RequestStep: |
438 self.currentThread.step(True) |
442 ## self.currentThread.step(True) |
439 self.eventExit = True |
443 ## self.eventExit = True |
440 return |
444 ## return |
441 |
445 ## |
442 if cmd == DebugProtocol.RequestStepOver: |
446 ## if cmd == DebugProtocol.RequestStepOver: |
443 self.currentThread.step(False) |
447 ## self.currentThread.step(False) |
444 self.eventExit = True |
448 ## self.eventExit = True |
445 return |
449 ## return |
446 |
450 ## |
447 if cmd == DebugProtocol.RequestStepOut: |
451 ## if cmd == DebugProtocol.RequestStepOut: |
448 self.currentThread.stepOut() |
452 ## self.currentThread.stepOut() |
449 self.eventExit = True |
453 ## self.eventExit = True |
450 return |
454 ## return |
451 |
455 ## |
452 if cmd == DebugProtocol.RequestStepQuit: |
456 ## if cmd == DebugProtocol.RequestStepQuit: |
453 if self.passive: |
457 ## if self.passive: |
454 self.progTerminated(42) |
458 ## self.progTerminated(42) |
455 else: |
459 ## else: |
456 self.set_quit() |
460 ## self.set_quit() |
457 self.eventExit = True |
461 ## self.eventExit = True |
458 return |
462 ## return |
459 |
463 ## |
460 if cmd == DebugProtocol.RequestContinue: |
464 ## if cmd == DebugProtocol.RequestContinue: |
461 special = int(arg) |
465 ## special = int(arg) |
462 self.currentThread.go(special) |
466 ## self.currentThread.go(special) |
463 self.eventExit = True |
467 ## self.eventExit = True |
464 return |
468 ## return |
465 |
469 ## |
466 if cmd == DebugProtocol.RequestOK: |
470 ## if cmd == DebugProtocol.RequestOK: |
467 self.write(self.pendingResponse + '\n') |
471 ## self.write(self.pendingResponse + '\n') |
468 self.pendingResponse = DebugProtocol.ResponseOK |
472 ## self.pendingResponse = DebugProtocol.ResponseOK |
469 return |
473 ## return |
470 |
474 ## |
471 if cmd == DebugProtocol.RequestCallTrace: |
475 if cmd == DebugProtocol.RequestCallTrace: |
472 if arg.strip().lower() == "on": |
476 if arg.strip().lower() == "on": |
473 callTraceEnabled = True |
477 callTraceEnabled = True |
474 else: |
478 else: |
475 callTraceEnabled = False |
479 callTraceEnabled = False |
533 ## self.callTraceEnabled = self.__newCallTraceEnabled |
537 ## self.callTraceEnabled = self.__newCallTraceEnabled |
534 ## res = self.mainThread.run(code, self.debugMod.__dict__) |
538 ## res = self.mainThread.run(code, self.debugMod.__dict__) |
535 ## self.progTerminated(res) |
539 ## self.progTerminated(res) |
536 ## return |
540 ## return |
537 ## |
541 ## |
538 if cmd == DebugProtocol.RequestRun: |
542 ## if cmd == DebugProtocol.RequestRun: |
539 sys.argv = [] |
543 ## sys.argv = [] |
540 wd, fn, args = arg.split('|') |
544 ## wd, fn, args = arg.split('|') |
541 self.__setCoding(fn) |
545 ## self.__setCoding(fn) |
542 sys.argv.append(fn) |
546 ## sys.argv.append(fn) |
543 sys.argv.extend(eval(args)) |
547 ## sys.argv.extend(eval(args)) |
544 sys.path = self.__getSysPath(os.path.dirname(sys.argv[0])) |
548 ## sys.path = self.__getSysPath(os.path.dirname(sys.argv[0])) |
545 if wd == '': |
549 ## if wd == '': |
546 os.chdir(sys.path[1]) |
550 ## os.chdir(sys.path[1]) |
547 else: |
551 ## else: |
548 os.chdir(wd) |
552 ## os.chdir(wd) |
549 |
553 ## |
550 self.running = sys.argv[0] |
554 ## self.running = sys.argv[0] |
551 self.mainFrame = None |
555 ## self.mainFrame = None |
552 self.botframe = None |
556 ## self.botframe = None |
553 self.inRawMode = False |
557 ## self.inRawMode = False |
554 |
558 ## |
555 self.threads.clear() |
559 ## self.threads.clear() |
556 self.attachThread(mainThread=True) |
560 ## self.attachThread(mainThread=True) |
557 |
561 ## |
558 # set the system exception handling function to ensure, that |
562 ## # set the system exception handling function to ensure, that |
559 # we report on all unhandled exceptions |
563 ## # we report on all unhandled exceptions |
560 sys.excepthook = self.__unhandled_exception |
564 ## sys.excepthook = self.__unhandled_exception |
561 self.__interceptSignals() |
565 ## self.__interceptSignals() |
562 |
566 ## |
563 self.mainThread.tracePython = False |
567 ## self.mainThread.tracePython = False |
564 |
568 ## |
565 self.debugMod.__dict__['__file__'] = sys.argv[0] |
569 ## self.debugMod.__dict__['__file__'] = sys.argv[0] |
566 sys.modules['__main__'] = self.debugMod |
570 ## sys.modules['__main__'] = self.debugMod |
567 res = 0 |
571 ## res = 0 |
568 code = self.__compileFileSource(self.running) |
572 ## code = self.__compileFileSource(self.running) |
569 if code: |
573 ## if code: |
570 try: |
574 ## try: |
571 exec(code, self.debugMod.__dict__) |
575 ## exec(code, self.debugMod.__dict__) |
572 except SystemExit as exc: |
576 ## except SystemExit as exc: |
573 res = exc.code |
577 ## res = exc.code |
574 atexit._run_exitfuncs() |
578 ## atexit._run_exitfuncs() |
575 self.writestream.flush() |
579 ## self.writestream.flush() |
576 self.progTerminated(res) |
580 ## self.progTerminated(res) |
577 return |
581 ## return |
578 |
582 ## |
579 if cmd == DebugProtocol.RequestProfile: |
583 ## if cmd == DebugProtocol.RequestProfile: |
580 sys.setprofile(None) |
584 ## sys.setprofile(None) |
581 import PyProfile |
585 ## import PyProfile |
582 sys.argv = [] |
586 ## sys.argv = [] |
583 wd, fn, args, erase = arg.split('|') |
587 ## wd, fn, args, erase = arg.split('|') |
584 self.__setCoding(fn) |
588 ## self.__setCoding(fn) |
585 sys.argv.append(fn) |
589 ## sys.argv.append(fn) |
586 sys.argv.extend(eval(args)) |
590 ## sys.argv.extend(eval(args)) |
587 sys.path = self.__getSysPath(os.path.dirname(sys.argv[0])) |
591 ## sys.path = self.__getSysPath(os.path.dirname(sys.argv[0])) |
588 if wd == '': |
592 ## if wd == '': |
589 os.chdir(sys.path[1]) |
593 ## os.chdir(sys.path[1]) |
590 else: |
594 ## else: |
591 os.chdir(wd) |
595 ## os.chdir(wd) |
592 |
596 ## |
593 # set the system exception handling function to ensure, that |
597 ## # set the system exception handling function to ensure, that |
594 # we report on all unhandled exceptions |
598 ## # we report on all unhandled exceptions |
595 sys.excepthook = self.__unhandled_exception |
599 ## sys.excepthook = self.__unhandled_exception |
596 self.__interceptSignals() |
600 ## self.__interceptSignals() |
597 |
601 ## |
598 # generate a profile object |
602 ## # generate a profile object |
599 self.prof = PyProfile.PyProfile(sys.argv[0]) |
603 ## self.prof = PyProfile.PyProfile(sys.argv[0]) |
600 |
604 ## |
601 if int(erase): |
605 ## if int(erase): |
602 self.prof.erase() |
606 ## self.prof.erase() |
603 self.debugMod.__dict__['__file__'] = sys.argv[0] |
607 ## self.debugMod.__dict__['__file__'] = sys.argv[0] |
604 sys.modules['__main__'] = self.debugMod |
608 ## sys.modules['__main__'] = self.debugMod |
605 fp = open(sys.argv[0], encoding=self.__coding) |
609 ## fp = open(sys.argv[0], encoding=self.__coding) |
606 try: |
610 ## try: |
607 script = fp.read() |
611 ## script = fp.read() |
608 finally: |
612 ## finally: |
609 fp.close() |
613 ## fp.close() |
610 if script: |
614 ## if script: |
611 if not script.endswith('\n'): |
615 ## if not script.endswith('\n'): |
612 script += '\n' |
616 ## script += '\n' |
613 self.running = sys.argv[0] |
617 ## self.running = sys.argv[0] |
614 res = 0 |
618 ## res = 0 |
615 try: |
619 ## try: |
616 self.prof.run(script) |
620 ## self.prof.run(script) |
617 except SystemExit as exc: |
621 ## except SystemExit as exc: |
618 res = exc.code |
622 ## res = exc.code |
619 atexit._run_exitfuncs() |
623 ## atexit._run_exitfuncs() |
620 self.prof.save() |
624 ## self.prof.save() |
621 self.writestream.flush() |
625 ## self.writestream.flush() |
622 self.progTerminated(res) |
626 ## self.progTerminated(res) |
623 return |
627 ## return |
624 |
628 ## |
625 if cmd == DebugProtocol.RequestCoverage: |
629 ## if cmd == DebugProtocol.RequestCoverage: |
626 from coverage import coverage |
630 ## from coverage import coverage |
627 sys.argv = [] |
631 ## sys.argv = [] |
628 wd, fn, args, erase = arg.split('@@') |
632 ## wd, fn, args, erase = arg.split('@@') |
629 self.__setCoding(fn) |
633 ## self.__setCoding(fn) |
630 sys.argv.append(fn) |
634 ## sys.argv.append(fn) |
631 sys.argv.extend(eval(args)) |
635 ## sys.argv.extend(eval(args)) |
632 sys.path = self.__getSysPath(os.path.dirname(sys.argv[0])) |
636 ## sys.path = self.__getSysPath(os.path.dirname(sys.argv[0])) |
633 if wd == '': |
637 ## if wd == '': |
634 os.chdir(sys.path[1]) |
638 ## os.chdir(sys.path[1]) |
635 else: |
639 ## else: |
636 os.chdir(wd) |
640 ## os.chdir(wd) |
637 |
641 ## |
638 # set the system exception handling function to ensure, that |
642 ## # set the system exception handling function to ensure, that |
639 # we report on all unhandled exceptions |
643 ## # we report on all unhandled exceptions |
640 sys.excepthook = self.__unhandled_exception |
644 ## sys.excepthook = self.__unhandled_exception |
641 self.__interceptSignals() |
645 ## self.__interceptSignals() |
642 |
646 ## |
643 # generate a coverage object |
647 ## # generate a coverage object |
644 self.cover = coverage( |
648 ## self.cover = coverage( |
645 auto_data=True, |
649 ## auto_data=True, |
646 data_file="{0}.coverage".format( |
650 ## data_file="{0}.coverage".format( |
647 os.path.splitext(sys.argv[0])[0])) |
651 ## os.path.splitext(sys.argv[0])[0])) |
648 |
652 ## |
649 if int(erase): |
653 ## if int(erase): |
650 self.cover.erase() |
654 ## self.cover.erase() |
651 sys.modules['__main__'] = self.debugMod |
655 ## sys.modules['__main__'] = self.debugMod |
652 self.debugMod.__dict__['__file__'] = sys.argv[0] |
656 ## self.debugMod.__dict__['__file__'] = sys.argv[0] |
653 fp = open(sys.argv[0], encoding=self.__coding) |
657 ## fp = open(sys.argv[0], encoding=self.__coding) |
654 try: |
658 ## try: |
655 script = fp.read() |
659 ## script = fp.read() |
656 finally: |
660 ## finally: |
657 fp.close() |
661 ## fp.close() |
658 if script: |
662 ## if script: |
659 if not script.endswith('\n'): |
663 ## if not script.endswith('\n'): |
660 script += '\n' |
664 ## script += '\n' |
661 code = compile(script, sys.argv[0], 'exec') |
665 ## code = compile(script, sys.argv[0], 'exec') |
662 self.running = sys.argv[0] |
666 ## self.running = sys.argv[0] |
663 res = 0 |
667 ## res = 0 |
664 self.cover.start() |
668 ## self.cover.start() |
665 try: |
669 ## try: |
666 exec(code, self.debugMod.__dict__) |
670 ## exec(code, self.debugMod.__dict__) |
667 except SystemExit as exc: |
671 ## except SystemExit as exc: |
668 res = exc.code |
672 ## res = exc.code |
669 atexit._run_exitfuncs() |
673 ## atexit._run_exitfuncs() |
670 self.cover.stop() |
674 ## self.cover.stop() |
671 self.cover.save() |
675 ## self.cover.save() |
672 self.writestream.flush() |
676 ## self.writestream.flush() |
673 self.progTerminated(res) |
677 ## self.progTerminated(res) |
674 return |
678 ## return |
675 |
679 |
676 if cmd == DebugProtocol.RequestShutdown: |
680 if cmd == DebugProtocol.RequestShutdown: |
677 self.sessionClose() |
681 self.sessionClose() |
678 return |
682 return |
679 |
683 |
928 |
932 |
929 if cmd == DebugProtocol.RequestForkMode: |
933 if cmd == DebugProtocol.RequestForkMode: |
930 self.fork_auto, self.fork_child = eval(arg) |
934 self.fork_auto, self.fork_child = eval(arg) |
931 return |
935 return |
932 |
936 |
933 # If we are handling raw mode input then reset the mode and break out |
937 ## # If we are handling raw mode input then reset the mode and break out |
934 # of the current event loop. |
938 ## # of the current event loop. |
935 if self.inRawMode: |
939 ## if self.inRawMode: |
936 self.inRawMode = False |
940 ## self.inRawMode = False |
937 self.rawLine = line |
941 ## self.rawLine = line |
938 self.eventExit = True |
942 ## self.eventExit = True |
939 return |
943 ## return |
940 |
944 ## |
941 if self.buffer: |
945 ## if self.buffer: |
942 self.buffer = self.buffer + '\n' + line |
946 ## self.buffer = self.buffer + '\n' + line |
943 else: |
947 ## else: |
944 self.buffer = line |
948 ## self.buffer = line |
945 |
949 ## |
946 try: |
950 ## try: |
947 code = self.compile_command(self.buffer, self.readstream.name) |
951 ## code = self.compile_command(self.buffer, self.readstream.name) |
948 except (OverflowError, SyntaxError, ValueError): |
952 ## except (OverflowError, SyntaxError, ValueError): |
949 # Report the exception |
953 ## # Report the exception |
950 sys.last_type, sys.last_value, sys.last_traceback = sys.exc_info() |
954 ## sys.last_type, sys.last_value, sys.last_traceback = sys.exc_info() |
951 for l in traceback.format_exception_only( |
955 ## for l in traceback.format_exception_only( |
952 sys.last_type, sys.last_value): |
956 ## sys.last_type, sys.last_value): |
953 self.write(l) |
957 ## self.write(l) |
954 self.buffer = '' |
958 ## self.buffer = '' |
955 else: |
959 ## else: |
956 if code is None: |
960 ## if code is None: |
957 self.pendingResponse = DebugProtocol.ResponseContinue |
961 ## self.pendingResponse = DebugProtocol.ResponseContinue |
958 else: |
962 ## else: |
959 self.buffer = '' |
963 ## self.buffer = '' |
960 |
964 ## |
961 try: |
965 ## try: |
962 if self.running is None: |
966 ## if self.running is None: |
963 exec(code, self.debugMod.__dict__) |
967 ## exec(code, self.debugMod.__dict__) |
964 else: |
968 ## else: |
965 if self.currentThread is None: |
969 ## if self.currentThread is None: |
966 # program has terminated |
970 ## # program has terminated |
967 self.running = None |
971 ## self.running = None |
968 _globals = self.debugMod.__dict__ |
972 ## _globals = self.debugMod.__dict__ |
969 _locals = _globals |
973 ## _locals = _globals |
970 else: |
974 ## else: |
971 cf = self.currentThread.getCurrentFrame() |
975 ## cf = self.currentThread.getCurrentFrame() |
972 # program has terminated |
976 ## # program has terminated |
973 if cf is None: |
977 ## if cf is None: |
974 self.running = None |
978 ## self.running = None |
975 _globals = self.debugMod.__dict__ |
979 ## _globals = self.debugMod.__dict__ |
976 _locals = _globals |
980 ## _locals = _globals |
977 else: |
981 ## else: |
978 frmnr = self.framenr |
982 ## frmnr = self.framenr |
979 while cf is not None and frmnr > 0: |
983 ## while cf is not None and frmnr > 0: |
980 cf = cf.f_back |
984 ## cf = cf.f_back |
981 frmnr -= 1 |
985 ## frmnr -= 1 |
982 _globals = cf.f_globals |
986 ## _globals = cf.f_globals |
983 _locals = \ |
987 ## _locals = \ |
984 self.currentThread.getFrameLocals( |
988 ## self.currentThread.getFrameLocals( |
985 self.framenr) |
989 ## self.framenr) |
986 # reset sys.stdout to our redirector (unconditionally) |
990 ## # reset sys.stdout to our redirector (unconditionally) |
987 if "sys" in _globals: |
991 ## if "sys" in _globals: |
988 __stdout = _globals["sys"].stdout |
992 ## __stdout = _globals["sys"].stdout |
989 _globals["sys"].stdout = self.writestream |
993 ## _globals["sys"].stdout = self.writestream |
990 exec(code, _globals, _locals) |
994 ## exec(code, _globals, _locals) |
991 _globals["sys"].stdout = __stdout |
995 ## _globals["sys"].stdout = __stdout |
992 elif "sys" in _locals: |
996 ## elif "sys" in _locals: |
993 __stdout = _locals["sys"].stdout |
997 ## __stdout = _locals["sys"].stdout |
994 _locals["sys"].stdout = self.writestream |
998 ## _locals["sys"].stdout = self.writestream |
995 exec(code, _globals, _locals) |
999 ## exec(code, _globals, _locals) |
996 _locals["sys"].stdout = __stdout |
1000 ## _locals["sys"].stdout = __stdout |
997 else: |
1001 ## else: |
998 exec(code, _globals, _locals) |
1002 ## exec(code, _globals, _locals) |
999 |
1003 ## |
1000 self.currentThread.storeFrameLocals(self.framenr) |
1004 ## self.currentThread.storeFrameLocals(self.framenr) |
1001 except SystemExit as exc: |
1005 ## except SystemExit as exc: |
1002 self.progTerminated(exc.code) |
1006 ## self.progTerminated(exc.code) |
1003 except Exception: |
1007 ## except Exception: |
1004 # Report the exception and the traceback |
1008 ## # Report the exception and the traceback |
1005 try: |
1009 ## try: |
1006 exc_type, exc_value, exc_tb = sys.exc_info() |
1010 ## exc_type, exc_value, exc_tb = sys.exc_info() |
1007 sys.last_type = exc_type |
1011 ## sys.last_type = exc_type |
1008 sys.last_value = exc_value |
1012 ## sys.last_value = exc_value |
1009 sys.last_traceback = exc_tb |
1013 ## sys.last_traceback = exc_tb |
1010 tblist = traceback.extract_tb(exc_tb) |
1014 ## tblist = traceback.extract_tb(exc_tb) |
1011 del tblist[:1] |
1015 ## del tblist[:1] |
1012 list = traceback.format_list(tblist) |
1016 ## list = traceback.format_list(tblist) |
1013 if list: |
1017 ## if list: |
1014 list.insert(0, "Traceback (innermost last):\n") |
1018 ## list.insert(0, "Traceback (innermost last):\n") |
1015 list[len(list):] = traceback.format_exception_only( |
1019 ## list[len(list):] = traceback.format_exception_only( |
1016 exc_type, exc_value) |
1020 ## exc_type, exc_value) |
1017 finally: |
1021 ## finally: |
1018 tblist = exc_tb = None |
1022 ## tblist = exc_tb = None |
1019 |
1023 ## |
1020 for l in list: |
1024 ## for l in list: |
1021 self.write(l) |
1025 ## self.write(l) |
1022 |
1026 |
1023 def __handleJsonCommand(self, jsonStr): |
1027 def __handleJsonCommand(self, jsonStr): |
1024 """ |
1028 """ |
1025 Private method to handle a command serialized as a JSON string. |
1029 Private method to handle a command serialized as a JSON string. |
1026 """ |
1030 """ |
1102 code = self.__compileFileSource(self.running) |
1106 code = self.__compileFileSource(self.running) |
1103 if code: |
1107 if code: |
1104 self.callTraceEnabled = self.__newCallTraceEnabled |
1108 self.callTraceEnabled = self.__newCallTraceEnabled |
1105 res = self.mainThread.run(code, self.debugMod.__dict__) |
1109 res = self.mainThread.run(code, self.debugMod.__dict__) |
1106 self.progTerminated(res) |
1110 self.progTerminated(res) |
|
1111 return |
|
1112 |
|
1113 if method == "RequestRun": |
|
1114 sys.argv = [] |
|
1115 self.__setCoding(params["filename"]) |
|
1116 sys.argv.append(params["filename"]) |
|
1117 sys.argv.extend(params["argv"]) |
|
1118 sys.path = self.__getSysPath(os.path.dirname(sys.argv[0])) |
|
1119 if params["workdir"] == '': |
|
1120 os.chdir(sys.path[1]) |
|
1121 else: |
|
1122 os.chdir(params["workdir"]) |
|
1123 |
|
1124 self.running = sys.argv[0] |
|
1125 self.mainFrame = None |
|
1126 self.botframe = None |
|
1127 self.inRawMode = False |
|
1128 |
|
1129 self.fork_auto = params["autofork"] |
|
1130 self.fork_child = params["forkChild"] |
|
1131 |
|
1132 self.threads.clear() |
|
1133 self.attachThread(mainThread=True) |
|
1134 |
|
1135 # set the system exception handling function to ensure, that |
|
1136 # we report on all unhandled exceptions |
|
1137 sys.excepthook = self.__unhandled_exception |
|
1138 self.__interceptSignals() |
|
1139 |
|
1140 self.mainThread.tracePython = False |
|
1141 |
|
1142 self.debugMod.__dict__['__file__'] = sys.argv[0] |
|
1143 sys.modules['__main__'] = self.debugMod |
|
1144 res = 0 |
|
1145 code = self.__compileFileSource(self.running) |
|
1146 if code: |
|
1147 try: |
|
1148 exec(code, self.debugMod.__dict__) |
|
1149 except SystemExit as exc: |
|
1150 res = exc.code |
|
1151 atexit._run_exitfuncs() |
|
1152 self.writestream.flush() |
|
1153 self.progTerminated(res) |
|
1154 return |
|
1155 |
|
1156 if method == "RequestCoverage": |
|
1157 from coverage import coverage |
|
1158 sys.argv = [] |
|
1159 self.__setCoding(params["filename"]) |
|
1160 sys.argv.append(params["filename"]) |
|
1161 sys.argv.extend(params["argv"]) |
|
1162 sys.path = self.__getSysPath(os.path.dirname(sys.argv[0])) |
|
1163 if params["workdir"] == '': |
|
1164 os.chdir(sys.path[1]) |
|
1165 else: |
|
1166 os.chdir(params["workdir"]) |
|
1167 |
|
1168 # set the system exception handling function to ensure, that |
|
1169 # we report on all unhandled exceptions |
|
1170 sys.excepthook = self.__unhandled_exception |
|
1171 self.__interceptSignals() |
|
1172 |
|
1173 # generate a coverage object |
|
1174 self.cover = coverage( |
|
1175 auto_data=True, |
|
1176 data_file="{0}.coverage".format( |
|
1177 os.path.splitext(sys.argv[0])[0])) |
|
1178 |
|
1179 if params["erase"]: |
|
1180 self.cover.erase() |
|
1181 sys.modules['__main__'] = self.debugMod |
|
1182 self.debugMod.__dict__['__file__'] = sys.argv[0] |
|
1183 fp = open(sys.argv[0], encoding=self.__coding) |
|
1184 try: |
|
1185 script = fp.read() |
|
1186 finally: |
|
1187 fp.close() |
|
1188 if script: |
|
1189 if not script.endswith('\n'): |
|
1190 script += '\n' |
|
1191 code = compile(script, sys.argv[0], 'exec') |
|
1192 self.running = sys.argv[0] |
|
1193 res = 0 |
|
1194 self.cover.start() |
|
1195 try: |
|
1196 exec(code, self.debugMod.__dict__) |
|
1197 except SystemExit as exc: |
|
1198 res = exc.code |
|
1199 atexit._run_exitfuncs() |
|
1200 self.cover.stop() |
|
1201 self.cover.save() |
|
1202 self.writestream.flush() |
|
1203 self.progTerminated(res) |
|
1204 return |
|
1205 |
|
1206 if method == "RequestProfile": |
|
1207 sys.setprofile(None) |
|
1208 import PyProfile |
|
1209 sys.argv = [] |
|
1210 self.__setCoding(params["filename"]) |
|
1211 sys.argv.append(params["filename"]) |
|
1212 sys.argv.extend(params["argv"]) |
|
1213 sys.path = self.__getSysPath(os.path.dirname(sys.argv[0])) |
|
1214 if params["workdir"] == '': |
|
1215 os.chdir(sys.path[1]) |
|
1216 else: |
|
1217 os.chdir(params["workdir"]) |
|
1218 |
|
1219 # set the system exception handling function to ensure, that |
|
1220 # we report on all unhandled exceptions |
|
1221 sys.excepthook = self.__unhandled_exception |
|
1222 self.__interceptSignals() |
|
1223 |
|
1224 # generate a profile object |
|
1225 self.prof = PyProfile.PyProfile(sys.argv[0]) |
|
1226 |
|
1227 if params["erase"]: |
|
1228 self.prof.erase() |
|
1229 self.debugMod.__dict__['__file__'] = sys.argv[0] |
|
1230 sys.modules['__main__'] = self.debugMod |
|
1231 fp = open(sys.argv[0], encoding=self.__coding) |
|
1232 try: |
|
1233 script = fp.read() |
|
1234 finally: |
|
1235 fp.close() |
|
1236 if script: |
|
1237 if not script.endswith('\n'): |
|
1238 script += '\n' |
|
1239 self.running = sys.argv[0] |
|
1240 res = 0 |
|
1241 try: |
|
1242 self.prof.run(script) |
|
1243 except SystemExit as exc: |
|
1244 res = exc.code |
|
1245 atexit._run_exitfuncs() |
|
1246 self.prof.save() |
|
1247 self.writestream.flush() |
|
1248 self.progTerminated(res) |
|
1249 return |
|
1250 |
|
1251 if method == "ExecuteStatement": |
|
1252 if self.buffer: |
|
1253 self.buffer = self.buffer + '\n' + params["statement"] |
|
1254 else: |
|
1255 self.buffer = params["statement"] |
|
1256 |
|
1257 try: |
|
1258 code = self.compile_command(self.buffer, self.readstream.name) |
|
1259 except (OverflowError, SyntaxError, ValueError): |
|
1260 # Report the exception |
|
1261 sys.last_type, sys.last_value, sys.last_traceback = \ |
|
1262 sys.exc_info() |
|
1263 for l in traceback.format_exception_only( |
|
1264 sys.last_type, sys.last_value): |
|
1265 self.write(l) |
|
1266 self.buffer = '' |
|
1267 else: |
|
1268 if code is None: |
|
1269 self.__sendJsonCommand("ResponseContinue", {}) |
|
1270 return |
|
1271 else: |
|
1272 self.buffer = '' |
|
1273 |
|
1274 try: |
|
1275 if self.running is None: |
|
1276 exec(code, self.debugMod.__dict__) |
|
1277 else: |
|
1278 if self.currentThread is None: |
|
1279 # program has terminated |
|
1280 self.running = None |
|
1281 _globals = self.debugMod.__dict__ |
|
1282 _locals = _globals |
|
1283 else: |
|
1284 cf = self.currentThread.getCurrentFrame() |
|
1285 # program has terminated |
|
1286 if cf is None: |
|
1287 self.running = None |
|
1288 _globals = self.debugMod.__dict__ |
|
1289 _locals = _globals |
|
1290 else: |
|
1291 frmnr = self.framenr |
|
1292 while cf is not None and frmnr > 0: |
|
1293 cf = cf.f_back |
|
1294 frmnr -= 1 |
|
1295 _globals = cf.f_globals |
|
1296 _locals = \ |
|
1297 self.currentThread.getFrameLocals( |
|
1298 self.framenr) |
|
1299 # reset sys.stdout to our redirector |
|
1300 # (unconditionally) |
|
1301 if "sys" in _globals: |
|
1302 __stdout = _globals["sys"].stdout |
|
1303 _globals["sys"].stdout = self.writestream |
|
1304 exec(code, _globals, _locals) |
|
1305 _globals["sys"].stdout = __stdout |
|
1306 elif "sys" in _locals: |
|
1307 __stdout = _locals["sys"].stdout |
|
1308 _locals["sys"].stdout = self.writestream |
|
1309 exec(code, _globals, _locals) |
|
1310 _locals["sys"].stdout = __stdout |
|
1311 else: |
|
1312 exec(code, _globals, _locals) |
|
1313 |
|
1314 self.currentThread.storeFrameLocals(self.framenr) |
|
1315 except SystemExit as exc: |
|
1316 self.progTerminated(exc.code) |
|
1317 except Exception: |
|
1318 # Report the exception and the traceback |
|
1319 try: |
|
1320 exc_type, exc_value, exc_tb = sys.exc_info() |
|
1321 sys.last_type = exc_type |
|
1322 sys.last_value = exc_value |
|
1323 sys.last_traceback = exc_tb |
|
1324 tblist = traceback.extract_tb(exc_tb) |
|
1325 del tblist[:1] |
|
1326 list = traceback.format_list(tblist) |
|
1327 if list: |
|
1328 list.insert(0, "Traceback (innermost last):\n") |
|
1329 list[len(list):] = \ |
|
1330 traceback.format_exception_only( |
|
1331 exc_type, exc_value) |
|
1332 finally: |
|
1333 tblist = exc_tb = None |
|
1334 |
|
1335 for l in list: |
|
1336 self.write(l) |
|
1337 |
|
1338 self.__sendJsonCommand("ResponseOK", {}) |
|
1339 return |
|
1340 |
|
1341 if method == "RequestStep": |
|
1342 self.currentThread.step(True) |
|
1343 self.eventExit = True |
|
1344 return |
|
1345 |
|
1346 if method == "RequestStepOver": |
|
1347 self.currentThread.step(False) |
|
1348 self.eventExit = True |
|
1349 return |
|
1350 |
|
1351 if method == "RequestStepOut": |
|
1352 self.currentThread.stepOut() |
|
1353 self.eventExit = True |
|
1354 return |
|
1355 |
|
1356 if method == "RequestStepQuit": |
|
1357 if self.passive: |
|
1358 self.progTerminated(42) |
|
1359 else: |
|
1360 self.set_quit() |
|
1361 self.eventExit = True |
|
1362 return |
|
1363 |
|
1364 if method == "RequestContinue": |
|
1365 self.currentThread.go(params["special"]) |
|
1366 self.eventExit = True |
|
1367 return |
|
1368 |
|
1369 if method == "RawInput": |
|
1370 # If we are handling raw mode input then reset the mode and break out |
|
1371 # of the current event loop. |
|
1372 ## if self.inRawMode: |
|
1373 ## self.inRawMode = False |
|
1374 self.rawLine = params["input"] |
|
1375 self.eventExit = True |
1107 return |
1376 return |
1108 |
1377 |
1109 |
1378 |
1110 def __sendJsonCommand(self, command, params): |
1379 def __sendJsonCommand(self, command, params): |
1111 """ |
1380 """ |