Sun, 19 Feb 2017 22:13:48 +0100
Improved atexit handling.
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

1  # * coding: utf8 * 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

2  
5389
9b1c800daff3
Updated copyright for 2017.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5287
diff
changeset

3  # Copyright (c) 2002  2017 Detlev Offenbach <detlev@dieoffenbachs.de> 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

4  # 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

5  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

6  """ 
5087
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

7  Module implementing the debug base class which based originally on bdb. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

8  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

9  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

10  import sys 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

11  import os 
5179
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

12  import types 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

13  import atexit 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

14  import inspect 
4642
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

15  import ctypes 
5044
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

16  import time 
4365
d97f2e05ae1b
Enhanced the Python3 debugger a little bit in accordance with bdb.py.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4309
diff
changeset

17  from inspect import CO_GENERATOR 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

18  
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

19  from BreakpointWatch import Breakpoint, Watch 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

20  
5179
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

21  if sys.version_info[0] == 2: 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

22  import thread as _thread 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

23  from inspect import getargvalues, formatargvalues 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

24  else: 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

25  import _thread 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

26  from DebugUtilities import getargvalues, formatargvalues 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

27  unicode = str 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

28  basestring = str 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

29  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

30  gRecursionLimit = 64 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

31  
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
935
diff
changeset

32  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

33  def printerr(s): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

34  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

35  Module function used for debugging the debug client. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

36  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

37  @param s data to be printed 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

38  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

39  sys.__stderr__.write('{0!s}\n'.format(s)) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

40  sys.__stderr__.flush() 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

41  
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
935
diff
changeset

42  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

43  def setRecursionLimit(limit): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

44  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

45  Module function to set the recursion limit. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

46  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

47  @param limit recursion limit (integer) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

48  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

49  global gRecursionLimit 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

50  gRecursionLimit = limit 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

51  
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
935
diff
changeset

52  
5087
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

53  class DebugBase(object): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

54  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

55  Class implementing base class of the debugger. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

56  
5087
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

57  Provides methods for the 'owning' client to call to step etc. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

58  """ 
5005
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

59  # Don't thrust distutils.sysconfig.get_python_lib: possible case mismatch 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

60  # on Windows 
5087
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

61  lib = os.path.dirname(inspect.__file__) 
5005
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

62  # tuple required because it's accessed a lot of times by startswith method 
5087
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

63  pathsToSkip = ('<', os.path.dirname(__file__), inspect.__file__[:1]) 
5005
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

64  filesToSkip = {} 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

65  
5007
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

66  # cache for fixed file names 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

67  _fnCache = {} 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

68  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

69  def __init__(self, dbgClient): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

70  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

71  Constructor 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

72  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

73  @param dbgClient the owning client 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

74  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

75  self._dbgClient = dbgClient 
5179
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

76  
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

77  # Some informations about the thread 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

78  self.isMainThread = False 
5206
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

79  self.quitting = False 
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset

80  self.id = 1 
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset

81  self.name = '' 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

82  
5005
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

83  self.tracePythonLibs(0) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

84  
5050
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

85  # Special handling of a recursion error 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

86  self.skipFrames = 0 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

87  
5206
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

88  self.isBroken = False 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

89  self.cFrame = None 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

90  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

91  # current frame we are at 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

92  self.currentFrame = None 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

93  
5206
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

94  # frames, where we want to stop or release debugger 
5085
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

95  self.botframe = None 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

96  self.stopframe = None 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

97  self.returnframe = None 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

98  self.stop_everywhere = False 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

99  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

100  self.__recursionDepth = 1 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

101  self.setRecursionDepth(inspect.currentframe()) 
5044
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

102  
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

103  # background task to periodicaly check for client interactions 
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

104  self.eventPollFlag = False 
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

105  self.timer = _thread.start_new_thread(self.__eventPollTimer, ()) 
5273
be55746da9d1
Wrong frames when running in sys.breakpoint fixed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5263
diff
changeset

106  
be55746da9d1
Wrong frames when running in sys.breakpoint fixed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5263
diff
changeset

107  # provide a hook to perform a hard breakpoint 
be55746da9d1
Wrong frames when running in sys.breakpoint fixed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5263
diff
changeset

108  # Use it like this: 
be55746da9d1
Wrong frames when running in sys.breakpoint fixed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5263
diff
changeset

109  # if hasattr(sys, 'breakpoint): sys.breakpoint() 
be55746da9d1
Wrong frames when running in sys.breakpoint fixed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5263
diff
changeset

110  sys.breakpoint = self.set_trace 
5044
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

111  
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

112  def __eventPollTimer(self): 
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

113  """ 
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

114  Private method to set a flag every 0.5 s to check for new messages. 
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

115  """ 
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

116  while True: 
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

117  time.sleep(0.5) 
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

118  self.eventPollFlag = True 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

119  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

120  def getCurrentFrame(self): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

121  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

122  Public method to return the current frame. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

123  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

124  @return the current frame 
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset

125  @rtype frame object 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

126  """ 
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset

127  # Don't show any local frames after the program was stopped 
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset

128  if self.quitting: 
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset

129  return None 
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset

130  
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
935
diff
changeset

131  return self.currentFrame 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

132  
4309
cc9c62f55413
Changed the Python debugger backends to evaluate statements entered into the shell in the frame selected in the local variables viewer.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4293
diff
changeset

133  def getFrameLocals(self, frmnr=0): 
935
bf9ee1e00bc5
Fixed an issue in the Python debuggers related to the usage of the locals dictionary.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
826
diff
changeset

134  """ 
4309
cc9c62f55413
Changed the Python debugger backends to evaluate statements entered into the shell in the frame selected in the local variables viewer.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4293
diff
changeset

135  Public method to return the locals dictionary of the current frame 
cc9c62f55413
Changed the Python debugger backends to evaluate statements entered into the shell in the frame selected in the local variables viewer.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4293
diff
changeset

136  or a frame below. 
935
bf9ee1e00bc5
Fixed an issue in the Python debuggers related to the usage of the locals dictionary.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
826
diff
changeset

137  
4309
cc9c62f55413
Changed the Python debugger backends to evaluate statements entered into the shell in the frame selected in the local variables viewer.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4293
diff
changeset

138  @keyparam frmnr distance of frame to get locals dictionary of. 0 is 
cc9c62f55413
Changed the Python debugger backends to evaluate statements entered into the shell in the frame selected in the local variables viewer.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4293
diff
changeset

