Пример #1
0
    def run(self, args):
        if not self.core.is_running(): return False

        if self.proc.curindex + 1 != len(self.proc.stack):
            self.errmsg("You can only jump within the bottom frame")
            return False

        if self.proc.curframe.f_trace is None:
            self.errmsg("Sigh - operation can't be done here.")
            return False

        lineno = self.proc.get_an_int(args[1],
                                      ("jump: a line number is required, " +
                                       "got %s.") % args[1])
        if lineno is None: return False
        try:
            # Set to change position, update our copy of the stack,
            # and display the new position
            print(self.proc.curframe.f_trace)
            self.proc.curframe.f_lineno = lineno
            self.proc.stack[self.proc.curindex] = \
                self.proc.stack[self.proc.curindex][0], lineno
            Mcmdproc.print_location(self.proc)
        except ValueError:
            _, e, _ = sys.exc_info()
            self.errmsg('jump failed: %s' % e)
        return False
Пример #2
0
    def run(self, args):
        if not self.core.is_running(): return False

        if self.proc.curindex + 1 != len(self.proc.stack):
            self.errmsg("You can only jump within the bottom frame")
            return False

        if self.proc.curframe.f_trace is None:
            self.errmsg("Sigh - operation can't be done here.")
            return False

        lineno = self.proc.get_an_int(args[1],
                                      ("jump: a line number is required, " +
                                       "got %s.") % args[1])
        if lineno is None: return False
        try:
            # Set to change position, update our copy of the stack,
            # and display the new position
            print(self.proc.curframe.f_trace)
            self.proc.curframe.f_lineno = lineno
            self.proc.stack[self.proc.curindex] = \
                self.proc.stack[self.proc.curindex][0], lineno
            Mcmdproc.print_location(self.proc)
        except ValueError as e:
            self.errmsg('jump failed: %s' % e)
        return False
Пример #3
0
    def run(self, args):
        if not self.core.is_running(): return False

        if self.proc.curindex + 1 != len(self.proc.stack):
            self.errmsg("You can only skip within the bottom frame.")
            return False

        if self.proc.curframe.f_trace is None:
            self.errmsg("Sigh - operation can't be done here.")
            return False

        if len(args) == 1:
            count = 1
        else:
            msg   = "skip: expecting a number, got %s." % args[1]
            count = self.proc.get_an_int(args[1], msg)
            pass
        co = self.proc.curframe.f_code
        offset = self.proc.curframe.f_lasti
        if count is None: return False
        lineno = Mbytecode.next_linestart(co, offset, count)

        if lineno < 0:
            self.errmsg('No next line found')
            return False

        try:
            # Set to change position, update our copy of the stack,
            # and display the new position
            self.proc.curframe.f_lineno = lineno
            self.proc.stack[self.proc.curindex] = \
                self.proc.stack[self.proc.curindex][0], lineno
            Mcmdproc.print_location(self.proc)
        except ValueError:
            _, e, _ = sys.exc_info()
            self.errmsg('skip failed: %s' % e)
        return False
Пример #4
0
    def run(self, args):
        if not self.core.is_running(): return False

        if self.proc.curindex + 1 != len(self.proc.stack):
            self.errmsg("You can only skip within the bottom frame.")
            return False

        if self.proc.curframe.f_trace is None:
            self.errmsg("Sigh - operation can't be done here.")
            return False

        if len(args) == 1:
            count = 1
        else:
            msg = "skip: expecting a number, got %s." % args[1]
            count = self.proc.get_an_int(args[1], msg)
            pass
        co = self.proc.curframe.f_code
        offset = self.proc.curframe.f_lasti
        if count is None: return False
        lineno = Mbytecode.next_linestart(co, offset, count)

        if lineno < 0:
            self.errmsg('No next line found')
            return False

        try:
            # Set to change position, update our copy of the stack,
            # and display the new position
            self.proc.curframe.f_lineno = lineno
            self.proc.stack[self.proc.curindex] = \
                self.proc.stack[self.proc.curindex][0], lineno
            Mcmdproc.print_location(self.proc)
        except ValueError:
            _, e, _ = sys.exc_info()
            self.errmsg('skip failed: %s' % e)
        return False
Пример #5
0
 def run_python(self, args):
     leave_loop = self.python_cmd(["python"])
     if not leave_loop:
         Mcmdproc.print_location(self.proc)
     return leave_loop
Пример #6
0
    def event_hook(
        self,
        event: str,
        offset: int,
        byteName: str,
        byteCode: int,
        line_number: int,
        intArg: Optional[int],
        event_arg: Any,
        vm: Any,
        prompt="trepan-xpy",
    ):
        "command event processor: reading a commands do something with them."

        def frame_setup(frame):
            filename = frame.f_code.co_filename
            lineno = frame.f_lineno
            line = linecache.getline(filename, lineno, frame.f_globals)
            if not line:
                opts = {
                    "output": "plain",
                    "reload_on_change": self.settings("reload"),
                    "strip_nl": False,
                }
                m = re.search("^<frozen (.*)>", filename)
                if m and m.group(1):
                    filename = pyficache.unmap_file(m.group(1))
                line = pyficache.getline(filename, lineno, opts)
            self.current_source_text = line
            return line, filename

        self.vm = vm
        self.frame = vm.frame
        self.event = event
        self.event_arg = event_arg

        # In order to follow Python's sys.settrace()'s convention:
        # returning "None" turns off tracing for the scope.
        # However we do not need to return a reference to ourself,
        # a callable (this may be allowed in the future though).
        # Instead for now a string status is returned
        # * "skip" for skip next instruction, and
        # * "return" for immediate return
        # * "finish" for "step out"

        self.return_status = True

        if event == "fatal":
            self.core.execution_status = "Terminated"
            # One last hurrah!

            tb = vm.last_traceback
            if tb:
                frame_setup(tb.tb_frame)
                self.vm.frames = []
                while tb:
                    self.vm.frames.insert(0, tb.tb_frame)
                    tb = tb.tb_next
                self.curframe = self.frame = self.vm.frames[0]
                self.setup()
                self.curindex = len(vm.frames) - 1
                print_location(self)

            self.set_prompt("trepan-xpy:pm")
            self.process_commands()
            return None

        if self.vm.frame:
            self.core.execution_status = "Running"
        else:
            self.core.execution_status = "Terminated"
            return

        line, filename = frame_setup(self.frame)
        if self.settings("skip"):
            # Note that in contrast to skipping intructions
            # when return_status is set to "skip", here
            # we are execution the instruction but just skipping
            # any handling this instruction the debugger.
            if Mbytecode.is_def_stmt(line, self.frame):
                return self
            if Mbytecode.is_class_def(line, self.frame):
                return
            pass
        self.thread_name = current_thread_name()
        self.frame_thread_name = self.thread_name

        self.setup()
        print_location(self)
        if offset >= 0 and event not in ('call', 'return'):
            self.msg("%s" % format_instruction_with_highlight(
                vm.frame,
                vm.opc,
                byteName,
                intArg,
                event_arg,
                offset,
                line_number,
                extra_debug=False,
                settings=self.debugger.settings,
                show_line=
                False,  # We show the line number in our location reporting
                vm=self.vm,
                repr=self._repr.repr))

        self.set_prompt(prompt)
        self.process_commands()
        if filename == "<string>":
            pyficache.remove_remap_file("<string>")
        return self.return_status
Пример #7
0
 def run_python(self, args):
     leave_loop = self.python_cmd(['python'])
     if not leave_loop: Mcmdproc.print_location(self.proc)
     return leave_loop