示例#1
0
    // This is called when the python extension is first loaded.
    public static void LoadExtension()
    {
        WriteOutput("IronPython-Mdbg Extension loaded");

        g_python            = new IronPython.Hosting.PythonEngine();
        g_pythonInteractive = new PythonCommandLine(g_python);

        string ver = g_python.GetType().Assembly.GetName().Version.ToString();

        WriteOutput(MDbgOutputConstants.Ignore, "Binding against Iron Python version: " + ver);

        // Get original load command, for use in python load command.
        g_origLoadCmd = Shell.Commands.Lookup("load");

        // Add Python extension commands to Shell.Commands.
        MDbgAttributeDefinedCommand.AddCommandsFromType(Shell.Commands, typeof(PythonExt));

        // Add the current directory to the python engine search path.

        g_python.AddToPath(Environment.CurrentDirectory);

        // Tell Python about some key objects in Mdbg. Python can then reflect over these objects.
        // These variables live at some special "main" scope. Python Modules imported via python "import" command
        // can't access them. Use PythonEngine.ExecuteFile() to import files such that they can access these vars.
        g_python.Globals.Add("CommandBase", IronPython.Runtime.Types.ReflectedType.FromType(typeof(CommandBase)));

        // Hook input + output. This is redirecting pythons 'sys.stdout, sys.stdin, sys.stderr'
        // This connects python's sys.stdout --> Stream --> Mdbg console.
        MDbgStream s = new MDbgStream();

        // New codepaths for IronPython 1.0
        g_python.SetStandardInput(s);
        g_python.SetStandardOutput(s);
        g_python.SetStandardError(s);
    }
示例#2
0
        public void Add(IMDbgCommand command)
        {
            if (command == null)
            {
                Debug.Assert(false);
                throw new Exception();
            }

            if (command.MinimumAbbrev > command.CommandName.Length)
            {
                throw new MDbgShellException("Cannot add command '" + command.CommandName + "'. Abbreviation is " +
                    command.MinimumAbbrev + " characters. Can't be more than " + command.CommandName.Length);
            }

            List<IMDbgCommand> cmdList;
            if (!m_commands.TryGetValue(command.CommandName, out cmdList))
            {
                // The command doesn't have an entry in the command list, we must create a new one.
                cmdList = new List<IMDbgCommand>();
                cmdList.Add(command);   // create a list for this command (this list allows overriding commands)
                m_commands.Add(command.CommandName, cmdList);
            }
            else
            {
                // We are reloading an extension, so remove the previous command and add it to the end of
                // the list.
                Debug.Assert(!cmdList.Contains(command), "Previous command was not unloaded properly");
                cmdList.Add(command);
                m_commands[command.CommandName] = cmdList;  // update
            }
        }
示例#3
0
文件: Mdbg.cs 项目: VE-2016/VE-2016
        public void Remove(IMDbgCommand command)
        {
            if (command == null)
            {
                Debug.Assert(false);
                throw new Exception();
            }

            if (command.MinimumAbbrev > command.CommandName.Length)
            {
                throw new MDbgShellException("Cannot remove command '" + command.CommandName + "'. Abbreviation is " +
                                             command.MinimumAbbrev + " characters. Can't be more than " + command.CommandName.Length);
            }

            // Extensions are allowed to override a command, but we want to make sure that we retain all original commands
            // We don't delete any previously defined commands
            List <IMDbgCommand> cmdList;

            if (!m_commands.TryGetValue(command.CommandName, out cmdList))
            {
                // We shouldn't ever try to remove a command that hasn't been added
                Debug.Assert(false, "Attempted to remove a command that does not exist");
            }
            else
            {
                // We are reloading an extension, so remove the previous command and add it to the end of
                // the list.
                cmdList.Remove(command);
            }
        }