139  the current frame (int) 
cc9c62f55413
Changed the Python debugger backends to evaluate statements entered into the shell in the frame selected in the local variables viewer.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4293
diff
changeset

140  @return locals dictionary of the frame 
935
bf9ee1e00bc5
Fixed an issue in the Python debuggers related to the usage of the locals dictionary.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
826
diff
changeset

141  """ 
4642
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

142  f = self.currentFrame 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

143  while f is not None and frmnr > 0: 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

144  f = f.f_back 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

145  frmnr = 1 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

146  return f.f_locals 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

147  
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

148  def storeFrameLocals(self, frmnr=0): 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

149  """ 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

150  Public method to store the locals into the frame, so an access to 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

151  frame.f_locals returns the last data. 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

152  
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

153  @keyparam frmnr distance of frame to store locals dictionary to. 0 is 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

154  the current frame (int) 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

155  """ 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

156  cf = self.currentFrame 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

157  while cf is not None and frmnr > 0: 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

158  cf = cf.f_back 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

159  frmnr = 1 
5156
5cb4740bd2a9
Little addition to the debuggers to make them more compatible with PyPy.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5140
diff
changeset

160  
5cb4740bd2a9
Little addition to the debuggers to make them more compatible with PyPy.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5140
diff
changeset

161  try: 
5cb4740bd2a9
Little addition to the debuggers to make them more compatible with PyPy.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5140
diff
changeset

162  if "__pypy__" in sys.builtin_module_names: 
5cb4740bd2a9
Little addition to the debuggers to make them more compatible with PyPy.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5140
diff
changeset

163  import __pypy__ 
5cb4740bd2a9
Little addition to the debuggers to make them more compatible with PyPy.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5140
diff
changeset

164  __pypy__.locals_to_fast(cf) 
5cb4740bd2a9
Little addition to the debuggers to make them more compatible with PyPy.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5140
diff
changeset

165  return 
5cb4740bd2a9
Little addition to the debuggers to make them more compatible with PyPy.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5140
diff
changeset

166  except Exception: 
5cb4740bd2a9
Little addition to the debuggers to make them more compatible with PyPy.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5140
diff
changeset

167  pass 
5cb4740bd2a9
Little addition to the debuggers to make them more compatible with PyPy.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5140
diff
changeset

168  
4642
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

169  ctypes.pythonapi.PyFrame_LocalsToFast( 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

170  ctypes.py_object(cf), 
f18d5fb9a53b
Store values entered into the shell in selected frame.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4631
diff
changeset

171  ctypes.c_int(0)) 
935
bf9ee1e00bc5
Fixed an issue in the Python debuggers related to the usage of the locals dictionary.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
826
diff
changeset

172  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

173  def step(self, traceMode): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

174  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

175  Public method to perform a step operation in this thread. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

176  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

177  @param traceMode If it is True, then the step is a step into, 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

178  otherwise it is a step over. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

179  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

180  if traceMode: 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

181  self.set_step() 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

182  else: 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

183  self.set_next(self.currentFrame) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

184  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

185  def stepOut(self): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

186  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

187  Public method to perform a step out of the current call. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

188  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

189  self.set_return(self.currentFrame) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

190  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

191  def go(self, special): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

192  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

193  Public method to resume the thread. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

194  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

195  It resumes the thread stopping only at breakpoints or exceptions. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

196  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

197  @param special flag indicating a special continue operation 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

198  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

199  self.set_continue(special) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

200  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

201  def setRecursionDepth(self, frame): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

202  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

203  Public method to determine the current recursion depth. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

204  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

205  @param frame The current stack frame. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

206  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

207  self.__recursionDepth = 0 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

208  while frame is not None: 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

209  self.__recursionDepth += 1 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

210  frame = frame.f_back 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

211  
5046
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

212  def profileWithRecursion(self, frame, event, arg): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

213  """ 
2166
15b4e58d61d7
Fixed some typos in source docu.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1509
diff
changeset

214  Public method used to trace some stuff independent of the debugger 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

215  trace function. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

216  
5046
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

217  @param frame current stack frame 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

218  @type frame object 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

219  @param event trace event 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

220  @type str 
2953
703452a2876f
Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2927
diff
changeset

221  @param arg arguments 
5046
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

222  @type depends on the previous event parameter 
2953
703452a2876f
Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2927
diff
changeset

223  @exception RuntimeError raised to indicate too many recursions 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

224  """ 
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
935
diff
changeset

225  if event == 'return': 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

226  self.cFrame = frame.f_back 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

227  self.__recursionDepth = 1 
5046
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

228  if self._dbgClient.callTraceEnabled: 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

229  self.__sendCallTrace(event, frame, self.cFrame) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

230  elif event == 'call': 
5046
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

231  if self._dbgClient.callTraceEnabled: 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

232  self.__sendCallTrace(event, self.cFrame, frame) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

233  self.cFrame = frame 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

234  self.__recursionDepth += 1 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

235  if self.__recursionDepth > gRecursionLimit: 
3021
801289962f4e
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2987
diff
changeset

236  raise RuntimeError( 
801289962f4e
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2987
diff
changeset

237  'maximum recursion depth exceeded\n' 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

238  '(offending frame is two down the stack)') 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

239  
5046
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

240  def profile(self, frame, event, arg): 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

241  """ 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

242  Public method used to trace some stuff independent of the debugger 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

243  trace function. 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

244  
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

245  @param frame current stack frame 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

246  @type frame object 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

247  @param event trace event 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

248  @type str 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

249  @param arg arguments 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

250  @type depends on the previous event parameter 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

251  """ 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

252  if event == 'return': 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

253  self.__sendCallTrace(event, frame, frame.f_back) 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

254  elif event == 'call': 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

255  self.__sendCallTrace(event, frame.f_back, frame) 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

256  
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2166
diff
changeset

257  def __sendCallTrace(self, event, fromFrame, toFrame): 
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2166
diff
changeset

258  """ 
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2166
diff
changeset

259  Private method to send a call/return trace. 
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2166
diff
changeset

260  
5046
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

261  @param event trace event 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

262  @type str 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

263  @param fromFrame originating frame 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

264  @type frame object 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

265  @param toFrame destination frame 
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

266  @type frame object 
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2166
diff
changeset

