DebugClients/Python/DebugBase.py

branch
debugger speed
changeset 5204
7376ae3e6668
parent 5203
6f876aca1c34
child 5205
df1709f0e49f
equal deleted inserted replaced
5203:6f876aca1c34 5204:7376ae3e6668
641 @type str 641 @type str
642 """ 642 """
643 Watch.clear_watch(cond) 643 Watch.clear_watch(cond)
644 self._dbgClient.sendClearTemporaryWatch(cond) 644 self._dbgClient.sendClearTemporaryWatch(cond)
645 645
646 def getStack(self): 646 def getStack(self, frame=None, applyTrace=False):
647 """ 647 """
648 Public method to get the stack. 648 Public method to get the stack.
649 649
650 @keyparam frame frame object to inspect
651 @type frame object or list
652 @keyparam applyTrace flag to assign trace function to fr.f_trace
653 @type bool
650 @return list of lists with file name (string), line number (integer) 654 @return list of lists with file name (string), line number (integer)
651 and function name (string) 655 and function name (string)
652 """ 656 """
653 fr = self.cFrame 657 if frame is None:
658 fr = self.getCurrentFrame()
659 elif type(frame) == list:
660 fr = frame.pop(0)
661 else:
662 fr = frame
663
654 stack = [] 664 stack = []
655 while fr is not None: 665 while fr is not None:
666 if applyTrace:
667 # Reset the trace function so we can be sure
668 # to trace all functions up the stack... This gets around
669 # problems where an exception/breakpoint has occurred
670 # but we had disabled tracing along the way via a None
671 # return from dispatch_call
672 fr.f_trace = self.trace_dispatch
673
656 fname = self._dbgClient.absPath(self.fix_frame_filename(fr)) 674 fname = self._dbgClient.absPath(self.fix_frame_filename(fr))
657 if not fname.startswith("<"): 675 # Always show at least one stack frame, even if it's from eric.
658 fline = fr.f_lineno 676 if stack and os.path.basename(fname).startswith(
659 ffunc = fr.f_code.co_name 677 ("DebugBase.py", "DebugClientBase.py",
660 678 "ThreadExtension.py", "threading.py")):
661 if ffunc == '?': 679 break
662 ffunc = '' 680
663 681 fline = fr.f_lineno
664 if ffunc and not ffunc.startswith("<"): 682 ffunc = fr.f_code.co_name
665 argInfo = getargvalues(fr) 683
666 try: 684 if ffunc == '?':
667 fargs = formatargvalues( 685 ffunc = ''
668 argInfo.args, argInfo.varargs, 686
669 argInfo.keywords, argInfo.locals) 687 if ffunc and not ffunc.startswith("<"):
670 except Exception: 688 argInfo = getargvalues(fr)
671 fargs = "" 689 try:
690 fargs = formatargvalues(
691 argInfo.args, argInfo.varargs,
692 argInfo.keywords, argInfo.locals)
693 except Exception:
694 fargs = ""
695 else:
696 fargs = ""
697
698 stack.append([fname, fline, ffunc, fargs])
699
700 # is it a stack frame or exception list?
701 if type(frame) == list:
702 if frame != []:
703 fr = frame.pop(0)
672 else: 704 else:
673 fargs = "" 705 fr = None
674
675 stack.append([fname, fline, ffunc, fargs])
676
677 if fr == self._dbgClient.mainFrame:
678 fr = None
679 else: 706 else:
680 fr = fr.f_back 707 fr = fr.f_back
681 708
682 return stack 709 return stack
683 710
691 # We never stop on line 0. 718 # We never stop on line 0.
692 if frame.f_lineno == 0: 719 if frame.f_lineno == 0:
693 return 720 return
694 721
695 self.currentFrame = frame 722 self.currentFrame = frame
696 723 stack = self.getStack(frame, applyTrace=True)
697 fr = frame
698 stack = []
699 while fr is not None:
700 # Reset the trace function so we can be sure
701 # to trace all functions up the stack... This gets around
702 # problems where an exception/breakpoint has occurred
703 # but we had disabled tracing along the way via a None
704 # return from dispatch_call
705 fr.f_trace = self.trace_dispatch
706 fname = self._dbgClient.absPath(self.fix_frame_filename(fr))
707 if not fname.startswith("<"):
708 fline = fr.f_lineno
709 ffunc = fr.f_code.co_name
710
711 if ffunc == '?':
712 ffunc = ''
713
714 if ffunc and not ffunc.startswith("<"):
715 argInfo = getargvalues(fr)
716 try:
717 fargs = formatargvalues(
718 argInfo.args, argInfo.varargs,
719 argInfo.keywords, argInfo.locals)
720 except Exception:
721 fargs = ""
722 else:
723 fargs = ""
724
725 stack.append([fname, fline, ffunc, fargs])
726
727 if fr == self._dbgClient.mainFrame:
728 fr = None
729 else:
730 fr = fr.f_back
731 724
732 self.__isBroken = True 725 self.__isBroken = True
733 726
734 self._dbgClient.sendResponseLine(stack) 727 self._dbgClient.sendResponseLine(stack)
735 self._dbgClient.eventLoop() 728 self._dbgClient.eventLoop()
855 frlist = self.__extract_stack(exctb) 848 frlist = self.__extract_stack(exctb)
856 frlist.reverse() 849 frlist.reverse()
857 850
858 self.currentFrame = frlist[0] 851 self.currentFrame = frlist[0]
859 852
860 for fr in frlist[self.skipFrames:]: 853 stack = self.getStack(frlist[self.skipFrames:])
861 filename = self._dbgClient.absPath(self.fix_frame_filename(fr))
862
863 if os.path.basename(filename).startswith("DebugClientBase"):
864 break
865
866 linenr = fr.f_lineno
867 ffunc = fr.f_code.co_name
868
869 if ffunc == '?':
870 ffunc = ''
871
872 if ffunc and not ffunc.startswith("<"):
873 argInfo = getargvalues(fr)
874 try:
875 fargs = formatargvalues(
876 argInfo.args, argInfo.varargs,
877 argInfo.keywords, argInfo.locals)
878 except Exception:
879 fargs = ""
880 else:
881 fargs = ""
882
883 stack.append([filename, linenr, ffunc, fargs])
884 854
885 self._dbgClient.sendException(exctypetxt, excvaltxt, stack) 855 self._dbgClient.sendException(exctypetxt, excvaltxt, stack)
886 856
887 if exctb is None: 857 if exctb is None:
888 return 858 return

eric ide

mercurial