--- a/DebugClients/Python/DebugBase.py Tue Oct 04 21:14:28 2016 +0200 +++ b/DebugClients/Python/DebugBase.py Tue Oct 04 21:25:15 2016 +0200 @@ -643,39 +643,66 @@ Watch.clear_watch(cond) self._dbgClient.sendClearTemporaryWatch(cond) - def getStack(self): + def getStack(self, frame=None, applyTrace=False): """ Public method to get the stack. + @keyparam frame frame object to inspect + @type frame object or list + @keyparam applyTrace flag to assign trace function to fr.f_trace + @type bool @return list of lists with file name (string), line number (integer) and function name (string) """ - fr = self.cFrame + if frame is None: + fr = self.getCurrentFrame() + elif type(frame) == list: + fr = frame.pop(0) + else: + fr = frame + stack = [] while fr is not None: + if applyTrace: + # Reset the trace function so we can be sure + # to trace all functions up the stack... This gets around + # problems where an exception/breakpoint has occurred + # but we had disabled tracing along the way via a None + # return from dispatch_call + fr.f_trace = self.trace_dispatch + fname = self._dbgClient.absPath(self.fix_frame_filename(fr)) - if not fname.startswith("<"): - fline = fr.f_lineno - ffunc = fr.f_code.co_name - - if ffunc == '?': - ffunc = '' - - if ffunc and not ffunc.startswith("<"): - argInfo = getargvalues(fr) - try: - fargs = formatargvalues( - argInfo.args, argInfo.varargs, - argInfo.keywords, argInfo.locals) - except Exception: - fargs = "" + # Always show at least one stack frame, even if it's from eric. + if stack and os.path.basename(fname).startswith( + ("DebugBase.py", "DebugClientBase.py", + "ThreadExtension.py", "threading.py")): + break + + fline = fr.f_lineno + ffunc = fr.f_code.co_name + + if ffunc == '?': + ffunc = '' + + if ffunc and not ffunc.startswith("<"): + argInfo = getargvalues(fr) + try: + fargs = formatargvalues( + argInfo.args, argInfo.varargs, + argInfo.keywords, argInfo.locals) + except Exception: + fargs = "" + else: + fargs = "" + + stack.append([fname, fline, ffunc, fargs]) + + # is it a stack frame or exception list? + if type(frame) == list: + if frame != []: + fr = frame.pop(0) else: - fargs = "" - - stack.append([fname, fline, ffunc, fargs]) - - if fr == self._dbgClient.mainFrame: - fr = None + fr = None else: fr = fr.f_back @@ -693,41 +720,7 @@ return self.currentFrame = frame - - fr = frame - stack = [] - while fr is not None: - # Reset the trace function so we can be sure - # to trace all functions up the stack... This gets around - # problems where an exception/breakpoint has occurred - # but we had disabled tracing along the way via a None - # return from dispatch_call - fr.f_trace = self.trace_dispatch - fname = self._dbgClient.absPath(self.fix_frame_filename(fr)) - if not fname.startswith("<"): - fline = fr.f_lineno - ffunc = fr.f_code.co_name - - if ffunc == '?': - ffunc = '' - - if ffunc and not ffunc.startswith("<"): - argInfo = getargvalues(fr) - try: - fargs = formatargvalues( - argInfo.args, argInfo.varargs, - argInfo.keywords, argInfo.locals) - except Exception: - fargs = "" - else: - fargs = "" - - stack.append([fname, fline, ffunc, fargs]) - - if fr == self._dbgClient.mainFrame: - fr = None - else: - fr = fr.f_back + stack = self.getStack(frame, applyTrace=True) self.__isBroken = True @@ -857,30 +850,7 @@ self.currentFrame = frlist[0] - for fr in frlist[self.skipFrames:]: - filename = self._dbgClient.absPath(self.fix_frame_filename(fr)) - - if os.path.basename(filename).startswith("DebugClientBase"): - break - - linenr = fr.f_lineno - ffunc = fr.f_code.co_name - - if ffunc == '?': - ffunc = '' - - if ffunc and not ffunc.startswith("<"): - argInfo = getargvalues(fr) - try: - fargs = formatargvalues( - argInfo.args, argInfo.varargs, - argInfo.keywords, argInfo.locals) - except Exception: - fargs = "" - else: - fargs = "" - - stack.append([filename, linenr, ffunc, fargs]) + stack = self.getStack(frlist[self.skipFrames:]) self._dbgClient.sendException(exctypetxt, excvaltxt, stack)