267  """ 
5046
d57f18f15f1a
Don't track the recursion limit by hand.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5045
diff
changeset

268  if not self.__skipFrame(fromFrame) and not self.__skipFrame(toFrame): 
5174  269  fromInfo = { 
270  "filename": self._dbgClient.absPath(  
271  self.fix_frame_filename(fromFrame)),  
272  "linenumber": fromFrame.f_lineno,  
273  "codename": fromFrame.f_code.co_name,  
274  }  
275  toInfo = {  
276  "filename": self._dbgClient.absPath(  
277  self.fix_frame_filename(toFrame)),  
278  "linenumber": toFrame.f_lineno,  
279  "codename": toFrame.f_code.co_name,  
280  }  
281  self._dbgClient.sendCallTrace(event, fromInfo, toInfo)  
2170
f4e0f6133ace
Started implementing the call trace functionality.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2166
diff
changeset

282  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

283  def trace_dispatch(self, frame, event, arg): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

284  """ 
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3160
diff
changeset

285  Public method reimplemented from bdb.py to do some special things. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

286  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

287  This specialty is to check the connection to the debug server 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

288  for new events (i.e. new breakpoints) while we are going through 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

289  the code. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

290  
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

291  @param frame The current stack frame 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

292  @type frame object 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

293  @param event The trace event 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

294  @type str 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

295  @param arg The arguments 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

296  @type depends on the previous event parameter 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

297  @return local trace function 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

298  @rtype trace function or None 
5084
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

299  @exception SystemExit 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

300  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

301  # give the client a chance to push through new break points. 
5044
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

302  if self.eventPollFlag: 
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

303  self._dbgClient.eventPoll() 
630b9f290a77
No polling of incoming messages. Just wait for a flag.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5041
diff
changeset

304  self.eventPollFlag = False 
5083
4affedf129c5
Don't check the quitting flag after each operation.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5064
diff
changeset

305  
4affedf129c5
Don't check the quitting flag after each operation.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5064
diff
changeset

306  if self.quitting: 
5084
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

307  raise SystemExit 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

308  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

309  if event == 'line': 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

310  if self.stop_here(frame) or self.break_here(frame): 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

311  self.user_line(frame) 
5263
50a03ff54b15
Make PyPy stop at breakpoints again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5239
diff
changeset

312  return self.trace_dispatch 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

313  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

314  if event == 'call': 
5417
3458d1c8c5fc
Fixed a subtle bug in the debugger client causing it to exit, if the first line is an import statement.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5389
diff
changeset

315  if self.botframe is None and frame.f_lineno >= 1: 
5205
df1709f0e49f
Change evaluation of last frame to run atexit functions again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5204
diff
changeset

316  self.botframe = frame 
5085
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

317  frame.f_trace = self.trace_dispatch 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

318  
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

319  self.user_line(frame) 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

320  return self.trace_dispatch 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

321  
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

322  if not (self.stop_here(frame) or 
5045
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

323  self.__checkBreakInFrame(frame) or 
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

324  Watch.watches != []): 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

325  # No need to trace this function 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

326  return 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

327  return self.trace_dispatch 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

328  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

329  if event == 'return': 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

330  return 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

331  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

332  if event == 'exception': 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

333  if not self.__skipFrame(frame): 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

334  # When stepping with next/until/return in a generator frame, 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

335  # skip the internal StopIteration exception (with no traceback) 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

336  # triggered by a subiterator run with the 'yield from' 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

337  # statement. 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

338  if not (frame.f_code.co_flags & CO_GENERATOR and 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

339  arg[0] is StopIteration and arg[2] is None): 
5536
d28e800f2810
Remove obsolete parameter 'frame' at user_exception function.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5417
diff
changeset

340  self.user_exception(arg) 
5048
9899fb545b1f
Fixed some code style issues and removed the obsolete method shouldSkip.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5046
diff
changeset

341  # Stop at the StopIteration or GeneratorExit exception when the 
9899fb545b1f
Fixed some code style issues and removed the obsolete method shouldSkip.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5046
diff
changeset

342  # user has set stopframe in a generator by issuing a return 
9899fb545b1f
Fixed some code style issues and removed the obsolete method shouldSkip.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5046
diff
changeset

343  # command, or a next/until command at the last statement in the 
9899fb545b1f
Fixed some code style issues and removed the obsolete method shouldSkip.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5046
diff
changeset

344  # generator before the exception. 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

345  elif (self.stopframe and frame is not self.stopframe and 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

346  self.stopframe.f_code.co_flags & CO_GENERATOR and 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

347  arg[0] in (StopIteration, GeneratorExit)): 
5536
d28e800f2810
Remove obsolete parameter 'frame' at user_exception function.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5417
diff
changeset

348  self.user_exception(arg) 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

349  return 
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

350  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

351  if event == 'c_call': 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

352  return 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

353  if event == 'c_exception': 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

354  return 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

355  if event == 'c_return': 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

356  return 
5174  357  
5128
b6cbdba69967
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5125
diff
changeset

358  print('DebugBase.trace_dispatch:' # __IGNORE_WARNING__ 
b6cbdba69967
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5125
diff
changeset

359  ' unknown debugging event: ', 
5125
eb1b3e0577e4
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5124
diff
changeset

360  repr(event)) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

361  return self.trace_dispatch 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

362  
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
935
diff
changeset

363  def set_trace(self, frame=None): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

364  """ 
5064
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

365  Public method to start debugging from 'frame'. 
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

366  
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

367  If frame is not specified, debugging starts from caller's frame. 
5086
6cb8be573090
New set_trace for sys.breakpoint to reflect the changes in previous commit.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5085
diff
changeset

368  Because of jump optimizations it's not possible to use sys.breakpoint() 
6cb8be573090
New set_trace for sys.breakpoint to reflect the changes in previous commit.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5085
diff
changeset

369  as last instruction in a function or method. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

370  
5086
6cb8be573090
New set_trace for sys.breakpoint to reflect the changes in previous commit.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5085
diff
changeset

371  @keyparam frame frame to start debugging from 
5064
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

372  @type frame object 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

373  """ 
5064
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

374  if frame is None: 
5086
6cb8be573090
New set_trace for sys.breakpoint to reflect the changes in previous commit.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5085
diff
changeset

375  frame = sys._getframe().f_back # Skip set_trace method 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

376  
5206
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

377  if sys.version_info[0] == 2: 
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

378  stopOnHandleLine = self._dbgClient.handleLine.func_code 
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

