示例#1
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);
                }
            }
        }
示例#2
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);
        }
示例#3
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);
            }
        }