示例#4
0
    // Returns a list of all MDbg commands defined in loaded python scripts or at the command line.
    private static List <IMDbgCommand> RescanPythonCommands()
    {
        object r = g_python.Evaluate("dir()");

        IronPython.Runtime.List namesList = r as IronPython.Runtime.List;
        if (namesList == null)
        {
            return(null);
        }

        List <IMDbgCommand> scannedCommands = new List <IMDbgCommand>();

        foreach (string name in namesList)
        {
            // test if it is an mdbg command
            try
            {
                r = g_python.Evaluate(string.Format("{0}.__doc__", name));
            }
            catch
            {
                r = null;
            }
            string       docString = r as string;
            IMDbgCommand mdbgCmd   = ParseCommandDocString(name, docString);
            if (mdbgCmd != null)
            {
                scannedCommands.Add(mdbgCmd);
            }
        }
        return(scannedCommands);
    }
示例#5
0
文件: PythonExt.cs 项目: Orvid/Cosmos
    // This is called when the python extension is first loaded.
    public static void LoadExtension()
    {
        WriteOutput("IronPython-Mdbg Extension loaded");

        g_python = new IronPython.Hosting.PythonEngine();
        g_pythonInteractive = new PythonCommandLine(g_python);

        string ver = g_python.GetType().Assembly.GetName().Version.ToString();
        WriteOutput(MDbgOutputConstants.Ignore, "Binding against Iron Python version: " + ver);

        // Get original load command, for use in python load command.
        g_origLoadCmd = Shell.Commands.Lookup("load");

        // Add Python extension commands to Shell.Commands.
        MDbgAttributeDefinedCommand.AddCommandsFromType(Shell.Commands, typeof(PythonExt));

        // Add the current directory to the python engine search path.
        
        g_python.AddToPath(Environment.CurrentDirectory);

        // Tell Python about some key objects in Mdbg. Python can then reflect over these objects.
        // These variables live at some special "main" scope. Python Modules imported via python "import" command
        // can't access them. Use PythonEngine.ExecuteFile() to import files such that they can access these vars.
        g_python.Globals.Add("CommandBase", IronPython.Runtime.Types.ReflectedType.FromType(typeof(CommandBase)));

        // Hook input + output. This is redirecting pythons 'sys.stdout, sys.stdin, sys.stderr' 
        // This connects python's sys.stdout --> Stream --> Mdbg console.
        MDbgStream s = new MDbgStream();

        // New codepaths for IronPython 1.0
        g_python.SetStandardInput(s);
        g_python.SetStandardOutput(s);
        g_python.SetStandardError(s);
    }
示例#6
0
        public void Add(IMDbgCommand command)
        {
            if (command == null)
            {
                Debug.Assert(false);
                throw new Exception();
            }

            if (command.MinimumAbbrev > command.CommandName.Length)
            {
                throw new MDbgShellException("Cannot add command '" + command.CommandName + "'. Abbreviation is " +
                                             command.MinimumAbbrev + " characters. Can't be more than " +
                                             command.CommandName.Length);
            }


            // extensions are allowed to override a command, i.e. this means we will delete previously defined command
            // with such name.
            foreach (IMDbgCommand c in m_commands)
            {
                if (c.CommandName.Equals(command.CommandName))
                {
                    m_commands.Remove(c);
                    break; // there should never be 2 command with same name in a collection
                    // therefore we can break-out from the search.
                }
            }

            m_commands.Add(command);
            m_needSorting = true;
        }
示例#7
0
文件: Screen.cs 项目: cobergmd/cdbg
        private void ProcessCommandLine()
        {
            try
            {
                IMDbgCommand dbgcmd  = null;
                string       cmdArgs = null;
                string       cmdLine = _Prompt.ToString();
                if (string.IsNullOrEmpty(cmdLine))
                {
                    return;
                }

                _CmdHistory.Add(cmdLine);
                _CmdHistoryIdx = 0;
                _Shell.Commands.ParseCommand(cmdLine, out dbgcmd, out cmdArgs);
                _Prompt.EraseToEnd();
                dbgcmd.Execute(cmdArgs);
                DisplaySource();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    WriteError(ex.InnerException.Message);
                }
                else
                {
                    WriteError(ex.Message);
                }
            }
        }
