예제 #1
0
 def test_count_frames(self):
     f = inspect.currentframe()
     frame_count = Mstack.count_frames(f)
     self.assertTrue(Mstack.count_frames(f) > 2)
     self.assertEqual(frame_count-1, Mstack.count_frames(f.f_back))
     self.assertEqual(frame_count-1, Mstack.count_frames(f, 1))
     return
예제 #2
0
 def test_count_frames(self):
     f = inspect.currentframe()
     frame_count = Mstack.count_frames(f)
     self.assertTrue(Mstack.count_frames(f) > 2)
     self.assertEqual(frame_count - 1, Mstack.count_frames(f.f_back))
     self.assertEqual(frame_count - 1, Mstack.count_frames(f, 1))
     return
예제 #3
0
    def is_stop_here(self, frame, event, arg):
        """ Does the magic to determine if we stop here and run a
        command processor or not. If so, return True and set
        self.stop_reason; if not, return False.

        Determining factors can be whether a breakpoint was
        encountered, whether we are stepping, next'ing, finish'ing,
        and, if so, whether there is an ignore counter.
        """

        # Add an generic event filter here?
        # FIXME TODO: Check for
        #  - thread switching (under set option)

        # Check for "next" and "finish" stopping via stop_level

        # Do we want a different line and if so,
        # do we have one?
        lineno = frame.f_lineno
        filename = frame.f_code.co_filename
        if self.different_line and event == 'line':
            if self.last_lineno == lineno and self.last_filename == filename:
                return False
            pass
        self.last_lineno   = lineno
        self.last_filename = filename

        if self.stop_level is not None:
            if frame != self.last_frame:
                # Recompute stack_depth:
                if self.last_frame:
                    if frame.f_back == self.last_frame:
                        self.last_level += 1
                    elif self.last_frame.f_back == frame:
                        self.last_level -= 1
                    else:
                        self.last_level = Mstack.count_frames(frame)
                else:
                    self.last_level = Mstack.count_frames(frame)
                self.last_frame = frame
                pass
            if self.last_level > self.stop_level:
                return False
            elif self.last_level == self.stop_level and \
                    self.stop_on_finish and event in ['return', 'c_return']:
                self.stop_level = None
                self.stop_reason = "in return for 'finish' command"
                return True
            pass

        # Check for stepping
        if self._is_step_next_stop(event):
            self.stop_reason = 'at a stepping statement'
            return True

        return False
예제 #4
0
    def is_stop_here(self, frame, event, arg):
        """ Does the magic to determine if we stop here and run a
        command processor or not. If so, return True and set
        self.stop_reason; if not, return False.

        Determining factors can be whether a breakpoint was
        encountered, whether we are stepping, next'ing, finish'ing,
        and, if so, whether there is an ignore counter.
        """

        # Add an generic event filter here?
        # FIXME TODO: Check for
        #  - thread switching (under set option)

        # Check for "next" and "finish" stopping via stop_level

        # Do we want a different line and if so,
        # do we have one?
        lineno = frame.f_lineno
        filename = frame.f_code.co_filename
        if self.different_line and event == 'line':
            if self.last_lineno == lineno and self.last_filename == filename:
                return False
            pass
        self.last_lineno = lineno
        self.last_filename = filename

        if self.stop_level is not None:
            if frame != self.last_frame:
                # Recompute stack_depth:
                if self.last_frame:
                    if frame.f_back == self.last_frame:
                        self.last_level += 1
                    elif self.last_frame.f_back == frame:
                        self.last_level -= 1
                    else:
                        self.last_level = Mstack.count_frames(frame)
                else:
                    self.last_level = Mstack.count_frames(frame)
                self.last_frame = frame
                pass
            if self.last_level > self.stop_level:
                return False
            elif self.last_level == self.stop_level and \
                    self.stop_on_finish and event in ['return', 'c_return']:
                self.stop_level = None
                self.stop_reason = "in return for 'finish' command"
                return True
            pass

        # Check for stepping
        if self._is_step_next_stop(event):
            self.stop_reason = 'at a stepping statement'
            return True

        return False
예제 #5
0
 def set_next(self, frame, step_ignore=0, step_events=None):
     "Sets to stop on the next event that happens in frame 'frame'."
     self.step_events      = None  # Consider all events
     self.stop_level       = Mstack.count_frames(frame)
     self.last_level       = self.stop_level
     self.last_frame       = frame
     self.stop_on_finish   = False
     self.step_ignore      = step_ignore
     return
예제 #6
0
 def set_next(self, frame, step_ignore=0, step_events=None):
     "Sets to stop on the next event that happens in frame 'frame'."
     self.step_events      = None  # Consider all events
     self.stop_level       = Mstack.count_frames(frame)
     self.last_level       = self.stop_level
     self.last_frame       = frame
     self.stop_on_finish   = False
     self.step_ignore      = step_ignore
     return
예제 #7
0
    def run(self, args):
        if self.proc.stack is None: return False
        if len(args) <= 1:
            levels = 1
        else:
            levels = self.proc.get_int(args[1], default=1, cmdname='finish')
            if levels is None: return False
            pass

        # print "+++ %d" % levels
        self.core.step_events      = ['return']
        self.core.stop_on_finish   = True
        self.core.stop_level       = \
          Mstack.count_frames(self.proc.frame)-levels
        self.core.last_frame       = self.proc.frame
        self.proc.continue_running = True   # Break out of command read loop
        return True
예제 #8
0
    def run(self, args):
        if self.proc.stack is None: return False
        if len(args) <= 1:
            levels = 1
        else:
            levels = self.proc.get_int(args[1], default=1, cmdname='finish')
            if levels is None: return False
            pass

        # print "+++ %d" % levels
        self.core.step_events = ['return']
        self.core.stop_on_finish = True
        self.core.stop_level       = \
          Mstack.count_frames(self.proc.frame)-levels
        self.core.last_frame = self.proc.frame
        self.proc.continue_running = True  # Break out of command read loop
        return True