示例#1
0
 def eval(self, arg):
     """Eval string arg in the current frame context."""
     try:
         return eval(arg, self.curframe.f_globals,
                     self.curframe.f_locals)
     except:
         t, v = sys.exc_info()[:2]
         if isinstance(t, str):
             exc_type_name = t
             pass
         else: exc_type_name = t.__name__
         Mmsg.errmsg(self, str("%s: %s" % (exc_type_name, arg)))
         raise
     return None  # Not reached
示例#2
0
 def eval(self, arg):
     """Eval string arg in the current frame context."""
     try:
         return eval(arg, self.curframe.f_globals, self.curframe.f_locals)
     except:
         t, v = sys.exc_info()[:2]
         if isinstance(t, str):
             exc_type_name = t
             pass
         else:
             exc_type_name = t.__name__
         Mmsg.errmsg(self, str("%s: %s" % (exc_type_name, arg)))
         raise
     return None  # Not reached
示例#3
0
 def ok_for_running(self, cmd_obj, name, cmd_hash):
     '''We separate some of the common debugger command checks here:
     whether it makes sense to run the command in this execution state,
     if the command has the right number of arguments and so on.
     '''
     if hasattr(cmd_obj, 'execution_set'):
         if not (self.core.execution_status in cmd_obj.execution_set):
             part1 = ("Command '%s' is not available for execution "
                      "status:" % name)
             Mmsg.errmsg(
                 self,
                 Mmisc.wrapped_lines(part1, self.core.execution_status,
                                     self.debugger.settings['width']))
             return False
         pass
     if self.frame is None and cmd_obj.need_stack:
         self.intf[-1].errmsg("Command '%s' needs an execution stack." %
                              name)
         return False
     return True
示例#4
0
 def ok_for_running(self, cmd_obj, name, cmd_hash):
     '''We separate some of the common debugger command checks here:
     whether it makes sense to run the command in this execution state,
     if the command has the right number of arguments and so on.
     '''
     if hasattr(cmd_obj, 'execution_set'):
         if not (self.core.execution_status in cmd_obj.execution_set):
             part1 = ("Command '%s' is not available for execution "
                      "status:" % name)
             Mmsg.errmsg(self,
                         Mmisc.
                         wrapped_lines(part1,
                                         self.core.execution_status,
                                         self.debugger.settings['width']))
             return False
         pass
     if self.frame is None and cmd_obj.need_stack:
         self.intf[-1].errmsg("Command '%s' needs an execution stack."
                              % name)
         return False
     return True
示例#5
0
    def adjust_frame(self, pos, absolute_pos):
        """Adjust stack frame by pos positions. If absolute_pos then
        pos is an absolute number. Otherwise it is a relative number.

        A negative number indexes from the other end."""
        if not self.curframe:
            Mmsg.errmsg(self, "No stack.")
            return

        # Below we remove any negativity. At the end, pos will be
        # the new value of self.curindex.
        if absolute_pos:
            if pos >= 0:
                pos = len(self.stack) - pos - 1
            else:
                pos = -pos - 1
        else:
            pos += self.curindex

        if pos < 0:
            Mmsg.errmsg(self,
                        "Adjusting would put us beyond the oldest frame.")
            return
        elif pos >= len(self.stack):
            Mmsg.errmsg(self,
                        "Adjusting would put us beyond the newest frame.")
            return

        self.curindex = pos
        self.curframe = self.stack[self.curindex][0]
        self.print_location()
        self.list_lineno = None
        return
示例#6
0
    def adjust_frame(self, pos, absolute_pos):
        """Adjust stack frame by pos positions. If absolute_pos then
        pos is an absolute number. Otherwise it is a relative number.

        A negative number indexes from the other end."""
        if not self.curframe:
            Mmsg.errmsg(self, "No stack.")
            return

        # Below we remove any negativity. At the end, pos will be
        # the new value of self.curindex.
        if absolute_pos:
            if pos >= 0:
                pos = len(self.stack)-pos-1
            else:
                pos = -pos-1
        else:
            pos += self.curindex

        if pos < 0:
            Mmsg.errmsg(self,
                        "Adjusting would put us beyond the oldest frame.")
            return
        elif pos >= len(self.stack):
            Mmsg.errmsg(self,
                        "Adjusting would put us beyond the newest frame.")
            return

        self.curindex = pos
        self.curframe = self.stack[self.curindex][0]
        self.print_location()
        self.list_lineno = None
        return
