16 import time |
16 import time |
17 from inspect import CO_GENERATOR |
17 from inspect import CO_GENERATOR |
18 |
18 |
19 from BreakpointWatch import Breakpoint, Watch |
19 from BreakpointWatch import Breakpoint, Watch |
20 |
20 |
21 if sys.version_info[0] == 2: |
21 import _thread |
22 import thread as _thread |
22 from DebugUtilities import getargvalues, formatargvalues |
23 from inspect import getargvalues, formatargvalues |
|
24 else: |
|
25 import _thread |
|
26 from DebugUtilities import getargvalues, formatargvalues |
|
27 unicode = str |
|
28 basestring = str |
|
29 |
23 |
30 gRecursionLimit = 64 |
24 gRecursionLimit = 64 |
31 |
25 |
32 |
26 |
33 def printerr(s): |
27 def printerr(s): |
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): |
619 frame.f_code.co_firstlineno] = False |
610 frame.f_code.co_firstlineno] = False |
620 return False |
611 return False |
621 lineNo = frame.f_code.co_firstlineno |
612 lineNo = frame.f_code.co_firstlineno |
622 lineNumbers = [lineNo] |
613 lineNumbers = [lineNo] |
623 |
614 |
624 if sys.version_info[0] == 2: |
615 co_lnotab = frame.f_code.co_lnotab[1::2] |
625 co_lnotab = map(ord, frame.f_code.co_lnotab[1::2]) |
|
626 else: |
|
627 co_lnotab = frame.f_code.co_lnotab[1::2] |
|
628 |
616 |
629 # No need to handle special case if a lot of lines between |
617 # No need to handle special case if a lot of lines between |
630 # (e.g. closure), because the additional lines won't cause a bp |
618 # (e.g. closure), because the additional lines won't cause a bp |
631 for co_lno in co_lnotab: |
619 for co_lno in co_lnotab: |
632 if co_lno >= 0x80: |
620 if co_lno >= 0x80: |
868 if unhandled: |
856 if unhandled: |
869 exctypetxt = "unhandled {0!s}".format(str(exctype)) |
857 exctypetxt = "unhandled {0!s}".format(str(exctype)) |
870 else: |
858 else: |
871 exctypetxt = str(exctype) |
859 exctypetxt = str(exctype) |
872 |
860 |
873 if sys.version_info[0] == 2: |
861 excvaltxt = str(excval) |
874 try: |
|
875 excvaltxt = unicode(excval).encode(self._dbgClient.getCoding()) |
|
876 except UnicodeError: |
|
877 excvaltxt = str(excval) |
|
878 else: |
|
879 excvaltxt = str(excval) |
|
880 |
862 |
881 # Don't step into libraries, which are used by our debugger methods |
863 # Don't step into libraries, which are used by our debugger methods |
882 if exctb is not None: |
864 if exctb is not None: |
883 self.stop_everywhere = False |
865 self.stop_everywhere = False |
884 |
866 |
918 type object. |
900 type object. |
919 |
901 |
920 @param exctype type of the exception |
902 @param exctype type of the exception |
921 @return exception name (string) |
903 @return exception name (string) |
922 """ |
904 """ |
923 if sys.version_info[0] == 2: |
905 return str(exctype).replace("<class '", "").replace("'>", "") |
924 if type(exctype) in [types.ClassType, # Python up to 2.4 |
|
925 types.TypeType]: # Python 2.5+ |
|
926 return exctype.__name__ |
|
927 else: |
|
928 return exctype |
|
929 else: |
|
930 return str(exctype).replace("<class '", "").replace("'>", "") |
|
931 |
906 |
932 def __extract_stack(self, exctb): |
907 def __extract_stack(self, exctb): |
933 """ |
908 """ |
934 Private member to return a list of stack frames. |
909 Private member to return a list of stack frames. |
935 |
910 |
955 """ |
930 """ |
956 exctype, excval, exctb = excinfo |
931 exctype, excval, exctb = excinfo |
957 if excval is None: |
932 if excval is None: |
958 exitcode = 0 |
933 exitcode = 0 |
959 message = "" |
934 message = "" |
960 elif isinstance(excval, basestring): |
935 elif isinstance(excval, str): |
961 exitcode = 1 |
936 exitcode = 1 |
962 message = excval |
937 message = excval |
963 elif isinstance(excval, bytes): |
938 elif isinstance(excval, bytes): |
964 exitcode = 1 |
939 exitcode = 1 |
965 message = excval.decode() |
940 message = excval.decode() |
966 elif isinstance(excval, int): |
941 elif isinstance(excval, int): |
967 exitcode = excval |
942 exitcode = excval |
968 message = "" |
943 message = "" |
969 elif isinstance(excval, SystemExit): |
944 elif isinstance(excval, SystemExit): |
970 code = excval.code |
945 code = excval.code |
971 if isinstance(code, basestring): |
946 if isinstance(code, str): |
972 exitcode = 1 |
947 exitcode = 1 |
973 message = code |
948 message = code |
974 elif isinstance(code, bytes): |
949 elif isinstance(code, bytes): |
975 exitcode = 1 |
950 exitcode = 1 |
976 message = code.decode() |
951 message = code.decode() |