379  else: 
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

380  stopOnHandleLine = self._dbgClient.handleLine.__code__ 
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

381  
5086
6cb8be573090
New set_trace for sys.breakpoint to reflect the changes in previous commit.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5085
diff
changeset

382  frame.f_trace = self.trace_dispatch 
5274
a19743a4a8fa
Easier and fail save way to get the correct botframe at sys.breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5273
diff
changeset

383  while frame.f_back is not None: 
a19743a4a8fa
Easier and fail save way to get the correct botframe at sys.breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5273
diff
changeset

384  # stop at erics debugger frame or a threading bootstrap 
a19743a4a8fa
Easier and fail save way to get the correct botframe at sys.breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5273
diff
changeset

385  if (frame.f_back.f_code == stopOnHandleLine): 
5064
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

386  frame.f_trace = self.trace_dispatch 
5086
6cb8be573090
New set_trace for sys.breakpoint to reflect the changes in previous commit.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5085
diff
changeset

387  self.botframe = frame 
6cb8be573090
New set_trace for sys.breakpoint to reflect the changes in previous commit.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5085
diff
changeset

388  break 
6cb8be573090
New set_trace for sys.breakpoint to reflect the changes in previous commit.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5085
diff
changeset

389  
5064
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

390  frame = frame.f_back 
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

391  
5086
6cb8be573090
New set_trace for sys.breakpoint to reflect the changes in previous commit.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5085
diff
changeset

392  self.stop_everywhere = True 
5064
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

393  sys.settrace(self.trace_dispatch) 
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

394  sys.setprofile(self._dbgClient.callTraceEnabled) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

395  
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

396  def bootstrap(self, target, args, kwargs): 
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5206
diff
changeset

397  """ 
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

398  Public method to bootstrap a thread. 
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5206
diff
changeset

399  
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5206
diff
changeset

400  It wraps the call to the user function to enable tracing 
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5206
diff
changeset

401  before hand. 
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

402  
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

403  @param target function which is called in the new created thread 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

404  @type function pointer 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

405  @param args arguments to pass to target 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

406  @type tuple 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

407  @param kwargs keyword arguments to pass to target 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

408  @type dict 
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5206
diff
changeset

409  """ 
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5206
diff
changeset

410  try: 
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

411  frame = sys._getframe() 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

412  self.botframe = frame 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

413  # First time the dispach function is called, a "base debug" 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

414  # function has to be returned, which is called at every user code 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

415  # function call. Because of setting botframe manually, the 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

416  # specific branch returning the trace_dispatch itself is skipped. 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

417  # Because the next step is always in threading.py and we assume 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

418  # that there is no breakpoint in it, it's save to return 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

419  # trace_dispatch unconditionally. 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

420  sys.settrace(lambda frame, event, arg: self.trace_dispatch) 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

421  frame.f_trace = self.trace_dispatch 
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

422  
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset

423  target(*args, **kwargs) 
5538
d6de2206af1e
Handling of unhandled exceptions restored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5537
diff
changeset

424  except Exception: 
d6de2206af1e
Handling of unhandled exceptions restored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5537
diff
changeset

425  excinfo = sys.exc_info() 
d6de2206af1e
Handling of unhandled exceptions restored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5537
diff
changeset

426  self.user_exception(excinfo, True) 
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5206
diff
changeset

427  finally: 
5538
d6de2206af1e
Handling of unhandled exceptions restored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5537
diff
changeset

428  sys.settrace(None) 
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5206
diff
changeset

429  sys.setprofile(None) 
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5206
diff
changeset

430  
5540
40992b7a60a9
Improved atexit handling.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5539
diff
changeset

431  def run(self, cmd, globals=None, locals=None, debug=True): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

432  """ 
5084
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

433  Public method to start a given command under debugger control. 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

434  
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

435  @param cmd command / code to execute under debugger control 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

436  @type str or CodeType 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

437  @keyparam globals dictionary of global variables for cmd 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

438  @type dict 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

439  @keyparam locals dictionary of local variables for cmd 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

440  @type dict 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

441  """ 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

442  if globals is None: 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

443  import __main__ 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

444  globals = __main__.__dict__ 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

445  
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

446  if locals is None: 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

447  locals = globals 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

448  
5179
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

449  if not isinstance(cmd, types.CodeType): 
5084
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

450  cmd = compile(cmd, "<string>", "exec") 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

451  
5540
40992b7a60a9
Improved atexit handling.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5539
diff
changeset

452  if debug: 
40992b7a60a9
Improved atexit handling.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5539
diff
changeset

453  sys.settrace(self.trace_dispatch) 
40992b7a60a9
Improved atexit handling.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5539
diff
changeset

454  
5084
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

455  try: 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

456  exec(cmd, globals, locals) 
5537
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

457  atexit._run_exitfuncs() 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

458  self._dbgClient.progTerminated(0) 
5084
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

459  except SystemExit: 
5537
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

460  atexit._run_exitfuncs() 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

461  excinfo = sys.exc_info() 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

462  exitcode, message = self.__extractSystemExitMessage(excinfo) 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

463  self._dbgClient.progTerminated(exitcode, message) 
5538
d6de2206af1e
Handling of unhandled exceptions restored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5537
diff
changeset

464  except Exception: 
d6de2206af1e
Handling of unhandled exceptions restored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5537
diff
changeset

465  excinfo = sys.exc_info() 
d6de2206af1e
Handling of unhandled exceptions restored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5537
diff
changeset

466  self.user_exception(excinfo, True) 
5084
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

467  finally: 
5206
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

468  self.quitting = True 
5084
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

469  sys.settrace(None) 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

470  
5085
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

471  def _set_stopinfo(self, stopframe, returnframe): 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

472  """ 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

473  Protected method to update the frame pointers. 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

474  
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

475  @param stopframe the frame object where to stop 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

476  @type frame object 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

477  @param returnframe the frame object where to stop on a function return 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

478  @type frame object 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

479  """ 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

480  self.stopframe = stopframe 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

481  self.returnframe = returnframe 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

482  self.stop_everywhere = False 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

483  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

484  def set_continue(self, special): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