示例#8
0
文件: Mdbg.cs 项目: VE-2016/VE-2016
        public void Add(IMDbgCommand command)
        {
            if (command == null)
            {
                Debug.Assert(false);
                throw new Exception();
            }

            if (command.MinimumAbbrev > command.CommandName.Length)
            {
                throw new MDbgShellException("Cannot add command '" + command.CommandName + "'. Abbreviation is " +
                                             command.MinimumAbbrev + " characters. Can't be more than " + command.CommandName.Length);
            }

            List <IMDbgCommand> cmdList;

            if (!m_commands.TryGetValue(command.CommandName, out cmdList))
            {
                // The command doesn't have an entry in the command list, we must create a new one.
                cmdList = new List <IMDbgCommand>();
                cmdList.Add(command);   // create a list for this command (this list allows overriding commands)
                m_commands.Add(command.CommandName, cmdList);
            }
            else
            {
                // We are reloading an extension, so remove the previous command and add it to the end of
                // the list.
                Debug.Assert(!cmdList.Contains(command), "Previous command was not unloaded properly");
                cmdList.Add(command);
                m_commands[command.CommandName] = cmdList;  // update
            }
        }
示例#9
0
        /// <summary>
        /// Initializes a new instance of the <b>CommandExecutedEventArgs</b> class.
        /// </summary>
        /// <param name="sender">The sender for this event</param>
        /// <param name="command">The command that is getting executed</param>
        /// <param name="arguments">The arguments for the command</param>
        /// <param name="movementCommand">Is this a movement command.</param>
        public CommandExecutedEventArgs(IMDbgShell sender, IMDbgCommand command, string arguments,
                                        bool movementCommand)
        {
            Debug.Assert(sender != null);
            Debug.Assert((command == null) == (arguments == null));

            m_sender = sender;
            m_command = command;
            m_arguments = arguments;
            m_movementCommand = movementCommand;
        }
示例#10
0
        public IMDbgCommand Lookup(string commandName)
        {
            ArrayList al = new ArrayList();

            foreach (List <IMDbgCommand> cmdList in m_commands.Values)
            {
                if (cmdList.Count < 1)
                {
                    // We may have unloaded an extension which can create empty entries in m_commands.  Continue
                    // to list valid commands.
                    continue;
                }
                // The last command in the list points to the last command that was added and ALWAYS points
                // to the command that we should execute
                IMDbgCommand cmd = cmdList[cmdList.Count - 1];

                if (commandName.Length < cmd.MinimumAbbrev)
                {
                    continue;
                }

                if (String.Compare(cmd.CommandName, 0, commandName, 0, commandName.Length, true,
                                   CultureInfo.CurrentUICulture // command names could get localized in the future
                                   ) == 0)
                {
                    if (cmd.CommandName.Length == commandName.Length)
                    {
                        // if we have a perfect match for the command, then we return the command without
                        // taking into account any other partial command completitions.
                        return(cmd);
                    }
                    al.Add(cmd);
                }
            }


            if (al.Count == 0)
            {
                throw new MDbgShellException("Command '" + commandName + "' not found.");
            }
            else if (al.Count == 1)
            {
                return((IMDbgCommand)al[0]);
            }
            else
            {
                StringBuilder s = new StringBuilder("Command prefix too short. \nPossible completitions:");
                foreach (IMDbgCommand c in al)
                {
                    s.Append("\n").Append(c.CommandName);
                }
                throw new MDbgShellException(s.ToString());
            }
        }
示例#11
0
        /// <summary>
        /// Initializes a new instance of the <b>CommandExecutedEventArgs</b> class.
        /// </summary>
        /// <param name="sender">The sender for this event</param>
        /// <param name="command">The command that is getting executed</param>
        /// <param name="arguments">The arguments for the command</param>
        /// <param name="movementCommand">Is this a movement command.</param>
        public CommandExecutedEventArgs(IMDbgShell sender, IMDbgCommand command, string arguments,
                                        bool movementCommand)
        {
            Debug.Assert(sender != null);
            Debug.Assert((command == null) == (arguments == null));

            m_sender          = sender;
            m_command         = command;
            m_arguments       = arguments;
            m_movementCommand = movementCommand;
        }
