Exemple #1
0
        public override int Execute(ICommandContext ctx, string[] args, char[] flags)
        {
            if (!this.VerifyArgsCount(args, 0, 1))
            {
                this.PrintUsage(ctx);
                return(1);
            }

            if (args.Length == 0)
            {
                IList <string> avaiCommands = this.commands.Keys.ToList();
                avaiCommands.Insert(0, "echo");
                avaiCommands.Insert(0, "clear");
                avaiCommands.Insert(0, "help");

                ctx.SendOutput(String.Join("\n", avaiCommands.ToArray()));
            }
            else if (args.Length == 1)
            {
                if (this.commands.ContainsKey(args[0].ToLower()))
                {
                    IDebugCommand cmd = this.commands[args[0].ToLower()];

                    ctx.SendOutput(String.Format("Usage:\t{0}\n{1}", cmd.GetUsage(), cmd.GetHelp()));
                    return(0);
                }

                ctx.SendOutput(String.Format("Cannot find any help information for debug command {0}.", args[0]));
                return(1);
            }

            return(0);
        }
Exemple #2
0
 public CommandContext(string rawCommand, IDebugCommand command, string[] args, char[] flags)
 {
     this.rawCommand   = rawCommand;
     this.command      = command;
     this.commandArgs  = args;
     this.commandFlags = flags;
 }
Exemple #3
0
        private byte[] WaitForData(IDebugCommand cmd)
        {
            var cmdTask = _debugServer.AddCommand(cmd);

            cmdTask.Wait();
            return(cmdTask.Result);
        }
Exemple #4
0
        protected byte[] WaitForCommand(IDebugCommand command)
        {
            var task = _server.AddCommand(command);

            task.Wait();
            return(task.Result);
        }
Exemple #5
0
        public Task <byte[]> AddCommand(IDebugCommand cmd)
        {
            if (_state == DebuggerState.NotConnected || _state == DebuggerState.Stopping)
            {
                return(Task.FromResult <byte[]>(null));
            }

            var wrapper = new DebugCommandWrapper(cmd);

            _commands.Enqueue(wrapper);
            return(wrapper.TCS.Task);
        }
Exemple #6
0
        internal void RegisterCommandCallback(string commandName, IDebugCommand command)
        {
            commandName = commandName.ToLower();

            if (this.coreCommands.Contains(commandName))
            {
                throw new ArgumentException("Cannot overwrite a core command.", "commandName");
            }

            if (this.commandsTable.ContainsKey(commandName))
            {
                this.commandsTable[commandName] = command;
                return;
            }

            this.commandsTable.Add(commandName.ToLower(), command);
        }
Exemple #7
0
        private void ExecuteCommandWithClearState(IDebugCommand command)
        {
            InDebug = false;
            _state  = DebuggerState.NotConnected;
            // Notify anyone interested
            DebuggerDetached?.Invoke();
            Trace.WriteLine("Debugger Server - Execute Command with Clear " + command);
            // Clear the commands buffer
            DebugCommandWrapper cmd;

            while (_commands.TryDequeue(out cmd))
            {
                cmd.TCS.SetResult(_emptyCommandResponse);
            }
            // Clear the current command
            _currentCommand           = null;
            _currentCommandBuffer     = null;
            _currentCommandReceiveIdx = 0;
            _transport.Write(command.CommandBuffer);
        }
Exemple #8
0
        internal void EvaluateCommand(string command)
        {
            command = command.Trim();

            if (string.IsNullOrEmpty(command))
            {
                this.AddMessage(new DebugConsoleLogMessage(String.Empty));
                return;
            }

            if (command.Equals("!"))
            {
                this.EvaluateCommand(this.commandHistory.GetLast());
                return;
            }

            this.commandHistory.Add(command);
            this.AddMessage(new DebugConsoleLogMessage(command, DebugConsoleMessageType.Input));

            IList <string> input = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            input = input.Select(str => str.ToLower()).ToList();

            string cmd = input[0];

            input.RemoveAt(0);

            switch (cmd)
            {
            case "clear":
                this.ClearLog();
                break;

            case "echo":
                this.AddMessage(new DebugConsoleLogMessage(String.Join(" ", input.ToArray())));
                break;

            default:
                if (this.commandsTable.ContainsKey(cmd))
                {
                    IDebugCommand dCmd = this.commandsTable[cmd];

                    CommandContext context = new CommandContext(command, dCmd, input.ToArray(), new char[0]);

                    if (!dCmd.CanExecute(context))
                    {
                        return;
                    }

                    int exitCode;
                    if ((exitCode = dCmd.Execute(context, input.ToArray(), new char[0])) != 0)
                    {
                        this.AddMessage(new DebugConsoleLogMessage(String.Format("Command ended with unproper exit code: {0}", exitCode)));
                    }
                }
                else
                {
                    this.AddMessage(new DebugConsoleLogMessage(String.Format("Unknown Command: {0}", cmd)));
                }
                break;
            }
        }
Exemple #9
0
 public static void RegisterCommand(string commandName, IDebugCommand command)
 {
     DebugConsole.Instance.RegisterCommandCallback(commandName, command);
 }
Exemple #10
0
 public DebugCommandWrapper(IDebugCommand cmd)
 {
     Command = cmd;
     TCS     = new TaskCompletionSource <byte[]>();
 }