485  """ 
5085
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

486  Public method to stop only on next breakpoint. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

487  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

488  @param special flag indicating a special continue operation 
5085
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

489  @type bool 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

490  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

491  # Here we only set a new stop frame if it is a normal continue. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

492  if not special: 
5205
df1709f0e49f
Change evaluation of last frame to run atexit functions again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5204
diff
changeset

493  self._set_stopinfo(None, None) 
5085
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

494  
5064
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

495  # Disable tracing if not started in debug mode 
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

496  if not self._dbgClient.debugging: 
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

497  sys.settrace(None) 
9f4e3914e50c
Improvements on eric's set_trace and set_continue if not in debugging mode.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5063
diff
changeset

498  sys.setprofile(None) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

499  
5085
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

500  def set_step(self): 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

501  """ 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

502  Public method to stop after one line of code. 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

503  """ 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

504  self._set_stopinfo(None, None) 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

505  self.stop_everywhere = True 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

506  
5087
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

507  def set_next(self, frame): 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

508  """ 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

509  Public method to stop on the next line in or below the given frame. 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

510  
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

511  @param frame the frame object 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

512  @type frame object 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

513  """ 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

514  self._set_stopinfo(frame, frame.f_back) 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

515  frame.f_back.f_trace = self.trace_dispatch 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

516  frame.f_trace = self.trace_dispatch 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

517  
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

518  def set_return(self, frame): 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

519  """ 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

520  Public method to stop when returning from the given frame. 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

521  
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

522  @param frame the frame object 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

523  @type frame object 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

524  """ 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

525  self._set_stopinfo(None, frame.f_back) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

526  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

527  def set_quit(self): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

528  """ 
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
935
diff
changeset

529  Public method to quit. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

530  
5087
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

531  Disables the trace functions and resets all frame pointer. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

532  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

533  sys.setprofile(None) 
5087
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

534  self.stopframe = None 
59316f14216b
Not much left of bdb, so removed it entirely.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5086
diff
changeset

535  self.returnframe = None 
5287
971f24c89e6b
Restore normal stop functionality (F10).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5274
diff
changeset

536  for debugThread in self._dbgClient.threads.values(): 
971f24c89e6b
Restore normal stop functionality (F10).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5274
diff
changeset

537  debugThread.quitting = True 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

538  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

539  def fix_frame_filename(self, frame): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

540  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

541  Public method used to fixup the filename for a given frame. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

542  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

543  The logic employed here is that if a module was loaded 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

544  from a .pyc file, then the correct .py to operate with 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

545  should be in the same path as the .pyc. The reason this 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

546  logic is needed is that when a .pyc file is generated, the 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

547  filename embedded and thus what is readable in the code object 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

548  of the frame object is the fully qualified filepath when the 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

549  pyc is generated. If files are moved from machine to machine 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

550  this can break debugging as the .pyc will refer to the .py 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

551  on the original machine. Another case might be sharing 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

552  code over a network... This logic deals with that. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

553  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

554  @param frame the frame object 
5007
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

555  @type frame object 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

556  @return fixed up file name 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

557  @rtype str 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

558  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

559  # get module name from __file__ 
5007
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

560  fn = frame.f_globals.get('__file__') 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

561  try: 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

562  return self._fnCache[fn] 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

563  except KeyError: 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

564  if fn and fn != frame.f_code.co_filename: 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

565  absFilename = os.path.abspath(fn) 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

566  if absFilename.endswith(('.pyc', '.pyo')): 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

567  fixedName = absFilename[:1] 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

568  if not os.path.exists(fixedName): 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

569  fixedName = absFilename 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

570  else: 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

571  fixedName = absFilename 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

572  else: 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

573  fixedName = frame.f_code.co_filename 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

574  # update cache 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

575  self._fnCache[fn] = fixedName 
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

576  return fixedName 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

577  
5045
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

578  def __checkBreakInFrame(self, frame): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

579  """ 
5045
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

580  Private method to check if the function / method has a line number 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

581  which is a breakpoint. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

582  
5045
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

583  @param frame the frame object 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

584  @type frame object 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

585  @return Flag indicating a function / method with breakpoint 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

586  @rtype bool 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

587  """ 
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
935
diff
changeset

588  try: 
5045
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

589  return Breakpoint.breakInFrameCache[ 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

590  frame.f_globals.get('__file__'), 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

591  frame.f_code.co_firstlineno] 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

592  except KeyError: 
5045
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

593  filename = self.fix_frame_filename(frame) 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

594  if filename not in Breakpoint.breakInFile: 
5048
9899fb545b1f
Fixed some code style issues and removed the obsolete method shouldSkip.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5046
diff
changeset

595  Breakpoint.breakInFrameCache[ 
9899fb545b1f
Fixed some code style issues and removed the obsolete method shouldSkip.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5046
diff
changeset

596  frame.f_globals.get('__file__'), 
5045
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

597  frame.f_code.co_firstlineno] = False 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

598  return False 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

599  lineNo = frame.f_code.co_firstlineno 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

600  lineNumbers = [lineNo] 
5203
6f876aca1c34
Changed calculation of line numbers in a function to work properly on Python 3.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5183
diff
changeset

601  
6f876aca1c34
Changed calculation of line numbers in a function to work properly on Python 3.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5183
diff
changeset

602  if sys.version_info[0] == 2: 
6f876aca1c34
Changed calculation of line numbers in a function to work properly on Python 3.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5183
diff
changeset

603  co_lnotab = map(ord, frame.f_code.co_lnotab[1::2]) 
6f876aca1c34
Changed calculation of line numbers in a function to work properly on Python 3.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5183
diff
changeset

604  else: 
6f876aca1c34
Changed calculation of line numbers in a function to work properly on Python 3.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5183
diff
changeset

605  co_lnotab = frame.f_code.co_lnotab[1::2] 
6f876aca1c34
Changed calculation of line numbers in a function to work properly on Python 3.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5183
diff
changeset

606  
5045
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

607  # No need to handle special case if a lot of lines between 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

608  # (e.g. closure), because the additional lines won't cause a bp 
5203
6f876aca1c34
Changed calculation of line numbers in a function to work properly on Python 3.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5183
diff
changeset

609  for co_lno in co_lnotab: 
5045
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

610  lineNo += co_lno 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

611  lineNumbers.append(lineNo) 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

612  
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

613  for bp in Breakpoint.breakInFile[filename]: 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

614  if bp in lineNumbers: 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

615  Breakpoint.breakInFrameCache[ 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

616  frame.f_globals.get('__file__'), 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

617  frame.f_code.co_firstlineno] = True 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

