public void ConnectViaDebugChannel(DebugConnectionListener target)
 {
     try
     {
         var result = DebugConnection.Connect(target);
         Client = new RpcClient(result, this);
         RaisePropertyChanged(nameof(Client));
     }
     catch
     {
         Messages.Add($"Failed to connect to debug channel");
     }
 }
示例#2
0
        async static Task Run(string[] args)
        {
            RegisterCommand("help", Help, "help", "Shows the list of available commands (this).");
            RegisterCommand("disconnect", Disconnect, "disconnect", "Disconnects from the debug server.");
            RegisterCommand("break", Break, "break", "Suspends execution before the next OSI instruction to be executed.");
            RegisterCommand("step", Step, "step [over|in|out]", "Executes the next OSI instruction. (over: until the next instruction in this subroutine, out: until the next instruction after this subroutine returns; default is over)");
            RegisterCommand("resume", Resume, "resume", "Resumes OSI execution when the debug server is suspended.");
            RegisterCommand("stack", Stack, "stack [values|trace|frames]", "Shows the contents of the stack of the OSI virtual machine (values: just the OSI values on the stack, trace: just the call stack, frames: the full detail of the frames of the stack; default is values)");

            string hostname = "localhost";
            int    port     = 10001;

            Console.Write("Hostname (Blank for '" + hostname + "') > ");
            string hostnameInput = Console.ReadLine().Trim();

            if (hostnameInput.Length > 0)
            {
                hostname = hostnameInput;
            }
            Console.Write("Remote port (Blank for " + port + ") > ");
            string portInput = Console.ReadLine().Trim();

            if (portInput.Length > 0)
            {
                if (!Int32.TryParse(portInput, out port))
                {
                    Console.WriteLine("Invalid port. Using " + port + ".");
                }
            }

            Console.Clear();
            //Console.CursorTop = 1;

            Connection = new DebugConnection(System.Threading.SynchronizationContext.Current, hostname, port);
            BetterWriteLine("Connecting to " + hostname + ":" + port + "...");
            await Connection.Connect();

            if (!Connection.IsConnected)
            {
                BetterWriteLine("Connection failed.");
            }
            else
            {
                BetterWriteLine("Connected!");
                bool exit = false;
                Connection.ServerDisconnect += (_, __) =>
                {
                    BetterWriteLine("Disconnected by server.");
                    exit = true;
                    //throw new Exception(); // Hack to interrupt the ReadLine() method
                };
                Connection.ServerDebugOutput += (_, output) =>
                {
                    BetterWrite(output, "[VM]: ");
                };
                Connection.ServerException += (_, output) =>
                {
                    BetterWrite(output, "[VM Error]: ");
                };
                Connection.VMState.ExecutionStateChanged += (_, __) =>
                {
                    int oldrow = Console.CursorTop;
                    int oldcol = Console.CursorLeft;
                    Console.CursorLeft = Console.WindowWidth - 12;
                    Console.CursorTop  = 0;
                    if (Connection.VMState.ExecutionState == VMState.VMExecutionState.Unknown)
                    {
                        Console.Write("?");
                        Console.Write("           ");
                    }
                    else if (Connection.VMState.ExecutionState == VMState.VMExecutionState.NativeCode)
                    {
                        Console.Write("N");
                        Console.Write("           ");
                    }
                    else if (Connection.VMState.ExecutionState == VMState.VMExecutionState.OSIRunning)
                    {
                        Console.Write("R");
                        Console.Write("           ");
                    }
                    else if (Connection.VMState.ExecutionState == VMState.VMExecutionState.OSISuspended)
                    {
                        Console.Write("P");
                        Console.Write(":0x" + Connection.VMState.InstructionPointer.ToString("X8"));
                    }
                    Console.CursorLeft = oldcol;
                    Console.CursorTop  = oldrow;
                };

                while (!exit)
                {
                    string prologue = hostname + ":" + port + " > ";
                    Console.CursorTop  = 0;
                    Console.CursorLeft = 0;
                    Console.Write(prologue.PadRight(Console.BufferWidth - 12));
                    //Console.CursorTop = 0;
                    Console.CursorLeft = prologue.Length;
                    string command = Console.ReadLine();

                    /*Console.Write(hostname + ":" + port + " > ");
                    *  Console.CursorTop = 0;
                    *  Console.CursorLeft = 0;
                    *
                    *  Console.CursorTop = 0;
                    *  Console.CursorLeft = 0;
                    *  Console.Write(hostname + ":" + port + " > ");*/

                    string[] parts = command.Split(' ');
                    if (parts.Length > 0)
                    {
                        BetterWriteLine(" > " + command);
                        if (Commands.ContainsKey(parts[0]))
                        {
                            exit = Commands[parts[0]].Run(parts);
                        }
                        else
                        {
                            Help(new string[] { });
                        }
                    }
                }
            }
            BetterWriteLine("Press any key to exit.");
            Console.ReadKey();
        }