示例#7
0
 def exec_line(self, line):
     if self.curframe:
         local_vars = self.curframe.f_locals
         global_vars = self.curframe.f_globals
     else:
         local_vars = None
         # FIXME: should probably have place where the
         # user can store variables inside the debug session.
         # The setup for this should be elsewhere. Possibly
         # in interaction.
         global_vars = None
     try:
         code = compile(line + '\n', '"%s"' % line, 'single')
         exec code in global_vars, local_vars
     except:
         t, v = sys.exc_info()[:2]
         if isinstance(t, types.StringType):
             exc_type_name = t
         else: exc_type_name = t.__name__
         Mmsg.errmsg(self, '%s: %s' % (str(exc_type_name), str(v)))
         pass
     return
示例#8
0
 def exec_line(self, line):
     if self.curframe:
         local_vars = self.curframe.f_locals
         global_vars = self.curframe.f_globals
     else:
         local_vars = None
         # FIXME: should probably have place where the
         # user can store variables inside the debug session.
         # The setup for this should be elsewhere. Possibly
         # in interaction.
         global_vars = None
     try:
         code = compile(line + "\n", '"%s"' % line, "single")
         exec(code, global_vars, local_vars)
     except:
         t, v = sys.exc_info()[:2]
         if isinstance(t, bytes):
             exc_type_name = t
         else:
             exc_type_name = t.__name__
         Mmsg.errmsg(self, "%s: %s" % (str(exc_type_name), str(v)))
         pass
     return
示例#9
0
    def process_command(self):
        # process command
        self.response = {"errs": [], "msg": []}
        cmd_hash = self.intf[-1].read_command()

        # FIXME: put this into a routine
        if not isinstance(cmd_hash, dict):
            Mmsg.errmsg(
                self,
                "invalid input, expecting a hash: %s" % cmd_hash,
                {"set_name": True},
            )
            self.intf[-1].msg(self.response)
            return False
        if "command" not in cmd_hash:
            Mmsg.errmsg(
                self,
                "invalid input, expecting a 'command' key: %s" % cmd_hash,
                {"set_name": True},
            )
            self.intf[-1].msg(self.response)
            return False

        self.cmd_name = cmd_hash["command"]
        cmd_name = resolve_name(self, self.cmd_name)
        if cmd_name:
            cmd_obj = self.commands[cmd_name]
            if self.ok_for_running(cmd_obj, cmd_name, cmd_hash):
                try:
                    self.response["name"] = cmd_name
                    result = cmd_obj.run(cmd_hash)
                    self.intf[-1].msg(self.response)
                    if result:
                        return result
                except (Mexcept.DebuggerQuit, Mexcept.DebuggerRestart,
                        SystemExit):
                    # Let these exceptions propagate through
                    raise
                except:
                    Mmsg.errmsg(self,
                                "INTERNAL ERROR: " + traceback.format_exc())
                    pass
                pass
            else:
                self.undefined_cmd(cmd_name)
                pass
            pass
        return False
示例#10
0
    def process_command(self):
        # process command
        self.response = {'errs': [], 'msg': []}
        cmd_hash = self.intf[-1].read_command()

        # FIXME: put this into a routine
        if isinstance(cmd_hash, types.DictType):
            Mmsg.errmsg(self, "invalid input, expecting a hash: %s" % cmd_hash,
                        {'set_name': True})
            self.intf[-1].msg(self.response)
            return False
        if 'command' not in cmd_hash:
            Mmsg.errmsg(self,
                        "invalid input, expecting a 'command' key: %s" %
                        cmd_hash,
                        {'set_name': True})
            self.intf[-1].msg(self.response)
            return False

        self.cmd_name = cmd_hash['command']
        cmd_name = resolve_name(self, self.cmd_name)
        if cmd_name:
            cmd_obj = self.commands[cmd_name]
            if self.ok_for_running(cmd_obj, cmd_name, cmd_hash):
                try:
                    self.response['name'] = cmd_name
                    result = cmd_obj.run(cmd_hash)
                    self.intf[-1].msg(self.response)
                    if result: return result
                except (Mexcept.DebuggerQuit,
                        Mexcept.DebuggerRestart, SystemExit):
                    # Let these exceptions propagate through
                    raise
                except:
                    Mmsg.errmsg(self, "INTERNAL ERROR: " +
                                traceback.format_exc())
                    pass
                pass
            else:
                self.undefined_cmd(cmd_name)
                pass
            pass
        return False
示例#11
0
 def undefined_cmd(self, cmd):
     """Error message when a command doesn't exist"""
     Mmsg.errmsg(self, 'Undefined command: "%s". Try "help".' % cmd)
     return
示例#12
0
 def undefined_cmd(self, cmd):
     """Error message when a command doesn't exist"""
     Mmsg.errmsg(self, 'Undefined command: "%s". Try "help".' % cmd)
     return