618  return True 
5048
9899fb545b1f
Fixed some code style issues and removed the obsolete method shouldSkip.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5046
diff
changeset

619  Breakpoint.breakInFrameCache[ 
9899fb545b1f
Fixed some code style issues and removed the obsolete method shouldSkip.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5046
diff
changeset

620  frame.f_globals.get('__file__'), 
5045
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

621  frame.f_code.co_firstlineno] = False 
50862a6a2c63
Check only once if a function / method has a breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5044
diff
changeset

622  return False 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

623  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

624  def break_here(self, frame): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

625  """ 
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3160
diff
changeset

626  Public method reimplemented from bdb.py to fix the filename from the 
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3160
diff
changeset

627  frame. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

628  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

629  See fix_frame_filename for more info. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

630  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

631  @param frame the frame object 
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

632  @type frame object 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

633  @return flag indicating the break status 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

634  @rtype bool 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

635  """ 
5007
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

636  filename = self.fix_frame_filename(frame) 
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

637  if (filename, frame.f_lineno) in Breakpoint.breaks: 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

638  bp, flag = Breakpoint.effectiveBreak( 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

639  filename, frame.f_lineno, frame) 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

640  if bp: 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

641  # flag says ok to delete temp. bp 
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

642  if flag and bp.temporary: 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

643  self.__do_clearBreak(filename, frame.f_lineno) 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

644  return True 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

645  
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

646  if Watch.watches != []: 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

647  bp, flag = Watch.effectiveWatch(frame) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

648  if bp: 
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

649  # flag says ok to delete temp. watch 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

650  if flag and bp.temporary: 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

651  self.__do_clearWatch(bp.cond) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

652  return True 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

653  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

654  return False 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

655  
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

656  def __do_clearBreak(self, filename, lineno): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

657  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

658  Private method called to clear a temporary breakpoint. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

659  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

660  @param filename name of the file the bp belongs to 
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

661  @type str 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

662  @param lineno linenumber of the bp 
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

663  @type int 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

664  """ 
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

665  Breakpoint.clear_break(filename, lineno) 
5124
1ba8ee313b57
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4830
diff
changeset

666  self._dbgClient.sendClearTemporaryBreakpoint(filename, lineno) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

667  
5041
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

668  def __do_clearWatch(self, cond): 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

669  """ 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

670  Private method called to clear a temporary watch expression. 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

671  
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

672  @param cond expression of the watch expression to be cleared 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

673  @type str 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

674  """ 
f00a4c8bcbbd
Breakpoint and Watch and thier basic methods in new classes extracted.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5012
diff
changeset

675  Watch.clear_watch(cond) 
5174  676  self._dbgClient.sendClearTemporaryWatch(cond) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

677  
5204
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

678  def getStack(self, frame=None, applyTrace=False): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

679  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

680  Public method to get the stack. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

681  
5204
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

682  @keyparam frame frame object to inspect 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

683  @type frame object or list 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

684  @keyparam applyTrace flag to assign trace function to fr.f_trace 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

685  @type bool 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

686  @return list of lists with file name (string), line number (integer) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

687  and function name (string) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

688  """ 
5204
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

689  if frame is None: 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

690  fr = self.getCurrentFrame() 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

691  elif type(frame) == list: 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

692  fr = frame.pop(0) 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

693  else: 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

694  fr = frame 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

695  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

696  stack = [] 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

697  while fr is not None: 
5204
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

698  if applyTrace: 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

699  # Reset the trace function so we can be sure 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

700  # to trace all functions up the stack... This gets around 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

701  # problems where an exception/breakpoint has occurred 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

702  # but we had disabled tracing along the way via a None 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

703  # return from dispatch_call 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

704  fr.f_trace = self.trace_dispatch 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

705  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

706  fname = self._dbgClient.absPath(self.fix_frame_filename(fr)) 
5204
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

707  # Always show at least one stack frame, even if it's from eric. 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

708  if stack and os.path.basename(fname).startswith( 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

709  ("DebugBase.py", "DebugClientBase.py", 
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5206
diff
changeset

710  "ThreadExtension.py", "threading.py")): 
5204
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

711  break 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

712  
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

713  fline = fr.f_lineno 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

714  ffunc = fr.f_code.co_name 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

715  
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

716  if ffunc == '?': 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

717  ffunc = '' 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

718  
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

719  if ffunc and not ffunc.startswith("<"): 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

720  argInfo = getargvalues(fr) 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

721  try: 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

722  fargs = formatargvalues( 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

723  argInfo.args, argInfo.varargs, 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

724  argInfo.keywords, argInfo.locals) 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

725  except Exception: 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

726  fargs = "" 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

727  else: 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

728  fargs = "" 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

729  
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

730  stack.append([fname, fline, ffunc, fargs]) 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

731  
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

732  # is it a stack frame or exception list? 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

733  if type(frame) == list: 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

734  if frame != []: 
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

735  fr = frame.pop(0) 
2620
a3be952f2ae4
Extended the Python debugger backends to report the call arguments and values of the frames.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2486
diff
changeset

736  else: 
5204
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

737  fr = None 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

738  else: 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

739  fr = fr.f_back 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

740  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

741  return stack 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

742  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

743  def user_line(self, frame): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

744  """ 
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3160
diff
changeset

745  Public method reimplemented to handle the program about to execute a 
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3160
diff
changeset

746  particular line. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

747  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

748  @param frame the frame object 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

749  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

750  # We never stop on line 0. 
5063
0b5dccc8aacb
Hide frames belonging to the debugger at a regular breakpoint.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5062
diff
changeset

751  if frame.f_lineno == 0: 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

752  return 
5088
5b992bcb3c86
Remove some obsolet code, which can't be executed anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5087
diff
changeset

753  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

754  self.currentFrame = frame 
5204
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

755  stack = self.getStack(frame, applyTrace=True) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

756  
5206
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

757  self.isBroken = True 
5221
960afd19c1b6
Give the next debugger command to the thread where we are stopped at the moment.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5209
diff
changeset

758  self._dbgClient.lockClient() 
960afd19c1b6
Give the next debugger command to the thread where we are stopped at the moment.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5209
diff
changeset

759  self._dbgClient.currentThread = self 
960afd19c1b6
Give the next debugger command to the thread where we are stopped at the moment.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5209
diff
changeset

760  self._dbgClient.currentThreadExec = self 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

761  
5124
1ba8ee313b57
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4830
diff
changeset

762  self._dbgClient.sendResponseLine(stack) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

763  self._dbgClient.eventLoop() 
5012
be693f11da53
Avoid unnecessary function calls.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5007
diff
changeset

764  
5206
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

765  self.isBroken = False 
5221
960afd19c1b6
Give the next debugger command to the thread where we are stopped at the moment.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5209
diff
changeset

766  self._dbgClient.unlockClient() 
5206
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

767  
5536
d28e800f2810
Remove obsolete parameter 'frame' at user_exception function.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5417
diff
changeset

768  def user_exception(self, excinfo, unhandled=False): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

769  """ 
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3160
diff
changeset