示例#12
0
文件: Mdbg.cs 项目: VE-2016/VE-2016
        public void ParseCommand(string commandLineText, out IMDbgCommand command, out string commandArguments)
        {
            commandLineText = commandLineText.Trim();
            int n = commandLineText.Length;
            int i = 0;

            while (i < n && !Char.IsWhiteSpace(commandLineText, i))
            {
                i++;
            }
            string cmdName = commandLineText.Substring(0, i);

            commandArguments = commandLineText.Substring(i).Trim();
            command          = Lookup(cmdName);
        }
示例#13
0
        int IComparable.CompareTo(object obj)
        {
            MDbgPythonCommand pc = obj as MDbgPythonCommand;

            if (pc != null)
            {
                return(string.Compare(this.m_funcName, pc.m_funcName));
            }
            else
            {
                IMDbgCommand mc = obj as IMDbgCommand;
                Debug.Assert(mc != null);
                if (mc == null)
                {
                    return(1);
                }
                return(-mc.CompareTo(this));
            }
        }
示例#14
0
 public void ParseCommand(string commandLineText, out IMDbgCommand command, out string commandArguments)
 {
     try
     {
         commandLineText = commandLineText.Trim();
         int n = commandLineText.Length;
         int i = 0;
         while (i < n && !Char.IsWhiteSpace(commandLineText, i))
         {
             i++;
         }
         string cmdName = commandLineText.Substring(0, i);
         commandArguments = commandLineText.Substring(i).Trim();
         command          = Lookup(cmdName);
     }
     catch (Exception ex)
     {
         OriginalMDbgMessages.WriteLine("In ParseCommand, Exception while executing " + commandLineText + "    :   " +
                                        ex.Message + "\n\n" + ex.StackTrace);
         command          = null;
         commandArguments = null;
     }
 }
        public void Add(IMDbgCommand command)
        {
            if (command == null)
            {
                Debug.Assert(false);
                throw new Exception();
            }

            if (command.MinimumAbbrev > command.CommandName.Length)
            {
                throw new MDbgShellException("Cannot add command '" + command.CommandName + "'. Abbreviation is " +
                                             command.MinimumAbbrev + " characters. Can't be more than " +
                                             command.CommandName.Length);
            }


            // extensions are allowed to override a command, i.e. this means we will delete previously defined command
            // with such name.
            foreach (IMDbgCommand c in m_commands)
            {
                if (c.CommandName.Equals(command.CommandName))
                {
                    m_commands.Remove(c);
                    break; // there should never be 2 command with same name in a collection
                    // therefore we can break-out from the search.
                }
            }

            m_commands.Add(command);
            m_needSorting = true;
        }
