167 try: |
161 try: |
168 if "__pypy__" in sys.builtin_module_names: |
162 if "__pypy__" in sys.builtin_module_names: |
169 import __pypy__ |
163 import __pypy__ |
170 __pypy__.locals_to_fast(cf) |
164 __pypy__.locals_to_fast(cf) |
171 return |
165 return |
172 except Exception: |
166 except Exception: # secok |
173 pass |
167 pass |
174 |
168 |
175 ctypes.pythonapi.PyFrame_LocalsToFast( |
169 ctypes.pythonapi.PyFrame_LocalsToFast( |
176 ctypes.py_object(cf), |
170 ctypes.py_object(cf), |
177 ctypes.c_int(0)) |
171 ctypes.c_int(0)) |
381 @type frame object |
375 @type frame object |
382 """ |
376 """ |
383 if frame is None: |
377 if frame is None: |
384 frame = sys._getframe().f_back # Skip set_trace method |
378 frame = sys._getframe().f_back # Skip set_trace method |
385 |
379 |
386 if sys.version_info[0] == 2: |
380 stopOnHandleCommand = self._dbgClient.handleJsonCommand.__code__ |
387 stopOnHandleCommand = self._dbgClient.handleJsonCommand.func_code |
|
388 else: |
|
389 stopOnHandleCommand = self._dbgClient.handleJsonCommand.__code__ |
|
390 |
381 |
391 frame.f_trace = self.trace_dispatch |
382 frame.f_trace = self.trace_dispatch |
392 while frame.f_back is not None: |
383 while frame.f_back is not None: |
393 # stop at eric's debugger frame or a threading bootstrap |
384 # stop at eric's debugger frame or a threading bootstrap |
394 if (frame.f_back.f_code == stopOnHandleCommand): |
385 if (frame.f_back.f_code == stopOnHandleCommand): |
459 # function call. This is ensured by setting stop_everywhere. |
450 # function call. This is ensured by setting stop_everywhere. |
460 self.stop_everywhere = True |
451 self.stop_everywhere = True |
461 sys.settrace(self.trace_dispatch) |
452 sys.settrace(self.trace_dispatch) |
462 |
453 |
463 try: |
454 try: |
464 exec(cmd, globalsDict, localsDict) |
455 exec(cmd, globalsDict, localsDict) # secok |
465 atexit._run_exitfuncs() |
456 atexit._run_exitfuncs() |
466 self._dbgClient.progTerminated(0) |
457 self._dbgClient.progTerminated(0) |
467 exitcode = 0 |
458 exitcode = 0 |
468 except SystemExit: |
459 except SystemExit: |
469 atexit._run_exitfuncs() |
460 atexit._run_exitfuncs() |
624 frame.f_code.co_firstlineno] = False |
615 frame.f_code.co_firstlineno] = False |
625 return False |
616 return False |
626 lineNo = frame.f_code.co_firstlineno |
617 lineNo = frame.f_code.co_firstlineno |
627 lineNumbers = [lineNo] |
618 lineNumbers = [lineNo] |
628 |
619 |
629 if sys.version_info[0] == 2: |
620 co_lnotab = frame.f_code.co_lnotab[1::2] |
630 co_lnotab = map(ord, frame.f_code.co_lnotab[1::2]) |
|
631 else: |
|
632 co_lnotab = frame.f_code.co_lnotab[1::2] |
|
633 |
621 |
634 # No need to handle special case if a lot of lines between |
622 # No need to handle special case if a lot of lines between |
635 # (e.g. closure), because the additional lines won't cause a bp |
623 # (e.g. closure), because the additional lines won't cause a bp |
636 for co_lno in co_lnotab: |
624 for co_lno in co_lnotab: |
637 if co_lno >= 0x80: |
625 if co_lno >= 0x80: |
814 # ignore these |
802 # ignore these |
815 return |
803 return |
816 |
804 |
817 if exctype in [SyntaxError, IndentationError]: |
805 if exctype in [SyntaxError, IndentationError]: |
818 try: |
806 try: |
819 # tuple could only occure on Python 2, but not always! |
|
820 if type(excval) == tuple: |
807 if type(excval) == tuple: |
821 message, details = excval |
808 message, details = excval |
822 filename, lineno, charno, text = details |
809 filename, lineno, charno, text = details |
823 else: |
810 else: |
824 message = excval.msg |
811 message = excval.msg |
875 if unhandled: |
862 if unhandled: |
876 exctypetxt = "unhandled {0!s}".format(str(exctype)) |
863 exctypetxt = "unhandled {0!s}".format(str(exctype)) |
877 else: |
864 else: |
878 exctypetxt = str(exctype) |
865 exctypetxt = str(exctype) |
879 |
866 |
880 if sys.version_info[0] == 2: |
867 excvaltxt = str(excval) |
881 try: |
|
882 excvaltxt = unicode(excval).encode(self._dbgClient.getCoding()) |
|
883 except UnicodeError: |
|
884 excvaltxt = str(excval) |
|
885 else: |
|
886 excvaltxt = str(excval) |
|
887 |
868 |
888 # Don't step into libraries, which are used by our debugger methods |
869 # Don't step into libraries, which are used by our debugger methods |
889 if exctb is not None: |
870 if exctb is not None: |
890 self.stop_everywhere = False |
871 self.stop_everywhere = False |
891 |
872 |
929 type object. |
910 type object. |
930 |
911 |
931 @param exctype type of the exception |
912 @param exctype type of the exception |
932 @return exception name (string) |
913 @return exception name (string) |
933 """ |
914 """ |
934 if sys.version_info[0] == 2: |
915 return str(exctype).replace("<class '", "").replace("'>", "") |
935 if type(exctype) in [types.ClassType, # Python up to 2.4 |
|
936 types.TypeType]: # Python 2.5+ |
|
937 return exctype.__name__ |
|
938 else: |
|
939 return exctype |
|
940 else: |
|
941 return exctype.__name__ |
|
942 |
916 |
943 def __extract_stack(self, exctb): |
917 def __extract_stack(self, exctb): |
944 """ |
918 """ |
945 Private member to return a list of stack frames. |
919 Private member to return a list of stack frames. |
946 |
920 |
966 """ |
940 """ |
967 exctype, excval, exctb = excinfo |
941 exctype, excval, exctb = excinfo |
968 if excval is None: |
942 if excval is None: |
969 exitcode = 0 |
943 exitcode = 0 |
970 message = "" |
944 message = "" |
971 elif isinstance(excval, basestring): |
945 elif isinstance(excval, str): |
972 exitcode = 1 |
946 exitcode = 1 |
973 message = excval |
947 message = excval |
974 elif isinstance(excval, bytes): |
948 elif isinstance(excval, bytes): |
975 exitcode = 1 |
949 exitcode = 1 |
976 message = excval.decode() |
950 message = excval.decode() |
977 elif isinstance(excval, int): |
951 elif isinstance(excval, int): |
978 exitcode = excval |
952 exitcode = excval |
979 message = "" |
953 message = "" |
980 elif isinstance(excval, SystemExit): |
954 elif isinstance(excval, SystemExit): |
981 code = excval.code |
955 code = excval.code |
982 if isinstance(code, basestring): |
956 if isinstance(code, str): |
983 exitcode = 1 |
957 exitcode = 1 |
984 message = code |
958 message = code |
985 elif isinstance(code, bytes): |
959 elif isinstance(code, bytes): |
986 exitcode = 1 |
960 exitcode = 1 |
987 message = code.decode() |
961 message = code.decode() |