770  Public method reimplemented to report an exception to the debug server. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

771  
5084
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

772  @param excinfo details about the exception 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

773  @type tuple(Exception, excval object, traceback frame object) 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

774  @keyparam unhandled flag indicating an uncaught exception 
25115adf9758
Don't use bdb.BdbQuit anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5083
diff
changeset

775  @type bool 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

776  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

777  exctype, excval, exctb = excinfo 
4063
b7269498aa95
Fixed a serious issue handling 'nonerror' exceptions in the debugger. This bug was about 10 years old.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4021
diff
changeset

778  
5537
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

779  if exctype in [GeneratorExit, StopIteration, SystemExit]: 
4063
b7269498aa95
Fixed a serious issue handling 'nonerror' exceptions in the debugger. This bug was about 10 years old.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4021
diff
changeset

780  # ignore these 
b7269498aa95
Fixed a serious issue handling 'nonerror' exceptions in the debugger. This bug was about 10 years old.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4021
diff
changeset

781  return 
b7269498aa95
Fixed a serious issue handling 'nonerror' exceptions in the debugger. This bug was about 10 years old.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4021
diff
changeset

782  
2927
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

783  if exctype in [SyntaxError, IndentationError]: 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

784  try: 
5183
f7037c006edf
Invalid __future__ import didn't show a valid error message on Python 2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5179
diff
changeset

785  # tuple could only occure on Python 2, but not always! 
f7037c006edf
Invalid __future__ import didn't show a valid error message on Python 2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5179
diff
changeset

786  if type(excval) == tuple: 
f7037c006edf
Invalid __future__ import didn't show a valid error message on Python 2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5179
diff
changeset

787  message, details = excval 
f7037c006edf
Invalid __future__ import didn't show a valid error message on Python 2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5179
diff
changeset

788  filename, lineno, charno, text = details 
5179
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

789  else: 
5183
f7037c006edf
Invalid __future__ import didn't show a valid error message on Python 2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5179
diff
changeset

790  message = excval.msg 
f7037c006edf
Invalid __future__ import didn't show a valid error message on Python 2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5179
diff
changeset

791  filename = excval.filename 
f7037c006edf
Invalid __future__ import didn't show a valid error message on Python 2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5179
diff
changeset

792  lineno = excval.lineno 
f7037c006edf
Invalid __future__ import didn't show a valid error message on Python 2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5179
diff
changeset

793  charno = excval.offset 
5239  794  
5184
79b3922094ba
Fixed an interesting issue showing up when the code contains an invalid future statement.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5169
diff
changeset

795  if charno is None: 
79b3922094ba
Fixed an interesting issue showing up when the code contains an invalid future statement.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5169
diff
changeset

796  charno = 0 
5183
f7037c006edf
Invalid __future__ import didn't show a valid error message on Python 2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5179
diff
changeset

797  
f7037c006edf
Invalid __future__ import didn't show a valid error message on Python 2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5179
diff
changeset

798  filename = os.path.abspath(filename) 
5124
1ba8ee313b57
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4830
diff
changeset

799  realSyntaxError = os.path.exists(filename) 
3085
4a0f54a64496
Fixed an issue in the Python3 debugger backend handling syntax errors.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3032
diff
changeset

800  except (AttributeError, ValueError): 
5124
1ba8ee313b57
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4830
diff
changeset

801  message = "" 
1ba8ee313b57
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4830
diff
changeset

802  filename = "" 
1ba8ee313b57
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4830
diff
changeset

803  lineno = 0 
1ba8ee313b57
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4830
diff
changeset

804  charno = 0 
2927
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

805  realSyntaxError = True 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

806  
2927
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

807  if realSyntaxError: 
5124
1ba8ee313b57
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4830
diff
changeset

808  self._dbgClient.sendSyntaxError( 
1ba8ee313b57
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4830
diff
changeset

809  message, filename, lineno, charno) 
2927
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

810  self._dbgClient.eventLoop() 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

811  return 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

812  
5050
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

813  self.skipFrames = 0 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

814  if (exctype == RuntimeError and 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

815  str(excval).startswith('maximum recursion depth exceeded') or 
5206
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

816  sys.version_info >= (3, 5) and 
997064ba25d6
Some clean up and restructuring.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5205
diff
changeset

817  exctype == RecursionError): # __IGNORE_WARNING__ 
5050
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

818  excval = 'maximum recursion depth exceeded' 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

819  depth = 0 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

820  tb = exctb 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

821  while tb: 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

822  tb = tb.tb_next 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

823  
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

824  if (tb and tb.tb_frame.f_code.co_name == 'trace_dispatch' and 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

825  __file__.startswith(tb.tb_frame.f_code.co_filename)): 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

826  depth = 1 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

827  self.skipFrames += depth 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

828  
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

829  # always 1 if running without debugger 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

830  self.skipFrames = max(1, self.skipFrames) 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

831  
2927
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

832  exctype = self.__extractExceptionName(exctype) 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

833  
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

834  if excval is None: 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

835  excval = '' 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

836  
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

837  if unhandled: 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

838  exctypetxt = "unhandled {0!s}".format(str(exctype)) 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

839  else: 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

840  exctypetxt = str(exctype) 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

841  
5179
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

842  if sys.version_info[0] == 2: 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

843  try: 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

844  excvaltxt = unicode(excval).encode(self._dbgClient.getCoding()) 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

845  except UnicodeError: 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

846  excvaltxt = str(excval) 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

847  else: 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

848  excvaltxt = str(excval) 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

849  
5124
1ba8ee313b57
Continued modernizing the debugger interface.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4830
diff
changeset

850  stack = [] 
2927
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

851  if exctb: 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

852  frlist = self.__extract_stack(exctb) 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

853  frlist.reverse() 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

854  
2927
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