示例#16
0
文件: Screen.cs 项目: cobergmd/cdbg
        public void Draw()
        {
            int winHeight = Console.WindowHeight;

            DrawMenu(winHeight - 1);
            _Prompt.Draw(winHeight - 2);

            bool           refreshViewer = false;
            bool           refreshList   = false;
            ConsoleKeyInfo cki           = Console.ReadKey(true);

            if (cki != null)
            {
                if (cki.Key == ConsoleKey.Enter) // evaluate
                {
                    if (_FileList.IsVisible)
                    {
                        if (_SelectedCmd != null)
                        {
                            _Prompt.Load(_SelectedCmd);
                            _SelectedCmd = null;
                        }
                        _FileList.Close();
                    }
                    ProcessCommandLine();
                }
                else if (cki.Key == ConsoleKey.Tab && (cki.Modifiers & ConsoleModifiers.Control) != 0)
                {
                    if (_CurrentBufferIdx == _Buffers.Count - 1)
                    {
                        _CurrentBufferIdx = 0;
                    }
                    else
                    {
                        _CurrentBufferIdx += 1;
                    }

                    _CurrentView  = _Buffers[_CurrentBufferIdx];
                    refreshViewer = true;
                }
                else if (cki.Key == ConsoleKey.Tab)
                {
                    if (_FileList.IsVisible && _SelectedCmd != null)
                    {
                        _Prompt.Load(_SelectedCmd);
                        _FileList.Close();
                        _SelectedCmd  = null;
                        refreshViewer = true;
                    }
                }
                else if (cki.Key == ConsoleKey.F2)
                {
                    DrawVariableViewer();
                }
                else if (cki.Key == ConsoleKey.F4)
                {
                    Stop();
                }
                else if (cki.Key == ConsoleKey.F10)
                {
                    string       cmdArgs = null;
                    IMDbgCommand dbgcmd  = null;
                    _Shell.Commands.ParseCommand("n", out dbgcmd, out cmdArgs);
                    dbgcmd.Execute(cmdArgs);
                }
                else if (cki.Key == ConsoleKey.F12)
                {
                    if (_CurrentMenu == _AltMenu)
                    {
                        _CurrentMenu = _MainMenu;
                    }
                    else
                    {
                        _CurrentMenu = _AltMenu;
                    }
                }
                else if (cki.Key == ConsoleKey.Home)
                {
                    _Prompt.MoveToHome();
                }
                else if (cki.Key == ConsoleKey.End)
                {
                    _Prompt.MoveToEnd();
                }
                else if (cki.Key == ConsoleKey.Backspace)
                {
                    _Prompt.Backspace();
                    refreshList = true;
                }
                else if (cki.Key == ConsoleKey.Delete)
                {
                    _Prompt.Delete();
                    refreshList = true;
                }
                else if (cki.Key == ConsoleKey.RightArrow)
                {
                    _Prompt.MoveRight();
                }
                else if (cki.Key == ConsoleKey.LeftArrow)
                {
                    _Prompt.MoveLeft();
                }
                else if (cki.Key == ConsoleKey.Escape)
                {
                    _FileList.Close();
                    refreshViewer = true;
                }
                else if (cki.Key == ConsoleKey.UpArrow)
                {
                    if ((cki.Modifiers & ConsoleModifiers.Control) != 0)
                    {
                        if (_CurrentView != null)
                        {
                            _CurrentView.DecreaseLine(1);
                            refreshViewer = true;
                        }
                    }
                    else
                    {
                        if (_FileList.IsVisible)
                        {
                            _SelectedCmd = _FileList.MoveSelection(FileList.ArrowMovement.Up);
                            refreshList  = true;
                        }
                        else
                        {
                            // update prompt with command history
                            _Prompt.Load(GetNextCommand());
                        }
                    }
                }
                else if (cki.Key == ConsoleKey.DownArrow)
                {
                    if ((cki.Modifiers & ConsoleModifiers.Control) != 0)
                    {
                        if (_CurrentView != null)
                        {
                            _CurrentView.IncreaseLine(1);
                            refreshViewer = true;
                        }
                    }
                    else
                    {
                        if (_FileList.IsVisible)
                        {
                            _SelectedCmd = _FileList.MoveSelection(FileList.ArrowMovement.Down);
                            refreshList  = true;
                        }
                        else
                        {
                            // update prompt with command history
                            _Prompt.Load(GetPreviousCommand());
                        }
                    }
                }
                else if (cki.Key == ConsoleKey.PageDown)
                {
                    if (_CurrentView != null)
                    {
                        _CurrentView.IncreasePage();
                        refreshViewer = true;
                    }
                }
                else if (cki.Key == ConsoleKey.PageUp)
                {
                    if (_CurrentView != null)
                    {
                        _CurrentView.DecreasePage();
                        refreshViewer = true;
                    }
                }
                else // add to buffer
                {
                    _Prompt.AddCharacter(cki.KeyChar);
                    refreshList = true;
                }
            }
            if (refreshList)
            {
                _FileList.Draw(_Prompt.ToString());
            }
            if (_CurrentView != null && refreshViewer)
            {
                _CurrentView.Draw(0, Console.WindowHeight - 3);
            }
        }
