src/eric7/DebugClients/Python/DebugBase.py

branch
eric7-maintenance
changeset 10460
3b34efa2857c
parent 10439
21c28b0f9e41
child 10542
e46910b0ce73
equal deleted inserted replaced
10366:411df92e881f 10460:3b34efa2857c
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 # Copyright (c) 2002 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2002 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing the debug base class which based originally on bdb. 7 Module implementing the debug base class which based originally on bdb.
8 """ 8 """
35 def printerr(s): 35 def printerr(s):
36 """ 36 """
37 Module function used for debugging the debug client. 37 Module function used for debugging the debug client.
38 38
39 @param s data to be printed 39 @param s data to be printed
40 @type str
40 """ 41 """
41 sys.__stderr__.write("{0!s}\n".format(s)) 42 sys.__stderr__.write("{0!s}\n".format(s))
42 sys.__stderr__.flush() 43 sys.__stderr__.flush()
43 44
44 45
45 def setRecursionLimit(limit): 46 def setRecursionLimit(limit):
46 """ 47 """
47 Module function to set the recursion limit. 48 Module function to set the recursion limit.
48 49
49 @param limit recursion limit (integer) 50 @param limit recursion limit
51 @type int
50 """ 52 """
51 global gRecursionLimit 53 global gRecursionLimit
52 gRecursionLimit = limit 54 gRecursionLimit = limit
53 55
54 56
73 def __init__(self, dbgClient): 75 def __init__(self, dbgClient):
74 """ 76 """
75 Constructor 77 Constructor
76 78
77 @param dbgClient the owning client 79 @param dbgClient the owning client
80 @type DebugClient
78 """ 81 """
79 self._dbgClient = dbgClient 82 self._dbgClient = dbgClient
80 83
81 # Some informations about the thread 84 # Some informations about the thread
82 self.isMainThread = False 85 self.isMainThread = False
149 """ 152 """
150 Public method to return the locals dictionary of the current frame 153 Public method to return the locals dictionary of the current frame
151 or a frame below. 154 or a frame below.
152 155
153 @param frmnr distance of frame to get locals dictionary of. 0 is 156 @param frmnr distance of frame to get locals dictionary of. 0 is
154 the current frame (int) 157 the current frame
158 @type int
155 @return locals dictionary of the frame 159 @return locals dictionary of the frame
160 @rtype dict
156 """ 161 """
157 try: 162 try:
158 f = self.frameList[frmnr] 163 f = self.frameList[frmnr]
159 return f.f_locals 164 return f.f_locals
160 except IndexError: 165 except IndexError:
164 """ 169 """
165 Public method to store the locals into the frame, so an access to 170 Public method to store the locals into the frame, so an access to
166 frame.f_locals returns the last data. 171 frame.f_locals returns the last data.
167 172
168 @param frmnr distance of frame to store locals dictionary to. 0 is 173 @param frmnr distance of frame to store locals dictionary to. 0 is
169 the current frame (int) 174 the current frame
175 @type int
170 """ 176 """
171 with contextlib.suppress(IndexError): 177 with contextlib.suppress(IndexError):
172 cf = self.frameList[frmnr] 178 cf = self.frameList[frmnr]
173 179
174 with contextlib.suppress(ImportError, AttributeError): 180 with contextlib.suppress(ImportError, AttributeError):
184 """ 190 """
185 Public method to perform a step operation in this thread. 191 Public method to perform a step operation in this thread.
186 192
187 @param traceMode If it is True, then the step is a step into, 193 @param traceMode If it is True, then the step is a step into,
188 otherwise it is a step over. 194 otherwise it is a step over.
195 @type bool
189 """ 196 """
190 if traceMode: 197 if traceMode:
191 self.set_step() 198 self.set_step()
192 else: 199 else:
193 self.set_next(self.currentFrame) 200 self.set_next(self.currentFrame)
203 Public method to resume the thread. 210 Public method to resume the thread.
204 211
205 It resumes the thread stopping only at breakpoints or exceptions. 212 It resumes the thread stopping only at breakpoints or exceptions.
206 213
207 @param special flag indicating a special continue operation 214 @param special flag indicating a special continue operation
215 @type bool
208 """ 216 """
209 self.set_continue(special) 217 self.set_continue(special)
210 218
211 def setRecursionDepth(self, frame): 219 def setRecursionDepth(self, frame):
212 """ 220 """
213 Public method to determine the current recursion depth. 221 Public method to determine the current recursion depth.
214 222
215 @param frame The current stack frame. 223 @param frame The current stack frame.
224 @type frame object
216 """ 225 """
217 self.__recursionDepth = 0 226 self.__recursionDepth = 0
218 while frame is not None: 227 while frame is not None:
219 self.__recursionDepth += 1 228 self.__recursionDepth += 1
220 frame = frame.f_back 229 frame = frame.f_back
769 778
770 @param frame frame object to inspect 779 @param frame frame object to inspect
771 @type frame object or list 780 @type frame object or list
772 @param applyTrace flag to assign trace function to fr.f_trace 781 @param applyTrace flag to assign trace function to fr.f_trace
773 @type bool 782 @type bool
774 @return list of lists with file name (string), line number (integer) 783 @return list of lists with file name, line number, function name
775 and function name (string) 784 and function arguments
785 @rtype list of list of [str, int, str, str]
776 """ 786 """
777 tb_lineno = None 787 tb_lineno = None
778 if frame is None: 788 if frame is None:
779 fr = self.getFrame() 789 fr = self.getFrame()
780 elif isinstance(frame, list): 790 elif isinstance(frame, list):
839 def user_line(self, frame): 849 def user_line(self, frame):
840 """ 850 """
841 Public method reimplemented to handle the program about to execute a 851 Public method reimplemented to handle the program about to execute a
842 particular line. 852 particular line.
843 853
844 @param frame the frame object 854 @param frame reference to the frame object
855 @type frame object
845 """ 856 """
846 # We never stop on line 0. 857 # We never stop on line 0.
847 if frame.f_lineno == 0: 858 if frame.f_lineno == 0:
848 return 859 return
849 860
1000 """ 1011 """
1001 Private method to extract the exception name given the exception 1012 Private method to extract the exception name given the exception
1002 type object. 1013 type object.
1003 1014
1004 @param exctype type of the exception 1015 @param exctype type of the exception
1005 @return exception name (string) 1016 @type type
1017 @return exception name
1018 @rtype str
1006 """ 1019 """
1007 return str(exctype).replace("<class '", "").replace("'>", "") 1020 return str(exctype).replace("<class '", "").replace("'>", "")
1008 1021
1009 def __extract_stack(self, exctb): 1022 def __extract_stack(self, exctb):
1010 """ 1023 """
1011 Private member to return a list of stack frames. 1024 Private member to return a list of stack frames.
1012 1025
1013 @param exctb exception traceback 1026 @param exctb exception traceback
1027 @type traceback
1014 @return list of stack frames 1028 @return list of stack frames
1029 @rtype list of frame
1015 """ 1030 """
1016 tb = exctb 1031 tb = exctb
1017 stack = [] 1032 stack = []
1018 while tb is not None: 1033 while tb is not None:
1019 stack.append((tb.tb_frame, tb.tb_lineno)) 1034 stack.append((tb.tb_frame, tb.tb_lineno))

eric ide

mercurial