855  self.currentFrame = frlist[0] 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

856  
5204
7376ae3e6668
Unify the three different variants of getStack (user_line and user_exception).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5203
diff
changeset

857  stack = self.getStack(frlist[self.skipFrames:]) 
2927
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

858  
5179
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

859  self._dbgClient.sendException(exctypetxt, excvaltxt, stack) 
2927
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

860  
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

861  if exctb is None: 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

862  return 
f36b757378f1
Fixed an issue in the Python debugger backends when a syntax error was raised for an invalid source file. That will be treated now like any other exception.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2648
diff
changeset

863  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

864  self._dbgClient.eventLoop() 
5050
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

865  self.skipFrames = 0 
a6335e924d08
Hide frames belonging to the debugger at a recursion exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5048
diff
changeset

866  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

867  def __extractExceptionName(self, exctype): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

868  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

869  Private method to extract the exception name given the exception 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

870  type object. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

871  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

872  @param exctype type of the exception 
2953
703452a2876f
Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2927
diff
changeset

873  @return exception name (string) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

874  """ 
5179
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

875  if sys.version_info[0] == 2: 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

876  if type(exctype) in [types.ClassType, # Python up to 2.4 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

877  types.TypeType]: # Python 2.5+ 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

878  return exctype.__name__ 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

879  else: 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

880  return exctype 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

881  else: 
5f56410e7624
Combined version of the Python debugger.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5178
diff
changeset

882  return str(exctype).replace("<class '", "").replace("'>", "") 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

883  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

884  def __extract_stack(self, exctb): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

885  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

886  Private member to return a list of stack frames. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

887  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

888  @param exctb exception traceback 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

889  @return list of stack frames 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

890  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

891  tb = exctb 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

892  stack = [] 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

893  while tb is not None: 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

894  stack.append(tb.tb_frame) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

895  tb = tb.tb_next 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

896  tb = None 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

897  return stack 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

898  
5537
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

899  def __extractSystemExitMessage(self, excinfo): 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

900  """ 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

901  Private method to get the SystemExit code and message. 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

902  
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

903  @param excinfo details about the SystemExit exception 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

904  @type tuple(Exception, excval object, traceback frame object) 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

905  @return SystemExit code and message 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

906  @rtype int, str 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

907  """ 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

908  exctype, excval, exctb = excinfo 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

909  if excval is None: 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

910  exitcode = 0 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

911  message = "" 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

912  elif isinstance(excval, basestring): 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

913  exitcode = 1 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

914  message = excval 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

915  elif isinstance(excval, bytes): 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

916  exitcode = 1 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

917  message = excval.decode() 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

918  elif isinstance(excval, int): 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

919  exitcode = excval 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

920  message = "" 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

921  elif isinstance(excval, SystemExit): 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

922  code = excval.code 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

923  if isinstance(code, basestring): 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

924  exitcode = 1 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

925  message = code 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

926  elif isinstance(code, bytes): 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

927  exitcode = 1 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

928  message = code.decode() 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

929  elif isinstance(code, int): 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

930  exitcode = code 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

931  message = "" 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

932  else: 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

933  exitcode = 1 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

934  message = str(code) 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

935  else: 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

936  exitcode = 1 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

937  message = str(excval) 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

938  
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

939  return exitcode, message 
706ac32a4538
Improved handling of program termination. atexit is only run once as specified anymore.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5536
diff
changeset

940  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

941  def stop_here(self, frame): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

942  """ 
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3160
diff
changeset

943  Public method reimplemented to filter out debugger files. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

944  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

945  Tracing is turned off for files that are part of the 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

946  debugger that are called from the application being debugged. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

947  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

948  @param frame the frame object 
5085
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

949  @type frame object 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

950  @return flag indicating whether the debugger should stop here 
5085
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

951  @rtype bool 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

952  """ 
5005
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

953  if self.__skipFrame(frame): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

954  return False 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

955  
5085
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

956  return (self.stop_everywhere or 
85dfb7886fb9
Determination where to stop in stop_here heavily reworked.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5084
diff
changeset

957  frame is self.stopframe or 
5205
df1709f0e49f
Change evaluation of last frame to run atexit functions again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5204
diff
changeset

958  frame is self.returnframe) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

959  
5005
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

960  def tracePythonLibs(self, enable): 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

961  """ 
5007
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

962  Public method to update the settings to trace into Python libraries. 
5005
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

963  
5007
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

964  @param enable flag to debug into Python libraries 
5174  965  @type bool 
5005
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

966  """ 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

967  pathsToSkip = list(self.pathsToSkip) 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

968  # don't trace into Python library? 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

969  if enable: 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

970  pathsToSkip = [x for x in pathsToSkip if not x.endswith( 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

971  ("sitepackages", "distpackages", self.lib))] 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

972  else: 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

973  pathsToSkip.append(self.lib) 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

974  localLib = [x for x in sys.path if x.endswith(("sitepackages", 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

975  "distpackages")) and not x.startswith(self.lib)] 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

976  pathsToSkip.extend(localLib) 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

977  
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

978  self.pathsToSkip = tuple(pathsToSkip) 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

979  
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

980  def __skipFrame(self, frame): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

981  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

982  Private method to filter out debugger files. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

983  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

984  Tracing is turned off for files that are part of the 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

985  debugger that are called from the application being debugged. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

986  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

987  @param frame the frame object 
5007
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

988  @type frame object 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

989  @return flag indicating whether the debugger should skip this frame 
5007
e2fa12bb0f53
Don't canonic the filename any more and cache it.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5005
diff
changeset

990  @rtype bool 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

991  """ 
5005
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

992  try: 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

993  return self.filesToSkip[frame.f_code.co_filename] 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

994  except KeyError: 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

995  ret = frame.f_code.co_filename.startswith(self.pathsToSkip) 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

996  self.filesToSkip[frame.f_code.co_filename] = ret 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

997  return ret 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

998  except AttributeError: 
684f5ba04f0b
First improvements on debugger speed: Cheaper detection of unwanted files and
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4830
diff
changeset

999  # if frame is None 
3640
2bf828881e86
Fixed stop at sys.breakpoint() in run mode under Python3 and on first run (Py2 and 3).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3591
diff
changeset

1000  return True 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

1001  
4543
2e6a880670e9
Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4455
diff
changeset

1002  # 
2e6a880670e9
Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4455
diff
changeset

1003  # eflag: noqa = M702 