示例#17
0
文件: Mdbg.cs 项目: VE-2016/VE-2016
        //////////////////////////////////////////////////////////////////////////////////
        //
        // Private implementation
        //
        //////////////////////////////////////////////////////////////////////////////////

        private int RunInputLoop()
        {
            // Run the event loop
            string       input;
            IMDbgCommand cmd     = null;
            string       cmdArgs = null;

            int stopCount = -1;

            while (m_run && IO.ReadCommand(out input))
            {
                try
                {
                    if (Debugger.Processes.HaveActive)
                    {
                        stopCount = Debugger.Processes.Active.StopCounter;
                    }

                    if (input == null || input.Length == 0)
                    {
                        if (cmd == null || !cmd.IsRepeatable)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        Commands.ParseCommand(input, out cmd, out cmdArgs);
                    }
                    cmd.Execute(cmdArgs);

                    int  newStopCount    = Debugger.Processes.HaveActive ? Debugger.Processes.Active.StopCounter : Int32.MaxValue;
                    bool movementCommand = newStopCount > stopCount;
                    stopCount = newStopCount;

                    if (OnCommandExecuted != null)
                    {
                        OnCommandExecuted(this, new CommandExecutedEventArgs(this, cmd, cmdArgs, movementCommand));
                    }

                    newStopCount    = Debugger.Processes.HaveActive ? Debugger.Processes.Active.StopCounter : Int32.MaxValue;
                    movementCommand = newStopCount > stopCount;

                    while (newStopCount > stopCount)
                    {
                        stopCount = newStopCount;

                        if (OnCommandExecuted != null)
                        {
                            OnCommandExecuted(this, new CommandExecutedEventArgs(this, null, null, movementCommand));
                        }

                        newStopCount    = Debugger.Processes.HaveActive ? Debugger.Processes.Active.StopCounter : Int32.MaxValue;
                        movementCommand = newStopCount > stopCount;
                    }
                    stopCount = newStopCount;
                }
                catch (Exception e)
                {
                    ReportException(e);
                }
            } // end while
            return(m_exitCode);
        }
示例#18
0
 public void ParseCommand(string commandLineText, out IMDbgCommand command, out string commandArguments)
 {
     commandLineText = commandLineText.Trim();
     int n = commandLineText.Length;
     int i = 0;
     while (i < n && !Char.IsWhiteSpace(commandLineText, i))
     {
         i++;
     }
     string cmdName = commandLineText.Substring(0, i);
     commandArguments = commandLineText.Substring(i).Trim();
     command = Lookup(cmdName);
 }
示例#19
0
        public void Remove(IMDbgCommand command)
        {
            if (command == null)
            {
                Debug.Assert(false);
                throw new Exception();
            }

            if (command.MinimumAbbrev > command.CommandName.Length)
            {
                throw new MDbgShellException("Cannot remove command '" + command.CommandName + "'. Abbreviation is " +
                    command.MinimumAbbrev + " characters. Can't be more than " + command.CommandName.Length);
            }

            // Extensions are allowed to override a command, but we want to make sure that we retain all original commands
            // We don't delete any previously defined commands
            List<IMDbgCommand> cmdList;
            if (!m_commands.TryGetValue(command.CommandName, out cmdList))
            {
                // We shouldn't ever try to remove a command that hasn't been added
                Debug.Assert(false, "Attempted to remove a command that does not exist");
            }
            else
            {
                // We are reloading an extension, so remove the previous command and add it to the end of
                // the list.
                cmdList.Remove(command);
            }
        }
 public void ParseCommand(string commandLineText, out IMDbgCommand command, out string commandArguments)
 {
     try
     {
         commandLineText = commandLineText.Trim();
         int n = commandLineText.Length;
         int i = 0;
         while (i < n && !Char.IsWhiteSpace(commandLineText, i))
         {
             i++;
         }
         string cmdName = commandLineText.Substring(0, i);
         commandArguments = commandLineText.Substring(i).Trim();
         command = Lookup(cmdName);
     }
     catch (Exception ex)
     {
         OriginalMDbgMessages.WriteLine("In ParseCommand, Exception while executing " + commandLineText + "    :   " +
                               ex.Message + "\n\n" + ex.StackTrace);
         command = null;
         commandArguments = null;
     }
 }