Exemplo n.º 1
0
    def event_processor(self, frame, event, event_arg, prompt='trepan3k'):
        'command event processor: reading a commands do something with them.'
        self.frame = frame
        self.event = event
        self.event_arg = event_arg

        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
        if self.settings('skip') is not None:
            if Mbytecode.is_def_stmt(line, frame):
                return True
            if Mbytecode.is_class_def(line, frame):
                return True
            pass
        self.thread_name = Mthread.current_thread_name()
        self.frame_thread_name = self.thread_name
        self.set_prompt(prompt)
        self.process_commands()
        if filename == '<string>': pyficache.remove_remap_file('<string>')
        return True
Exemplo n.º 2
0
    def run_eval(self, expr, start_opts=None, globals_=None, locals_=None):
        """ Run debugger on string `expr' which will executed via the
        built-in Python function: eval; `globals_' and `locals_' are
        the dictionaries to use for local and global variables. If
        `globals' is not given, __main__.__dict__ (the current global
        variables) is used. If `locals_' is not given, it becomes a
        copy of `globals_'.

        See also `run_call' if what you to debug a function call and
        `run' if you want to debug general Python statements.
        """
        if globals_ is None:
            globals_ = globals()
        if locals_ is None:
            locals_ = globals_
        if not isinstance(expr, types.CodeType):
            self.eval_string = expr
            expr = expr+'\n'
            pass
        retval = None
        self.core.start(start_opts)
        try:
            retval = eval(expr, globals_, locals_)
        except DebuggerQuit:
            pass
        finally:
            pyficache.remove_remap_file('<string>')
            self.core.stop()
        return retval
Exemplo n.º 3
0
    def event_processor(self, frame, event, event_arg, prompt='trepan2'):
        'command event processor: reading a commands do something with them.'
        self.frame     = frame
        self.event     = event
        self.event_arg = event_arg

        filename = frame.f_code.co_filename
        lineno   = frame.f_lineno
        if sys.version_info[0] == 2 and sys.version_info[1] <= 4:
            line = None
        else:
            line = linecache.getline(filename, lineno, frame.f_globals)
            pass
        if not line:
            opts = {'output': 'plain',
                    'reload_on_change': self.settings('reload'),
                    'strip_nl': False}
            line = pyficache.getline(filename, lineno, opts)
        self.current_source_text = line
        if self.settings('skip') is not None:
            if Mbytecode.is_def_stmt(line, frame):
                return True
            if Mbytecode.is_class_def(line, frame):
                return True
            pass
        self.thread_name = Mthread.current_thread_name()
        self.frame_thread_name = self.thread_name
        self.set_prompt(prompt)
        self.process_commands()
        if filename == '<string>': pyficache.remove_remap_file('<string>')
        return True
Exemplo n.º 4
0
    def event_processor(self, frame, event, event_arg, prompt='trepan2'):
        'command event processor: reading a commands do something with them.'
        self.frame = frame
        self.event = event
        self.event_arg = event_arg

        filename = frame.f_code.co_filename
        lineno = frame.f_lineno
        if sys.version_info[0] == 2 and sys.version_info[1] <= 4:
            line = None
        else:
            line = linecache.getline(filename, lineno, frame.f_globals)
            pass
        if not line:
            opts = {
                'output': 'plain',
                'reload_on_change': self.settings('reload'),
                'strip_nl': False
            }
            line = pyficache.getline(filename, lineno, opts)
        self.current_source_text = line
        if self.settings('skip') is not None:
            if Mbytecode.is_def_stmt(line, frame):
                return True
            if Mbytecode.is_class_def(line, frame):
                return True
            pass
        self.thread_name = Mthread.current_thread_name()
        self.frame_thread_name = self.thread_name
        self.set_prompt(prompt)
        self.process_commands()
        if filename == '<string>': pyficache.remove_remap_file('<string>')
        return True
Exemplo n.º 5
0
    def event_processor(self, frame, event, event_arg, prompt="trepan2"):
        "command event processor: reading a commands do something with them."
        self.frame = frame
        self.event = event
        self.event_arg = event_arg

        filename = frame.f_code.co_filename
        lineno = frame.f_lineno
        if sys.version_info[0] == 2 and sys.version_info[1] <= 4:
            line = None
        else:
            line = linecache.getline(filename, lineno, frame.f_globals)
            pass
        if not line:
            opts = {
                "output": "plain",
                "reload_on_change": self.settings("reload"),
                "strip_nl": False,
            }
            line = pyficache.getline(filename, lineno, opts)
        self.current_source_text = line
        if self.settings("skip") is not None:
            if Mbytecode.is_def_stmt(line, frame):
                return True
            if Mbytecode.is_class_def(line, frame):
                return True
            pass
        self.thread_name = Mthread.current_thread_name()
        self.frame_thread_name = self.thread_name
        self.set_prompt(prompt)
        self.process_commands()
        if filename == "<string>":
            pyficache.remove_remap_file("<string>")
        return True
Exemplo n.º 6
0
 def test_remap(self):
     pyficache.remap_file(__file__, 'another-name')
     line1 = pyficache.getline('another-name', 1)
     line2 = pyficache.getline(__file__, 1)
     self.assertEqual(line1, line2,
                      'Both lines should be the same via remap_file')
     filename = pyficache.remove_remap_file('another-name')
     self.assertEqual(filename, __file__)
     filename = pyficache.remove_remap_file('another-name')
     self.assertEqual(filename, None)
     return
Exemplo n.º 7
0
    def event_processor(self, frame, event, event_arg, prompt="trepan3k"):
        """
        command event processor: reading a commands do something with them.

        See https://docs.python.org/3/library/sys.html#sys.settrace
        for how this protocol works and what the events means.

        Of particular note those is what we return:

            The local trace function should return a reference to
            itself (or to another function for further tracing in that
            scope), or None to turn off tracing in that scope.

            If there is any error occurred in the trace function, it
            will be unset, just like settrace(None) is called.
        """

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

        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
        if self.settings("skip") is not None:
            if is_def_stmt(line, frame):
                return self.event_processor
            if is_class_def(line, frame):
                return self.event_processor
            pass
        self.thread_name = Mthread.current_thread_name()
        self.frame_thread_name = self.thread_name
        self.set_prompt(prompt)
        self.process_commands()
        if filename == "<string>":
            pyficache.remove_remap_file("<string>")
        return self.event_processor
Exemplo n.º 8
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